@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,1182 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
3
|
+
import { parseSessionEntries, SessionManager } from "@mariozechner/pi-coding-agent";
|
|
4
|
+
import { childTraceOrder, compareTraceOrder, eventTraceOrder, transcriptTraceOrder } from "../../shared/trace-order.js";
|
|
5
|
+
import { isChatWebSessionArchived } from "./session-metadata.js";
|
|
6
|
+
export async function loadPiSessionMetadata(session, cwd = process.cwd()) {
|
|
7
|
+
const piSession = await findPiSession(session, cwd);
|
|
8
|
+
return metadataFromPiSession(piSession);
|
|
9
|
+
}
|
|
10
|
+
function metadataFromPiSession(piSession) {
|
|
11
|
+
if (!piSession)
|
|
12
|
+
return {};
|
|
13
|
+
return {
|
|
14
|
+
sessionPath: piSession.path,
|
|
15
|
+
name: piSession.name,
|
|
16
|
+
firstMessage: piSession.firstMessage,
|
|
17
|
+
modified: piSession.modified,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
export async function buildSessionNodes(sessions, indexItems, cwd = process.cwd(), unreadCounts = new Map()) {
|
|
21
|
+
const indexByKey = new Map(indexItems.map((item) => [item.piboSessionId, item]));
|
|
22
|
+
const nodes = new Map();
|
|
23
|
+
const piSessionsByCwd = new Map();
|
|
24
|
+
for (const session of sessions) {
|
|
25
|
+
const sessionCwd = session.workspace ?? cwd;
|
|
26
|
+
let piSessions = piSessionsByCwd.get(sessionCwd);
|
|
27
|
+
if (!piSessions) {
|
|
28
|
+
piSessions = listPiSessions(sessionCwd);
|
|
29
|
+
piSessionsByCwd.set(sessionCwd, piSessions);
|
|
30
|
+
}
|
|
31
|
+
const metadata = metadataFromPiSession((await piSessions).find((piSession) => piSession.id === session.piSessionId));
|
|
32
|
+
const indexed = indexByKey.get(session.id);
|
|
33
|
+
nodes.set(session.id, {
|
|
34
|
+
piboSessionId: session.id,
|
|
35
|
+
piSessionId: session.piSessionId,
|
|
36
|
+
parentId: session.parentId,
|
|
37
|
+
originId: session.originId,
|
|
38
|
+
profile: session.profile,
|
|
39
|
+
subagentName: stringValue(session.metadata?.subagentName),
|
|
40
|
+
title: createSessionTitle(session, metadata),
|
|
41
|
+
subtitle: session.id,
|
|
42
|
+
archived: isChatWebSessionArchived(session),
|
|
43
|
+
status: indexed?.status ?? "idle",
|
|
44
|
+
lastActivityAt: indexed?.lastActivityAt ?? metadata.modified ?? session.updatedAt,
|
|
45
|
+
unreadCount: unreadCounts.get(session.id) || undefined,
|
|
46
|
+
derivedSessions: [],
|
|
47
|
+
children: [],
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
const roots = [];
|
|
51
|
+
for (const node of nodes.values()) {
|
|
52
|
+
const parent = node.parentId ? nodes.get(node.parentId) : undefined;
|
|
53
|
+
if (parent) {
|
|
54
|
+
parent.children.push(node);
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
roots.push(node);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
for (const node of nodes.values()) {
|
|
61
|
+
if (!node.originId)
|
|
62
|
+
continue;
|
|
63
|
+
const origin = nodes.get(node.originId);
|
|
64
|
+
if (!origin)
|
|
65
|
+
continue;
|
|
66
|
+
origin.derivedSessions.push({
|
|
67
|
+
piboSessionId: node.piboSessionId,
|
|
68
|
+
profile: node.profile,
|
|
69
|
+
subagentName: node.subagentName,
|
|
70
|
+
title: node.title,
|
|
71
|
+
status: node.status,
|
|
72
|
+
lastActivityAt: node.lastActivityAt,
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
const sortNodes = (items) => {
|
|
76
|
+
items.sort((left, right) => (right.lastActivityAt ?? "").localeCompare(left.lastActivityAt ?? ""));
|
|
77
|
+
for (const item of items) {
|
|
78
|
+
item.derivedSessions.sort((left, right) => (right.lastActivityAt ?? "").localeCompare(left.lastActivityAt ?? ""));
|
|
79
|
+
sortNodes(item.children);
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
sortNodes(roots);
|
|
83
|
+
return roots;
|
|
84
|
+
}
|
|
85
|
+
export async function buildTraceView(input) {
|
|
86
|
+
const metadata = await loadPiSessionMetadata(input.session, input.session.workspace ?? input.cwd);
|
|
87
|
+
const allEntries = metadata.sessionPath ? readEntries(metadata.sessionPath) : [];
|
|
88
|
+
const sessionStatus = input.status ?? "idle";
|
|
89
|
+
const openTranscriptEventIds = findOpenTranscriptEventIds(input.events, sessionStatus);
|
|
90
|
+
const entries = projectTranscriptEntries(allEntries, sessionStatus, openTranscriptEventIds);
|
|
91
|
+
const nodes = traceNodesFromEntries(input.session.id, entries);
|
|
92
|
+
const byId = mapTraceNodesById(nodes);
|
|
93
|
+
const childByParent = mapChildren(input.sessions);
|
|
94
|
+
const linkedChildByToolCallId = mapSubagentSessionLinks(input.events);
|
|
95
|
+
const hasPersistedTranscript = entries.some((entry) => entry.type === "message");
|
|
96
|
+
for (const storedEvent of input.events) {
|
|
97
|
+
if (hasPersistedTranscript &&
|
|
98
|
+
isTranscriptEchoEvent(storedEvent.payload) &&
|
|
99
|
+
!shouldKeepTranscriptEchoEvent(storedEvent.payload, openTranscriptEventIds)) {
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
if (hasPersistedTranscript && isStaleToolCallEchoEvent(storedEvent.payload, sessionStatus)) {
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
if (storedEvent.payload.type === "assistant_delta") {
|
|
106
|
+
mergeAssistantDeltaEvent(nodes, byId, storedEvent.payload, sessionStatus, storedEvent.createdAt, storedEvent.eventSequence);
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
if (storedEvent.payload.type === "thinking_delta") {
|
|
110
|
+
mergeThinkingDeltaEvent(nodes, byId, storedEvent.payload, sessionStatus, storedEvent.createdAt, storedEvent.eventSequence);
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
const node = traceNodeFromEvent(input.session.id, storedEvent.payload, childByParent, linkedChildByToolCallId, sessionStatus, storedEvent.createdAt, storedEvent.eventSequence);
|
|
114
|
+
if (!node)
|
|
115
|
+
continue;
|
|
116
|
+
if (node.type === "agent.turn" && node.eventId) {
|
|
117
|
+
const existingTurn = [...byId.values()].find((candidate) => candidate.type === "agent.turn" && candidate.eventId === node.eventId);
|
|
118
|
+
if (existingTurn) {
|
|
119
|
+
existingTurn.status = node.status;
|
|
120
|
+
existingTurn.completedAt = node.completedAt ?? existingTurn.completedAt;
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
if (node.type === "assistant.message") {
|
|
125
|
+
const existing = byId.get(node.id);
|
|
126
|
+
if (existing) {
|
|
127
|
+
mergeAssistantMessageEvent(existing, node);
|
|
128
|
+
closeParentTurnForFinalAssistant(byId, existing);
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
closeParentTurnForFinalAssistant(byId, node);
|
|
132
|
+
}
|
|
133
|
+
if (node.type === "model.reasoning") {
|
|
134
|
+
const existing = byId.get(node.id);
|
|
135
|
+
if (existing) {
|
|
136
|
+
mergeReasoningEvent(existing, node);
|
|
137
|
+
continue;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
if (node.toolCallId) {
|
|
141
|
+
const existing = [...byId.values()].find((candidate) => candidate.toolCallId === node.toolCallId &&
|
|
142
|
+
(candidate.type === "tool.call" || candidate.type === "agent.delegation"));
|
|
143
|
+
if (existing) {
|
|
144
|
+
if (isRunStartToolNode(existing) && node.type === "agent.delegation") {
|
|
145
|
+
attachAsyncAgentRunNode(existing, input.session.id, storedEvent.createdAt, node);
|
|
146
|
+
continue;
|
|
147
|
+
}
|
|
148
|
+
mergeToolEvent(existing, node);
|
|
149
|
+
attachAsyncAgentRunNode(existing, input.session.id, storedEvent.createdAt);
|
|
150
|
+
continue;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
if (node.eventId && byId.has(node.id))
|
|
154
|
+
continue;
|
|
155
|
+
attachAsyncAgentRunNode(node, input.session.id, storedEvent.createdAt);
|
|
156
|
+
nodes.push(node);
|
|
157
|
+
for (const indexed of flattenTraceNodes([node]))
|
|
158
|
+
byId.set(indexed.id, indexed);
|
|
159
|
+
}
|
|
160
|
+
const nestedNodes = nestTraceNodes(nodes);
|
|
161
|
+
reconcileAsyncAgentRunStatuses(nestedNodes);
|
|
162
|
+
sortTraceNodes(nestedNodes);
|
|
163
|
+
return {
|
|
164
|
+
piboSessionId: input.session.id,
|
|
165
|
+
piSessionId: input.session.piSessionId,
|
|
166
|
+
title: createSessionTitle(input.session, metadata),
|
|
167
|
+
version: createTraceViewVersion({
|
|
168
|
+
session: input.session,
|
|
169
|
+
sessions: input.sessions,
|
|
170
|
+
events: input.events,
|
|
171
|
+
status: sessionStatus,
|
|
172
|
+
metadata,
|
|
173
|
+
latestStreamId: input.latestStreamId,
|
|
174
|
+
}),
|
|
175
|
+
latestStreamId: input.latestStreamId,
|
|
176
|
+
nodes: nestedNodes,
|
|
177
|
+
rawEvents: input.includeRawEvents === false ? [] : input.events.slice(-(input.rawEventsLimit ?? input.events.length)),
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
export function createTraceViewVersion(input) {
|
|
181
|
+
const relevantSessions = input.sessions
|
|
182
|
+
.map((session) => ({
|
|
183
|
+
id: session.id,
|
|
184
|
+
parentId: session.parentId ?? null,
|
|
185
|
+
originId: session.originId ?? null,
|
|
186
|
+
updatedAt: session.updatedAt,
|
|
187
|
+
title: session.title ?? null,
|
|
188
|
+
}))
|
|
189
|
+
.sort((left, right) => left.id.localeCompare(right.id));
|
|
190
|
+
const eventTail = input.events.at(-1);
|
|
191
|
+
return createHash("sha1")
|
|
192
|
+
.update(JSON.stringify({
|
|
193
|
+
session: {
|
|
194
|
+
id: input.session.id,
|
|
195
|
+
piSessionId: input.session.piSessionId,
|
|
196
|
+
profile: input.session.profile,
|
|
197
|
+
title: input.session.title ?? null,
|
|
198
|
+
updatedAt: input.session.updatedAt,
|
|
199
|
+
},
|
|
200
|
+
metadata: {
|
|
201
|
+
name: input.metadata?.name ?? null,
|
|
202
|
+
firstMessage: input.metadata?.firstMessage ?? null,
|
|
203
|
+
modified: input.metadata?.modified ?? null,
|
|
204
|
+
},
|
|
205
|
+
status: input.status ?? "idle",
|
|
206
|
+
events: {
|
|
207
|
+
lastSequence: eventTail?.eventSequence ?? null,
|
|
208
|
+
lastCreatedAt: eventTail?.createdAt ?? null,
|
|
209
|
+
latestStreamId: input.latestStreamId ?? null,
|
|
210
|
+
},
|
|
211
|
+
sessions: relevantSessions,
|
|
212
|
+
}))
|
|
213
|
+
.digest("hex");
|
|
214
|
+
}
|
|
215
|
+
export async function listPiSessions(cwd = process.cwd()) {
|
|
216
|
+
const sessions = await SessionManager.list(cwd);
|
|
217
|
+
return sessions.map((session) => ({
|
|
218
|
+
path: session.path,
|
|
219
|
+
id: session.id,
|
|
220
|
+
cwd: session.cwd,
|
|
221
|
+
name: session.name,
|
|
222
|
+
parentSessionPath: session.parentSessionPath,
|
|
223
|
+
created: session.created.toISOString(),
|
|
224
|
+
modified: session.modified.toISOString(),
|
|
225
|
+
messageCount: session.messageCount,
|
|
226
|
+
firstMessage: session.firstMessage,
|
|
227
|
+
}));
|
|
228
|
+
}
|
|
229
|
+
function createSessionTitle(session, metadata) {
|
|
230
|
+
const candidate = session.title || metadata.name || metadata.firstMessage || session.id;
|
|
231
|
+
return truncateTitle(candidate);
|
|
232
|
+
}
|
|
233
|
+
function truncateTitle(title, maxLength = 56) {
|
|
234
|
+
const normalized = title.replace(/\s+/g, " ").trim();
|
|
235
|
+
if (normalized.length <= maxLength)
|
|
236
|
+
return normalized || "Untitled Session";
|
|
237
|
+
return `${normalized.slice(0, maxLength - 1)}…`;
|
|
238
|
+
}
|
|
239
|
+
async function findPiSession(piboSession, cwd) {
|
|
240
|
+
const sessions = await listPiSessions(cwd);
|
|
241
|
+
return sessions.find((session) => session.id === piboSession.piSessionId);
|
|
242
|
+
}
|
|
243
|
+
function readEntries(path) {
|
|
244
|
+
if (!existsSync(path))
|
|
245
|
+
return [];
|
|
246
|
+
const content = readFileSync(path, "utf8");
|
|
247
|
+
return parseSessionEntries(content).filter((entry) => entry.type !== "session");
|
|
248
|
+
}
|
|
249
|
+
function projectTranscriptEntries(entries, sessionStatus, openTranscriptEventIds) {
|
|
250
|
+
if (sessionStatus !== "running" || openTranscriptEventIds.size === 0)
|
|
251
|
+
return entries;
|
|
252
|
+
let lastUserMessageIndex = -1;
|
|
253
|
+
for (let index = entries.length - 1; index >= 0; index -= 1) {
|
|
254
|
+
const entry = entries[index];
|
|
255
|
+
if (entry.type === "message" && messageRole(entry) === "user") {
|
|
256
|
+
lastUserMessageIndex = index;
|
|
257
|
+
break;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
return lastUserMessageIndex === -1 ? entries : entries.slice(0, lastUserMessageIndex);
|
|
261
|
+
}
|
|
262
|
+
function messageRole(entry) {
|
|
263
|
+
return entry.message.role;
|
|
264
|
+
}
|
|
265
|
+
function messageContent(entry) {
|
|
266
|
+
return entry.message.content;
|
|
267
|
+
}
|
|
268
|
+
function messageParts(entry) {
|
|
269
|
+
const content = messageContent(entry);
|
|
270
|
+
if (typeof content === "string")
|
|
271
|
+
return [{ type: "text", text: content }];
|
|
272
|
+
return Array.isArray(content) ? content : [];
|
|
273
|
+
}
|
|
274
|
+
export function traceNodesFromEntries(piboSessionId, entries) {
|
|
275
|
+
const nodes = [];
|
|
276
|
+
for (let index = 0; index < entries.length; index += 1) {
|
|
277
|
+
const entry = entries[index];
|
|
278
|
+
if (entry.type === "message") {
|
|
279
|
+
const role = messageRole(entry);
|
|
280
|
+
if (role === "user") {
|
|
281
|
+
nodes.push(createUserMessageNode(piboSessionId, entry, messageContent(entry), index));
|
|
282
|
+
}
|
|
283
|
+
else if (role === "assistant" || role === "toolResult") {
|
|
284
|
+
const turn = collectAssistantTurn(entries, index);
|
|
285
|
+
nodes.push(...createAssistantTurnNodes(piboSessionId, turn.entries));
|
|
286
|
+
index = turn.nextIndex - 1;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
else if (entry.type === "session_info" && entry.name) {
|
|
290
|
+
nodes.push({
|
|
291
|
+
id: `entry:${entry.id}`,
|
|
292
|
+
entryId: entry.id,
|
|
293
|
+
piboSessionId,
|
|
294
|
+
type: "execution.command",
|
|
295
|
+
title: "Session Info",
|
|
296
|
+
status: "done",
|
|
297
|
+
startedAt: entry.timestamp,
|
|
298
|
+
output: { name: entry.name },
|
|
299
|
+
source: "transcript",
|
|
300
|
+
stableKey: `entry:${entry.id}`,
|
|
301
|
+
orderKey: transcriptTraceOrder(index, 0, "execution.command"),
|
|
302
|
+
children: [],
|
|
303
|
+
});
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
reconcileAsyncAgentRunStatuses(nodes);
|
|
307
|
+
sortTraceNodes(nodes);
|
|
308
|
+
return nodes;
|
|
309
|
+
}
|
|
310
|
+
function collectAssistantTurn(entries, startIndex) {
|
|
311
|
+
const turnEntries = [];
|
|
312
|
+
let index = startIndex;
|
|
313
|
+
while (index < entries.length) {
|
|
314
|
+
const entry = entries[index];
|
|
315
|
+
if (entry.type !== "message")
|
|
316
|
+
break;
|
|
317
|
+
const role = messageRole(entry);
|
|
318
|
+
if (role !== "assistant" && role !== "toolResult")
|
|
319
|
+
break;
|
|
320
|
+
turnEntries.push({ entry, index });
|
|
321
|
+
index += 1;
|
|
322
|
+
}
|
|
323
|
+
return { entries: turnEntries, nextIndex: index };
|
|
324
|
+
}
|
|
325
|
+
function createUserMessageNode(piboSessionId, entry, content, entryIndex) {
|
|
326
|
+
const text = extractText(content);
|
|
327
|
+
const notification = parseRunNotificationText(text);
|
|
328
|
+
if (notification) {
|
|
329
|
+
return createRunNotificationNode({
|
|
330
|
+
id: `entry:${entry.id}`,
|
|
331
|
+
entryId: entry.id,
|
|
332
|
+
piboSessionId,
|
|
333
|
+
startedAt: entry.timestamp,
|
|
334
|
+
orderKey: transcriptTraceOrder(entryIndex, 0, "yielded.run"),
|
|
335
|
+
source: "transcript",
|
|
336
|
+
stableKey: `entry:${entry.id}`,
|
|
337
|
+
notification,
|
|
338
|
+
});
|
|
339
|
+
}
|
|
340
|
+
return {
|
|
341
|
+
id: `entry:${entry.id}`,
|
|
342
|
+
entryId: entry.id,
|
|
343
|
+
piboSessionId,
|
|
344
|
+
type: "user.message",
|
|
345
|
+
title: "User Message",
|
|
346
|
+
status: "done",
|
|
347
|
+
startedAt: entry.timestamp,
|
|
348
|
+
summary: text,
|
|
349
|
+
output: text,
|
|
350
|
+
source: "transcript",
|
|
351
|
+
stableKey: `entry:${entry.id}`,
|
|
352
|
+
orderKey: transcriptTraceOrder(entryIndex, 0, "user.message"),
|
|
353
|
+
children: [],
|
|
354
|
+
};
|
|
355
|
+
}
|
|
356
|
+
function createAssistantTurnNodes(piboSessionId, entries) {
|
|
357
|
+
const firstAssistant = entries.find(({ entry }) => messageRole(entry) === "assistant");
|
|
358
|
+
if (!firstAssistant)
|
|
359
|
+
return [];
|
|
360
|
+
const orderedNodes = [];
|
|
361
|
+
const toolsByCallId = new Map();
|
|
362
|
+
for (const { entry, index: entryIndex } of entries) {
|
|
363
|
+
if (messageRole(entry) === "toolResult") {
|
|
364
|
+
mergePersistedToolResult(toolsByCallId, orderedNodes, entry, piboSessionId, entryIndex);
|
|
365
|
+
continue;
|
|
366
|
+
}
|
|
367
|
+
const responseStatus = messageStatus(entry.message);
|
|
368
|
+
const responseError = messageError(entry.message);
|
|
369
|
+
let responseNode;
|
|
370
|
+
for (const [index, part] of messageParts(entry).entries()) {
|
|
371
|
+
const typed = part;
|
|
372
|
+
if (typed.type === "thinking" && typeof typed.thinking === "string" && hasVisibleText(typed.thinking)) {
|
|
373
|
+
orderedNodes.push(createReasoningNode(piboSessionId, entry, entryIndex, index, typed.thinking));
|
|
374
|
+
}
|
|
375
|
+
else if (typed.type === "text" && typeof typed.text === "string" && typed.text !== "") {
|
|
376
|
+
if (!responseNode) {
|
|
377
|
+
responseNode = createAssistantMessageNode({
|
|
378
|
+
id: `entry:${entry.id}:response`,
|
|
379
|
+
piboSessionId,
|
|
380
|
+
entry,
|
|
381
|
+
entryIndex,
|
|
382
|
+
contentPartIndex: index,
|
|
383
|
+
status: responseStatus,
|
|
384
|
+
text: typed.text,
|
|
385
|
+
error: responseError,
|
|
386
|
+
children: [],
|
|
387
|
+
startedAt: entry.timestamp,
|
|
388
|
+
completedAt: entry.timestamp,
|
|
389
|
+
});
|
|
390
|
+
orderedNodes.push(responseNode);
|
|
391
|
+
}
|
|
392
|
+
else {
|
|
393
|
+
responseNode.summary = `${typeof responseNode.summary === "string" ? responseNode.summary : ""}${typed.text}`;
|
|
394
|
+
responseNode.output = `${typeof responseNode.output === "string" ? responseNode.output : ""}${typed.text}`;
|
|
395
|
+
responseNode.completedAt = entry.timestamp;
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
else if (typed.type === "toolCall" && typeof typed.id === "string" && typeof typed.name === "string") {
|
|
399
|
+
const toolNode = createToolCallNode(piboSessionId, entry, entryIndex, index, typed);
|
|
400
|
+
orderedNodes.push(toolNode);
|
|
401
|
+
toolsByCallId.set(typed.id, toolNode);
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
if (responseNode) {
|
|
405
|
+
responseNode.status = responseStatus;
|
|
406
|
+
responseNode.error = responseError;
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
return orderedNodes;
|
|
410
|
+
}
|
|
411
|
+
function createReasoningNode(piboSessionId, entry, entryIndex, index, thinking) {
|
|
412
|
+
return {
|
|
413
|
+
id: `entry:${entry.id}:thinking:${index}`,
|
|
414
|
+
entryId: entry.id,
|
|
415
|
+
piboSessionId,
|
|
416
|
+
type: "model.reasoning",
|
|
417
|
+
title: "Thinking",
|
|
418
|
+
status: "done",
|
|
419
|
+
startedAt: entry.timestamp,
|
|
420
|
+
summary: thinking,
|
|
421
|
+
output: thinking,
|
|
422
|
+
source: "transcript",
|
|
423
|
+
stableKey: `entry:${entry.id}:thinking:${index}`,
|
|
424
|
+
orderKey: transcriptTraceOrder(entryIndex, index, "model.reasoning"),
|
|
425
|
+
children: [],
|
|
426
|
+
};
|
|
427
|
+
}
|
|
428
|
+
function createToolCallNode(piboSessionId, entry, entryIndex, contentPartIndex, part) {
|
|
429
|
+
const name = typeof part.name === "string" ? part.name : "Tool Call";
|
|
430
|
+
const toolCallId = typeof part.id === "string" ? part.id : undefined;
|
|
431
|
+
return {
|
|
432
|
+
id: `entry:${entry.id}:tool:${String(part.id)}`,
|
|
433
|
+
entryId: entry.id,
|
|
434
|
+
piboSessionId,
|
|
435
|
+
toolCallId,
|
|
436
|
+
type: isSubagentToolName(name) ? "agent.delegation" : "tool.call",
|
|
437
|
+
title: name,
|
|
438
|
+
status: "done",
|
|
439
|
+
startedAt: entry.timestamp,
|
|
440
|
+
input: part.arguments ?? {},
|
|
441
|
+
source: "transcript",
|
|
442
|
+
stableKey: toolCallId ? `tool:${toolCallId}` : `entry:${entry.id}:tool:${contentPartIndex}`,
|
|
443
|
+
orderKey: transcriptTraceOrder(entryIndex, contentPartIndex, isSubagentToolName(name) ? "agent.delegation" : "tool.call"),
|
|
444
|
+
children: [],
|
|
445
|
+
};
|
|
446
|
+
}
|
|
447
|
+
function mergePersistedToolResult(toolsByCallId, childNodes, entry, piboSessionId, entryIndex) {
|
|
448
|
+
const message = entry.message;
|
|
449
|
+
const toolCallId = typeof message.toolCallId === "string" ? message.toolCallId : undefined;
|
|
450
|
+
if (!toolCallId)
|
|
451
|
+
return;
|
|
452
|
+
let toolNode = toolsByCallId.get(toolCallId);
|
|
453
|
+
if (!toolNode) {
|
|
454
|
+
toolNode = createMissingToolResultNode(piboSessionId, entry, entryIndex, toolCallId);
|
|
455
|
+
childNodes.push(toolNode);
|
|
456
|
+
toolsByCallId.set(toolCallId, toolNode);
|
|
457
|
+
}
|
|
458
|
+
toolNode.status = message.isError === true ? "error" : "done";
|
|
459
|
+
toolNode.completedAt = entry.timestamp;
|
|
460
|
+
toolNode.output = toolResultOutput(message);
|
|
461
|
+
toolNode.error = message.isError === true ? stringifyPreview(toolNode.output) : undefined;
|
|
462
|
+
attachAsyncAgentRunNode(toolNode, piboSessionId, entry.timestamp);
|
|
463
|
+
}
|
|
464
|
+
function createMissingToolResultNode(piboSessionId, entry, entryIndex, toolCallId) {
|
|
465
|
+
const message = entry.message;
|
|
466
|
+
return {
|
|
467
|
+
id: `entry:${entry.id}:tool-result:${toolCallId}`,
|
|
468
|
+
entryId: entry.id,
|
|
469
|
+
piboSessionId,
|
|
470
|
+
toolCallId,
|
|
471
|
+
type: "tool.result",
|
|
472
|
+
title: typeof message.toolName === "string" ? message.toolName : "Tool Result",
|
|
473
|
+
status: "done",
|
|
474
|
+
startedAt: entry.timestamp,
|
|
475
|
+
source: "transcript",
|
|
476
|
+
stableKey: `tool:${toolCallId}`,
|
|
477
|
+
orderKey: transcriptTraceOrder(entryIndex, 0, "tool.result"),
|
|
478
|
+
children: [],
|
|
479
|
+
};
|
|
480
|
+
}
|
|
481
|
+
function toolResultOutput(message) {
|
|
482
|
+
if (message.details === undefined)
|
|
483
|
+
return { content: message.content };
|
|
484
|
+
return { content: message.content, details: message.details };
|
|
485
|
+
}
|
|
486
|
+
function createAssistantMessageNode(input) {
|
|
487
|
+
return {
|
|
488
|
+
id: input.id,
|
|
489
|
+
entryId: input.entry.id,
|
|
490
|
+
piboSessionId: input.piboSessionId,
|
|
491
|
+
type: "assistant.message",
|
|
492
|
+
title: "Agent Message",
|
|
493
|
+
status: input.status,
|
|
494
|
+
startedAt: input.startedAt ?? input.entry.timestamp,
|
|
495
|
+
completedAt: input.completedAt,
|
|
496
|
+
summary: input.text,
|
|
497
|
+
output: input.text,
|
|
498
|
+
error: input.error,
|
|
499
|
+
source: "transcript",
|
|
500
|
+
stableKey: `entry:${input.entry.id}:response:${input.contentPartIndex}`,
|
|
501
|
+
orderKey: transcriptTraceOrder(input.entryIndex, input.contentPartIndex, "assistant.message"),
|
|
502
|
+
children: input.children ?? [],
|
|
503
|
+
};
|
|
504
|
+
}
|
|
505
|
+
function traceNodeFromEvent(piboSessionId, event, childByParent, linkedChildByToolCallId, sessionStatus, createdAt, eventSequence) {
|
|
506
|
+
const eventId = "eventId" in event && typeof event.eventId === "string" ? event.eventId : undefined;
|
|
507
|
+
const id = `event:${event.type}:${eventId ?? cryptoSafeId(event)}`;
|
|
508
|
+
const turnParentId = eventId ? messageTurnNodeId(eventId) : undefined;
|
|
509
|
+
const base = {
|
|
510
|
+
id,
|
|
511
|
+
piboSessionId,
|
|
512
|
+
eventId,
|
|
513
|
+
startedAt: createdAt,
|
|
514
|
+
source: "event-log",
|
|
515
|
+
stableKey: eventStableKey(event),
|
|
516
|
+
orderKey: eventTraceNodeOrder(eventSequence, event.type),
|
|
517
|
+
children: [],
|
|
518
|
+
};
|
|
519
|
+
switch (event.type) {
|
|
520
|
+
case "message_queued": {
|
|
521
|
+
const notification = parseRunNotificationText(event.text);
|
|
522
|
+
if (event.source === "service" && notification) {
|
|
523
|
+
return createRunNotificationNode({
|
|
524
|
+
id,
|
|
525
|
+
piboSessionId,
|
|
526
|
+
eventId,
|
|
527
|
+
startedAt: createdAt,
|
|
528
|
+
source: "event-log",
|
|
529
|
+
stableKey: eventId ? `run-notification:${eventId}` : id,
|
|
530
|
+
orderKey: eventTraceNodeOrder(eventSequence, event.type),
|
|
531
|
+
notification,
|
|
532
|
+
});
|
|
533
|
+
}
|
|
534
|
+
return {
|
|
535
|
+
...base,
|
|
536
|
+
type: "user.message",
|
|
537
|
+
title: "User Message",
|
|
538
|
+
status: "done",
|
|
539
|
+
summary: event.text,
|
|
540
|
+
output: event.text,
|
|
541
|
+
};
|
|
542
|
+
}
|
|
543
|
+
case "message_started":
|
|
544
|
+
case "message_finished":
|
|
545
|
+
if (event.source === "service")
|
|
546
|
+
return undefined;
|
|
547
|
+
return {
|
|
548
|
+
...base,
|
|
549
|
+
id: eventId ? messageTurnNodeId(eventId) : id,
|
|
550
|
+
type: "agent.turn",
|
|
551
|
+
title: "Agent Turn",
|
|
552
|
+
status: event.type === "message_finished" || sessionStatus !== "running" ? "done" : "running",
|
|
553
|
+
completedAt: event.type === "message_finished" ? createdAt : undefined,
|
|
554
|
+
summary: event.type === "message_started" ? event.text : undefined,
|
|
555
|
+
input: event.type === "message_started" ? { text: event.text, source: event.source } : undefined,
|
|
556
|
+
stableKey: eventId ? `turn:${eventId}` : base.stableKey,
|
|
557
|
+
};
|
|
558
|
+
case "thinking_finished": {
|
|
559
|
+
if (!hasVisibleText(event.text))
|
|
560
|
+
return undefined;
|
|
561
|
+
const thinkingId = thinkingEventNodeId(event);
|
|
562
|
+
return {
|
|
563
|
+
...base,
|
|
564
|
+
id: thinkingId ? thinkingNodeId(thinkingId) : id,
|
|
565
|
+
parentId: turnParentId,
|
|
566
|
+
type: "model.reasoning",
|
|
567
|
+
title: "Thinking",
|
|
568
|
+
status: "done",
|
|
569
|
+
summary: event.text,
|
|
570
|
+
output: event.text,
|
|
571
|
+
stableKey: thinkingId ? `reasoning:${thinkingId}` : base.stableKey,
|
|
572
|
+
};
|
|
573
|
+
}
|
|
574
|
+
case "assistant_message": {
|
|
575
|
+
const assistantId = assistantEventNodeId(event);
|
|
576
|
+
return {
|
|
577
|
+
...base,
|
|
578
|
+
id: assistantId ? assistantMessageNodeId(assistantId) : id,
|
|
579
|
+
parentId: turnParentId,
|
|
580
|
+
type: "assistant.message",
|
|
581
|
+
title: "Agent Message",
|
|
582
|
+
status: "done",
|
|
583
|
+
summary: event.text,
|
|
584
|
+
output: event.text,
|
|
585
|
+
stableKey: assistantId ? `assistant:${assistantId}` : base.stableKey,
|
|
586
|
+
};
|
|
587
|
+
}
|
|
588
|
+
case "tool_call":
|
|
589
|
+
case "tool_execution_started":
|
|
590
|
+
case "tool_execution_updated":
|
|
591
|
+
case "tool_execution_finished": {
|
|
592
|
+
const subagentTool = isSubagentToolName(event.toolName);
|
|
593
|
+
const linkedPiboSessionId = linkedChildByToolCallId.get(event.toolCallId) ??
|
|
594
|
+
(subagentTool ? findLikelyChildSession(piboSessionId, event.toolName, event, childByParent) : undefined);
|
|
595
|
+
return {
|
|
596
|
+
...base,
|
|
597
|
+
id: `tool:${event.toolCallId}`,
|
|
598
|
+
parentId: turnParentId,
|
|
599
|
+
toolCallId: event.toolCallId,
|
|
600
|
+
type: subagentTool ? "agent.delegation" : "tool.call",
|
|
601
|
+
title: event.toolName,
|
|
602
|
+
status: event.type === "tool_execution_finished"
|
|
603
|
+
? event.isError
|
|
604
|
+
? "error"
|
|
605
|
+
: "done"
|
|
606
|
+
: sessionStatus === "running" &&
|
|
607
|
+
(event.type === "tool_execution_started" || event.type === "tool_execution_updated")
|
|
608
|
+
? "running"
|
|
609
|
+
: "done",
|
|
610
|
+
completedAt: event.type === "tool_execution_finished" ? createdAt : undefined,
|
|
611
|
+
input: "args" in event ? event.args : undefined,
|
|
612
|
+
output: event.type === "tool_execution_finished"
|
|
613
|
+
? event.result
|
|
614
|
+
: event.type === "tool_execution_updated"
|
|
615
|
+
? event.partialResult
|
|
616
|
+
: undefined,
|
|
617
|
+
error: event.type === "tool_execution_finished" && event.isError ? stringifyPreview(event.result) : undefined,
|
|
618
|
+
linkedPiboSessionId,
|
|
619
|
+
stableKey: `tool:${event.toolCallId}`,
|
|
620
|
+
children: [],
|
|
621
|
+
};
|
|
622
|
+
}
|
|
623
|
+
case "subagent_session":
|
|
624
|
+
return {
|
|
625
|
+
...base,
|
|
626
|
+
id: event.toolCallId ? `tool:${event.toolCallId}` : id,
|
|
627
|
+
eventId,
|
|
628
|
+
toolCallId: event.toolCallId,
|
|
629
|
+
type: "agent.delegation",
|
|
630
|
+
title: event.toolName,
|
|
631
|
+
status: sessionStatus === "running" ? "running" : "done",
|
|
632
|
+
summary: event.subagentName,
|
|
633
|
+
input: { subagentName: event.subagentName, threadKey: event.threadKey },
|
|
634
|
+
linkedPiboSessionId: event.childPiboSessionId,
|
|
635
|
+
stableKey: event.toolCallId ? `tool:${event.toolCallId}` : `subagent:${event.childPiboSessionId}`,
|
|
636
|
+
children: [],
|
|
637
|
+
};
|
|
638
|
+
case "execution_result":
|
|
639
|
+
if (isInternalSessionOperation(event.action))
|
|
640
|
+
return undefined;
|
|
641
|
+
return {
|
|
642
|
+
...base,
|
|
643
|
+
type: "execution.command",
|
|
644
|
+
title: event.action,
|
|
645
|
+
status: "done",
|
|
646
|
+
input: { action: event.action },
|
|
647
|
+
output: event.result,
|
|
648
|
+
};
|
|
649
|
+
case "session_error":
|
|
650
|
+
return {
|
|
651
|
+
...base,
|
|
652
|
+
type: "error",
|
|
653
|
+
title: "Error",
|
|
654
|
+
status: "error",
|
|
655
|
+
error: event.error,
|
|
656
|
+
output: event.error,
|
|
657
|
+
};
|
|
658
|
+
default:
|
|
659
|
+
return undefined;
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
function mergeAssistantDeltaEvent(nodes, byId, event, sessionStatus, createdAt, eventSequence) {
|
|
663
|
+
if (event.text.length === 0)
|
|
664
|
+
return;
|
|
665
|
+
const assistantId = assistantEventNodeId(event);
|
|
666
|
+
const id = assistantId ? assistantMessageNodeId(assistantId) : `event:assistant_delta:${cryptoSafeId(event)}`;
|
|
667
|
+
const existing = byId.get(id);
|
|
668
|
+
if (existing) {
|
|
669
|
+
const text = `${typeof existing.output === "string" ? existing.output : ""}${event.text}`;
|
|
670
|
+
existing.status = sessionStatus === "running" ? "running" : "done";
|
|
671
|
+
existing.summary = text;
|
|
672
|
+
existing.output = text;
|
|
673
|
+
return;
|
|
674
|
+
}
|
|
675
|
+
const node = {
|
|
676
|
+
id,
|
|
677
|
+
parentId: event.eventId ? messageTurnNodeId(event.eventId) : undefined,
|
|
678
|
+
piboSessionId: event.piboSessionId,
|
|
679
|
+
eventId: event.eventId,
|
|
680
|
+
type: "assistant.message",
|
|
681
|
+
title: "Agent Message",
|
|
682
|
+
status: sessionStatus === "running" ? "running" : "done",
|
|
683
|
+
startedAt: createdAt,
|
|
684
|
+
summary: event.text,
|
|
685
|
+
output: event.text,
|
|
686
|
+
source: "event-log",
|
|
687
|
+
stableKey: assistantId ? `assistant:${assistantId}` : id,
|
|
688
|
+
orderKey: eventTraceNodeOrder(eventSequence, event.type),
|
|
689
|
+
children: [],
|
|
690
|
+
};
|
|
691
|
+
nodes.push(node);
|
|
692
|
+
byId.set(node.id, node);
|
|
693
|
+
}
|
|
694
|
+
function mergeAssistantMessageEvent(target, update) {
|
|
695
|
+
target.status = update.status;
|
|
696
|
+
target.summary = update.summary ?? target.summary;
|
|
697
|
+
target.output = update.output ?? target.output;
|
|
698
|
+
target.error = update.error ?? target.error;
|
|
699
|
+
target.completedAt = update.completedAt ?? target.completedAt;
|
|
700
|
+
}
|
|
701
|
+
function mergeThinkingDeltaEvent(nodes, byId, event, sessionStatus, createdAt, eventSequence) {
|
|
702
|
+
if (event.text.length === 0)
|
|
703
|
+
return;
|
|
704
|
+
const thinkingId = thinkingEventNodeId(event);
|
|
705
|
+
const id = thinkingId ? thinkingNodeId(thinkingId) : `event:thinking_delta:${cryptoSafeId(event)}`;
|
|
706
|
+
const existing = byId.get(id);
|
|
707
|
+
if (existing) {
|
|
708
|
+
const text = `${typeof existing.output === "string" ? existing.output : ""}${event.text}`;
|
|
709
|
+
existing.status = sessionStatus === "running" ? "running" : "done";
|
|
710
|
+
existing.summary = text;
|
|
711
|
+
existing.output = text;
|
|
712
|
+
return;
|
|
713
|
+
}
|
|
714
|
+
const node = {
|
|
715
|
+
id,
|
|
716
|
+
parentId: event.eventId ? messageTurnNodeId(event.eventId) : undefined,
|
|
717
|
+
piboSessionId: event.piboSessionId,
|
|
718
|
+
eventId: event.eventId,
|
|
719
|
+
type: "model.reasoning",
|
|
720
|
+
title: "Thinking",
|
|
721
|
+
status: sessionStatus === "running" ? "running" : "done",
|
|
722
|
+
startedAt: createdAt,
|
|
723
|
+
summary: event.text,
|
|
724
|
+
output: event.text,
|
|
725
|
+
source: "event-log",
|
|
726
|
+
stableKey: thinkingId ? `reasoning:${thinkingId}` : id,
|
|
727
|
+
orderKey: eventTraceNodeOrder(eventSequence, event.type),
|
|
728
|
+
children: [],
|
|
729
|
+
};
|
|
730
|
+
nodes.push(node);
|
|
731
|
+
byId.set(node.id, node);
|
|
732
|
+
}
|
|
733
|
+
function mergeReasoningEvent(target, update) {
|
|
734
|
+
target.status = update.status;
|
|
735
|
+
target.summary = update.summary ?? target.summary;
|
|
736
|
+
target.output = update.output ?? target.output;
|
|
737
|
+
target.completedAt = update.completedAt ?? target.completedAt;
|
|
738
|
+
}
|
|
739
|
+
function closeParentTurnForFinalAssistant(byId, assistant) {
|
|
740
|
+
if (!assistant.parentId || assistant.status !== "done")
|
|
741
|
+
return;
|
|
742
|
+
const parent = byId.get(assistant.parentId);
|
|
743
|
+
if (!parent || parent.type !== "agent.turn")
|
|
744
|
+
return;
|
|
745
|
+
parent.status = "done";
|
|
746
|
+
parent.completedAt = assistant.completedAt ?? assistant.startedAt ?? parent.completedAt;
|
|
747
|
+
}
|
|
748
|
+
function isInternalSessionOperation(action) {
|
|
749
|
+
return action === "session.fork" || action === "session.clone" || action === "session.switch";
|
|
750
|
+
}
|
|
751
|
+
function isTranscriptEchoEvent(event) {
|
|
752
|
+
return (event.type === "message_queued" ||
|
|
753
|
+
event.type === "message_started" ||
|
|
754
|
+
event.type === "message_finished" ||
|
|
755
|
+
event.type === "assistant_delta" ||
|
|
756
|
+
event.type === "assistant_message" ||
|
|
757
|
+
event.type === "thinking_started" ||
|
|
758
|
+
event.type === "thinking_delta" ||
|
|
759
|
+
event.type === "thinking_finished");
|
|
760
|
+
}
|
|
761
|
+
function shouldKeepTranscriptEchoEvent(event, openTranscriptEventIds) {
|
|
762
|
+
const eventId = "eventId" in event && typeof event.eventId === "string" ? event.eventId : undefined;
|
|
763
|
+
return Boolean(eventId && openTranscriptEventIds.has(eventId));
|
|
764
|
+
}
|
|
765
|
+
function isStaleToolCallEchoEvent(event, sessionStatus) {
|
|
766
|
+
return sessionStatus !== "running" && event.type === "tool_call";
|
|
767
|
+
}
|
|
768
|
+
function findOpenTranscriptEventIds(events, sessionStatus) {
|
|
769
|
+
if (sessionStatus !== "running")
|
|
770
|
+
return new Set();
|
|
771
|
+
const open = new Set();
|
|
772
|
+
for (const storedEvent of events) {
|
|
773
|
+
const event = storedEvent.payload;
|
|
774
|
+
const eventId = "eventId" in event && typeof event.eventId === "string" ? event.eventId : undefined;
|
|
775
|
+
if (!eventId)
|
|
776
|
+
continue;
|
|
777
|
+
if (isOpenTranscriptEvent(event)) {
|
|
778
|
+
open.add(eventId);
|
|
779
|
+
}
|
|
780
|
+
else if (event.type === "message_finished" || event.type === "session_error") {
|
|
781
|
+
open.delete(eventId);
|
|
782
|
+
}
|
|
783
|
+
}
|
|
784
|
+
return open;
|
|
785
|
+
}
|
|
786
|
+
function isOpenTranscriptEvent(event) {
|
|
787
|
+
return (event.type === "message_queued" ||
|
|
788
|
+
event.type === "message_started" ||
|
|
789
|
+
event.type === "assistant_delta" ||
|
|
790
|
+
event.type === "assistant_message" ||
|
|
791
|
+
event.type === "thinking_started" ||
|
|
792
|
+
event.type === "thinking_delta" ||
|
|
793
|
+
event.type === "thinking_finished");
|
|
794
|
+
}
|
|
795
|
+
function eventTraceNodeOrder(eventSequence, type) {
|
|
796
|
+
return eventTraceOrder(eventSequence, eventNodeKind(type));
|
|
797
|
+
}
|
|
798
|
+
function eventNodeKind(type) {
|
|
799
|
+
switch (type) {
|
|
800
|
+
case "message_queued":
|
|
801
|
+
return "user.message";
|
|
802
|
+
case "message_started":
|
|
803
|
+
case "message_finished":
|
|
804
|
+
return "agent.turn";
|
|
805
|
+
case "thinking_started":
|
|
806
|
+
case "thinking_delta":
|
|
807
|
+
case "thinking_finished":
|
|
808
|
+
return "model.reasoning";
|
|
809
|
+
case "tool_call":
|
|
810
|
+
case "tool_execution_started":
|
|
811
|
+
case "tool_execution_updated":
|
|
812
|
+
case "tool_execution_finished":
|
|
813
|
+
case "subagent_session":
|
|
814
|
+
return "tool.call";
|
|
815
|
+
case "assistant_delta":
|
|
816
|
+
case "assistant_message":
|
|
817
|
+
return "assistant.message";
|
|
818
|
+
case "execution_result":
|
|
819
|
+
return "execution.command";
|
|
820
|
+
case "session_error":
|
|
821
|
+
return "error";
|
|
822
|
+
default:
|
|
823
|
+
return "execution.command";
|
|
824
|
+
}
|
|
825
|
+
}
|
|
826
|
+
function eventStableKey(event) {
|
|
827
|
+
const eventId = "eventId" in event && typeof event.eventId === "string" ? event.eventId : undefined;
|
|
828
|
+
if (event.type === "tool_call" || event.type === "tool_execution_started" || event.type === "tool_execution_updated" || event.type === "tool_execution_finished") {
|
|
829
|
+
return `tool:${event.toolCallId}`;
|
|
830
|
+
}
|
|
831
|
+
if (event.type === "subagent_session" && event.toolCallId)
|
|
832
|
+
return `tool:${event.toolCallId}`;
|
|
833
|
+
if (eventId && (event.type === "message_started" || event.type === "message_finished"))
|
|
834
|
+
return `turn:${eventId}`;
|
|
835
|
+
if (event.type === "thinking_started" || event.type === "thinking_delta" || event.type === "thinking_finished") {
|
|
836
|
+
const thinkingId = thinkingEventNodeId(event);
|
|
837
|
+
if (thinkingId)
|
|
838
|
+
return `reasoning:${thinkingId}`;
|
|
839
|
+
}
|
|
840
|
+
if (event.type === "assistant_delta" || event.type === "assistant_message") {
|
|
841
|
+
const assistantId = assistantEventNodeId(event);
|
|
842
|
+
if (assistantId)
|
|
843
|
+
return `assistant:${assistantId}`;
|
|
844
|
+
}
|
|
845
|
+
return `event:${event.type}:${eventId ?? cryptoSafeId(event)}`;
|
|
846
|
+
}
|
|
847
|
+
function messageTurnNodeId(eventId) {
|
|
848
|
+
return `event:message:${eventId}`;
|
|
849
|
+
}
|
|
850
|
+
function assistantMessageNodeId(eventId) {
|
|
851
|
+
return `event:assistant:${eventId}`;
|
|
852
|
+
}
|
|
853
|
+
function assistantEventNodeId(event) {
|
|
854
|
+
if (!event.eventId)
|
|
855
|
+
return undefined;
|
|
856
|
+
const partIndex = typeof event.assistantIndex === "number" ? event.assistantIndex : event.contentIndex;
|
|
857
|
+
return typeof partIndex === "number" ? `${event.eventId}:assistant:${partIndex}` : event.eventId;
|
|
858
|
+
}
|
|
859
|
+
function thinkingNodeId(eventId) {
|
|
860
|
+
return `event:thinking:${eventId}`;
|
|
861
|
+
}
|
|
862
|
+
function thinkingEventNodeId(event) {
|
|
863
|
+
if (!event.eventId)
|
|
864
|
+
return undefined;
|
|
865
|
+
const partIndex = typeof event.thinkingIndex === "number" ? event.thinkingIndex : event.contentIndex;
|
|
866
|
+
return typeof partIndex === "number" ? `${event.eventId}:thinking:${partIndex}` : event.eventId;
|
|
867
|
+
}
|
|
868
|
+
function mapTraceNodesById(nodes) {
|
|
869
|
+
const byId = new Map();
|
|
870
|
+
for (const node of flattenTraceNodes(nodes))
|
|
871
|
+
byId.set(node.id, node);
|
|
872
|
+
return byId;
|
|
873
|
+
}
|
|
874
|
+
function sortTraceNodes(nodes) {
|
|
875
|
+
nodes.sort(compareTraceNodes);
|
|
876
|
+
for (const node of nodes)
|
|
877
|
+
sortTraceNodes(node.children);
|
|
878
|
+
}
|
|
879
|
+
function compareTraceNodes(left, right) {
|
|
880
|
+
const byOrder = compareTraceOrder(left.orderKey, right.orderKey);
|
|
881
|
+
if (byOrder !== 0)
|
|
882
|
+
return byOrder;
|
|
883
|
+
return (left.startedAt ?? "").localeCompare(right.startedAt ?? "") || left.id.localeCompare(right.id);
|
|
884
|
+
}
|
|
885
|
+
function flattenTraceNodes(nodes) {
|
|
886
|
+
return nodes.flatMap((node) => [node, ...flattenTraceNodes(node.children)]);
|
|
887
|
+
}
|
|
888
|
+
function nestTraceNodes(nodes) {
|
|
889
|
+
const byId = new Map();
|
|
890
|
+
for (const node of nodes) {
|
|
891
|
+
byId.set(node.id, { ...node, children: [...node.children] });
|
|
892
|
+
}
|
|
893
|
+
const nestedChildIds = new Set();
|
|
894
|
+
for (const node of byId.values()) {
|
|
895
|
+
if (!node.parentId)
|
|
896
|
+
continue;
|
|
897
|
+
const parent = byId.get(node.parentId);
|
|
898
|
+
if (!parent)
|
|
899
|
+
continue;
|
|
900
|
+
parent.children.push(node);
|
|
901
|
+
nestedChildIds.add(node.id);
|
|
902
|
+
}
|
|
903
|
+
const roots = [...byId.values()].filter((node) => !nestedChildIds.has(node.id));
|
|
904
|
+
sortTraceNodes(roots);
|
|
905
|
+
return roots;
|
|
906
|
+
}
|
|
907
|
+
function mergeToolEvent(target, update) {
|
|
908
|
+
target.status = update.status;
|
|
909
|
+
target.summary = update.summary ?? target.summary;
|
|
910
|
+
target.input = update.input ?? target.input;
|
|
911
|
+
target.output = update.output ?? target.output;
|
|
912
|
+
target.error = update.error ?? target.error;
|
|
913
|
+
target.completedAt = update.completedAt ?? target.completedAt;
|
|
914
|
+
target.linkedPiboSessionId = update.linkedPiboSessionId ?? target.linkedPiboSessionId;
|
|
915
|
+
}
|
|
916
|
+
function attachAsyncAgentRunNode(parent, piboSessionId, startedAt, delegation) {
|
|
917
|
+
const node = createAsyncAgentRunNode(parent, piboSessionId, startedAt, delegation);
|
|
918
|
+
if (!node)
|
|
919
|
+
return;
|
|
920
|
+
const existing = parent.children.find((child) => child.id === node.id);
|
|
921
|
+
if (existing) {
|
|
922
|
+
mergeToolEvent(existing, node);
|
|
923
|
+
existing.runId = node.runId ?? existing.runId;
|
|
924
|
+
return;
|
|
925
|
+
}
|
|
926
|
+
parent.children.push(node);
|
|
927
|
+
}
|
|
928
|
+
function reconcileAsyncAgentRunStatuses(nodes) {
|
|
929
|
+
const runSnapshots = new Map();
|
|
930
|
+
for (const node of flattenTraceNodes(nodes)) {
|
|
931
|
+
const snapshot = extractRunSnapshot(node.output);
|
|
932
|
+
if (!snapshot)
|
|
933
|
+
continue;
|
|
934
|
+
const runId = stringValue(snapshot.runId);
|
|
935
|
+
if (!runId)
|
|
936
|
+
continue;
|
|
937
|
+
runSnapshots.set(runId, {
|
|
938
|
+
snapshot,
|
|
939
|
+
completedAt: stringValue(snapshot.completedAt) ?? stringValue(snapshot.updatedAt) ?? node.completedAt,
|
|
940
|
+
});
|
|
941
|
+
}
|
|
942
|
+
for (const node of flattenTraceNodes(nodes)) {
|
|
943
|
+
if (node.type !== "agent.async" || !node.runId)
|
|
944
|
+
continue;
|
|
945
|
+
const latest = runSnapshots.get(node.runId);
|
|
946
|
+
if (!latest)
|
|
947
|
+
continue;
|
|
948
|
+
const status = stringValue(latest.snapshot.status);
|
|
949
|
+
if (status !== "completed" && status !== "cancelled" && status !== "failed")
|
|
950
|
+
continue;
|
|
951
|
+
node.status = status === "failed" ? "error" : "done";
|
|
952
|
+
node.completedAt = latest.completedAt ?? node.completedAt;
|
|
953
|
+
node.output = latest.snapshot;
|
|
954
|
+
if (status === "failed")
|
|
955
|
+
node.error = stringValue(latest.snapshot.summary) ?? node.error;
|
|
956
|
+
}
|
|
957
|
+
}
|
|
958
|
+
function createAsyncAgentRunNode(parent, piboSessionId, startedAt, delegation) {
|
|
959
|
+
if (!isRunStartToolNode(parent))
|
|
960
|
+
return undefined;
|
|
961
|
+
const run = extractRunSnapshot(parent.output);
|
|
962
|
+
const input = isRecord(parent.input) ? parent.input : {};
|
|
963
|
+
const toolName = stringValue(run?.toolName) ?? stringValue(input.toolName) ?? delegation?.title;
|
|
964
|
+
if (!toolName || !isSubagentToolName(toolName))
|
|
965
|
+
return undefined;
|
|
966
|
+
const subagentName = stringValue(delegation?.summary) ?? subagentNameFromToolName(toolName);
|
|
967
|
+
const runId = stringValue(run?.runId);
|
|
968
|
+
const runStatus = stringValue(run?.status);
|
|
969
|
+
const delegatedArguments = input.arguments;
|
|
970
|
+
const completionPolicy = stringValue(run?.completionPolicy) ?? stringValue(input.completionPolicy);
|
|
971
|
+
return {
|
|
972
|
+
id: `${parent.id}:async-agent`,
|
|
973
|
+
parentId: parent.id,
|
|
974
|
+
piboSessionId,
|
|
975
|
+
eventId: parent.eventId,
|
|
976
|
+
toolCallId: parent.toolCallId,
|
|
977
|
+
runId,
|
|
978
|
+
type: "agent.async",
|
|
979
|
+
title: subagentName,
|
|
980
|
+
status: asyncAgentStatus(parent, runStatus),
|
|
981
|
+
startedAt: delegation?.startedAt ?? startedAt ?? parent.startedAt,
|
|
982
|
+
completedAt: runStatus === "completed" || runStatus === "cancelled" ? parent.completedAt : undefined,
|
|
983
|
+
summary: `Started by ${parent.title}`,
|
|
984
|
+
input: {
|
|
985
|
+
startedBy: parent.title,
|
|
986
|
+
startToolCallId: parent.toolCallId,
|
|
987
|
+
toolName,
|
|
988
|
+
subagentName,
|
|
989
|
+
runId,
|
|
990
|
+
completionPolicy,
|
|
991
|
+
arguments: delegatedArguments,
|
|
992
|
+
threadKey: isRecord(delegation?.input) ? delegation.input.threadKey : undefined,
|
|
993
|
+
},
|
|
994
|
+
output: run,
|
|
995
|
+
error: parent.error,
|
|
996
|
+
linkedPiboSessionId: delegation?.linkedPiboSessionId ?? parent.linkedPiboSessionId,
|
|
997
|
+
source: parent.source,
|
|
998
|
+
stableKey: runId ? `async-agent:${runId}` : `${parent.stableKey ?? parent.id}:async-agent`,
|
|
999
|
+
orderKey: childTraceOrder(parent.orderKey, "agent.async"),
|
|
1000
|
+
children: [],
|
|
1001
|
+
};
|
|
1002
|
+
}
|
|
1003
|
+
function isRunStartToolNode(node) {
|
|
1004
|
+
return node.type === "tool.call" && node.title === "pibo_run_start";
|
|
1005
|
+
}
|
|
1006
|
+
function extractRunSnapshot(value) {
|
|
1007
|
+
if (!isRecord(value))
|
|
1008
|
+
return undefined;
|
|
1009
|
+
if (isRunSnapshot(value))
|
|
1010
|
+
return value;
|
|
1011
|
+
if (isRecord(value.details) && isRunSnapshot(value.details))
|
|
1012
|
+
return value.details;
|
|
1013
|
+
return undefined;
|
|
1014
|
+
}
|
|
1015
|
+
function isRunSnapshot(value) {
|
|
1016
|
+
return typeof value.runId === "string" && typeof value.toolName === "string";
|
|
1017
|
+
}
|
|
1018
|
+
function stringValue(value) {
|
|
1019
|
+
return typeof value === "string" ? value : undefined;
|
|
1020
|
+
}
|
|
1021
|
+
function subagentNameFromToolName(toolName) {
|
|
1022
|
+
return toolName.slice("pibo_subagent_".length);
|
|
1023
|
+
}
|
|
1024
|
+
function asyncAgentStatus(parent, runStatus) {
|
|
1025
|
+
if (parent.status === "error" || runStatus === "failed")
|
|
1026
|
+
return "error";
|
|
1027
|
+
if (runStatus === "completed" || runStatus === "cancelled")
|
|
1028
|
+
return "done";
|
|
1029
|
+
return "running";
|
|
1030
|
+
}
|
|
1031
|
+
function mapChildren(sessions) {
|
|
1032
|
+
const result = new Map();
|
|
1033
|
+
for (const session of sessions) {
|
|
1034
|
+
if (!session.parentId)
|
|
1035
|
+
continue;
|
|
1036
|
+
const children = result.get(session.parentId) ?? [];
|
|
1037
|
+
children.push(session);
|
|
1038
|
+
result.set(session.parentId, children);
|
|
1039
|
+
}
|
|
1040
|
+
return result;
|
|
1041
|
+
}
|
|
1042
|
+
function mapSubagentSessionLinks(events) {
|
|
1043
|
+
const result = new Map();
|
|
1044
|
+
for (const storedEvent of events) {
|
|
1045
|
+
const event = storedEvent.payload;
|
|
1046
|
+
if (event.type !== "subagent_session" || !event.toolCallId)
|
|
1047
|
+
continue;
|
|
1048
|
+
result.set(event.toolCallId, event.childPiboSessionId);
|
|
1049
|
+
}
|
|
1050
|
+
return result;
|
|
1051
|
+
}
|
|
1052
|
+
function findLikelyChildSession(piboSessionId, toolName, event, childByParent) {
|
|
1053
|
+
if (!isSubagentToolName(toolName))
|
|
1054
|
+
return undefined;
|
|
1055
|
+
const candidates = childByParent.get(piboSessionId)?.filter((session) => session.metadata?.subagentToolName === toolName) ?? [];
|
|
1056
|
+
const threadKey = toolEventThreadKey(event);
|
|
1057
|
+
if (threadKey) {
|
|
1058
|
+
return candidates.find((session) => session.metadata?.threadKey === threadKey)?.id;
|
|
1059
|
+
}
|
|
1060
|
+
return candidates.length === 1 ? candidates[0].id : undefined;
|
|
1061
|
+
}
|
|
1062
|
+
function isSubagentToolName(name) {
|
|
1063
|
+
return name.startsWith("pibo_subagent_");
|
|
1064
|
+
}
|
|
1065
|
+
function toolEventThreadKey(event) {
|
|
1066
|
+
const args = "args" in event && event.args && typeof event.args === "object" && !Array.isArray(event.args) ? event.args : undefined;
|
|
1067
|
+
const threadKey = args && "threadKey" in args ? args.threadKey : undefined;
|
|
1068
|
+
return typeof threadKey === "string" && threadKey.trim() ? threadKey.trim() : undefined;
|
|
1069
|
+
}
|
|
1070
|
+
function messageStatus(message) {
|
|
1071
|
+
if (message && typeof message === "object") {
|
|
1072
|
+
const stopReason = message.stopReason;
|
|
1073
|
+
const errorMessage = message.errorMessage;
|
|
1074
|
+
if (stopReason === "error" || typeof errorMessage === "string")
|
|
1075
|
+
return "error";
|
|
1076
|
+
}
|
|
1077
|
+
return "done";
|
|
1078
|
+
}
|
|
1079
|
+
function messageError(message) {
|
|
1080
|
+
if (!message || typeof message !== "object")
|
|
1081
|
+
return undefined;
|
|
1082
|
+
const errorMessage = message.errorMessage;
|
|
1083
|
+
return typeof errorMessage === "string" ? errorMessage : undefined;
|
|
1084
|
+
}
|
|
1085
|
+
function hasVisibleText(value) {
|
|
1086
|
+
return typeof value === "string" && value.trim().length > 0;
|
|
1087
|
+
}
|
|
1088
|
+
function extractText(content) {
|
|
1089
|
+
if (typeof content === "string")
|
|
1090
|
+
return content;
|
|
1091
|
+
if (!Array.isArray(content))
|
|
1092
|
+
return "";
|
|
1093
|
+
return content
|
|
1094
|
+
.map((part) => {
|
|
1095
|
+
const typed = part;
|
|
1096
|
+
if (typed.type === "text" && typeof typed.text === "string")
|
|
1097
|
+
return typed.text;
|
|
1098
|
+
return "";
|
|
1099
|
+
})
|
|
1100
|
+
.join("");
|
|
1101
|
+
}
|
|
1102
|
+
function stringifyPreview(value) {
|
|
1103
|
+
if (typeof value === "string")
|
|
1104
|
+
return value;
|
|
1105
|
+
try {
|
|
1106
|
+
return JSON.stringify(value);
|
|
1107
|
+
}
|
|
1108
|
+
catch {
|
|
1109
|
+
return String(value);
|
|
1110
|
+
}
|
|
1111
|
+
}
|
|
1112
|
+
function parseRunNotificationText(text) {
|
|
1113
|
+
const trimmed = text.trim();
|
|
1114
|
+
const start = "<pibo_run_notification>";
|
|
1115
|
+
const end = "</pibo_run_notification>";
|
|
1116
|
+
if (!trimmed.startsWith(start) || !trimmed.endsWith(end))
|
|
1117
|
+
return undefined;
|
|
1118
|
+
const jsonText = trimmed.slice(start.length, trimmed.length - end.length).trim();
|
|
1119
|
+
try {
|
|
1120
|
+
const parsed = JSON.parse(jsonText);
|
|
1121
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed))
|
|
1122
|
+
return undefined;
|
|
1123
|
+
return parsed;
|
|
1124
|
+
}
|
|
1125
|
+
catch {
|
|
1126
|
+
return undefined;
|
|
1127
|
+
}
|
|
1128
|
+
}
|
|
1129
|
+
function createRunNotificationNode(input) {
|
|
1130
|
+
const runs = runNotificationRuns(input.notification);
|
|
1131
|
+
const singleRun = runs.length === 1 ? runs[0] : undefined;
|
|
1132
|
+
const failedCount = countRunGroup(input.notification.failed);
|
|
1133
|
+
const runningCount = countRunGroup(input.notification.running);
|
|
1134
|
+
return {
|
|
1135
|
+
id: input.id,
|
|
1136
|
+
entryId: input.entryId,
|
|
1137
|
+
piboSessionId: input.piboSessionId,
|
|
1138
|
+
eventId: input.eventId,
|
|
1139
|
+
runId: typeof singleRun?.runId === "string" ? singleRun.runId : undefined,
|
|
1140
|
+
type: "yielded.run",
|
|
1141
|
+
title: "Run Notification",
|
|
1142
|
+
status: failedCount > 0 ? "error" : runningCount > 0 ? "running" : "done",
|
|
1143
|
+
startedAt: input.startedAt,
|
|
1144
|
+
summary: runNotificationSummary(input.notification),
|
|
1145
|
+
output: input.notification,
|
|
1146
|
+
source: input.source,
|
|
1147
|
+
stableKey: input.stableKey ?? input.id,
|
|
1148
|
+
orderKey: input.orderKey,
|
|
1149
|
+
children: [],
|
|
1150
|
+
};
|
|
1151
|
+
}
|
|
1152
|
+
function runNotificationRuns(notification) {
|
|
1153
|
+
return [
|
|
1154
|
+
...runGroup(notification.completed),
|
|
1155
|
+
...runGroup(notification.failed),
|
|
1156
|
+
...runGroup(notification.cancelled),
|
|
1157
|
+
...runGroup(notification.running),
|
|
1158
|
+
];
|
|
1159
|
+
}
|
|
1160
|
+
function runGroup(value) {
|
|
1161
|
+
return Array.isArray(value) ? value.filter(isRecord) : [];
|
|
1162
|
+
}
|
|
1163
|
+
function countRunGroup(value) {
|
|
1164
|
+
return Array.isArray(value) ? value.length : 0;
|
|
1165
|
+
}
|
|
1166
|
+
function runNotificationSummary(notification) {
|
|
1167
|
+
const parts = [
|
|
1168
|
+
[countRunGroup(notification.completed), "completed"],
|
|
1169
|
+
[countRunGroup(notification.failed), "failed"],
|
|
1170
|
+
[countRunGroup(notification.cancelled), "cancelled"],
|
|
1171
|
+
[countRunGroup(notification.running), "running"],
|
|
1172
|
+
]
|
|
1173
|
+
.filter(([count]) => Number(count) > 0)
|
|
1174
|
+
.map(([count, label]) => `${count} ${label}`);
|
|
1175
|
+
return parts.length ? parts.join(", ") : "No yielded run updates";
|
|
1176
|
+
}
|
|
1177
|
+
function isRecord(value) {
|
|
1178
|
+
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
1179
|
+
}
|
|
1180
|
+
function cryptoSafeId(value) {
|
|
1181
|
+
return Buffer.from(JSON.stringify(value)).toString("base64url").slice(0, 48);
|
|
1182
|
+
}
|