@pasko70/pibo 1.0.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/.codex/skills/pi-agent-harness/SKILL.md +319 -0
- package/.codex/skills/pi-agent-harness/agents/openai.yaml +4 -0
- package/README.md +318 -0
- package/context/codex-base-prompt.md +144 -0
- package/context/pibo-compaction-prompt.md +100 -0
- package/context/pibo-system-prompt.md +17 -0
- package/dist/apps/chat/agent-profiles.js +26 -0
- package/dist/apps/chat/agent-store.js +336 -0
- package/dist/apps/chat/event-log.js +307 -0
- package/dist/apps/chat/read-model.js +218 -0
- package/dist/apps/chat/rooms.js +321 -0
- package/dist/apps/chat/session-metadata.js +14 -0
- package/dist/apps/chat/stream.js +122 -0
- package/dist/apps/chat/trace.js +1182 -0
- package/dist/apps/chat/web-app.js +2569 -0
- package/dist/apps/chat-ui/assets/apl-BxEMbctQ.js +1 -0
- package/dist/apps/chat-ui/assets/asciiarmor-eFjeGRuZ.js +1 -0
- package/dist/apps/chat-ui/assets/asn1-Cfx-0pt9.js +1 -0
- package/dist/apps/chat-ui/assets/asterisk-B5BHTsBr.js +1 -0
- package/dist/apps/chat-ui/assets/brainfuck-CAA2xofr.js +1 -0
- package/dist/apps/chat-ui/assets/clike-BoDCOLzN.js +1 -0
- package/dist/apps/chat-ui/assets/clojure-kVFSWX0o.js +1 -0
- package/dist/apps/chat-ui/assets/cmake-BUPAhezI.js +1 -0
- package/dist/apps/chat-ui/assets/cobol-BfgHZgup.js +1 -0
- package/dist/apps/chat-ui/assets/coffeescript-G1Pe_1AZ.js +1 -0
- package/dist/apps/chat-ui/assets/commonlisp-B3N0CjHn.js +1 -0
- package/dist/apps/chat-ui/assets/crystal-C15ndaGM.js +1 -0
- package/dist/apps/chat-ui/assets/css-BqOeyZOV.js +1 -0
- package/dist/apps/chat-ui/assets/cypher-KjIKv-wW.js +1 -0
- package/dist/apps/chat-ui/assets/d-BlT5AEC-.js +1 -0
- package/dist/apps/chat-ui/assets/diff-oF98tbqj.js +1 -0
- package/dist/apps/chat-ui/assets/dist--55mTWk3.js +1 -0
- package/dist/apps/chat-ui/assets/dist-B5rcjVCj.js +1 -0
- package/dist/apps/chat-ui/assets/dist-BPv5MdlL.js +1 -0
- package/dist/apps/chat-ui/assets/dist-BZ39rB1W.js +1 -0
- package/dist/apps/chat-ui/assets/dist-BsedZGJo.js +1 -0
- package/dist/apps/chat-ui/assets/dist-BvO6SpaM.js +9 -0
- package/dist/apps/chat-ui/assets/dist-C5YJOwhH.js +1 -0
- package/dist/apps/chat-ui/assets/dist-C5oXtFSP.js +1 -0
- package/dist/apps/chat-ui/assets/dist-CG_gRSwv.js +23 -0
- package/dist/apps/chat-ui/assets/dist-CKM5j-iy.js +1 -0
- package/dist/apps/chat-ui/assets/dist-CUp9us2q.js +1 -0
- package/dist/apps/chat-ui/assets/dist-CZ9T4Cly.js +1 -0
- package/dist/apps/chat-ui/assets/dist-D4HhiFWB.js +6 -0
- package/dist/apps/chat-ui/assets/dist-DHE-yBLH.js +1 -0
- package/dist/apps/chat-ui/assets/dist-DSKQpPaz.js +1 -0
- package/dist/apps/chat-ui/assets/dist-L1B-KWZO.js +1 -0
- package/dist/apps/chat-ui/assets/dist-SVPsM5Oi.js +13 -0
- package/dist/apps/chat-ui/assets/dist-Zqt9kNG9.js +1 -0
- package/dist/apps/chat-ui/assets/dist-_DPv0-QF.js +1 -0
- package/dist/apps/chat-ui/assets/dist-_oM7g0eh.js +11 -0
- package/dist/apps/chat-ui/assets/dist-laadbMWg.js +1 -0
- package/dist/apps/chat-ui/assets/dist-nFui3f-r.js +2 -0
- package/dist/apps/chat-ui/assets/dist-tGfufz3b.js +1 -0
- package/dist/apps/chat-ui/assets/dockerfile-CUaqzcqp.js +1 -0
- package/dist/apps/chat-ui/assets/dtd-VCA9yr61.js +1 -0
- package/dist/apps/chat-ui/assets/dylan-O-V5Dw5W.js +1 -0
- package/dist/apps/chat-ui/assets/ebnf-SPmdBkvT.js +1 -0
- package/dist/apps/chat-ui/assets/ecl-ChfCttfI.js +1 -0
- package/dist/apps/chat-ui/assets/eiffel-cB9EbjeN.js +1 -0
- package/dist/apps/chat-ui/assets/elm-BTiVflBU.js +1 -0
- package/dist/apps/chat-ui/assets/erlang-egf0TXFm.js +1 -0
- package/dist/apps/chat-ui/assets/factor-C2tAxNob.js +1 -0
- package/dist/apps/chat-ui/assets/fcl-BiCjh1tj.js +1 -0
- package/dist/apps/chat-ui/assets/forth-C4kDGW6u.js +1 -0
- package/dist/apps/chat-ui/assets/fortran-DzkLaPnd.js +1 -0
- package/dist/apps/chat-ui/assets/gas-DMOxskQF.js +1 -0
- package/dist/apps/chat-ui/assets/gherkin-BPxBpp-k.js +1 -0
- package/dist/apps/chat-ui/assets/groovy-CkEnc0ZY.js +1 -0
- package/dist/apps/chat-ui/assets/haskell-Dadpo9-w.js +1 -0
- package/dist/apps/chat-ui/assets/haxe-CDNZL9MW.js +1 -0
- package/dist/apps/chat-ui/assets/http-jy9Zxxt3.js +1 -0
- package/dist/apps/chat-ui/assets/idl-CGSB6iiy.js +1 -0
- package/dist/apps/chat-ui/assets/index-BdcqTugD.js +151 -0
- package/dist/apps/chat-ui/assets/index-Dk-opWl3.css +1 -0
- package/dist/apps/chat-ui/assets/javascript-DSlzRUd8.js +1 -0
- package/dist/apps/chat-ui/assets/julia-DTiF9v6R.js +1 -0
- package/dist/apps/chat-ui/assets/livescript-Ci8Xxna6.js +1 -0
- package/dist/apps/chat-ui/assets/lua-eVxIrt9t.js +1 -0
- package/dist/apps/chat-ui/assets/mathematica-Da3grj36.js +1 -0
- package/dist/apps/chat-ui/assets/mbox-BWBMSafM.js +1 -0
- package/dist/apps/chat-ui/assets/mirc-CtHu9S1B.js +1 -0
- package/dist/apps/chat-ui/assets/mllike-wTFlPWXS.js +1 -0
- package/dist/apps/chat-ui/assets/modelica-cKbQ0UXu.js +1 -0
- package/dist/apps/chat-ui/assets/mscgen-C5pXQCMK.js +1 -0
- package/dist/apps/chat-ui/assets/mumps-CKBHkOQq.js +1 -0
- package/dist/apps/chat-ui/assets/nginx-B00AiQel.js +1 -0
- package/dist/apps/chat-ui/assets/nsis-SMDwKltR.js +1 -0
- package/dist/apps/chat-ui/assets/ntriples-B_36EBV0.js +1 -0
- package/dist/apps/chat-ui/assets/octave-BXPjzAif.js +1 -0
- package/dist/apps/chat-ui/assets/oz-Dedpat1M.js +1 -0
- package/dist/apps/chat-ui/assets/pascal-CMcUg72K.js +1 -0
- package/dist/apps/chat-ui/assets/perl-DoVTbnzt.js +1 -0
- package/dist/apps/chat-ui/assets/pig-CULXT1YV.js +1 -0
- package/dist/apps/chat-ui/assets/powershell-Cv5Uhf6b.js +1 -0
- package/dist/apps/chat-ui/assets/properties-CQ1C2P-M.js +1 -0
- package/dist/apps/chat-ui/assets/protobuf-SRlvzrl6.js +1 -0
- package/dist/apps/chat-ui/assets/pug-Bo3wfL-f.js +1 -0
- package/dist/apps/chat-ui/assets/puppet-ClSqCGj6.js +1 -0
- package/dist/apps/chat-ui/assets/python-C2_X1GpX.js +1 -0
- package/dist/apps/chat-ui/assets/q-B_6Gdyzl.js +1 -0
- package/dist/apps/chat-ui/assets/r-BD07NGED.js +1 -0
- package/dist/apps/chat-ui/assets/rolldown-runtime-S-ySWqyJ.js +1 -0
- package/dist/apps/chat-ui/assets/rpm-CRu5Z2Jl.js +1 -0
- package/dist/apps/chat-ui/assets/ruby-dZPnOz8h.js +1 -0
- package/dist/apps/chat-ui/assets/sas-S2t8_sDI.js +1 -0
- package/dist/apps/chat-ui/assets/scheme-WcyFWLW2.js +1 -0
- package/dist/apps/chat-ui/assets/shell-DUelnYSh.js +1 -0
- package/dist/apps/chat-ui/assets/sieve-jDjlVhNh.js +1 -0
- package/dist/apps/chat-ui/assets/simple-mode-CL04yRVp.js +1 -0
- package/dist/apps/chat-ui/assets/smalltalk-ddWDYy10.js +1 -0
- package/dist/apps/chat-ui/assets/solr-C7rQhLuW.js +1 -0
- package/dist/apps/chat-ui/assets/sparql--fPCCgVd.js +1 -0
- package/dist/apps/chat-ui/assets/spreadsheet-DjthqD5G.js +1 -0
- package/dist/apps/chat-ui/assets/sql-D_dieYbr.js +1 -0
- package/dist/apps/chat-ui/assets/stex-rHcFYcA0.js +1 -0
- package/dist/apps/chat-ui/assets/stylus-DxF70RNr.js +1 -0
- package/dist/apps/chat-ui/assets/swift-T0hDoOb-.js +1 -0
- package/dist/apps/chat-ui/assets/tcl-Dlzy1mPk.js +1 -0
- package/dist/apps/chat-ui/assets/textile-Dy5rFZe5.js +1 -0
- package/dist/apps/chat-ui/assets/tiddlywiki-DQP1OymS.js +1 -0
- package/dist/apps/chat-ui/assets/tiki-0vOj3DB2.js +1 -0
- package/dist/apps/chat-ui/assets/toml-DEltN0lI.js +1 -0
- package/dist/apps/chat-ui/assets/troff-CRbBpEqY.js +1 -0
- package/dist/apps/chat-ui/assets/ttcn-M5q1nLKg.js +1 -0
- package/dist/apps/chat-ui/assets/ttcn-cfg-Rmw9NWq9.js +1 -0
- package/dist/apps/chat-ui/assets/turtle-BCDWhJK0.js +1 -0
- package/dist/apps/chat-ui/assets/vb-QQ7LGlOz.js +1 -0
- package/dist/apps/chat-ui/assets/vbscript-BiSEdUzz.js +1 -0
- package/dist/apps/chat-ui/assets/velocity-CzMg5_6w.js +1 -0
- package/dist/apps/chat-ui/assets/verilog-BJOO83gk.js +1 -0
- package/dist/apps/chat-ui/assets/vhdl-ed4zAZAA.js +1 -0
- package/dist/apps/chat-ui/assets/webidl-Ddy6hbV6.js +1 -0
- package/dist/apps/chat-ui/assets/xquery-Bw1zwhh6.js +1 -0
- package/dist/apps/chat-ui/assets/yacas-DZdTXy3s.js +1 -0
- package/dist/apps/chat-ui/assets/z80-DMG02_YV.js +1 -0
- package/dist/apps/chat-ui/index.html +15 -0
- package/dist/apps/context-files-ui/assets/apl-14BqhLYK.js +1 -0
- package/dist/apps/context-files-ui/assets/asciiarmor-WLvjqI7d.js +1 -0
- package/dist/apps/context-files-ui/assets/asn1-Bg4FbdCg.js +1 -0
- package/dist/apps/context-files-ui/assets/asterisk-B2MO-X4d.js +1 -0
- package/dist/apps/context-files-ui/assets/brainfuck-CV9kufud.js +1 -0
- package/dist/apps/context-files-ui/assets/clike-CjmcUpt6.js +1 -0
- package/dist/apps/context-files-ui/assets/clojure-De3QGfx6.js +1 -0
- package/dist/apps/context-files-ui/assets/cmake-i2VDNaRq.js +1 -0
- package/dist/apps/context-files-ui/assets/cobol-BwO6DF08.js +1 -0
- package/dist/apps/context-files-ui/assets/coffeescript-BtivDvRz.js +1 -0
- package/dist/apps/context-files-ui/assets/commonlisp-DFkEQdLP.js +1 -0
- package/dist/apps/context-files-ui/assets/crystal-CU0NkcVL.js +1 -0
- package/dist/apps/context-files-ui/assets/css-CbMZAQ1W.js +1 -0
- package/dist/apps/context-files-ui/assets/cypher-Dke5QOzv.js +1 -0
- package/dist/apps/context-files-ui/assets/d-TPqSVaHM.js +1 -0
- package/dist/apps/context-files-ui/assets/diff-B365LSoZ.js +1 -0
- package/dist/apps/context-files-ui/assets/dist-B5PTVnox.js +1 -0
- package/dist/apps/context-files-ui/assets/dist-B5ZAfwf5.js +1 -0
- package/dist/apps/context-files-ui/assets/dist-BJW3917N.js +11 -0
- package/dist/apps/context-files-ui/assets/dist-BkUONE3N.js +1 -0
- package/dist/apps/context-files-ui/assets/dist-CKQF1zEu.js +1 -0
- package/dist/apps/context-files-ui/assets/dist-CwbH_3RN.js +1 -0
- package/dist/apps/context-files-ui/assets/dist-CxRLRmMx.js +2 -0
- package/dist/apps/context-files-ui/assets/dist-D1KyNDg5.js +13 -0
- package/dist/apps/context-files-ui/assets/dist-DFi2YGux.js +1 -0
- package/dist/apps/context-files-ui/assets/dist-DKoyMSNr.js +1 -0
- package/dist/apps/context-files-ui/assets/dist-DLMjd26T.js +1 -0
- package/dist/apps/context-files-ui/assets/dist-DQXzt2Ng.js +1 -0
- package/dist/apps/context-files-ui/assets/dist-DotDq_kD.js +1 -0
- package/dist/apps/context-files-ui/assets/dist-DyfSeBMu.js +1 -0
- package/dist/apps/context-files-ui/assets/dist-MyZgX9K2.js +9 -0
- package/dist/apps/context-files-ui/assets/dist-QQuDy4KA.js +1 -0
- package/dist/apps/context-files-ui/assets/dist-YwR9dpb-.js +1 -0
- package/dist/apps/context-files-ui/assets/dist-dTBsFYAl.js +1 -0
- package/dist/apps/context-files-ui/assets/dockerfile-CJb2sekW.js +1 -0
- package/dist/apps/context-files-ui/assets/dtd-CBMymJ7O.js +1 -0
- package/dist/apps/context-files-ui/assets/dylan-08Azy1NK.js +1 -0
- package/dist/apps/context-files-ui/assets/ebnf-Dkum_1J8.js +1 -0
- package/dist/apps/context-files-ui/assets/ecl-dhxjHL8y.js +1 -0
- package/dist/apps/context-files-ui/assets/eiffel-C446m6dI.js +1 -0
- package/dist/apps/context-files-ui/assets/elm-po1E9de0.js +1 -0
- package/dist/apps/context-files-ui/assets/erlang-BD5LkVkR.js +1 -0
- package/dist/apps/context-files-ui/assets/factor-B2EMQZkP.js +1 -0
- package/dist/apps/context-files-ui/assets/fcl-DkEOamHd.js +1 -0
- package/dist/apps/context-files-ui/assets/forth-dCg2_HVB.js +1 -0
- package/dist/apps/context-files-ui/assets/fortran-3ZpXLFh1.js +1 -0
- package/dist/apps/context-files-ui/assets/gas-DMmxLZRI.js +1 -0
- package/dist/apps/context-files-ui/assets/gherkin-DUSFg2R6.js +1 -0
- package/dist/apps/context-files-ui/assets/groovy-Cmduloe1.js +1 -0
- package/dist/apps/context-files-ui/assets/haskell-Cyr255R9.js +1 -0
- package/dist/apps/context-files-ui/assets/haxe-BJVKtprM.js +1 -0
- package/dist/apps/context-files-ui/assets/http-DszHFpc-.js +1 -0
- package/dist/apps/context-files-ui/assets/idl-Cati9Nrv.js +1 -0
- package/dist/apps/context-files-ui/assets/index-BwRDoHMC.css +1 -0
- package/dist/apps/context-files-ui/assets/index-GwvjXytt.js +202 -0
- package/dist/apps/context-files-ui/assets/javascript-C5pDVaoP.js +1 -0
- package/dist/apps/context-files-ui/assets/julia-DlqY1cTU.js +1 -0
- package/dist/apps/context-files-ui/assets/livescript-C6p8-2W1.js +1 -0
- package/dist/apps/context-files-ui/assets/lua-BxuTHaF7.js +1 -0
- package/dist/apps/context-files-ui/assets/mathematica-nDHZUMJT.js +1 -0
- package/dist/apps/context-files-ui/assets/mbox-DAaR0Hcz.js +1 -0
- package/dist/apps/context-files-ui/assets/mirc-CCA0FRfl.js +1 -0
- package/dist/apps/context-files-ui/assets/mllike-Cw3Iccsb.js +1 -0
- package/dist/apps/context-files-ui/assets/modelica-Czx80fNR.js +1 -0
- package/dist/apps/context-files-ui/assets/mscgen-BmfuTbzG.js +1 -0
- package/dist/apps/context-files-ui/assets/mumps-Ds_ZaumL.js +1 -0
- package/dist/apps/context-files-ui/assets/nginx-D9M2PQ4U.js +1 -0
- package/dist/apps/context-files-ui/assets/nsis-DOo3SJmd.js +1 -0
- package/dist/apps/context-files-ui/assets/ntriples-DLHGTvHs.js +1 -0
- package/dist/apps/context-files-ui/assets/octave-8jj96JiC.js +1 -0
- package/dist/apps/context-files-ui/assets/oz-BmMq7iC4.js +1 -0
- package/dist/apps/context-files-ui/assets/pascal-BgMr6XpT.js +1 -0
- package/dist/apps/context-files-ui/assets/perl-D6YJObi_.js +1 -0
- package/dist/apps/context-files-ui/assets/pig-nx7uchs8.js +1 -0
- package/dist/apps/context-files-ui/assets/powershell-B4IPkVxR.js +1 -0
- package/dist/apps/context-files-ui/assets/properties-CoavQdLC.js +1 -0
- package/dist/apps/context-files-ui/assets/protobuf-D5EWhcmc.js +1 -0
- package/dist/apps/context-files-ui/assets/pug-QU72BPAa.js +1 -0
- package/dist/apps/context-files-ui/assets/puppet-B_0GFuyD.js +1 -0
- package/dist/apps/context-files-ui/assets/python-Cs7sNzy_.js +1 -0
- package/dist/apps/context-files-ui/assets/q-BIB9pPtI.js +1 -0
- package/dist/apps/context-files-ui/assets/r-CN5s4f3o.js +1 -0
- package/dist/apps/context-files-ui/assets/rpm-Ct_Ck8mQ.js +1 -0
- package/dist/apps/context-files-ui/assets/ruby-BVPradRk.js +1 -0
- package/dist/apps/context-files-ui/assets/sas-DN4j74IF.js +1 -0
- package/dist/apps/context-files-ui/assets/scheme-CvNgHAnh.js +1 -0
- package/dist/apps/context-files-ui/assets/shell-BjiMLAaM.js +1 -0
- package/dist/apps/context-files-ui/assets/sieve-C2U1O5Z4.js +1 -0
- package/dist/apps/context-files-ui/assets/simple-mode-DnMbQuKW.js +1 -0
- package/dist/apps/context-files-ui/assets/smalltalk-DkYwYufV.js +1 -0
- package/dist/apps/context-files-ui/assets/solr-BopnSD-v.js +1 -0
- package/dist/apps/context-files-ui/assets/sparql-Cpg3YQfd.js +1 -0
- package/dist/apps/context-files-ui/assets/spreadsheet-kRxtVt9J.js +1 -0
- package/dist/apps/context-files-ui/assets/sql-DYI2GwJR.js +1 -0
- package/dist/apps/context-files-ui/assets/stex-BCRT8IJ3.js +1 -0
- package/dist/apps/context-files-ui/assets/stylus-CARoeVE9.js +1 -0
- package/dist/apps/context-files-ui/assets/swift-DKNaLAK6.js +1 -0
- package/dist/apps/context-files-ui/assets/tcl-CQyXkgMH.js +1 -0
- package/dist/apps/context-files-ui/assets/textile-Yg_UWn-t.js +1 -0
- package/dist/apps/context-files-ui/assets/tiddlywiki-dqVbkfX4.js +1 -0
- package/dist/apps/context-files-ui/assets/tiki-CC_ic8g0.js +1 -0
- package/dist/apps/context-files-ui/assets/toml-B7gGzVkJ.js +1 -0
- package/dist/apps/context-files-ui/assets/troff-Bq3z6oAu.js +1 -0
- package/dist/apps/context-files-ui/assets/ttcn-GvRgs2AT.js +1 -0
- package/dist/apps/context-files-ui/assets/ttcn-cfg-CGCXz7Vo.js +1 -0
- package/dist/apps/context-files-ui/assets/turtle-CwIpz2yy.js +1 -0
- package/dist/apps/context-files-ui/assets/vb-BmcHUM2C.js +1 -0
- package/dist/apps/context-files-ui/assets/vbscript-Cs9dylre.js +1 -0
- package/dist/apps/context-files-ui/assets/velocity-CBWU0VCy.js +1 -0
- package/dist/apps/context-files-ui/assets/verilog-DVCHmufx.js +1 -0
- package/dist/apps/context-files-ui/assets/vhdl-BGDk4f1d.js +1 -0
- package/dist/apps/context-files-ui/assets/webidl-egXQEWlC.js +1 -0
- package/dist/apps/context-files-ui/assets/xquery-5f0hn7cg.js +1 -0
- package/dist/apps/context-files-ui/assets/yacas-DNs9XkmQ.js +1 -0
- package/dist/apps/context-files-ui/assets/z80-B7Dfb4UO.js +1 -0
- package/dist/apps/context-files-ui/index.html +14 -0
- package/dist/auth/better-auth.js +129 -0
- package/dist/auth/types.js +14 -0
- package/dist/bin/pibo.js +3 -0
- package/dist/channels/types.js +1 -0
- package/dist/cli-errors.js +18 -0
- package/dist/cli.js +264 -0
- package/dist/config/config.js +167 -0
- package/dist/core/base-prompt.js +104 -0
- package/dist/core/codex-compat.js +44 -0
- package/dist/core/compaction-prompt.js +258 -0
- package/dist/core/events.js +1 -0
- package/dist/core/profiles.js +138 -0
- package/dist/core/routed-session.js +538 -0
- package/dist/core/runtime.js +323 -0
- package/dist/core/session-router.js +437 -0
- package/dist/core/system-prompt-template.js +56 -0
- package/dist/core/thinking.js +9 -0
- package/dist/core/workspace.js +5 -0
- package/dist/debug/events.js +92 -0
- package/dist/debug/index.js +631 -0
- package/dist/debug/session.js +200 -0
- package/dist/debug/sql.js +238 -0
- package/dist/debug/stores.js +49 -0
- package/dist/debug/trace.js +245 -0
- package/dist/env.js +32 -0
- package/dist/gateway/client.js +200 -0
- package/dist/gateway/protocol.js +46 -0
- package/dist/gateway/request.js +146 -0
- package/dist/gateway/server.js +221 -0
- package/dist/gateway/tool.js +69 -0
- package/dist/gateway/web.js +80 -0
- package/dist/index.js +23 -0
- package/dist/local/client.js +77 -0
- package/dist/local/extension.js +548 -0
- package/dist/local/tui.js +25 -0
- package/dist/mcp/agent-context.js +123 -0
- package/dist/mcp/client.js +332 -0
- package/dist/mcp/commands/call.js +146 -0
- package/dist/mcp/commands/grep.js +145 -0
- package/dist/mcp/commands/info.js +71 -0
- package/dist/mcp/commands/list.js +94 -0
- package/dist/mcp/config-command.js +217 -0
- package/dist/mcp/config.js +440 -0
- package/dist/mcp/daemon-client.js +266 -0
- package/dist/mcp/daemon.js +327 -0
- package/dist/mcp/errors.js +287 -0
- package/dist/mcp/index.js +431 -0
- package/dist/mcp/output.js +171 -0
- package/dist/mcp/python-runtime.js +131 -0
- package/dist/mcp/registry.js +116 -0
- package/dist/mcp/version.js +5 -0
- package/dist/pi-packages/cli.js +92 -0
- package/dist/pi-packages/installer.js +70 -0
- package/dist/pi-packages/metadata.js +231 -0
- package/dist/pi-packages/runtime.js +61 -0
- package/dist/pi-packages/store.js +175 -0
- package/dist/pi-packages/types.js +1 -0
- package/dist/plugins/better-auth.js +11 -0
- package/dist/plugins/builtin.js +249 -0
- package/dist/plugins/chat-web.js +11 -0
- package/dist/plugins/codex-compat.js +72 -0
- package/dist/plugins/context-files-store.js +354 -0
- package/dist/plugins/context-files.js +999 -0
- package/dist/plugins/core-tools.js +94 -0
- package/dist/plugins/example.js +67 -0
- package/dist/plugins/registry.js +368 -0
- package/dist/plugins/remote-agent.js +9 -0
- package/dist/plugins/types.js +1 -0
- package/dist/plugins/web.js +11 -0
- package/dist/reliability/store.js +759 -0
- package/dist/remote/channel.js +176 -0
- package/dist/remote/client.js +92 -0
- package/dist/remote/examples/tui-controller.js +263 -0
- package/dist/remote/protocol.js +55 -0
- package/dist/remote/session-client.js +189 -0
- package/dist/runs/registry.js +323 -0
- package/dist/runs/tools.js +185 -0
- package/dist/sessions/bindings.js +41 -0
- package/dist/sessions/sqlite-store.js +154 -0
- package/dist/sessions/store.js +125 -0
- package/dist/shared/trace-order.js +83 -0
- package/dist/subagents/tool.js +63 -0
- package/dist/tools/browser-use-cdp.js +207 -0
- package/dist/tools/browser-use-leases.js +338 -0
- package/dist/tools/browser-use-wrapper.js +338 -0
- package/dist/tools/codex-compat.js +85 -0
- package/dist/tools/desktop-env.js +90 -0
- package/dist/tools/guides.js +276 -0
- package/dist/tools/index.js +366 -0
- package/dist/tools/python-runtime.js +154 -0
- package/dist/tools/registry.js +107 -0
- package/dist/tools/web-search.js +137 -0
- package/dist/web/auth.js +10 -0
- package/dist/web/channel.js +151 -0
- package/dist/web/http.js +110 -0
- package/dist/web/types.js +1 -0
- package/package.json +74 -0
- package/src/mcp/LICENSE.mcp-cli +21 -0
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
import { buildTraceView } from "../apps/chat/trace.js";
|
|
2
|
+
import { compareTraceOrder } from "../shared/trace-order.js";
|
|
3
|
+
import { openReadOnlyDebugDatabase, withStorePath } from "./sql.js";
|
|
4
|
+
export async function inspectDebugTrace(piboSessionId, stores, options = {}) {
|
|
5
|
+
if (!stores.sessions.exists)
|
|
6
|
+
throw new Error(`Debug store "sessions" not found at ${stores.sessions.defaultPath}`);
|
|
7
|
+
if (!stores.chat.exists)
|
|
8
|
+
throw new Error(`Debug store "chat" not found at ${stores.chat.defaultPath}`);
|
|
9
|
+
const sessionsDb = openReadOnlyDebugDatabase(stores.sessions);
|
|
10
|
+
const chatDb = openReadOnlyDebugDatabase(stores.chat);
|
|
11
|
+
try {
|
|
12
|
+
const sessionRow = sessionsDb.prepare("SELECT * FROM pibo_sessions WHERE id = ?").get(piboSessionId);
|
|
13
|
+
if (!sessionRow)
|
|
14
|
+
throw new Error(`Pibo session "${piboSessionId}" not found`);
|
|
15
|
+
const session = sessionFromRow(sessionRow);
|
|
16
|
+
const sessions = sessionsDb.prepare("SELECT * FROM pibo_sessions").all().map(sessionFromRow);
|
|
17
|
+
const chatRow = tableExists(chatDb, "web_chat_sessions")
|
|
18
|
+
? chatDb.prepare("SELECT status FROM web_chat_sessions WHERE pibo_session_id = ?").get(piboSessionId)
|
|
19
|
+
: undefined;
|
|
20
|
+
const events = tableExists(chatDb, "web_chat_events")
|
|
21
|
+
? chatDb
|
|
22
|
+
.prepare("SELECT * FROM web_chat_events WHERE pibo_session_id = ? ORDER BY rowid ASC")
|
|
23
|
+
.all(piboSessionId).map(eventFromRow)
|
|
24
|
+
: [];
|
|
25
|
+
const view = await buildTraceView({
|
|
26
|
+
session,
|
|
27
|
+
sessions,
|
|
28
|
+
events,
|
|
29
|
+
status: chatRow?.status === "running" || chatRow?.status === "error" ? chatRow.status : "idle",
|
|
30
|
+
});
|
|
31
|
+
const rows = flattenTraceNodes(view.nodes);
|
|
32
|
+
const filtered = options.runningOnly ? rows.filter((node) => node.status === "running") : rows;
|
|
33
|
+
return {
|
|
34
|
+
piboSessionId: view.piboSessionId,
|
|
35
|
+
piSessionId: view.piSessionId,
|
|
36
|
+
title: view.title,
|
|
37
|
+
status: traceStatus(view),
|
|
38
|
+
nodes: filtered,
|
|
39
|
+
rawNodeCount: rows.length,
|
|
40
|
+
...(options.check ? { checks: checkTraceView(view) } : {}),
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
throw withStorePath(withStorePath(error, stores.chat), stores.sessions);
|
|
45
|
+
}
|
|
46
|
+
finally {
|
|
47
|
+
sessionsDb.close();
|
|
48
|
+
chatDb.close();
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
export function formatDebugTrace(result) {
|
|
52
|
+
const lines = [
|
|
53
|
+
`piboSessionId: ${result.piboSessionId}`,
|
|
54
|
+
`piSessionId: ${result.piSessionId}`,
|
|
55
|
+
`title: ${result.title}`,
|
|
56
|
+
`status: ${result.status}`,
|
|
57
|
+
"",
|
|
58
|
+
];
|
|
59
|
+
if (result.nodes.length === 0) {
|
|
60
|
+
lines.push("nodes: 0");
|
|
61
|
+
return lines.join("\n");
|
|
62
|
+
}
|
|
63
|
+
lines.push("status\ttype\ttitle\tid\trunId\tlinkedPiboSessionId");
|
|
64
|
+
for (const node of result.nodes) {
|
|
65
|
+
const title = `${" ".repeat(node.depth)}${node.title}`;
|
|
66
|
+
lines.push([
|
|
67
|
+
node.status,
|
|
68
|
+
node.type,
|
|
69
|
+
title,
|
|
70
|
+
node.id,
|
|
71
|
+
node.runId ?? "",
|
|
72
|
+
node.linkedPiboSessionId ?? "",
|
|
73
|
+
].join("\t"));
|
|
74
|
+
}
|
|
75
|
+
lines.push(`nodes: ${result.nodes.length}${result.nodes.length !== result.rawNodeCount ? ` of ${result.rawNodeCount}` : ""}`);
|
|
76
|
+
if (result.checks) {
|
|
77
|
+
lines.push("");
|
|
78
|
+
lines.push(`checks: ${result.checks.status}`);
|
|
79
|
+
for (const issue of result.checks.issues) {
|
|
80
|
+
lines.push(`${issue.severity}\t${issue.code}\t${issue.nodeId ?? ""}\t${issue.message}`);
|
|
81
|
+
}
|
|
82
|
+
if (result.checks.issues.length === 0)
|
|
83
|
+
lines.push("issues: 0");
|
|
84
|
+
}
|
|
85
|
+
return lines.join("\n");
|
|
86
|
+
}
|
|
87
|
+
function flattenTraceNodes(nodes, depth = 0) {
|
|
88
|
+
return nodes.flatMap((node) => [
|
|
89
|
+
{
|
|
90
|
+
status: node.status,
|
|
91
|
+
type: node.type,
|
|
92
|
+
title: node.title,
|
|
93
|
+
id: node.id,
|
|
94
|
+
runId: node.runId,
|
|
95
|
+
toolCallId: node.toolCallId,
|
|
96
|
+
linkedPiboSessionId: node.linkedPiboSessionId,
|
|
97
|
+
source: node.source,
|
|
98
|
+
stableKey: node.stableKey,
|
|
99
|
+
order: formatOrderKey(node),
|
|
100
|
+
startedAt: node.startedAt,
|
|
101
|
+
completedAt: node.completedAt,
|
|
102
|
+
depth,
|
|
103
|
+
},
|
|
104
|
+
...flattenTraceNodes(node.children, depth + 1),
|
|
105
|
+
]);
|
|
106
|
+
}
|
|
107
|
+
function traceStatus(view) {
|
|
108
|
+
const rows = flattenTraceNodes(view.nodes);
|
|
109
|
+
if (rows.some((node) => node.status === "error"))
|
|
110
|
+
return "error";
|
|
111
|
+
if (rows.some((node) => node.status === "running"))
|
|
112
|
+
return "running";
|
|
113
|
+
return "done";
|
|
114
|
+
}
|
|
115
|
+
function checkTraceView(view) {
|
|
116
|
+
const issues = [];
|
|
117
|
+
const all = flattenPiboTraceNodes(view.nodes);
|
|
118
|
+
const ids = new Set();
|
|
119
|
+
for (const node of all) {
|
|
120
|
+
if (ids.has(node.id)) {
|
|
121
|
+
issues.push({
|
|
122
|
+
severity: "warning",
|
|
123
|
+
code: "duplicate_id",
|
|
124
|
+
nodeId: node.id,
|
|
125
|
+
message: "Trace node id appears more than once.",
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
ids.add(node.id);
|
|
129
|
+
if (!node.orderKey) {
|
|
130
|
+
issues.push({
|
|
131
|
+
severity: "warning",
|
|
132
|
+
code: "missing_order",
|
|
133
|
+
nodeId: node.id,
|
|
134
|
+
message: "Trace node has no stable order key and may fall back to timestamp ordering.",
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
if (!node.source) {
|
|
138
|
+
issues.push({
|
|
139
|
+
severity: "warning",
|
|
140
|
+
code: "missing_source",
|
|
141
|
+
nodeId: node.id,
|
|
142
|
+
message: "Trace node has no projection source.",
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
if (!node.stableKey) {
|
|
146
|
+
issues.push({
|
|
147
|
+
severity: "warning",
|
|
148
|
+
code: "missing_stable_key",
|
|
149
|
+
nodeId: node.id,
|
|
150
|
+
message: "Trace node has no conceptual stable key.",
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
for (const node of all) {
|
|
155
|
+
if (node.parentId && !ids.has(node.parentId)) {
|
|
156
|
+
issues.push({
|
|
157
|
+
severity: "warning",
|
|
158
|
+
code: "missing_parent",
|
|
159
|
+
nodeId: node.id,
|
|
160
|
+
message: `Parent "${node.parentId}" is not present in the trace tree.`,
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
checkSiblingOrder(view.nodes, issues);
|
|
165
|
+
return { status: issues.length ? "warning" : "ok", issues };
|
|
166
|
+
}
|
|
167
|
+
function checkSiblingOrder(nodes, issues) {
|
|
168
|
+
for (let index = 1; index < nodes.length; index += 1) {
|
|
169
|
+
if (compareOrder(nodes[index - 1], nodes[index]) > 0) {
|
|
170
|
+
issues.push({
|
|
171
|
+
severity: "warning",
|
|
172
|
+
code: "order_regression",
|
|
173
|
+
nodeId: nodes[index].id,
|
|
174
|
+
message: `Node appears before previous sibling by stable order: ${nodes[index - 1].id}`,
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
for (const node of nodes)
|
|
179
|
+
checkSiblingOrder(node.children, issues);
|
|
180
|
+
}
|
|
181
|
+
function compareOrder(left, right) {
|
|
182
|
+
return compareTraceOrder(left.orderKey, right.orderKey) || left.id.localeCompare(right.id);
|
|
183
|
+
}
|
|
184
|
+
function flattenPiboTraceNodes(nodes) {
|
|
185
|
+
return nodes.flatMap((node) => [node, ...flattenPiboTraceNodes(node.children)]);
|
|
186
|
+
}
|
|
187
|
+
function formatOrderKey(node) {
|
|
188
|
+
const order = node.orderKey;
|
|
189
|
+
if (!order)
|
|
190
|
+
return undefined;
|
|
191
|
+
return [
|
|
192
|
+
`turn=${order.turnSeq}`,
|
|
193
|
+
order.transcriptIndex === undefined ? undefined : `tx=${order.transcriptIndex}`,
|
|
194
|
+
order.contentPartIndex === undefined ? undefined : `part=${order.contentPartIndex}`,
|
|
195
|
+
order.eventSequence === undefined ? undefined : `event=${order.eventSequence}`,
|
|
196
|
+
order.streamFrameIndex === undefined ? undefined : `frame=${order.streamFrameIndex}`,
|
|
197
|
+
`phase=${order.phaseRank}`,
|
|
198
|
+
`source=${order.sourceRank}`,
|
|
199
|
+
].filter(Boolean).join(",");
|
|
200
|
+
}
|
|
201
|
+
function sessionFromRow(row) {
|
|
202
|
+
return {
|
|
203
|
+
id: row.id,
|
|
204
|
+
piSessionId: row.pi_session_id,
|
|
205
|
+
channel: row.channel,
|
|
206
|
+
kind: row.kind,
|
|
207
|
+
profile: row.profile,
|
|
208
|
+
ownerScope: row.owner_scope ?? undefined,
|
|
209
|
+
parentId: row.parent_id ?? undefined,
|
|
210
|
+
originId: row.origin_id ?? undefined,
|
|
211
|
+
workspace: row.workspace ?? undefined,
|
|
212
|
+
title: row.title ?? undefined,
|
|
213
|
+
metadata: parseObject(row.metadata_json),
|
|
214
|
+
createdAt: row.created_at,
|
|
215
|
+
updatedAt: row.updated_at,
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
function eventFromRow(row) {
|
|
219
|
+
return {
|
|
220
|
+
id: row.id,
|
|
221
|
+
piboSessionId: row.pibo_session_id,
|
|
222
|
+
eventSequence: row.event_sequence ?? undefined,
|
|
223
|
+
eventId: row.event_id ?? undefined,
|
|
224
|
+
type: row.type,
|
|
225
|
+
createdAt: row.created_at,
|
|
226
|
+
payload: JSON.parse(row.payload_json),
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
function tableExists(db, table) {
|
|
230
|
+
const row = db.prepare("SELECT name FROM sqlite_schema WHERE type = 'table' AND name = ?").get(table);
|
|
231
|
+
return row !== undefined;
|
|
232
|
+
}
|
|
233
|
+
function parseObject(value) {
|
|
234
|
+
if (!value)
|
|
235
|
+
return {};
|
|
236
|
+
try {
|
|
237
|
+
const parsed = JSON.parse(value);
|
|
238
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed))
|
|
239
|
+
return {};
|
|
240
|
+
return parsed;
|
|
241
|
+
}
|
|
242
|
+
catch {
|
|
243
|
+
return {};
|
|
244
|
+
}
|
|
245
|
+
}
|
package/dist/env.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
2
|
+
import { resolve } from "node:path";
|
|
3
|
+
function parseEnvLine(line) {
|
|
4
|
+
const trimmed = line.trim();
|
|
5
|
+
if (!trimmed || trimmed.startsWith("#"))
|
|
6
|
+
return undefined;
|
|
7
|
+
const equalsIndex = trimmed.indexOf("=");
|
|
8
|
+
if (equalsIndex === -1)
|
|
9
|
+
return undefined;
|
|
10
|
+
const key = trimmed.slice(0, equalsIndex).trim();
|
|
11
|
+
let value = trimmed.slice(equalsIndex + 1).trim();
|
|
12
|
+
if (!key)
|
|
13
|
+
return undefined;
|
|
14
|
+
if ((value.startsWith('"') && value.endsWith('"')) ||
|
|
15
|
+
(value.startsWith("'") && value.endsWith("'"))) {
|
|
16
|
+
value = value.slice(1, -1);
|
|
17
|
+
}
|
|
18
|
+
return [key, value];
|
|
19
|
+
}
|
|
20
|
+
export function loadDotEnv(path = ".env") {
|
|
21
|
+
const resolvedPath = resolve(path);
|
|
22
|
+
if (!existsSync(resolvedPath))
|
|
23
|
+
return;
|
|
24
|
+
const content = readFileSync(resolvedPath, "utf-8");
|
|
25
|
+
for (const line of content.split(/\r?\n/)) {
|
|
26
|
+
const entry = parseEnvLine(line);
|
|
27
|
+
if (!entry)
|
|
28
|
+
continue;
|
|
29
|
+
const [key, value] = entry;
|
|
30
|
+
process.env[key] ??= value;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { connect } from "node:net";
|
|
3
|
+
import readline from "node:readline/promises";
|
|
4
|
+
import { stdin as input, stdout as output } from "node:process";
|
|
5
|
+
import { DEFAULT_GATEWAY_HOST, DEFAULT_GATEWAY_PORT, encodeFrame, } from "./protocol.js";
|
|
6
|
+
import { parsePiboThinkingLevel } from "../core/thinking.js";
|
|
7
|
+
function parseJsonLine(line) {
|
|
8
|
+
try {
|
|
9
|
+
return JSON.parse(line);
|
|
10
|
+
}
|
|
11
|
+
catch {
|
|
12
|
+
return undefined;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
function writeFrame(socket, frame) {
|
|
16
|
+
socket.write(encodeFrame(frame));
|
|
17
|
+
}
|
|
18
|
+
function printResponse(frame) {
|
|
19
|
+
if (frame.ok)
|
|
20
|
+
return;
|
|
21
|
+
console.error(`\nerror: ${frame.error?.message ?? "request failed"}`);
|
|
22
|
+
}
|
|
23
|
+
function isSessionStatus(value) {
|
|
24
|
+
if (!value || typeof value !== "object")
|
|
25
|
+
return false;
|
|
26
|
+
const candidate = value;
|
|
27
|
+
return (typeof candidate.piboSessionId === "string" &&
|
|
28
|
+
typeof candidate.queuedMessages === "number" &&
|
|
29
|
+
typeof candidate.processing === "boolean");
|
|
30
|
+
}
|
|
31
|
+
function printExecutionResult(event) {
|
|
32
|
+
if (event.action === "status" && isSessionStatus(event.result)) {
|
|
33
|
+
console.error(`status: session=${event.result.piboSessionId} queued=${event.result.queuedMessages} processing=${event.result.processing} streaming=${event.result.streaming}`);
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
if (event.action === "clear_queue" && event.result && typeof event.result === "object") {
|
|
37
|
+
const cleared = event.result.cleared;
|
|
38
|
+
console.error(`clear: removed ${typeof cleared === "number" ? cleared : 0} queued message(s)`);
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
console.error(`${event.action}: ${JSON.stringify(event.result)}`);
|
|
42
|
+
}
|
|
43
|
+
function printIncomingMessage(event, state) {
|
|
44
|
+
if (event.source === "user")
|
|
45
|
+
return;
|
|
46
|
+
if (event.eventId && state.visibleIncomingEventIds.has(event.eventId))
|
|
47
|
+
return;
|
|
48
|
+
if (event.eventId)
|
|
49
|
+
state.visibleIncomingEventIds.add(event.eventId);
|
|
50
|
+
const source = event.source ?? "external";
|
|
51
|
+
console.error(`\nincoming ${source}> ${event.text}`);
|
|
52
|
+
}
|
|
53
|
+
function printEvent(frame, piboSessionId, state) {
|
|
54
|
+
if (frame.type !== "event" || frame.event !== "router")
|
|
55
|
+
return;
|
|
56
|
+
const event = frame.payload;
|
|
57
|
+
if (event.piboSessionId !== piboSessionId)
|
|
58
|
+
return;
|
|
59
|
+
if (event.type === "message_queued") {
|
|
60
|
+
printIncomingMessage(event, state);
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
if (event.type === "assistant_delta") {
|
|
64
|
+
state.sawAssistantDelta = true;
|
|
65
|
+
output.write(event.text);
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
if (event.type === "thinking_started") {
|
|
69
|
+
state.sawThinkingDelta = false;
|
|
70
|
+
if (state.showThinking)
|
|
71
|
+
output.write("\nthinking> ");
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
if (event.type === "thinking_delta") {
|
|
75
|
+
if (!state.showThinking)
|
|
76
|
+
return;
|
|
77
|
+
state.sawThinkingDelta = true;
|
|
78
|
+
output.write(event.text);
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
if (event.type === "thinking_finished") {
|
|
82
|
+
if (!state.showThinking)
|
|
83
|
+
return;
|
|
84
|
+
if (!state.sawThinkingDelta && event.text)
|
|
85
|
+
output.write(event.text);
|
|
86
|
+
state.sawThinkingDelta = false;
|
|
87
|
+
output.write("\n");
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
if (event.type === "assistant_message") {
|
|
91
|
+
if (!state.sawAssistantDelta) {
|
|
92
|
+
output.write(event.text);
|
|
93
|
+
}
|
|
94
|
+
state.sawAssistantDelta = false;
|
|
95
|
+
output.write("\n");
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
if (event.type === "session_error") {
|
|
99
|
+
console.error(`\nsession error: ${event.error}`);
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
if (event.type === "execution_result") {
|
|
103
|
+
printExecutionResult(event);
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
if (event.type === "message_started") {
|
|
107
|
+
state.sawAssistantDelta = false;
|
|
108
|
+
printIncomingMessage(event, state);
|
|
109
|
+
output.write("assistant> ");
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
export async function runGatewayClient(options = {}) {
|
|
113
|
+
const host = options.host ?? DEFAULT_GATEWAY_HOST;
|
|
114
|
+
const port = options.port ?? DEFAULT_GATEWAY_PORT;
|
|
115
|
+
const piboSessionId = options.piboSessionId ?? "default";
|
|
116
|
+
const socket = connect({ host, port });
|
|
117
|
+
socket.setEncoding("utf-8");
|
|
118
|
+
await new Promise((resolve, reject) => {
|
|
119
|
+
socket.once("connect", resolve);
|
|
120
|
+
socket.once("error", reject);
|
|
121
|
+
});
|
|
122
|
+
console.error(`connected to pibo gateway at ${host}:${port}`);
|
|
123
|
+
console.error(`session: ${piboSessionId}`);
|
|
124
|
+
console.error("type a message, /status, /clear, /abort, /thinking [level], /thinking-show, or /quit");
|
|
125
|
+
let buffer = "";
|
|
126
|
+
const renderState = {
|
|
127
|
+
visibleIncomingEventIds: new Set(),
|
|
128
|
+
sawAssistantDelta: false,
|
|
129
|
+
showThinking: false,
|
|
130
|
+
sawThinkingDelta: false,
|
|
131
|
+
};
|
|
132
|
+
socket.on("data", (chunk) => {
|
|
133
|
+
buffer += chunk;
|
|
134
|
+
let newlineIndex = buffer.indexOf("\n");
|
|
135
|
+
while (newlineIndex !== -1) {
|
|
136
|
+
const line = buffer.slice(0, newlineIndex).trim();
|
|
137
|
+
buffer = buffer.slice(newlineIndex + 1);
|
|
138
|
+
const frame = line ? parseJsonLine(line) : undefined;
|
|
139
|
+
if (frame?.type === "res") {
|
|
140
|
+
printResponse(frame);
|
|
141
|
+
}
|
|
142
|
+
else if (frame?.type === "event") {
|
|
143
|
+
printEvent(frame, piboSessionId, renderState);
|
|
144
|
+
}
|
|
145
|
+
newlineIndex = buffer.indexOf("\n");
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
const rl = readline.createInterface({ input, output });
|
|
149
|
+
try {
|
|
150
|
+
while (!socket.destroyed) {
|
|
151
|
+
const text = (await rl.question("you> ")).trim();
|
|
152
|
+
if (!text)
|
|
153
|
+
continue;
|
|
154
|
+
if (text === "/quit" || text === "/exit")
|
|
155
|
+
break;
|
|
156
|
+
if (text === "/thinking-show") {
|
|
157
|
+
renderState.showThinking = !renderState.showThinking;
|
|
158
|
+
console.error(`thinking display: ${renderState.showThinking ? "on" : "off"}`);
|
|
159
|
+
continue;
|
|
160
|
+
}
|
|
161
|
+
if (text === "/thinking" || text.startsWith("/thinking ")) {
|
|
162
|
+
const level = text.slice("/thinking".length).trim();
|
|
163
|
+
let params;
|
|
164
|
+
try {
|
|
165
|
+
params = level ? { level: parsePiboThinkingLevel(level) } : undefined;
|
|
166
|
+
}
|
|
167
|
+
catch (error) {
|
|
168
|
+
console.error(error instanceof Error ? error.message : String(error));
|
|
169
|
+
continue;
|
|
170
|
+
}
|
|
171
|
+
writeFrame(socket, {
|
|
172
|
+
type: "req",
|
|
173
|
+
id: randomUUID(),
|
|
174
|
+
event: params === undefined
|
|
175
|
+
? { type: "execution", piboSessionId, action: "thinking" }
|
|
176
|
+
: { type: "execution", piboSessionId, action: "thinking", params },
|
|
177
|
+
});
|
|
178
|
+
continue;
|
|
179
|
+
}
|
|
180
|
+
if (text === "/status" || text === "/clear" || text === "/abort") {
|
|
181
|
+
const action = text === "/status" ? "status" : text === "/clear" ? "clear_queue" : "abort";
|
|
182
|
+
writeFrame(socket, {
|
|
183
|
+
type: "req",
|
|
184
|
+
id: randomUUID(),
|
|
185
|
+
event: { type: "execution", piboSessionId, action },
|
|
186
|
+
});
|
|
187
|
+
continue;
|
|
188
|
+
}
|
|
189
|
+
writeFrame(socket, {
|
|
190
|
+
type: "req",
|
|
191
|
+
id: randomUUID(),
|
|
192
|
+
event: { type: "message", piboSessionId, text, source: "user" },
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
finally {
|
|
197
|
+
rl.close();
|
|
198
|
+
socket.end();
|
|
199
|
+
}
|
|
200
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
export const DEFAULT_GATEWAY_HOST = "127.0.0.1";
|
|
2
|
+
export const DEFAULT_GATEWAY_PORT = 4789;
|
|
3
|
+
function isJsonValue(value) {
|
|
4
|
+
if (value === null ||
|
|
5
|
+
typeof value === "string" ||
|
|
6
|
+
typeof value === "boolean" ||
|
|
7
|
+
(typeof value === "number" && Number.isFinite(value))) {
|
|
8
|
+
return true;
|
|
9
|
+
}
|
|
10
|
+
if (Array.isArray(value)) {
|
|
11
|
+
return value.every(isJsonValue);
|
|
12
|
+
}
|
|
13
|
+
if (typeof value === "object") {
|
|
14
|
+
return Object.values(value).every(isJsonValue);
|
|
15
|
+
}
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
export function isGatewayRequestFrame(value) {
|
|
19
|
+
if (!value || typeof value !== "object")
|
|
20
|
+
return false;
|
|
21
|
+
const frame = value;
|
|
22
|
+
if (frame.type !== "req" || typeof frame.id !== "string")
|
|
23
|
+
return false;
|
|
24
|
+
if (!frame.event || typeof frame.event !== "object")
|
|
25
|
+
return false;
|
|
26
|
+
const event = frame.event;
|
|
27
|
+
if (typeof event.piboSessionId !== "string" || event.piboSessionId.length === 0)
|
|
28
|
+
return false;
|
|
29
|
+
if (event.type === "message")
|
|
30
|
+
return typeof event.text === "string";
|
|
31
|
+
if (event.type === "execution") {
|
|
32
|
+
return typeof event.action === "string" && (event.params === undefined || isJsonValue(event.params));
|
|
33
|
+
}
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
export function encodeFrame(frame) {
|
|
37
|
+
return `${JSON.stringify(frame)}\n`;
|
|
38
|
+
}
|
|
39
|
+
export function errorResponse(id, error) {
|
|
40
|
+
return {
|
|
41
|
+
type: "res",
|
|
42
|
+
id,
|
|
43
|
+
ok: false,
|
|
44
|
+
error: { message: error instanceof Error ? error.message : String(error) },
|
|
45
|
+
};
|
|
46
|
+
}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { connect } from "node:net";
|
|
3
|
+
import { DEFAULT_GATEWAY_HOST, DEFAULT_GATEWAY_PORT, encodeFrame, } from "./protocol.js";
|
|
4
|
+
function parseJsonLine(line) {
|
|
5
|
+
try {
|
|
6
|
+
return JSON.parse(line);
|
|
7
|
+
}
|
|
8
|
+
catch {
|
|
9
|
+
return undefined;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
function writeFrame(socket, frame) {
|
|
13
|
+
socket.write(encodeFrame(frame));
|
|
14
|
+
}
|
|
15
|
+
export async function sendGatewayEvent(event, options = {}) {
|
|
16
|
+
const host = options.host ?? DEFAULT_GATEWAY_HOST;
|
|
17
|
+
const port = options.port ?? DEFAULT_GATEWAY_PORT;
|
|
18
|
+
const timeoutMs = options.timeoutMs ?? 5000;
|
|
19
|
+
const id = randomUUID();
|
|
20
|
+
const eventWithId = { ...event, id: event.id ?? id };
|
|
21
|
+
return await new Promise((resolve, reject) => {
|
|
22
|
+
const socket = connect({ host, port });
|
|
23
|
+
socket.setEncoding("utf-8");
|
|
24
|
+
let buffer = "";
|
|
25
|
+
let settled = false;
|
|
26
|
+
const timeout = setTimeout(() => {
|
|
27
|
+
finish(new Error(`Timed out waiting for gateway response at ${host}:${port}`));
|
|
28
|
+
}, timeoutMs);
|
|
29
|
+
const finish = (result) => {
|
|
30
|
+
if (settled)
|
|
31
|
+
return;
|
|
32
|
+
settled = true;
|
|
33
|
+
clearTimeout(timeout);
|
|
34
|
+
socket.end();
|
|
35
|
+
if (result instanceof Error) {
|
|
36
|
+
reject(result);
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
resolve(result);
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
socket.once("connect", () => {
|
|
43
|
+
writeFrame(socket, { type: "req", id, event: eventWithId });
|
|
44
|
+
});
|
|
45
|
+
socket.once("error", finish);
|
|
46
|
+
socket.once("close", () => {
|
|
47
|
+
finish(new Error("Gateway connection closed before response"));
|
|
48
|
+
});
|
|
49
|
+
socket.on("data", (chunk) => {
|
|
50
|
+
buffer += chunk;
|
|
51
|
+
let newlineIndex = buffer.indexOf("\n");
|
|
52
|
+
while (newlineIndex !== -1) {
|
|
53
|
+
const line = buffer.slice(0, newlineIndex).trim();
|
|
54
|
+
buffer = buffer.slice(newlineIndex + 1);
|
|
55
|
+
const frame = line ? parseJsonLine(line) : undefined;
|
|
56
|
+
if (frame?.type === "res" && frame.id === id) {
|
|
57
|
+
finish(frame);
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
newlineIndex = buffer.indexOf("\n");
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
export async function sendGatewayMessageAndWaitForReply(event, options = {}) {
|
|
66
|
+
const host = options.host ?? DEFAULT_GATEWAY_HOST;
|
|
67
|
+
const port = options.port ?? DEFAULT_GATEWAY_PORT;
|
|
68
|
+
const timeoutMs = options.timeoutMs ?? 120000;
|
|
69
|
+
const id = randomUUID();
|
|
70
|
+
const eventWithId = { ...event, id: event.id ?? id };
|
|
71
|
+
return await new Promise((resolve, reject) => {
|
|
72
|
+
const socket = connect({ host, port });
|
|
73
|
+
socket.setEncoding("utf-8");
|
|
74
|
+
let buffer = "";
|
|
75
|
+
let settled = false;
|
|
76
|
+
let response;
|
|
77
|
+
let reply;
|
|
78
|
+
const timeout = setTimeout(() => {
|
|
79
|
+
finish(new Error(`Timed out waiting for assistant reply from session "${event.piboSessionId}"`));
|
|
80
|
+
}, timeoutMs);
|
|
81
|
+
const finish = (result) => {
|
|
82
|
+
if (settled)
|
|
83
|
+
return;
|
|
84
|
+
settled = true;
|
|
85
|
+
clearTimeout(timeout);
|
|
86
|
+
socket.end();
|
|
87
|
+
if (result instanceof Error) {
|
|
88
|
+
reject(result);
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
resolve(result);
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
const handleFrame = (frame) => {
|
|
95
|
+
if (frame.type === "res" && frame.id === id) {
|
|
96
|
+
response = frame;
|
|
97
|
+
if (!frame.ok) {
|
|
98
|
+
finish(new Error(frame.error?.message ?? "Gateway rejected the message"));
|
|
99
|
+
}
|
|
100
|
+
else if (reply) {
|
|
101
|
+
finish({ response, reply });
|
|
102
|
+
}
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
if (frame.type !== "event" || frame.event !== "router")
|
|
106
|
+
return;
|
|
107
|
+
const output = frame.payload;
|
|
108
|
+
if (output.type === "session_error" &&
|
|
109
|
+
output.piboSessionId === eventWithId.piboSessionId &&
|
|
110
|
+
output.eventId === eventWithId.id) {
|
|
111
|
+
finish(new Error(output.error));
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
if (output.type === "assistant_message" &&
|
|
115
|
+
output.piboSessionId === eventWithId.piboSessionId &&
|
|
116
|
+
output.eventId === eventWithId.id) {
|
|
117
|
+
reply = output;
|
|
118
|
+
if (response?.ok) {
|
|
119
|
+
finish({ response, reply });
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
socket.once("connect", () => {
|
|
124
|
+
writeFrame(socket, { type: "req", id, event: eventWithId });
|
|
125
|
+
});
|
|
126
|
+
socket.once("error", finish);
|
|
127
|
+
socket.once("close", () => {
|
|
128
|
+
finish(new Error("Gateway connection closed before assistant reply"));
|
|
129
|
+
});
|
|
130
|
+
socket.on("data", (chunk) => {
|
|
131
|
+
buffer += chunk;
|
|
132
|
+
let newlineIndex = buffer.indexOf("\n");
|
|
133
|
+
while (newlineIndex !== -1) {
|
|
134
|
+
const line = buffer.slice(0, newlineIndex).trim();
|
|
135
|
+
buffer = buffer.slice(newlineIndex + 1);
|
|
136
|
+
const frame = line ? parseJsonLine(line) : undefined;
|
|
137
|
+
if (frame) {
|
|
138
|
+
handleFrame(frame);
|
|
139
|
+
if (settled)
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
newlineIndex = buffer.indexOf("\n");
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
}
|