@thebriangao/totem 1.4.4

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.
Files changed (405) hide show
  1. package/.dockerignore +23 -0
  2. package/.env.example +66 -0
  3. package/CHANGELOG.md +283 -0
  4. package/CONTRIBUTING.md +149 -0
  5. package/Dockerfile +53 -0
  6. package/LICENSE +37 -0
  7. package/README.md +587 -0
  8. package/SECURITY.md +79 -0
  9. package/TOOLS.md +429 -0
  10. package/WHOOP.md +2673 -0
  11. package/assets/banner.svg +38 -0
  12. package/dist/cli/index.js +589 -0
  13. package/dist/cli/index.js.map +1 -0
  14. package/dist/cli/setup.js +1127 -0
  15. package/dist/cli/setup.js.map +1 -0
  16. package/dist/cli/ui.js +512 -0
  17. package/dist/cli/ui.js.map +1 -0
  18. package/dist/cli/update.js +465 -0
  19. package/dist/cli/update.js.map +1 -0
  20. package/dist/data/behaviors.js +2777 -0
  21. package/dist/data/behaviors.js.map +1 -0
  22. package/dist/data/endpoints.js +320 -0
  23. package/dist/data/endpoints.js.map +1 -0
  24. package/dist/data/exercises.js +4863 -0
  25. package/dist/data/exercises.js.map +1 -0
  26. package/dist/data/sports.js +212 -0
  27. package/dist/data/sports.js.map +1 -0
  28. package/dist/lib/concurrency.js +27 -0
  29. package/dist/lib/concurrency.js.map +1 -0
  30. package/dist/lib/dates.js +29 -0
  31. package/dist/lib/dates.js.map +1 -0
  32. package/dist/lib/format.js +22 -0
  33. package/dist/lib/format.js.map +1 -0
  34. package/dist/lib/stats.js +32 -0
  35. package/dist/lib/stats.js.map +1 -0
  36. package/dist/lib/timezone.js +249 -0
  37. package/dist/lib/timezone.js.map +1 -0
  38. package/dist/lib/walk.js +396 -0
  39. package/dist/lib/walk.js.map +1 -0
  40. package/dist/projections/behavior_impact.js +96 -0
  41. package/dist/projections/behavior_impact.js.map +1 -0
  42. package/dist/projections/calendar.js +33 -0
  43. package/dist/projections/calendar.js.map +1 -0
  44. package/dist/projections/communities.js +105 -0
  45. package/dist/projections/communities.js.map +1 -0
  46. package/dist/projections/cycle.js +81 -0
  47. package/dist/projections/cycle.js.map +1 -0
  48. package/dist/projections/hr_zones.js +35 -0
  49. package/dist/projections/hr_zones.js.map +1 -0
  50. package/dist/projections/journal.js +56 -0
  51. package/dist/projections/journal.js.map +1 -0
  52. package/dist/projections/leaderboard.js +37 -0
  53. package/dist/projections/leaderboard.js.map +1 -0
  54. package/dist/projections/lift_exercise.js +22 -0
  55. package/dist/projections/lift_exercise.js.map +1 -0
  56. package/dist/projections/lift_history.js +133 -0
  57. package/dist/projections/lift_history.js.map +1 -0
  58. package/dist/projections/lift_library.js +71 -0
  59. package/dist/projections/lift_library.js.map +1 -0
  60. package/dist/projections/lift_progression.js +138 -0
  61. package/dist/projections/lift_progression.js.map +1 -0
  62. package/dist/projections/lift_prs.js +20 -0
  63. package/dist/projections/lift_prs.js.map +1 -0
  64. package/dist/projections/live_hr.js +19 -0
  65. package/dist/projections/live_hr.js.map +1 -0
  66. package/dist/projections/live_state.js +23 -0
  67. package/dist/projections/live_state.js.map +1 -0
  68. package/dist/projections/live_stress.js +11 -0
  69. package/dist/projections/live_stress.js.map +1 -0
  70. package/dist/projections/performance_assessment.js +15 -0
  71. package/dist/projections/performance_assessment.js.map +1 -0
  72. package/dist/projections/profile.js +59 -0
  73. package/dist/projections/profile.js.map +1 -0
  74. package/dist/projections/recovery.js +131 -0
  75. package/dist/projections/recovery.js.map +1 -0
  76. package/dist/projections/sleep.js +256 -0
  77. package/dist/projections/sleep.js.map +1 -0
  78. package/dist/projections/sleep_need.js +32 -0
  79. package/dist/projections/sleep_need.js.map +1 -0
  80. package/dist/projections/smart_alarm.js +45 -0
  81. package/dist/projections/smart_alarm.js.map +1 -0
  82. package/dist/projections/strain.js +128 -0
  83. package/dist/projections/strain.js.map +1 -0
  84. package/dist/projections/stress.js +86 -0
  85. package/dist/projections/stress.js.map +1 -0
  86. package/dist/projections/today.js +129 -0
  87. package/dist/projections/today.js.map +1 -0
  88. package/dist/projections/trend.js +149 -0
  89. package/dist/projections/trend.js.map +1 -0
  90. package/dist/projections/workout.js +161 -0
  91. package/dist/projections/workout.js.map +1 -0
  92. package/dist/projections/workouts.js +37 -0
  93. package/dist/projections/workouts.js.map +1 -0
  94. package/dist/schemas/calendar.js +12 -0
  95. package/dist/schemas/calendar.js.map +1 -0
  96. package/dist/schemas/coach.js +11 -0
  97. package/dist/schemas/coach.js.map +1 -0
  98. package/dist/schemas/communities.js +51 -0
  99. package/dist/schemas/communities.js.map +1 -0
  100. package/dist/schemas/compare.js +15 -0
  101. package/dist/schemas/compare.js.map +1 -0
  102. package/dist/schemas/escape.js +18 -0
  103. package/dist/schemas/escape.js.map +1 -0
  104. package/dist/schemas/journal.js +69 -0
  105. package/dist/schemas/journal.js.map +1 -0
  106. package/dist/schemas/leaderboard.js +25 -0
  107. package/dist/schemas/leaderboard.js.map +1 -0
  108. package/dist/schemas/live.js +26 -0
  109. package/dist/schemas/live.js.map +1 -0
  110. package/dist/schemas/performance.js +12 -0
  111. package/dist/schemas/performance.js.map +1 -0
  112. package/dist/schemas/primitives.js +29 -0
  113. package/dist/schemas/primitives.js.map +1 -0
  114. package/dist/schemas/profile.js +39 -0
  115. package/dist/schemas/profile.js.map +1 -0
  116. package/dist/schemas/recovery.js +27 -0
  117. package/dist/schemas/recovery.js.map +1 -0
  118. package/dist/schemas/settings.js +26 -0
  119. package/dist/schemas/settings.js.map +1 -0
  120. package/dist/schemas/sleep.js +38 -0
  121. package/dist/schemas/sleep.js.map +1 -0
  122. package/dist/schemas/sleep_need.js +15 -0
  123. package/dist/schemas/sleep_need.js.map +1 -0
  124. package/dist/schemas/smart_alarm.js +36 -0
  125. package/dist/schemas/smart_alarm.js.map +1 -0
  126. package/dist/schemas/strain.js +24 -0
  127. package/dist/schemas/strain.js.map +1 -0
  128. package/dist/schemas/strength.js +170 -0
  129. package/dist/schemas/strength.js.map +1 -0
  130. package/dist/schemas/stress.js +16 -0
  131. package/dist/schemas/stress.js.map +1 -0
  132. package/dist/schemas/today.js +38 -0
  133. package/dist/schemas/today.js.map +1 -0
  134. package/dist/schemas/trend.js +50 -0
  135. package/dist/schemas/trend.js.map +1 -0
  136. package/dist/schemas/womens_health.js +23 -0
  137. package/dist/schemas/womens_health.js.map +1 -0
  138. package/dist/schemas/workouts.js +50 -0
  139. package/dist/schemas/workouts.js.map +1 -0
  140. package/dist/scripts/cognito_bootstrap.js +278 -0
  141. package/dist/scripts/cognito_bootstrap.js.map +1 -0
  142. package/dist/server-http.js +221 -0
  143. package/dist/server-http.js.map +1 -0
  144. package/dist/server.js +74 -0
  145. package/dist/server.js.map +1 -0
  146. package/dist/tools/register.js +117 -0
  147. package/dist/tools/register.js.map +1 -0
  148. package/dist/tools/v2/activity_create.js +64 -0
  149. package/dist/tools/v2/activity_create.js.map +1 -0
  150. package/dist/tools/v2/activity_delete.js +26 -0
  151. package/dist/tools/v2/activity_delete.js.map +1 -0
  152. package/dist/tools/v2/behavior_impact.js +36 -0
  153. package/dist/tools/v2/behavior_impact.js.map +1 -0
  154. package/dist/tools/v2/calendar.js +28 -0
  155. package/dist/tools/v2/calendar.js.map +1 -0
  156. package/dist/tools/v2/coach_ask.js +117 -0
  157. package/dist/tools/v2/coach_ask.js.map +1 -0
  158. package/dist/tools/v2/communities.js +60 -0
  159. package/dist/tools/v2/communities.js.map +1 -0
  160. package/dist/tools/v2/compare.js +67 -0
  161. package/dist/tools/v2/compare.js.map +1 -0
  162. package/dist/tools/v2/cycle.js +23 -0
  163. package/dist/tools/v2/cycle.js.map +1 -0
  164. package/dist/tools/v2/cycle_log.js +43 -0
  165. package/dist/tools/v2/cycle_log.js.map +1 -0
  166. package/dist/tools/v2/day.js +32 -0
  167. package/dist/tools/v2/day.js.map +1 -0
  168. package/dist/tools/v2/endpoints.js +28 -0
  169. package/dist/tools/v2/endpoints.js.map +1 -0
  170. package/dist/tools/v2/hidden_metric.js +28 -0
  171. package/dist/tools/v2/hidden_metric.js.map +1 -0
  172. package/dist/tools/v2/hr_zones.js +24 -0
  173. package/dist/tools/v2/hr_zones.js.map +1 -0
  174. package/dist/tools/v2/hr_zones_set.js +51 -0
  175. package/dist/tools/v2/hr_zones_set.js.map +1 -0
  176. package/dist/tools/v2/journal.js +26 -0
  177. package/dist/tools/v2/journal.js.map +1 -0
  178. package/dist/tools/v2/journal_autopop.js +19 -0
  179. package/dist/tools/v2/journal_autopop.js.map +1 -0
  180. package/dist/tools/v2/journal_catalog.js +44 -0
  181. package/dist/tools/v2/journal_catalog.js.map +1 -0
  182. package/dist/tools/v2/journal_log.js +78 -0
  183. package/dist/tools/v2/journal_log.js.map +1 -0
  184. package/dist/tools/v2/leaderboard.js +79 -0
  185. package/dist/tools/v2/leaderboard.js.map +1 -0
  186. package/dist/tools/v2/lift_catalog.js +47 -0
  187. package/dist/tools/v2/lift_catalog.js.map +1 -0
  188. package/dist/tools/v2/lift_custom_exercise.js +108 -0
  189. package/dist/tools/v2/lift_custom_exercise.js.map +1 -0
  190. package/dist/tools/v2/lift_exercise.js +31 -0
  191. package/dist/tools/v2/lift_exercise.js.map +1 -0
  192. package/dist/tools/v2/lift_history.js +39 -0
  193. package/dist/tools/v2/lift_history.js.map +1 -0
  194. package/dist/tools/v2/lift_library.js +22 -0
  195. package/dist/tools/v2/lift_library.js.map +1 -0
  196. package/dist/tools/v2/lift_log.js +95 -0
  197. package/dist/tools/v2/lift_log.js.map +1 -0
  198. package/dist/tools/v2/lift_progression.js +30 -0
  199. package/dist/tools/v2/lift_progression.js.map +1 -0
  200. package/dist/tools/v2/lift_prs.js +21 -0
  201. package/dist/tools/v2/lift_prs.js.map +1 -0
  202. package/dist/tools/v2/lift_template_save.js +83 -0
  203. package/dist/tools/v2/lift_template_save.js.map +1 -0
  204. package/dist/tools/v2/live_hr.js +21 -0
  205. package/dist/tools/v2/live_hr.js.map +1 -0
  206. package/dist/tools/v2/live_state.js +21 -0
  207. package/dist/tools/v2/live_state.js.map +1 -0
  208. package/dist/tools/v2/live_stress.js +22 -0
  209. package/dist/tools/v2/live_stress.js.map +1 -0
  210. package/dist/tools/v2/performance_assessment.js +38 -0
  211. package/dist/tools/v2/performance_assessment.js.map +1 -0
  212. package/dist/tools/v2/profile.js +28 -0
  213. package/dist/tools/v2/profile.js.map +1 -0
  214. package/dist/tools/v2/profile_update.js +66 -0
  215. package/dist/tools/v2/profile_update.js.map +1 -0
  216. package/dist/tools/v2/raw.js +43 -0
  217. package/dist/tools/v2/raw.js.map +1 -0
  218. package/dist/tools/v2/recovery.js +31 -0
  219. package/dist/tools/v2/recovery.js.map +1 -0
  220. package/dist/tools/v2/sleep.js +23 -0
  221. package/dist/tools/v2/sleep.js.map +1 -0
  222. package/dist/tools/v2/sleep_need.js +21 -0
  223. package/dist/tools/v2/sleep_need.js.map +1 -0
  224. package/dist/tools/v2/smart_alarm.js +24 -0
  225. package/dist/tools/v2/smart_alarm.js.map +1 -0
  226. package/dist/tools/v2/smart_alarm_set.js +94 -0
  227. package/dist/tools/v2/smart_alarm_set.js.map +1 -0
  228. package/dist/tools/v2/sports_catalog.js +26 -0
  229. package/dist/tools/v2/sports_catalog.js.map +1 -0
  230. package/dist/tools/v2/strain.js +23 -0
  231. package/dist/tools/v2/strain.js.map +1 -0
  232. package/dist/tools/v2/stress.js +23 -0
  233. package/dist/tools/v2/stress.js.map +1 -0
  234. package/dist/tools/v2/symptom_log.js +72 -0
  235. package/dist/tools/v2/symptom_log.js.map +1 -0
  236. package/dist/tools/v2/today.js +30 -0
  237. package/dist/tools/v2/today.js.map +1 -0
  238. package/dist/tools/v2/trend.js +26 -0
  239. package/dist/tools/v2/trend.js.map +1 -0
  240. package/dist/tools/v2/workout.js +23 -0
  241. package/dist/tools/v2/workout.js.map +1 -0
  242. package/dist/tools/v2/workouts.js +32 -0
  243. package/dist/tools/v2/workouts.js.map +1 -0
  244. package/dist/whoop/build_lift_body.js +67 -0
  245. package/dist/whoop/build_lift_body.js.map +1 -0
  246. package/dist/whoop/client.js +84 -0
  247. package/dist/whoop/client.js.map +1 -0
  248. package/dist/whoop/cognito.js +110 -0
  249. package/dist/whoop/cognito.js.map +1 -0
  250. package/dist/whoop/constants.js +4 -0
  251. package/dist/whoop/constants.js.map +1 -0
  252. package/dist/whoop/device.js +103 -0
  253. package/dist/whoop/device.js.map +1 -0
  254. package/dist/whoop/errors.js +42 -0
  255. package/dist/whoop/errors.js.map +1 -0
  256. package/dist/whoop/init_timezone.js +62 -0
  257. package/dist/whoop/init_timezone.js.map +1 -0
  258. package/dist/whoop/installation.js +62 -0
  259. package/dist/whoop/installation.js.map +1 -0
  260. package/dist/whoop/json_out.js +9 -0
  261. package/dist/whoop/json_out.js.map +1 -0
  262. package/dist/whoop/oauth_provider.js +297 -0
  263. package/dist/whoop/oauth_provider.js.map +1 -0
  264. package/dist/whoop/session_state.js +34 -0
  265. package/dist/whoop/session_state.js.map +1 -0
  266. package/dist/whoop/token_manager.js +60 -0
  267. package/dist/whoop/token_manager.js.map +1 -0
  268. package/dist/whoop/token_store.js +47 -0
  269. package/dist/whoop/token_store.js.map +1 -0
  270. package/dist/whoop/types.js +82 -0
  271. package/dist/whoop/types.js.map +1 -0
  272. package/dist/whoop/write_safety.js +23 -0
  273. package/dist/whoop/write_safety.js.map +1 -0
  274. package/package.json +66 -0
  275. package/src/cli/index.ts +597 -0
  276. package/src/cli/setup.ts +1106 -0
  277. package/src/cli/ui.ts +505 -0
  278. package/src/cli/update.ts +442 -0
  279. package/src/data/behaviors.ts +2784 -0
  280. package/src/data/endpoints.ts +319 -0
  281. package/src/data/exercises.ts +4868 -0
  282. package/src/data/sports.ts +218 -0
  283. package/src/lib/concurrency.ts +28 -0
  284. package/src/lib/dates.ts +35 -0
  285. package/src/lib/format.ts +27 -0
  286. package/src/lib/stats.ts +35 -0
  287. package/src/lib/timezone.ts +269 -0
  288. package/src/lib/walk.ts +418 -0
  289. package/src/projections/behavior_impact.ts +98 -0
  290. package/src/projections/calendar.ts +46 -0
  291. package/src/projections/communities.ts +135 -0
  292. package/src/projections/cycle.ts +85 -0
  293. package/src/projections/hr_zones.ts +43 -0
  294. package/src/projections/journal.ts +55 -0
  295. package/src/projections/leaderboard.ts +49 -0
  296. package/src/projections/lift_exercise.ts +29 -0
  297. package/src/projections/lift_history.ts +140 -0
  298. package/src/projections/lift_library.ts +70 -0
  299. package/src/projections/lift_progression.ts +138 -0
  300. package/src/projections/lift_prs.ts +23 -0
  301. package/src/projections/live_hr.ts +21 -0
  302. package/src/projections/live_state.ts +28 -0
  303. package/src/projections/live_stress.ts +13 -0
  304. package/src/projections/performance_assessment.ts +19 -0
  305. package/src/projections/profile.ts +71 -0
  306. package/src/projections/recovery.ts +133 -0
  307. package/src/projections/sleep.ts +276 -0
  308. package/src/projections/sleep_need.ts +36 -0
  309. package/src/projections/smart_alarm.ts +70 -0
  310. package/src/projections/strain.ts +131 -0
  311. package/src/projections/stress.ts +95 -0
  312. package/src/projections/today.ts +166 -0
  313. package/src/projections/trend.ts +149 -0
  314. package/src/projections/workout.ts +168 -0
  315. package/src/projections/workouts.ts +36 -0
  316. package/src/schemas/calendar.ts +13 -0
  317. package/src/schemas/coach.ts +11 -0
  318. package/src/schemas/communities.ts +56 -0
  319. package/src/schemas/compare.ts +17 -0
  320. package/src/schemas/escape.ts +21 -0
  321. package/src/schemas/journal.ts +80 -0
  322. package/src/schemas/leaderboard.ts +26 -0
  323. package/src/schemas/live.ts +31 -0
  324. package/src/schemas/performance.ts +13 -0
  325. package/src/schemas/primitives.ts +35 -0
  326. package/src/schemas/profile.ts +40 -0
  327. package/src/schemas/recovery.ts +28 -0
  328. package/src/schemas/settings.ts +30 -0
  329. package/src/schemas/sleep.ts +40 -0
  330. package/src/schemas/sleep_need.ts +16 -0
  331. package/src/schemas/smart_alarm.ts +40 -0
  332. package/src/schemas/strain.ts +25 -0
  333. package/src/schemas/strength.ts +189 -0
  334. package/src/schemas/stress.ts +17 -0
  335. package/src/schemas/today.ts +39 -0
  336. package/src/schemas/trend.ts +53 -0
  337. package/src/schemas/womens_health.ts +26 -0
  338. package/src/schemas/workouts.ts +55 -0
  339. package/src/scripts/cognito_bootstrap.ts +249 -0
  340. package/src/server-http.ts +241 -0
  341. package/src/server.ts +85 -0
  342. package/src/tools/register.ts +120 -0
  343. package/src/tools/v2/activity_create.ts +74 -0
  344. package/src/tools/v2/activity_delete.ts +33 -0
  345. package/src/tools/v2/behavior_impact.ts +39 -0
  346. package/src/tools/v2/calendar.ts +33 -0
  347. package/src/tools/v2/coach_ask.ts +131 -0
  348. package/src/tools/v2/communities.ts +65 -0
  349. package/src/tools/v2/compare.ts +83 -0
  350. package/src/tools/v2/cycle.ts +28 -0
  351. package/src/tools/v2/cycle_log.ts +51 -0
  352. package/src/tools/v2/day.ts +37 -0
  353. package/src/tools/v2/endpoints.ts +32 -0
  354. package/src/tools/v2/hidden_metric.ts +33 -0
  355. package/src/tools/v2/hr_zones.ts +29 -0
  356. package/src/tools/v2/hr_zones_set.ts +57 -0
  357. package/src/tools/v2/journal.ts +31 -0
  358. package/src/tools/v2/journal_autopop.ts +26 -0
  359. package/src/tools/v2/journal_catalog.ts +48 -0
  360. package/src/tools/v2/journal_log.ts +84 -0
  361. package/src/tools/v2/leaderboard.ts +92 -0
  362. package/src/tools/v2/lift_catalog.ts +48 -0
  363. package/src/tools/v2/lift_custom_exercise.ts +117 -0
  364. package/src/tools/v2/lift_exercise.ts +35 -0
  365. package/src/tools/v2/lift_history.ts +52 -0
  366. package/src/tools/v2/lift_library.ts +28 -0
  367. package/src/tools/v2/lift_log.ts +102 -0
  368. package/src/tools/v2/lift_progression.ts +34 -0
  369. package/src/tools/v2/lift_prs.ts +26 -0
  370. package/src/tools/v2/lift_template_save.ts +89 -0
  371. package/src/tools/v2/live_hr.ts +26 -0
  372. package/src/tools/v2/live_state.ts +26 -0
  373. package/src/tools/v2/live_stress.ts +27 -0
  374. package/src/tools/v2/performance_assessment.ts +44 -0
  375. package/src/tools/v2/profile.ts +33 -0
  376. package/src/tools/v2/profile_update.ts +76 -0
  377. package/src/tools/v2/raw.ts +50 -0
  378. package/src/tools/v2/recovery.ts +36 -0
  379. package/src/tools/v2/sleep.ts +28 -0
  380. package/src/tools/v2/sleep_need.ts +26 -0
  381. package/src/tools/v2/smart_alarm.ts +29 -0
  382. package/src/tools/v2/smart_alarm_set.ts +103 -0
  383. package/src/tools/v2/sports_catalog.ts +32 -0
  384. package/src/tools/v2/strain.ts +28 -0
  385. package/src/tools/v2/stress.ts +28 -0
  386. package/src/tools/v2/symptom_log.ts +78 -0
  387. package/src/tools/v2/today.ts +35 -0
  388. package/src/tools/v2/trend.ts +31 -0
  389. package/src/tools/v2/workout.ts +28 -0
  390. package/src/tools/v2/workouts.ts +37 -0
  391. package/src/whoop/build_lift_body.ts +84 -0
  392. package/src/whoop/client.ts +118 -0
  393. package/src/whoop/cognito.ts +150 -0
  394. package/src/whoop/constants.ts +3 -0
  395. package/src/whoop/device.ts +106 -0
  396. package/src/whoop/errors.ts +41 -0
  397. package/src/whoop/init_timezone.ts +64 -0
  398. package/src/whoop/installation.ts +58 -0
  399. package/src/whoop/json_out.ts +9 -0
  400. package/src/whoop/oauth_provider.ts +377 -0
  401. package/src/whoop/session_state.ts +41 -0
  402. package/src/whoop/token_manager.ts +76 -0
  403. package/src/whoop/token_store.ts +45 -0
  404. package/src/whoop/types.ts +89 -0
  405. package/src/whoop/write_safety.ts +30 -0
