nolo-cli 0.227.0-alpha.1 → 0.227.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -5
- package/{_executeModel-JKQGZ3HU.js → _executeModel-CXOFYVHC.js} +93 -87
- package/{action-CK64LS6S.js → action-R2EIXR7I.js} +11 -8
- package/{addContentAction-CARFID6E.js → addContentAction-W6JVLQ6H.js} +17 -16
- package/{addDialogAgentAction-APLZLFW5.js → addDialogAgentAction-LVNKMXKZ.js} +20 -19
- package/{agentDeleteCommand-NVR2V2HH.js → agentDeleteCommand-VFSZPEQ5.js} +145 -137
- package/{agentEmailCommands-UCVOWD3S.js → agentEmailCommands-KRUIF4EH.js} +149 -137
- package/{agentFavoriteCommands-4PDOP3GW.js → agentFavoriteCommands-7LOP3HUD.js} +6 -6
- package/{agentGrantCommands-FLCEXLUH.js → agentGrantCommands-L6O2HVJI.js} +7 -7
- package/agentListCommands-TDFOLWN3.js +644 -0
- package/{agentMachineCommands-V3DGEJU4.js → agentMachineCommands-PSH7Q5PF.js} +76 -67
- package/{agentProviderCommands-7QBFRFRK.js → agentProviderCommands-C5T7C5KZ.js} +7 -7
- package/{agentPullCommand-E6JBGBVG.js → agentPullCommand-QQQZSC6S.js} +7 -7
- package/agentRecordCommands-KCKCW2QU.js +188 -0
- package/agentRunCommand-EF2T2QWD.js +223 -0
- package/{agentRunControl-SNZZ5XP4.js → agentRunControl-CSMSJFFB.js} +25 -17
- package/{agentRuntimeLocal-GOX2DIY7.js → agentRuntimeLocal-6QXQS3TS.js} +64 -50
- package/{agentSlice-N7H2FRJA.js → agentSlice-IZ5ANAF7.js} +19 -18
- package/{appDeleteCommands-LZDN26FU.js → appDeleteCommands-4M7ETEEG.js} +68 -59
- package/{appDeployCommands-6IO6TTZH.js → appDeployCommands-2VJ2NDW5.js} +68 -59
- package/{appDeployStatusCommands-FG3LX24J.js → appDeployStatusCommands-LDFSWOPQ.js} +68 -59
- package/{appGetCommands-NAKVDVD4.js → appGetCommands-RHVNOPT4.js} +68 -59
- package/{appListCommands-KL56RN73.js → appListCommands-U3XEVTL4.js} +68 -59
- package/{authCommand-AUN5MXV2.js → authCommand-PVZ45QRO.js} +36 -31
- package/{authCommands-D2IPS6ES.js → authCommands-6AUYO65N.js} +18 -13
- package/{builtinSkillRegistry-UQGLKRYP.js → builtinSkillRegistry-LRVAQCPW.js} +6 -6
- package/{chromeCommands-G5UDKVSV.js → chromeCommands-S7AW3AOD.js} +383 -6
- package/{chromeOpsCommands-UJWN5HWH.js → chromeOpsCommands-TBPM6MR4.js} +8 -8
- package/{chunk-ABGULE7H.js → chunk-22YUCKMK.js} +16 -16
- package/{chunk-P2ZLUIW2.js → chunk-2BSLGODA.js} +350 -25
- package/{chunk-GOLPOTG5.js → chunk-2COM7SAH.js} +4 -4
- package/{chunk-ULAQPRHX.js → chunk-2FK2KZSL.js} +1 -1
- package/{chunk-PLPLH2XZ.js → chunk-2IPR4PBB.js} +2 -2
- package/chunk-2SXN7LAY.js +15 -0
- package/{chunk-XI2BWJM5.js → chunk-324FWHUA.js} +20 -3
- package/{chunk-7Z3WUZ4Q.js → chunk-3YYFU6H7.js} +74 -46
- package/{chunk-C2B7M567.js → chunk-4OXPN3WC.js} +17 -6
- package/chunk-4TVOZGOS.js +62 -0
- package/chunk-4ZCTKB27.js +31 -0
- package/chunk-53AEDFBL.js +33394 -0
- package/chunk-53W5BXLN.js +340 -0
- package/{chunk-OXA5GWHU.js → chunk-56O2J2Y4.js} +3 -3
- package/{chunk-IAJJYHIB.js → chunk-56PB7FEN.js} +8 -8
- package/{chunk-JWXITTQB.js → chunk-5HUO7SEX.js} +9 -107
- package/{chunk-AGP3YSEC.js → chunk-5PASH2MB.js} +46 -1
- package/{chunk-PHOSZT3E.js → chunk-5UAKGCQG.js} +1 -1
- package/{chunk-5RKRXQ2H.js → chunk-5VVP7DW3.js} +20 -13
- package/chunk-6ASGEP5D.js +21 -0
- package/chunk-6PXFEPHL.js +103 -0
- package/chunk-6RSNVJGO.js +279 -0
- package/{chunk-YGMBIXCF.js → chunk-6XRPBZRS.js} +4 -2
- package/{chunk-KMRKZNGT.js → chunk-6YYTTLJV.js} +14 -13
- package/{chunk-VREDDN25.js → chunk-76HAJUOJ.js} +14 -9
- package/{chunk-FKEZOMIF.js → chunk-7DXFOL5B.js} +1410 -768
- package/{chunk-LA7JYAKF.js → chunk-AKPKOI5Z.js} +6 -6
- package/{chunk-PWTNI4N7.js → chunk-ANUP75N2.js} +22 -0
- package/{chunk-F5AY2UZL.js → chunk-AO6T7U62.js} +592 -68
- package/{chunk-LJSNEV7M.js → chunk-AS6L5KSD.js} +8 -8
- package/{chunk-GOQ6ZVTN.js → chunk-AVSZ6PBM.js} +5 -5
- package/chunk-BIDSIRTS.js +307 -0
- package/chunk-C5A54QS7.js +108 -0
- package/{chunk-KYH7XW3K.js → chunk-CD2DK5JA.js} +135 -14
- package/{chunk-G6HJUMST.js → chunk-CJQBWHNM.js} +2 -2
- package/{chunk-EVGU5P4U.js → chunk-CO6E7YK6.js} +1 -1
- package/{chunk-ZYA2YDB6.js → chunk-CT5JXREL.js} +17 -17
- package/{chunk-VPAZ6BEN.js → chunk-CTWCZKNS.js} +42 -17
- package/{chunk-4OKTPFNX.js → chunk-CX2LYFZQ.js} +107 -66
- package/{chunk-YFLVRVYK.js → chunk-DLT2DN4M.js} +1 -1
- package/{chunk-LKA64WH4.js → chunk-DMPZMYH4.js} +37 -1
- package/{chunk-KFHREHUQ.js → chunk-DXWGFL2Z.js} +89 -1
- package/{chunk-OQHIVPG4.js → chunk-E6A5NHDH.js} +4 -1
- package/{chunk-IX2BXN2K.js → chunk-EDT65EUE.js} +6 -6
- package/{chunk-VP3BINY7.js → chunk-EQZZASCD.js} +31 -1
- package/{chunk-45LZIYXB.js → chunk-ESN4WNWU.js} +3 -2
- package/{chunk-M3JEW6N6.js → chunk-F26GAEH3.js} +10 -0
- package/{chunk-CVERLOJM.js → chunk-F4XIS5DL.js} +1215 -1431
- package/chunk-FDZ2GBWO.js +166 -0
- package/chunk-FGHEF6WI.js +34 -0
- package/{chunk-CSW7IPVD.js → chunk-FMYNIAI6.js} +61 -24
- package/{chunk-VIHDJ3FK.js → chunk-FNT5VENS.js} +15 -15
- package/{chunk-PMDVQBGA.js → chunk-GAHJLSDO.js} +14 -7
- package/{chunk-GRXSJR2Z.js → chunk-GVTFSLNI.js} +112 -109
- package/{chunk-UN7HIYMH.js → chunk-GX6DITLQ.js} +1 -1
- package/{chunk-3VFYQH3I.js → chunk-HIDVLMZC.js} +203 -156
- package/{chunk-5LQDHFBN.js → chunk-IDFGIROZ.js} +20 -17
- package/{chunk-UCFPVYP7.js → chunk-IFWXH7LH.js} +1 -1
- package/{chunk-LXTC53TN.js → chunk-J45ACAOQ.js} +815 -361
- package/{chunk-S6K5F3KP.js → chunk-JP2BH4NC.js} +1 -1
- package/{chunk-X2KRQP7V.js → chunk-JV5FHHF7.js} +1 -1
- package/{chunk-6EDAMVG6.js → chunk-K26XPZRB.js} +11 -11
- package/{chunk-RU6DULV4.js → chunk-KB5RQRSJ.js} +1 -1
- package/{chunk-T43K75CK.js → chunk-KC2QVCI7.js} +24 -178
- package/chunk-KK3FCYZM.js +647 -0
- package/{chunk-XZODOEKU.js → chunk-KMDHRVS7.js} +29 -5
- package/{chunk-4JVNURX4.js → chunk-KQHEGELM.js} +68 -16
- package/{chunk-UAPNPNSG.js → chunk-KW72WVHO.js} +2085 -1046
- package/{chunk-ILHQ2AXT.js → chunk-KZAT2M2V.js} +14 -8
- package/{chunk-L42CBKBZ.js → chunk-KZKMH374.js} +3 -3
- package/{chunk-ZI5SZ3MV.js → chunk-L6BLA6BT.js} +40 -31
- package/{chunk-AK5O76CC.js → chunk-LC5CVWP2.js} +3 -3
- package/{chunk-N5Z2V73W.js → chunk-LELADM5Q.js} +1 -1
- package/chunk-LHCGKAFO.js +739 -0
- package/{chunk-YOT437BH.js → chunk-LOF2EFUE.js} +203 -123
- package/{chunk-YQETUZ5V.js → chunk-LTVEOOZL.js} +29 -16
- package/{chunk-T2BEPTAG.js → chunk-MAA42MMV.js} +272 -26
- package/{chunk-NAOO4PVX.js → chunk-MECW2HJG.js} +16 -16
- package/{chunk-5HL4KC4A.js → chunk-MEDPR36J.js} +62 -87
- package/chunk-MVOZ22RZ.js +26 -0
- package/{chunk-YPPKC6FL.js → chunk-MYYNZG2M.js} +140 -40
- package/{chunk-UVUVQVZ6.js → chunk-MZVCFV3T.js} +19 -15
- package/{chunk-CQVGR3MX.js → chunk-N7MXFYLU.js} +7 -7
- package/{chunk-IC2I373Q.js → chunk-NEG5LYK5.js} +4 -4
- package/chunk-NJJK3PDA.js +133 -0
- package/{chunk-OB6DVWPF.js → chunk-OGZE6BZG.js} +331 -99
- package/{chunk-M3Y4IBIR.js → chunk-OHUYN3YU.js} +6 -6
- package/chunk-P27E22MA.js +203 -0
- package/{chunk-SFTTXGPM.js → chunk-PDAXMBLW.js} +35 -28
- package/{chunk-OBSEKCVK.js → chunk-PQ63BDV3.js} +210 -51
- package/{chunk-EUCFKKDM.js → chunk-PVFYPUIM.js} +40 -10
- package/{chunk-SRG5CNLC.js → chunk-QIVE5WJE.js} +8 -8
- package/{chunk-HOCHUZQ7.js → chunk-QJTZ76CP.js} +24 -6
- package/{chunk-5RKUPJYL.js → chunk-QLUYDJST.js} +11 -3
- package/{chunk-7Z6EW7AH.js → chunk-QOURTDZL.js} +97 -11
- package/{chunk-VZW34YUL.js → chunk-QWSH3UAQ.js} +8 -5
- package/{chunk-MK2Q7ZJD.js → chunk-R7XWZDOH.js} +58 -24
- package/{chunk-5FUN7EG4.js → chunk-RD3QLZQV.js} +83 -47
- package/{chunk-SW6OD4KE.js → chunk-RDPAIR67.js} +351 -18
- package/{chunk-NO3VBWTL.js → chunk-RXTZB2DH.js} +4 -4
- package/{chunk-AXYH4734.js → chunk-S25VJYXV.js} +21 -15
- package/{chunk-MWHOH4RJ.js → chunk-SESKIWB4.js} +6 -6
- package/{chunk-GUVXQSFZ.js → chunk-SF4GMDZO.js} +18 -108
- package/{chunk-TINJKQSO.js → chunk-SQRKAYQW.js} +25 -25
- package/chunk-SR4FE5VD.js +9 -0
- package/{chunk-3HTP4WZQ.js → chunk-SX6AWTNK.js} +46 -8
- package/{chunk-4WVJLODK.js → chunk-T23G6PXQ.js} +8 -3
- package/{chunk-CLCXHIBS.js → chunk-T4QY3HZ5.js} +1 -1
- package/{chunk-HVUDBOQG.js → chunk-TB5KTLNB.js} +9 -6
- package/{chunk-KRRE4A7D.js → chunk-TKE4OJ4B.js} +280 -56
- package/{chunk-S2NTVGA2.js → chunk-U35UUM5K.js} +2 -1
- package/{chunk-PPJYZRSQ.js → chunk-U5LOKQ2R.js} +30 -14
- package/{chunk-CKT6QUE2.js → chunk-UHW6SCVK.js} +1 -1
- package/{chunk-T5N6NHAT.js → chunk-UPOW5HTG.js} +6 -6
- package/{chunk-WJP4TH6U.js → chunk-VEVLLBFK.js} +2 -2
- package/{chunk-HGDKT2D6.js → chunk-VTHWBTRE.js} +177 -1
- package/{chunk-KJAAPGBE.js → chunk-VUHKG4KS.js} +6 -6
- package/{chunk-TOKPHZ55.js → chunk-W3HSD32M.js} +17 -10
- package/{chunk-2SKTCNWO.js → chunk-W5OJBZLZ.js} +4 -4
- package/chunk-WBSJAIZP.js +170 -0
- package/chunk-WDWZPASX.js +29 -0
- package/chunk-WFGNWWJI.js +326 -0
- package/{chunk-FIYSMXHY.js → chunk-WWTSEBDF.js} +1 -1
- package/{chunk-E2BESSAW.js → chunk-X4O7FJF5.js} +2 -0
- package/{chunk-HYKGIXNO.js → chunk-XGWRH3OF.js} +114 -29
- package/{chunk-XIEYGCN6.js → chunk-XKV53E4E.js} +460 -117
- package/{chunk-JHF6VLVL.js → chunk-XYRTC2Y3.js} +155 -170
- package/{chunk-L5I543VB.js → chunk-YGDYYFRX.js} +20 -24
- package/{chunk-ZADGPNTV.js → chunk-YHWMKGOX.js} +77 -103
- package/{chunk-6OVNSQHN.js → chunk-YLAHYLDQ.js} +5 -0
- package/chunk-Z6YTCDU4.js +24 -0
- package/{chunk-PVAWNHP5.js → chunk-ZP26NIZE.js} +647 -387
- package/{chunk-2G3YSVO6.js → chunk-ZQ6K57FJ.js} +3 -3
- package/{cliAgentConfigHelpers-QVSQYTKC.js → cliAgentConfigHelpers-37ZNEY5Y.js} +16 -16
- package/{cliAuthorityBrokerClient-XHH7MH2P.js → cliAuthorityBrokerClient-SFPC3WVK.js} +1 -1
- package/{cliEnvHelpers-D6HMC46Z.js → cliEnvHelpers-CNMP3RDX.js} +2 -2
- package/{cliExecutor-4MAX3PZL.js → cliExecutor-K6FDZTQ2.js} +3 -1
- package/cliLocalAgentRecordReader-53773JID.js +102 -0
- package/{commandRegistry-TKR6OWXP.js → commandRegistry-RJUO2VOD.js} +113 -101
- package/{contentThunks-BQWRPCTM.js → contentThunks-4EFHLUTB.js} +44 -41
- package/{cooldownCommands-FZYQOWI5.js → cooldownCommands-QL6DWGVU.js} +3 -3
- package/{createAgentAutomationAction-GFI6SJZV.js → createAgentAutomationAction-ZFFGJ7CZ.js} +44 -41
- package/{createDialogAction-MMBIHFFU.js → createDialogAction-SDUGVTPS.js} +45 -43
- package/{createPageAction-EEYUE5FB.js → createPageAction-NNM3OFLY.js} +49 -46
- package/{db-CS4ZJQKV.js → db-6NRZLEW2.js} +10 -7
- package/{dbSlice-X4Z4E4QU.js → dbSlice-5MQ3ELID.js} +16 -15
- package/{deleteFile-QOOP2UK7.js → deleteFile-VCCHS72Y.js} +12 -9
- package/{dialogCommands-OXBQ73DD.js → dialogCommands-SJK5KWXU.js} +73 -66
- package/dialogMessageRecord-OAV77LT7.js +7 -0
- package/{dialogNotifyCommand-VWS5G4OO.js → dialogNotifyCommand-PST75COP.js} +19 -19
- package/{dialogSlice-KGYIABDY.js → dialogSlice-2KLMHECR.js} +44 -41
- package/{dialogUsageCommand-FEWCN7IA.js → dialogUsageCommand-BZPKR3DW.js} +8 -8
- package/{docCreateCommands-LS32VKY3.js → docCreateCommands-K7CDL2HY.js} +66 -57
- package/{docDeleteCommands-JTYR5RPH.js → docDeleteCommands-ZEY5YCSP.js} +69 -60
- package/{docReadCommands-E5LTVKWN.js → docReadCommands-A4ROLIQG.js} +66 -57
- package/{docStore-TVS2FNER.js → docStore-A4O6YJAM.js} +19 -18
- package/{docUpdateCommands-I3J3JDZ2.js → docUpdateCommands-6HTFQY4O.js} +66 -57
- package/{fetchMessages-Q3INLN5F.js → fetchMessages-TQEUZD7H.js} +3 -3
- package/{getPricing-VNGFM4PN.js → getPricing-FCHYVRJU.js} +6 -6
- package/{handleSendMessageAction-SSON36TJ.js → handleSendMessageAction-6WEFYBUC.js} +87 -82
- package/{hostCredentialCreate-WTW4THJF.js → hostCredentialCreate-WOWCNOYM.js} +136 -123
- package/index.js +54 -16
- package/keys-RWF7UCB4.js +1 -1
- package/{lib-OT5OTXRU.js → lib-62SWPXNF.js} +3 -7
- package/{localDialogRead-V36DX2Q2.js → localDialogRead-3T2KMCRC.js} +2 -2
- package/{localRuntimeAdapter-MI2JGXSF.js → localRuntimeAdapter-7EDBDRYW.js} +147 -133
- package/{localRuntimeAuthority-IBJAT62G.js → localRuntimeAuthority-7DKIT7UH.js} +4 -2
- package/{localRuntimeDb-N7KHDXS2.js → localRuntimeDb-5WZ4RJJO.js} +1 -1
- package/{machineCommands-3LROJZDK.js → machineCommands-XRPC67LL.js} +290 -354
- package/machineWsRunDispatch-SOGFW472.js +203 -0
- package/markdownToSlate-KIYM7B3P.js +8 -0
- package/mcpLocalAuthorizeCommand-VOJARP3M.js +106 -0
- package/{memberThunks-CFEPHAND.js → memberThunks-KC3WJGL3.js} +26 -21
- package/{memoryCommands-JQMEJO7J.js → memoryCommands-BC6REPQB.js} +6 -6
- package/{models-H5NNZRLH.js → models-EP7VG6N2.js} +2 -2
- package/{overlay-THLKYIWY.js → overlay-JA3SPVUS.js} +7 -3
- package/package.json +1 -1
- package/{projectArchive-3X54XFVN.js → projectArchive-GDVPIZX2.js} +50 -47
- package/{providerPresetApply-FO36N5TX.js → providerPresetApply-4H7YP5D7.js} +9 -9
- package/{providerRegistry-U2BSFE6K.js → providerRegistry-F3UPOTIY.js} +9 -9
- package/{read-KA3L2V7O.js → read-T7VU2IMO.js} +11 -10
- package/{readDocTool-AMAZAPAW.js → readDocTool-BPQ3QJSD.js} +1 -1
- package/{readlineWorkspace-Z3YUH4SX.js → readlineWorkspace-OWQIIUGH.js} +9406 -6791
- package/rememberExplicit-CPAPONSI.js +15 -0
- package/{removeDialogAgentAction-JQOJSUM7.js → removeDialogAgentAction-FEUUVMYC.js} +23 -22
- package/{runAgentClientLoop-4FCFLMDJ.js → runAgentClientLoop-SJREK2B7.js} +107 -86
- package/{runtimeDoctorCommands-CXOCVDPU.js → runtimeDoctorCommands-XQD4MN4I.js} +19 -19
- package/{secretCommands-GGUAWAE7.js → secretCommands-LH7QTJO2.js} +3 -3
- package/{setDialogExtraReferencesAction-YXQTGXIN.js → setDialogExtraReferencesAction-JSTQJPXL.js} +19 -18
- package/{setPrimaryDialogAgentAction-YNLB66WE.js → setPrimaryDialogAgentAction-Z2BQE3IY.js} +23 -22
- package/{settingThunks-E6N7RSSS.js → settingThunks-C2YWCNYI.js} +186 -67
- package/{skillDiscovery-B5V23AXP.js → skillDiscovery-MDDKPTW3.js} +4 -3
- package/{spaceCommands-DB5DKC2J.js → spaceCommands-YRBQ52PG.js} +71 -62
- package/{store-JRVN62NM.js → store-Z53ICFL3.js} +3 -1
- package/{streamAgentChatTurn-FCBGMD4D.js → streamAgentChatTurn-NCA4BKDZ.js} +244 -185
- package/{switchDialogAgentAction-LAHLUECU.js → switchDialogAgentAction-G7XVAOGH.js} +20 -19
- package/{tableCommands-VNSXHAMG.js → tableCommands-UHEA5QNL.js} +14 -11
- package/{toolApiClient-OGQEBQVX.js → toolApiClient-N5PYW2R3.js} +8 -6
- package/{tools-6JD36D6K.js → tools-6WQVUGKV.js} +74 -70
- package/tuiRestart-3J7LRMPR.js +41 -0
- package/{tuiSummaryLlmCaller-UHZIPGAX.js → tuiSummaryLlmCaller-2J6NG53N.js} +24 -23
- package/{updateCommands-KZ54HCU5.js → updateCommands-5OYND6EF.js} +8 -6
- package/{updateDialogTitleAction-RV3EUEN3.js → updateDialogTitleAction-QCSN3RYO.js} +46 -43
- package/{usageCommand-KFVV6UL3.js → usageCommand-SK7JTEPC.js} +3 -3
- package/{usageRebuildCommand-HHFSNK46.js → usageRebuildCommand-DF3HUP6F.js} +4 -4
- package/webapi-QVV65DQF.js +2487 -0
- package/{windowsSelfUpdate-KERHIAB4.js → windowsSelfUpdate-HIYNL3VR.js} +2 -2
- package/workContext-Y3ADAPZU.js +14 -0
- package/workContextAccess-UZHDLBUR.js +11 -0
- package/workContextWriteNotice-YCSSMHN4.js +7 -0
- package/{workloadLifecycle-O2I3NZ2Q.js → workloadLifecycle-ZCSQCHG3.js} +9 -9
- package/agentListCommands-C65UESYM.js +0 -1004
- package/agentRecordCommands-6RCJS2EY.js +0 -176
- package/agentRunCommand-P3GRKXKS.js +0 -208
- package/chunk-2WZXXAQD.js +0 -57
- package/chunk-5ZMIIR23.js +0 -265
- package/chunk-62HXNQVV.js +0 -134
- package/chunk-BJF2MHJ3.js +0 -118
- package/chunk-KEPOVMF4.js +0 -91
- package/chunk-PXKF5CV4.js +0 -357
- package/chunk-WACI5I6V.js +0 -147
- package/chunk-YGILMZ7N.js +0 -81
- package/cliLocalAgentRecordReader-SPKAJYME.js +0 -90
- package/machineWsRunDispatch-BUUJRUUB.js +0 -191
- package/{accountResolver-EK2S4PWF.js → accountResolver-QETKNC7T.js} +4 -4
- package/{chunk-VXL2FZTP.js → chunk-HXER7YJF.js} +3 -3
- package/{chunk-BLVSFYQ3.js → chunk-LISC7BD4.js} +3 -3
- package/{chunk-SSGTV4FC.js → chunk-USGHJSGO.js} +5 -5
- package/{chunk-FJ23FZXF.js → chunk-VIYVRPMJ.js} +0 -0
- package/{offlineMarxistsAgentCommand-AGA2X5E4.js → offlineMarxistsAgentCommand-XVXUE6G5.js} +5 -5
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
|
+
AGENT_PROMPT_IN_MESSAGES,
|
|
2
3
|
DEVIN_CONNECT_URL,
|
|
3
4
|
parseSseDataLineJson,
|
|
4
5
|
parseSseDataLineObject
|
|
5
|
-
} from "./chunk-
|
|
6
|
-
import {
|
|
7
|
-
evaluateFileWritePolicy,
|
|
8
|
-
summarizeToolArguments
|
|
9
|
-
} from "./chunk-CHOZJMJS.js";
|
|
6
|
+
} from "./chunk-MYYNZG2M.js";
|
|
10
7
|
import {
|
|
8
|
+
ALWAYS_EXCLUDED_GLOBS,
|
|
11
9
|
EXECUTION_BACKEND_KINDS
|
|
12
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-ANUP75N2.js";
|
|
13
11
|
import {
|
|
14
12
|
formatImageSummary,
|
|
15
13
|
readLocalImage
|
|
@@ -22,27 +20,19 @@ import {
|
|
|
22
20
|
flushChatCompletionStream,
|
|
23
21
|
providerHttpFailure,
|
|
24
22
|
throwIfChatCompletionStreamFailed
|
|
25
|
-
} from "./chunk-
|
|
23
|
+
} from "./chunk-EDT65EUE.js";
|
|
26
24
|
import {
|
|
27
25
|
readSseFrames
|
|
28
26
|
} from "./chunk-HNUWUO75.js";
|
|
29
27
|
import {
|
|
30
|
-
|
|
31
|
-
|
|
28
|
+
evaluateFileWritePolicy,
|
|
29
|
+
summarizeToolArguments
|
|
30
|
+
} from "./chunk-CHOZJMJS.js";
|
|
32
31
|
import {
|
|
33
32
|
evaluateRequestBudget,
|
|
34
33
|
hasImageInRuntimeMessages,
|
|
35
34
|
stripImagePartsFromMessages
|
|
36
|
-
} from "./chunk-
|
|
37
|
-
import {
|
|
38
|
-
clipToolText,
|
|
39
|
-
resolveHistoricalToolContentCap,
|
|
40
|
-
resolveToolOutputProfile
|
|
41
|
-
} from "./chunk-2WZXXAQD.js";
|
|
42
|
-
import {
|
|
43
|
-
resolveAgentImageInputSupport,
|
|
44
|
-
resolveToolImagePolicy
|
|
45
|
-
} from "./chunk-3HTP4WZQ.js";
|
|
35
|
+
} from "./chunk-4OXPN3WC.js";
|
|
46
36
|
import {
|
|
47
37
|
applyShapingCounts,
|
|
48
38
|
attachProjectionFacts,
|
|
@@ -53,7 +43,7 @@ import {
|
|
|
53
43
|
projectUserPartForModel,
|
|
54
44
|
resolveOutboundDiagnosticSink,
|
|
55
45
|
writeThinkingFacts
|
|
56
|
-
} from "./chunk-
|
|
46
|
+
} from "./chunk-2FK2KZSL.js";
|
|
57
47
|
import {
|
|
58
48
|
createThinkParserState,
|
|
59
49
|
createToolCallAccumulator,
|
|
@@ -62,16 +52,9 @@ import {
|
|
|
62
52
|
finalizeAccumulatedToolCalls
|
|
63
53
|
} from "./chunk-56GBUMO5.js";
|
|
64
54
|
import {
|
|
65
|
-
CREDENTIAL_HYGIENE_RULE,
|
|
66
|
-
DELETE_SAFETY_RED_LINE,
|
|
67
|
-
DISPATCH_BACKEND_POLICY,
|
|
68
|
-
DISPATCH_CANDIDATE_POLICY,
|
|
69
|
-
PARALLEL_DISPATCH_DEFAULT_RULE,
|
|
70
|
-
PLATFORM_RISK_CONTROL_RULE,
|
|
71
55
|
TOOL_GUIDED_SECTION_ORDER,
|
|
72
|
-
VERIFY_BEFORE_CONCLUDING_RULE,
|
|
73
|
-
buildConsultationModeBlock,
|
|
74
56
|
buildIdentityBlock,
|
|
57
|
+
buildPlatformStaticScopedBlocks,
|
|
75
58
|
buildRuntimeGuidanceBlocks,
|
|
76
59
|
detectDispatchIntent,
|
|
77
60
|
detectDispatchIntentFromMessages,
|
|
@@ -79,7 +62,7 @@ import {
|
|
|
79
62
|
hashStablePrefixContent,
|
|
80
63
|
resolveResponseGuidelines,
|
|
81
64
|
resolveToolGuidedSections
|
|
82
|
-
} from "./chunk-
|
|
65
|
+
} from "./chunk-HIDVLMZC.js";
|
|
83
66
|
import {
|
|
84
67
|
BRIDGE_STREAM_MAX_CHARS,
|
|
85
68
|
CLI_NOLO_WORKSPACE_TOOL_NAMES,
|
|
@@ -94,10 +77,7 @@ import {
|
|
|
94
77
|
parseNoloWorkspaceToolArguments,
|
|
95
78
|
readTextStreamUpToChars,
|
|
96
79
|
resolveNoloDialogInput
|
|
97
|
-
} from "./chunk-
|
|
98
|
-
import {
|
|
99
|
-
applyToolSurfaceConstraints
|
|
100
|
-
} from "./chunk-IC2I373Q.js";
|
|
80
|
+
} from "./chunk-LOF2EFUE.js";
|
|
101
81
|
import {
|
|
102
82
|
classifyUnparsableToolArgs,
|
|
103
83
|
collectStablePromptPrefix,
|
|
@@ -121,7 +101,7 @@ import {
|
|
|
121
101
|
toOpenAiCompatibleMessages,
|
|
122
102
|
toResponsesTools,
|
|
123
103
|
transferDowngradedToolTurnOrigin
|
|
124
|
-
} from "./chunk-
|
|
104
|
+
} from "./chunk-W3HSD32M.js";
|
|
125
105
|
import {
|
|
126
106
|
TOOL_HAD_IMAGES,
|
|
127
107
|
TOOL_IMAGES,
|
|
@@ -134,13 +114,35 @@ import {
|
|
|
134
114
|
toolImageDelivery,
|
|
135
115
|
toolImages,
|
|
136
116
|
withoutToolImages
|
|
137
|
-
} from "./chunk-
|
|
117
|
+
} from "./chunk-X4O7FJF5.js";
|
|
138
118
|
import {
|
|
119
|
+
resolveToolExecutionContract
|
|
120
|
+
} from "./chunk-DMPZMYH4.js";
|
|
121
|
+
import {
|
|
122
|
+
resolveAgentImageInputSupport,
|
|
123
|
+
resolveToolImagePolicy
|
|
124
|
+
} from "./chunk-SX6AWTNK.js";
|
|
125
|
+
import {
|
|
126
|
+
isContextOverflowText,
|
|
139
127
|
isQuotaExhaustedError
|
|
140
128
|
} from "./chunk-TLE77UJ5.js";
|
|
129
|
+
import {
|
|
130
|
+
PROJECT_INSTRUCTION_MAX_BYTES,
|
|
131
|
+
PROJECT_INSTRUCTION_MAX_CHARS,
|
|
132
|
+
SECRET_PATTERNS,
|
|
133
|
+
clipToolText,
|
|
134
|
+
hasPotentialSecrets,
|
|
135
|
+
isCompleteInstructionOutput,
|
|
136
|
+
resolveHistoricalToolContentCap,
|
|
137
|
+
resolveToolOutputProfile,
|
|
138
|
+
sanitizeToolOutputContent,
|
|
139
|
+
sanitizeToolOutputText,
|
|
140
|
+
scrubObjectSecrets,
|
|
141
|
+
scrubSecrets
|
|
142
|
+
} from "./chunk-WFGNWWJI.js";
|
|
141
143
|
import {
|
|
142
144
|
isAgentSkillDisabled
|
|
143
|
-
} from "./chunk-
|
|
145
|
+
} from "./chunk-JV5FHHF7.js";
|
|
144
146
|
import {
|
|
145
147
|
buildDialogFallbackTitleFromUserInput
|
|
146
148
|
} from "./chunk-2MBTWINN.js";
|
|
@@ -152,15 +154,18 @@ import {
|
|
|
152
154
|
resolveEmptyAssistantFallbackMessage,
|
|
153
155
|
resolveEmptyAssistantOutcome,
|
|
154
156
|
resolveTruncatedReasoningTailLog
|
|
155
|
-
} from "./chunk-
|
|
157
|
+
} from "./chunk-LTVEOOZL.js";
|
|
156
158
|
import {
|
|
157
159
|
COMPACTION_SUMMARY_SCHEMA_VERSION,
|
|
158
160
|
COMPACTION_SUMMARY_SYSTEM_PROMPT,
|
|
159
|
-
buildBoundedCompactionRequest,
|
|
160
161
|
buildCompactionMetricsFromPlan,
|
|
162
|
+
buildHistoricalCompactionRequest,
|
|
163
|
+
buildSummarySourceDiagnostics,
|
|
164
|
+
buildSummarySourceSegments,
|
|
161
165
|
classifySummaryError,
|
|
162
166
|
computeSummarySourceMetadata,
|
|
163
167
|
createSummaryBudget,
|
|
168
|
+
diffSummarySourceSegments,
|
|
164
169
|
formatCompactionMetricsLog,
|
|
165
170
|
getMessageTokenCount,
|
|
166
171
|
getModelContextWindow,
|
|
@@ -172,10 +177,9 @@ import {
|
|
|
172
177
|
resolveCompressionTriggerRatio,
|
|
173
178
|
resolveEffectiveCompactionBudgets,
|
|
174
179
|
runSummaryWithContract,
|
|
175
|
-
sha256Hex,
|
|
176
180
|
summaryCompletionTokens,
|
|
177
181
|
truncateToolOutputForContext
|
|
178
|
-
} from "./chunk-
|
|
182
|
+
} from "./chunk-MAA42MMV.js";
|
|
179
183
|
import {
|
|
180
184
|
createProviderCallTimingTracker,
|
|
181
185
|
finalizeProviderCallTiming,
|
|
@@ -183,6 +187,9 @@ import {
|
|
|
183
187
|
observeMeaningfulProviderResponse,
|
|
184
188
|
withProviderCallTimingFields
|
|
185
189
|
} from "./chunk-H57T64RA.js";
|
|
190
|
+
import {
|
|
191
|
+
sha256Hex
|
|
192
|
+
} from "./chunk-SR4FE5VD.js";
|
|
186
193
|
import {
|
|
187
194
|
clipCompactText
|
|
188
195
|
} from "./chunk-5MMAK75Q.js";
|
|
@@ -190,14 +197,14 @@ import {
|
|
|
190
197
|
asRecordOrEmpty
|
|
191
198
|
} from "./chunk-KX6YBIHG.js";
|
|
192
199
|
import {
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
import {
|
|
200
|
+
TOOL_OUTPUT_SPILL_BYTES,
|
|
201
|
+
TOOL_OUTPUT_SPILL_LINES,
|
|
196
202
|
buildInteractiveCommandBlockedResult,
|
|
197
203
|
buildProcessTaskResultCapsule,
|
|
198
204
|
buildWorkspaceShellCommand,
|
|
199
205
|
buildWorkspaceShellEscapeBlockedResult,
|
|
200
206
|
buildWorkspaceShellPlan,
|
|
207
|
+
countLines,
|
|
201
208
|
createGlob,
|
|
202
209
|
deriveLabel,
|
|
203
210
|
extractActivity,
|
|
@@ -216,7 +223,7 @@ import {
|
|
|
216
223
|
spillToolOutput,
|
|
217
224
|
toProcessTaskView,
|
|
218
225
|
truncateToolOutput
|
|
219
|
-
} from "./chunk-
|
|
226
|
+
} from "./chunk-TB5KTLNB.js";
|
|
220
227
|
import {
|
|
221
228
|
estimateTokenCount
|
|
222
229
|
} from "./chunk-PSCNXBYA.js";
|
|
@@ -227,56 +234,69 @@ import {
|
|
|
227
234
|
isAbortError
|
|
228
235
|
} from "./chunk-7DPNBQSV.js";
|
|
229
236
|
import {
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
} from "./chunk-HNMXYYJR.js";
|
|
236
|
-
import {
|
|
237
|
-
WORKTREE_ISOLATION_PRELUDE
|
|
238
|
-
} from "./chunk-KRRE4A7D.js";
|
|
239
|
-
import {
|
|
240
|
-
canonicalizeToolName,
|
|
241
|
-
canonicalizeToolNames
|
|
242
|
-
} from "./chunk-6OVNSQHN.js";
|
|
243
|
-
import {
|
|
244
|
-
isRecord
|
|
245
|
-
} from "./chunk-KUG52IAP.js";
|
|
246
|
-
import {
|
|
247
|
-
PLATFORM_HOSTED_DEEPSEEK_FLASH_MODEL
|
|
248
|
-
} from "./chunk-OBSEKCVK.js";
|
|
249
|
-
import {
|
|
250
|
-
asTrimmedLowercaseString
|
|
251
|
-
} from "./chunk-QSJ3HFEF.js";
|
|
252
|
-
import {
|
|
253
|
-
buildDialogSummaryLayer
|
|
254
|
-
} from "./chunk-JWXITTQB.js";
|
|
237
|
+
buildAgentsMdLayer,
|
|
238
|
+
buildAgentsMdLayerHeader,
|
|
239
|
+
buildDialogSummaryLayer,
|
|
240
|
+
hasMemoryTools
|
|
241
|
+
} from "./chunk-5HUO7SEX.js";
|
|
255
242
|
import {
|
|
243
|
+
MEMORY_USE_GUIDANCE,
|
|
256
244
|
buildUserResponseLanguageContext
|
|
257
|
-
} from "./chunk-
|
|
258
|
-
import {
|
|
259
|
-
normalizeServerOrigin
|
|
260
|
-
} from "./chunk-CF7PE763.js";
|
|
245
|
+
} from "./chunk-YGDYYFRX.js";
|
|
261
246
|
import {
|
|
262
247
|
resolveNoloStateDir
|
|
263
248
|
} from "./chunk-6UBGXX2W.js";
|
|
249
|
+
import {
|
|
250
|
+
isTombstoneRecord
|
|
251
|
+
} from "./chunk-BV3FLP2L.js";
|
|
252
|
+
import {
|
|
253
|
+
dialogMessageRecordToAgentRuntimeMessage
|
|
254
|
+
} from "./chunk-4ZCTKB27.js";
|
|
264
255
|
import {
|
|
265
256
|
dialogMessageKey,
|
|
266
257
|
dialogMessageRange
|
|
267
258
|
} from "./chunk-OJKUU3LP.js";
|
|
259
|
+
import {
|
|
260
|
+
resolveLocalUserId
|
|
261
|
+
} from "./chunk-UPOW5HTG.js";
|
|
262
|
+
import {
|
|
263
|
+
applyToolSurfaceConstraints
|
|
264
|
+
} from "./chunk-NEG5LYK5.js";
|
|
265
|
+
import {
|
|
266
|
+
canonicalizeToolName,
|
|
267
|
+
canonicalizeToolNames
|
|
268
|
+
} from "./chunk-YLAHYLDQ.js";
|
|
268
269
|
import {
|
|
269
270
|
asTrimmedNonEmptyStringArray
|
|
270
271
|
} from "./chunk-I42VC5KR.js";
|
|
272
|
+
import {
|
|
273
|
+
asOptionalPositiveFiniteNumber
|
|
274
|
+
} from "./chunk-U6VC4MU4.js";
|
|
275
|
+
import {
|
|
276
|
+
toErrorMessage
|
|
277
|
+
} from "./chunk-HNMXYYJR.js";
|
|
278
|
+
import {
|
|
279
|
+
buildProviderAuthHeaders,
|
|
280
|
+
buildProviderExecutionPlan
|
|
281
|
+
} from "./chunk-K26XPZRB.js";
|
|
271
282
|
import {
|
|
272
283
|
asTrimmedString
|
|
273
284
|
} from "./chunk-3EUW3WEO.js";
|
|
274
285
|
import {
|
|
275
|
-
|
|
276
|
-
} from "./chunk-
|
|
286
|
+
isRecord
|
|
287
|
+
} from "./chunk-KUG52IAP.js";
|
|
277
288
|
import {
|
|
278
289
|
asOptionalTrimmedString
|
|
279
290
|
} from "./chunk-G3SUCT4W.js";
|
|
291
|
+
import {
|
|
292
|
+
normalizeServerOrigin
|
|
293
|
+
} from "./chunk-CF7PE763.js";
|
|
294
|
+
import {
|
|
295
|
+
PLATFORM_HOSTED_DEEPSEEK_FLASH_MODEL
|
|
296
|
+
} from "./chunk-PQ63BDV3.js";
|
|
297
|
+
import {
|
|
298
|
+
asTrimmedLowercaseString
|
|
299
|
+
} from "./chunk-QSJ3HFEF.js";
|
|
280
300
|
import {
|
|
281
301
|
__export
|
|
282
302
|
} from "./chunk-U67V476Y.js";
|
|
@@ -323,6 +343,36 @@ function readTitleParams(value) {
|
|
|
323
343
|
return Object.fromEntries(entries);
|
|
324
344
|
}
|
|
325
345
|
|
|
346
|
+
// packages/agent-runtime/dialogHistoryOrder.ts
|
|
347
|
+
import { decodeTime } from "ulid";
|
|
348
|
+
function orderDialogHistory(messages) {
|
|
349
|
+
const time = (message) => {
|
|
350
|
+
if (Number.isFinite(message.cliHistoryOrder)) return message.cliHistoryOrder;
|
|
351
|
+
const id = message.id ?? message.cliMessageId;
|
|
352
|
+
if (!id) return Infinity;
|
|
353
|
+
const timestamp = /^(\d+)-/.exec(id);
|
|
354
|
+
if (timestamp) return Number(timestamp[1]);
|
|
355
|
+
if (/^[0-9A-HJKMNP-TV-Z]{26}$/.test(id)) {
|
|
356
|
+
try {
|
|
357
|
+
return decodeTime(id);
|
|
358
|
+
} catch {
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
return Number.isFinite(message.createdAt) ? message.createdAt : -Infinity;
|
|
362
|
+
};
|
|
363
|
+
const identity2 = (message) => message.id ?? message.cliMessageId;
|
|
364
|
+
return messages.map((message, index) => ({ message, index, time: time(message) })).sort((a, b) => {
|
|
365
|
+
if (a.time !== b.time) return a.time < b.time ? -1 : 1;
|
|
366
|
+
const left = identity2(a.message), right = identity2(b.message);
|
|
367
|
+
if (left && right && left !== right) return left < right ? -1 : 1;
|
|
368
|
+
return a.index - b.index;
|
|
369
|
+
}).map(({ message }) => message);
|
|
370
|
+
}
|
|
371
|
+
function dialogTurnUserMessageId(turnId, index) {
|
|
372
|
+
if (typeof turnId !== "string" || !/^turn-[0-9A-HJKMNP-TV-Z]{26}$/.test(turnId)) return void 0;
|
|
373
|
+
return `${decodeTime(turnId.slice(5))}-${String(index + 1).padStart(3, "0")}-${turnId}`;
|
|
374
|
+
}
|
|
375
|
+
|
|
326
376
|
// packages/agent-runtime/contextRefusal.ts
|
|
327
377
|
var machineIdentifier = (value) => value && /^[A-Z][A-Z0-9_]{0,63}$/.test(value) ? value : void 0;
|
|
328
378
|
function classifyContextRefusal(args2) {
|
|
@@ -5548,8 +5598,8 @@ var runPromiseExitWith = (context3) => {
|
|
|
5548
5598
|
const runFork3 = runForkWith(context3);
|
|
5549
5599
|
return (effect, options) => {
|
|
5550
5600
|
const fiber3 = runFork3(effect, options);
|
|
5551
|
-
return new Promise((
|
|
5552
|
-
fiber3.addObserver((exit3) =>
|
|
5601
|
+
return new Promise((resolve7) => {
|
|
5602
|
+
fiber3.addObserver((exit3) => resolve7(exit3));
|
|
5553
5603
|
});
|
|
5554
5604
|
};
|
|
5555
5605
|
};
|
|
@@ -12772,8 +12822,8 @@ var toReadableStreamWith = /* @__PURE__ */ dual((args2) => isStream(args2[0]), (
|
|
|
12772
12822
|
}
|
|
12773
12823
|
},
|
|
12774
12824
|
pull() {
|
|
12775
|
-
return new Promise((
|
|
12776
|
-
currentResolve =
|
|
12825
|
+
return new Promise((resolve7) => {
|
|
12826
|
+
currentResolve = resolve7;
|
|
12777
12827
|
latch.openUnsafe();
|
|
12778
12828
|
});
|
|
12779
12829
|
},
|
|
@@ -13307,255 +13357,6 @@ function sanitizeToolCallPairing(messages) {
|
|
|
13307
13357
|
return output;
|
|
13308
13358
|
}
|
|
13309
13359
|
|
|
13310
|
-
// packages/agent-runtime/secretScrubber.ts
|
|
13311
|
-
var SECRET_PATTERNS = [
|
|
13312
|
-
// 1. PEM 私钥块(高危硬拦截)
|
|
13313
|
-
{
|
|
13314
|
-
kind: "PRIVATE_KEY",
|
|
13315
|
-
placeholder: "[REDACTED:PRIVATE_KEY]",
|
|
13316
|
-
regex: /-----BEGIN (?:[A-Z0-9 ]+)?PRIVATE KEY-----[\s\S]+?-----END (?:[A-Z0-9 ]+)?PRIVATE KEY-----/g
|
|
13317
|
-
},
|
|
13318
|
-
// 2. Anthropic API Key (sk-ant-...)
|
|
13319
|
-
{
|
|
13320
|
-
kind: "ANTHROPIC_KEY",
|
|
13321
|
-
placeholder: "[REDACTED:ANTHROPIC_KEY]",
|
|
13322
|
-
regex: /\bsk-ant-[a-zA-Z0-9_\-]{20,}\b/g
|
|
13323
|
-
},
|
|
13324
|
-
// 3. OpenAI / DeepSeek / 通用 API Key (sk-...)
|
|
13325
|
-
{
|
|
13326
|
-
kind: "API_KEY",
|
|
13327
|
-
placeholder: "[REDACTED:API_KEY]",
|
|
13328
|
-
regex: /\bsk-[a-zA-Z0-9_\-]{24,}\b/g
|
|
13329
|
-
},
|
|
13330
|
-
// 3b. BigModel / 智谱(GLM)API Key:32 位 hex + "." + 16 位字母数字
|
|
13331
|
-
// (2026-11 实证:这类 key 没有任何可辨识前缀,此前漏在清洗与入路隔离之外,
|
|
13332
|
-
// 用户贴进对话后明文直接进了 prompt / 历史 / 工具日志。)
|
|
13333
|
-
{
|
|
13334
|
-
kind: "BIGMODEL_KEY",
|
|
13335
|
-
placeholder: "[REDACTED:BIGMODEL_KEY]",
|
|
13336
|
-
regex: /\b[0-9a-fA-F]{32}\.[A-Za-z0-9]{16}\b/g
|
|
13337
|
-
},
|
|
13338
|
-
// 4. GitHub 访问令牌 (ghp_..., gho_..., github_pat_...)
|
|
13339
|
-
{
|
|
13340
|
-
kind: "GITHUB_TOKEN",
|
|
13341
|
-
placeholder: "[REDACTED:GITHUB_TOKEN]",
|
|
13342
|
-
regex: /\b(?:gh[pousr]_[a-zA-Z0-9]{30,}|github_pat_[a-zA-Z0-9_]{40,})\b/g
|
|
13343
|
-
},
|
|
13344
|
-
// 5. Bearer Token (JWT / Authorization Bearer)
|
|
13345
|
-
{
|
|
13346
|
-
kind: "BEARER_TOKEN",
|
|
13347
|
-
placeholder: "Bearer [REDACTED:BEARER_TOKEN]",
|
|
13348
|
-
regex: /\bBearer\s+[a-zA-Z0-9_\-\.]{25,}\b/gi
|
|
13349
|
-
},
|
|
13350
|
-
// 6. 常见环境变量或配置中的密码赋值 (PASSWORD=..., PASSWD=...)
|
|
13351
|
-
{
|
|
13352
|
-
kind: "PASSWORD",
|
|
13353
|
-
placeholder: "$1=[REDACTED:PASSWORD]",
|
|
13354
|
-
regex: /\b((?:DB_|DATABASE_|ADMIN_|ROOT_|MYSQL_|POSTGRES_)?(?:PASSWORD|PASSWD|SECRET_KEY))\s*=\s*['"]?([^\s'"]{4,})['"]?/gi
|
|
13355
|
-
}
|
|
13356
|
-
];
|
|
13357
|
-
var QUICK_PROBE_SUBSTRINGS = [
|
|
13358
|
-
"sk-",
|
|
13359
|
-
"ghp_",
|
|
13360
|
-
"gho_",
|
|
13361
|
-
"ghu_",
|
|
13362
|
-
"ghs_",
|
|
13363
|
-
"ghr_",
|
|
13364
|
-
"github_pat_",
|
|
13365
|
-
"PRIVATE KEY",
|
|
13366
|
-
"Bearer ",
|
|
13367
|
-
"bearer ",
|
|
13368
|
-
"PASSWORD",
|
|
13369
|
-
"password",
|
|
13370
|
-
"PASSWD",
|
|
13371
|
-
"SECRET_KEY"
|
|
13372
|
-
];
|
|
13373
|
-
var UNPREFIXED_PROBE_REGEX = /\b[0-9a-fA-F]{32}\.[A-Za-z0-9]{16}\b/;
|
|
13374
|
-
function hasPotentialSecrets(text2) {
|
|
13375
|
-
if (typeof text2 !== "string" || text2.length === 0) return false;
|
|
13376
|
-
if (QUICK_PROBE_SUBSTRINGS.some((probe) => text2.includes(probe))) return true;
|
|
13377
|
-
return UNPREFIXED_PROBE_REGEX.test(text2);
|
|
13378
|
-
}
|
|
13379
|
-
function scrubSecrets(text2) {
|
|
13380
|
-
if (typeof text2 !== "string" || text2.length === 0) {
|
|
13381
|
-
return { cleaned: text2, redactedCount: 0, matchedKinds: [] };
|
|
13382
|
-
}
|
|
13383
|
-
if (!hasPotentialSecrets(text2)) {
|
|
13384
|
-
return { cleaned: text2, redactedCount: 0, matchedKinds: [] };
|
|
13385
|
-
}
|
|
13386
|
-
let cleaned = text2;
|
|
13387
|
-
let redactedCount = 0;
|
|
13388
|
-
const matchedKinds = [];
|
|
13389
|
-
for (const pattern of SECRET_PATTERNS) {
|
|
13390
|
-
pattern.regex.lastIndex = 0;
|
|
13391
|
-
const matches = cleaned.match(pattern.regex);
|
|
13392
|
-
if (matches && matches.length > 0) {
|
|
13393
|
-
redactedCount += matches.length;
|
|
13394
|
-
if (!matchedKinds.includes(pattern.kind)) {
|
|
13395
|
-
matchedKinds.push(pattern.kind);
|
|
13396
|
-
}
|
|
13397
|
-
cleaned = cleaned.replace(pattern.regex, pattern.placeholder);
|
|
13398
|
-
}
|
|
13399
|
-
}
|
|
13400
|
-
return { cleaned, redactedCount, matchedKinds };
|
|
13401
|
-
}
|
|
13402
|
-
function scrubObjectSecrets(val) {
|
|
13403
|
-
if (val === null || val === void 0) return val;
|
|
13404
|
-
if (typeof val === "string") {
|
|
13405
|
-
return scrubSecrets(val).cleaned;
|
|
13406
|
-
}
|
|
13407
|
-
if (Array.isArray(val)) {
|
|
13408
|
-
return val.map((item) => scrubObjectSecrets(item));
|
|
13409
|
-
}
|
|
13410
|
-
if (typeof val === "object") {
|
|
13411
|
-
if (val instanceof Date || val instanceof RegExp) return val;
|
|
13412
|
-
const result4 = {};
|
|
13413
|
-
for (const [k, v] of Object.entries(val)) {
|
|
13414
|
-
result4[k] = scrubObjectSecrets(v);
|
|
13415
|
-
}
|
|
13416
|
-
return result4;
|
|
13417
|
-
}
|
|
13418
|
-
return val;
|
|
13419
|
-
}
|
|
13420
|
-
|
|
13421
|
-
// packages/agent-runtime/toolOutputSanitizer.ts
|
|
13422
|
-
var SANITIZE_REPLACEMENT_CHAR = "\uFFFD";
|
|
13423
|
-
var MAX_CONTROL_SEQUENCE_CHARS = 256;
|
|
13424
|
-
var ESC = 27;
|
|
13425
|
-
var BEL = 7;
|
|
13426
|
-
var LINE_FEED = 10;
|
|
13427
|
-
var TAB = 9;
|
|
13428
|
-
var DEL = 127;
|
|
13429
|
-
var C1_DCS = 144;
|
|
13430
|
-
var C1_SOS = 152;
|
|
13431
|
-
var C1_CSI = 155;
|
|
13432
|
-
var C1_ST = 156;
|
|
13433
|
-
var C1_OSC = 157;
|
|
13434
|
-
var C1_PM = 158;
|
|
13435
|
-
var C1_APC = 159;
|
|
13436
|
-
var HIGH_SURROGATE_MIN = 55296;
|
|
13437
|
-
var HIGH_SURROGATE_MAX = 56319;
|
|
13438
|
-
var LOW_SURROGATE_MIN = 56320;
|
|
13439
|
-
var LOW_SURROGATE_MAX = 57343;
|
|
13440
|
-
var NEEDS_SANITIZE_RE = new RegExp("[\\u0000-\\u0008\\u000b-\\u001f\\u007f-\\u009f]|\\p{Cs}", "u");
|
|
13441
|
-
function isC1Introducer(code) {
|
|
13442
|
-
return code === C1_CSI || code === C1_OSC || code === C1_DCS || code === C1_SOS || code === C1_PM || code === C1_APC;
|
|
13443
|
-
}
|
|
13444
|
-
var UNTERMINATED_SEQUENCE = -1;
|
|
13445
|
-
function skipCsiBody(text2, start, limit) {
|
|
13446
|
-
let i = start;
|
|
13447
|
-
while (i < limit) {
|
|
13448
|
-
const code = text2.charCodeAt(i);
|
|
13449
|
-
if (code >= 64 && code <= 126) return i + 1;
|
|
13450
|
-
if (code >= 32 && code <= 63) {
|
|
13451
|
-
i += 1;
|
|
13452
|
-
continue;
|
|
13453
|
-
}
|
|
13454
|
-
return i;
|
|
13455
|
-
}
|
|
13456
|
-
return UNTERMINATED_SEQUENCE;
|
|
13457
|
-
}
|
|
13458
|
-
function skipControlStringBody(text2, start, limit) {
|
|
13459
|
-
const length = text2.length;
|
|
13460
|
-
let i = start;
|
|
13461
|
-
while (i < limit) {
|
|
13462
|
-
const code = text2.charCodeAt(i);
|
|
13463
|
-
if (code === BEL || code === C1_ST) return i + 1;
|
|
13464
|
-
if (code === ESC && i + 1 < length && text2.charCodeAt(i + 1) === 92) {
|
|
13465
|
-
return Math.min(i + 2, limit);
|
|
13466
|
-
}
|
|
13467
|
-
i += 1;
|
|
13468
|
-
}
|
|
13469
|
-
return UNTERMINATED_SEQUENCE;
|
|
13470
|
-
}
|
|
13471
|
-
function skipEscapeSequence(text2, escIndex) {
|
|
13472
|
-
const length = text2.length;
|
|
13473
|
-
const limit = Math.min(length, escIndex + MAX_CONTROL_SEQUENCE_CHARS);
|
|
13474
|
-
const leadIndex = escIndex + 1;
|
|
13475
|
-
if (leadIndex >= length) return leadIndex;
|
|
13476
|
-
const lead = text2.charCodeAt(leadIndex);
|
|
13477
|
-
if (lead === 91) {
|
|
13478
|
-
const csiEnd = skipCsiBody(text2, leadIndex + 1, limit);
|
|
13479
|
-
return csiEnd === UNTERMINATED_SEQUENCE ? escIndex + 1 : csiEnd;
|
|
13480
|
-
}
|
|
13481
|
-
if (lead === 93 || lead === 80 || lead === 88 || lead === 94 || lead === 95) {
|
|
13482
|
-
const stringEnd = skipControlStringBody(text2, leadIndex + 1, limit);
|
|
13483
|
-
return stringEnd === UNTERMINATED_SEQUENCE ? escIndex + 1 : stringEnd;
|
|
13484
|
-
}
|
|
13485
|
-
let j = leadIndex;
|
|
13486
|
-
while (j < limit && text2.charCodeAt(j) >= 32 && text2.charCodeAt(j) <= 47) {
|
|
13487
|
-
j += 1;
|
|
13488
|
-
}
|
|
13489
|
-
if (j < limit) {
|
|
13490
|
-
const final = text2.charCodeAt(j);
|
|
13491
|
-
if (final >= 48 && final <= 126) return j + 1;
|
|
13492
|
-
}
|
|
13493
|
-
return escIndex + 1;
|
|
13494
|
-
}
|
|
13495
|
-
function skipC1Sequence(text2, index) {
|
|
13496
|
-
const limit = Math.min(text2.length, index + MAX_CONTROL_SEQUENCE_CHARS);
|
|
13497
|
-
const code = text2.charCodeAt(index);
|
|
13498
|
-
const bodyEnd = code === C1_CSI ? skipCsiBody(text2, index + 1, limit) : skipControlStringBody(text2, index + 1, limit);
|
|
13499
|
-
return bodyEnd === UNTERMINATED_SEQUENCE ? index + 1 : bodyEnd;
|
|
13500
|
-
}
|
|
13501
|
-
function sanitizeToolOutputText(text2) {
|
|
13502
|
-
if (typeof text2 !== "string" || text2.length === 0) return text2;
|
|
13503
|
-
if (!NEEDS_SANITIZE_RE.test(text2)) return text2;
|
|
13504
|
-
const out = [];
|
|
13505
|
-
const length = text2.length;
|
|
13506
|
-
let plainStart = 0;
|
|
13507
|
-
let i = 0;
|
|
13508
|
-
const dropRange = (end3) => {
|
|
13509
|
-
if (plainStart < i) out.push(text2.slice(plainStart, i));
|
|
13510
|
-
i = end3;
|
|
13511
|
-
plainStart = end3;
|
|
13512
|
-
};
|
|
13513
|
-
while (i < length) {
|
|
13514
|
-
const code = text2.charCodeAt(i);
|
|
13515
|
-
if (code === LINE_FEED || code === TAB) {
|
|
13516
|
-
i += 1;
|
|
13517
|
-
continue;
|
|
13518
|
-
}
|
|
13519
|
-
if (code === ESC) {
|
|
13520
|
-
dropRange(skipEscapeSequence(text2, i));
|
|
13521
|
-
continue;
|
|
13522
|
-
}
|
|
13523
|
-
if (isC1Introducer(code)) {
|
|
13524
|
-
dropRange(skipC1Sequence(text2, i));
|
|
13525
|
-
continue;
|
|
13526
|
-
}
|
|
13527
|
-
if (code < 32 || code === DEL || code >= 128 && code <= 159) {
|
|
13528
|
-
dropRange(i + 1);
|
|
13529
|
-
continue;
|
|
13530
|
-
}
|
|
13531
|
-
if (code >= HIGH_SURROGATE_MIN && code <= HIGH_SURROGATE_MAX) {
|
|
13532
|
-
const low = text2.charCodeAt(i + 1);
|
|
13533
|
-
if (low >= LOW_SURROGATE_MIN && low <= LOW_SURROGATE_MAX) {
|
|
13534
|
-
i += 2;
|
|
13535
|
-
continue;
|
|
13536
|
-
}
|
|
13537
|
-
if (plainStart < i) out.push(text2.slice(plainStart, i));
|
|
13538
|
-
out.push(SANITIZE_REPLACEMENT_CHAR);
|
|
13539
|
-
i += 1;
|
|
13540
|
-
plainStart = i;
|
|
13541
|
-
continue;
|
|
13542
|
-
}
|
|
13543
|
-
if (code >= LOW_SURROGATE_MIN && code <= LOW_SURROGATE_MAX) {
|
|
13544
|
-
if (plainStart < i) out.push(text2.slice(plainStart, i));
|
|
13545
|
-
out.push(SANITIZE_REPLACEMENT_CHAR);
|
|
13546
|
-
i += 1;
|
|
13547
|
-
plainStart = i;
|
|
13548
|
-
continue;
|
|
13549
|
-
}
|
|
13550
|
-
i += 1;
|
|
13551
|
-
}
|
|
13552
|
-
if (plainStart < length) out.push(text2.slice(plainStart));
|
|
13553
|
-
return out.join("");
|
|
13554
|
-
}
|
|
13555
|
-
function sanitizeToolOutputContent(content) {
|
|
13556
|
-
return typeof content === "string" ? sanitizeToolOutputText(content) : content;
|
|
13557
|
-
}
|
|
13558
|
-
|
|
13559
13360
|
// packages/agent-runtime/providerMessageProjection.ts
|
|
13560
13361
|
var TOOL_DURATION_METADATA_KEY = "toolExecMs";
|
|
13561
13362
|
var OBSERVATION_ONLY_METADATA_KEYS = /* @__PURE__ */ new Set([
|
|
@@ -13702,6 +13503,7 @@ function projectToolContentForProvider(args2) {
|
|
|
13702
13503
|
const content = typeof rawContent === "string" ? sanitizeToolOutputText(rawContent) : rawContent;
|
|
13703
13504
|
if (typeof content !== "string") return content;
|
|
13704
13505
|
if (isSpilledToolOutput(content)) return content;
|
|
13506
|
+
if (isCompleteInstructionOutput(args2.toolName, args2.metadata, content)) return content;
|
|
13705
13507
|
const metadataText = compactToolMetadata(args2.metadata);
|
|
13706
13508
|
const embeddedMetadataIndex = metadataText ? content.indexOf("\n\n[tool metadata]\n") : -1;
|
|
13707
13509
|
const contentForProjection = embeddedMetadataIndex >= 0 ? content.slice(0, embeddedMetadataIndex) : content;
|
|
@@ -13900,7 +13702,8 @@ ${args2.input}` : [
|
|
|
13900
13702
|
const prefix2 = stableContent ? [{
|
|
13901
13703
|
role: "system",
|
|
13902
13704
|
content: stableContent,
|
|
13903
|
-
stable_prefix_chars: stableContent.length
|
|
13705
|
+
stable_prefix_chars: stableContent.length,
|
|
13706
|
+
...args2.prompt?.trim() ? { [AGENT_PROMPT_IN_MESSAGES]: true } : {}
|
|
13904
13707
|
}] : [];
|
|
13905
13708
|
const composed2 = composeProviderMessages({
|
|
13906
13709
|
prefix: prefix2,
|
|
@@ -13923,7 +13726,11 @@ ${args2.input}` : [
|
|
|
13923
13726
|
}
|
|
13924
13727
|
const blocks = (args2.contextBlocks ?? []).map((block) => block.trim()).filter(Boolean);
|
|
13925
13728
|
const systemContent = [args2.prompt?.trim(), ...blocks].filter(Boolean).join("\n\n");
|
|
13926
|
-
const prefix = systemContent ? [{
|
|
13729
|
+
const prefix = systemContent ? [{
|
|
13730
|
+
role: "system",
|
|
13731
|
+
content: systemContent,
|
|
13732
|
+
...args2.prompt?.trim() ? { [AGENT_PROMPT_IN_MESSAGES]: true } : {}
|
|
13733
|
+
}] : [];
|
|
13927
13734
|
const composed = composeProviderMessages({
|
|
13928
13735
|
prefix,
|
|
13929
13736
|
history: args2.history,
|
|
@@ -14093,7 +13900,7 @@ function buildToolResultsSignature(toolExecutions) {
|
|
|
14093
13900
|
function resolveProgressGuardConfig(options, env = typeof process !== "undefined" ? process.env : {}) {
|
|
14094
13901
|
const envDisabled = env.NOLO_LOOP_PROGRESS_GUARD_DISABLED === "true" || env.NOLO_LOOP_PROGRESS_GUARD_DISABLED === "1";
|
|
14095
13902
|
const disabled = options?.disabled ?? envDisabled ?? false;
|
|
14096
|
-
const parsePositiveInt = (val,
|
|
13903
|
+
const parsePositiveInt = (val, fallback2) => {
|
|
14097
13904
|
if (typeof val === "number" && Number.isFinite(val) && val >= 1) {
|
|
14098
13905
|
return Math.floor(val);
|
|
14099
13906
|
}
|
|
@@ -14103,7 +13910,7 @@ function resolveProgressGuardConfig(options, env = typeof process !== "undefined
|
|
|
14103
13910
|
return parsed;
|
|
14104
13911
|
}
|
|
14105
13912
|
}
|
|
14106
|
-
return
|
|
13913
|
+
return fallback2;
|
|
14107
13914
|
};
|
|
14108
13915
|
const maxConsecutiveIdenticalRounds = parsePositiveInt(
|
|
14109
13916
|
options?.maxConsecutiveIdenticalRounds ?? env.NOLO_LOOP_MAX_IDENTICAL_ROUNDS,
|
|
@@ -14861,9 +14668,9 @@ function normalizeExecShellInput(input) {
|
|
|
14861
14668
|
const record2 = input;
|
|
14862
14669
|
let rawCommand = resolveShellCommandArg(record2);
|
|
14863
14670
|
if (typeof rawCommand !== "string" || !rawCommand.trim()) {
|
|
14864
|
-
const
|
|
14865
|
-
if (typeof
|
|
14866
|
-
rawCommand =
|
|
14671
|
+
const fallback2 = record2.command ?? record2.cmd;
|
|
14672
|
+
if (typeof fallback2 === "string" && fallback2.trim()) {
|
|
14673
|
+
rawCommand = fallback2;
|
|
14867
14674
|
}
|
|
14868
14675
|
}
|
|
14869
14676
|
const command = typeof rawCommand === "string" ? rawCommand.trim() : "";
|
|
@@ -15033,12 +14840,255 @@ async function invokeCapability(capabilityOrName, input, ctx = {}) {
|
|
|
15033
14840
|
}
|
|
15034
14841
|
|
|
15035
14842
|
// packages/agent-runtime/localWorkspaceTools.ts
|
|
15036
|
-
import { existsSync as
|
|
14843
|
+
import { existsSync as existsSync3 } from "node:fs";
|
|
15037
14844
|
import { createHash as createHash3 } from "node:crypto";
|
|
15038
14845
|
|
|
14846
|
+
// packages/agent-runtime/agentsMd.ts
|
|
14847
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
14848
|
+
import { resolve } from "node:path";
|
|
14849
|
+
var AGENTS_MD_MAX_BYTES = 8192;
|
|
14850
|
+
var AGENTS_MD_MARKER_RESERVE_BYTES = 512;
|
|
14851
|
+
var AGENTS_MD_CANDIDATES = ["AGENTS.md", "CLAUDE.md"];
|
|
14852
|
+
function truncateAgentsMdContent(content, maxBytes = AGENTS_MD_MAX_BYTES) {
|
|
14853
|
+
const buf = Buffer.from(content, "utf8");
|
|
14854
|
+
if (buf.byteLength <= maxBytes) {
|
|
14855
|
+
return content;
|
|
14856
|
+
}
|
|
14857
|
+
let boundary = Math.min(maxBytes, buf.byteLength);
|
|
14858
|
+
while (boundary > 0 && boundary < buf.byteLength && (buf[boundary] & 192) === 128) {
|
|
14859
|
+
boundary--;
|
|
14860
|
+
}
|
|
14861
|
+
const boundarySlice = buf.subarray(0, boundary).toString("utf8");
|
|
14862
|
+
const slice = buf.subarray(0, maxBytes);
|
|
14863
|
+
const lastNewline = slice.lastIndexOf(10);
|
|
14864
|
+
if (lastNewline > 0) {
|
|
14865
|
+
const lineCandidate = slice.subarray(0, lastNewline).toString("utf8");
|
|
14866
|
+
const lineBytes = Buffer.byteLength(lineCandidate, "utf8");
|
|
14867
|
+
const boundaryBytes = Buffer.byteLength(boundarySlice, "utf8");
|
|
14868
|
+
if (lineCandidate.trim().length > 0 && lineBytes * 2 >= boundaryBytes) {
|
|
14869
|
+
return lineCandidate.replace(/\r$/, "");
|
|
14870
|
+
}
|
|
14871
|
+
}
|
|
14872
|
+
return boundarySlice.replace(/\r$/, "");
|
|
14873
|
+
}
|
|
14874
|
+
var AGENTS_MD_SUMMARY_MAX_BYTES = 3072;
|
|
14875
|
+
var AGENTS_MD_SUMMARY_ITEM_MAX_CHARS = 120;
|
|
14876
|
+
var AGENTS_MD_SUMMARY_PRIORITY_KEYWORDS = [
|
|
14877
|
+
"review",
|
|
14878
|
+
"\u8BC4\u5BA1",
|
|
14879
|
+
"commit",
|
|
14880
|
+
"\u63D0\u4EA4",
|
|
14881
|
+
"worktree",
|
|
14882
|
+
"\u6D4B\u8BD5",
|
|
14883
|
+
"typecheck",
|
|
14884
|
+
"\u7C7B\u578B\u68C0\u67E5",
|
|
14885
|
+
"push",
|
|
14886
|
+
"\u53D1\u5E03",
|
|
14887
|
+
"\u6587\u6863\u843D\u4F4D",
|
|
14888
|
+
"\u5220\u9664",
|
|
14889
|
+
"\u6D3E\u53D1"
|
|
14890
|
+
];
|
|
14891
|
+
var AGENTS_MD_SUMMARY_POINTER_INSTRUCTION = "\u7528 readFile \u8BFB\u5168\u6587\uFF1A%REL%\uFF08cwd\uFF09/ %PATH%\n\u4EC5\u7D22\u5F15\uFF1A\u63D0\u4EA4/\u8BC4\u5BA1\u95E8\u7981\u3001worktree \u9694\u79BB\u3001\u6D4B\u8BD5/typecheck\u3001\u6587\u6863\u843D\u4F4D\u3001\u5220\u9664\u3001push/\u53D1\u5E03\u524D\uFF0C**\u5FC5\u987B\u5148 readFile \u8BFB\u5168\u6587\u518D\u6267\u884C**\u3002\n\u8DEF\u5F84\uFF1A%REL% \u76F8\u5BF9 cwd\uFF1Bmachine:<id>/\u6C99\u76D2\u6267\u884C\u9762 cwd \u7531\u5176\u51B3\u5B9A\uFF0C\u8BFB\u4E0D\u5230\u8BA9\u5BBF\u4E3B\u6CE8\u5165\u6216\u7528\u7EDD\u5BF9\u8DEF\u5F84\u3002";
|
|
14892
|
+
var AGENTS_MD_SUMMARY_DELETE_REFERENCE = "- \u5220\u9664/\u4E0D\u53EF\u9006\u64CD\u4F5C\uFF1A\u9075\u5B88\u7CFB\u7EDF\u63D0\u793A\u7684\u5220\u9664\u7EA2\u7EBF\uFF08\u5148\u5448\u73B0\u5B8C\u6574\u5F85\u5220\u6E05\u5355\u5E76\u83B7\u7528\u6237\u660E\u786E\u786E\u8BA4\uFF0C\u7981\u6B62\u5148\u5220\u540E\u62A5\u3001\u7981\u6B62\u6A21\u7CCA\u5B9A\u4F4D\uFF09\uFF0C\u4ED3\u5E93\u82E5\u6709\u9644\u52A0\u5220\u9664\u89C4\u5219\u89C1\u5B8C\u6574\u6587\u4EF6\u3002";
|
|
14893
|
+
var clipToChars = (text2, maxChars) => text2.length <= maxChars ? text2 : `${text2.slice(0, maxChars).trimEnd()}\u2026`;
|
|
14894
|
+
var parseAgentsMdItem = (body) => {
|
|
14895
|
+
const bold = /^\*\*(.+?)\*\*/.exec(body);
|
|
14896
|
+
if (bold) {
|
|
14897
|
+
return {
|
|
14898
|
+
label: bold[1].trim().replace(/[::]$/, ""),
|
|
14899
|
+
rest: body.slice(bold[0].length).replace(/^[::\s]+/, "")
|
|
14900
|
+
};
|
|
14901
|
+
}
|
|
14902
|
+
const firstClause = body.split(/[::]/)[0];
|
|
14903
|
+
return {
|
|
14904
|
+
label: clipToChars(firstClause.trim(), 40),
|
|
14905
|
+
rest: body.slice(firstClause.length).replace(/^[::\s]+/, "")
|
|
14906
|
+
};
|
|
14907
|
+
};
|
|
14908
|
+
var AGENTS_MD_COMMAND_TOKEN_PREFIX = /^(bunx?|npx|node|npm|pnpm|yarn|git|gh|tsc|deno)\b\s/;
|
|
14909
|
+
var extractAgentsMdCommandTokens = (body) => {
|
|
14910
|
+
const tokens = [];
|
|
14911
|
+
const seen = /* @__PURE__ */ new Set();
|
|
14912
|
+
for (const match7 of body.matchAll(/`([^`\n]+)`/g)) {
|
|
14913
|
+
const raw = match7[1];
|
|
14914
|
+
if (!AGENTS_MD_COMMAND_TOKEN_PREFIX.test(raw)) continue;
|
|
14915
|
+
if (seen.has(raw)) continue;
|
|
14916
|
+
seen.add(raw);
|
|
14917
|
+
tokens.push(raw);
|
|
14918
|
+
}
|
|
14919
|
+
return tokens;
|
|
14920
|
+
};
|
|
14921
|
+
var buildAgentsMdItemGist = (firstSentence, bulletBody) => {
|
|
14922
|
+
const max4 = AGENTS_MD_SUMMARY_ITEM_MAX_CHARS;
|
|
14923
|
+
const clipped = clipToChars(firstSentence, max4);
|
|
14924
|
+
const missing = extractAgentsMdCommandTokens(bulletBody).filter(
|
|
14925
|
+
(token) => !clipped.includes(token)
|
|
14926
|
+
);
|
|
14927
|
+
if (missing.length === 0) return clipped;
|
|
14928
|
+
let tail = "";
|
|
14929
|
+
for (const token of missing) {
|
|
14930
|
+
const candidate = tail ? `${tail} \`${token}\`` : `\`${token}\``;
|
|
14931
|
+
if (candidate.length > max4) continue;
|
|
14932
|
+
tail = candidate;
|
|
14933
|
+
}
|
|
14934
|
+
if (!tail) return clipped;
|
|
14935
|
+
const room = max4 - tail.length - 2;
|
|
14936
|
+
const head3 = room > 0 ? clipToChars(firstSentence, room) : "";
|
|
14937
|
+
return head3 ? `${head3} ${tail}` : tail;
|
|
14938
|
+
};
|
|
14939
|
+
var priorityOf = (label) => {
|
|
14940
|
+
const lowered = label.toLowerCase();
|
|
14941
|
+
for (let i = 0; i < AGENTS_MD_SUMMARY_PRIORITY_KEYWORDS.length; i += 1) {
|
|
14942
|
+
if (lowered.includes(AGENTS_MD_SUMMARY_PRIORITY_KEYWORDS[i].toLowerCase())) {
|
|
14943
|
+
return i;
|
|
14944
|
+
}
|
|
14945
|
+
}
|
|
14946
|
+
return -1;
|
|
14947
|
+
};
|
|
14948
|
+
var collectAgentsMdSummaryItems = (content) => {
|
|
14949
|
+
const items = [];
|
|
14950
|
+
const seen = /* @__PURE__ */ new Set();
|
|
14951
|
+
let section = null;
|
|
14952
|
+
for (const rawLine of content.split(/\r?\n/)) {
|
|
14953
|
+
const line = rawLine.trim();
|
|
14954
|
+
if (!line) continue;
|
|
14955
|
+
const heading = /^#{2,3}\s+(.+)$/.exec(line);
|
|
14956
|
+
if (heading) {
|
|
14957
|
+
section = heading[1].trim();
|
|
14958
|
+
continue;
|
|
14959
|
+
}
|
|
14960
|
+
if (line.startsWith("#") || line.startsWith("<") || line.startsWith("<!--")) {
|
|
14961
|
+
continue;
|
|
14962
|
+
}
|
|
14963
|
+
const bullet = /^[-*]\s+(.+)$/.exec(line);
|
|
14964
|
+
if (!bullet) continue;
|
|
14965
|
+
const { label, rest } = parseAgentsMdItem(bullet[1]);
|
|
14966
|
+
if (!label || seen.has(label)) continue;
|
|
14967
|
+
seen.add(label);
|
|
14968
|
+
const firstSentence = rest.split("\u3002")[0].trim();
|
|
14969
|
+
items.push({
|
|
14970
|
+
section,
|
|
14971
|
+
label,
|
|
14972
|
+
gist: buildAgentsMdItemGist(firstSentence, bullet[1]),
|
|
14973
|
+
priority: priorityOf(label)
|
|
14974
|
+
});
|
|
14975
|
+
}
|
|
14976
|
+
return items;
|
|
14977
|
+
};
|
|
14978
|
+
function buildAgentsMdSummaryBody(content, filePath, options = {}) {
|
|
14979
|
+
const budgetBytes = options.budgetBytes ?? AGENTS_MD_SUMMARY_MAX_BYTES;
|
|
14980
|
+
const items = collectAgentsMdSummaryItems(content);
|
|
14981
|
+
if (items.length === 0) return null;
|
|
14982
|
+
const relativePath = options.fileName ?? "AGENTS.md";
|
|
14983
|
+
const pointer = AGENTS_MD_SUMMARY_POINTER_INSTRUCTION.replaceAll(
|
|
14984
|
+
"%REL%",
|
|
14985
|
+
relativePath
|
|
14986
|
+
).replaceAll("%PATH%", filePath);
|
|
14987
|
+
const head3 = `${pointer}
|
|
14988
|
+
${AGENTS_MD_SUMMARY_DELETE_REFERENCE}
|
|
14989
|
+
`;
|
|
14990
|
+
if (Buffer.byteLength(head3, "utf8") > budgetBytes) return null;
|
|
14991
|
+
const candidates = [
|
|
14992
|
+
...items.filter((item) => item.priority >= 0).sort((a, b) => a.priority - b.priority),
|
|
14993
|
+
...items.filter((item) => item.priority < 0)
|
|
14994
|
+
];
|
|
14995
|
+
const noteBlock = `
|
|
14996
|
+
\u2026\uFF08\u7D22\u5F15\u5DF2\u622A\u65AD\uFF0C\u5176\u4F59\u951A\u70B9\u89C1\u5B8C\u6574\u6587\u4EF6\uFF09`;
|
|
14997
|
+
const noteBytes = Buffer.byteLength(noteBlock, "utf8");
|
|
14998
|
+
let used = Buffer.byteLength(head3, "utf8");
|
|
14999
|
+
const admitted = [];
|
|
15000
|
+
const seenSections = /* @__PURE__ */ new Set();
|
|
15001
|
+
let truncated = false;
|
|
15002
|
+
for (const item of candidates) {
|
|
15003
|
+
const line = item.gist ? `- ${item.label}\uFF1A${item.gist}` : `- ${item.label}`;
|
|
15004
|
+
const headingCost = item.section && !seenSections.has(item.section) ? Buffer.byteLength(`
|
|
15005
|
+
## ${item.section}`, "utf8") : 0;
|
|
15006
|
+
const cost = headingCost + Buffer.byteLength(`
|
|
15007
|
+
${line}`, "utf8");
|
|
15008
|
+
if (used + cost + noteBytes > budgetBytes) {
|
|
15009
|
+
truncated = true;
|
|
15010
|
+
continue;
|
|
15011
|
+
}
|
|
15012
|
+
used += cost;
|
|
15013
|
+
if (item.section) seenSections.add(item.section);
|
|
15014
|
+
admitted.push(item);
|
|
15015
|
+
}
|
|
15016
|
+
const groupOrder = [];
|
|
15017
|
+
for (const item of admitted) {
|
|
15018
|
+
if (!groupOrder.includes(item.section)) groupOrder.push(item.section);
|
|
15019
|
+
}
|
|
15020
|
+
const frozen = [];
|
|
15021
|
+
for (const section of groupOrder) {
|
|
15022
|
+
for (const item of admitted) {
|
|
15023
|
+
if (item.section !== section) continue;
|
|
15024
|
+
frozen.push({
|
|
15025
|
+
section,
|
|
15026
|
+
line: item.gist ? `- ${item.label}\uFF1A${item.gist}` : `- ${item.label}`
|
|
15027
|
+
});
|
|
15028
|
+
}
|
|
15029
|
+
}
|
|
15030
|
+
if (admitted.length === 0) return null;
|
|
15031
|
+
return `${head3}${renderSummarySections(frozen)}${truncated ? noteBlock : ""}`;
|
|
15032
|
+
}
|
|
15033
|
+
var renderSummarySections = (entries) => {
|
|
15034
|
+
let rendered = "";
|
|
15035
|
+
let currentSection = null;
|
|
15036
|
+
for (const entry of entries) {
|
|
15037
|
+
if (entry.section && entry.section !== currentSection) {
|
|
15038
|
+
rendered += `
|
|
15039
|
+
## ${entry.section}`;
|
|
15040
|
+
currentSection = entry.section;
|
|
15041
|
+
}
|
|
15042
|
+
rendered += `
|
|
15043
|
+
${entry.line}`;
|
|
15044
|
+
}
|
|
15045
|
+
return rendered;
|
|
15046
|
+
};
|
|
15047
|
+
function readAgentsMdLayerFromDisk(cwd) {
|
|
15048
|
+
for (const name of AGENTS_MD_CANDIDATES) {
|
|
15049
|
+
const filePath = resolve(cwd, name);
|
|
15050
|
+
if (!existsSync(filePath)) continue;
|
|
15051
|
+
try {
|
|
15052
|
+
const raw = readFileSync(filePath, "utf8");
|
|
15053
|
+
const content = raw.trim();
|
|
15054
|
+
if (!content) continue;
|
|
15055
|
+
const totalBytes = Buffer.byteLength(raw, "utf8");
|
|
15056
|
+
const trimmedBytes = Buffer.byteLength(content, "utf8");
|
|
15057
|
+
const headerBytes = Buffer.byteLength(buildAgentsMdLayerHeader(name), "utf8");
|
|
15058
|
+
if (headerBytes + trimmedBytes <= AGENTS_MD_MAX_BYTES) {
|
|
15059
|
+
return buildAgentsMdLayer(content, name);
|
|
15060
|
+
}
|
|
15061
|
+
const summaryBody = buildAgentsMdSummaryBody(content, filePath, {
|
|
15062
|
+
// 正文预算 = 摘要上限 − 块头部:buildAgentsMdLayer 会再拼一次头部,
|
|
15063
|
+
// 因此「头部 + 正文」才等于最终注入字节,不得超过摘要上限。
|
|
15064
|
+
budgetBytes: AGENTS_MD_SUMMARY_MAX_BYTES - headerBytes,
|
|
15065
|
+
fileName: name
|
|
15066
|
+
});
|
|
15067
|
+
if (summaryBody) return buildAgentsMdLayer(summaryBody, name);
|
|
15068
|
+
const buildMarker = (omitted2, withPath) => {
|
|
15069
|
+
const pathPart = withPath ? `\u5B8C\u6574\u6587\u4EF6\uFF1A${filePath}` : `\u5B8C\u6574\u6587\u4EF6\uFF1A\u5DE5\u4F5C\u533A\u6839\u76EE\u5F55\u7684 ${name}`;
|
|
15070
|
+
return `<!-- AGENTS.md truncated: \u539F\u6587\u4EF6 ${totalBytes} \u5B57\u8282\uFF0C\u6CE8\u5165\u9884\u7B97 ${AGENTS_MD_MAX_BYTES} \u5B57\u8282\uFF0C\u5DF2\u7701\u7565 ${omitted2} \u5B57\u8282\uFF08\u4E0A\u6587\u53EF\u80FD\u7F3A\u5C11\u6587\u4EF6\u672B\u5C3E\u7684 commit/review \u95E8\u7981\u7EC6\u5219\uFF0C\u63D0\u4EA4/\u8BC4\u5BA1\u524D\u8BF7\u8BFB\u5B8C\u6574\u6587\u4EF6\uFF09\u3002${pathPart} -->`;
|
|
15071
|
+
};
|
|
15072
|
+
const bodyBudget = AGENTS_MD_MAX_BYTES - AGENTS_MD_MARKER_RESERVE_BYTES - 2 - headerBytes;
|
|
15073
|
+
const body = truncateAgentsMdContent(content, bodyBudget);
|
|
15074
|
+
const bodyBytes = Buffer.byteLength(body, "utf8");
|
|
15075
|
+
const omitted = Math.max(0, totalBytes - bodyBytes);
|
|
15076
|
+
let marker = buildMarker(omitted, true);
|
|
15077
|
+
if (Buffer.byteLength(marker, "utf8") > AGENTS_MD_MARKER_RESERVE_BYTES) {
|
|
15078
|
+
marker = buildMarker(omitted, false);
|
|
15079
|
+
}
|
|
15080
|
+
return buildAgentsMdLayer(`${body}
|
|
15081
|
+
|
|
15082
|
+
${marker}`, name);
|
|
15083
|
+
} catch {
|
|
15084
|
+
}
|
|
15085
|
+
}
|
|
15086
|
+
return null;
|
|
15087
|
+
}
|
|
15088
|
+
|
|
15039
15089
|
// packages/agent-runtime/visualRenderer.node.ts
|
|
15040
15090
|
import { createRequire } from "node:module";
|
|
15041
|
-
import { existsSync } from "node:fs";
|
|
15091
|
+
import { existsSync as existsSync2 } from "node:fs";
|
|
15042
15092
|
import { realpath, stat, readFile } from "node:fs/promises";
|
|
15043
15093
|
import { isAbsolute, relative, win32 } from "node:path";
|
|
15044
15094
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
@@ -15091,7 +15141,7 @@ var VisualRenderSemaphore = class {
|
|
|
15091
15141
|
active = 0;
|
|
15092
15142
|
queue = [];
|
|
15093
15143
|
async run(task) {
|
|
15094
|
-
if (this.active >= this.limit) await new Promise((
|
|
15144
|
+
if (this.active >= this.limit) await new Promise((resolve7) => this.queue.push(resolve7));
|
|
15095
15145
|
else this.active++;
|
|
15096
15146
|
try {
|
|
15097
15147
|
return await task();
|
|
@@ -15109,7 +15159,7 @@ function visualRendererCapability() {
|
|
|
15109
15159
|
if (process.env.NOLO_VISUAL_RENDERER_DISABLED === "1") return { available: false, reasonCode: "disabled", reason: "Platform renderer disabled by NOLO_VISUAL_RENDERER_DISABLED=1 on this runtime host." };
|
|
15110
15160
|
try {
|
|
15111
15161
|
const { chromium } = require2("playwright");
|
|
15112
|
-
const executablePath = [chromium.executablePath(), resolveExecutableOnPath("google-chrome"), resolveExecutableOnPath("chromium"), resolveExecutableOnPath("chromium-browser")].find((path) => !!path &&
|
|
15162
|
+
const executablePath = [chromium.executablePath(), resolveExecutableOnPath("google-chrome"), resolveExecutableOnPath("chromium"), resolveExecutableOnPath("chromium-browser")].find((path) => !!path && existsSync2(path));
|
|
15113
15163
|
if (!executablePath) return { available: false, reasonCode: "missing-browser", reason: "No Chromium renderer installed. Install Playwright Chromium (playwright install chromium) or system Chromium/Google Chrome on the runtime host." };
|
|
15114
15164
|
return { available: true, chromium, executablePath };
|
|
15115
15165
|
} catch {
|
|
@@ -15285,7 +15335,7 @@ finally:
|
|
|
15285
15335
|
pass
|
|
15286
15336
|
bus.signal_unsubscribe(subscription)
|
|
15287
15337
|
`;
|
|
15288
|
-
var capturePortalScreenshot = (signal) => new Promise((
|
|
15338
|
+
var capturePortalScreenshot = (signal) => new Promise((resolve7, reject) => {
|
|
15289
15339
|
const child = spawn("/usr/bin/python3", ["-c", PORTAL_SCRIPT], { stdio: ["ignore", "pipe", "pipe"] });
|
|
15290
15340
|
let stdout = "";
|
|
15291
15341
|
let stderr = "";
|
|
@@ -15306,7 +15356,7 @@ var capturePortalScreenshot = (signal) => new Promise((resolve6, reject) => {
|
|
|
15306
15356
|
if (signal.aborted) return reject(new Error("portal capture timeout"));
|
|
15307
15357
|
if (code !== 0) return reject(new Error(stderr.trim() || `portal helper exited ${code}`));
|
|
15308
15358
|
try {
|
|
15309
|
-
|
|
15359
|
+
resolve7(JSON.parse(stdout));
|
|
15310
15360
|
} catch {
|
|
15311
15361
|
reject(new Error("invalid portal response"));
|
|
15312
15362
|
}
|
|
@@ -15318,7 +15368,7 @@ function createHostWindowCapture(options = {}) {
|
|
|
15318
15368
|
let active = 0;
|
|
15319
15369
|
const waiters = [];
|
|
15320
15370
|
function acquire(signal) {
|
|
15321
|
-
return new Promise((
|
|
15371
|
+
return new Promise((resolve7, reject) => {
|
|
15322
15372
|
const abort = () => {
|
|
15323
15373
|
const index = waiters.indexOf(start);
|
|
15324
15374
|
if (index >= 0) waiters.splice(index, 1);
|
|
@@ -15327,7 +15377,7 @@ function createHostWindowCapture(options = {}) {
|
|
|
15327
15377
|
const start = () => {
|
|
15328
15378
|
signal.removeEventListener("abort", abort);
|
|
15329
15379
|
active++;
|
|
15330
|
-
|
|
15380
|
+
resolve7();
|
|
15331
15381
|
};
|
|
15332
15382
|
if (signal.aborted) return abort();
|
|
15333
15383
|
if (active < concurrency) start();
|
|
@@ -15385,7 +15435,7 @@ var captureHostWindow = createHostWindowCapture();
|
|
|
15385
15435
|
// packages/agent-runtime/localWorkspaceTools.ts
|
|
15386
15436
|
import { lstat as lstat2, readdir as readdir2, readFile as readFile4, realpath as realpath3, stat as stat4 } from "node:fs/promises";
|
|
15387
15437
|
import { homedir } from "node:os";
|
|
15388
|
-
import { dirname as dirname2, relative as relative4, resolve as
|
|
15438
|
+
import { dirname as dirname2, relative as relative4, resolve as resolve5, sep as sep2 } from "node:path";
|
|
15389
15439
|
import { spawn as spawnChildProcess2 } from "node:child_process";
|
|
15390
15440
|
|
|
15391
15441
|
// packages/agent-runtime/runResultReadProjection.ts
|
|
@@ -15468,12 +15518,12 @@ function isLineRangeCovered(request3, covered) {
|
|
|
15468
15518
|
|
|
15469
15519
|
// packages/agent-runtime/fileTextSearch.ts
|
|
15470
15520
|
import { readdir, readFile as readFile3, stat as stat3 } from "node:fs/promises";
|
|
15471
|
-
import { basename as basename2, relative as relative2, resolve as
|
|
15521
|
+
import { basename as basename2, relative as relative2, resolve as resolve3 } from "node:path";
|
|
15472
15522
|
import { spawn as spawnChildProcess } from "node:child_process";
|
|
15473
15523
|
|
|
15474
15524
|
// packages/agent-runtime/gitignore.ts
|
|
15475
15525
|
import { readFile as readFile2, stat as stat2 } from "node:fs/promises";
|
|
15476
|
-
import { resolve } from "node:path";
|
|
15526
|
+
import { resolve as resolve2 } from "node:path";
|
|
15477
15527
|
function isIgnorableFsError(err) {
|
|
15478
15528
|
if (err && typeof err === "object" && "code" in err) {
|
|
15479
15529
|
const code = err.code;
|
|
@@ -15484,7 +15534,7 @@ function isIgnorableFsError(err) {
|
|
|
15484
15534
|
async function readRootGitignorePatterns(workspaceRoot) {
|
|
15485
15535
|
let content;
|
|
15486
15536
|
try {
|
|
15487
|
-
content = await readFile2(
|
|
15537
|
+
content = await readFile2(resolve2(workspaceRoot, ".gitignore"), "utf8");
|
|
15488
15538
|
} catch (err) {
|
|
15489
15539
|
if (isIgnorableFsError(err)) return [];
|
|
15490
15540
|
throw err;
|
|
@@ -15498,7 +15548,7 @@ async function readRootGitignorePatterns(workspaceRoot) {
|
|
|
15498
15548
|
}
|
|
15499
15549
|
async function hasRootGitignore(workspaceRoot) {
|
|
15500
15550
|
try {
|
|
15501
|
-
await stat2(
|
|
15551
|
+
await stat2(resolve2(workspaceRoot, ".gitignore"));
|
|
15502
15552
|
return true;
|
|
15503
15553
|
} catch (err) {
|
|
15504
15554
|
if (isIgnorableFsError(err)) return false;
|
|
@@ -15510,6 +15560,8 @@ async function hasRootGitignore(workspaceRoot) {
|
|
|
15510
15560
|
var normalizePath = (value) => value.replaceAll("\\", "/");
|
|
15511
15561
|
var pathFor = (root, file, absolute = false) => absolute ? normalizePath(file) : normalizePath(relative2(root, file) || basename2(file));
|
|
15512
15562
|
var COMMAND_LIMIT_HEADROOM = 1;
|
|
15563
|
+
var MAX_SEARCH_FILE_BYTES = 8 * 1024 * 1024;
|
|
15564
|
+
var MAX_SEARCH_LINE_CHARS = 2e3;
|
|
15513
15565
|
async function runCommand(binary, args2, cwd, maxResults) {
|
|
15514
15566
|
const recordLimit = maxResults === void 0 ? 0 : Math.max(0, maxResults) + COMMAND_LIMIT_HEADROOM;
|
|
15515
15567
|
return await new Promise((done4) => {
|
|
@@ -15517,7 +15569,12 @@ async function runCommand(binary, args2, cwd, maxResults) {
|
|
|
15517
15569
|
try {
|
|
15518
15570
|
const child = spawnChildProcess(binary, args2, { cwd, stdio: ["ignore", "pipe", "pipe"], windowsHide: true });
|
|
15519
15571
|
child.stdout.on("data", (chunk) => {
|
|
15520
|
-
|
|
15572
|
+
const room = MAX_SEARCH_FILE_BYTES - stdout.length;
|
|
15573
|
+
stdout += chunk.toString().slice(0, Math.max(0, room));
|
|
15574
|
+
if (stdout.length >= MAX_SEARCH_FILE_BYTES && !stopped) {
|
|
15575
|
+
stopped = true;
|
|
15576
|
+
child.kill();
|
|
15577
|
+
}
|
|
15521
15578
|
recordCount = parseMatches(cwd, stdout).length;
|
|
15522
15579
|
if (recordLimit > 0 && recordCount >= recordLimit && !stopped) {
|
|
15523
15580
|
stopped = true;
|
|
@@ -15547,14 +15604,14 @@ function isGrepExpressibleExclude(pattern) {
|
|
|
15547
15604
|
}
|
|
15548
15605
|
function commandArgs(o, binary, target) {
|
|
15549
15606
|
const args2 = binary === "rg" ? ["--line-number", "--no-heading", "--color", "never", "--null"] : ["-RIn", "--binary-files=without-match", "--null"];
|
|
15550
|
-
if (binary === "rg") args2.push("--no-require-git");
|
|
15607
|
+
if (binary === "rg") args2.push("--no-require-git", "--max-columns", String(MAX_SEARCH_LINE_CHARS), "--max-columns-preview");
|
|
15551
15608
|
if (o.regex !== true) args2.push(binary === "rg" ? "--fixed-strings" : "-F");
|
|
15552
15609
|
else if (binary === "grep") args2.push("-E");
|
|
15553
15610
|
if (o.caseSensitive === false) args2.push("-i");
|
|
15554
15611
|
if (binary === "rg") {
|
|
15555
15612
|
if (o.includeIgnored) args2.push("--no-ignore");
|
|
15556
15613
|
for (const x of o.exclude ?? []) args2.push("--glob", `!${x}`);
|
|
15557
|
-
if (o.include) args2.push("--
|
|
15614
|
+
if (o.include) args2.push("--type-add", `noloSearch:${o.include}`, "--type", "noloSearch");
|
|
15558
15615
|
} else {
|
|
15559
15616
|
for (const x of o.exclude ?? []) {
|
|
15560
15617
|
const clean = extractGrepExcludeDir(x);
|
|
@@ -15569,29 +15626,37 @@ function parseMatches(root, output) {
|
|
|
15569
15626
|
const records = [];
|
|
15570
15627
|
const pattern = /(?:^|\n)([^\0\n]+)\0(\d+):(.*?)(?=\n[^\0\n]+\0|$)/gs;
|
|
15571
15628
|
for (const match7 of output.matchAll(pattern)) {
|
|
15572
|
-
records.push({ file:
|
|
15629
|
+
records.push({ file: resolve3(root, match7[1] ?? ""), line: Number(match7[2]), text: (match7[3] ?? "").replace(/\n$/, "") });
|
|
15573
15630
|
}
|
|
15574
15631
|
return records;
|
|
15575
15632
|
}
|
|
15576
15633
|
async function decorate(root, raw, context3, absolute = false) {
|
|
15577
|
-
const
|
|
15634
|
+
const out = [];
|
|
15578
15635
|
for (const x of raw) {
|
|
15579
|
-
let lines =
|
|
15580
|
-
if (
|
|
15636
|
+
let lines = [];
|
|
15637
|
+
if (context3 > 0) {
|
|
15581
15638
|
try {
|
|
15582
|
-
|
|
15639
|
+
if ((await stat3(x.file)).size <= MAX_SEARCH_FILE_BYTES) {
|
|
15640
|
+
lines = (await readFile3(x.file, "utf8")).split(/\r\n|\r|\n/);
|
|
15641
|
+
}
|
|
15583
15642
|
} catch {
|
|
15584
|
-
continue;
|
|
15585
15643
|
}
|
|
15586
|
-
cache.set(x.file, lines);
|
|
15587
15644
|
}
|
|
15588
15645
|
const i = x.line - 1;
|
|
15589
|
-
out.push({
|
|
15646
|
+
out.push({
|
|
15647
|
+
path: pathFor(root, x.file, absolute),
|
|
15648
|
+
line: x.line,
|
|
15649
|
+
text: (lines[i] ?? x.text).slice(0, MAX_SEARCH_LINE_CHARS),
|
|
15650
|
+
before: lines.slice(Math.max(0, i - context3), i).map((line) => line.slice(0, MAX_SEARCH_LINE_CHARS)),
|
|
15651
|
+
after: lines.slice(i + 1, i + context3 + 1).map((line) => line.slice(0, MAX_SEARCH_LINE_CHARS))
|
|
15652
|
+
});
|
|
15590
15653
|
}
|
|
15591
15654
|
return out;
|
|
15592
15655
|
}
|
|
15593
15656
|
function globMatch(pattern, value) {
|
|
15594
15657
|
const p = normalizePath(pattern).replace(/^!/, "");
|
|
15658
|
+
const brace = /\{([^{}]+)\}/.exec(p);
|
|
15659
|
+
if (brace) return brace[1].split(",").some((part) => globMatch(p.slice(0, brace.index) + part + p.slice(brace.index + brace[0].length), value));
|
|
15595
15660
|
let source = "";
|
|
15596
15661
|
for (let i = 0; i < p.length; i++) {
|
|
15597
15662
|
const c = p[i];
|
|
@@ -15627,7 +15692,7 @@ async function jsSearch(o, targetPath) {
|
|
|
15627
15692
|
} else {
|
|
15628
15693
|
const walk = async (dir) => {
|
|
15629
15694
|
for (const e of await readdir(dir, { withFileTypes: true })) {
|
|
15630
|
-
const f =
|
|
15695
|
+
const f = resolve3(dir, e.name), rel = pathFor(o.root, f);
|
|
15631
15696
|
if (e.isDirectory()) {
|
|
15632
15697
|
if (!excludes.some((p) => globMatch(p, rel))) await walk(f);
|
|
15633
15698
|
} else if (e.isFile() && !excludes.some((p) => globMatch(p, rel)) && !isIgnored(rel) && (!o.include || globMatch(o.include, rel))) {
|
|
@@ -15641,6 +15706,8 @@ async function jsSearch(o, targetPath) {
|
|
|
15641
15706
|
const needle = o.caseSensitive === false ? o.query.toLowerCase() : o.query;
|
|
15642
15707
|
const out = [], context3 = o.contextLines ?? 0;
|
|
15643
15708
|
for (const file of files) {
|
|
15709
|
+
const info = await stat3(file).catch(() => null);
|
|
15710
|
+
if (!info || info.size > MAX_SEARCH_FILE_BYTES) continue;
|
|
15644
15711
|
const text2 = await readText(file);
|
|
15645
15712
|
if (!text2 || text2.includes("\0")) continue;
|
|
15646
15713
|
const lines = text2.split(/\r\n|\r|\n/);
|
|
@@ -15649,7 +15716,7 @@ async function jsSearch(o, targetPath) {
|
|
|
15649
15716
|
const hit = matcher ? matcher.test(line) : o.caseSensitive === false ? line.toLowerCase().includes(needle) : line.includes(needle);
|
|
15650
15717
|
if (!hit) continue;
|
|
15651
15718
|
if (out.length >= max4) return { matches: out, totalMatches: max4, truncated: true, engine: "js" };
|
|
15652
|
-
out.push({ path: pathFor(o.root, file, o.absolutePaths === true), line: i + 1, text: line, before: lines.slice(Math.max(0, i - context3), i), after: lines.slice(i + 1, i + context3 + 1) });
|
|
15719
|
+
out.push({ path: pathFor(o.root, file, o.absolutePaths === true), line: i + 1, text: line.slice(0, MAX_SEARCH_LINE_CHARS), before: lines.slice(Math.max(0, i - context3), i).map((line2) => line2.slice(0, MAX_SEARCH_LINE_CHARS)), after: lines.slice(i + 1, i + context3 + 1).map((line2) => line2.slice(0, MAX_SEARCH_LINE_CHARS)) });
|
|
15653
15720
|
}
|
|
15654
15721
|
}
|
|
15655
15722
|
return { matches: out, totalMatches: out.length, truncated: false, engine: "js" };
|
|
@@ -15676,12 +15743,13 @@ var COMMAND_ENGINES = [
|
|
|
15676
15743
|
{ engine: "grep", binaryOption: "resolveGrepBinary", binaryName: "grep", argsKey: "grep" }
|
|
15677
15744
|
];
|
|
15678
15745
|
async function searchFileTextMatches(o) {
|
|
15679
|
-
const targetPath =
|
|
15746
|
+
const targetPath = resolve3(o.root, o.target || ".");
|
|
15680
15747
|
const targetStat = await stat3(targetPath).catch(() => null);
|
|
15681
15748
|
if (!targetStat) return { matches: [], totalMatches: 0, truncated: false, engine: "js" };
|
|
15682
15749
|
if (targetStat.isFile()) return jsSearch(o, targetPath);
|
|
15683
15750
|
const run2 = o.runCommand ?? runCommand, max4 = o.maxResults;
|
|
15684
15751
|
for (const entry of COMMAND_ENGINES) {
|
|
15752
|
+
if (entry.engine === "ripgrep" && o.include && /[/\\]/.test(o.include)) continue;
|
|
15685
15753
|
if (entry.engine === "grep" && !await canGrepFulfillOptions(o)) continue;
|
|
15686
15754
|
const injectedResolver = o[entry.binaryOption];
|
|
15687
15755
|
const binary = injectedResolver ? injectedResolver() : resolveExecutableOnPath(entry.binaryName);
|
|
@@ -15729,6 +15797,7 @@ var TASK_WAIT_DEFAULT_TIMEOUT_MS = 5 * 6e4;
|
|
|
15729
15797
|
var TASK_WAIT_MAX_TIMEOUT_MS = 5 * 6e4;
|
|
15730
15798
|
var TASK_WAIT_POLL_INTERVAL_MS = 250;
|
|
15731
15799
|
var TASK_STOP_GRACE_MS = 2e3;
|
|
15800
|
+
var TASK_STOP_POLL_INTERVAL_MS = 40;
|
|
15732
15801
|
function resolveCleanupReport(evidence, previousStatus) {
|
|
15733
15802
|
const diagnostic = evidence.diagnostic ? { diagnostic: evidence.diagnostic } : {};
|
|
15734
15803
|
if (evidence.confirmedStopped) {
|
|
@@ -15745,7 +15814,7 @@ function resolveCleanupReport(evidence, previousStatus) {
|
|
|
15745
15814
|
}
|
|
15746
15815
|
var TERMINAL_EVENT_TYPES = /* @__PURE__ */ new Set(["exited", "killed"]);
|
|
15747
15816
|
function defaultSleep(ms) {
|
|
15748
|
-
return new Promise((
|
|
15817
|
+
return new Promise((resolve7) => setTimeout(resolve7, ms));
|
|
15749
15818
|
}
|
|
15750
15819
|
function defaultSignalSender(pid, signal) {
|
|
15751
15820
|
process.kill(pid, signal);
|
|
@@ -15950,8 +16019,17 @@ async function runTaskStop(args2) {
|
|
|
15950
16019
|
)
|
|
15951
16020
|
};
|
|
15952
16021
|
}
|
|
15953
|
-
|
|
15954
|
-
if (
|
|
16022
|
+
let alive = isProcessGroupAlive(record2.pgid, kill);
|
|
16023
|
+
if (alive && graceMs > 0) {
|
|
16024
|
+
let remaining = graceMs;
|
|
16025
|
+
while (remaining > 0 && alive) {
|
|
16026
|
+
const step = Math.min(TASK_STOP_POLL_INTERVAL_MS, remaining);
|
|
16027
|
+
await sleep3(step);
|
|
16028
|
+
remaining -= step;
|
|
16029
|
+
alive = isProcessGroupAlive(record2.pgid, kill);
|
|
16030
|
+
}
|
|
16031
|
+
}
|
|
16032
|
+
if (!alive) {
|
|
15955
16033
|
return {
|
|
15956
16034
|
outcome: "stopped",
|
|
15957
16035
|
taskId,
|
|
@@ -15996,6 +16074,7 @@ var WORKSPACE_TOOL_NAMES = [
|
|
|
15996
16074
|
"writeFile",
|
|
15997
16075
|
"editFile",
|
|
15998
16076
|
"globFiles",
|
|
16077
|
+
"searchFiles",
|
|
15999
16078
|
"captureVisualState",
|
|
16000
16079
|
"execShell",
|
|
16001
16080
|
"launchProcess",
|
|
@@ -16020,13 +16099,13 @@ function buildWorkspacePathProperty() {
|
|
|
16020
16099
|
};
|
|
16021
16100
|
}
|
|
16022
16101
|
function buildReadWorkspaceDescription() {
|
|
16023
|
-
return "Read a UTF-8 text file inside the workspace. Absolute paths and ~/ are also accepted (runtime spill files can be read directly). Use lines for focused range reads after search to save tokens. A range already delivered earlier for an unchanged file answers with a short notice instead of resending (force:true refetches).";
|
|
16102
|
+
return "Read a UTF-8 text file inside the workspace. For multiple files, call readFile concurrently in the same turn. Absolute paths and ~/ are also accepted (runtime spill files can be read directly). Use lines for focused range reads after search to save tokens. A range already delivered earlier for an unchanged file answers with a short notice instead of resending (force:true refetches).";
|
|
16024
16103
|
}
|
|
16025
16104
|
function buildReadWorkspaceParameters() {
|
|
16026
16105
|
const path = buildWorkspacePathProperty();
|
|
16027
16106
|
const lines = {
|
|
16028
16107
|
type: "string",
|
|
16029
|
-
description: 'Line slice: "40-120" (range, 1-based, inclusive), "120-" (from line to end), "-50" (tail N lines), "50" (head N lines). Omit to read
|
|
16108
|
+
description: 'Line slice: "40-120" (range, 1-based, inclusive), "120-" (from line to end), "-50" (tail N lines), "50" (head N lines). Omit to read from the start; large results return a bounded window. Continue from metadata endLine + 1.'
|
|
16030
16109
|
};
|
|
16031
16110
|
const force = {
|
|
16032
16111
|
type: "boolean",
|
|
@@ -16345,6 +16424,31 @@ function buildWorkspaceToolDefinition(toolName) {
|
|
|
16345
16424
|
if (toolName === "editFile") {
|
|
16346
16425
|
return buildReplaceWorkspaceTextTool();
|
|
16347
16426
|
}
|
|
16427
|
+
if (toolName === "searchFiles") {
|
|
16428
|
+
return {
|
|
16429
|
+
type: "function",
|
|
16430
|
+
function: {
|
|
16431
|
+
name: "searchFiles",
|
|
16432
|
+
description: "Search UTF-8 text files in the workspace by literal string or regex (works across code, docs, notes, and data files on Windows/macOS/Linux; respects .gitignore by default and stops early at maxResults). Prefer searchFiles over shell grep/rg/Select-String.",
|
|
16433
|
+
parameters: {
|
|
16434
|
+
type: "object",
|
|
16435
|
+
properties: {
|
|
16436
|
+
query: { type: "string", minLength: 1, description: "Search text. Also accepts pattern when query is omitted (grep/rg alias compatibility)." },
|
|
16437
|
+
path: buildWorkspacePathProperty(),
|
|
16438
|
+
regex: { type: "boolean", description: "Default false: search for a literal string. Set true for regex." },
|
|
16439
|
+
caseSensitive: { type: "boolean", description: "Default true." },
|
|
16440
|
+
include: { type: "string", description: "File glob filter, e.g. *.{ts,md}." },
|
|
16441
|
+
exclude: { type: "array", items: { type: "string" } },
|
|
16442
|
+
contextLines: { type: "integer", minimum: 0, maximum: 5 },
|
|
16443
|
+
maxResults: { type: "integer", minimum: 1, maximum: 1e3, description: "Default 100; stop early after this many matches." },
|
|
16444
|
+
includeIgnored: { type: "boolean", description: "Default false: respect .gitignore." }
|
|
16445
|
+
},
|
|
16446
|
+
required: ["query"],
|
|
16447
|
+
additionalProperties: false
|
|
16448
|
+
}
|
|
16449
|
+
}
|
|
16450
|
+
};
|
|
16451
|
+
}
|
|
16348
16452
|
if (toolName === "globFiles") {
|
|
16349
16453
|
return buildGlobWorkspaceFilesTool();
|
|
16350
16454
|
}
|
|
@@ -16366,9 +16470,9 @@ function filterDeclaredWorkspaceToolNames(args2) {
|
|
|
16366
16470
|
// packages/agent-runtime/workspacePathGuard.ts
|
|
16367
16471
|
import { constants as fsConstants } from "node:fs";
|
|
16368
16472
|
import { lstat, mkdir, open, readlink, realpath as realpath2 } from "node:fs/promises";
|
|
16369
|
-
import { basename as basename3, dirname, isAbsolute as isAbsolute2, join as join2, relative as relative3, resolve as
|
|
16473
|
+
import { basename as basename3, dirname, isAbsolute as isAbsolute2, join as join2, relative as relative3, resolve as resolve4, sep } from "node:path";
|
|
16370
16474
|
function isPathInsideRoot(root, targetPath) {
|
|
16371
|
-
const rel = relative3(
|
|
16475
|
+
const rel = relative3(resolve4(root), resolve4(targetPath));
|
|
16372
16476
|
return rel === "" || rel !== ".." && !rel.startsWith(`..${sep}`) && !isAbsolute2(rel);
|
|
16373
16477
|
}
|
|
16374
16478
|
function isNotFoundError(error) {
|
|
@@ -16377,7 +16481,7 @@ function isNotFoundError(error) {
|
|
|
16377
16481
|
}
|
|
16378
16482
|
async function realpathAllowMissing(targetPath) {
|
|
16379
16483
|
const tail = [];
|
|
16380
|
-
let current =
|
|
16484
|
+
let current = resolve4(targetPath);
|
|
16381
16485
|
for (; ; ) {
|
|
16382
16486
|
try {
|
|
16383
16487
|
const real = await realpath2(current);
|
|
@@ -16396,8 +16500,8 @@ async function realpathAllowMissing(targetPath) {
|
|
|
16396
16500
|
}
|
|
16397
16501
|
async function resolveWorkspaceSafePath(args2) {
|
|
16398
16502
|
const requested = args2.requestedPath ?? args2.targetPath;
|
|
16399
|
-
const lexicalRoot =
|
|
16400
|
-
const targetPath =
|
|
16503
|
+
const lexicalRoot = resolve4(args2.workspaceRoot);
|
|
16504
|
+
const targetPath = resolve4(args2.targetPath);
|
|
16401
16505
|
const lexicalInside = args2.lexicalInside ?? isPathInsideRoot(lexicalRoot, targetPath);
|
|
16402
16506
|
const [physicalRoot, resolved] = await Promise.all([
|
|
16403
16507
|
realpath2(lexicalRoot).catch(() => null),
|
|
@@ -16553,7 +16657,7 @@ async function openPinnedDirectory(dirPath, guard) {
|
|
|
16553
16657
|
}
|
|
16554
16658
|
async function createMissingDirectoryChain(guard) {
|
|
16555
16659
|
const missing = [];
|
|
16556
|
-
let existing =
|
|
16660
|
+
let existing = resolve4(guard.path);
|
|
16557
16661
|
for (; ; ) {
|
|
16558
16662
|
try {
|
|
16559
16663
|
await lstat(existing);
|
|
@@ -16673,25 +16777,6 @@ async function readRootGitignorePatterns2(workspaceRoot) {
|
|
|
16673
16777
|
return readRootGitignorePatterns(workspaceRoot);
|
|
16674
16778
|
}
|
|
16675
16779
|
var DEFAULT_LOCAL_API_ORIGIN = "http://127.0.0.1:38123";
|
|
16676
|
-
var ALWAYS_EXCLUDED_GLOBS = [
|
|
16677
|
-
".git/**",
|
|
16678
|
-
".nolo/**",
|
|
16679
|
-
"node_modules/**",
|
|
16680
|
-
"*.tsbuildinfo",
|
|
16681
|
-
"dist/**",
|
|
16682
|
-
"build/**",
|
|
16683
|
-
"out/**",
|
|
16684
|
-
"coverage/**",
|
|
16685
|
-
".next/**",
|
|
16686
|
-
".turbo/**",
|
|
16687
|
-
"public/assets/**",
|
|
16688
|
-
"*.min.js",
|
|
16689
|
-
"*.min.css",
|
|
16690
|
-
"*.map",
|
|
16691
|
-
"*.lock",
|
|
16692
|
-
"bun.lockb",
|
|
16693
|
-
"*.ldb"
|
|
16694
|
-
];
|
|
16695
16780
|
function readTrimmedString(value) {
|
|
16696
16781
|
return asOptionalTrimmedString(value);
|
|
16697
16782
|
}
|
|
@@ -16815,7 +16900,6 @@ function readExpectedReplacementCount(args2) {
|
|
|
16815
16900
|
}
|
|
16816
16901
|
return value;
|
|
16817
16902
|
}
|
|
16818
|
-
var READ_FILE_SLICE_FALLBACK_LINES = 200;
|
|
16819
16903
|
function isAbsentArg(value) {
|
|
16820
16904
|
return value === void 0 || value === null;
|
|
16821
16905
|
}
|
|
@@ -16887,17 +16971,9 @@ function parseLinesArg(value) {
|
|
|
16887
16971
|
return { slice: { startLine, endLine } };
|
|
16888
16972
|
}
|
|
16889
16973
|
function readFileSliceArgs(args2) {
|
|
16890
|
-
|
|
16891
|
-
const withFallback = (slice2, invalidLines) => {
|
|
16892
|
-
warnings.push(
|
|
16893
|
-
`No usable line range remained; returned the first ${READ_FILE_SLICE_FALLBACK_LINES} lines instead of the whole file.`
|
|
16894
|
-
);
|
|
16895
|
-
return { ...slice2, maxLines: READ_FILE_SLICE_FALLBACK_LINES, warnings, invalidLines };
|
|
16896
|
-
};
|
|
16897
|
-
if (isAbsentArg(args2.lines)) return { warnings, invalidLines: void 0 };
|
|
16974
|
+
if (isAbsentArg(args2.lines) || args2.lines === "") return {};
|
|
16898
16975
|
const { slice, warning } = parseLinesArg(args2.lines);
|
|
16899
|
-
|
|
16900
|
-
return slice ? { ...slice, warnings, invalidLines: void 0 } : withFallback({}, describeRejectedArgValue(args2.lines));
|
|
16976
|
+
return slice ? { slice } : { error: clipMarkerValue(warning ?? "Invalid line range", 240) };
|
|
16901
16977
|
}
|
|
16902
16978
|
function buildReadFileSliceHint(totalLines) {
|
|
16903
16979
|
return `File has ${totalLines} lines. Use lines: ${LINES_ARG_SYNTAX}, or omit it for the whole file.`;
|
|
@@ -17040,7 +17116,7 @@ function resolveRipgrepBinary(env = process.env) {
|
|
|
17040
17116
|
const fromEnv = asOptionalTrimmedString(env.NOLO_BUNDLED_RG);
|
|
17041
17117
|
if (fromEnv) {
|
|
17042
17118
|
try {
|
|
17043
|
-
if (
|
|
17119
|
+
if (existsSync3(fromEnv)) return fromEnv;
|
|
17044
17120
|
} catch {
|
|
17045
17121
|
}
|
|
17046
17122
|
}
|
|
@@ -17061,14 +17137,14 @@ async function resolveRuntimeOwnedSpillPath(targetPath) {
|
|
|
17061
17137
|
}
|
|
17062
17138
|
function expandHomePath(requestedPath) {
|
|
17063
17139
|
if (requestedPath === "~") return homedir();
|
|
17064
|
-
if (requestedPath.startsWith("~/")) return
|
|
17140
|
+
if (requestedPath.startsWith("~/")) return resolve5(homedir(), requestedPath.slice(2));
|
|
17065
17141
|
return requestedPath;
|
|
17066
17142
|
}
|
|
17067
17143
|
function resolveRequestedWorkspacePath(workspaceRoot, requestedPath) {
|
|
17068
|
-
return
|
|
17144
|
+
return resolve5(resolve5(workspaceRoot), expandHomePath(requestedPath));
|
|
17069
17145
|
}
|
|
17070
17146
|
async function resolveLocalWorkspaceToolApproval(args2) {
|
|
17071
|
-
const workspaceRoot =
|
|
17147
|
+
const workspaceRoot = resolve5(args2.workspaceRoot);
|
|
17072
17148
|
const targetPath = resolveRequestedWorkspacePath(workspaceRoot, args2.requestedPath);
|
|
17073
17149
|
const insideWorkspace = isPathInsideWorkspace({ workspaceRoot, targetPath });
|
|
17074
17150
|
const guard = await resolveWorkspaceSafePath({
|
|
@@ -17165,9 +17241,64 @@ var READ_FILE_LEDGER_MAX_RECORDS = 64;
|
|
|
17165
17241
|
var READ_FILE_LEDGER_MAX_KEYS = 256;
|
|
17166
17242
|
async function readFileTool(args2) {
|
|
17167
17243
|
const parsed = parseWorkspaceToolArguments(args2.call.arguments);
|
|
17244
|
+
if (parsed.files !== void 0 && !args2.batchItem) {
|
|
17245
|
+
if (!Array.isArray(parsed.files) || parsed.files.length < 1 || parsed.files.length > 8 || pickFirstAlias(parsed, PATH_FIELD_ALIASES) !== void 0) {
|
|
17246
|
+
return { content: "[readFile] Supply either path or files (1\u20138 items), not both.", metadata: { status: "invalid-arguments" } };
|
|
17247
|
+
}
|
|
17248
|
+
if (parsed.files.some((file) => !file || typeof file !== "object" || typeof file.path !== "string" || !file.path || file.path.length > 512 || file.lines !== void 0 && typeof file.lines !== "string")) {
|
|
17249
|
+
return { content: "[readFile] Each batch item requires a path (maximum 512 characters) and optional string lines.", metadata: { status: "invalid-arguments" } };
|
|
17250
|
+
}
|
|
17251
|
+
const items = parsed.files.map((item) => ({ path: item.path, status: "not-delivered" }));
|
|
17252
|
+
const budget = resolveHistoricalToolContentCap("readFile", 0);
|
|
17253
|
+
const batchStartLedger = args2.readLedger ? new Map([...args2.readLedger].map(([key, entry2]) => [key, { ...entry2, records: [...entry2.records] }])) : void 0;
|
|
17254
|
+
for (let i = 0; i < parsed.files.length; i++) {
|
|
17255
|
+
const file = parsed.files[i];
|
|
17256
|
+
if (!file || typeof file !== "object" || typeof file.path !== "string" || !file.path || file.lines !== void 0 && typeof file.lines !== "string") {
|
|
17257
|
+
items[i] = { ...items[i], status: "invalid-arguments" };
|
|
17258
|
+
continue;
|
|
17259
|
+
}
|
|
17260
|
+
const trialLedger = args2.readLedger ? new Map([...args2.readLedger].map(([key, entry2]) => [key, { ...entry2, records: [...entry2.records] }])) : void 0;
|
|
17261
|
+
try {
|
|
17262
|
+
const result4 = await readFileTool({ ...args2, batchItem: true, readLedger: trialLedger, call: { ...args2.call, arguments: JSON.stringify(file) } });
|
|
17263
|
+
const metadata2 = result4.metadata ?? {};
|
|
17264
|
+
const candidate = { path: file.path, status: metadata2.deduped ? "already-delivered" : metadata2.status === "invalid-arguments" ? "invalid-arguments" : metadata2.truncatedByCharLimit || metadata2.partialLine ? "partial" : "complete", content: result4.content, ...metadata2 };
|
|
17265
|
+
const previous = items[i];
|
|
17266
|
+
items[i] = candidate;
|
|
17267
|
+
const formatted = formatToolMessageContent({ toolName: "readFile", content: JSON.stringify(items), metadata: { batch: true, items: items.map(({ path, status, startLine, endLine }) => ({ path, status, startLine, endLine })) } });
|
|
17268
|
+
if (formatted.length > budget) {
|
|
17269
|
+
items[i] = previous;
|
|
17270
|
+
continue;
|
|
17271
|
+
}
|
|
17272
|
+
if (args2.readLedger && trialLedger) {
|
|
17273
|
+
args2.readLedger.clear();
|
|
17274
|
+
for (const [key, value] of trialLedger) args2.readLedger.set(key, value);
|
|
17275
|
+
}
|
|
17276
|
+
} catch {
|
|
17277
|
+
items[i] = { path: file.path, status: "error" };
|
|
17278
|
+
}
|
|
17279
|
+
}
|
|
17280
|
+
const batchContent = JSON.stringify(items);
|
|
17281
|
+
const batchMetadata = { batch: true, items: items.map(({ path, status, startLine, endLine }) => ({ path, status, startLine, endLine })) };
|
|
17282
|
+
if (formatToolMessageContent({ toolName: "readFile", content: batchContent, metadata: batchMetadata }).length > budget) {
|
|
17283
|
+
if (args2.readLedger && batchStartLedger) {
|
|
17284
|
+
args2.readLedger.clear();
|
|
17285
|
+
for (const [key, value] of batchStartLedger) args2.readLedger.set(key, value);
|
|
17286
|
+
}
|
|
17287
|
+
return { content: "[readFile] Batch request exceeds the shared delivery budget; no content delivered. Use fewer or shorter paths.", metadata: { status: "batch-limit-exceeded" } };
|
|
17288
|
+
}
|
|
17289
|
+
return { content: batchContent, metadata: batchMetadata };
|
|
17290
|
+
}
|
|
17168
17291
|
const requestedPath = requireWorkspaceToolPath(parsed);
|
|
17169
|
-
const
|
|
17170
|
-
|
|
17292
|
+
const parsedSlice = readFileSliceArgs(parsed);
|
|
17293
|
+
if (parsedSlice.error) {
|
|
17294
|
+
return {
|
|
17295
|
+
content: `[readFile] Invalid lines: ${parsedSlice.error} No file content was read. Use lines: ${LINES_ARG_SYNTAX}, or omit lines.`,
|
|
17296
|
+
metadata: { status: "invalid-arguments", tool: "readFile" }
|
|
17297
|
+
};
|
|
17298
|
+
}
|
|
17299
|
+
const sliceArgs = parsedSlice.slice ?? {};
|
|
17300
|
+
const warnings = [];
|
|
17301
|
+
const approval = await resolveLocalWorkspaceToolApproval({
|
|
17171
17302
|
workspaceRoot: args2.workspaceRoot,
|
|
17172
17303
|
requestedPath,
|
|
17173
17304
|
allowRuntimeOwnedSpill: true,
|
|
@@ -17182,45 +17313,101 @@ async function readFileTool(args2) {
|
|
|
17182
17313
|
content,
|
|
17183
17314
|
...sliceArgs
|
|
17184
17315
|
});
|
|
17185
|
-
const truncatedRead = defensivelyTruncateReadFile({
|
|
17186
|
-
content: sliced.content,
|
|
17187
|
-
totalLines: sliced.totalLines
|
|
17188
|
-
});
|
|
17189
|
-
const invalidLinesMarker = invalidLines !== void 0 ? `[readFile] lines=${clipMarkerValue(invalidLines)} was rejected (only ONE range: ${LINES_ARG_SYNTAX}); returned lines ${sliced.startLine}-${sliced.endLine} instead. Fix the argument before relying on this window.
|
|
17190
|
-
` : "";
|
|
17191
|
-
const finalRead = invalidLinesMarker.length > 0 ? defensivelyTruncateReadFile({
|
|
17192
|
-
content: truncatedRead.content,
|
|
17193
|
-
totalLines: sliced.totalLines,
|
|
17194
|
-
limit: Math.max(1, READ_FILE_MAX_CHAR_LIMIT - invalidLinesMarker.length)
|
|
17195
|
-
}) : truncatedRead;
|
|
17196
|
-
const finalContent = invalidLinesMarker + finalRead.content;
|
|
17197
|
-
const truncatedByCharLimit = truncatedRead.truncatedByCharLimit || finalRead.truncatedByCharLimit;
|
|
17198
|
-
const isTruncated = sliced.truncated || truncatedByCharLimit;
|
|
17199
17316
|
const relativePath = normalizeWorkspaceRelativePath({
|
|
17200
|
-
workspaceRoot:
|
|
17317
|
+
workspaceRoot: resolve5(args2.workspaceRoot),
|
|
17201
17318
|
targetPath: absolutePath
|
|
17202
17319
|
});
|
|
17320
|
+
const instructionPath = AGENTS_MD_CANDIDATES.some((name) => absolutePath === resolve5(args2.workspaceRoot, name));
|
|
17321
|
+
const instructionLimit = PROJECT_INSTRUCTION_MAX_BYTES;
|
|
17322
|
+
const instructionOversized = Buffer.byteLength(content) > instructionLimit || countLines(content) > TOOL_OUTPUT_SPILL_LINES;
|
|
17323
|
+
const instruction = !args2.batchItem && instructionPath && !instructionOversized;
|
|
17324
|
+
if (!args2.batchItem && instructionPath && instructionOversized && Object.keys(sliceArgs).length === 0) {
|
|
17325
|
+
return {
|
|
17326
|
+
content: `[readFile] Project instruction exceeds the delivery limit (${instructionLimit} bytes or ${TOOL_OUTPUT_SPILL_LINES} lines); no content delivered. Continue with lines="1-" to inspect the first bounded range.`,
|
|
17327
|
+
metadata: { path: relativePath, status: "instruction-limit-exceeded", truncated: true, totalBytes: Buffer.byteLength(originalContent) }
|
|
17328
|
+
};
|
|
17329
|
+
}
|
|
17330
|
+
const cap = instruction ? PROJECT_INSTRUCTION_MAX_CHARS : resolveHistoricalToolContentCap("readFile", 0);
|
|
17331
|
+
const selectedLines = splitTextLines(sliced.content);
|
|
17332
|
+
const makeMetadata = (body, endLine, windowed2, partialLine) => ({
|
|
17333
|
+
path: relativePath,
|
|
17334
|
+
...instruction ? { projectInstruction: true } : {},
|
|
17335
|
+
bytes: Buffer.byteLength(body),
|
|
17336
|
+
totalBytes: Buffer.byteLength(originalContent),
|
|
17337
|
+
...projection.projected ? {
|
|
17338
|
+
projection: "run-result-observations",
|
|
17339
|
+
projectedTotalBytes: Buffer.byteLength(content),
|
|
17340
|
+
rawReadHint: "readFile raw:true reads original evidence; line numbers are unchanged."
|
|
17341
|
+
} : {},
|
|
17342
|
+
startLine: sliced.startLine,
|
|
17343
|
+
...partialLine ? { partialLine: true } : { endLine },
|
|
17344
|
+
totalLines: sliced.totalLines,
|
|
17345
|
+
truncated: sliced.truncated || windowed2,
|
|
17346
|
+
...scrubSecrets(sanitizeToolOutputText(body)).cleaned !== body ? { contentSanitized: true } : {},
|
|
17347
|
+
...windowed2 ? { truncatedByByteLimit: true, truncatedByCharLimit: true } : {},
|
|
17348
|
+
...sliceArgs.maxLines ? { maxLines: sliceArgs.maxLines } : {},
|
|
17349
|
+
...sliceArgs.tailLines ? { tailLines: sliceArgs.tailLines } : {},
|
|
17350
|
+
...activity ? { activity } : {}
|
|
17351
|
+
});
|
|
17352
|
+
const fits = (body, endLine, windowed2) => {
|
|
17353
|
+
if (Buffer.byteLength(body) > TOOL_OUTPUT_SPILL_BYTES || countLines(body) > TOOL_OUTPUT_SPILL_LINES) return false;
|
|
17354
|
+
const metadata2 = makeMetadata(body, endLine, windowed2, false);
|
|
17355
|
+
return formatToolMessageContent({ toolName: "readFile", content: body, metadata: metadata2 }).length <= cap;
|
|
17356
|
+
};
|
|
17357
|
+
let deliveredCount = selectedLines.length;
|
|
17358
|
+
let finalContent = sliced.content;
|
|
17359
|
+
let windowed = false;
|
|
17360
|
+
if (!fits(finalContent, sliced.endLine, false)) {
|
|
17361
|
+
let low = 0;
|
|
17362
|
+
let high = selectedLines.length;
|
|
17363
|
+
while (low < high) {
|
|
17364
|
+
const mid = Math.ceil((low + high) / 2);
|
|
17365
|
+
const candidate = selectedLines.slice(0, mid).join("\n");
|
|
17366
|
+
if (fits(candidate, sliced.startLine + mid - 1, true)) low = mid;
|
|
17367
|
+
else high = mid - 1;
|
|
17368
|
+
}
|
|
17369
|
+
deliveredCount = low;
|
|
17370
|
+
windowed = true;
|
|
17371
|
+
finalContent = selectedLines.slice(0, deliveredCount).join("\n");
|
|
17372
|
+
}
|
|
17373
|
+
const oversizedLine = windowed && deliveredCount === 0;
|
|
17374
|
+
if (oversizedLine) {
|
|
17375
|
+
let low = 0;
|
|
17376
|
+
let high = Math.min(sliced.content.length, cap);
|
|
17377
|
+
while (low < high) {
|
|
17378
|
+
const mid = Math.ceil((low + high) / 2);
|
|
17379
|
+
const candidate = defensivelyTruncateReadFile({ content: sliced.content, totalLines: sliced.totalLines, limit: mid }).content;
|
|
17380
|
+
const metadata2 = makeMetadata(candidate, sliced.startLine, true, true);
|
|
17381
|
+
const fitsPreview = Buffer.byteLength(candidate) <= TOOL_OUTPUT_SPILL_BYTES && countLines(candidate) <= TOOL_OUTPUT_SPILL_LINES && formatToolMessageContent({ toolName: "readFile", content: candidate, metadata: metadata2 }).length <= cap;
|
|
17382
|
+
if (fitsPreview) low = mid;
|
|
17383
|
+
else high = mid - 1;
|
|
17384
|
+
}
|
|
17385
|
+
finalContent = low > 0 ? defensivelyTruncateReadFile({ content: sliced.content, totalLines: sliced.totalLines, limit: low }).content : "[readFile] Line exceeds the delivery budget; use codeSearch or another tool to inspect it.";
|
|
17386
|
+
}
|
|
17387
|
+
const deliveredEndLine = windowed && !oversizedLine ? sliced.startLine + deliveredCount - 1 : sliced.endLine;
|
|
17388
|
+
const metadata = makeMetadata(finalContent, deliveredEndLine, windowed, oversizedLine);
|
|
17203
17389
|
const force = parsed.force === true;
|
|
17204
17390
|
const ledger = args2.readLedger;
|
|
17205
|
-
const
|
|
17391
|
+
const deliveredRange = { startLine: sliced.startLine, endLine: deliveredEndLine };
|
|
17206
17392
|
const fingerprint = createHash3("sha1").update(originalContent).update(parsed.raw === true ? "\0raw" : "\0default").digest("hex").slice(0, 20);
|
|
17207
17393
|
let entry = ledger?.get(relativePath);
|
|
17208
17394
|
if (entry && entry.fingerprint !== fingerprint) {
|
|
17209
17395
|
entry = void 0;
|
|
17210
17396
|
ledger?.delete(relativePath);
|
|
17211
17397
|
}
|
|
17212
|
-
if (!force && entry && ledger) {
|
|
17213
|
-
const retainedCap = resolveHistoricalToolContentCap("readFile", 0);
|
|
17398
|
+
if (!force && entry && ledger && !oversizedLine) {
|
|
17399
|
+
const retainedCap = instructionPath && !instructionOversized ? PROJECT_INSTRUCTION_MAX_CHARS : resolveHistoricalToolContentCap("readFile", 0);
|
|
17214
17400
|
const retained = filterRetainedLedgerRecords(entry.records, retainedCap);
|
|
17215
|
-
if (retained.length > 0 && isLineRangeCovered(
|
|
17401
|
+
if (retained.length > 0 && isLineRangeCovered(deliveredRange, retained)) {
|
|
17216
17402
|
ledger.delete(relativePath);
|
|
17217
17403
|
ledger.set(relativePath, entry);
|
|
17218
17404
|
return {
|
|
17219
|
-
content: `[readFile] ${relativePath} lines ${
|
|
17405
|
+
content: `[readFile] ${relativePath} lines ${deliveredRange.startLine}-${deliveredRange.endLine} were already delivered earlier and the file is unchanged; not resending. Pass force:true to refetch.` + (windowed ? ` Continue with lines=${deliveredEndLine + 1}-.` : ""),
|
|
17220
17406
|
metadata: {
|
|
17221
17407
|
path: relativePath,
|
|
17222
|
-
startLine:
|
|
17223
|
-
endLine:
|
|
17408
|
+
startLine: deliveredRange.startLine,
|
|
17409
|
+
endLine: deliveredRange.endLine,
|
|
17410
|
+
...windowed ? { truncated: true } : {},
|
|
17224
17411
|
totalLines: sliced.totalLines,
|
|
17225
17412
|
deduped: true,
|
|
17226
17413
|
...warnings.length ? { warnings: [...warnings, buildReadFileSliceHint(sliced.totalLines)] } : {},
|
|
@@ -17229,29 +17416,10 @@ async function readFileTool(args2) {
|
|
|
17229
17416
|
};
|
|
17230
17417
|
}
|
|
17231
17418
|
}
|
|
17232
|
-
|
|
17233
|
-
|
|
17234
|
-
bytes: Buffer.byteLength(finalContent),
|
|
17235
|
-
totalBytes: Buffer.byteLength(originalContent),
|
|
17236
|
-
...projection.projected ? {
|
|
17237
|
-
projection: "run-result-observations",
|
|
17238
|
-
projectedTotalBytes: Buffer.byteLength(content),
|
|
17239
|
-
rawReadHint: "readFile raw:true reads original evidence; line numbers are unchanged."
|
|
17240
|
-
} : {},
|
|
17241
|
-
startLine: sliced.startLine,
|
|
17242
|
-
endLine: sliced.endLine,
|
|
17243
|
-
totalLines: sliced.totalLines,
|
|
17244
|
-
truncated: isTruncated,
|
|
17245
|
-
...truncatedByCharLimit ? { truncatedByByteLimit: true, truncatedByCharLimit: true } : {},
|
|
17246
|
-
...sliceArgs.maxLines ? { maxLines: sliceArgs.maxLines } : {},
|
|
17247
|
-
...sliceArgs.tailLines ? { tailLines: sliceArgs.tailLines } : {},
|
|
17248
|
-
...warnings.length ? { warnings: [...warnings, buildReadFileSliceHint(sliced.totalLines)] } : {},
|
|
17249
|
-
...activity ? { activity } : {}
|
|
17250
|
-
};
|
|
17251
|
-
if (!isTruncated && ledger) {
|
|
17252
|
-
const persistedChars = finalContent.length + "\n\n[tool metadata]\n".length + JSON.stringify(metadata).length;
|
|
17419
|
+
if (!oversizedLine && ledger) {
|
|
17420
|
+
const persistedChars = formatToolMessageContent({ toolName: "readFile", content: finalContent, metadata }).length;
|
|
17253
17421
|
const records = entry?.records ?? [];
|
|
17254
|
-
records.push({ ...
|
|
17422
|
+
records.push({ ...deliveredRange, chars: persistedChars });
|
|
17255
17423
|
ledger.delete(relativePath);
|
|
17256
17424
|
ledger.set(relativePath, {
|
|
17257
17425
|
fingerprint,
|
|
@@ -17287,7 +17455,7 @@ async function writeFileTool(args2) {
|
|
|
17287
17455
|
await ensureGuardedParentDirectory({ workspaceRoot: args2.workspaceRoot, fileApproval: approval });
|
|
17288
17456
|
await writeGuardApprovedFile(approval, content);
|
|
17289
17457
|
const relativePath = normalizeWorkspaceRelativePath({
|
|
17290
|
-
workspaceRoot:
|
|
17458
|
+
workspaceRoot: resolve5(args2.workspaceRoot),
|
|
17291
17459
|
targetPath: absolutePath
|
|
17292
17460
|
});
|
|
17293
17461
|
const activity = extractActivity(parsed);
|
|
@@ -17410,7 +17578,7 @@ ${hint}` : "")
|
|
|
17410
17578
|
}
|
|
17411
17579
|
await writeGuardApprovedFile(approval, nextContent);
|
|
17412
17580
|
const relativePath = normalizeWorkspaceRelativePath({
|
|
17413
|
-
workspaceRoot:
|
|
17581
|
+
workspaceRoot: resolve5(args2.workspaceRoot),
|
|
17414
17582
|
targetPath: absolutePath
|
|
17415
17583
|
});
|
|
17416
17584
|
const activity = extractActivity(parsed);
|
|
@@ -17450,7 +17618,7 @@ async function listWorkspaceEntries(args2) {
|
|
|
17450
17618
|
const names = (await readdir2(dirPath)).sort((left, right) => left.localeCompare(right));
|
|
17451
17619
|
for (const name of names) {
|
|
17452
17620
|
if (truncated) break;
|
|
17453
|
-
const absolutePath =
|
|
17621
|
+
const absolutePath = resolve5(dirPath, name);
|
|
17454
17622
|
const info = await stat4(absolutePath);
|
|
17455
17623
|
const relativePath = relative4(args2.dirPath, absolutePath) || ".";
|
|
17456
17624
|
const isDirectory = info.isDirectory();
|
|
@@ -17479,28 +17647,30 @@ async function internalSearchWorkspace(args2) {
|
|
|
17479
17647
|
allowRuntimeOwnedSpill: true,
|
|
17480
17648
|
...args2.confirmExternalFileAccess ? { confirmExternalFileAccess: args2.confirmExternalFileAccess } : {}
|
|
17481
17649
|
});
|
|
17482
|
-
const workspaceRoot =
|
|
17650
|
+
const workspaceRoot = resolve5(args2.workspaceRoot);
|
|
17483
17651
|
const inside = isPathInsideWorkspace({ workspaceRoot, targetPath: searchPath });
|
|
17484
17652
|
const result4 = await searchFileTextMatches({
|
|
17485
17653
|
root: inside ? workspaceRoot : searchPath,
|
|
17486
17654
|
target: inside ? normalizeWorkspaceRelativePath({ workspaceRoot, targetPath: searchPath }) : ".",
|
|
17487
17655
|
query: args2.query,
|
|
17488
|
-
regex: true,
|
|
17656
|
+
regex: args2.regex ?? true,
|
|
17489
17657
|
caseSensitive: args2.caseSensitive !== false,
|
|
17490
17658
|
contextLines: args2.contextLines,
|
|
17491
17659
|
maxResults: args2.maxResults ?? 200,
|
|
17492
|
-
includeIgnored: args2.workspaceRoot.includes(".worktrees") || !inside,
|
|
17660
|
+
includeIgnored: args2.includeIgnored ?? (args2.workspaceRoot.includes(".worktrees") || !inside),
|
|
17493
17661
|
absolutePaths: !inside,
|
|
17494
|
-
exclude: inside ?
|
|
17662
|
+
exclude: [...inside ? ALWAYS_EXCLUDED_GLOBS : [], ...args2.exclude ?? []],
|
|
17663
|
+
include: args2.include,
|
|
17664
|
+
resolveRipgrepBinary: args2.resolveRipgrepBinary,
|
|
17665
|
+
resolveGrepBinary: args2.resolveGrepBinary
|
|
17495
17666
|
});
|
|
17496
17667
|
const outputLines = result4.matches.flatMap((match7) => [
|
|
17497
17668
|
...match7.before.map((line, index) => `${match7.path}:${Math.max(1, match7.line - match7.before.length + index)}-${line}`),
|
|
17498
17669
|
`${match7.path}:${match7.line}:${match7.text}`,
|
|
17499
17670
|
...match7.after.map((line, index) => `${match7.path}:${match7.line + index + 1}-${line}`)
|
|
17500
17671
|
]);
|
|
17501
|
-
const rawContent = outputLines.join("\n");
|
|
17672
|
+
const rawContent = scrubSecrets(outputLines.join("\n")).cleaned;
|
|
17502
17673
|
const content = truncateToolOutput(rawContent, SEARCH_OUTPUT_CHAR_LIMIT);
|
|
17503
|
-
const matchLines = result4.matches.map((match7) => `${match7.path}:${match7.line}:${match7.text}`);
|
|
17504
17674
|
return {
|
|
17505
17675
|
content,
|
|
17506
17676
|
metadata: {
|
|
@@ -17509,6 +17679,7 @@ async function internalSearchWorkspace(args2) {
|
|
|
17509
17679
|
searchedPath: inside ? normalizeWorkspaceRelativePath({ workspaceRoot, targetPath: searchPath }) : ".",
|
|
17510
17680
|
count: outputLines.length,
|
|
17511
17681
|
matchCount: result4.totalMatches,
|
|
17682
|
+
totalMatches: result4.totalMatches,
|
|
17512
17683
|
matchedFiles: Array.from(new Set(result4.matches.map((match7) => match7.path))),
|
|
17513
17684
|
truncated: result4.truncated || content.length !== rawContent.length,
|
|
17514
17685
|
limitedByMaxResults: result4.truncated,
|
|
@@ -17559,7 +17730,7 @@ async function globFilesTool(args2) {
|
|
|
17559
17730
|
...args2.confirmExternalFileAccess ? { confirmExternalFileAccess: args2.confirmExternalFileAccess } : {}
|
|
17560
17731
|
});
|
|
17561
17732
|
const relativeSearchPath = normalizeWorkspaceRelativePath({
|
|
17562
|
-
workspaceRoot:
|
|
17733
|
+
workspaceRoot: resolve5(args2.workspaceRoot),
|
|
17563
17734
|
targetPath: searchPath
|
|
17564
17735
|
});
|
|
17565
17736
|
const pathPrefix = relativeSearchPath === "." ? "" : `${relativeSearchPath.replace(/\/+$/, "")}/`;
|
|
@@ -17856,7 +18027,7 @@ async function launchProcessTool(args2) {
|
|
|
17856
18027
|
];
|
|
17857
18028
|
const detached = process.platform !== "win32";
|
|
17858
18029
|
const proc = spawnChildProcess2(cmdArgs[0] ?? "", cmdArgs.slice(1), {
|
|
17859
|
-
cwd:
|
|
18030
|
+
cwd: resolve5(args2.workspaceRoot),
|
|
17860
18031
|
stdio: ["ignore", "pipe", "pipe"],
|
|
17861
18032
|
detached,
|
|
17862
18033
|
windowsHide: true
|
|
@@ -18125,6 +18296,36 @@ function createLocalWorkspaceToolExecutors(args2) {
|
|
|
18125
18296
|
workspaceRoot: args2.workspaceRoot,
|
|
18126
18297
|
...fileAccess
|
|
18127
18298
|
}),
|
|
18299
|
+
searchFiles: async (call) => {
|
|
18300
|
+
const parsed = parseWorkspaceToolArguments(call.arguments);
|
|
18301
|
+
const query = parsed.query === void 0 ? parsed.pattern : parsed.query;
|
|
18302
|
+
if (typeof query !== "string" || !query.length) throw new Error("searchFiles requires a non-empty query.");
|
|
18303
|
+
for (const key of ["regex", "caseSensitive", "includeIgnored"]) {
|
|
18304
|
+
if (parsed[key] !== void 0 && typeof parsed[key] !== "boolean") throw new Error(`${key} must be a boolean.`);
|
|
18305
|
+
}
|
|
18306
|
+
for (const key of ["path", "include"]) {
|
|
18307
|
+
if (parsed[key] !== void 0 && typeof parsed[key] !== "string") throw new Error(`${key} must be a string.`);
|
|
18308
|
+
}
|
|
18309
|
+
if (parsed.exclude !== void 0 && (!Array.isArray(parsed.exclude) || !parsed.exclude.every((item) => typeof item === "string"))) throw new Error("exclude must be an array of strings.");
|
|
18310
|
+
for (const [key, min4, max4] of [["contextLines", 0, 5], ["maxResults", 1, 1e3]]) {
|
|
18311
|
+
if (parsed[key] !== void 0 && (!Number.isInteger(parsed[key]) || Number(parsed[key]) < min4 || Number(parsed[key]) > max4)) throw new Error(`${key} must be an integer from ${min4} to ${max4}.`);
|
|
18312
|
+
}
|
|
18313
|
+
return internalSearchWorkspace({
|
|
18314
|
+
workspaceRoot: args2.workspaceRoot,
|
|
18315
|
+
query,
|
|
18316
|
+
path: parsed.path,
|
|
18317
|
+
regex: parsed.regex === true,
|
|
18318
|
+
caseSensitive: parsed.caseSensitive !== false,
|
|
18319
|
+
include: parsed.include,
|
|
18320
|
+
exclude: parsed.exclude ?? [],
|
|
18321
|
+
contextLines: parsed.contextLines,
|
|
18322
|
+
maxResults: parsed.maxResults ?? 100,
|
|
18323
|
+
includeIgnored: parsed.includeIgnored === true,
|
|
18324
|
+
confirmExternalFileAccess: args2.confirmExternalFileAccess,
|
|
18325
|
+
resolveRipgrepBinary: args2.resolveRipgrepBinary,
|
|
18326
|
+
resolveGrepBinary: args2.resolveGrepBinary
|
|
18327
|
+
});
|
|
18328
|
+
},
|
|
18128
18329
|
globFiles: (call) => globFilesTool({
|
|
18129
18330
|
call,
|
|
18130
18331
|
workspaceRoot: args2.workspaceRoot,
|
|
@@ -18180,12 +18381,12 @@ function createLocalWorkspaceToolExecutors(args2) {
|
|
|
18180
18381
|
images: results2.flatMap((result4) => result4.images ?? [])
|
|
18181
18382
|
};
|
|
18182
18383
|
},
|
|
18183
|
-
readFile: (call) => readFileTool({
|
|
18384
|
+
readFile: Object.assign((call) => readFileTool({
|
|
18184
18385
|
call,
|
|
18185
18386
|
workspaceRoot: args2.workspaceRoot,
|
|
18186
18387
|
...readFileLedger ? { readLedger: readFileLedger } : {},
|
|
18187
18388
|
...fileAccess
|
|
18188
|
-
}),
|
|
18389
|
+
}), { resetReadLedger: () => readFileLedger?.clear() }),
|
|
18189
18390
|
writeFile: (call) => writeFileTool({
|
|
18190
18391
|
call,
|
|
18191
18392
|
workspaceRoot: args2.workspaceRoot,
|
|
@@ -18345,6 +18546,9 @@ function validateToolArguments(args2) {
|
|
|
18345
18546
|
}
|
|
18346
18547
|
record2 = parsed;
|
|
18347
18548
|
}
|
|
18549
|
+
if (toolName === "searchFiles" && record2.query === void 0 && typeof record2.pattern === "string" && record2.pattern.length) {
|
|
18550
|
+
record2 = { ...record2, query: record2.pattern };
|
|
18551
|
+
}
|
|
18348
18552
|
for (const field of requiredFields) {
|
|
18349
18553
|
if (record2[field] !== void 0) continue;
|
|
18350
18554
|
if (isAliasSatisfied(record2, field)) continue;
|
|
@@ -18429,6 +18633,7 @@ var DEFAULT_LOCAL_TOOLS = /* @__PURE__ */ new Set([
|
|
|
18429
18633
|
"writeFile",
|
|
18430
18634
|
"editFile",
|
|
18431
18635
|
"globFiles",
|
|
18636
|
+
"searchFiles",
|
|
18432
18637
|
"execShell",
|
|
18433
18638
|
"launchProcess",
|
|
18434
18639
|
"listProcesses",
|
|
@@ -19184,44 +19389,140 @@ function createTurnUsageLedger(args2) {
|
|
|
19184
19389
|
};
|
|
19185
19390
|
}
|
|
19186
19391
|
|
|
19187
|
-
// packages/agent-runtime/
|
|
19188
|
-
var
|
|
19392
|
+
// packages/agent-runtime/agentRunIsolation.ts
|
|
19393
|
+
var ORCHESTRATION_TOOL_NAMES = /* @__PURE__ */ new Set([
|
|
19394
|
+
"startAgentRun",
|
|
19395
|
+
"controlAgentRun",
|
|
19396
|
+
"listAgents",
|
|
19397
|
+
"readAgent",
|
|
19398
|
+
"runStreamingAgent"
|
|
19399
|
+
]);
|
|
19400
|
+
var INTERACTION_REQUIRED_TOOL_NAMES = /* @__PURE__ */ new Set([
|
|
19401
|
+
"ask_user",
|
|
19402
|
+
// 凭据请求:需要宿主交互面板(Block 1a);desktop 无通道时同 ask_user 剥离。
|
|
19403
|
+
"secret-request"
|
|
19404
|
+
]);
|
|
19405
|
+
var SELF_MUTATION_TOOL_NAMES = /* @__PURE__ */ new Set([
|
|
19406
|
+
"updateSelf",
|
|
19407
|
+
"updateAgent"
|
|
19408
|
+
]);
|
|
19409
|
+
var SUBTASK_REMOVED_TOOL_NAMES = /* @__PURE__ */ new Set([
|
|
19410
|
+
...ORCHESTRATION_TOOL_NAMES,
|
|
19411
|
+
...INTERACTION_REQUIRED_TOOL_NAMES,
|
|
19412
|
+
...SELF_MUTATION_TOOL_NAMES
|
|
19413
|
+
]);
|
|
19414
|
+
function isSubtaskRun(env) {
|
|
19415
|
+
if (!env) return false;
|
|
19416
|
+
const value = env.NOLO_AGENT_RUN_CHILD;
|
|
19417
|
+
return typeof value === "string" && value.length > 0 && value !== "0";
|
|
19418
|
+
}
|
|
19419
|
+
var RUN_WAKE_CHANNEL_ENV = "NOLO_RUN_WAKE";
|
|
19420
|
+
function hasRunWakeChannel(env) {
|
|
19421
|
+
if (!env) return false;
|
|
19422
|
+
const value = env[RUN_WAKE_CHANNEL_ENV];
|
|
19423
|
+
return typeof value === "string" && value.length > 0 && value !== "0";
|
|
19424
|
+
}
|
|
19425
|
+
function filterToolNamesForRunKind(toolNames, isSubtask) {
|
|
19426
|
+
if (!isSubtask) return [...toolNames];
|
|
19427
|
+
return toolNames.filter((name) => !SUBTASK_REMOVED_TOOL_NAMES.has(name));
|
|
19428
|
+
}
|
|
19189
19429
|
|
|
19190
|
-
// packages/agent-runtime/
|
|
19191
|
-
var
|
|
19192
|
-
|
|
19193
|
-
|
|
19194
|
-
|
|
19195
|
-
|
|
19196
|
-
|
|
19197
|
-
|
|
19198
|
-
|
|
19199
|
-
|
|
19200
|
-
|
|
19201
|
-
|
|
19202
|
-
if (
|
|
19203
|
-
if (
|
|
19204
|
-
|
|
19205
|
-
|
|
19206
|
-
|
|
19207
|
-
|
|
19208
|
-
|
|
19209
|
-
|
|
19210
|
-
|
|
19211
|
-
|
|
19212
|
-
|
|
19213
|
-
|
|
19214
|
-
|
|
19215
|
-
if (
|
|
19216
|
-
|
|
19217
|
-
|
|
19218
|
-
|
|
19219
|
-
|
|
19220
|
-
|
|
19221
|
-
|
|
19222
|
-
|
|
19430
|
+
// packages/agent-runtime/subtaskBudget.ts
|
|
19431
|
+
var DEFAULT_SUBTASK_SOFT_BUDGET_MILESTONE_1_TOOL_CALLS = 40;
|
|
19432
|
+
var DEFAULT_SUBTASK_SOFT_BUDGET_MILESTONE_2_TOOL_CALLS = 80;
|
|
19433
|
+
var SUBTASK_SOFT_BUDGET_MILESTONE_1_PREFIX = "[\u7CFB\u7EDF\u63D0\u793A \xB7 \u5B50\u4EFB\u52A1\u8F6F\u9884\u7B97\u63D0\u9192]";
|
|
19434
|
+
var SUBTASK_SOFT_BUDGET_MILESTONE_2_PREFIX = "[\u7CFB\u7EDF\u63D0\u793A \xB7 \u5B50\u4EFB\u52A1\u5F3A\u6536\u655B\u63D0\u9192]";
|
|
19435
|
+
function buildSubtaskSoftBudgetMilestone1Prompt(toolCallCount) {
|
|
19436
|
+
return `${SUBTASK_SOFT_BUDGET_MILESTONE_1_PREFIX} \u5F53\u524D\u5B50\u4EFB\u52A1\u5DF2\u7D2F\u8BA1\u6267\u884C ${toolCallCount} \u6B21\u5DE5\u5177\u8C03\u7528\uFF0C\u8BF7\u505A\u4E00\u6B21\u6536\u655B\u81EA\u68C0\uFF1A\u82E5\u6838\u5FC3\u76EE\u6807\u4E0E\u5FC5\u9700\u9A8C\u8BC1\u5DF2\u5B8C\u6210\uFF0C\u8BF7\u5C3D\u5FEB\u6574\u7406\u7ED3\u679C\u5E76\u6536\u655B\u4EA4\u4ED8\uFF1B\u82E5\u540C\u4E00\u62A5\u9519\u5DF2\u8FDE\u7EED\u91CD\u8BD5\u4E14\u65E0\u65B0\u8BC1\u636E\uFF0C\u8BF7\u505C\u6B62\u76F2\u8BD5\u5E76\u5728\u7ED3\u679C\u4E2D\u5982\u5B9E\u62A5\u544A\u6839\u56E0\u4E0E\u963B\u788D\uFF1B\u82E5\u786E\u7CFB\u6B63\u5E38\u7684\u591A\u6587\u4EF6\u4FEE\u6539\u6216\u9A8C\u8BC1\u5DE5\u4F5C\uFF0C\u53EF\u7EE7\u7EED\u7A33\u6B65\u5B8C\u6210\u3002`;
|
|
19437
|
+
}
|
|
19438
|
+
function buildSubtaskSoftBudgetMilestone2Prompt(toolCallCount) {
|
|
19439
|
+
return `${SUBTASK_SOFT_BUDGET_MILESTONE_2_PREFIX} \u5F53\u524D\u5B50\u4EFB\u52A1\u5DF2\u7D2F\u8BA1\u6267\u884C ${toolCallCount} \u6B21\u5DE5\u5177\u8C03\u7528\u3002\u5EFA\u8BAE\u5728\u5B8C\u6210\u5F53\u524D\u624B\u5934\u6700\u540E\u4E00\u6B65\u5FC5\u8981\u9A8C\u8BC1\u540E\uFF0C\u7ACB\u5373\u6574\u7406\u5DF2\u6709\u6210\u679C\u3001\u672A\u5B8C\u6210\u9879\u4E0E\u5EFA\u8BAE\u7684\u4E0B\u4E00\u6B65\u76F4\u63A5\u4EA4\u4ED8\u7236\u5BF9\u8BDD\uFF0C\u907F\u514D\u5355\u6B21\u5B50\u4EFB\u52A1\u8FC7\u5EA6\u6D88\u8017\u914D\u989D\u4E0E\u4E0A\u4E0B\u6587\u3002`;
|
|
19440
|
+
}
|
|
19441
|
+
function resolveSoftBudgetEnv(explicitEnv) {
|
|
19442
|
+
if (explicitEnv !== void 0) return explicitEnv;
|
|
19443
|
+
if (typeof process !== "undefined" && process.env) return process.env;
|
|
19444
|
+
return void 0;
|
|
19445
|
+
}
|
|
19446
|
+
function isEnvSoftBudgetDisabled(env) {
|
|
19447
|
+
const raw = env?.NOLO_SUBTASK_SOFT_BUDGET?.trim().toLowerCase();
|
|
19448
|
+
return raw === "0" || raw === "false";
|
|
19449
|
+
}
|
|
19450
|
+
function hasParentDialogEnvSignal(env) {
|
|
19451
|
+
const raw = env?.NOLO_PARENT_DIALOG_ID;
|
|
19452
|
+
return typeof raw === "string" && raw.trim().length > 0;
|
|
19453
|
+
}
|
|
19454
|
+
function normalizeThreshold(value) {
|
|
19455
|
+
if (typeof value !== "number" || !Number.isFinite(value) || value <= 0) {
|
|
19456
|
+
return void 0;
|
|
19457
|
+
}
|
|
19458
|
+
return Math.floor(value);
|
|
19459
|
+
}
|
|
19460
|
+
function createSubtaskSoftBudgetAdvisor(options) {
|
|
19461
|
+
const env = resolveSoftBudgetEnv(options?.env);
|
|
19462
|
+
const envDisabled = isEnvSoftBudgetDisabled(env);
|
|
19463
|
+
const configDisabled = options?.softBudget === false || typeof options?.softBudget === "object" && options.softBudget !== null && options.softBudget.enabled === false;
|
|
19464
|
+
const configEnabled = options?.softBudget === true || typeof options?.softBudget === "object" && options.softBudget !== null && options.softBudget.enabled !== false;
|
|
19465
|
+
const hasSubtaskContext = options?.isSubtask === true || options?.runKind === "subtask" || hasParentDialogEnvSignal(env) || isSubtaskRun(env);
|
|
19466
|
+
const enabled = !envDisabled && !configDisabled && (configEnabled || hasSubtaskContext);
|
|
19467
|
+
const rawConfig = typeof options?.softBudget === "object" && options.softBudget !== null ? options.softBudget : void 0;
|
|
19468
|
+
const milestone1ToolCalls = normalizeThreshold(rawConfig?.milestone1ToolCalls) ?? DEFAULT_SUBTASK_SOFT_BUDGET_MILESTONE_1_TOOL_CALLS;
|
|
19469
|
+
const explicitMilestone2 = normalizeThreshold(rawConfig?.milestone2ToolCalls);
|
|
19470
|
+
const milestone2ToolCalls = explicitMilestone2 !== void 0 ? Math.max(milestone1ToolCalls + 1, explicitMilestone2) : Math.max(
|
|
19471
|
+
DEFAULT_SUBTASK_SOFT_BUDGET_MILESTONE_2_TOOL_CALLS,
|
|
19472
|
+
milestone1ToolCalls * 2
|
|
19473
|
+
);
|
|
19474
|
+
let milestone1Triggered = false;
|
|
19475
|
+
let milestone2Triggered = false;
|
|
19476
|
+
let lastObservedToolCallCount = 0;
|
|
19477
|
+
function observeToolCalls(toolCallCount) {
|
|
19478
|
+
const normalized = typeof toolCallCount === "number" && Number.isFinite(toolCallCount) && toolCallCount > 0 ? Math.floor(toolCallCount) : 0;
|
|
19479
|
+
if (normalized > lastObservedToolCallCount) {
|
|
19480
|
+
lastObservedToolCallCount = normalized;
|
|
19481
|
+
}
|
|
19482
|
+
if (!enabled) return null;
|
|
19483
|
+
if (!milestone2Triggered && normalized >= milestone2ToolCalls) {
|
|
19484
|
+
milestone1Triggered = true;
|
|
19485
|
+
milestone2Triggered = true;
|
|
19486
|
+
return {
|
|
19487
|
+
milestone: 2,
|
|
19488
|
+
threshold: milestone2ToolCalls,
|
|
19489
|
+
toolCallCount: normalized,
|
|
19490
|
+
message: buildSubtaskSoftBudgetMilestone2Prompt(normalized)
|
|
19491
|
+
};
|
|
19492
|
+
}
|
|
19493
|
+
if (!milestone1Triggered && normalized >= milestone1ToolCalls) {
|
|
19494
|
+
milestone1Triggered = true;
|
|
19495
|
+
return {
|
|
19496
|
+
milestone: 1,
|
|
19497
|
+
threshold: milestone1ToolCalls,
|
|
19498
|
+
toolCallCount: normalized,
|
|
19499
|
+
message: buildSubtaskSoftBudgetMilestone1Prompt(normalized)
|
|
19500
|
+
};
|
|
19501
|
+
}
|
|
19502
|
+
return null;
|
|
19503
|
+
}
|
|
19504
|
+
function getState2() {
|
|
19505
|
+
return {
|
|
19506
|
+
enabled,
|
|
19507
|
+
milestone1ToolCalls,
|
|
19508
|
+
milestone2ToolCalls,
|
|
19509
|
+
milestone1Triggered,
|
|
19510
|
+
milestone2Triggered,
|
|
19511
|
+
lastObservedToolCallCount
|
|
19512
|
+
};
|
|
19513
|
+
}
|
|
19514
|
+
return {
|
|
19515
|
+
enabled,
|
|
19516
|
+
milestone1ToolCalls,
|
|
19517
|
+
milestone2ToolCalls,
|
|
19518
|
+
observeToolCalls,
|
|
19519
|
+
getState: getState2
|
|
19520
|
+
};
|
|
19223
19521
|
}
|
|
19224
19522
|
|
|
19523
|
+
// packages/agent-runtime/leafFinalHandoff.ts
|
|
19524
|
+
var LEAF_FINAL_HANDOFF_INSTRUCTIONS = `Leaf subtask final: return only the result, blockers/findings, and minimal evidence the parent needs. Do not narrate your process or restate the task. Keep success concise without dropping the current delivery scope, unresolved blockers or evidence references; on failure include the blocker, severity when relevant, and an evidence reference (file:line, test command, commit, artifact, or run/dialog). If the task explicitly requires a long-form deliverable (document, translation, dataset, code, or other artifact), provide that deliverable in full and keep only the handoff around it concise. During execution, follow the brief as given: keep progress updates incremental to the brief; the final report must stand alone with the complete current delivery scope, unresolved blockers and evidence references, including on continuation; only when new evidence would materially change the goal, risk, irreversibility, or DoD should you surface it as a blocker/finding \u2014 do not silently expand scope or re-litigate the settled direction. Own investigation, implementation, related checks and failure fixes within the brief\u2019s scope and budget; leave goals and critical decisions to the parent. For required DoD checks, include the worktree, checked version (including uncommitted change scope), command, check scope, pass/fail and original-output reference; explicitly mark checks not run or evidence unavailable. Reuse valid same-version evidence; additional checks are warranted for version changes, missing/conflicting evidence or integration risk. Do not invent version metadata. Process done/exit 0 and assistant claims do not establish passing tests, user acceptance, independent review approval, integration or release; runtime acceptance is observations only and unknown remains unknown. Preserve a requested reviewer JSON/checkVerdict format; do not wrap it in another report. Keep success concise without omitting required evidence.`;
|
|
19525
|
+
|
|
19225
19526
|
// packages/agent-runtime/contextBlockScope.ts
|
|
19226
19527
|
var isContextBlockScope = (value) => {
|
|
19227
19528
|
if (typeof value !== "object" || value === null) return false;
|
|
@@ -19283,6 +19584,25 @@ function findSummaryAnchorIndex(bridged, anchorId) {
|
|
|
19283
19584
|
const index = Number(legacy[1]);
|
|
19284
19585
|
return Number.isSafeInteger(index) && index < bridged.length ? index : -1;
|
|
19285
19586
|
}
|
|
19587
|
+
function logSummarySourceDiagnostics(phase, dialogId, history, anchor, segmentDiff) {
|
|
19588
|
+
const sourceHash = hashSummarySourceSlice(history, anchor)?.slice(0, 16);
|
|
19589
|
+
if (phase === "invalidated" && segmentDiff) {
|
|
19590
|
+
console.log(`[compaction-source] ${JSON.stringify({
|
|
19591
|
+
phase,
|
|
19592
|
+
dialogId,
|
|
19593
|
+
sourceHash,
|
|
19594
|
+
kind: "segment-diff",
|
|
19595
|
+
...segmentDiff
|
|
19596
|
+
})}`);
|
|
19597
|
+
}
|
|
19598
|
+
const rows = buildSummarySourceDiagnostics(toPlanCompressionMessages(history), anchor);
|
|
19599
|
+
for (const row of rows) console.log(`[compaction-source] ${JSON.stringify({
|
|
19600
|
+
phase,
|
|
19601
|
+
dialogId,
|
|
19602
|
+
sourceHash,
|
|
19603
|
+
...row
|
|
19604
|
+
})}`);
|
|
19605
|
+
}
|
|
19286
19606
|
function hashSummarySourceSlice(history, summarizedBeforeId) {
|
|
19287
19607
|
if (!summarizedBeforeId) return void 0;
|
|
19288
19608
|
const bridged = toPlanCompressionMessages(history);
|
|
@@ -19472,13 +19792,15 @@ async function maybeAutoCompactLocalHistory(args2) {
|
|
|
19472
19792
|
let reason;
|
|
19473
19793
|
if (invalidStored?.schemaVersion !== void 0 && invalidStored.schemaVersion !== COMPACTION_SUMMARY_SCHEMA_VERSION) {
|
|
19474
19794
|
reason = "schema-version-mismatch";
|
|
19475
|
-
} else if (typeof invalidStored?.summarizedBeforeId !== "string" ||
|
|
19795
|
+
} else if (typeof invalidStored?.summarizedBeforeId !== "string" || findSummaryAnchorIndex(bridged, invalidStored.summarizedBeforeId) === -1) {
|
|
19476
19796
|
reason = "anchor-not-found";
|
|
19477
19797
|
} else if (typeof invalidStored?.sourceCount === "number" && history.length < invalidStored.sourceCount) {
|
|
19478
19798
|
reason = "history-trimmed";
|
|
19479
19799
|
} else {
|
|
19480
19800
|
reason = "hash-mismatch";
|
|
19481
19801
|
}
|
|
19802
|
+
const currentSegments = buildSummarySourceSegments(bridged, invalidStored?.summarizedBeforeId);
|
|
19803
|
+
const segmentDiff = reason === "hash-mismatch" ? diffSummarySourceSegments(invalidStored?.sourceSegments, currentSegments) : void 0;
|
|
19482
19804
|
console.warn(
|
|
19483
19805
|
`[localLoop] invalidated dialog summary for ${dialogId} (${reason}); discarding and re-compressing`,
|
|
19484
19806
|
// 诊断分项(**仅加日志,不改任何哈希/校验/重锚语义**):区分「历史真被改写」
|
|
@@ -19491,9 +19813,17 @@ async function maybeAutoCompactLocalHistory(args2) {
|
|
|
19491
19813
|
storedSourceCount: typeof invalidStored?.sourceCount === "number" ? invalidStored.sourceCount : null,
|
|
19492
19814
|
summarizedBeforeId: typeof invalidStored?.summarizedBeforeId === "string" ? invalidStored.summarizedBeforeId : null,
|
|
19493
19815
|
recomputedHashPrefix: hashSummarySourceSlice(history, invalidStored?.summarizedBeforeId)?.slice(0, 8) ?? null,
|
|
19494
|
-
storedHashPrefix: typeof invalidStored?.sourceHash === "string" && invalidStored.sourceHash ? invalidStored.sourceHash.slice(0, 8) : null
|
|
19816
|
+
storedHashPrefix: typeof invalidStored?.sourceHash === "string" && invalidStored.sourceHash ? invalidStored.sourceHash.slice(0, 8) : null,
|
|
19817
|
+
...segmentDiff ? { segmentDiff } : {}
|
|
19495
19818
|
}
|
|
19496
19819
|
);
|
|
19820
|
+
logSummarySourceDiagnostics(
|
|
19821
|
+
"invalidated",
|
|
19822
|
+
dialogId,
|
|
19823
|
+
history,
|
|
19824
|
+
invalidStored?.summarizedBeforeId,
|
|
19825
|
+
segmentDiff
|
|
19826
|
+
);
|
|
19497
19827
|
stored = null;
|
|
19498
19828
|
}
|
|
19499
19829
|
const existingSummary = typeof stored?.summary === "string" ? stored.summary : "";
|
|
@@ -19503,7 +19833,7 @@ async function maybeAutoCompactLocalHistory(args2) {
|
|
|
19503
19833
|
const contextWindow = typeof args2.contextWindow === "number" && Number.isFinite(args2.contextWindow) && args2.contextWindow > 0 ? args2.contextWindow : getModelContextWindow(args2.model ?? "");
|
|
19504
19834
|
const allMsgs = toPlanCompressionMessages(prepareHistoryForNextTurn(history, args2.contextReferenceResolver));
|
|
19505
19835
|
const maxInputItems = resolveProviderInputItemLimit({ provider: args2.provider, endpoint: args2.providerEndpoint });
|
|
19506
|
-
const force = args2.force === true || args2.requestOverBudget?.(
|
|
19836
|
+
const force = args2.force === true || invalidSummary || args2.requestOverBudget?.(
|
|
19507
19837
|
existingSummary ? projectHistoryWithSummary({ history, summary: existingSummary, summarizedBeforeId }) : history
|
|
19508
19838
|
) === true;
|
|
19509
19839
|
const plan = planCompression({
|
|
@@ -19587,7 +19917,7 @@ async function maybeAutoCompactLocalHistory(args2) {
|
|
|
19587
19917
|
};
|
|
19588
19918
|
}
|
|
19589
19919
|
const msgsToCompress = plan.msgsToCompress;
|
|
19590
|
-
const bounded3 =
|
|
19920
|
+
const bounded3 = buildHistoricalCompactionRequest({
|
|
19591
19921
|
msgsToCompress,
|
|
19592
19922
|
previousSummary: existingSummary,
|
|
19593
19923
|
contextWindow,
|
|
@@ -19740,20 +20070,20 @@ async function maybeAutoCompactLocalHistory(args2) {
|
|
|
19740
20070
|
});
|
|
19741
20071
|
}
|
|
19742
20072
|
};
|
|
19743
|
-
const
|
|
20073
|
+
const fallback2 = args2.summaryFallback?.preferPlatform ? args2.summaryFallback : void 0;
|
|
19744
20074
|
let eligibility;
|
|
19745
|
-
const routedFallback =
|
|
20075
|
+
const routedFallback = fallback2 ? Object.assign(
|
|
19746
20076
|
async (content, options) => {
|
|
19747
20077
|
summaryModel = PLATFORM_HOSTED_DEEPSEEK_FLASH_MODEL;
|
|
19748
20078
|
summaryProvider = "nolo";
|
|
19749
|
-
return physicalRequest("platform", () =>
|
|
20079
|
+
return physicalRequest("platform", () => fallback2(content, { ...options, attemptId: compactionAttemptId }));
|
|
19750
20080
|
},
|
|
19751
20081
|
{
|
|
19752
|
-
preferPlatform: (options) => eligibility ??=
|
|
19753
|
-
...
|
|
20082
|
+
preferPlatform: (options) => eligibility ??= fallback2.preferPlatform(options),
|
|
20083
|
+
...fallback2.complete ? { complete: async (content, options) => {
|
|
19754
20084
|
summaryModel = PLATFORM_HOSTED_DEEPSEEK_FLASH_MODEL;
|
|
19755
20085
|
summaryProvider = "nolo";
|
|
19756
|
-
return physicalRequest("platform", () =>
|
|
20086
|
+
return physicalRequest("platform", () => fallback2.complete(content, { ...options, attemptId: compactionAttemptId }));
|
|
19757
20087
|
} } : {}
|
|
19758
20088
|
}
|
|
19759
20089
|
) : void 0;
|
|
@@ -19781,7 +20111,7 @@ async function maybeAutoCompactLocalHistory(args2) {
|
|
|
19781
20111
|
primaryElapsedMs = Date.now() - compactionT0;
|
|
19782
20112
|
logCompactionTiming("provider-error", {});
|
|
19783
20113
|
emitPhase({ kind: "compaction-retry", attempt: attempt + 1, maxAttempts });
|
|
19784
|
-
await new Promise((
|
|
20114
|
+
await new Promise((resolve7, reject) => {
|
|
19785
20115
|
const signal = requestController.signal;
|
|
19786
20116
|
const cancel = () => {
|
|
19787
20117
|
clearTimeout(timer);
|
|
@@ -19790,7 +20120,7 @@ async function maybeAutoCompactLocalHistory(args2) {
|
|
|
19790
20120
|
};
|
|
19791
20121
|
const timer = setTimeout(() => {
|
|
19792
20122
|
signal.removeEventListener("abort", cancel);
|
|
19793
|
-
|
|
20123
|
+
resolve7();
|
|
19794
20124
|
}, delayMs);
|
|
19795
20125
|
signal.addEventListener("abort", cancel, { once: true });
|
|
19796
20126
|
if (signal.aborted) cancel();
|
|
@@ -19804,16 +20134,16 @@ async function maybeAutoCompactLocalHistory(args2) {
|
|
|
19804
20134
|
(error) => ({ kind: "provider-error", error })
|
|
19805
20135
|
);
|
|
19806
20136
|
const guards = [];
|
|
19807
|
-
if (timeoutMs) guards.push(new Promise((
|
|
20137
|
+
if (timeoutMs) guards.push(new Promise((resolve7) => {
|
|
19808
20138
|
timeoutHandle = setTimeout(() => {
|
|
19809
20139
|
requestController.abort(new DOMException("Summary deadline exceeded", "TimeoutError"));
|
|
19810
|
-
|
|
20140
|
+
resolve7({ kind: "timeout" });
|
|
19811
20141
|
}, timeoutMs);
|
|
19812
20142
|
}));
|
|
19813
|
-
if (args2.abortSignal) guards.push(new Promise((
|
|
20143
|
+
if (args2.abortSignal) guards.push(new Promise((resolve7) => {
|
|
19814
20144
|
abortListener = () => {
|
|
19815
20145
|
requestController.abort(args2.abortSignal?.reason);
|
|
19816
|
-
|
|
20146
|
+
resolve7({ kind: "aborted" });
|
|
19817
20147
|
};
|
|
19818
20148
|
args2.abortSignal?.addEventListener("abort", abortListener, { once: true });
|
|
19819
20149
|
if (args2.abortSignal?.aborted) abortListener();
|
|
@@ -19927,8 +20257,13 @@ async function maybeAutoCompactLocalHistory(args2) {
|
|
|
19927
20257
|
}
|
|
19928
20258
|
};
|
|
19929
20259
|
}
|
|
20260
|
+
const bridgedHistory = toPlanCompressionMessages(history);
|
|
19930
20261
|
const sourceMeta = await computeSummarySourceMetadata(
|
|
19931
|
-
|
|
20262
|
+
bridgedHistory,
|
|
20263
|
+
bounded3.summarizedBeforeId
|
|
20264
|
+
);
|
|
20265
|
+
const sourceSegments = buildSummarySourceSegments(
|
|
20266
|
+
bridgedHistory,
|
|
19932
20267
|
bounded3.summarizedBeforeId
|
|
19933
20268
|
);
|
|
19934
20269
|
if (Date.now() >= summaryDeadlineMs) throw Object.assign(new Error("Summary deadline exceeded"), { compactionReason: "timeout" });
|
|
@@ -19936,7 +20271,7 @@ async function maybeAutoCompactLocalHistory(args2) {
|
|
|
19936
20271
|
throw Object.assign(new Error("auto-compaction aborted"), { compactionReason: "aborted" });
|
|
19937
20272
|
}
|
|
19938
20273
|
const saveT0 = Date.now();
|
|
19939
|
-
|
|
20274
|
+
const summarySavePayload = {
|
|
19940
20275
|
dialogId,
|
|
19941
20276
|
summary: newSummary,
|
|
19942
20277
|
summarizedBeforeId: bounded3.summarizedBeforeId,
|
|
@@ -19944,13 +20279,16 @@ async function maybeAutoCompactLocalHistory(args2) {
|
|
|
19944
20279
|
sourceHash: sourceMeta?.sourceHash,
|
|
19945
20280
|
sourceCount: sourceMeta?.sourceCount ?? 0,
|
|
19946
20281
|
schemaVersion: COMPACTION_SUMMARY_SCHEMA_VERSION,
|
|
20282
|
+
...sourceSegments.length > 0 ? { sourceSegments } : {},
|
|
19947
20283
|
referenceKeys: Array.from(
|
|
19948
20284
|
new Set(
|
|
19949
20285
|
history.slice(0, sourceMeta?.sourceCount ?? 0).flatMap((message) => extractReferenceKeysFromMessage(message))
|
|
19950
20286
|
)
|
|
19951
20287
|
)
|
|
19952
|
-
}
|
|
20288
|
+
};
|
|
20289
|
+
await adapter.saveDialogSummary(summarySavePayload);
|
|
19953
20290
|
saveElapsedMs = Date.now() - saveT0;
|
|
20291
|
+
logSummarySourceDiagnostics("saved", dialogId, history, bounded3.summarizedBeforeId);
|
|
19954
20292
|
console.log(formatCompactionMetricsLog(metrics));
|
|
19955
20293
|
logCompactionTiming("success", {
|
|
19956
20294
|
model: result4?.model ?? args2.model ?? null,
|
|
@@ -20131,7 +20469,7 @@ function createTurnCompactionController(args2) {
|
|
|
20131
20469
|
return { history: result4.history, applied: result4.history !== history, usage: result4.usage };
|
|
20132
20470
|
};
|
|
20133
20471
|
let lastCompactionOutcome;
|
|
20134
|
-
const prepareRequest = async (requestOverBudget, initial = false, availableHistoryTokens) => {
|
|
20472
|
+
const prepareRequest = async (requestOverBudget, initial = false, availableHistoryTokens, force = false) => {
|
|
20135
20473
|
lastCompactionOutcome = void 0;
|
|
20136
20474
|
const contextUsage = args2.getContextUsage();
|
|
20137
20475
|
let inputTokens = contextUsage ? normalizeUsage(contextUsage).input_tokens : 0;
|
|
@@ -20143,8 +20481,8 @@ function createTurnCompactionController(args2) {
|
|
|
20143
20481
|
}
|
|
20144
20482
|
}
|
|
20145
20483
|
const ratio = inputTokens > 0 ? Math.min(1, inputTokens / args2.contextWindow) : void 0;
|
|
20146
|
-
if (!requestOverBudget && ratio !== void 0 && ratio < args2.compressionTriggerRatio * 0.85 && resolveProviderInputItemLimit({ provider: args2.provider, endpoint: args2.providerEndpoint }) === void 0) {
|
|
20147
|
-
return;
|
|
20484
|
+
if (!force && !requestOverBudget && ratio !== void 0 && ratio < args2.compressionTriggerRatio * 0.85 && resolveProviderInputItemLimit({ provider: args2.provider, endpoint: args2.providerEndpoint }) === void 0) {
|
|
20485
|
+
return false;
|
|
20148
20486
|
}
|
|
20149
20487
|
try {
|
|
20150
20488
|
const compacted = await maybeAutoCompactLocalHistory({
|
|
@@ -20164,6 +20502,7 @@ function createTurnCompactionController(args2) {
|
|
|
20164
20502
|
providerEndpoint: args2.providerEndpoint,
|
|
20165
20503
|
resolveProvider: args2.resolveProvider,
|
|
20166
20504
|
contextWindow: args2.contextWindow,
|
|
20505
|
+
...force ? { force: true } : {},
|
|
20167
20506
|
...ratio !== void 0 ? { realContextUsagePercent: ratio } : {},
|
|
20168
20507
|
abortSignal: args2.abortSignal,
|
|
20169
20508
|
timeoutMs: args2.timeoutMs,
|
|
@@ -20190,12 +20529,16 @@ function createTurnCompactionController(args2) {
|
|
|
20190
20529
|
args2.onSelectedSummary?.(compacted.selectedSummary ?? { outcome: initial ? "absent" : "unknown" });
|
|
20191
20530
|
}
|
|
20192
20531
|
emitObservation(compacted);
|
|
20532
|
+
return Boolean(compacted.compressed && compacted.summaryGenerated);
|
|
20193
20533
|
} catch (error) {
|
|
20194
20534
|
lastCompactionOutcome = { ...lastCompactionOutcome, error: classifySummaryError(error) };
|
|
20195
20535
|
console.warn("[localLoop] in-loop auto-compaction failed:", error);
|
|
20536
|
+
return false;
|
|
20196
20537
|
}
|
|
20197
20538
|
};
|
|
20198
|
-
return { getLastCompactionOutcome: () => lastCompactionOutcome, runInitial, maybeCompactInLoop: () =>
|
|
20539
|
+
return { getLastCompactionOutcome: () => lastCompactionOutcome, runInitial, maybeCompactInLoop: async () => {
|
|
20540
|
+
await prepareRequest();
|
|
20541
|
+
}, forceCompact, prepareRequest };
|
|
20199
20542
|
}
|
|
20200
20543
|
|
|
20201
20544
|
// packages/agent-runtime/providerCallTelemetry.ts
|
|
@@ -20517,10 +20860,6 @@ function attachUsageRecordsToError(error, usageRecords) {
|
|
|
20517
20860
|
}
|
|
20518
20861
|
async function persistFailedLocalTurn(args2) {
|
|
20519
20862
|
const errorMessage = toErrorMessage(args2.error);
|
|
20520
|
-
const businessCompletion = evaluateTaskExecutionContract(args2.input.taskExecutionContract, {
|
|
20521
|
-
stopped: args2.input.abortSignal?.aborted || args2.error instanceof Error && args2.error.code === LOCAL_TURN_ABORTED_CODE,
|
|
20522
|
-
executionFailed: true
|
|
20523
|
-
});
|
|
20524
20863
|
try {
|
|
20525
20864
|
const saved = await args2.adapter.saveTurn({
|
|
20526
20865
|
agentKey: args2.agentKey,
|
|
@@ -20531,7 +20870,6 @@ async function persistFailedLocalTurn(args2) {
|
|
|
20531
20870
|
toolCallCount: args2.toolCallCount ?? 0,
|
|
20532
20871
|
error: true,
|
|
20533
20872
|
errorMessage,
|
|
20534
|
-
...businessCompletion ? { businessCompletion } : {},
|
|
20535
20873
|
...args2.usage ? { usage: args2.usage } : {}
|
|
20536
20874
|
},
|
|
20537
20875
|
...args2.accountingUsage ? { accountingUsage: args2.accountingUsage } : {},
|
|
@@ -20578,6 +20916,7 @@ function combineRollbackError(primary, rollbackError) {
|
|
|
20578
20916
|
return combined;
|
|
20579
20917
|
}
|
|
20580
20918
|
async function runLocalAgentTurn(input) {
|
|
20919
|
+
input = { ...input, runtimeContext: input.runtimeContext ? { ...input.runtimeContext } : void 0 };
|
|
20581
20920
|
const legacyCallbacks = {
|
|
20582
20921
|
onLoopEvent: input.onLoopEvent,
|
|
20583
20922
|
onToolEvent: input.onToolEvent,
|
|
@@ -20720,8 +21059,16 @@ async function runLocalAgentTurn(input) {
|
|
|
20720
21059
|
// 防止 session-scope 的 agentCollaboration 段逐轮翻转击穿前缀缓存。
|
|
20721
21060
|
dispatchIntent: detectDispatchIntentFromMessages(history) || detectDispatchIntent(
|
|
20722
21061
|
typeof input.input === "string" ? input.input : void 0
|
|
20723
|
-
)
|
|
21062
|
+
),
|
|
21063
|
+
runKind: input.runKind
|
|
20724
21064
|
});
|
|
21065
|
+
const callerScopes = normalizeContextBlockScopes(
|
|
21066
|
+
input.contextBlocks,
|
|
21067
|
+
input.contextBlockScopes
|
|
21068
|
+
);
|
|
21069
|
+
const callerHasMemoryGuidance = callerScopes.some(
|
|
21070
|
+
(scope3) => scope3.content.includes(MEMORY_USE_GUIDANCE)
|
|
21071
|
+
);
|
|
20725
21072
|
const guidanceScopes = [
|
|
20726
21073
|
...input.userLanguage?.trim() ? [buildUserResponseLanguageContext({ language: input.userLanguage })] : [],
|
|
20727
21074
|
guidanceBlocks.startupProtocol,
|
|
@@ -20730,12 +21077,14 @@ async function runLocalAgentTurn(input) {
|
|
|
20730
21077
|
// 注入顺序遵循 TOOL_GUIDED_SECTION_ORDER(与 buildSystemPrompt 的显式
|
|
20731
21078
|
// layer 列表同源),禁止用 Object.values 自行定序。
|
|
20732
21079
|
...TOOL_GUIDED_SECTION_ORDER.map((id) => toolGuidedSections[id] ?? ""),
|
|
21080
|
+
// 记忆使用指引(session-scope,进稳定前缀):判定真值是 turnContext 的
|
|
21081
|
+
// `hasMemoryTools`(有效工具面),与 web/server 的 buildSystemPrompt 同一条
|
|
21082
|
+
// 规则。放在这里而不是各宿主:CLI/TUI/desktop 都经 runLocalAgentTurn 进入本
|
|
21083
|
+
// 函数,一处即可覆盖三端,并补齐「空库 + 有记忆工具」这一档——此前本地宿主
|
|
21084
|
+
// 只按记忆 overlay 是否为空门控,空库时模型永远不知道该怎么用记忆工具。
|
|
21085
|
+
...hasMemoryTools(agentTools) && !callerHasMemoryGuidance ? [MEMORY_USE_GUIDANCE] : [],
|
|
20733
21086
|
...input.runKind === "subtask" ? [LEAF_FINAL_HANDOFF_INSTRUCTIONS] : []
|
|
20734
21087
|
].map((content) => content.trim()).filter((content) => content.length > 0).map((content) => ({ content, cacheScope: "session" }));
|
|
20735
|
-
const callerScopes = normalizeContextBlockScopes(
|
|
20736
|
-
input.contextBlocks,
|
|
20737
|
-
input.contextBlockScopes
|
|
20738
|
-
);
|
|
20739
21088
|
const responseGuidelines = resolveResponseGuidelines(
|
|
20740
21089
|
input.responseViewport ?? "unknown"
|
|
20741
21090
|
);
|
|
@@ -20749,24 +21098,8 @@ async function runLocalAgentTurn(input) {
|
|
|
20749
21098
|
] : []
|
|
20750
21099
|
];
|
|
20751
21100
|
const mergedContextBlockScopes = [
|
|
20752
|
-
//
|
|
20753
|
-
|
|
20754
|
-
{ content: DELETE_SAFETY_RED_LINE, cacheScope: "session" },
|
|
20755
|
-
// 凭据纪律:与红线同为系统层固定块,紧随其后(四条装配线同源)。
|
|
20756
|
-
{ content: CREDENTIAL_HYGIENE_RULE, cacheScope: "session" },
|
|
20757
|
-
// 并行是默认:系统层固定块,紧随红线(localLoop 无 static 作用域,用 session 占位,
|
|
20758
|
-
// 「最顶」由数组首位保证——与红线同一约定)。
|
|
20759
|
-
{ content: VERIFY_BEFORE_CONCLUDING_RULE, cacheScope: "session" },
|
|
20760
|
-
{ content: PARALLEL_DISPATCH_DEFAULT_RULE, cacheScope: "session" },
|
|
20761
|
-
// 派发落点:并行派发纪律的下一层(派到哪个执行后端),沿用 session 占位约定。
|
|
20762
|
-
{ content: DISPATCH_BACKEND_POLICY, cacheScope: "session" },
|
|
20763
|
-
{ content: DISPATCH_CANDIDATE_POLICY, cacheScope: "session" },
|
|
20764
|
-
// 平台风控纪律:无条件系统层块,沿用 session 占位约定。
|
|
20765
|
-
{ content: PLATFORM_RISK_CONTROL_RULE, cacheScope: "session" },
|
|
20766
|
-
{ content: buildConsultationModeBlock(), cacheScope: "session" },
|
|
20767
|
-
// Git 任务隔离:系统层固定前置,四条装配线同序(请教模式之后、身份信息之前;
|
|
20768
|
-
// skill 配置 disabled 也注入)。
|
|
20769
|
-
{ content: WORKTREE_ISOLATION_PRELUDE, cacheScope: "session" },
|
|
21101
|
+
// 顶部固定平台层(唯一真源见 platformStaticPromptLayers.ts;localLoop 无 static 作用域,session 占位)。
|
|
21102
|
+
...buildPlatformStaticScopedBlocks(),
|
|
20770
21103
|
{ content: identityBlock, cacheScope: "session" },
|
|
20771
21104
|
...guidanceScopes,
|
|
20772
21105
|
// 回复行为准则:local 线(CLI 非交互 / 桌面 / TUI)的唯一注入边界。
|
|
@@ -20821,19 +21154,23 @@ async function runLocalAgentTurn(input) {
|
|
|
20821
21154
|
summaryFallback: input.compactionSummaryFallback ?? readHostCompactionSummaryFallback(input.adapter),
|
|
20822
21155
|
boundary: observationBoundary,
|
|
20823
21156
|
getContextUsage: () => usageLedger.lastContextUsage(),
|
|
20824
|
-
getCanonicalCompactionHistory: () => [
|
|
21157
|
+
getCanonicalCompactionHistory: () => orderDialogHistory([
|
|
20825
21158
|
...canonicalHistory,
|
|
20826
21159
|
...transcript.persisted(
|
|
20827
21160
|
sanitizedPersistedInput,
|
|
20828
21161
|
input.persistedInputReference
|
|
20829
|
-
)
|
|
20830
|
-
|
|
21162
|
+
).map((message) => {
|
|
21163
|
+
const receipt = message.cliMessageId;
|
|
21164
|
+
return receipt ? { ...message, id: receipt } : message;
|
|
21165
|
+
})
|
|
21166
|
+
]),
|
|
20831
21167
|
getWorkingPrefix: () => transcript.working().slice(0, prefixCount),
|
|
20832
21168
|
onSelectedSummary: (summary) => {
|
|
20833
21169
|
selectedSummary = summary;
|
|
20834
21170
|
},
|
|
20835
21171
|
replaceWorkingView: (next) => {
|
|
20836
21172
|
transcript.replaceWorkingHistory(next);
|
|
21173
|
+
input.adapter.onWorkingHistoryReplaced?.();
|
|
20837
21174
|
summaryProjectedPhase = contextPhase("summary-projected", next);
|
|
20838
21175
|
},
|
|
20839
21176
|
contextReferenceResolver: input.adapter.host === "cli" ? input.contextReferenceResolver : void 0,
|
|
@@ -20880,6 +21217,11 @@ async function runLocalAgentTurn(input) {
|
|
|
20880
21217
|
})));
|
|
20881
21218
|
messages.splice(currentInputStart, messages.length - currentInputStart, ...sanitizedUsers);
|
|
20882
21219
|
}
|
|
21220
|
+
if (!input.userMessages?.length && input.adapter.host === "cli") {
|
|
21221
|
+
const userIndex = builtMessages.prefixCount + history.length;
|
|
21222
|
+
const id = dialogTurnUserMessageId(input.runtimeContext?.turnId, 0);
|
|
21223
|
+
if (id && messages[userIndex]?.role === "user") messages[userIndex] = { ...messages[userIndex], id };
|
|
21224
|
+
}
|
|
20883
21225
|
const acceptToolImages = createToolImageLedger();
|
|
20884
21226
|
const transcript = createTurnTranscript({
|
|
20885
21227
|
initialWorking: messages,
|
|
@@ -20909,6 +21251,12 @@ async function runLocalAgentTurn(input) {
|
|
|
20909
21251
|
let skipFinalAppend = false;
|
|
20910
21252
|
let partialContent = "";
|
|
20911
21253
|
const progressGuard = createLocalLoopProgressGuard(input.progressGuardConfig);
|
|
21254
|
+
const softBudgetAdvisor = createSubtaskSoftBudgetAdvisor({
|
|
21255
|
+
softBudget: input.softBudget,
|
|
21256
|
+
isSubtask: input.isSubtask,
|
|
21257
|
+
runKind: input.runKind,
|
|
21258
|
+
...input.softBudgetEnv ? { env: input.softBudgetEnv } : {}
|
|
21259
|
+
});
|
|
20912
21260
|
let pendingInjectionCommits = [];
|
|
20913
21261
|
let inFlightTransactions = [];
|
|
20914
21262
|
let rollbackInjectionCommits = async () => {
|
|
@@ -20929,7 +21277,8 @@ async function runLocalAgentTurn(input) {
|
|
|
20929
21277
|
transcript.push({
|
|
20930
21278
|
role: "user",
|
|
20931
21279
|
content,
|
|
20932
|
-
...message.cliMessageId ? { cliMessageId: message.cliMessageId } : {}
|
|
21280
|
+
...message.cliMessageId ? { cliMessageId: message.cliMessageId } : {},
|
|
21281
|
+
...Number.isFinite(message.cliHistoryOrder) ? { cliHistoryOrder: message.cliHistoryOrder } : {}
|
|
20933
21282
|
});
|
|
20934
21283
|
}
|
|
20935
21284
|
pendingInjectionCommits.push({ commit: entry.commit, rollback: entry.rollback, messages: entry.messages });
|
|
@@ -21029,7 +21378,7 @@ async function runLocalAgentTurn(input) {
|
|
|
21029
21378
|
});
|
|
21030
21379
|
imageDowngradeEmitted = true;
|
|
21031
21380
|
}
|
|
21032
|
-
|
|
21381
|
+
let requestMessages = projectRequest(transcript.working());
|
|
21033
21382
|
if (requestOverBudget(requestMessages)) {
|
|
21034
21383
|
const budget = evaluateLocalRequestBudget({
|
|
21035
21384
|
messages: requestMessages,
|
|
@@ -21050,7 +21399,7 @@ async function runLocalAgentTurn(input) {
|
|
|
21050
21399
|
}));
|
|
21051
21400
|
}
|
|
21052
21401
|
budgetTrimPhase = contextPhase("budget-trim", requestMessages, { droppedCount: 0 });
|
|
21053
|
-
|
|
21402
|
+
let contextMetrics = {
|
|
21054
21403
|
...preparedMessages.metrics,
|
|
21055
21404
|
messageCount: requestMessages.length,
|
|
21056
21405
|
contentChars: requestMessages.reduce(
|
|
@@ -21072,8 +21421,8 @@ async function runLocalAgentTurn(input) {
|
|
|
21072
21421
|
input.onToolEvent || input.onObservationEvent || input.observationBoundary
|
|
21073
21422
|
);
|
|
21074
21423
|
let llmStreamActivity = 0;
|
|
21075
|
-
|
|
21076
|
-
|
|
21424
|
+
let callStartedAt = Date.now();
|
|
21425
|
+
let requestTelemetry = buildRequestTelemetry({
|
|
21077
21426
|
// 无 dialogId 的新对话用本 turn 唯一键,避免不同新对话共用一个槽误报漂移。
|
|
21078
21427
|
dialogKey: input.continueDialogId || newDialogTelemetryKey,
|
|
21079
21428
|
messages: requestMessages,
|
|
@@ -21090,6 +21439,16 @@ async function runLocalAgentTurn(input) {
|
|
|
21090
21439
|
inFlightTransactions = pendingInjectionCommits.splice(0);
|
|
21091
21440
|
try {
|
|
21092
21441
|
for (const transaction of inFlightTransactions) await transaction.commit();
|
|
21442
|
+
input.runtimeContext = { ...input.runtimeContext };
|
|
21443
|
+
delete input.runtimeContext.userMessageId;
|
|
21444
|
+
const admittedMessages = inFlightTransactions.flatMap((transaction) => transaction.messages);
|
|
21445
|
+
if (admittedMessages.length === 1 && admittedMessages[0]?.cliMessageId) {
|
|
21446
|
+
try {
|
|
21447
|
+
const id = await input.resolveInjectedUserMessageId?.(admittedMessages);
|
|
21448
|
+
if (id === admittedMessages[0].cliMessageId) input.runtimeContext.userMessageId = id;
|
|
21449
|
+
} catch {
|
|
21450
|
+
}
|
|
21451
|
+
}
|
|
21093
21452
|
if (input.abortSignal?.aborted) throw buildAbortedError();
|
|
21094
21453
|
} catch (error) {
|
|
21095
21454
|
const toRollback = inFlightTransactions;
|
|
@@ -21102,83 +21461,148 @@ async function runLocalAgentTurn(input) {
|
|
|
21102
21461
|
throw error;
|
|
21103
21462
|
}
|
|
21104
21463
|
}
|
|
21105
|
-
|
|
21106
|
-
|
|
21107
|
-
|
|
21108
|
-
|
|
21109
|
-
|
|
21110
|
-
|
|
21111
|
-
|
|
21112
|
-
}
|
|
21464
|
+
const tryOverflowRescueCompaction = async () => {
|
|
21465
|
+
const beforeTokens = estimateLocalRequestInput(requestMessages);
|
|
21466
|
+
const compacted = await compaction.prepareRequest((source) => {
|
|
21467
|
+
const projected = composeProviderMessages({
|
|
21468
|
+
prefix: transcript.working().slice(0, prefixCount),
|
|
21469
|
+
history: source,
|
|
21470
|
+
contextReferenceResolver: input.adapter.host === "cli" ? input.contextReferenceResolver : void 0
|
|
21471
|
+
});
|
|
21472
|
+
return requestOverBudget(projectRequest(projected.messages));
|
|
21473
|
+
}, false, availableHistoryTokens, true);
|
|
21474
|
+
if (!compacted) return false;
|
|
21475
|
+
const nextPrepared = prepareMessagesForProviderCall(transcript.working());
|
|
21476
|
+
const nextRequestMessages = projectRequest(transcript.working());
|
|
21477
|
+
const afterTokens = estimateLocalRequestInput(nextRequestMessages);
|
|
21478
|
+
if (afterTokens >= beforeTokens || requestOverBudget(nextRequestMessages)) return false;
|
|
21479
|
+
requestMessages = nextRequestMessages;
|
|
21480
|
+
contextMetrics = {
|
|
21481
|
+
...nextPrepared.metrics,
|
|
21482
|
+
messageCount: requestMessages.length,
|
|
21483
|
+
contentChars: requestMessages.reduce(
|
|
21484
|
+
(total, message) => total + contentCharCount(message.content),
|
|
21485
|
+
0
|
|
21486
|
+
),
|
|
21487
|
+
stableContextChars: builtMessages.stableContextChars,
|
|
21488
|
+
dynamicContextChars: builtMessages.dynamicContextChars
|
|
21489
|
+
};
|
|
21490
|
+
callStartedAt = Date.now();
|
|
21491
|
+
requestTelemetry = buildRequestTelemetry({
|
|
21492
|
+
dialogKey: input.continueDialogId || newDialogTelemetryKey,
|
|
21113
21493
|
messages: requestMessages,
|
|
21114
|
-
|
|
21115
|
-
|
|
21116
|
-
|
|
21117
|
-
|
|
21118
|
-
|
|
21119
|
-
...input.abortSignal ? { signal: input.abortSignal } : {},
|
|
21120
|
-
// 计费归因:续聊轮次带上 dialogId,platform proxy 才能把 token 记录
|
|
21121
|
-
// 归到具体对话而不是 chat-proxy 兜底桶。新对话首轮 id 尚未分配。
|
|
21122
|
-
...input.continueDialogId ? { dialogId: input.continueDialogId } : {},
|
|
21123
|
-
...shouldStreamDeltas ? { onTextDelta: (chunk) => {
|
|
21124
|
-
llmStreamActivity += 1;
|
|
21125
|
-
partialContent += chunk;
|
|
21126
|
-
observationBoundary.emit({
|
|
21127
|
-
kind: "text-delta",
|
|
21128
|
-
chunk,
|
|
21129
|
-
round,
|
|
21130
|
-
atMs: Date.now()
|
|
21131
|
-
});
|
|
21132
|
-
} } : {},
|
|
21133
|
-
...shouldStreamReasoning ? { onReasoningDelta: (chunk) => {
|
|
21134
|
-
llmStreamActivity += 1;
|
|
21135
|
-
observationBoundary.emit({
|
|
21136
|
-
kind: "reasoning-delta",
|
|
21137
|
-
chunk,
|
|
21138
|
-
round,
|
|
21139
|
-
atMs: Date.now()
|
|
21140
|
-
});
|
|
21141
|
-
} } : {},
|
|
21142
|
-
...shouldPassToolEvents ? { onToolEvent: (event) => {
|
|
21143
|
-
llmStreamActivity += 1;
|
|
21144
|
-
observationBoundary.emit({
|
|
21145
|
-
kind: "tool-event",
|
|
21146
|
-
event,
|
|
21147
|
-
round,
|
|
21148
|
-
atMs: Date.now()
|
|
21149
|
-
});
|
|
21150
|
-
} } : {},
|
|
21151
|
-
...shouldPassToolEvents ? { toolEventRound: round } : {}
|
|
21494
|
+
provenance: {
|
|
21495
|
+
schemaVersion: 1,
|
|
21496
|
+
transport: provider.transport ?? "unknown",
|
|
21497
|
+
phases: [historyLoadedPhase, summaryProjectedPhase, budgetTrimPhase, contextPhase("final-request", requestMessages)],
|
|
21498
|
+
summary: selectedSummary
|
|
21152
21499
|
},
|
|
21153
|
-
|
|
21154
|
-
activityVersion: () => llmStreamActivity,
|
|
21155
|
-
round,
|
|
21156
|
-
input,
|
|
21157
|
-
boundary: observationBoundary,
|
|
21158
|
-
context: contextMetrics,
|
|
21159
|
-
providerName: agentConfig.provider,
|
|
21160
|
-
model: provider.model
|
|
21500
|
+
toolsHash: safeToolNamesHash(agentTools)
|
|
21161
21501
|
});
|
|
21162
|
-
|
|
21163
|
-
|
|
21164
|
-
|
|
21165
|
-
|
|
21166
|
-
|
|
21167
|
-
|
|
21168
|
-
|
|
21169
|
-
|
|
21502
|
+
resetToolImageDelivery(requestMessages.flatMap(toolImages));
|
|
21503
|
+
return true;
|
|
21504
|
+
};
|
|
21505
|
+
let overflowRescueAttempted = false;
|
|
21506
|
+
while (true) {
|
|
21507
|
+
llmStreamActivity = 0;
|
|
21508
|
+
partialContent = "";
|
|
21509
|
+
let providerInvoked = false;
|
|
21510
|
+
try {
|
|
21511
|
+
result4 = await runCompleteWithTimeout({
|
|
21512
|
+
provider: { complete: (messages2, options) => {
|
|
21513
|
+
providerInvoked = true;
|
|
21514
|
+
inFlightTransactions = [];
|
|
21515
|
+
return provider.complete(messages2, options);
|
|
21516
|
+
} },
|
|
21517
|
+
messages: requestMessages,
|
|
21518
|
+
options: {
|
|
21519
|
+
timeoutMs: resolveLlmRequestTimeoutMs(input),
|
|
21520
|
+
// 用户取消信号穿进 provider options:providerStreamRetry 据此在
|
|
21521
|
+
// 取消后跳过重试,provider 分支(如 antigravity/openai-compatible)
|
|
21522
|
+
// 也可把 fetch 绑定到同一信号,实现真正的传输层取消。
|
|
21523
|
+
...input.abortSignal ? { signal: input.abortSignal } : {},
|
|
21524
|
+
// 计费归因:续聊轮次带上 dialogId,platform proxy 才能把 token 记录
|
|
21525
|
+
// 归到具体对话而不是 chat-proxy 兜底桶。新对话首轮 id 尚未分配。
|
|
21526
|
+
...input.continueDialogId ? { dialogId: input.continueDialogId } : {},
|
|
21527
|
+
...shouldStreamDeltas ? { onTextDelta: (chunk) => {
|
|
21528
|
+
llmStreamActivity += 1;
|
|
21529
|
+
partialContent += chunk;
|
|
21530
|
+
observationBoundary.emit({
|
|
21531
|
+
kind: "text-delta",
|
|
21532
|
+
chunk,
|
|
21533
|
+
round,
|
|
21534
|
+
atMs: Date.now()
|
|
21535
|
+
});
|
|
21536
|
+
} } : {},
|
|
21537
|
+
...shouldStreamReasoning ? { onReasoningDelta: (chunk) => {
|
|
21538
|
+
llmStreamActivity += 1;
|
|
21539
|
+
observationBoundary.emit({
|
|
21540
|
+
kind: "reasoning-delta",
|
|
21541
|
+
chunk,
|
|
21542
|
+
round,
|
|
21543
|
+
atMs: Date.now()
|
|
21544
|
+
});
|
|
21545
|
+
} } : {},
|
|
21546
|
+
...shouldPassToolEvents ? { onToolEvent: (event) => {
|
|
21547
|
+
llmStreamActivity += 1;
|
|
21548
|
+
observationBoundary.emit({
|
|
21549
|
+
kind: "tool-event",
|
|
21550
|
+
event,
|
|
21551
|
+
round,
|
|
21552
|
+
atMs: Date.now()
|
|
21553
|
+
});
|
|
21554
|
+
} } : {},
|
|
21555
|
+
...shouldPassToolEvents ? { toolEventRound: round } : {}
|
|
21556
|
+
},
|
|
21557
|
+
timeoutMs: resolveLlmRequestTimeoutMs(input),
|
|
21558
|
+
activityVersion: () => llmStreamActivity,
|
|
21559
|
+
round,
|
|
21560
|
+
input,
|
|
21561
|
+
boundary: observationBoundary,
|
|
21562
|
+
context: contextMetrics,
|
|
21563
|
+
providerName: agentConfig.provider,
|
|
21564
|
+
model: provider.model
|
|
21565
|
+
});
|
|
21566
|
+
} catch (error) {
|
|
21567
|
+
if (!providerInvoked && inFlightTransactions.length > 0) {
|
|
21568
|
+
const toRollback = inFlightTransactions;
|
|
21569
|
+
inFlightTransactions = [];
|
|
21570
|
+
try {
|
|
21571
|
+
await rollbackInjectionCommits(toRollback);
|
|
21572
|
+
} catch (rbErr) {
|
|
21573
|
+
error = combineRollbackError(error, rbErr);
|
|
21574
|
+
}
|
|
21575
|
+
}
|
|
21576
|
+
if (providerInvoked) usageLedger.recordProviderCall({
|
|
21577
|
+
model: agentConfig.model,
|
|
21578
|
+
telemetry: {
|
|
21579
|
+
...requestTelemetry,
|
|
21580
|
+
round,
|
|
21581
|
+
endTs: Date.now(),
|
|
21582
|
+
requestState: input.abortSignal?.aborted ? "cancelled" : "failed"
|
|
21583
|
+
}
|
|
21584
|
+
});
|
|
21585
|
+
if (providerInvoked && !overflowRescueAttempted && llmStreamActivity === 0 && !input.abortSignal?.aborted && isContextOverflowText(toErrorMessage(error))) {
|
|
21586
|
+
overflowRescueAttempted = true;
|
|
21587
|
+
if (await tryOverflowRescueCompaction()) {
|
|
21588
|
+
continue;
|
|
21589
|
+
}
|
|
21170
21590
|
}
|
|
21591
|
+
throw error;
|
|
21171
21592
|
}
|
|
21172
|
-
if (
|
|
21173
|
-
|
|
21174
|
-
|
|
21175
|
-
|
|
21176
|
-
|
|
21177
|
-
|
|
21178
|
-
|
|
21593
|
+
if ((result4.error || result4.runtimeProviderFailure) && !overflowRescueAttempted && llmStreamActivity === 0 && !input.abortSignal?.aborted && isContextOverflowText(result4.runtimeProviderFailure?.message ?? result4.errorMessage ?? "")) {
|
|
21594
|
+
overflowRescueAttempted = true;
|
|
21595
|
+
usageLedger.recordProviderCall({
|
|
21596
|
+
usage: result4.usage,
|
|
21597
|
+
model: result4.model ?? agentConfig.model,
|
|
21598
|
+
provider: result4.provider,
|
|
21599
|
+
telemetry: { ...finalizeCallTelemetry(requestTelemetry, result4, round, callStartedAt), requestState: "failed" }
|
|
21600
|
+
});
|
|
21601
|
+
if (await tryOverflowRescueCompaction()) {
|
|
21602
|
+
continue;
|
|
21179
21603
|
}
|
|
21180
|
-
}
|
|
21181
|
-
|
|
21604
|
+
}
|
|
21605
|
+
break;
|
|
21182
21606
|
}
|
|
21183
21607
|
acceptToolImages.discard(requestMessages.flatMap(toolImages).filter((image) => toolImageDelivery(image) === "impossible"));
|
|
21184
21608
|
acceptToolImages.commit(
|
|
@@ -21474,6 +21898,15 @@ ${reasoningTailLog}
|
|
|
21474
21898
|
};
|
|
21475
21899
|
break;
|
|
21476
21900
|
}
|
|
21901
|
+
if (!input.abortSignal?.aborted) {
|
|
21902
|
+
const softBudgetAdvisory = softBudgetAdvisor.observeToolCalls(toolCallCount);
|
|
21903
|
+
if (softBudgetAdvisory) {
|
|
21904
|
+
transcript.push({
|
|
21905
|
+
role: "user",
|
|
21906
|
+
content: softBudgetAdvisory.message
|
|
21907
|
+
});
|
|
21908
|
+
}
|
|
21909
|
+
}
|
|
21477
21910
|
loopTiming.mark("roundEnd", round);
|
|
21478
21911
|
round += 1;
|
|
21479
21912
|
}
|
|
@@ -21525,12 +21958,6 @@ ${reasoningTailLog}
|
|
|
21525
21958
|
...result4,
|
|
21526
21959
|
stopReason: input.abortSignal?.aborted ? "aborted" : result4.error || result4.runtimeProviderFailure || result4.emptyAssistantFallbackReason ? "error" : stopReason
|
|
21527
21960
|
};
|
|
21528
|
-
delete result4.businessCompletion;
|
|
21529
|
-
const businessCompletion = evaluateTaskExecutionContract(input.taskExecutionContract, {
|
|
21530
|
-
stopped: input.abortSignal?.aborted,
|
|
21531
|
-
executionFailed: result4.error === true || !!result4.runtimeProviderFailure || !!result4.emptyAssistantFallbackReason
|
|
21532
|
-
});
|
|
21533
|
-
if (businessCompletion) result4.businessCompletion = businessCompletion;
|
|
21534
21961
|
if (!skipFinalAppend) {
|
|
21535
21962
|
const truncatedReasoningTailLog = resolveTruncatedReasoningTailLog(
|
|
21536
21963
|
result4.emptyAssistantFallbackReason,
|
|
@@ -22535,756 +22962,6 @@ async function resolveOpenAiCompatibleProviderConfig(args2) {
|
|
|
22535
22962
|
};
|
|
22536
22963
|
}
|
|
22537
22964
|
|
|
22538
|
-
// packages/agent-runtime/macOsKeychainCredentialBroker.ts
|
|
22539
|
-
import { spawn as spawn2 } from "node:child_process";
|
|
22540
|
-
var MACOS_KEYCHAIN_SERVICE_PREFIX = "nolo.credentials.keys";
|
|
22541
|
-
var MACOS_KEYCHAIN_ACCOUNT = "api-key";
|
|
22542
|
-
var SECURITY_ITEM_NOT_FOUND_EXIT = 44;
|
|
22543
|
-
var DEFAULT_SECURITY_BIN = "/usr/bin/security";
|
|
22544
|
-
function safeCredentialRef(ref) {
|
|
22545
|
-
try {
|
|
22546
|
-
return assertCredentialRef(ref);
|
|
22547
|
-
} catch {
|
|
22548
|
-
throw new Error("invalid_ref");
|
|
22549
|
-
}
|
|
22550
|
-
}
|
|
22551
|
-
function credentialRefToMacOsKeychainService(ref, servicePrefix = MACOS_KEYCHAIN_SERVICE_PREFIX) {
|
|
22552
|
-
const safe = safeCredentialRef(ref);
|
|
22553
|
-
const hex = Buffer.from(safe, "utf8").toString("hex");
|
|
22554
|
-
if (!hex) {
|
|
22555
|
-
throw new Error("invalid_ref");
|
|
22556
|
-
}
|
|
22557
|
-
return `${servicePrefix}.${hex}`;
|
|
22558
|
-
}
|
|
22559
|
-
function rethrowBrokerError(op, _error) {
|
|
22560
|
-
throw new Error(`credential_broker_${op}_failed`);
|
|
22561
|
-
}
|
|
22562
|
-
function createDefaultSecurityRunner(securityBin = DEFAULT_SECURITY_BIN) {
|
|
22563
|
-
return function defaultSecurityRunner(input) {
|
|
22564
|
-
return new Promise((resolve6) => {
|
|
22565
|
-
let settled = false;
|
|
22566
|
-
const finish = (result4) => {
|
|
22567
|
-
if (settled) return;
|
|
22568
|
-
settled = true;
|
|
22569
|
-
resolve6(result4);
|
|
22570
|
-
};
|
|
22571
|
-
let child;
|
|
22572
|
-
try {
|
|
22573
|
-
child = spawn2(securityBin, input.args, {
|
|
22574
|
-
stdio: ["pipe", "pipe", "pipe"]
|
|
22575
|
-
});
|
|
22576
|
-
} catch {
|
|
22577
|
-
finish({ exitCode: -1, stdout: "", stderr: "" });
|
|
22578
|
-
return;
|
|
22579
|
-
}
|
|
22580
|
-
let stdout = "";
|
|
22581
|
-
let stderr = "";
|
|
22582
|
-
child.stdout?.setEncoding("utf8");
|
|
22583
|
-
child.stderr?.setEncoding("utf8");
|
|
22584
|
-
child.stdout?.on("data", (chunk) => {
|
|
22585
|
-
stdout += chunk;
|
|
22586
|
-
});
|
|
22587
|
-
child.stderr?.on("data", (chunk) => {
|
|
22588
|
-
stderr += chunk;
|
|
22589
|
-
});
|
|
22590
|
-
child.on("error", () => {
|
|
22591
|
-
finish({ exitCode: -1, stdout: "", stderr: "" });
|
|
22592
|
-
});
|
|
22593
|
-
child.on("close", (code) => {
|
|
22594
|
-
finish({
|
|
22595
|
-
exitCode: typeof code === "number" ? code : -1,
|
|
22596
|
-
stdout,
|
|
22597
|
-
stderr
|
|
22598
|
-
});
|
|
22599
|
-
});
|
|
22600
|
-
if (input.stdin !== void 0) {
|
|
22601
|
-
child.stdin?.write(input.stdin);
|
|
22602
|
-
}
|
|
22603
|
-
child.stdin?.end();
|
|
22604
|
-
});
|
|
22605
|
-
};
|
|
22606
|
-
}
|
|
22607
|
-
function createMacOsKeychainCredentialBroker(options = {}) {
|
|
22608
|
-
const runner = options.runner ?? createDefaultSecurityRunner(options.securityBin);
|
|
22609
|
-
const servicePrefix = options.servicePrefix ?? MACOS_KEYCHAIN_SERVICE_PREFIX;
|
|
22610
|
-
const account = options.account ?? MACOS_KEYCHAIN_ACCOUNT;
|
|
22611
|
-
const serviceFor = (ref) => credentialRefToMacOsKeychainService(ref, servicePrefix);
|
|
22612
|
-
return {
|
|
22613
|
-
async get(ref) {
|
|
22614
|
-
const safeRef = safeCredentialRef(ref);
|
|
22615
|
-
const service4 = serviceFor(safeRef);
|
|
22616
|
-
let result4;
|
|
22617
|
-
try {
|
|
22618
|
-
result4 = await runner({
|
|
22619
|
-
args: [
|
|
22620
|
-
"find-generic-password",
|
|
22621
|
-
"-a",
|
|
22622
|
-
account,
|
|
22623
|
-
"-s",
|
|
22624
|
-
service4,
|
|
22625
|
-
"-w"
|
|
22626
|
-
]
|
|
22627
|
-
});
|
|
22628
|
-
} catch (error) {
|
|
22629
|
-
rethrowBrokerError("get", error);
|
|
22630
|
-
}
|
|
22631
|
-
if (result4.exitCode === SECURITY_ITEM_NOT_FOUND_EXIT) {
|
|
22632
|
-
return null;
|
|
22633
|
-
}
|
|
22634
|
-
if (result4.exitCode !== 0) {
|
|
22635
|
-
rethrowBrokerError("get");
|
|
22636
|
-
}
|
|
22637
|
-
const secret = result4.stdout.replace(/\n$/, "");
|
|
22638
|
-
return secret.length > 0 ? secret : null;
|
|
22639
|
-
},
|
|
22640
|
-
async put(ref, secret) {
|
|
22641
|
-
const safeRef = safeCredentialRef(ref);
|
|
22642
|
-
const value = asTrimmedString(secret);
|
|
22643
|
-
if (!value) {
|
|
22644
|
-
throw new Error("Cannot store an empty credential secret.");
|
|
22645
|
-
}
|
|
22646
|
-
const service4 = serviceFor(safeRef);
|
|
22647
|
-
const stdin = `${value}
|
|
22648
|
-
${value}
|
|
22649
|
-
`;
|
|
22650
|
-
let result4;
|
|
22651
|
-
try {
|
|
22652
|
-
result4 = await runner({
|
|
22653
|
-
args: [
|
|
22654
|
-
"add-generic-password",
|
|
22655
|
-
"-a",
|
|
22656
|
-
account,
|
|
22657
|
-
"-s",
|
|
22658
|
-
service4,
|
|
22659
|
-
"-U",
|
|
22660
|
-
"-w"
|
|
22661
|
-
],
|
|
22662
|
-
stdin
|
|
22663
|
-
});
|
|
22664
|
-
} catch (error) {
|
|
22665
|
-
rethrowBrokerError("put", error);
|
|
22666
|
-
}
|
|
22667
|
-
if (result4.exitCode !== 0) {
|
|
22668
|
-
rethrowBrokerError("put");
|
|
22669
|
-
}
|
|
22670
|
-
},
|
|
22671
|
-
async delete(ref) {
|
|
22672
|
-
const safeRef = safeCredentialRef(ref);
|
|
22673
|
-
const service4 = serviceFor(safeRef);
|
|
22674
|
-
let result4;
|
|
22675
|
-
try {
|
|
22676
|
-
result4 = await runner({
|
|
22677
|
-
args: [
|
|
22678
|
-
"delete-generic-password",
|
|
22679
|
-
"-a",
|
|
22680
|
-
account,
|
|
22681
|
-
"-s",
|
|
22682
|
-
service4
|
|
22683
|
-
]
|
|
22684
|
-
});
|
|
22685
|
-
} catch (error) {
|
|
22686
|
-
rethrowBrokerError("delete", error);
|
|
22687
|
-
}
|
|
22688
|
-
if (result4.exitCode === 0 || result4.exitCode === SECURITY_ITEM_NOT_FOUND_EXIT) {
|
|
22689
|
-
return;
|
|
22690
|
-
}
|
|
22691
|
-
rethrowBrokerError("delete");
|
|
22692
|
-
},
|
|
22693
|
-
async has(ref) {
|
|
22694
|
-
const safeRef = safeCredentialRef(ref);
|
|
22695
|
-
const service4 = serviceFor(safeRef);
|
|
22696
|
-
let result4;
|
|
22697
|
-
try {
|
|
22698
|
-
result4 = await runner({
|
|
22699
|
-
args: [
|
|
22700
|
-
"find-generic-password",
|
|
22701
|
-
"-a",
|
|
22702
|
-
account,
|
|
22703
|
-
"-s",
|
|
22704
|
-
service4
|
|
22705
|
-
]
|
|
22706
|
-
});
|
|
22707
|
-
} catch (error) {
|
|
22708
|
-
rethrowBrokerError("has", error);
|
|
22709
|
-
}
|
|
22710
|
-
if (result4.exitCode === SECURITY_ITEM_NOT_FOUND_EXIT) {
|
|
22711
|
-
return false;
|
|
22712
|
-
}
|
|
22713
|
-
if (result4.exitCode !== 0) {
|
|
22714
|
-
rethrowBrokerError("has");
|
|
22715
|
-
}
|
|
22716
|
-
return true;
|
|
22717
|
-
}
|
|
22718
|
-
};
|
|
22719
|
-
}
|
|
22720
|
-
|
|
22721
|
-
// packages/agent-runtime/windowsCredentialManagerBroker.ts
|
|
22722
|
-
import { spawn as spawn3 } from "node:child_process";
|
|
22723
|
-
var WINDOWS_CREDENTIAL_TARGET_PREFIX = "nolo.credentials.keys";
|
|
22724
|
-
var WIN_ERROR_NOT_FOUND = 1168;
|
|
22725
|
-
var WINDOWS_CREDENTIAL_MANAGER_SCRIPT = `
|
|
22726
|
-
$ErrorActionPreference = 'Stop'
|
|
22727
|
-
try {
|
|
22728
|
-
$raw = [Console]::In.ReadToEnd()
|
|
22729
|
-
if ([string]::IsNullOrWhiteSpace($raw)) { exit 1 }
|
|
22730
|
-
$req = $raw | ConvertFrom-Json
|
|
22731
|
-
$op = [string]$req.op
|
|
22732
|
-
$target = [string]$req.target
|
|
22733
|
-
if ([string]::IsNullOrWhiteSpace($op) -or [string]::IsNullOrWhiteSpace($target)) { exit 1 }
|
|
22734
|
-
|
|
22735
|
-
Add-Type @"
|
|
22736
|
-
using System;
|
|
22737
|
-
using System.Runtime.InteropServices;
|
|
22738
|
-
using System.Text;
|
|
22739
|
-
|
|
22740
|
-
public class NoloCredNative {
|
|
22741
|
-
public const int CRED_TYPE_GENERIC = 1;
|
|
22742
|
-
public const int CRED_PERSIST_LOCAL_MACHINE = 2;
|
|
22743
|
-
public const int ERROR_NOT_FOUND = 1168;
|
|
22744
|
-
|
|
22745
|
-
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
|
|
22746
|
-
public struct CREDENTIAL {
|
|
22747
|
-
public int Flags;
|
|
22748
|
-
public int Type;
|
|
22749
|
-
public string TargetName;
|
|
22750
|
-
public string Comment;
|
|
22751
|
-
public long LastWritten;
|
|
22752
|
-
public int CredentialBlobSize;
|
|
22753
|
-
public IntPtr CredentialBlob;
|
|
22754
|
-
public int Persist;
|
|
22755
|
-
public int AttributeCount;
|
|
22756
|
-
public IntPtr Attributes;
|
|
22757
|
-
public string TargetAlias;
|
|
22758
|
-
public string UserName;
|
|
22759
|
-
}
|
|
22760
|
-
|
|
22761
|
-
[DllImport("advapi32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
|
|
22762
|
-
public static extern bool CredWriteW(ref CREDENTIAL userCredential, uint flags);
|
|
22763
|
-
|
|
22764
|
-
[DllImport("advapi32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
|
|
22765
|
-
public static extern bool CredReadW(string target, int type, int reservedFlag, out IntPtr credentialPtr);
|
|
22766
|
-
|
|
22767
|
-
[DllImport("advapi32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
|
|
22768
|
-
public static extern bool CredDeleteW(string target, int type, int flags);
|
|
22769
|
-
|
|
22770
|
-
[DllImport("advapi32.dll", SetLastError = true)]
|
|
22771
|
-
public static extern void CredFree(IntPtr buffer);
|
|
22772
|
-
}
|
|
22773
|
-
"@
|
|
22774
|
-
|
|
22775
|
-
if ($op -eq 'get') {
|
|
22776
|
-
$ptr = [IntPtr]::Zero
|
|
22777
|
-
$ok = [NoloCredNative]::CredReadW($target, [NoloCredNative]::CRED_TYPE_GENERIC, 0, [ref]$ptr)
|
|
22778
|
-
if (-not $ok) {
|
|
22779
|
-
exit [Runtime.InteropServices.Marshal]::GetLastWin32Error()
|
|
22780
|
-
}
|
|
22781
|
-
try {
|
|
22782
|
-
$cred = [Runtime.InteropServices.Marshal]::PtrToStructure($ptr, [type][NoloCredNative+CREDENTIAL])
|
|
22783
|
-
if ($cred.CredentialBlobSize -le 0 -or $cred.CredentialBlob -eq [IntPtr]::Zero) {
|
|
22784
|
-
$payload = @{ secret = '' } | ConvertTo-Json -Compress
|
|
22785
|
-
[Console]::Out.Write($payload)
|
|
22786
|
-
exit 0
|
|
22787
|
-
}
|
|
22788
|
-
$bytes = New-Object byte[] $cred.CredentialBlobSize
|
|
22789
|
-
[Runtime.InteropServices.Marshal]::Copy($cred.CredentialBlob, $bytes, 0, $cred.CredentialBlobSize)
|
|
22790
|
-
$secret = [Text.Encoding]::UTF8.GetString($bytes)
|
|
22791
|
-
$payload = @{ secret = $secret } | ConvertTo-Json -Compress
|
|
22792
|
-
[Console]::Out.Write($payload)
|
|
22793
|
-
exit 0
|
|
22794
|
-
} finally {
|
|
22795
|
-
[NoloCredNative]::CredFree($ptr)
|
|
22796
|
-
}
|
|
22797
|
-
}
|
|
22798
|
-
|
|
22799
|
-
if ($op -eq 'has') {
|
|
22800
|
-
$ptr = [IntPtr]::Zero
|
|
22801
|
-
$ok = [NoloCredNative]::CredReadW($target, [NoloCredNative]::CRED_TYPE_GENERIC, 0, [ref]$ptr)
|
|
22802
|
-
if (-not $ok) {
|
|
22803
|
-
exit [Runtime.InteropServices.Marshal]::GetLastWin32Error()
|
|
22804
|
-
}
|
|
22805
|
-
[NoloCredNative]::CredFree($ptr)
|
|
22806
|
-
exit 0
|
|
22807
|
-
}
|
|
22808
|
-
|
|
22809
|
-
if ($op -eq 'put') {
|
|
22810
|
-
$secret = [string]$req.secret
|
|
22811
|
-
if ([string]::IsNullOrEmpty($secret)) { exit 1 }
|
|
22812
|
-
$blob = [Text.Encoding]::UTF8.GetBytes($secret)
|
|
22813
|
-
$cred = New-Object NoloCredNative+CREDENTIAL
|
|
22814
|
-
$cred.Type = [NoloCredNative]::CRED_TYPE_GENERIC
|
|
22815
|
-
$cred.TargetName = $target
|
|
22816
|
-
$cred.UserName = 'api-key'
|
|
22817
|
-
$cred.Persist = [NoloCredNative]::CRED_PERSIST_LOCAL_MACHINE
|
|
22818
|
-
$cred.CredentialBlobSize = $blob.Length
|
|
22819
|
-
$cred.CredentialBlob = [Runtime.InteropServices.Marshal]::AllocHGlobal($blob.Length)
|
|
22820
|
-
try {
|
|
22821
|
-
if ($blob.Length -gt 0) {
|
|
22822
|
-
[Runtime.InteropServices.Marshal]::Copy($blob, 0, $cred.CredentialBlob, $blob.Length)
|
|
22823
|
-
}
|
|
22824
|
-
$ok = [NoloCredNative]::CredWriteW([ref]$cred, 0)
|
|
22825
|
-
if (-not $ok) {
|
|
22826
|
-
exit [Runtime.InteropServices.Marshal]::GetLastWin32Error()
|
|
22827
|
-
}
|
|
22828
|
-
exit 0
|
|
22829
|
-
} finally {
|
|
22830
|
-
[Runtime.InteropServices.Marshal]::FreeHGlobal($cred.CredentialBlob)
|
|
22831
|
-
}
|
|
22832
|
-
}
|
|
22833
|
-
|
|
22834
|
-
if ($op -eq 'delete') {
|
|
22835
|
-
$ok = [NoloCredNative]::CredDeleteW($target, [NoloCredNative]::CRED_TYPE_GENERIC, 0)
|
|
22836
|
-
if (-not $ok) {
|
|
22837
|
-
exit [Runtime.InteropServices.Marshal]::GetLastWin32Error()
|
|
22838
|
-
}
|
|
22839
|
-
exit 0
|
|
22840
|
-
}
|
|
22841
|
-
|
|
22842
|
-
exit 1
|
|
22843
|
-
} catch {
|
|
22844
|
-
exit 1
|
|
22845
|
-
}
|
|
22846
|
-
`.trim();
|
|
22847
|
-
function safeCredentialRef2(ref) {
|
|
22848
|
-
try {
|
|
22849
|
-
return assertCredentialRef(ref);
|
|
22850
|
-
} catch {
|
|
22851
|
-
throw new Error("invalid_ref");
|
|
22852
|
-
}
|
|
22853
|
-
}
|
|
22854
|
-
function credentialRefToWindowsCredentialTarget(ref, targetPrefix = WINDOWS_CREDENTIAL_TARGET_PREFIX) {
|
|
22855
|
-
const safe = safeCredentialRef2(ref);
|
|
22856
|
-
const hex = Buffer.from(safe, "utf8").toString("hex");
|
|
22857
|
-
if (!hex) {
|
|
22858
|
-
throw new Error("invalid_ref");
|
|
22859
|
-
}
|
|
22860
|
-
return `${targetPrefix}.${hex}`;
|
|
22861
|
-
}
|
|
22862
|
-
function rethrowBrokerError2(op, _error) {
|
|
22863
|
-
throw new Error(`credential_broker_${op}_failed`);
|
|
22864
|
-
}
|
|
22865
|
-
function buildWindowsCredentialPowerShellArgs(script = WINDOWS_CREDENTIAL_MANAGER_SCRIPT) {
|
|
22866
|
-
const encoded = Buffer.from(script, "utf16le").toString("base64");
|
|
22867
|
-
return [
|
|
22868
|
-
"-NoProfile",
|
|
22869
|
-
"-NonInteractive",
|
|
22870
|
-
"-ExecutionPolicy",
|
|
22871
|
-
"Bypass",
|
|
22872
|
-
"-EncodedCommand",
|
|
22873
|
-
encoded
|
|
22874
|
-
];
|
|
22875
|
-
}
|
|
22876
|
-
function requestStdin(payload) {
|
|
22877
|
-
return JSON.stringify(payload);
|
|
22878
|
-
}
|
|
22879
|
-
function parseGetSecretFromStdout(stdout) {
|
|
22880
|
-
const trimmed = asTrimmedString(stdout);
|
|
22881
|
-
if (!trimmed) {
|
|
22882
|
-
rethrowBrokerError2("get");
|
|
22883
|
-
}
|
|
22884
|
-
let parsed;
|
|
22885
|
-
try {
|
|
22886
|
-
parsed = JSON.parse(trimmed);
|
|
22887
|
-
} catch {
|
|
22888
|
-
rethrowBrokerError2("get");
|
|
22889
|
-
}
|
|
22890
|
-
if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed) || typeof parsed.secret !== "string") {
|
|
22891
|
-
rethrowBrokerError2("get");
|
|
22892
|
-
}
|
|
22893
|
-
return parsed.secret;
|
|
22894
|
-
}
|
|
22895
|
-
function spawnShell(bin, args2, stdin) {
|
|
22896
|
-
return new Promise((resolve6) => {
|
|
22897
|
-
let settled = false;
|
|
22898
|
-
const finish = (result4) => {
|
|
22899
|
-
if (settled) return;
|
|
22900
|
-
settled = true;
|
|
22901
|
-
resolve6(result4);
|
|
22902
|
-
};
|
|
22903
|
-
let child;
|
|
22904
|
-
try {
|
|
22905
|
-
child = spawn3(bin, args2, {
|
|
22906
|
-
stdio: ["pipe", "pipe", "pipe"],
|
|
22907
|
-
windowsHide: true
|
|
22908
|
-
});
|
|
22909
|
-
} catch {
|
|
22910
|
-
finish({ exitCode: -1, stdout: "", stderr: "" });
|
|
22911
|
-
return;
|
|
22912
|
-
}
|
|
22913
|
-
let stdout = "";
|
|
22914
|
-
let stderr = "";
|
|
22915
|
-
child.stdout?.setEncoding("utf8");
|
|
22916
|
-
child.stderr?.setEncoding("utf8");
|
|
22917
|
-
child.stdout?.on("data", (chunk) => {
|
|
22918
|
-
stdout += chunk;
|
|
22919
|
-
});
|
|
22920
|
-
child.stderr?.on("data", (chunk) => {
|
|
22921
|
-
stderr += chunk;
|
|
22922
|
-
});
|
|
22923
|
-
child.on("error", () => {
|
|
22924
|
-
finish({ exitCode: -1, stdout: "", stderr: "" });
|
|
22925
|
-
});
|
|
22926
|
-
child.on("close", (code) => {
|
|
22927
|
-
finish({
|
|
22928
|
-
exitCode: typeof code === "number" ? code : -1,
|
|
22929
|
-
stdout,
|
|
22930
|
-
stderr
|
|
22931
|
-
});
|
|
22932
|
-
});
|
|
22933
|
-
if (stdin !== void 0) {
|
|
22934
|
-
child.stdin?.write(stdin);
|
|
22935
|
-
}
|
|
22936
|
-
child.stdin?.end();
|
|
22937
|
-
});
|
|
22938
|
-
}
|
|
22939
|
-
function createDefaultWindowsCredentialRunner(shellBin) {
|
|
22940
|
-
let resolvedBin = shellBin ?? null;
|
|
22941
|
-
return async function defaultWindowsCredentialRunner(input) {
|
|
22942
|
-
if (resolvedBin) {
|
|
22943
|
-
return spawnShell(resolvedBin, input.args, input.stdin);
|
|
22944
|
-
}
|
|
22945
|
-
const first = await spawnShell("powershell.exe", input.args, input.stdin);
|
|
22946
|
-
if (first.exitCode !== -1) {
|
|
22947
|
-
resolvedBin = "powershell.exe";
|
|
22948
|
-
return first;
|
|
22949
|
-
}
|
|
22950
|
-
const second = await spawnShell("pwsh", input.args, input.stdin);
|
|
22951
|
-
if (second.exitCode !== -1) {
|
|
22952
|
-
resolvedBin = "pwsh";
|
|
22953
|
-
}
|
|
22954
|
-
return second;
|
|
22955
|
-
};
|
|
22956
|
-
}
|
|
22957
|
-
function createWindowsCredentialManagerBroker(options = {}) {
|
|
22958
|
-
const runner = options.runner ?? createDefaultWindowsCredentialRunner(options.shellBin);
|
|
22959
|
-
const targetPrefix = options.targetPrefix ?? WINDOWS_CREDENTIAL_TARGET_PREFIX;
|
|
22960
|
-
const targetFor = (ref) => credentialRefToWindowsCredentialTarget(ref, targetPrefix);
|
|
22961
|
-
const staticArgs = buildWindowsCredentialPowerShellArgs();
|
|
22962
|
-
return {
|
|
22963
|
-
async get(ref) {
|
|
22964
|
-
const safeRef = safeCredentialRef2(ref);
|
|
22965
|
-
const target = targetFor(safeRef);
|
|
22966
|
-
let result4;
|
|
22967
|
-
try {
|
|
22968
|
-
result4 = await runner({
|
|
22969
|
-
args: staticArgs,
|
|
22970
|
-
stdin: requestStdin({ op: "get", target })
|
|
22971
|
-
});
|
|
22972
|
-
} catch (error) {
|
|
22973
|
-
rethrowBrokerError2("get", error);
|
|
22974
|
-
}
|
|
22975
|
-
if (result4.exitCode === WIN_ERROR_NOT_FOUND) {
|
|
22976
|
-
return null;
|
|
22977
|
-
}
|
|
22978
|
-
if (result4.exitCode !== 0) {
|
|
22979
|
-
rethrowBrokerError2("get");
|
|
22980
|
-
}
|
|
22981
|
-
const secret = parseGetSecretFromStdout(result4.stdout);
|
|
22982
|
-
return secret.length > 0 ? secret : null;
|
|
22983
|
-
},
|
|
22984
|
-
async put(ref, secret) {
|
|
22985
|
-
const safeRef = safeCredentialRef2(ref);
|
|
22986
|
-
const value = asTrimmedString(secret);
|
|
22987
|
-
if (!value) {
|
|
22988
|
-
throw new Error("Cannot store an empty credential secret.");
|
|
22989
|
-
}
|
|
22990
|
-
const target = targetFor(safeRef);
|
|
22991
|
-
let result4;
|
|
22992
|
-
try {
|
|
22993
|
-
result4 = await runner({
|
|
22994
|
-
args: staticArgs,
|
|
22995
|
-
stdin: requestStdin({ op: "put", target, secret: value })
|
|
22996
|
-
});
|
|
22997
|
-
} catch (error) {
|
|
22998
|
-
rethrowBrokerError2("put", error);
|
|
22999
|
-
}
|
|
23000
|
-
if (result4.exitCode !== 0) {
|
|
23001
|
-
rethrowBrokerError2("put");
|
|
23002
|
-
}
|
|
23003
|
-
},
|
|
23004
|
-
async delete(ref) {
|
|
23005
|
-
const safeRef = safeCredentialRef2(ref);
|
|
23006
|
-
const target = targetFor(safeRef);
|
|
23007
|
-
let result4;
|
|
23008
|
-
try {
|
|
23009
|
-
result4 = await runner({
|
|
23010
|
-
args: staticArgs,
|
|
23011
|
-
stdin: requestStdin({ op: "delete", target })
|
|
23012
|
-
});
|
|
23013
|
-
} catch (error) {
|
|
23014
|
-
rethrowBrokerError2("delete", error);
|
|
23015
|
-
}
|
|
23016
|
-
if (result4.exitCode === 0 || result4.exitCode === WIN_ERROR_NOT_FOUND) {
|
|
23017
|
-
return;
|
|
23018
|
-
}
|
|
23019
|
-
rethrowBrokerError2("delete");
|
|
23020
|
-
},
|
|
23021
|
-
async has(ref) {
|
|
23022
|
-
const safeRef = safeCredentialRef2(ref);
|
|
23023
|
-
const target = targetFor(safeRef);
|
|
23024
|
-
let result4;
|
|
23025
|
-
try {
|
|
23026
|
-
result4 = await runner({
|
|
23027
|
-
args: staticArgs,
|
|
23028
|
-
stdin: requestStdin({ op: "has", target })
|
|
23029
|
-
});
|
|
23030
|
-
} catch (error) {
|
|
23031
|
-
rethrowBrokerError2("has", error);
|
|
23032
|
-
}
|
|
23033
|
-
if (result4.exitCode === WIN_ERROR_NOT_FOUND) {
|
|
23034
|
-
return false;
|
|
23035
|
-
}
|
|
23036
|
-
if (result4.exitCode !== 0) {
|
|
23037
|
-
rethrowBrokerError2("has");
|
|
23038
|
-
}
|
|
23039
|
-
return true;
|
|
23040
|
-
}
|
|
23041
|
-
};
|
|
23042
|
-
}
|
|
23043
|
-
|
|
23044
|
-
// packages/agent-runtime/linuxSecretServiceCredentialBroker.ts
|
|
23045
|
-
import { spawn as spawn4 } from "node:child_process";
|
|
23046
|
-
var LINUX_SECRET_SERVICE_ATTRIBUTE = "nolo-credential";
|
|
23047
|
-
var SECRET_TOOL_NO_MATCH_EXIT = 1;
|
|
23048
|
-
var DEFAULT_SECRET_TOOL_BIN = "secret-tool";
|
|
23049
|
-
function safeCredentialRef3(ref) {
|
|
23050
|
-
try {
|
|
23051
|
-
return assertCredentialRef(ref);
|
|
23052
|
-
} catch {
|
|
23053
|
-
throw new Error("invalid_ref");
|
|
23054
|
-
}
|
|
23055
|
-
}
|
|
23056
|
-
function brokerFailure(op) {
|
|
23057
|
-
throw new Error(`credential_broker_${op}_failed`);
|
|
23058
|
-
}
|
|
23059
|
-
function createDefaultSecretToolRunner(secretToolBin = DEFAULT_SECRET_TOOL_BIN) {
|
|
23060
|
-
return (input) => new Promise((resolve6) => {
|
|
23061
|
-
let stdout = "";
|
|
23062
|
-
let stderr = "";
|
|
23063
|
-
let settled = false;
|
|
23064
|
-
const finish = (result4) => {
|
|
23065
|
-
if (settled) return;
|
|
23066
|
-
settled = true;
|
|
23067
|
-
resolve6(result4);
|
|
23068
|
-
};
|
|
23069
|
-
let child;
|
|
23070
|
-
try {
|
|
23071
|
-
child = spawn4(secretToolBin, input.args, {
|
|
23072
|
-
stdio: ["pipe", "pipe", "pipe"]
|
|
23073
|
-
});
|
|
23074
|
-
} catch {
|
|
23075
|
-
finish({ exitCode: -1, stdout: "", stderr: "" });
|
|
23076
|
-
return;
|
|
23077
|
-
}
|
|
23078
|
-
child.stdout?.on("data", (chunk) => {
|
|
23079
|
-
stdout += chunk;
|
|
23080
|
-
});
|
|
23081
|
-
child.stderr?.on("data", (chunk) => {
|
|
23082
|
-
stderr += chunk;
|
|
23083
|
-
});
|
|
23084
|
-
child.on("error", () => {
|
|
23085
|
-
finish({ exitCode: -1, stdout: "", stderr: "" });
|
|
23086
|
-
});
|
|
23087
|
-
child.on("close", (code) => {
|
|
23088
|
-
finish({
|
|
23089
|
-
exitCode: typeof code === "number" ? code : -1,
|
|
23090
|
-
stdout,
|
|
23091
|
-
stderr
|
|
23092
|
-
});
|
|
23093
|
-
});
|
|
23094
|
-
if (input.stdin !== void 0) {
|
|
23095
|
-
child.stdin?.write(input.stdin);
|
|
23096
|
-
}
|
|
23097
|
-
child.stdin?.end();
|
|
23098
|
-
});
|
|
23099
|
-
}
|
|
23100
|
-
function createLinuxSecretServiceCredentialBroker(options = {}) {
|
|
23101
|
-
const runner = options.runner ?? createDefaultSecretToolRunner(options.secretToolBin);
|
|
23102
|
-
const attribute = options.attribute ?? LINUX_SECRET_SERVICE_ATTRIBUTE;
|
|
23103
|
-
const attrArgs = (ref) => [attribute, ref];
|
|
23104
|
-
const lookup3 = async (ref) => {
|
|
23105
|
-
try {
|
|
23106
|
-
return await runner({ args: ["lookup", ...attrArgs(ref)] });
|
|
23107
|
-
} catch {
|
|
23108
|
-
brokerFailure("get");
|
|
23109
|
-
}
|
|
23110
|
-
};
|
|
23111
|
-
return {
|
|
23112
|
-
async get(ref) {
|
|
23113
|
-
const safeRef = safeCredentialRef3(ref);
|
|
23114
|
-
const result4 = await lookup3(safeRef);
|
|
23115
|
-
if (result4.exitCode === SECRET_TOOL_NO_MATCH_EXIT) return null;
|
|
23116
|
-
if (result4.exitCode !== 0) brokerFailure("get");
|
|
23117
|
-
const secret = result4.stdout.replace(/\n$/, "");
|
|
23118
|
-
return secret.length > 0 ? secret : null;
|
|
23119
|
-
},
|
|
23120
|
-
async put(ref, secret) {
|
|
23121
|
-
const safeRef = safeCredentialRef3(ref);
|
|
23122
|
-
const value = asTrimmedString(secret);
|
|
23123
|
-
if (!value) {
|
|
23124
|
-
throw new Error("Cannot store an empty credential secret.");
|
|
23125
|
-
}
|
|
23126
|
-
const args2 = [
|
|
23127
|
-
"store",
|
|
23128
|
-
`--label=nolo-credential:${safeRef}`,
|
|
23129
|
-
...attrArgs(safeRef)
|
|
23130
|
-
];
|
|
23131
|
-
if (value.includes("\n") || args2.some((arg) => arg.includes(value))) {
|
|
23132
|
-
brokerFailure("put");
|
|
23133
|
-
}
|
|
23134
|
-
let result4;
|
|
23135
|
-
try {
|
|
23136
|
-
result4 = await runner({ args: args2, stdin: value });
|
|
23137
|
-
} catch {
|
|
23138
|
-
brokerFailure("put");
|
|
23139
|
-
}
|
|
23140
|
-
if (result4.exitCode !== 0) brokerFailure("put");
|
|
23141
|
-
},
|
|
23142
|
-
async delete(ref) {
|
|
23143
|
-
const safeRef = safeCredentialRef3(ref);
|
|
23144
|
-
let result4;
|
|
23145
|
-
try {
|
|
23146
|
-
result4 = await runner({ args: ["clear", ...attrArgs(safeRef)] });
|
|
23147
|
-
} catch {
|
|
23148
|
-
brokerFailure("delete");
|
|
23149
|
-
}
|
|
23150
|
-
if (result4.exitCode === 0 || result4.exitCode === SECRET_TOOL_NO_MATCH_EXIT) {
|
|
23151
|
-
return;
|
|
23152
|
-
}
|
|
23153
|
-
brokerFailure("delete");
|
|
23154
|
-
},
|
|
23155
|
-
async has(ref) {
|
|
23156
|
-
const safeRef = safeCredentialRef3(ref);
|
|
23157
|
-
const result4 = await lookup3(safeRef);
|
|
23158
|
-
if (result4.exitCode === SECRET_TOOL_NO_MATCH_EXIT) return false;
|
|
23159
|
-
if (result4.exitCode !== 0) brokerFailure("has");
|
|
23160
|
-
return true;
|
|
23161
|
-
}
|
|
23162
|
-
};
|
|
23163
|
-
}
|
|
23164
|
-
|
|
23165
|
-
// packages/agent-runtime/desktopHostCredentialBroker.ts
|
|
23166
|
-
function createClosedCredentialBroker(code = "credential_store_unavailable") {
|
|
23167
|
-
const fail9 = () => {
|
|
23168
|
-
throw new Error(code);
|
|
23169
|
-
};
|
|
23170
|
-
return {
|
|
23171
|
-
get: fail9,
|
|
23172
|
-
put: fail9,
|
|
23173
|
-
delete: fail9,
|
|
23174
|
-
has: () => false
|
|
23175
|
-
};
|
|
23176
|
-
}
|
|
23177
|
-
function createHostCredentialBrokerChain(args2) {
|
|
23178
|
-
const { strict, session, legacy, notifySessionFallback, notifyLegacyHit } = args2;
|
|
23179
|
-
const legacyNoticed = /* @__PURE__ */ new Set();
|
|
23180
|
-
let sessionNotified = false;
|
|
23181
|
-
const noticeSession = () => {
|
|
23182
|
-
if (sessionNotified || !notifySessionFallback) return;
|
|
23183
|
-
sessionNotified = true;
|
|
23184
|
-
try {
|
|
23185
|
-
notifySessionFallback();
|
|
23186
|
-
} catch {
|
|
23187
|
-
}
|
|
23188
|
-
};
|
|
23189
|
-
return {
|
|
23190
|
-
async get(ref) {
|
|
23191
|
-
try {
|
|
23192
|
-
const strictValue = await strict.get(ref);
|
|
23193
|
-
if (strictValue !== null && strictValue !== void 0) return strictValue;
|
|
23194
|
-
} catch {
|
|
23195
|
-
}
|
|
23196
|
-
const sessionValue = await session.get(ref);
|
|
23197
|
-
if (sessionValue !== null && sessionValue !== void 0) return sessionValue;
|
|
23198
|
-
if (!legacy) return null;
|
|
23199
|
-
const legacyValue = await legacy.get(ref);
|
|
23200
|
-
if (legacyValue !== null && legacyValue !== void 0) {
|
|
23201
|
-
if (notifyLegacyHit && !legacyNoticed.has(ref)) {
|
|
23202
|
-
legacyNoticed.add(ref);
|
|
23203
|
-
try {
|
|
23204
|
-
notifyLegacyHit(ref);
|
|
23205
|
-
} catch {
|
|
23206
|
-
}
|
|
23207
|
-
}
|
|
23208
|
-
return legacyValue;
|
|
23209
|
-
}
|
|
23210
|
-
return null;
|
|
23211
|
-
},
|
|
23212
|
-
async put(ref, secret) {
|
|
23213
|
-
try {
|
|
23214
|
-
await strict.put(ref, secret);
|
|
23215
|
-
if (await strict.has(ref)) return;
|
|
23216
|
-
} catch {
|
|
23217
|
-
}
|
|
23218
|
-
await session.put(ref, secret);
|
|
23219
|
-
noticeSession();
|
|
23220
|
-
},
|
|
23221
|
-
async delete(ref) {
|
|
23222
|
-
try {
|
|
23223
|
-
await strict.delete(ref);
|
|
23224
|
-
} catch {
|
|
23225
|
-
}
|
|
23226
|
-
try {
|
|
23227
|
-
await session.delete(ref);
|
|
23228
|
-
} catch {
|
|
23229
|
-
}
|
|
23230
|
-
if (legacy) await legacy.delete(ref);
|
|
23231
|
-
},
|
|
23232
|
-
async has(ref) {
|
|
23233
|
-
try {
|
|
23234
|
-
if (await strict.has(ref)) return true;
|
|
23235
|
-
} catch {
|
|
23236
|
-
}
|
|
23237
|
-
if (await session.has(ref)) return true;
|
|
23238
|
-
return legacy ? await legacy.has(ref) : false;
|
|
23239
|
-
}
|
|
23240
|
-
};
|
|
23241
|
-
}
|
|
23242
|
-
function createStrictHostCredentialBroker(options = {}) {
|
|
23243
|
-
const platform = options.platform ?? process.platform;
|
|
23244
|
-
const env = options.env ?? process.env;
|
|
23245
|
-
const override = String(env.NOLO_DESKTOP_CREDENTIAL_STORE ?? "").trim().toLowerCase();
|
|
23246
|
-
if (override === "file") {
|
|
23247
|
-
return createClosedCredentialBroker("credential_store_file_not_allowed");
|
|
23248
|
-
}
|
|
23249
|
-
if (platform === "darwin" || override === "keychain") {
|
|
23250
|
-
return options.keychainBroker ?? (options.createKeychainBroker ?? (() => createMacOsKeychainCredentialBroker()))();
|
|
23251
|
-
}
|
|
23252
|
-
if (platform === "win32" || override === "credman") {
|
|
23253
|
-
return options.windowsCredentialBroker ?? (options.createWindowsCredentialBroker ?? (() => createWindowsCredentialManagerBroker()))();
|
|
23254
|
-
}
|
|
23255
|
-
if (platform === "linux" || override === "secret-service") {
|
|
23256
|
-
return options.linuxSecretServiceBroker ?? (options.createLinuxSecretServiceBroker ?? (() => createLinuxSecretServiceCredentialBroker()))();
|
|
23257
|
-
}
|
|
23258
|
-
return createClosedCredentialBroker("credential_store_unsupported");
|
|
23259
|
-
}
|
|
23260
|
-
|
|
23261
|
-
// packages/agent-runtime/dialogMessageRecord.ts
|
|
23262
|
-
function dialogMessageRecordToAgentRuntimeMessage(record2) {
|
|
23263
|
-
if (!record2 || typeof record2 !== "object") return null;
|
|
23264
|
-
if (record2.role !== "user" && record2.role !== "assistant" && record2.role !== "tool") return null;
|
|
23265
|
-
return {
|
|
23266
|
-
...typeof record2.id === "string" ? { id: record2.id } : {},
|
|
23267
|
-
role: record2.role,
|
|
23268
|
-
content: record2.content ?? "",
|
|
23269
|
-
...record2.contextReference !== void 0 ? { context_reference: record2.contextReference } : {},
|
|
23270
|
-
...typeof record2.reasoning_content === "string" ? { reasoning_content: record2.reasoning_content } : {},
|
|
23271
|
-
...typeof record2.toolCallId === "string" ? { tool_call_id: record2.toolCallId } : {},
|
|
23272
|
-
...Array.isArray(record2.tool_calls) ? { tool_calls: record2.tool_calls } : {},
|
|
23273
|
-
...record2.toolPayload !== void 0 ? { toolPayload: record2.toolPayload } : {},
|
|
23274
|
-
...typeof record2.toolName === "string" ? { toolName: record2.toolName } : {},
|
|
23275
|
-
// 写侧(dialogWritePlan)把 tool_result_metadata 以 `metadata` 字段落库;
|
|
23276
|
-
// 回读必须还原,否则跨 turn 投影丢失 metadata 后缀,同一 tool 消息的字节
|
|
23277
|
-
// 在 turn 边界漂移 → provider 前缀缓存断裂(stable projection 契约,
|
|
23278
|
-
// 见 docs/plans/2026-09-05-tool-output-cache-stability.md)。
|
|
23279
|
-
...record2.metadata && typeof record2.metadata === "object" ? { tool_result_metadata: record2.metadata } : {},
|
|
23280
|
-
...(() => {
|
|
23281
|
-
const raw = record2.createdAt;
|
|
23282
|
-
const ms = typeof raw === "number" ? raw : typeof raw === "string" ? Date.parse(raw) : NaN;
|
|
23283
|
-
return Number.isFinite(ms) ? { createdAt: ms } : {};
|
|
23284
|
-
})()
|
|
23285
|
-
};
|
|
23286
|
-
}
|
|
23287
|
-
|
|
23288
22965
|
// packages/agent-runtime/dialogWritePlan.ts
|
|
23289
22966
|
function extractLastUserText(messages) {
|
|
23290
22967
|
const lastUser = [...messages].reverse().find((message) => message.role === "user");
|
|
@@ -23710,11 +23387,11 @@ var E_ALREADY_LOCKED = new Error("mutex already locked");
|
|
|
23710
23387
|
var E_CANCELED = new Error("request for lock canceled");
|
|
23711
23388
|
var __awaiter$2 = function(thisArg, _arguments, P, generator) {
|
|
23712
23389
|
function adopt(value) {
|
|
23713
|
-
return value instanceof P ? value : new P(function(
|
|
23714
|
-
|
|
23390
|
+
return value instanceof P ? value : new P(function(resolve7) {
|
|
23391
|
+
resolve7(value);
|
|
23715
23392
|
});
|
|
23716
23393
|
}
|
|
23717
|
-
return new (P || (P = Promise))(function(
|
|
23394
|
+
return new (P || (P = Promise))(function(resolve7, reject) {
|
|
23718
23395
|
function fulfilled(value) {
|
|
23719
23396
|
try {
|
|
23720
23397
|
step(generator.next(value));
|
|
@@ -23730,7 +23407,7 @@ var __awaiter$2 = function(thisArg, _arguments, P, generator) {
|
|
|
23730
23407
|
}
|
|
23731
23408
|
}
|
|
23732
23409
|
function step(result4) {
|
|
23733
|
-
result4.done ?
|
|
23410
|
+
result4.done ? resolve7(result4.value) : adopt(result4.value).then(fulfilled, rejected);
|
|
23734
23411
|
}
|
|
23735
23412
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
23736
23413
|
});
|
|
@@ -23745,8 +23422,8 @@ var Semaphore = class {
|
|
|
23745
23422
|
acquire(weight = 1, priority = 0) {
|
|
23746
23423
|
if (weight <= 0)
|
|
23747
23424
|
throw new Error(`invalid weight ${weight}: must be positive`);
|
|
23748
|
-
return new Promise((
|
|
23749
|
-
const task = { resolve:
|
|
23425
|
+
return new Promise((resolve7, reject) => {
|
|
23426
|
+
const task = { resolve: resolve7, reject, weight, priority };
|
|
23750
23427
|
const i = findIndexFromEnd(this._queue, (other) => priority <= other.priority);
|
|
23751
23428
|
if (i === -1 && weight <= this._value) {
|
|
23752
23429
|
this._dispatchItem(task);
|
|
@@ -23771,10 +23448,10 @@ var Semaphore = class {
|
|
|
23771
23448
|
if (this._couldLockImmediately(weight, priority)) {
|
|
23772
23449
|
return Promise.resolve();
|
|
23773
23450
|
} else {
|
|
23774
|
-
return new Promise((
|
|
23451
|
+
return new Promise((resolve7) => {
|
|
23775
23452
|
if (!this._weightedWaiters[weight - 1])
|
|
23776
23453
|
this._weightedWaiters[weight - 1] = [];
|
|
23777
|
-
insertSorted(this._weightedWaiters[weight - 1], { resolve:
|
|
23454
|
+
insertSorted(this._weightedWaiters[weight - 1], { resolve: resolve7, priority });
|
|
23778
23455
|
});
|
|
23779
23456
|
}
|
|
23780
23457
|
}
|
|
@@ -23857,11 +23534,11 @@ function findIndexFromEnd(a, predicate) {
|
|
|
23857
23534
|
}
|
|
23858
23535
|
var __awaiter$1 = function(thisArg, _arguments, P, generator) {
|
|
23859
23536
|
function adopt(value) {
|
|
23860
|
-
return value instanceof P ? value : new P(function(
|
|
23861
|
-
|
|
23537
|
+
return value instanceof P ? value : new P(function(resolve7) {
|
|
23538
|
+
resolve7(value);
|
|
23862
23539
|
});
|
|
23863
23540
|
}
|
|
23864
|
-
return new (P || (P = Promise))(function(
|
|
23541
|
+
return new (P || (P = Promise))(function(resolve7, reject) {
|
|
23865
23542
|
function fulfilled(value) {
|
|
23866
23543
|
try {
|
|
23867
23544
|
step(generator.next(value));
|
|
@@ -23877,7 +23554,7 @@ var __awaiter$1 = function(thisArg, _arguments, P, generator) {
|
|
|
23877
23554
|
}
|
|
23878
23555
|
}
|
|
23879
23556
|
function step(result4) {
|
|
23880
|
-
result4.done ?
|
|
23557
|
+
result4.done ? resolve7(result4.value) : adopt(result4.value).then(fulfilled, rejected);
|
|
23881
23558
|
}
|
|
23882
23559
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
23883
23560
|
});
|
|
@@ -23968,7 +23645,7 @@ async function registerDialogOwner(args2) {
|
|
|
23968
23645
|
// packages/cli/client/localDialogRecords.ts
|
|
23969
23646
|
var localDialogMessageRecordToRuntimeMessage = dialogMessageRecordToAgentRuntimeMessage;
|
|
23970
23647
|
function buildLocalDialogWritePlan(args2) {
|
|
23971
|
-
|
|
23648
|
+
const plan = buildAgentRuntimeDialogWritePlan({
|
|
23972
23649
|
input: args2.input,
|
|
23973
23650
|
userId: args2.userId,
|
|
23974
23651
|
now: args2.now,
|
|
@@ -23980,6 +23657,21 @@ function buildLocalDialogWritePlan(args2) {
|
|
|
23980
23657
|
},
|
|
23981
23658
|
...args2.titleOverride ? { titleOverride: args2.titleOverride } : {}
|
|
23982
23659
|
});
|
|
23660
|
+
const turnId = args2.input.runtimeContext?.turnId;
|
|
23661
|
+
const captureUserMessageIds = [];
|
|
23662
|
+
if (typeof turnId === "string" && /^turn-[0-9A-HJKMNP-TV-Z]{26}$/.test(turnId)) {
|
|
23663
|
+
const messages = args2.input.messages.filter((message) => message.role !== "system");
|
|
23664
|
+
for (const [index, message] of messages.entries()) {
|
|
23665
|
+
if (message.role !== "user" || message.cliMessageId) continue;
|
|
23666
|
+
const op = plan.ops[index + 1];
|
|
23667
|
+
const id = dialogTurnUserMessageId(turnId, index);
|
|
23668
|
+
const key = `dialog-${plan.dialogId}-msg-${id}`;
|
|
23669
|
+
op.key = key;
|
|
23670
|
+
op.value = { ...op.value, id, dbKey: key };
|
|
23671
|
+
captureUserMessageIds.push(id);
|
|
23672
|
+
}
|
|
23673
|
+
}
|
|
23674
|
+
return { ...plan, captureUserMessageIds };
|
|
23983
23675
|
}
|
|
23984
23676
|
async function saveCliPendingUserMessages(args2) {
|
|
23985
23677
|
const dialogKey = `dialog-${args2.userId}-${args2.dialogId}`;
|
|
@@ -24026,7 +23718,7 @@ async function saveCliPendingUserMessages(args2) {
|
|
|
24026
23718
|
if (ops.length) await args2.store.batch(ops);
|
|
24027
23719
|
}
|
|
24028
23720
|
async function readCliPendingUserMessages(store, dialogId) {
|
|
24029
|
-
const { readDialogMessageRecords } = await import("./cliLocalAgentRecordReader-
|
|
23721
|
+
const { readDialogMessageRecords } = await import("./cliLocalAgentRecordReader-53773JID.js");
|
|
24030
23722
|
const rows = await readDialogMessageRecords({ store, dialogId });
|
|
24031
23723
|
const uncertain = rows.filter(({ record: record2 }) => record2.metadata?.cliBatchPhase === "requested" && !record2.metadata?.cliBatchResolution);
|
|
24032
23724
|
const recovery = uncertain.length ? {
|
|
@@ -24075,6 +23767,8 @@ async function markCliUserBatchPhase(store, dialogId, messageId, phase, messageI
|
|
|
24075
23767
|
metadata: {
|
|
24076
23768
|
...message.metadata,
|
|
24077
23769
|
queueState: "accepted",
|
|
23770
|
+
cliBatchId: messageId,
|
|
23771
|
+
...Number.isFinite(prepared?.cliHistoryOrder) ? { cliHistoryOrder: prepared.cliHistoryOrder } : {},
|
|
24078
23772
|
...id === messageId ? { cliBatchPhase: phase, acceptedUserMessageIds: [...messageIds] } : {}
|
|
24079
23773
|
}
|
|
24080
23774
|
} });
|
|
@@ -24089,6 +23783,8 @@ async function rollbackCliUserBatchPhase(store, dialogId, batchId, messageIds) {
|
|
|
24089
23783
|
if (!record2) continue;
|
|
24090
23784
|
const metadata = { ...record2.metadata };
|
|
24091
23785
|
delete metadata.cliBatchPhase;
|
|
23786
|
+
delete metadata.cliBatchId;
|
|
23787
|
+
delete metadata.acceptedUserMessageIds;
|
|
24092
23788
|
metadata.queueState = "pending";
|
|
24093
23789
|
ops.push({ type: "put", key, value: { ...record2, metadata } });
|
|
24094
23790
|
}
|
|
@@ -24121,11 +23817,11 @@ async function readNoloProcessStream(readable) {
|
|
|
24121
23817
|
async function runNoloWorkspaceCliTool(call, args2) {
|
|
24122
23818
|
const cliArgs = buildNoloWorkspaceCommandArgs(call);
|
|
24123
23819
|
const bunSpawn = globalThis.Bun?.spawn;
|
|
24124
|
-
const
|
|
23820
|
+
const spawn2 = args2.spawn ?? (typeof bunSpawn === "function" ? bunSpawn : nodeSpawnFallback);
|
|
24125
23821
|
const execPath = args2.processExecPath ?? process.execPath;
|
|
24126
23822
|
const entrypoint = args2.cliEntrypoint;
|
|
24127
23823
|
const cmd = entrypoint && entrypoint !== execPath ? [execPath, entrypoint, ...cliArgs] : [execPath, ...cliArgs];
|
|
24128
|
-
const proc =
|
|
23824
|
+
const proc = spawn2({
|
|
24129
23825
|
cmd,
|
|
24130
23826
|
stdout: "pipe",
|
|
24131
23827
|
stderr: "pipe",
|
|
@@ -24151,7 +23847,15 @@ async function runNoloWorkspaceCliTool(call, args2) {
|
|
|
24151
23847
|
}
|
|
24152
23848
|
};
|
|
24153
23849
|
}
|
|
24154
|
-
|
|
23850
|
+
function isLocalExclusiveDialog(dialogId, meta, localChildDialogIds) {
|
|
23851
|
+
if (localChildDialogIds?.has(dialogId)) return true;
|
|
23852
|
+
const record2 = meta;
|
|
23853
|
+
if (!record2 || typeof record2 !== "object") return false;
|
|
23854
|
+
if (record2.triggerType === "cli-agent-run") return true;
|
|
23855
|
+
return Boolean(record2.localRuntime) && record2.executionMode === "background";
|
|
23856
|
+
}
|
|
23857
|
+
var fallback = (reason) => ({ outcome: "fallback", reason });
|
|
23858
|
+
async function readDialogInProcess(call, store, ctx) {
|
|
24155
23859
|
const args2 = parseNoloWorkspaceToolArguments(call.arguments);
|
|
24156
23860
|
const dialogInput = noloStringArg(args2.dialog ?? args2.dialogId ?? args2.id);
|
|
24157
23861
|
if (!dialogInput) throw new Error("readDialog requires dialog.");
|
|
@@ -24159,9 +23863,18 @@ async function readDialogInProcess(call, store, env) {
|
|
|
24159
23863
|
if (mode && mode !== "full" && mode !== "status") {
|
|
24160
23864
|
throw new Error(`readDialog mode must be "full" or "status", got "${mode}".`);
|
|
24161
23865
|
}
|
|
24162
|
-
|
|
24163
|
-
|
|
24164
|
-
const
|
|
23866
|
+
if (noloStringArg(args2.user ?? args2.userId ?? args2.owner)) return fallback("explicit-user");
|
|
23867
|
+
if (noloStringArg(args2.server ?? args2.serverBase ?? args2.serverUrl)) return fallback("explicit-server");
|
|
23868
|
+
const currentUserId = ctx.currentUserId;
|
|
23869
|
+
if (!currentUserId) return fallback("no-current-user");
|
|
23870
|
+
const { dbKey: dialogKey, dialogId, ownerId } = resolveNoloDialogInput(dialogInput, currentUserId);
|
|
23871
|
+
if (ownerId !== currentUserId) return fallback("foreign-owner");
|
|
23872
|
+
const meta = await store.read(dialogKey);
|
|
23873
|
+
if (!meta) return fallback("local-miss");
|
|
23874
|
+
if (isTombstoneRecord(meta)) return fallback("tombstone");
|
|
23875
|
+
if (!isLocalExclusiveDialog(dialogId, meta, ctx.localChildDialogIds)) {
|
|
23876
|
+
return fallback("cross-device-sync");
|
|
23877
|
+
}
|
|
24165
23878
|
if (mode === "status") {
|
|
24166
23879
|
const result4 = {
|
|
24167
23880
|
dialogId,
|
|
@@ -24172,8 +23885,11 @@ async function readDialogInProcess(call, store, env) {
|
|
|
24172
23885
|
source: "in-process"
|
|
24173
23886
|
};
|
|
24174
23887
|
return {
|
|
24175
|
-
|
|
24176
|
-
|
|
23888
|
+
outcome: "hit",
|
|
23889
|
+
result: {
|
|
23890
|
+
content: JSON.stringify(result4, null, 2),
|
|
23891
|
+
metadata: { noloWorkspaceTool: true, readDialog: true, inProcess: true, mode: "status" }
|
|
23892
|
+
}
|
|
24177
23893
|
};
|
|
24178
23894
|
}
|
|
24179
23895
|
const limitNum = noloPositiveIntegerString(args2.limit);
|
|
@@ -24182,15 +23898,18 @@ async function readDialogInProcess(call, store, env) {
|
|
|
24182
23898
|
maxResponseChars: DEFAULT_READ_DIALOG_MAX_RESPONSE_CHARS,
|
|
24183
23899
|
...limit !== void 0 ? { maxMessages: limit } : {}
|
|
24184
23900
|
});
|
|
23901
|
+
let hasMessages = false;
|
|
24185
23902
|
if (store.iterator) {
|
|
24186
23903
|
const { start, end: end3 } = dialogMessageRange(dialogId);
|
|
24187
23904
|
for await (const [, value] of store.iterator({ gte: start, lte: end3 })) {
|
|
24188
23905
|
const message = localDialogMessageRecordToRuntimeMessage(value) ?? value;
|
|
24189
23906
|
if (message) {
|
|
23907
|
+
hasMessages = true;
|
|
24190
23908
|
projector.addMessage(message);
|
|
24191
23909
|
}
|
|
24192
23910
|
}
|
|
24193
23911
|
}
|
|
23912
|
+
if (!hasMessages) return fallback("no-local-messages");
|
|
24194
23913
|
const projected = projector.finish(meta);
|
|
24195
23914
|
const built = buildDialogReadEnvelope({
|
|
24196
23915
|
meta: projected.meta,
|
|
@@ -24204,22 +23923,83 @@ async function readDialogInProcess(call, store, env) {
|
|
|
24204
23923
|
}
|
|
24205
23924
|
});
|
|
24206
23925
|
return {
|
|
24207
|
-
|
|
24208
|
-
|
|
23926
|
+
outcome: "hit",
|
|
23927
|
+
result: {
|
|
23928
|
+
content: built.serialized,
|
|
23929
|
+
metadata: { noloWorkspaceTool: true, readDialog: true, inProcess: true }
|
|
23930
|
+
}
|
|
24209
23931
|
};
|
|
24210
23932
|
}
|
|
24211
23933
|
function buildNoloWorkspaceCliToolExecutors(args2) {
|
|
24212
23934
|
const executors = {};
|
|
24213
23935
|
for (const toolName of CLI_NOLO_WORKSPACE_TOOL_NAMES) {
|
|
24214
23936
|
if (toolName === "loadSkill") continue;
|
|
24215
|
-
|
|
24216
|
-
|
|
23937
|
+
const inProcess = args2.inProcessExecutors?.[toolName];
|
|
23938
|
+
const storeBackedRead = toolName === "readDialog" && Boolean(args2.store || args2.resolveDialogStore);
|
|
23939
|
+
if (inProcess || storeBackedRead) {
|
|
23940
|
+
executors[toolName] = createInProcessWithCliFallback(args2, inProcess);
|
|
24217
23941
|
continue;
|
|
24218
23942
|
}
|
|
24219
23943
|
executors[toolName] = (call) => runNoloWorkspaceCliTool(call, args2);
|
|
24220
23944
|
}
|
|
24221
23945
|
return executors;
|
|
24222
23946
|
}
|
|
23947
|
+
function createInProcessWithCliFallback(args2, inProcess) {
|
|
23948
|
+
return async (call) => {
|
|
23949
|
+
let fallbackReason;
|
|
23950
|
+
try {
|
|
23951
|
+
if (inProcess) {
|
|
23952
|
+
const result4 = await inProcess(call, { env: args2.env });
|
|
23953
|
+
if (result4) return result4;
|
|
23954
|
+
fallbackReason = "local-miss";
|
|
23955
|
+
} else {
|
|
23956
|
+
const currentUserId = resolveHostCurrentUserId(args2);
|
|
23957
|
+
const store = await resolveInProcessDialogStore(args2);
|
|
23958
|
+
const outcome = store ? await readDialogInProcess(call, store, {
|
|
23959
|
+
env: args2.env,
|
|
23960
|
+
currentUserId,
|
|
23961
|
+
localChildDialogIds: resolveLocalChildDialogIds(args2)
|
|
23962
|
+
}) : { outcome: "fallback", reason: "no-store" };
|
|
23963
|
+
if (outcome.outcome === "hit") return outcome.result;
|
|
23964
|
+
fallbackReason = outcome.reason;
|
|
23965
|
+
}
|
|
23966
|
+
} catch (error) {
|
|
23967
|
+
fallbackReason = error instanceof Error ? error.message : String(error);
|
|
23968
|
+
}
|
|
23969
|
+
const bridged = await runNoloWorkspaceCliTool(call, args2);
|
|
23970
|
+
return {
|
|
23971
|
+
...bridged,
|
|
23972
|
+
metadata: { ...bridged.metadata, inProcessFallback: fallbackReason }
|
|
23973
|
+
};
|
|
23974
|
+
};
|
|
23975
|
+
}
|
|
23976
|
+
async function resolveInProcessDialogStore(args2) {
|
|
23977
|
+
if (args2.store) return args2.store;
|
|
23978
|
+
if (!args2.resolveDialogStore) return void 0;
|
|
23979
|
+
try {
|
|
23980
|
+
return await args2.resolveDialogStore();
|
|
23981
|
+
} catch {
|
|
23982
|
+
return void 0;
|
|
23983
|
+
}
|
|
23984
|
+
}
|
|
23985
|
+
function resolveLocalChildDialogIds(args2) {
|
|
23986
|
+
try {
|
|
23987
|
+
return args2.resolveLocalChildDialogIds?.();
|
|
23988
|
+
} catch {
|
|
23989
|
+
return void 0;
|
|
23990
|
+
}
|
|
23991
|
+
}
|
|
23992
|
+
function resolveHostCurrentUserId(args2) {
|
|
23993
|
+
try {
|
|
23994
|
+
const injected = args2.resolveCurrentUserId?.();
|
|
23995
|
+
if (injected && injected.trim()) return injected.trim();
|
|
23996
|
+
if (args2.resolveCurrentUserId) return void 0;
|
|
23997
|
+
const derived = resolveLocalUserId(args2.env ?? {});
|
|
23998
|
+
return derived && derived.trim() ? derived.trim() : void 0;
|
|
23999
|
+
} catch {
|
|
24000
|
+
return void 0;
|
|
24001
|
+
}
|
|
24002
|
+
}
|
|
24223
24003
|
var nodeSpawnFallback = (options) => {
|
|
24224
24004
|
return spawnToWebStreams({ cmd: options.cmd, env: options.env });
|
|
24225
24005
|
};
|
|
@@ -24237,10 +24017,10 @@ function buildLoadSkillExecutor(args2) {
|
|
|
24237
24017
|
metadata: { loadSkill: true, resolved: false }
|
|
24238
24018
|
};
|
|
24239
24019
|
}
|
|
24240
|
-
const { resolveSkillByName } = await import("./skillDiscovery-
|
|
24020
|
+
const { resolveSkillByName } = await import("./skillDiscovery-MDDKPTW3.js");
|
|
24241
24021
|
const resolved = resolveSkillByName(args2.cwd, name);
|
|
24242
24022
|
if (!resolved) {
|
|
24243
|
-
const { resolveBuiltinSkillByName } = await import("./builtinSkillRegistry-
|
|
24023
|
+
const { resolveBuiltinSkillByName } = await import("./builtinSkillRegistry-LRVAQCPW.js");
|
|
24244
24024
|
const builtin = resolveBuiltinSkillByName(name);
|
|
24245
24025
|
if (builtin) {
|
|
24246
24026
|
const denied = await rejectDisabledBuiltin(args2.agentSkillSource, builtin.slug, name, args2.resolveAgentSkillSource);
|
|
@@ -24267,8 +24047,8 @@ ${builtin.content}`,
|
|
|
24267
24047
|
};
|
|
24268
24048
|
}
|
|
24269
24049
|
try {
|
|
24270
|
-
const { readFileSync } = await import("node:fs");
|
|
24271
|
-
const body =
|
|
24050
|
+
const { readFileSync: readFileSync2 } = await import("node:fs");
|
|
24051
|
+
const body = readFileSync2(resolved, "utf8");
|
|
24272
24052
|
return {
|
|
24273
24053
|
content: `Skill "${name}" loaded inline. Follow its instructions.
|
|
24274
24054
|
|
|
@@ -24319,7 +24099,7 @@ async function loadPreciseSkill(cwd, parsed, agentSkillSource, resolveAgentSkill
|
|
|
24319
24099
|
if (!nonEmpty(parsed.slug) || has2("projectBinding") || has2("relativePath")) {
|
|
24320
24100
|
return reject("builtin requires only an exact slug.");
|
|
24321
24101
|
}
|
|
24322
|
-
const { listBuiltinSkills } = await import("./builtinSkillRegistry-
|
|
24102
|
+
const { listBuiltinSkills } = await import("./builtinSkillRegistry-LRVAQCPW.js");
|
|
24323
24103
|
const builtin = listBuiltinSkills().find((entry) => entry.slug === parsed.slug);
|
|
24324
24104
|
if (!builtin) return reject("builtin slug not found.");
|
|
24325
24105
|
const denied = await rejectDisabledBuiltin(agentSkillSource, builtin.slug, builtin.slug, resolveAgentSkillSource);
|
|
@@ -24344,8 +24124,8 @@ ${builtin.content}`,
|
|
|
24344
24124
|
return reject("project requires projectBinding and relativePath only.");
|
|
24345
24125
|
}
|
|
24346
24126
|
try {
|
|
24347
|
-
const { realpathSync, statSync, readFileSync } = await import("node:fs");
|
|
24348
|
-
const { resolve:
|
|
24127
|
+
const { realpathSync, statSync, readFileSync: readFileSync2 } = await import("node:fs");
|
|
24128
|
+
const { resolve: resolve7, relative: relative6, isAbsolute: isAbsolute5, basename: basename4, sep: sep3 } = await import("node:path");
|
|
24349
24129
|
const inside = (root, target) => {
|
|
24350
24130
|
const rel = relative6(root, target);
|
|
24351
24131
|
return rel !== "" && rel !== ".." && !rel.startsWith(`..${sep3}`) && !isAbsolute5(rel);
|
|
@@ -24357,8 +24137,8 @@ ${builtin.content}`,
|
|
|
24357
24137
|
if (isAbsolute5(parsed.relativePath) || basename4(parsed.relativePath) !== "SKILL.md") {
|
|
24358
24138
|
return reject("relativePath must reference a project SKILL.md.");
|
|
24359
24139
|
}
|
|
24360
|
-
const skillsRoot =
|
|
24361
|
-
const candidate =
|
|
24140
|
+
const skillsRoot = resolve7(realCwd, ".agents", "skills");
|
|
24141
|
+
const candidate = resolve7(realCwd, parsed.relativePath);
|
|
24362
24142
|
if (!inside(skillsRoot, candidate)) return reject("path is outside cwd/.agents/skills/.");
|
|
24363
24143
|
const realRoot = realpathSync(skillsRoot);
|
|
24364
24144
|
const realPath = realpathSync(candidate);
|
|
@@ -24366,7 +24146,7 @@ ${builtin.content}`,
|
|
|
24366
24146
|
return reject("skill path escapes cwd/.agents/skills/ or is not SKILL.md.");
|
|
24367
24147
|
}
|
|
24368
24148
|
if (!statSync(realPath).isFile()) return reject("SKILL.md is not a file.");
|
|
24369
|
-
const body =
|
|
24149
|
+
const body = readFileSync2(realPath, "utf8");
|
|
24370
24150
|
return {
|
|
24371
24151
|
content: `Skill "${parsed.relativePath}" loaded inline. Follow its instructions.
|
|
24372
24152
|
|
|
@@ -24385,7 +24165,7 @@ ${body}`,
|
|
|
24385
24165
|
}
|
|
24386
24166
|
}
|
|
24387
24167
|
async function formatUnknownSkillMessage(cwd, requestedName) {
|
|
24388
|
-
const { discoverSkills } = await import("./skillDiscovery-
|
|
24168
|
+
const { discoverSkills } = await import("./skillDiscovery-MDDKPTW3.js");
|
|
24389
24169
|
let available = [];
|
|
24390
24170
|
try {
|
|
24391
24171
|
available = discoverSkills(cwd).map((s) => s.name);
|
|
@@ -24957,11 +24737,11 @@ function createDevinProvider(options) {
|
|
|
24957
24737
|
}
|
|
24958
24738
|
|
|
24959
24739
|
// packages/agent-runtime/executionLeaseValidation.ts
|
|
24960
|
-
import { isAbsolute as isAbsolute4, relative as relative5, resolve as
|
|
24740
|
+
import { isAbsolute as isAbsolute4, relative as relative5, resolve as resolve6 } from "node:path";
|
|
24961
24741
|
function withinRoot(root, child) {
|
|
24962
24742
|
if (!isAbsolute4(root) || !isAbsolute4(child)) return false;
|
|
24963
|
-
const canonicalRoot =
|
|
24964
|
-
const canonicalChild =
|
|
24743
|
+
const canonicalRoot = resolve6(root);
|
|
24744
|
+
const canonicalChild = resolve6(child);
|
|
24965
24745
|
const suffix = relative5(canonicalRoot, canonicalChild);
|
|
24966
24746
|
return suffix === "" || suffix !== ".." && !suffix.startsWith("../") && !suffix.startsWith("..\\") && !isAbsolute4(suffix);
|
|
24967
24747
|
}
|
|
@@ -25024,17 +24804,16 @@ function verifyOwnerRouteAck(headers, expectedRequestId) {
|
|
|
25024
24804
|
}
|
|
25025
24805
|
|
|
25026
24806
|
export {
|
|
25027
|
-
createHostCredentialBrokerChain,
|
|
25028
|
-
createStrictHostCredentialBroker,
|
|
25029
24807
|
readCommandActionGatePayload,
|
|
25030
24808
|
readActionGate,
|
|
24809
|
+
orderDialogHistory,
|
|
25031
24810
|
Option_exports,
|
|
25032
24811
|
Duration_exports,
|
|
25033
24812
|
Exit_exports,
|
|
25034
24813
|
Effect_exports,
|
|
25035
|
-
scrubSecrets,
|
|
25036
24814
|
isDestructiveShellCommand,
|
|
25037
24815
|
evaluateShellCommandPolicy,
|
|
24816
|
+
readAgentsMdLayerFromDisk,
|
|
25038
24817
|
filterRetainedLedgerRecords,
|
|
25039
24818
|
isLineRangeCovered,
|
|
25040
24819
|
runTaskStop,
|
|
@@ -25058,6 +24837,12 @@ export {
|
|
|
25058
24837
|
runExecShellGates,
|
|
25059
24838
|
executeLocalToolWithPolicy,
|
|
25060
24839
|
LOCAL_TURN_ABORTED_CODE,
|
|
24840
|
+
isSubtaskRun,
|
|
24841
|
+
RUN_WAKE_CHANNEL_ENV,
|
|
24842
|
+
hasRunWakeChannel,
|
|
24843
|
+
filterToolNamesForRunKind,
|
|
24844
|
+
findSummaryAnchorIndex,
|
|
24845
|
+
validateStoredSummary,
|
|
25061
24846
|
projectContextProvenance,
|
|
25062
24847
|
hashToolDefinitions,
|
|
25063
24848
|
LOCAL_AGENT_CONFIG_MISSING_CODE,
|
|
@@ -25072,7 +24857,6 @@ export {
|
|
|
25072
24857
|
executeOpenAiCompatibleChatCompletion,
|
|
25073
24858
|
describeOpenAiCompatibleRequestBudget,
|
|
25074
24859
|
resolveOpenAiCompatibleProviderConfig,
|
|
25075
|
-
dialogMessageRecordToAgentRuntimeMessage,
|
|
25076
24860
|
buildAgentRuntimeDialogWritePlan,
|
|
25077
24861
|
shouldCacheHybridRemoteRecord,
|
|
25078
24862
|
parseSyncServersEnv,
|