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.
This commit is contained in:
Bossiara13 2026-05-15 15:43:04 +03:00
parent 0b1f1d4480
commit 12b1ed4ccb
13 changed files with 1038 additions and 1 deletions

View file

@ -0,0 +1,58 @@
-- "напомни в 18:00 забрать ребёнка"
local phrase = (jarvis.context.phrase or ""):lower()
local body = jarvis.text.strip_trigger(phrase, {
"напомни сегодня в",
"напомни в",
"разбуди в",
"поставь напоминалку на",
"remind me at",
"wake me at",
"нагадай о",
"розбуди о",
})
body = body:gsub("^[%s,:%.]+", ""):gsub("%s+$", "")
-- Parse "HH:MM <text>" or "HH MM <text>"
local h, m, rest = body:match("^(%d%d?)%s*[:%-%s]%s*(%d%d?)%s*(.*)$")
if not h then
h, rest = body:match("^(%d%d?)%s*(.*)$")
if not h then
jarvis.speak("Не понял время.")
jarvis.audio.play_error()
return { chain = false }
end
m = "00"
end
m = m or "00"
local hn = tonumber(h)
local mn = tonumber(m)
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("at %02d:%02d", hn, mn)
local text_body = (rest or ""):gsub("^[%s,:%.]+", ""):gsub("%s+$", "")
if text_body == "" then text_body = "Напоминание." end
local ok, err = pcall(function()
jarvis.scheduler.add({
name = "Reminder",
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 }

View file

@ -0,0 +1,62 @@
-- "каждый день в 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 }

View file

@ -0,0 +1,74 @@
-- "каждые 2 часа напоминай попить воды" / "каждый час напоминай размяться"
local phrase = (jarvis.context.phrase or ""):lower()
local body = jarvis.text.strip_trigger(phrase, {
"напоминай каждые",
"напоминай каждый",
"каждые",
"каждый час",
"remind me every",
"every",
"кожні",
"нагадуй кожні",
})
body = body:gsub("^[%s,:%.]+", ""):gsub("%s+$", "")
-- Parse "<N> <unit> <verb> <text>" or "час <text>" (implicit 1)
local n_str, unit, rest = body:match("^(%d+)%s+(%S+)%s*(.*)$")
local n, unit_norm, sample
if n_str then
n = tonumber(n_str)
if unit:match("^минут") or unit:match("^minute") then
unit_norm = "minutes"
sample = n .. " минут"
elseif unit:match("^час") or unit:match("^hour") then
unit_norm = "hours"
sample = n .. " час" .. (n == 1 and "" or (n < 5 and "а" or "ов"))
else
jarvis.speak("Не понял единицу.")
jarvis.audio.play_error()
return { chain = false }
end
else
-- "каждый час напоминай..."
local single, rest2 = body:match("^(%a+)%s*(.*)$")
if single and (single == "час" or single == "минуту" or single == "минута") then
n = 1
unit_norm = (single == "час") and "hours" or "minutes"
sample = (single == "час") and "час" or "минуту"
rest = rest2
else
jarvis.speak("Не понял через сколько повторять.")
jarvis.audio.play_error()
return { chain = false }
end
end
-- Strip optional reminder verb
local text_body = (rest or ""):gsub("^напоминай%s+", "")
:gsub("^напомни%s+", "")
:gsub("^remind me%s+", "")
:gsub("^[%s,:%.]+", "")
:gsub("%s+$", "")
if text_body == "" then text_body = "Напоминание." end
local schedule = string.format("every %d %s", n, unit_norm)
local ok, err = pcall(function()
jarvis.scheduler.add({
name = "Recurring",
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("Буду напоминать каждые " .. sample .. ".")
jarvis.audio.play_ok()
return { chain = false }

View file

@ -0,0 +1,102 @@
-- "напомни мне через 5 минут выключить кофеварку"
local phrase = (jarvis.context.phrase or ""):lower()
-- Strip the trigger
local body = jarvis.text.strip_trigger(phrase, {
"напомни мне через",
"напомни через",
"поставь напоминалку через",
"поставь напоминание через",
"разбуди через",
"remind me in",
"set a reminder in",
"нагадай через",
"постав нагадування через",
})
body = body:gsub("^[%s,:%.]+", ""):gsub("%s+$", "")
if body == "" then
jarvis.speak("Через сколько и про что напомнить?")
jarvis.audio.play_error()
return { chain = false }
end
-- Parse "<N> <unit> <text>"
-- N can be digit or word (один, два, ...) — for v1 only digits
local n_str, unit, rest = body:match("^(%d+)%s+(%S+)%s*(.*)$")
if not n_str then
-- maybe "час" / "минуту" (singular)
local single_unit, rest2 = body:match("^([%a]+)%s*(.*)$")
if single_unit then
local map = {
["час"] = "1 hours",
["минуту"] = "1 minutes",
["секунду"] = "1 seconds",
}
if map[single_unit] then
local schedule = "in " .. map[single_unit]
local text_body = rest2:gsub("^[%s,:%.]+", ""):gsub("%s+$", "")
if text_body == "" then text_body = "Напоминание." end
local ok, err = pcall(function()
jarvis.scheduler.add({
name = "Reminder",
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("Напомню через " .. single_unit .. ".")
jarvis.audio.play_ok()
return { chain = false }
end
end
jarvis.speak("Не понял через сколько. Скажите например: через 5 минут.")
jarvis.audio.play_error()
return { chain = false }
end
local n = tonumber(n_str)
local unit_norm
local sample
if unit:match("^минут") or unit == "минуты" or unit == "минуту" or unit:match("^minute") then
unit_norm = "minutes"
sample = n .. " минут"
elseif unit:match("^час") or unit:match("^hour") then
unit_norm = "hours"
sample = n .. " час" .. (n == 1 and "" or (n < 5 and "а" or "ов"))
elseif unit:match("^секунд") or unit:match("^second") then
unit_norm = "seconds"
sample = n .. " секунд"
else
jarvis.speak("Не понял единицу. Минуты или часы.")
jarvis.audio.play_error()
return { chain = false }
end
local schedule = string.format("in %d %s", n, unit_norm)
local text_body = rest:gsub("^[%s,:%.]+", ""):gsub("%s+$", "")
if text_body == "" then text_body = "Напоминание." end
local ok, err = pcall(function()
jarvis.scheduler.add({
name = "Reminder",
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("Напомню через " .. sample .. ".")
jarvis.audio.play_ok()
return { chain = false }

View file

@ -0,0 +1,8 @@
local n = jarvis.scheduler.clear()
if n == 0 then
jarvis.speak("В расписании и так пусто.")
else
jarvis.speak(string.format("Удалил %d задач.", n))
end
jarvis.audio.play_ok()
return { chain = false }

View file

@ -0,0 +1,109 @@
# IMBA-5: Proactive scheduler — recurring reminders, daily briefings, intervals.
[[commands]]
id = "scheduler.add_reminder"
type = "lua"
script = "add_reminder.lua"
sandbox = "standard"
timeout = 5000
[commands.phrases]
ru = [
"напомни мне через", "напомни через",
"поставь напоминалку через", "поставь напоминание через",
"разбуди через",
]
en = ["remind me in", "set a reminder in"]
ua = ["нагадай через", "постав нагадування через"]
[[commands]]
id = "scheduler.add_at"
type = "lua"
script = "add_at.lua"
sandbox = "standard"
timeout = 5000
[commands.phrases]
ru = [
"напомни в",
"напомни сегодня в",
"разбуди в",
"поставь напоминалку на",
]
en = ["remind me at", "wake me at"]
ua = ["нагадай о", "розбуди о"]
[[commands]]
id = "scheduler.add_recurring"
type = "lua"
script = "add_recurring.lua"
sandbox = "standard"
timeout = 5000
[commands.phrases]
ru = [
"каждые",
"каждый час",
"каждые два часа",
"напоминай каждые",
"напоминай каждый",
]
en = ["every", "remind me every"]
ua = ["кожні", "нагадуй кожні"]
[[commands]]
id = "scheduler.add_daily"
type = "lua"
script = "add_daily.lua"
sandbox = "standard"
timeout = 5000
[commands.phrases]
ru = [
"каждый день в",
"каждое утро в",
"ежедневно в",
"по утрам в",
]
en = ["every day at", "daily at"]
ua = ["щодня о", "кожен день о"]
[[commands]]
id = "scheduler.list"
type = "lua"
script = "list.lua"
sandbox = "minimal"
timeout = 3000
[commands.phrases]
ru = [
"что у меня запланировано",
"какие напоминания",
"покажи расписание",
"какие задачи у меня",
"что в расписании",
]
en = ["what's on my schedule", "show schedule", "list reminders"]
ua = ["що в розкладі", "покажи розклад"]
[[commands]]
id = "scheduler.clear"
type = "lua"
script = "clear.lua"
sandbox = "minimal"
timeout = 3000
[commands.phrases]
ru = [
"очисти расписание",
"удали все напоминания",
"отмени все напоминания",
"сбрось расписание",
]
en = ["clear schedule", "cancel all reminders"]
ua = ["очисти розклад", "скасуй всі нагадування"]

View file

@ -0,0 +1,20 @@
local tasks = jarvis.scheduler.list()
if #tasks == 0 then
jarvis.speak("Расписание пустое.")
jarvis.audio.play_ok()
return { chain = false }
end
local sample = math.min(#tasks, 5)
local line = string.format("Запланировано %d. ", #tasks)
for i = 1, sample do
local t = tasks[i]
local what = (t.action and t.action.text) or t.name or "задача"
line = line .. t.schedule_human .. ": " .. what
if i < sample then line = line .. ". " end
end
line = line .. "."
jarvis.speak(line)
jarvis.audio.play_ok()
return { chain = false }