ronin-skillforce 0.0.0-stage → 0.2.0-beta.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 +74 -0
- package/LICENSE +202 -0
- package/NOTICE +19 -0
- package/README.md +258 -2
- package/bin/cli.js +823 -0
- package/bin/commands/archive.js +192 -0
- package/bin/commands/capstone-status.js +82 -0
- package/bin/commands/check.js +298 -0
- package/bin/commands/create.js +226 -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-autostart.js +414 -0
- package/bin/commands/studio-state.js +159 -0
- package/bin/commands/studio.js +831 -0
- package/bin/commands/trail.js +361 -0
- package/bin/commands/web.js +348 -0
- package/bin/course-reader.js +602 -0
- package/bin/node-version.js +60 -0
- package/bin/platforms/_shared.js +337 -0
- package/bin/platforms/claude.js +85 -0
- package/bin/platforms/cursor.js +52 -0
- package/bin/platforms/gemini.js +64 -0
- package/bin/platforms/opencode.js +114 -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 +92 -4
- package/plugin.json +139 -0
- package/shared/SKILL.md +598 -0
- package/shared/agents/coach.md +228 -0
- package/shared/agents/navigator.md +208 -0
- package/shared/agents/professor.md +354 -0
- package/shared/agents/researcher.md +181 -0
- package/shared/agents/spotter.md +128 -0
- package/shared/commands/professor/archive.md +96 -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 +72 -0
- package/shared/commands/professor/export.md +69 -0
- package/shared/commands/professor/hint.md +120 -0
- package/shared/commands/professor/navigator.md +93 -0
- package/shared/commands/professor/new-topic.md +73 -0
- package/shared/commands/professor/next.md +178 -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 +57 -0
- package/shared/commands/professor/schedule.md +75 -0
- package/shared/commands/professor/skill-export.md +86 -0
- package/shared/commands/professor/spotter.md +93 -0
- package/shared/commands/professor/stuck.md +51 -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 +54 -0
- package/shared/hooks/pre-compact.js +221 -0
- package/studio/README.md +313 -0
- package/studio/dist/assets/BetaReportPanel-BJ9HIAnz.js +1 -0
- package/studio/dist/assets/Capstone-CoUU-jP7.js +6 -0
- package/studio/dist/assets/CodeWorkspace-BNrL4qvR.js +2 -0
- package/studio/dist/assets/Course-BMGTXus_.js +1 -0
- package/studio/dist/assets/Editor-Cw9j3cnp.js +53 -0
- package/studio/dist/assets/Home-D2woITq5.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-CYQhrDCZ.js +2 -0
- package/studio/dist/assets/NewCourse-CMpwVRQb.js +952 -0
- package/studio/dist/assets/Progress-2rS19Fur.js +1 -0
- package/studio/dist/assets/Review-SlqK-hjp.js +1 -0
- package/studio/dist/assets/Settings-t42u7n9H.js +1 -0
- package/studio/dist/assets/TutorPanel-DQDWIU7f.js +123 -0
- package/studio/dist/assets/abnfDiagram-WEYOIA3C-jTUmGBuB.js +1 -0
- package/studio/dist/assets/anthropic-iIm2l85r.js +15 -0
- package/studio/dist/assets/arc-Y1ARJVZ4.js +1 -0
- package/studio/dist/assets/architecture-WOLXFQ4H-Ch9Ld_vv.js +1 -0
- package/studio/dist/assets/architectureDiagram-ZHVYKT53-Dy-z6wsy.js +36 -0
- package/studio/dist/assets/array-BifhSqXX.js +1 -0
- package/studio/dist/assets/blockDiagram-RJAE7QA3-2fHVrc6N.js +140 -0
- package/studio/dist/assets/bridge-Cr0q4rLp.js +1 -0
- package/studio/dist/assets/c4Diagram-XDPPPE54-BuuKlG4V.js +38 -0
- package/studio/dist/assets/capstone-DhwBeNqk.js +135 -0
- package/studio/dist/assets/card-store-CVMBc-Pv.js +1 -0
- package/studio/dist/assets/channel-M_JkdHrL.js +1 -0
- package/studio/dist/assets/chunk-2E7WHVMD-lZdQWttk.js +88 -0
- package/studio/dist/assets/chunk-2Q5K7J3B-C1jixKkw.js +1 -0
- package/studio/dist/assets/chunk-4EMNKR2T-C6kbMwke.js +1 -0
- package/studio/dist/assets/chunk-55XCU76K-rkBzkZog.js +1 -0
- package/studio/dist/assets/chunk-5VM5RSS4-ZNzvKenW.js +15 -0
- package/studio/dist/assets/chunk-7S6XSTFO-Skg347QF.js +2 -0
- package/studio/dist/assets/chunk-AQDTSKZB-0pSDBJ23.js +72 -0
- package/studio/dist/assets/chunk-DSNLSHJZ-BaeQDl2i.js +129 -0
- package/studio/dist/assets/chunk-DUW6YSOI-Dgx8z5s3.js +1 -0
- package/studio/dist/assets/chunk-HAGFOTED-BEm00juw.js +62 -0
- package/studio/dist/assets/chunk-HNE4Q36P-DyCR-LvS.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-BNJ9uMmB.js +213 -0
- package/studio/dist/assets/chunk-UHW7PFBP-DqJczBLs.js +1 -0
- package/studio/dist/assets/chunk-VQ5W62QI-CVWYSP5Q.js +1 -0
- package/studio/dist/assets/chunk-WQQL4CDK-DJf0Dx05.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-BFUm_JHA.js +1 -0
- package/studio/dist/assets/chunk-ZAUX2LTX-C5ETkkSE.js +1 -0
- package/studio/dist/assets/chunk-ZCHMQSOR-WVX9r9PZ.js +2 -0
- package/studio/dist/assets/classDiagram-v2-4MYWR3UA-CI77SpuR.js +217 -0
- package/studio/dist/assets/cose-bilkent-JH36ORCC-DMBAZFnj.js +1 -0
- package/studio/dist/assets/course-export-C8jSPuda.js +1 -0
- package/studio/dist/assets/cynefin-EF2NZ3EQ-CLffmM25.js +1 -0
- package/studio/dist/assets/cynefinDiagram-WF24UDRP-BvLwocOb.js +62 -0
- package/studio/dist/assets/cytoscape.esm-CHBj4VkZ.js +321 -0
- package/studio/dist/assets/dagre-NK4GIZVX-C2nMAVdh.js +4 -0
- package/studio/dist/assets/defaultLocale-BFoDCU3G.js +1 -0
- package/studio/dist/assets/diagram-CBK3MWTC-Bid-pdax.js +24 -0
- package/studio/dist/assets/diagram-I5XIIV2D-DYJeAvzl.js +24 -0
- package/studio/dist/assets/diagram-ODIL2UCW-B06X2r_F.js +30 -0
- package/studio/dist/assets/diagram-PFBEJUXE-CwY--5Rz.js +3 -0
- package/studio/dist/assets/diagram-RJA3I4VV-4SqhH8zw.js +41 -0
- package/studio/dist/assets/diagram-TYUNFSNR-CrW4AIM9.js +200 -0
- package/studio/dist/assets/dist-CumnGVmJ.js +1 -0
- package/studio/dist/assets/ebnfDiagram-V4P3TTPT-xeoCmH-d.js +1 -0
- package/studio/dist/assets/elk-QONTBCTQ-Dadmz6iS.js +27 -0
- package/studio/dist/assets/erDiagram-KYQIGQAA-CSuH0bbF.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-CciVfx3I.js +1 -0
- package/studio/dist/assets/fetch-local-DG3O3hmQ.js +4 -0
- package/studio/dist/assets/flowDiagram-IUGLLWBU-DgNR54qK.js +1 -0
- package/studio/dist/assets/ganttDiagram-R7GPNTJY-C0wtA-2y.js +292 -0
- package/studio/dist/assets/gitGraph-VSP46ZUC-BXoDzaA3.js +1 -0
- package/studio/dist/assets/gitGraphDiagram-PDYL7XHY-vZBlNRPe.js +106 -0
- package/studio/dist/assets/graphlib-DS17s2tU.js +1 -0
- package/studio/dist/assets/index-CS8XPYbB.js +313 -0
- package/studio/dist/assets/index-CVenTTOY.css +2 -0
- package/studio/dist/assets/info-OHQRW6UA-bs2Qpf7P.js +1 -0
- package/studio/dist/assets/infoDiagram-MVDRKAX5-rPJio6-1.js +2 -0
- package/studio/dist/assets/init-C-OQMol4.js +1 -0
- package/studio/dist/assets/ishikawaDiagram-HPEHV2GE-CXf9XFff.js +70 -0
- package/studio/dist/assets/journeyDiagram-BOSHW7O7-C3MSH79o.js +139 -0
- package/studio/dist/assets/js.worker-AD7DjksO.js +4 -0
- package/studio/dist/assets/kanban-definition-FNSA4HC5-Bdh7SB4n.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-CHkoQXJF.js +1 -0
- package/studio/dist/assets/linear-C9iwaMOi.js +1 -0
- package/studio/dist/assets/mermaid-parser.core-Do1oxD1S.js +7 -0
- package/studio/dist/assets/mermaid.core-DgZUD0sU.js +44 -0
- package/studio/dist/assets/mindmap-definition-6OY57UG3-PUaK6oE_.js +98 -0
- package/studio/dist/assets/node.browser-DkpMze_r.js +1 -0
- package/studio/dist/assets/node.browser-HQ5SKBOf.js +1 -0
- package/studio/dist/assets/ollama-bJNp3jaD.js +1 -0
- package/studio/dist/assets/openai-compatible-0tmAyMlN.js +1 -0
- package/studio/dist/assets/ordinal-BDEzSJ7C.js +1 -0
- package/studio/dist/assets/packet-JDAUHWVQ-vf2FtqFr.js +1 -0
- package/studio/dist/assets/path-fybaL0A-.js +1 -0
- package/studio/dist/assets/pegDiagram-ECIUJNBX-NEVrgPTY.js +1 -0
- package/studio/dist/assets/pie-XZMESJXO-BIWydVNZ.js +1 -0
- package/studio/dist/assets/pieDiagram-GNMPY74T-BI9_u6rT.js +39 -0
- package/studio/dist/assets/python.worker-CzTrFdd9.js +24 -0
- package/studio/dist/assets/quadrantDiagram-D57K4MC3-ryNpoBC5.js +7 -0
- package/studio/dist/assets/radar-ABXABTNO-D8TjnvBB.js +1 -0
- package/studio/dist/assets/railroad-I3PHUGI6-BmEDV5kf.js +1 -0
- package/studio/dist/assets/railroad-abnf-LNEFI6M7-Cs_sArMc.js +1 -0
- package/studio/dist/assets/railroad-ebnf-DWYD2UWJ-DYuCq46d.js +1 -0
- package/studio/dist/assets/railroad-peg-JR7BVNR7-BcXSgdMy.js +1 -0
- package/studio/dist/assets/railroadDiagram-Y72NRBL7-DBcc8b2c.js +1 -0
- package/studio/dist/assets/react-B8SKf8RM.js +1 -0
- package/studio/dist/assets/rehype-katex-BfUIq5As.js +259 -0
- package/studio/dist/assets/remark-math-XvZOjmDO.js +5 -0
- package/studio/dist/assets/requirementDiagram-EQYSW5RA-CVcBgM1L.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-DjZ81hDs.js +40 -0
- package/studio/dist/assets/schemas-BOc2YsOP.js +55 -0
- package/studio/dist/assets/sequenceDiagram-BLEHNHQU-BNwOa2S7.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-BFWa5lEx.js +291 -0
- package/studio/dist/assets/swimlanes-B3ENRKFQ-LfM_Jg6Z.js +1 -0
- package/studio/dist/assets/swimlanesDiagram-AYQRV4AK-BDmpoiGp.js +8 -0
- package/studio/dist/assets/timeline-definition-JXYKGLGB-BwGzkWgZ.js +120 -0
- package/studio/dist/assets/treeView-D4JQ5SDB-MLk3VuRt.js +1 -0
- package/studio/dist/assets/treemap-SAJKECNS-D8iSjp7L.js +1 -0
- package/studio/dist/assets/useStream-rdsR6A7P.js +1 -0
- package/studio/dist/assets/usecaseDiagram-WPOLBNNX-BqxpaNlT.js +328 -0
- package/studio/dist/assets/vennDiagram-Q3Y3IDCW-CpeUDMhQ.js +34 -0
- package/studio/dist/assets/wardley-7MLQ67FV-tAMbCZAj.js +1 -0
- package/studio/dist/assets/wardleyDiagram-IVAIDKWA-CDJViWzt.js +78 -0
- package/studio/dist/assets/xychartDiagram-4URNHDU4-CwaQrd3_.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 +30 -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,831 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `skillforce studio` (CLI-05) — one command that brings the whole local platform up:
|
|
3
|
+
*
|
|
4
|
+
* 1. installs `web/` and `studio/` deps if missing, builds `studio/dist` if missing/stale
|
|
5
|
+
* 2. starts the local server (`web/server.js`, production, on `--api-port`) with a pairing token
|
|
6
|
+
* 3. serves `studio/dist` on `--port` (tiny static server, loopback only)
|
|
7
|
+
* 4. waits for `/api/studio/health`, then opens
|
|
8
|
+
* `http://127.0.0.1:<port>/#token=…` (plus `&bridge=…` for a non-default API port)
|
|
9
|
+
* (unless `--no-open`)
|
|
10
|
+
*
|
|
11
|
+
* Every URL this command polls or prints uses `127.0.0.1`, matching the server bind: `localhost`
|
|
12
|
+
* resolves to `::1` first on macOS, where another app may already be listening.
|
|
13
|
+
*
|
|
14
|
+
* Inherited `CLAUDECODE` / `CLAUDE_CODE_*` env vars are stripped from the child so a nested agent
|
|
15
|
+
* CLI (spawned by the bridge) behaves like a normal terminal.
|
|
16
|
+
*/
|
|
17
|
+
import { spawn, execSync, execFileSync } from 'child_process';
|
|
18
|
+
import { createServer } from 'http';
|
|
19
|
+
import { createServer as createNetServer } from 'net';
|
|
20
|
+
import { existsSync, statSync, readdirSync } from 'fs';
|
|
21
|
+
import { dirname, join } from 'path';
|
|
22
|
+
import { homedir } from 'os';
|
|
23
|
+
import { fileURLToPath } from 'url';
|
|
24
|
+
import { createRequire } from 'module';
|
|
25
|
+
import { createStaticHandler } from '../static-server.js';
|
|
26
|
+
import { requireStudioNode } from '../node-version.js';
|
|
27
|
+
import * as security from '../../web/security.js';
|
|
28
|
+
import {
|
|
29
|
+
isStudioHealthPayload,
|
|
30
|
+
removeState,
|
|
31
|
+
writeState,
|
|
32
|
+
} from './studio-state.js';
|
|
33
|
+
import {
|
|
34
|
+
LABEL,
|
|
35
|
+
UNSUPPORTED_PLATFORM,
|
|
36
|
+
collectStatus,
|
|
37
|
+
disableAutostart,
|
|
38
|
+
displayPath,
|
|
39
|
+
enableAutostart,
|
|
40
|
+
formatStatus,
|
|
41
|
+
stopStudio,
|
|
42
|
+
} from './studio-autostart.js';
|
|
43
|
+
|
|
44
|
+
export { isStudioHealthPayload };
|
|
45
|
+
|
|
46
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
47
|
+
export const REPO_ROOT = join(__dirname, '..', '..');
|
|
48
|
+
|
|
49
|
+
export const DEFAULT_PORT = 5180;
|
|
50
|
+
export const DEFAULT_API_PORT = 3000;
|
|
51
|
+
export const HEALTH_PATH = '/api/studio/health';
|
|
52
|
+
|
|
53
|
+
/** Hosts probed for a busy port: the `127.0.0.1` bind plus the IPv6 loopback `localhost` may use. */
|
|
54
|
+
export const LOOPBACK_HOSTS = ['127.0.0.1', '::1'];
|
|
55
|
+
|
|
56
|
+
/** Base URL the CLI polls and prints — the IPv4 literal, never `localhost`. */
|
|
57
|
+
export function loopbackUrl(port) {
|
|
58
|
+
return `http://127.0.0.1:${port}`;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** Rewrite an `http://localhost…` URL to the IPv4 loopback literal. */
|
|
62
|
+
export function toLoopbackUrl(url) {
|
|
63
|
+
return String(url).replace(/^http:\/\/localhost(?=[:/]|$)/, 'http://127.0.0.1');
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Usage text for `studio --help`. Kept as a plain string so the CLI can print it without starting
|
|
68
|
+
* or binding anything.
|
|
69
|
+
*/
|
|
70
|
+
export const STUDIO_USAGE = `
|
|
71
|
+
Usage: skillforce studio [options]
|
|
72
|
+
|
|
73
|
+
Start the local bridge server and Professor Studio, then open the browser (Node 22.5+).
|
|
74
|
+
|
|
75
|
+
Options:
|
|
76
|
+
--port <n> Studio port (default ${DEFAULT_PORT})
|
|
77
|
+
--api-port <n> Local bridge server port (default ${DEFAULT_API_PORT})
|
|
78
|
+
--no-open Do not open the browser
|
|
79
|
+
--strict-port Fail instead of picking another port when one is busy
|
|
80
|
+
--autostart on Start Studio at login (macOS, global install only)
|
|
81
|
+
--autostart off Remove the login item and stop starting Studio at login
|
|
82
|
+
--status Show whether Studio is running, its URLs, autostart and log path
|
|
83
|
+
--stop Stop the running Studio (never another app's process)
|
|
84
|
+
--rotate-token Generate a new pairing token and exit
|
|
85
|
+
-h, --help Show this help and exit
|
|
86
|
+
`.trim();
|
|
87
|
+
|
|
88
|
+
/** True when `-h` or `--help` is present. */
|
|
89
|
+
export function wantsHelp(args = []) {
|
|
90
|
+
return args.includes('--help') || args.includes('-h');
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Parse `--port`, `--api-port`, `--no-open`, `--strict-port`, `--status`, `--stop` and
|
|
96
|
+
* `--autostart on|off` (both `--flag value` and `--flag=value` forms).
|
|
97
|
+
* `portExplicit` / `apiPortExplicit` say whether the value came from a valid flag, which decides
|
|
98
|
+
* whether a busy port is an error or an auto-pick.
|
|
99
|
+
* `autostart` is `'on'`, `'off'` or `'invalid'` when the flag was given without a usable value;
|
|
100
|
+
* `null` means the flag was not used.
|
|
101
|
+
*
|
|
102
|
+
* @param {string[]} [args]
|
|
103
|
+
* @returns {{ port: number, apiPort: number, portExplicit: boolean, apiPortExplicit: boolean,
|
|
104
|
+
* open: boolean, rotateToken: boolean, strictPort: boolean, status: boolean,
|
|
105
|
+
* stop: boolean, autostart: 'on'|'off'|'invalid'|null }}
|
|
106
|
+
*/
|
|
107
|
+
export function parseStudioArgs(args = []) {
|
|
108
|
+
const valueOf = (name, fallback) => {
|
|
109
|
+
const eq = args.find((a) => a.startsWith(`${name}=`));
|
|
110
|
+
if (eq) return eq.slice(name.length + 1);
|
|
111
|
+
const i = args.indexOf(name);
|
|
112
|
+
if (i !== -1 && args[i + 1] && !args[i + 1].startsWith('--')) return args[i + 1];
|
|
113
|
+
return fallback;
|
|
114
|
+
};
|
|
115
|
+
const readPort = (name, fallback) => {
|
|
116
|
+
const raw = valueOf(name, null);
|
|
117
|
+
const parsed = Number.parseInt(raw, 10);
|
|
118
|
+
const valid = Number.isInteger(parsed) && parsed > 0 && parsed < 65536;
|
|
119
|
+
return { value: valid ? parsed : fallback, explicit: raw !== null && valid };
|
|
120
|
+
};
|
|
121
|
+
const port = readPort('--port', DEFAULT_PORT);
|
|
122
|
+
const apiPort = readPort('--api-port', DEFAULT_API_PORT);
|
|
123
|
+
const wantsAutostart = args.some((a) => a === '--autostart' || a.startsWith('--autostart='));
|
|
124
|
+
const autostartValue = valueOf('--autostart', null);
|
|
125
|
+
const autostart = wantsAutostart
|
|
126
|
+
? autostartValue === 'on' || autostartValue === 'off'
|
|
127
|
+
? autostartValue
|
|
128
|
+
: 'invalid'
|
|
129
|
+
: null;
|
|
130
|
+
return {
|
|
131
|
+
port: port.value,
|
|
132
|
+
apiPort: apiPort.value,
|
|
133
|
+
portExplicit: port.explicit,
|
|
134
|
+
apiPortExplicit: apiPort.explicit,
|
|
135
|
+
open: !args.includes('--no-open'),
|
|
136
|
+
rotateToken: args.includes('--rotate-token'),
|
|
137
|
+
strictPort: args.includes('--strict-port'),
|
|
138
|
+
status: args.includes('--status'),
|
|
139
|
+
stop: args.includes('--stop'),
|
|
140
|
+
autostart,
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/** Newest mtime (ms) of any file under `dir` (recursive), or 0 when it does not exist. */
|
|
145
|
+
export function newestMtime(dir) {
|
|
146
|
+
if (!existsSync(dir)) return 0;
|
|
147
|
+
let newest = 0;
|
|
148
|
+
const walk = (current) => {
|
|
149
|
+
let entries;
|
|
150
|
+
try {
|
|
151
|
+
entries = readdirSync(current, { withFileTypes: true });
|
|
152
|
+
} catch {
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
for (const entry of entries) {
|
|
156
|
+
const full = join(current, entry.name);
|
|
157
|
+
if (entry.isDirectory()) {
|
|
158
|
+
walk(full);
|
|
159
|
+
} else {
|
|
160
|
+
try {
|
|
161
|
+
const m = statSync(full).mtimeMs;
|
|
162
|
+
if (m > newest) newest = m;
|
|
163
|
+
} catch {
|
|
164
|
+
/* ignore */
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
walk(dir);
|
|
170
|
+
return newest;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* True when `dist/index.html` is missing or older than any source/config file.
|
|
175
|
+
* @param {string} studioDir
|
|
176
|
+
* @returns {boolean}
|
|
177
|
+
*/
|
|
178
|
+
export function isBuildStale(studioDir) {
|
|
179
|
+
const indexHtml = join(studioDir, 'dist', 'index.html');
|
|
180
|
+
if (!existsSync(indexHtml)) return true;
|
|
181
|
+
let builtAt;
|
|
182
|
+
try {
|
|
183
|
+
builtAt = statSync(indexHtml).mtimeMs;
|
|
184
|
+
} catch {
|
|
185
|
+
return true;
|
|
186
|
+
}
|
|
187
|
+
const inputs = [
|
|
188
|
+
newestMtime(join(studioDir, 'src')),
|
|
189
|
+
...['package.json', 'package-lock.json', 'vite.config.js', 'index.html'].map((f) => {
|
|
190
|
+
const p = join(studioDir, f);
|
|
191
|
+
try {
|
|
192
|
+
return existsSync(p) ? statSync(p).mtimeMs : 0;
|
|
193
|
+
} catch {
|
|
194
|
+
return 0;
|
|
195
|
+
}
|
|
196
|
+
}),
|
|
197
|
+
];
|
|
198
|
+
return inputs.some((m) => m > builtAt);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Copy `env`, dropping `CLAUDECODE` and every `CLAUDE_CODE_*` variable.
|
|
203
|
+
* @param {Record<string,string|undefined>} [env]
|
|
204
|
+
* @returns {Record<string,string|undefined>}
|
|
205
|
+
*/
|
|
206
|
+
export function stripAgentEnv(env = process.env) {
|
|
207
|
+
const out = {};
|
|
208
|
+
for (const [key, value] of Object.entries(env)) {
|
|
209
|
+
if (key === 'CLAUDECODE') continue;
|
|
210
|
+
if (key.startsWith('CLAUDE_CODE_')) continue;
|
|
211
|
+
out[key] = value;
|
|
212
|
+
}
|
|
213
|
+
return out;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/** Merge the Studio origins we will serve into any pre-existing `STUDIO_ORIGINS`. */
|
|
217
|
+
export function mergeOrigins(existing, port) {
|
|
218
|
+
const set = new Set(
|
|
219
|
+
String(existing || '')
|
|
220
|
+
.split(',')
|
|
221
|
+
.map((s) => s.trim())
|
|
222
|
+
.filter(Boolean)
|
|
223
|
+
);
|
|
224
|
+
set.add(`http://localhost:${port}`);
|
|
225
|
+
set.add(`http://127.0.0.1:${port}`);
|
|
226
|
+
return [...set].join(',');
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* Build the fragment pairing URL (D-03):
|
|
231
|
+
* <studio-url>/#token=<encoded token>[&bridge=<encoded apiUrl>]
|
|
232
|
+
* The bridge parameter is only present when the API port is not the default 3000. Ports are
|
|
233
|
+
* compared numerically because `parseWebArgs().port` is a string such as `'3000'`.
|
|
234
|
+
*
|
|
235
|
+
* @param {{ studioPort: number|string, apiPort: number|string, token: string }} opts
|
|
236
|
+
* @returns {{ apiUrl: string, studioUrl: string, pairingUrl: string }}
|
|
237
|
+
*/
|
|
238
|
+
export function buildPairingUrl({ studioPort, apiPort, token }) {
|
|
239
|
+
const apiUrl = loopbackUrl(apiPort);
|
|
240
|
+
const studioUrl = loopbackUrl(studioPort);
|
|
241
|
+
let pairingUrl = `${studioUrl}/#token=${encodeURIComponent(token)}`;
|
|
242
|
+
if (Number(apiPort) !== DEFAULT_API_PORT) {
|
|
243
|
+
pairingUrl += `&bridge=${encodeURIComponent(apiUrl)}`;
|
|
244
|
+
}
|
|
245
|
+
return { apiUrl, studioUrl, pairingUrl };
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/** `true` when `port` is busy on that family, `false` when free or the family is unavailable. */
|
|
249
|
+
function probeBind(port, host) {
|
|
250
|
+
return new Promise((resolve) => {
|
|
251
|
+
const server = createNetServer();
|
|
252
|
+
server.once('error', (err) => resolve(err?.code === 'EADDRINUSE'));
|
|
253
|
+
server.listen({ port, host, exclusive: true }, () => {
|
|
254
|
+
server.close(() => resolve(false));
|
|
255
|
+
});
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* True when something already listens on `port` on any loopback family. An IPv4-only listener
|
|
261
|
+
* leaves `::1:<port>` free and vice versa, so both families have to be probed.
|
|
262
|
+
*
|
|
263
|
+
* @param {number|string} port
|
|
264
|
+
* @param {{ hosts?: string[], probe?: (port: number, host: string) => Promise<boolean> }} [opts]
|
|
265
|
+
* @returns {Promise<boolean>}
|
|
266
|
+
*/
|
|
267
|
+
export async function isPortBusy(port, { hosts = LOOPBACK_HOSTS, probe = probeBind } = {}) {
|
|
268
|
+
const states = await Promise.all(hosts.map((host) => probe(Number(port), host)));
|
|
269
|
+
return states.some(Boolean);
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* First port at or above `from` that is free on every loopback family.
|
|
274
|
+
*
|
|
275
|
+
* @param {number} from
|
|
276
|
+
* @param {{ hosts?: string[], maxTries?: number,
|
|
277
|
+
* isBusy?: (port: number, opts?: object) => Promise<boolean> }} [opts]
|
|
278
|
+
* @returns {Promise<number>}
|
|
279
|
+
*/
|
|
280
|
+
export async function findFreePort(
|
|
281
|
+
from,
|
|
282
|
+
{ hosts = LOOPBACK_HOSTS, maxTries = 25, isBusy = isPortBusy } = {}
|
|
283
|
+
) {
|
|
284
|
+
const start = Number(from);
|
|
285
|
+
for (let port = start; port < start + maxTries && port < 65536; port += 1) {
|
|
286
|
+
if (!(await isBusy(port, { hosts }))) return port;
|
|
287
|
+
}
|
|
288
|
+
throw new Error(`No free loopback port between ${start} and ${start + maxTries - 1}.`);
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/**
|
|
292
|
+
* Keep both ports usable before anything binds: a busy default port moves to the next free one,
|
|
293
|
+
* while a busy port the user pinned with a flag is a hard error. `strict` removes the auto-pick
|
|
294
|
+
* entirely, so a LaunchAgent start never changes the URL it was paired on.
|
|
295
|
+
*
|
|
296
|
+
* @param {{ port: number, apiPort: number, portExplicit?: boolean, apiPortExplicit?: boolean,
|
|
297
|
+
* strict?: boolean,
|
|
298
|
+
* isBusy?: (port: number) => Promise<boolean>,
|
|
299
|
+
* findFree?: (from: number) => Promise<number> }} opts
|
|
300
|
+
* @returns {Promise<{ port: number, apiPort: number, notices: string[] }>}
|
|
301
|
+
*/
|
|
302
|
+
export async function resolveStudioPorts({
|
|
303
|
+
port,
|
|
304
|
+
apiPort,
|
|
305
|
+
portExplicit = false,
|
|
306
|
+
apiPortExplicit = false,
|
|
307
|
+
strict = false,
|
|
308
|
+
isBusy = (value) => isPortBusy(value),
|
|
309
|
+
findFree = (from) => findFreePort(from),
|
|
310
|
+
} = {}) {
|
|
311
|
+
const notices = [];
|
|
312
|
+
const pick = async (value, explicit, flag, label) => {
|
|
313
|
+
if (!(await isBusy(value))) return value;
|
|
314
|
+
if (explicit || strict) {
|
|
315
|
+
throw new Error(
|
|
316
|
+
`Port ${value} is already in use on loopback (127.0.0.1 or ::1). ` +
|
|
317
|
+
`Choose another port: --${flag} <free port>.`
|
|
318
|
+
);
|
|
319
|
+
}
|
|
320
|
+
const next = await findFree(value + 1);
|
|
321
|
+
notices.push(`Port ${value} is in use; using ${next} for ${label} instead.`);
|
|
322
|
+
return next;
|
|
323
|
+
};
|
|
324
|
+
const resolvedApiPort = await pick(apiPort, apiPortExplicit, 'api-port', 'the local server');
|
|
325
|
+
const resolvedPort = await pick(port, portExplicit, 'port', 'Studio');
|
|
326
|
+
return { port: resolvedPort, apiPort: resolvedApiPort, notices };
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
/**
|
|
330
|
+
* Resolve the pairing token through the shared helper (D-01/D-02). `repoRoot` is still accepted for
|
|
331
|
+
* tests but only supplies the one-time legacy `web/.studio-token` migration path; the token itself
|
|
332
|
+
* always lives under `PROFESSOR_HOME`.
|
|
333
|
+
*
|
|
334
|
+
* @param {{ repoRoot?: string, env?: Record<string,string|undefined>, home?: string }} [opts]
|
|
335
|
+
* @returns {string}
|
|
336
|
+
*/
|
|
337
|
+
export function resolveStudioToken({ repoRoot = REPO_ROOT, env = process.env, home } = {}) {
|
|
338
|
+
return security.ensureStudioToken({
|
|
339
|
+
env,
|
|
340
|
+
home: home || env.PROFESSOR_HOME,
|
|
341
|
+
legacyFile: security.legacyTokenPath(repoRoot),
|
|
342
|
+
});
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
/**
|
|
346
|
+
* Poll `/api/studio/health` until it answers 200 with the pairing token.
|
|
347
|
+
* A 404 or a JSON body that is not a Studio health payload means another app owns the port.
|
|
348
|
+
* @param {{ url: string, token: string, timeoutMs?: number, intervalMs?: number, fetchImpl?: typeof fetch }} opts
|
|
349
|
+
*/
|
|
350
|
+
export async function waitForHealth({
|
|
351
|
+
url,
|
|
352
|
+
token,
|
|
353
|
+
timeoutMs = 20000,
|
|
354
|
+
intervalMs = 250,
|
|
355
|
+
fetchImpl = globalThis.fetch,
|
|
356
|
+
}) {
|
|
357
|
+
const deadline = Date.now() + timeoutMs;
|
|
358
|
+
let lastError = 'no response';
|
|
359
|
+
let foreign = false;
|
|
360
|
+
while (Date.now() < deadline) {
|
|
361
|
+
try {
|
|
362
|
+
const res = await fetchImpl(url, { headers: { 'X-Studio-Token': token } });
|
|
363
|
+
if (res.ok) {
|
|
364
|
+
const body = await res.json().catch(() => null);
|
|
365
|
+
if (isStudioHealthPayload(body)) return body;
|
|
366
|
+
foreign = true;
|
|
367
|
+
lastError = 'an answer that is not Studio';
|
|
368
|
+
} else {
|
|
369
|
+
if (res.status === 404) foreign = true;
|
|
370
|
+
lastError = `HTTP ${res.status}`;
|
|
371
|
+
}
|
|
372
|
+
} catch (err) {
|
|
373
|
+
lastError = err.message;
|
|
374
|
+
}
|
|
375
|
+
await new Promise((r) => setTimeout(r, intervalMs));
|
|
376
|
+
}
|
|
377
|
+
const port = (() => {
|
|
378
|
+
try {
|
|
379
|
+
return new URL(url).port;
|
|
380
|
+
} catch {
|
|
381
|
+
return '';
|
|
382
|
+
}
|
|
383
|
+
})();
|
|
384
|
+
const hint =
|
|
385
|
+
foreign && port
|
|
386
|
+
? ` Another app is answering on port ${port}; start Studio with --api-port <free port>.`
|
|
387
|
+
: '';
|
|
388
|
+
throw new Error(`Studio server did not become healthy at ${url} (${lastError}).${hint}`);
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
/**
|
|
392
|
+
* Host-validating Studio static server. `bin/static-server.js` itself is not owned by Phase 2, so
|
|
393
|
+
* this thin wrapper rejects a spoofed/missing Host before delegating to its static handler (SEC-03).
|
|
394
|
+
*
|
|
395
|
+
* @param {{ root: string, host?: string, port?: number, extraHosts?: string[] }} opts
|
|
396
|
+
* @returns {Promise<{ server: import('http').Server, url: string, port: number,
|
|
397
|
+
* close: () => Promise<void> }>}
|
|
398
|
+
*/
|
|
399
|
+
export async function createStudioStaticServer({
|
|
400
|
+
root,
|
|
401
|
+
host = '127.0.0.1',
|
|
402
|
+
port = 0,
|
|
403
|
+
extraHosts = [],
|
|
404
|
+
} = {}) {
|
|
405
|
+
const handler = createStaticHandler({ root, spaFallback: true });
|
|
406
|
+
const server = createServer((req, res) => {
|
|
407
|
+
if (!security.isAllowedHost(req.headers?.host, { extraHosts })) {
|
|
408
|
+
res.writeHead(403, { 'Content-Type': 'application/json; charset=utf-8' });
|
|
409
|
+
res.end(JSON.stringify({ ok: false, error: 'Forbidden host', code: 'forbidden_host' }));
|
|
410
|
+
return;
|
|
411
|
+
}
|
|
412
|
+
handler(req, res);
|
|
413
|
+
});
|
|
414
|
+
|
|
415
|
+
await new Promise((resolveListen, reject) => {
|
|
416
|
+
server.once('error', reject);
|
|
417
|
+
server.listen(port, host, () => {
|
|
418
|
+
server.removeListener('error', reject);
|
|
419
|
+
resolveListen();
|
|
420
|
+
});
|
|
421
|
+
});
|
|
422
|
+
|
|
423
|
+
const address = server.address();
|
|
424
|
+
const actualPort = typeof address === 'object' && address ? address.port : port;
|
|
425
|
+
return {
|
|
426
|
+
server,
|
|
427
|
+
port: actualPort,
|
|
428
|
+
url: loopbackUrl(actualPort),
|
|
429
|
+
close: () => new Promise((done) => server.close(() => done())),
|
|
430
|
+
};
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
/** Open a URL in the OS browser. Never throws. */
|
|
434
|
+
export function openBrowser(url, { platform = process.platform, spawnImpl = spawn } = {}) {
|
|
435
|
+
try {
|
|
436
|
+
const child =
|
|
437
|
+
platform === 'darwin'
|
|
438
|
+
? spawnImpl('open', [url], { stdio: 'ignore', detached: true })
|
|
439
|
+
: platform === 'win32'
|
|
440
|
+
? spawnImpl('cmd', ['/c', 'start', '', url], { stdio: 'ignore', detached: true })
|
|
441
|
+
: spawnImpl('xdg-open', [url], { stdio: 'ignore', detached: true });
|
|
442
|
+
child.on?.('error', () => {});
|
|
443
|
+
child.unref?.();
|
|
444
|
+
return true;
|
|
445
|
+
} catch {
|
|
446
|
+
return false;
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
/** True when `pkg` can be resolved from `dir` (or any ancestor `node_modules`, e.g. the root). */
|
|
451
|
+
function canResolveFrom(dir, pkg) {
|
|
452
|
+
try {
|
|
453
|
+
createRequire(join(dir, 'index.js')).resolve(pkg);
|
|
454
|
+
return true;
|
|
455
|
+
} catch {
|
|
456
|
+
return false;
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
/**
|
|
461
|
+
* Install a package's deps only when they are genuinely missing. `probe` short-circuits the install
|
|
462
|
+
* when the dependency already resolves from an ancestor (the root package's own `node_modules`) —
|
|
463
|
+
* which is the case for the web server once `express`/`cors` are root dependencies.
|
|
464
|
+
*/
|
|
465
|
+
function ensureDeps({ dir, label, spinner, probe }) {
|
|
466
|
+
if (probe && canResolveFrom(dir, probe)) return false;
|
|
467
|
+
if (existsSync(join(dir, 'node_modules'))) return false;
|
|
468
|
+
if (!existsSync(join(dir, 'package.json'))) return false;
|
|
469
|
+
spinner.start(`Installing ${label} dependencies…`);
|
|
470
|
+
try {
|
|
471
|
+
execSync('npm install', { cwd: dir, stdio: 'pipe' });
|
|
472
|
+
spinner.succeed(`${label} dependencies installed.`);
|
|
473
|
+
return true;
|
|
474
|
+
} catch (err) {
|
|
475
|
+
spinner.fail(`${label} dependencies failed.`);
|
|
476
|
+
const message = String(err?.message || err);
|
|
477
|
+
if (err?.code === 'EACCES' || /EACCES|permission denied|read-only/i.test(message)) {
|
|
478
|
+
throw new Error(
|
|
479
|
+
`Cannot install ${label} dependencies in ${dir} (permission denied). ` +
|
|
480
|
+
'This happens when the package runs from the read-only npx cache. ' +
|
|
481
|
+
`Install the package globally instead (\`npm i -g ronin-skillforce\`) or re-run with a writable cache.`
|
|
482
|
+
);
|
|
483
|
+
}
|
|
484
|
+
throw new Error(`npm install failed in ${dir}: ${message}`);
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
/**
|
|
489
|
+
* Build `studio/dist` from source — but only from a git checkout. An installed package ships a
|
|
490
|
+
* prebuilt `studio/dist` and has no `studio/src`, so we never attempt a build there.
|
|
491
|
+
*/
|
|
492
|
+
function ensureBuild({ studioDir, spinner }) {
|
|
493
|
+
if (!existsSync(join(studioDir, 'src'))) return false;
|
|
494
|
+
if (!isBuildStale(studioDir)) return false;
|
|
495
|
+
spinner.start('Building Studio (studio/dist)…');
|
|
496
|
+
try {
|
|
497
|
+
execSync('npm run build', { cwd: studioDir, stdio: 'pipe' });
|
|
498
|
+
spinner.succeed('Studio built.');
|
|
499
|
+
return true;
|
|
500
|
+
} catch (err) {
|
|
501
|
+
spinner.fail('Studio build failed.');
|
|
502
|
+
throw new Error(`npm run build failed in ${studioDir}: ${err.message}`);
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
/**
|
|
507
|
+
* `--autostart on|off`, `--status` and `--stop`. None of them starts the Studio server, so they run
|
|
508
|
+
* before the Node 22.5 gate and never import `ora`.
|
|
509
|
+
*
|
|
510
|
+
* @param {{ parsed: object, ctx?: object, style?: Function, repoRoot: string }} opts
|
|
511
|
+
* @returns {Promise<number>} process exit code
|
|
512
|
+
*/
|
|
513
|
+
async function runBackground({ parsed, ctx = {}, style, repoRoot }) {
|
|
514
|
+
const {
|
|
515
|
+
env = process.env,
|
|
516
|
+
userHome,
|
|
517
|
+
platform = process.platform,
|
|
518
|
+
exec = execFileSync,
|
|
519
|
+
kill = process.kill,
|
|
520
|
+
fetchImpl = globalThis.fetch,
|
|
521
|
+
} = ctx;
|
|
522
|
+
const log = (line) => console.log(line);
|
|
523
|
+
const fail = (line) => console.error(style('error', line));
|
|
524
|
+
const show = (file) => displayPath(file, { home: userHome || homedir() });
|
|
525
|
+
|
|
526
|
+
if (parsed.autostart === 'invalid') {
|
|
527
|
+
fail('--autostart needs a value: on or off.');
|
|
528
|
+
return 1;
|
|
529
|
+
}
|
|
530
|
+
if (parsed.autostart && (parsed.status || parsed.stop)) {
|
|
531
|
+
fail('Use --autostart, --status or --stop one at a time.');
|
|
532
|
+
return 1;
|
|
533
|
+
}
|
|
534
|
+
if (parsed.autostart && platform !== 'darwin') {
|
|
535
|
+
fail(UNSUPPORTED_PLATFORM);
|
|
536
|
+
return 1;
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
if (parsed.autostart === 'on') {
|
|
540
|
+
try {
|
|
541
|
+
const ports = await resolveStudioPorts({
|
|
542
|
+
port: parsed.port,
|
|
543
|
+
apiPort: parsed.apiPort,
|
|
544
|
+
portExplicit: parsed.portExplicit,
|
|
545
|
+
apiPortExplicit: parsed.apiPortExplicit,
|
|
546
|
+
strict: true,
|
|
547
|
+
isBusy: ctx.isPortBusy,
|
|
548
|
+
findFree: ctx.findFreePort,
|
|
549
|
+
});
|
|
550
|
+
const { logPath } = enableAutostart({
|
|
551
|
+
port: ports.port,
|
|
552
|
+
apiPort: ports.apiPort,
|
|
553
|
+
cliPath: join(repoRoot, 'bin', 'cli.js'),
|
|
554
|
+
execPath: ctx.execPath,
|
|
555
|
+
env,
|
|
556
|
+
userHome,
|
|
557
|
+
platform,
|
|
558
|
+
exec,
|
|
559
|
+
uid: ctx.uid,
|
|
560
|
+
});
|
|
561
|
+
log(style('success', `Studio will start at login (${LABEL}).`));
|
|
562
|
+
log(` Studio URL: ${loopbackUrl(ports.port)}`);
|
|
563
|
+
log(` Log: ${show(logPath)}`);
|
|
564
|
+
return 0;
|
|
565
|
+
} catch (err) {
|
|
566
|
+
fail(err.message);
|
|
567
|
+
return 1;
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
if (parsed.autostart === 'off') {
|
|
572
|
+
try {
|
|
573
|
+
const { plistPath, removed } = disableAutostart({ userHome, platform, exec, uid: ctx.uid });
|
|
574
|
+
log(
|
|
575
|
+
removed
|
|
576
|
+
? `Studio will no longer start at login (removed ${show(plistPath)}).`
|
|
577
|
+
: 'Studio auto-start was already off.'
|
|
578
|
+
);
|
|
579
|
+
return 0;
|
|
580
|
+
} catch (err) {
|
|
581
|
+
fail(err.message);
|
|
582
|
+
return 1;
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
if (parsed.status) {
|
|
587
|
+
const report = await collectStatus({ env, userHome, kill, fetchImpl });
|
|
588
|
+
const pairingUrl =
|
|
589
|
+
report.token && report.state?.port && report.state?.apiPort
|
|
590
|
+
? buildPairingUrl({
|
|
591
|
+
studioPort: report.state.port,
|
|
592
|
+
apiPort: report.state.apiPort,
|
|
593
|
+
token: report.token,
|
|
594
|
+
}).pairingUrl
|
|
595
|
+
: null;
|
|
596
|
+
log(formatStatus({ ...report, pairingUrl, userHome: userHome || homedir() }));
|
|
597
|
+
return report.status === 'running' ? 0 : 1;
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
if (parsed.stop) {
|
|
601
|
+
const result = await stopStudio({ env, userHome, platform, exec, uid: ctx.uid, kill });
|
|
602
|
+
if (result.refused) {
|
|
603
|
+
fail(`Refusing to stop pid ${result.pid}: it is not a Studio process.`);
|
|
604
|
+
return 1;
|
|
605
|
+
}
|
|
606
|
+
if (result.stopped) {
|
|
607
|
+
log(
|
|
608
|
+
result.via === 'launchctl'
|
|
609
|
+
? 'Stopped Studio (launchd agent).'
|
|
610
|
+
: `Stopped Studio (pid ${result.pid}).`
|
|
611
|
+
);
|
|
612
|
+
return 0;
|
|
613
|
+
}
|
|
614
|
+
if (result.reason === 'stale') {
|
|
615
|
+
log(`Studio is not running (removed a stale studio.json for pid ${result.pid}).`);
|
|
616
|
+
} else {
|
|
617
|
+
log('Studio is not running.');
|
|
618
|
+
}
|
|
619
|
+
return 0;
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
return 1;
|
|
623
|
+
}
|
|
624
|
+
|
|
625
|
+
/**
|
|
626
|
+
* @param {{ args?: string[], cwd?: string, chalk?: object, style?: Function, repoRoot?: string,
|
|
627
|
+
* ora?: Function, spawnImpl?: typeof spawn, fetchImpl?: typeof fetch,
|
|
628
|
+
* openImpl?: typeof openBrowser, nodeVersion?: string,
|
|
629
|
+
* isPortBusy?: (port: number) => Promise<boolean>,
|
|
630
|
+
* findFreePort?: (from: number) => Promise<number> }} [ctx]
|
|
631
|
+
*/
|
|
632
|
+
export async function run(ctx = {}) {
|
|
633
|
+
const {
|
|
634
|
+
args = [],
|
|
635
|
+
chalk,
|
|
636
|
+
style = (t, m) => m,
|
|
637
|
+
repoRoot = REPO_ROOT,
|
|
638
|
+
spawnImpl = spawn,
|
|
639
|
+
fetchImpl = globalThis.fetch,
|
|
640
|
+
openImpl = openBrowser,
|
|
641
|
+
} = ctx;
|
|
642
|
+
|
|
643
|
+
if (wantsHelp(args)) {
|
|
644
|
+
console.log(STUDIO_USAGE);
|
|
645
|
+
return 0;
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
const parsed = parseStudioArgs(args);
|
|
649
|
+
if (parsed.autostart || parsed.status || parsed.stop) {
|
|
650
|
+
return runBackground({ parsed, ctx, style, repoRoot });
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
requireStudioNode(ctx.nodeVersion);
|
|
654
|
+
|
|
655
|
+
const ora = ctx.ora || (await import('ora')).default;
|
|
656
|
+
const { open, rotateToken } = parsed;
|
|
657
|
+
let { port, apiPort } = parsed;
|
|
658
|
+
|
|
659
|
+
const hasStartRequest = args.some((arg) => arg !== '--rotate-token');
|
|
660
|
+
let rotatedToken = null;
|
|
661
|
+
if (rotateToken) {
|
|
662
|
+
try {
|
|
663
|
+
rotatedToken = security.rotateStudioToken({ env: process.env });
|
|
664
|
+
} catch (err) {
|
|
665
|
+
if (err.code === 'env_token_immutable') {
|
|
666
|
+
console.error(style('error', err.message));
|
|
667
|
+
} else {
|
|
668
|
+
console.error(style('error', `Could not rotate token: ${err.message}`));
|
|
669
|
+
}
|
|
670
|
+
throw err;
|
|
671
|
+
}
|
|
672
|
+
const { pairingUrl } = buildPairingUrl({ studioPort: port, apiPort, token: rotatedToken });
|
|
673
|
+
console.log('');
|
|
674
|
+
console.log(` Pairing token: ${security.maskToken(rotatedToken)}`);
|
|
675
|
+
console.log(` Pairing URL: ${pairingUrl}`);
|
|
676
|
+
console.log('');
|
|
677
|
+
if (!hasStartRequest) return 0;
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
const webDir = join(repoRoot, 'web');
|
|
681
|
+
const studioDir = join(repoRoot, 'studio');
|
|
682
|
+
const serverEntry = join(webDir, 'server.js');
|
|
683
|
+
const distDir = join(studioDir, 'dist');
|
|
684
|
+
const studioHasSource = existsSync(join(studioDir, 'src'));
|
|
685
|
+
|
|
686
|
+
if (!existsSync(serverEntry)) {
|
|
687
|
+
throw new Error(`Local server not found at ${serverEntry}. Is the package installed fully?`);
|
|
688
|
+
}
|
|
689
|
+
|
|
690
|
+
const portOptions = {
|
|
691
|
+
port,
|
|
692
|
+
apiPort,
|
|
693
|
+
portExplicit: parsed.portExplicit,
|
|
694
|
+
apiPortExplicit: parsed.apiPortExplicit,
|
|
695
|
+
strict: parsed.strictPort,
|
|
696
|
+
isBusy: ctx.isPortBusy,
|
|
697
|
+
findFree: ctx.findFreePort,
|
|
698
|
+
};
|
|
699
|
+
let ports;
|
|
700
|
+
try {
|
|
701
|
+
ports = await resolveStudioPorts(portOptions);
|
|
702
|
+
} catch (err) {
|
|
703
|
+
// The LaunchAgent run has no terminal: one readable line in the log beats a stack trace.
|
|
704
|
+
if (!parsed.strictPort) throw err;
|
|
705
|
+
console.error(style('error', err.message));
|
|
706
|
+
return 1;
|
|
707
|
+
}
|
|
708
|
+
port = ports.port;
|
|
709
|
+
apiPort = ports.apiPort;
|
|
710
|
+
for (const notice of ports.notices) {
|
|
711
|
+
console.log(style('warning', notice));
|
|
712
|
+
}
|
|
713
|
+
|
|
714
|
+
console.log('');
|
|
715
|
+
const setupSpinner = ora('Preparing local platform…');
|
|
716
|
+
// `express`/`cors` are root dependencies, so the web server runs without a nested install. This
|
|
717
|
+
// stays as a fallback for a checkout that has `web/package.json` but no resolvable deps.
|
|
718
|
+
ensureDeps({ dir: webDir, label: 'web', spinner: setupSpinner, probe: 'express' });
|
|
719
|
+
if (studioHasSource) {
|
|
720
|
+
ensureDeps({ dir: studioDir, label: 'studio', spinner: setupSpinner });
|
|
721
|
+
}
|
|
722
|
+
ensureBuild({ studioDir, spinner: setupSpinner });
|
|
723
|
+
setupSpinner.stop();
|
|
724
|
+
|
|
725
|
+
if (!existsSync(join(distDir, 'index.html'))) {
|
|
726
|
+
throw new Error(`Studio build missing at ${distDir}. Run: cd ${studioDir} && npm run build`);
|
|
727
|
+
}
|
|
728
|
+
|
|
729
|
+
const token = rotatedToken || resolveStudioToken({ repoRoot });
|
|
730
|
+
const { apiUrl, studioUrl, pairingUrl } = buildPairingUrl({ studioPort: port, apiPort, token });
|
|
731
|
+
|
|
732
|
+
const env = stripAgentEnv(process.env);
|
|
733
|
+
env.NODE_ENV = 'production';
|
|
734
|
+
env.PORT = String(apiPort);
|
|
735
|
+
if (process.env.STUDIO_BRIDGE_TOKEN) {
|
|
736
|
+
env.STUDIO_BRIDGE_TOKEN = process.env.STUDIO_BRIDGE_TOKEN;
|
|
737
|
+
}
|
|
738
|
+
env.STUDIO_ORIGINS = mergeOrigins(process.env.STUDIO_ORIGINS, port);
|
|
739
|
+
|
|
740
|
+
const serverSpinner = ora(`Starting local server on ${apiUrl}…`).start();
|
|
741
|
+
const apiChild = spawnImpl(process.execPath, [serverEntry], {
|
|
742
|
+
cwd: webDir,
|
|
743
|
+
env,
|
|
744
|
+
stdio: ['ignore', 'inherit', 'inherit'],
|
|
745
|
+
});
|
|
746
|
+
|
|
747
|
+
let staticServer = null;
|
|
748
|
+
let shuttingDown = false;
|
|
749
|
+
let resolveDone;
|
|
750
|
+
const done = new Promise((resolve) => {
|
|
751
|
+
resolveDone = resolve;
|
|
752
|
+
});
|
|
753
|
+
|
|
754
|
+
const shutdown = async (code = 0) => {
|
|
755
|
+
if (shuttingDown) return;
|
|
756
|
+
shuttingDown = true;
|
|
757
|
+
try { removeState(); } catch { /* best effort */ }
|
|
758
|
+
try { apiChild.kill('SIGTERM'); } catch { /* already gone */ }
|
|
759
|
+
if (staticServer) {
|
|
760
|
+
try { await staticServer.close(); } catch { /* ignore */ }
|
|
761
|
+
}
|
|
762
|
+
process.off('SIGINT', onSignal);
|
|
763
|
+
process.off('SIGTERM', onSignal);
|
|
764
|
+
resolveDone(code);
|
|
765
|
+
};
|
|
766
|
+
const onSignal = () => {
|
|
767
|
+
console.log('');
|
|
768
|
+
console.log(style('info', 'Stopping Professor Studio…'));
|
|
769
|
+
shutdown(0);
|
|
770
|
+
};
|
|
771
|
+
process.on('SIGINT', onSignal);
|
|
772
|
+
process.on('SIGTERM', onSignal);
|
|
773
|
+
|
|
774
|
+
apiChild.on('error', (err) => {
|
|
775
|
+
serverSpinner.fail('Local server failed to start.');
|
|
776
|
+
console.error(style('error', `Could not start the local server: ${err.message}`));
|
|
777
|
+
shutdown(1);
|
|
778
|
+
});
|
|
779
|
+
apiChild.on('exit', (code) => {
|
|
780
|
+
if (!shuttingDown) {
|
|
781
|
+
serverSpinner.fail(`Local server exited (code ${code ?? 0}).`);
|
|
782
|
+
shutdown(code ?? 1);
|
|
783
|
+
}
|
|
784
|
+
});
|
|
785
|
+
|
|
786
|
+
const extraHosts = security.resolveExtraHosts({ env: process.env, host: process.env.HOST });
|
|
787
|
+
try {
|
|
788
|
+
staticServer = await createStudioStaticServer({ root: distDir, port, extraHosts });
|
|
789
|
+
} catch (err) {
|
|
790
|
+
serverSpinner.fail('Could not serve Studio.');
|
|
791
|
+
console.error(style('error', `Static server failed on port ${port}: ${err.message}`));
|
|
792
|
+
await shutdown(1);
|
|
793
|
+
return done;
|
|
794
|
+
}
|
|
795
|
+
|
|
796
|
+
try {
|
|
797
|
+
await waitForHealth({ url: `${apiUrl}${HEALTH_PATH}`, token, fetchImpl });
|
|
798
|
+
serverSpinner.succeed(`Local server ready at ${apiUrl}`);
|
|
799
|
+
} catch (err) {
|
|
800
|
+
serverSpinner.fail('Local server did not become healthy.');
|
|
801
|
+
console.error(style('error', err.message));
|
|
802
|
+
await shutdown(1);
|
|
803
|
+
return done;
|
|
804
|
+
}
|
|
805
|
+
|
|
806
|
+
try {
|
|
807
|
+
writeState(
|
|
808
|
+
{
|
|
809
|
+
pid: process.pid,
|
|
810
|
+
port,
|
|
811
|
+
apiPort,
|
|
812
|
+
studioUrl,
|
|
813
|
+
apiUrl,
|
|
814
|
+
startedAt: new Date().toISOString(),
|
|
815
|
+
},
|
|
816
|
+
{ env: process.env }
|
|
817
|
+
);
|
|
818
|
+
} catch (err) {
|
|
819
|
+
console.log(style('warning', `Could not record studio.json: ${err.message}`));
|
|
820
|
+
}
|
|
821
|
+
|
|
822
|
+
console.log('');
|
|
823
|
+
console.log(style('success', `Professor Studio is running at ${studioUrl}`));
|
|
824
|
+
console.log(` Pairing URL: ${pairingUrl}`);
|
|
825
|
+
console.log(style('info', 'Press Ctrl+C to stop'));
|
|
826
|
+
console.log('');
|
|
827
|
+
|
|
828
|
+
if (open) openImpl(pairingUrl);
|
|
829
|
+
|
|
830
|
+
return done;
|
|
831
|
+
}
|