@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
@@ -0,0 +1,38 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 820 260" font-family="ui-monospace, 'Cascadia Code', 'SF Mono', Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', monospace" text-rendering="geometricPrecision">
2
+ <title>totem</title>
3
+ <desc>ASCII banner for the totem project — your wearables, talk to them with AI. 48 tools, 47 microservices, 311 endpoints, remote-ready.</desc>
4
+ <style>
5
+ .block { font-size: 26px; font-weight: 700; fill: #1f1f1f; letter-spacing: 0; }
6
+ .pulse { stroke: #6b6b6b; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; fill: none; }
7
+ .stats { font-size: 14px; fill: #555; letter-spacing: 0.5px; }
8
+ .sep { fill: #b0b0b0; }
9
+ @media (prefers-color-scheme: dark) {
10
+ .block { fill: #e6e6e6; }
11
+ .pulse { stroke: #969696; }
12
+ .stats { fill: #b0b0b0; }
13
+ .sep { fill: #555; }
14
+ }
15
+ </style>
16
+
17
+ <!-- TOTEM wordmark (ansi_shadow), ~720px wide, centered in the 820 viewBox at x=48 -->
18
+ <text class="block" x="48" y="34" xml:space="preserve">████████╗ ██████╗ ████████╗███████╗███╗ ███╗</text>
19
+ <text class="block" x="48" y="62" xml:space="preserve">╚══██╔══╝██╔═══██╗╚══██╔══╝██╔════╝████╗ ████║</text>
20
+ <text class="block" x="48" y="90" xml:space="preserve"> ██║ ██║ ██║ ██║ █████╗ ██╔████╔██║</text>
21
+ <text class="block" x="48" y="118" xml:space="preserve"> ██║ ██║ ██║ ██║ ██╔══╝ ██║╚██╔╝██║</text>
22
+ <text class="block" x="48" y="146" xml:space="preserve"> ██║ ╚██████╔╝ ██║ ███████╗██║ ╚═╝ ██║</text>
23
+ <text class="block" x="48" y="174" xml:space="preserve"> ╚═╝ ╚═════╝ ╚═╝ ╚══════╝╚═╝ ╚═╝</text>
24
+
25
+ <!-- EKG: spans the banner width (x=45 → x=775). 5 beats centered at 117/262/407/552/697. -->
26
+ <path class="pulse" d="
27
+ M 45 210
28
+ L 87 210 L 92 207 L 97 210 L 112 210 L 114 213 L 117 185 L 120 218 L 125 205 L 132 210
29
+ L 232 210 L 237 207 L 242 210 L 257 210 L 259 213 L 262 185 L 265 218 L 270 205 L 277 210
30
+ L 377 210 L 382 207 L 387 210 L 402 210 L 404 213 L 407 185 L 410 218 L 415 205 L 422 210
31
+ L 522 210 L 527 207 L 532 210 L 547 210 L 549 213 L 552 185 L 555 218 L 560 205 L 567 210
32
+ L 667 210 L 672 207 L 677 210 L 692 210 L 694 213 L 697 185 L 700 218 L 705 205 L 712 210
33
+ L 775 210
34
+ "/>
35
+
36
+ <!-- Stats: horizontally centered to viewBox midpoint -->
37
+ <text class="stats" x="410" y="245" text-anchor="middle" xml:space="preserve">v1.4.4<tspan class="sep"> · </tspan>48 tools<tspan class="sep"> · </tspan>47 microservices<tspan class="sep"> · </tspan>311 endpoints</text>
38
+ </svg>
@@ -0,0 +1,589 @@
1
+ #!/usr/bin/env node
2
+ // totem CLI — the single entry point for everything (build/dev/test/auth/
3
+ // deploy/inspect); package.json has no `scripts`. Runs from anywhere on the
4
+ // system (after `npm link` or global install).
5
+ //
6
+ // Architecture:
7
+ // - Single-file CLI dispatcher.
8
+ // - `ROOT` is the package root, resolved from `import.meta.url` so the CLI
9
+ // always operates on its install dir regardless of cwd.
10
+ // - Commands that wrap dev tooling spawn the local node_modules/.bin binaries
11
+ // (tsx, vitest, tsc) so a `npm link`-ed install picks up the right versions.
12
+ // - Commands that wrap Fly assume `fly` is on the system PATH.
13
+ // - Banner uses 24-bit truecolor ANSI escapes (RGB); honors NO_COLOR and
14
+ // skips colors if stdout is not a TTY.
15
+ import { spawn } from "node:child_process";
16
+ import { readFileSync, existsSync } from "node:fs";
17
+ import { dirname, resolve } from "node:path";
18
+ import { fileURLToPath } from "node:url";
19
+ import { request as httpsRequest } from "node:https";
20
+ import { runCloudSetup, runLocalSetup } from "./setup.js";
21
+ import { runUpdate } from "./update.js";
22
+ import { runScript } from "./ui.js";
23
+ // ── locate package root ──────────────────────────────────────────────────
24
+ // This file lives at one of:
25
+ // <root>/dist/cli/index.js (compiled, normal install)
26
+ // <root>/src/cli/index.ts (dev, via tsx)
27
+ // Both are 2 dirs deep from the package root.
28
+ const HERE = dirname(fileURLToPath(import.meta.url));
29
+ const ROOT = resolve(HERE, "..", "..");
30
+ const PKG_PATH = resolve(ROOT, "package.json");
31
+ const PKG = JSON.parse(readFileSync(PKG_PATH, "utf8"));
32
+ const VERSION = PKG.version;
33
+ // ── color helpers ────────────────────────────────────────────────────────
34
+ // Whoop branding is mono (black/white). Banner uses a light-gray block text
35
+ // and a slightly dimmer gray for the pulse waveform. Truecolor (24-bit) —
36
+ // supported by every modern terminal (Terminal.app, iTerm2, Warp, kitty,
37
+ // alacritty, VS Code integrated terminal). Red/green retained for status
38
+ // semantics (✓ / ✗).
39
+ const useColor = Boolean(process.stdout.isTTY) && !process.env.NO_COLOR;
40
+ const ANSI = {
41
+ reset: "\x1b[0m",
42
+ bold: "\x1b[1m",
43
+ dim: "\x1b[2m",
44
+ brand: "\x1b[38;2;225;225;225m", // light gray — block text + accents
45
+ brandDim: "\x1b[38;2;150;150;150m", // medium gray — pulse waveform
46
+ gray: "\x1b[38;2;120;120;120m",
47
+ white: "\x1b[97m",
48
+ green: "\x1b[92m",
49
+ red: "\x1b[91m",
50
+ };
51
+ function wrap(code, s) {
52
+ return useColor ? `${code}${s}${ANSI.reset}` : s;
53
+ }
54
+ const c = {
55
+ brand: (s) => wrap(ANSI.brand, s),
56
+ brandDim: (s) => wrap(ANSI.brandDim, s),
57
+ gray: (s) => wrap(ANSI.gray, s),
58
+ white: (s) => wrap(ANSI.white, s),
59
+ green: (s) => wrap(ANSI.green, s),
60
+ red: (s) => wrap(ANSI.red, s),
61
+ bold: (s) => wrap(ANSI.bold, s),
62
+ dim: (s) => wrap(ANSI.dim, s),
63
+ };
64
+ // ── banner ───────────────────────────────────────────────────────────────
65
+ // The banner prints on EVERY command, at the very top — but to STDERR, so it
66
+ // shows in the terminal without ever touching stdout. That keeps the MCP
67
+ // protocol stream clean on `start`/`dev`, the parseable output clean on
68
+ // `version`/`config`, and every command safe to pipe. Color is decided from
69
+ // stderr's TTY (not stdout's) since that's where it's written.
70
+ function printBanner() {
71
+ const color = Boolean(process.stderr.isTTY) && !process.env.NO_COLOR;
72
+ const w = (code, s) => (color ? `${code}${s}${ANSI.reset}` : s);
73
+ const lines = [
74
+ "",
75
+ w(ANSI.brand, " ████████╗ ██████╗ ████████╗███████╗███╗ ███╗"),
76
+ w(ANSI.brand, " ╚══██╔══╝██╔═══██╗╚══██╔══╝██╔════╝████╗ ████║"),
77
+ w(ANSI.brand, " ██║ ██║ ██║ ██║ █████╗ ██╔████╔██║"),
78
+ w(ANSI.brand, " ██║ ██║ ██║ ██║ ██╔══╝ ██║╚██╔╝██║"),
79
+ w(ANSI.brand, " ██║ ╚██████╔╝ ██║ ███████╗██║ ╚═╝ ██║"),
80
+ w(ANSI.brand, " ╚═╝ ╚═════╝ ╚═╝ ╚══════╝╚═╝ ╚═╝"),
81
+ "",
82
+ w(ANSI.brandDim, " ▁▁▁▁▂▂▆▂▁▁▁▁▁▁▁▁▂▂▆▂▁▁▁▁▁▁▁▁▂▂▆▂▁▁▁▁▁▁▁▁▂▂▆▂▁▁▁▁▁▁▁▁▂▂▆▂▁▁▁▁▁▁▁▁▂▂▆▂▁▁▁"),
83
+ "",
84
+ ` ${w(ANSI.bold, "v" + VERSION)} ${w(ANSI.gray, "·")} ${w(ANSI.white, "48 tools")} ${w(ANSI.gray, "·")} ${w(ANSI.white, "47 microservices")} ${w(ANSI.gray, "·")} ${w(ANSI.white, "311 endpoints")}`,
85
+ "",
86
+ ];
87
+ for (const line of lines)
88
+ console.error(line);
89
+ }
90
+ const GROUP_ORDER = ["Get started", "Setup", "Deployed", "Local", "Inspect", "Help"];
91
+ const commands = {
92
+ // ── Get started (headline) ─────────────────────────────────────────────
93
+ cloud: {
94
+ group: "Get started",
95
+ desc: "★ Recommended. Guided deploy to a host (Fly/Railway/Cloud Run/custom) + connect claude.ai, ChatGPT, Claude Code, or any HTTP MCP client, in one command.",
96
+ run: async () => runCloudSetup(ROOT),
97
+ },
98
+ local: {
99
+ group: "Get started",
100
+ desc: "Guided setup to run the MCP on this machine (stdio) and wire it into Claude Desktop/Code, Cursor, VS Code, Gemini CLI, Codex, or Windsurf.",
101
+ run: async () => runLocalSetup(ROOT),
102
+ },
103
+ // ── Local ────────────────────────────────────────────────────────────
104
+ start: {
105
+ group: "Local",
106
+ desc: "Start the MCP server (stdio by default; --http for HTTP mode)",
107
+ usage: "totem start [--http]",
108
+ run: async (args) => {
109
+ const isHttp = args.includes("--http");
110
+ const serverJs = resolve(ROOT, "dist", "server.js");
111
+ if (!existsSync(serverJs)) {
112
+ console.error(c.red("dist/server.js not found.") + " Run " + c.bold("totem build") + " first.");
113
+ return 1;
114
+ }
115
+ const env = { ...process.env, MCP_TRANSPORT: isHttp ? "http" : "stdio" };
116
+ return run(process.execPath, [serverJs], { env });
117
+ },
118
+ },
119
+ dev: {
120
+ group: "Local",
121
+ desc: "Run the server in dev mode (tsx source if available, else built dist)",
122
+ run: async () => runScript(ROOT, "server", [], { preferSource: true }),
123
+ },
124
+ "dev:http": {
125
+ group: "Local",
126
+ desc: "Run the server in dev mode, HTTP transport",
127
+ run: async () => {
128
+ const env = { ...process.env, MCP_TRANSPORT: "http" };
129
+ return runScript(ROOT, "server", [], { preferSource: true, env });
130
+ },
131
+ },
132
+ build: {
133
+ group: "Local",
134
+ desc: "Compile TypeScript to dist/",
135
+ run: async () => run(npmBin("tsc"), []),
136
+ },
137
+ test: {
138
+ group: "Local",
139
+ desc: "Run the test suite (vitest)",
140
+ usage: "totem test [test-filter]",
141
+ run: async (args) => run(npmBin("vitest"), ["run", ...args]),
142
+ },
143
+ typecheck: {
144
+ group: "Local",
145
+ desc: "Run `tsc --noEmit`",
146
+ run: async () => run(npmBin("tsc"), ["--noEmit"]),
147
+ },
148
+ // ── Setup ────────────────────────────────────────────────────────────
149
+ auth: {
150
+ group: "Setup",
151
+ desc: "Log into Whoop + save tokens. Auto-detects first-time vs re-auth and local vs deployed — pushes new tokens to your deployment (Fly/Railway/Cloud Run/custom) when there is one. Run it for setup or when the ~30-day token expires",
152
+ usage: "totem auth [--app <fly-app>]",
153
+ run: async (args) => runScript(ROOT, "scripts/cognito_bootstrap", args),
154
+ },
155
+ // ── Deployed ─────────────────────────────────────────────────────────
156
+ deploy: {
157
+ group: "Deployed",
158
+ desc: "Re-deploy the current code to your existing deployment (Fly/Railway/Cloud Run)",
159
+ usage: "totem deploy [-- <extra args>]",
160
+ run: async (args) => {
161
+ const d = detectDeploy();
162
+ if (!d) {
163
+ console.error(c.red("No deployment found. Run `totem cloud` to set one up."));
164
+ return 1;
165
+ }
166
+ switch (d.platform) {
167
+ case "fly":
168
+ return run("fly", ["deploy", ...(d.app ? ["-a", d.app] : []), ...args]);
169
+ case "railway":
170
+ if (d.app)
171
+ await run("railway", ["link", "--project", d.app]);
172
+ return run("railway", ["up", ...args]);
173
+ case "cloudrun": {
174
+ const region = d.region ?? "us-west1";
175
+ return run("gcloud", ["run", "deploy", d.app, "--source", ".", "--region", region, "--min-instances", "1",
176
+ ...(d.project ? ["--project", d.project] : []), "--quiet", ...args]);
177
+ }
178
+ case "custom":
179
+ console.log(c.gray("Custom host — rebuild + restart your container yourself (see `totem cloud` → Custom)."));
180
+ return 0;
181
+ default:
182
+ console.log(c.gray(`'${d.platform}' has no remote to deploy to.`));
183
+ return 0;
184
+ }
185
+ },
186
+ },
187
+ update: {
188
+ group: "Deployed",
189
+ desc: "Interactive updater: pick a version (newest is the default; older warns), apply it with a guided build + redeploy, then optionally turn on auto-update. `--auto on|off` toggles auto-update; `--check` previews installed-vs-latest.",
190
+ usage: "totem update [--check] [--auto on|off]",
191
+ run: async (args) => runUpdate(args, {
192
+ root: ROOT,
193
+ version: VERSION,
194
+ pkgPath: PKG_PATH,
195
+ pkgName: PKG.name,
196
+ cliEntry: fileURLToPath(import.meta.url),
197
+ isGit: existsSync(resolve(ROOT, ".git")),
198
+ detectDeploy,
199
+ redeploy: () => commands.deploy.run([]),
200
+ }),
201
+ },
202
+ logs: {
203
+ group: "Deployed",
204
+ desc: "Tail logs from your deployment (Fly/Railway/Cloud Run)",
205
+ usage: "totem logs [-- <extra args>]",
206
+ run: async (args) => {
207
+ const d = detectDeploy();
208
+ if (!d) {
209
+ console.error(c.red("No deployment found. Run `totem cloud` first."));
210
+ return 1;
211
+ }
212
+ switch (d.platform) {
213
+ case "fly":
214
+ return run("fly", ["logs", ...(d.app ? ["-a", d.app] : []), ...args]);
215
+ case "railway":
216
+ if (d.app)
217
+ await run("railway", ["link", "--project", d.app]);
218
+ return run("railway", ["logs", ...args]);
219
+ case "cloudrun": {
220
+ const region = d.region ?? "us-west1";
221
+ return run("gcloud", ["run", "services", "logs", "read", d.app, "--region", region,
222
+ ...(d.project ? ["--project", d.project] : []), ...args]);
223
+ }
224
+ default:
225
+ console.log(c.gray(`Logs for a ${d.platform} deployment live on your own host — check its dashboard.`));
226
+ return 0;
227
+ }
228
+ },
229
+ },
230
+ status: {
231
+ group: "Deployed",
232
+ desc: "Show your deployment's status + ping /health",
233
+ run: async () => {
234
+ const d = detectDeploy();
235
+ if (!d) {
236
+ console.error(c.red("No deployment found. Run `totem cloud` first."));
237
+ return 1;
238
+ }
239
+ console.log(` ${c.gray("platform")} ${c.bold(d.platform)}${d.app ? ` ${c.gray("·")} ${d.app}` : ""}`);
240
+ if (d.url)
241
+ console.log(` ${c.gray("url ")} ${d.url}`);
242
+ console.log("");
243
+ switch (d.platform) {
244
+ case "fly":
245
+ if (d.app) {
246
+ console.log(c.gray(`→ fly status -a ${d.app}`));
247
+ await run("fly", ["status", "-a", d.app]);
248
+ }
249
+ break;
250
+ case "railway":
251
+ if (d.app)
252
+ await run("railway", ["link", "--project", d.app]);
253
+ console.log(c.gray("→ railway status"));
254
+ await run("railway", ["status"]);
255
+ break;
256
+ case "cloudrun": {
257
+ const region = d.region ?? "us-west1";
258
+ console.log(c.gray(`→ gcloud run services describe ${d.app}`));
259
+ await run("gcloud", ["run", "services", "describe", d.app, "--region", region,
260
+ ...(d.project ? ["--project", d.project] : []),
261
+ "--format=value(status.url,status.latestReadyRevisionName)"]);
262
+ break;
263
+ }
264
+ }
265
+ if (!d.url) {
266
+ console.log(c.gray("(no URL recorded — nothing to ping)"));
267
+ return 0;
268
+ }
269
+ console.log("");
270
+ console.log(c.gray(`→ GET ${cleanUrl(d.url)}/health`));
271
+ return ping(`${cleanUrl(d.url)}/health`);
272
+ },
273
+ },
274
+ ping: {
275
+ group: "Deployed",
276
+ desc: "GET /health on your deployed server",
277
+ run: async () => {
278
+ const d = detectDeploy();
279
+ if (!d?.url) {
280
+ console.error(c.red("No deployment URL found. Run `totem cloud` first (or set $FLY_APP)."));
281
+ return 1;
282
+ }
283
+ return ping(`${cleanUrl(d.url)}/health`);
284
+ },
285
+ },
286
+ // ── Inspect ──────────────────────────────────────────────────────────
287
+ info: {
288
+ group: "Inspect",
289
+ desc: "Show install path, version, env state, and your deployment",
290
+ run: async () => {
291
+ const d = detectDeploy();
292
+ const envExists = existsSync(resolve(ROOT, ".env"));
293
+ const built = existsSync(resolve(ROOT, "dist", "server.js"));
294
+ console.log(`${c.bold("totem")} ${c.gray("v" + VERSION)}`);
295
+ console.log("");
296
+ const row = (label, value) => console.log(` ${c.gray(label.padEnd(15))} ${value}`);
297
+ row("install root", ROOT);
298
+ row("node", process.version);
299
+ row("built (dist/)", built ? c.green("yes") : c.red("no — run `totem build`"));
300
+ row(".env", envExists ? c.green("present") : c.red("missing"));
301
+ if (d) {
302
+ row("deployment", c.green(d.platform) + (d.app ? c.gray(` · ${d.app}`) : ""));
303
+ if (d.region)
304
+ row("region", d.region);
305
+ if (d.url) {
306
+ row("deployed url", cleanUrl(d.url));
307
+ row("health probe", `${cleanUrl(d.url)}/health`);
308
+ row("mcp endpoint", `${cleanUrl(d.url)}/mcp`);
309
+ }
310
+ }
311
+ else {
312
+ row("deployment", c.gray("(none — run `totem cloud`)"));
313
+ }
314
+ return 0;
315
+ },
316
+ },
317
+ tools: {
318
+ group: "Inspect",
319
+ desc: "List the MCP tools the server exposes (48 total)",
320
+ run: async () => {
321
+ const reads = [
322
+ "whoop_today", "whoop_day", "whoop_profile", "whoop_calendar", "whoop_recovery",
323
+ "whoop_sleep", "whoop_strain", "whoop_trend", "whoop_compare", "whoop_stress",
324
+ "whoop_sleep_need", "whoop_live_hr", "whoop_live_state", "whoop_live_stress",
325
+ "whoop_workouts", "whoop_workout", "whoop_sports_catalog", "whoop_lift_prs",
326
+ "whoop_lift_exercise", "whoop_lift_progression", "whoop_lift_history",
327
+ "whoop_lift_library", "whoop_lift_catalog", "whoop_journal", "whoop_journal_catalog",
328
+ "whoop_behavior_impact", "whoop_cycle", "whoop_performance_assessment",
329
+ "whoop_smart_alarm", "whoop_leaderboard", "whoop_communities", "whoop_hr_zones",
330
+ ];
331
+ const writes = [
332
+ "whoop_activity_create", "whoop_activity_delete", "whoop_lift_log",
333
+ "whoop_lift_template_save", "whoop_lift_custom_exercise", "whoop_journal_log",
334
+ "whoop_journal_autopop", "whoop_cycle_log", "whoop_symptom_log",
335
+ "whoop_smart_alarm_set", "whoop_hr_zones_set", "whoop_profile_update",
336
+ "whoop_hidden_metric", "whoop_coach_ask",
337
+ ];
338
+ const raw = ["whoop_raw", "whoop_endpoints"];
339
+ console.log(`${c.bold("Reads")} ${c.gray("(" + reads.length + ")")}`);
340
+ for (const t of reads)
341
+ console.log(` ${c.green("●")} ${t}`);
342
+ console.log("");
343
+ console.log(`${c.bold("Writes")} ${c.gray("(" + writes.length + " — preview-first; confirm=false default)")}`);
344
+ for (const t of writes)
345
+ console.log(` ${c.brand("●")} ${t}`);
346
+ console.log("");
347
+ console.log(`${c.bold("Escape hatches")} ${c.gray("(" + raw.length + ")")}`);
348
+ for (const t of raw)
349
+ console.log(` ${c.gray("●")} ${t}`);
350
+ console.log("");
351
+ console.log(c.gray(`total: ${reads.length + writes.length + raw.length}`));
352
+ return 0;
353
+ },
354
+ },
355
+ config: {
356
+ group: "Inspect",
357
+ desc: "Print a Claude Desktop config snippet",
358
+ usage: "totem config <stdio|http>",
359
+ run: async (args) => {
360
+ const mode = args[0];
361
+ if (mode !== "stdio" && mode !== "http") {
362
+ console.log(c.bold("Pick a mode:"));
363
+ console.log(" " + c.brand("totem config stdio") + c.gray(" # local install"));
364
+ console.log(" " + c.brand("totem config http") + c.gray(" # remote deployment (uses mcp-remote bridge)"));
365
+ return 1;
366
+ }
367
+ const home = process.env.HOME ?? "~";
368
+ const cfgPath = resolve(home, "Library/Application Support/Claude/claude_desktop_config.json");
369
+ console.log(c.gray(`Edit: ${cfgPath}`));
370
+ console.log("");
371
+ if (mode === "stdio") {
372
+ console.log(JSON.stringify({
373
+ mcpServers: {
374
+ whoop: {
375
+ command: process.execPath,
376
+ args: [resolve(ROOT, "dist", "server.js")],
377
+ },
378
+ },
379
+ }, null, 2));
380
+ }
381
+ else {
382
+ // Claude Desktop doesn't natively support remote MCP — bridge via npx mcp-remote.
383
+ const d = detectDeploy();
384
+ const url = d?.url ? `${cleanUrl(d.url)}/mcp` : "https://YOUR-SERVER/mcp";
385
+ console.log(JSON.stringify({
386
+ mcpServers: {
387
+ whoop: {
388
+ command: "npx",
389
+ args: [
390
+ "-y",
391
+ "mcp-remote",
392
+ url,
393
+ "--header",
394
+ "Authorization:Bearer YOUR_MCP_AUTH_TOKEN",
395
+ ],
396
+ },
397
+ },
398
+ }, null, 2));
399
+ console.log("");
400
+ console.log(c.gray("Bridge: https://www.npmjs.com/package/mcp-remote"));
401
+ console.log(c.gray("Claude Desktop only supports stdio — `mcp-remote` proxies your HTTP server through it."));
402
+ }
403
+ return 0;
404
+ },
405
+ },
406
+ // ── Help ─────────────────────────────────────────────────────────────
407
+ version: {
408
+ group: "Help",
409
+ desc: "Print the version string",
410
+ run: async () => {
411
+ console.log(VERSION);
412
+ return 0;
413
+ },
414
+ },
415
+ help: {
416
+ group: "Help",
417
+ desc: "Show this help",
418
+ run: async () => {
419
+ printHelp();
420
+ return 0;
421
+ },
422
+ },
423
+ };
424
+ // Aliases — helpful shortcuts.
425
+ const aliases = {
426
+ "-h": "help",
427
+ "--help": "help",
428
+ "-v": "version",
429
+ "--version": "version",
430
+ };
431
+ // ── helpers ──────────────────────────────────────────────────────────────
432
+ function npmBin(name) {
433
+ const path = resolve(ROOT, "node_modules", ".bin", name);
434
+ if (!existsSync(path)) {
435
+ console.error(c.red(`Missing dev dependency: ${name}`));
436
+ console.error(c.gray(`Expected at: ${path}`));
437
+ console.error(c.gray(`Run `) + c.bold(`cd ${ROOT} && npm install`) + c.gray(` first.`));
438
+ process.exit(1);
439
+ }
440
+ return path;
441
+ }
442
+ function detectFlyApp() {
443
+ if (process.env.FLY_APP)
444
+ return process.env.FLY_APP;
445
+ const tomlPath = resolve(ROOT, "fly.toml");
446
+ if (existsSync(tomlPath)) {
447
+ const m = readFileSync(tomlPath, "utf8").match(/^app\s*=\s*['"]([^'"]+)['"]/m);
448
+ if (m && m[1])
449
+ return m[1];
450
+ }
451
+ return null;
452
+ }
453
+ function detectDeploy() {
454
+ const recPath = resolve(ROOT, ".totem-deploy.json");
455
+ if (existsSync(recPath)) {
456
+ try {
457
+ const r = JSON.parse(readFileSync(recPath, "utf8"));
458
+ if (r && typeof r.platform === "string")
459
+ return r;
460
+ }
461
+ catch { /* fall through to legacy detection */ }
462
+ }
463
+ const app = detectFlyApp();
464
+ if (app)
465
+ return { platform: "fly", app, url: `https://${app}.fly.dev` };
466
+ return null;
467
+ }
468
+ const cleanUrl = (u) => u.replace(/\/+$/, "");
469
+ function run(cmd, args, opts = {}) {
470
+ return new Promise((res) => {
471
+ const child = spawn(cmd, args, { stdio: "inherit", cwd: ROOT, ...opts });
472
+ child.on("exit", (code, signal) => {
473
+ if (signal) {
474
+ console.error(c.red(`\nKilled by signal ${signal}`));
475
+ res(128);
476
+ return;
477
+ }
478
+ res(code ?? 1);
479
+ });
480
+ child.on("error", (err) => {
481
+ console.error(c.red("Failed to spawn:"), err.message);
482
+ res(1);
483
+ });
484
+ });
485
+ }
486
+ function ping(url, timeoutMs = 10_000) {
487
+ return new Promise((res) => {
488
+ const u = new URL(url);
489
+ const req = httpsRequest({
490
+ method: "GET",
491
+ hostname: u.hostname,
492
+ port: u.port || 443,
493
+ path: u.pathname + u.search,
494
+ headers: { "user-agent": `totem/${VERSION}` },
495
+ }, (response) => {
496
+ let body = "";
497
+ response.setEncoding("utf8");
498
+ response.on("data", (chunk) => {
499
+ body += chunk;
500
+ });
501
+ response.on("end", () => {
502
+ const status = response.statusCode ?? 0;
503
+ const ok = status >= 200 && status < 300;
504
+ const label = ok ? c.green(`✓ ${status}`) : c.red(`✗ ${status}`);
505
+ const preview = body.length > 120 ? body.slice(0, 117) + "..." : body;
506
+ console.log(`${label} ${url} ${c.gray("→ " + preview.replace(/\s+/g, " ").trim())}`);
507
+ res(ok ? 0 : 1);
508
+ });
509
+ });
510
+ req.setTimeout(timeoutMs, () => {
511
+ req.destroy();
512
+ console.error(c.red(`✗ timeout after ${timeoutMs}ms:`), url);
513
+ res(1);
514
+ });
515
+ req.on("error", (err) => {
516
+ console.error(c.red("✗ network error:"), err.message);
517
+ res(1);
518
+ });
519
+ req.end();
520
+ });
521
+ }
522
+ function printHelp() {
523
+ console.log(`${c.bold("Usage:")} totem ${c.gray("<command>")} ${c.gray("[args]")}`);
524
+ console.log("");
525
+ const byGroup = {};
526
+ for (const [name, cmd] of Object.entries(commands)) {
527
+ byGroup[cmd.group] ??= [];
528
+ byGroup[cmd.group].push([name, cmd]);
529
+ }
530
+ for (const group of GROUP_ORDER) {
531
+ const list = byGroup[group];
532
+ if (!list || list.length === 0)
533
+ continue;
534
+ console.log(c.bold(group));
535
+ const longest = Math.max(...list.map(([n]) => n.length));
536
+ for (const [name, cmd] of list) {
537
+ const padded = name.padEnd(longest + 2);
538
+ console.log(` ${c.brand(padded)}${c.white(cmd.desc)}`);
539
+ if (cmd.usage) {
540
+ console.log(` ${" ".repeat(longest + 2)}${c.gray(cmd.usage)}`);
541
+ }
542
+ }
543
+ console.log("");
544
+ }
545
+ console.log(c.gray("Global flags:"));
546
+ console.log(c.gray(" --help, -h Show this help"));
547
+ console.log(c.gray(" --version, -v Show version"));
548
+ console.log(c.gray(" NO_COLOR=1 Disable ANSI colors"));
549
+ console.log("");
550
+ console.log(c.gray("First-time global install (from a clone of this repo):"));
551
+ console.log(c.gray(" cd ") + c.bold(ROOT));
552
+ console.log(c.gray(" npm install && npx tsc && npm link"));
553
+ console.log("");
554
+ console.log(c.gray("Repo: ") + c.white(PKG.name) + c.gray(" · ") + ROOT);
555
+ console.log("");
556
+ }
557
+ // ── main ─────────────────────────────────────────────────────────────────
558
+ async function main() {
559
+ const argv = process.argv.slice(2);
560
+ // Ctrl-C kills the CLI from anywhere — during a spinner, a subprocess, or
561
+ // between prompts — and restores the cursor a spinner/menu may have hidden.
562
+ // (Ctrl-C inside a text prompt is also caught in ui.ts's ask(), where readline
563
+ // intercepts SIGINT before it would reach the process.)
564
+ process.on("SIGINT", () => { process.stderr.write("\x1b[?25h"); process.exit(130); });
565
+ // Banner on EVERY invocation, at the very top. It goes to stderr (see
566
+ // printBanner), so even `start` (MCP stdio), `dev`, and `version` show it
567
+ // without corrupting their stdout.
568
+ printBanner();
569
+ if (argv.length === 0) {
570
+ printHelp();
571
+ return 0;
572
+ }
573
+ let name = argv[0];
574
+ if (name in aliases)
575
+ name = aliases[name];
576
+ const cmd = commands[name];
577
+ if (!cmd) {
578
+ console.error(`${c.red("Unknown command:")} ${name}`);
579
+ console.error("");
580
+ console.error(`Run ${c.bold("totem help")} to see all commands.`);
581
+ return 1;
582
+ }
583
+ return cmd.run(argv.slice(1));
584
+ }
585
+ main().then((code) => process.exit(code)).catch((err) => {
586
+ console.error(c.red("Fatal:"), err instanceof Error ? err.stack : err);
587
+ process.exit(1);
588
+ });
589
+ //# sourceMappingURL=index.js.map