feat(app): M5 step 4a, install the runtime and voice models into the data folder

- download: resumed downloads checked against a pinned SHA-256.
- install: uv 0.11.20, the worker/brain venv (Python 3.12, the new
  src/voice_worker/requirements-brain.txt), the MeloTTS venv (Python 3.11,
  PyTorch cu128), Whisper large-v3-turbo, the Korean MeloTTS voice and
  Strata, the M0 kit's recipe; markers per step and version, cancel, retry,
  everything (caches, temp, HF and NLTK data) inside the data folder, the uv
  cache cleaned and the worker settings pointed at the venvs when done.
- The services give the worker the same environment once installed.
- The wizard's model step shows and drives the install.

Installed from an empty folder on Linux and started the services on it:
worker connected, STT and TTS ready, nothing written outside the folder.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
javis-bot
2026-11-12 17:11:23 +09:00
parent b68eef3ec1
commit a4436698c8
13 changed files with 970 additions and 11 deletions

2
app/Cargo.lock generated
View File

@@ -1493,9 +1493,11 @@ dependencies = [
"futures-util",
"opus2",
"rand 0.9.5",
"reqwest",
"serde",
"serde_json",
"serenity",
"sha2",
"songbird",
"symphonia",
"tokio",

View File

@@ -29,6 +29,8 @@ base64 = "0.22"
async-trait = "0.1"
opus2 = "0.4"
fs4 = "1.1"
reqwest = { version = "0.12", default-features = false, features = ["rustls-tls", "stream"] }
sha2 = "0.10"
chrono = { version = "0.4", default-features = false, features = ["clock", "std"] }
zip = { version = "9", default-features = false, features = ["deflate"] }
unicode-normalization = "0.1"

View File

@@ -26,7 +26,7 @@ never deletes anything. `DataDir::choose(path)` creates it and writes the locati
```
config/ runtime/ models/llm models/stt models/tts models/vad memory/ browser/ collect/
cache/ logs/
cache/ logs/ models/hf models/nltk
```
`free_bytes(path)` reports the free space of the disk holding the folder (or its nearest existing
@@ -127,7 +127,39 @@ reaches the screen.
The dashboard's state is built from the core's events alone (`Dashboard::on_event` with the time),
so it is tested with made-up events.
## Admin commands (`app/src/admin_api.rs`)
## Install (`app/src/install.rs`, `app/src/download.rs`)
The wizard's model step installs the runtime into the data folder with the recipe the M0 kit used
on the game PC (`scripts/m0`). The steps, in order:
| Step | What |
|---|---|
| `uv` | `uv` 0.11.20, downloaded with resume and checked against the release's SHA-256, into `runtime/uv` |
| `worker_env` | Python 3.12 venv `runtime/venvs/worker` with `src/voice_worker/requirements.txt` and `requirements-brain.txt` (the v2 brain only; the repository's `requirements.txt` is v1's desktop app) |
| `melo_env` | Python 3.11 venv `runtime/venvs/melo`: PyTorch 2.11 cu128 (pinned so later installs keep it), MeloTTS at a pinned commit, `python-mecab-ko` instead of the Japanese MeCab |
| `stt_model` | Whisper `large-v3-turbo` (faster-whisper) |
| `tts_model` | the NLTK data MeloTTS's English g2p reads, then the worker's own `melo_child.py` loads the Korean voice once (downloading it) and must say its warm-up sentence |
| `strata` | Strata's own installer (`install.ps1`, `install.sh` elsewhere) with Strata's state, engine and components under `runtime/strata` and no PATH change |
The LLM itself (Qwen3.6-35B-A3B, about 23 GB) is downloaded by Strata on its first start, which the
app runs next (M5, later step).
- A finished step leaves `runtime/.done/<id>` holding its version (the pin; for `worker_env` a hash
of its requirement files), so later runs skip it and a new pin runs it again. Steps run one at a
time; a failure stops the run and the next run starts at that step; cancel stops the running
command or download (a download's part file stays, so the next try continues it).
- Every command runs with the layout's environment: `uv`'s cache and Pythons, `HF_HOME`
(`models/hf`), `NLTK_DATA` (`models/nltk`), temp files (`cache/tmp`) and Strata's folders, all
inside the data folder. Python comes from `uv` only. Output lines go to the `install` log tab.
- Downloads go to `<file>.part`, continue with an HTTP range after a break (a server without ranges
starts over), and are checked against the pinned SHA-256; a wrong checksum deletes the part.
- When every step is done, `uv`'s download cache is cleaned (the venvs hold copies), and
`voiceWorker` in the settings is pointed at the worker venv's Python with
`--melo-python <melo venv> --history memory/history.sqlite --brain` (other settings kept).
- With the install complete, the services start the worker with the same environment (models,
caches and temp files in the data folder; on Linux also the CUDA wheels' library folders).
`AdminApi::call(command, args)` is the one entry point of the screens, JSON in and out; errors come
back as Korean messages for the screen. The Tauri shell passes the screens' `invoke("admin",
@@ -144,6 +176,7 @@ back as Korean messages for the screen. The Tauri shell passes the screens' `inv
| `discord_guilds` / `discord_channels` `{guildId}` | the bot's servers / a server's voice and text channels, for the pickers |
| `settings_fields` / `settings_view` / `settings_apply` `{changes}` | the settings editor above; `restartNeeded` when the services run |
| `service_start` / `service_stop` / `service_restart` / `dashboard` | the controller and its snapshot |
| `install_status` / `install_start` / `install_cancel` | the install steps and their state, bytes and last line / run what is not done in the background / stop it |
| `logs_query` `{tab, level, find, after, limit}` / `logs_error_report` / `logs_export` `{from, to}` | the log hub; the zip goes to `logs/` and its path comes back |
The invite link asks for: view channels, send messages, read history, add reactions, manage
@@ -158,7 +191,8 @@ Plain HTML, CSS and an ES module, no build step, dark theme after `DESIGN.md`. A
- **First-run wizard** (while `firstRun`): data folder (free space, warning under 200 GB), PC check,
the model to download (the download itself is step 4 of M5), Discord bot (token check with the
Message Content state and the invite link, then save), server and auto-join voice channel
pickers, wake words, then start. Each step reached is saved, so a reload or a restart resumes at
pickers, wake words, then start. The model step shows the install (each step's state, download
bytes and last line; start, cancel, retry) and goes on only once everything is installed. Each step reached is saved, so a reload or a restart resumes at
that step; only the last step's start finishes it. A stored token lets the bot step go on
without entering it again.
- **Dashboard**: the snapshot every second; the header with start, restart and stop is rebuilt

View File

@@ -20,6 +20,7 @@ pub struct AdminApi {
location_file: PathBuf,
dir: Mutex<Option<DataDir>>,
controller: Mutex<Option<Arc<Controller>>>,
installer: Mutex<Option<Arc<crate::install::Installer>>>,
hub: Arc<LogHub>,
}
@@ -44,7 +45,7 @@ impl AdminApi {
/// `location_file`: where the data folder is remembered; `hub`: the app's log hub.
pub fn new(location_file: &Path, hub: Arc<LogHub>) -> Self {
let dir = DataDir::locate(location_file);
Self { location_file: location_file.to_path_buf(), dir: Mutex::new(dir), controller: Mutex::new(None), hub }
Self { location_file: location_file.to_path_buf(), dir: Mutex::new(dir), controller: Mutex::new(None), installer: Mutex::new(None), hub }
}
fn dir(&self) -> Result<DataDir, String> {
@@ -73,6 +74,18 @@ impl AdminApi {
.map_err(|e| format!("설정 진행 상황을 저장하지 못했습니다: {e}"))
}
/// The installer for the data folder; the Python sources come from the settings' worker folder.
fn installer(&self) -> Result<Arc<crate::install::Installer>, String> {
let dir = self.dir()?;
let mut i = self.installer.lock().unwrap();
if i.is_none() {
let src = crate::settings::load_settings(&dir.settings_file()).map_err(|e| e.0)?.voice_worker.cwd;
let layout = crate::install::Layout { data: dir.path().to_path_buf(), src };
*i = Some(crate::install::Installer::new(layout, crate::install::steps()));
}
Ok(i.clone().unwrap())
}
fn controller(&self) -> Result<Arc<Controller>, String> {
let dir = self.dir()?;
let mut c = self.controller.lock().unwrap();
@@ -127,9 +140,27 @@ impl AdminApi {
self.hub.set_dir(&dir.logs());
*self.dir.lock().unwrap() = Some(dir);
*self.controller.lock().unwrap() = None;
*self.installer.lock().unwrap() = None;
crate::info_log!("admin", "data folder chosen");
Ok(json!({"dataDir": path.to_string_lossy()}))
}
"install_status" => Ok(self.installer()?.status()),
"install_start" => {
let inst = self.installer()?;
let settings = self.dir()?.settings_file();
if !inst.start_then(move |layout| {
if let Err(e) = crate::install::apply_runtime_settings(&settings, layout) {
crate::error_log!("install", "could not point the settings at the runtime: {e}");
}
}) {
return Err("설치가 이미 진행 중입니다".into());
}
Ok(json!({"started": true}))
}
"install_cancel" => {
self.installer()?.cancel();
Ok(json!({"cancelling": true}))
}
"pc_check" => {
let usage = crate::system::usage().await;
let driver = crate::system::driver_version().await;
@@ -207,7 +238,7 @@ mod tests {
fn api(tag: &str) -> (AdminApi, PathBuf) {
let base = temp_dir(tag);
let loc = base.join("cfg").join("location.json");
(AdminApi { location_file: loc, dir: Mutex::new(None), controller: Mutex::new(None), hub: LogHub::new(None) },
(AdminApi { location_file: loc, dir: Mutex::new(None), controller: Mutex::new(None), installer: Mutex::new(None), hub: LogHub::new(None) },
base)
}

View File

@@ -10,7 +10,7 @@ pub const RECOMMENDED_FREE_BYTES: u64 = 200 * 1_000_000_000;
/// Folders inside the data folder (desktop-app.md, "데이터 폴더 구조").
pub const LAYOUT: &[&str] = &[
"config", "runtime", "models/llm", "models/stt", "models/tts", "models/vad", "memory", "browser",
"collect", "cache", "logs",
"collect", "cache", "logs", "models/hf", "models/nltk",
];
#[derive(Debug, Clone, PartialEq, Eq)]

187
app/src/download.rs Normal file
View File

@@ -0,0 +1,187 @@
//! Downloads for the installer (`app/src/admin.spec.md`, "Install"): resumed where they stopped, and
//! checked against a pinned SHA-256 before they are used.
use std::path::{Path, PathBuf};
use std::sync::atomic::{AtomicBool, Ordering};
use futures_util::StreamExt;
use sha2::{Digest, Sha256};
use tokio::io::AsyncWriteExt;
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct DownloadError(pub String);
impl std::fmt::Display for DownloadError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(&self.0)
}
}
impl std::error::Error for DownloadError {}
fn e(what: &str) -> impl FnOnce(std::io::Error) -> DownloadError + '_ {
move |err| DownloadError(format!("{what}: {err}"))
}
pub fn sha256_file(path: &Path) -> std::io::Result<String> {
let mut f = std::fs::File::open(path)?;
let mut h = Sha256::new();
std::io::copy(&mut f, &mut h)?;
Ok(format!("{:x}", h.finalize()))
}
/// Download `url` to `dest`, checked against `sha256` (lowercase hex). The bytes go to
/// `dest.part` first; an interrupted download continues from there (HTTP Range), a server that
/// ignores the range starts it over. A wrong checksum deletes the part file, so the next try starts
/// clean. `progress(done, total)` is called as bytes arrive; `cancel` stops it between chunks (the
/// part file stays for the next try). An existing `dest` with the right checksum is kept as it is.
pub async fn download(url: &str, dest: &Path, sha256: &str, progress: &(dyn Fn(u64, Option<u64>) + Sync),
cancel: &AtomicBool) -> Result<(), DownloadError> {
if dest.exists() && sha256_file(dest).map_err(e("could not read the download"))? == sha256 {
return Ok(());
}
if let Some(dir) = dest.parent() {
tokio::fs::create_dir_all(dir).await.map_err(e("could not create the download folder"))?;
}
let part = PathBuf::from(format!("{}.part", dest.display()));
let have = tokio::fs::metadata(&part).await.map(|m| m.len()).unwrap_or(0);
let client = reqwest::Client::builder().build().map_err(|x| DownloadError(x.to_string()))?;
let mut req = client.get(url);
if have > 0 {
req = req.header(reqwest::header::RANGE, format!("bytes={have}-"));
}
let resp = req.send().await.map_err(|x| DownloadError(format!("could not download {url}: {x}")))?;
let status = resp.status();
if status.as_u16() == 416 && have > 0 {
// The part file already holds every byte: check it below.
} else if !status.is_success() {
return Err(DownloadError(format!("download of {url} failed: HTTP {status}")));
}
let resumed = status.as_u16() == 206;
let total = resp.content_length().map(|n| if resumed { n + have } else { n });
let mut file = tokio::fs::OpenOptions::new().create(true).write(true).append(resumed).truncate(!resumed && status.as_u16() != 416)
.open(&part).await.map_err(e("could not write the download"))?;
let mut done = if resumed || status.as_u16() == 416 { have } else { 0 };
progress(done, total);
if status.as_u16() != 416 {
let mut stream = resp.bytes_stream();
while let Some(chunk) = stream.next().await {
if cancel.load(Ordering::Relaxed) {
file.flush().await.ok();
return Err(DownloadError("cancelled".into()));
}
let chunk = chunk.map_err(|x| DownloadError(format!("download of {url} broke off: {x}")))?;
file.write_all(&chunk).await.map_err(e("could not write the download"))?;
done += chunk.len() as u64;
progress(done, total);
}
}
file.flush().await.map_err(e("could not write the download"))?;
drop(file);
let got = sha256_file(&part).map_err(e("could not read the download"))?;
if got != sha256 {
let _ = tokio::fs::remove_file(&part).await;
return Err(DownloadError(format!("the download of {url} is damaged (checksum {got}, expected {sha256})")));
}
tokio::fs::rename(&part, dest).await.map_err(e("could not move the download into place"))?;
Ok(())
}
#[cfg(test)]
mod tests {
use super::*;
use crate::datadir::temp_dir;
use std::sync::{Arc, Mutex};
use tokio::io::{AsyncReadExt, AsyncWriteExt};
use tokio::net::TcpListener;
/// A file server that honours `Range: bytes=N-` (unless `ranges` is off) and can stop after
/// `cut` bytes of a response, like a broken connection. Records the ranges asked for.
async fn serve(body: Vec<u8>, ranges: bool, cut: Option<usize>) -> (String, Arc<Mutex<Vec<String>>>) {
let l = TcpListener::bind("127.0.0.1:0").await.unwrap();
let url = format!("http://{}/f.bin", l.local_addr().unwrap());
let asked = Arc::new(Mutex::new(vec![]));
let a2 = asked.clone();
let cut = Arc::new(Mutex::new(cut));
tokio::spawn(async move {
loop {
let Ok((mut s, _)) = l.accept().await else { return };
let mut buf = vec![0u8; 4096];
let n = s.read(&mut buf).await.unwrap_or(0);
let head = String::from_utf8_lossy(&buf[..n]).to_string();
let from = head.lines().find_map(|l| l.strip_prefix("range: bytes=").or(l.strip_prefix("Range: bytes=")))
.and_then(|r| r.trim_end_matches('-').parse::<usize>().ok());
a2.lock().unwrap().push(from.map(|f| f.to_string()).unwrap_or_default());
let (status, slice) = match from {
Some(f) if ranges && f >= body.len() => ("416 Range Not Satisfiable", &body[0..0]),
Some(f) if ranges => ("206 Partial Content", &body[f..]),
_ => ("200 OK", &body[..]),
};
let head = format!("HTTP/1.1 {status}\r\nContent-Length: {}\r\nConnection: close\r\n\r\n", slice.len());
let _ = s.write_all(head.as_bytes()).await;
let send = cut.lock().unwrap().take().map_or(slice.len(), |c| c.min(slice.len()));
let _ = s.write_all(&slice[..send]).await;
}
});
(url, asked)
}
fn data() -> (Vec<u8>, String) {
let b: Vec<u8> = (0..200_000u32).map(|i| (i * 31 % 251) as u8).collect();
let h = format!("{:x}", Sha256::digest(&b));
(b, h)
}
#[tokio::test]
async fn a_broken_download_resumes_where_it_stopped() {
let (body, sum) = data();
let (url, asked) = serve(body.clone(), true, Some(70_000)).await;
let dest = temp_dir("dl1").join("f.bin");
let never = AtomicBool::new(false);
assert!(download(&url, &dest, &sum, &|_, _| {}, &never).await.is_err(), "the first try breaks off");
assert!(!dest.exists());
let seen = Mutex::new(vec![]);
download(&url, &dest, &sum, &|d, t| seen.lock().unwrap().push((d, t)), &never).await.unwrap();
assert_eq!(std::fs::read(&dest).unwrap(), body);
assert_eq!(asked.lock().unwrap().as_slice(), ["", "70000"]);
let seen = seen.lock().unwrap();
assert_eq!(seen.first(), Some(&(70_000, Some(200_000))));
assert_eq!(seen.last(), Some(&(200_000, Some(200_000))));
// Present and right: nothing is fetched again.
download(&url, &dest, &sum, &|_, _| {}, &never).await.unwrap();
assert_eq!(asked.lock().unwrap().len(), 2);
}
#[tokio::test]
async fn a_server_without_ranges_starts_over_and_a_bad_checksum_is_thrown_away() {
let (body, sum) = data();
let (url, _) = serve(body.clone(), false, Some(50_000)).await;
let dest = temp_dir("dl2").join("f.bin");
let never = AtomicBool::new(false);
let _ = download(&url, &dest, &sum, &|_, _| {}, &never).await;
download(&url, &dest, &sum, &|_, _| {}, &never).await.unwrap();
assert_eq!(std::fs::read(&dest).unwrap(), body);
let wrong = "0".repeat(64);
let dest2 = temp_dir("dl3").join("f.bin");
let err = download(&url, &dest2, &wrong, &|_, _| {}, &never).await.unwrap_err();
assert!(err.0.contains("damaged"));
assert!(!dest2.exists() && !PathBuf::from(format!("{}.part", dest2.display())).exists());
}
#[tokio::test]
async fn cancelling_keeps_the_part_for_the_next_try() {
let (body, sum) = data();
let (url, asked) = serve(body.clone(), true, None).await;
let dest = temp_dir("dl4").join("f.bin");
let cancel = AtomicBool::new(false);
let err = download(&url, &dest, &sum, &|d, _| if d > 0 { cancel.store(true, Ordering::Relaxed) }, &cancel)
.await.unwrap_err();
assert_eq!(err.0, "cancelled");
let part = std::fs::metadata(format!("{}.part", dest.display())).unwrap().len();
assert!(part > 0 && part < body.len() as u64);
cancel.store(false, Ordering::Relaxed);
download(&url, &dest, &sum, &|_, _| {}, &cancel).await.unwrap();
assert_eq!(std::fs::read(&dest).unwrap(), body);
assert_eq!(asked.lock().unwrap()[1], part.to_string());
}
}

653
app/src/install.rs Normal file
View File

@@ -0,0 +1,653 @@
//! Runtime and model install into the data folder (`app/src/admin.spec.md`, "Install").
//!
//! The steps run one after another and each leaves a marker (`runtime/.done/<id>` holding its
//! version) once it finished, so a later run skips what is done and redoes a step whose pinned
//! version changed. The same recipe the M0 kit used on the game PC (`scripts/m0`): a pinned `uv`
//! installs Python and the venvs, Strata's own installer puts it in the folder. Every cache, temp
//! file and model goes inside the data folder.
use std::path::{Path, PathBuf};
use std::process::Stdio;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::{Arc, Mutex};
use async_trait::async_trait;
use serde::Serialize;
use tokio::io::{AsyncBufReadExt, BufReader};
/// Pinned `uv` (the version the M0 kit used), per platform: archive URL and SHA-256 from the
/// release's `.sha256` files.
pub const UV_VERSION: &str = "0.11.20";
#[cfg(windows)]
const UV_ARCHIVE: (&str, &str) = ("uv-x86_64-pc-windows-msvc.zip",
"4c281f1b6b9ccb14d9567ebde9a218a7cabfb35e5ffe8c1d4ef5e2821a655474");
#[cfg(not(windows))]
const UV_ARCHIVE: (&str, &str) = ("uv-x86_64-unknown-linux-gnu.tar.gz",
"5de211d9278af365497d387e25316907b3b4a9f25b4476dd6dbf238d6f85cff3");
pub const STRATA_INSTALL: &str = "https://github.com/Niko1221/Strata/releases/latest/download/install";
/// MeloTTS and the PyTorch it runs on (scripts/m0/m0lib/envs.py, "melo").
const CU128_INDEX: &str = "https://download.pytorch.org/whl/cu128";
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";
/// Where everything goes, from the data folder and the app's Python sources (`voice_worker`, `jarvis`).
#[derive(Debug, Clone)]
pub struct Layout {
pub data: PathBuf,
pub src: PathBuf,
}
impl Layout {
pub fn runtime(&self) -> PathBuf {
self.data.join("runtime")
}
pub fn uv(&self) -> PathBuf {
self.runtime().join("uv").join(if cfg!(windows) { "uv.exe" } else { "uv" })
}
pub fn venv(&self, name: &str) -> PathBuf {
self.runtime().join("venvs").join(name)
}
pub fn venv_python(&self, name: &str) -> PathBuf {
let v = self.venv(name);
if cfg!(windows) { v.join("Scripts").join("python.exe") } else { v.join("bin").join("python") }
}
pub fn strata_home(&self) -> PathBuf {
self.runtime().join("strata")
}
pub fn strata_exe(&self) -> PathBuf {
self.strata_home().join("terminal").join("current").join("bin")
.join(if cfg!(windows) { "strata.cmd" } else { "strata" })
}
/// 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")
}
fn done_marker(&self, id: &str) -> PathBuf {
self.runtime().join(".done").join(id)
}
/// The environment every install command and the voice worker run with: caches, temp files and
/// models inside the data folder, Python from uv only.
pub fn env(&self) -> Vec<(String, String)> {
let s = |p: PathBuf| p.to_string_lossy().into_owned();
let tmp = s(self.data.join("cache").join("tmp"));
let mut env = vec![
("UV_CACHE_DIR".into(), s(self.data.join("cache").join("uv"))),
("UV_PYTHON_INSTALL_DIR".into(), s(self.runtime().join("python"))),
("UV_PYTHON_PREFERENCE".into(), "only-managed".into()),
("UV_LINK_MODE".into(), "copy".into()),
("PYTHONUTF8".into(), "1".into()),
("PYTHONIOENCODING".into(), "utf-8".into()),
("HF_HOME".into(), s(self.hf_home())),
("NLTK_DATA".into(), s(self.data.join("models").join("nltk"))),
("TMP".into(), tmp.clone()),
("TEMP".into(), tmp.clone()),
("TMPDIR".into(), tmp),
("STRATA_DATA_DIR".into(), s(self.strata_home())),
("STRATA_NO_PATH".into(), "1".into()),
("STRATA_HOME".into(), s(self.strata_home().join("home"))),
("STRATA_COMPONENTS_DIR".into(), s(self.strata_home().join("components"))),
];
if cfg!(windows) {
env.push(("LOCALAPPDATA".into(), s(self.strata_home().join("localappdata"))));
} else {
// On Windows the worker adds the pip CUDA wheels' DLL folders itself; on Linux the loader
// needs them in LD_LIBRARY_PATH before the process starts.
let libs = self.cuda_lib_dirs();
if !libs.is_empty() {
let mut path = libs.iter().map(|p| s(p.clone())).collect::<Vec<_>>().join(":");
if let Ok(old) = std::env::var("LD_LIBRARY_PATH") {
path = format!("{path}:{old}");
}
env.push(("LD_LIBRARY_PATH".into(), path));
}
}
env
}
/// `nvidia/*/lib` folders of the worker venv's CUDA wheels (cuBLAS, cuDNN).
fn cuda_lib_dirs(&self) -> Vec<PathBuf> {
let mut out = vec![];
let Ok(libs) = std::fs::read_dir(self.venv("worker").join("lib")) else { return out };
for py in libs.flatten() {
let nvidia = py.path().join("site-packages").join("nvidia");
if let Ok(rd) = std::fs::read_dir(&nvidia) {
out.extend(rd.flatten().map(|e| e.path().join("lib")).filter(|p| p.is_dir()));
}
}
out.sort();
out
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize)]
#[serde(rename_all = "lowercase")]
pub enum StepState {
Pending,
Running,
Done,
Failed,
}
#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct StepStatus {
pub id: String,
pub label: String,
pub size_hint: String,
pub state: StepState,
/// Bytes done and total of a download, when the step has one.
pub bytes: Option<(u64, Option<u64>)>,
/// The step's last output line or its error (no secrets: install output holds none).
pub note: Option<String>,
}
/// What a step gets: the layout, a way to report, and the cancel flag.
pub struct Ctx {
pub layout: Layout,
status: Arc<Mutex<Vec<StepStatus>>>,
index: usize,
pub cancel: Arc<AtomicBool>,
}
impl Ctx {
pub fn note(&self, line: &str) {
let line: String = line.chars().take(300).collect();
self.status.lock().unwrap()[self.index].note = Some(line);
}
pub fn bytes(&self, done: u64, total: Option<u64>) {
self.status.lock().unwrap()[self.index].bytes = Some((done, total));
}
/// Run a program with the layout's environment; each output line becomes the step's note and an
/// `install` log line. Fails on a non-zero exit, with the last line.
pub async fn run(&self, program: &Path, args: &[&str]) -> Result<(), String> {
let mut cmd = tokio::process::Command::new(program);
cmd.args(args).envs(self.layout.env()).stdin(Stdio::null()).stdout(Stdio::piped()).stderr(Stdio::piped())
.kill_on_drop(true);
#[cfg(windows)]
cmd.creation_flags(0x0800_0000); // CREATE_NO_WINDOW
let _ = std::fs::create_dir_all(self.layout.data.join("cache").join("tmp"));
let name = program.file_name().map(|n| n.to_string_lossy().into_owned()).unwrap_or_default();
crate::info_log!("install", "run {name} {}", args.first().copied().unwrap_or(""));
let mut child = cmd.spawn().map_err(|e| format!("{name}을(를) 실행하지 못했습니다: {e}"))?;
let (out, err) = (child.stdout.take().unwrap(), child.stderr.take().unwrap());
let last = Arc::new(Mutex::new(String::new()));
let pump = |r: Box<dyn tokio::io::AsyncRead + Unpin + Send>| {
let (last, status, index) = (last.clone(), self.status.clone(), self.index);
tokio::spawn(async move {
let mut lines = BufReader::new(r).lines();
while let Ok(Some(l)) = lines.next_line().await {
let l = l.trim().to_owned();
if l.is_empty() {
continue;
}
if let Some(hub) = crate::logs::installed() {
hub.push(crate::logs::Level::Info, "install", &l);
}
status.lock().unwrap()[index].note = Some(l.chars().take(300).collect());
*last.lock().unwrap() = l;
}
})
};
let (a, b) = (pump(Box::new(out)), pump(Box::new(err)));
let status = loop {
tokio::select! {
s = child.wait() => break s.map_err(|e| e.to_string())?,
_ = tokio::time::sleep(std::time::Duration::from_millis(200)) => {
if self.cancel.load(Ordering::Relaxed) {
let _ = child.kill().await;
return Err("cancelled".into());
}
}
}
};
let _ = (a.await, b.await);
if status.success() {
Ok(())
} else {
Err(format!("{name}이(가) 실패했습니다 ({status}): {}", last.lock().unwrap()))
}
}
}
#[async_trait]
pub trait Step: Send + Sync {
fn id(&self) -> &'static str;
fn label(&self) -> &'static str;
fn size_hint(&self) -> &'static str;
/// Changing it (a new pin, new requirement files) makes the step run again.
fn version(&self, layout: &Layout) -> String;
async fn run(&self, ctx: &Ctx) -> Result<(), String>;
}
pub struct Installer {
layout: Layout,
steps: Vec<Box<dyn Step>>,
status: Arc<Mutex<Vec<StepStatus>>>,
running: AtomicBool,
cancel: Arc<AtomicBool>,
}
impl Installer {
pub fn new(layout: Layout, steps: Vec<Box<dyn Step>>) -> Arc<Self> {
let status = steps.iter().map(|s| StepStatus { id: s.id().into(), label: s.label().into(),
size_hint: s.size_hint().into(), state: StepState::Pending, bytes: None, note: None }).collect();
let me = Arc::new(Self { layout, steps, status: Arc::new(Mutex::new(status)), running: AtomicBool::new(false),
cancel: Arc::new(AtomicBool::new(false)) });
me.mark_done();
me
}
fn is_done(&self, s: &dyn Step) -> bool {
std::fs::read_to_string(self.layout.done_marker(s.id())).is_ok_and(|v| v == s.version(&self.layout))
}
fn mark_done(&self) {
let mut st = self.status.lock().unwrap();
for (i, s) in self.steps.iter().enumerate() {
if st[i].state != StepState::Running {
st[i].state = if self.is_done(s.as_ref()) { StepState::Done } else if st[i].state == StepState::Failed {
StepState::Failed } else { StepState::Pending };
}
}
}
pub fn status(&self) -> serde_json::Value {
self.mark_done();
let steps = self.status.lock().unwrap().clone();
let all_done = steps.iter().all(|s| s.state == StepState::Done);
serde_json::json!({"running": self.running.load(Ordering::SeqCst), "done": all_done, "steps": steps})
}
pub fn all_done(&self) -> bool {
self.steps.iter().all(|s| self.is_done(s.as_ref()))
}
/// Run the steps not done yet, in order, in the background, then `finished` once all are done;
/// false if already running.
pub fn start_then(self: &Arc<Self>, finished: impl FnOnce(&Layout) + Send + 'static) -> bool {
if self.running.swap(true, Ordering::SeqCst) {
return false;
}
self.cancel.store(false, Ordering::SeqCst);
let me = self.clone();
tokio::spawn(async move {
if me.run_all().await {
finished(&me.layout);
}
me.running.store(false, Ordering::SeqCst);
});
true
}
/// The same, awaited (tests and the command line).
pub async fn run_all(self: &Arc<Self>) -> bool {
let mut ran = false;
for (i, step) in self.steps.iter().enumerate() {
if self.is_done(step.as_ref()) {
continue;
}
ran = true;
{
let mut st = self.status.lock().unwrap();
st[i].state = StepState::Running;
st[i].note = None;
st[i].bytes = None;
}
crate::info_log!("install", "step {} started", step.id());
let ctx = Ctx { layout: self.layout.clone(), status: self.status.clone(), index: i, cancel: self.cancel.clone() };
let result = step.run(&ctx).await;
let mut st = self.status.lock().unwrap();
match result {
Ok(()) => {
let marker = self.layout.done_marker(step.id());
let _ = crate::datadir::write_atomic(&marker, step.version(&self.layout).as_bytes());
st[i].state = StepState::Done;
crate::info_log!("install", "step {} done", step.id());
}
Err(e) => {
st[i].state = StepState::Failed;
st[i].note = Some(if e == "cancelled" { "취소했습니다. 다시 시도하면 이어서 받습니다.".into() } else { e.clone() });
crate::error_log!("install", "step {} failed: {e}", step.id());
return false;
}
}
}
// The venvs hold copies (UV_LINK_MODE=copy): the download cache (about 12 GB after the
// MeloTTS venv) is no longer needed once everything is in.
let uv = self.layout.uv();
if ran && uv.exists() {
let mut cmd = tokio::process::Command::new(&uv);
cmd.args(["cache", "clean"]).envs(self.layout.env()).stdin(Stdio::null()).stdout(Stdio::null())
.stderr(Stdio::null());
#[cfg(windows)]
cmd.creation_flags(0x0800_0000);
let ok = cmd.status().await.is_ok_and(|s| s.success());
crate::info_log!("install", "download cache cleaned: {ok}");
}
true
}
pub fn cancel(&self) {
self.cancel.store(true, Ordering::SeqCst);
}
}
// ---- the real steps -------------------------------------------------------------------------------
struct UvStep;
#[async_trait]
impl Step for UvStep {
fn id(&self) -> &'static str { "uv" }
fn label(&self) -> &'static str { "설치 도구(uv)" }
fn size_hint(&self) -> &'static str { "약 25MB" }
fn version(&self, _: &Layout) -> String { UV_VERSION.into() }
async fn run(&self, ctx: &Ctx) -> Result<(), String> {
let (file, sum) = UV_ARCHIVE;
let url = format!("https://github.com/astral-sh/uv/releases/download/{UV_VERSION}/{file}");
let archive = ctx.layout.data.join("cache").join("downloads").join(file);
crate::download::download(&url, &archive, sum, &|d, t| ctx.bytes(d, t), &ctx.cancel).await.map_err(|e| e.0)?;
let dir = ctx.layout.uv().parent().unwrap().to_path_buf();
std::fs::create_dir_all(&dir).map_err(|e| e.to_string())?;
if file.ends_with(".zip") {
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(name) = entry.enclosed_name().and_then(|p| p.file_name().map(PathBuf::from)) else { continue };
if entry.is_file() {
let mut out = std::fs::File::create(dir.join(name)).map_err(|e| e.to_string())?;
std::io::copy(&mut entry, &mut out).map_err(|e| e.to_string())?;
}
}
} else {
ctx.run(Path::new("tar"), &["-xzf", &archive.to_string_lossy(), "-C", &dir.to_string_lossy(),
"--strip-components=1"]).await?;
}
ctx.run(&ctx.layout.uv(), &["--version"]).await
}
}
/// `uv venv` then `uv pip install` steps for one venv.
async fn venv(ctx: &Ctx, name: &str, python: &str) -> Result<PathBuf, String> {
let uv = ctx.layout.uv();
ctx.run(&uv, &["venv", "--clear", "--python", python, &ctx.layout.venv(name).to_string_lossy()]).await?;
Ok(ctx.layout.venv_python(name))
}
struct WorkerEnvStep;
#[async_trait]
impl Step for WorkerEnvStep {
fn id(&self) -> &'static str { "worker_env" }
fn label(&self) -> &'static str { "음성 워커·두뇌 Python 환경" }
fn size_hint(&self) -> &'static str { "약 1.5GB" }
fn version(&self, layout: &Layout) -> String {
// The requirement files ship with the app: new pins in them install again.
let read = |f: &str| std::fs::read(layout.src.join("voice_worker").join(f)).unwrap_or_default();
let mut h = <sha2::Sha256 as sha2::Digest>::new();
sha2::Digest::update(&mut h, read("requirements.txt"));
sha2::Digest::update(&mut h, read("requirements-brain.txt"));
format!("3.12|{:x}", sha2::Digest::finalize(h))
}
async fn run(&self, ctx: &Ctx) -> Result<(), String> {
let py = venv(ctx, "worker", "3.12").await?;
let reqs = |f: &str| ctx.layout.src.join("voice_worker").join(f).to_string_lossy().into_owned();
ctx.run(&ctx.layout.uv(), &["pip", "install", "--python", &py.to_string_lossy(),
"-r", &reqs("requirements.txt"), "-r", &reqs("requirements-brain.txt")]).await
}
}
struct MeloEnvStep;
#[async_trait]
impl Step for MeloEnvStep {
fn id(&self) -> &'static str { "melo_env" }
fn label(&self) -> &'static str { "음성(MeloTTS) Python 환경" }
fn size_hint(&self) -> &'static str { "약 4GB" }
fn version(&self, _: &Layout) -> String { format!("3.11|{}|{MELO_URL}", TORCH.join(",")) }
async fn run(&self, ctx: &Ctx) -> Result<(), String> {
let uv = ctx.layout.uv();
let py = venv(ctx, "melo", "3.11").await?;
let p = py.to_string_lossy().into_owned();
ctx.run(&uv, &["pip", "install", "--python", &p, TORCH[0], TORCH[1], "--index-url", CU128_INDEX]).await?;
// Later installs must not swap the CUDA build of torch for another.
let pin = ctx.layout.venv("melo").join("torch-pin.txt");
std::fs::write(&pin, TORCH_PIN).map_err(|e| e.to_string())?;
let pin = pin.to_string_lossy().into_owned();
let keep = ["-c", pin.as_str(), "--extra-index-url", CU128_INDEX, "--index-strategy", "unsafe-best-match"];
let mut args = vec!["pip", "install", "--python", &p, MELO_URL];
args.extend(keep);
ctx.run(&uv, &args).await?;
// mecab-python3 (Japanese, folder "MeCab") and python-mecab-ko (folder "mecab") are the same
// folder on Windows: remove the Japanese one first (melo_child stubs its tagger).
ctx.run(&uv, &["pip", "uninstall", "--python", &p, "mecab-python3"]).await?;
remove_package_dir(&ctx.layout.venv("melo"), "mecab");
let mut args = vec!["pip", "install", "--python", &p, "python-mecab-ko==1.3.7", "python-mecab-ko-dic==2.1.1.post2"];
args.extend(keep);
ctx.run(&uv, &args).await?;
// The full `unidic` ships without its dictionary; removed, the fallback unidic_lite is used.
ctx.run(&uv, &["pip", "uninstall", "--python", &p, "unidic"]).await
}
}
fn remove_package_dir(venv: &Path, name: &str) {
let mut sites = vec![venv.join("Lib").join("site-packages")];
if let Ok(rd) = std::fs::read_dir(venv.join("lib")) {
sites.extend(rd.flatten().map(|e| e.path().join("site-packages")));
}
for site in sites {
if let Ok(rd) = std::fs::read_dir(&site) {
for e in rd.flatten() {
if e.file_name().to_string_lossy().eq_ignore_ascii_case(name) && e.path().is_dir() {
let _ = std::fs::remove_dir_all(e.path());
}
}
}
}
}
struct SttModelStep;
#[async_trait]
impl Step for SttModelStep {
fn id(&self) -> &'static str { "stt_model" }
fn label(&self) -> &'static str { "받아 적기 모델(Whisper)" }
fn size_hint(&self) -> &'static str { "약 1.6GB" }
fn version(&self, _: &Layout) -> String { STT_MODEL.into() }
async fn run(&self, ctx: &Ctx) -> Result<(), String> {
let code = format!("from faster_whisper.utils import download_model; print(download_model({STT_MODEL:?}))");
ctx.run(&ctx.layout.venv_python("worker"), &["-c", &code]).await
}
}
struct TtsModelStep;
#[async_trait]
impl Step for TtsModelStep {
fn id(&self) -> &'static str { "tts_model" }
fn label(&self) -> &'static str { "한국어 음성 모델(MeloTTS)" }
fn size_hint(&self) -> &'static str { "약 1GB" }
fn version(&self, _: &Layout) -> String { "KR".into() }
async fn run(&self, ctx: &Ctx) -> Result<(), String> {
// The worker's own MeloTTS child loads the Korean voice (downloading it) and says one
// warm-up sentence, then exits with no input: exit 0 means the voice works.
// MeloTTS's English g2p (g2p_en) fetches NLTK data into the user's home folder on first use;
// fetched here into the data folder's NLTK_DATA instead, where it then finds them.
let nltk = ctx.layout.data.join("models").join("nltk");
std::fs::create_dir_all(&nltk).map_err(|e| e.to_string())?;
// NLTK refuses a data folder other accounts may write (a group-writable umask on Linux).
#[cfg(unix)]
{
use std::os::unix::fs::PermissionsExt;
let _ = std::fs::set_permissions(&nltk, std::fs::Permissions::from_mode(0o755));
}
let code = format!("import nltk\nfor p in ('averaged_perceptron_tagger_eng', 'averaged_perceptron_tagger', 'cmudict'):\n \
assert nltk.download(p, download_dir={:?}, quiet=True), p", nltk.to_string_lossy());
ctx.run(&ctx.layout.venv_python("melo"), &["-c", &code]).await?;
let child = ctx.layout.src.join("voice_worker").join("melo_child.py");
ctx.run(&ctx.layout.venv_python("melo"), &[&child.to_string_lossy(), "--device", "cpu", "--language", "KR"]).await
}
}
struct StrataStep;
#[async_trait]
impl Step for StrataStep {
fn id(&self) -> &'static str { "strata" }
fn label(&self) -> &'static str { "LLM 엔진(Strata)" }
fn size_hint(&self) -> &'static str { "약 1GB" }
fn version(&self, _: &Layout) -> String { "latest".into() }
async fn run(&self, ctx: &Ctx) -> Result<(), String> {
let home = ctx.layout.strata_home();
std::fs::create_dir_all(&home).map_err(|e| e.to_string())?;
if cfg!(windows) {
let script = format!("Set-Location -LiteralPath '{}'; irm {STRATA_INSTALL}.ps1 | iex", home.display());
ctx.run(Path::new("powershell"), &["-NoProfile", "-ExecutionPolicy", "Bypass", "-Command", &script]).await?;
} else {
let script = format!("cd '{}' && curl -fsSL {STRATA_INSTALL}.sh -o install.sh && sh install.sh", home.display());
ctx.run(Path::new("sh"), &["-c", &script]).await?;
}
if !ctx.layout.strata_exe().exists() {
return Err("Strata 설치가 끝났지만 실행 파일이 없습니다".into());
}
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).
pub fn apply_runtime_settings(settings_file: &Path, layout: &Layout) -> Result<(), String> {
let mut raw: serde_json::Map<String, serde_json::Value> = match std::fs::read_to_string(settings_file) {
Ok(t) => serde_json::from_str(t.trim_start_matches('\u{feff}')).map_err(|e| format!("설정 파일을 읽지 못했습니다: {e}"))?,
Err(_) => serde_json::Map::new(),
};
let s = |p: PathBuf| p.to_string_lossy().into_owned();
let worker = raw.entry("voiceWorker").or_insert_with(|| serde_json::json!({}));
let w = worker.as_object_mut().ok_or("voiceWorker가 객체가 아닙니다")?;
w.insert("python".into(), serde_json::json!(s(layout.venv_python("worker"))));
w.insert("cwd".into(), serde_json::json!(s(layout.src.clone())));
w.insert("args".into(), serde_json::json!(["--melo-python", s(layout.venv_python("melo")),
"--history", s(layout.data.join("memory").join("history.sqlite")), "--brain"]));
let mut text = serde_json::to_string_pretty(&serde_json::Value::Object(raw)).unwrap();
text.push('\n');
crate::datadir::write_atomic(settings_file, text.as_bytes()).map_err(|e| e.to_string())
}
/// 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)]
}
#[cfg(test)]
mod tests {
use super::*;
use crate::datadir::temp_dir;
use std::sync::atomic::AtomicU32;
struct Fake {
id: &'static str,
version: String,
runs: Arc<AtomicU32>,
fail: bool,
}
#[async_trait]
impl Step for Fake {
fn id(&self) -> &'static str { self.id }
fn label(&self) -> &'static str { "fake" }
fn size_hint(&self) -> &'static str { "" }
fn version(&self, _: &Layout) -> String { self.version.clone() }
async fn run(&self, ctx: &Ctx) -> Result<(), String> {
self.runs.fetch_add(1, Ordering::SeqCst);
ctx.note("working");
if self.fail { Err("broke".into()) } else { Ok(()) }
}
}
fn layout(tag: &str) -> Layout {
Layout { data: temp_dir(tag), src: PathBuf::from("src") }
}
fn fakes(runs: &[Arc<AtomicU32>], versions: [&str; 3], fail_second: bool) -> Vec<Box<dyn Step>> {
let ids = ["a", "b", "c"];
(0..3).map(|i| Box::new(Fake { id: ids[i], version: versions[i].into(), runs: runs[i].clone(),
fail: fail_second && i == 1 }) as Box<dyn Step>).collect()
}
#[tokio::test]
async fn steps_run_in_order_stop_at_a_failure_and_resume_after_it() {
let l = layout("inst1");
let runs: Vec<Arc<AtomicU32>> = (0..3).map(|_| Arc::new(AtomicU32::new(0))).collect();
let i = Installer::new(l.clone(), fakes(&runs, ["1", "1", "1"], true));
assert!(!i.run_all().await);
let s = i.status();
let states: Vec<_> = s["steps"].as_array().unwrap().iter().map(|x| x["state"].as_str().unwrap().to_owned()).collect();
assert_eq!(states, ["done", "failed", "pending"]);
assert_eq!(s["steps"][1]["note"], "broke");
assert_eq!(runs.iter().map(|r| r.load(Ordering::SeqCst)).collect::<Vec<_>>(), [1, 1, 0]);
// A new run (a fresh app start) skips the finished step and carries on.
let i = Installer::new(l, fakes(&runs, ["1", "1", "1"], false));
assert!(i.run_all().await);
assert_eq!(runs.iter().map(|r| r.load(Ordering::SeqCst)).collect::<Vec<_>>(), [1, 2, 1]);
assert!(i.all_done() && i.status()["done"] == true);
}
#[tokio::test]
async fn a_new_pinned_version_runs_its_step_again() {
let l = layout("inst2");
let runs: Vec<Arc<AtomicU32>> = (0..3).map(|_| Arc::new(AtomicU32::new(0))).collect();
assert!(Installer::new(l.clone(), fakes(&runs, ["1", "1", "1"], false)).run_all().await);
let i = Installer::new(l, fakes(&runs, ["1", "2", "1"], false));
assert!(!i.all_done());
assert!(i.run_all().await);
assert_eq!(runs.iter().map(|r| r.load(Ordering::SeqCst)).collect::<Vec<_>>(), [1, 2, 1]);
}
#[cfg(unix)]
#[tokio::test]
async fn a_command_reports_its_lines_fails_on_exit_codes_and_stops_on_cancel() {
let l = layout("inst3");
let i = Installer::new(l.clone(), vec![]);
let status = Arc::new(Mutex::new(vec![StepStatus { id: "x".into(), label: "".into(), size_hint: "".into(),
state: StepState::Running, bytes: None, note: None }]));
let ctx = Ctx { layout: l.clone(), status: status.clone(), index: 0, cancel: i.cancel.clone() };
ctx.run(Path::new("sh"), &["-c", "echo one; echo two; echo $UV_CACHE_DIR"]).await.unwrap();
let note = status.lock().unwrap()[0].note.clone().unwrap();
assert!(note.ends_with("cache/uv") && note.starts_with(&l.data.to_string_lossy().to_string()), "{note}");
let err = ctx.run(Path::new("sh"), &["-c", "echo nope; exit 3"]).await.unwrap_err();
assert!(err.contains("nope"), "{err}");
let cancel = ctx.cancel.clone();
tokio::spawn(async move {
tokio::time::sleep(std::time::Duration::from_millis(300)).await;
cancel.store(true, Ordering::SeqCst);
});
let t = std::time::Instant::now();
assert_eq!(ctx.run(Path::new("sh"), &["-c", "sleep 30"]).await.unwrap_err(), "cancelled");
assert!(t.elapsed() < std::time::Duration::from_secs(5));
}
#[test]
fn the_settings_point_at_the_installed_runtime_and_keep_the_rest() {
let l = layout("inst5");
let f = l.data.join("config").join("settings.json");
std::fs::create_dir_all(f.parent().unwrap()).unwrap();
std::fs::write(&f, r#"{"call": {"earcon": false}, "voiceWorker": {"python": "old"}}"#).unwrap();
apply_runtime_settings(&f, &l).unwrap();
let s = crate::settings::load_settings(&f).unwrap();
assert_eq!(std::path::Path::new(&s.voice_worker.python), l.venv_python("worker"));
assert_eq!(s.voice_worker.args[0..2], ["--melo-python".to_string(), l.venv_python("melo").to_string_lossy().into_owned()]);
assert!(s.voice_worker.args.contains(&"--brain".to_string()));
assert!(!s.call.earcon, "other settings are kept");
}
#[test]
fn everything_goes_inside_the_data_folder() {
let l = layout("inst4");
for (k, v) in l.env() {
if v.contains('/') || v.contains('\\') {
assert!(v.starts_with(&l.data.to_string_lossy().to_string()), "{k}={v}");
}
}
assert!(l.uv().starts_with(&l.data) && l.venv_python("worker").starts_with(&l.data));
}
}

View File

@@ -10,8 +10,10 @@ pub mod dashboard;
pub mod datadir;
pub mod discord;
pub mod discord_setup;
pub mod download;
pub mod earcon;
pub mod frames;
pub mod install;
pub mod logs;
pub mod playback;
pub mod policy;

View File

@@ -52,6 +52,7 @@ pub fn tab_of(category: &str) -> &'static str {
"browser" => "browser",
"capture" => "capture",
"game" => "game",
"install" => "install",
_ => "app",
}
}

View File

@@ -40,7 +40,13 @@ pub async fn start_services(data_dir: &Path) -> Result<Services, Box<dyn std::er
};
let w = &settings.voice_worker;
let worker_process = WorkerProcess::new(WorkerProcessOptions::new(&w.python, &w.cwd, w.args.clone()))?;
let mut wopts = WorkerProcessOptions::new(&w.python, &w.cwd, w.args.clone());
// With the installed runtime, the worker's models, caches and temp files stay in the data folder.
let layout = crate::install::Layout { data: data_dir.to_path_buf(), src: w.cwd.clone() };
if crate::install::Installer::new(layout.clone(), crate::install::steps()).all_done() {
wopts.env.extend(layout.env());
}
let worker_process = WorkerProcess::new(wopts)?;
let mut process_events = worker_process.subscribe();
worker_process.start();
let mut opts = WorkerClientOptions::new(worker_process.url(), worker_process.token.clone());

View File

@@ -429,9 +429,41 @@ async function wizard(status) {
p.driver && !p.driverOk ? h("p", {}, "NVIDIA 드라이버를 최신으로 올려 주세요: ", h("a", { href: "https://www.nvidia.com/drivers", target: "_blank" }, "nvidia.com/drivers")) : null,
nav(true, () => go(2))];
},
async () => [h("h2", {}, "받을 모델"),
h("p", {}, "대화 모델 Qwen3.6-35B-A3B(약 23GB)와 받아 적기(Whisper)·음성(MeloTTS) 모델을 받습니다. 고를 것은 없고, 설치가 끝나면 이 PC에 맞는 설정을 스스로 정합니다."),
h("p", { class: "muted small" }, "자동 설치는 다음 업데이트에서 이 단계에 들어옵니다."), nav(true, () => go(3))],
async () => {
// The install runs in the app; this step shows it and polls while it is on screen.
const list = h("table");
const btn = h("button", { class: "btn" });
const next = nav(true, () => go(3));
const nextBtn = next.lastChild;
const SIZE = (b) => (b >= 1e9 ? (b / 1e9).toFixed(1) + " GB" : (b / 1e6).toFixed(0) + " MB");
const STEP = { pending: ["대기", ""], running: ["설치 중", "warn"], done: ["완료", "ok"], failed: ["실패", "bad"] };
const my = wgen;
async function poll() {
if (my !== wgen) return;
let st;
try { st = await api("install_status"); } catch (e) { return fail(e); }
if (my !== wgen) return;
list.replaceChildren(h("tbody", {}, st.steps.map((x) => {
const [label, cls] = STEP[x.state] ?? [x.state, ""];
const bytes = x.bytes && x.state === "running" ? ` ${SIZE(x.bytes[0])}${x.bytes[1] ? " / " + SIZE(x.bytes[1]) : ""}` : "";
return h("tr", {}, h("td", {}, x.label, h("div", { class: "small muted" }, x.sizeHint)),
h("td", {}, h("span", { class: "badge " + cls }, label + bytes)),
h("td", { class: "small muted", style: "max-width:320px;word-break:break-all" }, x.state === "done" ? "" : (x.note ?? "")));
})));
btn.textContent = st.running ? "취소" : st.done ? "설치됨" : st.steps.some((x) => x.state === "failed") ? "다시 시도" : "설치 시작";
btn.disabled = st.done && !st.running;
btn.onclick = async () => {
try { await api(st.running ? "install_cancel" : "install_start"); } catch (e) { fail(e); }
poll();
};
nextBtn.disabled = !st.done;
if (st.running) setTimeout(poll, 1000);
}
poll();
return [h("h2", {}, "런타임과 모델 설치"),
h("p", {}, "음성 워커와 두뇌를 돌릴 Python 환경, 받아 적기(Whisper)·음성(MeloTTS) 모델, LLM 엔진(Strata)을 데이터 폴더 안에 받습니다. 끊겨도 다음에 이어서 받습니다. 대화 모델 Qwen3.6-35B-A3B(약 23GB)는 Strata를 처음 켤 때 받습니다."),
list, h("div", { class: "row", style: "margin-top:12px" }, btn), next];
},
async () => {
const input = h("input", { type: "password", placeholder: "디스코드 봇 토큰", autocomplete: "off" });
const out = h("div");

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,9 @@
# The v2 brain (--brain): the jarvis reply engine, its tools and the MCP client, on top of
# requirements.txt in this folder. Checked in a fresh Python 3.12 venv (2026-11-12): the worker,
# brain, engine and tool tests pass with exactly these two files. The repository's requirements.txt
# is v1's desktop app (PyQt, chatterbox, ...) and is not needed here.
requests==2.32.3
beautifulsoup4==4.12.3
html2text==2024.2.26
mcp==1.28.0
rapidfuzz==3.6.1