@hattoriai/poney 0.0.0-stage → 0.1.1
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/LICENSE +21 -0
- package/README.md +23 -2
- package/bin/poney-mcp.mjs +3 -0
- package/bin/poney.mjs +3 -0
- package/brief-change.md +23 -0
- package/brief-tour.md +43 -0
- package/brief.md +133 -0
- package/dist/chunk-BCOS4LFB.js +1184 -0
- package/dist/chunk-BCOS4LFB.js.map +1 -0
- package/dist/chunk-TPJZDQG6.js +290 -0
- package/dist/chunk-TPJZDQG6.js.map +1 -0
- package/dist/chunk-YLKV6LIU.js +621 -0
- package/dist/chunk-YLKV6LIU.js.map +1 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +181 -0
- package/dist/cli.js.map +1 -0
- package/dist/hub-FERXNPJS.js +4 -0
- package/dist/hub-FERXNPJS.js.map +1 -0
- package/dist/live/types.d.ts +165 -0
- package/dist/live/types.js +3 -0
- package/dist/live/types.js.map +1 -0
- package/dist/mcp.d.ts +2 -0
- package/dist/mcp.js +288 -0
- package/dist/mcp.js.map +1 -0
- package/dist/ops.d.ts +1575 -0
- package/dist/ops.js +3 -0
- package/dist/ops.js.map +1 -0
- package/dist/plugins/index.d.ts +94 -0
- package/dist/plugins/index.js +3 -0
- package/dist/plugins/index.js.map +1 -0
- package/dist/run-25PP2HWH.js +3 -0
- package/dist/run-25PP2HWH.js.map +1 -0
- package/dist/types-N-oiuMYy.d.ts +77 -0
- package/examples/tour.poney +195 -0
- package/examples/walkthrough.poney +644 -0
- package/package.json +76 -4
- package/studio/assets/abap-BdImnpbu.js +1 -0
- package/studio/assets/actionscript-3-B3316cI-.js +1 -0
- package/studio/assets/ada-BIOnG6TC.js +1 -0
- package/studio/assets/ahk-BrbAagtO.js +1 -0
- package/studio/assets/ahk2-8Zs4aa1G.js +1 -0
- package/studio/assets/andromeeda-C4gqWexZ.js +1 -0
- package/studio/assets/angular-html-D_SYSyRt.js +1 -0
- package/studio/assets/angular-ts-DGq0tZX5.js +1 -0
- package/studio/assets/apache-Pmp26Uib.js +1 -0
- package/studio/assets/apex-DhZFqWV2.js +1 -0
- package/studio/assets/apl-ChzvTHjC.js +1 -0
- package/studio/assets/applescript-Co6uUVPk.js +1 -0
- package/studio/assets/ara-BRHolxvo.js +1 -0
- package/studio/assets/asciidoc-CSVQ5wI8.js +1 -0
- package/studio/assets/asm-D_Q5rh1f.js +1 -0
- package/studio/assets/astro-DTjqU0_L.js +1 -0
- package/studio/assets/aurora-x-D-2ljcwZ.js +1 -0
- package/studio/assets/awk-DMzUqQB5.js +1 -0
- package/studio/assets/ayu-dark-DYE7WIF3.js +1 -0
- package/studio/assets/ayu-light-BA47KaF1.js +1 -0
- package/studio/assets/ayu-mirage-32ctXXKs.js +1 -0
- package/studio/assets/ballerina-BFfxhgS-.js +1 -0
- package/studio/assets/bat-CickPsom.js +1 -0
- package/studio/assets/beancount-BgSHGh8x.js +1 -0
- package/studio/assets/berry-uYugtg8r.js +1 -0
- package/studio/assets/bibtex-CHM0blh-.js +1 -0
- package/studio/assets/bicep-Bmn6On1c.js +1 -0
- package/studio/assets/bird2-Bx8U0n9b.js +1 -0
- package/studio/assets/blade-k33SngOZ.js +1 -0
- package/studio/assets/bsl-DlhNcFeZ.js +1 -0
- package/studio/assets/c-BIGW1oBm.js +1 -0
- package/studio/assets/c3-Dp5svz6Z.js +1 -0
- package/studio/assets/cadence-Bv_4Rxtq.js +1 -0
- package/studio/assets/cairo-KRGpt6FW.js +1 -0
- package/studio/assets/catppuccin-frappe-CZL1YF0i.js +1 -0
- package/studio/assets/catppuccin-latte-DH-8KZSZ.js +1 -0
- package/studio/assets/catppuccin-macchiato-B7yYVSCf.js +1 -0
- package/studio/assets/catppuccin-mocha-Ct7hS0mc.js +1 -0
- package/studio/assets/chapel-DTp_pixX.js +1 -0
- package/studio/assets/clarity-Dn5IMItf.js +1 -0
- package/studio/assets/clojure-P80f7IUj.js +1 -0
- package/studio/assets/cmake-D1j8_8rp.js +1 -0
- package/studio/assets/cobol-BBKr1ja6.js +1 -0
- package/studio/assets/codeowners-Bp6g37R7.js +1 -0
- package/studio/assets/codeql-DsOJ9woJ.js +1 -0
- package/studio/assets/coffee-Ch7k5sss.js +1 -0
- package/studio/assets/common-lisp-Cg-RD9OK.js +1 -0
- package/studio/assets/coq-BqXF5kFF.js +1 -0
- package/studio/assets/cpp-BMRokrvK.js +1 -0
- package/studio/assets/crystal-LUwhHfY5.js +1 -0
- package/studio/assets/csharp-B_TYUkTI.js +1 -0
- package/studio/assets/css-Z72CF80r.js +1 -0
- package/studio/assets/csv-fuZLfV_i.js +1 -0
- package/studio/assets/cue-D82EKSYY.js +1 -0
- package/studio/assets/cypher-COkxafJQ.js +1 -0
- package/studio/assets/d-85-TOEBH.js +1 -0
- package/studio/assets/dark-plus-C3mMm8J8.js +1 -0
- package/studio/assets/dart-CtKP3W-j.js +1 -0
- package/studio/assets/dax-CEL-wOlO.js +1 -0
- package/studio/assets/desktop-BmXAJ9_W.js +1 -0
- package/studio/assets/diff-D97Zzqfu.js +1 -0
- package/studio/assets/dist-_ey1iXf6.js +153 -0
- package/studio/assets/docker-BcOcwvcX.js +1 -0
- package/studio/assets/dotenv-De0Btta0.js +1 -0
- package/studio/assets/dracula-BzJJZx-M.js +1 -0
- package/studio/assets/dracula-soft-BXkSAIEj.js +1 -0
- package/studio/assets/dream-maker-BtqSS_iP.js +1 -0
- package/studio/assets/edge-CJaD-t2L.js +1 -0
- package/studio/assets/elixir-DkJLSxtU.js +1 -0
- package/studio/assets/elk.bundled-Bw5WzyyE.js +26 -0
- package/studio/assets/elm-DbKCFpqz.js +1 -0
- package/studio/assets/emacs-lisp-DaIrSCgJ.js +1 -0
- package/studio/assets/erb-CSMaCouu.js +1 -0
- package/studio/assets/erlang-DsQrWhSR.js +1 -0
- package/studio/assets/everforest-dark-BgDCqdQA.js +1 -0
- package/studio/assets/everforest-light-C8M2exoo.js +1 -0
- package/studio/assets/fennel-BYunw83y.js +1 -0
- package/studio/assets/fish-BvzEVeQv.js +1 -0
- package/studio/assets/fluent-C4IJs8-o.js +1 -0
- package/studio/assets/fortran-fixed-form-CkoXwp7k.js +1 -0
- package/studio/assets/fortran-free-form-BxgE0vQu.js +1 -0
- package/studio/assets/fsharp-CXgrBDvD.js +1 -0
- package/studio/assets/gdresource-TyuKm33G.js +1 -0
- package/studio/assets/gdscript-DqcFQ5yU.js +1 -0
- package/studio/assets/gdshader-DkwncUOv.js +1 -0
- package/studio/assets/genie-D0YGMca9.js +1 -0
- package/studio/assets/gherkin-DyxjwDmM.js +1 -0
- package/studio/assets/git-commit-F4YmCXRG.js +1 -0
- package/studio/assets/git-rebase-r7XF79zn.js +1 -0
- package/studio/assets/github-dark-DHJKELXO.js +1 -0
- package/studio/assets/github-dark-default-Cuk6v7N8.js +1 -0
- package/studio/assets/github-dark-dimmed-DH5Ifo-i.js +1 -0
- package/studio/assets/github-dark-high-contrast-E3gJ1_iC.js +1 -0
- package/studio/assets/github-light-DAi9KRSo.js +1 -0
- package/studio/assets/github-light-default-D7oLnXFd.js +1 -0
- package/studio/assets/github-light-high-contrast-BfjtVDDH.js +1 -0
- package/studio/assets/gleam-BspZqrRM.js +1 -0
- package/studio/assets/glimmer-js-Drrc9bTt.js +1 -0
- package/studio/assets/glimmer-ts-zeybXsvi.js +1 -0
- package/studio/assets/glsl-DplSGwfg.js +1 -0
- package/studio/assets/gn-8iBmfbXw.js +1 -0
- package/studio/assets/gnuplot-DdkO51Og.js +1 -0
- package/studio/assets/go-C27-OAKa.js +1 -0
- package/studio/assets/graphql-ChdNCCLP.js +1 -0
- package/studio/assets/groovy-gcz8RCvz.js +1 -0
- package/studio/assets/gruvbox-dark-hard-CFHQjOhq.js +1 -0
- package/studio/assets/gruvbox-dark-medium-GsRaNv29.js +1 -0
- package/studio/assets/gruvbox-dark-soft-CVdnzihN.js +1 -0
- package/studio/assets/gruvbox-light-hard-CH1njM8p.js +1 -0
- package/studio/assets/gruvbox-light-medium-DRw_LuNl.js +1 -0
- package/studio/assets/gruvbox-light-soft-hJgmCMqR.js +1 -0
- package/studio/assets/hack-Ck6-gGSS.js +1 -0
- package/studio/assets/haml-GN_XdMnF.js +1 -0
- package/studio/assets/handlebars-DPT5vKgj.js +1 -0
- package/studio/assets/hanken-grotesk-latin-ext-wght-normal-Dg-wlmqe.woff2 +0 -0
- package/studio/assets/hanken-grotesk-latin-wght-normal-CaVRRdDk.woff2 +0 -0
- package/studio/assets/hanken-grotesk-vietnamese-wght-normal-CHiFlh_0.woff2 +0 -0
- package/studio/assets/haskell-Df6bDoY_.js +1 -0
- package/studio/assets/haxe-CfZj7gIn.js +1 -0
- package/studio/assets/hcl-BWvSN4gD.js +1 -0
- package/studio/assets/hjson-D5-asLiD.js +1 -0
- package/studio/assets/hlsl-D3lLCCz7.js +1 -0
- package/studio/assets/horizon-BUw7H-hv.js +1 -0
- package/studio/assets/horizon-bright-CUuTKBJd.js +1 -0
- package/studio/assets/houston-DnULxvSX.js +1 -0
- package/studio/assets/html-BlS82ilI.js +1 -0
- package/studio/assets/html-derivative-DZhk3IEZ.js +1 -0
- package/studio/assets/http-jrhK8wxY.js +1 -0
- package/studio/assets/hurl-irOxFIW8.js +1 -0
- package/studio/assets/hxml-2-FPmUDs.js +1 -0
- package/studio/assets/hy-DFXneXwc.js +1 -0
- package/studio/assets/imba-DGztddWO.js +1 -0
- package/studio/assets/index-B-C2JUUu.css +1 -0
- package/studio/assets/index-DOjop_HJ.js +889 -0
- package/studio/assets/ini-BEwlwnbL.js +1 -0
- package/studio/assets/java-CylS5w8V.js +1 -0
- package/studio/assets/javascript-wDzz0qaB.js +1 -0
- package/studio/assets/jetbrains-mono-cyrillic-wght-normal-D73BlboJ.woff2 +0 -0
- package/studio/assets/jetbrains-mono-greek-wght-normal-Bw9x6K1M.woff2 +0 -0
- package/studio/assets/jetbrains-mono-latin-ext-wght-normal-DBQx-q_a.woff2 +0 -0
- package/studio/assets/jetbrains-mono-latin-wght-normal-B9CIFXIH.woff2 +0 -0
- package/studio/assets/jetbrains-mono-vietnamese-wght-normal-Bt-aOZkq.woff2 +0 -0
- package/studio/assets/jinja-DFQZVq3b.js +1 -0
- package/studio/assets/jison-wvAkD_A8.js +1 -0
- package/studio/assets/json-Cp-IABpG.js +1 -0
- package/studio/assets/json5-C9tS-k6U.js +1 -0
- package/studio/assets/jsonc-Des-eS-w.js +1 -0
- package/studio/assets/jsonl-DcaNXYhu.js +1 -0
- package/studio/assets/jsonnet-DFQXde-d.js +1 -0
- package/studio/assets/jssm-C2t-YnRu.js +1 -0
- package/studio/assets/jsx-g9-lgVsj.js +1 -0
- package/studio/assets/julia-Cu79e8SL.js +1 -0
- package/studio/assets/just-CMxyWJJc.js +1 -0
- package/studio/assets/kanagawa-dragon-BuwD2xS4.js +1 -0
- package/studio/assets/kanagawa-lotus-C3DzagqV.js +1 -0
- package/studio/assets/kanagawa-wave-DFGoQZhC.js +1 -0
- package/studio/assets/kdl-DV7GczEv.js +1 -0
- package/studio/assets/kotlin-BdnUsdx6.js +1 -0
- package/studio/assets/kusto-wEQ09or8.js +1 -0
- package/studio/assets/laserwave-DUszq2jm.js +1 -0
- package/studio/assets/latex-DJVikpzR.js +1 -0
- package/studio/assets/lean-BZvkOJ9d.js +1 -0
- package/studio/assets/less-B1dDrJ26.js +1 -0
- package/studio/assets/light-plus-B7mTdjB0.js +1 -0
- package/studio/assets/liquid-B-duXHXw.js +1 -0
- package/studio/assets/llvm-BZoOZj88.js +1 -0
- package/studio/assets/log-2UxHyX5q.js +1 -0
- package/studio/assets/logo-BtOb2qkB.js +1 -0
- package/studio/assets/lua-BaeVxFsk.js +1 -0
- package/studio/assets/luau-nOZpfvQi.js +1 -0
- package/studio/assets/make-CHLpvVh8.js +1 -0
- package/studio/assets/markdown-Cvjx9yec.js +1 -0
- package/studio/assets/marko-BYgDmDgU.js +1 -0
- package/studio/assets/material-theme-D5KoaKCx.js +1 -0
- package/studio/assets/material-theme-darker-BfHTSMKl.js +1 -0
- package/studio/assets/material-theme-lighter-B0m2ddpp.js +1 -0
- package/studio/assets/material-theme-ocean-CyktbL80.js +1 -0
- package/studio/assets/material-theme-palenight-Csfq5Kiy.js +1 -0
- package/studio/assets/matlab-D7o27uSR.js +1 -0
- package/studio/assets/mdc-DF4WjDMn.js +1 -0
- package/studio/assets/mdx-Cmh6b_Ma.js +1 -0
- package/studio/assets/mermaid-CQcHuHx7.js +1 -0
- package/studio/assets/min-dark-CafNBF8u.js +1 -0
- package/studio/assets/min-light-CTRr51gU.js +1 -0
- package/studio/assets/mipsasm-CKIfxQSi.js +1 -0
- package/studio/assets/mojo-DJz3ZmWd.js +1 -0
- package/studio/assets/monokai-CR4piiQ-.js +1 -0
- package/studio/assets/moonbit-Bag4Rp_g.js +1 -0
- package/studio/assets/move-el3G9tDJ.js +1 -0
- package/studio/assets/narrat-DRg8JJMk.js +1 -0
- package/studio/assets/nextflow-BCxp2Aob.js +1 -0
- package/studio/assets/nextflow-groovy-CedDknKX.js +1 -0
- package/studio/assets/nginx-BpAMiNFr.js +1 -0
- package/studio/assets/night-owl-C39BiMTA.js +1 -0
- package/studio/assets/night-owl-light-CMTm3GFP.js +1 -0
- package/studio/assets/nim-nV83PyhX.js +1 -0
- package/studio/assets/nix-CwoSXNpI.js +1 -0
- package/studio/assets/nord-Ddv68eIx.js +1 -0
- package/studio/assets/nsis-BlV79W_Q.js +1 -0
- package/studio/assets/nushell-BXD5iret.js +1 -0
- package/studio/assets/objective-c-DXmwc3jG.js +1 -0
- package/studio/assets/objective-cpp-CLxacb5B.js +1 -0
- package/studio/assets/ocaml-C0hk2d4L.js +1 -0
- package/studio/assets/odin-BBf5iR-q.js +1 -0
- package/studio/assets/one-dark-pro-CxGP3dtY.js +1 -0
- package/studio/assets/one-light-C3Wv6jpd.js +1 -0
- package/studio/assets/openscad-C4EeE6gA.js +1 -0
- package/studio/assets/org-6a7ccXN_.js +1 -0
- package/studio/assets/pascal-D93ZcfNL.js +1 -0
- package/studio/assets/perl-5klg-GXX.js +1 -0
- package/studio/assets/php-DoruYMF0.js +1 -0
- package/studio/assets/pkl-u5AG7uiY.js +1 -0
- package/studio/assets/plastic-3e1v2bzS.js +1 -0
- package/studio/assets/plsql-ChMvpjG-.js +1 -0
- package/studio/assets/po-BTJTHyun.js +1 -0
- package/studio/assets/poimandres-CS3Unz2-.js +1 -0
- package/studio/assets/polar-C0HS_06l.js +1 -0
- package/studio/assets/postcss-CXtECtnM.js +1 -0
- package/studio/assets/powerquery-CEu0bR-o.js +1 -0
- package/studio/assets/powershell-Dd0kTxKP.js +1 -0
- package/studio/assets/prisma-Vru482bI.js +1 -0
- package/studio/assets/prolog-CbFg5uaA.js +1 -0
- package/studio/assets/proto-C7zT0LnQ.js +1 -0
- package/studio/assets/pug-BtYPkAgq.js +1 -0
- package/studio/assets/puppet-BMWR74SV.js +1 -0
- package/studio/assets/purescript-CklMAg4u.js +1 -0
- package/studio/assets/python-B6aJPvgy.js +1 -0
- package/studio/assets/qml-3beO22l8.js +1 -0
- package/studio/assets/qmldir-C8lEn-DE.js +1 -0
- package/studio/assets/qss-IeuSbFQv.js +1 -0
- package/studio/assets/r-Cf5RLm7j.js +1 -0
- package/studio/assets/racket-BqYA7rlc.js +1 -0
- package/studio/assets/raku-DXvB9xmW.js +1 -0
- package/studio/assets/razor-CyjPwjZj.js +1 -0
- package/studio/assets/rbs-CpoqiR4B.js +1 -0
- package/studio/assets/red-DMbB5_pp.js +1 -0
- package/studio/assets/reg-C-SQnVFl.js +1 -0
- package/studio/assets/regexp-CDVJQ6XC.js +1 -0
- package/studio/assets/rel-C3B-1QV4.js +1 -0
- package/studio/assets/riscv-BM1_JUlF.js +1 -0
- package/studio/assets/ron-D8l8udqQ.js +1 -0
- package/studio/assets/rose-pine-5qJOZa0Y.js +1 -0
- package/studio/assets/rose-pine-dawn-zx0QlTCp.js +1 -0
- package/studio/assets/rose-pine-moon-C9pEdX9L.js +1 -0
- package/studio/assets/rosmsg-BJDFO7_C.js +1 -0
- package/studio/assets/rst-CVOjT0e7.js +1 -0
- package/studio/assets/ruby-C8rp0wew.js +1 -0
- package/studio/assets/rust-DPvrY3IQ.js +1 -0
- package/studio/assets/sas-BGn39htG.js +1 -0
- package/studio/assets/sass-Cj5Yp3dK.js +1 -0
- package/studio/assets/scala-CqE71os6.js +1 -0
- package/studio/assets/scheme-C98Dy4si.js +1 -0
- package/studio/assets/scss-Cw6XMfVs.js +1 -0
- package/studio/assets/sdbl-DVxCFoDh.js +1 -0
- package/studio/assets/shaderlab-Dg9Lc6iA.js +1 -0
- package/studio/assets/shellscript-Yzrsuije.js +1 -0
- package/studio/assets/shellsession-BADoaaVG.js +1 -0
- package/studio/assets/slack-dark-BthQWCQV.js +1 -0
- package/studio/assets/slack-ochin-DqwNpetd.js +1 -0
- package/studio/assets/smalltalk-BOQMe2GC.js +1 -0
- package/studio/assets/smithy-cds9vsN8.js +1 -0
- package/studio/assets/snazzy-light-Bw305WKR.js +1 -0
- package/studio/assets/solarized-dark-UcubFVte.js +1 -0
- package/studio/assets/solarized-light-DCG28T6R.js +1 -0
- package/studio/assets/solidity-DijEV5ha.js +1 -0
- package/studio/assets/soy-zscZBeg6.js +1 -0
- package/studio/assets/sparql-rVzFXLq3.js +1 -0
- package/studio/assets/splunk-BtCnVYZw.js +1 -0
- package/studio/assets/sql-DkvoVjww.js +1 -0
- package/studio/assets/src-Br__iChL.js +88 -0
- package/studio/assets/ssh-config-_ykCGR6B.js +1 -0
- package/studio/assets/stata-DACIj5bg.js +1 -0
- package/studio/assets/stylus-BEDo0Tqx.js +1 -0
- package/studio/assets/surrealql-Cjom0U5J.js +1 -0
- package/studio/assets/svelte-D84K1R2Q.js +1 -0
- package/studio/assets/swift-C2oV4EkX.js +1 -0
- package/studio/assets/synthwave-84-CbfX1IO0.js +1 -0
- package/studio/assets/system-verilog-0hqHdDBg.js +1 -0
- package/studio/assets/systemd-4A_iFExJ.js +1 -0
- package/studio/assets/talonscript-CkByrt1z.js +1 -0
- package/studio/assets/tasl-QIJgUcNo.js +1 -0
- package/studio/assets/tcl-dwOrl1Do.js +1 -0
- package/studio/assets/templ-Vpw5XpSW.js +1 -0
- package/studio/assets/terraform-BETggiCN.js +1 -0
- package/studio/assets/tex-D96PA37w.js +1 -0
- package/studio/assets/tokyo-night-hegEt444.js +1 -0
- package/studio/assets/toml-vGWfd6FD.js +1 -0
- package/studio/assets/ts-tags-Ls60c9xG.js +1 -0
- package/studio/assets/tsv-B_m7g4N7.js +1 -0
- package/studio/assets/tsx-COt5Ahok.js +1 -0
- package/studio/assets/turtle-BsS91CYL.js +1 -0
- package/studio/assets/twig-D9-LOF2p.js +1 -0
- package/studio/assets/typescript-BPQ3VLAy.js +1 -0
- package/studio/assets/typespec-ClX509-Q.js +1 -0
- package/studio/assets/typst-DamkJZ1Q.js +1 -0
- package/studio/assets/v-BGw2Nkan.js +1 -0
- package/studio/assets/vala-CsfeWuGM.js +1 -0
- package/studio/assets/vb-Cu-pLBUe.js +1 -0
- package/studio/assets/verilog-nZwndyjY.js +1 -0
- package/studio/assets/vesper-DRje8inN.js +1 -0
- package/studio/assets/vhdl-CeAyd5Ju.js +1 -0
- package/studio/assets/viml-CJc9bBzg.js +1 -0
- package/studio/assets/vitesse-black-Bkuqu6BP.js +1 -0
- package/studio/assets/vitesse-dark-D0r3Knsf.js +1 -0
- package/studio/assets/vitesse-light-CVO1_9PV.js +1 -0
- package/studio/assets/vue-DSqPwMUe.js +1 -0
- package/studio/assets/vue-html-AaS7Mt5G.js +1 -0
- package/studio/assets/vue-vine-C0RcJ6UU.js +1 -0
- package/studio/assets/vyper-CDx5xZoG.js +1 -0
- package/studio/assets/wasm-Cey7Y6ql.js +1 -0
- package/studio/assets/wasm-MzD3tlZU.js +1 -0
- package/studio/assets/wenyan-BV7otONQ.js +1 -0
- package/studio/assets/wgsl-Dx-B1_4e.js +1 -0
- package/studio/assets/wikitext-BhOHFoWU.js +1 -0
- package/studio/assets/wit-5i3qLPDT.js +1 -0
- package/studio/assets/wolfram-lXgVvXCa.js +1 -0
- package/studio/assets/xml-sdJ4AIDG.js +1 -0
- package/studio/assets/xsl-CtQFsRM5.js +1 -0
- package/studio/assets/yaml-Buea-lGh.js +1 -0
- package/studio/assets/zenscript-DVFEvuxE.js +1 -0
- package/studio/assets/zig-VOosw3JB.js +1 -0
- package/studio/favicon.svg +7 -0
- package/studio/index.html +15 -0
|
@@ -0,0 +1,1184 @@
|
|
|
1
|
+
import { studioDist, mcpCommand, check } from './chunk-TPJZDQG6.js';
|
|
2
|
+
import { methods, client, ndJsonStream, PROTOCOL_VERSION } from '@agentclientprotocol/sdk';
|
|
3
|
+
import { execFile, execFileSync, spawn } from 'child_process';
|
|
4
|
+
import { Writable, Readable } from 'stream';
|
|
5
|
+
import { join, dirname, normalize, extname, basename, resolve, delimiter } from 'path';
|
|
6
|
+
import { createServer } from 'http';
|
|
7
|
+
import { readFileSync, existsSync, mkdirSync, writeFileSync, watch, statSync, readdirSync, mkdtempSync, accessSync, constants } from 'fs';
|
|
8
|
+
import { createRequire } from 'module';
|
|
9
|
+
import { homedir, tmpdir } from 'os';
|
|
10
|
+
import { promisify } from 'util';
|
|
11
|
+
import { fileURLToPath } from 'url';
|
|
12
|
+
import { EventEmitter } from 'events';
|
|
13
|
+
|
|
14
|
+
var AUTH_REQUIRED = -32e3;
|
|
15
|
+
var AgentStartError = class extends Error {
|
|
16
|
+
constructor(message, signIn) {
|
|
17
|
+
super(message);
|
|
18
|
+
this.signIn = signIn;
|
|
19
|
+
}
|
|
20
|
+
signIn;
|
|
21
|
+
};
|
|
22
|
+
async function startAgent(spec, cwd, options = {}) {
|
|
23
|
+
if (!spec.available) throw new AgentStartError(`${spec.name} is not installed. ${spec.install}`, false);
|
|
24
|
+
const child = spawn(spec.command, spec.args, { cwd, stdio: ["pipe", "pipe", "pipe"], env: process.env });
|
|
25
|
+
let lines = [];
|
|
26
|
+
child.stderr?.on("data", (d) => {
|
|
27
|
+
lines = [...lines, ...d.toString().split("\n").filter(Boolean)].slice(-20);
|
|
28
|
+
});
|
|
29
|
+
const exited = new Promise((_, reject) => {
|
|
30
|
+
child.once("error", (e) => reject(new AgentStartError(`${spec.name} did not start: ${e.message}`, false)));
|
|
31
|
+
child.once("exit", (code) => reject(new AgentStartError(`${spec.name} stopped (exit ${code}). ${lines.slice(-3).join(" ")}`.trim(), false)));
|
|
32
|
+
});
|
|
33
|
+
exited.catch(() => void 0);
|
|
34
|
+
let app = client({ name: "Poney Studio" });
|
|
35
|
+
if (options.onUpdate) app = app.onNotification(methods.client.session.update, ({ params }) => options.onUpdate(params));
|
|
36
|
+
app = app.onRequest(methods.client.session.requestPermission, ({ params }) => options.onPermission?.(params) ?? { outcome: { outcome: "cancelled" } });
|
|
37
|
+
const connection = app.connect(ndJsonStream(Writable.toWeb(child.stdin), Readable.toWeb(child.stdout)));
|
|
38
|
+
const stop = () => {
|
|
39
|
+
connection.close();
|
|
40
|
+
if (child.exitCode === null) child.kill();
|
|
41
|
+
};
|
|
42
|
+
const opened = (async () => {
|
|
43
|
+
const init = await connection.agent.request(methods.agent.initialize, {
|
|
44
|
+
protocolVersion: PROTOCOL_VERSION,
|
|
45
|
+
clientCapabilities: { fs: { readTextFile: false, writeTextFile: false }, terminal: false },
|
|
46
|
+
clientInfo: { name: "poney-studio", version: "0.1.0" }
|
|
47
|
+
});
|
|
48
|
+
const canAppend = init.agentCapabilities?.sessionCapabilities?.systemPrompt != null;
|
|
49
|
+
const systemPrompt = canAppend && options.systemPrompt ? { mode: "append", content: [{ type: "text", text: options.systemPrompt }] } : void 0;
|
|
50
|
+
const request = { cwd, mcpServers: options.mcpServers ?? [], ...systemPrompt ? { systemPrompt } : {} };
|
|
51
|
+
const session = await connection.agent.request(methods.agent.session.new, request);
|
|
52
|
+
return { sessionId: session.sessionId, session, systemPromptApplied: !!systemPrompt };
|
|
53
|
+
})();
|
|
54
|
+
const ms = options.timeoutMs ?? 6e4;
|
|
55
|
+
const late = new Promise((_, reject) => setTimeout(() => reject(new AgentStartError(`${spec.name} did not answer within ${Math.round(ms / 1e3)} seconds.`, false)), ms));
|
|
56
|
+
try {
|
|
57
|
+
const { sessionId, session, systemPromptApplied } = await Promise.race([opened, exited, late]);
|
|
58
|
+
return { child, connection, sessionId, session, systemPromptApplied, stderr: () => lines, stop };
|
|
59
|
+
} catch (e) {
|
|
60
|
+
stop();
|
|
61
|
+
if (e instanceof AgentStartError) throw e;
|
|
62
|
+
const err = e;
|
|
63
|
+
const signIn = err.code === AUTH_REQUIRED || /auth|sign.?in|log.?in|credential|api key/i.test(err.message ?? "");
|
|
64
|
+
throw new AgentStartError(signIn ? `${spec.name} needs a sign-in. ${spec.signIn}` : `${spec.name} failed: ${err.message ?? String(e)}`, signIn);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
var CATEGORY = { model: "model", thought_level: "effort", mode: "mode", speed: "speed" };
|
|
68
|
+
function withRecommendation(o) {
|
|
69
|
+
const m = /\s*\(recommended\)\s*$/i.exec(o.name);
|
|
70
|
+
return m ? { ...o, name: o.name.slice(0, m.index), recommended: true } : o;
|
|
71
|
+
}
|
|
72
|
+
function fromConfigOptions(options = []) {
|
|
73
|
+
return options.map((o) => {
|
|
74
|
+
const category = CATEGORY[o.category ?? ""] ?? "other";
|
|
75
|
+
if (o.type === "boolean") return { id: o.id, name: o.name, category, kind: "boolean", current: o.currentValue, options: [], via: "config" };
|
|
76
|
+
const flat = o.options.flatMap((x) => "group" in x ? x.options.map((y) => ({ ...y, group: x.name })) : [x]);
|
|
77
|
+
const choices = flat.map(withRecommendation).map(({ value, name, description, recommended, ...rest }) => ({
|
|
78
|
+
value,
|
|
79
|
+
name,
|
|
80
|
+
...description ? { description } : {},
|
|
81
|
+
..."group" in rest ? { group: rest.group } : {},
|
|
82
|
+
...recommended ? { recommended } : {}
|
|
83
|
+
}));
|
|
84
|
+
choices.sort((a, b) => Number(!!b.recommended) - Number(!!a.recommended));
|
|
85
|
+
return { id: o.id, name: o.name, category, kind: "select", current: o.currentValue, options: choices, via: "config" };
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
function fromLists(models, modes, have) {
|
|
89
|
+
const out = [];
|
|
90
|
+
if (models?.availableModels?.length && !have.some((s) => s.category === "model"))
|
|
91
|
+
out.push({ id: "model", name: "Model", category: "model", kind: "select", current: models.currentModelId ?? "", options: models.availableModels.map((m) => ({ value: m.modelId, name: m.name, ...m.description ? { description: m.description } : {} })), via: "model" });
|
|
92
|
+
if (modes?.availableModes?.length && !have.some((s) => s.category === "mode"))
|
|
93
|
+
out.push({ id: "mode", name: "Mode", category: "mode", kind: "select", current: modes.currentModeId ?? "", options: modes.availableModes.map((m) => ({ value: m.id, name: m.name, ...m.description ? { description: m.description } : {} })), via: "mode" });
|
|
94
|
+
return out;
|
|
95
|
+
}
|
|
96
|
+
async function applySetting(connection, sessionId, settings, id, value) {
|
|
97
|
+
const s = settings.find((x) => x.id === id);
|
|
98
|
+
if (!s) throw new Error(`No setting "${id}"`);
|
|
99
|
+
if (s.via === "config") {
|
|
100
|
+
const res = await connection.agent.request(
|
|
101
|
+
methods.agent.session.setConfigOption,
|
|
102
|
+
s.kind === "boolean" ? { sessionId, configId: id, type: "boolean", value: Boolean(value) } : { sessionId, configId: id, value: String(value) }
|
|
103
|
+
);
|
|
104
|
+
const next = fromConfigOptions(res.configOptions);
|
|
105
|
+
return [...next, ...settings.filter((x) => x.via !== "config")];
|
|
106
|
+
}
|
|
107
|
+
if (s.via === "mode") await connection.agent.request(methods.agent.session.setMode, { sessionId, modeId: String(value) });
|
|
108
|
+
else await connection.agent.request("session/set_model", { sessionId, modelId: String(value) });
|
|
109
|
+
return settings.map((x) => x.id === id ? { ...x, current: value } : x);
|
|
110
|
+
}
|
|
111
|
+
function workspaceProject(cwd) {
|
|
112
|
+
const name = basename(cwd) || "workspace";
|
|
113
|
+
const id = name.toLowerCase().replace(/[^a-z0-9._-]+/g, "-").replace(/^[^a-z0-9]+/, "") || "workspace";
|
|
114
|
+
return { cwd, id, name };
|
|
115
|
+
}
|
|
116
|
+
function emptyDocument(w) {
|
|
117
|
+
return { poneyVersion: "0.1.0", project: { id: w.id, name: w.name, description: `The code in ${w.cwd}.` }, model: {}, views: [], walkthroughs: [] };
|
|
118
|
+
}
|
|
119
|
+
function intoWorkspace(document, w) {
|
|
120
|
+
if (!document || typeof document !== "object") return document;
|
|
121
|
+
const d = document;
|
|
122
|
+
return { ...d, project: { ...d.project ?? {}, id: w.id, name: d.project?.name ?? w.name } };
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// src/agents/bridge.ts
|
|
126
|
+
var AgentBridge = class {
|
|
127
|
+
constructor(state, mcp) {
|
|
128
|
+
this.state = state;
|
|
129
|
+
this.mcp = mcp;
|
|
130
|
+
}
|
|
131
|
+
state;
|
|
132
|
+
mcp;
|
|
133
|
+
agent;
|
|
134
|
+
connection;
|
|
135
|
+
sessionId;
|
|
136
|
+
spec;
|
|
137
|
+
cwd = "";
|
|
138
|
+
queue = [];
|
|
139
|
+
busy = false;
|
|
140
|
+
settings = [];
|
|
141
|
+
briefed = false;
|
|
142
|
+
/** The agent took the briefing as system instructions; else each request carries a short reminder. */
|
|
143
|
+
systemPrompt = false;
|
|
144
|
+
/** The agent message being written in this turn, and tool calls by their ACP id. */
|
|
145
|
+
writing;
|
|
146
|
+
tools = /* @__PURE__ */ new Map();
|
|
147
|
+
choices = /* @__PURE__ */ new Map();
|
|
148
|
+
get connected() {
|
|
149
|
+
return !!this.sessionId;
|
|
150
|
+
}
|
|
151
|
+
/** Starts the agent in a folder and opens a session with the Poney tools. */
|
|
152
|
+
async connect(spec, cwd) {
|
|
153
|
+
await this.disconnect();
|
|
154
|
+
const mcp = this.mcp();
|
|
155
|
+
const agent = await startAgent(spec, cwd, {
|
|
156
|
+
mcpServers: [{ name: "poney", command: mcp.command, args: mcp.args, env: [{ name: "PONEY_HUB_URL", value: mcp.hubUrl }] }],
|
|
157
|
+
systemPrompt: briefing(cwd),
|
|
158
|
+
onUpdate: (n) => this.onUpdate(n),
|
|
159
|
+
onPermission: (p) => this.onPermission(p)
|
|
160
|
+
});
|
|
161
|
+
this.agent = agent;
|
|
162
|
+
this.spec = spec;
|
|
163
|
+
this.cwd = cwd;
|
|
164
|
+
this.sessionId = agent.sessionId;
|
|
165
|
+
this.connection = agent.connection;
|
|
166
|
+
const offered = fromConfigOptions(agent.session.configOptions ?? []);
|
|
167
|
+
const raw = agent.session;
|
|
168
|
+
this.settings = [...offered, ...fromLists(raw.models, raw.modes, offered)].map((s) => ({ ...s, initial: s.current }));
|
|
169
|
+
agent.child.once("exit", () => {
|
|
170
|
+
if (this.agent !== agent) return;
|
|
171
|
+
this.state.put({ from: "notice", text: `${spec.name} stopped. ${agent.stderr().slice(-2).join(" ")}`.trim(), tone: "error" });
|
|
172
|
+
this.reset();
|
|
173
|
+
});
|
|
174
|
+
this.briefed = agent.systemPromptApplied;
|
|
175
|
+
this.systemPrompt = agent.systemPromptApplied;
|
|
176
|
+
this.state.setWorkspace(workspaceProject(cwd), true);
|
|
177
|
+
this.publish();
|
|
178
|
+
}
|
|
179
|
+
/** Stops the agent. Questions go back to agents that listen over MCP. */
|
|
180
|
+
async disconnect() {
|
|
181
|
+
const agent = this.agent;
|
|
182
|
+
for (const choose of this.choices.values()) choose(null);
|
|
183
|
+
this.reset();
|
|
184
|
+
agent?.stop();
|
|
185
|
+
}
|
|
186
|
+
/** Stops the current request; the session stays. */
|
|
187
|
+
async cancel() {
|
|
188
|
+
if (!this.sessionId || !this.connection) return;
|
|
189
|
+
this.queue = [];
|
|
190
|
+
for (const choose of this.choices.values()) choose(null);
|
|
191
|
+
await this.connection.agent.notify(methods.agent.session.cancel, { sessionId: this.sessionId });
|
|
192
|
+
}
|
|
193
|
+
/** Changes one of the session's settings (model, effort, mode…). */
|
|
194
|
+
async setSetting(id, value) {
|
|
195
|
+
if (!this.sessionId || !this.connection) throw new Error("No agent is connected.");
|
|
196
|
+
this.settings = keepInitial(await applySetting(this.connection, this.sessionId, this.settings, id, value), this.settings);
|
|
197
|
+
this.publish();
|
|
198
|
+
}
|
|
199
|
+
/** The person's answer to a permission request. */
|
|
200
|
+
choose(messageId, optionId) {
|
|
201
|
+
this.choices.get(messageId)?.(optionId);
|
|
202
|
+
}
|
|
203
|
+
reset() {
|
|
204
|
+
this.agent = void 0;
|
|
205
|
+
this.connection = void 0;
|
|
206
|
+
this.sessionId = void 0;
|
|
207
|
+
this.queue = [];
|
|
208
|
+
this.busy = false;
|
|
209
|
+
this.writing = void 0;
|
|
210
|
+
this.tools.clear();
|
|
211
|
+
this.choices.clear();
|
|
212
|
+
this.state.setSession(null, null);
|
|
213
|
+
}
|
|
214
|
+
publish() {
|
|
215
|
+
if (!this.spec || !this.sessionId) return this.state.setSession(null, null);
|
|
216
|
+
this.state.setSession({ providerId: this.spec.id, name: this.spec.name, cwd: this.cwd, busy: this.busy, settings: this.settings }, (q) => this.enqueue(q));
|
|
217
|
+
}
|
|
218
|
+
enqueue(q) {
|
|
219
|
+
this.queue.push(q);
|
|
220
|
+
void this.drain();
|
|
221
|
+
}
|
|
222
|
+
/** Sends questions one at a time: an agent answers one prompt per turn. */
|
|
223
|
+
async drain() {
|
|
224
|
+
if (this.busy || !this.sessionId || !this.connection) return;
|
|
225
|
+
const q = this.queue.shift();
|
|
226
|
+
if (!q) return;
|
|
227
|
+
this.busy = true;
|
|
228
|
+
this.publish();
|
|
229
|
+
this.writing = void 0;
|
|
230
|
+
try {
|
|
231
|
+
await this.connection.agent.request(methods.agent.session.prompt, { sessionId: this.sessionId, prompt: [{ type: "text", text: this.promptFor(q) }] });
|
|
232
|
+
} catch (e) {
|
|
233
|
+
this.state.put({ from: "notice", text: `The request failed: ${e instanceof Error ? e.message : String(e)}`, tone: "error" });
|
|
234
|
+
} finally {
|
|
235
|
+
const last = this.writing;
|
|
236
|
+
if (last) this.state.put({ ...last, done: true });
|
|
237
|
+
this.writing = void 0;
|
|
238
|
+
this.busy = false;
|
|
239
|
+
this.publish();
|
|
240
|
+
void this.drain();
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
/** The person's words, with where they are, and the first time, how to work with Poney. */
|
|
244
|
+
promptFor(q) {
|
|
245
|
+
const where = [
|
|
246
|
+
q.walkthrough && `They are reading the walkthrough "${q.walkthrough}"${q.scene ? `, scene "${q.scene}"` : ""}.`,
|
|
247
|
+
q.selection && !q.context?.length && `They selected ${q.selection.kind} "${q.selection.title}" (${q.selection.ref}).`
|
|
248
|
+
].filter(Boolean);
|
|
249
|
+
const about = (q.context ?? []).map((c) => c.quote ? `- this text from the page: "${c.quote}"` : `- ${c.kind} "${c.title}" (${c.ref})`);
|
|
250
|
+
if (about.length) where.push(`The question is about:
|
|
251
|
+
${about.join("\n")}`);
|
|
252
|
+
const parts = [where.length ? `[${where.join(" ")}]` : "", q.text].filter(Boolean);
|
|
253
|
+
if (!this.briefed) {
|
|
254
|
+
this.briefed = true;
|
|
255
|
+
parts.unshift(briefing(this.cwd));
|
|
256
|
+
} else if (!this.systemPrompt) parts.unshift(`[Poney Studio: explain the code in ${this.cwd}, with Poney documents when a picture helps. Say so briefly if the request is about something else.]`);
|
|
257
|
+
return parts.join("\n\n");
|
|
258
|
+
}
|
|
259
|
+
onUpdate(n) {
|
|
260
|
+
if (n.sessionId !== this.sessionId) return;
|
|
261
|
+
const u = n.update;
|
|
262
|
+
switch (u.sessionUpdate) {
|
|
263
|
+
case "agent_message_chunk": {
|
|
264
|
+
if (u.content.type !== "text") return;
|
|
265
|
+
const text = (this.writing?.text ?? "") + u.content.text;
|
|
266
|
+
this.writing = this.state.put(this.writing ? { ...this.writing, text } : { from: "agent", text });
|
|
267
|
+
return;
|
|
268
|
+
}
|
|
269
|
+
case "tool_call": {
|
|
270
|
+
if (this.writing) this.state.put({ ...this.writing, done: true });
|
|
271
|
+
this.writing = void 0;
|
|
272
|
+
const m = this.state.put({ from: "tool", title: u.title, status: u.status ?? "pending", kind: u.kind });
|
|
273
|
+
this.tools.set(u.toolCallId, m);
|
|
274
|
+
return;
|
|
275
|
+
}
|
|
276
|
+
case "config_option_update": {
|
|
277
|
+
this.settings = keepInitial([...fromConfigOptions(u.configOptions), ...this.settings.filter((s) => s.via !== "config")], this.settings);
|
|
278
|
+
this.publish();
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
281
|
+
case "current_mode_update": {
|
|
282
|
+
this.settings = this.settings.map((s) => s.via === "mode" ? { ...s, current: u.currentModeId } : s);
|
|
283
|
+
this.publish();
|
|
284
|
+
return;
|
|
285
|
+
}
|
|
286
|
+
case "tool_call_update": {
|
|
287
|
+
const m = this.tools.get(u.toolCallId);
|
|
288
|
+
if (!m) return;
|
|
289
|
+
this.tools.set(u.toolCallId, this.state.put({ ...m, title: u.title ?? m.title, status: u.status ?? m.status }));
|
|
290
|
+
return;
|
|
291
|
+
}
|
|
292
|
+
default:
|
|
293
|
+
return;
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
async onPermission(p) {
|
|
297
|
+
const m = this.state.put({ from: "permission", title: p.toolCall.title ?? "The agent asks to continue", options: p.options.map((o) => ({ id: o.optionId, name: o.name, kind: o.kind })) });
|
|
298
|
+
const optionId = await new Promise((resolve2) => this.choices.set(m.id, resolve2));
|
|
299
|
+
this.choices.delete(m.id);
|
|
300
|
+
this.state.put({ ...m, chosen: optionId ?? "cancelled" });
|
|
301
|
+
return { outcome: optionId ? { outcome: "selected", optionId } : { outcome: "cancelled" } };
|
|
302
|
+
}
|
|
303
|
+
};
|
|
304
|
+
var keepInitial = (next, before) => next.map((s) => ({ ...s, initial: before.find((b) => b.id === s.id)?.initial ?? s.initial }));
|
|
305
|
+
function briefing(cwd) {
|
|
306
|
+
return `You work for a person in Poney Studio. Poney Studio shows walkthroughs and tours of the code in ${cwd} as diagrams and scenes. Your job is to help the person understand this code, and the way you answer is with Poney documents.
|
|
307
|
+
|
|
308
|
+
How to work:
|
|
309
|
+
- Call poney_guide once before you write a document: topic "tour" to teach code as it is, topic "change" to explain a commit or a branch. Follow it.
|
|
310
|
+
- Read the code before you claim anything about it. Never invent files, functions, tests or numbers.
|
|
311
|
+
- Copy code with poney_excerpt. Check every document with poney_check (repo "${cwd}", rev "working") until it has no errors. Look at each scene with poney_render.
|
|
312
|
+
- Show the document with poney_open: the person sees it at once, and Poney saves it to docs/poney/ in this folder. Pass documents inline to these tools. Do not write or change other files in the repository.
|
|
313
|
+
- Keep one document for this folder, and never lose what is in it. To add to it, get it with poney_read (includeDocument: true), add walkthroughs, diagrams or scenes, and open it again. Remove things only when the person asks.
|
|
314
|
+
|
|
315
|
+
How to answer questions:
|
|
316
|
+
- Each question from the person comes to you as a new message. When you have answered or opened the document, end your turn. Do not call poney_wait or poney_reply: they are for agents in their own session.
|
|
317
|
+
- The person may ask about a scene or an element; the request says which.
|
|
318
|
+
- Answer in plain, short words. When a picture helps, add a scene to the open document, open it again, and name the scene in your answer.
|
|
319
|
+
- If the person asks for something outside this code, say so briefly.`;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
// src/live/api.ts
|
|
323
|
+
var LocalLive = class {
|
|
324
|
+
constructor(state, server) {
|
|
325
|
+
this.state = state;
|
|
326
|
+
this.server = server;
|
|
327
|
+
}
|
|
328
|
+
state;
|
|
329
|
+
server;
|
|
330
|
+
get studioUrl() {
|
|
331
|
+
return this.server.studioUrl;
|
|
332
|
+
}
|
|
333
|
+
async open(document) {
|
|
334
|
+
return { revision: this.state.open(document), viewers: this.server.viewers };
|
|
335
|
+
}
|
|
336
|
+
async read() {
|
|
337
|
+
return { viewers: this.server.viewers, studio: this.state.studio, current: this.state.current(), thread: this.state.thread() };
|
|
338
|
+
}
|
|
339
|
+
async waitForQuestions(timeoutMs) {
|
|
340
|
+
const questions = await this.state.waitForQuestions(timeoutMs);
|
|
341
|
+
return { questions, viewers: this.server.viewers, place: { walkthrough: this.state.studio?.walkthrough, scene: this.state.studio?.scene }, answeredInStudio: !!this.state.status().session };
|
|
342
|
+
}
|
|
343
|
+
async reply(text, extra = {}) {
|
|
344
|
+
return this.state.reply(text, extra);
|
|
345
|
+
}
|
|
346
|
+
};
|
|
347
|
+
var RemoteLive = class {
|
|
348
|
+
constructor(url) {
|
|
349
|
+
this.url = url;
|
|
350
|
+
}
|
|
351
|
+
url;
|
|
352
|
+
get studioUrl() {
|
|
353
|
+
return `${this.url}/`;
|
|
354
|
+
}
|
|
355
|
+
async call(path, init) {
|
|
356
|
+
const res = await fetch(`${this.url}${path}`, {
|
|
357
|
+
method: init?.method ?? (init?.body === void 0 ? "GET" : "POST"),
|
|
358
|
+
headers: init?.body === void 0 ? void 0 : { "content-type": "application/json" },
|
|
359
|
+
body: init?.body === void 0 ? void 0 : JSON.stringify(init.body),
|
|
360
|
+
signal: AbortSignal.timeout(init?.timeoutMs ?? 3e4)
|
|
361
|
+
});
|
|
362
|
+
if (!res.ok) throw new Error(`The Poney hub at ${this.url} answered ${res.status}: ${await res.text()}`);
|
|
363
|
+
return await res.json();
|
|
364
|
+
}
|
|
365
|
+
open(document) {
|
|
366
|
+
return this.call("/api/live/open", { body: { document } });
|
|
367
|
+
}
|
|
368
|
+
read() {
|
|
369
|
+
return this.call("/api/live/read");
|
|
370
|
+
}
|
|
371
|
+
waitForQuestions(timeoutMs) {
|
|
372
|
+
return this.call(`/api/live/wait?timeout=${timeoutMs}`, { timeoutMs: timeoutMs + 1e4 });
|
|
373
|
+
}
|
|
374
|
+
reply(text, extra = {}) {
|
|
375
|
+
return this.call("/api/live/reply", { body: { text, ...extra } });
|
|
376
|
+
}
|
|
377
|
+
};
|
|
378
|
+
async function isPoneyHub(url) {
|
|
379
|
+
try {
|
|
380
|
+
const res = await fetch(`${url}/api/live`, { signal: AbortSignal.timeout(800) });
|
|
381
|
+
if (!res.ok) return false;
|
|
382
|
+
const body2 = await res.json();
|
|
383
|
+
return body2.poney === true;
|
|
384
|
+
} catch {
|
|
385
|
+
return false;
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
var require2 = createRequire(import.meta.url);
|
|
389
|
+
var exec = promisify(execFile);
|
|
390
|
+
function packageBin(pkg) {
|
|
391
|
+
try {
|
|
392
|
+
const manifest = require2.resolve(`${pkg}/package.json`);
|
|
393
|
+
const { bin } = require2(manifest);
|
|
394
|
+
const file = typeof bin === "string" ? bin : bin && Object.values(bin)[0];
|
|
395
|
+
return file ? join(dirname(manifest), file) : void 0;
|
|
396
|
+
} catch {
|
|
397
|
+
return void 0;
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
function onPath(program) {
|
|
401
|
+
for (const dir of (process.env.PATH ?? "").split(delimiter)) {
|
|
402
|
+
if (!dir) continue;
|
|
403
|
+
const file = join(dir, program);
|
|
404
|
+
try {
|
|
405
|
+
accessSync(file, constants.X_OK);
|
|
406
|
+
return file;
|
|
407
|
+
} catch {
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
return void 0;
|
|
411
|
+
}
|
|
412
|
+
async function run(command, args) {
|
|
413
|
+
try {
|
|
414
|
+
const { stdout, stderr } = await exec(command, args, { timeout: 2e4, env: { ...process.env, NO_COLOR: "1" } });
|
|
415
|
+
return { code: 0, out: strip(`${stdout}${stderr}`) };
|
|
416
|
+
} catch (e) {
|
|
417
|
+
const err = e;
|
|
418
|
+
return { code: typeof err.code === "number" ? err.code : 1, out: strip(`${err.stdout ?? ""}${err.stderr ?? err.message}`) };
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
var strip = (t) => t.replace(/\x1b\[[0-9;]*m/g, "").trim();
|
|
422
|
+
async function claudeStatus() {
|
|
423
|
+
const bin = onPath("claude");
|
|
424
|
+
if (!bin) return void 0;
|
|
425
|
+
const { out } = await run(bin, ["auth", "status"]);
|
|
426
|
+
try {
|
|
427
|
+
const s = JSON.parse(out.slice(out.indexOf("{")));
|
|
428
|
+
return s.loggedIn ? { state: "ready", detail: `Signed in${s.authMethod ? ` with ${s.authMethod}` : ""}${s.configDirectory ? ` (${s.configDirectory.replace(homedir(), "~")})` : ""}.` } : { state: "sign-in", detail: "Not signed in." };
|
|
429
|
+
} catch {
|
|
430
|
+
return { state: "unsure", detail: "Claude Code did not say whether it is signed in." };
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
async function codexStatus() {
|
|
434
|
+
const bin = onPath("codex");
|
|
435
|
+
if (!bin) return void 0;
|
|
436
|
+
const { code, out } = await run(bin, ["login", "status"]);
|
|
437
|
+
return code === 0 ? { state: "ready", detail: `${out.split("\n")[0] || "Signed in"}.` } : { state: "sign-in", detail: out.split("\n")[0] || "Not signed in." };
|
|
438
|
+
}
|
|
439
|
+
async function opencodeStatus(bin) {
|
|
440
|
+
const { out } = await run(bin, ["auth", "list"]);
|
|
441
|
+
const stored = Number(/(\d+)\s+credentials?/i.exec(out)?.[1] ?? 0);
|
|
442
|
+
const fromEnv = [...out.matchAll(/●\s+(.+?)\s+([A-Z][A-Z0-9_]+)\s*$/gm)].map((m) => `${m[1]} (${m[2]})`);
|
|
443
|
+
if (stored > 0) return { state: "ready", detail: `${stored} stored sign-in${stored > 1 ? "s" : ""}.` };
|
|
444
|
+
if (fromEnv.length) return { state: "unsure", detail: `No stored sign-in. It can only use keys from your environment: ${fromEnv.join(", ")}.` };
|
|
445
|
+
return { state: "sign-in", detail: "No sign-in, and no provider key in the environment." };
|
|
446
|
+
}
|
|
447
|
+
function builtInProviders() {
|
|
448
|
+
const claude = packageBin("@agentclientprotocol/claude-agent-acp");
|
|
449
|
+
const codex = packageBin("@agentclientprotocol/codex-acp");
|
|
450
|
+
const opencode = onPath("opencode");
|
|
451
|
+
const copilot = onPath("copilot");
|
|
452
|
+
return [
|
|
453
|
+
{ id: "claude-code", name: "Claude Code", command: process.execPath, args: claude ? [claude] : [], available: !!claude, install: "Reinstall Poney's dependencies (npm install).", signIn: 'Run "claude" in a terminal and sign in with /login.', status: claudeStatus },
|
|
454
|
+
{ id: "codex", name: "OpenAI Codex", command: process.execPath, args: codex ? [codex] : [], available: !!codex, install: "Reinstall Poney's dependencies (npm install).", signIn: 'Run "codex login" in a terminal.', status: codexStatus },
|
|
455
|
+
{ id: "opencode", name: "OpenCode", command: opencode ?? "opencode", args: ["acp"], available: !!opencode, install: "Install OpenCode: https://opencode.ai", signIn: 'Run "opencode auth login" in a terminal.', status: opencode ? () => opencodeStatus(opencode) : void 0 },
|
|
456
|
+
{ id: "copilot", name: "GitHub Copilot", command: copilot ?? "copilot", args: ["--acp", "--stdio"], available: !!copilot, install: "Install the Copilot CLI: npm install -g @github/copilot", signIn: 'Run "copilot" in a terminal and sign in with /login.' }
|
|
457
|
+
];
|
|
458
|
+
}
|
|
459
|
+
function parseCommand(line) {
|
|
460
|
+
const words = [...line.matchAll(/"([^"]*)"|'([^']*)'|(\S+)/g)].map((m) => m[1] ?? m[2] ?? m[3]);
|
|
461
|
+
if (!words.length) return void 0;
|
|
462
|
+
return { command: words[0], args: words.slice(1) };
|
|
463
|
+
}
|
|
464
|
+
function customProvider(name, commandLine) {
|
|
465
|
+
const parsed = parseCommand(commandLine);
|
|
466
|
+
if (!parsed) return void 0;
|
|
467
|
+
const found = parsed.command.includes("/") ? parsed.command : onPath(parsed.command);
|
|
468
|
+
return { id: `custom:${name}`, name, ...parsed, command: found ?? parsed.command, available: !!found, install: `"${parsed.command}" is not on PATH.`, signIn: "Sign in as the agent's documentation says.", custom: true };
|
|
469
|
+
}
|
|
470
|
+
var describeProvider = ({ id, name, install, available, signIn, custom }) => ({ id, name, install, available, signIn, ...custom ? { custom } : {} });
|
|
471
|
+
var run2 = promisify(execFile);
|
|
472
|
+
var CLONES = join(homedir(), ".poney", "workspaces");
|
|
473
|
+
var isGit = (dir) => existsSync(join(dir, ".git"));
|
|
474
|
+
function listFolders(path) {
|
|
475
|
+
const dir = resolve(path || homedir());
|
|
476
|
+
if (!existsSync(dir) || !statSync(dir).isDirectory()) throw new Error(`No folder "${dir}"`);
|
|
477
|
+
const entries = readdirSync(dir, { withFileTypes: true });
|
|
478
|
+
const files = entries.filter((e) => e.isFile() && e.name.endsWith(".poney")).map((e) => ({ name: e.name, path: join(dir, e.name) })).sort((a, b) => a.name.localeCompare(b.name));
|
|
479
|
+
const folders = entries.filter((e) => e.isDirectory() && !e.name.startsWith(".") && e.name !== "node_modules").map((e) => ({ name: e.name, path: join(dir, e.name), git: isGit(join(dir, e.name)) })).sort((a, b) => a.name.localeCompare(b.name));
|
|
480
|
+
const parent = dirname(dir);
|
|
481
|
+
return { path: dir, parent: parent === dir ? void 0 : parent, git: isGit(dir), folders, files };
|
|
482
|
+
}
|
|
483
|
+
function checkFolder(path) {
|
|
484
|
+
const dir = resolve(path);
|
|
485
|
+
if (!existsSync(dir) || !statSync(dir).isDirectory()) throw new Error(`No folder "${dir}"`);
|
|
486
|
+
return dir;
|
|
487
|
+
}
|
|
488
|
+
var GIT_URL = /^(https:\/\/[\w.@:/~-]+|git@[\w.-]+:[\w./~-]+|ssh:\/\/[\w.@:/~-]+)$/;
|
|
489
|
+
async function cloneRepository(url) {
|
|
490
|
+
const clean = url.trim().replace(/\/+$/, "");
|
|
491
|
+
if (!GIT_URL.test(clean)) throw new Error("Give an https://, ssh:// or git@ address of a Git repository.");
|
|
492
|
+
const name = basename(clean).replace(/\.git$/, "").replace(/[^\w.-]/g, "-") || "repository";
|
|
493
|
+
const owner = basename(dirname(clean.replace(/^git@[^:]+:/, "/"))).replace(/[^\w.-]/g, "-");
|
|
494
|
+
const dest = join(CLONES, owner ? `${owner}-${name}` : name);
|
|
495
|
+
if (isGit(dest)) return dest;
|
|
496
|
+
mkdirSync(CLONES, { recursive: true });
|
|
497
|
+
try {
|
|
498
|
+
await run2("git", ["clone", "--depth", "100", "--", clean, dest], { timeout: 10 * 6e4, env: { ...process.env, GIT_TERMINAL_PROMPT: "0" } });
|
|
499
|
+
} catch (e) {
|
|
500
|
+
const err = e;
|
|
501
|
+
throw new Error(`git clone failed: ${(err.stderr ?? err.message).trim().split("\n").pop()}`);
|
|
502
|
+
}
|
|
503
|
+
return dest;
|
|
504
|
+
}
|
|
505
|
+
var fileLists = /* @__PURE__ */ new Map();
|
|
506
|
+
async function filesOf(dir) {
|
|
507
|
+
const hit = fileLists.get(dir);
|
|
508
|
+
if (hit && Date.now() - hit.at < 3e4) return hit.files;
|
|
509
|
+
let files;
|
|
510
|
+
try {
|
|
511
|
+
const { stdout } = await run2("git", ["-C", dir, "ls-files", "--cached", "--others", "--exclude-standard"], { maxBuffer: 64 * 1024 * 1024 });
|
|
512
|
+
files = stdout.split("\n").filter(Boolean);
|
|
513
|
+
} catch {
|
|
514
|
+
files = [];
|
|
515
|
+
const walk = (rel, depth) => {
|
|
516
|
+
if (files.length > 2e4 || depth > 8) return;
|
|
517
|
+
for (const e of readdirSync(join(dir, rel), { withFileTypes: true })) {
|
|
518
|
+
if (e.name.startsWith(".") || e.name === "node_modules" || e.name === "dist" || e.name === "_build" || e.name === "deps") continue;
|
|
519
|
+
const path = rel ? `${rel}/${e.name}` : e.name;
|
|
520
|
+
if (e.isDirectory()) walk(path, depth + 1);
|
|
521
|
+
else files.push(path);
|
|
522
|
+
}
|
|
523
|
+
};
|
|
524
|
+
walk("", 0);
|
|
525
|
+
}
|
|
526
|
+
fileLists.set(dir, { at: Date.now(), files });
|
|
527
|
+
return files;
|
|
528
|
+
}
|
|
529
|
+
async function searchFiles(dir, query, limit = 8) {
|
|
530
|
+
const words = query.toLowerCase().split(/\s+/).filter(Boolean);
|
|
531
|
+
const files = await filesOf(checkFolder(dir));
|
|
532
|
+
const score = (path) => {
|
|
533
|
+
const p = path.toLowerCase();
|
|
534
|
+
const name = basename(p);
|
|
535
|
+
if (!words.every((w2) => p.includes(w2))) return -1;
|
|
536
|
+
const w = words[words.length - 1] ?? "";
|
|
537
|
+
return (name.startsWith(w) ? 3 : name.includes(w) ? 2 : 1) * 1e3 - path.length;
|
|
538
|
+
};
|
|
539
|
+
return files.map((f) => [f, score(f)]).filter(([, s]) => s >= 0).sort((a, b) => b[1] - a[1]).slice(0, limit).map(([f]) => f);
|
|
540
|
+
}
|
|
541
|
+
var cache = /* @__PURE__ */ new Map();
|
|
542
|
+
var FRESH_MS = 5 * 6e4;
|
|
543
|
+
async function checkProvider(spec, fresh = false) {
|
|
544
|
+
const hit = cache.get(spec.id);
|
|
545
|
+
if (!fresh && hit && Date.now() - hit.at < FRESH_MS) return hit.status;
|
|
546
|
+
const status = await check2(spec);
|
|
547
|
+
cache.set(spec.id, { at: Date.now(), status });
|
|
548
|
+
return status;
|
|
549
|
+
}
|
|
550
|
+
async function check2(spec) {
|
|
551
|
+
if (!spec.available) return { state: "error", detail: spec.install };
|
|
552
|
+
const told = await spec.status?.().catch(() => void 0);
|
|
553
|
+
if (told) return told;
|
|
554
|
+
try {
|
|
555
|
+
const agent = await startAgent(spec, mkdtempSync(join(tmpdir(), "poney-check-")), { timeoutMs: 45e3 });
|
|
556
|
+
agent.stop();
|
|
557
|
+
return { state: "unsure", detail: "A test session opened. Poney cannot ask this agent whether it is signed in; the first request will tell." };
|
|
558
|
+
} catch (e) {
|
|
559
|
+
if (e instanceof AgentStartError && e.signIn) return { state: "sign-in", detail: "It asks for a sign-in." };
|
|
560
|
+
return { state: "error", detail: e instanceof Error ? e.message : String(e) };
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
var SOURCES = ["../../src", "../../../core/src", "../../../react/src", "../../../layout/src"].map((p) => fileURLToPath(new URL(p, import.meta.url)));
|
|
564
|
+
function buildStamp() {
|
|
565
|
+
let newest = 0;
|
|
566
|
+
const walk = (dir) => {
|
|
567
|
+
let entries;
|
|
568
|
+
try {
|
|
569
|
+
entries = readdirSync(dir, { withFileTypes: true });
|
|
570
|
+
} catch {
|
|
571
|
+
return;
|
|
572
|
+
}
|
|
573
|
+
for (const e of entries) {
|
|
574
|
+
const path = join(dir, e.name);
|
|
575
|
+
if (e.isDirectory()) walk(path);
|
|
576
|
+
else if (/\.(ts|tsx)$/.test(e.name)) newest = Math.max(newest, statSync(path).mtimeMs);
|
|
577
|
+
}
|
|
578
|
+
};
|
|
579
|
+
SOURCES.forEach(walk);
|
|
580
|
+
return String(Math.round(newest));
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
// src/live/server.ts
|
|
584
|
+
var DIST = studioDist();
|
|
585
|
+
var TYPES = {
|
|
586
|
+
".html": "text/html; charset=utf-8",
|
|
587
|
+
".js": "text/javascript",
|
|
588
|
+
".css": "text/css",
|
|
589
|
+
".svg": "image/svg+xml",
|
|
590
|
+
".woff2": "font/woff2",
|
|
591
|
+
".woff": "font/woff",
|
|
592
|
+
".png": "image/png",
|
|
593
|
+
".json": "application/json"
|
|
594
|
+
};
|
|
595
|
+
var DEV_ORIGINS = ["http://localhost:5173", "http://127.0.0.1:5173"];
|
|
596
|
+
var LiveServer = class {
|
|
597
|
+
constructor(state, bridge, files) {
|
|
598
|
+
this.state = state;
|
|
599
|
+
this.bridge = bridge;
|
|
600
|
+
this.files = files;
|
|
601
|
+
const send = (event, data) => {
|
|
602
|
+
const payload = `event: ${event}
|
|
603
|
+
data: ${JSON.stringify(data)}
|
|
604
|
+
|
|
605
|
+
`;
|
|
606
|
+
for (const c of this.clients) c.write(payload);
|
|
607
|
+
};
|
|
608
|
+
state.on("document", (revision, document, source) => send("document", { revision, document, source }));
|
|
609
|
+
state.on("message", (message) => send("message", message));
|
|
610
|
+
state.on("agent", (status) => send("agent", status));
|
|
611
|
+
state.on("file", (path) => send("file", { path: path ?? null }));
|
|
612
|
+
state.on("workspace", (w) => send("project", { root: w?.cwd ?? null, name: w?.name ?? null }));
|
|
613
|
+
state.on("overlays", (o) => send("overlays", o));
|
|
614
|
+
}
|
|
615
|
+
state;
|
|
616
|
+
bridge;
|
|
617
|
+
files;
|
|
618
|
+
server;
|
|
619
|
+
clients = /* @__PURE__ */ new Set();
|
|
620
|
+
port = 0;
|
|
621
|
+
/** The code this hub runs, and who started it ("dev" for the Studio's dev server). */
|
|
622
|
+
build = buildStamp();
|
|
623
|
+
owner = process.env.PONEY_HUB_OWNER ?? "other";
|
|
624
|
+
/** Called when a local program asks this hub to stop (see /api/live/stop). */
|
|
625
|
+
onStopRequest;
|
|
626
|
+
get url() {
|
|
627
|
+
return `http://127.0.0.1:${this.port}`;
|
|
628
|
+
}
|
|
629
|
+
get servesStudio() {
|
|
630
|
+
return existsSync(join(DIST, "index.html"));
|
|
631
|
+
}
|
|
632
|
+
/** Where a person opens the Studio for this hub. */
|
|
633
|
+
get studioUrl() {
|
|
634
|
+
return this.servesStudio ? `${this.url}/` : `http://localhost:5173/?live=${encodeURIComponent(this.url)}`;
|
|
635
|
+
}
|
|
636
|
+
get viewers() {
|
|
637
|
+
return this.clients.size;
|
|
638
|
+
}
|
|
639
|
+
async start(preferred = Number(process.env.PONEY_PORT ?? 5319)) {
|
|
640
|
+
for (let port = preferred; port < preferred + 20; port++) {
|
|
641
|
+
try {
|
|
642
|
+
await this.listen(port);
|
|
643
|
+
this.port = port;
|
|
644
|
+
return;
|
|
645
|
+
} catch {
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
throw new Error(`No free port from ${preferred} to ${preferred + 19}`);
|
|
649
|
+
}
|
|
650
|
+
listen(port) {
|
|
651
|
+
return new Promise((resolve2, reject) => {
|
|
652
|
+
const server = createServer((req, res) => void this.handle(req, res));
|
|
653
|
+
server.once("error", reject);
|
|
654
|
+
server.listen(port, "127.0.0.1", () => {
|
|
655
|
+
this.server = server;
|
|
656
|
+
resolve2();
|
|
657
|
+
});
|
|
658
|
+
});
|
|
659
|
+
}
|
|
660
|
+
stop() {
|
|
661
|
+
this.state.close();
|
|
662
|
+
this.files?.close();
|
|
663
|
+
void this.bridge?.disconnect();
|
|
664
|
+
for (const c of this.clients) c.end();
|
|
665
|
+
this.server?.close();
|
|
666
|
+
}
|
|
667
|
+
/* ─── Requests ──────────────────────────────────────────────────────── */
|
|
668
|
+
allowedOrigin(origin) {
|
|
669
|
+
return !origin || origin === this.url || origin === `http://localhost:${this.port}` || DEV_ORIGINS.includes(origin);
|
|
670
|
+
}
|
|
671
|
+
async handle(req, res) {
|
|
672
|
+
const host = req.headers.host ?? "";
|
|
673
|
+
if (host !== `127.0.0.1:${this.port}` && host !== `localhost:${this.port}`) return void res.writeHead(403).end("Wrong host");
|
|
674
|
+
const origin = req.headers.origin;
|
|
675
|
+
if (!this.allowedOrigin(origin)) return void res.writeHead(403).end("Wrong origin");
|
|
676
|
+
if (origin) {
|
|
677
|
+
res.setHeader("Access-Control-Allow-Origin", origin);
|
|
678
|
+
res.setHeader("Vary", "Origin");
|
|
679
|
+
res.setHeader("Access-Control-Allow-Headers", "content-type");
|
|
680
|
+
}
|
|
681
|
+
if (req.method === "OPTIONS") return void res.writeHead(204).end();
|
|
682
|
+
const url = new URL(req.url ?? "/", this.url);
|
|
683
|
+
try {
|
|
684
|
+
if (url.pathname.startsWith("/api/")) return await this.api(url, req, res);
|
|
685
|
+
return this.serveStudio(url.pathname, res);
|
|
686
|
+
} catch (e) {
|
|
687
|
+
json(res, 400, { error: e instanceof Error ? e.message : String(e) });
|
|
688
|
+
}
|
|
689
|
+
}
|
|
690
|
+
async api(url, req, res) {
|
|
691
|
+
const route = `${req.method} ${url.pathname}`;
|
|
692
|
+
const s = this.state;
|
|
693
|
+
switch (route) {
|
|
694
|
+
/* Live document and conversation */
|
|
695
|
+
case "GET /api/live":
|
|
696
|
+
return json(res, 200, { poney: true, revision: s.shown()?.revision ?? 0, viewers: this.viewers, build: this.build, owner: this.owner });
|
|
697
|
+
case "POST /api/live/stop":
|
|
698
|
+
if (req.headers.origin || this.owner !== "dev" || !this.onStopRequest) return json(res, 403, { error: "This hub does not stop on request." });
|
|
699
|
+
json(res, 200, { stopping: true });
|
|
700
|
+
setTimeout(() => this.onStopRequest?.(), 50);
|
|
701
|
+
return;
|
|
702
|
+
case "GET /api/live/events":
|
|
703
|
+
return this.events(req, res);
|
|
704
|
+
case "POST /api/live/state":
|
|
705
|
+
s.report(await body(req));
|
|
706
|
+
return void res.writeHead(204).end();
|
|
707
|
+
case "POST /api/live/open": {
|
|
708
|
+
const { document } = await body(req);
|
|
709
|
+
if (document === void 0) return json(res, 400, { error: "Give a document" });
|
|
710
|
+
return json(res, 200, { revision: s.open(document), viewers: this.viewers });
|
|
711
|
+
}
|
|
712
|
+
case "GET /api/live/read":
|
|
713
|
+
return json(res, 200, { viewers: this.viewers, studio: s.studio, current: s.current(), thread: s.thread() });
|
|
714
|
+
case "GET /api/live/wait": {
|
|
715
|
+
const ms = Math.min(9e5, Math.max(0, Number(url.searchParams.get("timeout") ?? 3e5)));
|
|
716
|
+
const questions = await s.waitForQuestions(ms);
|
|
717
|
+
return json(res, 200, { questions, viewers: this.viewers, place: { walkthrough: s.studio?.walkthrough, scene: s.studio?.scene }, answeredInStudio: !!s.status().session });
|
|
718
|
+
}
|
|
719
|
+
case "POST /api/live/ask": {
|
|
720
|
+
const q = await body(req);
|
|
721
|
+
const text = typeof q.text === "string" ? q.text.trim().slice(0, 8e3) : "";
|
|
722
|
+
if (!text) return json(res, 400, { error: "Empty question" });
|
|
723
|
+
const context = Array.isArray(q.context) ? q.context.slice(0, 12).map((c) => ({ ...c.ref ? { ref: String(c.ref).slice(0, 200) } : {}, title: String(c.title ?? "").slice(0, 200), kind: String(c.kind ?? "").slice(0, 40), ...c.quote ? { quote: String(c.quote).slice(0, 2e3) } : {} })) : void 0;
|
|
724
|
+
return json(res, 200, s.ask(text, { walkthrough: q.walkthrough, scene: q.scene, selection: q.selection, ...context?.length ? { context } : {} }));
|
|
725
|
+
}
|
|
726
|
+
case "POST /api/live/reply": {
|
|
727
|
+
const r = await body(req);
|
|
728
|
+
if (!r.text) return json(res, 400, { error: "Empty reply" });
|
|
729
|
+
return json(res, 200, s.reply(r.text, { inReplyTo: r.inReplyTo, walkthrough: r.walkthrough, scene: r.scene }));
|
|
730
|
+
}
|
|
731
|
+
/* Agents the Studio starts */
|
|
732
|
+
case "GET /api/agent":
|
|
733
|
+
return json(res, 200, { providers: builtInProviders().map(describeProvider), status: s.status(), canStart: !!this.bridge, mcpServer: mcpCommand() });
|
|
734
|
+
case "POST /api/agent/check": {
|
|
735
|
+
const r = await body(req);
|
|
736
|
+
const spec = providerFor(r);
|
|
737
|
+
if (!spec) return json(res, 400, { error: "Unknown agent" });
|
|
738
|
+
return json(res, 200, await checkProvider(spec, r.fresh));
|
|
739
|
+
}
|
|
740
|
+
case "POST /api/agent/connect": {
|
|
741
|
+
if (!this.bridge) return json(res, 400, { error: "This hub cannot start agents." });
|
|
742
|
+
const r = await body(req);
|
|
743
|
+
const spec = providerFor(r);
|
|
744
|
+
if (!spec) return json(res, 400, { error: "Unknown agent" });
|
|
745
|
+
await this.bridge.connect(spec, checkFolder(r.cwd ?? ""));
|
|
746
|
+
return json(res, 200, s.status());
|
|
747
|
+
}
|
|
748
|
+
case "POST /api/agent/disconnect":
|
|
749
|
+
await this.bridge?.disconnect();
|
|
750
|
+
return json(res, 200, s.status());
|
|
751
|
+
case "POST /api/agent/cancel":
|
|
752
|
+
await this.bridge?.cancel();
|
|
753
|
+
return json(res, 200, s.status());
|
|
754
|
+
case "POST /api/agent/setting": {
|
|
755
|
+
const r = await body(req);
|
|
756
|
+
if (!this.bridge || !r.id || r.value === void 0) return json(res, 400, { error: "Give id and value" });
|
|
757
|
+
await this.bridge.setSetting(r.id, r.value);
|
|
758
|
+
return json(res, 200, s.status());
|
|
759
|
+
}
|
|
760
|
+
case "POST /api/agent/permission": {
|
|
761
|
+
const r = await body(req);
|
|
762
|
+
if (typeof r.messageId !== "number" || !r.optionId) return json(res, 400, { error: "Give messageId and optionId" });
|
|
763
|
+
this.bridge?.choose(r.messageId, r.optionId);
|
|
764
|
+
return json(res, 200, { ok: true });
|
|
765
|
+
}
|
|
766
|
+
/* The project folder */
|
|
767
|
+
case "GET /api/plugins": {
|
|
768
|
+
const { available } = await import('./run-25PP2HWH.js');
|
|
769
|
+
const dir = s.project?.cwd;
|
|
770
|
+
if (!dir) return json(res, 200, { root: null, importers: [], overlays: [], problems: [] });
|
|
771
|
+
return json(res, 200, { root: dir, ...await available(dir) });
|
|
772
|
+
}
|
|
773
|
+
case "POST /api/import": {
|
|
774
|
+
const { runImport } = await import('./run-25PP2HWH.js');
|
|
775
|
+
const r = await body(req);
|
|
776
|
+
if (!s.project) return json(res, 400, { error: "Choose the folder with the code first." });
|
|
777
|
+
const { document, summary } = await runImport(r.importer ?? "", s.project.cwd, { into: s.current(), path: r.path, store: r.store });
|
|
778
|
+
const checked = check({ document });
|
|
779
|
+
if (!checked.result?.ok) return json(res, 400, { error: `The document has errors after the import.
|
|
780
|
+
${checked.report}` });
|
|
781
|
+
s.open(document, "agent");
|
|
782
|
+
return json(res, 200, { summary });
|
|
783
|
+
}
|
|
784
|
+
case "POST /api/overlays/run": {
|
|
785
|
+
const { runOverlay } = await import('./run-25PP2HWH.js');
|
|
786
|
+
const r = await body(req);
|
|
787
|
+
if (!s.project) return json(res, 400, { error: "Choose the folder with the code first." });
|
|
788
|
+
const result = await runOverlay(r.id ?? "", s.project.cwd, s.current());
|
|
789
|
+
s.setOverlay(r.id, result);
|
|
790
|
+
return json(res, 200, result);
|
|
791
|
+
}
|
|
792
|
+
case "POST /api/overlays/clear": {
|
|
793
|
+
const r = await body(req);
|
|
794
|
+
s.setOverlay(r.id ?? "", null);
|
|
795
|
+
return json(res, 200, {});
|
|
796
|
+
}
|
|
797
|
+
case "POST /api/project/open": {
|
|
798
|
+
const r = await body(req);
|
|
799
|
+
s.setWorkspace(workspaceProject(checkFolder(r.path ?? "")));
|
|
800
|
+
return json(res, 200, { root: s.project?.cwd });
|
|
801
|
+
}
|
|
802
|
+
case "POST /api/agent/connect-here": {
|
|
803
|
+
if (!this.bridge) return json(res, 400, { error: "This hub cannot start agents." });
|
|
804
|
+
const r = await body(req);
|
|
805
|
+
if (r.folder) s.setWorkspace(workspaceProject(checkFolder(r.folder)), true);
|
|
806
|
+
if (!s.project) return json(res, 400, { error: "Choose the folder with the code first." });
|
|
807
|
+
const spec = providerFor(r);
|
|
808
|
+
if (!spec) return json(res, 400, { error: "Unknown agent" });
|
|
809
|
+
await this.bridge.connect(spec, s.project.cwd);
|
|
810
|
+
return json(res, 200, s.status());
|
|
811
|
+
}
|
|
812
|
+
/* Files */
|
|
813
|
+
case "POST /api/files/open": {
|
|
814
|
+
if (!this.files) return json(res, 400, { error: "This hub cannot open files." });
|
|
815
|
+
const r = await body(req);
|
|
816
|
+
if (!r.path) return json(res, 400, { error: "Give a path" });
|
|
817
|
+
this.files.open(r.path);
|
|
818
|
+
return json(res, 200, { path: r.path });
|
|
819
|
+
}
|
|
820
|
+
/* Workspaces */
|
|
821
|
+
case "GET /api/workspace/folders":
|
|
822
|
+
return json(res, 200, listFolders(url.searchParams.get("path") ?? void 0));
|
|
823
|
+
case "GET /api/workspace/files": {
|
|
824
|
+
const cwd = s.status().session?.cwd ?? (s.file ? dirname(s.file) : void 0);
|
|
825
|
+
if (!cwd) return json(res, 200, { files: [] });
|
|
826
|
+
return json(res, 200, { root: cwd, files: await searchFiles(cwd, url.searchParams.get("q") ?? "") });
|
|
827
|
+
}
|
|
828
|
+
case "POST /api/workspace/clone": {
|
|
829
|
+
const r = await body(req);
|
|
830
|
+
return json(res, 200, { path: await cloneRepository(r.url ?? "") });
|
|
831
|
+
}
|
|
832
|
+
default:
|
|
833
|
+
return json(res, 404, { error: `No route ${route}` });
|
|
834
|
+
}
|
|
835
|
+
}
|
|
836
|
+
/** Server-sent events: what is open now, then every change. */
|
|
837
|
+
events(req, res) {
|
|
838
|
+
res.writeHead(200, { "content-type": "text/event-stream", "cache-control": "no-cache", connection: "keep-alive" });
|
|
839
|
+
res.write(": connected\n\n");
|
|
840
|
+
const shown = this.state.shown();
|
|
841
|
+
if (shown) res.write(`event: document
|
|
842
|
+
data: ${JSON.stringify(shown)}
|
|
843
|
+
|
|
844
|
+
`);
|
|
845
|
+
res.write(`event: thread
|
|
846
|
+
data: ${JSON.stringify({ messages: this.state.thread() })}
|
|
847
|
+
|
|
848
|
+
`);
|
|
849
|
+
res.write(`event: agent
|
|
850
|
+
data: ${JSON.stringify(this.state.status())}
|
|
851
|
+
|
|
852
|
+
`);
|
|
853
|
+
res.write(`event: file
|
|
854
|
+
data: ${JSON.stringify({ path: this.state.file ?? null })}
|
|
855
|
+
|
|
856
|
+
`);
|
|
857
|
+
res.write(`event: project
|
|
858
|
+
data: ${JSON.stringify({ root: this.state.project?.cwd ?? null, name: this.state.project?.name ?? null })}
|
|
859
|
+
|
|
860
|
+
`);
|
|
861
|
+
res.write(`event: overlays
|
|
862
|
+
data: ${JSON.stringify(this.state.overlays)}
|
|
863
|
+
|
|
864
|
+
`);
|
|
865
|
+
this.clients.add(res);
|
|
866
|
+
const beat = setInterval(() => res.write(": beat\n\n"), 2e4);
|
|
867
|
+
req.on("close", () => {
|
|
868
|
+
clearInterval(beat);
|
|
869
|
+
this.clients.delete(res);
|
|
870
|
+
});
|
|
871
|
+
}
|
|
872
|
+
serveStudio(pathname, res) {
|
|
873
|
+
if (!this.servesStudio) {
|
|
874
|
+
res.writeHead(503, { "content-type": "text/plain; charset=utf-8" });
|
|
875
|
+
return void res.end('Poney Studio is not built. Run "npm run build" in the Poney repository, or run "npm run dev" and open the address the agent gives you.');
|
|
876
|
+
}
|
|
877
|
+
const safe = normalize(decodeURIComponent(pathname)).replace(/^(\.\.[/\\])+/, "");
|
|
878
|
+
let file = join(DIST, safe);
|
|
879
|
+
if (!file.startsWith(DIST) || !existsSync(file) || statSync(file).isDirectory()) file = join(DIST, "index.html");
|
|
880
|
+
res.writeHead(200, { "content-type": TYPES[extname(file)] ?? "application/octet-stream" });
|
|
881
|
+
res.end(readFileSync(file));
|
|
882
|
+
}
|
|
883
|
+
};
|
|
884
|
+
var providerFor = (r) => r.custom ? customProvider(r.custom.name, r.custom.command) : builtInProviders().find((p) => p.id === r.providerId);
|
|
885
|
+
function json(res, status, value) {
|
|
886
|
+
res.writeHead(status, { "content-type": "application/json" }).end(JSON.stringify(value));
|
|
887
|
+
}
|
|
888
|
+
function body(req) {
|
|
889
|
+
return new Promise((resolve2, reject) => {
|
|
890
|
+
let text = "";
|
|
891
|
+
req.on("data", (chunk) => {
|
|
892
|
+
text += chunk;
|
|
893
|
+
if (text.length > 2e7) req.destroy();
|
|
894
|
+
});
|
|
895
|
+
req.on("end", () => {
|
|
896
|
+
try {
|
|
897
|
+
resolve2(text ? JSON.parse(text) : {});
|
|
898
|
+
} catch {
|
|
899
|
+
reject(new Error("Not JSON"));
|
|
900
|
+
}
|
|
901
|
+
});
|
|
902
|
+
req.on("error", reject);
|
|
903
|
+
});
|
|
904
|
+
}
|
|
905
|
+
var LiveState = class extends EventEmitter {
|
|
906
|
+
document;
|
|
907
|
+
source = "agent";
|
|
908
|
+
revision = 0;
|
|
909
|
+
messages = [];
|
|
910
|
+
/** Questions an agent took over MCP (poney_wait). */
|
|
911
|
+
delivered = 0;
|
|
912
|
+
waiters = /* @__PURE__ */ new Set();
|
|
913
|
+
responder = null;
|
|
914
|
+
session = null;
|
|
915
|
+
workspace;
|
|
916
|
+
path;
|
|
917
|
+
studio;
|
|
918
|
+
shownOverlays = {};
|
|
919
|
+
/* ─── The document ──────────────────────────────────────────────────── */
|
|
920
|
+
/** Shows a document in every open Studio. Returns its revision. While an agent works in a folder, the document joins that folder's project. */
|
|
921
|
+
open(document, source = "agent") {
|
|
922
|
+
this.document = this.workspace && source === "agent" ? intoWorkspace(document, { ...this.workspace, id: this.openProjectId ?? this.workspace.id }) : document;
|
|
923
|
+
this.source = source;
|
|
924
|
+
this.revision++;
|
|
925
|
+
this.studio = void 0;
|
|
926
|
+
this.emit("document", this.revision, this.document, source);
|
|
927
|
+
return this.revision;
|
|
928
|
+
}
|
|
929
|
+
/** Overlay results shown in the Studio, by id. */
|
|
930
|
+
get overlays() {
|
|
931
|
+
return this.shownOverlays;
|
|
932
|
+
}
|
|
933
|
+
/** Shows an overlay's result, or with null, stops showing it. */
|
|
934
|
+
setOverlay(id, result) {
|
|
935
|
+
const { [id]: _, ...rest } = this.shownOverlays;
|
|
936
|
+
this.shownOverlays = result ? { ...rest, [id]: result } : rest;
|
|
937
|
+
this.emit("overlays", this.shownOverlays);
|
|
938
|
+
}
|
|
939
|
+
/** The file the open document is saved to. */
|
|
940
|
+
get file() {
|
|
941
|
+
return this.path;
|
|
942
|
+
}
|
|
943
|
+
setFile(path) {
|
|
944
|
+
this.path = path;
|
|
945
|
+
this.emit("file", path);
|
|
946
|
+
}
|
|
947
|
+
/** The open document and its revision, if any. */
|
|
948
|
+
shown() {
|
|
949
|
+
return this.document === void 0 ? void 0 : { revision: this.revision, document: this.document, source: this.source };
|
|
950
|
+
}
|
|
951
|
+
/** The document the person is looking at: their edits if any, else what was opened. */
|
|
952
|
+
current() {
|
|
953
|
+
return this.studio?.document ?? this.document;
|
|
954
|
+
}
|
|
955
|
+
report(state) {
|
|
956
|
+
this.studio = { ...state, receivedAt: (/* @__PURE__ */ new Date()).toISOString() };
|
|
957
|
+
if (state.document !== void 0) {
|
|
958
|
+
this.document = state.document;
|
|
959
|
+
this.emit("edited", state.document);
|
|
960
|
+
}
|
|
961
|
+
}
|
|
962
|
+
/* ─── The conversation ──────────────────────────────────────────────── */
|
|
963
|
+
thread() {
|
|
964
|
+
return [...this.messages];
|
|
965
|
+
}
|
|
966
|
+
/** Adds a message, or replaces the one with the same id. */
|
|
967
|
+
put(input) {
|
|
968
|
+
const existing = "id" in input ? this.messages.findIndex((m) => m.id === input.id) : -1;
|
|
969
|
+
const message = existing >= 0 ? input : { ...input, id: this.messages.length + 1, at: (/* @__PURE__ */ new Date()).toISOString() };
|
|
970
|
+
if (existing >= 0) this.messages[existing] = message;
|
|
971
|
+
else this.messages.push(message);
|
|
972
|
+
this.emit("message", message);
|
|
973
|
+
return message;
|
|
974
|
+
}
|
|
975
|
+
/**
|
|
976
|
+
* A question from the person. An agent the Studio started answers at once;
|
|
977
|
+
* otherwise it waits for an agent that listens over MCP.
|
|
978
|
+
*/
|
|
979
|
+
ask(text, place = {}) {
|
|
980
|
+
const m = this.put({ from: "person", text, ...place });
|
|
981
|
+
if (this.responder) {
|
|
982
|
+
this.delivered = m.id;
|
|
983
|
+
this.responder(m);
|
|
984
|
+
} else for (const wake of this.waiters) wake();
|
|
985
|
+
return m;
|
|
986
|
+
}
|
|
987
|
+
/** An answer written by an agent in its own session (poney_reply). */
|
|
988
|
+
reply(text, extra = {}) {
|
|
989
|
+
return this.put({ from: "agent", text, done: true, ...extra });
|
|
990
|
+
}
|
|
991
|
+
/**
|
|
992
|
+
* Questions no agent has taken yet. If there are none, waits up to
|
|
993
|
+
* `timeoutMs` for the next one. Returns an empty list when time runs out.
|
|
994
|
+
*/
|
|
995
|
+
async waitForQuestions(timeoutMs) {
|
|
996
|
+
if (this.responder) return [];
|
|
997
|
+
const pending = () => this.messages.filter((m) => m.from === "person" && m.id > this.delivered);
|
|
998
|
+
if (!pending().length) {
|
|
999
|
+
let wake = () => {
|
|
1000
|
+
};
|
|
1001
|
+
const woken = new Promise((resolve2) => wake = resolve2);
|
|
1002
|
+
this.waiters.add(wake);
|
|
1003
|
+
this.emitAgent();
|
|
1004
|
+
const timer = setTimeout(wake, timeoutMs);
|
|
1005
|
+
await woken;
|
|
1006
|
+
clearTimeout(timer);
|
|
1007
|
+
this.waiters.delete(wake);
|
|
1008
|
+
this.emitAgent();
|
|
1009
|
+
}
|
|
1010
|
+
const out = pending();
|
|
1011
|
+
if (out.length) this.delivered = Math.max(this.delivered, ...out.map((m) => m.id));
|
|
1012
|
+
return out;
|
|
1013
|
+
}
|
|
1014
|
+
/* ─── The workspace ─────────────────────────────────────────────────── */
|
|
1015
|
+
/** The project folder: the folder the open document belongs to, where agents work. */
|
|
1016
|
+
get project() {
|
|
1017
|
+
return this.workspace;
|
|
1018
|
+
}
|
|
1019
|
+
/**
|
|
1020
|
+
* Opens a folder as the project, or, with a document tied to it, records
|
|
1021
|
+
* the folder it belongs to. What opens for it (its file, the document already
|
|
1022
|
+
* open, or an empty project) is decided where files are known. With
|
|
1023
|
+
* `keep`, the folder is only where agents work: the open document stays.
|
|
1024
|
+
*/
|
|
1025
|
+
setWorkspace(w, keep = false) {
|
|
1026
|
+
if (w?.cwd === this.workspace?.cwd) return;
|
|
1027
|
+
this.workspace = w;
|
|
1028
|
+
this.emit("workspace", w, keep);
|
|
1029
|
+
}
|
|
1030
|
+
/** The id of the open document's project. */
|
|
1031
|
+
get openProjectId() {
|
|
1032
|
+
return this.document?.project?.id;
|
|
1033
|
+
}
|
|
1034
|
+
/* ─── Who answers ───────────────────────────────────────────────────── */
|
|
1035
|
+
/** An agent the Studio started takes over the questions; null gives them back to MCP agents. */
|
|
1036
|
+
setSession(session, responder) {
|
|
1037
|
+
this.session = session;
|
|
1038
|
+
this.responder = responder;
|
|
1039
|
+
if (responder) for (const wake of this.waiters) wake();
|
|
1040
|
+
this.emitAgent();
|
|
1041
|
+
}
|
|
1042
|
+
status() {
|
|
1043
|
+
return { session: this.session, listening: this.waiters.size > 0 };
|
|
1044
|
+
}
|
|
1045
|
+
emitAgent() {
|
|
1046
|
+
this.emit("agent", this.status());
|
|
1047
|
+
}
|
|
1048
|
+
/** Releases agents that wait for a question. */
|
|
1049
|
+
close() {
|
|
1050
|
+
for (const wake of this.waiters) wake();
|
|
1051
|
+
}
|
|
1052
|
+
};
|
|
1053
|
+
function repositoryOf(dir) {
|
|
1054
|
+
try {
|
|
1055
|
+
return execFileSync("git", ["-C", dir, "rev-parse", "--show-toplevel"], { encoding: "utf8", stdio: ["ignore", "pipe", "ignore"] }).trim() || void 0;
|
|
1056
|
+
} catch {
|
|
1057
|
+
return void 0;
|
|
1058
|
+
}
|
|
1059
|
+
}
|
|
1060
|
+
var workspaceFile = (w) => join(w.cwd, "docs", "poney", `${w.id}.poney`);
|
|
1061
|
+
var isEmpty = (doc) => {
|
|
1062
|
+
const d = doc;
|
|
1063
|
+
return !d?.views?.length && !d?.walkthroughs?.length;
|
|
1064
|
+
};
|
|
1065
|
+
var DocumentFiles = class {
|
|
1066
|
+
constructor(state) {
|
|
1067
|
+
this.state = state;
|
|
1068
|
+
state.on("document", (_rev, doc, source) => {
|
|
1069
|
+
if (source === "agent") this.save(doc);
|
|
1070
|
+
});
|
|
1071
|
+
state.on("edited", (doc) => this.save(doc));
|
|
1072
|
+
state.on("workspace", (w, keep) => w && this.openWorkspace(w, keep));
|
|
1073
|
+
}
|
|
1074
|
+
state;
|
|
1075
|
+
watcher;
|
|
1076
|
+
/** What this process wrote last, so its own writes are not read back as changes. */
|
|
1077
|
+
written;
|
|
1078
|
+
timer;
|
|
1079
|
+
/** The project the file holds. A document of another project releases the file; it never overwrites it. */
|
|
1080
|
+
project;
|
|
1081
|
+
/** Opens a .poney file and ties the document to it. Throws with the check report when it is not a valid document. */
|
|
1082
|
+
open(path) {
|
|
1083
|
+
const text = readFileSync(path, "utf8");
|
|
1084
|
+
const { result, report } = check({ text });
|
|
1085
|
+
if (!result?.ok) throw new Error(`"${path}" is not a valid Poney document.
|
|
1086
|
+
${report}`);
|
|
1087
|
+
const doc = JSON.parse(text);
|
|
1088
|
+
this.tie(path, doc.project?.id, text);
|
|
1089
|
+
this.state.open(doc, "file");
|
|
1090
|
+
const root = repositoryOf(dirname(path));
|
|
1091
|
+
if (root && root !== this.state.project?.cwd) this.state.setWorkspace(workspaceProject(root));
|
|
1092
|
+
}
|
|
1093
|
+
/**
|
|
1094
|
+
* A project folder. The document already open stays when it belongs here,
|
|
1095
|
+
* or when it has no file yet (it is saved to docs/poney/ here). Otherwise
|
|
1096
|
+
* the folder's own file opens, or an empty project that becomes a file when
|
|
1097
|
+
* there is something to keep.
|
|
1098
|
+
*/
|
|
1099
|
+
openWorkspace(w, keep = false) {
|
|
1100
|
+
const open = this.state.shown()?.document;
|
|
1101
|
+
const file = this.state.file;
|
|
1102
|
+
if (file && file.startsWith(`${w.cwd}/`)) return;
|
|
1103
|
+
if (keep && file && open && !isEmpty(open)) return;
|
|
1104
|
+
if (open && !file && !isEmpty(open)) {
|
|
1105
|
+
const id = this.state.openProjectId ?? w.id;
|
|
1106
|
+
this.tie(join(w.cwd, "docs", "poney", `${id}.poney`), id);
|
|
1107
|
+
return this.save(open);
|
|
1108
|
+
}
|
|
1109
|
+
const path = workspaceFile(w);
|
|
1110
|
+
if (existsSync(path)) {
|
|
1111
|
+
try {
|
|
1112
|
+
return this.open(path);
|
|
1113
|
+
} catch (e) {
|
|
1114
|
+
this.state.put({ from: "notice", text: e instanceof Error ? e.message.split("\n")[0] : String(e), tone: "error" });
|
|
1115
|
+
}
|
|
1116
|
+
}
|
|
1117
|
+
this.tie(path, w.id);
|
|
1118
|
+
if (this.state.openProjectId !== w.id) this.state.open(emptyDocument(w), "workspace");
|
|
1119
|
+
}
|
|
1120
|
+
tie(path, project, text) {
|
|
1121
|
+
this.watcher?.close();
|
|
1122
|
+
this.watcher = void 0;
|
|
1123
|
+
this.written = text;
|
|
1124
|
+
this.project = project;
|
|
1125
|
+
this.state.setFile(path);
|
|
1126
|
+
if (!path) return;
|
|
1127
|
+
if (existsSync(path)) this.watch(path);
|
|
1128
|
+
}
|
|
1129
|
+
/** Writes the document to its file, unless it is empty or unchanged. */
|
|
1130
|
+
save(doc) {
|
|
1131
|
+
const path = this.state.file;
|
|
1132
|
+
if (!path || isEmpty(doc)) return;
|
|
1133
|
+
const id = doc.project?.id;
|
|
1134
|
+
if (this.project && id !== this.project) return this.tie(void 0);
|
|
1135
|
+
const text = `${JSON.stringify(doc, null, 2)}
|
|
1136
|
+
`;
|
|
1137
|
+
if (text === this.written) return;
|
|
1138
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
1139
|
+
this.written = text;
|
|
1140
|
+
writeFileSync(path, text);
|
|
1141
|
+
if (!this.watcher) this.watch(path);
|
|
1142
|
+
}
|
|
1143
|
+
/** Changes on disk show in the Studio; a file that no longer reads as a document is reported, not opened. */
|
|
1144
|
+
watch(path) {
|
|
1145
|
+
this.watcher = watch(path, () => {
|
|
1146
|
+
clearTimeout(this.timer);
|
|
1147
|
+
this.timer = setTimeout(() => {
|
|
1148
|
+
if (this.state.file !== path || !existsSync(path)) return;
|
|
1149
|
+
const text = readFileSync(path, "utf8");
|
|
1150
|
+
if (text === this.written) return;
|
|
1151
|
+
const { result, report } = check({ text });
|
|
1152
|
+
if (!result?.ok) return void this.state.put({ from: "notice", text: `${path} changed on disk but is not a valid document: ${report.split("\n")[0]}`, tone: "error" });
|
|
1153
|
+
this.written = text;
|
|
1154
|
+
this.state.open(JSON.parse(text), "file");
|
|
1155
|
+
}, 150);
|
|
1156
|
+
});
|
|
1157
|
+
}
|
|
1158
|
+
close() {
|
|
1159
|
+
this.watcher?.close();
|
|
1160
|
+
}
|
|
1161
|
+
};
|
|
1162
|
+
|
|
1163
|
+
// src/live/hub.ts
|
|
1164
|
+
async function startHub(port) {
|
|
1165
|
+
const state = new LiveState();
|
|
1166
|
+
let server;
|
|
1167
|
+
const bridge = new AgentBridge(state, () => ({ ...mcpCommand(), command: process.execPath, hubUrl: server.url }));
|
|
1168
|
+
const files = new DocumentFiles(state);
|
|
1169
|
+
server = new LiveServer(state, bridge, files);
|
|
1170
|
+
await server.start(port);
|
|
1171
|
+
return { state, files, server, live: new LocalLive(state, server), bridge };
|
|
1172
|
+
}
|
|
1173
|
+
async function attachOrStart() {
|
|
1174
|
+
const given = process.env.PONEY_HUB_URL;
|
|
1175
|
+
if (given) return { live: new RemoteLive(given.replace(/\/+$/, "")) };
|
|
1176
|
+
const usual = `http://127.0.0.1:${Number(process.env.PONEY_PORT ?? 5319)}`;
|
|
1177
|
+
if (await isPoneyHub(usual)) return { live: new RemoteLive(usual) };
|
|
1178
|
+
const hub = await startHub();
|
|
1179
|
+
return { live: hub.live, hub };
|
|
1180
|
+
}
|
|
1181
|
+
|
|
1182
|
+
export { attachOrStart, startHub };
|
|
1183
|
+
//# sourceMappingURL=chunk-BCOS4LFB.js.map
|
|
1184
|
+
//# sourceMappingURL=chunk-BCOS4LFB.js.map
|