@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/dist/cli/app.js
ADDED
|
@@ -0,0 +1,675 @@
|
|
|
1
|
+
// The `totem` command: the command table, help, and the short commands
|
|
2
|
+
// (status, ping, logs, deploy, tools, token, start, dev, build, test).
|
|
3
|
+
// The guided flows live in setup.ts, auth.ts and update.ts.
|
|
4
|
+
//
|
|
5
|
+
// `runCli(argv, ctx, io)` is the whole program as a function of its arguments,
|
|
6
|
+
// so tests can render any screen. index.ts is only the entry point.
|
|
7
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
8
|
+
import { resolve } from "node:path";
|
|
9
|
+
import { realAuthDeps, runAuth } from "./auth.js";
|
|
10
|
+
import { CLIENTS, tildify } from "./clients.js";
|
|
11
|
+
import { configFile, readDeployRecord } from "./deploy_record.js";
|
|
12
|
+
import { runCloudSetup, runConnect, runLocalSetup } from "./setup.js";
|
|
13
|
+
import { pkgBin } from "./spawn.js";
|
|
14
|
+
import { scriptCommand } from "./sys.js";
|
|
15
|
+
import { resolveTokenFilePath } from "../whoop/token_store.js";
|
|
16
|
+
import { runUpdate } from "./update.js";
|
|
17
|
+
import { padEnd, when, wrap } from "./ui.js";
|
|
18
|
+
const GROUPS = ["Set up", "Run and maintain", "Develop"];
|
|
19
|
+
const HOST_NAME = { fly: "Fly.io", railway: "Railway", cloudflare: "Cloudflare", cloudrun: "Google Cloud Run", custom: "your own server", local: "this computer" };
|
|
20
|
+
/** Wrangler through npx (see setup.ts): Cloudflare needs nothing installed beyond Node. */
|
|
21
|
+
const WRANGLER = ["--yes", "wrangler@4"];
|
|
22
|
+
const cleanUrl = (u) => u.replace(/\/+$/, "");
|
|
23
|
+
/**
|
|
24
|
+
* The fly.toml a Fly deploy uses: the one `totem cloud` wrote in totem's config
|
|
25
|
+
* folder, else (installs before 2.0) one in the install, else none.
|
|
26
|
+
*/
|
|
27
|
+
export function flyConfigPath(root, sys) {
|
|
28
|
+
return [configFile(sys, "fly.toml"), resolve(root, "fly.toml")].find((f) => existsSync(f)) ?? null;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Where the server is deployed: the deploy record written by
|
|
32
|
+
* `totem cloud` / `totem local`, else (deploys older than the record) the Fly
|
|
33
|
+
* app named by $FLY_APP or fly.toml.
|
|
34
|
+
*/
|
|
35
|
+
export function detectDeploy(root, sys) {
|
|
36
|
+
const record = readDeployRecord(root, sys);
|
|
37
|
+
if (record)
|
|
38
|
+
return record;
|
|
39
|
+
let app = sys.env.FLY_APP || null;
|
|
40
|
+
const toml = flyConfigPath(root, sys);
|
|
41
|
+
if (!app && toml)
|
|
42
|
+
app = readFileSync(toml, "utf8").match(/^app\s*=\s*['"]([^'"]+)['"]/m)?.[1] ?? null;
|
|
43
|
+
return app ? { platform: "fly", app, url: `https://${app}.fly.dev` } : null;
|
|
44
|
+
}
|
|
45
|
+
const NOT_SET_UP = [["Run on this computer", "totem local"], ["Deploy a server", "totem cloud"]];
|
|
46
|
+
/** The deployment, or an explanation printed and null. */
|
|
47
|
+
function remoteDeploy(app, io, what) {
|
|
48
|
+
const d = detectDeploy(app.root, io.sys);
|
|
49
|
+
if (d && d.platform !== "local")
|
|
50
|
+
return d;
|
|
51
|
+
if (d)
|
|
52
|
+
io.ui.error(`${what} is for a deployed server. This install runs on this computer.`, { fix: [["Deploy a server", "totem cloud"]] });
|
|
53
|
+
else
|
|
54
|
+
io.ui.error("totem isn't set up yet.", { fix: NOT_SET_UP });
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
// ── deploy / logs / status ──────────────────────────────────────────────────
|
|
58
|
+
const HOST_CLI = {
|
|
59
|
+
fly: { names: ["fly", "flyctl"], install: "brew install flyctl" },
|
|
60
|
+
railway: { names: ["railway"], install: "npm i -g @railway/cli" },
|
|
61
|
+
cloudflare: { names: ["npx"], install: "install Node.js from https://nodejs.org" },
|
|
62
|
+
// Servers deployed by totem 1.x; totem 2 no longer creates them.
|
|
63
|
+
cloudrun: { names: ["gcloud"], install: "brew install --cask google-cloud-sdk" },
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* The host's CLI on this machine ("fly" or "flyctl", whichever is installed),
|
|
67
|
+
* or an explanation printed and null. A server deployed from another machine
|
|
68
|
+
* leaves this one without the CLI: say that, not "spawn fly ENOENT".
|
|
69
|
+
*/
|
|
70
|
+
function hostCli(io, d, command) {
|
|
71
|
+
const cli = HOST_CLI[d.platform];
|
|
72
|
+
if (!cli)
|
|
73
|
+
return null;
|
|
74
|
+
const found = cli.names.find((n) => io.sys.has(n));
|
|
75
|
+
if (found)
|
|
76
|
+
return found;
|
|
77
|
+
io.ui.error(`${command} needs the ${HOST_NAME[d.platform] ?? d.platform} CLI (${cli.names[0]}), which isn't installed on this machine.`, {
|
|
78
|
+
fix: [["Install it", cli.install], ["Then", command]],
|
|
79
|
+
});
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* The host commands that deploy this install's code again, in order. `fly` is
|
|
84
|
+
* the Fly binary to use; `flyConfig` the fly.toml to deploy with (it keeps the
|
|
85
|
+
* volume mount), when there is one.
|
|
86
|
+
*/
|
|
87
|
+
export function deployCommands(d, extra = [], fly = "fly", flyConfig = null) {
|
|
88
|
+
switch (d.platform) {
|
|
89
|
+
case "fly":
|
|
90
|
+
return [[fly, ["deploy", ...(flyConfig ? ["--config", flyConfig] : []), ...(d.app ? ["-a", d.app] : []), ...extra]]];
|
|
91
|
+
case "railway":
|
|
92
|
+
return [...(d.app ? [["railway", ["link", "--project", d.app]]] : []), ["railway", ["up", "--ci", ...(d.service ? ["--service", d.service] : []), ...extra]]];
|
|
93
|
+
case "cloudflare":
|
|
94
|
+
return [["npx", [...WRANGLER, "deploy", ...(d.app ? ["--name", d.app] : []), ...extra]]];
|
|
95
|
+
case "cloudrun":
|
|
96
|
+
return [["gcloud", ["run", "deploy", d.app ?? "totem", "--source", ".", "--region", d.region ?? "us-west1", "--min-instances", "1",
|
|
97
|
+
...(d.project ? ["--project", d.project] : []), "--quiet", ...extra]]];
|
|
98
|
+
default:
|
|
99
|
+
return null;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
/** `totem deploy` with its output captured (for the updater). */
|
|
103
|
+
export async function redeployCaptured(app, io, onLine) {
|
|
104
|
+
const d = detectDeploy(app.root, io.sys);
|
|
105
|
+
const fly = ["fly", "flyctl"].find((n) => io.sys.has(n)) ?? "fly";
|
|
106
|
+
const commands = d ? deployCommands(d, [], fly, flyConfigPath(app.root, io.sys)) : null;
|
|
107
|
+
if (!commands)
|
|
108
|
+
return { code: 1, stdout: "", stderr: "no deployment that totem can deploy to" };
|
|
109
|
+
let last = { code: 0, stdout: "", stderr: "" };
|
|
110
|
+
for (const [cmd, args] of commands) {
|
|
111
|
+
last = await io.sys.exec(cmd, args, { cwd: app.root, onLine });
|
|
112
|
+
if (last.code !== 0)
|
|
113
|
+
return last;
|
|
114
|
+
}
|
|
115
|
+
return last;
|
|
116
|
+
}
|
|
117
|
+
async function deploy(args, app, io) {
|
|
118
|
+
const { ui, sys } = io;
|
|
119
|
+
const d = remoteDeploy(app, io, "totem deploy");
|
|
120
|
+
if (!d)
|
|
121
|
+
return 1;
|
|
122
|
+
const extra = args.filter((a) => a !== "--");
|
|
123
|
+
if (!HOST_CLI[d.platform]) {
|
|
124
|
+
ui.error("totem can't deploy to a self-hosted server from here.", {
|
|
125
|
+
detail: "On its host: rebuild the image (docker build -t totem .) and start it again.",
|
|
126
|
+
});
|
|
127
|
+
return 1;
|
|
128
|
+
}
|
|
129
|
+
const cli = hostCli(io, d, "totem deploy");
|
|
130
|
+
if (!cli)
|
|
131
|
+
return 1;
|
|
132
|
+
const toml = d.platform === "fly" ? flyConfigPath(app.root, io.sys) : null;
|
|
133
|
+
const commands = deployCommands(d, extra, cli, toml);
|
|
134
|
+
ui.header("totem deploy", `Deploy this install's code to ${HOST_NAME[d.platform] ?? d.platform}${d.app ? ` (${d.app})` : ""}.`);
|
|
135
|
+
if (d.platform === "fly") {
|
|
136
|
+
if (toml && !/^\[mounts\]/m.test(readFileSync(toml, "utf8"))) {
|
|
137
|
+
ui.warn(`${tildify(toml, io.sys.home)} has no [mounts]: the server keeps its WHOOP login on the machine's own disk and loses it on every restart.`);
|
|
138
|
+
ui.para("To keep it, create a volume and mount it, then deploy again:", 2);
|
|
139
|
+
ui.code([`fly volumes create totem_data --app ${d.app ?? "<app>"} --size 1`, "", "[mounts]", ' source = "totem_data"', ' destination = "/data"']);
|
|
140
|
+
ui.line();
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
for (const [cmd, cmdArgs] of commands) {
|
|
144
|
+
ui.hint(`$ ${cmd} ${cmdArgs.join(" ")}`, 2);
|
|
145
|
+
const code = await sys.run(cmd, cmdArgs, { cwd: app.root });
|
|
146
|
+
if (code !== 0) {
|
|
147
|
+
ui.line();
|
|
148
|
+
ui.error(`${cmd} ${cmdArgs[0]} failed (exit ${code}). The server is unchanged.`, { fix: [["Try again", "totem deploy"], ["Read the server's logs", "totem logs"]] });
|
|
149
|
+
return code;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
ui.line();
|
|
153
|
+
ui.ok("Deployed");
|
|
154
|
+
ui.hint("Check it: totem status");
|
|
155
|
+
return 0;
|
|
156
|
+
}
|
|
157
|
+
async function logs(args, app, io) {
|
|
158
|
+
const { ui, sys } = io;
|
|
159
|
+
const d = remoteDeploy(app, io, "totem logs");
|
|
160
|
+
if (!d)
|
|
161
|
+
return 1;
|
|
162
|
+
const extra = args.filter((a) => a !== "--");
|
|
163
|
+
if (!HOST_CLI[d.platform]) {
|
|
164
|
+
ui.error("The logs of a self-hosted server are on its host.", { detail: "There: docker logs <container>" });
|
|
165
|
+
return 1;
|
|
166
|
+
}
|
|
167
|
+
const cli = hostCli(io, d, "totem logs");
|
|
168
|
+
if (!cli)
|
|
169
|
+
return 1;
|
|
170
|
+
switch (d.platform) {
|
|
171
|
+
case "fly":
|
|
172
|
+
return sys.run(cli, ["logs", ...(d.app ? ["-a", d.app] : []), ...extra], { cwd: app.root });
|
|
173
|
+
case "railway":
|
|
174
|
+
if (d.app)
|
|
175
|
+
await sys.run("railway", ["link", "--project", d.app], { cwd: app.root });
|
|
176
|
+
return sys.run("railway", ["logs", ...(d.service ? ["--service", d.service] : []), ...extra], { cwd: app.root });
|
|
177
|
+
case "cloudflare":
|
|
178
|
+
return sys.run("npx", [...WRANGLER, "tail", ...(d.app ? [d.app] : []), ...extra], { cwd: app.root });
|
|
179
|
+
case "cloudrun":
|
|
180
|
+
return sys.run("gcloud", ["run", "services", "logs", "read", d.app ?? "totem", "--region", d.region ?? "us-west1",
|
|
181
|
+
...(d.project ? ["--project", d.project] : []), ...extra], { cwd: app.root });
|
|
182
|
+
default:
|
|
183
|
+
return 1;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
/** One health check line. Returns whether the server answered. */
|
|
187
|
+
async function health(io, url) {
|
|
188
|
+
const { ui, sys } = io;
|
|
189
|
+
const r = await ui.task(`Asking ${url}`, () => sys.httpGet(`${url}/health`, 10_000));
|
|
190
|
+
if (r.status >= 200 && r.status < 300) {
|
|
191
|
+
let build = "";
|
|
192
|
+
try {
|
|
193
|
+
build = String(JSON.parse(r.body).build ?? "");
|
|
194
|
+
}
|
|
195
|
+
catch { /* not JSON */ }
|
|
196
|
+
ui.ok("The server is up", `answered in ${r.ms} ms${build ? `, build ${build}` : ""}`);
|
|
197
|
+
return true;
|
|
198
|
+
}
|
|
199
|
+
ui.fail("The server isn't answering", r.status ? `HTTP ${r.status} from /health` : r.error ?? "no answer");
|
|
200
|
+
return false;
|
|
201
|
+
}
|
|
202
|
+
async function ping(_args, app, io) {
|
|
203
|
+
const { ui } = io;
|
|
204
|
+
const d = remoteDeploy(app, io, "totem ping");
|
|
205
|
+
if (!d)
|
|
206
|
+
return 1;
|
|
207
|
+
if (!d.url) {
|
|
208
|
+
ui.error("No address is recorded for the server.", { fix: [["Set it up again", "totem cloud"]] });
|
|
209
|
+
return 1;
|
|
210
|
+
}
|
|
211
|
+
ui.header("totem ping");
|
|
212
|
+
if (await health(io, cleanUrl(d.url)))
|
|
213
|
+
return 0;
|
|
214
|
+
ui.rows([["Read its logs", ui.kit.c.accent("totem logs")], ["The full picture", ui.kit.c.accent("totem status")]], 2);
|
|
215
|
+
return 1;
|
|
216
|
+
}
|
|
217
|
+
async function status(args, app, io) {
|
|
218
|
+
const { ui, sys } = io;
|
|
219
|
+
const auth = io.auth ?? realAuthDeps;
|
|
220
|
+
const d = detectDeploy(app.root, sys);
|
|
221
|
+
ui.header("totem status");
|
|
222
|
+
const rows = [["Version", app.version], ["Install", tildify(app.root, sys.home)]];
|
|
223
|
+
if (!d) {
|
|
224
|
+
ui.rows(rows);
|
|
225
|
+
ui.line();
|
|
226
|
+
ui.problem("totem isn't set up yet.", { fix: NOT_SET_UP });
|
|
227
|
+
return 1;
|
|
228
|
+
}
|
|
229
|
+
const local = d.platform === "local";
|
|
230
|
+
rows.push(["Runs on", local ? "this computer, started by your AI client" : `${HOST_NAME[d.platform] ?? d.platform}${d.app && d.platform !== "custom" ? `, ${d.platform === "railway" ? "project" : d.platform === "cloudrun" ? "service" : d.platform === "cloudflare" ? "Worker" : "app"} ${d.app}` : ""}`]);
|
|
231
|
+
if (d.url)
|
|
232
|
+
rows.push(["Address", cleanUrl(d.url)]);
|
|
233
|
+
ui.rows(rows);
|
|
234
|
+
ui.line();
|
|
235
|
+
if (local) {
|
|
236
|
+
const built = existsSync(resolve(app.root, "dist", "server.js"));
|
|
237
|
+
if (built)
|
|
238
|
+
ui.ok("The server is built");
|
|
239
|
+
else
|
|
240
|
+
ui.problem("The server isn't built.", { fix: [["Build it", "totem build"]] });
|
|
241
|
+
const login = auth.readLocalStatus(resolveTokenFilePath(auth.cliEnv(resolve(app.root, ".env"))));
|
|
242
|
+
if (login.state === "tokens")
|
|
243
|
+
ui.ok("WHOOP login saved", `${when(login.savedAt)}${login.refreshedAt ? `, refreshed ${when(login.refreshedAt)}` : ""}`);
|
|
244
|
+
else
|
|
245
|
+
ui.problem(login.state === "unreadable" ? "The WHOOP login file can't be read." : "There is no WHOOP login on this computer.", { fix: [["Log in", "totem auth"]] });
|
|
246
|
+
return built && login.state === "tokens" ? 0 : 1;
|
|
247
|
+
}
|
|
248
|
+
if (args.includes("--host")) {
|
|
249
|
+
// The host's own view, in its own words.
|
|
250
|
+
const fly = ["fly", "flyctl"].find((n) => sys.has(n)) ?? "fly";
|
|
251
|
+
const view = d.platform === "fly" && d.app ? [fly, ["status", "-a", d.app]]
|
|
252
|
+
: d.platform === "railway" ? ["railway", ["service", "status", ...(d.service ? ["--service", d.service] : [])]]
|
|
253
|
+
: d.platform === "cloudflare" && d.app ? ["npx", [...WRANGLER, "deployments", "list", "--name", d.app]]
|
|
254
|
+
: d.platform === "cloudrun" && d.app ? ["gcloud", ["run", "services", "describe", d.app, "--region", d.region ?? "us-west1", ...(d.project ? ["--project", d.project] : []), "--format=value(status.url,status.latestReadyRevisionName)"]]
|
|
255
|
+
: null;
|
|
256
|
+
if (view) {
|
|
257
|
+
if (d.platform === "railway" && d.app)
|
|
258
|
+
await sys.run("railway", ["link", "--project", d.app], { cwd: app.root });
|
|
259
|
+
ui.hint(`$ ${view[0]} ${view[1].join(" ")}`, 2);
|
|
260
|
+
await sys.run(view[0], view[1], { cwd: app.root });
|
|
261
|
+
ui.line();
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
if (!d.url) {
|
|
265
|
+
ui.warn("No address is recorded for the server, so it can't be checked.");
|
|
266
|
+
return 0;
|
|
267
|
+
}
|
|
268
|
+
const up = await health(io, cleanUrl(d.url));
|
|
269
|
+
if (!up) {
|
|
270
|
+
ui.rows([["Read its logs", ui.kit.c.accent("totem logs")], ...(d.platform === "custom" ? [] : [["Deploy it again", ui.kit.c.accent("totem deploy")]])], 2);
|
|
271
|
+
return 1;
|
|
272
|
+
}
|
|
273
|
+
const token = d.mcp_auth_token;
|
|
274
|
+
if (!token) {
|
|
275
|
+
ui.info("WHOOP login: unknown from here", "totem has no MCP_AUTH_TOKEN recorded for this server");
|
|
276
|
+
return 0;
|
|
277
|
+
}
|
|
278
|
+
const r = await ui.task("Asking about its WHOOP login", () => auth.fetchRemoteStatus(cleanUrl(d.url), token));
|
|
279
|
+
if (!r.ok) {
|
|
280
|
+
ui.warn("Couldn't ask the server about its WHOOP login", r.detail || r.reason);
|
|
281
|
+
return 0;
|
|
282
|
+
}
|
|
283
|
+
const s = r.status;
|
|
284
|
+
if (s.state === "ok")
|
|
285
|
+
ui.ok("The server has a WHOOP login", s.refreshed_at ? `refreshed ${when(s.refreshed_at)}` : undefined);
|
|
286
|
+
else
|
|
287
|
+
ui.problem(`The server's WHOOP login is ${s.state ?? "missing"}.`, { detail: s.detail, fix: [["Log in again", "totem auth"]] });
|
|
288
|
+
if (s.durable === false)
|
|
289
|
+
ui.warn("Its token file isn't on a volume", "a restart loses the login");
|
|
290
|
+
return s.state === "ok" ? 0 : 1;
|
|
291
|
+
}
|
|
292
|
+
// ── tools ────────────────────────────────────────────────────────────────────
|
|
293
|
+
/** The tool names the server registers, read from the real registry. */
|
|
294
|
+
async function registeredTools() {
|
|
295
|
+
const { READ_TOOLS, WRITE_TOOLS } = await import("../tools/register.js");
|
|
296
|
+
const names = (registers) => {
|
|
297
|
+
const seen = [];
|
|
298
|
+
const recorder = { registerTool: (name) => { seen.push(name); } };
|
|
299
|
+
for (const register of registers)
|
|
300
|
+
register(recorder, {});
|
|
301
|
+
return seen;
|
|
302
|
+
};
|
|
303
|
+
return { read: names(READ_TOOLS), write: names(WRITE_TOOLS) };
|
|
304
|
+
}
|
|
305
|
+
export function toolsScreen(k, tools) {
|
|
306
|
+
const total = tools.read.length + tools.write.length;
|
|
307
|
+
const columnWidth = Math.max(...[...tools.read, ...tools.write].map((n) => n.length)) + 2;
|
|
308
|
+
const columns = Math.max(1, Math.floor((k.style.width - 2) / columnWidth));
|
|
309
|
+
const grid = (names) => {
|
|
310
|
+
const rows = [];
|
|
311
|
+
for (let i = 0; i < names.length; i += columns)
|
|
312
|
+
rows.push(" " + names.slice(i, i + columns).map((n) => padEnd(n, columnWidth)).join("").trimEnd());
|
|
313
|
+
return rows;
|
|
314
|
+
};
|
|
315
|
+
return [
|
|
316
|
+
"",
|
|
317
|
+
...k.header("totem tools", `${total} tools: ${tools.read.length} read your WHOOP data and ${tools.write.length} change it. A tool that changes something returns a preview and does nothing until the client confirms.`),
|
|
318
|
+
"",
|
|
319
|
+
...k.section(`Read ${k.c.dim(`(${tools.read.length})`)}`),
|
|
320
|
+
...grid(tools.read),
|
|
321
|
+
"",
|
|
322
|
+
...k.section(`Write ${k.c.dim(`(${tools.write.length})`)}`),
|
|
323
|
+
...grid(tools.write),
|
|
324
|
+
"",
|
|
325
|
+
...k.hint("What each one does: TOOLS.md", 0),
|
|
326
|
+
];
|
|
327
|
+
}
|
|
328
|
+
// ── token ────────────────────────────────────────────────────────────────────
|
|
329
|
+
async function token(args, app, io) {
|
|
330
|
+
const { ui, sys } = io;
|
|
331
|
+
const d = remoteDeploy(app, io, "totem token");
|
|
332
|
+
if (!d)
|
|
333
|
+
return 1;
|
|
334
|
+
if (!d.mcp_auth_token) {
|
|
335
|
+
ui.error("totem has no MCP_AUTH_TOKEN recorded for this server.", {
|
|
336
|
+
detail: "It is the MCP_AUTH_TOKEN secret on the host. totem records it the next time you log in.",
|
|
337
|
+
fix: [["Log in and record it", "totem auth"]],
|
|
338
|
+
});
|
|
339
|
+
return 1;
|
|
340
|
+
}
|
|
341
|
+
// The token is the server's master key. On a terminal it would stay in the
|
|
342
|
+
// scrollback, so it only prints into a pipe or a $(…) unless asked.
|
|
343
|
+
if (sys.tty && !args.includes("--show")) {
|
|
344
|
+
ui.error("totem token doesn't put the token on your screen.", {
|
|
345
|
+
detail: "It is the server's master key. Use it inside a command, where it is never displayed:",
|
|
346
|
+
fix: [["In a header", 'curl -H "Authorization: Bearer $(totem token)" <url>'], ["Show it anyway", "totem token --show"]],
|
|
347
|
+
});
|
|
348
|
+
return 1;
|
|
349
|
+
}
|
|
350
|
+
ui.line(d.mcp_auth_token);
|
|
351
|
+
return 0;
|
|
352
|
+
}
|
|
353
|
+
// ── running the server and dev tools ─────────────────────────────────────────
|
|
354
|
+
async function devTool(app, io, pkg, bin, args) {
|
|
355
|
+
const path = pkgBin(app.root, pkg, bin);
|
|
356
|
+
if (!path) {
|
|
357
|
+
io.ui.error(`${pkg} isn't installed in this install.`, { detail: "It is a development dependency: a source checkout has it after npm install.", fix: [["Install", "npm install"]] });
|
|
358
|
+
return 1;
|
|
359
|
+
}
|
|
360
|
+
return io.sys.run(io.sys.node, [path, ...args], { cwd: app.root });
|
|
361
|
+
}
|
|
362
|
+
const commands = {
|
|
363
|
+
cloud: {
|
|
364
|
+
group: "Set up",
|
|
365
|
+
summary: "Deploy your own server; connect claude.ai, ChatGPT and others",
|
|
366
|
+
usage: "totem cloud [--verbose]",
|
|
367
|
+
about: "Guides you through deploying totem to Cloudflare, Fly.io, Railway or your own Docker host: pick a host, confirm the plan, wait for the deploy, log in to WHOOP in a browser window, then connect your clients. Nothing is created before you confirm the plan.",
|
|
368
|
+
options: [["--verbose", "Show the host CLI's full output instead of one progress line"]],
|
|
369
|
+
examples: ["totem cloud"],
|
|
370
|
+
run: (args, app, io) => runCloudSetup(app.root, io, { verbose: args.includes("--verbose") }),
|
|
371
|
+
},
|
|
372
|
+
local: {
|
|
373
|
+
group: "Set up",
|
|
374
|
+
summary: "Run on this computer; set up the AI apps you have",
|
|
375
|
+
usage: "totem local",
|
|
376
|
+
about: "Sets totem up on this computer: builds the server if needed, logs you in to WHOOP in a browser window, and adds totem to the client you pick (Claude Desktop, Claude Code, Cursor, Codex, OpenCode and more). The client starts the server itself; nothing is hosted.",
|
|
377
|
+
examples: ["totem local"],
|
|
378
|
+
run: (_args, app, io) => runLocalSetup(app.root, io),
|
|
379
|
+
},
|
|
380
|
+
connect: {
|
|
381
|
+
group: "Set up",
|
|
382
|
+
summary: "Connect your apps, or show what to paste where",
|
|
383
|
+
usage: "totem connect [client] [--print]",
|
|
384
|
+
about: `With no client, shows how to connect every client to this install. With one, sets it up (a local install) or shows its steps (a deployed server). Clients: ${CLIENTS.map((c) => c.id).join(", ")}, other.`,
|
|
385
|
+
options: [["--print", "Show what to add instead of writing the client's config"]],
|
|
386
|
+
examples: ["totem connect", "totem connect cursor", "totem connect claude-code --print"],
|
|
387
|
+
run: (args, app, io) => runConnect(app.root, args, io),
|
|
388
|
+
},
|
|
389
|
+
auth: {
|
|
390
|
+
group: "Set up",
|
|
391
|
+
summary: "Log in to WHOOP, in a browser window",
|
|
392
|
+
usage: "totem auth [options]",
|
|
393
|
+
about: "Opens a browser window on WHOOP's site, where you log in yourself; totem never sees your password. The login is saved on this computer, or sent to your deployed server, which keeps it fresh from then on.",
|
|
394
|
+
options: [
|
|
395
|
+
["--status", "Show where the login lives and when it was last refreshed"],
|
|
396
|
+
["--paste", "Paste the whoop-auth-refresh-token cookie instead of using a browser"],
|
|
397
|
+
["--local", "Save on this computer even when a server is set up"],
|
|
398
|
+
["--url <url>", "Send the login to the totem server at <url>"],
|
|
399
|
+
["--allow-http", "Let --url be plain http (a private network you trust)"],
|
|
400
|
+
["--browser <path>", "Use this browser"],
|
|
401
|
+
],
|
|
402
|
+
env: [
|
|
403
|
+
["TOTEM_TOKEN_FILE", "Where the login is kept on this computer"],
|
|
404
|
+
["TOTEM_BROWSER", "Path of the browser to use"],
|
|
405
|
+
["TOTEM_ADMIN_TOKEN", "The server's MCP_AUTH_TOKEN, when totem has none recorded"],
|
|
406
|
+
],
|
|
407
|
+
examples: ["totem auth", "totem auth --status", "TOTEM_ADMIN_TOKEN=<token> totem auth --url https://totem.example.com"],
|
|
408
|
+
run: (args, app, io) => runAuth(app.root, args, {}, io),
|
|
409
|
+
},
|
|
410
|
+
status: {
|
|
411
|
+
group: "Run and maintain",
|
|
412
|
+
summary: "Show how this install, its server and its login are doing",
|
|
413
|
+
usage: "totem status [--host]",
|
|
414
|
+
about: "Shows the version, where totem runs, whether the server answers, and whether it has a WHOOP login. Exits non-zero when something needs attention.",
|
|
415
|
+
options: [["--host", "Also show the host's own view (on Fly: fly status)"]],
|
|
416
|
+
run: status,
|
|
417
|
+
},
|
|
418
|
+
ping: {
|
|
419
|
+
group: "Run and maintain",
|
|
420
|
+
summary: "Check that the server answers",
|
|
421
|
+
usage: "totem ping",
|
|
422
|
+
about: "Requests /health from the deployed server and reports the answer.",
|
|
423
|
+
run: ping,
|
|
424
|
+
},
|
|
425
|
+
logs: {
|
|
426
|
+
group: "Run and maintain",
|
|
427
|
+
summary: "Show the server's logs",
|
|
428
|
+
usage: "totem logs [-- <host options>]",
|
|
429
|
+
about: "Runs the host's log command for your server (fly logs, railway logs, wrangler tail). Anything after -- goes to that command.",
|
|
430
|
+
run: logs,
|
|
431
|
+
},
|
|
432
|
+
deploy: {
|
|
433
|
+
group: "Run and maintain",
|
|
434
|
+
summary: "Deploy this install's code to the server again",
|
|
435
|
+
usage: "totem deploy [-- <host options>]",
|
|
436
|
+
about: "Builds and deploys the code in this install to the server set up by totem cloud. Secrets and the WHOOP login stay as they are. Anything after -- goes to the host's deploy command.",
|
|
437
|
+
run: deploy,
|
|
438
|
+
},
|
|
439
|
+
update: {
|
|
440
|
+
group: "Run and maintain",
|
|
441
|
+
summary: "Update totem; --check, --auto on|off",
|
|
442
|
+
usage: "totem update [--check | --auto on|off]",
|
|
443
|
+
about: "Installs a release: pick one (the newest is first), and totem installs it, rebuilds, deploys it to your server and checks the server answers. If a step fails it goes back to the version you had.",
|
|
444
|
+
options: [
|
|
445
|
+
["--check", "Only show the installed and the latest version"],
|
|
446
|
+
["--auto on", "Install new releases automatically, checking every 6 hours"],
|
|
447
|
+
["--auto off", "Stop installing them automatically"],
|
|
448
|
+
],
|
|
449
|
+
examples: ["totem update", "totem update --check"],
|
|
450
|
+
run: (args, app, io) => runUpdate(args, {
|
|
451
|
+
root: app.root, version: app.version, pkgPath: app.pkgPath, pkgName: app.pkgName, cliEntry: app.cliEntry,
|
|
452
|
+
isGit: existsSync(resolve(app.root, ".git")),
|
|
453
|
+
detectDeploy: () => detectDeploy(app.root, io.sys),
|
|
454
|
+
redeploy: (onLine) => redeployCaptured(app, io, onLine),
|
|
455
|
+
}, io),
|
|
456
|
+
},
|
|
457
|
+
tools: {
|
|
458
|
+
group: "Run and maintain",
|
|
459
|
+
summary: "List the tools the server gives a client",
|
|
460
|
+
usage: "totem tools",
|
|
461
|
+
about: "Lists the MCP tools by name: the ones that read your WHOOP data and the ones that change it.",
|
|
462
|
+
run: async (_args, _app, io) => { io.ui.lines(toolsScreen(io.ui.kit, await registeredTools())); return 0; },
|
|
463
|
+
},
|
|
464
|
+
token: {
|
|
465
|
+
group: "Run and maintain",
|
|
466
|
+
summary: "Print the server's MCP_AUTH_TOKEN, for use in a command",
|
|
467
|
+
usage: "totem token [--show]",
|
|
468
|
+
about: "Prints the deployed server's MCP_AUTH_TOKEN so a command can use it without the token appearing on screen: --header \"Authorization: Bearer $(totem token)\". On a terminal it prints only with --show.",
|
|
469
|
+
options: [["--show", "Print it even to a terminal"]],
|
|
470
|
+
run: token,
|
|
471
|
+
},
|
|
472
|
+
start: {
|
|
473
|
+
group: "Develop",
|
|
474
|
+
summary: "Start the MCP server (stdio; --http for HTTP)",
|
|
475
|
+
usage: "totem start [--http]",
|
|
476
|
+
about: "Starts the built server. Over stdio it is what a local client runs. With --http it listens on PORT (default 3000) and needs MCP_AUTH_TOKEN set to at least 32 characters.",
|
|
477
|
+
options: [["--http", "Serve over HTTP instead of stdio"]],
|
|
478
|
+
run: async (args, app, io) => {
|
|
479
|
+
const serverJs = resolve(app.root, "dist", "server.js");
|
|
480
|
+
if (!existsSync(serverJs)) {
|
|
481
|
+
io.ui.error("The server isn't built yet.", { fix: [["Build it", "totem build"]] });
|
|
482
|
+
return 1;
|
|
483
|
+
}
|
|
484
|
+
return io.sys.run(io.sys.node, [serverJs], { cwd: app.root, env: { ...io.sys.env, MCP_TRANSPORT: args.includes("--http") ? "http" : "stdio" } });
|
|
485
|
+
},
|
|
486
|
+
},
|
|
487
|
+
dev: {
|
|
488
|
+
group: "Develop",
|
|
489
|
+
summary: "Start the server from source (--http for HTTP)",
|
|
490
|
+
usage: "totem dev [--http]",
|
|
491
|
+
about: "Starts the server from the TypeScript source when this is a source checkout (no rebuild needed), else from the build.",
|
|
492
|
+
options: [["--http", "Serve over HTTP instead of stdio"]],
|
|
493
|
+
run: async (args, app, io) => {
|
|
494
|
+
const script = scriptCommand(app.root, "server", true);
|
|
495
|
+
if (!script) {
|
|
496
|
+
io.ui.error("There is no server to start: no build and no source checkout.", { fix: [["Install and build", "npm install && totem build"]] });
|
|
497
|
+
return 1;
|
|
498
|
+
}
|
|
499
|
+
return io.sys.run(io.sys.node, script, { cwd: app.root, env: args.includes("--http") ? { ...io.sys.env, MCP_TRANSPORT: "http" } : io.sys.env });
|
|
500
|
+
},
|
|
501
|
+
},
|
|
502
|
+
build: {
|
|
503
|
+
group: "Develop",
|
|
504
|
+
summary: "Compile the TypeScript source to dist/",
|
|
505
|
+
usage: "totem build",
|
|
506
|
+
about: "Runs the TypeScript compiler over src/.",
|
|
507
|
+
run: (args, app, io) => devTool(app, io, "typescript", "tsc", args),
|
|
508
|
+
},
|
|
509
|
+
test: {
|
|
510
|
+
group: "Develop",
|
|
511
|
+
summary: "Run the tests",
|
|
512
|
+
usage: "totem test [filter]",
|
|
513
|
+
about: "Runs the test suite with vitest. A filter runs only the test files whose path matches.",
|
|
514
|
+
run: (args, app, io) => devTool(app, io, "vitest", "vitest", ["run", ...args]),
|
|
515
|
+
},
|
|
516
|
+
typecheck: {
|
|
517
|
+
group: "Develop",
|
|
518
|
+
summary: "Check types without building",
|
|
519
|
+
usage: "totem typecheck",
|
|
520
|
+
about: "Runs the TypeScript compiler with --noEmit.",
|
|
521
|
+
run: (args, app, io) => devTool(app, io, "typescript", "tsc", ["--noEmit", ...args]),
|
|
522
|
+
},
|
|
523
|
+
};
|
|
524
|
+
/** Other names for a command: old ones kept working, and the usual flags. */
|
|
525
|
+
const ALIASES = {
|
|
526
|
+
info: ["status"],
|
|
527
|
+
config: ["connect"],
|
|
528
|
+
"dev:http": ["dev", "--http"],
|
|
529
|
+
};
|
|
530
|
+
/**
|
|
531
|
+
* A table's own entry for what was typed. `commands[name]` alone also finds
|
|
532
|
+
* what every object inherits: `totem constructor` and `totem toString` were
|
|
533
|
+
* "commands" with nothing to run, and crashed with a TypeError.
|
|
534
|
+
*/
|
|
535
|
+
const own = (table, key) => (Object.hasOwn(table, key) ? table[key] : undefined);
|
|
536
|
+
// ── help ─────────────────────────────────────────────────────────────────────
|
|
537
|
+
const TAGLINE = "Your WHOOP data in Claude, ChatGPT and other AI apps, over MCP.";
|
|
538
|
+
/** Commands as a two-column table: the command in its colour, what it does beside it. */
|
|
539
|
+
function commandRows(k, entries, nameWidth) {
|
|
540
|
+
const w = nameWidth ?? Math.max(...entries.map(([n]) => n.length)) + 3;
|
|
541
|
+
const room = k.style.width - 2 - w;
|
|
542
|
+
return entries.flatMap(([name, summary]) => wrap(summary, room).map((line, i) => ` ${i === 0 ? k.c.accent(padEnd(name, w)) : " ".repeat(w)}${line}`));
|
|
543
|
+
}
|
|
544
|
+
/** "totem 2.0.0" and the tagline. */
|
|
545
|
+
const totemTitle = (k, version) => {
|
|
546
|
+
const [first, ...rest] = k.header("totem", TAGLINE);
|
|
547
|
+
return [`${first} ${k.c.dim(version)}`, ...rest];
|
|
548
|
+
};
|
|
549
|
+
export function helpScreen(k, app) {
|
|
550
|
+
const lines = ["", ...totemTitle(k, app.version), "", `${k.c.bold("Usage:")} totem <command> [options]`];
|
|
551
|
+
// One column width for every group, so the summaries line up down the page.
|
|
552
|
+
const nameWidth = Math.max(...Object.keys(commands).map((n) => n.length)) + 3;
|
|
553
|
+
for (const group of GROUPS) {
|
|
554
|
+
lines.push("", ...k.section(group));
|
|
555
|
+
lines.push(...commandRows(k, Object.entries(commands).filter(([, cmd]) => cmd.group === group).map(([name, cmd]) => [name, cmd.summary]), nameWidth));
|
|
556
|
+
}
|
|
557
|
+
lines.push("", ...k.section("Options"));
|
|
558
|
+
const flags = [["-h, --help", "Show this; totem <command> --help for one command"], ["-v, --version", "Print the version"], ["--no-color", "Plain output (NO_COLOR=1 does the same)"]];
|
|
559
|
+
lines.push(...flags.flatMap(([flag, text]) => wrap(text, k.style.width - 2 - 16).map((line, i) => ` ${i === 0 ? padEnd(flag, 16) : " ".repeat(16)}${line}`)));
|
|
560
|
+
lines.push("", `New here? Start with ${k.c.accent("totem cloud")}`, "");
|
|
561
|
+
return lines;
|
|
562
|
+
}
|
|
563
|
+
export function commandHelp(k, name) {
|
|
564
|
+
const cmd = own(commands, name);
|
|
565
|
+
if (!cmd)
|
|
566
|
+
return null;
|
|
567
|
+
const table = (pairs) => {
|
|
568
|
+
const w = Math.max(...pairs.map(([a]) => a.length)) + 3;
|
|
569
|
+
return pairs.flatMap(([a, b]) => wrap(b, k.style.width - 2 - w).map((line, i) => ` ${i === 0 ? padEnd(a, w) : " ".repeat(w)}${line}`));
|
|
570
|
+
};
|
|
571
|
+
const lines = ["", ...k.header(`totem ${name}`), ...k.para(cmd.about), "", `${k.c.bold("Usage:")} ${cmd.usage}`];
|
|
572
|
+
if (cmd.options?.length)
|
|
573
|
+
lines.push("", ...k.section("Options"), ...table(cmd.options));
|
|
574
|
+
if (cmd.env?.length)
|
|
575
|
+
lines.push("", ...k.section("Environment"), ...table(cmd.env));
|
|
576
|
+
if (cmd.examples?.length)
|
|
577
|
+
lines.push("", ...k.section("Examples"), ...k.code(cmd.examples));
|
|
578
|
+
lines.push("");
|
|
579
|
+
return lines;
|
|
580
|
+
}
|
|
581
|
+
/** Bare `totem`: the logo, where this install stands, and the commands that matter from here. */
|
|
582
|
+
export function homeScreen(k, app, state) {
|
|
583
|
+
const top = k.logo ? ["", ...k.banner("totem", TAGLINE, `version ${app.version}`)] : ["", ...totemTitle(k, app.version)];
|
|
584
|
+
const summary = (name) => [`totem ${name}`, commands[name].summary];
|
|
585
|
+
const d = state.deploy;
|
|
586
|
+
const body = [""];
|
|
587
|
+
if (!d) {
|
|
588
|
+
body.push(...k.section("Get started"), ...commandRows(k, [summary("cloud"), summary("local")]));
|
|
589
|
+
}
|
|
590
|
+
else if (d.platform === "local") {
|
|
591
|
+
body.push(...k.section("Runs on this computer"));
|
|
592
|
+
if (state.login?.state === "tokens")
|
|
593
|
+
body.push(...k.mark("ok", "WHOOP login saved", when(state.login.savedAt)));
|
|
594
|
+
else
|
|
595
|
+
body.push(...k.mark("warn", "No WHOOP login on this computer", "totem auth"));
|
|
596
|
+
body.push("", ...commandRows(k, [summary("connect"), summary("status"), summary("update")]));
|
|
597
|
+
}
|
|
598
|
+
else {
|
|
599
|
+
body.push(...k.section(`Runs on ${HOST_NAME[d.platform] ?? d.platform}${d.app && d.platform !== "custom" ? ` ${k.c.dim(`(${d.app})`)}` : ""}`));
|
|
600
|
+
if (d.url)
|
|
601
|
+
body.push(` ${k.c.link(cleanUrl(d.url))}`);
|
|
602
|
+
body.push("", ...commandRows(k, [summary("status"), summary("connect"), summary("logs"), summary("update")]));
|
|
603
|
+
}
|
|
604
|
+
return [...top, ...body, "", `Every command: ${k.c.accent("totem help")}`, ""];
|
|
605
|
+
}
|
|
606
|
+
/** The command a mistyped one most likely meant, if one is close. */
|
|
607
|
+
export function nearest(name) {
|
|
608
|
+
const names = [...Object.keys(commands), ...Object.keys(ALIASES)];
|
|
609
|
+
const distance = (a, b) => {
|
|
610
|
+
const row = Array.from({ length: b.length + 1 }, (_, i) => i);
|
|
611
|
+
for (let i = 1; i <= a.length; i++) {
|
|
612
|
+
let prev = row[0];
|
|
613
|
+
row[0] = i;
|
|
614
|
+
for (let j = 1; j <= b.length; j++) {
|
|
615
|
+
const tmp = row[j];
|
|
616
|
+
row[j] = Math.min(row[j] + 1, row[j - 1] + 1, prev + (a[i - 1] === b[j - 1] ? 0 : 1));
|
|
617
|
+
prev = tmp;
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
return row[b.length];
|
|
621
|
+
};
|
|
622
|
+
const prefixed = names.find((n) => n.startsWith(name) && name.length >= 2);
|
|
623
|
+
if (prefixed)
|
|
624
|
+
return prefixed;
|
|
625
|
+
const [best] = names.map((n) => [n, distance(name, n)]).sort((a, b) => a[1] - b[1]);
|
|
626
|
+
return best && best[1] <= 2 ? best[0] : null;
|
|
627
|
+
}
|
|
628
|
+
// ── entry ────────────────────────────────────────────────────────────────────
|
|
629
|
+
export async function runCli(argv, app, io) {
|
|
630
|
+
const { ui } = io;
|
|
631
|
+
let [name, ...args] = argv;
|
|
632
|
+
if (name === undefined) {
|
|
633
|
+
const deploy = detectDeploy(app.root, io.sys);
|
|
634
|
+
const auth = io.auth ?? realAuthDeps;
|
|
635
|
+
const login = deploy?.platform === "local" ? auth.readLocalStatus(resolveTokenFilePath(auth.cliEnv(resolve(app.root, ".env")))) : undefined;
|
|
636
|
+
ui.lines(homeScreen(ui.kit, app, { deploy, login }));
|
|
637
|
+
return 0;
|
|
638
|
+
}
|
|
639
|
+
if (name === "help" || name === "-h" || name === "--help") {
|
|
640
|
+
const topic = name === "help" ? args[0] : undefined;
|
|
641
|
+
if (topic) {
|
|
642
|
+
const help = commandHelp(ui.kit, own(ALIASES, topic)?.[0] ?? topic);
|
|
643
|
+
if (help) {
|
|
644
|
+
ui.lines(help);
|
|
645
|
+
return 0;
|
|
646
|
+
}
|
|
647
|
+
name = topic; // falls through to "unknown command"
|
|
648
|
+
}
|
|
649
|
+
else {
|
|
650
|
+
ui.lines(helpScreen(ui.kit, app));
|
|
651
|
+
return 0;
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
if (name === "version" || name === "-v" || name === "--version") {
|
|
655
|
+
ui.line(app.version);
|
|
656
|
+
return 0;
|
|
657
|
+
}
|
|
658
|
+
const alias = own(ALIASES, name);
|
|
659
|
+
if (alias) {
|
|
660
|
+
name = alias[0];
|
|
661
|
+
args = [...alias.slice(1), ...args];
|
|
662
|
+
}
|
|
663
|
+
const cmd = own(commands, name);
|
|
664
|
+
if (!cmd) {
|
|
665
|
+
const close = nearest(name);
|
|
666
|
+
ui.error(`"${name}" isn't a totem command.`, { fix: [...(close ? [["Did you mean", `totem ${close}`]] : []), ["See them all", "totem help"]] });
|
|
667
|
+
return 2;
|
|
668
|
+
}
|
|
669
|
+
if (args.includes("--help") || args.includes("-h")) {
|
|
670
|
+
ui.lines(commandHelp(ui.kit, name));
|
|
671
|
+
return 0;
|
|
672
|
+
}
|
|
673
|
+
return cmd.run(args, app, io);
|
|
674
|
+
}
|
|
675
|
+
//# sourceMappingURL=app.js.map
|