J.A.R.V.I.S-rust/resources/commands/scheduler/add_daily.lua

63 lines
1.9 KiB
Lua
Raw Permalink Normal View History

feat(scheduler): IMBA-5 proactive scheduler — reminders, daily briefings, intervals Background thread that wakes J.A.R.V.I.S. on a schedule to speak reminders. Nothing else competes here on desktop — Алиса/Сири are reactive-only. Core (crates/jarvis-core/src/scheduler.rs) - Schedule::{Daily{h,m}, Interval{secs}, Once{at}} with Schedule::parse for "daily HH:MM" / "at HH:MM" / "every N minutes|hours" / "in N minutes|hours". Russian units (час/часа/часов/минут/секунд) also accepted. - ScheduledTask {id, name, schedule, action, last_fired, enabled, created_at}. Action::Speak{text} | Action::Lua{script_path}. - JSON persistence at <APP_CONFIG_DIR>/schedule.json, atomic write-through. - add/remove/clear/list/find; mark_fired auto-deletes Once tasks. - start_background() spawns a 30-second tick thread (idempotent). Each tick calls due_tasks(), fires Action via tts::speak_default (after voices::play_reply "ahem" cue) or Lua engine. - 7 unit tests (all passing). Lua API (crates/jarvis-core/src/lua/api/scheduler.rs) - jarvis.scheduler.add({name, schedule, action={type, text|script_path}}) - jarvis.scheduler.{list, count, remove(id), clear}. - Tasks come back as {id, name, schedule_human, action, enabled, last_fired}. Wire-up (crates/jarvis-app/src/main.rs) - scheduler::init() + scheduler::start_background() after profiles::init. - Tasks survive restarts via schedule.json. Voice commands (resources/commands/scheduler/, 6 ids) - scheduler.add_reminder "напомни через 5 минут выключить кофеварку" - scheduler.add_at "напомни в 18:00 забрать ребёнка" - scheduler.add_recurring "каждые 2 часа напоминай попить воды" - scheduler.add_daily "каждый день в 9:00 делай briefing" - scheduler.list "что у меня запланировано" - scheduler.clear "очисти расписание" Russian-aware parsers (час/часа/часов, минут/минуту/минуты) live inside the Lua packs — easy to extend without touching Rust. Tests: 31/31 jarvis-core unit tests pass (24 prior + 7 scheduler). Build: cargo build --release -p jarvis-app and -p jarvis-gui both green.
2026-05-15 15:43:04 +03:00
-- "каждый день в 9:00 делай briefing" / "каждое утро в 8 напоминай зарядку"
local phrase = (jarvis.context.phrase or ""):lower()
local body = jarvis.text.strip_trigger(phrase, {
"каждое утро в",
"каждый день в",
"ежедневно в",
"по утрам в",
"every day at",
"daily at",
"щодня о",
"кожен день о",
})
body = body:gsub("^[%s,:%.]+", ""):gsub("%s+$", "")
-- Parse "HH:MM <text>" or "HH <text>"
local h, m, rest = body:match("^(%d%d?)%s*[:%-]%s*(%d%d?)%s*(.*)$")
if not h then
h, rest = body:match("^(%d%d?)%s*(.*)$")
m = "00"
end
if not h then
jarvis.speak("Не понял время.")
jarvis.audio.play_error()
return { chain = false }
end
local hn = tonumber(h)
local mn = tonumber(m) or 0
if hn < 0 or hn > 23 or mn < 0 or mn > 59 then
jarvis.speak("Время вне диапазона.")
jarvis.audio.play_error()
return { chain = false }
end
local schedule = string.format("daily %02d:%02d", hn, mn)
local text_body = (rest or ""):gsub("^напоминай%s+", "")
:gsub("^напомни%s+", "")
:gsub("^делай%s+", "")
:gsub("^[%s,:%.]+", "")
:gsub("%s+$", "")
if text_body == "" then text_body = "Доброе утро." end
local ok, err = pcall(function()
jarvis.scheduler.add({
name = "Daily",
schedule = schedule,
action = { type = "speak", text = text_body }
})
end)
if not ok then
jarvis.log("warn", "scheduler.add: " .. tostring(err))
jarvis.speak("Не получилось.")
jarvis.audio.play_error()
return { chain = false }
end
jarvis.speak(string.format("Каждый день в %02d:%02d.", hn, mn))
jarvis.audio.play_ok()
return { chain = false }