@thebriangao/totem 1.4.4 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.dev.vars.example +5 -0
- package/.dockerignore +5 -0
- package/.env.example +29 -20
- package/CHANGELOG.md +99 -1
- package/CONTRIBUTING.md +48 -116
- package/Dockerfile +46 -12
- package/README.md +172 -498
- package/SECURITY.md +36 -59
- package/TOOLS.md +448 -311
- package/WHOOP.md +497 -2659
- package/assets/brand/SOURCES.md +38 -0
- package/assets/brand/totem.png +0 -0
- package/assets/brand/totem.svg +13 -0
- package/assets/fonts/Manrope-OFL.txt +93 -0
- package/assets/fonts/manrope-latin.woff2 +0 -0
- package/dist/build_info.js +5 -0
- package/dist/build_info.js.map +1 -0
- package/dist/cli/app.js +675 -0
- package/dist/cli/app.js.map +1 -0
- package/dist/cli/auth.js +297 -0
- package/dist/cli/auth.js.map +1 -0
- package/dist/cli/auth_flow.js +268 -0
- package/dist/cli/auth_flow.js.map +1 -0
- package/dist/cli/browser_login.js +368 -0
- package/dist/cli/browser_login.js.map +1 -0
- package/dist/cli/clients.js +403 -0
- package/dist/cli/clients.js.map +1 -0
- package/dist/cli/deploy_record.js +96 -0
- package/dist/cli/deploy_record.js.map +1 -0
- package/dist/cli/index.js +39 -575
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/links.js +28 -0
- package/dist/cli/links.js.map +1 -0
- package/dist/cli/logo.js +63 -0
- package/dist/cli/logo.js.map +1 -0
- package/dist/cli/setup.js +1157 -1017
- package/dist/cli/setup.js.map +1 -1
- package/dist/cli/spawn.js +80 -0
- package/dist/cli/spawn.js.map +1 -0
- package/dist/cli/sys.js +219 -0
- package/dist/cli/sys.js.map +1 -0
- package/dist/cli/ui.js +712 -463
- package/dist/cli/ui.js.map +1 -1
- package/dist/cli/update.js +425 -282
- package/dist/cli/update.js.map +1 -1
- package/dist/cloudflare/token_store.js +48 -0
- package/dist/cloudflare/token_store.js.map +1 -0
- package/dist/cloudflare/worker.js +155 -0
- package/dist/cloudflare/worker.js.map +1 -0
- package/dist/data/behaviors.js +2733 -617
- package/dist/data/behaviors.js.map +1 -1
- package/dist/data/endpoint_catalog.js +2681 -0
- package/dist/data/endpoint_catalog.js.map +1 -0
- package/dist/data/exercises.js +373 -4859
- package/dist/data/exercises.js.map +1 -1
- package/dist/data/garments.js +19 -0
- package/dist/data/garments.js.map +1 -0
- package/dist/data/sports.js +219 -208
- package/dist/data/sports.js.map +1 -1
- package/dist/lib/activity_list.js +123 -0
- package/dist/lib/activity_list.js.map +1 -0
- package/dist/lib/activity_records.js +195 -0
- package/dist/lib/activity_records.js.map +1 -0
- package/dist/lib/activity_results.js +44 -0
- package/dist/lib/activity_results.js.map +1 -0
- package/dist/lib/activity_types.js +164 -0
- package/dist/lib/activity_types.js.map +1 -0
- package/dist/lib/brand.js +63 -0
- package/dist/lib/brand.js.map +1 -0
- package/dist/lib/clock.js +24 -0
- package/dist/lib/clock.js.map +1 -0
- package/dist/lib/coach_session.js +345 -0
- package/dist/lib/coach_session.js.map +1 -0
- package/dist/lib/concurrency.js.map +1 -1
- package/dist/lib/dates.js +19 -0
- package/dist/lib/dates.js.map +1 -1
- package/dist/lib/env_file.js +195 -0
- package/dist/lib/env_file.js.map +1 -0
- package/dist/lib/health_plans_write.js +44 -0
- package/dist/lib/health_plans_write.js.map +1 -0
- package/dist/lib/heart_rate.js +34 -0
- package/dist/lib/heart_rate.js.map +1 -0
- package/dist/lib/highlight.js +81 -0
- package/dist/lib/highlight.js.map +1 -0
- package/dist/lib/install_links.js +47 -0
- package/dist/lib/install_links.js.map +1 -0
- package/dist/lib/instant.js +50 -0
- package/dist/lib/instant.js.map +1 -0
- package/dist/lib/journal_behaviors.js +382 -0
- package/dist/lib/journal_behaviors.js.map +1 -0
- package/dist/lib/lift_catalog.js +218 -0
- package/dist/lib/lift_catalog.js.map +1 -0
- package/dist/lib/lift_history.js +66 -0
- package/dist/lib/lift_history.js.map +1 -0
- package/dist/lib/lift_sets.js +146 -0
- package/dist/lib/lift_sets.js.map +1 -0
- package/dist/lib/lift_tool.js +20 -0
- package/dist/lib/lift_tool.js.map +1 -0
- package/dist/lib/profile_settings.js +101 -0
- package/dist/lib/profile_settings.js.map +1 -0
- package/dist/lib/screen_content.js +44 -0
- package/dist/lib/screen_content.js.map +1 -0
- package/dist/lib/timezone.js +48 -6
- package/dist/lib/timezone.js.map +1 -1
- package/dist/lib/walk.js +6 -1
- package/dist/lib/walk.js.map +1 -1
- package/dist/lib/weight_readings.js +61 -0
- package/dist/lib/weight_readings.js.map +1 -0
- package/dist/projections/activities.js +193 -0
- package/dist/projections/activities.js.map +1 -0
- package/dist/projections/alarm_schedule.js +102 -0
- package/dist/projections/alarm_schedule.js.map +1 -0
- package/dist/projections/coach.js +203 -0
- package/dist/projections/coach.js.map +1 -0
- package/dist/projections/community.js +165 -0
- package/dist/projections/community.js.map +1 -0
- package/dist/projections/health_features.js +167 -0
- package/dist/projections/health_features.js.map +1 -0
- package/dist/projections/hormonal_insights.js +239 -0
- package/dist/projections/hormonal_insights.js.map +1 -0
- package/dist/projections/journal_v2.js +157 -0
- package/dist/projections/journal_v2.js.map +1 -0
- package/dist/projections/lift_cards.js +115 -0
- package/dist/projections/lift_cards.js.map +1 -0
- package/dist/projections/lift_exercise_v2.js +131 -0
- package/dist/projections/lift_exercise_v2.js.map +1 -0
- package/dist/projections/lift_library_v2.js +67 -0
- package/dist/projections/lift_library_v2.js.map +1 -0
- package/dist/projections/lift_sessions.js +211 -0
- package/dist/projections/lift_sessions.js.map +1 -0
- package/dist/projections/memory.js +95 -0
- package/dist/projections/memory.js.map +1 -0
- package/dist/projections/milestones.js +119 -0
- package/dist/projections/milestones.js.map +1 -0
- package/dist/projections/profile_v2.js +150 -0
- package/dist/projections/profile_v2.js.map +1 -0
- package/dist/projections/settings_v2.js +153 -0
- package/dist/projections/settings_v2.js.map +1 -0
- package/dist/projections/sleep.js +4 -21
- package/dist/projections/sleep.js.map +1 -1
- package/dist/projections/v2/calendar.js +43 -0
- package/dist/projections/v2/calendar.js.map +1 -0
- package/dist/projections/v2/core_common.js +86 -0
- package/dist/projections/v2/core_common.js.map +1 -0
- package/dist/projections/v2/core_home.js +136 -0
- package/dist/projections/v2/core_home.js.map +1 -0
- package/dist/projections/v2/core_sleep_need.js +23 -0
- package/dist/projections/v2/core_sleep_need.js.map +1 -0
- package/dist/projections/v2/day.js +92 -0
- package/dist/projections/v2/day.js.map +1 -0
- package/dist/projections/v2/heart_rate.js +54 -0
- package/dist/projections/v2/heart_rate.js.map +1 -0
- package/dist/projections/v2/history.js +140 -0
- package/dist/projections/v2/history.js.map +1 -0
- package/dist/projections/v2/now.js +39 -0
- package/dist/projections/v2/now.js.map +1 -0
- package/dist/projections/v2/recovery.js +77 -0
- package/dist/projections/v2/recovery.js.map +1 -0
- package/dist/projections/v2/sleep.js +218 -0
- package/dist/projections/v2/sleep.js.map +1 -0
- package/dist/projections/v2/strain.js +39 -0
- package/dist/projections/v2/strain.js.map +1 -0
- package/dist/projections/v2/stress.js +92 -0
- package/dist/projections/v2/stress.js.map +1 -0
- package/dist/projections/v2/trend.js +205 -0
- package/dist/projections/v2/trend.js.map +1 -0
- package/dist/projections/weekly_plan.js +66 -0
- package/dist/projections/weekly_plan.js.map +1 -0
- package/dist/projections/weight_readings.js +57 -0
- package/dist/projections/weight_readings.js.map +1 -0
- package/dist/projections/workout.js +37 -15
- package/dist/projections/workout.js.map +1 -1
- package/dist/schemas/activities.js +123 -0
- package/dist/schemas/activities.js.map +1 -0
- package/dist/schemas/alarm_schedule.js +62 -0
- package/dist/schemas/alarm_schedule.js.map +1 -0
- package/dist/schemas/coach.js +76 -8
- package/dist/schemas/coach.js.map +1 -1
- package/dist/schemas/community.js +70 -0
- package/dist/schemas/community.js.map +1 -0
- package/dist/schemas/health.js +36 -0
- package/dist/schemas/health.js.map +1 -0
- package/dist/schemas/hormonal_insights.js +90 -0
- package/dist/schemas/hormonal_insights.js.map +1 -0
- package/dist/schemas/journal.js +4 -0
- package/dist/schemas/journal.js.map +1 -1
- package/dist/schemas/journal_v2.js +106 -0
- package/dist/schemas/journal_v2.js.map +1 -0
- package/dist/schemas/memory.js +42 -0
- package/dist/schemas/memory.js.map +1 -0
- package/dist/schemas/milestones.js +39 -0
- package/dist/schemas/milestones.js.map +1 -0
- package/dist/schemas/profile_v2.js +60 -0
- package/dist/schemas/profile_v2.js.map +1 -0
- package/dist/schemas/settings_v2.js +56 -0
- package/dist/schemas/settings_v2.js.map +1 -0
- package/dist/schemas/sleep.js +8 -1
- package/dist/schemas/sleep.js.map +1 -1
- package/dist/schemas/strength.js +10 -1
- package/dist/schemas/strength.js.map +1 -1
- package/dist/schemas/strength_v2.js +190 -0
- package/dist/schemas/strength_v2.js.map +1 -0
- package/dist/schemas/v2/calendar.js +8 -0
- package/dist/schemas/v2/calendar.js.map +1 -0
- package/dist/schemas/v2/core_common.js +42 -0
- package/dist/schemas/v2/core_common.js.map +1 -0
- package/dist/schemas/v2/day.js +73 -0
- package/dist/schemas/v2/day.js.map +1 -0
- package/dist/schemas/v2/now.js +25 -0
- package/dist/schemas/v2/now.js.map +1 -0
- package/dist/schemas/v2/recovery.js +35 -0
- package/dist/schemas/v2/recovery.js.map +1 -0
- package/dist/schemas/v2/sleep.js +44 -0
- package/dist/schemas/v2/sleep.js.map +1 -0
- package/dist/schemas/v2/strain.js +16 -0
- package/dist/schemas/v2/strain.js.map +1 -0
- package/dist/schemas/v2/stress.js +20 -0
- package/dist/schemas/v2/stress.js.map +1 -0
- package/dist/schemas/v2/trend.js +42 -0
- package/dist/schemas/v2/trend.js.map +1 -0
- package/dist/schemas/weekly_plan.js +31 -0
- package/dist/schemas/weekly_plan.js.map +1 -0
- package/dist/schemas/weight.js +28 -0
- package/dist/schemas/weight.js.map +1 -0
- package/dist/scripts/build_behaviors.js +114 -0
- package/dist/scripts/build_behaviors.js.map +1 -0
- package/dist/scripts/cognito_bootstrap.js +9 -277
- package/dist/scripts/cognito_bootstrap.js.map +1 -1
- package/dist/scripts/gen_activity_catalogs.js +104 -0
- package/dist/scripts/gen_activity_catalogs.js.map +1 -0
- package/dist/server-admin.js +156 -0
- package/dist/server-admin.js.map +1 -0
- package/dist/server-http.js +270 -48
- package/dist/server-http.js.map +1 -1
- package/dist/server.js +136 -23
- package/dist/server.js.map +1 -1
- package/dist/tools/annotations.js +15 -0
- package/dist/tools/annotations.js.map +1 -0
- package/dist/tools/define.js +31 -0
- package/dist/tools/define.js.map +1 -0
- package/dist/tools/register.js +59 -94
- package/dist/tools/register.js.map +1 -1
- package/dist/tools/resources.js +70 -0
- package/dist/tools/resources.js.map +1 -0
- package/dist/tools/slim_schema.js +90 -0
- package/dist/tools/slim_schema.js.map +1 -0
- package/dist/tools/v2/activity_delete.js +63 -17
- package/dist/tools/v2/activity_delete.js.map +1 -1
- package/dist/tools/v2/activity_edit.js +396 -0
- package/dist/tools/v2/activity_edit.js.map +1 -0
- package/dist/tools/v2/activity_log.js +152 -0
- package/dist/tools/v2/activity_log.js.map +1 -0
- package/dist/tools/v2/calendar.js +19 -21
- package/dist/tools/v2/calendar.js.map +1 -1
- package/dist/tools/v2/coach_ask.js +74 -110
- package/dist/tools/v2/coach_ask.js.map +1 -1
- package/dist/tools/v2/coach_history.js +120 -0
- package/dist/tools/v2/coach_history.js.map +1 -0
- package/dist/tools/v2/community.js +124 -0
- package/dist/tools/v2/community.js.map +1 -0
- package/dist/tools/v2/cycle.js +63 -15
- package/dist/tools/v2/cycle.js.map +1 -1
- package/dist/tools/v2/cycle_log.js +289 -32
- package/dist/tools/v2/cycle_log.js.map +1 -1
- package/dist/tools/v2/day.js +126 -24
- package/dist/tools/v2/day.js.map +1 -1
- package/dist/tools/v2/health.js +116 -0
- package/dist/tools/v2/health.js.map +1 -0
- package/dist/tools/v2/hr_zones_set.js +134 -34
- package/dist/tools/v2/hr_zones_set.js.map +1 -1
- package/dist/tools/v2/journal.js +75 -17
- package/dist/tools/v2/journal.js.map +1 -1
- package/dist/tools/v2/journal_log.js +306 -65
- package/dist/tools/v2/journal_log.js.map +1 -1
- package/dist/tools/v2/lift_exercise.js +125 -22
- package/dist/tools/v2/lift_exercise.js.map +1 -1
- package/dist/tools/v2/lift_exercise_set.js +291 -0
- package/dist/tools/v2/lift_exercise_set.js.map +1 -0
- package/dist/tools/v2/lift_library.js +51 -12
- package/dist/tools/v2/lift_library.js.map +1 -1
- package/dist/tools/v2/lift_log.js +309 -72
- package/dist/tools/v2/lift_log.js.map +1 -1
- package/dist/tools/v2/lift_sessions.js +248 -0
- package/dist/tools/v2/lift_sessions.js.map +1 -0
- package/dist/tools/v2/lift_template.js +232 -0
- package/dist/tools/v2/lift_template.js.map +1 -0
- package/dist/tools/v2/memory.js +45 -0
- package/dist/tools/v2/memory.js.map +1 -0
- package/dist/tools/v2/memory_set.js +107 -0
- package/dist/tools/v2/memory_set.js.map +1 -0
- package/dist/tools/v2/milestones.js +50 -0
- package/dist/tools/v2/milestones.js.map +1 -0
- package/dist/tools/v2/now.js +49 -0
- package/dist/tools/v2/now.js.map +1 -0
- package/dist/tools/v2/preferences.js +51 -0
- package/dist/tools/v2/preferences.js.map +1 -0
- package/dist/tools/v2/preferences_set.js +388 -0
- package/dist/tools/v2/preferences_set.js.map +1 -0
- package/dist/tools/v2/profile.js +54 -22
- package/dist/tools/v2/profile.js.map +1 -1
- package/dist/tools/v2/profile_update.js +167 -55
- package/dist/tools/v2/profile_update.js.map +1 -1
- package/dist/tools/v2/raw.js +91 -34
- package/dist/tools/v2/raw.js.map +1 -1
- package/dist/tools/v2/recovery.js +37 -23
- package/dist/tools/v2/recovery.js.map +1 -1
- package/dist/tools/v2/sleep.js +52 -16
- package/dist/tools/v2/sleep.js.map +1 -1
- package/dist/tools/v2/smart_alarm.js +54 -20
- package/dist/tools/v2/smart_alarm.js.map +1 -1
- package/dist/tools/v2/smart_alarm_set.js +264 -86
- package/dist/tools/v2/smart_alarm_set.js.map +1 -1
- package/dist/tools/v2/strain.js +15 -15
- package/dist/tools/v2/strain.js.map +1 -1
- package/dist/tools/v2/stress.js +17 -15
- package/dist/tools/v2/stress.js.map +1 -1
- package/dist/tools/v2/trend.js +56 -20
- package/dist/tools/v2/trend.js.map +1 -1
- package/dist/tools/v2/weekly_plan.js +30 -0
- package/dist/tools/v2/weekly_plan.js.map +1 -0
- package/dist/tools/v2/weekly_plan_set.js +134 -0
- package/dist/tools/v2/weekly_plan_set.js.map +1 -0
- package/dist/tools/v2/weight.js +56 -0
- package/dist/tools/v2/weight.js.map +1 -0
- package/dist/tools/v2/weight_log.js +188 -0
- package/dist/tools/v2/weight_log.js.map +1 -0
- package/dist/tools/v2/workouts.js +159 -25
- package/dist/tools/v2/workouts.js.map +1 -1
- package/dist/version.js +6 -0
- package/dist/version.js.map +1 -0
- package/dist/whoop/bff.js +94 -0
- package/dist/whoop/bff.js.map +1 -0
- package/dist/whoop/client.js +392 -18
- package/dist/whoop/client.js.map +1 -1
- package/dist/whoop/cognito.js +106 -79
- package/dist/whoop/cognito.js.map +1 -1
- package/dist/whoop/connect_page.js +165 -0
- package/dist/whoop/connect_page.js.map +1 -0
- package/dist/whoop/consent_font.js +287 -0
- package/dist/whoop/consent_font.js.map +1 -0
- package/dist/whoop/consent_logos.js +22 -0
- package/dist/whoop/consent_logos.js.map +1 -0
- package/dist/whoop/consent_page.js +291 -0
- package/dist/whoop/consent_page.js.map +1 -0
- package/dist/whoop/constants.js +5 -1
- package/dist/whoop/constants.js.map +1 -1
- package/dist/whoop/device.js +4 -4
- package/dist/whoop/device.js.map +1 -1
- package/dist/whoop/errors.js +85 -4
- package/dist/whoop/errors.js.map +1 -1
- package/dist/whoop/init_timezone.js +57 -17
- package/dist/whoop/init_timezone.js.map +1 -1
- package/dist/whoop/installation.js +15 -10
- package/dist/whoop/installation.js.map +1 -1
- package/dist/whoop/json_out.js +52 -6
- package/dist/whoop/json_out.js.map +1 -1
- package/dist/whoop/oauth_provider.js +81 -78
- package/dist/whoop/oauth_provider.js.map +1 -1
- package/dist/whoop/token_lock.js +331 -0
- package/dist/whoop/token_lock.js.map +1 -0
- package/dist/whoop/token_manager.js +536 -42
- package/dist/whoop/token_manager.js.map +1 -1
- package/dist/whoop/token_store.js +303 -36
- package/dist/whoop/token_store.js.map +1 -1
- package/dist/whoop/units.js +28 -0
- package/dist/whoop/units.js.map +1 -0
- package/package.json +29 -13
- package/scripts/build-mcpb.mjs +72 -0
- package/scripts/embed-consent-font.mjs +34 -0
- package/scripts/readme-media.ts +195 -0
- package/scripts/tools-md.ts +89 -0
- package/scripts/whoop-md.ts +119 -0
- package/src/build_info.ts +4 -0
- package/src/cli/app.ts +696 -0
- package/src/cli/auth.ts +350 -0
- package/src/cli/auth_flow.ts +356 -0
- package/src/cli/browser_login.ts +402 -0
- package/src/cli/clients.ts +467 -0
- package/src/cli/deploy_record.ts +100 -0
- package/src/cli/index.ts +41 -583
- package/src/cli/links.ts +43 -0
- package/src/cli/logo.ts +64 -0
- package/src/cli/setup.ts +1147 -979
- package/src/cli/spawn.ts +88 -0
- package/src/cli/sys.ts +267 -0
- package/src/cli/ui.ts +778 -436
- package/src/cli/update.ts +436 -274
- package/src/cloudflare/runtime.d.ts +27 -0
- package/src/cloudflare/token_store.ts +57 -0
- package/src/cloudflare/worker.ts +174 -0
- package/src/data/behaviors.ts +2760 -622
- package/src/data/endpoint_catalog.ts +2695 -0
- package/src/data/exercises.ts +379 -4861
- package/src/data/garments.ts +28 -0
- package/src/data/sports.ts +239 -211
- package/src/lib/activity_list.ts +150 -0
- package/src/lib/activity_records.ts +213 -0
- package/src/lib/activity_results.ts +51 -0
- package/src/lib/activity_types.ts +176 -0
- package/src/lib/brand.ts +71 -0
- package/src/lib/clock.ts +16 -0
- package/src/lib/coach_session.ts +434 -0
- package/src/lib/dates.ts +18 -0
- package/src/lib/env_file.ts +191 -0
- package/src/lib/health_plans_write.ts +53 -0
- package/src/lib/heart_rate.ts +42 -0
- package/src/lib/highlight.ts +71 -0
- package/src/lib/install_links.ts +61 -0
- package/src/lib/instant.ts +54 -0
- package/src/lib/journal_behaviors.ts +453 -0
- package/src/lib/lift_catalog.ts +258 -0
- package/src/lib/lift_history.ts +75 -0
- package/src/lib/lift_sets.ts +164 -0
- package/src/lib/lift_tool.ts +25 -0
- package/src/lib/profile_settings.ts +102 -0
- package/src/lib/screen_content.ts +40 -0
- package/src/lib/timezone.ts +44 -8
- package/src/lib/walk.ts +4 -1
- package/src/lib/weight_readings.ts +82 -0
- package/src/projections/activities.ts +199 -0
- package/src/projections/alarm_schedule.ts +98 -0
- package/src/projections/coach.ts +218 -0
- package/src/projections/community.ts +187 -0
- package/src/projections/health_features.ts +191 -0
- package/src/projections/hormonal_insights.ts +277 -0
- package/src/projections/journal_v2.ts +173 -0
- package/src/projections/lift_cards.ts +131 -0
- package/src/projections/lift_exercise_v2.ts +147 -0
- package/src/projections/lift_library_v2.ts +77 -0
- package/src/projections/lift_sessions.ts +250 -0
- package/src/projections/memory.ts +100 -0
- package/src/projections/milestones.ts +133 -0
- package/src/projections/profile_v2.ts +166 -0
- package/src/projections/settings_v2.ts +179 -0
- package/src/projections/sleep.ts +7 -21
- package/src/projections/v2/calendar.ts +48 -0
- package/src/projections/v2/core_common.ts +95 -0
- package/src/projections/v2/core_home.ts +177 -0
- package/src/projections/v2/core_sleep_need.ts +37 -0
- package/src/projections/v2/day.ts +162 -0
- package/src/projections/v2/heart_rate.ts +73 -0
- package/src/projections/v2/history.ts +153 -0
- package/src/projections/v2/now.ts +59 -0
- package/src/projections/v2/recovery.ts +120 -0
- package/src/projections/v2/sleep.ts +281 -0
- package/src/projections/v2/strain.ts +63 -0
- package/src/projections/v2/stress.ts +111 -0
- package/src/projections/v2/trend.ts +242 -0
- package/src/projections/weekly_plan.ts +79 -0
- package/src/projections/weight_readings.ts +57 -0
- package/src/projections/workout.ts +36 -17
- package/src/schemas/activities.ts +136 -0
- package/src/schemas/alarm_schedule.ts +70 -0
- package/src/schemas/coach.ts +98 -8
- package/src/schemas/community.ts +77 -0
- package/src/schemas/health.ts +36 -0
- package/src/schemas/hormonal_insights.ts +108 -0
- package/src/schemas/journal.ts +4 -0
- package/src/schemas/journal_v2.ts +112 -0
- package/src/schemas/memory.ts +48 -0
- package/src/schemas/milestones.ts +48 -0
- package/src/schemas/profile_v2.ts +63 -0
- package/src/schemas/settings_v2.ts +63 -0
- package/src/schemas/sleep.ts +9 -1
- package/src/schemas/strength.ts +10 -1
- package/src/schemas/strength_v2.ts +210 -0
- package/src/schemas/v2/calendar.ts +8 -0
- package/src/schemas/v2/core_common.ts +50 -0
- package/src/schemas/v2/day.ts +79 -0
- package/src/schemas/v2/now.ts +25 -0
- package/src/schemas/v2/recovery.ts +38 -0
- package/src/schemas/v2/sleep.ts +46 -0
- package/src/schemas/v2/strain.ts +16 -0
- package/src/schemas/v2/stress.ts +20 -0
- package/src/schemas/v2/trend.ts +45 -0
- package/src/schemas/weekly_plan.ts +36 -0
- package/src/schemas/weight.ts +53 -0
- package/src/scripts/build_behaviors.ts +116 -0
- package/src/scripts/cognito_bootstrap.ts +10 -249
- package/src/scripts/gen_activity_catalogs.ts +121 -0
- package/src/server-admin.ts +171 -0
- package/src/server-http.ts +290 -53
- package/src/server.ts +130 -26
- package/src/tools/annotations.ts +25 -0
- package/src/tools/define.ts +53 -0
- package/src/tools/register.ts +64 -94
- package/src/tools/resources.ts +92 -0
- package/src/tools/slim_schema.ts +102 -0
- package/src/tools/v2/activity_delete.ts +61 -23
- package/src/tools/v2/activity_edit.ts +378 -0
- package/src/tools/v2/activity_log.ts +154 -0
- package/src/tools/v2/calendar.ts +22 -21
- package/src/tools/v2/coach_ask.ts +83 -119
- package/src/tools/v2/coach_history.ts +140 -0
- package/src/tools/v2/community.ts +137 -0
- package/src/tools/v2/cycle.ts +78 -20
- package/src/tools/v2/cycle_log.ts +291 -40
- package/src/tools/v2/day.ts +126 -25
- package/src/tools/v2/health.ts +114 -0
- package/src/tools/v2/hr_zones_set.ts +132 -45
- package/src/tools/v2/journal.ts +78 -23
- package/src/tools/v2/journal_log.ts +321 -69
- package/src/tools/v2/lift_exercise.ts +135 -27
- package/src/tools/v2/lift_exercise_set.ts +272 -0
- package/src/tools/v2/lift_library.ts +57 -21
- package/src/tools/v2/lift_log.ts +325 -83
- package/src/tools/v2/lift_sessions.ts +255 -0
- package/src/tools/v2/lift_template.ts +229 -0
- package/src/tools/v2/memory.ts +54 -0
- package/src/tools/v2/memory_set.ts +110 -0
- package/src/tools/v2/milestones.ts +59 -0
- package/src/tools/v2/now.ts +61 -0
- package/src/tools/v2/preferences.ts +61 -0
- package/src/tools/v2/preferences_set.ts +403 -0
- package/src/tools/v2/profile.ts +56 -26
- package/src/tools/v2/profile_update.ts +151 -60
- package/src/tools/v2/raw.ts +89 -36
- package/src/tools/v2/recovery.ts +44 -25
- package/src/tools/v2/sleep.ts +57 -18
- package/src/tools/v2/smart_alarm.ts +62 -24
- package/src/tools/v2/smart_alarm_set.ts +240 -90
- package/src/tools/v2/strain.ts +19 -16
- package/src/tools/v2/stress.ts +22 -17
- package/src/tools/v2/trend.ts +58 -20
- package/src/tools/v2/weekly_plan.ts +38 -0
- package/src/tools/v2/weekly_plan_set.ts +132 -0
- package/src/tools/v2/weight.ts +61 -0
- package/src/tools/v2/weight_log.ts +193 -0
- package/src/tools/v2/workouts.ts +156 -26
- package/src/version.ts +5 -0
- package/src/whoop/bff.ts +84 -0
- package/src/whoop/client.ts +448 -18
- package/src/whoop/cognito.ts +110 -99
- package/src/whoop/connect_page.ts +183 -0
- package/src/whoop/consent_font.ts +289 -0
- package/src/whoop/consent_logos.ts +24 -0
- package/src/whoop/consent_page.ts +326 -0
- package/src/whoop/constants.ts +5 -1
- package/src/whoop/device.ts +4 -4
- package/src/whoop/errors.ts +89 -4
- package/src/whoop/init_timezone.ts +57 -16
- package/src/whoop/installation.ts +16 -7
- package/src/whoop/json_out.ts +51 -6
- package/src/whoop/oauth_provider.ts +84 -91
- package/src/whoop/token_lock.ts +345 -0
- package/src/whoop/token_manager.ts +580 -53
- package/src/whoop/token_store.ts +341 -32
- package/src/whoop/units.ts +35 -0
- package/wrangler.jsonc +17 -0
- package/assets/banner.svg +0 -38
- package/dist/data/endpoints.js +0 -320
- package/dist/data/endpoints.js.map +0 -1
- package/dist/lib/format.js +0 -22
- package/dist/lib/format.js.map +0 -1
- package/dist/lib/stats.js +0 -32
- package/dist/lib/stats.js.map +0 -1
- package/dist/projections/calendar.js +0 -33
- package/dist/projections/calendar.js.map +0 -1
- package/dist/projections/communities.js +0 -105
- package/dist/projections/communities.js.map +0 -1
- package/dist/projections/cycle.js +0 -81
- package/dist/projections/cycle.js.map +0 -1
- package/dist/projections/hr_zones.js +0 -35
- package/dist/projections/hr_zones.js.map +0 -1
- package/dist/projections/journal.js +0 -56
- package/dist/projections/journal.js.map +0 -1
- package/dist/projections/leaderboard.js +0 -37
- package/dist/projections/leaderboard.js.map +0 -1
- package/dist/projections/lift_exercise.js +0 -22
- package/dist/projections/lift_exercise.js.map +0 -1
- package/dist/projections/lift_history.js +0 -133
- package/dist/projections/lift_history.js.map +0 -1
- package/dist/projections/lift_library.js +0 -71
- package/dist/projections/lift_library.js.map +0 -1
- package/dist/projections/lift_progression.js +0 -138
- package/dist/projections/lift_progression.js.map +0 -1
- package/dist/projections/lift_prs.js +0 -20
- package/dist/projections/lift_prs.js.map +0 -1
- package/dist/projections/live_hr.js +0 -19
- package/dist/projections/live_hr.js.map +0 -1
- package/dist/projections/live_state.js +0 -23
- package/dist/projections/live_state.js.map +0 -1
- package/dist/projections/live_stress.js +0 -11
- package/dist/projections/live_stress.js.map +0 -1
- package/dist/projections/performance_assessment.js +0 -15
- package/dist/projections/performance_assessment.js.map +0 -1
- package/dist/projections/profile.js +0 -59
- package/dist/projections/profile.js.map +0 -1
- package/dist/projections/recovery.js +0 -131
- package/dist/projections/recovery.js.map +0 -1
- package/dist/projections/sleep_need.js +0 -32
- package/dist/projections/sleep_need.js.map +0 -1
- package/dist/projections/smart_alarm.js +0 -45
- package/dist/projections/smart_alarm.js.map +0 -1
- package/dist/projections/strain.js +0 -128
- package/dist/projections/strain.js.map +0 -1
- package/dist/projections/stress.js +0 -86
- package/dist/projections/stress.js.map +0 -1
- package/dist/projections/today.js +0 -129
- package/dist/projections/today.js.map +0 -1
- package/dist/projections/trend.js +0 -149
- package/dist/projections/trend.js.map +0 -1
- package/dist/projections/workouts.js +0 -37
- package/dist/projections/workouts.js.map +0 -1
- package/dist/schemas/calendar.js +0 -12
- package/dist/schemas/calendar.js.map +0 -1
- package/dist/schemas/communities.js +0 -51
- package/dist/schemas/communities.js.map +0 -1
- package/dist/schemas/compare.js +0 -15
- package/dist/schemas/compare.js.map +0 -1
- package/dist/schemas/leaderboard.js +0 -25
- package/dist/schemas/leaderboard.js.map +0 -1
- package/dist/schemas/live.js +0 -26
- package/dist/schemas/live.js.map +0 -1
- package/dist/schemas/performance.js +0 -12
- package/dist/schemas/performance.js.map +0 -1
- package/dist/schemas/profile.js +0 -39
- package/dist/schemas/profile.js.map +0 -1
- package/dist/schemas/recovery.js +0 -27
- package/dist/schemas/recovery.js.map +0 -1
- package/dist/schemas/settings.js +0 -26
- package/dist/schemas/settings.js.map +0 -1
- package/dist/schemas/sleep_need.js +0 -15
- package/dist/schemas/sleep_need.js.map +0 -1
- package/dist/schemas/smart_alarm.js +0 -36
- package/dist/schemas/smart_alarm.js.map +0 -1
- package/dist/schemas/strain.js +0 -24
- package/dist/schemas/strain.js.map +0 -1
- package/dist/schemas/stress.js +0 -16
- package/dist/schemas/stress.js.map +0 -1
- package/dist/schemas/today.js +0 -38
- package/dist/schemas/today.js.map +0 -1
- package/dist/schemas/trend.js +0 -50
- package/dist/schemas/trend.js.map +0 -1
- package/dist/schemas/womens_health.js +0 -23
- package/dist/schemas/womens_health.js.map +0 -1
- package/dist/tools/v2/activity_create.js +0 -64
- package/dist/tools/v2/activity_create.js.map +0 -1
- package/dist/tools/v2/behavior_impact.js +0 -36
- package/dist/tools/v2/behavior_impact.js.map +0 -1
- package/dist/tools/v2/communities.js +0 -60
- package/dist/tools/v2/communities.js.map +0 -1
- package/dist/tools/v2/compare.js +0 -67
- package/dist/tools/v2/compare.js.map +0 -1
- package/dist/tools/v2/endpoints.js +0 -28
- package/dist/tools/v2/endpoints.js.map +0 -1
- package/dist/tools/v2/hidden_metric.js +0 -28
- package/dist/tools/v2/hidden_metric.js.map +0 -1
- package/dist/tools/v2/hr_zones.js +0 -24
- package/dist/tools/v2/hr_zones.js.map +0 -1
- package/dist/tools/v2/journal_autopop.js +0 -19
- package/dist/tools/v2/journal_autopop.js.map +0 -1
- package/dist/tools/v2/journal_catalog.js +0 -44
- package/dist/tools/v2/journal_catalog.js.map +0 -1
- package/dist/tools/v2/leaderboard.js +0 -79
- package/dist/tools/v2/leaderboard.js.map +0 -1
- package/dist/tools/v2/lift_catalog.js +0 -47
- package/dist/tools/v2/lift_catalog.js.map +0 -1
- package/dist/tools/v2/lift_custom_exercise.js +0 -108
- package/dist/tools/v2/lift_custom_exercise.js.map +0 -1
- package/dist/tools/v2/lift_history.js +0 -39
- package/dist/tools/v2/lift_history.js.map +0 -1
- package/dist/tools/v2/lift_progression.js +0 -30
- package/dist/tools/v2/lift_progression.js.map +0 -1
- package/dist/tools/v2/lift_prs.js +0 -21
- package/dist/tools/v2/lift_prs.js.map +0 -1
- package/dist/tools/v2/lift_template_save.js +0 -83
- package/dist/tools/v2/lift_template_save.js.map +0 -1
- package/dist/tools/v2/live_hr.js +0 -21
- package/dist/tools/v2/live_hr.js.map +0 -1
- package/dist/tools/v2/live_state.js +0 -21
- package/dist/tools/v2/live_state.js.map +0 -1
- package/dist/tools/v2/live_stress.js +0 -22
- package/dist/tools/v2/live_stress.js.map +0 -1
- package/dist/tools/v2/performance_assessment.js +0 -38
- package/dist/tools/v2/performance_assessment.js.map +0 -1
- package/dist/tools/v2/sleep_need.js +0 -21
- package/dist/tools/v2/sleep_need.js.map +0 -1
- package/dist/tools/v2/sports_catalog.js +0 -26
- package/dist/tools/v2/sports_catalog.js.map +0 -1
- package/dist/tools/v2/symptom_log.js +0 -72
- package/dist/tools/v2/symptom_log.js.map +0 -1
- package/dist/tools/v2/today.js +0 -30
- package/dist/tools/v2/today.js.map +0 -1
- package/dist/tools/v2/workout.js +0 -23
- package/dist/tools/v2/workout.js.map +0 -1
- package/dist/whoop/build_lift_body.js +0 -67
- package/dist/whoop/build_lift_body.js.map +0 -1
- package/dist/whoop/session_state.js +0 -34
- package/dist/whoop/session_state.js.map +0 -1
- package/dist/whoop/types.js +0 -82
- package/dist/whoop/types.js.map +0 -1
- package/src/data/endpoints.ts +0 -319
- package/src/lib/format.ts +0 -27
- package/src/lib/stats.ts +0 -35
- package/src/projections/calendar.ts +0 -46
- package/src/projections/communities.ts +0 -135
- package/src/projections/cycle.ts +0 -85
- package/src/projections/hr_zones.ts +0 -43
- package/src/projections/journal.ts +0 -55
- package/src/projections/leaderboard.ts +0 -49
- package/src/projections/lift_exercise.ts +0 -29
- package/src/projections/lift_history.ts +0 -140
- package/src/projections/lift_library.ts +0 -70
- package/src/projections/lift_progression.ts +0 -138
- package/src/projections/lift_prs.ts +0 -23
- package/src/projections/live_hr.ts +0 -21
- package/src/projections/live_state.ts +0 -28
- package/src/projections/live_stress.ts +0 -13
- package/src/projections/performance_assessment.ts +0 -19
- package/src/projections/profile.ts +0 -71
- package/src/projections/recovery.ts +0 -133
- package/src/projections/sleep_need.ts +0 -36
- package/src/projections/smart_alarm.ts +0 -70
- package/src/projections/strain.ts +0 -131
- package/src/projections/stress.ts +0 -95
- package/src/projections/today.ts +0 -166
- package/src/projections/trend.ts +0 -149
- package/src/projections/workouts.ts +0 -36
- package/src/schemas/calendar.ts +0 -13
- package/src/schemas/communities.ts +0 -56
- package/src/schemas/compare.ts +0 -17
- package/src/schemas/leaderboard.ts +0 -26
- package/src/schemas/live.ts +0 -31
- package/src/schemas/performance.ts +0 -13
- package/src/schemas/profile.ts +0 -40
- package/src/schemas/recovery.ts +0 -28
- package/src/schemas/settings.ts +0 -30
- package/src/schemas/sleep_need.ts +0 -16
- package/src/schemas/smart_alarm.ts +0 -40
- package/src/schemas/strain.ts +0 -25
- package/src/schemas/stress.ts +0 -17
- package/src/schemas/today.ts +0 -39
- package/src/schemas/trend.ts +0 -53
- package/src/schemas/womens_health.ts +0 -26
- package/src/tools/v2/activity_create.ts +0 -74
- package/src/tools/v2/behavior_impact.ts +0 -39
- package/src/tools/v2/communities.ts +0 -65
- package/src/tools/v2/compare.ts +0 -83
- package/src/tools/v2/endpoints.ts +0 -32
- package/src/tools/v2/hidden_metric.ts +0 -33
- package/src/tools/v2/hr_zones.ts +0 -29
- package/src/tools/v2/journal_autopop.ts +0 -26
- package/src/tools/v2/journal_catalog.ts +0 -48
- package/src/tools/v2/leaderboard.ts +0 -92
- package/src/tools/v2/lift_catalog.ts +0 -48
- package/src/tools/v2/lift_custom_exercise.ts +0 -117
- package/src/tools/v2/lift_history.ts +0 -52
- package/src/tools/v2/lift_progression.ts +0 -34
- package/src/tools/v2/lift_prs.ts +0 -26
- package/src/tools/v2/lift_template_save.ts +0 -89
- package/src/tools/v2/live_hr.ts +0 -26
- package/src/tools/v2/live_state.ts +0 -26
- package/src/tools/v2/live_stress.ts +0 -27
- package/src/tools/v2/performance_assessment.ts +0 -44
- package/src/tools/v2/sleep_need.ts +0 -26
- package/src/tools/v2/sports_catalog.ts +0 -32
- package/src/tools/v2/symptom_log.ts +0 -78
- package/src/tools/v2/today.ts +0 -35
- package/src/tools/v2/workout.ts +0 -28
- package/src/whoop/build_lift_body.ts +0 -84
- package/src/whoop/session_state.ts +0 -41
- package/src/whoop/types.ts +0 -89
package/src/tools/v2/lift_log.ts
CHANGED
|
@@ -1,102 +1,344 @@
|
|
|
1
|
+
// whoop_lift_log (W+): log a finished Strength Trainer workout, or attach sets to
|
|
2
|
+
// an existing activity. Ports PR #40 (set timing across the window, the 0-rep
|
|
3
|
+
// guard, local-date name, requested vs saved window) and PR #49 (attach via
|
|
4
|
+
// link-cardio-workout) by @chaotix345, reworked per SPEC.md D2/D6 and §6.
|
|
1
5
|
import { z } from "zod";
|
|
2
6
|
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
3
7
|
import type { WhoopClient } from "../../whoop/client.js";
|
|
4
|
-
import {
|
|
8
|
+
import { defineTool, respond } from "../define.js";
|
|
9
|
+
import { WRITE_ADDITIVE } from "../annotations.js";
|
|
10
|
+
import { LiftLogOutV2 } from "../../schemas/strength_v2.js";
|
|
5
11
|
import { preview } from "../../whoop/write_safety.js";
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
12
|
+
import { accountWeightUnit, type WeightUnit } from "../../whoop/units.js";
|
|
13
|
+
import { WhoopApiError, WhoopConflictError } from "../../whoop/errors.js";
|
|
14
|
+
import { get } from "../../whoop/bff.js";
|
|
15
|
+
import { assertNotFuture, isoDay } from "../../lib/dates.js";
|
|
16
|
+
import { ExerciseResolver } from "../../lib/lift_catalog.js";
|
|
17
|
+
import {
|
|
18
|
+
buildActivityGroups,
|
|
19
|
+
buildTemplateGroups,
|
|
20
|
+
duringLiteral,
|
|
21
|
+
liftTimezone,
|
|
22
|
+
localTime,
|
|
23
|
+
parseDuring,
|
|
24
|
+
sentWeight,
|
|
25
|
+
setShapeProblems,
|
|
26
|
+
zeroRepWeightedSets,
|
|
27
|
+
type ExerciseSets,
|
|
28
|
+
} from "../../lib/lift_sets.js";
|
|
29
|
+
import { errorMessage, liftError } from "../../lib/lift_tool.js";
|
|
30
|
+
import { findHistoryCard, weightMismatch } from "../../lib/lift_history.js";
|
|
31
|
+
import { readActivityAs } from "../../lib/activity_records.js";
|
|
32
|
+
import { overlappingTiles } from "../../lib/activity_list.js";
|
|
33
|
+
import { setScheme } from "../../projections/lift_sessions.js";
|
|
34
|
+
import { instantInput, toInstantOpt } from "../../lib/instant.js";
|
|
10
35
|
|
|
11
|
-
const
|
|
36
|
+
const TOOL = "whoop_lift_log";
|
|
37
|
+
export const LIFT_PATH = "/weightlifting-service/v2/weightlifting-workout/activity";
|
|
38
|
+
export const LINK_PATH = "/weightlifting-service/v2/weightlifting-workout/link-cardio-workout";
|
|
39
|
+
const DEFAULT_MINUTES = 30;
|
|
40
|
+
const MAX_HOURS = 12;
|
|
41
|
+
|
|
42
|
+
const SetIn = z.object({
|
|
43
|
+
reps: z.number().int().min(0).max(1000).optional(),
|
|
44
|
+
weight: z.number().min(0).max(2000).optional(),
|
|
45
|
+
time_seconds: z.number().int().min(1).max(86_400).optional(),
|
|
46
|
+
performed: z.boolean().optional().describe("false = planned but skipped"),
|
|
47
|
+
});
|
|
48
|
+
const ExerciseIn = z.object({
|
|
49
|
+
exercise_id: z.string().optional().describe("From whoop_lift_library search"),
|
|
50
|
+
name: z.string().optional().describe("Or the exact name"),
|
|
51
|
+
sets: z.array(SetIn).min(1).max(50),
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
/** Per exercise, what will be logged: weights as the caller gave them, plus `sent` (the account's unit) when converted. */
|
|
55
|
+
function sessionSummary(items: ExerciseSets[], units: { input: WeightUnit; account: WeightUnit }) {
|
|
56
|
+
return items.map(({ exercise, sets }) => {
|
|
57
|
+
const timed = exercise.volume_input_format === "TIME";
|
|
58
|
+
const performed = sets.filter((s) => s.performed !== false);
|
|
59
|
+
return {
|
|
60
|
+
id: exercise.exercise_id,
|
|
61
|
+
name: exercise.name,
|
|
62
|
+
sets: setScheme(performed.map((s) => (timed ? (s.time_seconds ?? null) : (s.reps ?? null))), timed ? "s" : ""),
|
|
63
|
+
weights: performed.map((s) => s.weight ?? 0),
|
|
64
|
+
...(units.input !== units.account ? { sent: performed.map((s) => sentWeight(s.weight, units.input, units.account)) } : {}),
|
|
65
|
+
...(performed.length < sets.length ? { skipped: sets.length - performed.length } : {}),
|
|
66
|
+
};
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Does the first exercise's history (fresh, paged, retried while WHOOP catches
|
|
72
|
+
* up) show this activity with the weights that were sent? History is the only
|
|
73
|
+
* read that shows a lift's sets with their unit, so this is the check that
|
|
74
|
+
* catches a weight WHOOP read in another unit than the one it was converted to.
|
|
75
|
+
*/
|
|
76
|
+
async function verifyInHistory(
|
|
77
|
+
client: WhoopClient,
|
|
78
|
+
activityId: string,
|
|
79
|
+
item: ExerciseSets | undefined,
|
|
80
|
+
notBefore: string | undefined,
|
|
81
|
+
sent: { weights: number[]; unit: WeightUnit },
|
|
82
|
+
warnings: string[],
|
|
83
|
+
): Promise<boolean> {
|
|
84
|
+
if (!item) return false;
|
|
85
|
+
const name = item.exercise.name;
|
|
86
|
+
try {
|
|
87
|
+
const card = await findHistoryCard(client, item.exercise.exercise_id, activityId, notBefore);
|
|
88
|
+
if (!card) {
|
|
89
|
+
// History lags; the raw activity record answers at once and says whether the write landed at all.
|
|
90
|
+
const record = await readActivityAs(client, activityId, "CARDIO").catch(() => null);
|
|
91
|
+
warnings.push(record
|
|
92
|
+
? `The activity exists, but ${name}'s history doesn't show its sets yet (WHOOP can lag ~30 s), so the weights are unconfirmed. Don't log it again; check whoop_lift_exercise history.`
|
|
93
|
+
: `${name}'s history doesn't show this activity yet (WHOOP can lag ~30 s); check whoop_lift_exercise history before logging again.`);
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
let ok = true;
|
|
97
|
+
if (card.sets.length !== sent.weights.length) {
|
|
98
|
+
warnings.push(`${name}: history shows ${card.sets.length} sets, ${sent.weights.length} were sent.`);
|
|
99
|
+
ok = false;
|
|
100
|
+
}
|
|
101
|
+
const off = weightMismatch(card, sent.weights, sent.unit);
|
|
102
|
+
if (off) {
|
|
103
|
+
warnings.push(`${name}: WHOOP shows ${off.shown.join("/")} ${off.unit} where ${off.expected.join("/")} ${off.unit} was sent. The account's weight unit may have changed during the write: delete activity ${activityId} (whoop_activity_delete) and log it again.`);
|
|
104
|
+
ok = false;
|
|
105
|
+
}
|
|
106
|
+
return ok;
|
|
107
|
+
} catch (e) {
|
|
108
|
+
warnings.push(`Read-back failed: ${errorMessage(e)}`);
|
|
109
|
+
return false;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
12
112
|
|
|
13
113
|
export function registerLiftLog(server: McpServer, client: WhoopClient): void {
|
|
14
|
-
server
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
exercises: z.array(
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
})).min(1),
|
|
29
|
-
})).min(1),
|
|
114
|
+
defineTool(server, {
|
|
115
|
+
name: TOOL,
|
|
116
|
+
description:
|
|
117
|
+
"Log a finished strength workout as a new Strength Trainer activity, or attach the sets to an existing activity " +
|
|
118
|
+
"(attach_to_activity_id; permanent, WHOOP has no unlink). Weights need unit. Refused: a window overlapping another activity, and " +
|
|
119
|
+
"weighted sets with 0 reps (WHOOP would award a permanent PR). Previews unless confirm:true.",
|
|
120
|
+
input: {
|
|
121
|
+
exercises: z.array(ExerciseIn).min(1).max(30),
|
|
122
|
+
unit: z.enum(["kg", "lb"]).optional(),
|
|
123
|
+
start: instantInput().optional().describe("Default end minus 30 min"),
|
|
124
|
+
end: instantInput().optional().describe("Default now"),
|
|
125
|
+
name: z.string().min(1).max(100).optional(),
|
|
126
|
+
rpe: z.number().int().min(0).max(10).optional(),
|
|
127
|
+
attach_to_activity_id: z.string().optional(),
|
|
30
128
|
confirm: z.boolean().default(false),
|
|
31
129
|
},
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
],
|
|
50
|
-
isError: true,
|
|
51
|
-
};
|
|
130
|
+
annotations: WRITE_ADDITIVE,
|
|
131
|
+
}, async ({ exercises, unit, start: startIn, end: endIn, name, rpe, attach_to_activity_id, confirm }) => {
|
|
132
|
+
const start = toInstantOpt(startIn, "start");
|
|
133
|
+
const end = toInstantOpt(endIn, "end");
|
|
134
|
+
const warnings: string[] = [];
|
|
135
|
+
const attach = attach_to_activity_id?.trim();
|
|
136
|
+
|
|
137
|
+
// 1. Validate what needs no network.
|
|
138
|
+
// No default unit: a bare 225 read as kg on a lb account logs 496 lb and a PR that can't be removed.
|
|
139
|
+
if (!unit && exercises.some((e) => e.sets.some((s) => (s.weight ?? 0) > 0))) {
|
|
140
|
+
return liftError({ error: "Say which unit the weights are in: unit \"kg\" or \"lb\". Nothing is assumed." });
|
|
141
|
+
}
|
|
142
|
+
let window: { startMs: number; endMs: number } | null = null;
|
|
143
|
+
if (attach) {
|
|
144
|
+
if (start || end) warnings.push("start/end are ignored when attaching: the activity keeps its own window.");
|
|
145
|
+
if (exercises.some((e) => e.sets.some((s) => s.performed === false))) {
|
|
146
|
+
return liftError({ error: "performed:false can't be attached: every linked set counts. Leave skipped sets out." });
|
|
52
147
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
148
|
+
} else {
|
|
149
|
+
const endMs = end ? Date.parse(end) : Date.now();
|
|
150
|
+
const startMs = start ? Date.parse(start) : endMs - DEFAULT_MINUTES * 60_000;
|
|
151
|
+
if (endMs <= startMs) return liftError({ error: "end must be after start.", start, end });
|
|
152
|
+
if (endMs - startMs > MAX_HOURS * 3_600_000) return liftError({ error: `A lift longer than ${MAX_HOURS} h is almost certainly a wrong start or end.` });
|
|
153
|
+
try {
|
|
154
|
+
assertNotFuture(new Date(endMs).toISOString(), "end");
|
|
155
|
+
} catch (e) {
|
|
156
|
+
return liftError({ error: errorMessage(e) });
|
|
157
|
+
}
|
|
158
|
+
window = { startMs, endMs };
|
|
159
|
+
}
|
|
160
|
+
const refuseZeroRep = (sets: ReturnType<typeof zeroRepWeightedSets>) => liftError({
|
|
161
|
+
error: "Sets with weight and 0 reps are refused: WHOOP awards them a weight PR that can't be removed.",
|
|
162
|
+
sets,
|
|
163
|
+
fix: "Log only completed reps, or leave missed attempts out.",
|
|
164
|
+
});
|
|
165
|
+
const zeroRep = zeroRepWeightedSets(exercises.map((e) => ({ label: e.exercise_id ?? e.name ?? "?", sets: e.sets })));
|
|
166
|
+
if (zeroRep.length > 0) return refuseZeroRep(zeroRep);
|
|
167
|
+
|
|
168
|
+
// 2. Fresh pre-reads: exercise rows (sent verbatim), display unit, attach target.
|
|
169
|
+
const resolution = await new ExerciseResolver(client).resolveAll(exercises);
|
|
170
|
+
if (!resolution.ok) return liftError({ error: "Unknown exercise(s).", misses: resolution.misses });
|
|
171
|
+
const items: ExerciseSets[] = resolution.exercises.map((exercise, i) => ({ exercise, sets: exercises[i]!.sets }));
|
|
172
|
+
// Again now that the exercises are known: time_seconds only excuses 0 reps on a timed exercise.
|
|
173
|
+
const zeroRepResolved = zeroRepWeightedSets(items.map(({ exercise, sets }) => ({ label: exercise.name, sets, timed: exercise.volume_input_format === "TIME" })));
|
|
174
|
+
if (zeroRepResolved.length > 0) return refuseZeroRep(zeroRepResolved);
|
|
175
|
+
const problems = setShapeProblems(items);
|
|
176
|
+
if (problems.length > 0) return liftError({ error: "Some sets don't fit their exercise.", problems });
|
|
177
|
+
// A new lift must not be sent into an occupied window. WHOOP answers 409 and creates
|
|
178
|
+
// no activity, but it keeps the workout: live 2026-11-21, all seven 409'd lifts left
|
|
179
|
+
// their sets in exercise history with no activity to delete them through, where they
|
|
180
|
+
// win medals, set the PR tile and feed e1RM. This is a refusal, not PR #40's
|
|
181
|
+
// replace_overlapping (D6): nothing is deleted.
|
|
182
|
+
if (window) {
|
|
183
|
+
const clash = await overlappingTiles(client, new Date(window.startMs).toISOString(), new Date(window.endMs).toISOString());
|
|
184
|
+
if (clash.tiles.length > 0) {
|
|
185
|
+
return liftError({
|
|
186
|
+
error: "The window overlaps an existing activity, so nothing was sent. (WHOOP refuses an overlapping lift with a 409 yet keeps its sets in exercise history, where they can't be deleted.)",
|
|
187
|
+
overlaps: clash.tiles.map((t) => ({ activity_id: t.activity_id, type: t.internal_name, start: t.start, end: t.end })),
|
|
188
|
+
fix: "Pick a window that doesn't overlap, or delete the other activity with whoop_activity_delete first.",
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
if (!clash.complete) {
|
|
192
|
+
return liftError({ error: "Couldn't read the day's activities to rule out an overlap, so nothing was sent: WHOOP keeps an overlapping lift's sets with no way to delete them. Try again." });
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// The attach target: the raw record answers in every state; cardio-details (the
|
|
197
|
+
// fallback) 400s for the first seconds after a create, and the link still works then.
|
|
198
|
+
let target: Awaited<ReturnType<typeof readActivityAs>> = null;
|
|
199
|
+
if (attach) {
|
|
200
|
+
try {
|
|
201
|
+
target = await readActivityAs(client, attach, "CARDIO");
|
|
202
|
+
if (!target) return liftError({ error: `No activity ${attach}.` });
|
|
203
|
+
} catch (e) {
|
|
204
|
+
if (!(e instanceof WhoopApiError && e.status === 400)) return liftError({ error: `Couldn't read activity ${attach}: ${errorMessage(e)}` });
|
|
205
|
+
warnings.push("The activity's details aren't readable yet (pending), so its sport and time aren't shown.");
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
// The display unit is the last read before the write (D2): WHOOP reads the
|
|
210
|
+
// numbers in whatever unit the account shows at that moment.
|
|
211
|
+
const account = await accountWeightUnit(client);
|
|
212
|
+
const units = { input: unit ?? account, account };
|
|
213
|
+
const converted = units.input !== account;
|
|
214
|
+
const sentWeights = (sets: ExerciseSets["sets"]) => sets.map((s) => sentWeight(s.weight, units.input, account));
|
|
215
|
+
/** Receipt fields: `unit` is the caller's; what WHOOP received is spelled out only when it differs. */
|
|
216
|
+
const unitFields = {
|
|
217
|
+
unit: units.input,
|
|
218
|
+
sent_unit: converted ? account : null,
|
|
219
|
+
sent_weights: converted ? items.map(({ sets }) => sentWeights(sets)) : null,
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
if (attach) {
|
|
223
|
+
const sport = target?.type ?? null;
|
|
224
|
+
const tz = liftTimezone();
|
|
225
|
+
const activityStart = target?.start ?? null;
|
|
226
|
+
const linkName = name ?? (activityStart ? isoDay(new Date(activityStart)) : isoDay());
|
|
59
227
|
const body = {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
msk_total_volume_kg: 0,
|
|
65
|
-
msk_intensity_percent: 0,
|
|
66
|
-
raw_msk_strain_score: 0,
|
|
67
|
-
workout_groups,
|
|
228
|
+
activity_id: attach,
|
|
229
|
+
rpe: rpe ?? 0,
|
|
230
|
+
template_id: -1,
|
|
231
|
+
template: { name: linkName, source: "USER", workout_template_key: -1, workout_groups: buildTemplateGroups(items, units) },
|
|
68
232
|
};
|
|
69
233
|
if (!confirm) {
|
|
70
|
-
return {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
exercise_list: exercises.map((e) => ({ name: e.exercise_id, set_count: e.sets.length })),
|
|
79
|
-
}),
|
|
80
|
-
),
|
|
81
|
-
},
|
|
82
|
-
],
|
|
83
|
-
};
|
|
234
|
+
return respond(TOOL, LiftLogOutV2, preview("POST", LINK_PATH, {
|
|
235
|
+
attach_to: { activity_id: attach, sport, start: activityStart ? localTime(Date.parse(activityStart), tz) : null },
|
|
236
|
+
exercises: sessionSummary(items, units),
|
|
237
|
+
unit: units.input,
|
|
238
|
+
...(converted ? { sent_unit: account } : {}),
|
|
239
|
+
permanent: "Linking can't be undone; only deleting the activity removes these sets.",
|
|
240
|
+
...(warnings.length ? { warnings } : {}),
|
|
241
|
+
}));
|
|
84
242
|
}
|
|
85
|
-
|
|
86
|
-
const projected = {
|
|
87
|
-
logged: true as const,
|
|
88
|
-
activity_id: receipt.id,
|
|
89
|
-
exercise_count: exercises.length,
|
|
90
|
-
set_count,
|
|
91
|
-
total_volume_kg: null,
|
|
92
|
-
};
|
|
243
|
+
let linked: unknown;
|
|
93
244
|
try {
|
|
94
|
-
|
|
95
|
-
return { content: [{ type: "text", text: jsonOut(out) }] };
|
|
245
|
+
linked = await client.post(LINK_PATH, body);
|
|
96
246
|
} catch (e) {
|
|
97
|
-
if (e instanceof
|
|
247
|
+
if (e instanceof WhoopConflictError) {
|
|
248
|
+
return liftError({ error: `Activity ${attach} already has Strength Trainer sets linked, and WHOOP has no unlink. Nothing was attached.`, detail: e.message });
|
|
249
|
+
}
|
|
98
250
|
throw e;
|
|
99
251
|
}
|
|
100
|
-
|
|
101
|
-
|
|
252
|
+
const meta = get(linked, "workout_metadata");
|
|
253
|
+
const linkedStart = parseDuring(get(meta, "during"))?.[0];
|
|
254
|
+
const notBefore = linkedStart !== undefined ? new Date(linkedStart).toISOString() : (activityStart ?? undefined);
|
|
255
|
+
const verified = await verifyInHistory(client, attach, items[0], notBefore, { weights: sentWeights(items[0]!.sets), unit: account }, warnings);
|
|
256
|
+
return respond(TOOL, LiftLogOutV2, {
|
|
257
|
+
action: "attached",
|
|
258
|
+
activity_id: attach,
|
|
259
|
+
saved_during: (get(meta, "during") as string | undefined) ?? null,
|
|
260
|
+
score_state: (get(meta, "score_state") as string | undefined) ?? null,
|
|
261
|
+
...unitFields,
|
|
262
|
+
verified,
|
|
263
|
+
warnings,
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
const { startMs, endMs } = window!;
|
|
268
|
+
const timezone = liftTimezone();
|
|
269
|
+
const requested = duringLiteral(startMs, endMs);
|
|
270
|
+
const { workout_groups } = buildActivityGroups(items, window!, units);
|
|
271
|
+
const body: Record<string, unknown> = {
|
|
272
|
+
name: name ?? isoDay(new Date(endMs)),
|
|
273
|
+
during: requested,
|
|
274
|
+
timezone,
|
|
275
|
+
scaled_msk_strain_score: 0,
|
|
276
|
+
msk_total_volume_kg: 0,
|
|
277
|
+
msk_intensity_percent: 0,
|
|
278
|
+
raw_msk_strain_score: 0,
|
|
279
|
+
workout_template_id: -1,
|
|
280
|
+
workout_groups,
|
|
281
|
+
};
|
|
282
|
+
if (rpe !== undefined) body.rpe = rpe;
|
|
283
|
+
|
|
284
|
+
if (!confirm) {
|
|
285
|
+
return respond(TOOL, LiftLogOutV2, preview("POST", LIFT_PATH, {
|
|
286
|
+
name: body.name,
|
|
287
|
+
during: requested,
|
|
288
|
+
local: `${localTime(startMs, timezone)} to ${localTime(endMs, timezone).slice(11)} ${timezone}`,
|
|
289
|
+
exercises: sessionSummary(items, units),
|
|
290
|
+
unit: units.input,
|
|
291
|
+
...(converted ? { sent_unit: account } : {}),
|
|
292
|
+
...(rpe !== undefined ? { rpe } : {}),
|
|
293
|
+
}));
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
let receipt: unknown;
|
|
297
|
+
try {
|
|
298
|
+
receipt = await client.post(LIFT_PATH, body);
|
|
299
|
+
} catch (e) {
|
|
300
|
+
if (e instanceof WhoopConflictError) {
|
|
301
|
+
return liftError({
|
|
302
|
+
error: "WHOOP refused the lift (409): the window overlaps an activity the pre-check didn't see. No activity was created, but WHOOP keeps the sets: they now show in each exercise's history without an activity, count toward PRs and e1RM, and can't be deleted. Don't send these sets again unless you mean to log them twice.",
|
|
303
|
+
during: requested,
|
|
304
|
+
fix: "Find the overlapping activity (whoop_workouts for that day), then pick a clear window or delete it with whoop_activity_delete.",
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
if (e instanceof WhoopApiError && e.status === 422) {
|
|
308
|
+
return liftError({ error: "WHOOP rejected the workout shape (422, no details). Nothing was logged.", detail: e.message });
|
|
309
|
+
}
|
|
310
|
+
throw e;
|
|
311
|
+
}
|
|
312
|
+
const activityId = get(receipt, "id");
|
|
313
|
+
if (typeof activityId !== "string") throw new Error("WHOOP accepted the lift but returned no activity id; check the app before retrying.");
|
|
314
|
+
|
|
315
|
+
const saved = (get(receipt, "during") as string | undefined) ?? null;
|
|
316
|
+
const savedMs = parseDuring(saved);
|
|
317
|
+
if (savedMs && (savedMs[0] < startMs || savedMs[1] > endMs)) warnings.push(`WHOOP widened the window to ${saved} (requested ${requested}).`);
|
|
318
|
+
const firstPerformed = items.find((it) => it.sets.some((s) => s.performed !== false));
|
|
319
|
+
let verified: boolean;
|
|
320
|
+
if (firstPerformed) {
|
|
321
|
+
const performed = firstPerformed.sets.filter((s) => s.performed !== false);
|
|
322
|
+
verified = await verifyInHistory(client, activityId, firstPerformed, new Date(savedMs?.[0] ?? startMs).toISOString(), { weights: sentWeights(performed), unit: account }, warnings);
|
|
323
|
+
} else {
|
|
324
|
+
// Nothing performed, so nothing reaches history. The raw activity record answers in
|
|
325
|
+
// every state; cardio-details 400s for the first seconds after a create.
|
|
326
|
+
try {
|
|
327
|
+
verified = (await readActivityAs(client, activityId, "CARDIO"))?.type === "weightlifting_msk";
|
|
328
|
+
if (!verified) warnings.push("The new activity doesn't read back as a Strength Trainer workout.");
|
|
329
|
+
} catch (e) {
|
|
330
|
+
verified = false;
|
|
331
|
+
warnings.push(`Read-back failed: ${errorMessage(e)}`);
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
return respond(TOOL, LiftLogOutV2, {
|
|
335
|
+
action: "logged",
|
|
336
|
+
activity_id: activityId,
|
|
337
|
+
saved_during: saved,
|
|
338
|
+
score_state: (get(receipt, "score_state") as string | undefined) ?? null,
|
|
339
|
+
...unitFields,
|
|
340
|
+
verified,
|
|
341
|
+
warnings,
|
|
342
|
+
});
|
|
343
|
+
});
|
|
102
344
|
}
|