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,248 @@
1
+ /**
2
+ * Self-check convention shared with the Phase 23/28 exercise skeletons (CODE-03).
3
+ *
4
+ * The exercise file ships *skeleton + self-checks only*, in the course language's own idiom:
5
+ * - Python `assert <expr>` inside `if __name__ == "__main__":`
6
+ * - JavaScript `console.assert(<expr>, "<msg>")` and/or the injected `check("<name>", () => …)`
7
+ * (a tiny helper we provide so checks can be named)
8
+ * - SQL the expected result rows in a comment directive (`-- @check <name>` + `-- @expect <json>`)
9
+ *
10
+ * "Check" runs the file and reports each self-check as pass/fail. This module owns the *pure*
11
+ * parts — parsing / source instrumentation / row comparison — so both the browser workers and
12
+ * the tests use exactly the same rules. It never invents or reveals a solution.
13
+ *
14
+ * Result shape used everywhere: `{ name, passed, message }`.
15
+ */
16
+
17
+ /**
18
+ * @typedef {{ name: string, passed: boolean, message?: string }} CheckResult
19
+ */
20
+
21
+ /**
22
+ * Flatten check results into a summary.
23
+ * @param {CheckResult[]} checks
24
+ */
25
+ export function summarize(checks) {
26
+ const list = Array.isArray(checks) ? checks : [];
27
+ const passed = list.filter((c) => c.passed).length;
28
+ return { passed, failed: list.length - passed, total: list.length };
29
+ }
30
+
31
+ const MAX_NAME = 80;
32
+
33
+ /** @param {string} text */
34
+ function clipName(text) {
35
+ const clean = String(text || '').replace(/\s+/g, ' ').trim();
36
+ return clean.length > MAX_NAME ? `${clean.slice(0, MAX_NAME - 1)}…` : clean;
37
+ }
38
+
39
+ /* ------------------------------------------------------------------ JavaScript */
40
+
41
+ /**
42
+ * Statically discover the checks the UI can show before a run.
43
+ * This is best-effort (used only for the "n checks" label); the worker records the real results.
44
+ * @param {string} source
45
+ * @returns {string[]}
46
+ */
47
+ export function listJsChecks(source) {
48
+ const names = [];
49
+ const text = String(source || '');
50
+
51
+ const checkCall = /(?:^|[^.\w])check\s*\(\s*(['"`])([^'"`]*)\1/g;
52
+ let m;
53
+ while ((m = checkCall.exec(text))) names.push(clipName(m[2]));
54
+
55
+ const assertCall = /console\.assert\s*\(/g;
56
+ let i = 0;
57
+ while ((m = assertCall.exec(text))) {
58
+ const message = readAssertMessage(text, m.index + m[0].length);
59
+ i += 1;
60
+ names.push(clipName(message || `console.assert #${i}`));
61
+ }
62
+ return names;
63
+ }
64
+
65
+ /**
66
+ * Read the second argument of a `console.assert(...)` starting right after the open paren.
67
+ * Balanced-paren aware; returns the string literal message if present.
68
+ * @param {string} text
69
+ * @param {number} start index just after `console.assert(`
70
+ * @returns {string|null}
71
+ */
72
+ function readAssertMessage(text, start) {
73
+ let depth = 1;
74
+ let i = start;
75
+ let inString = null;
76
+ let lastTopComma = -1;
77
+ for (; i < text.length; i++) {
78
+ const ch = text[i];
79
+ const prev = text[i - 1];
80
+ if (inString) {
81
+ if (ch === inString && prev !== '\\') inString = null;
82
+ continue;
83
+ }
84
+ if (ch === '"' || ch === "'" || ch === '`') {
85
+ inString = ch;
86
+ continue;
87
+ }
88
+ if (ch === '(' || ch === '[' || ch === '{') depth += 1;
89
+ else if (ch === ')' || ch === ']' || ch === '}') {
90
+ depth -= 1;
91
+ if (depth === 0) break;
92
+ } else if (ch === ',' && depth === 1) lastTopComma = i;
93
+ }
94
+ if (lastTopComma < 0) return null;
95
+ const arg = text.slice(lastTopComma + 1, i).trim();
96
+ const str = /^(['"`])(.*)\1$/s.exec(arg);
97
+ return str ? str[2] : arg;
98
+ }
99
+
100
+ /**
101
+ * JavaScript instrumentation is a no-op at the source level: the worker injects
102
+ * `console.assert` + `check(name, fn)` and records results at runtime (so one failed check
103
+ * never stops the others). Kept as a function so the worker and tests share one entry point.
104
+ * @param {string} source
105
+ * @returns {{ code: string, checks: string[] }}
106
+ */
107
+ export function instrumentJs(source) {
108
+ return { code: String(source ?? ''), checks: listJsChecks(source) };
109
+ }
110
+
111
+ /* ------------------------------------------------------------------ Python */
112
+
113
+ /**
114
+ * Rewrite single-line `assert <expr>[, <msg>]` statements into recorded `__check(...)` calls so
115
+ * every self-check runs and is reported individually (an `AssertionError` would otherwise abort
116
+ * the whole script). The expression is passed as a thunk, so it is evaluated exactly once.
117
+ *
118
+ * Limitation (documented): asserts spanning multiple source lines are not rewritten.
119
+ * @param {string} source
120
+ * @returns {{ code: string, checks: string[] }}
121
+ */
122
+ export function instrumentPython(source) {
123
+ const lines = String(source ?? '').split('\n');
124
+ const names = [];
125
+ const out = lines.map((line) => {
126
+ const m = /^(\s*)assert\s+(.+?)\s*$/.exec(line);
127
+ if (!m) return line;
128
+ const indent = m[1];
129
+ const body = m[2];
130
+ const { expr, message } = splitPythonAssert(body);
131
+ const name = clipName(message || expr);
132
+ names.push(name);
133
+ const msgLiteral = message ? JSON.stringify(message) : 'None';
134
+ const exprLiteral = JSON.stringify(expr);
135
+ return `${indent}__check(${JSON.stringify(name)}, lambda: (${expr}), ${msgLiteral}, ${exprLiteral})`;
136
+ });
137
+ return { code: out.join('\n'), checks: names };
138
+ }
139
+
140
+ /**
141
+ * Split a Python assert body into its expression and optional message.
142
+ * The message is everything after the *last* top-level comma (depth 0, outside strings).
143
+ * @param {string} body
144
+ * @returns {{ expr: string, message: string|null }}
145
+ */
146
+ export function splitPythonAssert(body) {
147
+ const text = String(body);
148
+ let depth = 0;
149
+ let inString = null;
150
+ let lastComma = -1;
151
+ for (let i = 0; i < text.length; i++) {
152
+ const ch = text[i];
153
+ const prev = text[i - 1];
154
+ if (inString) {
155
+ if (ch === inString && prev !== '\\') inString = null;
156
+ continue;
157
+ }
158
+ if (ch === '"' || ch === "'") {
159
+ inString = ch;
160
+ continue;
161
+ }
162
+ if (ch === '(' || ch === '[' || ch === '{') depth += 1;
163
+ else if (ch === ')' || ch === ']' || ch === '}') depth -= 1;
164
+ else if (ch === ',' && depth === 0) lastComma = i;
165
+ }
166
+ if (lastComma < 0) return { expr: text.trim(), message: null };
167
+ return {
168
+ expr: text.slice(0, lastComma).trim(),
169
+ message: text.slice(lastComma + 1).trim().replace(/^(['"])(.*)\1$/s, '$2'),
170
+ };
171
+ }
172
+
173
+ /* ------------------------------------------------------------------ SQL */
174
+
175
+ /**
176
+ * Parse `-- @check <name>` / `-- @expect <json-rows>` directives from a SQL exercise file.
177
+ *
178
+ * Convention (kept dead simple and documented so the skeleton generator can emit it):
179
+ * -- @check returns top scorer
180
+ * -- @expect [{"name": "Ada", "score": 9}]
181
+ *
182
+ * Each `@expect` becomes one check comparing the *last* result set to the expected rows.
183
+ * With no directives, Check simply runs the query and shows the table.
184
+ *
185
+ * @param {string} source
186
+ * @returns {Array<{ name: string, expected: any }>}
187
+ */
188
+ export function parseSqlChecks(source) {
189
+ const lines = String(source ?? '').split('\n');
190
+ const out = [];
191
+ let pendingName = null;
192
+ for (const raw of lines) {
193
+ const line = raw.trim();
194
+ const check = /^--\s*@check\s+(.+)$/i.exec(line);
195
+ if (check) {
196
+ pendingName = clipName(check[1]);
197
+ continue;
198
+ }
199
+ const expect = /^--\s*@expect\s+(.+)$/i.exec(line);
200
+ if (expect) {
201
+ const json = expect[1].trim();
202
+ let parsed = null;
203
+ try {
204
+ parsed = JSON.parse(json);
205
+ } catch {
206
+ parsed = json;
207
+ }
208
+ out.push({ name: pendingName || `@expect #${out.length + 1}`, expected: parsed });
209
+ pendingName = null;
210
+ }
211
+ }
212
+ return out;
213
+ }
214
+
215
+ /**
216
+ * Compare a SQL result set (array of row objects) to an expected array of row objects.
217
+ * Order-insensitive; values compared loosely (numbers vs numeric strings match) because
218
+ * sql.js and drivers differ on typing.
219
+ * @param {any} actual
220
+ * @param {any} expected
221
+ * @returns {boolean}
222
+ */
223
+ export function compareSqlRows(actual, expected) {
224
+ if (!Array.isArray(expected)) return false;
225
+ if (!Array.isArray(actual)) return false;
226
+ if (actual.length !== expected.length) return false;
227
+ const norm = (rows) =>
228
+ rows
229
+ .map((row) =>
230
+ JSON.stringify(
231
+ Object.keys(row || {})
232
+ .sort()
233
+ .map((k) => [k, loose(row[k])])
234
+ )
235
+ )
236
+ .sort();
237
+ return JSON.stringify(norm(actual)) === JSON.stringify(norm(expected));
238
+ }
239
+
240
+ /** @param {any} value */
241
+ function loose(value) {
242
+ if (value === null || value === undefined) return null;
243
+ if (typeof value === 'number') return String(value);
244
+ if (typeof value === 'string' && value.trim() !== '' && !Number.isNaN(Number(value))) {
245
+ return String(Number(value));
246
+ }
247
+ return String(value);
248
+ }
@@ -0,0 +1,98 @@
1
+ /**
2
+ * Live code registry (CODE-05) — the bridge between the Workspace tab and the tutor's
3
+ * "Check my answer" (Phase 25).
4
+ *
5
+ * The workspace pushes the *current* editor contents here on every change; the tutor reads them
6
+ * with `getCurrentCode(lessonId)`. If the workspace was never opened this session, we fall back to
7
+ * the last files saved in the repository so a reopened lesson still has code to attach.
8
+ *
9
+ * Deliberately framework-free and side-effect-light so both the component and a future tutor
10
+ * prompt builder import one function.
11
+ */
12
+ import { listWorkspaceFiles } from '../repo/index.js';
13
+ import { filesFromRows } from './skeleton.js';
14
+ import { normalizeLanguage } from './languages.js';
15
+ import { hashFiles } from './hash.js';
16
+
17
+ /**
18
+ * @typedef {{ language: string, entry: string, files: Record<string,string>, hash: string, updatedAt: string }} CodeSnapshot
19
+ */
20
+
21
+ /** @type {Map<string, CodeSnapshot>} */
22
+ const cache = new Map();
23
+
24
+ /**
25
+ * Record the editor's current contents for a lesson.
26
+ * @param {string} lessonId
27
+ * @param {{ language?: string|null, entry?: string|null, files?: Record<string,string>|Array<{path:string,content:string}> }} input
28
+ * @returns {CodeSnapshot}
29
+ */
30
+ export function setCurrentCode(lessonId, { language = null, entry = null, files = {} } = {}) {
31
+ const map = Array.isArray(files)
32
+ ? Object.fromEntries(files.map((f) => [f.path, String(f.content ?? '')]))
33
+ : Object.fromEntries(Object.entries(files || {}).map(([k, v]) => [k, String(v ?? '')]));
34
+ const entryPath = entry || Object.keys(map)[0] || null;
35
+ const snapshot = {
36
+ language: normalizeLanguage(language) || null,
37
+ entry: entryPath,
38
+ files: map,
39
+ hash: hashFiles(map),
40
+ updatedAt: new Date().toISOString(),
41
+ };
42
+ cache.set(lessonId, snapshot);
43
+ return snapshot;
44
+ }
45
+
46
+ /** @param {string} lessonId */
47
+ export function clearCurrentCode(lessonId) {
48
+ cache.delete(lessonId);
49
+ }
50
+
51
+ /**
52
+ * The code to attach to a tutor request. Reads the live buffer, falling back to the repository.
53
+ * @param {string} lessonId
54
+ * @returns {Promise<CodeSnapshot|null>}
55
+ */
56
+ export async function getCurrentCode(lessonId) {
57
+ if (!lessonId) return null;
58
+ const live = cache.get(lessonId);
59
+ if (live) return live;
60
+ let rows = [];
61
+ try {
62
+ rows = await listWorkspaceFiles(lessonId);
63
+ } catch {
64
+ return null;
65
+ }
66
+ const files = filesFromRows(rows);
67
+ if (!files.length) return null;
68
+ const map = Object.fromEntries(files.map((f) => [f.path, f.content]));
69
+ const snapshot = {
70
+ language: files[0].language || null,
71
+ entry: files[0].path || null,
72
+ files: map,
73
+ hash: hashFiles(map),
74
+ updatedAt: new Date().toISOString(),
75
+ };
76
+ cache.set(lessonId, snapshot);
77
+ return snapshot;
78
+ }
79
+
80
+ /**
81
+ * A compact text block a tutor prompt can embed (never a solution — just the learner's code).
82
+ * @param {string} lessonId
83
+ * @param {{ maxBytes?: number }} [opts]
84
+ * @returns {Promise<string|null>}
85
+ */
86
+ export async function currentCodeBlock(lessonId, { maxBytes = 20_000 } = {}) {
87
+ const snapshot = await getCurrentCode(lessonId);
88
+ if (!snapshot) return null;
89
+ let out = '';
90
+ for (const [path, content] of Object.entries(snapshot.files)) {
91
+ out += `\n--- ${path} ---\n${content}\n`;
92
+ if (out.length > maxBytes) {
93
+ out = out.slice(0, maxBytes) + '\n… (truncated)';
94
+ break;
95
+ }
96
+ }
97
+ return out.trim() || null;
98
+ }
@@ -0,0 +1,109 @@
1
+ /**
2
+ * Minimal ESM → CommonJS transform so multi-file JavaScript exercises can run in a Web Worker
3
+ * (CODE-01/02). The worker compiles every workspace file as a CommonJS module and supplies a
4
+ * tiny `require` that resolves sibling files; this module belongs to that loader.
5
+ *
6
+ * Scope: single-line `import` / `export` forms used in teaching skeletons. It is a *shim*, not a
7
+ * bundler — dynamic `import()`, `export * from`, and bare package specifiers are left for the
8
+ * worker to report clearly. Pure module → unit-tested.
9
+ */
10
+
11
+ /**
12
+ * @param {string} code
13
+ * @returns {string}
14
+ */
15
+ export function esmToCjs(code) {
16
+ const text = String(code ?? '');
17
+ const lines = text.split('\n');
18
+ const namedExports = new Set();
19
+ const out = [];
20
+ let touched = false;
21
+
22
+ for (const line of lines) {
23
+ let m;
24
+
25
+ // import x from 'p' | import { a, b as c } from 'p' | import * as ns from 'p' | import 'p'
26
+ if ((m = /^\s*import\s+([A-Za-z_$][\w$]*)\s+from\s+(['"])([^'"]+)\2\s*;?\s*$/.exec(line))) {
27
+ touched = true;
28
+ out.push(`const ${m[1]} = __interop(require(${JSON.stringify(m[3])}));`);
29
+ continue;
30
+ }
31
+ if ((m = /^\s*import\s+\*\s+as\s+([A-Za-z_$][\w$]*)\s+from\s+(['"])([^'"]+)\2\s*;?\s*$/.exec(line))) {
32
+ touched = true;
33
+ out.push(`const ${m[1]} = require(${JSON.stringify(m[3])});`);
34
+ continue;
35
+ }
36
+ if ((m = /^\s*import\s+\{([^}]*)\}\s+from\s+(['"])([^'"]+)\2\s*;?\s*$/.exec(line))) {
37
+ touched = true;
38
+ out.push(`const { ${specifiersToBinding(m[1])} } = require(${JSON.stringify(m[3])});`);
39
+ continue;
40
+ }
41
+ if ((m = /^\s*import\s+(['"])([^'"]+)\1\s*;?\s*$/.exec(line))) {
42
+ touched = true;
43
+ out.push(`require(${JSON.stringify(m[2])});`);
44
+ continue;
45
+ }
46
+
47
+ // export default <expr>
48
+ if ((m = /^\s*export\s+default\s+(.*)$/.exec(line))) {
49
+ touched = true;
50
+ out.push(`__module.exports.default = ${m[1]}; __module.exports.__esModule = true;`);
51
+ continue;
52
+ }
53
+
54
+ // export { a, b as c };
55
+ if ((m = /^\s*export\s+\{([^}]*)\}\s*;?\s*$/.exec(line))) {
56
+ touched = true;
57
+ for (const assignment of namedExportAssignments(m[1])) out.push(assignment);
58
+ continue;
59
+ }
60
+
61
+ // export const/let/var/function/class Name …
62
+ if ((m = /^(\s*)export\s+(const|let|var|function|class|async\s+function)\s+([A-Za-z_$][\w$]*)/.exec(line))) {
63
+ touched = true;
64
+ namedExports.add(m[3]);
65
+ out.push(line.replace(/^(\s*)export\s+/, '$1'));
66
+ continue;
67
+ }
68
+
69
+ out.push(line);
70
+ }
71
+
72
+ if (namedExports.size) {
73
+ const tail = [...namedExports].map((n) => `__module.exports.${n} = ${n};`).join(' ');
74
+ out.push(tail);
75
+ }
76
+ return touched ? out.join('\n') : text;
77
+ }
78
+
79
+ /**
80
+ * @param {string} specifiers `a, b as c`
81
+ */
82
+ function specifiersToBinding(specifiers) {
83
+ return String(specifiers)
84
+ .split(',')
85
+ .map((s) => s.trim())
86
+ .filter(Boolean)
87
+ .map((s) => {
88
+ const as = /^([A-Za-z_$][\w$]*)\s+as\s+([A-Za-z_$][\w$]*)$/.exec(s);
89
+ return as ? `${as[1]}: ${as[2]}` : s;
90
+ })
91
+ .join(', ');
92
+ }
93
+
94
+ /**
95
+ * @param {string} specifiers `a, b as c`
96
+ * @returns {string[]}
97
+ */
98
+ function namedExportAssignments(specifiers) {
99
+ return String(specifiers)
100
+ .split(',')
101
+ .map((s) => s.trim())
102
+ .filter(Boolean)
103
+ .map((s) => {
104
+ const as = /^([A-Za-z_$][\w$]*)\s+as\s+([A-Za-z_$][\w$]*)$/.exec(s);
105
+ return as
106
+ ? `__module.exports.${as[2]} = ${as[1]};`
107
+ : `__module.exports.${s} = ${s};`;
108
+ });
109
+ }
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Stable, dependency-free hash for code snapshots (CODE-05).
3
+ *
4
+ * Run results store a snapshot hash so the history drawer can tell when the code changed without
5
+ * comparing full file bodies. FNV-1a over the ordered JSON of files is deterministic across
6
+ * sessions and platforms (no async crypto needed, works in workers).
7
+ */
8
+
9
+ /**
10
+ * FNV-1a 32-bit. Returns 8 hex chars.
11
+ * @param {string} input
12
+ * @returns {string}
13
+ */
14
+ export function fnv1a(input) {
15
+ let hash = 0x811c9dc5;
16
+ for (let i = 0; i < input.length; i++) {
17
+ hash ^= input.charCodeAt(i);
18
+ // 32-bit FNV prime multiply, kept in uint32 range.
19
+ hash = Math.imul(hash, 0x01000193) >>> 0;
20
+ }
21
+ return hash.toString(16).padStart(8, '0');
22
+ }
23
+
24
+ /**
25
+ * @param {Record<string,string>|Array<{path:string, content:string}>} files
26
+ * @returns {string} stable hash of path + content, order-independent by path
27
+ */
28
+ export function hashFiles(files) {
29
+ const rows = Array.isArray(files)
30
+ ? files.map((f) => [String(f.path), String(f.content ?? '')])
31
+ : Object.entries(files || {}).map(([path, content]) => [String(path), String(content ?? '')]);
32
+ rows.sort((a, b) => (a[0] < b[0] ? -1 : a[0] > b[0] ? 1 : 0));
33
+ return fnv1a(JSON.stringify(rows));
34
+ }
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Run-result (de)serialisation for the history drawer (CODE-05).
3
+ *
4
+ * The Phase 22 `run_results` table has columns for the result but none for the code snapshot, so
5
+ * we store a compact `{ checks, snapshot, hash }` object in its `checks_json` column. This module
6
+ * owns that encoding so the schema change (a dedicated column, Phase 26) is a one-file swap.
7
+ * Backwards compatible: a bare checks array (the original meaning) is still understood.
8
+ */
9
+ import { hashFiles } from './hash.js';
10
+
11
+ /**
12
+ * @param {{ checks?: any[], files?: Record<string,string>, entry?: string|null, language?: string|null }} input
13
+ * @returns {{ checks: any[], snapshot: { files: Record<string,string>, entry: string|null, language: string|null, hash: string } }}
14
+ */
15
+ export function encodeRunPayload({ checks = [], files = {}, entry = null, language = null } = {}) {
16
+ const snapshot = { files, entry, language, hash: hashFiles(files) };
17
+ return { checks: Array.isArray(checks) ? checks : [], snapshot };
18
+ }
19
+
20
+ /**
21
+ * @param {object} row a `run_results` repo row
22
+ * @returns {{ id:string, runner:string, language:string|null, stdout:string, stderr:string, exitCode:number|null, durationMs:number|null, createdAt:string, checks:any[], snapshot:object|null, hash:string|null }}
23
+ */
24
+ export function decodeRunResult(row = {}) {
25
+ let raw = null;
26
+ if (row.checks_json) {
27
+ try {
28
+ raw = JSON.parse(row.checks_json);
29
+ } catch {
30
+ raw = null;
31
+ }
32
+ }
33
+ const checks = Array.isArray(raw) ? raw : Array.isArray(raw?.checks) ? raw.checks : [];
34
+ const snapshot = !Array.isArray(raw) && raw?.snapshot ? raw.snapshot : null;
35
+ return {
36
+ id: row.id,
37
+ runner: row.runner || 'browser',
38
+ language: row.language || null,
39
+ stdout: row.stdout || '',
40
+ stderr: row.stderr || '',
41
+ exitCode: row.exit_code ?? null,
42
+ durationMs: row.duration_ms ?? null,
43
+ createdAt: row.created_at || '',
44
+ checks,
45
+ snapshot,
46
+ hash: snapshot?.hash || null,
47
+ };
48
+ }