cuetra 0.1.3 → 0.1.5

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 (620) hide show
  1. package/cli/README.md +81 -0
  2. package/cli/bin/cuetra.js +140 -0
  3. package/cli/lib/commands.js +215 -0
  4. package/cli/lib/licence.js +485 -0
  5. package/cli/lib/pack.js +162 -0
  6. package/cli/lib/physics.js +191 -0
  7. package/cli/package.json +13 -0
  8. package/mcp-server/README.md +78 -0
  9. package/mcp-server/bin/cuetra-mcp.js +130 -0
  10. package/mcp-server/lib/licence.js +485 -0
  11. package/mcp-server/lib/pack.js +132 -0
  12. package/mcp-server/lib/tools.js +245 -0
  13. package/mcp-server/pack/activity.svg +1 -0
  14. package/mcp-server/pack/airplay.svg +1 -0
  15. package/mcp-server/pack/anchor.svg +1 -0
  16. package/mcp-server/pack/aperture.svg +1 -0
  17. package/mcp-server/pack/arrow-right.svg +1 -0
  18. package/mcp-server/pack/arrow-up.svg +1 -0
  19. package/mcp-server/pack/award.svg +1 -0
  20. package/mcp-server/pack/badge-check.svg +1 -0
  21. package/mcp-server/pack/battery.svg +1 -0
  22. package/mcp-server/pack/bell-ring.svg +1 -0
  23. package/mcp-server/pack/bell.svg +1 -0
  24. package/mcp-server/pack/bike.svg +1 -0
  25. package/mcp-server/pack/blocks.svg +1 -0
  26. package/mcp-server/pack/bluetooth.svg +1 -0
  27. package/mcp-server/pack/book-open.svg +1 -0
  28. package/mcp-server/pack/book.svg +1 -0
  29. package/mcp-server/pack/bookmark.svg +1 -0
  30. package/mcp-server/pack/box.svg +1 -0
  31. package/mcp-server/pack/brain.svg +1 -0
  32. package/mcp-server/pack/briefcase.svg +1 -0
  33. package/mcp-server/pack/bug.svg +1 -0
  34. package/mcp-server/pack/bus.svg +1 -0
  35. package/mcp-server/pack/calculator.svg +1 -0
  36. package/mcp-server/pack/calendar.svg +1 -0
  37. package/mcp-server/pack/camera.svg +1 -0
  38. package/mcp-server/pack/car.svg +1 -0
  39. package/mcp-server/pack/check.svg +1 -0
  40. package/mcp-server/pack/chevron-down.svg +1 -0
  41. package/mcp-server/pack/circle-alert.svg +1 -0
  42. package/mcp-server/pack/circle-check.svg +1 -0
  43. package/mcp-server/pack/clipboard.svg +1 -0
  44. package/mcp-server/pack/clock.svg +1 -0
  45. package/mcp-server/pack/cloud.svg +1 -0
  46. package/mcp-server/pack/code.svg +1 -0
  47. package/mcp-server/pack/coffee.svg +1 -0
  48. package/mcp-server/pack/command.svg +1 -0
  49. package/mcp-server/pack/compass.svg +1 -0
  50. package/mcp-server/pack/cookie.svg +1 -0
  51. package/mcp-server/pack/copy.svg +1 -0
  52. package/mcp-server/pack/cpu.svg +1 -0
  53. package/mcp-server/pack/credit-card.svg +1 -0
  54. package/mcp-server/pack/crown.svg +1 -0
  55. package/mcp-server/pack/database.svg +1 -0
  56. package/mcp-server/pack/diamond.svg +1 -0
  57. package/mcp-server/pack/download.svg +1 -0
  58. package/mcp-server/pack/external-link.svg +1 -0
  59. package/mcp-server/pack/eye.svg +1 -0
  60. package/mcp-server/pack/file.svg +1 -0
  61. package/mcp-server/pack/flag.svg +1 -0
  62. package/mcp-server/pack/flame.svg +1 -0
  63. package/mcp-server/pack/folder.svg +1 -0
  64. package/mcp-server/pack/free-list.json +113 -0
  65. package/mcp-server/pack/gift.svg +1 -0
  66. package/mcp-server/pack/globe.svg +1 -0
  67. package/mcp-server/pack/headphones.svg +1 -0
  68. package/mcp-server/pack/heart.svg +1 -0
  69. package/mcp-server/pack/image.svg +1 -0
  70. package/mcp-server/pack/key.svg +1 -0
  71. package/mcp-server/pack/layers.svg +1 -0
  72. package/mcp-server/pack/link.svg +1 -0
  73. package/mcp-server/pack/list.svg +1 -0
  74. package/mcp-server/pack/lock-open.svg +1 -0
  75. package/mcp-server/pack/lock.svg +1 -0
  76. package/mcp-server/pack/mail.svg +1 -0
  77. package/mcp-server/pack/menu.svg +1 -0
  78. package/mcp-server/pack/message-square.svg +1 -0
  79. package/mcp-server/pack/mic.svg +1 -0
  80. package/mcp-server/pack/minus.svg +1 -0
  81. package/mcp-server/pack/monitor.svg +1 -0
  82. package/mcp-server/pack/moon.svg +1 -0
  83. package/mcp-server/pack/motion.json +1 -0
  84. package/mcp-server/pack/navigation.svg +1 -0
  85. package/mcp-server/pack/pause.svg +1 -0
  86. package/mcp-server/pack/pen.svg +1 -0
  87. package/mcp-server/pack/phone.svg +1 -0
  88. package/mcp-server/pack/play.svg +1 -0
  89. package/mcp-server/pack/plus.svg +1 -0
  90. package/mcp-server/pack/power.svg +1 -0
  91. package/mcp-server/pack/printer.svg +1 -0
  92. package/mcp-server/pack/refresh-cw.svg +1 -0
  93. package/mcp-server/pack/rocket.svg +1 -0
  94. package/mcp-server/pack/search.svg +1 -0
  95. package/mcp-server/pack/send.svg +1 -0
  96. package/mcp-server/pack/settings.svg +1 -0
  97. package/mcp-server/pack/shield-check.svg +1 -0
  98. package/mcp-server/pack/shopping-cart.svg +1 -0
  99. package/mcp-server/pack/smartphone.svg +1 -0
  100. package/mcp-server/pack/star.svg +1 -0
  101. package/mcp-server/pack/sun.svg +1 -0
  102. package/mcp-server/pack/tag.svg +1 -0
  103. package/mcp-server/pack/terminal.svg +1 -0
  104. package/mcp-server/pack/thumbs-up.svg +1 -0
  105. package/mcp-server/pack/trash.svg +1 -0
  106. package/mcp-server/pack/trending-up.svg +1 -0
  107. package/mcp-server/pack/umbrella.svg +1 -0
  108. package/mcp-server/pack/upload.svg +1 -0
  109. package/mcp-server/pack/user.svg +1 -0
  110. package/mcp-server/pack/users.svg +1 -0
  111. package/mcp-server/pack/volume.svg +1 -0
  112. package/mcp-server/pack/watch.svg +1 -0
  113. package/mcp-server/pack/x.svg +1 -0
  114. package/mcp-server/pack/zap.svg +1 -0
  115. package/mcp-server/package.json +13 -0
  116. package/motion.json +1 -1
  117. package/pack/activity.svg +1 -0
  118. package/pack/airplay.svg +1 -0
  119. package/pack/anchor.svg +1 -0
  120. package/pack/aperture.svg +1 -0
  121. package/pack/arrow-right.svg +1 -0
  122. package/pack/arrow-up.svg +1 -0
  123. package/pack/award.svg +1 -0
  124. package/pack/badge-check.svg +1 -0
  125. package/pack/battery.svg +1 -0
  126. package/pack/bell-ring.svg +1 -0
  127. package/pack/bell.svg +1 -0
  128. package/pack/bike.svg +1 -0
  129. package/pack/blocks.svg +1 -0
  130. package/pack/bluetooth.svg +1 -0
  131. package/pack/book-open.svg +1 -0
  132. package/pack/book.svg +1 -0
  133. package/pack/bookmark.svg +1 -0
  134. package/pack/box.svg +1 -0
  135. package/pack/brain.svg +1 -0
  136. package/pack/briefcase.svg +1 -0
  137. package/pack/bug.svg +1 -0
  138. package/pack/bus.svg +1 -0
  139. package/pack/calculator.svg +1 -0
  140. package/pack/calendar.svg +1 -0
  141. package/pack/camera.svg +1 -0
  142. package/pack/car.svg +1 -0
  143. package/pack/check.svg +1 -0
  144. package/pack/chevron-down.svg +1 -0
  145. package/pack/circle-alert.svg +1 -0
  146. package/pack/circle-check.svg +1 -0
  147. package/pack/clipboard.svg +1 -0
  148. package/pack/clock.svg +1 -0
  149. package/pack/cloud.svg +1 -0
  150. package/pack/code.svg +1 -0
  151. package/pack/coffee.svg +1 -0
  152. package/pack/command.svg +1 -0
  153. package/pack/compass.svg +1 -0
  154. package/pack/cookie.svg +1 -0
  155. package/pack/copy.svg +1 -0
  156. package/pack/cpu.svg +1 -0
  157. package/pack/credit-card.svg +1 -0
  158. package/pack/crown.svg +1 -0
  159. package/pack/database.svg +1 -0
  160. package/pack/diamond.svg +1 -0
  161. package/pack/download.svg +1 -0
  162. package/pack/duotone/activity.svg +1 -0
  163. package/pack/duotone/airplay.svg +1 -0
  164. package/pack/duotone/anchor.svg +1 -0
  165. package/pack/duotone/aperture.svg +1 -0
  166. package/pack/duotone/arrow-right.svg +1 -0
  167. package/pack/duotone/arrow-up.svg +1 -0
  168. package/pack/duotone/award.svg +1 -0
  169. package/pack/duotone/badge-check.svg +1 -0
  170. package/pack/duotone/battery.svg +1 -0
  171. package/pack/duotone/bell-ring.svg +1 -0
  172. package/pack/duotone/bell.svg +1 -0
  173. package/pack/duotone/bike.svg +1 -0
  174. package/pack/duotone/blocks.svg +1 -0
  175. package/pack/duotone/bluetooth.svg +1 -0
  176. package/pack/duotone/book-open.svg +1 -0
  177. package/pack/duotone/book.svg +1 -0
  178. package/pack/duotone/bookmark.svg +1 -0
  179. package/pack/duotone/box.svg +1 -0
  180. package/pack/duotone/brain.svg +1 -0
  181. package/pack/duotone/briefcase.svg +1 -0
  182. package/pack/duotone/bug.svg +1 -0
  183. package/pack/duotone/bus.svg +1 -0
  184. package/pack/duotone/calculator.svg +1 -0
  185. package/pack/duotone/calendar.svg +1 -0
  186. package/pack/duotone/camera.svg +1 -0
  187. package/pack/duotone/car.svg +1 -0
  188. package/pack/duotone/check.svg +1 -0
  189. package/pack/duotone/chevron-down.svg +1 -0
  190. package/pack/duotone/circle-alert.svg +1 -0
  191. package/pack/duotone/circle-check.svg +1 -0
  192. package/pack/duotone/clipboard.svg +1 -0
  193. package/pack/duotone/clock.svg +1 -0
  194. package/pack/duotone/cloud.svg +1 -0
  195. package/pack/duotone/code.svg +1 -0
  196. package/pack/duotone/coffee.svg +1 -0
  197. package/pack/duotone/command.svg +1 -0
  198. package/pack/duotone/compass.svg +1 -0
  199. package/pack/duotone/cookie.svg +1 -0
  200. package/pack/duotone/copy.svg +1 -0
  201. package/pack/duotone/cpu.svg +1 -0
  202. package/pack/duotone/credit-card.svg +1 -0
  203. package/pack/duotone/crown.svg +1 -0
  204. package/pack/duotone/database.svg +1 -0
  205. package/pack/duotone/diamond.svg +1 -0
  206. package/pack/duotone/download.svg +1 -0
  207. package/pack/duotone/external-link.svg +1 -0
  208. package/pack/duotone/eye.svg +1 -0
  209. package/pack/duotone/file.svg +1 -0
  210. package/pack/duotone/flag.svg +1 -0
  211. package/pack/duotone/flame.svg +1 -0
  212. package/pack/duotone/folder.svg +1 -0
  213. package/pack/duotone/gift.svg +1 -0
  214. package/pack/duotone/globe.svg +1 -0
  215. package/pack/duotone/headphones.svg +1 -0
  216. package/pack/duotone/heart.svg +1 -0
  217. package/pack/duotone/image.svg +1 -0
  218. package/pack/duotone/key.svg +1 -0
  219. package/pack/duotone/layers.svg +1 -0
  220. package/pack/duotone/link.svg +1 -0
  221. package/pack/duotone/list.svg +1 -0
  222. package/pack/duotone/lock-open.svg +1 -0
  223. package/pack/duotone/lock.svg +1 -0
  224. package/pack/duotone/mail.svg +1 -0
  225. package/pack/duotone/menu.svg +1 -0
  226. package/pack/duotone/message-square.svg +1 -0
  227. package/pack/duotone/mic.svg +1 -0
  228. package/pack/duotone/minus.svg +1 -0
  229. package/pack/duotone/monitor.svg +1 -0
  230. package/pack/duotone/moon.svg +1 -0
  231. package/pack/duotone/navigation.svg +1 -0
  232. package/pack/duotone/pause.svg +1 -0
  233. package/pack/duotone/pen.svg +1 -0
  234. package/pack/duotone/phone.svg +1 -0
  235. package/pack/duotone/play.svg +1 -0
  236. package/pack/duotone/plus.svg +1 -0
  237. package/pack/duotone/power.svg +1 -0
  238. package/pack/duotone/printer.svg +1 -0
  239. package/pack/duotone/refresh-cw.svg +1 -0
  240. package/pack/duotone/rocket.svg +1 -0
  241. package/pack/duotone/search.svg +1 -0
  242. package/pack/duotone/send.svg +1 -0
  243. package/pack/duotone/settings.svg +1 -0
  244. package/pack/duotone/shield-check.svg +1 -0
  245. package/pack/duotone/shopping-cart.svg +1 -0
  246. package/pack/duotone/smartphone.svg +1 -0
  247. package/pack/duotone/star.svg +1 -0
  248. package/pack/duotone/sun.svg +1 -0
  249. package/pack/duotone/tag.svg +1 -0
  250. package/pack/duotone/terminal.svg +1 -0
  251. package/pack/duotone/thumbs-up.svg +1 -0
  252. package/pack/duotone/trash.svg +1 -0
  253. package/pack/duotone/trending-up.svg +1 -0
  254. package/pack/duotone/umbrella.svg +1 -0
  255. package/pack/duotone/upload.svg +1 -0
  256. package/pack/duotone/user.svg +1 -0
  257. package/pack/duotone/users.svg +1 -0
  258. package/pack/duotone/volume.svg +1 -0
  259. package/pack/duotone/watch.svg +1 -0
  260. package/pack/duotone/x.svg +1 -0
  261. package/pack/duotone/zap.svg +1 -0
  262. package/pack/external-link.svg +1 -0
  263. package/pack/eye.svg +1 -0
  264. package/pack/file.svg +1 -0
  265. package/pack/flag.svg +1 -0
  266. package/pack/flame.svg +1 -0
  267. package/pack/folder.svg +1 -0
  268. package/pack/free-list.json +113 -0
  269. package/pack/gift.svg +1 -0
  270. package/pack/glass/activity.svg +1 -0
  271. package/pack/glass/airplay.svg +1 -0
  272. package/pack/glass/anchor.svg +1 -0
  273. package/pack/glass/aperture.svg +1 -0
  274. package/pack/glass/arrow-right.svg +1 -0
  275. package/pack/glass/arrow-up.svg +1 -0
  276. package/pack/glass/award.svg +1 -0
  277. package/pack/glass/badge-check.svg +1 -0
  278. package/pack/glass/battery.svg +1 -0
  279. package/pack/glass/bell-ring.svg +1 -0
  280. package/pack/glass/bell.svg +1 -0
  281. package/pack/glass/bike.svg +1 -0
  282. package/pack/glass/blocks.svg +1 -0
  283. package/pack/glass/bluetooth.svg +1 -0
  284. package/pack/glass/book-open.svg +1 -0
  285. package/pack/glass/book.svg +1 -0
  286. package/pack/glass/bookmark.svg +1 -0
  287. package/pack/glass/box.svg +1 -0
  288. package/pack/glass/brain.svg +1 -0
  289. package/pack/glass/briefcase.svg +1 -0
  290. package/pack/glass/bug.svg +1 -0
  291. package/pack/glass/bus.svg +1 -0
  292. package/pack/glass/calculator.svg +1 -0
  293. package/pack/glass/calendar.svg +1 -0
  294. package/pack/glass/camera.svg +1 -0
  295. package/pack/glass/car.svg +1 -0
  296. package/pack/glass/check.svg +1 -0
  297. package/pack/glass/chevron-down.svg +1 -0
  298. package/pack/glass/circle-alert.svg +1 -0
  299. package/pack/glass/circle-check.svg +1 -0
  300. package/pack/glass/clipboard.svg +1 -0
  301. package/pack/glass/clock.svg +1 -0
  302. package/pack/glass/cloud.svg +1 -0
  303. package/pack/glass/code.svg +1 -0
  304. package/pack/glass/coffee.svg +1 -0
  305. package/pack/glass/command.svg +1 -0
  306. package/pack/glass/compass.svg +1 -0
  307. package/pack/glass/cookie.svg +1 -0
  308. package/pack/glass/copy.svg +1 -0
  309. package/pack/glass/cpu.svg +1 -0
  310. package/pack/glass/credit-card.svg +1 -0
  311. package/pack/glass/crown.svg +1 -0
  312. package/pack/glass/database.svg +1 -0
  313. package/pack/glass/diamond.svg +1 -0
  314. package/pack/glass/download.svg +1 -0
  315. package/pack/glass/external-link.svg +1 -0
  316. package/pack/glass/eye.svg +1 -0
  317. package/pack/glass/file.svg +1 -0
  318. package/pack/glass/flag.svg +1 -0
  319. package/pack/glass/flame.svg +1 -0
  320. package/pack/glass/folder.svg +1 -0
  321. package/pack/glass/gift.svg +1 -0
  322. package/pack/glass/globe.svg +1 -0
  323. package/pack/glass/headphones.svg +1 -0
  324. package/pack/glass/heart.svg +1 -0
  325. package/pack/glass/image.svg +1 -0
  326. package/pack/glass/key.svg +1 -0
  327. package/pack/glass/layers.svg +1 -0
  328. package/pack/glass/link.svg +1 -0
  329. package/pack/glass/list.svg +1 -0
  330. package/pack/glass/lock-open.svg +1 -0
  331. package/pack/glass/lock.svg +1 -0
  332. package/pack/glass/mail.svg +1 -0
  333. package/pack/glass/menu.svg +1 -0
  334. package/pack/glass/message-square.svg +1 -0
  335. package/pack/glass/mic.svg +1 -0
  336. package/pack/glass/minus.svg +1 -0
  337. package/pack/glass/monitor.svg +1 -0
  338. package/pack/glass/moon.svg +1 -0
  339. package/pack/glass/navigation.svg +1 -0
  340. package/pack/glass/pause.svg +1 -0
  341. package/pack/glass/pen.svg +1 -0
  342. package/pack/glass/phone.svg +1 -0
  343. package/pack/glass/play.svg +1 -0
  344. package/pack/glass/plus.svg +1 -0
  345. package/pack/glass/power.svg +1 -0
  346. package/pack/glass/printer.svg +1 -0
  347. package/pack/glass/refresh-cw.svg +1 -0
  348. package/pack/glass/rocket.svg +1 -0
  349. package/pack/glass/search.svg +1 -0
  350. package/pack/glass/send.svg +1 -0
  351. package/pack/glass/settings.svg +1 -0
  352. package/pack/glass/shield-check.svg +1 -0
  353. package/pack/glass/shopping-cart.svg +1 -0
  354. package/pack/glass/smartphone.svg +1 -0
  355. package/pack/glass/star.svg +1 -0
  356. package/pack/glass/sun.svg +1 -0
  357. package/pack/glass/tag.svg +1 -0
  358. package/pack/glass/terminal.svg +1 -0
  359. package/pack/glass/thumbs-up.svg +1 -0
  360. package/pack/glass/trash.svg +1 -0
  361. package/pack/glass/trending-up.svg +1 -0
  362. package/pack/glass/umbrella.svg +1 -0
  363. package/pack/glass/upload.svg +1 -0
  364. package/pack/glass/user.svg +1 -0
  365. package/pack/glass/users.svg +1 -0
  366. package/pack/glass/volume.svg +1 -0
  367. package/pack/glass/watch.svg +1 -0
  368. package/pack/glass/x.svg +1 -0
  369. package/pack/glass/zap.svg +1 -0
  370. package/pack/globe.svg +1 -0
  371. package/pack/headphones.svg +1 -0
  372. package/pack/heart.svg +1 -0
  373. package/pack/image.svg +1 -0
  374. package/pack/key.svg +1 -0
  375. package/pack/layers.svg +1 -0
  376. package/pack/link.svg +1 -0
  377. package/pack/list.svg +1 -0
  378. package/pack/lock-open.svg +1 -0
  379. package/pack/lock.svg +1 -0
  380. package/pack/mail.svg +1 -0
  381. package/pack/menu.svg +1 -0
  382. package/pack/message-square.svg +1 -0
  383. package/pack/mic.svg +1 -0
  384. package/pack/minus.svg +1 -0
  385. package/pack/monitor.svg +1 -0
  386. package/pack/moon.svg +1 -0
  387. package/pack/motion.json +1 -0
  388. package/pack/navigation.svg +1 -0
  389. package/pack/outline/activity.svg +1 -0
  390. package/pack/outline/airplay.svg +1 -0
  391. package/pack/outline/anchor.svg +1 -0
  392. package/pack/outline/aperture.svg +1 -0
  393. package/pack/outline/arrow-right.svg +1 -0
  394. package/pack/outline/arrow-up.svg +1 -0
  395. package/pack/outline/award.svg +1 -0
  396. package/pack/outline/badge-check.svg +1 -0
  397. package/pack/outline/battery.svg +1 -0
  398. package/pack/outline/bell-ring.svg +1 -0
  399. package/pack/outline/bell.svg +1 -0
  400. package/pack/outline/bike.svg +1 -0
  401. package/pack/outline/blocks.svg +1 -0
  402. package/pack/outline/bluetooth.svg +1 -0
  403. package/pack/outline/book-open.svg +1 -0
  404. package/pack/outline/book.svg +1 -0
  405. package/pack/outline/bookmark.svg +1 -0
  406. package/pack/outline/box.svg +1 -0
  407. package/pack/outline/brain.svg +1 -0
  408. package/pack/outline/briefcase.svg +1 -0
  409. package/pack/outline/bug.svg +1 -0
  410. package/pack/outline/bus.svg +1 -0
  411. package/pack/outline/calculator.svg +1 -0
  412. package/pack/outline/calendar.svg +1 -0
  413. package/pack/outline/camera.svg +1 -0
  414. package/pack/outline/car.svg +1 -0
  415. package/pack/outline/check.svg +1 -0
  416. package/pack/outline/chevron-down.svg +1 -0
  417. package/pack/outline/circle-alert.svg +1 -0
  418. package/pack/outline/circle-check.svg +1 -0
  419. package/pack/outline/clipboard.svg +1 -0
  420. package/pack/outline/clock.svg +1 -0
  421. package/pack/outline/cloud.svg +1 -0
  422. package/pack/outline/code.svg +1 -0
  423. package/pack/outline/coffee.svg +1 -0
  424. package/pack/outline/command.svg +1 -0
  425. package/pack/outline/compass.svg +1 -0
  426. package/pack/outline/cookie.svg +1 -0
  427. package/pack/outline/copy.svg +1 -0
  428. package/pack/outline/cpu.svg +1 -0
  429. package/pack/outline/credit-card.svg +1 -0
  430. package/pack/outline/crown.svg +1 -0
  431. package/pack/outline/database.svg +1 -0
  432. package/pack/outline/diamond.svg +1 -0
  433. package/pack/outline/download.svg +1 -0
  434. package/pack/outline/external-link.svg +1 -0
  435. package/pack/outline/eye.svg +1 -0
  436. package/pack/outline/file.svg +1 -0
  437. package/pack/outline/flag.svg +1 -0
  438. package/pack/outline/flame.svg +1 -0
  439. package/pack/outline/folder.svg +1 -0
  440. package/pack/outline/gift.svg +1 -0
  441. package/pack/outline/globe.svg +1 -0
  442. package/pack/outline/headphones.svg +1 -0
  443. package/pack/outline/heart.svg +1 -0
  444. package/pack/outline/image.svg +1 -0
  445. package/pack/outline/key.svg +1 -0
  446. package/pack/outline/layers.svg +1 -0
  447. package/pack/outline/link.svg +1 -0
  448. package/pack/outline/list.svg +1 -0
  449. package/pack/outline/lock-open.svg +1 -0
  450. package/pack/outline/lock.svg +1 -0
  451. package/pack/outline/mail.svg +1 -0
  452. package/pack/outline/menu.svg +1 -0
  453. package/pack/outline/message-square.svg +1 -0
  454. package/pack/outline/mic.svg +1 -0
  455. package/pack/outline/minus.svg +1 -0
  456. package/pack/outline/monitor.svg +1 -0
  457. package/pack/outline/moon.svg +1 -0
  458. package/pack/outline/navigation.svg +1 -0
  459. package/pack/outline/pause.svg +1 -0
  460. package/pack/outline/pen.svg +1 -0
  461. package/pack/outline/phone.svg +1 -0
  462. package/pack/outline/play.svg +1 -0
  463. package/pack/outline/plus.svg +1 -0
  464. package/pack/outline/power.svg +1 -0
  465. package/pack/outline/printer.svg +1 -0
  466. package/pack/outline/refresh-cw.svg +1 -0
  467. package/pack/outline/rocket.svg +1 -0
  468. package/pack/outline/search.svg +1 -0
  469. package/pack/outline/send.svg +1 -0
  470. package/pack/outline/settings.svg +1 -0
  471. package/pack/outline/shield-check.svg +1 -0
  472. package/pack/outline/shopping-cart.svg +1 -0
  473. package/pack/outline/smartphone.svg +1 -0
  474. package/pack/outline/star.svg +1 -0
  475. package/pack/outline/sun.svg +1 -0
  476. package/pack/outline/tag.svg +1 -0
  477. package/pack/outline/terminal.svg +1 -0
  478. package/pack/outline/thumbs-up.svg +1 -0
  479. package/pack/outline/trash.svg +1 -0
  480. package/pack/outline/trending-up.svg +1 -0
  481. package/pack/outline/umbrella.svg +1 -0
  482. package/pack/outline/upload.svg +1 -0
  483. package/pack/outline/user.svg +1 -0
  484. package/pack/outline/users.svg +1 -0
  485. package/pack/outline/volume.svg +1 -0
  486. package/pack/outline/watch.svg +1 -0
  487. package/pack/outline/x.svg +1 -0
  488. package/pack/outline/zap.svg +1 -0
  489. package/pack/pause.svg +1 -0
  490. package/pack/pen.svg +1 -0
  491. package/pack/phone.svg +1 -0
  492. package/pack/play.svg +1 -0
  493. package/pack/plus.svg +1 -0
  494. package/pack/power.svg +1 -0
  495. package/pack/printer.svg +1 -0
  496. package/pack/refresh-cw.svg +1 -0
  497. package/pack/rocket.svg +1 -0
  498. package/pack/search.svg +1 -0
  499. package/pack/send.svg +1 -0
  500. package/pack/settings.svg +1 -0
  501. package/pack/shield-check.svg +1 -0
  502. package/pack/shopping-cart.svg +1 -0
  503. package/pack/smartphone.svg +1 -0
  504. package/pack/solid/activity.svg +1 -0
  505. package/pack/solid/airplay.svg +1 -0
  506. package/pack/solid/anchor.svg +1 -0
  507. package/pack/solid/aperture.svg +1 -0
  508. package/pack/solid/arrow-right.svg +1 -0
  509. package/pack/solid/arrow-up.svg +1 -0
  510. package/pack/solid/award.svg +1 -0
  511. package/pack/solid/badge-check.svg +1 -0
  512. package/pack/solid/battery.svg +1 -0
  513. package/pack/solid/bell-ring.svg +1 -0
  514. package/pack/solid/bell.svg +1 -0
  515. package/pack/solid/bike.svg +1 -0
  516. package/pack/solid/blocks.svg +1 -0
  517. package/pack/solid/bluetooth.svg +1 -0
  518. package/pack/solid/book-open.svg +1 -0
  519. package/pack/solid/book.svg +1 -0
  520. package/pack/solid/bookmark.svg +1 -0
  521. package/pack/solid/box.svg +1 -0
  522. package/pack/solid/brain.svg +1 -0
  523. package/pack/solid/briefcase.svg +1 -0
  524. package/pack/solid/bug.svg +1 -0
  525. package/pack/solid/bus.svg +1 -0
  526. package/pack/solid/calculator.svg +1 -0
  527. package/pack/solid/calendar.svg +1 -0
  528. package/pack/solid/camera.svg +1 -0
  529. package/pack/solid/car.svg +1 -0
  530. package/pack/solid/check.svg +1 -0
  531. package/pack/solid/chevron-down.svg +1 -0
  532. package/pack/solid/circle-alert.svg +1 -0
  533. package/pack/solid/circle-check.svg +1 -0
  534. package/pack/solid/clipboard.svg +1 -0
  535. package/pack/solid/clock.svg +1 -0
  536. package/pack/solid/cloud.svg +1 -0
  537. package/pack/solid/code.svg +1 -0
  538. package/pack/solid/coffee.svg +1 -0
  539. package/pack/solid/command.svg +1 -0
  540. package/pack/solid/compass.svg +1 -0
  541. package/pack/solid/cookie.svg +1 -0
  542. package/pack/solid/copy.svg +1 -0
  543. package/pack/solid/cpu.svg +1 -0
  544. package/pack/solid/credit-card.svg +1 -0
  545. package/pack/solid/crown.svg +1 -0
  546. package/pack/solid/database.svg +1 -0
  547. package/pack/solid/diamond.svg +1 -0
  548. package/pack/solid/download.svg +1 -0
  549. package/pack/solid/external-link.svg +1 -0
  550. package/pack/solid/eye.svg +1 -0
  551. package/pack/solid/file.svg +1 -0
  552. package/pack/solid/flag.svg +1 -0
  553. package/pack/solid/flame.svg +1 -0
  554. package/pack/solid/folder.svg +1 -0
  555. package/pack/solid/gift.svg +1 -0
  556. package/pack/solid/globe.svg +1 -0
  557. package/pack/solid/headphones.svg +1 -0
  558. package/pack/solid/heart.svg +1 -0
  559. package/pack/solid/image.svg +1 -0
  560. package/pack/solid/key.svg +1 -0
  561. package/pack/solid/layers.svg +1 -0
  562. package/pack/solid/link.svg +1 -0
  563. package/pack/solid/list.svg +1 -0
  564. package/pack/solid/lock-open.svg +1 -0
  565. package/pack/solid/lock.svg +1 -0
  566. package/pack/solid/mail.svg +1 -0
  567. package/pack/solid/menu.svg +1 -0
  568. package/pack/solid/message-square.svg +1 -0
  569. package/pack/solid/mic.svg +1 -0
  570. package/pack/solid/minus.svg +1 -0
  571. package/pack/solid/monitor.svg +1 -0
  572. package/pack/solid/moon.svg +1 -0
  573. package/pack/solid/navigation.svg +1 -0
  574. package/pack/solid/pause.svg +1 -0
  575. package/pack/solid/pen.svg +1 -0
  576. package/pack/solid/phone.svg +1 -0
  577. package/pack/solid/play.svg +1 -0
  578. package/pack/solid/plus.svg +1 -0
  579. package/pack/solid/power.svg +1 -0
  580. package/pack/solid/printer.svg +1 -0
  581. package/pack/solid/refresh-cw.svg +1 -0
  582. package/pack/solid/rocket.svg +1 -0
  583. package/pack/solid/search.svg +1 -0
  584. package/pack/solid/send.svg +1 -0
  585. package/pack/solid/settings.svg +1 -0
  586. package/pack/solid/shield-check.svg +1 -0
  587. package/pack/solid/shopping-cart.svg +1 -0
  588. package/pack/solid/smartphone.svg +1 -0
  589. package/pack/solid/star.svg +1 -0
  590. package/pack/solid/sun.svg +1 -0
  591. package/pack/solid/tag.svg +1 -0
  592. package/pack/solid/terminal.svg +1 -0
  593. package/pack/solid/thumbs-up.svg +1 -0
  594. package/pack/solid/trash.svg +1 -0
  595. package/pack/solid/trending-up.svg +1 -0
  596. package/pack/solid/umbrella.svg +1 -0
  597. package/pack/solid/upload.svg +1 -0
  598. package/pack/solid/user.svg +1 -0
  599. package/pack/solid/users.svg +1 -0
  600. package/pack/solid/volume.svg +1 -0
  601. package/pack/solid/watch.svg +1 -0
  602. package/pack/solid/x.svg +1 -0
  603. package/pack/solid/zap.svg +1 -0
  604. package/pack/star.svg +1 -0
  605. package/pack/sun.svg +1 -0
  606. package/pack/tag.svg +1 -0
  607. package/pack/terminal.svg +1 -0
  608. package/pack/thumbs-up.svg +1 -0
  609. package/pack/trash.svg +1 -0
  610. package/pack/trending-up.svg +1 -0
  611. package/pack/umbrella.svg +1 -0
  612. package/pack/upload.svg +1 -0
  613. package/pack/user.svg +1 -0
  614. package/pack/users.svg +1 -0
  615. package/pack/volume.svg +1 -0
  616. package/pack/watch.svg +1 -0
  617. package/pack/x.svg +1 -0
  618. package/pack/zap.svg +1 -0
  619. package/package.json +27 -18
  620. package/src/licence.js +98 -0
