Expand description
Guided break routines + the routine engine (#152, #153).
A routine is an ordered list of RoutineSteps — each a short
instruction shown for a number of seconds — that the break overlay walks
through instead of rotating flat hint text. Each routine is tagged with a
RoutineCategory and a RoutineDifficulty.
Per break kind the user picks, in the Breaks tab, one of three modes
(persisted in Settings as micro_routine / long_routine):
""— off; the overlay falls back to plain hint rotation.- a routine id — always run that specific routine.
"random"— the engine: pick a routine at break time from the bundled set, filtered by the profile’s chosen categories (*_routine_categories) and a maximum difficulty (*_routine_max_difficulty).
The selection core (routines_matching + resolve_routine) is
pure and deterministic — the only impurity is random_index, which
chooses which of the matching routines to run.
Structs§
- Resolved
Routine - Steps + pacing metadata resolved for a single break, produced by a
single
random_indexcall so all three fields always come from the same routine draw. - Routine
- A curated, ordered sequence of guided break steps with a stable
id(persisted in settings), a humanlabel, and engine metadata (category/difficulty).Deserializeso user routines can arrive from imported content packs (#155) and persist inSettings.
Enums§
- Routine
Category - The theme a routine belongs to, used to filter the randomized pool.
- Routine
Difficulty - How demanding a routine is. Ordered
Gentle < Moderate < Active; the per-kind*_routine_max_difficultyfilter includes everything up to and including the chosen level.DefaultisActive(the most permissive filter) so a stale/unknown value can fall back through the shareddeserialize_with_fallbackhelper, matching the other tolerant settings enums. - Routine
Kind - Which break kind a routine is offered for. Sleep has no routines.
Functions§
- all_
routines - Every routine available to a profile: the bundled starters plus any the
user has imported from a content pack (
custom_routines). A custom routine whose id collides with a starter is dropped so the built-in always wins (import already rejects such ids, but resolve stays defensive). - get_
routines - List every routine (starter + imported) for the Breaks-tab picker.
- random_
index 🔒 - A random index in
[0, n), or0whennis0or entropy is unavailable. The lone impurity in the routine engine; kept tiny so the pure selection core stays fully testable. Uniform enough for picking a routine (the modulo bias across a handful of routines is negligible). - resolve_
routine - Resolve the guided routine for a break of
kindfrom the user’s per-kind settings:""→ none, a routine id → that routine,"random"→ the engine picks one from the filtered pool. Unknown ids and theSleepkind resolve to an empty routine. A singlerandom_indexcall is made so steps and pacing always come from the same pick. - routine 🔒
- routines_
matching - The routines that match a break
kindand the engine filters: the kind’s pool, intersected withcategories(empty means “all categories”) and capped atmax_difficulty. Pure so every filter combination is unit-testable. Sleep matches nothing. - starter_
routines - The bundled starter routines, ordered as they appear in the picker (micro
first, then long). Pure and allocation-only so it can be returned straight
from the
get_routinescommand and unit-tested without state. - step 🔒