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.
- package/CHANGELOG.md +26 -0
- package/LICENSE +21 -0
- package/README.md +225 -2
- package/bin/cli.js +811 -0
- package/bin/commands/check.js +298 -0
- package/bin/commands/create.js +169 -0
- package/bin/commands/doctor.js +392 -0
- package/bin/commands/import.js +557 -0
- package/bin/commands/next.js +125 -0
- package/bin/commands/review.js +207 -0
- package/bin/commands/status.js +114 -0
- package/bin/commands/studio.js +497 -0
- package/bin/commands/trail.js +211 -0
- package/bin/commands/web.js +350 -0
- package/bin/course-reader.js +611 -0
- package/bin/node-version.js +60 -0
- package/bin/platforms/_shared.js +211 -0
- package/bin/platforms/claude.js +104 -0
- package/bin/platforms/cursor.js +49 -0
- package/bin/platforms/gemini.js +65 -0
- package/bin/platforms/opencode.js +95 -0
- package/bin/registry-helpers.js +504 -0
- package/bin/static-server.js +153 -0
- package/bin/studio-store.js +94 -0
- package/bin/sync-shared.sh +5 -0
- package/package.json +91 -4
- package/plugin.json +139 -0
- package/shared/SKILL.md +568 -0
- package/shared/agents/coach.md +225 -0
- package/shared/agents/navigator.md +215 -0
- package/shared/agents/professor.md +372 -0
- package/shared/agents/researcher.md +181 -0
- package/shared/agents/spotter.md +129 -0
- package/shared/commands/professor/archive.md +103 -0
- package/shared/commands/professor/capstone-review.md +79 -0
- package/shared/commands/professor/capstone.md +34 -0
- package/shared/commands/professor/discuss.md +18 -0
- package/shared/commands/professor/done.md +44 -0
- package/shared/commands/professor/export.md +69 -0
- package/shared/commands/professor/hint.md +108 -0
- package/shared/commands/professor/navigator.md +67 -0
- package/shared/commands/professor/new-topic.md +73 -0
- package/shared/commands/professor/next.md +174 -0
- package/shared/commands/professor/note.md +63 -0
- package/shared/commands/professor/onboard.md +95 -0
- package/shared/commands/professor/progress.md +46 -0
- package/shared/commands/professor/publish.md +93 -0
- package/shared/commands/professor/quiz.md +27 -0
- package/shared/commands/professor/recall.md +74 -0
- package/shared/commands/professor/review.md +43 -0
- package/shared/commands/professor/schedule.md +75 -0
- package/shared/commands/professor/skill-export.md +87 -0
- package/shared/commands/professor/spotter.md +76 -0
- package/shared/commands/professor/stuck.md +27 -0
- package/shared/commands/professor/switch.md +50 -0
- package/shared/commands/professor/syllabus.md +9 -0
- package/shared/commands/professor/template-export.md +91 -0
- package/shared/commands/professor/template-import.md +111 -0
- package/shared/commands/professor/worktrees.md +58 -0
- package/shared/hooks/pre-compact.js +232 -0
- package/studio/README.md +313 -0
- package/studio/dist/assets/BetaReportPanel-8NrDLiPm.js +1 -0
- package/studio/dist/assets/Capstone-Cv9kH6LY.js +6 -0
- package/studio/dist/assets/CodeWorkspace-BwCEINWo.js +2 -0
- package/studio/dist/assets/Course-BJ_hafUP.js +1 -0
- package/studio/dist/assets/Editor-CV0mNhlz.js +53 -0
- package/studio/dist/assets/Home-C1ry89ak.js +1 -0
- package/studio/dist/assets/KaTeX_AMS-Regular-BQhdFMY1.woff2 +0 -0
- package/studio/dist/assets/KaTeX_AMS-Regular-DMm9YOAa.woff +0 -0
- package/studio/dist/assets/KaTeX_AMS-Regular-DRggAlZN.ttf +0 -0
- package/studio/dist/assets/KaTeX_Caligraphic-Bold-ATXxdsX0.ttf +0 -0
- package/studio/dist/assets/KaTeX_Caligraphic-Bold-BEiXGLvX.woff +0 -0
- package/studio/dist/assets/KaTeX_Caligraphic-Bold-Dq_IR9rO.woff2 +0 -0
- package/studio/dist/assets/KaTeX_Caligraphic-Regular-CTRA-rTL.woff +0 -0
- package/studio/dist/assets/KaTeX_Caligraphic-Regular-Di6jR-x-.woff2 +0 -0
- package/studio/dist/assets/KaTeX_Caligraphic-Regular-wX97UBjC.ttf +0 -0
- package/studio/dist/assets/KaTeX_Fraktur-Bold-BdnERNNW.ttf +0 -0
- package/studio/dist/assets/KaTeX_Fraktur-Bold-BsDP51OF.woff +0 -0
- package/studio/dist/assets/KaTeX_Fraktur-Bold-CL6g_b3V.woff2 +0 -0
- package/studio/dist/assets/KaTeX_Fraktur-Regular-CB_wures.ttf +0 -0
- package/studio/dist/assets/KaTeX_Fraktur-Regular-CTYiF6lA.woff2 +0 -0
- package/studio/dist/assets/KaTeX_Fraktur-Regular-Dxdc4cR9.woff +0 -0
- package/studio/dist/assets/KaTeX_Main-Bold-Cx986IdX.woff2 +0 -0
- package/studio/dist/assets/KaTeX_Main-Bold-Jm3AIy58.woff +0 -0
- package/studio/dist/assets/KaTeX_Main-Bold-waoOVXN0.ttf +0 -0
- package/studio/dist/assets/KaTeX_Main-BoldItalic-DxDJ3AOS.woff2 +0 -0
- package/studio/dist/assets/KaTeX_Main-BoldItalic-DzxPMmG6.ttf +0 -0
- package/studio/dist/assets/KaTeX_Main-BoldItalic-SpSLRI95.woff +0 -0
- package/studio/dist/assets/KaTeX_Main-Italic-3WenGoN9.ttf +0 -0
- package/studio/dist/assets/KaTeX_Main-Italic-BMLOBm91.woff +0 -0
- package/studio/dist/assets/KaTeX_Main-Italic-NWA7e6Wa.woff2 +0 -0
- package/studio/dist/assets/KaTeX_Main-Regular-B22Nviop.woff2 +0 -0
- package/studio/dist/assets/KaTeX_Main-Regular-Dr94JaBh.woff +0 -0
- package/studio/dist/assets/KaTeX_Main-Regular-ypZvNtVU.ttf +0 -0
- package/studio/dist/assets/KaTeX_Math-BoldItalic-B3XSjfu4.ttf +0 -0
- package/studio/dist/assets/KaTeX_Math-BoldItalic-CZnvNsCZ.woff2 +0 -0
- package/studio/dist/assets/KaTeX_Math-BoldItalic-iY-2wyZ7.woff +0 -0
- package/studio/dist/assets/KaTeX_Math-Italic-DA0__PXp.woff +0 -0
- package/studio/dist/assets/KaTeX_Math-Italic-flOr_0UB.ttf +0 -0
- package/studio/dist/assets/KaTeX_Math-Italic-t53AETM-.woff2 +0 -0
- package/studio/dist/assets/KaTeX_SansSerif-Bold-CFMepnvq.ttf +0 -0
- package/studio/dist/assets/KaTeX_SansSerif-Bold-D1sUS0GD.woff2 +0 -0
- package/studio/dist/assets/KaTeX_SansSerif-Bold-DbIhKOiC.woff +0 -0
- package/studio/dist/assets/KaTeX_SansSerif-Italic-C3H0VqGB.woff2 +0 -0
- package/studio/dist/assets/KaTeX_SansSerif-Italic-DN2j7dab.woff +0 -0
- package/studio/dist/assets/KaTeX_SansSerif-Italic-YYjJ1zSn.ttf +0 -0
- package/studio/dist/assets/KaTeX_SansSerif-Regular-BNo7hRIc.ttf +0 -0
- package/studio/dist/assets/KaTeX_SansSerif-Regular-CS6fqUqJ.woff +0 -0
- package/studio/dist/assets/KaTeX_SansSerif-Regular-DDBCnlJ7.woff2 +0 -0
- package/studio/dist/assets/KaTeX_Script-Regular-C5JkGWo-.ttf +0 -0
- package/studio/dist/assets/KaTeX_Script-Regular-D3wIWfF6.woff2 +0 -0
- package/studio/dist/assets/KaTeX_Script-Regular-D5yQViql.woff +0 -0
- package/studio/dist/assets/KaTeX_Size1-Regular-C195tn64.woff +0 -0
- package/studio/dist/assets/KaTeX_Size1-Regular-Dbsnue_I.ttf +0 -0
- package/studio/dist/assets/KaTeX_Size1-Regular-mCD8mA8B.woff2 +0 -0
- package/studio/dist/assets/KaTeX_Size2-Regular-B7gKUWhC.ttf +0 -0
- package/studio/dist/assets/KaTeX_Size2-Regular-Dy4dx90m.woff2 +0 -0
- package/studio/dist/assets/KaTeX_Size2-Regular-oD1tc_U0.woff +0 -0
- package/studio/dist/assets/KaTeX_Size3-Regular-CTq5MqoE.woff +0 -0
- package/studio/dist/assets/KaTeX_Size3-Regular-DgpXs0kz.ttf +0 -0
- package/studio/dist/assets/KaTeX_Size4-Regular-BF-4gkZK.woff +0 -0
- package/studio/dist/assets/KaTeX_Size4-Regular-DWFBv043.ttf +0 -0
- package/studio/dist/assets/KaTeX_Size4-Regular-Dl5lxZxV.woff2 +0 -0
- package/studio/dist/assets/KaTeX_Typewriter-Regular-C0xS9mPB.woff +0 -0
- package/studio/dist/assets/KaTeX_Typewriter-Regular-CO6r4hn1.woff2 +0 -0
- package/studio/dist/assets/KaTeX_Typewriter-Regular-D3Ib7_Hf.ttf +0 -0
- package/studio/dist/assets/Lesson-2e9TD9yL.js +2 -0
- package/studio/dist/assets/NewCourse-BZeOg2xn.js +952 -0
- package/studio/dist/assets/Progress-CRc_xEWC.js +1 -0
- package/studio/dist/assets/Review-6QEbHEfk.js +1 -0
- package/studio/dist/assets/Settings-NFnqVQui.js +1 -0
- package/studio/dist/assets/TutorPanel-DXQ6Z3BY.js +123 -0
- package/studio/dist/assets/abnfDiagram-WEYOIA3C-qeSjKlGM.js +1 -0
- package/studio/dist/assets/anthropic-D7NiQCUH.js +15 -0
- package/studio/dist/assets/arc-Y1ARJVZ4.js +1 -0
- package/studio/dist/assets/architecture-WOLXFQ4H-COG-m35l.js +1 -0
- package/studio/dist/assets/architectureDiagram-ZHVYKT53-VO7uKoeD.js +36 -0
- package/studio/dist/assets/array-BifhSqXX.js +1 -0
- package/studio/dist/assets/blockDiagram-RJAE7QA3-BGJF_qiL.js +140 -0
- package/studio/dist/assets/bridge-BTh0AeNX.js +1 -0
- package/studio/dist/assets/c4Diagram-XDPPPE54-C-S10RgU.js +38 -0
- package/studio/dist/assets/capstone-Amn6Hztq.js +135 -0
- package/studio/dist/assets/card-store-BrbrtX9w.js +1 -0
- package/studio/dist/assets/channel-SJiUQu_N.js +1 -0
- package/studio/dist/assets/chunk-2E7WHVMD-fv-iqTyC.js +88 -0
- package/studio/dist/assets/chunk-2Q5K7J3B-C1jixKkw.js +1 -0
- package/studio/dist/assets/chunk-4EMNKR2T-CY9IZrgv.js +1 -0
- package/studio/dist/assets/chunk-55XCU76K-DyTZz7v_.js +1 -0
- package/studio/dist/assets/chunk-5VM5RSS4-ZNzvKenW.js +15 -0
- package/studio/dist/assets/chunk-7S6XSTFO-BNMzTLRW.js +2 -0
- package/studio/dist/assets/chunk-AQDTSKZB-CEYANohH.js +72 -0
- package/studio/dist/assets/chunk-DSNLSHJZ-CDk5EXjH.js +129 -0
- package/studio/dist/assets/chunk-DUW6YSOI-Dgx8z5s3.js +1 -0
- package/studio/dist/assets/chunk-HAGFOTED-hNAi1zh_.js +62 -0
- package/studio/dist/assets/chunk-HNE4Q36P-COJnSYoZ.js +1 -0
- package/studio/dist/assets/chunk-J5ZVWO5B-oDCd-gWO.js +1 -0
- package/studio/dist/assets/chunk-JWPE2WC7-DVXcaiue.js +1 -0
- package/studio/dist/assets/chunk-NGNAAXSQ-C2Wy9Xmz.js +136 -0
- package/studio/dist/assets/chunk-NQOKRVIF-BU6KVxRr.js +213 -0
- package/studio/dist/assets/chunk-UHW7PFBP-DYvxL9JG.js +1 -0
- package/studio/dist/assets/chunk-VQ5W62QI-CuRfk65j.js +1 -0
- package/studio/dist/assets/chunk-WQQL4CDK-KaG7x-Mb.js +10 -0
- package/studio/dist/assets/chunk-XXDRQBXY-CnbRkih_.js +1 -0
- package/studio/dist/assets/chunk-Y2CYZVJY-DsF7k-Jl.js +1 -0
- package/studio/dist/assets/chunk-YZO67HFG-DbuqIZmk.js +1 -0
- package/studio/dist/assets/chunk-ZAUX2LTX-bk4ivUmc.js +1 -0
- package/studio/dist/assets/chunk-ZCHMQSOR-B_LElfwh.js +2 -0
- package/studio/dist/assets/classDiagram-v2-4MYWR3UA-DtCJ6H_X.js +217 -0
- package/studio/dist/assets/cose-bilkent-JH36ORCC-DMBAZFnj.js +1 -0
- package/studio/dist/assets/course-export-DpaOTT3a.js +1 -0
- package/studio/dist/assets/cynefin-EF2NZ3EQ-D9btHJvU.js +1 -0
- package/studio/dist/assets/cynefinDiagram-WF24UDRP-CsFJuv27.js +62 -0
- package/studio/dist/assets/cytoscape.esm-CHBj4VkZ.js +321 -0
- package/studio/dist/assets/dagre-NK4GIZVX-Cg1Duec7.js +4 -0
- package/studio/dist/assets/defaultLocale-BFoDCU3G.js +1 -0
- package/studio/dist/assets/diagram-CBK3MWTC-_KU2m5gd.js +24 -0
- package/studio/dist/assets/diagram-I5XIIV2D-5RaBrwUA.js +24 -0
- package/studio/dist/assets/diagram-ODIL2UCW-C0VKxoD3.js +30 -0
- package/studio/dist/assets/diagram-PFBEJUXE-BaHcZEP2.js +3 -0
- package/studio/dist/assets/diagram-RJA3I4VV-cwSAZ90p.js +41 -0
- package/studio/dist/assets/diagram-TYUNFSNR-BJImxCEN.js +200 -0
- package/studio/dist/assets/dist-CumnGVmJ.js +1 -0
- package/studio/dist/assets/ebnfDiagram-V4P3TTPT-OQQLRXcm.js +1 -0
- package/studio/dist/assets/elk-QONTBCTQ-BJGhQHxQ.js +27 -0
- package/studio/dist/assets/erDiagram-KYQIGQAA-D91EKSep.js +99 -0
- package/studio/dist/assets/error-BTdmRKoB.js +1 -0
- package/studio/dist/assets/errors-BZa_CNHL.js +1 -0
- package/studio/dist/assets/eventmodeling-K75KTNOO-DgdTRgnw.js +1 -0
- package/studio/dist/assets/fetch-local-DG3O3hmQ.js +4 -0
- package/studio/dist/assets/flowDiagram-IUGLLWBU-CVnJYMum.js +1 -0
- package/studio/dist/assets/ganttDiagram-R7GPNTJY-CSYLPWEI.js +292 -0
- package/studio/dist/assets/gitGraph-VSP46ZUC-D6GWaV9y.js +1 -0
- package/studio/dist/assets/gitGraphDiagram-PDYL7XHY-CaV31bvT.js +106 -0
- package/studio/dist/assets/graphlib-DS17s2tU.js +1 -0
- package/studio/dist/assets/index-CVenTTOY.css +2 -0
- package/studio/dist/assets/index-DioXTZVc.js +313 -0
- package/studio/dist/assets/info-OHQRW6UA-BN-x8GoN.js +1 -0
- package/studio/dist/assets/infoDiagram-MVDRKAX5-CIose_cy.js +2 -0
- package/studio/dist/assets/init-C-OQMol4.js +1 -0
- package/studio/dist/assets/ishikawaDiagram-HPEHV2GE-DCihSNBw.js +70 -0
- package/studio/dist/assets/journeyDiagram-BOSHW7O7-Bz3o3RIX.js +139 -0
- package/studio/dist/assets/js.worker-AD7DjksO.js +4 -0
- package/studio/dist/assets/kanban-definition-FNSA4HC5-BUyqvlFE.js +89 -0
- package/studio/dist/assets/katex-B_JcIwqj.js +257 -0
- package/studio/dist/assets/katex-BgsA2lO1.css +1 -0
- package/studio/dist/assets/line-B08T8KlK.js +1 -0
- package/studio/dist/assets/linear-C9iwaMOi.js +1 -0
- package/studio/dist/assets/mermaid-parser.core-BYwreSUy.js +7 -0
- package/studio/dist/assets/mermaid.core-DTO1oDmq.js +44 -0
- package/studio/dist/assets/mindmap-definition-6OY57UG3-BGLwKheY.js +98 -0
- package/studio/dist/assets/node.browser-BISniYn8.js +1 -0
- package/studio/dist/assets/node.browser-HQ5SKBOf.js +1 -0
- package/studio/dist/assets/ollama-De5w84tG.js +1 -0
- package/studio/dist/assets/openai-compatible-Joy1oK3L.js +1 -0
- package/studio/dist/assets/ordinal-BDEzSJ7C.js +1 -0
- package/studio/dist/assets/packet-JDAUHWVQ-CDIMjHS_.js +1 -0
- package/studio/dist/assets/path-fybaL0A-.js +1 -0
- package/studio/dist/assets/pegDiagram-ECIUJNBX-DWXm4mwS.js +1 -0
- package/studio/dist/assets/pie-XZMESJXO-CY3QQiKZ.js +1 -0
- package/studio/dist/assets/pieDiagram-GNMPY74T-M1aCnI7W.js +39 -0
- package/studio/dist/assets/python.worker-CzTrFdd9.js +24 -0
- package/studio/dist/assets/quadrantDiagram-D57K4MC3-BFFtO7U5.js +7 -0
- package/studio/dist/assets/radar-ABXABTNO-DT0W4_Xn.js +1 -0
- package/studio/dist/assets/railroad-I3PHUGI6-_VCpgZR5.js +1 -0
- package/studio/dist/assets/railroad-abnf-LNEFI6M7-DkSpQ5YY.js +1 -0
- package/studio/dist/assets/railroad-ebnf-DWYD2UWJ-BqWILdGb.js +1 -0
- package/studio/dist/assets/railroad-peg-JR7BVNR7-BB0bQL-Z.js +1 -0
- package/studio/dist/assets/railroadDiagram-Y72NRBL7-CjLKjIdJ.js +1 -0
- package/studio/dist/assets/react-B8SKf8RM.js +1 -0
- package/studio/dist/assets/rehype-katex-C-sKddsH.js +259 -0
- package/studio/dist/assets/remark-math-C-ox67hE.js +5 -0
- package/studio/dist/assets/requirementDiagram-EQYSW5RA-CnwzZqR8.js +84 -0
- package/studio/dist/assets/rolldown-runtime-COiEfhsA.js +1 -0
- package/studio/dist/assets/rough.esm-Dy-Kn_BL.js +1 -0
- package/studio/dist/assets/sankeyDiagram-SY24JHO5-CPDugTUl.js +40 -0
- package/studio/dist/assets/schemas-BOc2YsOP.js +55 -0
- package/studio/dist/assets/sequenceDiagram-BLEHNHQU-1dLfeU9Y.js +169 -0
- package/studio/dist/assets/settings-DhwuyNPU.js +1 -0
- package/studio/dist/assets/sizeCapture-INFHLROL-3uHXrFqA.js +1 -0
- package/studio/dist/assets/spec-nAnsSMkw.js +1 -0
- package/studio/dist/assets/sql-wasm-C1D_RJuy.wasm +0 -0
- package/studio/dist/assets/sql.worker-D7pBHOrq.js +4 -0
- package/studio/dist/assets/src-BWF7jMDv.js +1 -0
- package/studio/dist/assets/stateDiagram-v2-A6IESKWZ-DR7CmEjj.js +291 -0
- package/studio/dist/assets/swimlanes-B3ENRKFQ-BAWB9omQ.js +1 -0
- package/studio/dist/assets/swimlanesDiagram-AYQRV4AK-qeuHru16.js +8 -0
- package/studio/dist/assets/timeline-definition-JXYKGLGB-DNkj8z77.js +120 -0
- package/studio/dist/assets/treeView-D4JQ5SDB-BA-ouhMb.js +1 -0
- package/studio/dist/assets/treemap-SAJKECNS-BrrGxsAb.js +1 -0
- package/studio/dist/assets/useStream-rdsR6A7P.js +1 -0
- package/studio/dist/assets/usecaseDiagram-WPOLBNNX-BB3D0Dt_.js +328 -0
- package/studio/dist/assets/vennDiagram-Q3Y3IDCW-BrtqtKTE.js +34 -0
- package/studio/dist/assets/wardley-7MLQ67FV-BKkemDql.js +1 -0
- package/studio/dist/assets/wardleyDiagram-IVAIDKWA-DFnI3P5z.js +78 -0
- package/studio/dist/assets/xychartDiagram-4URNHDU4-Da0DZG_q.js +7 -0
- package/studio/dist/index.html +20 -0
- package/studio/dist/preview.html +22 -0
- package/studio/migrations/0001_init.sql +188 -0
- package/studio/migrations/0002_external_ids.sql +20 -0
- package/studio/migrations/0003_course_language.sql +12 -0
- package/studio/migrations/0004_capstone.sql +51 -0
- package/studio/migrations/0005_beta_loop.sql +73 -0
- package/studio/migrations/0006_interactive_exercises.sql +49 -0
- package/studio/src/lib/activity.js +92 -0
- package/studio/src/lib/ai/anthropic.js +109 -0
- package/studio/src/lib/ai/bridge.js +126 -0
- package/studio/src/lib/ai/catalog.js +160 -0
- package/studio/src/lib/ai/config.js +70 -0
- package/studio/src/lib/ai/errors.js +95 -0
- package/studio/src/lib/ai/fetch-local.js +104 -0
- package/studio/src/lib/ai/index.js +194 -0
- package/studio/src/lib/ai/ollama.js +136 -0
- package/studio/src/lib/ai/openai-compatible.js +101 -0
- package/studio/src/lib/ai/provider-utils.js +107 -0
- package/studio/src/lib/ai/sse.js +99 -0
- package/studio/src/lib/ai/status.js +92 -0
- package/studio/src/lib/ai/useStream.js +109 -0
- package/studio/src/lib/beta/metrics.js +147 -0
- package/studio/src/lib/beta/report.js +134 -0
- package/studio/src/lib/capstone-evidence.js +758 -0
- package/studio/src/lib/capstone.js +663 -0
- package/studio/src/lib/chat-store.js +128 -0
- package/studio/src/lib/course-export.js +38 -0
- package/studio/src/lib/course.js +187 -0
- package/studio/src/lib/exercises/journal-entry.js +259 -0
- package/studio/src/lib/exercises/placement.js +31 -0
- package/studio/src/lib/exercises/registry.js +19 -0
- package/studio/src/lib/exercises/spec.js +129 -0
- package/studio/src/lib/i18n/detect.js +162 -0
- package/studio/src/lib/i18n/en/app.json +23 -0
- package/studio/src/lib/i18n/en/betaReport.json +55 -0
- package/studio/src/lib/i18n/en/capstone.json +57 -0
- package/studio/src/lib/i18n/en/common.json +25 -0
- package/studio/src/lib/i18n/en/course.json +27 -0
- package/studio/src/lib/i18n/en/data.json +35 -0
- package/studio/src/lib/i18n/en/durability.json +5 -0
- package/studio/src/lib/i18n/en/errors.json +20 -0
- package/studio/src/lib/i18n/en/exercises.json +55 -0
- package/studio/src/lib/i18n/en/externalEvidence.json +76 -0
- package/studio/src/lib/i18n/en/home.json +18 -0
- package/studio/src/lib/i18n/en/lesson.json +33 -0
- package/studio/src/lib/i18n/en/nav.json +8 -0
- package/studio/src/lib/i18n/en/newCourse.json +51 -0
- package/studio/src/lib/i18n/en/onboarding.json +35 -0
- package/studio/src/lib/i18n/en/playwrightTemplate.json +20 -0
- package/studio/src/lib/i18n/en/practice.json +79 -0
- package/studio/src/lib/i18n/en/provider.json +27 -0
- package/studio/src/lib/i18n/en/providerMeta.json +26 -0
- package/studio/src/lib/i18n/en/reflection.json +17 -0
- package/studio/src/lib/i18n/en/revision.json +52 -0
- package/studio/src/lib/i18n/en/runnerNotice.json +14 -0
- package/studio/src/lib/i18n/en/settings.json +12 -0
- package/studio/src/lib/i18n/en/storage.json +49 -0
- package/studio/src/lib/i18n/en/tutor.json +39 -0
- package/studio/src/lib/i18n/en/workspace.json +50 -0
- package/studio/src/lib/i18n/index.js +144 -0
- package/studio/src/lib/i18n/languages.js +93 -0
- package/studio/src/lib/i18n/vi/app.json +23 -0
- package/studio/src/lib/i18n/vi/betaReport.json +55 -0
- package/studio/src/lib/i18n/vi/capstone.json +57 -0
- package/studio/src/lib/i18n/vi/common.json +25 -0
- package/studio/src/lib/i18n/vi/course.json +27 -0
- package/studio/src/lib/i18n/vi/data.json +35 -0
- package/studio/src/lib/i18n/vi/durability.json +5 -0
- package/studio/src/lib/i18n/vi/errors.json +20 -0
- package/studio/src/lib/i18n/vi/exercises.json +55 -0
- package/studio/src/lib/i18n/vi/externalEvidence.json +76 -0
- package/studio/src/lib/i18n/vi/home.json +18 -0
- package/studio/src/lib/i18n/vi/lesson.json +33 -0
- package/studio/src/lib/i18n/vi/nav.json +8 -0
- package/studio/src/lib/i18n/vi/newCourse.json +51 -0
- package/studio/src/lib/i18n/vi/onboarding.json +35 -0
- package/studio/src/lib/i18n/vi/playwrightTemplate.json +20 -0
- package/studio/src/lib/i18n/vi/practice.json +79 -0
- package/studio/src/lib/i18n/vi/provider.json +27 -0
- package/studio/src/lib/i18n/vi/providerMeta.json +26 -0
- package/studio/src/lib/i18n/vi/reflection.json +17 -0
- package/studio/src/lib/i18n/vi/revision.json +52 -0
- package/studio/src/lib/i18n/vi/runnerNotice.json +14 -0
- package/studio/src/lib/i18n/vi/settings.json +12 -0
- package/studio/src/lib/i18n/vi/storage.json +49 -0
- package/studio/src/lib/i18n/vi/tutor.json +39 -0
- package/studio/src/lib/i18n/vi/workspace.json +50 -0
- package/studio/src/lib/ids.js +10 -0
- package/studio/src/lib/json.js +26 -0
- package/studio/src/lib/markdown.js +74 -0
- package/studio/src/lib/prompts/base.js +139 -0
- package/studio/src/lib/prompts/capstone.js +777 -0
- package/studio/src/lib/prompts/course.js +150 -0
- package/studio/src/lib/prompts/lesson.js +275 -0
- package/studio/src/lib/prompts/practice.js +511 -0
- package/studio/src/lib/prompts/tutor.js +509 -0
- package/studio/src/lib/repo/blocked-adapter.js +69 -0
- package/studio/src/lib/repo/events.js +239 -0
- package/studio/src/lib/repo/idb-adapter.js +226 -0
- package/studio/src/lib/repo/index.js +1315 -0
- package/studio/src/lib/repo/memory-adapter.js +115 -0
- package/studio/src/lib/repo/remote-adapter.js +158 -0
- package/studio/src/lib/repo/schema.js +143 -0
- package/studio/src/lib/repo/select-adapter.js +345 -0
- package/studio/src/lib/router.js +71 -0
- package/studio/src/lib/runner/browser.js +244 -0
- package/studio/src/lib/runner/checks.js +248 -0
- package/studio/src/lib/runner/current-code.js +98 -0
- package/studio/src/lib/runner/esm-cjs.js +109 -0
- package/studio/src/lib/runner/hash.js +34 -0
- package/studio/src/lib/runner/history.js +48 -0
- package/studio/src/lib/runner/index.js +168 -0
- package/studio/src/lib/runner/languages.js +258 -0
- package/studio/src/lib/runner/local.js +139 -0
- package/studio/src/lib/runner/path.js +104 -0
- package/studio/src/lib/runner/skeleton.js +315 -0
- package/studio/src/lib/runner/strip-types.js +134 -0
- package/studio/src/lib/settings.js +399 -0
- package/studio/src/lib/srs.js +39 -0
- package/templates/agent/settings.json +6 -0
- package/templates/claude/plugin.json +139 -0
- package/templates/claude/settings.json +15 -0
- package/templates/cursor/professor.mdc +4 -0
- package/templates/cursor/settings.json +18 -0
- package/templates/gemini/GEMINI.md +28 -0
- package/templates/gemini/settings.json +5 -0
- package/templates/opencode/opencode.json +3 -0
- package/templates/researcher/README.md +61 -0
- package/templates/researcher/settings.json +18 -0
- package/web/client/components.json +15 -0
- package/web/client/index.html +12 -0
- package/web/client/package-lock.json +8732 -0
- package/web/client/package.json +39 -0
- package/web/client/postcss.config.js +6 -0
- package/web/client/src/App.jsx +140 -0
- package/web/client/src/api/client.js +357 -0
- package/web/client/src/components/ChatPanel.jsx +417 -0
- package/web/client/src/components/CommandPills.jsx +50 -0
- package/web/client/src/components/DeprecationBanner.jsx +21 -0
- package/web/client/src/components/ExerciseEditor.jsx +164 -0
- package/web/client/src/components/Header.jsx +119 -0
- package/web/client/src/components/LecturePanel.jsx +342 -0
- package/web/client/src/components/MobileTabSwitcher.jsx +51 -0
- package/web/client/src/components/SplitPane.jsx +42 -0
- package/web/client/src/components/ui/alert.jsx +38 -0
- package/web/client/src/components/ui/badge.jsx +24 -0
- package/web/client/src/components/ui/button.jsx +23 -0
- package/web/client/src/components/ui/select.jsx +74 -0
- package/web/client/src/hooks/useSSE.js +152 -0
- package/web/client/src/hooks/useWebSocket.js +98 -0
- package/web/client/src/index.css +23 -0
- package/web/client/src/lib/utils.js +6 -0
- package/web/client/src/main.jsx +12 -0
- package/web/client/src/utils/markdown.js +50 -0
- package/web/client/tailwind.config.js +8 -0
- package/web/client/vite.config.js +21 -0
- package/web/dist/assets/index-C1W0eXIQ.js +294 -0
- package/web/dist/assets/index-C3OUx70T.css +1 -0
- package/web/dist/index.html +13 -0
- package/web/lecture-archive.js +172 -0
- package/web/legacy-server.js +1277 -0
- package/web/package-lock.json +855 -0
- package/web/package.json +10 -0
- package/web/security.js +1016 -0
- package/web/server.js +390 -0
- package/web/studio-api/agents.js +580 -0
- package/web/studio-api/bridge.js +199 -0
- package/web/studio-api/db.js +66 -0
- package/web/studio-api/guards.js +201 -0
- package/web/studio-api/health.js +538 -0
- package/web/studio-api.js +214 -0
- package/web/studio-db.js +380 -0
- package/web/studio-runner.js +568 -0
|
@@ -0,0 +1,568 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Studio local runner (CODE-04) — an Express Router that writes the learner's workspace files to
|
|
3
|
+
* disk and runs their installed toolchain, streaming output back over SSE.
|
|
4
|
+
*
|
|
5
|
+
* Mounted by `web/studio-api.js` (Phase 26) as:
|
|
6
|
+
* router.use('/run', createRunnerRouter({ workspacesRoot }))
|
|
7
|
+
* so it inherits the parent router's pairing token + CORS allowlist — this file does NOT add CORS
|
|
8
|
+
* or auth of its own (never call it from a public origin without the parent guard).
|
|
9
|
+
*
|
|
10
|
+
* Safety model:
|
|
11
|
+
* - files are confined to `${workspacesRoot}/<courseSlug>/` (slug + relative-path validation)
|
|
12
|
+
* - only an allowlist of commands runs; `spawn` with `shell: false` (no shell interpolation)
|
|
13
|
+
* - hard 20 s timeout, 200 KB output cap, and the whole process tree is killed on timeout or
|
|
14
|
+
* when the client disconnects
|
|
15
|
+
*
|
|
16
|
+
* Endpoints:
|
|
17
|
+
* POST {mount}/ and POST {mount}/run -> SSE stdout/stderr/exit
|
|
18
|
+
* GET {mount}/toolchains -> { node: true, python3: false, … }
|
|
19
|
+
*
|
|
20
|
+
* Exported standalone (no dependency on studio/) so it can be unit-tested and reused.
|
|
21
|
+
*/
|
|
22
|
+
import express from 'express';
|
|
23
|
+
import { spawn, spawnSync } from 'node:child_process';
|
|
24
|
+
import { constants as fsConstants } from 'node:fs';
|
|
25
|
+
import { mkdir, open } from 'node:fs/promises';
|
|
26
|
+
import { homedir } from 'node:os';
|
|
27
|
+
import { dirname, join } from 'node:path';
|
|
28
|
+
|
|
29
|
+
import * as security from './security.js';
|
|
30
|
+
|
|
31
|
+
export const DEFAULT_TIMEOUT_MS = 20_000;
|
|
32
|
+
export const MAX_TIMEOUT_MS = 30_000;
|
|
33
|
+
export const MAX_OUTPUT_BYTES = 200_000;
|
|
34
|
+
export const MAX_TOTAL_FILES_BYTES = 2_000_000;
|
|
35
|
+
|
|
36
|
+
/** Commands the runner is allowed to execute, per language. */
|
|
37
|
+
export const COMMANDS = {
|
|
38
|
+
javascript: "node",
|
|
39
|
+
python: "python3",
|
|
40
|
+
go: "go",
|
|
41
|
+
java: "javac",
|
|
42
|
+
rust: "rustc",
|
|
43
|
+
bash: "bash",
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Commands that must never become reachable through this runner, even if a future language mapping
|
|
48
|
+
* is added. Checked by `buildPipeline` and again in `runStep` (defense in depth).
|
|
49
|
+
*/
|
|
50
|
+
export const COMMAND_DENYLIST = new Set([
|
|
51
|
+
'npm',
|
|
52
|
+
'npx',
|
|
53
|
+
'pnpm',
|
|
54
|
+
'yarn',
|
|
55
|
+
'playwright',
|
|
56
|
+
'sh',
|
|
57
|
+
'bash',
|
|
58
|
+
'zsh',
|
|
59
|
+
'fish',
|
|
60
|
+
'cmd',
|
|
61
|
+
'powershell',
|
|
62
|
+
]);
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Executable shim extensions a package manager or tool can be wrapped in (Windows `.cmd`/`.ps1`,
|
|
66
|
+
* npm's `.cmd` shims, Cygwin's `.exe`, …). They are stripped from the end of a command name before
|
|
67
|
+
* the allow/deny checks so `npx.cmd` and `NPM.EXE` cannot bypass `COMMAND_DENYLIST`.
|
|
68
|
+
*/
|
|
69
|
+
export const COMMAND_SHIM_EXTENSIONS = Object.freeze(['.exe', '.cmd', '.bat', '.com', '.ps1']);
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Reduce any spelling of a command to the bare executable name the lists are written against:
|
|
73
|
+
* the last path segment (POSIX `/` or Windows `\`), lowercased, with any trailing shim extension
|
|
74
|
+
* removed repeatedly (so `npm.cmd.exe` → `npm`).
|
|
75
|
+
* @param {unknown} command
|
|
76
|
+
* @returns {string} the normalized command name (empty string when nothing usable was supplied)
|
|
77
|
+
*/
|
|
78
|
+
export function normalizeCommandName(command) {
|
|
79
|
+
let name = String(command ?? '')
|
|
80
|
+
.trim()
|
|
81
|
+
.split(/[\\/]/)
|
|
82
|
+
.pop()
|
|
83
|
+
.toLowerCase();
|
|
84
|
+
for (;;) {
|
|
85
|
+
const ext = COMMAND_SHIM_EXTENSIONS.find((candidate) => name.endsWith(candidate));
|
|
86
|
+
if (!ext) return name;
|
|
87
|
+
name = name.slice(0, -ext.length);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Reject a deny-listed command. Bash is the single exception and only for the explicit `bash`
|
|
93
|
+
* language with `allowBash` true.
|
|
94
|
+
* @param {string} command
|
|
95
|
+
* @param {{ allowBash?: boolean }} [opts]
|
|
96
|
+
* @returns {true}
|
|
97
|
+
*/
|
|
98
|
+
export function assertCommandAllowed(command, { allowBash = false } = {}) {
|
|
99
|
+
const name = normalizeCommandName(command);
|
|
100
|
+
if (!name) {
|
|
101
|
+
const err = new Error('No command supplied.');
|
|
102
|
+
err.code = 'command_denied';
|
|
103
|
+
throw err;
|
|
104
|
+
}
|
|
105
|
+
if (name === 'bash' && allowBash) return true;
|
|
106
|
+
if (COMMAND_DENYLIST.has(name)) {
|
|
107
|
+
const err = new Error(`Command "${name}" is not allowed by the local runner.`);
|
|
108
|
+
err.code = 'command_denied';
|
|
109
|
+
throw err;
|
|
110
|
+
}
|
|
111
|
+
return true;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Pure concurrency counter. `tryAcquire` returns false when saturated; `release` never drops below
|
|
116
|
+
* zero, so an extra release from a close/error handler is harmless.
|
|
117
|
+
* @param {{ max?: number }} [opts]
|
|
118
|
+
* @returns {{ tryAcquire: () => boolean, release: () => void, readonly size: number, readonly max: number }}
|
|
119
|
+
*/
|
|
120
|
+
export function createRunLimiter({ max = 2 } = {}) {
|
|
121
|
+
const limit = Math.min(8, Math.max(1, Math.trunc(Number(max) || 1)));
|
|
122
|
+
let active = 0;
|
|
123
|
+
return {
|
|
124
|
+
tryAcquire() {
|
|
125
|
+
if (active >= limit) return false;
|
|
126
|
+
active += 1;
|
|
127
|
+
return true;
|
|
128
|
+
},
|
|
129
|
+
release() {
|
|
130
|
+
if (active > 0) active -= 1;
|
|
131
|
+
},
|
|
132
|
+
get size() {
|
|
133
|
+
return active;
|
|
134
|
+
},
|
|
135
|
+
get max() {
|
|
136
|
+
return limit;
|
|
137
|
+
},
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/** Clamp PROFESSOR_MAX_RUNS / options.maxRuns to 1-8, defaulting to 2. */
|
|
142
|
+
function resolveMaxRuns(value) {
|
|
143
|
+
const n = Math.trunc(Number(value));
|
|
144
|
+
if (!Number.isFinite(n) || n < 1) return 2;
|
|
145
|
+
return Math.min(8, n);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
const CONTROL_CHARS = /[\u0000-\u001f\u007f]/;
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* @param {unknown} path
|
|
152
|
+
* @returns {boolean}
|
|
153
|
+
*/
|
|
154
|
+
export function isSafeRelPath(path) {
|
|
155
|
+
if (typeof path !== 'string') return false;
|
|
156
|
+
const value = path.trim();
|
|
157
|
+
if (!value || value.length > 512) return false;
|
|
158
|
+
if (CONTROL_CHARS.test(value)) return false;
|
|
159
|
+
if (value.startsWith('/') || value.startsWith('~')) return false;
|
|
160
|
+
if (/^[a-zA-Z]:[\\/]/.test(value)) return false;
|
|
161
|
+
if (value.includes('\\')) return false;
|
|
162
|
+
if (value.endsWith('/')) return false;
|
|
163
|
+
return value.split('/').every((seg) => seg !== '' && seg !== '.' && seg !== '..');
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/** @param {unknown} slug @returns {boolean} */
|
|
167
|
+
export function isSafeSlug(slug) {
|
|
168
|
+
if (typeof slug !== 'string') return false;
|
|
169
|
+
const value = slug.trim();
|
|
170
|
+
if (!value || value.length > 120) return false;
|
|
171
|
+
if (!/^[a-z0-9][a-z0-9._-]*$/i.test(value)) return false;
|
|
172
|
+
return value !== '.' && value !== '..';
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/** @returns {string} */
|
|
176
|
+
export function defaultWorkspacesRoot() {
|
|
177
|
+
const home = process.env.PROFESSOR_HOME || join(homedir(), '.professor');
|
|
178
|
+
return join(home, 'workspaces');
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Build the run pipeline (ordered commands) for a language + entry file.
|
|
183
|
+
* @param {string} language
|
|
184
|
+
* @param {string} entry
|
|
185
|
+
* @param {Record<string,string>} files
|
|
186
|
+
* @param {{ allowBash?: boolean }} [opts]
|
|
187
|
+
* @returns {Array<{ cmd: string, args: string[] }>}
|
|
188
|
+
*/
|
|
189
|
+
export function buildPipeline(language, entry, files, { allowBash = false } = {}) {
|
|
190
|
+
let steps;
|
|
191
|
+
switch (language) {
|
|
192
|
+
case 'javascript':
|
|
193
|
+
steps = [{ cmd: 'node', args: [entry] }];
|
|
194
|
+
break;
|
|
195
|
+
case 'python':
|
|
196
|
+
steps = [{ cmd: 'python3', args: [entry] }];
|
|
197
|
+
break;
|
|
198
|
+
case 'go':
|
|
199
|
+
steps = [{ cmd: 'go', args: ['run', entry] }];
|
|
200
|
+
break;
|
|
201
|
+
case 'java': {
|
|
202
|
+
const sources = Object.keys(files).filter((f) => f.endsWith('.java'));
|
|
203
|
+
const list = sources.length ? sources : [entry];
|
|
204
|
+
const className = entry.replace(/\.java$/i, '');
|
|
205
|
+
steps = [
|
|
206
|
+
{ cmd: 'javac', args: list },
|
|
207
|
+
{ cmd: 'java', args: [className] },
|
|
208
|
+
];
|
|
209
|
+
break;
|
|
210
|
+
}
|
|
211
|
+
case 'rust': {
|
|
212
|
+
const bin = `./${entry.replace(/\.rs$/i, '')}`;
|
|
213
|
+
steps = [
|
|
214
|
+
{ cmd: 'rustc', args: [entry, '-o', entry.replace(/\.rs$/i, '')] },
|
|
215
|
+
{ cmd: bin, args: [] },
|
|
216
|
+
];
|
|
217
|
+
break;
|
|
218
|
+
}
|
|
219
|
+
case 'bash':
|
|
220
|
+
if (!allowBash) throw new Error('Bash is not enabled on this server (set PROFESSOR_ALLOW_BASH=1 to allow it).');
|
|
221
|
+
steps = [{ cmd: 'bash', args: [entry] }];
|
|
222
|
+
break;
|
|
223
|
+
default:
|
|
224
|
+
throw new Error(`No local toolchain for "${language}". Supported locally: node, python3, go, javac/java, rustc${allowBash ? ', bash' : ''}.`);
|
|
225
|
+
}
|
|
226
|
+
for (const step of steps) assertCommandAllowed(step.cmd, { allowBash });
|
|
227
|
+
return steps;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* Probe for an executable on PATH. Never passes a `cwd`: on a fresh machine the workspaces root
|
|
232
|
+
* may not exist yet, and `spawnSync` with a missing `cwd` fails with ENOENT (which would report
|
|
233
|
+
* every toolchain as absent).
|
|
234
|
+
* @param {string} cmd
|
|
235
|
+
* @returns {boolean}
|
|
236
|
+
*/
|
|
237
|
+
export function commandExists(cmd) {
|
|
238
|
+
const finder = process.platform === 'win32' ? 'where' : 'which';
|
|
239
|
+
try {
|
|
240
|
+
const res = spawnSync(finder, [cmd], { stdio: 'ignore' });
|
|
241
|
+
return res.status === 0;
|
|
242
|
+
} catch {
|
|
243
|
+
return false;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* Kill a spawned process tree (SIGKILL on POSIX, taskkill /T on Windows).
|
|
249
|
+
* @param {import('node:child_process').ChildProcess} child
|
|
250
|
+
*/
|
|
251
|
+
export function killTree(child) {
|
|
252
|
+
if (!child || child.killed || child.exitCode !== null) return;
|
|
253
|
+
try {
|
|
254
|
+
if (process.platform === 'win32') {
|
|
255
|
+
spawnSync('taskkill', ['/pid', String(child.pid), '/T', '/F'], { stdio: 'ignore' });
|
|
256
|
+
} else {
|
|
257
|
+
process.kill(-child.pid, 'SIGKILL');
|
|
258
|
+
}
|
|
259
|
+
} catch {
|
|
260
|
+
try {
|
|
261
|
+
child.kill('SIGKILL');
|
|
262
|
+
} catch {
|
|
263
|
+
/* already gone */
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* @param {{ workspacesRoot?: string, allowBash?: boolean,
|
|
270
|
+
* spawnImpl?: typeof spawn, maxRuns?: number,
|
|
271
|
+
* mintLimiter?: (max: number) => ReturnType<typeof createRunLimiter> }} [options]
|
|
272
|
+
* @returns {import('express').Router}
|
|
273
|
+
*/
|
|
274
|
+
export function createRunnerRouter(options = {}) {
|
|
275
|
+
const workspacesRoot = options.workspacesRoot || defaultWorkspacesRoot();
|
|
276
|
+
const allowBash = options.allowBash ?? process.env.PROFESSOR_ALLOW_BASH === '1';
|
|
277
|
+
const maxRuns = resolveMaxRuns(options.maxRuns ?? process.env.PROFESSOR_MAX_RUNS);
|
|
278
|
+
const spawnImpl = options.spawnImpl || spawn;
|
|
279
|
+
const mintLimiter = options.mintLimiter || ((max) => createRunLimiter({ max }));
|
|
280
|
+
const limiter = mintLimiter(maxRuns);
|
|
281
|
+
const router = express.Router();
|
|
282
|
+
router.use(express.json({ limit: '4mb' }));
|
|
283
|
+
router.runLimiter = limiter;
|
|
284
|
+
|
|
285
|
+
router.get('/toolchains', (_req, res) => {
|
|
286
|
+
const result = {};
|
|
287
|
+
for (const cmd of ['node', 'python3', 'go', 'javac', 'java', 'rustc', 'bash']) {
|
|
288
|
+
result[cmd] = commandExists(cmd);
|
|
289
|
+
}
|
|
290
|
+
res.json(result);
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
const runHandler = (req, res) =>
|
|
294
|
+
handleRun(req, res, { workspacesRoot, allowBash, spawnImpl, limiter });
|
|
295
|
+
router.post('/', runHandler);
|
|
296
|
+
router.post('/run', runHandler);
|
|
297
|
+
|
|
298
|
+
router.use((err, _req, res, _next) => {
|
|
299
|
+
res.status(400).json({ error: err?.message || 'Runner request failed' });
|
|
300
|
+
});
|
|
301
|
+
|
|
302
|
+
return router;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
/**
|
|
306
|
+
* @param {import('express').Request} req
|
|
307
|
+
* @param {import('express').Response} res
|
|
308
|
+
* @param {{ workspacesRoot: string, allowBash: boolean, spawnImpl: typeof spawn,
|
|
309
|
+
* limiter: ReturnType<typeof createRunLimiter> }} opts
|
|
310
|
+
*/
|
|
311
|
+
async function handleRun(req, res, { workspacesRoot, allowBash, spawnImpl, limiter }) {
|
|
312
|
+
const body = req.body || {};
|
|
313
|
+
const courseSlug = String(body.courseSlug || 'workspace');
|
|
314
|
+
const language = String(body.language || '').toLowerCase();
|
|
315
|
+
const entry = String(body.entry || '');
|
|
316
|
+
const files = normalizeFiles(body.files);
|
|
317
|
+
const timeoutMs = Math.min(Math.max(Number(body.timeoutMs) || DEFAULT_TIMEOUT_MS, 1000), MAX_TIMEOUT_MS);
|
|
318
|
+
|
|
319
|
+
if (!isSafeSlug(courseSlug)) {
|
|
320
|
+
res.status(400).json({ error: `Unsafe course slug: ${courseSlug}` });
|
|
321
|
+
return;
|
|
322
|
+
}
|
|
323
|
+
if (!files.length) {
|
|
324
|
+
res.status(400).json({ error: 'No files supplied' });
|
|
325
|
+
return;
|
|
326
|
+
}
|
|
327
|
+
for (const file of files) {
|
|
328
|
+
if (!isSafeRelPath(file.path) || !security.isSafeWorkspaceRelPath(file.path)) {
|
|
329
|
+
res.status(400).json({ error: `Unsafe file path: ${file.path}` });
|
|
330
|
+
return;
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
const totalBytes = files.reduce((n, f) => n + Buffer.byteLength(f.content, 'utf8'), 0);
|
|
334
|
+
if (totalBytes > MAX_TOTAL_FILES_BYTES) {
|
|
335
|
+
res.status(400).json({ error: 'Workspace files are too large to run.' });
|
|
336
|
+
return;
|
|
337
|
+
}
|
|
338
|
+
const entryPath = entry || files[0].path;
|
|
339
|
+
if (
|
|
340
|
+
!isSafeRelPath(entryPath) ||
|
|
341
|
+
!security.isSafeWorkspaceRelPath(entryPath) ||
|
|
342
|
+
!files.some((f) => f.path === entryPath)
|
|
343
|
+
) {
|
|
344
|
+
res.status(400).json({ error: `Entry file is missing or unsafe: ${entryPath}` });
|
|
345
|
+
return;
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
let pipeline;
|
|
349
|
+
try {
|
|
350
|
+
pipeline = buildPipeline(language, entryPath, Object.fromEntries(files.map((f) => [f.path, f.content])), { allowBash });
|
|
351
|
+
} catch (err) {
|
|
352
|
+
res.status(400).json({ error: err.message, ...(err.code ? { code: err.code } : {}) });
|
|
353
|
+
return;
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
// Realpath containment is validated before the limiter and before any filesystem side effect.
|
|
357
|
+
let courseDir;
|
|
358
|
+
const targets = [];
|
|
359
|
+
try {
|
|
360
|
+
courseDir = security.resolveInside(workspacesRoot, courseSlug);
|
|
361
|
+
for (const file of files) {
|
|
362
|
+
targets.push({
|
|
363
|
+
file,
|
|
364
|
+
target: security.resolveInside(workspacesRoot, courseSlug, ...file.path.split('/')),
|
|
365
|
+
});
|
|
366
|
+
}
|
|
367
|
+
} catch (err) {
|
|
368
|
+
res.status(400).json({ error: err.message, code: err.code || 'unsafe_path' });
|
|
369
|
+
return;
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
if (!limiter.tryAcquire()) {
|
|
373
|
+
res.setHeader('Retry-After', '1');
|
|
374
|
+
res.status(429).json({ error: 'Too many concurrent runs', code: 'busy' });
|
|
375
|
+
return;
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
let released = false;
|
|
379
|
+
const release = () => {
|
|
380
|
+
if (released) return;
|
|
381
|
+
released = true;
|
|
382
|
+
limiter.release();
|
|
383
|
+
};
|
|
384
|
+
res.on('close', release);
|
|
385
|
+
|
|
386
|
+
const learnerEnv = {
|
|
387
|
+
...security.buildLearnerEnv(process.env),
|
|
388
|
+
PYTHONUNBUFFERED: '1',
|
|
389
|
+
PYTHONIOENCODING: 'utf-8',
|
|
390
|
+
};
|
|
391
|
+
|
|
392
|
+
try {
|
|
393
|
+
try {
|
|
394
|
+
await mkdir(workspacesRoot, { recursive: true });
|
|
395
|
+
await mkdir(courseDir, { recursive: true });
|
|
396
|
+
const flags =
|
|
397
|
+
fsConstants.O_WRONLY |
|
|
398
|
+
fsConstants.O_CREAT |
|
|
399
|
+
fsConstants.O_TRUNC |
|
|
400
|
+
(fsConstants.O_NOFOLLOW || 0);
|
|
401
|
+
for (const { file, target } of targets) {
|
|
402
|
+
await mkdir(dirname(target), { recursive: true });
|
|
403
|
+
const handle = await open(target, flags, 0o600);
|
|
404
|
+
try {
|
|
405
|
+
await handle.writeFile(file.content, 'utf8');
|
|
406
|
+
} finally {
|
|
407
|
+
await handle.close();
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
} catch (err) {
|
|
411
|
+
res.status(500).json({ error: `Could not prepare workspace: ${err.message}` });
|
|
412
|
+
return;
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
startStream(res);
|
|
416
|
+
await streamPipeline(pipeline, {
|
|
417
|
+
cwd: courseDir,
|
|
418
|
+
timeoutMs,
|
|
419
|
+
res,
|
|
420
|
+
spawnImpl,
|
|
421
|
+
allowBash,
|
|
422
|
+
env: learnerEnv,
|
|
423
|
+
});
|
|
424
|
+
} finally {
|
|
425
|
+
release();
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
/**
|
|
430
|
+
* @param {Array<{cmd:string,args:string[]}>} pipeline
|
|
431
|
+
* @param {{ cwd: string, timeoutMs: number, res: import('express').Response,
|
|
432
|
+
* spawnImpl: typeof spawn, allowBash: boolean, env: Record<string,string> }} ctx
|
|
433
|
+
*/
|
|
434
|
+
async function streamPipeline(pipeline, { cwd, timeoutMs, res, spawnImpl, allowBash, env }) {
|
|
435
|
+
let outputBytes = 0;
|
|
436
|
+
let truncated = false;
|
|
437
|
+
let killed = false;
|
|
438
|
+
let finished = false;
|
|
439
|
+
|
|
440
|
+
const send = (obj) => {
|
|
441
|
+
if (res.writableEnded) return;
|
|
442
|
+
res.write(`data: ${JSON.stringify(obj)}\n\n`);
|
|
443
|
+
};
|
|
444
|
+
|
|
445
|
+
const finish = (code) => {
|
|
446
|
+
if (finished) return;
|
|
447
|
+
finished = true;
|
|
448
|
+
if (truncated) send({ stderr: '\n… (output truncated)\n' });
|
|
449
|
+
send({ exit: typeof code === 'number' ? code : 0 });
|
|
450
|
+
if (res.writableEnded) return;
|
|
451
|
+
res.write('data: [DONE]\n\n');
|
|
452
|
+
res.end();
|
|
453
|
+
};
|
|
454
|
+
|
|
455
|
+
const killAll = () => {
|
|
456
|
+
killed = true;
|
|
457
|
+
for (const child of children) killTree(child);
|
|
458
|
+
};
|
|
459
|
+
|
|
460
|
+
/** @type {import('node:child_process').ChildProcess[]} */
|
|
461
|
+
const children = [];
|
|
462
|
+
res.on('close', killAll);
|
|
463
|
+
const timer = setTimeout(() => {
|
|
464
|
+
send({ stderr: `\nTimed out after ${Math.round(timeoutMs / 1000)}s — the process was stopped.\n` });
|
|
465
|
+
killAll();
|
|
466
|
+
finish(124);
|
|
467
|
+
}, timeoutMs);
|
|
468
|
+
|
|
469
|
+
const capture = (child) => {
|
|
470
|
+
const onChunk = (stream, chunk) => {
|
|
471
|
+
if (truncated) return;
|
|
472
|
+
const text = chunk.toString('utf8');
|
|
473
|
+
const remaining = MAX_OUTPUT_BYTES - outputBytes;
|
|
474
|
+
if (remaining <= 0) {
|
|
475
|
+
truncated = true;
|
|
476
|
+
killAll();
|
|
477
|
+
return;
|
|
478
|
+
}
|
|
479
|
+
if (text.length > remaining) {
|
|
480
|
+
send({ [stream]: text.slice(0, remaining) });
|
|
481
|
+
outputBytes = MAX_OUTPUT_BYTES;
|
|
482
|
+
truncated = true;
|
|
483
|
+
killAll();
|
|
484
|
+
return;
|
|
485
|
+
}
|
|
486
|
+
outputBytes += Buffer.byteLength(text, 'utf8');
|
|
487
|
+
send({ [stream]: text });
|
|
488
|
+
};
|
|
489
|
+
child.stdout?.on('data', (c) => onChunk('stdout', c));
|
|
490
|
+
child.stderr?.on('data', (c) => onChunk('stderr', c));
|
|
491
|
+
};
|
|
492
|
+
|
|
493
|
+
for (let i = 0; i < pipeline.length; i++) {
|
|
494
|
+
const step = pipeline[i];
|
|
495
|
+
if (killed) break;
|
|
496
|
+
const code = await runStep(step, { cwd, capture, out: children, send, spawnImpl, allowBash, env });
|
|
497
|
+
if (killed) {
|
|
498
|
+
clearTimeout(timer);
|
|
499
|
+
finish(truncated ? 1 : 124);
|
|
500
|
+
return;
|
|
501
|
+
}
|
|
502
|
+
if (code !== 0) {
|
|
503
|
+
clearTimeout(timer);
|
|
504
|
+
finish(code);
|
|
505
|
+
return;
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
clearTimeout(timer);
|
|
510
|
+
finish(0);
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
/**
|
|
514
|
+
* @param {{ cmd: string, args: string[] }} step
|
|
515
|
+
* @param {{ cwd: string, capture: Function, out: any[], send: Function,
|
|
516
|
+
* spawnImpl: typeof spawn, allowBash: boolean, env: Record<string,string> }} ctx
|
|
517
|
+
* @returns {Promise<number>}
|
|
518
|
+
*/
|
|
519
|
+
function runStep(step, { cwd, capture, out, send, spawnImpl, allowBash, env }) {
|
|
520
|
+
try {
|
|
521
|
+
assertCommandAllowed(step.cmd, { allowBash });
|
|
522
|
+
} catch (err) {
|
|
523
|
+
send({ stderr: `Refusing to run ${step.cmd}: ${err.message}\n` });
|
|
524
|
+
return Promise.resolve(126);
|
|
525
|
+
}
|
|
526
|
+
return new Promise((resolvePromise) => {
|
|
527
|
+
let child;
|
|
528
|
+
try {
|
|
529
|
+
child = spawnImpl(step.cmd, step.args, {
|
|
530
|
+
cwd,
|
|
531
|
+
shell: false,
|
|
532
|
+
detached: process.platform !== 'win32',
|
|
533
|
+
env,
|
|
534
|
+
});
|
|
535
|
+
} catch (err) {
|
|
536
|
+
send({ stderr: `Failed to start ${step.cmd}: ${err.message}\n` });
|
|
537
|
+
return resolvePromise(127);
|
|
538
|
+
}
|
|
539
|
+
out.push(child);
|
|
540
|
+
capture(child);
|
|
541
|
+
child.on('error', (err) => {
|
|
542
|
+
send({ stderr: `Failed to start ${step.cmd}: ${err.message}\n` });
|
|
543
|
+
resolvePromise(127);
|
|
544
|
+
});
|
|
545
|
+
child.on('close', (code) => resolvePromise(typeof code === 'number' ? code : 1));
|
|
546
|
+
});
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
/** @param {import('express').Response} res */
|
|
550
|
+
function startStream(res) {
|
|
551
|
+
res.status(200);
|
|
552
|
+
res.setHeader('Content-Type', 'text/event-stream; charset=utf-8');
|
|
553
|
+
res.setHeader('Cache-Control', 'no-cache, no-transform');
|
|
554
|
+
res.setHeader('Connection', 'keep-alive');
|
|
555
|
+
res.setHeader('X-Accel-Buffering', 'no');
|
|
556
|
+
res.flushHeaders?.();
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
/** @param {any} files @returns {Array<{path:string,content:string}>} */
|
|
560
|
+
function normalizeFiles(files) {
|
|
561
|
+
if (!files) return [];
|
|
562
|
+
const rows = Array.isArray(files)
|
|
563
|
+
? files.map((f) => ({ path: f?.path ?? f?.name, content: f?.content ?? '' }))
|
|
564
|
+
: Object.entries(files).map(([path, content]) => ({ path, content }));
|
|
565
|
+
return rows
|
|
566
|
+
.filter((f) => typeof f.path === 'string' && f.path)
|
|
567
|
+
.map((f) => ({ path: f.path, content: String(f.content ?? '') }));
|
|
568
|
+
}
|