@@ -0,0 +1,485 @@
1
+ // Online licence validation for the Cuetra MCP server.
2
+ // Mirrors cli/lib/licence.js - duplicated by design: @cuetra/cli and
3
+ // @cuetra/mcp-server ship as independent zero-dependency packages, so each one
4
+ // carries its own copy of this gate. Keep the two files in sync when changing
5
+ // the validation flow, the cache or the error classes.
6
+ //
7
+ // Flow (mirrors the site's redeem flow, src/redeem.js + src/licence.js):
8
+ // 1. shape check - the tier-aware parseKey from src/licence.js. A key that
9
+ // does not parse is never sent anywhere. The parser also routes the key:
10
+ // CUETRA-... shapes (and the legacy shape) belong to Polar, UUIDs belong
11
+ // to Dodo Payments, the second processor (owner order 2026-11-28).
12
+ // 2. offline cache - one small JSON file per key under the OS user cache
13
+ // dir (key-hash-named, never inside the repo), trusted for 7 days and
14
+ // written ONLY after a successful live validation. The cached entry also
15
+ // carries the tier for Dodo keys, whose key string spells no tier out.
16
+ // 3. live POST to the issuing processor - both are public, key-as-credential
17
+ // endpoints, so the key itself is the credential and no secret ships in
18
+ // this package:
19
+ // - Polar: the same unauthenticated customer-portal endpoints
20
+ // cuetra.com/redeem uses, with the same organization id, Polar version
21
+ // and per-tier benefit ids. Personal and Team keys (activation-limited
22
+ // benefits) activate once on first contact and re-validate with the
23
+ // persisted activation id afterwards, so a cache refresh never consumes
24
+ // another seat. Business keys carry no activation limit, so they
25
+ // validate instead.
26
+ // - Dodo Payments: live.dodopayments.com/licenses/activate + /validate
27
+ // (its API reference marks them "No API Key Required"). Activation is
28
+ // uniform for every Dodo tier - the per-key activation limit is set on
29
+ // the License Key entitlement in Dodo's dashboard - and the activation
30
+ // reply names the issuing product, which is the only place a Dodo key's
31
+ // tier can come from. The reply's customer contact details are never
32
+ // extracted, cached or printed.
33
+ //
34
+ // validateLicence never throws for the expected classes; it returns
35
+ // { status, detail } where status is one of:
36
+ // "valid" - the issuing processor accepted the key just now
37
+ // (cache refreshed)
38
+ // "cache-valid" - a live validation from the last 7 days is cached,
39
+ // so no processor was contacted this run
40
+ // "shape-invalid" - the key does not parse; nothing was sent anywhere
41
+ // "rejected" - the processor answered no (unknown, revoked, expired
42
+ // or seat-limited key); the detail carries the reason
43
+ // "offline-no-cache" - the processor could not be reached and no fresh
44
+ // validation is cached, so the key cannot unlock
45
+ // anything
46
+ import { createHash } from "node:crypto";
47
+ import fs from "node:fs";
48
+ import os from "node:os";
49
+ import path from "node:path";
50
+ import { TIER_NAME, parseKey } from "../../src/licence.js";
51
+
52
+ // Endpoints, org id, API version and per-tier benefit ids are the public
53
+ // constants the site's redeem flow already ships (src/redeem.js). They are
54
+ // identifiers, not secrets: the licence key is the only credential.
55
+ const POLAR_API_BASE = "https://api.polar.sh";
56
+ const POLAR_ORG_ID = "6c111b6c-f8b6-4ff9-a027-45e0ad239f1e";
57
+ const POLAR_VERSION = "2026-10";
58
+ const BENEFIT_BY_TIER = {
59
+ personal: "ca4c888d-6335-473a-8eb0-a1dff3c0f74f",
60
+ team: "dea32856-a0b8-43af-bef3-12c722cb8762",
61
+ business: "f34a15b3-2dfc-4ee8-ac08-98af2d52338d",
62
+ };
63
+
64
+ // Dodo Payments, the second processor. Public key-as-credential endpoints on
65
+ // the live-mode server (Dodo API reference: "No API Key Required" for
66
+ // activate / validate / deactivate). Identifiers, not secrets - the licence
67
+ // key is still the only credential.
68
+ const DODO_API_BASE = "https://live.dodopayments.com";
69
+ // A Dodo key is a UUID and spells no tier out, so the tier is read from the
70
+ // product that issued the key (named in the activation reply).
71
+ // The Dodo product ids below are the owner's real ids, created in the Dodo
72
+ // dashboard (app.dodopayments.com -> Products, test mode) on 2026-11-28 - the
73
+ // same ids the site's pricing page and redeem flow use, so a licence bought
74
+ // there is issued for one of these product ids.
75
+ const DODO_PRODUCT_BY_TIER = {
76
+ personal: "pdt_0NstEH9D1MlrZImlYwIyF",
77
+ team: "pdt_0NstEWsEJRcxHtFUbWega",
78
+ business: "pdt_0NstEaiJQWZCJqddcNos2",
79
+ };
80
+
81
+ const CACHE_VERSION = 1;
82
+ const CACHE_TTL_MS = 7 * 24 * 60 * 60 * 1000; // one live validation is trusted for 7 days
83
+ const REQUEST_TIMEOUT_MS = 10000;
84
+ const MAX_DETAIL_CHARS = 200;
85
+ const ACTIVATION_PREFIX = "cuetra mcp on";
86
+
87
+ // Mask a key for every log, note and transcript: first 4 chars + "..." + length.
88
+ export function maskKey(rawKey) {
89
+ const text = typeof rawKey === "string" ? rawKey : String(rawKey ?? "");
90
+ if (!text.trim()) return "(no key)";
91
+ return `${text.slice(0, 4)}...(${text.length} chars)`;
92
+ }
93
+
94
+ // A result unlocks paid content only when the issuing processor said yes now,
95
+ // or said yes within the 7-day cache window.
96
+ export function isLicenceAllowed(result) {
97
+ return !!result && (result.status === "valid" || result.status === "cache-valid");
98
+ }
99
+
100
+ function normalizeKey(rawKey) {
101
+ return String(rawKey).trim().toUpperCase().replace(/\s+/g, "");
102
+ }
103
+
104
+ function keyHash(normalized) {
105
+ return createHash("sha256").update(normalized).digest("hex").slice(0, 32);
106
+ }
107
+
108
+ // The cache lives under the OS user cache dir, never inside the repo or pack.
109
+ // CUETRA_LICENCE_CACHE_DIR overrides the location (tests, CI, locked-down
110
+ // machines); the override is also what the dry-run transcripts use to prove
111
+ // the cache classes without touching a real user profile.
112
+ function cacheDir() {
113
+ const override = process.env.CUETRA_LICENCE_CACHE_DIR;
114
+ if (override) return path.resolve(override);
115
+ const home = os.homedir();
116
+ if (!home) return path.join(os.tmpdir(), "cuetra-licence-cache");
117
+ if (process.platform === "win32") {
118
+ return path.join(process.env.LOCALAPPDATA || home, "Cuetra", "licence-cache");
119
+ }
120
+ if (process.platform === "darwin") {
121
+ return path.join(home, "Library", "Caches", "cuetra", "licence-cache");
122
+ }
123
+ return path.join(process.env.XDG_CACHE_HOME || path.join(home, ".cache"), "cuetra", "licence-cache");
124
+ }
125
+
126
+ function cacheFile(normalized) {
127
+ return path.join(cacheDir(), `licence-${keyHash(normalized)}.json`);
128
+ }
129
+
130
+ // Missing, unreadable or corrupt cache entries read as "no cache": a damaged
131
+ // cache must fail closed, never open.
132
+ function readCacheEntry(normalized) {
133
+ try {
134
+ const entry = JSON.parse(fs.readFileSync(cacheFile(normalized), "utf8"));
135
+ if (!entry || typeof entry !== "object" || entry.version !== CACHE_VERSION) return null;
136
+ if (entry.keyHash !== keyHash(normalized)) return null;
137
+ const validatedAt = Date.parse(entry.validatedAt);
138
+ if (!Number.isFinite(validatedAt)) return null;
139
+ return {
140
+ tier: typeof entry.tier === "string" ? entry.tier : null,
141
+ activationId: typeof entry.activationId === "string" && entry.activationId ? entry.activationId : null,
142
+ validatedAt,
143
+ };
144
+ } catch {
145
+ return null;
146
+ }
147
+ }
148
+
149
+ // The cache is written ONLY after a successful live validation, so it can
150
+ // never smuggle an unvalidated key past the gate. A cache that cannot be
151
+ // written (read-only home dir, sandbox) never invalidates a valid licence.
152
+ function writeCacheEntry(normalized, tier, activationId) {
153
+ const entry = {
154
+ version: CACHE_VERSION,
155
+ keyHash: keyHash(normalized),
156
+ tier,
157
+ activationId: activationId || null,
158
+ validatedAt: new Date().toISOString(),
159
+ validForDays: CACHE_TTL_MS / (24 * 60 * 60 * 1000),
160
+ };
161
+ try {
162
+ fs.mkdirSync(cacheDir(), { recursive: true });
163
+ fs.writeFileSync(cacheFile(normalized), JSON.stringify(entry, null, 2) + "\n", "utf8");
164
+ return true;
165
+ } catch {
166
+ return false;
167
+ }
168
+ }
169
+
170
+ function ageText(ms) {
171
+ const minutes = Math.floor(ms / 60000);
172
+ if (minutes < 1) return "less than a minute";
173
+ if (minutes < 60) return `${minutes} minute(s)`;
174
+ const hours = Math.floor(minutes / 60);
175
+ if (hours < 48) return `${hours} hour(s)`;
176
+ return `${Math.floor(hours / 24)} day(s)`;
177
+ }
178
+
179
+ // One Polar customer-portal POST, sent exactly the way the redeem flow sends
180
+ // it. Returns the HTTP status and a sanitized detail; transport-level failure
181
+ // (offline, DNS, timeout) throws, because that is a different class.
182
+ async function polarPost(endpoint, body, normalized) {
183
+ const response = await fetch(`${POLAR_API_BASE}/v1/customer-portal/license-keys/${endpoint}`, {
184
+ method: "POST",
185
+ headers: { "Content-Type": "application/json", "Polar-Version": POLAR_VERSION },
186
+ body: JSON.stringify(body),
187
+ signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS),
188
+ });
189
+ let parsed = null;
190
+ let detail = "";
191
+ try {
192
+ parsed = await response.json();
193
+ const raw =
194
+ typeof parsed?.detail === "string" ? parsed.detail :
195
+ typeof parsed?.error === "string" ? parsed.error :
196
+ parsed?.detail === undefined ? "" : JSON.stringify(parsed.detail);
197
+ // The key must never appear in a detail string that ends up in a log.
198
+ detail = String(raw).slice(0, MAX_DETAIL_CHARS).split(normalized).join(maskKey(normalized)).trim();
199
+ } catch {
200
+ detail = ""; // a non-JSON body (proxy error page) reads as no detail
201
+ }
202
+ return { status: response.status, ok: response.ok, detail, body: parsed };
203
+ }
204
+
205
+ // One live validation round for a parsed key. Returns exactly one of:
206
+ // { kind: "valid", activationId } Polar said yes
207
+ // { kind: "rejected", detail, seatLimit } Polar said no, with the reason
208
+ // { kind: "unreachable" } Polar could not be reached at all
209
+ async function liveValidate(normalized, parsed, cachedActivationId) {
210
+ async function validateOnce(activationId) {
211
+ const body = { key: normalized, organization_id: POLAR_ORG_ID, benefit_id: BENEFIT_BY_TIER[parsed.tier] };
212
+ if (activationId) body.activation_id = activationId;
213
+ const response = await polarPost("validate", body, normalized);
214
+ if (response.ok) return { kind: "valid", activationId };
215
+ if (response.status === 404 || response.status === 400) {
216
+ // 404 = unknown/revoked/expired key, or a mismatched benefit/activation
217
+ // ("no access - don't retry", per Polar's failure table). 400 = the
218
+ // request itself is unsatisfable. Both are honest rejections.
219
+ return { kind: "rejected", detail: response.detail, seatLimit: false };
220
+ }
221
+ return { kind: "unreachable" };
222
+ }
223
+
224
+ async function activateOnce() {
225
+ const response = await polarPost(
226
+ "activate",
227
+ { key: normalized, organization_id: POLAR_ORG_ID, label: `${ACTIVATION_PREFIX} ${os.hostname()}` },
228
+ normalized
229
+ );
230
+ if (response.ok) {
231
+ // activate replies with the activation record; its id must accompany
232
+ // every later validate, or each cache refresh would take another seat.
233
+ const id = response.body && typeof response.body.id === "string" ? response.body.id : null;
234
+ return { kind: "valid", activationId: id };
235
+ }
236
+ if (response.status === 403 || response.status === 404 || response.status === 400) {
237
+ // 403 = revoked/disabled/expired key, a benefit without activation
238
+ // limits, or every seat is in use; 404 = unknown key.
239
+ return {
240
+ kind: "rejected",
241
+ detail: response.detail,
242
+ seatLimit: response.status === 403 && /limit/i.test(response.detail),
243
+ };
244
+ }
245
+ return { kind: "unreachable" };
246
+ }
247
+
248
+ try {
249
+ if (parsed.tier === "business") {
250
+ // Business carries no activation limit: activating would 403 by design,
251
+ // so it validates instead - the same choice the redeem flow makes.
252
+ return await validateOnce(null);
253
+ }
254
+ if (cachedActivationId) {
255
+ // Refresh path: validate the stored activation so a re-check never takes
256
+ // a second seat. If the stored activation is gone (the buyer deactivated
257
+ // this device in the Polar portal), one activate attempt re-takes the
258
+ // freed slot; a revoked key still ends as rejected by that same call.
259
+ const result = await validateOnce(cachedActivationId);
260
+ if (result.kind !== "rejected") return result;
261
+ const retry = await activateOnce();
262
+ if (retry.kind === "rejected") {
263
+ return { kind: "rejected", detail: retry.detail || result.detail, seatLimit: retry.seatLimit };
264
+ }
265
+ return retry;
266
+ }
267
+ // First contact for an activation-limited key: take a seat, as redeem does.
268
+ return await activateOnce();
269
+ } catch {
270
+ // fetch only throws for transport-level failures; that is "unreachable",
271
+ // never "rejected" - Polar said nothing at all.
272
+ return { kind: "unreachable" };
273
+ }
274
+ }
275
+
276
+ // Reverse map: the product that issued a Dodo key -> the Cuetra tier. An id
277
+ // that is not one of ours (any other Dodo product) reads as null, and
278
+ // the caller fails closed.
279
+ function dodoTierForProduct(productId) {
280
+ if (typeof productId !== "string") return null;
281
+ for (const tier of Object.keys(DODO_PRODUCT_BY_TIER)) {
282
+ if (DODO_PRODUCT_BY_TIER[tier] === productId) return tier;
283
+ }
284
+ return null;
285
+ }
286
+
287
+ // One Dodo public licence POST. Same shape as polarPost: HTTP status, a
288
+ // sanitized detail, and ONLY the licence-relevant fields out of the body.
289
+ // The activate reply also carries customer contact details; they are never
290
+ // extracted, so they cannot reach a log, a note or the cache.
291
+ async function dodoPost(endpoint, body, normalized) {
292
+ const response = await fetch(`${DODO_API_BASE}/licenses/${endpoint}`, {
293
+ method: "POST",
294
+ headers: { "Content-Type": "application/json" },
295
+ body: JSON.stringify(body),
296
+ signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS),
297
+ });
298
+ let parsed = null;
299
+ let detail = "";
300
+ try {
301
+ parsed = await response.json();
302
+ const raw = typeof parsed?.message === "string" ? parsed.message : typeof parsed?.error === "string" ? parsed.error : "";
303
+ detail = String(raw).slice(0, MAX_DETAIL_CHARS).split(normalized).join(maskKey(normalized)).trim();
304
+ } catch {
305
+ detail = ""; // a non-JSON body reads as no detail
306
+ }
307
+ return {
308
+ status: response.status,
309
+ ok: response.ok,
310
+ detail,
311
+ instanceId: typeof parsed?.id === "string" ? parsed.id : null,
312
+ productId: parsed?.product && typeof parsed.product.product_id === "string" ? parsed.product.product_id : null,
313
+ valid: typeof parsed?.valid === "boolean" ? parsed.valid : null,
314
+ };
315
+ }
316
+
317
+ // One live Dodo round for a parsed key. Returns exactly one of:
318
+ // { kind: "valid", activationId, tier } Dodo said yes (tier from the
319
+ // issuing product, or the cache on a
320
+ // refresh that only re-validated)
321
+ // { kind: "rejected", detail, seatLimit } Dodo said no, with the reason
322
+ // { kind: "unreachable" } Dodo could not be reached at all
323
+ async function liveDodo(normalized, cachedActivationId) {
324
+ async function activateOnce() {
325
+ const response = await dodoPost("activate", { license_key: normalized, name: `${ACTIVATION_PREFIX} ${os.hostname()}` }, normalized);
326
+ if (response.ok) {
327
+ const tier = dodoTierForProduct(response.productId);
328
+ if (!tier) {
329
+ // Fail-closed: an accepted key for an unknown product unlocks nothing.
330
+ return {
331
+ kind: "rejected",
332
+ detail: "the key was accepted, but it does not belong to a Cuetra product - email hello@cuetra.com with your receipt",
333
+ seatLimit: false,
334
+ };
335
+ }
336
+ return { kind: "valid", activationId: response.instanceId, tier };
337
+ }
338
+ // Per Dodo's API reference: 422 = activation limit reached, 403 = the
339
+ // key is inactive, 404 = the key does not exist.
340
+ if (response.status === 422) {
341
+ return { kind: "rejected", detail: response.detail || "activation limit reached", seatLimit: true };
342
+ }
343
+ if (response.status === 403 || response.status === 404) {
344
+ return { kind: "rejected", detail: response.detail, seatLimit: false };
345
+ }
346
+ return { kind: "unreachable" };
347
+ }
348
+
349
+ async function validateOnce(activationId) {
350
+ const body = { license_key: normalized };
351
+ if (activationId) body.license_key_instance_id = activationId;
352
+ const response = await dodoPost("validate", body, normalized);
353
+ if (response.ok && response.valid === true) return { kind: "valid", activationId };
354
+ if (response.status === 404 || response.status === 403 || response.status === 422 || response.valid === false) {
355
+ // valid:false covers a disabled/expired key; 404 an unknown one; 422 a
356
+ // malformed request. All are honest rejections.
357
+ return { kind: "rejected", detail: response.detail, seatLimit: false };
358
+ }
359
+ return { kind: "unreachable" };
360
+ }
361
+
362
+ try {
363
+ if (cachedActivationId) {
364
+ // Refresh path: re-validate the stored activation so a re-check never
365
+ // takes a second seat. If the stored activation is gone (the buyer
366
+ // freed the device), one activate attempt re-takes the freed slot;
367
+ // a revoked key still ends as rejected by that same call.
368
+ const result = await validateOnce(cachedActivationId);
369
+ if (result.kind !== "rejected") return result;
370
+ const retry = await activateOnce();
371
+ if (retry.kind === "rejected") {
372
+ return { kind: "rejected", detail: retry.detail || result.detail, seatLimit: retry.seatLimit };
373
+ }
374
+ return retry;
375
+ }
376
+ // First contact: take an activation, as redeem does.
377
+ return await activateOnce();
378
+ } catch {
379
+ // fetch only throws for transport-level failures; that is "unreachable",
380
+ // never "rejected" - Dodo said nothing at all.
381
+ return { kind: "unreachable" };
382
+ }
383
+ }
384
+
385
+ function rejectedDetail(rawKey, live, provider) {
386
+ const mask = maskKey(rawKey);
387
+ const service = provider === "dodo" ? "Dodo Payments" : "Polar";
388
+ if (live.seatLimit) {
389
+ const seatAdvice =
390
+ provider === "dodo"
391
+ ? "Email hello@cuetra.com to free an old device and re-run, or upgrade at cuetra.com/pricing"
392
+ : "Deactivate an old device in your Polar customer portal and re-run, or upgrade at cuetra.com/pricing";
393
+ return (
394
+ `${service} rejected the key ${mask}: every activation of this key is already in use` +
395
+ `${live.detail ? ` (${live.detail})` : ""}. ${seatAdvice}`
396
+ );
397
+ }
398
+ return (
399
+ `${service} rejected the key ${mask}${live.detail ? ` (${live.detail})` : ""} - ` +
400
+ `copy the key again from your ${service} receipt or cuetra.com/redeem`
401
+ );
402
+ }
403
+
404
+ // Polar keys spell the tier out; a Dodo key's tier lives in the validation
405
+ // result (or the cache), so anything unknown falls back to the plain name.
406
+ function tierName(tier) {
407
+ return TIER_NAME[tier] || "Cuetra licence";
408
+ }
409
+
410
+ // Validate a licence key: shape -> offline cache -> live POST to the processor
411
+ // the key belongs to. The free tier never calls this; the paid path calls it
412
+ // once per run. Expected classes come back as a structured result - only a
413
+ // genuine bug can throw.
414
+ export async function validateLicence(rawKey) {
415
+ if (typeof rawKey !== "string" || !rawKey.trim()) {
416
+ return { status: "shape-invalid", detail: "no licence key was provided, so nothing was validated or sent anywhere" };
417
+ }
418
+ const parsed = parseKey(rawKey);
419
+ if (!parsed) {
420
+ return {
421
+ status: "shape-invalid",
422
+ detail: `the key ${maskKey(rawKey)} did not match the Cuetra key shapes (Polar's CUETRA-... or Dodo Payments' five-group code), so it was not sent anywhere - copy the key again from your receipt or cuetra.com/redeem`,
423
+ };
424
+ }
425
+
426
+ const provider = parsed.provider; // "polar" | "dodo"
427
+ // Polar keys are sent upper-cased; Dodo UUIDs lower-cased, exactly as
428
+ // parseKey normalised them, so the cache hash and the wire format agree.
429
+ const normalized = provider === "dodo" ? parsed.key : normalizeKey(rawKey);
430
+ const service = provider === "dodo" ? "Dodo Payments" : "Polar";
431
+ const serviceHost = provider === "dodo" ? DODO_API_BASE : POLAR_API_BASE;
432
+
433
+ const cached = readCacheEntry(normalized);
434
+ const cacheAge = cached ? Date.now() - cached.validatedAt : null;
435
+
436
+ if (cached && cacheAge <= CACHE_TTL_MS) {
437
+ // A Dodo key spells no tier out, so the cached live validation names it;
438
+ // a Polar key already knows its own.
439
+ const tier = parsed.tier || cached.tier;
440
+ return {
441
+ status: "cache-valid",
442
+ tier,
443
+ detail:
444
+ `${tierName(tier)} - ${maskKey(rawKey)} passed the offline validation cache ` +
445
+ `(live ${service} check ${ageText(cacheAge)} ago; the cache is kept for 7 days), so ${service} was not contacted this run`,
446
+ };
447
+ }
448
+
449
+ const live =
450
+ provider === "dodo"
451
+ ? await liveDodo(normalized, cached ? cached.activationId : null)
452
+ : await liveValidate(normalized, parsed, cached ? cached.activationId : null);
453
+
454
+ if (live.kind === "valid") {
455
+ // The tier of a Dodo key comes from the activation reply; on a refresh
456
+ // that only re-validated, the earlier cached tier still names it.
457
+ const tier = live.tier || parsed.tier || (cached ? cached.tier : null);
458
+ const wrote = writeCacheEntry(normalized, tier, live.activationId);
459
+ const cacheNote = wrote ? "" : " (the offline cache could not be written, so the next run needs the network again)";
460
+ return {
461
+ status: "valid",
462
+ tier,
463
+ detail: `${tierName(tier)} - key ${maskKey(rawKey)} validated with ${service} just now${cacheNote}`,
464
+ };
465
+ }
466
+ if (live.kind === "rejected") {
467
+ return { status: "rejected", detail: rejectedDetail(rawKey, live, provider) };
468
+ }
469
+ if (cached) {
470
+ return {
471
+ status: "offline-no-cache",
472
+ detail:
473
+ `could not reach the licence server (${serviceHost}), and the cached validation for ${maskKey(rawKey)} ` +
474
+ `is ${ageText(cacheAge)} old - older than the 7-day window - so paid content stays locked. ` +
475
+ "Re-run once while online to revalidate the key",
476
+ };
477
+ }
478
+ return {
479
+ status: "offline-no-cache",
480
+ detail:
481
+ `could not reach the licence server (${serviceHost}) to validate ${maskKey(rawKey)}, and no validation from the ` +
482
+ `last 7 days is cached, so paid content stays locked. Re-run once while online; keys come from the ${service} ` +
483
+ "receipt or cuetra.com/redeem",
484
+ };
485
+ }
@@ -0,0 +1,132 @@
1
+ // Owns pack access and licence state for the MCP server. Without a licence key only
2
+ // the bundled free sampler set (100 icons, shipped in ../pack) is served; paid access
3
+ // requires both CUETRA_LICENCE_KEY and CUETRA_PACK_DIR pointing at the unpacked full
4
+ // pack - mirroring the CLI's licence behavior - and the key must PASS online
5
+ // validation with the processor that issued it, Polar or Dodo Payments
6
+ // (lib/licence.js: a live check, or one cached within the
7
+ // 7-day window). A paid request without a validated key gets an honest error,
8
+ // never paid content.
9
+ import fs from "node:fs";
10
+ import path from "node:path";
11
+ import { fileURLToPath } from "node:url";
12
+ import { isLicenceAllowed, validateLicence } from "./licence.js";
13
+
14
+ // The free sampler set ships inside this package, so the default path is portable.
15
+ export const BUNDLED_FREE_PACK_DIR = fileURLToPath(new URL("../pack/", import.meta.url));
16
+
17
+ // Validation runs only on the paid path: a run without a full pack directory
18
+ // never contacts a licence server. The shape check itself (first step of
19
+ // validateLicence) is the tier-aware parseKey from src/licence.js - Polar,
20
+ // Dodo or legacy shape, legacy keys checksum-verified - so a malformed key is
21
+ // never sent anywhere.
22
+ // The MCP server runs from this repo, so the relative import resolves to src/.
23
+
24
+ export const FREE_SET_SIZE = 100;
25
+
26
+ // Strict load: a pack without a readable motion.json is a startup error, not an
27
+ // empty tool set. The map is read once; icon SVGs are read per call.
28
+ function loadPack(dir) {
29
+ const resolved = path.resolve(dir);
30
+ const mapPath = path.join(resolved, "motion.json");
31
+ if (!fs.existsSync(mapPath)) {
32
+ throw new Error(`no motion.json in pack directory: ${resolved}`);
33
+ }
34
+ const map = JSON.parse(fs.readFileSync(mapPath, "utf8"));
35
+ if (!map || typeof map.icons !== "object") {
36
+ throw new Error(`motion.json in ${resolved} has no icons map`);
37
+ }
38
+ return { dir: resolved, map, iconNames: Object.keys(map.icons).sort() };
39
+ }
40
+
41
+ // True when a configured pack directory is the bundled free sampler set itself
42
+ // (same directory, any path spelling).
43
+ function isBundledFreeDir(dir) {
44
+ try {
45
+ return fs.realpathSync(path.resolve(dir)) === fs.realpathSync(path.resolve(BUNDLED_FREE_PACK_DIR));
46
+ } catch {
47
+ return path.resolve(dir) === path.resolve(BUNDLED_FREE_PACK_DIR);
48
+ }
49
+ }
50
+
51
+ // Paid content is served only when a full pack directory is configured AND the
52
+ // licence key passed online validation with the processor that issued it.
53
+ // Anything less serves the bundled free set, and the notes say exactly which
54
+ // class failed and what to do about it - never paid content.
55
+ export async function resolvePack() {
56
+ const licenceKey = process.env.CUETRA_LICENCE_KEY;
57
+ const packDirEnv = process.env.CUETRA_PACK_DIR;
58
+ const notes = [];
59
+
60
+ if (!packDirEnv) {
61
+ if (licenceKey) {
62
+ // CLI parity: a key alone gates nothing here either - paid icons need
63
+ // the pack directory too, so the key is not validated (no network) and
64
+ // the startup note says what is missing.
65
+ notes.push(
66
+ "CUETRA_LICENCE_KEY is set but no CUETRA_PACK_DIR is configured, so the key was not validated; " +
67
+ "serving the free sampler set. Paid icons need both a validated key (Polar or Dodo Payments) and the full pack directory."
68
+ );
69
+ }
70
+ const pack = loadPack(BUNDLED_FREE_PACK_DIR);
71
+ return { ...pack, licensed: false, notes };
72
+ }
73
+
74
+ // The bundled free set is free content however explicitly it is configured;
75
+ // serving it never needs a key or the network.
76
+ if (isBundledFreeDir(packDirEnv)) {
77
+ notes.push("CUETRA_PACK_DIR points at the free sampler set, so no licence check is needed");
78
+ const pack = loadPack(BUNDLED_FREE_PACK_DIR);
79
+ return { ...pack, licensed: false, notes };
80
+ }
81
+
82
+ if (!licenceKey) {
83
+ notes.push(
84
+ "CUETRA_PACK_DIR is set but no CUETRA_LICENCE_KEY is configured; serving the free sampler set. " +
85
+ "Paid icons need a licence key that passes online validation (Polar or Dodo Payments)."
86
+ );
87
+ const pack = loadPack(BUNDLED_FREE_PACK_DIR);
88
+ return { ...pack, licensed: false, notes };
89
+ }
90
+
91
+ // The paid gate: one validation per server start (live check, or the 7-day
92
+ // offline cache). Fail-closed on every other class.
93
+ const validation = await validateLicence(licenceKey);
94
+ if (isLicenceAllowed(validation)) {
95
+ const pack = loadPack(packDirEnv);
96
+ return { ...pack, licensed: true, notes: [validation.detail] };
97
+ }
98
+
99
+ notes.push(`${validation.detail} — serving the free sampler set`);
100
+ const pack = loadPack(BUNDLED_FREE_PACK_DIR);
101
+ return { ...pack, licensed: false, notes };
102
+ }
103
+
104
+ export function readIconSvg(pack, iconName) {
105
+ const svgPath = path.join(pack.dir, `${iconName}.svg`);
106
+ if (!fs.existsSync(svgPath)) {
107
+ return null;
108
+ }
109
+ return fs.readFileSync(svgPath, "utf8");
110
+ }
111
+
112
+ // Extract one treatment's kinetic group from a multi-treatment SVG. The pack stores all
113
+ // four treatments in one file as sibling `<g class="mt" data-treatment="...">` blocks, so
114
+ // a single block is recovered by scanning for its balanced `</g>` close - a non-greedy
115
+ // regex cannot do this, because nested part groups also close with `</g>`.
116
+ export function extractTreatment(svgText, treatment) {
117
+ const marker = `<g class="mt" data-treatment="${treatment}"`;
118
+ const start = svgText.indexOf(marker);
119
+ if (start === -1) return null;
120
+ const openEnd = svgText.indexOf(">", start);
121
+ const tagPattern = /<(\/?)g[\s>]/g;
122
+ tagPattern.lastIndex = openEnd + 1;
123
+ let depth = 1;
124
+ let match;
125
+ while (depth > 0 && (match = tagPattern.exec(svgText)) !== null) {
126
+ depth += match[1] === "/" ? -1 : 1;
127
+ }
128
+ if (depth !== 0) return null;
129
+ const group = svgText.slice(start, tagPattern.lastIndex);
130
+ const svgOpenTag = svgText.slice(0, svgText.indexOf(">") + 1);
131
+ return `${svgOpenTag}\n ${group}\n</svg>`;
132
+ }