ronin-skillforce 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (429) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/LICENSE +21 -0
  3. package/README.md +225 -2
  4. package/bin/cli.js +811 -0
  5. package/bin/commands/check.js +298 -0
  6. package/bin/commands/create.js +169 -0
  7. package/bin/commands/doctor.js +392 -0
  8. package/bin/commands/import.js +557 -0
  9. package/bin/commands/next.js +125 -0
  10. package/bin/commands/review.js +207 -0
  11. package/bin/commands/status.js +114 -0
  12. package/bin/commands/studio.js +497 -0
  13. package/bin/commands/trail.js +211 -0
  14. package/bin/commands/web.js +350 -0
  15. package/bin/course-reader.js +611 -0
  16. package/bin/node-version.js +60 -0
  17. package/bin/platforms/_shared.js +211 -0
  18. package/bin/platforms/claude.js +104 -0
  19. package/bin/platforms/cursor.js +49 -0
  20. package/bin/platforms/gemini.js +65 -0
  21. package/bin/platforms/opencode.js +95 -0
  22. package/bin/registry-helpers.js +504 -0
  23. package/bin/static-server.js +153 -0
  24. package/bin/studio-store.js +94 -0
  25. package/bin/sync-shared.sh +5 -0
  26. package/package.json +91 -4
  27. package/plugin.json +139 -0
  28. package/shared/SKILL.md +568 -0
  29. package/shared/agents/coach.md +225 -0
  30. package/shared/agents/navigator.md +215 -0
  31. package/shared/agents/professor.md +372 -0
  32. package/shared/agents/researcher.md +181 -0
  33. package/shared/agents/spotter.md +129 -0
  34. package/shared/commands/professor/archive.md +103 -0
  35. package/shared/commands/professor/capstone-review.md +79 -0
  36. package/shared/commands/professor/capstone.md +34 -0
  37. package/shared/commands/professor/discuss.md +18 -0
  38. package/shared/commands/professor/done.md +44 -0
  39. package/shared/commands/professor/export.md +69 -0
  40. package/shared/commands/professor/hint.md +108 -0
  41. package/shared/commands/professor/navigator.md +67 -0
  42. package/shared/commands/professor/new-topic.md +73 -0
  43. package/shared/commands/professor/next.md +174 -0
  44. package/shared/commands/professor/note.md +63 -0
  45. package/shared/commands/professor/onboard.md +95 -0
  46. package/shared/commands/professor/progress.md +46 -0
  47. package/shared/commands/professor/publish.md +93 -0
  48. package/shared/commands/professor/quiz.md +27 -0
  49. package/shared/commands/professor/recall.md +74 -0
  50. package/shared/commands/professor/review.md +43 -0
  51. package/shared/commands/professor/schedule.md +75 -0
  52. package/shared/commands/professor/skill-export.md +87 -0
  53. package/shared/commands/professor/spotter.md +76 -0
  54. package/shared/commands/professor/stuck.md +27 -0
  55. package/shared/commands/professor/switch.md +50 -0
  56. package/shared/commands/professor/syllabus.md +9 -0
  57. package/shared/commands/professor/template-export.md +91 -0
  58. package/shared/commands/professor/template-import.md +111 -0
  59. package/shared/commands/professor/worktrees.md +58 -0
  60. package/shared/hooks/pre-compact.js +232 -0
  61. package/studio/README.md +313 -0
  62. package/studio/dist/assets/BetaReportPanel-8NrDLiPm.js +1 -0
  63. package/studio/dist/assets/Capstone-Cv9kH6LY.js +6 -0
  64. package/studio/dist/assets/CodeWorkspace-BwCEINWo.js +2 -0
  65. package/studio/dist/assets/Course-BJ_hafUP.js +1 -0
  66. package/studio/dist/assets/Editor-CV0mNhlz.js +53 -0
  67. package/studio/dist/assets/Home-C1ry89ak.js +1 -0
  68. package/studio/dist/assets/KaTeX_AMS-Regular-BQhdFMY1.woff2 +0 -0
  69. package/studio/dist/assets/KaTeX_AMS-Regular-DMm9YOAa.woff +0 -0
  70. package/studio/dist/assets/KaTeX_AMS-Regular-DRggAlZN.ttf +0 -0
  71. package/studio/dist/assets/KaTeX_Caligraphic-Bold-ATXxdsX0.ttf +0 -0
  72. package/studio/dist/assets/KaTeX_Caligraphic-Bold-BEiXGLvX.woff +0 -0
  73. package/studio/dist/assets/KaTeX_Caligraphic-Bold-Dq_IR9rO.woff2 +0 -0
  74. package/studio/dist/assets/KaTeX_Caligraphic-Regular-CTRA-rTL.woff +0 -0
  75. package/studio/dist/assets/KaTeX_Caligraphic-Regular-Di6jR-x-.woff2 +0 -0
  76. package/studio/dist/assets/KaTeX_Caligraphic-Regular-wX97UBjC.ttf +0 -0
  77. package/studio/dist/assets/KaTeX_Fraktur-Bold-BdnERNNW.ttf +0 -0
  78. package/studio/dist/assets/KaTeX_Fraktur-Bold-BsDP51OF.woff +0 -0
  79. package/studio/dist/assets/KaTeX_Fraktur-Bold-CL6g_b3V.woff2 +0 -0
  80. package/studio/dist/assets/KaTeX_Fraktur-Regular-CB_wures.ttf +0 -0
  81. package/studio/dist/assets/KaTeX_Fraktur-Regular-CTYiF6lA.woff2 +0 -0
  82. package/studio/dist/assets/KaTeX_Fraktur-Regular-Dxdc4cR9.woff +0 -0
  83. package/studio/dist/assets/KaTeX_Main-Bold-Cx986IdX.woff2 +0 -0
  84. package/studio/dist/assets/KaTeX_Main-Bold-Jm3AIy58.woff +0 -0
  85. package/studio/dist/assets/KaTeX_Main-Bold-waoOVXN0.ttf +0 -0
  86. package/studio/dist/assets/KaTeX_Main-BoldItalic-DxDJ3AOS.woff2 +0 -0
  87. package/studio/dist/assets/KaTeX_Main-BoldItalic-DzxPMmG6.ttf +0 -0
  88. package/studio/dist/assets/KaTeX_Main-BoldItalic-SpSLRI95.woff +0 -0
  89. package/studio/dist/assets/KaTeX_Main-Italic-3WenGoN9.ttf +0 -0
  90. package/studio/dist/assets/KaTeX_Main-Italic-BMLOBm91.woff +0 -0
  91. package/studio/dist/assets/KaTeX_Main-Italic-NWA7e6Wa.woff2 +0 -0
  92. package/studio/dist/assets/KaTeX_Main-Regular-B22Nviop.woff2 +0 -0
  93. package/studio/dist/assets/KaTeX_Main-Regular-Dr94JaBh.woff +0 -0
  94. package/studio/dist/assets/KaTeX_Main-Regular-ypZvNtVU.ttf +0 -0
  95. package/studio/dist/assets/KaTeX_Math-BoldItalic-B3XSjfu4.ttf +0 -0
  96. package/studio/dist/assets/KaTeX_Math-BoldItalic-CZnvNsCZ.woff2 +0 -0
  97. package/studio/dist/assets/KaTeX_Math-BoldItalic-iY-2wyZ7.woff +0 -0
  98. package/studio/dist/assets/KaTeX_Math-Italic-DA0__PXp.woff +0 -0
  99. package/studio/dist/assets/KaTeX_Math-Italic-flOr_0UB.ttf +0 -0
  100. package/studio/dist/assets/KaTeX_Math-Italic-t53AETM-.woff2 +0 -0
  101. package/studio/dist/assets/KaTeX_SansSerif-Bold-CFMepnvq.ttf +0 -0
  102. package/studio/dist/assets/KaTeX_SansSerif-Bold-D1sUS0GD.woff2 +0 -0
  103. package/studio/dist/assets/KaTeX_SansSerif-Bold-DbIhKOiC.woff +0 -0
  104. package/studio/dist/assets/KaTeX_SansSerif-Italic-C3H0VqGB.woff2 +0 -0
  105. package/studio/dist/assets/KaTeX_SansSerif-Italic-DN2j7dab.woff +0 -0
  106. package/studio/dist/assets/KaTeX_SansSerif-Italic-YYjJ1zSn.ttf +0 -0
  107. package/studio/dist/assets/KaTeX_SansSerif-Regular-BNo7hRIc.ttf +0 -0
  108. package/studio/dist/assets/KaTeX_SansSerif-Regular-CS6fqUqJ.woff +0 -0
  109. package/studio/dist/assets/KaTeX_SansSerif-Regular-DDBCnlJ7.woff2 +0 -0
  110. package/studio/dist/assets/KaTeX_Script-Regular-C5JkGWo-.ttf +0 -0
  111. package/studio/dist/assets/KaTeX_Script-Regular-D3wIWfF6.woff2 +0 -0
  112. package/studio/dist/assets/KaTeX_Script-Regular-D5yQViql.woff +0 -0
  113. package/studio/dist/assets/KaTeX_Size1-Regular-C195tn64.woff +0 -0
  114. package/studio/dist/assets/KaTeX_Size1-Regular-Dbsnue_I.ttf +0 -0
  115. package/studio/dist/assets/KaTeX_Size1-Regular-mCD8mA8B.woff2 +0 -0
  116. package/studio/dist/assets/KaTeX_Size2-Regular-B7gKUWhC.ttf +0 -0
  117. package/studio/dist/assets/KaTeX_Size2-Regular-Dy4dx90m.woff2 +0 -0
  118. package/studio/dist/assets/KaTeX_Size2-Regular-oD1tc_U0.woff +0 -0
  119. package/studio/dist/assets/KaTeX_Size3-Regular-CTq5MqoE.woff +0 -0
  120. package/studio/dist/assets/KaTeX_Size3-Regular-DgpXs0kz.ttf +0 -0
  121. package/studio/dist/assets/KaTeX_Size4-Regular-BF-4gkZK.woff +0 -0
  122. package/studio/dist/assets/KaTeX_Size4-Regular-DWFBv043.ttf +0 -0
  123. package/studio/dist/assets/KaTeX_Size4-Regular-Dl5lxZxV.woff2 +0 -0
  124. package/studio/dist/assets/KaTeX_Typewriter-Regular-C0xS9mPB.woff +0 -0
  125. package/studio/dist/assets/KaTeX_Typewriter-Regular-CO6r4hn1.woff2 +0 -0
  126. package/studio/dist/assets/KaTeX_Typewriter-Regular-D3Ib7_Hf.ttf +0 -0
  127. package/studio/dist/assets/Lesson-2e9TD9yL.js +2 -0
  128. package/studio/dist/assets/NewCourse-BZeOg2xn.js +952 -0
  129. package/studio/dist/assets/Progress-CRc_xEWC.js +1 -0
  130. package/studio/dist/assets/Review-6QEbHEfk.js +1 -0
  131. package/studio/dist/assets/Settings-NFnqVQui.js +1 -0
  132. package/studio/dist/assets/TutorPanel-DXQ6Z3BY.js +123 -0
  133. package/studio/dist/assets/abnfDiagram-WEYOIA3C-qeSjKlGM.js +1 -0
  134. package/studio/dist/assets/anthropic-D7NiQCUH.js +15 -0
  135. package/studio/dist/assets/arc-Y1ARJVZ4.js +1 -0
  136. package/studio/dist/assets/architecture-WOLXFQ4H-COG-m35l.js +1 -0
  137. package/studio/dist/assets/architectureDiagram-ZHVYKT53-VO7uKoeD.js +36 -0
  138. package/studio/dist/assets/array-BifhSqXX.js +1 -0
  139. package/studio/dist/assets/blockDiagram-RJAE7QA3-BGJF_qiL.js +140 -0
  140. package/studio/dist/assets/bridge-BTh0AeNX.js +1 -0
  141. package/studio/dist/assets/c4Diagram-XDPPPE54-C-S10RgU.js +38 -0
  142. package/studio/dist/assets/capstone-Amn6Hztq.js +135 -0
  143. package/studio/dist/assets/card-store-BrbrtX9w.js +1 -0
  144. package/studio/dist/assets/channel-SJiUQu_N.js +1 -0
  145. package/studio/dist/assets/chunk-2E7WHVMD-fv-iqTyC.js +88 -0
  146. package/studio/dist/assets/chunk-2Q5K7J3B-C1jixKkw.js +1 -0
  147. package/studio/dist/assets/chunk-4EMNKR2T-CY9IZrgv.js +1 -0
  148. package/studio/dist/assets/chunk-55XCU76K-DyTZz7v_.js +1 -0
  149. package/studio/dist/assets/chunk-5VM5RSS4-ZNzvKenW.js +15 -0
  150. package/studio/dist/assets/chunk-7S6XSTFO-BNMzTLRW.js +2 -0
  151. package/studio/dist/assets/chunk-AQDTSKZB-CEYANohH.js +72 -0
  152. package/studio/dist/assets/chunk-DSNLSHJZ-CDk5EXjH.js +129 -0
  153. package/studio/dist/assets/chunk-DUW6YSOI-Dgx8z5s3.js +1 -0
  154. package/studio/dist/assets/chunk-HAGFOTED-hNAi1zh_.js +62 -0
  155. package/studio/dist/assets/chunk-HNE4Q36P-COJnSYoZ.js +1 -0
  156. package/studio/dist/assets/chunk-J5ZVWO5B-oDCd-gWO.js +1 -0
  157. package/studio/dist/assets/chunk-JWPE2WC7-DVXcaiue.js +1 -0
  158. package/studio/dist/assets/chunk-NGNAAXSQ-C2Wy9Xmz.js +136 -0
  159. package/studio/dist/assets/chunk-NQOKRVIF-BU6KVxRr.js +213 -0
  160. package/studio/dist/assets/chunk-UHW7PFBP-DYvxL9JG.js +1 -0
  161. package/studio/dist/assets/chunk-VQ5W62QI-CuRfk65j.js +1 -0
  162. package/studio/dist/assets/chunk-WQQL4CDK-KaG7x-Mb.js +10 -0
  163. package/studio/dist/assets/chunk-XXDRQBXY-CnbRkih_.js +1 -0
  164. package/studio/dist/assets/chunk-Y2CYZVJY-DsF7k-Jl.js +1 -0
  165. package/studio/dist/assets/chunk-YZO67HFG-DbuqIZmk.js +1 -0
  166. package/studio/dist/assets/chunk-ZAUX2LTX-bk4ivUmc.js +1 -0
  167. package/studio/dist/assets/chunk-ZCHMQSOR-B_LElfwh.js +2 -0
  168. package/studio/dist/assets/classDiagram-v2-4MYWR3UA-DtCJ6H_X.js +217 -0
  169. package/studio/dist/assets/cose-bilkent-JH36ORCC-DMBAZFnj.js +1 -0
  170. package/studio/dist/assets/course-export-DpaOTT3a.js +1 -0
  171. package/studio/dist/assets/cynefin-EF2NZ3EQ-D9btHJvU.js +1 -0
  172. package/studio/dist/assets/cynefinDiagram-WF24UDRP-CsFJuv27.js +62 -0
  173. package/studio/dist/assets/cytoscape.esm-CHBj4VkZ.js +321 -0
  174. package/studio/dist/assets/dagre-NK4GIZVX-Cg1Duec7.js +4 -0
  175. package/studio/dist/assets/defaultLocale-BFoDCU3G.js +1 -0
  176. package/studio/dist/assets/diagram-CBK3MWTC-_KU2m5gd.js +24 -0
  177. package/studio/dist/assets/diagram-I5XIIV2D-5RaBrwUA.js +24 -0
  178. package/studio/dist/assets/diagram-ODIL2UCW-C0VKxoD3.js +30 -0
  179. package/studio/dist/assets/diagram-PFBEJUXE-BaHcZEP2.js +3 -0
  180. package/studio/dist/assets/diagram-RJA3I4VV-cwSAZ90p.js +41 -0
  181. package/studio/dist/assets/diagram-TYUNFSNR-BJImxCEN.js +200 -0
  182. package/studio/dist/assets/dist-CumnGVmJ.js +1 -0
  183. package/studio/dist/assets/ebnfDiagram-V4P3TTPT-OQQLRXcm.js +1 -0
  184. package/studio/dist/assets/elk-QONTBCTQ-BJGhQHxQ.js +27 -0
  185. package/studio/dist/assets/erDiagram-KYQIGQAA-D91EKSep.js +99 -0
  186. package/studio/dist/assets/error-BTdmRKoB.js +1 -0
  187. package/studio/dist/assets/errors-BZa_CNHL.js +1 -0
  188. package/studio/dist/assets/eventmodeling-K75KTNOO-DgdTRgnw.js +1 -0
  189. package/studio/dist/assets/fetch-local-DG3O3hmQ.js +4 -0
  190. package/studio/dist/assets/flowDiagram-IUGLLWBU-CVnJYMum.js +1 -0
  191. package/studio/dist/assets/ganttDiagram-R7GPNTJY-CSYLPWEI.js +292 -0
  192. package/studio/dist/assets/gitGraph-VSP46ZUC-D6GWaV9y.js +1 -0
  193. package/studio/dist/assets/gitGraphDiagram-PDYL7XHY-CaV31bvT.js +106 -0
  194. package/studio/dist/assets/graphlib-DS17s2tU.js +1 -0
  195. package/studio/dist/assets/index-CVenTTOY.css +2 -0
  196. package/studio/dist/assets/index-DioXTZVc.js +313 -0
  197. package/studio/dist/assets/info-OHQRW6UA-BN-x8GoN.js +1 -0
  198. package/studio/dist/assets/infoDiagram-MVDRKAX5-CIose_cy.js +2 -0
  199. package/studio/dist/assets/init-C-OQMol4.js +1 -0
  200. package/studio/dist/assets/ishikawaDiagram-HPEHV2GE-DCihSNBw.js +70 -0
  201. package/studio/dist/assets/journeyDiagram-BOSHW7O7-Bz3o3RIX.js +139 -0
  202. package/studio/dist/assets/js.worker-AD7DjksO.js +4 -0
  203. package/studio/dist/assets/kanban-definition-FNSA4HC5-BUyqvlFE.js +89 -0
  204. package/studio/dist/assets/katex-B_JcIwqj.js +257 -0
  205. package/studio/dist/assets/katex-BgsA2lO1.css +1 -0
  206. package/studio/dist/assets/line-B08T8KlK.js +1 -0
  207. package/studio/dist/assets/linear-C9iwaMOi.js +1 -0
  208. package/studio/dist/assets/mermaid-parser.core-BYwreSUy.js +7 -0
  209. package/studio/dist/assets/mermaid.core-DTO1oDmq.js +44 -0
  210. package/studio/dist/assets/mindmap-definition-6OY57UG3-BGLwKheY.js +98 -0
  211. package/studio/dist/assets/node.browser-BISniYn8.js +1 -0
  212. package/studio/dist/assets/node.browser-HQ5SKBOf.js +1 -0
  213. package/studio/dist/assets/ollama-De5w84tG.js +1 -0
  214. package/studio/dist/assets/openai-compatible-Joy1oK3L.js +1 -0
  215. package/studio/dist/assets/ordinal-BDEzSJ7C.js +1 -0
  216. package/studio/dist/assets/packet-JDAUHWVQ-CDIMjHS_.js +1 -0
  217. package/studio/dist/assets/path-fybaL0A-.js +1 -0
  218. package/studio/dist/assets/pegDiagram-ECIUJNBX-DWXm4mwS.js +1 -0
  219. package/studio/dist/assets/pie-XZMESJXO-CY3QQiKZ.js +1 -0
  220. package/studio/dist/assets/pieDiagram-GNMPY74T-M1aCnI7W.js +39 -0
  221. package/studio/dist/assets/python.worker-CzTrFdd9.js +24 -0
  222. package/studio/dist/assets/quadrantDiagram-D57K4MC3-BFFtO7U5.js +7 -0
  223. package/studio/dist/assets/radar-ABXABTNO-DT0W4_Xn.js +1 -0
  224. package/studio/dist/assets/railroad-I3PHUGI6-_VCpgZR5.js +1 -0
  225. package/studio/dist/assets/railroad-abnf-LNEFI6M7-DkSpQ5YY.js +1 -0
  226. package/studio/dist/assets/railroad-ebnf-DWYD2UWJ-BqWILdGb.js +1 -0
  227. package/studio/dist/assets/railroad-peg-JR7BVNR7-BB0bQL-Z.js +1 -0
  228. package/studio/dist/assets/railroadDiagram-Y72NRBL7-CjLKjIdJ.js +1 -0
  229. package/studio/dist/assets/react-B8SKf8RM.js +1 -0
  230. package/studio/dist/assets/rehype-katex-C-sKddsH.js +259 -0
  231. package/studio/dist/assets/remark-math-C-ox67hE.js +5 -0
  232. package/studio/dist/assets/requirementDiagram-EQYSW5RA-CnwzZqR8.js +84 -0
  233. package/studio/dist/assets/rolldown-runtime-COiEfhsA.js +1 -0
  234. package/studio/dist/assets/rough.esm-Dy-Kn_BL.js +1 -0
  235. package/studio/dist/assets/sankeyDiagram-SY24JHO5-CPDugTUl.js +40 -0
  236. package/studio/dist/assets/schemas-BOc2YsOP.js +55 -0
  237. package/studio/dist/assets/sequenceDiagram-BLEHNHQU-1dLfeU9Y.js +169 -0
  238. package/studio/dist/assets/settings-DhwuyNPU.js +1 -0
  239. package/studio/dist/assets/sizeCapture-INFHLROL-3uHXrFqA.js +1 -0
  240. package/studio/dist/assets/spec-nAnsSMkw.js +1 -0
  241. package/studio/dist/assets/sql-wasm-C1D_RJuy.wasm +0 -0
  242. package/studio/dist/assets/sql.worker-D7pBHOrq.js +4 -0
  243. package/studio/dist/assets/src-BWF7jMDv.js +1 -0
  244. package/studio/dist/assets/stateDiagram-v2-A6IESKWZ-DR7CmEjj.js +291 -0
  245. package/studio/dist/assets/swimlanes-B3ENRKFQ-BAWB9omQ.js +1 -0
  246. package/studio/dist/assets/swimlanesDiagram-AYQRV4AK-qeuHru16.js +8 -0
  247. package/studio/dist/assets/timeline-definition-JXYKGLGB-DNkj8z77.js +120 -0
  248. package/studio/dist/assets/treeView-D4JQ5SDB-BA-ouhMb.js +1 -0
  249. package/studio/dist/assets/treemap-SAJKECNS-BrrGxsAb.js +1 -0
  250. package/studio/dist/assets/useStream-rdsR6A7P.js +1 -0
  251. package/studio/dist/assets/usecaseDiagram-WPOLBNNX-BB3D0Dt_.js +328 -0
  252. package/studio/dist/assets/vennDiagram-Q3Y3IDCW-BrtqtKTE.js +34 -0
  253. package/studio/dist/assets/wardley-7MLQ67FV-BKkemDql.js +1 -0
  254. package/studio/dist/assets/wardleyDiagram-IVAIDKWA-DFnI3P5z.js +78 -0
  255. package/studio/dist/assets/xychartDiagram-4URNHDU4-Da0DZG_q.js +7 -0
  256. package/studio/dist/index.html +20 -0
  257. package/studio/dist/preview.html +22 -0
  258. package/studio/migrations/0001_init.sql +188 -0
  259. package/studio/migrations/0002_external_ids.sql +20 -0
  260. package/studio/migrations/0003_course_language.sql +12 -0
  261. package/studio/migrations/0004_capstone.sql +51 -0
  262. package/studio/migrations/0005_beta_loop.sql +73 -0
  263. package/studio/migrations/0006_interactive_exercises.sql +49 -0
  264. package/studio/src/lib/activity.js +92 -0
  265. package/studio/src/lib/ai/anthropic.js +109 -0
  266. package/studio/src/lib/ai/bridge.js +126 -0
  267. package/studio/src/lib/ai/catalog.js +160 -0
  268. package/studio/src/lib/ai/config.js +70 -0
  269. package/studio/src/lib/ai/errors.js +95 -0
  270. package/studio/src/lib/ai/fetch-local.js +104 -0
  271. package/studio/src/lib/ai/index.js +194 -0
  272. package/studio/src/lib/ai/ollama.js +136 -0
  273. package/studio/src/lib/ai/openai-compatible.js +101 -0
  274. package/studio/src/lib/ai/provider-utils.js +107 -0
  275. package/studio/src/lib/ai/sse.js +99 -0
  276. package/studio/src/lib/ai/status.js +92 -0
  277. package/studio/src/lib/ai/useStream.js +109 -0
  278. package/studio/src/lib/beta/metrics.js +147 -0
  279. package/studio/src/lib/beta/report.js +134 -0
  280. package/studio/src/lib/capstone-evidence.js +758 -0
  281. package/studio/src/lib/capstone.js +663 -0
  282. package/studio/src/lib/chat-store.js +128 -0
  283. package/studio/src/lib/course-export.js +38 -0
  284. package/studio/src/lib/course.js +187 -0
  285. package/studio/src/lib/exercises/journal-entry.js +259 -0
  286. package/studio/src/lib/exercises/placement.js +31 -0
  287. package/studio/src/lib/exercises/registry.js +19 -0
  288. package/studio/src/lib/exercises/spec.js +129 -0
  289. package/studio/src/lib/i18n/detect.js +162 -0
  290. package/studio/src/lib/i18n/en/app.json +23 -0
  291. package/studio/src/lib/i18n/en/betaReport.json +55 -0
  292. package/studio/src/lib/i18n/en/capstone.json +57 -0
  293. package/studio/src/lib/i18n/en/common.json +25 -0
  294. package/studio/src/lib/i18n/en/course.json +27 -0
  295. package/studio/src/lib/i18n/en/data.json +35 -0
  296. package/studio/src/lib/i18n/en/durability.json +5 -0
  297. package/studio/src/lib/i18n/en/errors.json +20 -0
  298. package/studio/src/lib/i18n/en/exercises.json +55 -0
  299. package/studio/src/lib/i18n/en/externalEvidence.json +76 -0
  300. package/studio/src/lib/i18n/en/home.json +18 -0
  301. package/studio/src/lib/i18n/en/lesson.json +33 -0
  302. package/studio/src/lib/i18n/en/nav.json +8 -0
  303. package/studio/src/lib/i18n/en/newCourse.json +51 -0
  304. package/studio/src/lib/i18n/en/onboarding.json +35 -0
  305. package/studio/src/lib/i18n/en/playwrightTemplate.json +20 -0
  306. package/studio/src/lib/i18n/en/practice.json +79 -0
  307. package/studio/src/lib/i18n/en/provider.json +27 -0
  308. package/studio/src/lib/i18n/en/providerMeta.json +26 -0
  309. package/studio/src/lib/i18n/en/reflection.json +17 -0
  310. package/studio/src/lib/i18n/en/revision.json +52 -0
  311. package/studio/src/lib/i18n/en/runnerNotice.json +14 -0
  312. package/studio/src/lib/i18n/en/settings.json +12 -0
  313. package/studio/src/lib/i18n/en/storage.json +49 -0
  314. package/studio/src/lib/i18n/en/tutor.json +39 -0
  315. package/studio/src/lib/i18n/en/workspace.json +50 -0
  316. package/studio/src/lib/i18n/index.js +144 -0
  317. package/studio/src/lib/i18n/languages.js +93 -0
  318. package/studio/src/lib/i18n/vi/app.json +23 -0
  319. package/studio/src/lib/i18n/vi/betaReport.json +55 -0
  320. package/studio/src/lib/i18n/vi/capstone.json +57 -0
  321. package/studio/src/lib/i18n/vi/common.json +25 -0
  322. package/studio/src/lib/i18n/vi/course.json +27 -0
  323. package/studio/src/lib/i18n/vi/data.json +35 -0
  324. package/studio/src/lib/i18n/vi/durability.json +5 -0
  325. package/studio/src/lib/i18n/vi/errors.json +20 -0
  326. package/studio/src/lib/i18n/vi/exercises.json +55 -0
  327. package/studio/src/lib/i18n/vi/externalEvidence.json +76 -0
  328. package/studio/src/lib/i18n/vi/home.json +18 -0
  329. package/studio/src/lib/i18n/vi/lesson.json +33 -0
  330. package/studio/src/lib/i18n/vi/nav.json +8 -0
  331. package/studio/src/lib/i18n/vi/newCourse.json +51 -0
  332. package/studio/src/lib/i18n/vi/onboarding.json +35 -0
  333. package/studio/src/lib/i18n/vi/playwrightTemplate.json +20 -0
  334. package/studio/src/lib/i18n/vi/practice.json +79 -0
  335. package/studio/src/lib/i18n/vi/provider.json +27 -0
  336. package/studio/src/lib/i18n/vi/providerMeta.json +26 -0
  337. package/studio/src/lib/i18n/vi/reflection.json +17 -0
  338. package/studio/src/lib/i18n/vi/revision.json +52 -0
  339. package/studio/src/lib/i18n/vi/runnerNotice.json +14 -0
  340. package/studio/src/lib/i18n/vi/settings.json +12 -0
  341. package/studio/src/lib/i18n/vi/storage.json +49 -0
  342. package/studio/src/lib/i18n/vi/tutor.json +39 -0
  343. package/studio/src/lib/i18n/vi/workspace.json +50 -0
  344. package/studio/src/lib/ids.js +10 -0
  345. package/studio/src/lib/json.js +26 -0
  346. package/studio/src/lib/markdown.js +74 -0
  347. package/studio/src/lib/prompts/base.js +139 -0
  348. package/studio/src/lib/prompts/capstone.js +777 -0
  349. package/studio/src/lib/prompts/course.js +150 -0
  350. package/studio/src/lib/prompts/lesson.js +275 -0
  351. package/studio/src/lib/prompts/practice.js +511 -0
  352. package/studio/src/lib/prompts/tutor.js +509 -0
  353. package/studio/src/lib/repo/blocked-adapter.js +69 -0
  354. package/studio/src/lib/repo/events.js +239 -0
  355. package/studio/src/lib/repo/idb-adapter.js +226 -0
  356. package/studio/src/lib/repo/index.js +1315 -0
  357. package/studio/src/lib/repo/memory-adapter.js +115 -0
  358. package/studio/src/lib/repo/remote-adapter.js +158 -0
  359. package/studio/src/lib/repo/schema.js +143 -0
  360. package/studio/src/lib/repo/select-adapter.js +345 -0
  361. package/studio/src/lib/router.js +71 -0
  362. package/studio/src/lib/runner/browser.js +244 -0
  363. package/studio/src/lib/runner/checks.js +248 -0
  364. package/studio/src/lib/runner/current-code.js +98 -0
  365. package/studio/src/lib/runner/esm-cjs.js +109 -0
  366. package/studio/src/lib/runner/hash.js +34 -0
  367. package/studio/src/lib/runner/history.js +48 -0
  368. package/studio/src/lib/runner/index.js +168 -0
  369. package/studio/src/lib/runner/languages.js +258 -0
  370. package/studio/src/lib/runner/local.js +139 -0
  371. package/studio/src/lib/runner/path.js +104 -0
  372. package/studio/src/lib/runner/skeleton.js +315 -0
  373. package/studio/src/lib/runner/strip-types.js +134 -0
  374. package/studio/src/lib/settings.js +399 -0
  375. package/studio/src/lib/srs.js +39 -0
  376. package/templates/agent/settings.json +6 -0
  377. package/templates/claude/plugin.json +139 -0
  378. package/templates/claude/settings.json +15 -0
  379. package/templates/cursor/professor.mdc +4 -0
  380. package/templates/cursor/settings.json +18 -0
  381. package/templates/gemini/GEMINI.md +28 -0
  382. package/templates/gemini/settings.json +5 -0
  383. package/templates/opencode/opencode.json +3 -0
  384. package/templates/researcher/README.md +61 -0
  385. package/templates/researcher/settings.json +18 -0
  386. package/web/client/components.json +15 -0
  387. package/web/client/index.html +12 -0
  388. package/web/client/package-lock.json +8732 -0
  389. package/web/client/package.json +39 -0
  390. package/web/client/postcss.config.js +6 -0
  391. package/web/client/src/App.jsx +140 -0
  392. package/web/client/src/api/client.js +357 -0
  393. package/web/client/src/components/ChatPanel.jsx +417 -0
  394. package/web/client/src/components/CommandPills.jsx +50 -0
  395. package/web/client/src/components/DeprecationBanner.jsx +21 -0
  396. package/web/client/src/components/ExerciseEditor.jsx +164 -0
  397. package/web/client/src/components/Header.jsx +119 -0
  398. package/web/client/src/components/LecturePanel.jsx +342 -0
  399. package/web/client/src/components/MobileTabSwitcher.jsx +51 -0
  400. package/web/client/src/components/SplitPane.jsx +42 -0
  401. package/web/client/src/components/ui/alert.jsx +38 -0
  402. package/web/client/src/components/ui/badge.jsx +24 -0
  403. package/web/client/src/components/ui/button.jsx +23 -0
  404. package/web/client/src/components/ui/select.jsx +74 -0
  405. package/web/client/src/hooks/useSSE.js +152 -0
  406. package/web/client/src/hooks/useWebSocket.js +98 -0
  407. package/web/client/src/index.css +23 -0
  408. package/web/client/src/lib/utils.js +6 -0
  409. package/web/client/src/main.jsx +12 -0
  410. package/web/client/src/utils/markdown.js +50 -0
  411. package/web/client/tailwind.config.js +8 -0
  412. package/web/client/vite.config.js +21 -0
  413. package/web/dist/assets/index-C1W0eXIQ.js +294 -0
  414. package/web/dist/assets/index-C3OUx70T.css +1 -0
  415. package/web/dist/index.html +13 -0
  416. package/web/lecture-archive.js +172 -0
  417. package/web/legacy-server.js +1277 -0
  418. package/web/package-lock.json +855 -0
  419. package/web/package.json +10 -0
  420. package/web/security.js +1016 -0
  421. package/web/server.js +390 -0
  422. package/web/studio-api/agents.js +580 -0
  423. package/web/studio-api/bridge.js +199 -0
  424. package/web/studio-api/db.js +66 -0
  425. package/web/studio-api/guards.js +201 -0
  426. package/web/studio-api/health.js +538 -0
  427. package/web/studio-api.js +214 -0
  428. package/web/studio-db.js +380 -0
  429. package/web/studio-runner.js +568 -0
