feat: TTS backend abstraction + 4 'imba' features + Lua packs

Big push driven by user feedback ("делай имбу") and web research on what
voice assistants need to be the ideal:

TTS backend abstraction (P0.1)
  - new module crates/jarvis-core/src/tts/{mod,sapi,piper,silero}.rs
  - TtsBackend trait with SapiBackend (current PowerShell), PiperBackend
    (rhasspy/piper, neural quality), SileroBackend (python subprocess)
  - JARVIS_TTS env var picks (sapi|piper|silero). Auto-detect Piper if
    binary + voice present in tools/piper/. Falls back to SAPI on missing.
  - SpeakOpts {lang, detached, raw} replaces ad-hoc args. text_utils
    sanitiser applied unless raw=true.
  - llm_fallback + lua/api/tts both routed through tts::backend().
  - tools/piper/install.ps1 downloads piper.exe + ru_RU-irina-medium.onnx
    from rhasspy releases + huggingface. Smoke-test included.
  - tools/silero/silero_tts.py helper (PyTorch); rust spawns it as subprocess.

IMBA-1 Agentic LLM router
  - crates/jarvis-app/src/llm_router.rs
  - When fuzzy/intent matcher fails, LLM picks the closest command from the
    full registry. Returns JSON {command_id, confidence, reason}.
  - Threshold-gated re-dispatch via substitute phrase. JARVIS_LLM_ROUTER=1
    enables; JARVIS_LLM_ROUTER_THRESHOLD overrides 0.55 default.
  - Inserted in app.rs::execute_command between "no match" and existing
    llm_fallback chat fallback.

IMBA-2 Long-term memory
  - crates/jarvis-core/src/long_term_memory.rs — JSON store at
    APP_CONFIG_DIR/long_term_memory.json. Atomic write-through.
  - remember/recall/search/forget/all/build_context API.
  - Lua bindings: jarvis.memory.* (5 functions).
  - llm_fallback auto-injects relevant facts (substring search of prompt)
    into system message before LLM call.
  - Pack resources/commands/memory_pack/ with 4 commands: remember, recall,
    forget, list.

IMBA-3 Profile switching (work/game/sleep/driving/default)
  - crates/jarvis-core/src/profiles.rs — JSON profiles at APP_CONFIG_DIR/profiles/
    Auto-seeds 5 defaults on first run with personality + allow/deny lists +
    greetings + emoji icons.
  - active_profile.txt persists choice across restart.
  - Lua bindings: jarvis.profile.{active,set,list,allows,active_name}.
  - llm_fallback prepends profile personality to system prompt.
  - Pack resources/commands/profile_switch/ with 6 voice triggers.

IMBA-4 Multimodal screenshot + vision LLM
  - crates/jarvis-core/src/lua/api/vision.rs — gated on HTTP sandbox.
  - jarvis.vision.screenshot() captures via PowerShell System.Drawing.
  - jarvis.vision.describe(prompt?) sends base64 PNG to Groq vision model
    (default llama-3.2-11b-vision-preview, override via GROQ_VISION_MODEL).
  - Pack resources/commands/vision/ with 2 commands: describe + read_error.

P0.2 Continuous conversation grace window
  - config::CONVERSATION_GRACE_MS = 30_000.
  - app.rs: after command result, if grace_ms > 0 keep listening WITHOUT
    re-wake for the grace duration. Existing CMS_WAIT_DELAY back-dated so
    the existing timeout fires at start + grace_ms.

Tests: 24/24 jarvis-core unit tests pass (including 5 text_utils).
Build: cargo build --release -p jarvis-app and -p jarvis-gui both succeed
on Windows MSVC (VS 2026 Enterprise vcvars64).

Notes for setup:
  - Piper voice install: pwsh tools/piper/install.ps1 (downloads ~90 MB).
  - GROQ_TOKEN needed for IMBA-1 (router) and IMBA-4 (vision).
  - All features are opt-in via env vars or auto-detect; existing SAPI +
    fuzzy match path remains the default.
