@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/update.js
CHANGED
|
@@ -1,45 +1,51 @@
|
|
|
1
|
-
// `totem update
|
|
1
|
+
// `totem update`: the updater.
|
|
2
2
|
//
|
|
3
|
-
//
|
|
4
|
-
// totem update
|
|
5
|
-
//
|
|
6
|
-
//
|
|
7
|
-
// totem update --auto
|
|
8
|
-
// totem update --auto off → remove it
|
|
9
|
-
// totem update --check → non-interactive: print installed-vs-latest + auto state
|
|
10
|
-
// totem update --auto-run → internal: the scheduled job's non-interactive apply
|
|
3
|
+
// totem update pick a version (newest first), install it, redeploy
|
|
4
|
+
// totem update --check installed vs latest, and whether auto-update is on
|
|
5
|
+
// totem update --auto on install new releases automatically (launchd / cron)
|
|
6
|
+
// totem update --auto off stop doing that
|
|
7
|
+
// totem update --auto-run internal: what the scheduled job runs
|
|
11
8
|
//
|
|
12
|
-
// Version index: every release is a git tag (git installs)
|
|
13
|
-
// installs); GitHub Releases supplies the
|
|
14
|
-
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
9
|
+
// Version index: every release is a git tag (git installs) and an npm version
|
|
10
|
+
// (npm installs); GitHub Releases supplies the dates and notes in the picker.
|
|
11
|
+
import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
12
|
+
import { delimiter as pathDelimiter, dirname, resolve } from "node:path";
|
|
13
|
+
import { lastLine, tildify } from "./clients.js";
|
|
14
|
+
import { configFile, dockerBuildArgs } from "./deploy_record.js";
|
|
15
|
+
import { pkgBin } from "./spawn.js";
|
|
16
|
+
import { realIo } from "./sys.js";
|
|
17
|
+
import { duration, listOf, shellLines, shellPath } from "./ui.js";
|
|
18
18
|
const AUTO_LABEL = "com.totem.autoupdate";
|
|
19
|
-
const AUTO_INTERVAL_SEC = 6 * 60 * 60; //
|
|
19
|
+
const AUTO_INTERVAL_SEC = 6 * 60 * 60; // there is no push channel to a user's machine: poll
|
|
20
20
|
const cleanUrl = (u) => u.replace(/\/+$/, "");
|
|
21
|
-
const home = () => process.env.HOME ?? process.env.USERPROFILE ?? "~";
|
|
22
21
|
const autoLogPath = (root) => resolve(root, ".totem-autoupdate.log");
|
|
22
|
+
const HOST_NAME = { fly: "Fly", railway: "Railway", cloudflare: "Cloudflare", cloudrun: "Cloud Run" };
|
|
23
23
|
// ── semver ────────────────────────────────────────────────────────────────
|
|
24
|
-
// Compare two x.y.z strings (leading "v" ignored). -1 / 0 / 1.
|
|
24
|
+
// Compare two x.y.z[-pre] strings (leading "v" ignored). -1 / 0 / 1. A
|
|
25
|
+
// prerelease sorts below its release (1.6.0-rc.1 < 1.6.0).
|
|
25
26
|
export function compareSemver(a, b) {
|
|
26
|
-
const
|
|
27
|
-
const
|
|
27
|
+
const [coreA = "", preA = ""] = a.replace(/^v/, "").split(/-(.*)/s);
|
|
28
|
+
const [coreB = "", preB = ""] = b.replace(/^v/, "").split(/-(.*)/s);
|
|
29
|
+
const pa = coreA.split(".").map((n) => parseInt(n, 10) || 0);
|
|
30
|
+
const pb = coreB.split(".").map((n) => parseInt(n, 10) || 0);
|
|
28
31
|
for (let i = 0; i < 3; i++) {
|
|
29
32
|
const d = (pa[i] ?? 0) - (pb[i] ?? 0);
|
|
30
33
|
if (d !== 0)
|
|
31
34
|
return d < 0 ? -1 : 1;
|
|
32
35
|
}
|
|
33
|
-
|
|
36
|
+
if (preA === preB)
|
|
37
|
+
return 0;
|
|
38
|
+
if (!preA)
|
|
39
|
+
return 1;
|
|
40
|
+
if (!preB)
|
|
41
|
+
return -1;
|
|
42
|
+
return Math.sign(preA.localeCompare(preB, "en", { numeric: true }));
|
|
34
43
|
}
|
|
44
|
+
// Only plain x.y.z releases are installable — never prereleases.
|
|
45
|
+
export const isRelease = (v) => /^\d+\.\d+\.\d+$/.test(v);
|
|
35
46
|
export function isNewer(candidate, current) {
|
|
36
47
|
return compareSemver(candidate, current) > 0;
|
|
37
48
|
}
|
|
38
|
-
// The last meaningful line of captured output, for surfacing a failure reason.
|
|
39
|
-
function lastLine(r) {
|
|
40
|
-
const lines = (r.stderr + "\n" + r.stdout).split("\n").map((l) => l.trim()).filter(Boolean);
|
|
41
|
-
return lines.length ? lines[lines.length - 1] : "";
|
|
42
|
-
}
|
|
43
49
|
// owner/repo for the GitHub Releases API, parsed from package.json repository.url.
|
|
44
50
|
function repoSlug(pkgPath) {
|
|
45
51
|
try {
|
|
@@ -52,8 +58,8 @@ function repoSlug(pkgPath) {
|
|
|
52
58
|
return null;
|
|
53
59
|
}
|
|
54
60
|
}
|
|
55
|
-
//
|
|
56
|
-
//
|
|
61
|
+
// Notes and dates from the GitHub Releases API. Best-effort: without them the
|
|
62
|
+
// picker shows bare versions.
|
|
57
63
|
export function parseReleases(json) {
|
|
58
64
|
const out = new Map();
|
|
59
65
|
try {
|
|
@@ -70,30 +76,23 @@ export function parseReleases(json) {
|
|
|
70
76
|
catch { /* leave empty */ }
|
|
71
77
|
return out;
|
|
72
78
|
}
|
|
73
|
-
|
|
79
|
+
// The installable versions for THIS install type, newest first, with notes.
|
|
80
|
+
async function fetchVersions(ctx, io) {
|
|
81
|
+
const { sys } = io;
|
|
74
82
|
const slug = repoSlug(ctx.pkgPath);
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
// GitHub's API requires a User-Agent — httpGet sends one ("totem-setup").
|
|
78
|
-
const r = await httpGet(`https://api.github.com/repos/${slug}/releases?per_page=100`, 8000);
|
|
79
|
-
return r.status === 200 ? parseReleases(r.body) : new Map();
|
|
80
|
-
}
|
|
81
|
-
// The installable versions for THIS install type, newest first, enriched with notes.
|
|
82
|
-
async function fetchVersions(ctx) {
|
|
83
|
-
const notes = await fetchReleaseNotes(ctx);
|
|
83
|
+
const releases = slug ? await sys.httpGet(`https://api.github.com/repos/${slug}/releases?per_page=100`, 8000) : null;
|
|
84
|
+
const notes = releases?.status === 200 ? parseReleases(releases.body) : new Map();
|
|
84
85
|
let versions = [];
|
|
85
86
|
const commitDates = new Map();
|
|
86
87
|
if (ctx.isGit) {
|
|
87
|
-
await
|
|
88
|
-
const out =
|
|
88
|
+
await sys.exec("git", ["fetch", "--tags", "--quiet", "origin"], { cwd: ctx.root });
|
|
89
|
+
const out = (await sys.exec("git", ["tag", "--sort=-v:refname"], { cwd: ctx.root })).stdout;
|
|
89
90
|
versions = out.split("\n").map((s) => s.trim()).filter((t) => /^v\d+\.\d+\.\d+$/.test(t)).map((t) => t.replace(/^v/, ""));
|
|
90
|
-
// Date a version by when its
|
|
91
|
-
//
|
|
92
|
-
//
|
|
93
|
-
//
|
|
94
|
-
|
|
95
|
-
// commit date in both shapes.
|
|
96
|
-
const dates = capture("git", ["for-each-ref", "--format=%(refname:short) %(*committerdate:short) %(committerdate:short)", "refs/tags"], { cwd: ctx.root }).stdout;
|
|
91
|
+
// Date a version by when its code was committed, not when the GitHub
|
|
92
|
+
// release was published: a tag added later would show out of order.
|
|
93
|
+
// `*committerdate` dereferences an annotated tag; the plain one covers a
|
|
94
|
+
// lightweight tag. The first date after the ref is the commit's either way.
|
|
95
|
+
const dates = (await sys.exec("git", ["for-each-ref", "--format=%(refname:short) %(*committerdate:short) %(committerdate:short)", "refs/tags"], { cwd: ctx.root })).stdout;
|
|
97
96
|
for (const line of dates.split("\n")) {
|
|
98
97
|
const m = line.trim().match(/^v(\d+\.\d+\.\d+)\s+(\d{4}-\d{2}-\d{2})/);
|
|
99
98
|
if (m)
|
|
@@ -101,10 +100,10 @@ async function fetchVersions(ctx) {
|
|
|
101
100
|
}
|
|
102
101
|
}
|
|
103
102
|
else {
|
|
104
|
-
const out =
|
|
103
|
+
const out = (await sys.exec("npm", ["view", ctx.pkgName, "versions", "--json"])).stdout.trim();
|
|
105
104
|
try {
|
|
106
105
|
const parsed = JSON.parse(out);
|
|
107
|
-
versions = Array.isArray(parsed) ? parsed : [parsed];
|
|
106
|
+
versions = (Array.isArray(parsed) ? parsed : [parsed]).filter(isRelease);
|
|
108
107
|
}
|
|
109
108
|
catch {
|
|
110
109
|
versions = [];
|
|
@@ -113,143 +112,193 @@ async function fetchVersions(ctx) {
|
|
|
113
112
|
versions = [...new Set(versions)].sort((a, b) => compareSemver(b, a));
|
|
114
113
|
return versions.map((v) => ({ version: v, tag: `v${v}`, date: commitDates.get(v) ?? notes.get(v)?.date, notes: notes.get(v)?.notes }));
|
|
115
114
|
}
|
|
116
|
-
// ──
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
115
|
+
// ── applying a version ───────────────────────────────────────────────────────
|
|
116
|
+
const tail = (r, lines = 6) => `${r.stdout}\n${r.stderr}`.split("\n").map((l) => l.trimEnd()).filter((l) => l.trim() !== "").slice(-lines);
|
|
117
|
+
const RETRY = ["Try again", "totem update"];
|
|
118
|
+
/**
|
|
119
|
+
* One captured step: spinner while it runs, then ✓ with how long it took, or
|
|
120
|
+
* why it failed. `retry` adds the command to run again (left off when a
|
|
121
|
+
* rollback follows and says it after).
|
|
122
|
+
*/
|
|
123
|
+
async function staged(io, label, done, run, opts = {}) {
|
|
124
|
+
const { ui, sys } = io;
|
|
125
|
+
const started = sys.now();
|
|
126
|
+
const r = await ui.task(label, run, { slow: Boolean(opts.slow) });
|
|
121
127
|
if (r.code === 0) {
|
|
122
|
-
|
|
128
|
+
ui.ok(done, duration(sys.now() - started));
|
|
123
129
|
return true;
|
|
124
130
|
}
|
|
125
|
-
|
|
126
|
-
const why = lastLine(r);
|
|
127
|
-
if (why)
|
|
128
|
-
console.log(c.gray(` ${why}`));
|
|
131
|
+
ui.problem(`${label} failed.`, { detail: tail(r), fix: opts.retry ? [RETRY] : undefined });
|
|
129
132
|
return false;
|
|
130
133
|
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
134
|
+
/**
|
|
135
|
+
* Install `target`, rebuild, and bring the server along. A git install checks
|
|
136
|
+
* out the release tag (never `main`); an npm install reinstalls that version.
|
|
137
|
+
*/
|
|
138
|
+
export async function applyVersion(ctx, target, io = realIo()) {
|
|
139
|
+
const { ui, sys } = io;
|
|
140
|
+
const d = ctx.detectDeploy();
|
|
141
|
+
const remote = d && d.platform !== "local" ? d : null;
|
|
142
|
+
const total = remote ? 2 : 1;
|
|
143
|
+
const heading = (n, title) => (total > 1 ? ui.step(n, total, title) : ui.section(title));
|
|
144
|
+
// Undo for a git install (set once the checkout is about to move). An npm
|
|
145
|
+
// install has nothing to undo: a failed `npm install -g` leaves the old one.
|
|
146
|
+
let rollback = async () => { };
|
|
147
|
+
heading(1, `Install ${target.version}`);
|
|
135
148
|
if (ctx.isGit) {
|
|
136
|
-
// Never clobber
|
|
137
|
-
// dist/, fly.toml) don't block a checkout
|
|
138
|
-
const dirty =
|
|
149
|
+
// Never clobber local edits to tracked files (a dev checkout). Untracked
|
|
150
|
+
// files (.env, dist/, fly.toml) don't block a checkout.
|
|
151
|
+
const dirty = (await sys.exec("git", ["status", "--porcelain", "--untracked-files=no"], { cwd: ctx.root })).stdout.trim();
|
|
139
152
|
if (dirty) {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
153
|
+
ui.problem("This checkout has uncommitted changes to tracked files.", {
|
|
154
|
+
detail: dirty.split("\n").slice(0, 5),
|
|
155
|
+
fix: [["Commit or stash them, then", "totem update"]],
|
|
156
|
+
});
|
|
157
|
+
return "failed";
|
|
143
158
|
}
|
|
144
|
-
if (!(await staged("
|
|
145
|
-
return
|
|
146
|
-
if
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
159
|
+
if (!(await staged(io, "Fetching releases", "Releases fetched", () => sys.exec("git", ["fetch", "--tags", "--quiet", "origin"], { cwd: ctx.root }), { retry: true })))
|
|
160
|
+
return "failed";
|
|
161
|
+
// Where to go back to if the update doesn't finish: the branch when on one,
|
|
162
|
+
// else the commit (a release tag is a detached checkout).
|
|
163
|
+
const previous = (await sys.exec("git", ["symbolic-ref", "--short", "-q", "HEAD"], { cwd: ctx.root })).stdout.trim()
|
|
164
|
+
|| (await sys.exec("git", ["rev-parse", "HEAD"], { cwd: ctx.root })).stdout.trim();
|
|
165
|
+
// `npm install` may rewrite package-lock.json (another npm version writes it
|
|
166
|
+
// its own way). The tracked tree was clean when this began, so that change
|
|
167
|
+
// is npm's, not the person's. Left there, git refuses the checkout that
|
|
168
|
+
// goes back to the old version ("local changes would be overwritten": the
|
|
169
|
+
// lock differs between any two releases), and after a good update the next
|
|
170
|
+
// one stops at "uncommitted changes". Put the committed file back.
|
|
171
|
+
const install = async (onLine) => {
|
|
172
|
+
const r = await sys.exec("npm", ["install"], { cwd: ctx.root, onLine });
|
|
173
|
+
await sys.exec("git", ["checkout", "--quiet", "--", "package-lock.json"], { cwd: ctx.root });
|
|
174
|
+
return r;
|
|
175
|
+
};
|
|
176
|
+
const build = async (onLine) => {
|
|
177
|
+
const tsc = pkgBin(ctx.root, "typescript", "tsc");
|
|
178
|
+
return tsc ? sys.exec(sys.node, [tsc], { cwd: ctx.root, onLine }) : { code: 1, stdout: "", stderr: "typescript isn't installed in node_modules" };
|
|
179
|
+
};
|
|
180
|
+
// A half-applied update must not stay: the checkout has already moved
|
|
181
|
+
// package.json to the new version, so the next check would read that, find
|
|
182
|
+
// nothing newer and report "up to date" on top of the old build. Going back
|
|
183
|
+
// (the tracked tree was clean, so this only moves HEAD) means the next run
|
|
184
|
+
// tries again.
|
|
185
|
+
rollback = async () => {
|
|
186
|
+
if (!previous)
|
|
187
|
+
return;
|
|
188
|
+
const back = await ui.task(`Going back to ${ctx.version}`, () => sys.exec("git", ["checkout", "--quiet", previous], { cwd: ctx.root }));
|
|
189
|
+
if (back.code !== 0) {
|
|
190
|
+
ui.problem(`Couldn't go back to ${ctx.version}.`, { detail: lastLine(back), fix: [["Do it by hand", `git checkout ${previous} && npm install && totem build`]] });
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
// Put the old build back too. Whatever broke the update may break this.
|
|
194
|
+
const rebuilt = await ui.task(`Rebuilding ${ctx.version}`, async () => (await install()).code === 0 && (await build()).code === 0);
|
|
195
|
+
if (rebuilt)
|
|
196
|
+
ui.ok(`Back on ${ctx.version}; nothing changed`);
|
|
197
|
+
else
|
|
198
|
+
ui.warn(`Back on ${ctx.version}'s source, but it didn't rebuild.`, "run: npm install && totem build");
|
|
199
|
+
ui.rows([[RETRY[0], ui.kit.c.accent(RETRY[1])]], 2);
|
|
200
|
+
};
|
|
201
|
+
// Every version, the latest included, is its release tag: a detached
|
|
202
|
+
// checkout. Never `main`: that is unreleased code, and on a fork's clone
|
|
203
|
+
// origin/main can be older than the release being installed.
|
|
204
|
+
if (!(await staged(io, `Checking out ${target.tag}`, `Checked out ${target.tag}`, () => sys.exec("git", ["checkout", "--quiet", target.tag], { cwd: ctx.root }), { retry: true })))
|
|
205
|
+
return "failed";
|
|
206
|
+
if (!(await staged(io, "Installing dependencies", "Dependencies installed", install, { slow: true }))) {
|
|
207
|
+
await rollback();
|
|
208
|
+
return "failed";
|
|
153
209
|
}
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
return 1;
|
|
210
|
+
if (!(await staged(io, "Building", "Built", build, { slow: true }))) {
|
|
211
|
+
await rollback();
|
|
212
|
+
return "failed";
|
|
158
213
|
}
|
|
159
|
-
if (!(await staged("installing dependencies", () => captureAsync("npm", ["install"], { cwd: ctx.root }))))
|
|
160
|
-
return 1;
|
|
161
|
-
const tsc = resolve(ctx.root, "node_modules", ".bin", "tsc");
|
|
162
|
-
if (!(await staged("building", () => captureAsync(process.execPath, [tsc], { cwd: ctx.root }))))
|
|
163
|
-
return 1;
|
|
164
214
|
}
|
|
165
215
|
else {
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
// Propagate the new code to wherever the server actually runs. What that takes
|
|
170
|
-
// depends entirely on the user's RECORDED deploy state — branch on it, never
|
|
171
|
-
// assume:
|
|
172
|
-
// • no record → nothing remote exists; local code is already updated.
|
|
173
|
-
// • local (stdio) → just restart the MCP client to pick up the new build.
|
|
174
|
-
// • fly/railway/cloudrun → rebuild-from-source on deploy; fully automatic.
|
|
175
|
-
// • custom / self-host → a container on a box we can't reach; we must NOT fake
|
|
176
|
-
// a deploy or health-check (it'd pass against the OLD container) — print the
|
|
177
|
-
// exact rebuild/restart steps instead.
|
|
178
|
-
const d = ctx.detectDeploy();
|
|
179
|
-
const AUTO_DEPLOY = new Set(["fly", "railway", "cloudrun"]);
|
|
180
|
-
if (!d || d.platform === "local") {
|
|
181
|
-
console.log(c.gray(d?.platform === "local"
|
|
182
|
-
? "\n Local install — restart your MCP client to load the new build."
|
|
183
|
-
: "\n No deployment recorded — local code is updated (run `totem cloud` to deploy a server)."));
|
|
184
|
-
}
|
|
185
|
-
else if (AUTO_DEPLOY.has(d.platform)) {
|
|
186
|
-
// The platform CLI must be present to push from here. If it's gone (a fresh
|
|
187
|
-
// machine, or you ran update from a different box than you deployed from),
|
|
188
|
-
// don't surface a cryptic `spawn fly ENOENT` + "server unchanged" — the local
|
|
189
|
-
// code IS updated; say plainly the redeploy needs the CLI.
|
|
190
|
-
const cliMissing = d.platform === "fly" ? !(commandExists("fly") || commandExists("flyctl"))
|
|
191
|
-
: d.platform === "railway" ? !commandExists("railway")
|
|
192
|
-
: !commandExists("gcloud");
|
|
193
|
-
if (cliMissing) {
|
|
194
|
-
const cli = d.platform === "fly" ? "flyctl" : d.platform === "railway" ? "railway" : "gcloud";
|
|
195
|
-
console.log(c.yellow(`\n Local code updated — but the ${d.platform} CLI (${cli}) isn't installed here, so the deployment wasn't pushed.`));
|
|
196
|
-
console.log(c.gray(` Install ${cli} and run \`totem deploy\`, or re-run \`totem cloud\`.`));
|
|
197
|
-
return 0;
|
|
198
|
-
}
|
|
199
|
-
console.log(c.bold(`\n Redeploying to ${d.platform}${d.app ? ` (${d.app})` : ""}…`));
|
|
200
|
-
if ((await ctx.redeploy()) !== 0) {
|
|
201
|
-
console.log(c.red(" ✗ deploy failed — your live server is unchanged."));
|
|
202
|
-
return 1;
|
|
203
|
-
}
|
|
204
|
-
if (d.url) {
|
|
205
|
-
const url = `${cleanUrl(d.url)}/health`;
|
|
206
|
-
console.log(c.gray(` health check → ${url}`));
|
|
207
|
-
if ((await ping(url)) !== 0) {
|
|
208
|
-
console.log(c.red(" ⚠ /health didn't return 200 — the server may be unhealthy."));
|
|
209
|
-
console.log(c.gray(d.platform === "fly" ? ` Roll back: fly releases -a ${d.app} → redeploy the prior release.` : " Roll back to the previous version on your host."));
|
|
210
|
-
return 1;
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
// A redeploy restarts the server. This is a code-only update — secrets persist
|
|
214
|
-
// on the host, so tokens carry over. But /health passing doesn't prove Whoop
|
|
215
|
-
// auth survived the restart (cloud uses the in-memory token store, which can
|
|
216
|
-
// strand a rotated refresh token), so point at the fix if calls start failing.
|
|
217
|
-
console.log(c.gray(" Tokens persist across the redeploy. If Whoop calls start failing afterward, run `totem auth` to refresh + re-push them."));
|
|
216
|
+
const spec = `${ctx.pkgName}@${target.version}`;
|
|
217
|
+
if (!(await staged(io, `Installing ${spec}`, `Installed ${spec}`, (onLine) => sys.exec("npm", ["install", "-g", spec], { onLine }), { slow: true, retry: true })))
|
|
218
|
+
return "failed";
|
|
218
219
|
}
|
|
219
|
-
|
|
220
|
-
|
|
220
|
+
// Bring the server along. What that takes depends on where it runs:
|
|
221
|
+
// - nowhere / this computer: the client loads the new build when it restarts;
|
|
222
|
+
// - Fly, Railway, Cloud Run: redeploy from here and check /health;
|
|
223
|
+
// - a self-hosted container: totem can't reach it, so it must not pretend
|
|
224
|
+
// to (a health check would pass against the OLD container). Print the steps.
|
|
225
|
+
if (!remote)
|
|
226
|
+
return "done";
|
|
227
|
+
const host = HOST_NAME[remote.platform];
|
|
228
|
+
if (!host) {
|
|
229
|
+
heading(2, "Your server");
|
|
230
|
+
selfHostSteps(io, ctx, remote);
|
|
231
|
+
return "local-only";
|
|
221
232
|
}
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
233
|
+
heading(2, `Deploy to ${host}`);
|
|
234
|
+
// The host's CLI has to be on this machine to deploy from it.
|
|
235
|
+
const cli = remote.platform === "fly" ? ["fly", "flyctl"] : remote.platform === "railway" ? ["railway"] : remote.platform === "cloudflare" ? ["npx"] : ["gcloud"];
|
|
236
|
+
if (!cli.some((c) => sys.has(c))) {
|
|
237
|
+
ui.warn(`The ${host} CLI (${cli[cli.length - 1]}) isn't installed on this machine, so the server still runs ${ctx.version}.`);
|
|
238
|
+
ui.hint(`Install it, then: totem deploy`);
|
|
239
|
+
return "local-only";
|
|
240
|
+
}
|
|
241
|
+
const started = sys.now();
|
|
242
|
+
const deploy = await ui.task(`Deploying${remote.app ? ` ${remote.app}` : ""}`, (set) => ctx.redeploy(set), { slow: true });
|
|
243
|
+
if (deploy.code !== 0) {
|
|
244
|
+
ui.problem("The deploy failed. The server is unchanged.", { detail: tail(deploy) });
|
|
245
|
+
// Keep this install on the version the server runs, so the next check sees
|
|
246
|
+
// the release as still to do instead of "up to date".
|
|
247
|
+
await rollback();
|
|
248
|
+
return "failed";
|
|
249
|
+
}
|
|
250
|
+
ui.ok(`Deployed${remote.app ? ` ${remote.app}` : ""}`, duration(sys.now() - started));
|
|
251
|
+
if (remote.url) {
|
|
252
|
+
const health = await ui.task("Checking the server", () => sys.httpGet(`${cleanUrl(remote.url)}/health`, 10_000));
|
|
253
|
+
if (health.status < 200 || health.status >= 300) {
|
|
254
|
+
ui.problem("The new version is deployed, but the server isn't answering /health.", {
|
|
255
|
+
detail: health.status ? `HTTP ${health.status}` : health.error ?? "no answer",
|
|
256
|
+
fix: [["Read its logs", "totem logs"], ...(remote.platform === "fly" && remote.app ? [["See earlier releases", `fly releases -a ${remote.app}`]] : [])],
|
|
257
|
+
});
|
|
258
|
+
return "failed";
|
|
259
|
+
}
|
|
260
|
+
ui.ok("The server is up", "/health answered");
|
|
261
|
+
}
|
|
262
|
+
if (remote.platform === "cloudrun")
|
|
263
|
+
ui.warn("A new Cloud Run revision starts without a WHOOP login.", "log in again: totem auth");
|
|
264
|
+
else if (remote.platform === "cloudflare")
|
|
265
|
+
ui.hint("The WHOOP login lives in the Worker's Durable Object and carries over. If tools start failing: totem auth");
|
|
266
|
+
else
|
|
267
|
+
ui.hint("The WHOOP login lives on the server's volume and carries over. If tools start failing: totem auth");
|
|
268
|
+
return "done";
|
|
238
269
|
}
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
270
|
+
// Self-hosted (Docker on a VPS, a home server, …): totem can't reach the
|
|
271
|
+
// container, and how it is run varies, so print the recipe to adapt.
|
|
272
|
+
function selfHostSteps(io, ctx, d) {
|
|
273
|
+
const { ui, sys } = io;
|
|
274
|
+
// The env file `totem cloud` wrote: in totem's config folder (installs before 2.0: .env.deploy in the install).
|
|
275
|
+
const envFile = [configFile(sys, "deploy.env"), resolve(ctx.root, ".env.deploy")].find((f) => existsSync(f));
|
|
276
|
+
const envArg = envFile ? shellPath(envFile) : "<your env file>";
|
|
277
|
+
ui.para("totem can't reach a self-hosted container. This install is updated; on the host that runs the server:");
|
|
278
|
+
ui.line();
|
|
279
|
+
ui.para("1. Get this version there (git pull the checkout, or copy it over).");
|
|
280
|
+
ui.para("2. Rebuild the image:");
|
|
281
|
+
ui.code(shellLines([...dockerBuildArgs(ctx.root), shellPath(ctx.root)], ui.style.width - 7, sys.platform), 5);
|
|
282
|
+
ui.para("3. Stop the old container, then start the new image the way you did before:");
|
|
283
|
+
ui.code(shellLines(["docker", "run", "-d", "--restart", "unless-stopped", "-p", "3000:3000", "-v", "totem-data:/data", "--env-file", envArg, "totem"], ui.style.width - 7, sys.platform), 5);
|
|
284
|
+
if (d.url) {
|
|
285
|
+
ui.para("4. Check it:");
|
|
286
|
+
ui.code([`curl ${cleanUrl(d.url)}/health`], 5);
|
|
287
|
+
}
|
|
244
288
|
}
|
|
245
289
|
// ── auto-update scheduler (launchd on macOS, cron on Linux) ──────────────────
|
|
246
|
-
|
|
290
|
+
const plistPath = (home) => resolve(home, "Library", "LaunchAgents", `${AUTO_LABEL}.plist`);
|
|
247
291
|
function xmlEscape(s) {
|
|
248
292
|
return s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
249
293
|
}
|
|
250
294
|
// A launchd LaunchAgent that runs `totem update --auto-run` every intervalSec.
|
|
251
|
-
|
|
295
|
+
// `path` becomes the job's PATH: launchd starts jobs with /usr/bin:/bin:/usr/sbin:/sbin,
|
|
296
|
+
// where npm and the deploy CLIs usually aren't.
|
|
297
|
+
export function launchdPlist(programArgs, intervalSec, workingDir, logPath, path) {
|
|
252
298
|
const args = programArgs.map((a) => ` <string>${xmlEscape(a)}</string>`).join("\n");
|
|
299
|
+
const env = path
|
|
300
|
+
? ` <key>EnvironmentVariables</key>\n <dict>\n <key>PATH</key>\n <string>${xmlEscape(path)}</string>\n </dict>\n`
|
|
301
|
+
: "";
|
|
253
302
|
return `<?xml version="1.0" encoding="UTF-8"?>
|
|
254
303
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
255
304
|
<plist version="1.0">
|
|
@@ -266,7 +315,7 @@ ${args}
|
|
|
266
315
|
<false/>
|
|
267
316
|
<key>WorkingDirectory</key>
|
|
268
317
|
<string>${xmlEscape(workingDir)}</string>
|
|
269
|
-
<key>StandardOutPath</key>
|
|
318
|
+
${env} <key>StandardOutPath</key>
|
|
270
319
|
<string>${xmlEscape(logPath)}</string>
|
|
271
320
|
<key>StandardErrorPath</key>
|
|
272
321
|
<string>${xmlEscape(logPath)}</string>
|
|
@@ -274,192 +323,286 @@ ${args}
|
|
|
274
323
|
</plist>
|
|
275
324
|
`;
|
|
276
325
|
}
|
|
277
|
-
// One cron line, tagged so we can find + remove exactly ours.
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
326
|
+
// One cron line, tagged so we can find + remove exactly ours. Every word is
|
|
327
|
+
// quoted for sh (cron hands the line to `sh -c`), and `%` is escaped: cron ends
|
|
328
|
+
// the command at a bare `%` and feeds the rest to it as stdin.
|
|
329
|
+
// `path`, when given, is exported first: cron's own PATH is /usr/bin:/bin.
|
|
330
|
+
export function cronLine(programArgs, root, logPath, path) {
|
|
331
|
+
const shq = (s) => `'${s.replace(/'/g, `'\\''`)}'`.replace(/%/g, "\\%");
|
|
332
|
+
const word = (s) => (/^[A-Za-z0-9_/.:=@+-]+$/.test(s) ? s : shq(s));
|
|
333
|
+
const setPath = path ? `export PATH=${shq(path)}; ` : "";
|
|
334
|
+
return `0 */6 * * * ${setPath}cd ${shq(root)} && ${programArgs.map(word).join(" ")} >> ${shq(logPath)} 2>&1 # ${AUTO_LABEL}`;
|
|
281
335
|
}
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
336
|
+
/**
|
|
337
|
+
* The PATH a scheduled run gets: this node's directory (where npm lives) ahead
|
|
338
|
+
* of the PATH `totem update --auto on` was run with, which can see git and the
|
|
339
|
+
* deploy CLI. launchd and cron would otherwise start the job with a bare system
|
|
340
|
+
* PATH, where `npm install` and `fly deploy` fail with ENOENT.
|
|
341
|
+
*/
|
|
342
|
+
export function schedulerPath(execPath = process.execPath, envPath = process.env.PATH ?? "", delimiter = pathDelimiter) {
|
|
343
|
+
const dirs = [dirname(execPath), ...envPath.split(delimiter)].map((d) => d.trim()).filter(Boolean);
|
|
344
|
+
return [...new Set(dirs)].join(delimiter);
|
|
345
|
+
}
|
|
346
|
+
/**
|
|
347
|
+
* The person's crontab without totem's line, or why it couldn't be read.
|
|
348
|
+
*
|
|
349
|
+
* `crontab -l` exits non-zero both when there is no crontab yet (start from an
|
|
350
|
+
* empty one) and when the crontab couldn't be read. Its output is empty either
|
|
351
|
+
* way, and writing back "everything but totem's line" after the second erased
|
|
352
|
+
* every job the person had.
|
|
353
|
+
*/
|
|
354
|
+
async function otherCronJobs(io) {
|
|
355
|
+
const r = await io.sys.exec("crontab", ["-l"]);
|
|
356
|
+
// "no crontab for <user>" (cron, cronie); "can't open '<user>': No such file or directory" (BusyBox).
|
|
357
|
+
if (r.code !== 0 && !/no crontab|no such file/i.test(`${r.stderr}\n${r.stdout}`))
|
|
358
|
+
return { ok: false, why: lastLine(r) };
|
|
359
|
+
const all = r.code === 0 ? r.stdout.split("\n") : [];
|
|
360
|
+
return { ok: true, lines: all.filter((l) => l && !l.includes(AUTO_LABEL)), hadTotem: all.some((l) => l.includes(AUTO_LABEL)) };
|
|
361
|
+
}
|
|
362
|
+
export async function isAutoOn(io) {
|
|
363
|
+
const { sys } = io;
|
|
364
|
+
if (sys.platform === "darwin")
|
|
365
|
+
return existsSync(plistPath(sys.home));
|
|
366
|
+
if (sys.platform === "linux") {
|
|
367
|
+
const r = await sys.exec("crontab", ["-l"]);
|
|
287
368
|
return r.code === 0 && r.stdout.includes(AUTO_LABEL);
|
|
288
369
|
}
|
|
289
370
|
return false;
|
|
290
371
|
}
|
|
291
|
-
function
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
async function enableAuto(ctx) {
|
|
295
|
-
const args = autoRunArgs(ctx);
|
|
372
|
+
async function enableAuto(ctx, io) {
|
|
373
|
+
const { ui, sys } = io;
|
|
374
|
+
const args = [sys.node, ctx.cliEntry, "update", "--auto-run"];
|
|
296
375
|
const log = autoLogPath(ctx.root);
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
376
|
+
const path = schedulerPath(sys.node, sys.env.PATH ?? "");
|
|
377
|
+
let via;
|
|
378
|
+
if (sys.platform === "darwin") {
|
|
379
|
+
const p = plistPath(sys.home);
|
|
380
|
+
mkdirSync(dirname(p), { recursive: true });
|
|
381
|
+
writeFileSync(p, launchdPlist(args, AUTO_INTERVAL_SEC, ctx.root, log, path));
|
|
382
|
+
await sys.exec("launchctl", ["unload", p]); // fine if it wasn't loaded
|
|
383
|
+
const load = await sys.exec("launchctl", ["load", p]);
|
|
303
384
|
if (load.code !== 0) {
|
|
304
|
-
|
|
385
|
+
ui.problem("launchd wouldn't load the auto-update job.", { detail: lastLine(load), fix: [["Try again", "totem update --auto on"]] });
|
|
305
386
|
return false;
|
|
306
387
|
}
|
|
307
|
-
|
|
388
|
+
via = "launchd";
|
|
308
389
|
}
|
|
309
|
-
else if (
|
|
310
|
-
const
|
|
311
|
-
|
|
312
|
-
|
|
390
|
+
else if (sys.platform === "linux") {
|
|
391
|
+
const others = await otherCronJobs(io);
|
|
392
|
+
if (!others.ok) {
|
|
393
|
+
ui.problem("Couldn't read your crontab, so totem left it as it is.", { detail: others.why, fix: [["Try again", "totem update --auto on"]] });
|
|
394
|
+
return false;
|
|
395
|
+
}
|
|
396
|
+
const existing = [...others.lines, cronLine(args, ctx.root, log, path)];
|
|
397
|
+
const set = await sys.exec("crontab", ["-"], { input: existing.join("\n") + "\n" });
|
|
313
398
|
if (set.code !== 0) {
|
|
314
|
-
|
|
399
|
+
ui.problem("cron wouldn't take the auto-update job.", { detail: lastLine(set), fix: [["Try again", "totem update --auto on"]] });
|
|
315
400
|
return false;
|
|
316
401
|
}
|
|
317
|
-
|
|
402
|
+
via = "cron";
|
|
318
403
|
}
|
|
319
404
|
else {
|
|
320
|
-
|
|
321
|
-
|
|
405
|
+
ui.warn("Auto-update isn't available on this system.");
|
|
406
|
+
ui.para("To get the same, schedule this command every 6 hours:", 2);
|
|
407
|
+
ui.code([args.join(" ")]);
|
|
322
408
|
return false;
|
|
323
409
|
}
|
|
324
|
-
|
|
410
|
+
ui.ok("Auto-update is on", `checks every 6 hours, through ${via}`);
|
|
411
|
+
ui.rows([["Log", tildify(log, sys.home)], ["Turn it off", "totem update --auto off"]], 2);
|
|
325
412
|
return true;
|
|
326
413
|
}
|
|
327
|
-
async function disableAuto(
|
|
328
|
-
|
|
329
|
-
|
|
414
|
+
async function disableAuto(io) {
|
|
415
|
+
const { ui, sys } = io;
|
|
416
|
+
if (sys.platform === "darwin") {
|
|
417
|
+
const p = plistPath(sys.home);
|
|
330
418
|
if (existsSync(p)) {
|
|
331
|
-
await
|
|
419
|
+
await sys.exec("launchctl", ["unload", p]);
|
|
332
420
|
rmSync(p, { force: true });
|
|
333
421
|
}
|
|
334
|
-
console.log(c.green(" ✓ auto-update off"));
|
|
335
422
|
}
|
|
336
|
-
else if (
|
|
337
|
-
const
|
|
338
|
-
|
|
339
|
-
|
|
423
|
+
else if (sys.platform === "linux") {
|
|
424
|
+
const others = await otherCronJobs(io);
|
|
425
|
+
if (!others.ok) {
|
|
426
|
+
ui.problem("Couldn't read your crontab, so totem left it as it is.", { detail: others.why, fix: [["Try again", "totem update --auto off"]] });
|
|
427
|
+
return false;
|
|
428
|
+
}
|
|
429
|
+
// Only a crontab with totem's line in it needs rewriting.
|
|
430
|
+
if (others.hadTotem)
|
|
431
|
+
await sys.exec("crontab", ["-"], { input: others.lines.length ? others.lines.join("\n") + "\n" : "\n" });
|
|
340
432
|
}
|
|
341
433
|
else {
|
|
342
|
-
|
|
434
|
+
ui.warn("totem schedules nothing on this system. If you scheduled it yourself, remove that.");
|
|
435
|
+
return true;
|
|
343
436
|
}
|
|
437
|
+
ui.ok("Auto-update is off", "update by hand with: totem update");
|
|
344
438
|
return true;
|
|
345
439
|
}
|
|
346
440
|
// ── flows ────────────────────────────────────────────────────────────────────
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
441
|
+
function finish(io, ctx, target, applied) {
|
|
442
|
+
const { ui } = io;
|
|
443
|
+
// The step that failed has said why, what version this is back on, and what to run.
|
|
444
|
+
if (applied === "failed")
|
|
445
|
+
return 1;
|
|
446
|
+
const d = ctx.detectDeploy();
|
|
447
|
+
if (applied === "local-only") {
|
|
448
|
+
ui.next([`This install is on ${target.version}. The server is not yet: finish the steps above.`]);
|
|
449
|
+
return 0;
|
|
450
|
+
}
|
|
451
|
+
if (!d || d.platform === "local")
|
|
452
|
+
ui.next([`totem is now ${target.version}.`, "Restart your AI client so it starts the new version."]);
|
|
453
|
+
else {
|
|
454
|
+
ui.line();
|
|
455
|
+
ui.ok(`totem is now ${target.version}, here and on the server`);
|
|
456
|
+
}
|
|
457
|
+
return 0;
|
|
458
|
+
}
|
|
459
|
+
async function runInteractive(ctx, io) {
|
|
460
|
+
const { ui } = io;
|
|
461
|
+
const { g } = ui.kit;
|
|
462
|
+
ui.header("totem update", `Version ${ctx.version} is installed.`);
|
|
463
|
+
const versions = await ui.task("Looking up releases", () => fetchVersions(ctx, io));
|
|
350
464
|
if (!versions.length) {
|
|
351
|
-
|
|
465
|
+
ui.problem("Couldn't get the list of releases.", { detail: "Is this machine online?", fix: [["Try again", "totem update"]] });
|
|
352
466
|
return 1;
|
|
353
467
|
}
|
|
354
468
|
const latest = versions[0];
|
|
355
469
|
const choices = versions.map((v) => {
|
|
356
|
-
const
|
|
357
|
-
|
|
358
|
-
tags.push(c.green("latest"));
|
|
359
|
-
if (v.version === ctx.version)
|
|
360
|
-
tags.push(c.cyan("current"));
|
|
361
|
-
if (v.date)
|
|
362
|
-
tags.push(c.dim(v.date));
|
|
363
|
-
const note = v.notes ? c.dim("· " + (v.notes.length > 44 ? v.notes.slice(0, 43) + "…" : v.notes)) : "";
|
|
364
|
-
return { label: `v${v.version}`, hint: [tags.join(" "), note].filter(Boolean).join(" ") };
|
|
470
|
+
const facts = [v.version === latest.version ? "latest" : "", v.version === ctx.version ? "installed" : "", v.date ?? "", v.notes ?? ""].filter(Boolean);
|
|
471
|
+
return { label: v.version, hint: facts.join(` ${g.dot} `) };
|
|
365
472
|
});
|
|
366
|
-
const
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
if (!(await promptYesNo(" Install this older version anyway?", false))) {
|
|
373
|
-
console.log(c.gray(" Cancelled."));
|
|
473
|
+
const target = versions[await ui.select("Which version?", choices, 0)];
|
|
474
|
+
if (target.version !== latest.version) {
|
|
475
|
+
const ahead = versions.filter((v) => compareSemver(v.version, target.version) > 0).map((v) => v.version);
|
|
476
|
+
ui.warn(`${target.version} is older than ${listOf(ahead.length > 3 ? [...ahead.slice(0, 3), `${ahead.length - 3} more`] : ahead)}.`);
|
|
477
|
+
if (!(await ui.confirm(`Install ${target.version} anyway?`, false))) {
|
|
478
|
+
ui.hint("Nothing changed.", 2);
|
|
374
479
|
return 0;
|
|
375
480
|
}
|
|
376
481
|
}
|
|
377
482
|
else if (target.version === ctx.version) {
|
|
378
|
-
|
|
379
|
-
|
|
483
|
+
ui.ok(`${ctx.version} is the latest, and it is installed`);
|
|
484
|
+
if (!(await ui.confirm("Install it again anyway?", false)))
|
|
380
485
|
return 0;
|
|
381
|
-
}
|
|
382
486
|
}
|
|
383
|
-
const
|
|
384
|
-
if (
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
if (await promptYesNo(" Turn on auto-update? (auto-pulls + sets up every new release)", false))
|
|
392
|
-
await enableAuto(ctx);
|
|
487
|
+
const applied = await applyVersion(ctx, target, io);
|
|
488
|
+
if (applied !== "failed") {
|
|
489
|
+
// The auto-update switch has to agree with the choice just made.
|
|
490
|
+
const autoOn = await isAutoOn(io);
|
|
491
|
+
if (target.version === latest.version && !autoOn && (io.sys.platform === "darwin" || io.sys.platform === "linux")) {
|
|
492
|
+
ui.line();
|
|
493
|
+
if (await ui.confirm("Install new releases automatically from now on?", false))
|
|
494
|
+
await enableAuto(ctx, io);
|
|
393
495
|
}
|
|
394
|
-
else {
|
|
395
|
-
|
|
496
|
+
else if (target.version !== latest.version && autoOn) {
|
|
497
|
+
ui.line();
|
|
498
|
+
ui.warn(`Auto-update is on: at its next check it would move you back to ${latest.version}.`);
|
|
499
|
+
if (await ui.confirm(`Turn it off to stay on ${target.version}?`, true))
|
|
500
|
+
await disableAuto(io);
|
|
396
501
|
}
|
|
397
502
|
}
|
|
398
|
-
|
|
399
|
-
console.log(c.yellow("\n ⚠ Auto-update is ON — it'll move you back to the latest on the next check."));
|
|
400
|
-
if (await promptYesNo(" Turn auto-update OFF to stay pinned to this version?", true))
|
|
401
|
-
await disableAuto(ctx);
|
|
402
|
-
}
|
|
403
|
-
printDone(target.version);
|
|
404
|
-
return 0;
|
|
503
|
+
return finish(io, ctx, target, applied);
|
|
405
504
|
}
|
|
406
|
-
async function runCheck(ctx) {
|
|
407
|
-
|
|
408
|
-
|
|
505
|
+
async function runCheck(ctx, io) {
|
|
506
|
+
const { ui } = io;
|
|
507
|
+
ui.header("totem update --check");
|
|
508
|
+
const versions = await ui.task("Looking up releases", () => fetchVersions(ctx, io));
|
|
409
509
|
if (!versions.length) {
|
|
410
|
-
|
|
510
|
+
ui.problem("Couldn't get the list of releases.", { detail: "Is this machine online?", fix: [["Try again", "totem update --check"]] });
|
|
411
511
|
return 1;
|
|
412
512
|
}
|
|
413
513
|
const latest = versions[0];
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
514
|
+
ui.rows([
|
|
515
|
+
["Installed", ctx.version],
|
|
516
|
+
["Latest", `${latest.version}${latest.date ? `, released ${latest.date}` : ""}`],
|
|
517
|
+
["Auto-update", (await isAutoOn(io)) ? "on" : "off"],
|
|
518
|
+
]);
|
|
519
|
+
ui.line();
|
|
520
|
+
if (isNewer(latest.version, ctx.version)) {
|
|
521
|
+
ui.warn(`An update is available: ${latest.version}.`);
|
|
522
|
+
ui.rows([["Install it", ui.kit.c.accent("totem update")]], 2);
|
|
523
|
+
}
|
|
524
|
+
else {
|
|
525
|
+
ui.ok("Up to date");
|
|
526
|
+
}
|
|
420
527
|
return 0;
|
|
421
528
|
}
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
529
|
+
/**
|
|
530
|
+
* Whether an unattended update may move this checkout: `git rev-parse
|
|
531
|
+
* --abbrev-ref HEAD` says `main`, or `HEAD` when detached (at a release tag).
|
|
532
|
+
* An empty answer (git failed) is not a yes.
|
|
533
|
+
*/
|
|
534
|
+
export function followsReleases(branch) {
|
|
535
|
+
return branch === "main" || branch === "HEAD";
|
|
536
|
+
}
|
|
537
|
+
// The scheduled job: no questions, install the latest if it is newer, and leave
|
|
538
|
+
// one dated line per outcome in the log.
|
|
539
|
+
async function runAuto(ctx, io) {
|
|
540
|
+
const { ui, sys } = io;
|
|
541
|
+
const log = (message) => ui.line(`[totem auto-update ${new Date(sys.now()).toISOString()}] ${message}`);
|
|
542
|
+
if (ctx.isGit) {
|
|
543
|
+
// An update checks out the release tag. Only do that unattended to a
|
|
544
|
+
// checkout that is following releases: on `main`, or already detached at a
|
|
545
|
+
// tag. Anything else is someone's work in progress (a feature branch whose
|
|
546
|
+
// tracked tree happens to be clean), and silently moving it off its branch
|
|
547
|
+
// loses their place.
|
|
548
|
+
const branch = (await sys.exec("git", ["rev-parse", "--abbrev-ref", "HEAD"], { cwd: ctx.root })).stdout.trim();
|
|
549
|
+
if (!followsReleases(branch)) {
|
|
550
|
+
log(`on branch '${branch}', not main or a release tag: skipped (update it yourself with \`totem update\`)`);
|
|
551
|
+
return 0;
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
const latest = (await fetchVersions(ctx, io))[0];
|
|
427
555
|
if (!latest) {
|
|
428
|
-
|
|
556
|
+
log("couldn't get the list of releases (offline?): skipped");
|
|
429
557
|
return 0;
|
|
430
558
|
}
|
|
431
559
|
if (!isNewer(latest.version, ctx.version)) {
|
|
432
|
-
|
|
560
|
+
log(`up to date on ${ctx.version}`);
|
|
433
561
|
return 0;
|
|
434
562
|
}
|
|
435
|
-
|
|
436
|
-
const
|
|
437
|
-
|
|
438
|
-
|
|
563
|
+
log(`${latest.version} is out (installed: ${ctx.version}): installing`);
|
|
564
|
+
const applied = await applyVersion(ctx, latest, io);
|
|
565
|
+
if (applied === "done")
|
|
566
|
+
log(`now on ${latest.version}`);
|
|
567
|
+
else if (applied === "local-only")
|
|
568
|
+
log(`this install is on ${latest.version}; the server was NOT updated (see above)`);
|
|
569
|
+
else
|
|
570
|
+
log(`FAILED: still on ${ctx.version}; the next check tries again`);
|
|
571
|
+
return applied === "failed" ? 1 : 0;
|
|
439
572
|
}
|
|
440
|
-
export async function runUpdate(args, ctx) {
|
|
573
|
+
export async function runUpdate(args, ctx, io = realIo()) {
|
|
574
|
+
const { ui } = io;
|
|
441
575
|
const autoIdx = args.indexOf("--auto");
|
|
442
576
|
if (autoIdx !== -1) {
|
|
443
577
|
const val = (args[autoIdx + 1] ?? "").toLowerCase();
|
|
444
578
|
if (val === "on") {
|
|
445
|
-
|
|
446
|
-
if (!(await enableAuto(ctx)))
|
|
579
|
+
ui.header("totem update --auto on", "Install new releases automatically.");
|
|
580
|
+
if (!(await enableAuto(ctx, io)))
|
|
447
581
|
return 1;
|
|
448
|
-
//
|
|
449
|
-
|
|
450
|
-
|
|
582
|
+
// Turning it on means "I want the newest": check once now.
|
|
583
|
+
const latest = (await ui.task("Looking up releases", () => fetchVersions(ctx, io)))[0];
|
|
584
|
+
if (!latest) {
|
|
585
|
+
ui.warn("Couldn't check for a release right now; the first scheduled check will.");
|
|
586
|
+
return 0;
|
|
587
|
+
}
|
|
588
|
+
if (!isNewer(latest.version, ctx.version)) {
|
|
589
|
+
ui.ok("Up to date", `${ctx.version} is the latest`);
|
|
590
|
+
return 0;
|
|
591
|
+
}
|
|
592
|
+
ui.info(`${latest.version} is out: installing it now.`);
|
|
593
|
+
return finish(io, ctx, latest, await applyVersion(ctx, latest, io));
|
|
451
594
|
}
|
|
452
595
|
if (val === "off") {
|
|
453
|
-
|
|
454
|
-
return (await disableAuto(
|
|
596
|
+
ui.header("totem update --auto off");
|
|
597
|
+
return (await disableAuto(io)) ? 0 : 1;
|
|
455
598
|
}
|
|
456
|
-
|
|
599
|
+
ui.error(`--auto takes "on" or "off"${val ? `, not "${val}"` : ""}.`, { fix: [["Turn it on", "totem update --auto on"], ["Turn it off", "totem update --auto off"]] });
|
|
457
600
|
return 1;
|
|
458
601
|
}
|
|
459
602
|
if (args.includes("--auto-run"))
|
|
460
|
-
return runAuto(ctx);
|
|
603
|
+
return runAuto(ctx, io);
|
|
461
604
|
if (args.includes("--check"))
|
|
462
|
-
return runCheck(ctx);
|
|
463
|
-
return runInteractive(ctx);
|
|
605
|
+
return runCheck(ctx, io);
|
|
606
|
+
return runInteractive(ctx, io);
|
|
464
607
|
}
|
|
465
608
|
//# sourceMappingURL=update.js.map
|