feat(app): start Strata from the data folder and point the brain at it

M5 step 4, second part. The services start the LLM first: the installed
Strata with the M0 kit's model and normal placement (models in
models/llm, parallel 1, or 2 when a chat channel answers every message,
pictures off, --restart), wait until /v1/models lists the model, and stop
it last. The first start downloads the model; the dashboard shows
Strata's last line and percentage, and stop also cancels a start (the
server is cleared). llm.url uses a server the app does not start.

On every start the app writes config/brain.json (Strata's /v1, the
listed model id, memory/jarvis.db) and hands it to the worker as
JARVIS_CONFIG_PATH. Loading a config with its own db_path no longer
creates ~/.local/share/jarvis.

service_start/service_restart run in the background. Settings gain
llm.context and llm.port (model screen) and llm.url (file only).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
javis-bot
2026-11-12 17:45:38 +09:00
parent 1a6d6447f6
commit 5c510bb602
16 changed files with 741 additions and 62 deletions

View File

@@ -150,9 +150,21 @@ pub struct Ctx {
status: Arc<Mutex<Vec<StepStatus>>>,
index: usize,
pub cancel: Arc<AtomicBool>,
/// The log tab its command lines go to.
tab: &'static str,
}
impl Ctx {
/// A context for commands outside the install (Strata's start and stop, `strata.rs`): their
/// lines go to log tab `tab`, the last one is `last_note`.
pub fn standalone(layout: Layout, tab: &'static str, cancel: Arc<AtomicBool>) -> Self {
let status = vec![StepStatus { id: tab.into(), label: String::new(), size_hint: String::new(),
state: StepState::Running, bytes: None, note: None }];
Self { layout, status: Arc::new(Mutex::new(status)), index: 0, cancel, tab }
}
pub fn last_note(&self) -> Option<String> {
self.status.lock().unwrap()[self.index].note.clone()
}
pub fn note(&self, line: &str) {
let line: String = line.chars().take(300).collect();
self.status.lock().unwrap()[self.index].note = Some(line);
@@ -183,12 +195,12 @@ impl Ctx {
cmd.process_group(0);
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(""));
crate::info_log!(self.tab, "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);
let (last, status, index, tab) = (last.clone(), self.status.clone(), self.index, self.tab);
tokio::spawn(async move {
let mut lines = BufReader::new(r).lines();
while let Ok(Some(l)) = lines.next_line().await {
@@ -197,7 +209,7 @@ impl Ctx {
continue;
}
if let Some(hub) = crate::logs::installed() {
hub.push(crate::logs::Level::Info, "install", &l);
hub.push(crate::logs::Level::Info, tab, &l);
}
status.lock().unwrap()[index].note = Some(l.chars().take(300).collect());
*last.lock().unwrap() = l;
@@ -329,7 +341,8 @@ impl Installer {
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 ctx = Ctx { layout: self.layout.clone(), status: self.status.clone(), index: i, cancel: self.cancel.clone(),
tab: "install" };
let result = step.run(&ctx).await;
let mut st = self.status.lock().unwrap();
match result {
@@ -657,7 +670,7 @@ mod tests {
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() };
let ctx = Ctx { layout: l.clone(), status: status.clone(), index: 0, cancel: i.cancel.clone(), tab: "install" };
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}");
@@ -680,7 +693,7 @@ mod tests {
let status = Arc::new(Mutex::new(vec![StepStatus { id: "x".into(), label: "".into(), size_hint: "".into(),
state: StepState::Running, bytes: None, note: None }]));
let cancel = Arc::new(AtomicBool::new(false));
let ctx = Ctx { layout: l.clone(), status, index: 0, cancel: cancel.clone() };
let ctx = Ctx { layout: l.clone(), status, index: 0, cancel: cancel.clone(), tab: "install" };
let pidfile = l.data.join("child.pid");
let script = format!("sleep 60 & echo $! > {}; wait", pidfile.display());
let c2 = cancel.clone();
@@ -709,7 +722,7 @@ mod tests {
std::fs::create_dir_all(&dir).unwrap();
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: Arc::new(AtomicBool::new(false)) };
let ctx = Ctx { layout: l.clone(), status: status.clone(), index: 0, cancel: Arc::new(AtomicBool::new(false)), tab: "install" };
ctx.run_in(Path::new("sh"), &["-c", "touch made && pwd"], Some(&dir)).await.unwrap();
assert!(dir.join("made").exists());
}