This commit is contained in:
Bossiara13 2026-05-15 15:32:44 +03:00
parent 80b54af1ee
commit 0b1f1d4480
34 changed files with 2304 additions and 90 deletions

View file

@ -0,0 +1,59 @@
# IMBA-2: Long-term memory — remember/recall/forget arbitrary facts.
[[commands]]
id = "memory.remember"
type = "lua"
script = "remember.lua"
sandbox = "standard"
timeout = 3000
[commands.phrases]
ru = [
"запомни обо мне", "запомни что",
"помни что", "запомни это",
"запомни про меня",
]
en = ["remember that", "remember about me", "memorize"]
ua = ["запам'ятай що", "запам'ятай про мене"]
[[commands]]
id = "memory.recall"
type = "lua"
script = "recall.lua"
sandbox = "standard"
timeout = 3000
[commands.phrases]
ru = [
"что ты помнишь о", "что ты знаешь обо мне",
"что помнишь про", "вспомни",
]
en = ["what do you remember about", "recall"]
ua = ["що ти пам'ятаєш про"]
[[commands]]
id = "memory.forget"
type = "lua"
script = "forget.lua"
sandbox = "standard"
timeout = 3000
[commands.phrases]
ru = ["забудь про", "забудь что", "забудь обо мне"]
en = ["forget about", "forget that"]
ua = ["забудь про"]
[[commands]]
id = "memory.list"
type = "lua"
script = "list.lua"
sandbox = "minimal"
timeout = 3000
[commands.phrases]
ru = ["что ты помнишь", "что ты знаешь обо мне", "покажи память"]
en = ["what do you remember", "list memory", "show memory"]
ua = ["що ти пам'ятаєш"]

View file

@ -0,0 +1,36 @@
local phrase = (jarvis.context.phrase or ""):lower()
local key = jarvis.text.strip_trigger(phrase, {
"забудь про",
"забудь что",
"забудь обо мне",
"forget about",
"forget that",
"забудь про",
})
key = key:gsub("^[%s,:%.]+", ""):gsub("%s+$", "")
if key == "" then
jarvis.speak("Что именно забыть?")
jarvis.audio.play_error()
return { chain = false }
end
local removed = jarvis.memory.forget(key)
if removed then
jarvis.speak("Забыл про " .. key .. ".")
jarvis.audio.play_ok()
else
-- try substring search and remove first hit
local hits = jarvis.memory.search(key, 1)
if #hits > 0 then
jarvis.memory.forget(hits[1].key)
jarvis.speak("Забыл про " .. hits[1].key .. ".")
jarvis.audio.play_ok()
else
jarvis.speak("Я и не помнил про " .. key .. ".")
jarvis.audio.play_not_found()
end
end
return { chain = false }

View file

@ -0,0 +1,19 @@
local recs = jarvis.memory.all()
if #recs == 0 then
jarvis.speak("Я пока ничего о вас не запомнил.")
jarvis.audio.play_ok()
return { chain = false }
end
local count = #recs
local sample = math.min(count, 5)
local line = string.format("Помню %d фактов. Первые: ", count)
for i = 1, sample do
line = line .. recs[i].key
if i < sample then line = line .. ", " end
end
line = line .. "."
jarvis.speak(line)
jarvis.audio.play_ok()
return { chain = false }

View file