@@ -0,0 +1,315 @@
1
+ /**
2
+ * Derive the initial workspace files from a lesson's Markdown (CODE-01).
3
+ *
4
+ * A programming lesson ships its exercise skeleton as a fenced code block under the
5
+ * "Exercise" section (Phase 23/28 convention). We pick the fence with `TODO` markers; otherwise the
6
+ * first block whose info string matches the course language; if there is none we fall back to an
7
+ * empty `main.<ext>`. Concept-section code samples are only used when there is no Exercise section
8
+ * at all — the learner should land on the thing they are asked to do.
9
+ */
10
+ import { defaultEntry, guessCourseLanguage, languageForPath, normalizeLanguage } from './languages.js';
11
+ import { isExerciseHeading } from '../prompts/lesson.js';
12
+
13
+ /**
14
+ * @typedef {{ path: string, content: string, language: string|null }} SeedFile
15
+ */
16
+
17
+ /**
18
+ * Extract all fenced code blocks from Markdown.
19
+ * @param {string} markdown
20
+ * @returns {Array<{ info: string, code: string, start: number, end: number }>}
21
+ */
22
+ export function extractFencedBlocks(markdown) {
23
+ const text = String(markdown ?? '');
24
+ const blocks = [];
25
+ const fence = /^([ \t]*)(`{3,}|~{3,})[ \t]*([^\n]*)\n([\s\S]*?)\n[ \t]*\2[ \t]*$/gm;
26
+ let m;
27
+ while ((m = fence.exec(text))) {
28
+ blocks.push({
29
+ info: (m[3] || '').trim().split(/\s+/)[0],
30
+ code: m[4],
31
+ start: m.index,
32
+ end: m.index + m[0].length,
33
+ });
34
+ }
35
+ return blocks;
36
+ }
37
+
38
+ /**
39
+ * Locate the first heading whose text starts with "exercise", returning its body and the absolute
40
+ * range of the section (heading → next heading of the same or higher level).
41
+ *
42
+ * Heading-looking lines inside a fenced code block are not headings: a `# comment` at column 0 is
43
+ * ordinary code in Bash, Python, Ruby and friends, and treating it as one used to cut the exercise
44
+ * section short inside its own fence (RON-197). Fence ranges come from `extractFencedBlocks`, so
45
+ * there is exactly one fence parser in this module.
46
+ *
47
+ * @param {string} markdown
48
+ * @returns {{ body: string, start: number, end: number } | null}
49
+ */
50
+ export function findExerciseSection(markdown) {
51
+ const text = String(markdown ?? '');
52
+ const fenced = extractFencedBlocks(text);
53
+ const inFence = (index) => fenced.some((block) => index >= block.start && index < block.end);
54
+ const heading = /^(#{1,6})[ \t]+(.+?)[ \t]*$/gm;
55
+ let match;
56
+ let level = 0;
57
+ let start = -1;
58
+ let bodyStart = -1;
59
+ while ((match = heading.exec(text))) {
60
+ if (inFence(match.index)) continue;
61
+ if (start >= 0) {
62
+ if (match[1].length <= level) {
63
+ return { body: text.slice(bodyStart, match.index), start, end: match.index };
64
+ }
65
+ continue;
66
+ }
67
+ if (isExerciseHeading(match[2])) {
68
+ start = match.index;
69
+ level = match[1].length;
70
+ bodyStart = match.index + match[0].length;
71
+ }
72
+ }
73
+ if (start < 0) return null;
74
+ return { body: text.slice(bodyStart), start, end: text.length };
75
+ }
76
+
77
+ /**
78
+ * @param {string|null|undefined} info fenced-code info string (e.g. `js`, `language-python`)
79
+ * @param {string|null} language the course language
80
+ */
81
+ function blockMatches(info, language) {
82
+ const normalised = normalizeLanguage(info);
83
+ if (!language) return Boolean(normalised);
84
+ return normalised === language;
85
+ }
86
+
87
+ const TODO_MARKER = /\bTODO\b/;
88
+
89
+ /**
90
+ * A TODO fence is the exercise skeleton; a reference file or a self-check block next to it is not.
91
+ * Unsupported-language fences still qualify: generated lessons sometimes ship the real skeleton in
92
+ * `dockerfile`/`yaml`, and a reference file in the course language must not shadow it.
93
+ * @param {{ code: string }} block
94
+ */
95
+ function isTodoSkeleton(block) {
96
+ return TODO_MARKER.test(block.code);
97
+ }
98
+
99
+ /**
100
+ * @param {Array<{ info: string, code: string }>} candidates
101
+ * @param {string|null} lang
102
+ */
103
+ function chooseSkeleton(candidates, lang) {
104
+ const todos = candidates.filter(isTodoSkeleton);
105
+ return (
106
+ todos.find((b) => blockMatches(b.info, lang)) ||
107
+ todos[0] ||
108
+ candidates.find((b) => blockMatches(b.info, lang)) ||
109
+ (!lang ? candidates[0] : null)
110
+ );
111
+ }
112
+
113
+ /**
114
+ * The fences the exercise section offers, falling back to the whole lesson.
115
+ * @param {string} markdown
116
+ * @param {Array<{ start: number, end: number }>} blocks
117
+ */
118
+ function exerciseCandidates(markdown, blocks) {
119
+ const section = findExerciseSection(markdown);
120
+ const pool = section
121
+ ? blocks.filter((b) => b.start >= section.start && b.end <= section.end)
122
+ : blocks;
123
+ return pool.length ? pool : blocks;
124
+ }
125
+
126
+ /**
127
+ * Pick the exercise skeleton from a lesson body.
128
+ * @param {string} markdown
129
+ * @param {{ language?: string|null, course?: object }} [opts]
130
+ * @returns {{ content: string, language: string|null, unsupported?: string } | null}
131
+ */
132
+ export function extractSkeleton(markdown, { language = null, course = null } = {}) {
133
+ const lang = normalizeLanguage(language) || guessCourseLanguage(course || {});
134
+ const blocks = extractFencedBlocks(markdown);
135
+ if (!blocks.length) return null;
136
+
137
+ const chosen = chooseSkeleton(exerciseCandidates(markdown, blocks), lang);
138
+ if (!chosen) return null;
139
+ const normalised = normalizeLanguage(chosen.info);
140
+ if (!normalised && chosen.info) return { content: chosen.code, language: null, unsupported: chosen.info };
141
+ return { content: chosen.code, language: normalised || lang || null };
142
+ }
143
+
144
+ /**
145
+ * Build the initial files for a lesson workspace, plus the skeleton the Workspace cannot run.
146
+ *
147
+ * An unsupported skeleton seeds nothing: an unrelated entry file full of another language's code is
148
+ * worse than an empty workspace. The caller shows the text read-only instead.
149
+ *
150
+ * @param {{ content_md?: string }|null} lesson
151
+ * @param {object|null} course
152
+ * @param {{ language?: string|null }} [opts]
153
+ * @returns {{ files: SeedFile[], unsupportedSkeleton: { info: string, content: string }|null }}
154
+ */
155
+ export function planSeed(lesson, course = null, { language = null } = {}) {
156
+ const lang = normalizeLanguage(language) || guessCourseLanguage(course || {});
157
+ const skeleton = lesson?.content_md ? extractSkeleton(lesson.content_md, { language: lang, course }) : null;
158
+ if (skeleton?.unsupported) {
159
+ return {
160
+ files: [],
161
+ unsupportedSkeleton: { info: skeleton.unsupported, content: skeleton.content },
162
+ };
163
+ }
164
+ if (skeleton) {
165
+ const resolved = skeleton.language || lang || 'javascript';
166
+ return {
167
+ files: [{ path: defaultEntry(resolved), content: skeleton.content, language: resolved }],
168
+ unsupportedSkeleton: null,
169
+ };
170
+ }
171
+ const fallback = lang || 'javascript';
172
+ return {
173
+ files: [{ path: defaultEntry(fallback), content: '', language: fallback }],
174
+ unsupportedSkeleton: null,
175
+ };
176
+ }
177
+
178
+ /**
179
+ * The files only. Kept for callers that do not need to report an unsupported skeleton.
180
+ * @param {{ content_md?: string }|null} lesson
181
+ * @param {object|null} course
182
+ * @param {{ language?: string|null }} [opts]
183
+ * @returns {SeedFile[]}
184
+ */
185
+ export function seedFiles(lesson, course = null, opts = {}) {
186
+ return planSeed(lesson, course, opts).files;
187
+ }
188
+
189
+ /**
190
+ * What a reset writes and which stored files it must soft-delete.
191
+ *
192
+ * When the exercise cannot be seeded at all, a reset drops every stored file: otherwise the row an
193
+ * earlier build wrote (the reference fence in `main.js`) comes straight back on the next load.
194
+ *
195
+ * @param {{ lesson?: object|null, course?: object|null, storedPaths?: string[] }} [input]
196
+ * @returns {{
197
+ * files: SeedFile[],
198
+ * persist: boolean,
199
+ * unsupportedSkeleton: { info: string, content: string }|null,
200
+ * deletePaths: string[],
201
+ * }}
202
+ */
203
+ export function planReset({ lesson = null, course = null, storedPaths = [] } = {}) {
204
+ const { files, unsupportedSkeleton } = planSeed(lesson, course);
205
+ const persist = !unsupportedSkeleton && files.some((f) => !isBlank(f.content));
206
+ return {
207
+ files,
208
+ persist,
209
+ unsupportedSkeleton,
210
+ deletePaths: unsupportedSkeleton ? [...new Set(storedPaths)] : [],
211
+ };
212
+ }
213
+
214
+ /**
215
+ * True when every stored file is a verbatim copy of a lesson fence that is not the exercise skeleton
216
+ * — the reference or self-check block an earlier build seeded. Any difference is a learner edit and
217
+ * keeps the file untouched.
218
+ * @param {SeedFile[]} stored
219
+ * @param {string} markdown
220
+ * @param {string|null} language
221
+ */
222
+ function isStaleReferenceSeed(stored, markdown, language) {
223
+ if (!stored.length) return false;
224
+ const blocks = extractFencedBlocks(markdown);
225
+ if (!blocks.length) return false;
226
+ const chosen = chooseSkeleton(exerciseCandidates(markdown, blocks), language);
227
+ const references = new Set(
228
+ blocks
229
+ .filter((b) => b !== chosen)
230
+ .map((b) => b.code.trim())
231
+ .filter(Boolean)
232
+ );
233
+ if (!references.size) return false;
234
+ return stored.every((f) => references.has(String(f.content ?? '').trim()));
235
+ }
236
+
237
+ /**
238
+ * Normalise stored repo rows into `{ path, content, language }`. Soft-deleted rows never reach
239
+ * here — the adapter filters them out (see `repo.deleteWorkspaceFile`).
240
+ * @param {Array<object>} rows
241
+ * @returns {SeedFile[]}
242
+ */
243
+ export function filesFromRows(rows) {
244
+ return (rows || [])
245
+ .map((r) => ({
246
+ path: r.path,
247
+ content: r.content ?? '',
248
+ language: normalizeLanguage(r.language) || languageForPath(r.path),
249
+ }))
250
+ .filter((f) => typeof f.path === 'string' && f.path);
251
+ }
252
+
253
+ /**
254
+ * @param {string|null|undefined} content
255
+ * @returns {boolean} true when the learner never put anything in the file
256
+ */
257
+ function isBlank(content) {
258
+ return !String(content ?? '').trim();
259
+ }
260
+
261
+ /**
262
+ * Decide what the Workspace opens with (RON-196).
263
+ *
264
+ * Lesson Markdown lives in `lesson_versions`, never on the `lessons` row the UI holds, so the seed
265
+ * comes from the current version; the row's own `content_md` is only a backwards-compatible
266
+ * fallback when there is no version. Stored workspace files still win over the skeleton — unless
267
+ * every one of them is blank and the lesson has no run result: that is an empty seed persisted by
268
+ * an earlier build, so the rows are overwritten with the skeleton instead of trapping the learner
269
+ * on an empty editor.
270
+ *
271
+ * A stored row that is a verbatim copy of a non-skeleton fence is the same kind of stale seed: an
272
+ * earlier build seeded the reference block it found first, so it is re-seeded too. A learner who
273
+ * changed even one character keeps their file.
274
+ *
275
+ * `persist` is false when the seed has no skeleton: keeping the empty file in memory only lets a
276
+ * later lesson version still seed it.
277
+ *
278
+ * `stalePaths` lists the stored rows the re-seed does not replace — an earlier build guessed the
279
+ * entry extension from the course (`main.js`), while the skeleton fence resolves to another one
280
+ * (`main.sh`), or it wrote the reference fence and the exercise cannot be seeded at all. The caller
281
+ * soft-deletes them, so the learner does not get a stray file next to the skeleton.
282
+ *
283
+ * `unsupportedSkeleton` is set when the exercise skeleton is in a language no runner executes: no
284
+ * file is seeded or persisted, and the caller shows the text read-only.
285
+ *
286
+ * @param {{
287
+ * lesson?: object|null,
288
+ * course?: object|null,
289
+ * version?: { content_md?: string }|null,
290
+ * rows?: Array<object>,
291
+ * runCount?: number,
292
+ * }} [input]
293
+ * @returns {{
294
+ * files: SeedFile[],
295
+ * persist: boolean,
296
+ * stalePaths: string[],
297
+ * unsupportedSkeleton: { info: string, content: string }|null,
298
+ * }}
299
+ */
300
+ export function resolveWorkspaceSeed({ lesson = null, course = null, version = null, rows = [], runCount = 0 } = {}) {
301
+ const stored = filesFromRows(rows);
302
+ const content_md = version?.content_md || lesson?.content_md || '';
303
+ const untouched = stored.length > 0 && stored.every((f) => isBlank(f.content)) && runCount === 0;
304
+ const staleSeed = !untouched && isStaleReferenceSeed(stored, content_md, guessCourseLanguage(course || {}));
305
+ if (stored.length && !untouched && !staleSeed) {
306
+ return { files: stored, persist: false, stalePaths: [], unsupportedSkeleton: null };
307
+ }
308
+
309
+ const { files, unsupportedSkeleton } = planSeed({ ...(lesson || {}), content_md }, course);
310
+ const persist = !unsupportedSkeleton && files.some((f) => !isBlank(f.content));
311
+ const kept = new Set(files.map((f) => f.path));
312
+ const stalePaths =
313
+ persist || staleSeed ? stored.filter((f) => !kept.has(f.path)).map((f) => f.path) : [];
314
+ return { files, persist, stalePaths, unsupportedSkeleton };
315
+ }
@@ -0,0 +1,134 @@
1
+ /**
2
+ * Tiny, dependency-free TypeScript → JavaScript type eraser (CODE-02).
3
+ *
4
+ * The brief allows either `esbuild-wasm` (lazy) or a "tiny transform". We deliberately avoid the
5
+ * ~10 MB esbuild wasm: only type *syntax* needs removing, not transpilation. This handles the
6
+ * constructs a teaching skeleton actually contains:
7
+ * - `interface X { … }`, `type X = …`, `import type …`, `declare …`
8
+ * - `as T` casts, `satisfies T`, non-null `!` on member access
9
+ * - parameter / variable / return type annotations, generics `foo<T>(…)`, optional `?:`
10
+ *
11
+ * It is intentionally conservative: primitives and Capitalized type names only, so object
12
+ * literals (`{ key: value }`) are left untouched. Advanced TS (enums, decorators, namespaces)
13
+ * is out of scope — the worker surfaces a clear SyntaxError telling the learner to use `.js`.
14
+ * Pure module → unit-tested against both TS samples and plain JS (must stay unchanged).
15
+ */
16
+
17
+ const PRIMITIVE = "(?:string|number|boolean|any|unknown|void|never|object|symbol|bigint|undefined|null)";
18
+ // A Capitalized name only counts as a type when it is clearly one: `Foo<T>` or `Foo[]`. Object
19
+ // literals (`key: 'value'`, `nested: { n: 1 }`, `Type: Number`) therefore survive untouched.
20
+ const NAMED_TYPE = "[A-Z][\\w$]*(?:<[^<>()]*>|\\[\\])";
21
+ const TYPE_ATOM = `(?:${PRIMITIVE}|${NAMED_TYPE})`;
22
+ const TYPE_EXPR = `${TYPE_ATOM}(?:\\s*\\|\\s*${TYPE_ATOM})*`;
23
+ // identifier? (":" | "?:") Type
24
+ const ANNOTATION = new RegExp(`([A-Za-z_$][\\w$]*)\\s*\\??\\s*:\\s*(${TYPE_EXPR})`, 'g');
25
+ const RETURN_TYPE = new RegExp(`(\\))\\s*:\\s*${TYPE_EXPR}(?=\\s*(?:=>|\\{))`, 'g');
26
+
27
+ /**
28
+ * @param {string} source
29
+ * @returns {string} the source with type annotations removed
30
+ */
31
+ export function stripTypes(source) {
32
+ let code = String(source ?? '');
33
+ code = removeLineStatement(code, /^\s*import\s+type\s[^\n]*$/gm);
34
+ code = removeLineStatement(code, /^\s*export\s+type\s+\{[^}]*\}\s*[^\n]*$/gm);
35
+ code = removeLineStatement(code, /^\s*declare\s+[^\n]*$/gm);
36
+ code = removeBalancedBlocks(code, /\b(?:export\s+)?interface\s+[A-Za-z_$][\w$]*(?:\s+extends\s+[^{]+)?\s*\{/g);
37
+ code = removeTypeAliases(code);
38
+ code = code.replace(/\b(?:as|satisfies)\s+const\b/g, '');
39
+ code = code.replace(/\s(?:as|satisfies)\s+[A-Za-z_$][\w$.]*(?:<[^<>()]*>)?(?:\s*\|\s*[A-Za-z_$][\w$.]*)*(\[\])?/g, '');
40
+ code = code.replace(RETURN_TYPE, '$1');
41
+ code = code.replace(/([A-Za-z_$][\w$]*)\s*<[A-Za-z_$][\w$,\s[\]|]*>\s*(?=\()/g, '$1');
42
+ code = code.replace(ANNOTATION, '$1');
43
+ code = code.replace(/([)\]A-Za-z_$"])(?:!)(?=\s*[.[(;])/g, '$1');
44
+ return code;
45
+ }
46
+
47
+ /**
48
+ * @param {string} code
49
+ * @param {RegExp} pattern line-matching pattern (with `m`)
50
+ */
51
+ function removeLineStatement(code, pattern) {
52
+ return code.replace(pattern, '');
53
+ }
54
+
55
+ /**
56
+ * Remove blocks opened by `pattern` (which ends at the opening `{`) up to the matching `}`.
57
+ * @param {string} code
58
+ * @param {RegExp} pattern global regex whose match ends with `{`
59
+ */
60
+ function removeBalancedBlocks(code, pattern) {
61
+ let result = code;
62
+ let match;
63
+ pattern.lastIndex = 0;
64
+ while ((match = pattern.exec(result))) {
65
+ const open = match.index + match[0].length - 1;
66
+ const close = matchBrace(result, open);
67
+ if (close < 0) break;
68
+ result = result.slice(0, match.index) + result.slice(close + 1);
69
+ pattern.lastIndex = 0;
70
+ }
71
+ return result;
72
+ }
73
+
74
+ /**
75
+ * Remove `type X = …;` alias declarations (balanced to the terminating `;`).
76
+ * @param {string} code
77
+ */
78
+ function removeTypeAliases(code) {
79
+ let result = code;
80
+ let searchFrom = 0;
81
+ const re = /\btype\s+[A-Za-z_$][\w$]*(?:<[^<>]*>)?\s*=/g;
82
+ for (;;) {
83
+ re.lastIndex = searchFrom;
84
+ const m = re.exec(result);
85
+ if (!m) break;
86
+ const start = m.index;
87
+ let i = re.lastIndex;
88
+ let depth = 0;
89
+ let inString = null;
90
+ for (; i < result.length; i++) {
91
+ const ch = result[i];
92
+ const prev = result[i - 1];
93
+ if (inString) {
94
+ if (ch === inString && prev !== '\\') inString = null;
95
+ continue;
96
+ }
97
+ if (ch === '"' || ch === "'" || ch === '`') inString = ch;
98
+ else if (ch === '(' || ch === '[' || ch === '{') depth += 1;
99
+ else if (ch === ')' || ch === ']' || ch === '}') depth -= 1;
100
+ else if (ch === ';' && depth === 0) break;
101
+ else if (ch === '\n' && depth === 0) break;
102
+ }
103
+ let end = i;
104
+ if (result[i] === ';') end = i + 1;
105
+ result = result.slice(0, start) + result.slice(end);
106
+ searchFrom = start;
107
+ }
108
+ return result;
109
+ }
110
+
111
+ /**
112
+ * Index of the `}` matching the `{` at `open`, or -1.
113
+ * @param {string} text
114
+ * @param {number} open
115
+ */
116
+ function matchBrace(text, open) {
117
+ let depth = 0;
118
+ let inString = null;
119
+ for (let i = open; i < text.length; i++) {
120
+ const ch = text[i];
121
+ const prev = text[i - 1];
122
+ if (inString) {
123
+ if (ch === inString && prev !== '\\') inString = null;
124
+ continue;
125
+ }
126
+ if (ch === '"' || ch === "'" || ch === '`') inString = ch;
127
+ else if (ch === '{') depth += 1;
128
+ else if (ch === '}') {
129
+ depth -= 1;
130
+ if (depth === 0) return i;
131
+ }
132
+ }
133
+ return -1;
134
+ }