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

6 lines
198 B
Lua
Raw 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
local n = jarvis.scheduler.clear()
if n == 0 then
refactor: maintainability pass — dedup, central env config, cmd helpers, tests, ARCHITECTURE.md User asked the code stays easy to fix/extend as the feature surface grows. This commit refactors what was duplicated, centralises what was scattered, adds tests where there were none, and writes the architecture doc that contributors will need. Deduplication - tts::play_wav extracted to tts/mod.rs as pub(crate). Was identical in piper.rs and silero.rs (~25 lines × 2). Both backends now call super::play_wav. Centralised env config - new crates/jarvis-core/src/runtime_config.rs — single doc-file for every JARVIS_* / GROQ_* / OLLAMA_* env var. Includes: - ENV_* constants with doc comments - get(name) / get_bool(name, default) / get_parse(name, default) helpers - feature-flag wrappers: llm_tts_enabled(), llm_router_enabled(), llm_router_threshold() - log_effective_config() prints active values on startup - migrated llm_fallback (JARVIS_LLM_TTS), llm_router (JARVIS_LLM_ROUTER, JARVIS_LLM_ROUTER_THRESHOLD) to use the new helpers. Pattern set for future migrations. Lua boilerplate killer - new crates/jarvis-core/src/lua/api/cmd.rs exposing: jarvis.cmd.ok(msg?) — play_ok + speak + {chain=false} jarvis.cmd.chain_ok(msg?) — same but chain=true jarvis.cmd.error(msg?) — play_error + speak + {chain=false} jarvis.cmd.not_found(msg?) — play_not_found + speak + {chain=false} jarvis.cmd.silent_ok / silent_error - refactored 5 packs (daily_briefing/off, memory_pack/list, pomodoro/stop, habit_nudge/stop_all, scheduler/clear) — each lost 3-4 lines of repetitive play_*/speak/return boilerplate. Pattern for future packs documented in ARCHITECTURE.md. Tests (was 32, now 49) - long_term_memory: 8 new tests for normalize_key, search_in (rank, limit, empty), build_context_from (empty + populated), serde round-trips for MemoryRecord and Store. Extracted pure logic (search_in, build_context_from) into pub(crate) functions to enable testing without global state. - profiles: 6 new tests for Profile::allows_command (empty/whitelist/blacklist/ deny-wins-over-allow), serde round-trip with all fields + minimal-fields tolerance via #[serde(default)]. - runtime_config: 2 tests for get_bool / get_parse defaults. - All 49 tests pass. New mood/energy log pack - resources/commands/mood_log/ with 2 commands: mood.record "запиши настроение 7" / "сегодня мне грустно" → stores timestamped entry via jarvis.memory.remember mood.recap "как прошла неделя" → LLM summarises last 30 entries - Showcase: composes memory + llm + cmd helpers in <30 lines per script. ARCHITECTURE.md (new, 250 lines) - Crate layout, data flow diagram (mic→action 10 steps), per-module responsibility table, configuration layers, TTS pipeline diagram, Lua sandbox details with API quick-ref, background-services overview, "how to add a pack/feature/TTS backend" recipes, test coverage map, build instructions with MSVC env, git workflow with Forgejo NO_PROXY trick. - Aimed at someone who just cloned the repo and needs to fix a bug fast. Build: cargo build --release -p jarvis-app -p jarvis-gui both green. Tests: 49/49 jarvis-core unit tests pass.
2026-05-15 16:06:18 +03:00
return jarvis.cmd.ok("В расписании и так пусто.")
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
end
refactor: maintainability pass — dedup, central env config, cmd helpers, tests, ARCHITECTURE.md User asked the code stays easy to fix/extend as the feature surface grows. This commit refactors what was duplicated, centralises what was scattered, adds tests where there were none, and writes the architecture doc that contributors will need. Deduplication - tts::play_wav extracted to tts/mod.rs as pub(crate). Was identical in piper.rs and silero.rs (~25 lines × 2). Both backends now call super::play_wav. Centralised env config - new crates/jarvis-core/src/runtime_config.rs — single doc-file for every JARVIS_* / GROQ_* / OLLAMA_* env var. Includes: - ENV_* constants with doc comments - get(name) / get_bool(name, default) / get_parse(name, default) helpers - feature-flag wrappers: llm_tts_enabled(), llm_router_enabled(), llm_router_threshold() - log_effective_config() prints active values on startup - migrated llm_fallback (JARVIS_LLM_TTS), llm_router (JARVIS_LLM_ROUTER, JARVIS_LLM_ROUTER_THRESHOLD) to use the new helpers. Pattern set for future migrations. Lua boilerplate killer - new crates/jarvis-core/src/lua/api/cmd.rs exposing: jarvis.cmd.ok(msg?) — play_ok + speak + {chain=false} jarvis.cmd.chain_ok(msg?) — same but chain=true jarvis.cmd.error(msg?) — play_error + speak + {chain=false} jarvis.cmd.not_found(msg?) — play_not_found + speak + {chain=false} jarvis.cmd.silent_ok / silent_error - refactored 5 packs (daily_briefing/off, memory_pack/list, pomodoro/stop, habit_nudge/stop_all, scheduler/clear) — each lost 3-4 lines of repetitive play_*/speak/return boilerplate. Pattern for future packs documented in ARCHITECTURE.md. Tests (was 32, now 49) - long_term_memory: 8 new tests for normalize_key, search_in (rank, limit, empty), build_context_from (empty + populated), serde round-trips for MemoryRecord and Store. Extracted pure logic (search_in, build_context_from) into pub(crate) functions to enable testing without global state. - profiles: 6 new tests for Profile::allows_command (empty/whitelist/blacklist/ deny-wins-over-allow), serde round-trip with all fields + minimal-fields tolerance via #[serde(default)]. - runtime_config: 2 tests for get_bool / get_parse defaults. - All 49 tests pass. New mood/energy log pack - resources/commands/mood_log/ with 2 commands: mood.record "запиши настроение 7" / "сегодня мне грустно" → stores timestamped entry via jarvis.memory.remember mood.recap "как прошла неделя" → LLM summarises last 30 entries - Showcase: composes memory + llm + cmd helpers in <30 lines per script. ARCHITECTURE.md (new, 250 lines) - Crate layout, data flow diagram (mic→action 10 steps), per-module responsibility table, configuration layers, TTS pipeline diagram, Lua sandbox details with API quick-ref, background-services overview, "how to add a pack/feature/TTS backend" recipes, test coverage map, build instructions with MSVC env, git workflow with Forgejo NO_PROXY trick. - Aimed at someone who just cloned the repo and needs to fix a bug fast. Build: cargo build --release -p jarvis-app -p jarvis-gui both green. Tests: 49/49 jarvis-core unit tests pass.
2026-05-15 16:06:18 +03:00
return jarvis.cmd.ok(string.format("Удалил %d задач.", n))