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

@@ -9,7 +9,7 @@ use std::sync::{Arc, Mutex};
use serde_json::{json, Map, Value};
use crate::control::{Controller, ServicesHost};
use crate::control::{Controller, ServicesHost, State};
use crate::datadir::{free_bytes, DataDir, RECOMMENDED_FREE_BYTES};
use crate::logs::{Level, LogHub};
use crate::secrets::{masked, Secrets, DISCORD_TOKEN};
@@ -89,7 +89,7 @@ impl AdminApi {
fn controller(&self) -> Result<Arc<Controller>, String> {
let dir = self.dir()?;
let mut c = self.controller.lock().unwrap();
Ok(c.get_or_insert_with(|| Controller::new(ServicesHost { data_dir: dir.path().to_path_buf() })).clone())
Ok(c.get_or_insert_with(|| Controller::new(ServicesHost::new(dir.path().to_path_buf()))).clone())
}
pub async fn call(&self, command: &str, args: Value) -> Result<Value, String> {
@@ -193,9 +193,21 @@ impl AdminApi {
crate::settings_edit::apply(&self.dir()?.settings_file(), &changes).map_err(|e| e.0)?;
Ok(json!({"saved": changes.len(), "restartNeeded": self.controller()?.state() == crate::control::State::Running}))
}
"service_start" => self.controller()?.start().await.map(|_| json!({"ok": true})),
// Starting can take long (the LLM's first start downloads the model), so it runs in the
// background and the dashboard shows how it goes; stop also cancels a start.
"service_start" | "service_restart" => {
let c = self.controller()?;
let restart = command == "service_restart";
let ok = if restart { c.state() == State::Running } else { matches!(c.state(), State::Stopped | State::Failed) };
if !ok {
return Err(format!("cannot {} while {:?}", if restart { "restart" } else { "start" }, c.state()).to_lowercase());
}
tokio::spawn(async move {
let _ = if restart { c.restart().await } else { c.start().await };
});
Ok(json!({"ok": true}))
}
"service_stop" => self.controller()?.stop().await.map(|_| json!({"ok": true})),
"service_restart" => self.controller()?.restart().await.map(|_| json!({"ok": true})),
"dashboard" => Ok(self.controller()?.snapshot().await),
"logs_query" => {
let tab = args.get("tab").and_then(Value::as_str).filter(|t| !t.is_empty() && *t != "all");