@ensocode/server 0.3.4 → 0.3.5
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/out/phone/assets/{abnfDiagram-VCTEODGH-6JYofuK8.js → abnfDiagram-VCTEODGH-k76opPl1.js} +1 -1
- package/out/phone/assets/architecture-7GRP2DOG-DFA8x3QF.js +1 -0
- package/out/phone/assets/{architectureDiagram-5GKGNRK7-BeLeAQB1.js → architectureDiagram-5GKGNRK7-yxQH9IuZ.js} +1 -1
- package/out/phone/assets/{blockDiagram-I7D4REHJ-uXn3vhT2.js → blockDiagram-I7D4REHJ-DoHteZpO.js} +1 -1
- package/out/phone/assets/{c4Diagram-7LVT6UL2-CjzMFRll.js → c4Diagram-7LVT6UL2-DQVO6L4q.js} +1 -1
- package/out/phone/assets/channel-BBjWfdZr.js +1 -0
- package/out/phone/assets/{chunk-4HAMMTFA-BA8HaYy2.js → chunk-4HAMMTFA-N9Rw4SGW.js} +1 -1
- package/out/phone/assets/{chunk-75Z2AOVW-BhIfO9es.js → chunk-75Z2AOVW-DKJ8pOxp.js} +1 -1
- package/out/phone/assets/{chunk-DU6HZSFF-BTLBHwj-.js → chunk-DU6HZSFF-BqGW8Nbd.js} +1 -1
- package/out/phone/assets/{chunk-F27PBJKO-CUw8NZk8.js → chunk-F27PBJKO-PkFmkghF.js} +1 -1
- package/out/phone/assets/{chunk-GMAD6QVW-bZOKnRyM.js → chunk-GMAD6QVW-C9VeD3Jk.js} +1 -1
- package/out/phone/assets/{chunk-GVQU2GXP-B0WIm1dS.js → chunk-GVQU2GXP-COhntOeE.js} +1 -1
- package/out/phone/assets/{chunk-IMKFNOWR-DWND4rEr.js → chunk-IMKFNOWR-B87ghLVD.js} +1 -1
- package/out/phone/assets/{chunk-L3NEJ4N5-DgMknY3k.js → chunk-L3NEJ4N5-C3N2izjg.js} +1 -1
- package/out/phone/assets/{chunk-OSK3NFVY-C5aEouov.js → chunk-OSK3NFVY-DaAlvVhz.js} +1 -1
- package/out/phone/assets/{chunk-P2QGCYS3-D2ID3RxV.js → chunk-P2QGCYS3-BQpKr8IZ.js} +1 -1
- package/out/phone/assets/{chunk-POPQ4Y6H-C1lOuNpV.js → chunk-POPQ4Y6H-B2TZMY6U.js} +1 -1
- package/out/phone/assets/{chunk-PWAF6VOD-CfqWQZRE.js → chunk-PWAF6VOD-CgRhpUJy.js} +1 -1
- package/out/phone/assets/{chunk-SHT3W25Y-p37Dlvn4.js → chunk-SHT3W25Y-BySMFA99.js} +1 -1
- package/out/phone/assets/{chunk-SVP7TREG-CSSqW-zb.js → chunk-SVP7TREG-EDGanDUX.js} +1 -1
- package/out/phone/assets/{chunk-TICWLB2K-Bse5ne4b.js → chunk-TICWLB2K-BtCZ8R2k.js} +1 -1
- package/out/phone/assets/classDiagram-ZZMXUADV-CXXjdIIU.js +1 -0
- package/out/phone/assets/classDiagram-v2-VYDZK3BY-CXXjdIIU.js +1 -0
- package/out/phone/assets/{cynefin-OW5HDTMX-BGQqPhYk.js → cynefin-OW5HDTMX-CdZmp44V.js} +1 -1
- package/out/phone/assets/{cynefinDiagram-5FMLGOSQ-Cz3XWaxY.js → cynefinDiagram-5FMLGOSQ-BCz9KwUb.js} +1 -1
- package/out/phone/assets/{dagre-GXQ25YYZ-CjAF6lSz.js → dagre-GXQ25YYZ-CgFeNgh6.js} +1 -1
- package/out/phone/assets/desk-C_b7mE6l.js +2 -0
- package/out/phone/assets/{diagram-S7CK7UJ4-B135cp5a.js → diagram-S7CK7UJ4-CwvaZIBf.js} +1 -1
- package/out/phone/assets/{diagram-UQ7AKVKN-C4pCe0fQ.js → diagram-UQ7AKVKN-DqnD4XoZ.js} +1 -1
- package/out/phone/assets/{diagram-VSXAHHWV-CYkCrin2.js → diagram-VSXAHHWV-Kqc9GudQ.js} +1 -1
- package/out/phone/assets/{diagram-VX7I27RA-CT_vufh_.js → diagram-VX7I27RA-B_0DLDQ0.js} +1 -1
- package/out/phone/assets/{diagram-Z3DM3KII-XEkkXu3P.js → diagram-Z3DM3KII-CppKBEPW.js} +1 -1
- package/out/phone/assets/{ebnfDiagram-PWID7BFC-DfLyeXjw.js → ebnfDiagram-PWID7BFC-DeYPNCu9.js} +1 -1
- package/out/phone/assets/{erDiagram-RLTQ6QDP-pKNbKkAP.js → erDiagram-RLTQ6QDP-MsfxDUmk.js} +1 -1
- package/out/phone/assets/eventmodeling-NTZA5JFV-D4a6gbOs.js +1 -0
- package/out/phone/assets/flowDiagram-HODETNUW-BBTtB5oX.js +1 -0
- package/out/phone/assets/{ganttDiagram-EL5Y4UJY-Df4E50Mj.js → ganttDiagram-EL5Y4UJY-DaScS1os.js} +1 -1
- package/out/phone/assets/{gitGraph-4MIJSDKK-CkjzZeFD.js → gitGraph-4MIJSDKK-C-FzqpZm.js} +1 -1
- package/out/phone/assets/{gitGraphDiagram-WWUBYQGX-CBxfRAfy.js → gitGraphDiagram-WWUBYQGX-4Yv-hAwf.js} +1 -1
- package/out/phone/assets/{info-A6RAGUB7-CHFXa2pw.js → info-A6RAGUB7-CGLEP4t7.js} +1 -1
- package/out/phone/assets/{infoDiagram-27XIBGKW-K0DnZhi4.js → infoDiagram-27XIBGKW-DapEgYQa.js} +1 -1
- package/out/phone/assets/{ishikawaDiagram-5VMMS53U-DTQF2ZuR.js → ishikawaDiagram-5VMMS53U-D1B2lZSG.js} +1 -1
- package/out/phone/assets/{journeyDiagram-3NMN7TZE-wBltkU2i.js → journeyDiagram-3NMN7TZE-BSAtMVJw.js} +1 -1
- package/out/phone/assets/{kanban-definition-UXKFOSKX-BZpcOajP.js → kanban-definition-UXKFOSKX-CfZ4oI7A.js} +1 -1
- package/out/phone/assets/{line-BflnZFgp.js → line-DAXmUM4p.js} +1 -1
- package/out/phone/assets/{main-Crtf_g8h.js → main-B0yD1pMI.js} +97 -97
- package/out/phone/assets/main-DNRbLxEx.css +1 -0
- package/out/phone/assets/{mermaid-parser.core-BiCTmcqa.js → mermaid-parser.core-IObm7oM0.js} +3 -3
- package/out/phone/assets/{mermaid.core-D3TwYaLF.js → mermaid.core-C1wA-mhD.js} +4 -4
- package/out/phone/assets/{mindmap-definition-YA3MSWOX-Cz0aS_6Y.js → mindmap-definition-YA3MSWOX-3ph0EaB9.js} +1 -1
- package/out/phone/assets/{packet-AYTQ26CC-DW-djbhd.js → packet-AYTQ26CC-BbDAe9Au.js} +1 -1
- package/out/phone/assets/{pegDiagram-XKGWAZYB-CE0sZZAE.js → pegDiagram-XKGWAZYB-EsuDcX_3.js} +1 -1
- package/out/phone/assets/{pie-WAS4IAKB-CKGFlXok.js → pie-WAS4IAKB-BQfIj1fu.js} +1 -1
- package/out/phone/assets/{pieDiagram-E7YTZNPT-BrnQ32_6.js → pieDiagram-E7YTZNPT-Cw19z5Ip.js} +1 -1
- package/out/phone/assets/{quadrantDiagram-AXDQQJYC-BrxDAygB.js → quadrantDiagram-AXDQQJYC-Bqwz_sa8.js} +1 -1
- package/out/phone/assets/{radar-RG4KPBEZ-Bo2f5QyA.js → radar-RG4KPBEZ-Dmp-89iD.js} +1 -1
- package/out/phone/assets/{railroad-74A4TZTK-BZEmm0Ha.js → railroad-74A4TZTK-dq2H8w8Y.js} +1 -1
- package/out/phone/assets/railroad-abnf-HS5TGJTU-DddVaVQM.js +1 -0
- package/out/phone/assets/railroad-ebnf-LZEXJU2U-BjvyqMjh.js +1 -0
- package/out/phone/assets/railroad-peg-WCYAUIDC-lBl4CV1_.js +1 -0
- package/out/phone/assets/{railroadDiagram-O6MQD6OU-BvOyUNMC.js → railroadDiagram-O6MQD6OU-D2Sbc7Wn.js} +1 -1
- package/out/phone/assets/{requirementDiagram-BXWQKSXE-T42N3TW5.js → requirementDiagram-BXWQKSXE-CLNUqxbl.js} +1 -1
- package/out/phone/assets/{sankeyDiagram-P5KCCOFB-0us9ErVV.js → sankeyDiagram-P5KCCOFB-Dme5iwcw.js} +1 -1
- package/out/phone/assets/{sequenceDiagram-WJ2MYXX4-BMcYh2ll.js → sequenceDiagram-WJ2MYXX4-C5dYSwPE.js} +1 -1
- package/out/phone/assets/{stateDiagram-D77RDMKH-CgP9dUc3.js → stateDiagram-D77RDMKH-BuxkPvJ6.js} +1 -1
- package/out/phone/assets/stateDiagram-v2-MP3YSRHH-Exd8xDBD.js +1 -0
- package/out/phone/assets/storage-p-WxHA1h.js +1 -0
- package/out/phone/assets/{swimlanes-42K2YHIH-VnE4ceCW.js → swimlanes-42K2YHIH-DHyXnytv.js} +1 -1
- package/out/phone/assets/swimlanesDiagram-VR7AAH4N-B62_42fO.js +8 -0
- package/out/phone/assets/{timeline-definition-24CTP7MA-tH3izgae.js → timeline-definition-24CTP7MA-Bm8Z0u2Z.js} +1 -1
- package/out/phone/assets/{treeView-Q6P3EWNA-CVFDOC7i.js → treeView-Q6P3EWNA-DFUxvDDO.js} +1 -1
- package/out/phone/assets/{treemap-WGGIJYW6-vmikHzt3.js → treemap-WGGIJYW6-CMC-hwzt.js} +1 -1
- package/out/phone/assets/{vennDiagram-4TSXK5OY-b8ttDCR-.js → vennDiagram-4TSXK5OY-CNL4gZsd.js} +1 -1
- package/out/phone/assets/{wardley-WFR3VGLG-D32vKoC1.js → wardley-WFR3VGLG-CHQoq9KJ.js} +1 -1
- package/out/phone/assets/{wardleyDiagram-VM6X3IG4-CMkaIPVH.js → wardleyDiagram-VM6X3IG4-DAuBfK1O.js} +1 -1
- package/out/phone/assets/{xychartDiagram-S5SC5T6Z-pLYDcql3.js → xychartDiagram-S5SC5T6Z-B2T9ECKd.js} +1 -1
- package/out/phone/desk.html +2 -2
- package/out/phone/index.html +3 -3
- package/out/renderer/assets/{abnfDiagram-VCTEODGH-N6OiVFQx.js → abnfDiagram-VCTEODGH-gdhrQbX6.js} +1 -1
- package/out/renderer/assets/{arc-CXVc3U0J.js → arc-D6-Q4l2d.js} +1 -1
- package/out/renderer/assets/{architectureDiagram-5GKGNRK7-BT5CXpcQ.js → architectureDiagram-5GKGNRK7-C4y0SbLT.js} +1 -1
- package/out/renderer/assets/{blockDiagram-I7D4REHJ-C32Vqzip.js → blockDiagram-I7D4REHJ-DrsoSFRK.js} +1 -1
- package/out/renderer/assets/{c4Diagram-7LVT6UL2-qjwL2BP8.js → c4Diagram-7LVT6UL2-1DD8BlM8.js} +1 -1
- package/out/renderer/assets/channel-Sck-tAAK.js +1 -0
- package/out/renderer/assets/{chunk-2Q5K7J3B-YC6CQiyD.js → chunk-2Q5K7J3B-DRyc0B7g.js} +1 -1
- package/out/renderer/assets/{chunk-5VM5RSS4-E-kluPz3.js → chunk-5VM5RSS4-BJe8SghE.js} +1 -1
- package/out/renderer/assets/{chunk-F27PBJKO-Bhx1_P75.js → chunk-F27PBJKO-BIipq4SK.js} +1 -1
- package/out/renderer/assets/{chunk-IMKFNOWR-Dgb_730B.js → chunk-IMKFNOWR-D5Ak3Xd9.js} +1 -1
- package/out/renderer/assets/{chunk-JWPE2WC7-COQNHw4u.js → chunk-JWPE2WC7-BcaWCpW-.js} +1 -1
- package/out/renderer/assets/{chunk-POPQ4Y6H-CQz4hRgP.js → chunk-POPQ4Y6H-C1TwLrrN.js} +1 -1
- package/out/renderer/assets/{chunk-SVP7TREG-DGp9XQFd.js → chunk-SVP7TREG-DDOXG_t3.js} +1 -1
- package/out/renderer/assets/{chunk-TICWLB2K-CovR1uHr.js → chunk-TICWLB2K-BqT15hZi.js} +1 -1
- package/out/renderer/assets/{chunk-XXDRQBXY-gVmqSU5b.js → chunk-XXDRQBXY-D01ts6SC.js} +1 -1
- package/out/renderer/assets/classDiagram-ZZMXUADV-DnB4QNNe.js +1 -0
- package/out/renderer/assets/classDiagram-v2-VYDZK3BY-DnB4QNNe.js +1 -0
- package/out/renderer/assets/{cose-bilkent-JH36ORCC-DD4PEqt_.js → cose-bilkent-JH36ORCC-C7NVrT2_.js} +1 -1
- package/out/renderer/assets/{cynefin-OW5HDTMX-DNsYCrBx.js → cynefin-OW5HDTMX-2LxdFmSk.js} +1 -1
- package/out/renderer/assets/{cynefinDiagram-5FMLGOSQ-CoSzqs25.js → cynefinDiagram-5FMLGOSQ-_AN_Mulc.js} +1 -1
- package/out/renderer/assets/{cytoscape-fcose-CV0MpCmk.js → cytoscape-fcose-COZkZZmX.js} +1 -1
- package/out/renderer/assets/{dagre-GXQ25YYZ-BxpTPeHN.js → dagre-GXQ25YYZ-BUTwlM6j.js} +1 -1
- package/out/renderer/assets/{diagram-S7CK7UJ4-Df_OM1vW.js → diagram-S7CK7UJ4-CseZZ-y2.js} +1 -1
- package/out/renderer/assets/{diagram-UQ7AKVKN-iovjmny_.js → diagram-UQ7AKVKN-Cb7llS-8.js} +1 -1
- package/out/renderer/assets/{diagram-VSXAHHWV-BMrwlcQx.js → diagram-VSXAHHWV-CtuGqQvp.js} +1 -1
- package/out/renderer/assets/{diagram-VX7I27RA-DqLh449X.js → diagram-VX7I27RA-BA8eov-1.js} +1 -1
- package/out/renderer/assets/{diagram-Z3DM3KII-CH_W77UO.js → diagram-Z3DM3KII-VZOjj6Hg.js} +1 -1
- package/out/renderer/assets/{ebnfDiagram-PWID7BFC-yjzodXoL.js → ebnfDiagram-PWID7BFC-YBIrle6d.js} +1 -1
- package/out/renderer/assets/{erDiagram-RLTQ6QDP-DXxhvHYS.js → erDiagram-RLTQ6QDP-BiKyPEqW.js} +1 -1
- package/out/renderer/assets/{flowDiagram-HODETNUW-b2AWCAaB.js → flowDiagram-HODETNUW-7wmZyLHw.js} +1 -1
- package/out/renderer/assets/{ganttDiagram-EL5Y4UJY-COkyXL3K.js → ganttDiagram-EL5Y4UJY-D4j4GJaT.js} +1 -1
- package/out/renderer/assets/{gitGraphDiagram-WWUBYQGX-BYPqy5fh.js → gitGraphDiagram-WWUBYQGX-BqveM1NI.js} +1 -1
- package/out/renderer/assets/globals-C9M_MZZV.js +2539 -0
- package/out/renderer/assets/globals-l3kDGoYH.css +1 -0
- package/out/renderer/assets/index-BzSTiwH2.js +117 -0
- package/out/renderer/assets/{infoDiagram-27XIBGKW-DNg-VxlH.js → infoDiagram-27XIBGKW-DLPLnIFP.js} +1 -1
- package/out/renderer/assets/{ishikawaDiagram-5VMMS53U-DProTI6a.js → ishikawaDiagram-5VMMS53U-48drIAMR.js} +1 -1
- package/out/renderer/assets/{journeyDiagram-3NMN7TZE-BWhC4n3f.js → journeyDiagram-3NMN7TZE-vjigqUq_.js} +1 -1
- package/out/renderer/assets/{kanban-definition-UXKFOSKX-CHJRR0qi.js → kanban-definition-UXKFOSKX-CpsYVONZ.js} +1 -1
- package/out/renderer/assets/{layout-D8t6q8k0.js → layout-DqfoORoO.js} +1 -1
- package/out/renderer/assets/{linear-Cxb1p4iF.js → linear-CJzBBHcp.js} +1 -1
- package/out/renderer/assets/{mermaid.core-CFNOEUmc.js → mermaid.core-DdrGP-Hn.js} +5 -5
- package/out/renderer/assets/{mindmap-definition-YA3MSWOX-Ba78cyY4.js → mindmap-definition-YA3MSWOX-D68tLNxp.js} +1 -1
- package/out/renderer/assets/{pegDiagram-XKGWAZYB-C7zqoWMk.js → pegDiagram-XKGWAZYB-DkgLTcrv.js} +1 -1
- package/out/renderer/assets/{pieDiagram-E7YTZNPT-g304yFeX.js → pieDiagram-E7YTZNPT-bz5NuX1w.js} +1 -1
- package/out/renderer/assets/{quadrantDiagram-AXDQQJYC-Bwn3gGTO.js → quadrantDiagram-AXDQQJYC-o_VKLyJA.js} +1 -1
- package/out/renderer/assets/{railroadDiagram-O6MQD6OU-DRetS8pv.js → railroadDiagram-O6MQD6OU-Dkf03e07.js} +1 -1
- package/out/renderer/assets/{requirementDiagram-BXWQKSXE-CHz0FVZ7.js → requirementDiagram-BXWQKSXE-CBUz_3YU.js} +1 -1
- package/out/renderer/assets/{sankeyDiagram-P5KCCOFB-BYGRDIG9.js → sankeyDiagram-P5KCCOFB-B0pjUr9g.js} +1 -1
- package/out/renderer/assets/{sequenceDiagram-WJ2MYXX4-B60RuFFk.js → sequenceDiagram-WJ2MYXX4-ClugIL0e.js} +1 -1
- package/out/renderer/assets/settings-DvhrDn2q.js +34 -0
- package/out/renderer/assets/{sizeCapture-INFHLROL-CB-i3Fmz.js → sizeCapture-INFHLROL-D6y0rctc.js} +1 -1
- package/out/renderer/assets/{stateDiagram-D77RDMKH-CJOcikAJ.js → stateDiagram-D77RDMKH-DiftQepS.js} +1 -1
- package/out/renderer/assets/stateDiagram-v2-MP3YSRHH-DxB2-9tl.js +1 -0
- package/out/renderer/assets/{swimlanes-42K2YHIH-Buap2upT.js → swimlanes-42K2YHIH-DhuTjCNj.js} +1 -1
- package/out/renderer/assets/swimlanesDiagram-VR7AAH4N-CYDUqExO.js +8 -0
- package/out/renderer/assets/{timeline-definition-24CTP7MA-BdQta3QT.js → timeline-definition-24CTP7MA-CrXqgptd.js} +1 -1
- package/out/renderer/assets/{vennDiagram-4TSXK5OY-BynM2l28.js → vennDiagram-4TSXK5OY-CDm8SO8U.js} +1 -1
- package/out/renderer/assets/{wardleyDiagram-VM6X3IG4-FZjDO9FY.js → wardleyDiagram-VM6X3IG4-CxyunHwQ.js} +1 -1
- package/out/renderer/assets/{xychartDiagram-S5SC5T6Z-pJPSISxM.js → xychartDiagram-S5SC5T6Z-CvC5YMSy.js} +1 -1
- package/out/renderer/index.html +3 -3
- package/out/renderer/settings.html +4 -4
- package/out/renderer/web-preload.js +1 -1
- package/out/server/agent.js +562 -532
- package/out/server/chunks/{agent--Q7N17bY.js → agent-_G_O-Cpa.js} +155 -214
- package/out/server/chunks/{gpuBackendInstall-P7COXJlD.js → gpuBackendInstall-Cb6TFh_8.js} +9 -8
- package/out/server/chunks/{loadProvider-DvvFIF6F.js → loadProvider-Be9Lu1Oi.js} +7 -20
- package/out/server/chunks/{manifest-BvEa5QR3.js → manifest-CB63GQ-i.js} +6 -3
- package/out/server/chunks/{workflowPresets-CuLnfQqa.js → workflowPresets-Djlp5LPV.js} +786 -1832
- package/out/server/index.js +5743 -6563
- package/out/server/plugin-host.js +31 -25
- package/package.json +4 -4
- package/out/phone/assets/architecture-7GRP2DOG-D7mwyuxS.js +0 -1
- package/out/phone/assets/channel-BsGN1oT0.js +0 -1
- package/out/phone/assets/classDiagram-ZZMXUADV-a1PUvjC2.js +0 -1
- package/out/phone/assets/classDiagram-v2-VYDZK3BY-a1PUvjC2.js +0 -1
- package/out/phone/assets/desk-1McWacjU.js +0 -2
- package/out/phone/assets/eventmodeling-NTZA5JFV-DcUsfQiW.js +0 -1
- package/out/phone/assets/flowDiagram-HODETNUW-sUobw8zi.js +0 -1
- package/out/phone/assets/main-CnA1zWP8.css +0 -1
- package/out/phone/assets/railroad-abnf-HS5TGJTU-CGiIT1ZV.js +0 -1
- package/out/phone/assets/railroad-ebnf-LZEXJU2U-C85Q3c0J.js +0 -1
- package/out/phone/assets/railroad-peg-WCYAUIDC-8qPPCLgU.js +0 -1
- package/out/phone/assets/stateDiagram-v2-MP3YSRHH-WM4CNSf-.js +0 -1
- package/out/phone/assets/storage-CahQ0cyN.js +0 -1
- package/out/phone/assets/swimlanesDiagram-VR7AAH4N-65AiMWVp.js +0 -8
- package/out/renderer/assets/channel-B1Cv56hA.js +0 -1
- package/out/renderer/assets/classDiagram-ZZMXUADV-CDWgELaf.js +0 -1
- package/out/renderer/assets/classDiagram-v2-VYDZK3BY-CDWgELaf.js +0 -1
- package/out/renderer/assets/globals-DX-8GWfJ.css +0 -1
- package/out/renderer/assets/globals-y5_C1IiJ.js +0 -2539
- package/out/renderer/assets/index-CHJ6mVl2.js +0 -117
- package/out/renderer/assets/settings-Cd128yRb.js +0 -34
- package/out/renderer/assets/stateDiagram-v2-MP3YSRHH-BosPi5SR.js +0 -1
- package/out/renderer/assets/swimlanesDiagram-VR7AAH4N-B7TQEEbL.js +0 -8
package/out/server/agent.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import path, { join, posix, dirname } from "node:path";
|
|
2
|
-
import { p as parseChildSessionIdentity, a as parseSessionIdentity, i as isApprovalReviewReason, b as parseApprovalAllowThreshold, c as isProbability, C as CONTEXT_OCCUPANCY_BUCKETS, d as CONTEXT_PART_ITEMS, e as parseProviderHeaders, M as MODEL_API_KINDS, r as resolvePiProviderBaseUrl, f as escapePiConfigValue, g as MODEL_REASONING_OVERRIDES, h as MODEL_THINKING_LEVEL_OVERRIDES, j as isCodexAccountKey, k as classifyCodexPoolFailure, l as isUuid, m as isChildInterceptEvent, P as PLUGIN_MESSAGE_TYPE, n as CONTEXT_USAGE_BUCKETS, B as BEFORE_AGENT_START_PROMPT_MAX, o as BEFORE_AGENT_START_APPEND_MAX, A as AGENT_END_TEXT_MAX, q as MaskReportBuilder,
|
|
3
|
-
import {
|
|
2
|
+
import { p as parseChildSessionIdentity, a as parseSessionIdentity, i as isApprovalReviewReason, b as parseApprovalAllowThreshold, c as isProbability, C as CONTEXT_OCCUPANCY_BUCKETS, d as CONTEXT_PART_ITEMS, e as parseProviderHeaders, M as MODEL_API_KINDS, r as resolvePiProviderBaseUrl, f as escapePiConfigValue, g as MODEL_REASONING_OVERRIDES, h as MODEL_THINKING_LEVEL_OVERRIDES, j as isCodexAccountKey, k as classifyCodexPoolFailure, l as isUuid, m as isChildInterceptEvent, P as PLUGIN_MESSAGE_TYPE, n as CONTEXT_USAGE_BUCKETS, B as BEFORE_AGENT_START_PROMPT_MAX, o as BEFORE_AGENT_START_APPEND_MAX, A as AGENT_END_TEXT_MAX, q as MaskReportBuilder, w as workspaceBranchChangedNote, D as DEFAULT_MAX_ACTIVE_COWORKERS, s as DEFAULT_AUTO_RETRY_LIMIT, t as isSameChildSessionIdentity, u as resolveCompactStrategy, v as DEFAULT_SSH_TIMEOUT_SECONDS, x as PLAN_ENTRY_TYPE, y as autoRetryOverrides, z as parseAgentSessionCustomEntry, E as toolBatchDigest, S as STALE_SESSION_ERROR, F as splitPlanPrefix, G as parsePlanMessage, H as isClassifierOnlyProvider, I as isOauthAccountPool, J as resolveEditMode, K as EMPTY_PLAN_STATE, L as mergeMaskReports, N as PRIVACY_MASK_ENTRY, O as parseAgentCommand } from "./chunks/agent-_G_O-Cpa.js";
|
|
3
|
+
import fs, { writeFileSync, statSync, mkdirSync, existsSync, readFileSync, appendFileSync, unlinkSync, renameSync, rmSync, constants, realpathSync, readdirSync } from "node:fs";
|
|
4
|
+
import { A as AGENT_WORKER_CRASH_FILE, P as PatchMutationUncertainError, n as normalizeApplyPatchArguments, a as APPLY_PATCH_PROMPT_GUIDELINES, e as executeApplyPatch, b as emptyUsage, s as shellQuote, k as killProcessTree, c as charsToTokens, t as toolOccupancyText, d as skillOccupancyText, f as estimateToolTokens, g as estimateSkillTokens, h as estimateInstructionTokens, V as VIRTUAL_PROVIDER_ID, p as providerKeyFor, O as OM_OBSERVATIONS_RECORDED, i as OM_REFLECTIONS_RECORDED, j as isObservationsRecordedData, l as isReflectionsRecordedData, m as isReflectionsConsolidatedData, o as isObservationsDroppedData, q as OM_REFLECTIONS_CONSOLIDATED, r as OM_OBSERVATIONS_DROPPED, u as OM_FOLDED, v as isMemoryDetails, w as isObservationsRecordedEntry, x as isReflectionsRecordedEntry, y as isReflectionsConsolidatedEntry, z as isObservationsDroppedEntry, B as buildObservationsRecordedData, C as buildReflectionsRecordedData, D as buildReflectionsConsolidatedData, E as buildObservationsDroppedData, F as readModelsDevCache, G as version, H as parseModelDirectorySnapshot, I as findCatalogModelById, J as findModelsDevModel, K as mergeCatalogEntry, L as resolveCustomModelCapabilities, M as closestMatchHint, N as mcpTimeoutMsOrDefault, Q as oneLine$1, R as mcpNamespaceName, S as assignMcpToolNames, T as MCP_OAUTH_REFRESH_SKEW_MS, U as mcpOAuthFingerprint, W as DEFAULT_MCP_CONNECT_TIMEOUT_MS, X as DEFAULT_MCP_CALL_TIMEOUT_MS, Y as isXaiChatModelId, Z as transcriptMessages, _ as projectMessage, $ as ensureAccountProvider, a0 as takeSnapshotTail, a1 as attachBackgroundCommandHooks, a2 as ForegroundDetachedError, a3 as withHardenedEnv, a4 as childProfileShell, a5 as withDetachableExec, a6 as ELEVATE_ASKPASS_ENV, a7 as buildElevatedCommand, a8 as ELEVATE_DECLINED_MARKER, a9 as ELEVATE_TIMED_OUT_MARKER, aa as ELEVATE_TIMEOUT_MS, ab as ELEVATE_UNAVAILABLE_MARKER, ac as expandSkillCommands, ad as CODEMODE_FORBIDDEN_TOOLS, ae as normalizeTaskCheck, af as validateFetchUrl, ag as isPublicAddress, ah as throwUnlessAllowed, ai as SEND_IMAGE_CAPTION_MAX, aj as SEND_IMAGE_PER_REPLY, ak as sendImageItems, al as prependTurnNote, am as describeSubagentModels, an as resolveWorkflowPresetArgs, ao as extractWriteTargetPaths, ap as programTokens, aq as BackgroundTaskManager, ar as isDeferredMcp, as as providerIdOfAccountKey, at as resolveOauthCatalogModel, au as createSshExecutor, av as partitionMcpNamespaces, aw as CodemodeHost, ax as ApprovalGate, ay as HUMAN_REQUEST_TIMEOUT_MS, az as TodoStaleReminder, aA as CoworkerIdleReminder, aB as createUnifiedSubagentTool, aC as workflowPresetRoots, aD as createBrowserTools, aE as withNavigateApproval, aF as createMemoryTools, aG as withComputerApproval, aH as createComputerTool, aI as withApproval, aJ as listWorkflowPresets, aK as createTaskTools, aL as BrowserInvoker, aM as MemoryInvoker, aN as PlanController, aO as ComputerInvoker, aP as AskManager, aQ as createAskTool, aR as lastAssistantText$1, aS as positiveContextWindow, aT as foregroundCommandTimeoutMs, aU as buildTurnDigest, aV as parseJsonFromAssistant, aW as validateAgainstSchema, aX as appendYieldJson, aY as appendCappedLog, aZ as AGENT_COMPACTION_LOG, a_ as describeTitleModel, a$ as buildRollingTitleUserText, b0 as buildInitialTitleUserText, b1 as ROLLING_TITLE_SYSTEM_PROMPT, b2 as TITLE_SYSTEM_PROMPT, b3 as extractTitle, b4 as titleRejectReason, b5 as WORKSPACE_WRITE_TOOL_ID, b6 as resolveChildReasoning, b7 as pickChildReasoningOverride, b8 as createWebTools, b9 as createTodoTool, ba as withPlanGate, bb as createSubmitPlanTool, bc as titleSummaryTimeoutMs, bd as splitUnattendedPrefix, be as resolveHarnessSkillRoots, bf as approvalReviewResultExtension, bg as readHarnessRuleFiles, bh as replacePersonaParagraph, bi as createProjectSettingsManager, bj as ANTIGRAVITY_PROVIDER_ID, bk as antigravityProviderConfig, bl as DEVIN_PROVIDER_ID, bm as devinProviderConfig, bn as QODER_PROVIDER_ID, bo as qoderProviderConfig, bp as QODER_CN_PROVIDER_ID, bq as installCodexLinkedRefresh, br as isHeadlessRun, bs as withBackground, bt as withProtectedFloor, bu as loadWorkflowPreset, bv as cloneModelsDevOauthModel, bw as withWriteScope, bx as withWritePreflight, by as validateApplyPatchTargets, bz as withAgentRead, bA as extractEditTargetPath, bB as buildSshShellCommand, bC as resolveSshControlPath, bD as sshPasswordEnv, bE as getApplyPatchPaths } from "./chunks/workflowPresets-Djlp5LPV.js";
|
|
5
|
+
import { i as isCursorModel, a as attachCursorBridgeToSession, b as indexCursorTools, l as loadCursorProvider, C as CURSOR_PROVIDER_ID, c as installPiCursorExecHook } from "./chunks/loadProvider-Be9Lu1Oi.js";
|
|
4
6
|
import { setGlobalDispatcher, EnvHttpProxyAgent, Agent, Pool, FormData as FormData$1, fetch as fetch$1 } from "undici";
|
|
5
7
|
import { spawn, execFile } from "node:child_process";
|
|
6
8
|
import { createHash, randomUUID, createHmac, randomBytes } from "node:crypto";
|
|
7
|
-
import fs, { statSync, mkdirSync, existsSync, readFileSync, appendFileSync, unlinkSync, renameSync, rmSync, writeFileSync, constants, realpathSync, readdirSync } from "node:fs";
|
|
8
9
|
import { getSupportedThinkingLevels, clampThinkingLevel, createAssistantMessageEventStream, isRetryableAssistantError } from "@earendil-works/pi-ai";
|
|
9
10
|
import { estimateTokens, serializeConversation as serializeConversation$1, convertToLlm, buildSessionContext, getAgentDir, defineTool, createEditToolDefinition, VIRTUAL_MODEL_STATE_ENTRY, createPowerShellToolDefinition, createBashToolDefinition, createLocalPowerShellOperations, createLocalBashOperations, stripFrontmatter, createGrepToolDefinition, createAgentSession, SessionManager, ModelRuntime, DefaultResourceLoader, createWriteToolDefinition, createReadToolDefinition, createFindToolDefinition, createLsToolDefinition, createSyntheticSourceInfo } from "@earendil-works/pi-coding-agent";
|
|
10
|
-
import { P as PatchMutationUncertainError, n as normalizeApplyPatchArguments, A as APPLY_PATCH_PROMPT_GUIDELINES, e as executeApplyPatch, a as emptyUsage, s as shellQuote, k as killProcessTree, c as charsToTokens, t as toolOccupancyText, b as skillOccupancyText, d as estimateToolTokens, f as estimateSkillTokens, g as estimateInstructionTokens, V as VIRTUAL_PROVIDER_ID, p as providerKeyFor, O as OM_OBSERVATIONS_RECORDED, h as OM_REFLECTIONS_RECORDED, i as isObservationsRecordedData, j as isReflectionsRecordedData, l as isReflectionsConsolidatedData, m as isObservationsDroppedData, o as OM_REFLECTIONS_CONSOLIDATED, q as OM_OBSERVATIONS_DROPPED, r as OM_FOLDED, u as isMemoryDetails, v as isObservationsRecordedEntry, w as isReflectionsRecordedEntry, x as isReflectionsConsolidatedEntry, y as isObservationsDroppedEntry, z as buildObservationsRecordedData, B as buildReflectionsRecordedData, C as buildReflectionsConsolidatedData, D as buildObservationsDroppedData, E as readModelsDevCache, F as version, G as parseModelDirectorySnapshot, H as findCatalogModelById, I as findModelsDevModel, J as mergeCatalogEntry, K as resolveCustomModelCapabilities, L as closestMatchHint, M as mcpTimeoutMsOrDefault, N as oneLine$1, Q as mcpNamespaceName, R as assignMcpToolNames, S as MCP_OAUTH_REFRESH_SKEW_MS, T as mcpOAuthFingerprint, U as DEFAULT_MCP_CONNECT_TIMEOUT_MS, W as DEFAULT_MCP_CALL_TIMEOUT_MS, X as isXaiChatModelId, Y as transcriptMessages, Z as projectMessage, _ as ensureAccountProvider, $ as takeSnapshotTail, a0 as attachBackgroundCommandHooks, a1 as ForegroundDetachedError, a2 as withHardenedEnv, a3 as childProfileShell, a4 as withDetachableExec, a5 as ELEVATE_ASKPASS_ENV, a6 as buildElevatedCommand, a7 as ELEVATE_DECLINED_MARKER, a8 as ELEVATE_TIMED_OUT_MARKER, a9 as ELEVATE_TIMEOUT_MS, aa as ELEVATE_UNAVAILABLE_MARKER, ab as expandSkillCommands, ac as CODEMODE_FORBIDDEN_TOOLS, ad as normalizeTaskCheck, ae as CAPABILITY_CATALOG, af as validateFetchUrl, ag as isPublicAddress, ah as throwUnlessAllowed, ai as SEND_IMAGE_CAPTION_MAX, aj as SEND_IMAGE_PER_REPLY, ak as sendImageItems, al as prependTurnNote, am as describeSubagentModels, an as resolveWorkflowPresetArgs, ao as extractWriteTargetPaths, ap as programTokens, aq as BackgroundTaskManager, ar as isDeferredMcp, as as providerIdOfAccountKey, at as resolveOauthCatalogModel, au as createSshExecutor, av as partitionMcpNamespaces, aw as CodemodeHost, ax as ApprovalGate, ay as HUMAN_REQUEST_TIMEOUT_MS, az as TodoStaleReminder, aA as CoworkerIdleReminder, aB as createUnifiedSubagentTool, aC as workflowPresetRoots, aD as createBrowserTools, aE as withNavigateApproval, aF as createMemoryTools, aG as withComputerApproval, aH as createComputerTool, aI as withApproval, aJ as listWorkflowPresets, aK as createTaskTools, aL as BrowserInvoker, aM as MemoryInvoker, aN as PlanController, aO as ComputerInvoker, aP as AskManager, aQ as createAskTool, aR as lastAssistantText$1, aS as positiveContextWindow, aT as foregroundCommandTimeoutMs, aU as buildTurnDigest, aV as parseJsonFromAssistant, aW as validateAgainstSchema, aX as appendYieldJson, aY as describeTitleModel, aZ as buildRollingTitleUserText, a_ as buildInitialTitleUserText, a$ as ROLLING_TITLE_SYSTEM_PROMPT, b0 as TITLE_SYSTEM_PROMPT, b1 as extractTitle, b2 as titleRejectReason, b3 as WORKSPACE_WRITE_TOOL_ID, b4 as resolveChildReasoning, b5 as pickChildReasoningOverride, b6 as EnsoSafeJournal, b7 as createWebTools, b8 as createTodoTool, b9 as withPlanGate, ba as createSubmitPlanTool, bb as titleSummaryTimeoutMs, bc as splitUnattendedPrefix, bd as resolveHarnessSkillRoots, be as approvalReviewResultExtension, bf as readHarnessRuleFiles, bg as replacePersonaParagraph, bh as createProjectSettingsManager, bi as ANTIGRAVITY_PROVIDER_ID, bj as antigravityProviderConfig, bk as DEVIN_PROVIDER_ID, bl as devinProviderConfig, bm as QODER_PROVIDER_ID, bn as qoderProviderConfig, bo as QODER_CN_PROVIDER_ID, bp as installCodexLinkedRefresh, bq as isHeadlessRun, br as withBackground, bs as withProtectedFloor, bt as ENSO_SYSTEM_PROMPT, bu as loadWorkflowPreset, bv as cloneModelsDevOauthModel, bw as withWriteScope, bx as withWritePreflight, by as validateApplyPatchTargets, bz as withAgentRead, bA as extractEditTargetPath, bB as buildSshShellCommand, bC as resolveSshControlPath, bD as sshPasswordEnv, bE as getApplyPatchPaths } from "./chunks/workflowPresets-CuLnfQqa.js";
|
|
11
11
|
import { rm, mkdtemp, readFile, stat, readdir, realpath, mkdir, lstat, open, unlink } from "node:fs/promises";
|
|
12
12
|
import "node:buffer";
|
|
13
13
|
import os, { tmpdir, homedir } from "node:os";
|
|
@@ -25,17 +25,19 @@ import { lookup } from "node:dns/promises";
|
|
|
25
25
|
import { isIP, BlockList } from "node:net";
|
|
26
26
|
import { createRequire } from "node:module";
|
|
27
27
|
import { QuickJS, JSException } from "quickjs-wasi";
|
|
28
|
-
import "node:events";
|
|
29
|
-
import "node:http2";
|
|
30
|
-
import "node:stream";
|
|
31
28
|
import "node:zlib";
|
|
32
29
|
import "yaml";
|
|
33
30
|
import "node:string_decoder";
|
|
34
31
|
import "node:util";
|
|
32
|
+
import "node:url";
|
|
35
33
|
import "@mozilla/readability";
|
|
36
34
|
import "linkedom";
|
|
37
35
|
import "turndown";
|
|
36
|
+
import "@earendil-works/pi-ai/api/transform-messages";
|
|
38
37
|
import "node:http";
|
|
38
|
+
import "node:events";
|
|
39
|
+
import "node:http2";
|
|
40
|
+
import "node:stream";
|
|
39
41
|
const PARENT_TYPES = /* @__PURE__ */ new Set(["spawn-parent", "prompt", "steer", "retry"]);
|
|
40
42
|
const CHILD_TYPES = /* @__PURE__ */ new Set(["spawn-child", "prompt", "steer", "retry"]);
|
|
41
43
|
function rejectUnparsableCommand(data) {
|
|
@@ -57,6 +59,24 @@ function rejectUnparsableCommand(data) {
|
|
|
57
59
|
...typeof instanceId === "string" && instanceId ? { instanceId } : {}
|
|
58
60
|
};
|
|
59
61
|
}
|
|
62
|
+
function installCrashRecord(dataDir2) {
|
|
63
|
+
process.on("uncaughtExceptionMonitor", (error, origin) => {
|
|
64
|
+
try {
|
|
65
|
+
const memory = process.memoryUsage();
|
|
66
|
+
const crash = {
|
|
67
|
+
pid: process.pid,
|
|
68
|
+
at: Date.now(),
|
|
69
|
+
origin,
|
|
70
|
+
message: error instanceof Error ? `${error.name}: ${error.message}` : String(error),
|
|
71
|
+
stack: error instanceof Error ? error.stack : void 0,
|
|
72
|
+
rss: memory.rss,
|
|
73
|
+
heapUsed: memory.heapUsed
|
|
74
|
+
};
|
|
75
|
+
writeFileSync(path.join(dataDir2, AGENT_WORKER_CRASH_FILE), JSON.stringify(crash), "utf8");
|
|
76
|
+
} catch {
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
}
|
|
60
80
|
const TIMEOUTS = { headersTimeout: 0, bodyTimeout: 0 };
|
|
61
81
|
function bootstrapWorkerProxyFromEnv() {
|
|
62
82
|
applyWorkerProxyEnv({});
|
|
@@ -227,8 +247,8 @@ class AgentControlInvoker {
|
|
|
227
247
|
kind
|
|
228
248
|
});
|
|
229
249
|
const onAbort = () => {
|
|
230
|
-
const
|
|
231
|
-
if (!
|
|
250
|
+
const pending2 = keepReceipt ? this.pending.get(requestId) : this.take(requestId);
|
|
251
|
+
if (!pending2) return;
|
|
232
252
|
cancel("abort");
|
|
233
253
|
if (!keepReceipt) reject(new Error("Agent control wait interrupted."));
|
|
234
254
|
};
|
|
@@ -254,9 +274,9 @@ class AgentControlInvoker {
|
|
|
254
274
|
});
|
|
255
275
|
}
|
|
256
276
|
resolve(requestId, response) {
|
|
257
|
-
const
|
|
258
|
-
if (!
|
|
259
|
-
|
|
277
|
+
const pending2 = this.take(requestId);
|
|
278
|
+
if (!pending2) return false;
|
|
279
|
+
pending2.resolve(response);
|
|
260
280
|
return true;
|
|
261
281
|
}
|
|
262
282
|
close(reason) {
|
|
@@ -265,16 +285,16 @@ class AgentControlInvoker {
|
|
|
265
285
|
}
|
|
266
286
|
}
|
|
267
287
|
take(requestId) {
|
|
268
|
-
const
|
|
269
|
-
if (!
|
|
288
|
+
const pending2 = this.pending.get(requestId);
|
|
289
|
+
if (!pending2) return void 0;
|
|
270
290
|
this.pending.delete(requestId);
|
|
271
|
-
if (
|
|
272
|
-
|
|
291
|
+
if (pending2.signal && pending2.onAbort) {
|
|
292
|
+
pending2.signal.removeEventListener("abort", pending2.onAbort);
|
|
273
293
|
}
|
|
274
|
-
if (
|
|
275
|
-
|
|
294
|
+
if (pending2.detach && pending2.onDetach) {
|
|
295
|
+
pending2.detach.removeEventListener("abort", pending2.onDetach);
|
|
276
296
|
}
|
|
277
|
-
return
|
|
297
|
+
return pending2;
|
|
278
298
|
}
|
|
279
299
|
}
|
|
280
300
|
function toPosixRemotePath(value) {
|
|
@@ -796,6 +816,10 @@ function ensureAssistantUsage(messages) {
|
|
|
796
816
|
}
|
|
797
817
|
return patched;
|
|
798
818
|
}
|
|
819
|
+
function auxiliaryReasoning(candidate, fallback = "medium") {
|
|
820
|
+
if (candidate?.reasoning !== "on") return void 0;
|
|
821
|
+
return candidate.thinkingLevel ?? fallback;
|
|
822
|
+
}
|
|
799
823
|
const HOT_BUILTIN_TOOL_IDS = [
|
|
800
824
|
"image_generation",
|
|
801
825
|
"subagent",
|
|
@@ -807,7 +831,8 @@ const HOT_BUILTIN_TOOL_IDS = [
|
|
|
807
831
|
"web",
|
|
808
832
|
"background_tasks",
|
|
809
833
|
"memory",
|
|
810
|
-
"computer"
|
|
834
|
+
"computer",
|
|
835
|
+
"turn_discard"
|
|
811
836
|
];
|
|
812
837
|
function enabledHotBuiltins(disabled) {
|
|
813
838
|
const off = new Set(disabled);
|
|
@@ -914,6 +939,10 @@ function parseArgs(cmd) {
|
|
|
914
939
|
if (cur) args.push(cur);
|
|
915
940
|
return args;
|
|
916
941
|
}
|
|
942
|
+
function quoteArg(value) {
|
|
943
|
+
return `'${value.replaceAll("'", `'"'"'`)}'`;
|
|
944
|
+
}
|
|
945
|
+
const LITERAL_PATHSPECS = { GIT_LITERAL_PATHSPECS: "1" };
|
|
917
946
|
const getRepoRoot = (cwd, host = localCheckpointHost) => host.git("rev-parse --show-toplevel", cwd);
|
|
918
947
|
function shouldIgnoreForSnapshot(path2) {
|
|
919
948
|
return path2.split(/[/\\]/).some((c) => IGNORED_DIR_NAMES.has(c));
|
|
@@ -1085,8 +1114,10 @@ async function createCheckpoint(opts, host = localCheckpointHost) {
|
|
|
1085
1114
|
}
|
|
1086
1115
|
const BATCH = 100;
|
|
1087
1116
|
for (let i = 0; i < filtered.length; i += BATCH) {
|
|
1088
|
-
const paths = filtered.slice(i, i + BATCH).map(
|
|
1089
|
-
await host.git(`add --all -- ${paths}`, root, {
|
|
1117
|
+
const paths = filtered.slice(i, i + BATCH).map(quoteArg).join(" ");
|
|
1118
|
+
await host.git(`add --all -- ${paths}`, root, {
|
|
1119
|
+
env: { ...tmpEnv, ...LITERAL_PATHSPECS }
|
|
1120
|
+
});
|
|
1090
1121
|
}
|
|
1091
1122
|
const worktreeTreeSha = await host.git("write-tree", root, { env: tmpEnv });
|
|
1092
1123
|
const msg = [
|
|
@@ -1162,8 +1193,8 @@ async function restoreCheckpoint(root, cp, host = localCheckpointHost) {
|
|
|
1162
1193
|
await host.git(`read-tree --reset ${cp.indexTreeSha}`, root);
|
|
1163
1194
|
}
|
|
1164
1195
|
async function safeClean(root, preexisting, skippedFiles, skippedDirs, host) {
|
|
1165
|
-
const output = await host.git("ls-files --others --exclude-standard", root).catch(() => "");
|
|
1166
|
-
const current = output.split("\
|
|
1196
|
+
const output = await host.git("ls-files -z --others --exclude-standard", root).catch(() => "");
|
|
1197
|
+
const current = output.split("\0").filter(Boolean);
|
|
1167
1198
|
if (current.length === 0) return;
|
|
1168
1199
|
const preSet = new Set(preexisting);
|
|
1169
1200
|
const sfSet = new Set(skippedFiles);
|
|
@@ -1177,8 +1208,8 @@ async function safeClean(root, preexisting, skippedFiles, skippedDirs, host) {
|
|
|
1177
1208
|
});
|
|
1178
1209
|
const BATCH = 100;
|
|
1179
1210
|
for (let i = 0; i < toRemove.length; i += BATCH) {
|
|
1180
|
-
const paths = toRemove.slice(i, i + BATCH).map(
|
|
1181
|
-
await host.git(`clean -f -- ${paths}`, root).catch(() => {
|
|
1211
|
+
const paths = toRemove.slice(i, i + BATCH).map(quoteArg).join(" ");
|
|
1212
|
+
await host.git(`clean -f -- ${paths}`, root, { env: LITERAL_PATHSPECS }).catch(() => {
|
|
1182
1213
|
});
|
|
1183
1214
|
}
|
|
1184
1215
|
}
|
|
@@ -1281,12 +1312,13 @@ class CheckpointManager {
|
|
|
1281
1312
|
host;
|
|
1282
1313
|
/** undefined = 未探测;null = 非 git 项目 */
|
|
1283
1314
|
root;
|
|
1284
|
-
|
|
1315
|
+
/** 本轮快照(进行中或已落定);同轮其余写盘工具共用,不各自打快照 */
|
|
1316
|
+
turnCheckpoint;
|
|
1285
1317
|
failures = 0;
|
|
1286
1318
|
disabled = false;
|
|
1287
1319
|
/** agent_start 时调用,放行本轮的一次快照 */
|
|
1288
1320
|
resetTurn() {
|
|
1289
|
-
this.
|
|
1321
|
+
this.turnCheckpoint = void 0;
|
|
1290
1322
|
}
|
|
1291
1323
|
async resolveRoot() {
|
|
1292
1324
|
if (this.root === void 0) {
|
|
@@ -1294,10 +1326,16 @@ class CheckpointManager {
|
|
|
1294
1326
|
}
|
|
1295
1327
|
return this.root;
|
|
1296
1328
|
}
|
|
1297
|
-
/**
|
|
1329
|
+
/**
|
|
1330
|
+
* 每轮至多一次;失败不抛(同轮不重试)。同轮调用都等同一个快照落定:pi 默认并行执行
|
|
1331
|
+
* 工具,只置标记就放行的话,后到的写盘会抢在快照的 git status/add 之前落盘
|
|
1332
|
+
*/
|
|
1298
1333
|
async ensureTurnCheckpoint(toolName) {
|
|
1299
|
-
if (this.disabled
|
|
1300
|
-
this.
|
|
1334
|
+
if (this.disabled) return;
|
|
1335
|
+
this.turnCheckpoint ??= this.createTurnCheckpoint(toolName);
|
|
1336
|
+
await this.turnCheckpoint;
|
|
1337
|
+
}
|
|
1338
|
+
async createTurnCheckpoint(toolName) {
|
|
1301
1339
|
try {
|
|
1302
1340
|
const root = await this.resolveRoot();
|
|
1303
1341
|
if (!root) {
|
|
@@ -1320,8 +1358,12 @@ class CheckpointManager {
|
|
|
1320
1358
|
void pruneCheckpoints(root, this.sessionId, void 0, this.host).catch(() => {
|
|
1321
1359
|
});
|
|
1322
1360
|
this.failures = 0;
|
|
1323
|
-
} catch {
|
|
1361
|
+
} catch (error) {
|
|
1324
1362
|
if (++this.failures >= 3) this.disabled = true;
|
|
1363
|
+
console.warn(
|
|
1364
|
+
`[checkpoint] ${this.sessionId.slice(0, 8)} snapshot failed (${this.failures}/3${this.disabled ? ", disabled for this session" : ""}):`,
|
|
1365
|
+
error instanceof Error ? error.message : String(error)
|
|
1366
|
+
);
|
|
1325
1367
|
}
|
|
1326
1368
|
}
|
|
1327
1369
|
/**
|
|
@@ -1689,7 +1731,7 @@ function createClaudeHooksExtension(options) {
|
|
|
1689
1731
|
name: `claude-hooks-${role.kind}`,
|
|
1690
1732
|
hidden: true,
|
|
1691
1733
|
factory: (pi) => {
|
|
1692
|
-
const
|
|
1734
|
+
const pending2 = [];
|
|
1693
1735
|
const preToolContext = /* @__PURE__ */ new Map();
|
|
1694
1736
|
let stopContinuations = 0;
|
|
1695
1737
|
const stopEvent = parent ? "Stop" : "SubagentStop";
|
|
@@ -1701,14 +1743,14 @@ function createClaudeHooksExtension(options) {
|
|
|
1701
1743
|
const source = options.resumed ? "resume" : "startup";
|
|
1702
1744
|
const outs = role.kind === "parent" ? await dispatch("SessionStart", ctx, { source }, source) : await dispatch("SubagentStart", ctx, agentFields(ctx), role.agentType);
|
|
1703
1745
|
const context = contexts(outs);
|
|
1704
|
-
if (context)
|
|
1746
|
+
if (context) pending2.push(context);
|
|
1705
1747
|
};
|
|
1706
1748
|
if (parent && has("SessionStart")) {
|
|
1707
1749
|
pi.on("session_compact", async (_event, ctx) => {
|
|
1708
1750
|
const context = contexts(
|
|
1709
1751
|
await dispatch("SessionStart", ctx, { source: "compact" }, "compact")
|
|
1710
1752
|
);
|
|
1711
|
-
if (context)
|
|
1753
|
+
if (context) pending2.push(context);
|
|
1712
1754
|
});
|
|
1713
1755
|
}
|
|
1714
1756
|
const runsPrompt = parent && has("UserPromptSubmit");
|
|
@@ -1716,7 +1758,7 @@ function createClaudeHooksExtension(options) {
|
|
|
1716
1758
|
pi.on("before_agent_start", async (event, ctx) => {
|
|
1717
1759
|
stopContinuations = 0;
|
|
1718
1760
|
if (!started) await runStart(ctx);
|
|
1719
|
-
const parts =
|
|
1761
|
+
const parts = pending2.splice(0);
|
|
1720
1762
|
if (runsPrompt && event.messageType === "user") {
|
|
1721
1763
|
const outs = await dispatch(
|
|
1722
1764
|
"UserPromptSubmit",
|
|
@@ -2367,7 +2409,7 @@ class ContextUsageTracker {
|
|
|
2367
2409
|
const currentNonMessageTokens = input.currentNonMessageTokens;
|
|
2368
2410
|
const branchMessages = input.branchMessages ?? input.activeMessages;
|
|
2369
2411
|
const compactionIndex = input.compactionIndex ?? -1;
|
|
2370
|
-
const
|
|
2412
|
+
const pending2 = this.#pending;
|
|
2371
2413
|
let usedTokens = 0;
|
|
2372
2414
|
let anchored = false;
|
|
2373
2415
|
let anchorEntry;
|
|
@@ -2382,14 +2424,14 @@ class ContextUsageTracker {
|
|
|
2382
2424
|
anchorIndex = resolveActiveIndex(input.activeMessages, anchorEntry);
|
|
2383
2425
|
}
|
|
2384
2426
|
const anchorEpoch = anchorEntry?.contextSnapshot?.compactionEpoch ?? 0;
|
|
2385
|
-
const useAnchor = anchorEntry !== void 0 && anchorIndex !== -1 && (!
|
|
2427
|
+
const useAnchor = anchorEntry !== void 0 && anchorIndex !== -1 && (!pending2 || anchorIndex >= pending2.cutoffCount && anchorEpoch >= pending2.epoch);
|
|
2386
2428
|
if (useAnchor && anchorEntry) {
|
|
2387
2429
|
const anchorNonMessage = anchorEntry.contextSnapshot?.nonMessageTokens ?? currentNonMessageTokens;
|
|
2388
2430
|
anchored = true;
|
|
2389
2431
|
usedTokens = correctedPromptTokens(anchorEntry) + Math.max(0, currentNonMessageTokens - anchorNonMessage) + sumEstimates(input.activeMessages, anchorIndex + 1, estimate) + pendingTokens;
|
|
2390
|
-
} else if (
|
|
2432
|
+
} else if (pending2) {
|
|
2391
2433
|
anchored = true;
|
|
2392
|
-
usedTokens =
|
|
2434
|
+
usedTokens = pending2.promptTokens + Math.max(0, currentNonMessageTokens - pending2.nonMessageTokens) + sumEstimates(input.activeMessages, pending2.cutoffCount, estimate) + pendingTokens;
|
|
2393
2435
|
} else if (branchMessages.length === 0) {
|
|
2394
2436
|
const liveAnchor = findTranscriptUsageAnchor(input.activeMessages);
|
|
2395
2437
|
if (liveAnchor) {
|
|
@@ -2648,18 +2690,21 @@ function selectKeptBoundary(input) {
|
|
|
2648
2690
|
branch.findIndex((entry) => entry.id === preparation.firstKeptEntryId)
|
|
2649
2691
|
);
|
|
2650
2692
|
const cuts = legalCuts(branch).filter((index) => index >= origin);
|
|
2693
|
+
const estimateFrom = (cut) => hint + branch.slice(cut).reduce((sum, entry) => sum + estimateMessageTokens(entry.message), 0);
|
|
2694
|
+
let estimatedAfter = estimateFrom(origin);
|
|
2651
2695
|
for (const cut of cuts) {
|
|
2652
|
-
|
|
2653
|
-
|
|
2654
|
-
if (
|
|
2655
|
-
|
|
2696
|
+
estimatedAfter = estimateFrom(cut);
|
|
2697
|
+
if (estimatedAfter > budget) continue;
|
|
2698
|
+
if (noSaving(input.savingBaseline, estimatedAfter)) {
|
|
2699
|
+
return { fail: "no_saving", budget, estimatedAfter };
|
|
2700
|
+
}
|
|
2656
2701
|
return {
|
|
2657
2702
|
firstKeptEntryId: branch[cut].id ?? preparation.firstKeptEntryId,
|
|
2658
2703
|
evicted: evictedItems(branch.slice(origin, cut)),
|
|
2659
2704
|
estimatedAfter
|
|
2660
2705
|
};
|
|
2661
2706
|
}
|
|
2662
|
-
return { fail: "uncompressible" };
|
|
2707
|
+
return { fail: "uncompressible", budget, estimatedAfter };
|
|
2663
2708
|
}
|
|
2664
2709
|
function contentChars(content) {
|
|
2665
2710
|
if (typeof content === "string") return content.length;
|
|
@@ -2686,24 +2731,10 @@ function legalCuts(branch) {
|
|
|
2686
2731
|
return entry.id && (role === "user" || role === "assistant") ? [index] : [];
|
|
2687
2732
|
});
|
|
2688
2733
|
}
|
|
2689
|
-
function
|
|
2690
|
-
|
|
2691
|
-
if (
|
|
2692
|
-
|
|
2693
|
-
return billed > 0 ? billed : 0;
|
|
2694
|
-
}
|
|
2695
|
-
function billedOverBudget(tail, budget) {
|
|
2696
|
-
for (let i = tail.length - 1; i >= 0; i--) {
|
|
2697
|
-
if (tail[i].message?.role !== "assistant") continue;
|
|
2698
|
-
const billed = billedTokens(tail[i].message);
|
|
2699
|
-
if (billed > 0) return billed > budget;
|
|
2700
|
-
}
|
|
2701
|
-
return false;
|
|
2702
|
-
}
|
|
2703
|
-
function noSaving(previous, after) {
|
|
2704
|
-
if (previous === void 0) return false;
|
|
2705
|
-
if (previous <= 0) return after >= previous;
|
|
2706
|
-
return (previous - after) / previous < MIN_SAVING_RATIO;
|
|
2734
|
+
function noSaving(baseline, after) {
|
|
2735
|
+
if (baseline === void 0) return false;
|
|
2736
|
+
if (baseline <= 0) return after >= baseline;
|
|
2737
|
+
return (baseline - after) / baseline < MIN_SAVING_RATIO;
|
|
2707
2738
|
}
|
|
2708
2739
|
function evictedItems(entries) {
|
|
2709
2740
|
return entries.flatMap((entry) => {
|
|
@@ -2723,7 +2754,20 @@ function evictedLabel(entry) {
|
|
|
2723
2754
|
if (msg.role === "user") return "user";
|
|
2724
2755
|
return void 0;
|
|
2725
2756
|
}
|
|
2726
|
-
const
|
|
2757
|
+
const pending = /* @__PURE__ */ new WeakMap();
|
|
2758
|
+
function recordCompactCancel(sessionManager, cancel) {
|
|
2759
|
+
pending.set(sessionManager, cancel);
|
|
2760
|
+
}
|
|
2761
|
+
function takeCompactCancel(sessionManager) {
|
|
2762
|
+
const cancel = pending.get(sessionManager);
|
|
2763
|
+
pending.delete(sessionManager);
|
|
2764
|
+
return cancel;
|
|
2765
|
+
}
|
|
2766
|
+
function formatCompactCancel(cancel) {
|
|
2767
|
+
const window = cancel.contextWindow ?? `未知,按默认 ${DEFAULT_CONTEXT_WINDOW}`;
|
|
2768
|
+
return cancel.reason === "no_saving" ? `压缩已取消(no_saving):压缩后约 ${cancel.estimatedAfter} tokens,相比压缩前 ${cancel.tokensBefore} 节省不足 10%` : `压缩已取消(uncompressible):最短可保留尾巴约 ${cancel.estimatedAfter} tokens,超过发送预算 ${cancel.budget}(上下文窗口 ${window},压缩前 ${cancel.tokensBefore})`;
|
|
2769
|
+
}
|
|
2770
|
+
const READ_ONLY_TOOLS$1 = /* @__PURE__ */ new Set(["read", "grep", "find", "ls", "glob"]);
|
|
2727
2771
|
function normalizeMessages(input) {
|
|
2728
2772
|
const out = [];
|
|
2729
2773
|
for (const item of input) {
|
|
@@ -2795,7 +2839,7 @@ function pruneMessages(messages, opts = {}) {
|
|
|
2795
2839
|
for (const msg of messages) {
|
|
2796
2840
|
if (msg.role !== "assistant") continue;
|
|
2797
2841
|
for (const call of toolCallBlocks(msg.content)) {
|
|
2798
|
-
if (!READ_ONLY_TOOLS.has(call.name)) {
|
|
2842
|
+
if (!READ_ONLY_TOOLS$1.has(call.name)) {
|
|
2799
2843
|
epoch++;
|
|
2800
2844
|
continue;
|
|
2801
2845
|
}
|
|
@@ -2855,12 +2899,12 @@ function atomicGroups(messages) {
|
|
|
2855
2899
|
const msg = messages[i];
|
|
2856
2900
|
const group = [msg];
|
|
2857
2901
|
i++;
|
|
2858
|
-
const
|
|
2902
|
+
const pending2 = new Set(
|
|
2859
2903
|
msg.role === "assistant" ? toolCallBlocks(msg.content).map((c) => c.id).filter((id) => resultIds.has(id)) : []
|
|
2860
2904
|
);
|
|
2861
|
-
while (
|
|
2905
|
+
while (pending2.size && i < messages.length) {
|
|
2862
2906
|
const next = messages[i];
|
|
2863
|
-
if (next.role === "toolResult" && next.toolCallId)
|
|
2907
|
+
if (next.role === "toolResult" && next.toolCallId) pending2.delete(next.toolCallId);
|
|
2864
2908
|
group.push(next);
|
|
2865
2909
|
i++;
|
|
2866
2910
|
}
|
|
@@ -3300,7 +3344,6 @@ async function summarizeHierarchical(chunks, facts, previousSummary, complete, m
|
|
|
3300
3344
|
}
|
|
3301
3345
|
}
|
|
3302
3346
|
function createEnsoCompactHandler(options = {}) {
|
|
3303
|
-
const lastEstimatedAfter = /* @__PURE__ */ new WeakMap();
|
|
3304
3347
|
return async (event, ctx) => {
|
|
3305
3348
|
const branch = asEntries(event.branchEntries ?? ctx.sessionManager.getBranch());
|
|
3306
3349
|
if (branch.length < 3) return;
|
|
@@ -3321,16 +3364,26 @@ function createEnsoCompactHandler(options = {}) {
|
|
|
3321
3364
|
let evicted = [];
|
|
3322
3365
|
const origin = branch.findIndex((entry) => entry.id === firstKeptEntryId);
|
|
3323
3366
|
if (origin >= 0) {
|
|
3367
|
+
const contextWindow = positiveWindow(ctx.model?.contextWindow);
|
|
3324
3368
|
const cut = selectKeptBoundary({
|
|
3325
3369
|
branch,
|
|
3326
3370
|
preparation: { firstKeptEntryId, previousSummary, tokensBefore },
|
|
3327
|
-
contextWindow
|
|
3328
|
-
|
|
3371
|
+
contextWindow,
|
|
3372
|
+
// 手动压缩是用户明确要求,不做节省判定
|
|
3373
|
+
savingBaseline: event.reason === "manual" ? void 0 : tokensBefore
|
|
3329
3374
|
});
|
|
3330
|
-
if ("fail" in cut)
|
|
3375
|
+
if ("fail" in cut) {
|
|
3376
|
+
recordCompactCancel(ctx.sessionManager, {
|
|
3377
|
+
reason: cut.fail,
|
|
3378
|
+
budget: cut.budget,
|
|
3379
|
+
estimatedAfter: cut.estimatedAfter,
|
|
3380
|
+
tokensBefore,
|
|
3381
|
+
...contextWindow ? { contextWindow } : {}
|
|
3382
|
+
});
|
|
3383
|
+
return { cancel: true };
|
|
3384
|
+
}
|
|
3331
3385
|
keptId = cut.firstKeptEntryId;
|
|
3332
3386
|
evicted = cut.evicted;
|
|
3333
|
-
lastEstimatedAfter.set(ctx.sessionManager, cut.estimatedAfter);
|
|
3334
3387
|
}
|
|
3335
3388
|
const keptIndex = branch.findIndex((entry) => entry.id === keptId);
|
|
3336
3389
|
const extra = origin >= 0 && keptIndex > origin ? branch.slice(origin, keptIndex) : [];
|
|
@@ -6291,10 +6344,10 @@ function sourceOriginAndQualifiers(entry) {
|
|
|
6291
6344
|
const timestamp = formatDisplayTimestamp(msg.timestamp, entry.timestamp);
|
|
6292
6345
|
if (msg.role === "user") return { origin: "User", timestamp, qualifiers: [] };
|
|
6293
6346
|
if (msg.role === "assistant") {
|
|
6294
|
-
const
|
|
6347
|
+
const toolCalls2 = uniqueStrings(
|
|
6295
6348
|
textContentBlocks(msg.content).filter((block) => block.type === "toolCall" && typeof block.name === "string").map((block) => block.name)
|
|
6296
6349
|
);
|
|
6297
|
-
return { origin: "Assistant", timestamp, qualifiers:
|
|
6350
|
+
return { origin: "Assistant", timestamp, qualifiers: toolCalls2.length > 0 ? [`tool calls: ${toolCalls2.join(", ")}`] : [] };
|
|
6298
6351
|
}
|
|
6299
6352
|
const toolName = msg.toolName;
|
|
6300
6353
|
return { origin: `Tool result: ${typeof toolName === "string" && toolName ? toolName : "unknown"}`, timestamp, qualifiers: [] };
|
|
@@ -6970,27 +7023,27 @@ function closesToolTurn(message) {
|
|
|
6970
7023
|
return ["user", "custom", "branchSummary", "compactionSummary"].includes(message.role);
|
|
6971
7024
|
}
|
|
6972
7025
|
function dropUnpairedToolResults(messages) {
|
|
6973
|
-
let
|
|
7026
|
+
let pending2 = /* @__PURE__ */ new Set();
|
|
6974
7027
|
let out;
|
|
6975
7028
|
for (let i = 0; i < messages.length; i++) {
|
|
6976
7029
|
const message = messages[i];
|
|
6977
7030
|
if (!message) continue;
|
|
6978
7031
|
if (message.role === "assistant") {
|
|
6979
7032
|
const skipped = message.stopReason === "error" || message.stopReason === "aborted";
|
|
6980
|
-
|
|
7033
|
+
pending2 = new Set(
|
|
6981
7034
|
skipped || !Array.isArray(message.content) ? [] : message.content.flatMap(
|
|
6982
7035
|
(b) => isToolCall(b) && typeof b.id === "string" ? [b.id] : []
|
|
6983
7036
|
)
|
|
6984
7037
|
);
|
|
6985
7038
|
} else if (message.role === "toolResult") {
|
|
6986
|
-
if (typeof message.toolCallId === "string" &&
|
|
7039
|
+
if (typeof message.toolCallId === "string" && pending2.delete(message.toolCallId)) {
|
|
6987
7040
|
out?.push(message);
|
|
6988
7041
|
continue;
|
|
6989
7042
|
}
|
|
6990
7043
|
out ??= messages.slice(0, i);
|
|
6991
7044
|
continue;
|
|
6992
7045
|
} else if (closesToolTurn(message)) {
|
|
6993
|
-
|
|
7046
|
+
pending2 = /* @__PURE__ */ new Set();
|
|
6994
7047
|
}
|
|
6995
7048
|
out?.push(message);
|
|
6996
7049
|
}
|
|
@@ -8195,18 +8248,23 @@ function mapToolResult(result, name) {
|
|
|
8195
8248
|
...payload.isError ? { isError: true } : {}
|
|
8196
8249
|
};
|
|
8197
8250
|
}
|
|
8198
|
-
function withTimeout(promise, ms, label) {
|
|
8251
|
+
function withTimeout(promise, ms, label, signal) {
|
|
8199
8252
|
return new Promise((resolve, reject) => {
|
|
8200
|
-
const timer = setTimeout(
|
|
8253
|
+
const timer = setTimeout(
|
|
8254
|
+
() => finish2(() => reject(new Error(`${label} timed out after ${ms}ms`))),
|
|
8255
|
+
ms
|
|
8256
|
+
);
|
|
8257
|
+
const onAbort = () => finish2(() => reject(Object.assign(new Error(`${label} aborted`), { name: "AbortError" })));
|
|
8258
|
+
const finish2 = (settle) => {
|
|
8259
|
+
clearTimeout(timer);
|
|
8260
|
+
signal?.removeEventListener("abort", onAbort);
|
|
8261
|
+
settle();
|
|
8262
|
+
};
|
|
8263
|
+
if (signal?.aborted) onAbort();
|
|
8264
|
+
else signal?.addEventListener("abort", onAbort, { once: true });
|
|
8201
8265
|
promise.then(
|
|
8202
|
-
(value) =>
|
|
8203
|
-
|
|
8204
|
-
resolve(value);
|
|
8205
|
-
},
|
|
8206
|
-
(error) => {
|
|
8207
|
-
clearTimeout(timer);
|
|
8208
|
-
reject(error);
|
|
8209
|
-
}
|
|
8266
|
+
(value) => finish2(() => resolve(value)),
|
|
8267
|
+
(error) => finish2(() => reject(error))
|
|
8210
8268
|
);
|
|
8211
8269
|
});
|
|
8212
8270
|
}
|
|
@@ -8238,10 +8296,10 @@ class McpManager {
|
|
|
8238
8296
|
async toolsFor(servers, budgetMs) {
|
|
8239
8297
|
const results = await Promise.all(
|
|
8240
8298
|
servers.map((server) => {
|
|
8241
|
-
const
|
|
8242
|
-
if (budgetMs === void 0) return
|
|
8299
|
+
const pending2 = this.connectionFor(server);
|
|
8300
|
+
if (budgetMs === void 0) return pending2;
|
|
8243
8301
|
return Promise.race([
|
|
8244
|
-
|
|
8302
|
+
pending2,
|
|
8245
8303
|
new Promise((resolve) => setTimeout(() => resolve(null), budgetMs))
|
|
8246
8304
|
]);
|
|
8247
8305
|
})
|
|
@@ -8280,7 +8338,7 @@ class McpManager {
|
|
|
8280
8338
|
})) : []
|
|
8281
8339
|
);
|
|
8282
8340
|
}
|
|
8283
|
-
/** 插件经 Main 调宿主 MCP
|
|
8341
|
+
/** 插件经 Main 调宿主 MCP 工具;中止让本次等待立即失败,已发出的调用经 signal 取消 */
|
|
8284
8342
|
async callPluginTool(servers, serverName, toolName, args, signal) {
|
|
8285
8343
|
const server = servers.find((s) => s.name === serverName);
|
|
8286
8344
|
if (!server) throw new Error(`MCP server not found: ${serverName}`);
|
|
@@ -8349,10 +8407,10 @@ class McpManager {
|
|
|
8349
8407
|
const failed = this.failedUntil.get(key);
|
|
8350
8408
|
if (failed && failed.fingerprint !== fingerprint2) this.failedUntil.delete(key);
|
|
8351
8409
|
else if (failed && Date.now() < failed.until) return Promise.resolve(null);
|
|
8352
|
-
let
|
|
8353
|
-
if (
|
|
8354
|
-
if (!
|
|
8355
|
-
|
|
8410
|
+
let pending2 = this.connections.get(key);
|
|
8411
|
+
if (pending2) pending2 = this.applyDispatchedTokens(key, server, pending2);
|
|
8412
|
+
if (!pending2) {
|
|
8413
|
+
pending2 = this.connect(server).catch((error) => {
|
|
8356
8414
|
console.error(`[mcp] connect failed for "${server.name}":`, error);
|
|
8357
8415
|
const challenge = this.scopeChallenges.get(key);
|
|
8358
8416
|
const unauthorized = Boolean(challenge) || isUnauthorized(error);
|
|
@@ -8370,15 +8428,15 @@ class McpManager {
|
|
|
8370
8428
|
});
|
|
8371
8429
|
return null;
|
|
8372
8430
|
});
|
|
8373
|
-
this.connections.set(key,
|
|
8431
|
+
this.connections.set(key, pending2);
|
|
8374
8432
|
}
|
|
8375
8433
|
this.dispatched.set(key, fingerprint2);
|
|
8376
|
-
return
|
|
8434
|
+
return pending2;
|
|
8377
8435
|
}
|
|
8378
8436
|
reconnect(server, stale) {
|
|
8379
8437
|
const key = connectionKey(server);
|
|
8380
|
-
const
|
|
8381
|
-
if (
|
|
8438
|
+
const pending2 = this.reconnecting.get(key);
|
|
8439
|
+
if (pending2) return pending2;
|
|
8382
8440
|
const attempt = this.doReconnect(key, server, stale).finally(() => {
|
|
8383
8441
|
this.reconnecting.delete(key);
|
|
8384
8442
|
});
|
|
@@ -8402,20 +8460,20 @@ class McpManager {
|
|
|
8402
8460
|
* 捕获着这个 client,为换 token 重建连接等于弄坏它们;只有撤销(不再下发凭据)才下线重建。
|
|
8403
8461
|
* 指纹与上次相同则是回传旧凭据,忽略。
|
|
8404
8462
|
*/
|
|
8405
|
-
applyDispatchedTokens(key, server,
|
|
8463
|
+
applyDispatchedTokens(key, server, pending2) {
|
|
8406
8464
|
const previous = this.dispatched.get(key);
|
|
8407
8465
|
const fingerprint2 = oauthFingerprint(server.oauth);
|
|
8408
|
-
if (previous === void 0 || previous === fingerprint2) return
|
|
8466
|
+
if (previous === void 0 || previous === fingerprint2) return pending2;
|
|
8409
8467
|
if (!server.oauth) {
|
|
8410
8468
|
this.connections.delete(key);
|
|
8411
8469
|
this.failedUntil.delete(key);
|
|
8412
|
-
void
|
|
8470
|
+
void pending2.then((connection) => connection?.client.close().catch(() => {
|
|
8413
8471
|
}));
|
|
8414
8472
|
return void 0;
|
|
8415
8473
|
}
|
|
8416
8474
|
this.failedUntil.delete(key);
|
|
8417
8475
|
this.oauth.get(key)?.offer(server.oauth);
|
|
8418
|
-
return
|
|
8476
|
+
return pending2;
|
|
8419
8477
|
}
|
|
8420
8478
|
/** worker 不能开浏览器:把挑战交给 Main,由用户重新授权时在已授予 scope 上追加 */
|
|
8421
8479
|
reportScopeChallenge(server, challenge) {
|
|
@@ -8515,19 +8573,26 @@ class McpManager {
|
|
|
8515
8573
|
}
|
|
8516
8574
|
toToolDefinition(client, server, tool, name, callTimeoutMs) {
|
|
8517
8575
|
let active = client;
|
|
8518
|
-
const invoke = (target, params) =>
|
|
8519
|
-
|
|
8520
|
-
|
|
8521
|
-
|
|
8522
|
-
|
|
8523
|
-
|
|
8524
|
-
|
|
8525
|
-
|
|
8526
|
-
|
|
8527
|
-
|
|
8528
|
-
|
|
8529
|
-
|
|
8530
|
-
|
|
8576
|
+
const invoke = (target, params, signal) => {
|
|
8577
|
+
const call = new AbortController();
|
|
8578
|
+
const forward = () => call.abort(signal?.reason);
|
|
8579
|
+
if (signal?.aborted) forward();
|
|
8580
|
+
else signal?.addEventListener("abort", forward, { once: true });
|
|
8581
|
+
return withTimeout(
|
|
8582
|
+
// SDK 内部请求默认 60s 超时,必须显式传入,否则外层 withTimeout 永远轮不到
|
|
8583
|
+
target.callTool(
|
|
8584
|
+
{
|
|
8585
|
+
name: tool.name,
|
|
8586
|
+
arguments: params ?? {}
|
|
8587
|
+
},
|
|
8588
|
+
void 0,
|
|
8589
|
+
{ timeout: callTimeoutMs, signal: call.signal }
|
|
8590
|
+
),
|
|
8591
|
+
callTimeoutMs,
|
|
8592
|
+
`callTool ${name}`,
|
|
8593
|
+
call.signal
|
|
8594
|
+
).finally(() => signal?.removeEventListener("abort", forward));
|
|
8595
|
+
};
|
|
8531
8596
|
const annotations = toAnnotations(tool.annotations);
|
|
8532
8597
|
return {
|
|
8533
8598
|
name,
|
|
@@ -8541,25 +8606,25 @@ class McpManager {
|
|
|
8541
8606
|
description: server.description || server.name
|
|
8542
8607
|
},
|
|
8543
8608
|
...annotations ? { annotations } : {},
|
|
8544
|
-
execute: async (_toolCallId, params) => {
|
|
8609
|
+
execute: async (_toolCallId, params, signal) => {
|
|
8545
8610
|
try {
|
|
8546
|
-
return mapToolResult(await invoke(active, params), name);
|
|
8611
|
+
return mapToolResult(await invoke(active, params, signal), name);
|
|
8547
8612
|
} catch (error) {
|
|
8548
8613
|
if (!isRetriableMcpConnectionError(error)) throw error;
|
|
8549
8614
|
const next = await this.reconnect(server, active);
|
|
8550
8615
|
if (!next) throw error;
|
|
8551
8616
|
active = next.client;
|
|
8552
|
-
return mapToolResult(await invoke(active, params), name);
|
|
8617
|
+
return mapToolResult(await invoke(active, params, signal), name);
|
|
8553
8618
|
}
|
|
8554
8619
|
}
|
|
8555
8620
|
};
|
|
8556
8621
|
}
|
|
8557
8622
|
/** worker 退出前断开全部连接(stdio 子进程随之终止) */
|
|
8558
8623
|
async closeAll() {
|
|
8559
|
-
const
|
|
8624
|
+
const pending2 = [...this.connections.values()];
|
|
8560
8625
|
this.connections.clear();
|
|
8561
8626
|
await Promise.allSettled(
|
|
8562
|
-
|
|
8627
|
+
pending2.map(async (entry) => {
|
|
8563
8628
|
const connection = await entry;
|
|
8564
8629
|
await connection?.client.close();
|
|
8565
8630
|
})
|
|
@@ -10066,7 +10131,8 @@ const SECRET_RULES = [
|
|
|
10066
10131
|
{
|
|
10067
10132
|
kind: "PASSWORD",
|
|
10068
10133
|
rule: "url",
|
|
10069
|
-
|
|
10134
|
+
// 先认 `:` 再回看 scheme:若从 scheme 起匹配,长串 `a.a.…` 的每个词首都会扫到串尾,二次复杂度
|
|
10135
|
+
re: /:(?<=\b[a-z][a-z0-9+.-]*:)\/\/[^\s/:@]+:([^\s/@]+)@/dgi,
|
|
10070
10136
|
group: 1,
|
|
10071
10137
|
keep: 0,
|
|
10072
10138
|
validate: (v) => !SKIP_VALUE.test(v) && !PLACEHOLDER_VALUE.test(v)
|
|
@@ -10074,7 +10140,9 @@ const SECRET_RULES = [
|
|
|
10074
10140
|
{
|
|
10075
10141
|
kind: kvKind,
|
|
10076
10142
|
rule: "kv",
|
|
10077
|
-
|
|
10143
|
+
// 负回看跳过“更早的词首经 `xx_`/`xx-` 前缀能走到”的起点:这里能匹配的,那个词首必先匹配到;
|
|
10144
|
+
// 否则长串 `a-a-…` 的每个词首都要把前缀重扫到串尾,二次复杂度
|
|
10145
|
+
re: /\b(?<!(?:^|[^A-Za-z0-9_])(?:[A-Za-z0-9]+[_-])+?)(?:[A-Za-z0-9]+[_-])*(api[_-]?key|secret(?:[_-]?key)?|access[_-]?token|refresh[_-]?token|auth[_-]?token|token|passwd|password|pwd|client[_-]?secret|private[_-]?key)["']?\s*[:=]\s*(?:"((?:\\.|[^"\\\n])*)"|'((?:\\.|[^'\\\n])*)'|([^\s"',;{}[\]]+))/dgi,
|
|
10078
10146
|
group: -1,
|
|
10079
10147
|
keep: 0,
|
|
10080
10148
|
validate: kvValue
|
|
@@ -11749,7 +11817,7 @@ async function prepareCommand(command2, signal, options, shell) {
|
|
|
11749
11817
|
return immediate(command2, withReason("bypassed", command2, "unsafe-wrapper"));
|
|
11750
11818
|
}
|
|
11751
11819
|
}
|
|
11752
|
-
const
|
|
11820
|
+
const pending2 = {
|
|
11753
11821
|
status: "pending",
|
|
11754
11822
|
originalCommand: command2,
|
|
11755
11823
|
rewrittenCommand
|
|
@@ -11790,7 +11858,7 @@ async function prepareCommand(command2, signal, options, shell) {
|
|
|
11790
11858
|
};
|
|
11791
11859
|
return {
|
|
11792
11860
|
command: runtimeCommand(rewrittenCommand, options.binaryPath, paths, shell),
|
|
11793
|
-
details: details(
|
|
11861
|
+
details: details(pending2),
|
|
11794
11862
|
finalize
|
|
11795
11863
|
};
|
|
11796
11864
|
}
|
|
@@ -11850,9 +11918,9 @@ class SystemReminderRegistry {
|
|
|
11850
11918
|
const blocks = [];
|
|
11851
11919
|
for (const provider of ranked) {
|
|
11852
11920
|
try {
|
|
11853
|
-
const
|
|
11854
|
-
if (Array.isArray(
|
|
11855
|
-
for (const block of
|
|
11921
|
+
const pending2 = provider.take();
|
|
11922
|
+
if (Array.isArray(pending2)) {
|
|
11923
|
+
for (const block of pending2) {
|
|
11856
11924
|
if (typeof block === "string" && block.trim()) blocks.push(block);
|
|
11857
11925
|
}
|
|
11858
11926
|
}
|
|
@@ -11881,9 +11949,9 @@ ${firstText.text}`;
|
|
|
11881
11949
|
return { ...result, content };
|
|
11882
11950
|
}
|
|
11883
11951
|
function withPendingReminders(result, registry2) {
|
|
11884
|
-
const
|
|
11885
|
-
if (
|
|
11886
|
-
const tagged =
|
|
11952
|
+
const pending2 = registry2.takePending();
|
|
11953
|
+
if (pending2.length === 0) return void 0;
|
|
11954
|
+
const tagged = pending2.map(
|
|
11887
11955
|
(block) => block.includes("<system-reminder>") || block.includes("<background-task-update>") ? block : systemReminderBlock(block)
|
|
11888
11956
|
);
|
|
11889
11957
|
return prependToolText(result, tagged.join("\n\n"));
|
|
@@ -12197,11 +12265,12 @@ function buildRemoteFindScript(pattern, cwd, options) {
|
|
|
12197
12265
|
const matcher = pattern.includes("/") ? `-path ${shellQuote(`${cwd}/${pattern.replaceAll("**/", "*").replaceAll("**", "*")}`)}` : `-name ${shellQuote(pattern)}`;
|
|
12198
12266
|
return `find ${shellQuote(cwd)} ${prunes} -type f ${matcher} -print 2>/dev/null | head -n ${options.limit}`;
|
|
12199
12267
|
}
|
|
12268
|
+
const REMOTE_GREP_DEFAULT_LIMIT = 100;
|
|
12200
12269
|
function buildRemoteGrepScript(params, cwd, engine) {
|
|
12201
12270
|
const target = shellQuote(
|
|
12202
12271
|
params.path ? params.path.startsWith("/") ? params.path : `${cwd}/${params.path}` : cwd
|
|
12203
12272
|
);
|
|
12204
|
-
const limit = params.limit ??
|
|
12273
|
+
const limit = params.limit ?? REMOTE_GREP_DEFAULT_LIMIT;
|
|
12205
12274
|
const parts = [];
|
|
12206
12275
|
if (engine === "rg") {
|
|
12207
12276
|
parts.push("rg -n --no-heading --color never");
|
|
@@ -12219,7 +12288,7 @@ function buildRemoteGrepScript(params, cwd, engine) {
|
|
|
12219
12288
|
parts.push("--exclude-dir=node_modules --exclude-dir=.git");
|
|
12220
12289
|
}
|
|
12221
12290
|
parts.push("--", shellQuote(params.pattern), target);
|
|
12222
|
-
return `${parts.join(" ")}
|
|
12291
|
+
return `${parts.join(" ")} | head -n ${limit}; exit "\${PIPESTATUS[0]}"`;
|
|
12223
12292
|
}
|
|
12224
12293
|
function createRemoteOperations(executor) {
|
|
12225
12294
|
const readFile2 = async (absolutePath) => {
|
|
@@ -12302,6 +12371,13 @@ function createRemoteOperations(executor) {
|
|
|
12302
12371
|
}
|
|
12303
12372
|
};
|
|
12304
12373
|
}
|
|
12374
|
+
const STDERR_SUMMARY_CHARS = 2e3;
|
|
12375
|
+
function stderrSummary(stderr) {
|
|
12376
|
+
const trimmed = stderr.trim();
|
|
12377
|
+
if (trimmed.length <= STDERR_SUMMARY_CHARS) return trimmed;
|
|
12378
|
+
return `${trimmed.slice(0, STDERR_SUMMARY_CHARS)}
|
|
12379
|
+
…(stderr truncated)`;
|
|
12380
|
+
}
|
|
12305
12381
|
function createRemoteGrepToolDefinition(cwd, executor) {
|
|
12306
12382
|
const base = createGrepToolDefinition(cwd);
|
|
12307
12383
|
let enginePromise;
|
|
@@ -12313,13 +12389,23 @@ function createRemoteGrepToolDefinition(cwd, executor) {
|
|
|
12313
12389
|
...base,
|
|
12314
12390
|
async execute(_toolCallId, params, signal, _onUpdate, _ctx) {
|
|
12315
12391
|
const engine = await detectEngine();
|
|
12316
|
-
const
|
|
12392
|
+
const grepParams = params;
|
|
12393
|
+
const script = buildRemoteGrepScript(grepParams, cwd, engine);
|
|
12317
12394
|
const result = await executor.exec(script, { signal });
|
|
12318
|
-
|
|
12319
|
-
|
|
12320
|
-
}
|
|
12395
|
+
const lines = result.stdout.match(/\n/g)?.length ?? 0;
|
|
12396
|
+
const cutByHead = lines >= (grepParams.limit ?? REMOTE_GREP_DEFAULT_LIMIT);
|
|
12321
12397
|
const text2 = result.stdout.replace(/\n+$/, "");
|
|
12322
|
-
|
|
12398
|
+
const partial = result.code === 2 && text2.length > 0 && !cutByHead;
|
|
12399
|
+
if (result.code > 1 && !cutByHead && !partial) {
|
|
12400
|
+
const summary = stderrSummary(result.stderr);
|
|
12401
|
+
throw new Error(summary || `remote grep failed (code ${result.code})`);
|
|
12402
|
+
}
|
|
12403
|
+
const warning = partial ? stderrSummary(result.stderr) : "";
|
|
12404
|
+
const body = warning ? `${text2}
|
|
12405
|
+
|
|
12406
|
+
[remote grep: some paths were unreadable]
|
|
12407
|
+
${warning}` : text2 || "No matches found";
|
|
12408
|
+
return { content: [{ type: "text", text: body }], details: void 0 };
|
|
12323
12409
|
}
|
|
12324
12410
|
};
|
|
12325
12411
|
}
|
|
@@ -12714,7 +12800,7 @@ class ToolOutputBudget {
|
|
|
12714
12800
|
}
|
|
12715
12801
|
read(uri) {
|
|
12716
12802
|
const id = parseArtifactUri(uri);
|
|
12717
|
-
if (!id) return void 0;
|
|
12803
|
+
if (!id || safeArtifactId(id) !== id) return void 0;
|
|
12718
12804
|
try {
|
|
12719
12805
|
return readFileSync(path.join(this.rootDir, `${id}.txt`), "utf8");
|
|
12720
12806
|
} catch {
|
|
@@ -12940,210 +13026,6 @@ function createDelegationTools(invoker, options = {}) {
|
|
|
12940
13026
|
)
|
|
12941
13027
|
];
|
|
12942
13028
|
}
|
|
12943
|
-
const isCapabilityId$1 = (value) => Object.hasOwn(CAPABILITY_CATALOG, value);
|
|
12944
|
-
class EnsoAppInvoker {
|
|
12945
|
-
constructor(child, getTurnId, emit) {
|
|
12946
|
-
this.child = child;
|
|
12947
|
-
this.getTurnId = getTurnId;
|
|
12948
|
-
this.emit = emit;
|
|
12949
|
-
}
|
|
12950
|
-
child;
|
|
12951
|
-
getTurnId;
|
|
12952
|
-
emit;
|
|
12953
|
-
pending = /* @__PURE__ */ new Map();
|
|
12954
|
-
invoke(capabilityId, params, signal) {
|
|
12955
|
-
if (!isCapabilityId$1(capabilityId)) {
|
|
12956
|
-
return Promise.reject(new Error(`unknown capability: ${capabilityId}`));
|
|
12957
|
-
}
|
|
12958
|
-
const spec = CAPABILITY_CATALOG[capabilityId];
|
|
12959
|
-
if (spec.execution.kind !== "executable") {
|
|
12960
|
-
return Promise.reject(
|
|
12961
|
-
new Error(
|
|
12962
|
-
`capability unavailable: ${spec.execution.reason} Suggested action: ${spec.execution.suggestedAction}`
|
|
12963
|
-
)
|
|
12964
|
-
);
|
|
12965
|
-
}
|
|
12966
|
-
const turnId = this.getTurnId()?.trim();
|
|
12967
|
-
if (!turnId) return Promise.reject(new Error("enso_app requires an active child turn"));
|
|
12968
|
-
if (signal?.aborted) {
|
|
12969
|
-
return Promise.reject(new Error("Enso capability invocation aborted"));
|
|
12970
|
-
}
|
|
12971
|
-
const requestId = randomUUID();
|
|
12972
|
-
const { promise, resolve, reject } = Promise.withResolvers();
|
|
12973
|
-
const settle = (result) => {
|
|
12974
|
-
if (!this.pending.delete(requestId)) return;
|
|
12975
|
-
signal?.removeEventListener("abort", onAbort);
|
|
12976
|
-
if (result instanceof Error) reject(result);
|
|
12977
|
-
else resolve(result);
|
|
12978
|
-
};
|
|
12979
|
-
const onAbort = () => settle(new Error("Enso capability invocation aborted"));
|
|
12980
|
-
this.pending.set(requestId, {
|
|
12981
|
-
turnId,
|
|
12982
|
-
resolve: (result) => settle(result),
|
|
12983
|
-
reject: (error) => settle(error)
|
|
12984
|
-
});
|
|
12985
|
-
signal?.addEventListener("abort", onAbort, { once: true });
|
|
12986
|
-
try {
|
|
12987
|
-
this.emit({ child: this.child, turnId, requestId, capabilityId, params });
|
|
12988
|
-
} catch (error) {
|
|
12989
|
-
settle(error instanceof Error ? error : new Error(String(error)));
|
|
12990
|
-
}
|
|
12991
|
-
return promise;
|
|
12992
|
-
}
|
|
12993
|
-
resolve(turnId, requestId, envelope) {
|
|
12994
|
-
const entry = this.pending.get(requestId);
|
|
12995
|
-
if (!entry) return { ok: false, error: "unknown request" };
|
|
12996
|
-
if (entry.turnId !== turnId) {
|
|
12997
|
-
entry.reject(new Error("Enso capability result turn mismatch"));
|
|
12998
|
-
return { ok: false, error: "turn mismatch" };
|
|
12999
|
-
}
|
|
13000
|
-
entry.resolve(envelope.modelResult);
|
|
13001
|
-
return { ok: true };
|
|
13002
|
-
}
|
|
13003
|
-
cancelAll(reason = "Enso capability invocation cancelled") {
|
|
13004
|
-
for (const entry of [...this.pending.values()]) entry.reject(new Error(reason));
|
|
13005
|
-
}
|
|
13006
|
-
get pendingCount() {
|
|
13007
|
-
return this.pending.size;
|
|
13008
|
-
}
|
|
13009
|
-
}
|
|
13010
|
-
function normalizeCapabilityParams(value) {
|
|
13011
|
-
if (typeof value !== "string") return value;
|
|
13012
|
-
const trimmed = value.trim();
|
|
13013
|
-
if (!trimmed.startsWith("{")) return value;
|
|
13014
|
-
try {
|
|
13015
|
-
const parsed = JSON.parse(trimmed);
|
|
13016
|
-
return parsed && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : value;
|
|
13017
|
-
} catch {
|
|
13018
|
-
return value;
|
|
13019
|
-
}
|
|
13020
|
-
}
|
|
13021
|
-
function createEnsoAppTool(invoker) {
|
|
13022
|
-
return {
|
|
13023
|
-
name: "enso_app",
|
|
13024
|
-
label: "Enso app",
|
|
13025
|
-
// 注:normalizeCapabilityParams 只做形态归一(字符串化 JSON → 对象),
|
|
13026
|
-
// 不放宽任何校验:真正的参数合法性仍由 Main gateway 按 inputSchema 判定。
|
|
13027
|
-
description: "Invoke one executable product capability through the protected Main gateway. Parameters are validated and target context is bound outside this worker.",
|
|
13028
|
-
promptSnippet: "enso_app: invoke only catalog capabilities marked executable; never invent capability ids or parameters",
|
|
13029
|
-
parameters: {
|
|
13030
|
-
type: "object",
|
|
13031
|
-
properties: {
|
|
13032
|
-
capability_id: { type: "string", description: "Public executable capability id" },
|
|
13033
|
-
// 必须声明 type:不声明时不同模型会自行猜测(实测 Claude 传 JSON 字符串、
|
|
13034
|
-
// Grok 传对象),字符串会被能力 inputSchema 判 "$ must be an object" 而全部失败。
|
|
13035
|
-
params: {
|
|
13036
|
-
type: "object",
|
|
13037
|
-
description: "Capability parameters matching its public input schema"
|
|
13038
|
-
}
|
|
13039
|
-
},
|
|
13040
|
-
required: ["capability_id", "params"],
|
|
13041
|
-
additionalProperties: false
|
|
13042
|
-
},
|
|
13043
|
-
// schema 校验之前先归一:声明 params 为 object 后,字符串化载荷会在校验阶段就被拦,
|
|
13044
|
-
// execute 里再处理就晚了。
|
|
13045
|
-
prepareArguments: ((args) => {
|
|
13046
|
-
if (!args || typeof args !== "object") return args;
|
|
13047
|
-
const record = args;
|
|
13048
|
-
const normalized = normalizeCapabilityParams(record.params);
|
|
13049
|
-
return normalized === record.params ? record : { ...record, params: normalized };
|
|
13050
|
-
}),
|
|
13051
|
-
async execute(_toolCallId, params, signal) {
|
|
13052
|
-
const { capability_id: capabilityId, params: capabilityParams } = params;
|
|
13053
|
-
if (!capabilityId?.trim()) throw new Error("capability_id is required");
|
|
13054
|
-
const result = await invoker.invoke(
|
|
13055
|
-
capabilityId.trim(),
|
|
13056
|
-
normalizeCapabilityParams(capabilityParams),
|
|
13057
|
-
signal
|
|
13058
|
-
);
|
|
13059
|
-
return {
|
|
13060
|
-
content: [{ type: "text", text: JSON.stringify(result) }],
|
|
13061
|
-
details: void 0
|
|
13062
|
-
};
|
|
13063
|
-
}
|
|
13064
|
-
};
|
|
13065
|
-
}
|
|
13066
|
-
const isCapabilityId = (value) => Object.hasOwn(CAPABILITY_CATALOG, value);
|
|
13067
|
-
function describeEnsoCapability(capabilityId) {
|
|
13068
|
-
if (!isCapabilityId(capabilityId)) return void 0;
|
|
13069
|
-
const spec = CAPABILITY_CATALOG[capabilityId];
|
|
13070
|
-
return {
|
|
13071
|
-
id: spec.id,
|
|
13072
|
-
label: PRODUCT_SURFACE_INVENTORY[capabilityId].label,
|
|
13073
|
-
domain: spec.domain,
|
|
13074
|
-
description: spec.description,
|
|
13075
|
-
inputSchema: spec.inputSchema,
|
|
13076
|
-
...spec.resultSchema ? { resultSchema: spec.resultSchema } : {},
|
|
13077
|
-
risk: spec.risk,
|
|
13078
|
-
targetContext: spec.targetContext,
|
|
13079
|
-
availability: spec.availability,
|
|
13080
|
-
execution: spec.execution.kind === "executable" ? { kind: "executable" } : {
|
|
13081
|
-
kind: "known-unavailable",
|
|
13082
|
-
reason: spec.execution.reason,
|
|
13083
|
-
suggestedAction: spec.execution.suggestedAction
|
|
13084
|
-
}
|
|
13085
|
-
};
|
|
13086
|
-
}
|
|
13087
|
-
function listEnsoCapabilities() {
|
|
13088
|
-
return Object.keys(CAPABILITY_CATALOG).sort().flatMap((capabilityId) => {
|
|
13089
|
-
if (!isCapabilityId(capabilityId)) return [];
|
|
13090
|
-
const spec = CAPABILITY_CATALOG[capabilityId];
|
|
13091
|
-
return [
|
|
13092
|
-
{
|
|
13093
|
-
id: spec.id,
|
|
13094
|
-
label: PRODUCT_SURFACE_INVENTORY[capabilityId].label,
|
|
13095
|
-
domain: spec.domain,
|
|
13096
|
-
risk: spec.risk,
|
|
13097
|
-
targetContext: spec.targetContext,
|
|
13098
|
-
availability: spec.availability,
|
|
13099
|
-
execution: spec.execution.kind === "executable" ? { kind: "executable" } : { kind: "known-unavailable", reason: spec.execution.reason }
|
|
13100
|
-
}
|
|
13101
|
-
];
|
|
13102
|
-
});
|
|
13103
|
-
}
|
|
13104
|
-
function createEnsoCapabilitiesTool() {
|
|
13105
|
-
return {
|
|
13106
|
-
name: "enso_capabilities",
|
|
13107
|
-
label: "Enso capabilities",
|
|
13108
|
-
description: "List compact EnsoCode capability summaries or describe one full public contract. Describe returns schemas and details without internal ids or secrets.",
|
|
13109
|
-
promptSnippet: "enso_capabilities: list when the catalog is not in context or the user asks about capabilities; describe before using an unclear capability with enso_app",
|
|
13110
|
-
parameters: {
|
|
13111
|
-
type: "object",
|
|
13112
|
-
properties: {
|
|
13113
|
-
operation: {
|
|
13114
|
-
type: "string",
|
|
13115
|
-
enum: ["list", "describe"],
|
|
13116
|
-
description: "list: all capabilities; describe: one capability contract"
|
|
13117
|
-
},
|
|
13118
|
-
capability_id: {
|
|
13119
|
-
type: "string",
|
|
13120
|
-
description: "Public capability id; required for describe"
|
|
13121
|
-
}
|
|
13122
|
-
},
|
|
13123
|
-
required: ["operation"],
|
|
13124
|
-
additionalProperties: false
|
|
13125
|
-
},
|
|
13126
|
-
async execute(_toolCallId, params) {
|
|
13127
|
-
const { operation, capability_id: capabilityId } = params;
|
|
13128
|
-
if (operation === "list") {
|
|
13129
|
-
return {
|
|
13130
|
-
content: [{ type: "text", text: JSON.stringify(listEnsoCapabilities()) }],
|
|
13131
|
-
details: void 0
|
|
13132
|
-
};
|
|
13133
|
-
}
|
|
13134
|
-
if (operation !== "describe") {
|
|
13135
|
-
throw new Error('operation must be "list" or "describe"');
|
|
13136
|
-
}
|
|
13137
|
-
if (!capabilityId?.trim()) throw new Error("describe requires capability_id");
|
|
13138
|
-
const descriptor = describeEnsoCapability(capabilityId.trim());
|
|
13139
|
-
if (!descriptor) throw new Error(`unknown capability: ${capabilityId.trim()}`);
|
|
13140
|
-
return {
|
|
13141
|
-
content: [{ type: "text", text: JSON.stringify(descriptor) }],
|
|
13142
|
-
details: void 0
|
|
13143
|
-
};
|
|
13144
|
-
}
|
|
13145
|
-
};
|
|
13146
|
-
}
|
|
13147
13029
|
const MAX_LIMIT = 100;
|
|
13148
13030
|
const ALIASES$2 = {
|
|
13149
13031
|
before: "beforeSeq",
|
|
@@ -13870,6 +13752,7 @@ function createPluginTools(descriptors, invoker) {
|
|
|
13870
13752
|
label: descriptor.name,
|
|
13871
13753
|
description: descriptor.description,
|
|
13872
13754
|
parameters: descriptor.parameters,
|
|
13755
|
+
...descriptor.readOnly ? { annotations: { readOnlyHint: true } } : {},
|
|
13873
13756
|
async execute(_toolCallId, params, signal, onUpdate) {
|
|
13874
13757
|
const result = await invoker.invoke(descriptor.name, params ?? {}, signal, {
|
|
13875
13758
|
timeoutMs: pluginToolLocalTimeoutMs(descriptor.timeoutMs),
|
|
@@ -14128,6 +14011,200 @@ function createSendImageTool(invoker, cwd, confirmOutside) {
|
|
|
14128
14011
|
}
|
|
14129
14012
|
};
|
|
14130
14013
|
}
|
|
14014
|
+
const READ_ONLY_PROGRAMS = /* @__PURE__ */ new Set([
|
|
14015
|
+
"ls",
|
|
14016
|
+
"tree",
|
|
14017
|
+
"pwd",
|
|
14018
|
+
"cd",
|
|
14019
|
+
"cat",
|
|
14020
|
+
"bat",
|
|
14021
|
+
"head",
|
|
14022
|
+
"tail",
|
|
14023
|
+
"wc",
|
|
14024
|
+
"nl",
|
|
14025
|
+
"tac",
|
|
14026
|
+
"less",
|
|
14027
|
+
"more",
|
|
14028
|
+
"rg",
|
|
14029
|
+
"grep",
|
|
14030
|
+
"egrep",
|
|
14031
|
+
"fgrep",
|
|
14032
|
+
"ag",
|
|
14033
|
+
"find",
|
|
14034
|
+
"fd",
|
|
14035
|
+
"fdfind",
|
|
14036
|
+
"which",
|
|
14037
|
+
"type",
|
|
14038
|
+
"file",
|
|
14039
|
+
"stat",
|
|
14040
|
+
"du",
|
|
14041
|
+
"df",
|
|
14042
|
+
"sort",
|
|
14043
|
+
"uniq",
|
|
14044
|
+
"cut",
|
|
14045
|
+
"tr",
|
|
14046
|
+
"awk",
|
|
14047
|
+
"sed",
|
|
14048
|
+
"diff",
|
|
14049
|
+
"jq",
|
|
14050
|
+
"yq",
|
|
14051
|
+
"echo",
|
|
14052
|
+
"printf",
|
|
14053
|
+
"basename",
|
|
14054
|
+
"dirname",
|
|
14055
|
+
"realpath",
|
|
14056
|
+
"readlink",
|
|
14057
|
+
"printenv",
|
|
14058
|
+
"date",
|
|
14059
|
+
"whoami",
|
|
14060
|
+
"uname",
|
|
14061
|
+
"column",
|
|
14062
|
+
"true",
|
|
14063
|
+
"test",
|
|
14064
|
+
"[",
|
|
14065
|
+
"git"
|
|
14066
|
+
]);
|
|
14067
|
+
const GIT_READ_SUBCOMMANDS = /* @__PURE__ */ new Set([
|
|
14068
|
+
"status",
|
|
14069
|
+
"log",
|
|
14070
|
+
"diff",
|
|
14071
|
+
"show",
|
|
14072
|
+
"blame",
|
|
14073
|
+
"grep",
|
|
14074
|
+
"ls-files",
|
|
14075
|
+
"ls-tree",
|
|
14076
|
+
"rev-parse",
|
|
14077
|
+
"describe",
|
|
14078
|
+
"shortlog",
|
|
14079
|
+
"reflog",
|
|
14080
|
+
"cat-file",
|
|
14081
|
+
"name-rev",
|
|
14082
|
+
"remote",
|
|
14083
|
+
"config",
|
|
14084
|
+
"branch",
|
|
14085
|
+
"tag"
|
|
14086
|
+
]);
|
|
14087
|
+
const WRITE_FLAGS = {
|
|
14088
|
+
sed: /^(-[a-zA-Z]*i|--in-place)|\/[a-zA-Z]*e[a-zA-Z]*['"]?$|^['"]?e\b/,
|
|
14089
|
+
awk: /^-[a-zA-Z]*[fiE]|^--(file|include|exec)/,
|
|
14090
|
+
// -s/--split-exp 按表达式把结果写成多个文件
|
|
14091
|
+
yq: /^-[a-zA-Z]*[is]|^--(inplace|split-exp)/,
|
|
14092
|
+
sort: /^-[a-zA-Z]*o|^--(output|compress-program)/,
|
|
14093
|
+
find: /^-(exec|execdir|ok|okdir|delete|fprint|fprintf|fprint0|fls)$/,
|
|
14094
|
+
git: /^--(output|ext-diff|textconv|filters|exec-path)/,
|
|
14095
|
+
rg: /^--pre($|=)/,
|
|
14096
|
+
fd: /^-[a-zA-Z0-9]*[xX]|^--exec/,
|
|
14097
|
+
fdfind: /^-[a-zA-Z0-9]*[xX]|^--exec/,
|
|
14098
|
+
ag: /^--pager/,
|
|
14099
|
+
bat: /^--pager/,
|
|
14100
|
+
tree: /^-o$|^--output/,
|
|
14101
|
+
file: /^-[a-zA-Z]*C/,
|
|
14102
|
+
date: /^(-s|--set)/
|
|
14103
|
+
};
|
|
14104
|
+
const GIT_WRITE_ARGS = {
|
|
14105
|
+
branch: /^-(d|D|m|M|c|C|u|f|-delete|-move|-copy|-set-upstream-to|-unset-upstream|-force)/,
|
|
14106
|
+
tag: /^-(a|s|d|f|m|F|-annotate|-sign|-delete|-force|-message)/,
|
|
14107
|
+
config: /^(-e|--edit|--unset|--unset-all|--add|--replace-all|--rename-section|--remove-section)$/,
|
|
14108
|
+
remote: /^(add|remove|rm|rename|set-url|set-head|set-branches|prune|update)$/,
|
|
14109
|
+
reflog: /^(expire|delete)$/,
|
|
14110
|
+
grep: /^(-O|--open-files-in-pager)/
|
|
14111
|
+
};
|
|
14112
|
+
const SYSTEM_BIN_PATH = /^\/(usr\/(local\/)?)?s?bin\/[^/]+$|^\/opt\/homebrew\/bin\/[^/]+$/;
|
|
14113
|
+
const GIT_SAFE_GLOBAL_FLAGS = /* @__PURE__ */ new Set(["--no-pager", "-P", "--no-optional-locks"]);
|
|
14114
|
+
const SAFE_ENV = /^(LC_[A-Z_]+|LANG|LANGUAGE|TZ|NO_COLOR|FORCE_COLOR|CLICOLOR(_FORCE)?|COLUMNS|TERM)=/;
|
|
14115
|
+
const VERSION_ONLY_PROGRAMS = /* @__PURE__ */ new Set([
|
|
14116
|
+
"node",
|
|
14117
|
+
"npm",
|
|
14118
|
+
"pnpm",
|
|
14119
|
+
"yarn",
|
|
14120
|
+
"bun",
|
|
14121
|
+
"deno",
|
|
14122
|
+
"python",
|
|
14123
|
+
"python3",
|
|
14124
|
+
"pip",
|
|
14125
|
+
"pip3",
|
|
14126
|
+
"ruby",
|
|
14127
|
+
"go",
|
|
14128
|
+
"cargo",
|
|
14129
|
+
"rustc",
|
|
14130
|
+
"java",
|
|
14131
|
+
"javac"
|
|
14132
|
+
]);
|
|
14133
|
+
const SED_PRINT_SCRIPT = /^['"]?((\d+|\$)(,(\d+|\$))?|\/[^/]*\/)p['"]?$/;
|
|
14134
|
+
const SED_SAFE_FLAGS = /* @__PURE__ */ new Set(["-n", "-E", "-r", "--quiet", "--silent"]);
|
|
14135
|
+
function splitEnvPrefix(segment) {
|
|
14136
|
+
const tokens = segment.trim().split(/\s+/);
|
|
14137
|
+
let i = 0;
|
|
14138
|
+
while (i < tokens.length && /^[A-Za-z_][A-Za-z0-9_]*=/.test(tokens[i])) i += 1;
|
|
14139
|
+
return { env: tokens.slice(0, i), tokens: tokens.slice(i) };
|
|
14140
|
+
}
|
|
14141
|
+
function firstProgram(segment) {
|
|
14142
|
+
const head = splitEnvPrefix(segment).tokens[0] ?? "";
|
|
14143
|
+
return head.slice(head.lastIndexOf("/") + 1);
|
|
14144
|
+
}
|
|
14145
|
+
function hasC0Control(text2) {
|
|
14146
|
+
for (let i = 0; i < text2.length; i++) {
|
|
14147
|
+
const code = text2.charCodeAt(i);
|
|
14148
|
+
if (code <= 31 && code !== 10) return true;
|
|
14149
|
+
}
|
|
14150
|
+
return false;
|
|
14151
|
+
}
|
|
14152
|
+
function isReadOnlySed(args) {
|
|
14153
|
+
const script = args.find((t) => !SED_SAFE_FLAGS.has(t));
|
|
14154
|
+
if (!script || !SED_PRINT_SCRIPT.test(script)) return false;
|
|
14155
|
+
return args.slice(0, args.indexOf(script)).every((t) => SED_SAFE_FLAGS.has(t));
|
|
14156
|
+
}
|
|
14157
|
+
function isReadOnlyGit(tokens) {
|
|
14158
|
+
let subIndex = 1;
|
|
14159
|
+
while (subIndex < tokens.length && tokens[subIndex].startsWith("-")) {
|
|
14160
|
+
if (tokens[subIndex] === "-C") {
|
|
14161
|
+
if (subIndex + 1 >= tokens.length) return false;
|
|
14162
|
+
subIndex += 2;
|
|
14163
|
+
} else if (GIT_SAFE_GLOBAL_FLAGS.has(tokens[subIndex])) subIndex += 1;
|
|
14164
|
+
else return false;
|
|
14165
|
+
}
|
|
14166
|
+
if (subIndex >= tokens.length) return false;
|
|
14167
|
+
const sub = tokens[subIndex];
|
|
14168
|
+
if (!GIT_READ_SUBCOMMANDS.has(sub)) return false;
|
|
14169
|
+
const args = tokens.slice(subIndex + 1);
|
|
14170
|
+
const writeArg = GIT_WRITE_ARGS[sub];
|
|
14171
|
+
if (writeArg && args.some((t) => writeArg.test(t))) return false;
|
|
14172
|
+
if (sub === "config" && !args.some((t) => /^(--get|--get-all|--list|-l|--get-regexp)$/.test(t)))
|
|
14173
|
+
return false;
|
|
14174
|
+
if ((sub === "branch" || sub === "tag") && args.some((t) => !t.startsWith("-")) && !args.some((t) => t === "-l" || t === "--list"))
|
|
14175
|
+
return false;
|
|
14176
|
+
return true;
|
|
14177
|
+
}
|
|
14178
|
+
function isReadOnlyCommand(command2) {
|
|
14179
|
+
const trimmed = command2.trim();
|
|
14180
|
+
if (!trimmed) return false;
|
|
14181
|
+
if (/\$\(|<\(|`/.test(trimmed) || hasC0Control(trimmed)) return false;
|
|
14182
|
+
const withoutStderr = trimmed.replace(/2>&1|[12]?>\s*\/dev\/null/g, "");
|
|
14183
|
+
if (withoutStderr.includes(">")) return false;
|
|
14184
|
+
const segments = withoutStderr.split(/\|\|?|&&?|;|\n/);
|
|
14185
|
+
for (const raw of segments) {
|
|
14186
|
+
const segment = raw.trim();
|
|
14187
|
+
if (!segment) continue;
|
|
14188
|
+
const { env, tokens } = splitEnvPrefix(segment);
|
|
14189
|
+
if (env.some((e) => !SAFE_ENV.test(e))) return false;
|
|
14190
|
+
const program = firstProgram(segment);
|
|
14191
|
+
const head = tokens[0] ?? "";
|
|
14192
|
+
if (head.includes("/") && !SYSTEM_BIN_PATH.test(head)) return false;
|
|
14193
|
+
const args = tokens.slice(1);
|
|
14194
|
+
if (VERSION_ONLY_PROGRAMS.has(program)) {
|
|
14195
|
+
if (args.length !== 1 || !["--version", "-v", "-V"].includes(args[0])) return false;
|
|
14196
|
+
continue;
|
|
14197
|
+
}
|
|
14198
|
+
if (!READ_ONLY_PROGRAMS.has(program)) return false;
|
|
14199
|
+
const writeFlag = WRITE_FLAGS[program];
|
|
14200
|
+
if (writeFlag && args.some((t) => writeFlag.test(t))) return false;
|
|
14201
|
+
if (program === "awk" && /system\s*\(/.test(args.join(" "))) return false;
|
|
14202
|
+
if (program === "sed" && !isReadOnlySed(args)) return false;
|
|
14203
|
+
if (program === "git" && !isReadOnlyGit(tokens)) return false;
|
|
14204
|
+
if (program === "uniq" && args.filter((t) => !t.startsWith("-")).length > 1) return false;
|
|
14205
|
+
}
|
|
14206
|
+
return true;
|
|
14207
|
+
}
|
|
14131
14208
|
const DISCARD = "turn_discard";
|
|
14132
14209
|
const RECALL = "turn_recall";
|
|
14133
14210
|
const PASSIVE = /* @__PURE__ */ new Set([
|
|
@@ -14139,19 +14216,43 @@ const PASSIVE = /* @__PURE__ */ new Set([
|
|
|
14139
14216
|
"usage",
|
|
14140
14217
|
"context_edit"
|
|
14141
14218
|
]);
|
|
14142
|
-
const
|
|
14143
|
-
|
|
14219
|
+
const REASON_MAX = 300;
|
|
14220
|
+
const NO_TRIGGER = `${DISCARD} found no user message or plugin delivery that started this turn.`;
|
|
14221
|
+
const READ_ONLY_TOOLS = /* @__PURE__ */ new Set([
|
|
14222
|
+
"read",
|
|
14223
|
+
"grep",
|
|
14224
|
+
"find",
|
|
14225
|
+
"ls",
|
|
14226
|
+
"glob",
|
|
14227
|
+
"web_search",
|
|
14228
|
+
"web_fetch",
|
|
14229
|
+
"memory_search",
|
|
14230
|
+
"recall",
|
|
14231
|
+
"task_output",
|
|
14232
|
+
"browser_snapshot",
|
|
14233
|
+
"browser_screenshot",
|
|
14234
|
+
RECALL
|
|
14235
|
+
]);
|
|
14236
|
+
function readOnlyCall(name, args, annotated) {
|
|
14237
|
+
if (READ_ONLY_TOOLS.has(name) || annotated.has(name)) return true;
|
|
14238
|
+
const { command: command2, background } = args ?? {};
|
|
14239
|
+
return name === "bash" && typeof command2 === "string" && background !== true && isReadOnlyCommand(command2);
|
|
14240
|
+
}
|
|
14241
|
+
function toolCalls(content) {
|
|
14144
14242
|
if (!Array.isArray(content)) return [];
|
|
14145
14243
|
return content.flatMap(
|
|
14146
|
-
(part) => part?.type === "toolCall" && typeof part.name === "string" ? [part.name] : []
|
|
14244
|
+
(part) => part?.type === "toolCall" && typeof part.name === "string" ? [{ name: part.name, args: part.arguments }] : []
|
|
14147
14245
|
);
|
|
14148
14246
|
}
|
|
14149
|
-
function
|
|
14247
|
+
function isTrigger(entry) {
|
|
14248
|
+
return entry.type === "custom_message" ? entry.customType === PLUGIN_MESSAGE_TYPE : entry.type === "message" && entry.message?.role === "user";
|
|
14249
|
+
}
|
|
14250
|
+
function planTurnDiscard(branch, readOnly = () => false) {
|
|
14150
14251
|
const plan = { triggers: [], run: [] };
|
|
14151
14252
|
for (let i = branch.length - 1; i >= 0; i--) {
|
|
14152
14253
|
const entry = branch[i];
|
|
14153
14254
|
if (PASSIVE.has(entry.type)) continue;
|
|
14154
|
-
if (entry
|
|
14255
|
+
if (isTrigger(entry)) {
|
|
14155
14256
|
plan.triggers.unshift(entry.id);
|
|
14156
14257
|
continue;
|
|
14157
14258
|
}
|
|
@@ -14162,15 +14263,17 @@ function planTurnDiscard(branch) {
|
|
|
14162
14263
|
continue;
|
|
14163
14264
|
}
|
|
14164
14265
|
if (role === "assistant") {
|
|
14165
|
-
const
|
|
14166
|
-
if (
|
|
14167
|
-
|
|
14266
|
+
const calls = toolCalls(entry.message?.content);
|
|
14267
|
+
if (calls.length === 0) return NO_TRIGGER;
|
|
14268
|
+
const changed = calls.find((c) => c.name !== DISCARD && !readOnly(c.name, c.args));
|
|
14269
|
+
if (changed)
|
|
14270
|
+
return `${DISCARD} cannot drop a turn that may have changed something (${changed.name}); only read-only tools are allowed before it.`;
|
|
14168
14271
|
plan.run.unshift(entry.id);
|
|
14169
14272
|
continue;
|
|
14170
14273
|
}
|
|
14171
|
-
return
|
|
14274
|
+
return NO_TRIGGER;
|
|
14172
14275
|
}
|
|
14173
|
-
return plan.triggers.length > 0 ? plan :
|
|
14276
|
+
return plan.triggers.length > 0 ? plan : NO_TRIGGER;
|
|
14174
14277
|
}
|
|
14175
14278
|
function turnDiscardEdits(plan, reason) {
|
|
14176
14279
|
return [
|
|
@@ -14178,7 +14281,7 @@ function turnDiscardEdits(plan, reason) {
|
|
|
14178
14281
|
type: "context_edit",
|
|
14179
14282
|
targetId,
|
|
14180
14283
|
replacement: {
|
|
14181
|
-
content: `[Discarded
|
|
14284
|
+
content: `[Discarded turn input ${targetId}${reason ? `: ${reason}` : ""}] Original hidden from context; call ${RECALL} with this id if needed.`
|
|
14182
14285
|
}
|
|
14183
14286
|
})),
|
|
14184
14287
|
...plan.run.map((targetId) => ({
|
|
@@ -14190,9 +14293,9 @@ function turnDiscardEdits(plan, reason) {
|
|
|
14190
14293
|
}
|
|
14191
14294
|
function recallDiscarded(branch, id) {
|
|
14192
14295
|
const entry = branch.find((item) => item.id === id);
|
|
14193
|
-
const discarded = entry
|
|
14194
|
-
if (!discarded) throw new Error(`No discarded
|
|
14195
|
-
const content = entry.content;
|
|
14296
|
+
const discarded = entry !== void 0 && isTrigger(entry) && branch.some((item) => item.type === "context_edit" && item.targetId === id);
|
|
14297
|
+
if (!discarded) throw new Error(`No discarded turn input with id ${id}.`);
|
|
14298
|
+
const content = entry.type === "message" ? entry.message?.content : entry.content;
|
|
14196
14299
|
if (typeof content === "string") return content;
|
|
14197
14300
|
if (!Array.isArray(content)) return "";
|
|
14198
14301
|
return content.map((part) => part?.type === "text" ? String(part.text ?? "") : `[${part?.type ?? "part"}]`).join("\n");
|
|
@@ -14209,15 +14312,30 @@ function discardReason(message, toolResults) {
|
|
|
14209
14312
|
}
|
|
14210
14313
|
return void 0;
|
|
14211
14314
|
}
|
|
14212
|
-
function
|
|
14315
|
+
function createTurnDiscardState() {
|
|
14316
|
+
return {
|
|
14317
|
+
readOnly: ((name, args) => readOnlyCall(name, args, /* @__PURE__ */ new Set()))
|
|
14318
|
+
};
|
|
14319
|
+
}
|
|
14320
|
+
function turnDiscardExtension(state) {
|
|
14213
14321
|
return {
|
|
14214
14322
|
name: "turn-discard",
|
|
14215
14323
|
hidden: true,
|
|
14216
14324
|
factory: (pi) => {
|
|
14325
|
+
state.readOnly = (name, args) => readOnlyCall(
|
|
14326
|
+
name,
|
|
14327
|
+
args,
|
|
14328
|
+
new Set(
|
|
14329
|
+
pi.getAllTools().filter((tool) => tool.annotations?.readOnlyHint === true).map((tool) => tool.name)
|
|
14330
|
+
)
|
|
14331
|
+
);
|
|
14217
14332
|
pi.on("turn_end", (event, ctx) => {
|
|
14218
14333
|
const reason = discardReason(event.message, event.toolResults);
|
|
14219
14334
|
if (reason === void 0) return;
|
|
14220
|
-
const plan = planTurnDiscard(
|
|
14335
|
+
const plan = planTurnDiscard(
|
|
14336
|
+
ctx.sessionManager.getBranch(),
|
|
14337
|
+
state.readOnly
|
|
14338
|
+
);
|
|
14221
14339
|
if (typeof plan === "string") return;
|
|
14222
14340
|
return { entries: [...event.entries, ...turnDiscardEdits(plan, reason)] };
|
|
14223
14341
|
});
|
|
@@ -14225,27 +14343,35 @@ function turnDiscardExtension() {
|
|
|
14225
14343
|
};
|
|
14226
14344
|
}
|
|
14227
14345
|
const text = (value) => [{ type: "text", text: value }];
|
|
14228
|
-
function createTurnDiscardTools() {
|
|
14346
|
+
function createTurnDiscardTools(state) {
|
|
14229
14347
|
return [
|
|
14230
14348
|
{
|
|
14231
14349
|
name: DISCARD,
|
|
14232
14350
|
label: "Turn discard",
|
|
14233
|
-
description: "
|
|
14234
|
-
promptSnippet: 'turn_discard: drop an irrelevant automatic delivery from context instead of replying "skip".',
|
|
14351
|
+
description: "Drop the current turn from your context when nothing in it needs to be remembered: an automatic plugin delivery (Telegram watch, scheduler) that needs no action, or a throwaway user question once answered (answer in the same message, then call this). Allowed only if this turn used read-only tools (read, grep, find, ls, web, read-only bash...); never after editing files, sending messages, or any other change. Ends the turn immediately; later context keeps only a one-line trace with an id for turn_recall. The timeline keeps everything.",
|
|
14352
|
+
promptSnippet: 'turn_discard: drop an irrelevant automatic delivery or a throwaway exchange from context instead of replying "skip".',
|
|
14235
14353
|
parameters: {
|
|
14236
14354
|
type: "object",
|
|
14237
14355
|
properties: {
|
|
14238
|
-
reason: {
|
|
14239
|
-
|
|
14240
|
-
|
|
14356
|
+
reason: {
|
|
14357
|
+
type: "string",
|
|
14358
|
+
description: `Optional, one line (max ${REASON_MAX} chars): what this was and why it needs nothing; add any conclusion from your read-only checks worth remembering. Stays in later context.`
|
|
14359
|
+
}
|
|
14360
|
+
}
|
|
14241
14361
|
},
|
|
14242
14362
|
async execute(_id, params, _signal, _onUpdate, ctx) {
|
|
14243
14363
|
const reason = String(params.reason ?? "").trim();
|
|
14244
|
-
if (
|
|
14245
|
-
|
|
14364
|
+
if (reason.length > REASON_MAX)
|
|
14365
|
+
throw new Error(
|
|
14366
|
+
`reason is longer than ${REASON_MAX} characters; shorten it to one line.`
|
|
14367
|
+
);
|
|
14368
|
+
const plan = planTurnDiscard(
|
|
14369
|
+
ctx.sessionManager.getBranch(),
|
|
14370
|
+
state.readOnly
|
|
14371
|
+
);
|
|
14246
14372
|
if (typeof plan === "string") throw new Error(plan);
|
|
14247
14373
|
return {
|
|
14248
|
-
content: text(`Turn discarded: ${reason}`),
|
|
14374
|
+
content: text(reason ? `Turn discarded: ${reason}` : "Turn discarded."),
|
|
14249
14375
|
details: { reason, triggers: plan.triggers },
|
|
14250
14376
|
terminate: true
|
|
14251
14377
|
};
|
|
@@ -14254,7 +14380,7 @@ function createTurnDiscardTools() {
|
|
|
14254
14380
|
{
|
|
14255
14381
|
name: RECALL,
|
|
14256
14382
|
label: "Turn recall",
|
|
14257
|
-
description: "Read the original content of a delivery previously removed by turn_discard.",
|
|
14383
|
+
description: "Read the original content of a delivery or user message previously removed by turn_discard.",
|
|
14258
14384
|
parameters: {
|
|
14259
14385
|
type: "object",
|
|
14260
14386
|
properties: { id: { type: "string", description: "Id shown in the discard trace" } },
|
|
@@ -15576,7 +15702,6 @@ function takeBranchContextNote(session, input) {
|
|
|
15576
15702
|
return input.includes(note) ? void 0 : note;
|
|
15577
15703
|
}
|
|
15578
15704
|
const PENDING_COUNTERS = {
|
|
15579
|
-
ensoApp: true,
|
|
15580
15705
|
browser: true,
|
|
15581
15706
|
memory: true,
|
|
15582
15707
|
delegation: true,
|
|
@@ -15642,7 +15767,7 @@ function createSessionResourceLoader(options) {
|
|
|
15642
15767
|
microcompactExtension(),
|
|
15643
15768
|
outputLimitRecoveryExtension,
|
|
15644
15769
|
...options.exploreFold ? [exploreFoldExtension(options.exploreFold)] : [],
|
|
15645
|
-
...options.turnDiscard ? [turnDiscardExtension()] : [],
|
|
15770
|
+
...options.turnDiscard ? [turnDiscardExtension(options.turnDiscard)] : [],
|
|
15646
15771
|
...options.reminders ? [systemReminderExtension(options.reminders)] : [],
|
|
15647
15772
|
...options.remoteSsh ? [
|
|
15648
15773
|
{
|
|
@@ -15747,32 +15872,6 @@ function withPluginPrompts(base, commands) {
|
|
|
15747
15872
|
);
|
|
15748
15873
|
return { prompts: [...base.prompts, ...extra], diagnostics: base.diagnostics };
|
|
15749
15874
|
}
|
|
15750
|
-
function createEnsoResourceLoader(cwd, agentDir, branchContext, silentTurnRecovery, oauthPoolRecovery) {
|
|
15751
|
-
return new DefaultResourceLoader({
|
|
15752
|
-
cwd,
|
|
15753
|
-
agentDir,
|
|
15754
|
-
// noExtensions 挡不住项目包解析(缺包会自动安装),同样用未信任的 settings
|
|
15755
|
-
settingsManager: createProjectSettingsManager(cwd, agentDir, []).settingsManager,
|
|
15756
|
-
noExtensions: true,
|
|
15757
|
-
noSkills: true,
|
|
15758
|
-
noPromptTemplates: true,
|
|
15759
|
-
noThemes: true,
|
|
15760
|
-
noContextFiles: true,
|
|
15761
|
-
extensionFactories: [
|
|
15762
|
-
branchContext,
|
|
15763
|
-
applyPatchResultExtension,
|
|
15764
|
-
approvalReviewResultExtension,
|
|
15765
|
-
silentTurnRecovery,
|
|
15766
|
-
...oauthPoolRecovery ? [oauthPoolRecovery] : []
|
|
15767
|
-
],
|
|
15768
|
-
systemPrompt: ENSO_SYSTEM_PROMPT,
|
|
15769
|
-
skillsOverride: () => ({ skills: [], diagnostics: [] }),
|
|
15770
|
-
promptsOverride: () => ({ prompts: [], diagnostics: [] }),
|
|
15771
|
-
themesOverride: () => ({ themes: [], diagnostics: [] }),
|
|
15772
|
-
agentsFilesOverride: () => ({ agentsFiles: [] }),
|
|
15773
|
-
appendSystemPromptOverride: () => []
|
|
15774
|
-
});
|
|
15775
|
-
}
|
|
15776
15875
|
function materializeSessionFile(session) {
|
|
15777
15876
|
const hasAssistant = session.messages?.some(
|
|
15778
15877
|
(message) => message?.role === "assistant"
|
|
@@ -16125,7 +16224,6 @@ ${text2}
|
|
|
16125
16224
|
child.gate.cancelAll();
|
|
16126
16225
|
child.asks.cancelAll();
|
|
16127
16226
|
cancelContinuousMemory(child.session.sessionManager);
|
|
16128
|
-
child.ensoApp?.cancelAll("Parent released");
|
|
16129
16227
|
try {
|
|
16130
16228
|
await child.session.abort();
|
|
16131
16229
|
} catch {
|
|
@@ -16146,7 +16244,6 @@ ${text2}
|
|
|
16146
16244
|
managed.gate.cancelAll();
|
|
16147
16245
|
managed.asks.cancelAll();
|
|
16148
16246
|
cancelContinuousMemory(managed.session.sessionManager);
|
|
16149
|
-
managed.ensoApp?.cancelAll("Session released");
|
|
16150
16247
|
managed.browser?.cancelAll("Session released");
|
|
16151
16248
|
managed.memory?.cancelAll("Session released");
|
|
16152
16249
|
managed.delegation?.cancelAll("Session released");
|
|
@@ -16401,7 +16498,7 @@ ${text2}
|
|
|
16401
16498
|
});
|
|
16402
16499
|
return;
|
|
16403
16500
|
}
|
|
16404
|
-
const identity = command2.type === "
|
|
16501
|
+
const identity = command2.type === "browser-result" || command2.type === "memory-result" || command2.type === "delegation-result" || command2.type === "computer-result" || command2.type === "plugin-tool-result" || command2.type === "plugin-tool-progress" || command2.type === "plugin-intercept-result" || command2.type === "plugin-inject" ? command2.identity : command2.type === "dismiss-child" || command2.type === "dismiss-coworker" || command2.type === "resume-coworker" ? command2.parent : command2.identity;
|
|
16405
16502
|
const scopeId = command2.type === "spawn-child" ? command2.identity.parent.sessionId : identity.sessionId;
|
|
16406
16503
|
if (this.workspaceSwitch.defer(scopeId, () => this.handleCommand(command2))) return;
|
|
16407
16504
|
const touched = this.sessions.get(identity.sessionId);
|
|
@@ -16450,8 +16547,9 @@ ${text2}
|
|
|
16450
16547
|
}
|
|
16451
16548
|
const managed = this.sessions.get(identity.sessionId);
|
|
16452
16549
|
if (!managed || !isSameGeneration(managed.identity, identity)) {
|
|
16453
|
-
if (command2.type === "prompt" || command2.type === "steer" || command2.type === "retry") {
|
|
16550
|
+
if (command2.type === "prompt" || command2.type === "steer" || command2.type === "retry" || command2.type === "rewind") {
|
|
16454
16551
|
const target = command2.identity;
|
|
16552
|
+
const instanceId = "instanceId" in command2 ? command2.instanceId : void 0;
|
|
16455
16553
|
this.options.emit(
|
|
16456
16554
|
"parent" in target ? { type: "child-rejected", identity: target, seq: 0, reason: message } : {
|
|
16457
16555
|
type: "parent-rejected",
|
|
@@ -16459,7 +16557,7 @@ ${text2}
|
|
|
16459
16557
|
seq: 0,
|
|
16460
16558
|
reason: message,
|
|
16461
16559
|
// 回显这条命令自己带的实例号:Main 只把发给当前实例的命令被拒算作当前实例结束
|
|
16462
|
-
...
|
|
16560
|
+
...instanceId ? { instanceId } : {}
|
|
16463
16561
|
}
|
|
16464
16562
|
);
|
|
16465
16563
|
}
|
|
@@ -16590,7 +16688,6 @@ ${text2}
|
|
|
16590
16688
|
managed.turnAborted = false;
|
|
16591
16689
|
if (command2.requestBudget) managed.requestBudget?.arm();
|
|
16592
16690
|
else managed.requestBudget?.disarm();
|
|
16593
|
-
managed.safeJournal?.appendUserText(command2.task.text);
|
|
16594
16691
|
const images = command2.task.images.map((image) => ({ type: "image", ...image }));
|
|
16595
16692
|
void managed.session.prompt(
|
|
16596
16693
|
consumeRole(managed, command2.task.text),
|
|
@@ -16789,15 +16886,6 @@ ${text2}
|
|
|
16789
16886
|
case "ask-respond":
|
|
16790
16887
|
this.must(command2.identity).asks.respond(command2.requestId, command2.answer);
|
|
16791
16888
|
return;
|
|
16792
|
-
case "capability-result": {
|
|
16793
|
-
const managed = this.must(command2.child);
|
|
16794
|
-
if (!managed.childIdentity || !isSameChildSessionIdentity(command2.child, managed.childIdentity) || managed.currentTurnId !== command2.turnId) {
|
|
16795
|
-
return;
|
|
16796
|
-
}
|
|
16797
|
-
managed.safeJournal?.appendCapabilityResult(command2.requestId, command2.envelope);
|
|
16798
|
-
managed.ensoApp?.resolve(command2.turnId, command2.requestId, command2.envelope);
|
|
16799
|
-
return;
|
|
16800
|
-
}
|
|
16801
16889
|
case "browser-result": {
|
|
16802
16890
|
const managed = this.must(command2.identity);
|
|
16803
16891
|
if (!managed.browser?.resolve(command2)) {
|
|
@@ -16926,7 +17014,7 @@ ${text2}
|
|
|
16926
17014
|
}
|
|
16927
17015
|
case "compact": {
|
|
16928
17016
|
const managed = this.must(command2.identity);
|
|
16929
|
-
if (managed.status
|
|
17017
|
+
if (managed.status === "running") {
|
|
16930
17018
|
managed.pendingCompact = command2.instructions ? { instructions: command2.instructions } : {};
|
|
16931
17019
|
managed.compaction = "queued";
|
|
16932
17020
|
this.options.emit({
|
|
@@ -17002,7 +17090,6 @@ ${text2}
|
|
|
17002
17090
|
managed.gate.cancelAll();
|
|
17003
17091
|
managed.asks.cancelAll();
|
|
17004
17092
|
cancelContinuousMemory(managed.session.sessionManager);
|
|
17005
|
-
managed.ensoApp?.cancelAll("Enso capability invocation aborted");
|
|
17006
17093
|
managed.browser?.cancelAll("Browser action aborted");
|
|
17007
17094
|
managed.memory?.cancelAll("Memory action aborted");
|
|
17008
17095
|
managed.delegation?.cancelAll("Delegation action aborted");
|
|
@@ -17075,6 +17162,7 @@ ${text2}
|
|
|
17075
17162
|
(result) => result.code === 0 && result.stdout.trim().length > 0 ? [{ path: `${cwd}/AGENTS.md`, content: result.stdout }] : []
|
|
17076
17163
|
).catch(() => []) : void 0;
|
|
17077
17164
|
const exploreFold = exploreFoldEnabled ? createExploreFoldState() : void 0;
|
|
17165
|
+
const turnDiscard = createTurnDiscardState();
|
|
17078
17166
|
if (smartCompactSummaryModel) {
|
|
17079
17167
|
await resolveBaseModelOrRefresh(runtime, smartCompactSummaryModel);
|
|
17080
17168
|
}
|
|
@@ -17126,7 +17214,7 @@ ${text2}
|
|
|
17126
17214
|
pluginHooks: { hooks: pluginHooks, role: { kind: "parent" }, resumed: Boolean(resumeFile) },
|
|
17127
17215
|
...pluginEventInvoker ? { pluginEvents: { invoker: pluginEventInvoker } } : {},
|
|
17128
17216
|
exploreFold,
|
|
17129
|
-
turnDiscard
|
|
17217
|
+
turnDiscard,
|
|
17130
17218
|
reminders,
|
|
17131
17219
|
codemode: codemodeHost.extension,
|
|
17132
17220
|
persona: systemPrompt,
|
|
@@ -17203,8 +17291,8 @@ ${text2}
|
|
|
17203
17291
|
return [note];
|
|
17204
17292
|
});
|
|
17205
17293
|
reminders.register("background-task", () => {
|
|
17206
|
-
const
|
|
17207
|
-
return
|
|
17294
|
+
const pending2 = takePendingReminders();
|
|
17295
|
+
return pending2.map((text2) => `<background-task-update>
|
|
17208
17296
|
${text2}
|
|
17209
17297
|
</background-task-update>`);
|
|
17210
17298
|
});
|
|
@@ -17237,8 +17325,8 @@ ${text2}
|
|
|
17237
17325
|
read: withPathHints(wrapRead(createReadToolDefinition(cwd)), cwd),
|
|
17238
17326
|
grep: withPathHints(createGrepToolDefinition(cwd), cwd)
|
|
17239
17327
|
};
|
|
17240
|
-
const { grep } = stock;
|
|
17241
17328
|
const read = withProtectedFloor(toolGate, "read", stock.read);
|
|
17329
|
+
const grep = withProtectedFloor(toolGate, "read", stock.grep);
|
|
17242
17330
|
return remoteOps && sshExecutor ? [
|
|
17243
17331
|
read,
|
|
17244
17332
|
grep,
|
|
@@ -17375,20 +17463,18 @@ ${text2}
|
|
|
17375
17463
|
thinkingOverride,
|
|
17376
17464
|
identity: childIdentity,
|
|
17377
17465
|
gate: childGate,
|
|
17378
|
-
askManager: askManager2,
|
|
17379
17466
|
resumeFile: childResume,
|
|
17380
17467
|
extraTools = [],
|
|
17381
17468
|
pluginSource
|
|
17382
17469
|
}) => {
|
|
17383
|
-
const
|
|
17384
|
-
const childPlugins = pluginSource && !isLockedEnso ? this.childPluginBridge(
|
|
17470
|
+
const childPlugins = pluginSource ? this.childPluginBridge(
|
|
17385
17471
|
pluginSource,
|
|
17386
17472
|
resolved?.displayName ?? agentType?.name,
|
|
17387
17473
|
resolved?.tools === "readonly" || agentType?.tools === "readonly" ? [] : pluginToolDescriptors,
|
|
17388
17474
|
childPluginEventPlan(pluginEventPlan)
|
|
17389
17475
|
) : void 0;
|
|
17390
17476
|
const selectedMcp = resolved?.mcpServers ?? agentType?.mcpServers ?? [];
|
|
17391
|
-
const mcpPending =
|
|
17477
|
+
const mcpPending = selectedMcp.length > 0 ? Promise.all(selectedMcp.map((server) => this.mcp.toolsFor([server], 3e3))) : Promise.resolve([]);
|
|
17392
17478
|
const selectedModel = modelOverride ?? resolved?.model ?? agentType?.model ?? model;
|
|
17393
17479
|
const base = await resolveSessionModel(runtime, selectedModel);
|
|
17394
17480
|
const childReasoning = resolveChildReasoning(
|
|
@@ -17401,14 +17487,11 @@ ${text2}
|
|
|
17401
17487
|
childReasoning.enabled,
|
|
17402
17488
|
selectedModel.modelId
|
|
17403
17489
|
);
|
|
17404
|
-
|
|
17405
|
-
throw new Error("Locked Enso child requires exact identity and ask manager.");
|
|
17406
|
-
}
|
|
17407
|
-
const childExploreFold = !isLockedEnso && exploreFoldEnabled ? createExploreFoldState() : void 0;
|
|
17490
|
+
const childExploreFold = exploreFoldEnabled ? createExploreFoldState() : void 0;
|
|
17408
17491
|
const typed = Boolean(resolved || agentType);
|
|
17409
17492
|
const childCodemode = new CodemodeHost({
|
|
17410
|
-
codemode:
|
|
17411
|
-
deferredServers:
|
|
17493
|
+
codemode: toolEnabled("isolated_sandbox"),
|
|
17494
|
+
deferredServers: typed ? [] : deferredMcp
|
|
17412
17495
|
});
|
|
17413
17496
|
const selectedSkillPaths = resolved?.skillPaths ?? agentType?.skillPaths ?? [];
|
|
17414
17497
|
const branchContext = this.branchContextExtension(
|
|
@@ -17422,13 +17505,7 @@ ${text2}
|
|
|
17422
17505
|
managed2.silentTurnKind = kind;
|
|
17423
17506
|
});
|
|
17424
17507
|
const childReminders = new SystemReminderRegistry();
|
|
17425
|
-
const subLoader =
|
|
17426
|
-
cwd,
|
|
17427
|
-
this.options.agentDir,
|
|
17428
|
-
branchContext,
|
|
17429
|
-
silentTurnRecovery,
|
|
17430
|
-
this.oauthPoolRecovery()
|
|
17431
|
-
) : createSessionResourceLoader({
|
|
17508
|
+
const subLoader = createSessionResourceLoader({
|
|
17432
17509
|
branchContext,
|
|
17433
17510
|
silentTurnRecovery,
|
|
17434
17511
|
oauthPoolRecovery: this.oauthPoolRecovery(),
|
|
@@ -17465,36 +17542,10 @@ ${text2}
|
|
|
17465
17542
|
throw new Error("Agent profile MCP resource failed to establish.");
|
|
17466
17543
|
}
|
|
17467
17544
|
const typeMcpTools = mcpToolGroups.flat().map((tool) => withApproval(childGate, "mcp", tool));
|
|
17468
|
-
const ensoApp = isLockedEnso && childIdentity && askManager2 ? new EnsoAppInvoker(
|
|
17469
|
-
childIdentity,
|
|
17470
|
-
() => this.sessions.get(childIdentity.sessionId)?.currentTurnId,
|
|
17471
|
-
(request) => {
|
|
17472
|
-
const managed2 = this.sessions.get(childIdentity.sessionId);
|
|
17473
|
-
if (!managed2?.childIdentity || !isSameChildSessionIdentity(childIdentity, managed2.childIdentity)) {
|
|
17474
|
-
throw new Error("Enso child generation is no longer current.");
|
|
17475
|
-
}
|
|
17476
|
-
managed2.safeJournal?.append({
|
|
17477
|
-
type: "enso-operation",
|
|
17478
|
-
operationId: request.requestId,
|
|
17479
|
-
capabilityId: request.capabilityId,
|
|
17480
|
-
toolCallId: request.requestId,
|
|
17481
|
-
at: Date.now()
|
|
17482
|
-
});
|
|
17483
|
-
this.options.emit({
|
|
17484
|
-
type: "capability-invoke",
|
|
17485
|
-
child: request.child,
|
|
17486
|
-
seq: ++managed2.seq,
|
|
17487
|
-
turnId: request.turnId,
|
|
17488
|
-
requestId: request.requestId,
|
|
17489
|
-
capabilityId: request.capabilityId,
|
|
17490
|
-
params: request.params
|
|
17491
|
-
});
|
|
17492
|
-
}
|
|
17493
|
-
) : void 0;
|
|
17494
17545
|
const childPluginTools = childPlugins?.tools ? createPluginTools([...childPlugins.descriptors], childPlugins.tools).map(
|
|
17495
17546
|
(tool) => withApproval(childGate, "mcp", tool)
|
|
17496
17547
|
) : [];
|
|
17497
|
-
const childTools =
|
|
17548
|
+
const childTools = [
|
|
17498
17549
|
...!toolEnabled(WORKSPACE_WRITE_TOOL_ID) || resolved?.tools === "readonly" || agentType?.tools === "readonly" ? readOnlyTools(childGate) : buildBaseTools(
|
|
17499
17550
|
childGate,
|
|
17500
17551
|
void 0,
|
|
@@ -17508,12 +17559,10 @@ ${text2}
|
|
|
17508
17559
|
];
|
|
17509
17560
|
const childRunaway = new RunawayGuard();
|
|
17510
17561
|
const requestBudget = new RequestBudget();
|
|
17511
|
-
|
|
17512
|
-
|
|
17513
|
-
|
|
17514
|
-
|
|
17515
|
-
});
|
|
17516
|
-
}
|
|
17562
|
+
childReminders.register("request-budget", () => {
|
|
17563
|
+
const notice = requestBudget.takeNotice();
|
|
17564
|
+
return notice ? [notice] : [];
|
|
17565
|
+
});
|
|
17517
17566
|
const childBudget = new ToolOutputBudget({
|
|
17518
17567
|
rootDir: path.join(
|
|
17519
17568
|
this.options.sessionDir,
|
|
@@ -17526,24 +17575,9 @@ ${text2}
|
|
|
17526
17575
|
runaway: childRunaway,
|
|
17527
17576
|
budget: childBudget
|
|
17528
17577
|
});
|
|
17529
|
-
const subTools = omitNamedTools(
|
|
17530
|
-
isLockedEnso ? rawSubTools : decorateChild(rawSubTools),
|
|
17531
|
-
disabledTools
|
|
17532
|
-
);
|
|
17578
|
+
const subTools = omitNamedTools(decorateChild(rawSubTools), disabledTools);
|
|
17533
17579
|
childCodemode.bindDeferredTools(deferredMcpLoader(childGate, decorateChild));
|
|
17534
|
-
const
|
|
17535
|
-
const sessionManager = safeJournal ? SessionManager.inMemory(cwd) : childResume ? SessionManager.open(childResume, this.options.sessionDir, cwd) : SessionManager.create(cwd, this.options.sessionDir);
|
|
17536
|
-
if (safeJournal && childResume) {
|
|
17537
|
-
for (const record of (await EnsoSafeJournal.restore(childResume)).records) {
|
|
17538
|
-
if (record.type === "safe-user-text") {
|
|
17539
|
-
sessionManager.appendMessage({
|
|
17540
|
-
role: "user",
|
|
17541
|
-
content: [{ type: "text", text: record.text }],
|
|
17542
|
-
timestamp: record.at
|
|
17543
|
-
});
|
|
17544
|
-
}
|
|
17545
|
-
}
|
|
17546
|
-
}
|
|
17580
|
+
const sessionManager = childResume ? SessionManager.open(childResume, this.options.sessionDir, cwd) : SessionManager.create(cwd, this.options.sessionDir);
|
|
17547
17581
|
const { session: session2 } = await createAgentSession({
|
|
17548
17582
|
cwd,
|
|
17549
17583
|
agentDir: this.options.agentDir,
|
|
@@ -17561,7 +17595,7 @@ ${text2}
|
|
|
17561
17595
|
subTools.map((tool) => withSystemReminders(tool, childReminders)),
|
|
17562
17596
|
cwd
|
|
17563
17597
|
) : void 0;
|
|
17564
|
-
if (childIdentity
|
|
17598
|
+
if (childIdentity) {
|
|
17565
17599
|
const childServers = typed ? selectedMcp : directMcp.filter((server) => !isDeferredMcp(server));
|
|
17566
17600
|
this.rememberMcpHotplug(
|
|
17567
17601
|
childIdentity.sessionId,
|
|
@@ -17580,16 +17614,14 @@ ${text2}
|
|
|
17580
17614
|
return {
|
|
17581
17615
|
session: session2,
|
|
17582
17616
|
modelId: selectedModel.modelId,
|
|
17583
|
-
...safeJournal ? { safeJournal } : {},
|
|
17584
17617
|
modelRef: settingsModelRef(selectedModel),
|
|
17585
17618
|
toolIds: [...subTools.map((tool) => tool.name), ...childExtraTools],
|
|
17586
|
-
//
|
|
17619
|
+
// 装饰器会克隆工具,所以要在装饰前按对象引用排除 MCP 与插件工具。
|
|
17587
17620
|
proofToolIds: [
|
|
17588
17621
|
...rawSubTools.filter((tool) => !typeMcpTools.includes(tool) && !childPluginTools.includes(tool)).map((tool) => tool.name),
|
|
17589
17622
|
...childExtraTools
|
|
17590
17623
|
],
|
|
17591
|
-
|
|
17592
|
-
...isLockedEnso ? {} : { runawayGuard: childRunaway },
|
|
17624
|
+
runawayGuard: childRunaway,
|
|
17593
17625
|
requestBudget,
|
|
17594
17626
|
...childPlugins?.tools ? { pluginTools: childPlugins.tools } : {},
|
|
17595
17627
|
...childPlugins?.events ? { pluginEvents: childPlugins.events } : {}
|
|
@@ -17791,7 +17823,7 @@ ${text2}
|
|
|
17791
17823
|
})
|
|
17792
17824
|
]),
|
|
17793
17825
|
...exploreFold ? createExploreFoldTools(exploreFold) : [],
|
|
17794
|
-
...createTurnDiscardTools(),
|
|
17826
|
+
...builtin("turn_discard", createTurnDiscardTools(turnDiscard)),
|
|
17795
17827
|
...builtin("background_tasks", createTaskTools(this.bgTasks, sessionId)),
|
|
17796
17828
|
...toolEnabled("goal") ? createGoalTools(
|
|
17797
17829
|
(kind, note) => {
|
|
@@ -17999,8 +18031,6 @@ ${text2}
|
|
|
17999
18031
|
toolIds: opts.toolIds ?? [],
|
|
18000
18032
|
proofToolIds: opts.proofToolIds ?? opts.toolIds ?? [],
|
|
18001
18033
|
promptedRequestIds: /* @__PURE__ */ new Set(),
|
|
18002
|
-
...opts.ensoApp ? { ensoApp: opts.ensoApp } : {},
|
|
18003
|
-
...opts.safeJournal ? { safeJournal: opts.safeJournal } : {},
|
|
18004
18034
|
adaptiveDowngraded: /* @__PURE__ */ new Set(),
|
|
18005
18035
|
silentTurnNudgeUsed: false,
|
|
18006
18036
|
...opts.runawayGuard ? { runawayGuard: opts.runawayGuard } : {},
|
|
@@ -18218,10 +18248,6 @@ ${text2}
|
|
|
18218
18248
|
if (cwd !== factory.cwd || identity.typeKey !== config.typeKey) {
|
|
18219
18249
|
throw new Error("Child source or Agent type does not match the reserved identity.");
|
|
18220
18250
|
}
|
|
18221
|
-
const isLockedEnso = identity.typeKey === ENSO_LOCKED_PROFILE.typeKey;
|
|
18222
|
-
if (isLockedEnso !== (config.tools === "enso-locked") || identity.profileId !== config.lockedProfileId || isLockedEnso && (identity.profileId !== ENSO_LOCKED_PROFILE.profileId || config.skillPaths.length !== 0 || config.mcpServers.length !== 0)) {
|
|
18223
|
-
throw new Error("Child locked profile does not match the reserved identity.");
|
|
18224
|
-
}
|
|
18225
18251
|
const existing = this.sessions.get(identity.sessionId);
|
|
18226
18252
|
if (existing) {
|
|
18227
18253
|
if (!existing.childIdentity || !isSameChildSessionIdentity(existing.childIdentity, identity)) {
|
|
@@ -18231,7 +18257,7 @@ ${text2}
|
|
|
18231
18257
|
type: "child-ready",
|
|
18232
18258
|
identity,
|
|
18233
18259
|
seq: ++existing.seq,
|
|
18234
|
-
sessionFile:
|
|
18260
|
+
sessionFile: requiredSessionFile(existing.session),
|
|
18235
18261
|
proof: {
|
|
18236
18262
|
spawnSpecId: config.spawnSpecId,
|
|
18237
18263
|
typeKey: config.typeKey,
|
|
@@ -18275,18 +18301,15 @@ ${text2}
|
|
|
18275
18301
|
resolved: config,
|
|
18276
18302
|
identity,
|
|
18277
18303
|
gate,
|
|
18278
|
-
askManager,
|
|
18279
18304
|
resumeFile,
|
|
18280
|
-
|
|
18281
|
-
|
|
18282
|
-
|
|
18283
|
-
|
|
18284
|
-
|
|
18285
|
-
|
|
18286
|
-
|
|
18287
|
-
|
|
18288
|
-
pluginSource: { identity, kind: "subagent", name: identity.instanceName }
|
|
18289
|
-
}
|
|
18305
|
+
extraTools: [
|
|
18306
|
+
createMessageMainTool(
|
|
18307
|
+
(text2, urgent) => this.notifier.notify(identity.parent.sessionId, text2, { urgent }),
|
|
18308
|
+
identity.instanceName
|
|
18309
|
+
),
|
|
18310
|
+
this.createPeerMessageTool(identity.parent.sessionId, identity.instanceName)
|
|
18311
|
+
],
|
|
18312
|
+
pluginSource: { identity, kind: "subagent", name: identity.instanceName }
|
|
18290
18313
|
});
|
|
18291
18314
|
const metadata = {
|
|
18292
18315
|
parentId: identity.parent.sessionId,
|
|
@@ -18294,8 +18317,7 @@ ${text2}
|
|
|
18294
18317
|
agentTypeKey: identity.typeKey,
|
|
18295
18318
|
agentInstanceId: identity.instanceId,
|
|
18296
18319
|
agentInstanceName: identity.instanceName,
|
|
18297
|
-
dispatchOrigin: "typed-mention"
|
|
18298
|
-
...identity.profileId ? { lockedProfileId: identity.profileId } : {}
|
|
18320
|
+
dispatchOrigin: "typed-mention"
|
|
18299
18321
|
};
|
|
18300
18322
|
const info = {
|
|
18301
18323
|
id: identity.sessionId,
|
|
@@ -18304,7 +18326,7 @@ ${text2}
|
|
|
18304
18326
|
agentType: identity.typeKey,
|
|
18305
18327
|
status: "idle",
|
|
18306
18328
|
modelId: result.modelId,
|
|
18307
|
-
sessionFile: result.
|
|
18329
|
+
sessionFile: result.session.sessionFile,
|
|
18308
18330
|
createdAt: Date.now()
|
|
18309
18331
|
};
|
|
18310
18332
|
parent.coworkers.set(identity.instanceName, info);
|
|
@@ -18321,10 +18343,8 @@ ${text2}
|
|
|
18321
18343
|
coworkerName: identity.instanceName,
|
|
18322
18344
|
resumeFile,
|
|
18323
18345
|
asks: askManager,
|
|
18324
|
-
ensoApp: result.ensoApp,
|
|
18325
18346
|
toolIds: result.toolIds,
|
|
18326
18347
|
proofToolIds: result.proofToolIds,
|
|
18327
|
-
safeJournal: result.safeJournal,
|
|
18328
18348
|
...result.runawayGuard ? { runawayGuard: result.runawayGuard } : {},
|
|
18329
18349
|
...result.requestBudget ? { requestBudget: result.requestBudget } : {}
|
|
18330
18350
|
});
|
|
@@ -18334,7 +18354,7 @@ ${text2}
|
|
|
18334
18354
|
type: "child-ready",
|
|
18335
18355
|
identity,
|
|
18336
18356
|
seq: ++managedRef.seq,
|
|
18337
|
-
sessionFile:
|
|
18357
|
+
sessionFile: requiredSessionFile(result.session),
|
|
18338
18358
|
proof: {
|
|
18339
18359
|
spawnSpecId: config.spawnSpecId,
|
|
18340
18360
|
typeKey: config.typeKey,
|
|
@@ -18446,7 +18466,6 @@ ${text2}
|
|
|
18446
18466
|
managed.gate.cancelAll();
|
|
18447
18467
|
managed.asks.cancelAll();
|
|
18448
18468
|
cancelContinuousMemory(managed.session.sessionManager);
|
|
18449
|
-
managed.ensoApp?.cancelAll("Child dismissed");
|
|
18450
18469
|
try {
|
|
18451
18470
|
await managed.session.abort();
|
|
18452
18471
|
} catch {
|
|
@@ -18761,13 +18780,7 @@ ${await this.runParentGate(managed, gateCommand)}` : base;
|
|
|
18761
18780
|
managed.pendingPrivacyMask = void 0;
|
|
18762
18781
|
}
|
|
18763
18782
|
this.replaceLastMessage(managed, projected);
|
|
18764
|
-
if (projected?.role === "assistant")
|
|
18765
|
-
const text2 = projected.content.filter(
|
|
18766
|
-
(part) => part.type === "text"
|
|
18767
|
-
).map((part) => part.text).join("\\n");
|
|
18768
|
-
if (text2) managed.safeJournal?.appendAssistantText(text2);
|
|
18769
|
-
this.noteBudgetRequest(managed, projected);
|
|
18770
|
-
}
|
|
18783
|
+
if (projected?.role === "assistant") this.noteBudgetRequest(managed, projected);
|
|
18771
18784
|
this.emitSessionMeta(managed);
|
|
18772
18785
|
return;
|
|
18773
18786
|
}
|
|
@@ -18850,7 +18863,11 @@ ${await this.runParentGate(managed, gateCommand)}` : base;
|
|
|
18850
18863
|
this.reconcileMessages(managed, this.transcript(managed));
|
|
18851
18864
|
this.rebaseContextUsage(managed);
|
|
18852
18865
|
managed.compaction = void 0;
|
|
18853
|
-
const
|
|
18866
|
+
const cancel = takeCompactCancel(managed.session.sessionManager);
|
|
18867
|
+
const cancelled = event.aborted && !event.errorMessage ? cancel : void 0;
|
|
18868
|
+
if (cancelled) this.logCompactCancel(managed, cancelled);
|
|
18869
|
+
const error = event.errorMessage || (cancelled ? formatCompactCancel(cancelled) : void 0);
|
|
18870
|
+
const succeeded = !error && !event.aborted;
|
|
18854
18871
|
if (succeeded) {
|
|
18855
18872
|
managed.compactionNoticeAt = managed.messages.length;
|
|
18856
18873
|
managed.plan?.compacted();
|
|
@@ -18861,8 +18878,8 @@ ${await this.runParentGate(managed, gateCommand)}` : base;
|
|
|
18861
18878
|
identity: managed.identity,
|
|
18862
18879
|
seq: ++managed.seq,
|
|
18863
18880
|
state: "end",
|
|
18864
|
-
...
|
|
18865
|
-
...!
|
|
18881
|
+
...error ? { error } : {},
|
|
18882
|
+
...!error && event.aborted ? { abandoned: true } : {}
|
|
18866
18883
|
});
|
|
18867
18884
|
return;
|
|
18868
18885
|
}
|
|
@@ -19404,6 +19421,14 @@ ${await this.runParentGate(managed, gateCommand)}` : base;
|
|
|
19404
19421
|
estimateSessionMessage(message) {
|
|
19405
19422
|
return estimateConversationTokens(message);
|
|
19406
19423
|
}
|
|
19424
|
+
/** 打包后 stdout 不可见:取消原因落到数据目录,事后可查 */
|
|
19425
|
+
logCompactCancel(managed, cancel) {
|
|
19426
|
+
if (!this.options.dataDir) return;
|
|
19427
|
+
appendCappedLog(
|
|
19428
|
+
path.join(this.options.dataDir, AGENT_COMPACTION_LOG),
|
|
19429
|
+
`compact-cancel session=${managed.identity.sessionId} ${JSON.stringify(cancel)}`
|
|
19430
|
+
);
|
|
19431
|
+
}
|
|
19407
19432
|
occupancyInputs(managed) {
|
|
19408
19433
|
const loader = managed.session.resourceLoader;
|
|
19409
19434
|
const sessionManager = managed.session.sessionManager;
|
|
@@ -19585,7 +19610,6 @@ ${await this.runParentGate(managed, gateCommand)}` : base;
|
|
|
19585
19610
|
this.bgTasks.stopAll();
|
|
19586
19611
|
for (const managed of this.sessions.values()) {
|
|
19587
19612
|
cancelContinuousMemory(managed.session.sessionManager);
|
|
19588
|
-
managed.ensoApp?.cancelAll("Enso worker shutdown");
|
|
19589
19613
|
managed.browser?.cancelAll("Enso worker shutdown");
|
|
19590
19614
|
managed.memory?.cancelAll("Enso worker shutdown");
|
|
19591
19615
|
managed.delegation?.cancelAll("Enso worker shutdown");
|
|
@@ -19799,10 +19823,12 @@ ${await this.runParentGate(managed, gateCommand)}` : base;
|
|
|
19799
19823
|
const timer = setTimeout(() => controller.abort(), command2.timeoutMs);
|
|
19800
19824
|
try {
|
|
19801
19825
|
const model = await resolveBaseModelOrRefresh(runtime, candidate);
|
|
19826
|
+
const requested = command2.reasoning;
|
|
19827
|
+
const reasoning = requested && requested !== "off" ? requested : auxiliaryReasoning(candidate);
|
|
19802
19828
|
const options = {
|
|
19803
19829
|
signal: controller.signal,
|
|
19804
19830
|
...command2.maxTokens !== void 0 ? { maxTokens: command2.maxTokens } : {},
|
|
19805
|
-
...
|
|
19831
|
+
...reasoning ? { reasoning } : {}
|
|
19806
19832
|
};
|
|
19807
19833
|
const message = command2.stream ? await this.readSimpleStream(
|
|
19808
19834
|
runtime,
|
|
@@ -19955,8 +19981,10 @@ ${await this.runParentGate(managed, gateCommand)}` : base;
|
|
|
19955
19981
|
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
19956
19982
|
try {
|
|
19957
19983
|
const model = await resolveBaseModelOrRefresh(runtime, candidate);
|
|
19984
|
+
const reasoning = auxiliaryReasoning(candidate);
|
|
19958
19985
|
const message = await runtime.completeSimple(model, context, {
|
|
19959
|
-
signal: controller.signal
|
|
19986
|
+
signal: controller.signal,
|
|
19987
|
+
...reasoning ? { reasoning } : {}
|
|
19960
19988
|
});
|
|
19961
19989
|
if (message.stopReason === "aborted") {
|
|
19962
19990
|
lastError = `${label}: timed out after ${Math.round(timeoutMs / 1e3)}s`;
|
|
@@ -20277,11 +20305,13 @@ const dataDir = process.env.ENSO_AGENT_DATA_DIR;
|
|
|
20277
20305
|
if (!dataDir) {
|
|
20278
20306
|
throw new Error("ENSO_AGENT_DATA_DIR is required");
|
|
20279
20307
|
}
|
|
20308
|
+
installCrashRecord(dataDir);
|
|
20280
20309
|
const supervisor = new SessionSupervisor({
|
|
20281
20310
|
emit: (event) => port.postMessage(event),
|
|
20282
20311
|
agentDir: path.join(dataDir, "pi-agent"),
|
|
20283
20312
|
sessionDir: path.join(dataDir, "sessions"),
|
|
20284
|
-
workflowDir: path.join(dataDir, "workflows")
|
|
20313
|
+
workflowDir: path.join(dataDir, "workflows"),
|
|
20314
|
+
dataDir
|
|
20285
20315
|
});
|
|
20286
20316
|
port.onMessage((data) => {
|
|
20287
20317
|
const command2 = parseAgentCommand(data);
|