feat(app): the bot's own Chrome in the data folder, reaching only public addresses

- install step browser: Chrome for Testing 157 (pinned SHA-256) into runtime/chrome
- services start it headless with its own profile when features.browser is on; CDP on a free
  loopback port passed to the worker as JARVIS_BROWSER_CDP; a failure leaves the services running
- every Chrome connection goes through the app's loopback egress proxy: one lookup, public
  addresses only (403 otherwise, no host logged), QUIC off, WebRTC only through the proxy
- stop: Browser.close, then kill after 5 s; dashboard shows the browser's state
- the worker's runtime environment follows the settings step, not every step being installed

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
javis-bot
2026-11-13 22:01:04 +09:00
parent 69f1bf4fa9
commit 24d0798bae
12 changed files with 724 additions and 16 deletions

View File

@@ -32,6 +32,15 @@ const TORCH: [&str; 2] = ["torch==2.11.0", "torchaudio==2.11.0"];
const TORCH_PIN: &str = "torch==2.11.0+cu128\ntorchaudio==2.11.0+cu128\n";
const MELO_URL: &str = "https://github.com/myshell-ai/MeloTTS/archive/209145371cff8fc3bd60d7be902ea69cbdb7965a.tar.gz";
pub const STT_MODEL: &str = "large-v3-turbo";
/// The bot browser (admin.spec.md, "Bot browser"): Chrome for Testing, per platform the archive
/// and its SHA-256 (computed from the downloads; Google publishes none).
pub const CHROME_VERSION: &str = "157.0.8103.78";
#[cfg(windows)]
const CHROME_ARCHIVE: (&str, &str) = ("win64/chrome-win64.zip",
"5f6ec40206407112702e163bf694d07f9fdc8ccbd346c70ce61fa62f716493f9");
#[cfg(not(windows))]
const CHROME_ARCHIVE: (&str, &str) = ("linux64/chrome-linux64.zip",
"9223832977a13db3646201b1341c1f9cf08afa3ceae92540116d7b0c062364fb");
/// Where everything goes, from the data folder and the app's Python sources (`voice_worker`, `jarvis`).
#[derive(Debug, Clone)]
@@ -61,6 +70,10 @@ impl Layout {
self.strata_home().join("terminal").join("current").join("bin")
.join(if cfg!(windows) { "strata.cmd" } else { "strata" })
}
pub fn chrome_exe(&self) -> PathBuf {
let dir = self.runtime().join("chrome");
if cfg!(windows) { dir.join("chrome-win64").join("chrome.exe") } else { dir.join("chrome-linux64").join("chrome") }
}
/// Hugging Face models (Whisper, MeloTTS and its BERT); the worker gets the same `HF_HOME`.
pub fn hf_home(&self) -> PathBuf {
self.data.join("models").join("hf")
@@ -346,6 +359,11 @@ impl Installer {
serde_json::json!({"running": self.running.load(Ordering::SeqCst), "done": all_done, "steps": steps})
}
/// Whether the step `id` is installed at its current version.
pub fn done(&self, id: &str) -> bool {
self.steps.iter().any(|s| s.id() == id && self.is_done(s.as_ref()))
}
pub fn all_done(&self) -> bool {
self.steps.iter().all(|s| self.is_done(s.as_ref()))
}
@@ -600,6 +618,55 @@ impl Step for StrataStep {
}
}
struct BrowserStep;
#[async_trait]
impl Step for BrowserStep {
fn id(&self) -> &'static str { "browser" }
fn label(&self) -> &'static str { "봇용 크롬" }
fn size_hint(&self) -> &'static str { "약 200MB" }
fn version(&self, _: &Layout) -> String { CHROME_VERSION.into() }
async fn run(&self, ctx: &Ctx) -> Result<(), String> {
let (path, sum) = CHROME_ARCHIVE;
let url = format!("https://storage.googleapis.com/chrome-for-testing-public/{CHROME_VERSION}/{path}");
let archive = ctx.layout.data.join("cache").join("downloads").join(path.rsplit('/').next().unwrap());
crate::download::download(&url, &archive, sum, &|d, t| ctx.bytes(d, t), &ctx.cancel).await.map_err(|e| e.0)?;
let dir = ctx.layout.runtime().join("chrome");
let _ = std::fs::remove_dir_all(&dir);
unzip(&archive, &dir)?;
let _ = std::fs::remove_file(&archive);
if !ctx.layout.chrome_exe().exists() {
return Err("크롬 압축을 풀었지만 실행 파일이 없습니다".into());
}
Ok(())
}
}
/// Unpack a zip into `dir`, keeping its folders and (on Unix) its executable bits.
fn unzip(archive: &Path, dir: &Path) -> Result<(), String> {
let f = std::fs::File::open(archive).map_err(|e| e.to_string())?;
let mut z = zip::ZipArchive::new(f).map_err(|e| e.to_string())?;
for i in 0..z.len() {
let mut entry = z.by_index(i).map_err(|e| e.to_string())?;
let Some(rel) = entry.enclosed_name() else { continue };
let out = dir.join(rel);
if entry.is_dir() {
std::fs::create_dir_all(&out).map_err(|e| e.to_string())?;
continue;
}
if let Some(parent) = out.parent() {
std::fs::create_dir_all(parent).map_err(|e| e.to_string())?;
}
let mut w = std::fs::File::create(&out).map_err(|e| e.to_string())?;
std::io::copy(&mut entry, &mut w).map_err(|e| e.to_string())?;
#[cfg(unix)]
if let Some(mode) = entry.unix_mode() {
use std::os::unix::fs::PermissionsExt;
std::fs::set_permissions(&out, std::fs::Permissions::from_mode(mode & 0o777)).map_err(|e| e.to_string())?;
}
}
Ok(())
}
/// Point the services at what was installed: the worker venv's Python and the arguments for the
/// MeloTTS venv, the history store and the brain (`voiceWorker` in `config/settings.json`; other
/// keys are kept).
@@ -638,7 +705,7 @@ impl Step for SettingsStep {
/// The install steps, in order.
pub fn steps() -> Vec<Box<dyn Step>> {
vec![Box::new(UvStep), Box::new(WorkerEnvStep), Box::new(MeloEnvStep), Box::new(SttModelStep),
Box::new(TtsModelStep), Box::new(StrataStep), Box::new(SettingsStep)]
Box::new(TtsModelStep), Box::new(StrataStep), Box::new(BrowserStep), Box::new(SettingsStep)]
}
#[cfg(test)]
@@ -823,4 +890,30 @@ mod tests {
}
assert!(l.uv().starts_with(&l.data) && l.venv_python("worker").starts_with(&l.data));
}
#[test]
fn a_zip_unpacks_with_its_folders_and_executable_bits() {
use std::io::Write;
let d = temp_dir("unzip");
let archive = d.join("a.zip");
let mut w = zip::ZipWriter::new(std::fs::File::create(&archive).unwrap());
let exe = zip::write::SimpleFileOptions::default().unix_permissions(0o755);
w.add_directory("top/sub/", zip::write::SimpleFileOptions::default()).unwrap();
w.start_file("top/chrome", exe).unwrap();
w.write_all(b"#!/bin/sh\n").unwrap();
w.start_file("top/sub/data.pak", zip::write::SimpleFileOptions::default().unix_permissions(0o644)).unwrap();
w.write_all(b"data").unwrap();
w.start_file("../escape", zip::write::SimpleFileOptions::default()).unwrap();
w.write_all(b"no").unwrap();
w.finish().unwrap();
let out = d.join("out");
unzip(&archive, &out).unwrap();
assert_eq!(std::fs::read(out.join("top/sub/data.pak")).unwrap(), b"data");
assert!(!d.join("escape").exists());
#[cfg(unix)]
{
use std::os::unix::fs::PermissionsExt;
assert_eq!(std::fs::metadata(out.join("top/chrome")).unwrap().permissions().mode() & 0o777, 0o755);
}
}
}