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
package/web/security.js
ADDED
|
@@ -0,0 +1,1016 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* security.js — the single home for Phase 2 security helpers.
|
|
3
|
+
*
|
|
4
|
+
* This module is deliberately pure-ish: it owns token file operations, path containment and the
|
|
5
|
+
* Host/Origin/JSON/env/argv predicates. It does not install Express middleware or open sockets, so
|
|
6
|
+
* every later plan composes the same tested contract.
|
|
7
|
+
*
|
|
8
|
+
* Token resolution order (D-01): `STUDIO_BRIDGE_TOKEN` -> existing token file -> one-time legacy
|
|
9
|
+
* migration -> a freshly generated 24-byte hex token. Every write re-applies mode `0600`.
|
|
10
|
+
*/
|
|
11
|
+
import { randomBytes } from 'crypto';
|
|
12
|
+
import {
|
|
13
|
+
chmodSync,
|
|
14
|
+
closeSync,
|
|
15
|
+
existsSync,
|
|
16
|
+
constants as fsConstants,
|
|
17
|
+
lstatSync,
|
|
18
|
+
mkdirSync,
|
|
19
|
+
openSync,
|
|
20
|
+
readFileSync,
|
|
21
|
+
readdirSync,
|
|
22
|
+
realpathSync,
|
|
23
|
+
renameSync,
|
|
24
|
+
rmSync,
|
|
25
|
+
statSync,
|
|
26
|
+
writeFileSync,
|
|
27
|
+
} from 'fs';
|
|
28
|
+
import { homedir } from 'os';
|
|
29
|
+
import { basename, dirname, isAbsolute, join, resolve, sep } from 'path';
|
|
30
|
+
|
|
31
|
+
/* ------------------------------------------------------------------ token lifecycle */
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Default token root. Kept as an exported constant for compatibility, but every helper accepts an
|
|
35
|
+
* explicit `home`/`env.PROFESSOR_HOME` and never falls back to this value when one is supplied.
|
|
36
|
+
*/
|
|
37
|
+
export const PROFESSOR_HOME =
|
|
38
|
+
process.env.PROFESSOR_HOME || join(homedir(), '.professor');
|
|
39
|
+
|
|
40
|
+
/** Resolve a token root without consulting the real home when the caller supplied one. */
|
|
41
|
+
function resolveHome({ env = {}, home } = {}) {
|
|
42
|
+
return home || env.PROFESSOR_HOME || join(homedir(), '.professor');
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Absolute path of the pairing token file.
|
|
47
|
+
* @param {Record<string, string|undefined>} [env]
|
|
48
|
+
* @returns {string}
|
|
49
|
+
*/
|
|
50
|
+
export function tokenFilePath(env = process.env) {
|
|
51
|
+
return join(resolveHome({ env }), 'studio-token');
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Legacy token path (`web/.studio-token`) for a repository root.
|
|
56
|
+
* @param {string} repoRoot
|
|
57
|
+
* @returns {string}
|
|
58
|
+
*/
|
|
59
|
+
export function legacyTokenPath(repoRoot) {
|
|
60
|
+
return join(repoRoot, 'web', '.studio-token');
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Read a token file without ever writing to it. Returns `null` when missing or empty.
|
|
65
|
+
* @param {string} file
|
|
66
|
+
* @returns {string|null}
|
|
67
|
+
*/
|
|
68
|
+
export function readTokenFile(file) {
|
|
69
|
+
try {
|
|
70
|
+
const token = readFileSync(file, 'utf-8').trim();
|
|
71
|
+
return token || null;
|
|
72
|
+
} catch {
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Atomically write a token file with mode `0600` (mode is re-applied even when the file existed).
|
|
79
|
+
* @param {string} file
|
|
80
|
+
* @param {string} token
|
|
81
|
+
* @returns {string} the file path
|
|
82
|
+
*/
|
|
83
|
+
export function writeTokenFile(file, token) {
|
|
84
|
+
const dir = dirname(file);
|
|
85
|
+
mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
86
|
+
try {
|
|
87
|
+
chmodSync(dir, 0o700);
|
|
88
|
+
} catch {
|
|
89
|
+
/* best effort: existing directories may be owned differently on exotic platforms */
|
|
90
|
+
}
|
|
91
|
+
const tmp = join(
|
|
92
|
+
dir,
|
|
93
|
+
`.studio-token.${process.pid}.${Date.now()}.${randomBytes(4).toString('hex')}.tmp`
|
|
94
|
+
);
|
|
95
|
+
try {
|
|
96
|
+
writeFileSync(tmp, `${token}\n`, { mode: 0o600 });
|
|
97
|
+
chmodSync(tmp, 0o600);
|
|
98
|
+
renameSync(tmp, file);
|
|
99
|
+
chmodSync(file, 0o600);
|
|
100
|
+
} catch (err) {
|
|
101
|
+
try {
|
|
102
|
+
rmSync(tmp, { force: true });
|
|
103
|
+
} catch {
|
|
104
|
+
/* ignore */
|
|
105
|
+
}
|
|
106
|
+
throw err;
|
|
107
|
+
}
|
|
108
|
+
return file;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Migrate a legacy `web/.studio-token` exactly once (D-02).
|
|
113
|
+
*
|
|
114
|
+
* Runs only when there is no env override and no new token file. The new file is written before the
|
|
115
|
+
* legacy file is deleted; when the new file already exists the legacy file is left untouched.
|
|
116
|
+
* @param {{ env?: Record<string,string|undefined>, legacyFile?: string, file?: string }} [opts]
|
|
117
|
+
* @returns {string|null}
|
|
118
|
+
*/
|
|
119
|
+
export function migrateLegacyToken({ env = {}, legacyFile, file } = {}) {
|
|
120
|
+
if (env.STUDIO_BRIDGE_TOKEN) return null;
|
|
121
|
+
if (!legacyFile || !file) return null;
|
|
122
|
+
if (existsSync(file)) return null;
|
|
123
|
+
const token = readTokenFile(legacyFile);
|
|
124
|
+
if (!token) return null;
|
|
125
|
+
writeTokenFile(file, token);
|
|
126
|
+
try {
|
|
127
|
+
rmSync(legacyFile, { force: true });
|
|
128
|
+
} catch {
|
|
129
|
+
/* best effort: the new token is already persisted */
|
|
130
|
+
}
|
|
131
|
+
return token;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Resolve the pairing token, generating and persisting it only when necessary.
|
|
136
|
+
* @param {{ env?: Record<string,string|undefined>, home?: string, legacyFile?: string,
|
|
137
|
+
* log?: (...a:any[])=>void }} [opts]
|
|
138
|
+
* @returns {string}
|
|
139
|
+
*/
|
|
140
|
+
export function ensureStudioToken({ env = process.env, home, legacyFile, log } = {}) {
|
|
141
|
+
if (env.STUDIO_BRIDGE_TOKEN) return env.STUDIO_BRIDGE_TOKEN;
|
|
142
|
+
|
|
143
|
+
const root = resolveHome({ env, home });
|
|
144
|
+
const file = join(root, 'studio-token');
|
|
145
|
+
|
|
146
|
+
const existing = readTokenFile(file);
|
|
147
|
+
if (existing) {
|
|
148
|
+
try {
|
|
149
|
+
chmodSync(file, 0o600);
|
|
150
|
+
} catch (err) {
|
|
151
|
+
log?.(`Warning: could not chmod ${file}: ${err.message}`);
|
|
152
|
+
}
|
|
153
|
+
return existing;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
const migrated = migrateLegacyToken({ env, legacyFile, file });
|
|
157
|
+
if (migrated) return migrated;
|
|
158
|
+
|
|
159
|
+
const token = randomBytes(24).toString('hex');
|
|
160
|
+
try {
|
|
161
|
+
writeTokenFile(file, token);
|
|
162
|
+
} catch (err) {
|
|
163
|
+
log?.(`Warning: could not write ${file}: ${err.message}`);
|
|
164
|
+
}
|
|
165
|
+
return token;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Fixed-width first-four/last-four mask. Never returns the full token (D-05).
|
|
170
|
+
* @param {string} token
|
|
171
|
+
* @returns {string}
|
|
172
|
+
*/
|
|
173
|
+
export function maskToken(token) {
|
|
174
|
+
if (typeof token !== 'string' || token.length === 0) return '••••';
|
|
175
|
+
if (token.length <= 8) return '•'.repeat(token.length);
|
|
176
|
+
return `${token.slice(0, 4)}…${token.slice(-4)}`;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Create a cached getter that re-reads the token file when `mtimeMs`/`size` change (D-23).
|
|
181
|
+
* @param {{ env?: Record<string,string|undefined>, home?: string, legacyFile?: string,
|
|
182
|
+
* log?: (...a:any[])=>void }} [opts]
|
|
183
|
+
* @returns {() => string}
|
|
184
|
+
*/
|
|
185
|
+
export function createTokenGetter({ env = process.env, home, legacyFile, log } = {}) {
|
|
186
|
+
const root = resolveHome({ env, home });
|
|
187
|
+
const file = join(root, 'studio-token');
|
|
188
|
+
let cache = null;
|
|
189
|
+
|
|
190
|
+
return function getToken() {
|
|
191
|
+
if (env.STUDIO_BRIDGE_TOKEN) return env.STUDIO_BRIDGE_TOKEN;
|
|
192
|
+
|
|
193
|
+
let info = null;
|
|
194
|
+
try {
|
|
195
|
+
info = statSync(file);
|
|
196
|
+
} catch {
|
|
197
|
+
info = null;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
if (cache && info && cache.mtimeMs === info.mtimeMs && cache.size === info.size) {
|
|
201
|
+
return cache.token;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
const token = readTokenFile(file);
|
|
205
|
+
if (token && info) {
|
|
206
|
+
cache = { token, mtimeMs: info.mtimeMs, size: info.size };
|
|
207
|
+
return token;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
const created = ensureStudioToken({ env, home, legacyFile, log });
|
|
211
|
+
try {
|
|
212
|
+
const after = statSync(file);
|
|
213
|
+
cache = { token: created, mtimeMs: after.mtimeMs, size: after.size };
|
|
214
|
+
} catch {
|
|
215
|
+
cache = { token: created, mtimeMs: 0, size: 0 };
|
|
216
|
+
}
|
|
217
|
+
return created;
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* Generate and atomically persist a new token. Refuses when `STUDIO_BRIDGE_TOKEN` is set (D-23).
|
|
223
|
+
* @param {{ env?: Record<string,string|undefined>, home?: string, legacyFile?: string,
|
|
224
|
+
* log?: (...a:any[])=>void }} [opts]
|
|
225
|
+
* @returns {string}
|
|
226
|
+
*/
|
|
227
|
+
export function rotateStudioToken({ env = process.env, home } = {}) {
|
|
228
|
+
if (env.STUDIO_BRIDGE_TOKEN) {
|
|
229
|
+
const err = new Error('STUDIO_BRIDGE_TOKEN is set; environment tokens cannot be rotated');
|
|
230
|
+
err.code = 'env_token_immutable';
|
|
231
|
+
throw err;
|
|
232
|
+
}
|
|
233
|
+
const root = resolveHome({ env, home });
|
|
234
|
+
const file = join(root, 'studio-token');
|
|
235
|
+
const token = randomBytes(24).toString('hex');
|
|
236
|
+
writeTokenFile(file, token);
|
|
237
|
+
return token;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/* ------------------------------------------------------------------ path containment */
|
|
241
|
+
|
|
242
|
+
const CONTROL_CHARS = /[\u0000-\u001f\u007f]/;
|
|
243
|
+
const COURSE_FILES = new Set(['COURSE.md', 'LECTURE.md', 'NOTES.md', 'CAPSTONE.md']);
|
|
244
|
+
const EXERCISE_FILENAME = /^[A-Za-z0-9][A-Za-z0-9._-]*\.md$/;
|
|
245
|
+
const SLUG = /^[a-z0-9][a-z0-9-]*$/;
|
|
246
|
+
const WINDOWS_DRIVE = /^[A-Za-z]:[\\/]/;
|
|
247
|
+
|
|
248
|
+
function unsafePath(message) {
|
|
249
|
+
const err = new Error(message);
|
|
250
|
+
err.code = 'unsafe_path';
|
|
251
|
+
return err;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* @param {unknown} slug
|
|
256
|
+
* @returns {boolean}
|
|
257
|
+
*/
|
|
258
|
+
export function isSafeSlug(slug) {
|
|
259
|
+
return (
|
|
260
|
+
typeof slug === 'string' &&
|
|
261
|
+
slug.length > 0 &&
|
|
262
|
+
slug.length <= 120 &&
|
|
263
|
+
SLUG.test(slug)
|
|
264
|
+
);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* @param {unknown} file
|
|
269
|
+
* @returns {boolean}
|
|
270
|
+
*/
|
|
271
|
+
export function isSafeCourseFile(file) {
|
|
272
|
+
return typeof file === 'string' && COURSE_FILES.has(file);
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* @param {unknown} filename
|
|
277
|
+
* @returns {boolean}
|
|
278
|
+
*/
|
|
279
|
+
export function isSafeExerciseFilename(filename) {
|
|
280
|
+
return (
|
|
281
|
+
typeof filename === 'string' &&
|
|
282
|
+
filename.length > 0 &&
|
|
283
|
+
filename.length <= 200 &&
|
|
284
|
+
!filename.includes('..') &&
|
|
285
|
+
EXERCISE_FILENAME.test(filename)
|
|
286
|
+
);
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
/**
|
|
290
|
+
* @param {unknown} relPath
|
|
291
|
+
* @returns {boolean}
|
|
292
|
+
*/
|
|
293
|
+
export function isSafeWorkspaceRelPath(relPath) {
|
|
294
|
+
if (typeof relPath !== 'string') return false;
|
|
295
|
+
if (!relPath || relPath.length > 512) return false;
|
|
296
|
+
if (CONTROL_CHARS.test(relPath)) return false;
|
|
297
|
+
if (relPath.startsWith('/') || relPath.startsWith('~')) return false;
|
|
298
|
+
if (WINDOWS_DRIVE.test(relPath)) return false;
|
|
299
|
+
if (relPath.includes('\\')) return false;
|
|
300
|
+
if (relPath.endsWith('/')) return false;
|
|
301
|
+
return relPath.split('/').every((seg) => seg !== '' && seg !== '.' && seg !== '..');
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
/** True when `child` is `parent` or nested inside it (case-sensitive lexical check). */
|
|
305
|
+
function isWithin(child, parent) {
|
|
306
|
+
if (child === parent) return true;
|
|
307
|
+
const prefix = parent.endsWith(sep) ? parent : parent + sep;
|
|
308
|
+
return child.startsWith(prefix);
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
/** Decode one URL-encoded segment and re-validate it; throws on any unsafe form. */
|
|
312
|
+
function decodeSegment(segment) {
|
|
313
|
+
if (typeof segment !== 'string') throw unsafePath('Unsafe path segment: not a string');
|
|
314
|
+
if (!segment) throw unsafePath('Unsafe path segment: empty');
|
|
315
|
+
if (CONTROL_CHARS.test(segment)) throw unsafePath('Unsafe path segment: control character');
|
|
316
|
+
|
|
317
|
+
let decoded;
|
|
318
|
+
try {
|
|
319
|
+
decoded = decodeURIComponent(segment);
|
|
320
|
+
} catch {
|
|
321
|
+
throw unsafePath(`Unsafe path segment: ${segment}`);
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
if (!decoded) throw unsafePath('Unsafe path segment: empty');
|
|
325
|
+
if (CONTROL_CHARS.test(decoded)) throw unsafePath('Unsafe path segment: control character');
|
|
326
|
+
if (decoded.includes('%')) throw unsafePath(`Unsafe path segment: ${segment}`);
|
|
327
|
+
if (decoded.includes('/') || decoded.includes('\\')) {
|
|
328
|
+
throw unsafePath(`Unsafe path segment: ${segment}`);
|
|
329
|
+
}
|
|
330
|
+
if (decoded === '.' || decoded === '..') throw unsafePath(`Unsafe path segment: ${decoded}`);
|
|
331
|
+
if (decoded.startsWith('~')) throw unsafePath(`Unsafe path segment: ${segment}`);
|
|
332
|
+
if (isAbsolute(decoded) || WINDOWS_DRIVE.test(decoded)) {
|
|
333
|
+
throw unsafePath(`Unsafe path segment: ${segment}`);
|
|
334
|
+
}
|
|
335
|
+
return decoded;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
/** Realpath of `p`, or of its nearest existing ancestor with the missing suffix re-appended. */
|
|
339
|
+
function realpathOfNearest(p) {
|
|
340
|
+
let current = resolve(p);
|
|
341
|
+
const missing = [];
|
|
342
|
+
while (true) {
|
|
343
|
+
try {
|
|
344
|
+
return { real: realpathSync.native(current), missing };
|
|
345
|
+
} catch (err) {
|
|
346
|
+
if (err.code !== 'ENOENT' && err.code !== 'ENOTDIR') throw err;
|
|
347
|
+
const parent = dirname(current);
|
|
348
|
+
if (parent === current) {
|
|
349
|
+
return { real: current, missing };
|
|
350
|
+
}
|
|
351
|
+
missing.unshift(basename(current));
|
|
352
|
+
current = parent;
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
/**
|
|
358
|
+
* Resolve `segments` under `root`, rejecting lexical, encoded, backslash, absolute and symlink
|
|
359
|
+
* escapes for both reads and writes.
|
|
360
|
+
* @param {string} root
|
|
361
|
+
* @param {...string} segments
|
|
362
|
+
* @returns {string} absolute path safely inside `root`
|
|
363
|
+
*/
|
|
364
|
+
export function resolveInside(root, ...segments) {
|
|
365
|
+
if (typeof root !== 'string' || !root) throw unsafePath('Unsafe path root');
|
|
366
|
+
if (CONTROL_CHARS.test(root)) throw unsafePath('Unsafe path root');
|
|
367
|
+
|
|
368
|
+
const absoluteRoot = resolve(root);
|
|
369
|
+
const decoded = segments.map(decodeSegment);
|
|
370
|
+
const candidate = resolve(absoluteRoot, ...decoded);
|
|
371
|
+
|
|
372
|
+
if (candidate !== absoluteRoot && !candidate.startsWith(absoluteRoot + sep)) {
|
|
373
|
+
throw unsafePath(`Refusing to resolve outside root: ${segments.join('/')}`);
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
const { real: realBase } = realpathOfNearest(absoluteRoot);
|
|
377
|
+
|
|
378
|
+
let probe = candidate;
|
|
379
|
+
while (true) {
|
|
380
|
+
let info;
|
|
381
|
+
try {
|
|
382
|
+
info = lstatSync(probe);
|
|
383
|
+
} catch {
|
|
384
|
+
info = null;
|
|
385
|
+
}
|
|
386
|
+
if (info) {
|
|
387
|
+
if (probe === candidate && info.isSymbolicLink()) {
|
|
388
|
+
throw unsafePath(`Refusing to follow symlink: ${candidate}`);
|
|
389
|
+
}
|
|
390
|
+
const realProbe = realpathSync.native(probe);
|
|
391
|
+
if (!isWithin(realProbe, realBase)) {
|
|
392
|
+
throw unsafePath(`Refusing to resolve outside root: ${candidate}`);
|
|
393
|
+
}
|
|
394
|
+
break;
|
|
395
|
+
}
|
|
396
|
+
const parent = dirname(probe);
|
|
397
|
+
if (parent === probe) break;
|
|
398
|
+
probe = parent;
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
return candidate;
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
/**
|
|
405
|
+
* Safely write `content` to `segments` under `root`. Directories are created only after every
|
|
406
|
+
* containment check passes; the last component is opened with `O_NOFOLLOW` where available.
|
|
407
|
+
* @param {string} root
|
|
408
|
+
* @param {string[]|string} segments
|
|
409
|
+
* @param {string} content
|
|
410
|
+
* @returns {string} the written path
|
|
411
|
+
*/
|
|
412
|
+
export function safeWriteFile(root, segments, content) {
|
|
413
|
+
const parts = Array.isArray(segments) ? segments : [segments];
|
|
414
|
+
const target = resolveInside(root, ...parts);
|
|
415
|
+
mkdirSync(dirname(target), { recursive: true, mode: 0o700 });
|
|
416
|
+
|
|
417
|
+
const flags =
|
|
418
|
+
fsConstants.O_WRONLY |
|
|
419
|
+
fsConstants.O_CREAT |
|
|
420
|
+
fsConstants.O_TRUNC |
|
|
421
|
+
(fsConstants.O_NOFOLLOW || 0);
|
|
422
|
+
let fd;
|
|
423
|
+
try {
|
|
424
|
+
fd = openSync(target, flags, 0o600);
|
|
425
|
+
writeFileSync(fd, content);
|
|
426
|
+
} finally {
|
|
427
|
+
if (fd !== undefined) closeSync(fd);
|
|
428
|
+
}
|
|
429
|
+
return target;
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
/* ------------------------------------------------------------------ Host and Origin */
|
|
433
|
+
|
|
434
|
+
export const HOST_ALLOWLIST = new Set(['localhost', '127.0.0.1', '[::1]']);
|
|
435
|
+
|
|
436
|
+
const WILDCARD_HOSTS = new Set(['*', '0.0.0.0', '::', '[::]', '']);
|
|
437
|
+
|
|
438
|
+
/**
|
|
439
|
+
* Parse a raw `Host` header into a normalized hostname, or `null` when malformed.
|
|
440
|
+
* @param {unknown} value
|
|
441
|
+
* @returns {string|null}
|
|
442
|
+
*/
|
|
443
|
+
export function parseHostHeader(value) {
|
|
444
|
+
if (typeof value !== 'string') return null;
|
|
445
|
+
if (!value || value !== value.trim()) return null;
|
|
446
|
+
if (/\s/.test(value) || CONTROL_CHARS.test(value)) return null;
|
|
447
|
+
if (value.includes('/') || value.includes('?') || value.includes('#')) return null;
|
|
448
|
+
|
|
449
|
+
let url;
|
|
450
|
+
try {
|
|
451
|
+
url = new URL(`http://${value}`);
|
|
452
|
+
} catch {
|
|
453
|
+
return null;
|
|
454
|
+
}
|
|
455
|
+
if (url.username || url.password) return null;
|
|
456
|
+
if (url.pathname !== '/' || url.search || url.hash) return null;
|
|
457
|
+
if (!url.hostname) return null;
|
|
458
|
+
return url.hostname.toLowerCase();
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
/**
|
|
462
|
+
* @param {unknown} value raw Host header
|
|
463
|
+
* @param {{ extraHosts?: string[] }} [opts]
|
|
464
|
+
* @returns {boolean}
|
|
465
|
+
*/
|
|
466
|
+
export function isAllowedHost(value, { extraHosts = [] } = {}) {
|
|
467
|
+
const hostname = parseHostHeader(value);
|
|
468
|
+
if (!hostname) return false;
|
|
469
|
+
if (HOST_ALLOWLIST.has(hostname)) return true;
|
|
470
|
+
for (const extra of extraHosts || []) {
|
|
471
|
+
const normalized = parseHostHeader(String(extra));
|
|
472
|
+
if (normalized && normalized === hostname) return true;
|
|
473
|
+
}
|
|
474
|
+
return false;
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
/**
|
|
478
|
+
* True when `STUDIO_ALLOW_NON_LOOPBACK` explicitly opts in (truthy flag or host list).
|
|
479
|
+
* `0`/`false`/`no`/`off` are treated as disabled.
|
|
480
|
+
* @param {Record<string,string|undefined>} [env]
|
|
481
|
+
* @returns {boolean}
|
|
482
|
+
*/
|
|
483
|
+
export function isNonLoopbackOptIn(env = process.env) {
|
|
484
|
+
const raw = env.STUDIO_ALLOW_NON_LOOPBACK;
|
|
485
|
+
if (raw === undefined || raw === null || raw === '') return false;
|
|
486
|
+
const value = String(raw).trim().toLowerCase();
|
|
487
|
+
return !(value === '0' || value === 'false' || value === 'no' || value === 'off');
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
/**
|
|
491
|
+
* Resolve the explicit non-loopback Host opt-in. Never returns a wildcard address.
|
|
492
|
+
* @param {{ env?: Record<string,string|undefined>, host?: string }} [opts]
|
|
493
|
+
* @returns {string[]}
|
|
494
|
+
*/
|
|
495
|
+
export function resolveExtraHosts({ env = process.env, host } = {}) {
|
|
496
|
+
const raw = env.STUDIO_ALLOW_NON_LOOPBACK;
|
|
497
|
+
if (raw === undefined || raw === null || raw === '') return [];
|
|
498
|
+
const value = String(raw).trim().toLowerCase();
|
|
499
|
+
if (value === '0' || value === 'false' || value === 'no' || value === 'off') return [];
|
|
500
|
+
const entries =
|
|
501
|
+
value === '1' || value === 'true'
|
|
502
|
+
? [host || env.HOST]
|
|
503
|
+
: String(raw)
|
|
504
|
+
.split(',')
|
|
505
|
+
.map((entry) => entry.trim())
|
|
506
|
+
.filter(Boolean);
|
|
507
|
+
|
|
508
|
+
const out = [];
|
|
509
|
+
for (const entry of entries) {
|
|
510
|
+
if (!entry) continue;
|
|
511
|
+
const normalized = parseHostHeader(entry);
|
|
512
|
+
const hostname = normalized || String(entry).toLowerCase();
|
|
513
|
+
if (WILDCARD_HOSTS.has(hostname)) continue;
|
|
514
|
+
if (!out.includes(hostname)) out.push(hostname);
|
|
515
|
+
}
|
|
516
|
+
return out;
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
/**
|
|
520
|
+
* @param {unknown} address
|
|
521
|
+
* @returns {boolean}
|
|
522
|
+
*/
|
|
523
|
+
export function isLoopbackAddress(address) {
|
|
524
|
+
if (typeof address !== 'string' || !address) return false;
|
|
525
|
+
return (
|
|
526
|
+
address === '127.0.0.1' ||
|
|
527
|
+
address === '::1' ||
|
|
528
|
+
address === '::ffff:127.0.0.1' ||
|
|
529
|
+
address.startsWith('127.') ||
|
|
530
|
+
address.startsWith('::ffff:127.')
|
|
531
|
+
);
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
export const DEFAULT_ORIGINS = 'http://localhost:5180,http://127.0.0.1:5180';
|
|
535
|
+
|
|
536
|
+
/**
|
|
537
|
+
* @param {string|Set<string>} [value]
|
|
538
|
+
* @returns {Set<string>}
|
|
539
|
+
*/
|
|
540
|
+
export function parseOrigins(value = DEFAULT_ORIGINS) {
|
|
541
|
+
if (value instanceof Set) return new Set(value);
|
|
542
|
+
const set = new Set(
|
|
543
|
+
String(value)
|
|
544
|
+
.split(',')
|
|
545
|
+
.map((entry) => entry.trim())
|
|
546
|
+
.filter(Boolean)
|
|
547
|
+
);
|
|
548
|
+
return set.size ? set : new Set(DEFAULT_ORIGINS.split(','));
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
/**
|
|
552
|
+
* @param {Set<string>|string[]|string} origins
|
|
553
|
+
* @returns {boolean}
|
|
554
|
+
*/
|
|
555
|
+
export function isWildcardOrigins(origins) {
|
|
556
|
+
if (origins instanceof Set) return origins.has('*');
|
|
557
|
+
if (Array.isArray(origins)) return origins.includes('*');
|
|
558
|
+
return String(origins || '')
|
|
559
|
+
.split(',')
|
|
560
|
+
.map((entry) => entry.trim())
|
|
561
|
+
.includes('*');
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
/**
|
|
565
|
+
* @param {unknown} origin
|
|
566
|
+
* @returns {boolean}
|
|
567
|
+
*/
|
|
568
|
+
export function isNullOrigin(origin) {
|
|
569
|
+
return typeof origin === 'string' && origin.trim().toLowerCase() === 'null';
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
/**
|
|
573
|
+
* Exact origin membership. An absent Origin returns `true` (the token guard still runs); the
|
|
574
|
+
* literal `null` origin is always rejected.
|
|
575
|
+
* @param {unknown} origin
|
|
576
|
+
* @param {Set<string>|string[]|string} origins
|
|
577
|
+
* @param {{ allowAll?: boolean }} [opts]
|
|
578
|
+
* @returns {boolean}
|
|
579
|
+
*/
|
|
580
|
+
export function isOriginAllowed(origin, origins, { allowAll = false } = {}) {
|
|
581
|
+
if (origin === undefined || origin === null) return true;
|
|
582
|
+
if (isNullOrigin(origin)) return false;
|
|
583
|
+
const set = origins instanceof Set ? origins : parseOrigins(origins);
|
|
584
|
+
if (allowAll || set.has('*')) return true;
|
|
585
|
+
return set.has(origin);
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
/* ------------------------------------------------------------------ JSON media type */
|
|
589
|
+
|
|
590
|
+
function headerOf(input, name) {
|
|
591
|
+
if (!input) return undefined;
|
|
592
|
+
const headers = input.headers || input;
|
|
593
|
+
const lower = name.toLowerCase();
|
|
594
|
+
if (headers[lower] !== undefined) return headers[lower];
|
|
595
|
+
for (const [key, value] of Object.entries(headers)) {
|
|
596
|
+
if (key.toLowerCase() === lower) return value;
|
|
597
|
+
}
|
|
598
|
+
return undefined;
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
/**
|
|
602
|
+
* @param {unknown} value raw Content-Type header
|
|
603
|
+
* @returns {boolean}
|
|
604
|
+
*/
|
|
605
|
+
export function isJsonMediaType(value) {
|
|
606
|
+
if (typeof value !== 'string') return false;
|
|
607
|
+
const [mediaType] = value.split(';');
|
|
608
|
+
return String(mediaType).trim().toLowerCase() === 'application/json';
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
/**
|
|
612
|
+
* @param {{ headers?: Record<string, unknown> }|Record<string, unknown>} reqOrHeaders
|
|
613
|
+
* @returns {boolean}
|
|
614
|
+
*/
|
|
615
|
+
export function hasRequestBody(reqOrHeaders) {
|
|
616
|
+
const transferEncoding = headerOf(reqOrHeaders, 'transfer-encoding');
|
|
617
|
+
if (transferEncoding) return true;
|
|
618
|
+
const length = Number(headerOf(reqOrHeaders, 'content-length') || 0);
|
|
619
|
+
return Number.isFinite(length) && length > 0;
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
/**
|
|
623
|
+
* @param {string} method
|
|
624
|
+
* @param {{ headers?: Record<string, unknown> }|Record<string, unknown>} reqOrHeaders
|
|
625
|
+
* @returns {boolean}
|
|
626
|
+
*/
|
|
627
|
+
export function requiresJsonContentType(method, reqOrHeaders) {
|
|
628
|
+
const verb = String(method || '').toUpperCase();
|
|
629
|
+
const hasBody = hasRequestBody(reqOrHeaders);
|
|
630
|
+
if (verb === 'POST' || verb === 'PUT' || verb === 'PATCH') {
|
|
631
|
+
return !hasBody || !isJsonMediaType(headerOf(reqOrHeaders, 'content-type'));
|
|
632
|
+
}
|
|
633
|
+
if (verb === 'DELETE') {
|
|
634
|
+
return hasBody && !isJsonMediaType(headerOf(reqOrHeaders, 'content-type'));
|
|
635
|
+
}
|
|
636
|
+
return false;
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
/* ------------------------------------------------------------------ agent env / argv */
|
|
640
|
+
|
|
641
|
+
export const AGENT_ENV_ALLOWLIST = Object.freeze([
|
|
642
|
+
// POSIX essentials.
|
|
643
|
+
'PATH',
|
|
644
|
+
'HOME',
|
|
645
|
+
'USER',
|
|
646
|
+
'LOGNAME',
|
|
647
|
+
'SHELL',
|
|
648
|
+
'TMPDIR',
|
|
649
|
+
'TMP',
|
|
650
|
+
'TEMP',
|
|
651
|
+
'LANG',
|
|
652
|
+
'LC_ALL',
|
|
653
|
+
'LC_CTYPE',
|
|
654
|
+
'TERM',
|
|
655
|
+
// Windows process/runtime essentials.
|
|
656
|
+
'SystemRoot',
|
|
657
|
+
'ComSpec',
|
|
658
|
+
'PATHEXT',
|
|
659
|
+
'WINDIR',
|
|
660
|
+
'APPDATA',
|
|
661
|
+
'LOCALAPPDATA',
|
|
662
|
+
'USERPROFILE',
|
|
663
|
+
'PROGRAMDATA',
|
|
664
|
+
'PROGRAMFILES',
|
|
665
|
+
'PROGRAMFILES(X86)',
|
|
666
|
+
'NUMBER_OF_PROCESSORS',
|
|
667
|
+
'PROCESSOR_ARCHITECTURE',
|
|
668
|
+
]);
|
|
669
|
+
|
|
670
|
+
export const LEARNER_ENV_ALLOWLIST = Object.freeze([
|
|
671
|
+
'PATH',
|
|
672
|
+
'HOME',
|
|
673
|
+
'USER',
|
|
674
|
+
'TMPDIR',
|
|
675
|
+
'TMP',
|
|
676
|
+
'TEMP',
|
|
677
|
+
'LANG',
|
|
678
|
+
'LC_ALL',
|
|
679
|
+
'LC_CTYPE',
|
|
680
|
+
'TERM',
|
|
681
|
+
'SystemRoot',
|
|
682
|
+
'ComSpec',
|
|
683
|
+
'PATHEXT',
|
|
684
|
+
'WINDIR',
|
|
685
|
+
'APPDATA',
|
|
686
|
+
'LOCALAPPDATA',
|
|
687
|
+
'USERPROFILE',
|
|
688
|
+
'PROGRAMDATA',
|
|
689
|
+
'PROGRAMFILES',
|
|
690
|
+
'PROGRAMFILES(X86)',
|
|
691
|
+
'NUMBER_OF_PROCESSORS',
|
|
692
|
+
'PROCESSOR_ARCHITECTURE',
|
|
693
|
+
]);
|
|
694
|
+
|
|
695
|
+
/** Exact deny keys plus prefix entries ending in `*`. */
|
|
696
|
+
export const AGENT_ENV_DENYLIST = new Set([
|
|
697
|
+
'NODE_OPTIONS',
|
|
698
|
+
'NODE_PATH',
|
|
699
|
+
'NODE_EXTRA_CA_CERTS',
|
|
700
|
+
'LD_PRELOAD',
|
|
701
|
+
'LD_LIBRARY_PATH',
|
|
702
|
+
'LD_AUDIT',
|
|
703
|
+
'DYLD_*',
|
|
704
|
+
'BASH_ENV',
|
|
705
|
+
'ENV',
|
|
706
|
+
'SHELLOPTS',
|
|
707
|
+
'BASHOPTS',
|
|
708
|
+
'PS4',
|
|
709
|
+
'PROMPT_COMMAND',
|
|
710
|
+
'CDPATH',
|
|
711
|
+
'PERL5LIB',
|
|
712
|
+
'PERL5OPT',
|
|
713
|
+
'PERL5DB',
|
|
714
|
+
'PYTHONPATH',
|
|
715
|
+
'PYTHONSTARTUP',
|
|
716
|
+
'PYTHONHOME',
|
|
717
|
+
'RUBYOPT',
|
|
718
|
+
'RUBYLIB',
|
|
719
|
+
'JAVA_TOOL_OPTIONS',
|
|
720
|
+
'_JAVA_OPTIONS',
|
|
721
|
+
'JDK_JAVA_OPTIONS',
|
|
722
|
+
'MAVEN_OPTS',
|
|
723
|
+
'GRADLE_OPTS',
|
|
724
|
+
'GIT_CONFIG_COUNT',
|
|
725
|
+
'GIT_CONFIG_KEY_*',
|
|
726
|
+
'GIT_CONFIG_VALUE_*',
|
|
727
|
+
'GIT_SSH_COMMAND',
|
|
728
|
+
'GIT_EXTERNAL_DIFF',
|
|
729
|
+
'GIT_PAGER',
|
|
730
|
+
'PAGER',
|
|
731
|
+
'LESSOPEN',
|
|
732
|
+
'LESSCLOSE',
|
|
733
|
+
'SSH_ASKPASS',
|
|
734
|
+
'SUDO_ASKPASS',
|
|
735
|
+
'npm_config_*',
|
|
736
|
+
'OPENCODE_PERMISSION',
|
|
737
|
+
'CLAUDE_DANGEROUSLY_SKIP_PERMISSIONS',
|
|
738
|
+
'CLAUDECODE',
|
|
739
|
+
'CLAUDE_CODE_*',
|
|
740
|
+
]);
|
|
741
|
+
|
|
742
|
+
/** @param {string} key @returns {boolean} */
|
|
743
|
+
function isDeniedEnvKey(key) {
|
|
744
|
+
if (AGENT_ENV_DENYLIST.has(key)) return true;
|
|
745
|
+
for (const entry of AGENT_ENV_DENYLIST) {
|
|
746
|
+
if (entry.endsWith('*') && key.startsWith(entry.slice(0, -1))) return true;
|
|
747
|
+
}
|
|
748
|
+
return false;
|
|
749
|
+
}
|
|
750
|
+
|
|
751
|
+
const AGENT_CREDENTIALS = {
|
|
752
|
+
claude: [
|
|
753
|
+
'ANTHROPIC_API_KEY',
|
|
754
|
+
'ANTHROPIC_AUTH_TOKEN',
|
|
755
|
+
'ANTHROPIC_BASE_URL',
|
|
756
|
+
'CLAUDE_API_KEY',
|
|
757
|
+
'CLAUDE_CONFIG_DIR',
|
|
758
|
+
],
|
|
759
|
+
gemini: ['GEMINI_API_KEY', 'GOOGLE_API_KEY', 'GOOGLE_APPLICATION_CREDENTIALS'],
|
|
760
|
+
cursor: ['CURSOR_API_KEY'],
|
|
761
|
+
opencode: ['OPENCODE_CONFIG_CONTENT', 'OPENCODE_MODEL'],
|
|
762
|
+
antigravity: ['GOOGLE_API_KEY', 'GOOGLE_APPLICATION_CREDENTIALS'],
|
|
763
|
+
ollama: ['OLLAMA_HOST', 'OLLAMA_MODEL'],
|
|
764
|
+
};
|
|
765
|
+
|
|
766
|
+
/** Keys the server itself builds and therefore never copies from the inherited environment. */
|
|
767
|
+
const SERVER_BUILT_KEYS = new Set(['OPENCODE_CONFIG_CONTENT']);
|
|
768
|
+
|
|
769
|
+
/**
|
|
770
|
+
* Build an allowlisted environment for an agent CLI (D-15).
|
|
771
|
+
* @param {string} agent
|
|
772
|
+
* @param {Record<string, string|undefined>} [env]
|
|
773
|
+
* @param {{ extraEnv?: Record<string, string|undefined> }} [opts]
|
|
774
|
+
* @returns {Record<string, string>}
|
|
775
|
+
*/
|
|
776
|
+
export function buildAgentEnv(agent, env = process.env, { extraEnv = {} } = {}) {
|
|
777
|
+
const allowed = new Set([
|
|
778
|
+
...AGENT_ENV_ALLOWLIST,
|
|
779
|
+
...(AGENT_CREDENTIALS[agent] || []),
|
|
780
|
+
]);
|
|
781
|
+
const out = {};
|
|
782
|
+
for (const key of allowed) {
|
|
783
|
+
if (SERVER_BUILT_KEYS.has(key)) continue;
|
|
784
|
+
if (isDeniedEnvKey(key)) continue;
|
|
785
|
+
const value = env?.[key];
|
|
786
|
+
if (value !== undefined) out[key] = value;
|
|
787
|
+
}
|
|
788
|
+
for (const [key, value] of Object.entries(extraEnv || {})) {
|
|
789
|
+
if (value !== undefined) out[key] = value;
|
|
790
|
+
}
|
|
791
|
+
return out;
|
|
792
|
+
}
|
|
793
|
+
|
|
794
|
+
/**
|
|
795
|
+
* Build the scrubbed environment for learner-run child processes (D-18).
|
|
796
|
+
* @param {Record<string, string|undefined>} [env]
|
|
797
|
+
* @returns {Record<string, string>}
|
|
798
|
+
*/
|
|
799
|
+
export function buildLearnerEnv(env = process.env) {
|
|
800
|
+
const out = {};
|
|
801
|
+
for (const key of LEARNER_ENV_ALLOWLIST) {
|
|
802
|
+
if (isDeniedEnvKey(key)) continue;
|
|
803
|
+
const value = env?.[key];
|
|
804
|
+
if (value !== undefined) out[key] = value;
|
|
805
|
+
}
|
|
806
|
+
return out;
|
|
807
|
+
}
|
|
808
|
+
|
|
809
|
+
/** Per-agent denied flags (exact tokens; value-aware handling lives in the assert helper). */
|
|
810
|
+
export const AGENT_DENY_FLAGS = Object.freeze({
|
|
811
|
+
claude: Object.freeze([
|
|
812
|
+
'--dangerously-skip-permissions',
|
|
813
|
+
'--allow-dangerously-skip-permissions',
|
|
814
|
+
'--enable-auto-mode',
|
|
815
|
+
'--permission-mode=bypassPermissions',
|
|
816
|
+
'--permission-mode=acceptEdits',
|
|
817
|
+
'--permission-mode=auto',
|
|
818
|
+
]),
|
|
819
|
+
cursor: Object.freeze([
|
|
820
|
+
'--force',
|
|
821
|
+
'-f',
|
|
822
|
+
'--yolo',
|
|
823
|
+
'--trust',
|
|
824
|
+
'--approve-mcps',
|
|
825
|
+
'--sandbox=disabled',
|
|
826
|
+
]),
|
|
827
|
+
opencode: Object.freeze(['--auto', '--dangerously-skip-permissions']),
|
|
828
|
+
gemini: Object.freeze([
|
|
829
|
+
'--yolo',
|
|
830
|
+
'-y',
|
|
831
|
+
'--skip-trust',
|
|
832
|
+
'--allowed-tools',
|
|
833
|
+
'--allowed-mcp-server-names',
|
|
834
|
+
]),
|
|
835
|
+
antigravity: Object.freeze([
|
|
836
|
+
'--dangerously-skip-permissions',
|
|
837
|
+
'--agent',
|
|
838
|
+
'--remote-control',
|
|
839
|
+
]),
|
|
840
|
+
ollama: Object.freeze([]),
|
|
841
|
+
});
|
|
842
|
+
|
|
843
|
+
const UNIVERSAL_DENY_FLAGS = new Set([
|
|
844
|
+
'--dangerously-skip-permissions',
|
|
845
|
+
'--allow-dangerously-skip-permissions',
|
|
846
|
+
'--yolo',
|
|
847
|
+
'--force',
|
|
848
|
+
'--trust',
|
|
849
|
+
]);
|
|
850
|
+
|
|
851
|
+
function unsafeInvocation(message, offending) {
|
|
852
|
+
const err = new Error(message);
|
|
853
|
+
err.code = 'unsafe_invocation';
|
|
854
|
+
err.offending = offending;
|
|
855
|
+
return err;
|
|
856
|
+
}
|
|
857
|
+
|
|
858
|
+
/**
|
|
859
|
+
* Reject a deny-listed flag (including `--flag=value` forms) or env key before spawn (D-15).
|
|
860
|
+
* @param {string} agent
|
|
861
|
+
* @param {string[]} argv
|
|
862
|
+
* @param {Record<string, string|undefined>} [env]
|
|
863
|
+
* @returns {true}
|
|
864
|
+
*/
|
|
865
|
+
export function assertSafeAgentInvocation(agent, argv, env = process.env) {
|
|
866
|
+
const args = Array.isArray(argv) ? argv.map(String) : [];
|
|
867
|
+
const deny = new Set([
|
|
868
|
+
...(AGENT_DENY_FLAGS[agent] || []),
|
|
869
|
+
...UNIVERSAL_DENY_FLAGS,
|
|
870
|
+
]);
|
|
871
|
+
|
|
872
|
+
for (let i = 0; i < args.length; i += 1) {
|
|
873
|
+
const arg = args[i];
|
|
874
|
+
const eq = arg.indexOf('=');
|
|
875
|
+
const flag = eq === -1 ? arg : arg.slice(0, eq);
|
|
876
|
+
const value = eq === -1 ? undefined : arg.slice(eq + 1);
|
|
877
|
+
const next = eq === -1 ? args[i + 1] : undefined;
|
|
878
|
+
|
|
879
|
+
if (deny.has(arg) || deny.has(flag)) {
|
|
880
|
+
throw unsafeInvocation(`Unsafe agent invocation flag: ${arg}`, arg);
|
|
881
|
+
}
|
|
882
|
+
|
|
883
|
+
if (flag === '--permission-mode' && agent === 'claude') {
|
|
884
|
+
const mode = value !== undefined ? value : next;
|
|
885
|
+
if (!mode || ['bypassPermissions', 'acceptEdits', 'auto'].includes(mode)) {
|
|
886
|
+
throw unsafeInvocation(`Unsafe permission mode: ${mode || arg}`, arg);
|
|
887
|
+
}
|
|
888
|
+
}
|
|
889
|
+
|
|
890
|
+
if (flag === '--approval-mode' && agent === 'gemini') {
|
|
891
|
+
const mode = value !== undefined ? value : next;
|
|
892
|
+
if (mode !== 'plan') {
|
|
893
|
+
throw unsafeInvocation(`Unsafe approval mode: ${mode || arg}`, arg);
|
|
894
|
+
}
|
|
895
|
+
}
|
|
896
|
+
|
|
897
|
+
if (flag === '--mode' && agent === 'antigravity') {
|
|
898
|
+
const mode = value !== undefined ? value : next;
|
|
899
|
+
if (mode !== 'plan') {
|
|
900
|
+
throw unsafeInvocation(`Unsafe execution mode: ${mode || arg}`, arg);
|
|
901
|
+
}
|
|
902
|
+
}
|
|
903
|
+
|
|
904
|
+
if (flag === '--sandbox' && agent === 'cursor') {
|
|
905
|
+
const mode = value !== undefined ? value : next;
|
|
906
|
+
if (mode === 'disabled') {
|
|
907
|
+
throw unsafeInvocation(`Unsafe sandbox mode: ${mode}`, arg);
|
|
908
|
+
}
|
|
909
|
+
}
|
|
910
|
+
}
|
|
911
|
+
|
|
912
|
+
for (const key of Object.keys(env || {})) {
|
|
913
|
+
if (isDeniedEnvKey(key)) {
|
|
914
|
+
throw unsafeInvocation(`Unsafe environment variable for agent: ${key}`, key);
|
|
915
|
+
}
|
|
916
|
+
}
|
|
917
|
+
|
|
918
|
+
return true;
|
|
919
|
+
}
|
|
920
|
+
|
|
921
|
+
/* ------------------------------------------------------------------ executables */
|
|
922
|
+
|
|
923
|
+
/**
|
|
924
|
+
* Cross-platform command resolver. Returns an absolute path or `null`; never spawns a shell.
|
|
925
|
+
* @param {string} command
|
|
926
|
+
* @param {{ platform?: string, pathValue?: string, fs?: object, pathext?: string }} [opts]
|
|
927
|
+
* @returns {string|null}
|
|
928
|
+
*/
|
|
929
|
+
export function resolveExecutable(
|
|
930
|
+
command,
|
|
931
|
+
{ platform = process.platform, pathValue = process.env.PATH || '', fs = null, pathext } = {}
|
|
932
|
+
) {
|
|
933
|
+
const io = fs || { statSync, readdirSync };
|
|
934
|
+
const isWin = platform === 'win32';
|
|
935
|
+
const exists = (candidate) => {
|
|
936
|
+
try {
|
|
937
|
+
return io.statSync(candidate).isFile();
|
|
938
|
+
} catch {
|
|
939
|
+
return false;
|
|
940
|
+
}
|
|
941
|
+
};
|
|
942
|
+
|
|
943
|
+
if (!command) return null;
|
|
944
|
+
|
|
945
|
+
if (isAbsolute(command) || command.includes('/') || (isWin && command.includes('\\'))) {
|
|
946
|
+
return exists(command) ? resolve(command) : null;
|
|
947
|
+
}
|
|
948
|
+
|
|
949
|
+
const dirs = String(pathValue || '')
|
|
950
|
+
.split(isWin ? ';' : ':')
|
|
951
|
+
.filter(Boolean);
|
|
952
|
+
const exts = isWin
|
|
953
|
+
? String(pathext || process.env.PATHEXT || '.COM;.EXE;.BAT;.CMD')
|
|
954
|
+
.split(';')
|
|
955
|
+
.filter(Boolean)
|
|
956
|
+
: [''];
|
|
957
|
+
|
|
958
|
+
for (const dir of dirs) {
|
|
959
|
+
if (isWin && typeof io.readdirSync === 'function') {
|
|
960
|
+
// Match the actual directory entry case-insensitively so the returned path is the real
|
|
961
|
+
// filename on both Windows and case-insensitive POSIX filesystems.
|
|
962
|
+
let names;
|
|
963
|
+
try {
|
|
964
|
+
names = io.readdirSync(dir);
|
|
965
|
+
} catch {
|
|
966
|
+
names = null;
|
|
967
|
+
}
|
|
968
|
+
if (names) {
|
|
969
|
+
for (const ext of exts) {
|
|
970
|
+
const wanted = `${command}${ext}`.toLowerCase();
|
|
971
|
+
const match = names.find((name) => name.toLowerCase() === wanted);
|
|
972
|
+
if (match && exists(join(dir, match))) return resolve(join(dir, match));
|
|
973
|
+
}
|
|
974
|
+
const bare = names.find((name) => name.toLowerCase() === command.toLowerCase());
|
|
975
|
+
if (bare && exists(join(dir, bare))) return resolve(join(dir, bare));
|
|
976
|
+
continue;
|
|
977
|
+
}
|
|
978
|
+
}
|
|
979
|
+
|
|
980
|
+
if (isWin) {
|
|
981
|
+
for (const ext of exts) {
|
|
982
|
+
const candidate = join(dir, command + ext);
|
|
983
|
+
if (exists(candidate)) return resolve(candidate);
|
|
984
|
+
}
|
|
985
|
+
const bare = join(dir, command);
|
|
986
|
+
if (exists(bare)) return resolve(bare);
|
|
987
|
+
} else {
|
|
988
|
+
const candidate = join(dir, command);
|
|
989
|
+
if (exists(candidate)) return resolve(candidate);
|
|
990
|
+
}
|
|
991
|
+
}
|
|
992
|
+
return null;
|
|
993
|
+
}
|
|
994
|
+
|
|
995
|
+
/**
|
|
996
|
+
* @param {string} resolvedPath
|
|
997
|
+
* @param {string} [platform]
|
|
998
|
+
* @returns {boolean}
|
|
999
|
+
*/
|
|
1000
|
+
export function isWindowsCommandShim(resolvedPath, platform = process.platform) {
|
|
1001
|
+
if (platform !== 'win32' || typeof resolvedPath !== 'string') return false;
|
|
1002
|
+
return /\.(cmd|bat)$/i.test(resolvedPath);
|
|
1003
|
+
}
|
|
1004
|
+
|
|
1005
|
+
/**
|
|
1006
|
+
* @param {string} name
|
|
1007
|
+
* @param {string} resolvedPath
|
|
1008
|
+
* @returns {string}
|
|
1009
|
+
*/
|
|
1010
|
+
export function unsupportedWindowsShimMessage(name, resolvedPath) {
|
|
1011
|
+
return (
|
|
1012
|
+
`${name} is installed as a Windows batch shim (${resolvedPath}). ` +
|
|
1013
|
+
'The local bridge runs agents without a shell, so .cmd/.bat shims are unsupported in this beta. ' +
|
|
1014
|
+
'Install the native binary or use WSL.'
|
|
1015
|
+
);
|
|
1016
|
+
}
|