4.5 KiB
Where the hooks are
API route registration — api/main.py
Lines 10-17: imported route modules and added to ROUTE_MODULES:
api.routes.routinesapi.routes.medicationsapi.routes.routine_steps_extendedapi.routes.routine_sessions_extendedapi.routes.routine_templatesapi.routes.routine_statsapi.routes.routine_tags
Bot command registration — bot/bot.py
Lines 23-24: imported bot.commands.routines and bot.commands.medications
These imports trigger register_module() and register_validator() at load time,
which makes the bot's AI parser route "routine" and "medication" interaction types
to the right handlers.
Bot command handlers — bot/commands/routines.py, bot/commands/medications.py
Each file:
- Defines an async handler (
handle_routine,handle_medication) - Defines a JSON validator for the AI parser
- Calls
register_module()to hook into the command registry - Calls
ai_parser.register_validator()to hook into parse validation
Scheduler — scheduler/daemon.py
poll_callback() now calls three check functions on every tick:
check_medication_reminders()— sends notifications for doses due nowcheck_routine_reminders()— sends notifications for scheduled routinescheck_refills()— warns when medication supply is running low
All three use core.notifications._sendToEnabledChannels() to deliver.
AI config — ai/ai_config.json
Updated the command_parser system prompt to list the two interaction types
(routine, medication) and the fields to extract for each. This is what
tells the LLM how to parse natural language into the right action structure.
Extended Routines API — New Modules
Routine Steps Extended — api/routes/routine_steps_extended.py
PUT /api/routines/<id>/steps/<step_id>/instructions— update step instructionsPUT /api/routines/<id>/steps/<step_id>/type— update step type (timer, checklist, etc)PUT /api/routines/<id>/steps/<step_id>/media— update media URL
Routine Sessions Extended — api/routes/routine_sessions_extended.py
POST /api/sessions/<id>/pause— pause active sessionPOST /api/sessions/<id>/resume— resume paused sessionPOST /api/sessions/<id>/abort— abort with reasonPOST /api/sessions/<id>/note— add note to sessionPUT /api/sessions/<id>/duration— record actual durationGET /api/sessions/<id>— get session with notes
Routine Templates — api/routes/routine_templates.py
GET /api/templates— list templatesPOST /api/templates— create templateGET /api/templates/<id>— get template with stepsPOST /api/templates/<id>/clone— clone to user's routinesPUT /api/templates/<id>— update templateDELETE /api/templates/<id>— delete templatePOST /api/templates/<id>/steps— add step to template
Routine Stats — api/routes/routine_stats.py
GET /api/routines/<id>/stats— completion statsGET /api/routines/streaks— all user streaksGET /api/routines/<id>/streak— specific routine streakGET /api/routines/weekly-summary— weekly progress
Routine Tags — api/routes/routine_tags.py
GET /api/tags— list tagsPOST /api/tags— create tagDELETE /api/tags/<id>— delete tagPOST /api/routines/<id>/tags— add tags to routineDELETE /api/routines/<id>/tags/<tag_id>— remove tagGET /api/routines/<id>/tags— get routine's tags
Core Modules — Business Logic
core/routines.py
Shared functions for routine operations:
start_session()— create and start a new sessionpause_session()— pause an active sessionresume_session()— resume a paused sessionabort_session()— abort with reasoncomplete_session()— mark complete and update streakclone_template()— clone template to user's routinescalculate_streak()— get current streak
core/stats.py
Statistics calculation functions:
get_routine_stats()— completion rate, avg duration, total timeget_user_streaks()— all streaks for userget_weekly_summary()— weekly progress summaryget_monthly_summary()— monthly progress summary
Bot Commands — Extended Routines
New actions added to bot/commands/routines.py:
pause— pause current sessionresume— resume paused sessionabort— abort with reasonnote— add note to sessionstats— show completion statisticsstreak— show current streaktemplates— list available templatesclone— clone a templatetag— add tag to routine