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