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

@@ -70,6 +70,16 @@ pub struct WorkerSettings {
pub args: Vec<String>,
}
/// The LLM (admin.spec.md, "LLM"): the app starts Strata on `port`, or uses a server already
/// running at `url` (an OpenAI-compatible `/v1` address) and starts nothing.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct LlmSettings {
pub url: Option<String>,
pub port: u16,
/// Tokens the model keeps at once (each request's share).
pub context: u32,
}
#[derive(Debug, Clone, PartialEq)]
pub struct Settings {
pub discord: DiscordSettings,
@@ -84,6 +94,7 @@ pub struct Settings {
/// The voice worker's memory settings (voice_worker.spec.md, "Memory settings"), sent in its
/// `hello`; the worker validates them, the settings screens check them first (admin.spec.md).
pub memory: Map<String, Value>,
pub llm: LlmSettings,
}
#[derive(Debug, Clone, PartialEq, Eq)]
@@ -126,6 +137,7 @@ impl Default for Settings {
chat_wake_words: None,
response: PolicySettings::default(),
memory: Map::new(),
llm: LlmSettings { url: None, port: 8080, context: 32768 },
}
}
}
@@ -399,9 +411,34 @@ pub fn parse_settings(raw: &Value) -> Result<Settings, SettingsError> {
Some(Value::Object(m)) => m.clone(),
Some(_) => return err("memory must be an object"),
},
llm: parse_llm(raw, &d.llm)?,
})
}
fn parse_llm(raw: &Map<String, Value>, d: &LlmSettings) -> Result<LlmSettings, SettingsError> {
let l = section(raw, "llm")?;
let url = match l.and_then(|m| m.get("url")) {
None | Some(Value::Null) => None,
Some(Value::String(s)) if s.starts_with("http://") || s.starts_with("https://") => Some(s.trim_end_matches('/').to_owned()),
Some(_) => return err("llm.url must be an http(s) address or null"),
};
let port = match l.and_then(|m| m.get("port")) {
None => d.port,
Some(v) => match v.as_u64() {
Some(n @ 1024..=65535) => n as u16,
_ => return err("llm.port must be an integer 1024-65535"),
},
};
let context = match l.and_then(|m| m.get("context")) {
None => d.context,
Some(v) => match v.as_u64() {
Some(n @ 4096..=262144) => n as u32,
_ => return err("llm.context must be an integer 4096-262144"),
},
};
Ok(LlmSettings { url, port, context })
}
/// Read and validate the settings file. A missing file means all defaults.
pub fn load_settings(path: &Path) -> Result<Settings, SettingsError> {
let text = match std::fs::read_to_string(path) {