@ -0,0 +1,52 @@
local phrase = (jarvis.context.phrase or ""):lower()
local query = jarvis.text.strip_trigger(phrase, {
"что ты помнишь о",
"что ты помнишь про",
"что ты знаешь обо мне",
"что помнишь про",
"вспомни",
"what do you remember about",
"recall",
"що ти пам'ятаєш про",
})
query = query:gsub("^[%s,:%.]+", ""):gsub("%s+$", "")
if query == "" then
-- show top-3 most recent
local recs = jarvis.memory.all()
if #recs == 0 then
jarvis.speak("Ничего пока не помню.")
jarvis.audio.play_ok()
return { chain = false }
end
local line = "Я помню: "
for i = 1, math.min(3, #recs) do
line = line .. recs[i].key .. "" .. recs[i].value .. ". "
end
jarvis.speak(line)
jarvis.audio.play_ok()
return { chain = false }
end
-- substring search
local hits = jarvis.memory.search(query, 3)
if #hits == 0 then
jarvis.speak("Ничего не нашёл про " .. query .. ".")
jarvis.audio.play_not_found()
return { chain = false }
end
local line = ""
if #hits == 1 then
line = hits[1].value
else
for i, h in ipairs(hits) do
line = line .. h.key .. ": " .. h.value
if i < #hits then line = line .. ". " end
end
end
jarvis.speak(line)
jarvis.audio.play_ok()
return { chain = false }

View file

@ -0,0 +1,55 @@
local phrase = (jarvis.context.phrase or ""):lower()
local body = jarvis.text.strip_trigger(phrase, {
"запомни обо мне что",
"запомни обо мне",
"запомни что",
"помни что",
"запомни это",
"запомни про меня",
"запомни",
"remember that",
"remember about me",
"memorize",
"запам'ятай що",
"запам'ятай про мене",
})
body = body:gsub("^[%s,:%.]+", ""):gsub("%s+$", "")
if body == "" then
jarvis.speak("Что именно запомнить?")
jarvis.audio.play_error()
return { chain = false }
end
-- Heuristic: derive a key. Look for "что X = Y" / "что у меня X" / etc.
-- For now: first 3-5 meaningful words become the key.
local key = body
local _, after_eq = body:find("=", 1, true)
if after_eq then
key = body:sub(1, after_eq - 1):gsub("%s+$", "")
body = body:sub(after_eq + 1):gsub("^%s+", "")
end
-- truncate key to first 6 words
local words = {}
for w in key:gmatch("%S+") do
table.insert(words, w)
if #words >= 6 then break end
end
key = table.concat(words, " ")
local ok, err = pcall(function()
jarvis.memory.remember(key, body)
end)
if not ok then
jarvis.log("warn", "memory.remember failed: " .. tostring(err))
jarvis.speak("Не удалось запомнить.")
jarvis.audio.play_error()
return { chain = false }
end
jarvis.speak("Запомнил.")
jarvis.audio.play_ok()
return { chain = false }

View file

@ -0,0 +1,78 @@
# IMBA-3: Profile switching — work / game / sleep / driving / default.
[[commands]]
id = "profile.work"
type = "lua"
script = "switch.lua"
sandbox = "standard"
timeout = 3000
[commands.phrases]
ru = ["режим работа", "включи режим работы", "рабочий режим", "переключись в работу"]
en = ["work mode", "switch to work mode", "enable work mode"]
ua = ["робочий режим", "режим роботи"]
[[commands]]
id = "profile.game"
type = "lua"
script = "switch.lua"
sandbox = "standard"
timeout = 3000
[commands.phrases]
ru = ["режим игра", "игровой режим", "включи игровой режим", "переключись в игры"]
en = ["game mode", "gaming mode", "switch to game"]
ua = ["ігровий режим", "режим гри"]
[[commands]]
id = "profile.sleep"
type = "lua"
script = "switch.lua"
sandbox = "standard"
timeout = 3000
[commands.phrases]
ru = ["режим сон", "ночной режим", "режим тишины", "иди спать", "выключи всё"]
en = ["sleep mode", "night mode", "quiet mode"]
ua = ["нічний режим", "режим сну"]
[[commands]]
id = "profile.driving"
type = "lua"
script = "switch.lua"
sandbox = "standard"
timeout = 3000
[commands.phrases]
ru = ["режим за рулём", "режим вождения", "я за рулём", "поехали"]
en = ["driving mode", "in the car"]
ua = ["режим водіння"]
[[commands]]
id = "profile.default"
type = "lua"
script = "switch.lua"
sandbox = "standard"
timeout = 3000
[commands.phrases]
ru = ["обычный режим", "режим по умолчанию", "сбрось режим", "вернись в обычный"]
en = ["normal mode", "default mode", "reset mode"]
ua = ["звичайний режим"]
[[commands]]
id = "profile.what"
type = "lua"
script = "what.lua"
sandbox = "minimal"
timeout = 2000
[commands.phrases]
ru = ["какой сейчас режим", "в каком ты режиме", "текущий режим", "какой режим"]
en = ["what mode", "current mode", "what profile"]
ua = ["який зараз режим"]

View file

@ -0,0 +1,27 @@
local cmd_id = jarvis.context.command_id or ""
-- map command id suffix → profile name
local target = cmd_id:gsub("^profile%.", "")
if target == "" then
jarvis.audio.play_error()
return { chain = false }
end
local ok, err = pcall(function()
local p = jarvis.profile.set(target)
if p and p.greeting and p.greeting ~= "" then
jarvis.speak(p.greeting)
else
local icon = (p and p.icon) or ""
jarvis.speak(string.format("Режим %s %s.", target, icon))
end
end)
if not ok then
jarvis.log("warn", "profile switch failed: " .. tostring(err))
jarvis.speak("Не удалось переключить режим.")
jarvis.audio.play_error()
return { chain = false }
end
jarvis.audio.play_ok()
return { chain = true }

View file

@ -0,0 +1,13 @@
local p = jarvis.profile.active()
local icon = (p and p.icon) or ""
local name = (p and p.name) or "default"
local desc = (p and p.description) or ""
local msg = string.format("Сейчас %s %s.", name, icon)
if desc ~= "" then
msg = msg .. " " .. desc
end
jarvis.speak(msg)
jarvis.audio.play_ok()
return { chain = false }

View file

@ -0,0 +1,30 @@
# IMBA-4: Multimodal — screenshot + vision LLM.
[[commands]]
id = "vision.describe"
type = "lua"
script = "describe.lua"
sandbox = "full"
timeout = 30000
[commands.phrases]
ru = [
"что на экране", "опиши экран",
"посмотри на экран", "что у меня на экране",
"посмотри на мой экран", "глянь на экран",
]
en = ["what's on screen", "describe screen", "look at my screen"]
ua = ["що на екрані", "поглянь на екран"]
[[commands]]
id = "vision.read_error"
type = "lua"
script = "read_error.lua"
sandbox = "full"
timeout = 30000
[commands.phrases]
ru = ["прочитай ошибку", "что за ошибка", "помоги с ошибкой"]
en = ["read the error", "what's the error", "help with the error"]
ua = ["прочитай помилку", "що за помилка"]

View file

@ -0,0 +1,13 @@
jarvis.speak("Сейчас посмотрю.")
local desc = jarvis.vision.describe("Опиши коротко (1-3 предложения) что сейчас на экране. По-русски.")
if not desc or desc == "" then
jarvis.speak("Не удалось разобрать экран. Проверь GROQ_TOKEN.")
jarvis.audio.play_error()
return { chain = false }
end
jarvis.speak(desc)
jarvis.audio.play_ok()
return { chain = false }

View file

@ -0,0 +1,18 @@
jarvis.speak("Смотрю на ошибку.")
local prompt = [[Найди на экране текст ошибки (сообщение об ошибке, stack trace, диалог об исключении).
Прочитай ключевое сообщение и одним коротким предложением подскажи возможную причину.
Если ошибки нет скажи "ошибок не вижу".
Отвечай по-русски. 1-3 предложения максимум.]]
local desc = jarvis.vision.describe(prompt)
if not desc or desc == "" then
jarvis.speak("Не получилось прочитать.")
jarvis.audio.play_error()
return { chain = false }
end
jarvis.speak(desc)
jarvis.audio.play_ok()
return { chain = false }