package/.dockerignore ADDED
@@ -0,0 +1,23 @@
1
+ node_modules
2
+ dist
3
+ .env*
4
+ .totem-deploy.json
5
+ fly.toml
6
+ .git
7
+ .gitignore
8
+ .vitest-cache
9
+ coverage
10
+ tests
11
+ *.tsbuildinfo
12
+ *.log
13
+ .DS_Store
14
+ .vscode
15
+ .idea
16
+ README.md
17
+ CHANGELOG.md
18
+ CONTRIBUTING.md
19
+ SECURITY.md
20
+ WHOOP.md
21
+ LICENSE
22
+ Dockerfile
23
+ .dockerignore
package/.env.example ADDED
@@ -0,0 +1,66 @@
1
+ # ─── Required: fill in before running `totem auth` ──────────
2
+ # WHOOP_PASSWORD is used ONCE to log in, then auto-removed from this file after a
3
+ # successful auth — only the tokens below are needed afterward. Re-running `auth`
4
+ # re-prompts for it (masked).
5
+ WHOOP_EMAIL=your@email.com
6
+ WHOOP_PASSWORD=your-whoop-password
7
+
8
+ # ─── Populated automatically by `totem auth`. Do NOT edit. ──
9
+ WHOOP_IOS_BEARER_TOKEN=
10
+ WHOOP_COGNITO_REFRESH_TOKEN=
11
+
12
+ # ─── Generated once on first run + written here. Do NOT edit. ──
13
+ # Per-install device id sent as x-whoop-installation-identifier (so requests
14
+ # look like one app install, not a shared constant). Randomized per install.
15
+ WHOOP_INSTALLATION_ID=
16
+
17
+ # ─── Optional: avoids one redundant bootstrap call per session ─────────────
18
+ # Get this from `totem auth` output (or any captured JWT).
19
+ WHOOP_USER_ID=
20
+
21
+ # ─── Timezone for response timestamps ──────────────────────────────────────
22
+ # Whoop returns all timestamps in UTC. The MCP rewrites them with an explicit
23
+ # offset so the AI sees clock-correct local times (e.g.,
24
+ # "2026-05-25T15:30:00-07:00" instead of "2026-05-25T22:30:00Z").
25
+ #
26
+ # Resolution chain:
27
+ # 1. WHOOP_TIMEZONE (this var) — IANA name like America/Los_Angeles,
28
+ # America/New_York, Europe/London, Asia/Tokyo. Explicit override.
29
+ # 2. Auto-detected from your Whoop profile's timezone_offset field —
30
+ # runs on server boot and refreshes hourly. Travelers get
31
+ # auto-updates as their phone moves between zones.
32
+ # 3. System TZ — last resort. UTC inside Docker / Fly / Railway, so
33
+ # Tier 2 saves you here if you don't read these docs.
34
+ #
35
+ # Leave blank to use auto-detect.
36
+ WHOOP_TIMEZONE=
37
+
38
+ # ─── Remote hosting (HTTP transport) ───────────────────────────────────────
39
+ # Leave MCP_TRANSPORT unset (or "stdio") for local Claude Desktop / Claude Code.
40
+ # Set MCP_TRANSPORT=http to expose the MCP over HTTP for remote clients.
41
+ #
42
+ # MCP_TRANSPORT=http
43
+ # MCP_AUTH_TOKEN=<generate with: openssl rand -hex 32>
44
+ # PORT=3000 # or MCP_HTTP_PORT, default 3000
45
+ # WHOOP_TOKEN_STORE=envfile # or "memory" for read-only filesystems. NOTE:
46
+ # # "memory" does not persist a rotated refresh
47
+ # # token across restarts — also set
48
+ # # WHOOP_INSTALLATION_ID on ephemeral hosts.
49
+ #
50
+ # ─── Two ways to authenticate against the HTTP server ──────────────────────
51
+ # 1. Static bearer (MCP_AUTH_TOKEN) — works with Claude Code (--header) and the
52
+ # Claude Desktop mcp-remote bridge. Always on.
53
+ # 2. OAuth 2.1 — required for claude.ai web + the Claude mobile app's custom
54
+ # connectors (they have no bearer-token field). Enable by setting:
55
+ #
56
+ # AUTH_PASSWORD=<a password you'll type once when adding the connector>
57
+ # PUBLIC_URL=https://your-app.fly.dev # your server's public origin (OAuth issuer)
58
+ #
59
+ # MCP_AUTH_TOKEN doubles as the JWT signing secret. Leave AUTH_PASSWORD unset
60
+ # to disable the OAuth/web-connector path entirely.
61
+ #
62
+ # See README → "Remote hosting" for the full deploy walkthrough.
63
+ MCP_TRANSPORT=
64
+ MCP_AUTH_TOKEN=
65
+ AUTH_PASSWORD=
66
+ PUBLIC_URL=
package/CHANGELOG.md ADDED
@@ -0,0 +1,283 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project. Format roughly follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/); versioning is [SemVer](https://semver.org/).
4
+
5
+ ## [Unreleased]
6
+
7
+ ## [1.4.4] — 2026-06-11
8
+
9
+ ### Changed
10
+
11
+ - **Account rename: `briangaoo` → `thebriangao`** across all three homes:
12
+ - **GitHub:** the repo now lives at [`thebriangao/totem`](https://github.com/thebriangao/totem). Old `briangaoo/totem` URLs (and existing git remotes) redirect, but update your remote anyway: `git remote set-url origin https://github.com/thebriangao/totem.git`.
13
+ - **npm:** the package is now **`@thebriangao/totem`**. `@briangaoo/totem` is deprecated with a pointer and will receive no further releases — npm-global installs should reinstall: `npm install -g @thebriangao/totem`. Git installs are unaffected.
14
+ - **MCP registry:** the server id is now **`io.github.thebriangao/totem`** (the old `io.github.briangaoo/totem` entry is retired).
15
+ - Nothing else changed in this release — no code, tool, or env-var changes; tokens, deployments, and `.env` files all carry over untouched.
16
+
17
+ Hardening pass on the `totem update` flow introduced in 1.4.2.
18
+
19
+ ### Changed
20
+
21
+ - **The version picker dates each version by its commit date** (when that version's code was written), not the GitHub release's publish time. Backfilled tags — e.g. `v1.1.0`, tagged days after `v1.2.0` — now show their true date (2026-05-26) in chronological order. Also removed the duplicate `v1.0.0` tag/release (it pointed at the same initial commit as `v1.1.0`).
22
+
23
+ ### Fixed
24
+
25
+ - **`totem update` handles every deployment state, branching on your recorded deploy — never a hardcoded assumption.** No deployment → updates local code only and says so (no phantom redeploy). Local/stdio → reminds you to restart the MCP client. Fly / Railway / Cloud Run → rebuild-from-source redeploy + `/health` gate. **Self-hosted (Docker / VPS / Render / home box)** → it used to print a vague line then run a `/health` check that *passed against the still-old container*, falsely reporting success; it now prints the exact rebuild + restart steps (with the `.env.deploy` it wrote) and skips the misleading health check, since totem can't reach a container running elsewhere.
26
+ - **A missing platform CLI no longer fails cryptically.** Redeploying when `flyctl` / `railway` / `gcloud` isn't installed (a fresh machine, or updating from a different box than you deployed from) used to spawn-error with `ENOENT` + "server unchanged". It now reports that local code is updated but the deploy wasn't pushed, and how to finish it.
27
+ - **Token carry-over after a redeploy is surfaced.** A redeploy restarts the server; secrets persist, but `/health` passing doesn't prove Whoop auth survived (the cloud memory token store can strand a rotated refresh token), so the success path points at `totem auth` if calls start failing.
28
+
29
+ ## [1.4.2] — 2026-06-07
30
+
31
+ ### Added
32
+
33
+ - **`totem update` is now an interactive updater.** Running it opens a version picker — every release, newest first, with dates + notes from GitHub Releases. The newest is the default; choosing an older one warns you what you'd be behind on (and you can re-run to go forward — being on the latest doesn't lock you out of pinning an older version). After you choose, it applies the change with a guided, animated build (git installs fast-forward `main` or check out the pinned tag, reinstall deps, rebuild; npm installs reinstall the chosen version), then redeploys to your existing host and health-checks `/health`. Requires a clean working tree (won't clobber local edits); a failed deploy leaves the live server untouched.
34
+ - **Opt-in auto-update.** After updating to the latest, `totem update` offers to turn on auto-update — or toggle it directly with **`totem update --auto on`** / **`--auto off`**. When on, a background job (launchd on macOS, cron on Linux) checks for new releases every 6 hours and applies them the same way (pull → build → redeploy → health-check), logging to `.totem-autoupdate.log`. It's a scheduled poll (there's no push channel to a user's machine) and only ever moves you to **released**, CI-gated versions — never bleeding-edge `main`. `--auto on` also pulls the newest immediately.
35
+ - Versions come from where they already live — git tags + GitHub Releases (git installs) and the npm registry (global installs) — so there's no separate version index to host. `totem update --check` remains a non-interactive installed-vs-latest preview and now also reports the auto-update state.
36
+
37
+ ## [1.4.1] — 2026-06-07
38
+
39
+ ### Fixed
40
+
41
+ - **`whoop_journal` always returned `behaviors: []`** even when journal entries were logged and confirmed in the app ([#2](https://github.com/thebriangao/totem/issues/2), reported by @theanswertw). The v3 drafts endpoint nests each logged behavior as `{ behavior_tracker: {id, …}, tracker_input: {behavior_tracker_id, answered_yes, magnitude_input_*, …} }`, but the projection read `behavior_tracker_id` off the top level of each entry — always `undefined`, so every behavior was filtered out (while `cycle_id`, read from a different field, still came through). The projection now reads the nested `tracker_input`/`behavior_tracker` shape and falls back to the flat shape. Root-caused with a live write→read→restore probe against a real account; added a populated-draft fixture + regression tests so the empty-only fixture can't hide it again. Test suite 212 → 219.
42
+
43
+ ## [1.4.0] — 2026-06-05
44
+
45
+ ### Changed
46
+
47
+ - **Renamed the project to Totem.** `whoop-mcp` → `totem` across the package name (`@briangaoo/totem`), the CLI binary (`totem <command>`), the MCP registry id (`io.github.briangaoo/totem`), the server identity, the banner, and the docs. **Whoop itself is untouched** — every `whoop_*` tool, the `WHOOP_*` env vars, the private-iOS-API adapter, and `WHOOP.md` are byte-for-byte the same. Totem is becoming a device-agnostic wearables→AI bridge (the MCP + projection layer doesn't care what you wear); Whoop is the first and currently only shipping adapter, with **Fitbit, Apple Watch, and Garmin in progress**.
48
+ - *Migration:* the npm package is republished under `@briangaoo/totem` and the old `@briangaoo/whoop-mcp` is deprecated with a pointer. Existing installs keep working; to move over, reinstall and use `totem` instead of `whoop-mcp`. A cloud deployment's saved record was `.whoop-mcp-deploy.json` and is now `.totem-deploy.json` — rename it (or just re-run `totem cloud`) so `totem deploy`/`logs`/`update` find it.
49
+
50
+ ### Added
51
+
52
+ - **`totem update`** — a one-liner that pulls the latest release from GitHub and redeploys in place. Compares your `HEAD` against `origin/main`, fast-forwards (or reinstalls the global package), rebuilds, redeploys to your existing host, and pings `/health` to confirm. `totem update --check` does a no-write dry run that just reports installed-vs-latest. Opt-in, never automatic.
53
+ - **CI verify gate.** A GitHub Actions workflow (`.github/workflows/ci.yml`) runs `tsc --noEmit`, the full vitest suite, and a build on every push to `main` and every PR — so nothing reaches the default branch (or a merged contribution) without passing the same checks run locally.
54
+
55
+ ## [1.3.0] — 2026-06-01
56
+
57
+ ### Added
58
+
59
+ - **Direct setup for the major AI clients, in both flows.** `totem local` now wires the server into your pick of **Claude Desktop, Claude Code, Cursor, VS Code (Copilot), Gemini CLI, Codex CLI, or Windsurf** — writing the right config to the right path automatically (or printing a universal block for any other MCP client). `totem cloud`'s connect step prints ready-to-paste instructions for **claude.ai, ChatGPT, Claude Code (remote), and Cursor/Windsurf/any HTTP MCP client** — URL + password for the OAuth clients, a bearer-token config block for the header-auth ones. Every stdio client uses the identical launch entry, so the server still self-loads its `.env` no matter which app starts it.
60
+
61
+ ## [1.2.4] — 2026-06-01
62
+
63
+ Bug-fix release for a remote-connector regression introduced in 1.2.3. stdio / Claude Code connections were unaffected.
64
+
65
+ ### Fixed
66
+
67
+ - **The claude.ai web/desktop/mobile connector couldn't connect on 1.2.3.** The 1.2.3 security pass set a `Content-Security-Policy` on *every* HTTP response. On the JSON OAuth-metadata responses Claude read that as a "server configuration issue"; on the consent (password) page the `form-action 'self'` directive blocked the OAuth redirect back to Claude, so submitting the password silently did nothing. The CSP is removed from the API/metadata responses entirely, and from the consent page — which keeps `X-Frame-Options: DENY` (the clickjacking control that page actually needs).
68
+ - **Audience binding (RFC 8707) is now log-only, not enforced.** A strict `resource`-claim check risked 401-ing a valid token and bricking the connector, so it logs a mismatch instead of rejecting. It'll return as strict once verified against a live token.
69
+ - **Reverted `redirect: "error"` on the Whoop API client** back to the default (follow), so a redirecting endpoint can't make a data tool throw.
70
+ - The consent endpoint now logs *which* check failed (password vs. client decode vs. redirect) instead of always saying "incorrect password" — so a future failure is diagnosable.
71
+
72
+ ## [1.2.3] — 2026-05-31
73
+
74
+ A security-hardening release — no API or tool changes, all behavior-compatible. Came out of a full codebase security audit.
75
+
76
+ ### Security
77
+
78
+ - **Token files are now written `0600`** (owner-only) instead of inheriting a `0644` umask — `.env` and the token store, with a `chmod` repair so files from older versions get tightened on the next write.
79
+ - **Your Whoop password is removed from `.env` after a successful login.** It was only ever needed for the one bootstrap call; every refresh uses the token. Re-running `auth` re-prompts for it (masked).
80
+ - **OAuth JWTs are signed with a key derived from `MCP_AUTH_TOKEN`** (HMAC), not the token itself — the static bearer and the signing secret are no longer the same value in two roles.
81
+ - **Access tokens are audience-bound** (RFC 8707): a token's `resource` claim must match this server's `/mcp` URL, so a token can't be replayed against another deployment that shares the secret.
82
+ - **Security headers** on every HTTP response (`X-Frame-Options: DENY`, `X-Content-Type-Options: nosniff`, `Referrer-Policy`, strict CSP) — the connector password page can no longer be framed (clickjacking).
83
+ - **The connector-password gate is harder to brute-force**: a global attempt ceiling independent of the spoofable per-IP key, plus a 16-char + character-class floor for user-chosen passwords (the auto-generated one was always strong).
84
+ - **Fly secrets are pushed over stdin** (`secrets import`), not argv — token/password values are no longer visible in `ps`/`/proc` during deploy or token rotation.
85
+ - **`totem cloud` now verifies the auth gate after deploy** — it asserts an unauthenticated `/mcp` returns 401 before declaring success.
86
+ - **`.gitignore` now excludes every `.env*` variant** (incl. backups) so a stray `.env.bak` can't be committed; `.dockerignore` excludes `.env*` + the deploy record so they're never uploaded to a build context.
87
+ - Outbound requests use `redirect: "error"`, and API error messages no longer echo response-body fragments — defense-in-depth against token/data leakage.
88
+
89
+ ### Changed
90
+
91
+ - **Reduced request burstiness** for stealth: the wide read fan-outs (`whoop_compare`, `whoop_lift_history`) are now paced (≤3 concurrent, small jitter) instead of firing all at once, and `whoop_coach_ask` polls on a jittered interval instead of a fixed 1.000 s metronome.
92
+ - On read-only hosts the install identifier is derived deterministically from the account email (stable across restarts) instead of a fresh random one per process. A boot warning fires if the bundled iOS app version has gone stale.
93
+
94
+ ## [1.2.2] — 2026-05-31
95
+
96
+ ### Changed
97
+
98
+ - **The Whoop password is now hidden as you type** during `totem auth` / `cloud` / `local`. It previously echoed in plaintext — fine in private, but exposed on a screen-share or recording. Implemented with an explicit raw-mode reader (terminal echo off, characters captured but never rendered), masked in both the guided-flow prompt and the standalone `auth` script. Everything else stays visible (email, MFA code, the auto-generated connector password).
99
+ - **New demo.** Replaced the static screenshot with a ~2-minute screen recording of the full `totem cloud` flow (`assets/demo.mp4`): install → Whoop login → Fly deploy → Claude connector → first query. The README loads it from GitHub, so it isn't bundled into the npm package.
100
+
101
+ ## [1.2.1] — 2026-05-31
102
+
103
+ A correctness + stealth pass. Every read and write tool was exercised individually against a live account (each call's raw API exchange compared with the projected output and the state read back), which surfaced a class of "returns HTTP 200 but the payload is empty or wrong" bugs that receipt-only testing missed.
104
+
105
+ ### Added
106
+
107
+ - **iOS-app identity headers on every data request.** The data client now sends the WHOOP iOS app's own header set — `user-agent: iOS`, `x-whoop-device-platform`/`-ios-version`/`-ios-build-number`/`-bundle-name`/`-installation-identifier`/`-time-zone`/`-clock-format`, `currency`/`locale`/`accept-language`/`priority`, and the capitalized `Bearer` scheme — captured from a live mitmproxy session (`src/whoop/device.ts`). Previously requests were a bare bearer token, which is trivially distinguishable from the app. The static values are the app's shared constants (camouflage, not a per-user signature); the installation identifier is a per-install random UUID persisted to `.env` (`src/whoop/installation.ts`, new `WHOOP_INSTALLATION_ID`); timezone is host-derived. We deliberately send nothing the app doesn't (no Sentry/`baggage`/`sentry-trace`, no marketing cookies), since a unique invented header in open-source code would be the exact one-line WAF rule to avoid. Transport-layer fingerprint (TLS/HTTP-2) is left unchanged — out of scope, and a Node TLS signature can't be hidden anyway. Full reasoning in `WHOOP.md` → "Headers for data requests".
108
+ - **`whoop_behavior_impact` is now self-discovering.** Called with no `behavior_id` it returns the list of every behavior with its `impact_uuid` + headline effect (from `GET /behavior-impact-service/v1/impact`); called with a UUID it returns the detail. Previously the tool only had the detail mode and required an impact UUID that **no other tool exposed** — so it was effectively un-callable by an AI (the catalog gate it carried pointed at the numeric `behavior_tracker_id`, the wrong id). The wrong gate was removed.
109
+
110
+ ### Fixed
111
+
112
+ These all returned `200` with an empty or wrong projection before — the kind of bug that passes a green test suite and a status-code check:
113
+
114
+ - **`whoop_stress` returned an empty timeline.** The projection read `stress_state.timeline`, but `stress_state` is a string (`"RELAXED"`); the real data is in `gauge` (current level) + `stress_graph.graph` (the intraday points). Rewritten; the ~700-point graph is downsampled to ≤48 timeline points with reconstructed timestamps.
115
+ - **`whoop_trend` returned `value: null` (and blank dates) for every time/duration metric** (TIME_IN_BED, SLEEP_DEBT_POST, RESTORATIVE_SLEEP, the three STRESS metrics, HR_ZONES_1_3/4_5, STRENGTH_ACTIVITY_TIME). Those metrics render as bar plots — the value + date live in `bar_groups[].bars[].data_scrubber_details`, not the group-level label the projection read — and `labelToNumber` rejected the `"11:14"` duration form. Now reads the per-bar details and falls back to `timeLabelToMs`.
116
+ - **`whoop_cycle` returned all-null despite a populated response.** The projection searched for tile types (`CYCLE_PHASE_TILE`, `HORMONAL_MODE_TILE`) that don't exist in the `menstrual-cycle-insights` BFF. Rewritten to read the real tiles — `HEADER_TILE` (phase + "Cycle Day N"), `TYPICAL_CYCLE_TILE` (cycle length), `CALENDAR_TILE` (period/ovulation predictions from first-day-of-phase markers). Also: this endpoint must be called **with** the `date` query param (it 404s without it) — which is why it was previously misdiagnosed as "women's-health not enabled".
117
+ - **`whoop_workout` `hr_curve` was always empty.** The points carry no timestamp field — the bpm is in `value_display`, the time is `position_x` (fraction of the workout window). The old code looked for a `timestamp`/`dsd.timestamp` that never existed and dropped every point. Now rebuilt from `start + position_x·duration`, downsampled to ≤120 points.
118
+ - **`whoop_lift_progression` mislabeled its segments** (`week`/`month`) for exercises that only have `month`/`six_month` data, because it labeled by array position. Now labels from `segment_controller.element_names`. Same bar-plot parsing fix as `whoop_trend`.
119
+ - **`whoop_recovery` returned null SpO2 / skin temperature.** Those aren't in the deep-dive tiles; the tool now also fetches `/developer/v2/recovery` and reads `score.spo2_percentage` / `score.skin_temp_celsius`.
120
+ - **`whoop_coach_ask` returned a truncated reply.** The Whoop Coach response streams token-by-token, and the poll loop broke on the first non-empty chunk — so it returned a fragment like `"56"` instead of the finished answer. Now keeps the latest text and stops only when the turn is `COMPLETE` (or the text settles).
121
+ - **`whoop_symptom_log` crashed on menstruation-only / cervical-mucus-only calls** (`Cannot read properties of undefined (reading 'length')` when `symptoms` was omitted). Guarded with a default — the zod default already covered the live MCP path, but the handler is now robust on any path.
122
+
123
+ ### Changed
124
+
125
+ - **`whoop_journal_log` description now warns it REPLACES the day's entry** and instructs reading `whoop_journal` first to avoid silently wiping behaviors already logged that day.
126
+ - **`whoop_smart_alarm_set` description routes wake-time changes to `mode=schedule`.** `mode=preferences` returns 200 but its `lower/upper_time_bound` don't persist when an explicit schedule exists (server-ignored, verified live); the schedule mode is what actually controls the wake time.
127
+ - Description clarifications for `whoop_cycle` (needs women's-health enabled; some fields always null) and `whoop_workout` (a just-logged activity is `pending` and errors on detail reads until scored).
128
+ - **Tool descriptions rewritten across the surface** — terser and deliberately example-free for id-taking tools (listing sample ids led the model to guess ones outside the list; now it must read the catalog), with the catalog read enforced by a hard gate that errors until the matching catalog tool (`whoop_sports_catalog` / `whoop_lift_catalog` / `whoop_journal_catalog`) has been called that session (`whoop_activity_create`, the three lift writes, `whoop_journal_log`, `whoop_symptom_log`).
129
+ - Test suite 178 → **212** — added `tests/projections/round3_data_fixes.test.ts` (regressions for every projection bug above; each assert fails against the pre-fix code) plus new committed fixtures (`cycle_insights.json`, `behavior_impact_list.json`, `recovery_v2.json`, `trend_time_in_bed.json`).
130
+
131
+ ## [1.2.0] — 2026-05-29
132
+
133
+ ### Security
134
+
135
+ - **OAuth consent gate hardened.** The connector password minimum is now 12 chars (was 4), and `POST /oauth/consent` — a custom route not covered by the SDK's OAuth rate-limiter — now enforces a per-IP fixed-window limit (10 attempts / 15 min → `429`), blunting brute force against the gate to your health data.
136
+ - **Scrubbed every real identifier from the bundled endpoint catalog.** `src/data/endpoints.ts` shipped concrete identifiers captured during reverse-engineering — community + user IDs, a personal email, a device serial + signature, HealthKit pairing tokens, and capture timestamps. All are now templated (`{id}`, `{userId}`, `{email}`, `{strapSerial}`, `{strapSignature}`, `{token}`, `{code}`, `{timestamp}`) and the list deduped (384 → 311 entries). The generator's contract (header comment) is now actually enforced.
137
+
138
+ ### Fixed
139
+
140
+ - **`whoop_journal` (+ other timestamp fields) threw on Whoop's no-colon offset form.** Output schemas used `z.iso.datetime({ offset: true })`, which rejects the `+0000` / `-0700` form Whoop's journal/pg-range endpoints emit — and validation runs *before* `localizeTimestamps` normalizes it, so a populated `recorded_at` raised `WhoopProjectionError`. Replaced with a shared `IsoDateTime` schema (in `schemas/primitives.ts`) accepting `Z`, `±HH:MM`, and `±HHMM`; added a regression test.
141
+ - **HTTP server crashed on boot when `PUBLIC_URL` was empty.** `process.env.PUBLIC_URL ?? localhost` let an empty string reach `new URL("")` (a `TypeError`), crash-looping the first deploy on hosts that inject `PUBLIC_URL=""` (the Railway / Cloud Run first pass). Now treated as unset (`||`).
142
+ - **`whoop_lift_log` mislabeled the logged workout's timezone on cloud hosts** (used the system zone — UTC on Fly/Docker). Now prefers an IANA `WHOOP_TIMEZONE`, falling back to the system zone for local use.
143
+ - **`whoop_workouts` `limit` now caps at 25** to match the upstream API page size (the schema advertised up to 50 but the fetch silently returned ≤25).
144
+ - CLI banner tool count corrected (47 → 48); removed dead code in the recovery/trend projections; clarified the `session_state` gate comment (per-process, not per-session).
145
+
146
+ ### Added
147
+
148
+ - **Two guided "one-command" setup flows** — the new recommended way to get going:
149
+ - **`totem cloud`** ★ — walks you through the entire server-hosted path in one command: Whoop auth (SMS handled) → pick a host → generate `MCP_AUTH_TOKEN` + connector password → set env → deploy → verify `/health` + OAuth metadata are live → open claude.ai's connector page and print the URL + password to paste. By the end, Claude is connected across web, desktop, and mobile. Platforms: **Fly**, **Railway**, and **Cloud Run** — all fully CLI-automated and tested end-to-end (installs the host CLI if missing, logs you in, deploys, auto-detects the URL, sets `PUBLIC_URL`, verifies `/health` + OAuth) — plus **Custom** (printed Docker + env steps for any other host or your own server). OAuth is the default. (Koyeb was dropped before release — its signup now forces a paid $30/mo plan, so it no longer fits a zero-cost path; the Custom/Docker route covers it.)
150
+ - **`totem local`** — guided stdio setup: auth → build → writes the Claude Desktop config (or prints the Claude Code one-liner).
151
+ - New CLI modules `src/cli/ui.ts` (shared prompts/colors/runners) + `src/cli/setup.ts` (the flows). `cloud` writes a `.totem-deploy.json` record so `auth` knows where to push.
152
+ - **Warm by default — no cold starts.** Fly deployments now set `min_machines_running = 1` + `auto_stop_machines = "suspend"`, and Cloud Run gets `--min-instances 1`, so the connector never cold-starts — without this, the first request after an idle auto-stop fails while the VM/container boots (~10s). Railway already runs continuously; the printed Custom `docker run` uses `--restart unless-stopped`.
153
+ - **Interactive UX hardening (both flows).** Animated spinners on every otherwise-silent step (network lookups, health polling, backoff waits — driven by an async `captureAsync` so they actually animate, since `spawnSync` blocks the loop). **Explicit confirmations** before anything sensitive — IAM grants, API enablement, billable deploys, project creation, dependency installs, account switches — each printing the exact command + consequence. **Arrow-key (↑/↓, j/k, number) selection** replacing every numbered prompt, hardened against concatenated/split key delivery and EOF (no more hangs on Ctrl-D). **Account + GCP-project pickers** are now always offered (use current, switch account, or create a project) instead of silently inheriting whatever's active. Plus: auto-generated 18-char connector password copied to the clipboard, and the deployed URL auto-detected (no paste step). Every one of the five paths (Fly/Railway/Cloud Run/Custom + local) was deployed and verified end-to-end through the real CLI.
154
+ - **Banner on every command.** The figlet "WHOOP MCP" banner now prints at the top of *every* `totem` invocation (was: only the no-arg help). It's written to **stderr**, so it shows in the terminal without ever polluting stdout — `start`/`dev` keep a clean MCP protocol stream and `version`/`config` stay machine-parseable + pipe-safe.
155
+ - **One `auth` command for all token management** (replaces `bootstrap` + `rebootstrap`). `totem auth` logs you into Whoop, saves the tokens to `.env`, and **auto-detects** two things: *new vs re-auth* (whether you already have tokens — messaging only) and *local vs deployed* (reads `.totem-deploy.json`). For a deployment it pushes the new tokens to **wherever you actually deployed** — Fly (`fly secrets set`), Railway (`railway variables`), Cloud Run (`gcloud run services update`), printed values for a Custom host — or notes "restart your client" for a local install. Auto/silent when the account has no SMS MFA; prompts for the code when it does. The separate `refresh` command was removed; the guided `cloud`/`local` flows call `auth` internally in tokens-only mode so they don't double-push. Help is grouped with the two guided commands as the headline; everything else (logs, ping, deploy, start, etc.) stays available as advanced commands.
156
+ - **Sleep hypnogram + in-sleep heart rate.** `whoop_sleep` now returns the full **hypnogram** — the per-stage timeline (REM/light/SWS/wake), ~58 segments a night — reconstructed from the deep-dive's per-stage HR-curve points, plus **`sleep_hr`** (avg/min bpm). Both were schema'd but previously returned empty/null. Transition times come from each point's clock label anchored to the sleep window at its midpoint (the graph's `position_x` carries ~40 min of axis padding), emitted in UTC for `localizeTimestamps`. Sleep HRV / respiratory rate / debt / latency stay null — not exposed by the endpoint.
157
+
158
+ ### Added
159
+
160
+ - **OAuth 2.1 authorization server (for claude.ai web + Claude mobile connectors).** Claude's custom-connector UI on web/mobile only supports OAuth — there's no bearer-token field — so the bearer setup only worked with Claude Code and the Claude Desktop `mcp-remote` bridge. The HTTP server now embeds a full OAuth 2.1 + PKCE authorization server (via the MCP SDK's `mcpAuthRouter` + a custom `OAuthServerProvider`), so the deployed server can be added as a custom connector and synced across every device on your Claude account.
161
+ - **Password gate**: the `/authorize` step serves a small password page; the user enters `AUTH_PASSWORD` once when adding the connector. A stranger who finds the URL still can't connect.
162
+ - **Stateless by design** (survives Fly's auto-stop restarts): access + refresh tokens are HS256 JWTs signed with `MCP_AUTH_TOKEN`; registered clients (dynamic client registration) encode their redirect URIs into a signed `client_id`, so Claude never has to re-register after a cold start. Only the 60-second authorization codes are in-memory.
163
+ - **Backward compatible**: `/mcp` still accepts the static `MCP_AUTH_TOKEN` bearer (Claude Code + Desktop bridge unchanged). `verifyAccessToken` accepts either.
164
+ - New env vars: `AUTH_PASSWORD` (enables the OAuth path) and `PUBLIC_URL` (the OAuth issuer origin). Leave `AUTH_PASSWORD` unset to disable.
165
+ - The HTTP server migrated from raw `node:http` to **Express** (required by the SDK's OAuth router). The per-session McpServer routing is unchanged. 9 new OAuth provider tests + the 9 existing HTTP-auth tests pass (the auth gate now returns spec-correct status codes via the SDK's `requireBearerAuth`).
166
+
167
+ ### Fixed
168
+
169
+ - **Timezone, both directions.** Two bugs were causing the AI to see wrong clock values:
170
+ - *Output:* `localizeTimestamps` only matched `Z`-suffixed timestamps, but Whoop's journal + pg-range endpoints emit the `+0000` form (e.g. `2026-05-23T07:35:46.220+0000`). Those passed through as UTC. The matcher now catches `Z`, `+0000`, and `+00:00`, all of which mean UTC, and rewrites them to the user's local offset.
171
+ - *Input:* `todayIso()` (the default for ~12 tools' `date` param) computed "today" from the server's calendar day. On a UTC host like Fly, that's a day ahead of the user during their evening, so "how am I doing today" could query tomorrow. It now resolves the calendar day in the configured `WHOOP_TIMEZONE` / auto-detected profile TZ via a new `zonedParts()` helper. `performance_assessment` had the same class of bug (`getTimezoneOffset()` returns 0 on UTC hosts) — fixed to use the configured TZ. 10 new timezone tests (164 total).
172
+ - **`whoop_lift_history` description was misleading.** It claimed "set-level detail" but its `sets[]` array is always empty — the `/cardio-details` endpoint only exposes per-exercise aggregates. So when asked for individual sets, the AI called `lift_history` and got nothing useful. The description now states it returns per-exercise aggregates and routes per-set questions to `whoop_lift_exercise`, which already returns every set (reps/weight/medal per set) correctly.
173
+
174
+ ### Added
175
+
176
+ - **`whoop_communities`** (new tool, brings total to 48). Lists the communities you're a member of (teams, friend groups) with member counts and — optionally — your rank in each across a chosen metric (strain/sleep/recovery) over a window (day/week/month). Complements `whoop_leaderboard`: use `whoop_communities` to discover community IDs, then drill into one with `whoop_leaderboard`. Source: `GET /community-service/v1/communities/memberships` (already in use by `whoop_leaderboard` for community auto-discovery). Schema is permissive at the record level since the per-record field set hasn't been captured against a live account at the time of release — a `WhoopProjectionError` from this tool is the signal that Whoop's actual shape differs from the inferred one and the projection needs tightening.
177
+ - **Strain target** added to `whoop_strain` output. The existing deep-dive response carries `score_target`, `lower_optimal_percentage`, and `higher_optimal_percentage` as 0–1 fractions of max strain (21); the projection multiplies by 21 to expose them as strain values. New schema field: `target: {value, optimal_lower, optimal_upper}`. Lets the AI answer "should I work out today?" with a concrete number ("you're at 18.9, target was 13.2 — already past optimal") instead of just a state label.
178
+
179
+ ### Added (earlier in this cycle)
180
+
181
+ - **README banner.** New SVG banner at the top of the README (`assets/banner.svg`) — figlet-style "WHOOP MCP" block text in light gray with a 5-beat EKG pulse waveform underneath (real `<path>` element, not ASCII), centered horizontally, theme-aware via `prefers-color-scheme` (auto-flips to light text on dark mode). Added `assets/` to `package.json` `files` whitelist so it ships with the published package.
182
+
183
+ ### Fixed
184
+
185
+ - **Timestamps returned in user's local timezone.** Whoop's API returns every timestamp in UTC (`2026-05-25T22:30:00Z`), which confused the AI on the consumer side — `22:30:00` got interpreted as a clock time when it's really 3:30 PM in San Jose. The MCP now rewrites every UTC timestamp in tool responses with an explicit local offset (`2026-05-25T15:30:00-07:00`) — same instant, but the AI sees the actual local clock value. Implementation: single helper in `src/lib/timezone.ts`, applied in `jsonOut()` so every tool gets the conversion for free.
186
+
187
+ Three-tier resolution chain so OSS users on any host get sensible timestamps without manual config:
188
+ 1. **`WHOOP_TIMEZONE` env var** (IANA name like `America/Los_Angeles`) — explicit override.
189
+ 2. **Auto-detected from Whoop profile.** On server boot, the MCP fetches `/users-service/v2/bootstrap` and caches the user's `timezone_offset` (e.g., `-0700`). Refreshes hourly so travelers get auto-updates without restarting. Fire-and-forget — server startup doesn't block on the fetch.
190
+ 3. **System TZ** — last resort. UTC on Fly/Railway/Docker, so Tier 2 saves you here.
191
+
192
+ Tier 2 means `WHOOP_TIMEZONE` is now **optional** for nearly all users — local installs use system TZ, deployed installs use the Whoop-profile fallback automatically. `toLocalIso()` handles both IANA names (`America/Los_Angeles`) and fixed offsets (`-0700`, `-07:00`) since Whoop's API returns the offset form. 25 unit tests covering DST transitions, positive/negative/half-hour offsets, date rollover, millisecond precision, the priority chain, and pass-through for date-only / non-ISO strings.
193
+ - **Claude Desktop config for remote MCP.** Docs (README → Remote hosting) and the `totem config http` CLI command previously emitted the `{"url": "...", "headers": {...}}` format for Claude Desktop, which Claude Desktop rejects with *"The following entries in claude_desktop_config.json are not valid MCP server configurations and were skipped"*. That format only works for **Claude Code** (which natively supports remote MCP). Claude Desktop only speaks stdio, so the docs + CLI now emit a stdio bridge config using [`mcp-remote`](https://www.npmjs.com/package/mcp-remote) — a small Node package that proxies HTTP MCP servers as stdio. First run downloads via `npx` (~5s), subsequent runs are cached.
194
+
195
+ ### Added
196
+
197
+ - **`totem` CLI.** New first-class command (single binary, installable via `npm link` or, once published, `npm install -g totem`) that wraps every npm script plus operational helpers. Works from any directory — the CLI resolves its own install root from `import.meta.url`, so `totem deploy` from `~/Desktop` does the same thing as `cd totem && fly deploy`.
198
+ - Subcommands across 5 groups:
199
+ - **Local**: `start [--http]`, `dev`, `dev:http`, `build`, `test`, `typecheck`
200
+ - **Setup**: `auth` (login + token refresh; pushes to your deployment)
201
+ - **Deployed**: `deploy`, `logs`, `status`, `ping`
202
+ - **Inspect**: `info`, `tools`, `config <stdio|http>`
203
+ - **Help**: `help`, `version` (+ `--help`, `-h`, `--version`, `-v` aliases)
204
+ - ANSI 24-bit truecolor banner with the Whoop pulse waveform (honors `NO_COLOR`, skipped on non-TTY stdout).
205
+ - `totem start` keeps stdout clean (no banner, no header) so it works as a drop-in for `node dist/server.js` in Claude Desktop stdio configs.
206
+ - `totem ping` and `totem status` hit the deployed `/health` endpoint live — instant "is my deploy alive" check.
207
+ - `totem config http` and `totem config stdio` print pre-filled Claude Desktop config snippets with absolute paths or your detected Fly URL.
208
+
209
+ ### Changed
210
+
211
+ - `package.json` → `bin.totem` now points at `./dist/cli/index.js` (was `./dist/server.js`). The MCP server is still bootable via `totem start` — this is a CLI surface change, not a server change. Anyone with a Claude Desktop config invoking `totem` directly (none of the published quickstarts did this) should switch to `totem start` or stay on `node dist/server.js`.
212
+ - Token refresh is folded into `totem auth`: re-running it logs you back in and (for a deployment) pushes the new tokens to the host in one command — solving the ~30-day refresh-token expiry for remote deployments.
213
+ - Troubleshooting + README → Remote hosting now document the recovery flow: when Cognito tokens hit their 30-day wall, you run `totem auth`, type the SMS code (if your account has MFA), and the new tokens get pushed to your deployment automatically (~10s restart).
214
+
215
+ ### Known limitation
216
+
217
+ - The `auth` re-auth flow still requires you to be at a machine with the repo + the platform CLI installed. If you're traveling when the token dies, you're locked out. A future feature would add a `/admin` web route accepting the SMS code from a browser, callable from a phone.
218
+
219
+ ## [1.1.0] — 2026-05-26
220
+
221
+ ### Added
222
+
223
+ - **Remote hosting via HTTP transport.** The MCP now supports two transport modes:
224
+ - `MCP_TRANSPORT=stdio` (default) — current local Claude Desktop / Claude Code behavior
225
+ - `MCP_TRANSPORT=http` — boots a Streamable HTTP server at `/mcp` behind a bearer-token gate, suitable for deployment to Fly.io, Railway, Render, a VPS, or any Docker host
226
+ - Static bearer-token auth via `MCP_AUTH_TOKEN` env var (generate with `openssl rand -hex 32`). Constant-time compare to dodge timing attacks. Returns 401 on missing or wrong token without leaking which.
227
+ - Health probe at `GET /health` (no auth).
228
+ - CORS pre-configured for browser-based MCP clients.
229
+ - **`Dockerfile`** — multi-stage Alpine build, ~150 MB, runs as the non-root `node` user, ships a `HEALTHCHECK` directive. Deploy anywhere that runs containers.
230
+ - **`TokenStore` abstraction** (`src/whoop/token_store.ts`) — `EnvFileTokenStore` (default, writes refreshed tokens back to `.env`) and `MemoryTokenStore` (for read-only filesystems like Cloudflare Workers). Selectable via `WHOOP_TOKEN_STORE` env var. The Dockerfile uses `memory` by default; mount a writable volume + set `envfile` if you want persistence across restarts.
231
+ - **New npm scripts**: `dev:http` and `start:http` for running locally in HTTP mode.
232
+ - **9 HTTP-auth unit tests** in `tests/whoop/http_auth.test.ts` covering: 401 with no header / wrong token / wrong-length token (timing-safe path), 400 malformed body, 200 `/health` (no auth), 404 unknown path, 204 OPTIONS preflight with CORS headers, refuses to start with missing or too-short auth token.
233
+ - **New README section: "Remote hosting"** — full walkthrough including the Docker-based deploy path, instructions for Fly / Railway / Render / VPS / Cloudflare Tunnel, AI-client config snippets for both Claude Desktop and Claude Code with the bearer header, environment-variable reference, and a security model section.
234
+
235
+ ### Changed
236
+
237
+ - `TokenManager` constructor now takes either `{ store: TokenStore }` or `{ envPath: string }` (the latter is shorthand for `new EnvFileTokenStore(envPath)`). Existing local stdio behavior is unchanged.
238
+ - Server version bumped to 1.1.0 in both `package.json` and the `McpServer` constructor.
239
+
240
+ ### Migration
241
+
242
+ The default `MCP_TRANSPORT=stdio` means existing local installs are unaffected. To move to HTTP, follow the new [Remote hosting](README.md#remote-hosting) walkthrough.
243
+
244
+ ## [1.0.0] — 2026-05-26
245
+
246
+ Initial public release.
247
+
248
+ ### Added
249
+
250
+ - **47 MCP tools** wrapping Whoop's private iOS API:
251
+ - 31 reads (today, day, profile, calendar, recovery, sleep, strain, trend, compare, stress, sleep_need, live_hr, live_state, live_stress, workouts, workout, sports_catalog, lift_prs, lift_exercise, lift_progression, lift_history, lift_library, lift_catalog, journal, journal_catalog, behavior_impact, cycle, performance_assessment, smart_alarm, leaderboard, hr_zones)
252
+ - 14 writes (activity_create, activity_delete, lift_log, lift_template_save, lift_custom_exercise, journal_log, journal_autopop, cycle_log, symptom_log, smart_alarm_set, hr_zones_set, profile_update, hidden_metric, coach_ask)
253
+ - 2 escape hatches (raw, endpoints)
254
+ - **4 bundled catalogs** generated from live API: 372 official Strength Trainer exercises, 308 journal behaviors, 203 sport_id mappings, 384 deduped iOS endpoint paths.
255
+ - **Session-scoped catalog gate** in `src/whoop/session_state.ts`. Tools that take exercise / behavior / sport IDs refuse to run until the corresponding lookup tool has been called once per session. Keeps ~14k tokens out of the system prompt.
256
+ - **Write-safety harness**: every write tool defaults `confirm: false`, returning a preview of what would be sent. AI must explicitly re-call with `confirm: true` to fire.
257
+ - **AWS Cognito auth** via Whoop's `/auth-service/v3/whoop/` proxy. No AWS SDK, no client secret extraction. Supports SMS MFA + TOTP. Auto-refresh on 401 with single-flight gate; persists refreshed tokens to `.env`.
258
+ - **Structured zod-validated outputs**. Every tool's response goes through a per-tool schema before returning to the client — catches Whoop API drift instead of silently returning malformed data.
259
+ - **TypeScript 6 strict** with `noUncheckedIndexedAccess`, `exactOptionalPropertyTypes`, `noImplicitOverride`. Node 24+.
260
+ - **116 unit tests** (vitest, fixture-driven projection tests).
261
+ - **MIT license** with Whoop trademark disclaimer.
262
+
263
+ ### Documentation
264
+
265
+ - [`README.md`](README.md) — full developer-grade documentation: setup, every tool's signature + endpoints + caveats, architecture, schema design, write-safety details, token usage analysis, FAQ, troubleshooting.
266
+ - [`WHOOP.md`](WHOOP.md) — 5,900-line reverse-engineering writeup: methodology, every microservice, every endpoint, every body shape, every enum, every status code pattern, auth flows, capture sessions, the dedup pipeline.
267
+
268
+ ### Known limitations
269
+
270
+ - **Reverse-engineered.** Whoop can change response shapes any time; when they do, projections may need updating. The zod schemas surface drift as `WhoopProjectionError` rather than silent corruption — see [Fixing a broken projection](README.md#fixing-a-broken-projection) for the recovery loop.
271
+ - **Avatar upload** is not wrapped (requires multipart upload with raw PNG bytes).
272
+ - **Webhooks** (Whoop's push-notification surface for sleep/workout/recovery events) are not exposed by the MCP. The OAuth API has 6 webhook events; we don't currently subscribe.
273
+ - **Per-set strength detail** (set 1: 10 reps @ 200lbs, set 2: ...) is not available in `/cardio-details`. `whoop_lift_history` returns per-exercise aggregates (set count, total reps, tonnage, medals). For per-set numbers across all your workouts of a specific exercise, use `whoop_lift_exercise`.
274
+ - **`whoop_cycle`** requires the user's MCI (menstrual cycle insights) survey to be completed. Fresh accounts return 400 until they set `contraception_type`.
275
+
276
+ ### Pre-1.0 milestones (in the testing repo)
277
+
278
+ The v1 codebase (a thinner raw-passthrough version with no projections or write-safety harness) is archived at `../whoop-testing/v1/` for reference.
279
+
280
+ Reverse-engineering happened across three mitm capture sessions in May 2026:
281
+ - **Phase 1** (2026-05-23): primary account, read-heavy session, 122 MB capture
282
+ - **Phase 8a** (2026-05-24): test account onboarding, 29 MB
283
+ - **Phase 8b** (2026-05-24): test account write surface, 284 MB
@@ -0,0 +1,149 @@
1
+ # Contributing to totem
2
+
3
+ Pull requests welcome. The codebase is small and the test suite is fast, so iteration is quick.
4
+
5
+ ---
6
+
7
+ ## Quick orientation
8
+
9
+ ```
10
+ src/
11
+ ├── server.ts # MCP entry — branches on MCP_TRANSPORT (stdio default, http opt-in)
12
+ ├── server-http.ts # Streamable HTTP transport + bearer-token auth gate (since v1.1.0)
13
+ ├── whoop/ # Auth + HTTP-client layer (don't break unless you know what you're doing)
14
+ │ ├── client.ts # Outbound HTTP wrapper, error classification, 30s timeout
15
+ │ ├── cognito.ts # Cognito proxy auth (no AWS SDK, no client secret)
16
+ │ ├── token_manager.ts # Auto-refresh, single-flight, persists via TokenStore
17
+ │ ├── token_store.ts # EnvFileTokenStore + MemoryTokenStore (since v1.1.0)
18
+ │ ├── write_safety.ts # preview() + withPreview() helpers
19
+ │ ├── build_lift_body.ts
20
+ │ ├── session_state.ts # In-memory catalog-gate Set
21
+ │ ├── errors.ts, json_out.ts, constants.ts, types.ts
22
+ ├── data/ # Auto-generated catalogs (behaviors, exercises, sports, endpoints)
23
+ ├── schemas/ # zod schemas for every tool's output (the contract with Claude)
24
+ ├── projections/ # Raw API response → flat domain object (one per tool group)
25
+ ├── lib/ # walk / dates / format / stats helpers
26
+ └── tools/
27
+ ├── register.ts # Wires every tool to the MCP server
28
+ └── v2/ # 48 tool handlers, one per file
29
+ ```
30
+
31
+ Every tool follows a three-layer pattern: **schema** (defines the output shape) → **projection** (walks the raw API response into that shape) → **tool** (registers it with the MCP server, validates input args, calls the client, runs the projection, returns).
32
+
33
+ See [README.md → Architecture](README.md#architecture) for the full pattern walkthrough. See [README.md → Remote hosting](README.md#remote-hosting) for the HTTP transport architecture (added in v1.1.0).
34
+
35
+ ---
36
+
37
+ ## Setup
38
+
39
+ ```bash
40
+ git clone https://github.com/thebriangao/totem.git
41
+ cd totem
42
+ npm install
43
+ npx tsc && npm link # one-time: builds + puts `totem` on PATH
44
+ cp .env.example .env
45
+ # edit .env with your Whoop creds
46
+ totem auth
47
+ totem test # 233 tests, <2s
48
+ totem typecheck
49
+ totem build
50
+
51
+ # stdio mode (default, for local Claude Desktop / Claude Code):
52
+ totem dev
53
+
54
+ # HTTP mode (for remote hosting via Docker/Fly/etc.):
55
+ MCP_AUTH_TOKEN=$(openssl rand -hex 32) totem dev:http
56
+ curl http://localhost:3000/health # → {"status":"ok"}
57
+ ```
58
+
59
+ > The only `npm` steps are `npm install` and the one-time `npx tsc` (you need a build before the `totem` CLI exists). Everything else is a `totem` command — `package.json` has no `scripts`. `totem test`/`dev`/`typecheck` run against the source directly, so you don't rebuild to iterate.
60
+
61
+ ---
62
+
63
+ ## Adding a new tool
64
+
65
+ Walkthrough lives in [README.md → Adding a new tool](README.md#adding-a-new-tool). Short version:
66
+
67
+ 1. Pick a source endpoint (browse [`WHOOP.md`](WHOOP.md) for the relevant microservice).
68
+ 2. Add a zod schema in `src/schemas/`.
69
+ 3. Add a projection function in `src/projections/`. Tested against captured fixtures in `tests/fixtures/*.json`.
70
+ 4. Add a tool file in `src/tools/v2/` (~30 lines: register with the MCP server, parse args, call client, project, validate, return).
71
+ 5. Wire it up in `src/tools/register.ts`.
72
+ 6. Add a projection test in `tests/projections/`.
73
+ 7. `totem typecheck && totem test && totem build`.
74
+
75
+ ---
76
+
77
+ ## Fixing a broken projection (Whoop API drift)
78
+
79
+ When Whoop changes a response shape, projections may start returning all-null or partial outputs. They typically don't throw — zod schemas validate the *shape*, not the *content*, so null-heavy outputs pass validation silently.
80
+
81
+ To debug:
82
+
83
+ 1. Hit the endpoint live via `whoop_raw` — get the current shape into your hands.
84
+ 2. Save it as a captured fixture under `tests/fixtures/`.
85
+ 3. Diff against the old fixture. Common drift patterns:
86
+ - Tile types renamed (e.g. `GRAPHING_CARD` → `SCORE_GAUGE`)
87
+ - Card titles changed (e.g. `"RECOVERY"` → no title, identified by `content.id` instead)
88
+ - Sport name mappings changed (e.g. `weightlifting_msk` exposed via different internal_name)
89
+ 4. Rewrite the projection to walk the new shape.
90
+ 5. Update the per-projection tests with the new expected values.
91
+ 6. Document the migration in [`WHOOP.md`](WHOOP.md) so the next person knows.
92
+
93
+ Recent precedents to read:
94
+ - May 2026 deep-dive migration: `src/projections/recovery.ts`, `src/projections/strain.ts`. See [Pattern 2b in the endpoints doc](WHOOP.md).
95
+ - Sport-name filter fix: `src/projections/lift_history.ts` — old `/strength/i` regex matched none of `weightlifting_msk` / `weightlifting` / `powerlifting`.
96
+
97
+ ---
98
+
99
+ ## Testing
100
+
101
+ - **`totem test`** — 233 unit tests in <2s. Fixture-driven for projections; integration-style for the HTTP transport (`tests/whoop/http_auth.test.ts` spins up a real `http.Server` and hits it with `fetch`).
102
+ - **Live-API tests live in a separate `whoop-testing` archive.** They require a dummy account and aren't safe to expose to first-time users. If you want to add or run them, ask Brian.
103
+ - When fixing a projection, update its fixture in `tests/fixtures/` and the corresponding test in `tests/projections/` (`round1`/`round2`/`round3`, plus `round3_data_fixes.test.ts` for the live-audit data-extraction regressions).
104
+ - When changing the HTTP transport (`src/server-http.ts`) or auth model, add coverage to `tests/whoop/http_auth.test.ts`. The pattern is: boot a real server on an ephemeral port with a stub `WhoopClient`, then assert with `fetch()`.
105
+ - **CI runs the same checks on every PR.** `.github/workflows/ci.yml` runs `tsc --noEmit`, the full `vitest` suite, and a build on each push to `main` and each pull request. Run `totem typecheck && totem test && totem build` locally before opening a PR and it'll pass green — nothing reaches `main` (or a merge) without it.
106
+
107
+ ---
108
+
109
+ ## Code style
110
+
111
+ - TypeScript 6 strict mode (`noUncheckedIndexedAccess`, `exactOptionalPropertyTypes`, `noImplicitOverride`).
112
+ - No `any`. Use `unknown` + narrow with `isObject` / `asString` / `asNumber` from `src/lib/walk.ts`.
113
+ - Match the existing conventions in adjacent files — don't unilaterally refactor.
114
+ - Don't add features beyond what the task requires.
115
+ - One tool per file. ~30 lines is normal; over 100 is a smell unless the schema is genuinely complex (`whoop_smart_alarm_set` has 4 modes — that's fine).
116
+
117
+ ---
118
+
119
+ ## Commit style
120
+
121
+ Follow what's already in the log:
122
+
123
+ ```
124
+ fix: whoop_recovery + whoop_strain were silently returning all-null
125
+
126
+ <one paragraph explaining what broke and how you found it>
127
+ <one paragraph on the fix>
128
+ <verification: live-API check or test result>
129
+ ```
130
+
131
+ For commits that change behavior, include a before/after measurement when possible. The bug reports + fixes in the existing log are good models.
132
+
133
+ ---
134
+
135
+ ## Reporting bugs
136
+
137
+ Open an issue with:
138
+ - Which tool
139
+ - The exact arguments you called it with
140
+ - The full output (especially if it's all-null or partial)
141
+ - The current state of your account that should be in the output (e.g. "I have 3 workouts on May 23 but `whoop_workouts` returns empty")
142
+
143
+ If you can attach a `whoop_raw` capture of the underlying endpoint, even better.
144
+
145
+ ---
146
+
147
+ ## Code of conduct
148
+
149
+ Be decent. This is a small project run by a teenager.
package/Dockerfile ADDED
@@ -0,0 +1,53 @@
1
+ # Multi-stage build to keep the final image small.
2
+ #
3
+ # Deploy anywhere that runs Docker: Fly.io, Railway, Render, a VPS, etc.
4
+ # The server listens on $PORT (default 3000) at /mcp behind a bearer-token
5
+ # auth gate. See README → "Remote hosting" for the full deploy walkthrough.
6
+
7
+ # ─── build stage ───────────────────────────────────────────────────────────
8
+ FROM node:24-alpine AS builder
9
+ WORKDIR /app
10
+
11
+ # Copy manifests first so the npm install layer caches when only source changes.
12
+ COPY package.json package-lock.json ./
13
+ RUN npm ci
14
+
15
+ COPY tsconfig.json ./
16
+ COPY src ./src
17
+ # Build with the local TypeScript compiler (devDep from `npm ci`), then drop
18
+ # devDeps. The `totem` CLI isn't available in the build stage, so we invoke
19
+ # tsc directly rather than going through it.
20
+ RUN npx tsc && npm prune --omit=dev
21
+
22
+ # ─── runtime stage ─────────────────────────────────────────────────────────
23
+ FROM node:24-alpine AS runtime
24
+ WORKDIR /app
25
+
26
+ # Run as a non-root user. node:alpine ships with a `node` user (uid 1000).
27
+ USER node
28
+
29
+ COPY --chown=node:node --from=builder /app/node_modules ./node_modules
30
+ COPY --chown=node:node --from=builder /app/dist ./dist
31
+ COPY --chown=node:node --from=builder /app/package.json ./
32
+
33
+ # These three env vars are required at runtime. Set them via your host's
34
+ # secrets mechanism (`fly secrets set`, Railway env, docker run -e, etc.):
35
+ # WHOOP_EMAIL — your Whoop account email
36
+ # WHOOP_IOS_BEARER_TOKEN — from `totem auth` on your Mac
37
+ # WHOOP_COGNITO_REFRESH_TOKEN — from `totem auth` on your Mac
38
+ # MCP_AUTH_TOKEN — random secret your MCP client will send
39
+ #
40
+ # (Or just run `totem cloud` — it builds, deploys, and sets all of this.)
41
+ #
42
+ # This image forces HTTP transport.
43
+ ENV MCP_TRANSPORT=http
44
+ ENV WHOOP_TOKEN_STORE=memory
45
+ ENV NODE_ENV=production
46
+ ENV PORT=3000
47
+
48
+ EXPOSE 3000
49
+
50
+ HEALTHCHECK --interval=30s --timeout=5s --start-period=5s --retries=3 \
51
+ CMD wget -qO- http://127.0.0.1:3000/health || exit 1
52
+
53
+ CMD ["node", "dist/server.js"]