nolo-cli 0.212.0-alpha.1 → 0.219.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -2
- package/{_executeModel-KE6MBNUJ.js → _executeModel-WW57SJN4.js} +111 -82
- package/{accountResolver-4LKIHEKL.js → accountResolver-EK2S4PWF.js} +6 -6
- package/{action-DF5UYSJF.js → action-CK64LS6S.js} +12 -11
- package/{addContentAction-N2YC5IL3.js → addContentAction-EQXMFNPR.js} +18 -17
- package/{addDialogAgentAction-3NKVQCEC.js → addDialogAgentAction-RSDZDASD.js} +21 -20
- package/{agentDeleteCommand-NWK7VU4N.js → agentDeleteCommand-X2VWEKUA.js} +127 -118
- package/{agentEmailCommands-UZ4DHEX2.js → agentEmailCommands-6IE773VW.js} +132 -124
- package/{agentFavoriteCommands-EDK743YA.js → agentFavoriteCommands-2LKGKSUD.js} +7 -8
- package/{agentGrantCommands-RQWK2TEV.js → agentGrantCommands-QQV4N4JW.js} +5 -5
- package/{agentListCommands-HE7L2A6L.js → agentListCommands-5UNM7CGG.js} +196 -124
- package/{agentMachineCommands-6TE4MBMP.js → agentMachineCommands-EVWFKK6Q.js} +62 -53
- package/{agentProviderCommands-Q5O33MED.js → agentProviderCommands-ZCH37KAL.js} +5 -5
- package/{agentPullCommand-6EM3URVK.js → agentPullCommand-XN6ZPBUW.js} +7 -7
- package/agentRecordCommands-DX2WE6BH.js +176 -0
- package/agentRunCommand-KGOT2AFB.js +206 -0
- package/{agentRunControl-OI3LOENH.js → agentRunControl-QDFW5P2T.js} +30 -15
- package/{agentRuntimeLocal-HL526DNQ.js → agentRuntimeLocal-SD7U2EGY.js} +52 -45
- package/{agentSlice-TMYP2UEA.js → agentSlice-ACZGTZVW.js} +20 -19
- package/{appDeleteCommands-ZERW4AXY.js → appDeleteCommands-NE3NQQJL.js} +61 -52
- package/{appDeployCommands-DUWSMYHL.js → appDeployCommands-2BAHY522.js} +61 -52
- package/{appDeployStatusCommands-N2KIE4BF.js → appDeployStatusCommands-JTW6LZNC.js} +61 -52
- package/{appGetCommands-YVR4NPVY.js → appGetCommands-WKFEJO6A.js} +61 -52
- package/{appListCommands-JS6HOHZS.js → appListCommands-HNAZZLFX.js} +61 -52
- package/{authCommand-FE2C3ZUM.js → authCommand-4FDPL7WG.js} +29 -28
- package/{authCommands-HV3EAU3V.js → authCommands-GAJ3NIXO.js} +14 -13
- package/{builtinSkillRegistry-3YOIGEF6.js → builtinSkillRegistry-PXH7EGQB.js} +11 -13
- package/{chromeCommands-REEAH4SX.js → chromeCommands-G5UDKVSV.js} +3 -3
- package/{chromeOpsCommands-HEN5AX2J.js → chromeOpsCommands-YKX2QX3A.js} +20 -10
- package/chunk-2KTUDBG7.js +675 -0
- package/{chunk-TCZHTTUU.js → chunk-2OLYKYNY.js} +8 -8
- package/{chunk-PYRUW7XN.js → chunk-2VUZSVAS.js} +136 -54
- package/chunk-2YGBI2XB.js +30 -0
- package/chunk-2ZKFCIJJ.js +13 -0
- package/{chunk-3FOQHGHN.js → chunk-3ESU44FG.js} +4 -4
- package/{chunk-GNDJKC4B.js → chunk-3N4ASIP6.js} +29 -29
- package/{chunk-4KB6WQUL.js → chunk-4A2JIXR2.js} +1 -1
- package/{chunk-MYOH447Z.js → chunk-4JVNURX4.js} +1 -1
- package/{chunk-IJXYFTV7.js → chunk-4NMHE7CX.js} +20 -20
- package/{chunk-YDH3FDFQ.js → chunk-5FUN7EG4.js} +1 -1
- package/chunk-5OZC7R7Y.js +97 -0
- package/chunk-5R63B62U.js +364 -0
- package/{chunk-LKDF3ATR.js → chunk-5RKUPJYL.js} +1 -1
- package/{chunk-5AQR3DGV.js → chunk-652XYZGP.js} +80 -11
- package/{chunk-6OQUPIQF.js → chunk-65XXHYZ5.js} +4 -4
- package/{chunk-IF45XG7K.js → chunk-6D7NVU66.js} +40 -24
- package/{chunk-DM6UMOEL.js → chunk-6NKA6RKF.js} +2 -2
- package/{chunk-ZC3CMUKU.js → chunk-6OVNSQHN.js} +84 -2
- package/{chunk-H2TJUNCH.js → chunk-6RQFZCKH.js} +18 -18
- package/{chunk-OOF4UPC5.js → chunk-7UH3DGV6.js} +17 -159
- package/{chunk-M6RL5JCD.js → chunk-7WPAI5JJ.js} +14 -14
- package/{chunk-P5L7CXOC.js → chunk-7Z6EW7AH.js} +3 -2
- package/{chunk-3AKFVZ2I.js → chunk-AFHOCBSP.js} +3 -3
- package/{chunk-HPFCI4SK.js → chunk-AK5O76CC.js} +3 -3
- package/{chunk-Y63ZSOR6.js → chunk-AL3TYDIF.js} +1 -1
- package/{chunk-PJNFNEJE.js → chunk-AMEOV5VZ.js} +59 -13
- package/chunk-AVHRSJUH.js +1621 -0
- package/{chunk-IAPCBNEE.js → chunk-BGGHA5DV.js} +1 -1
- package/{chunk-NBTY7YJF.js → chunk-BR3GT6MR.js} +1 -0
- package/{chunk-7RFNTILS.js → chunk-BUDVRYES.js} +2 -2
- package/{chunk-D2MDMY2M.js → chunk-BV3FLP2L.js} +47 -1
- package/{chunk-25JZEIXN.js → chunk-C4VAR65S.js} +92 -150
- package/{chunk-AVTVGMDY.js → chunk-C4WTX5TU.js} +2 -2
- package/{chunk-F6UUQOG6.js → chunk-CKT6QUE2.js} +4 -4
- package/{chunk-6VLJ6YA7.js → chunk-CXDPIPZ4.js} +9 -9
- package/{secretCommands-4QS3HCA2.js → chunk-D726I5AZ.js} +191 -16
- package/{chunk-4KH4J3G5.js → chunk-DJSTBAOU.js} +19 -7
- package/chunk-DVQH4BTR.js +1137 -0
- package/{chunk-7OCO4TDT.js → chunk-EGXPAWLG.js} +1 -1
- package/chunk-EOWLBDY6.js +142 -0
- package/chunk-EUCFKKDM.js +247 -0
- package/chunk-EWQ3HGNZ.js +90 -0
- package/{chunk-NJR3WKVP.js → chunk-F3TQURKK.js} +281 -159
- package/{chunk-GSQNH63I.js → chunk-FIYSMXHY.js} +3 -19
- package/{chunk-KSTEXKL6.js → chunk-FJ23FZXF.js} +76 -31
- package/{chunk-NOMIGOST.js → chunk-FRSBYNWI.js} +116 -124
- package/{chunk-VZKUKCA6.js → chunk-FVZW66K4.js} +3676 -243
- package/{chunk-YUA6OAH5.js → chunk-G2EJ7NL4.js} +2 -2
- package/{chunk-OXME3PEE.js → chunk-GBWGPTA7.js} +2 -1
- package/{chunk-MMNYUVLW.js → chunk-GGKNJ42M.js} +11 -77
- package/{chunk-INSBKSBB.js → chunk-GIABSSWQ.js} +4 -4
- package/{chunk-EZFQ6XRV.js → chunk-GNHMRBYZ.js} +861 -59
- package/{chunk-IIQ6JGRI.js → chunk-GVGOEMNV.js} +2 -2
- package/{chunk-WXYLV624.js → chunk-H7R3365N.js} +4 -4
- package/chunk-HCJFGH6Y.js +1382 -0
- package/{chunk-YUXQAVRD.js → chunk-HOCHUZQ7.js} +257 -90
- package/{chunk-Y2WUYX4I.js → chunk-HXER7YJF.js} +4 -4
- package/{chunk-CTPXME7U.js → chunk-IWH5SOU4.js} +29 -6
- package/{chunk-INN4LTAJ.js → chunk-IWQAOW2X.js} +2 -2
- package/{chunk-RPQXPZZF.js → chunk-J6T25AJ6.js} +908 -13
- package/{chunk-KIM6CLW5.js → chunk-JC5XLWZK.js} +42 -15
- package/chunk-JVRQ6YVK.js +99 -0
- package/{chunk-ZRSNONOB.js → chunk-JWXITTQB.js} +8 -3
- package/{chunk-HIRC32DV.js → chunk-K5FNYHZC.js} +543 -29
- package/{chunk-RU4SD66C.js → chunk-KAVGK4ES.js} +30 -254
- package/{chunk-JNKSDZFS.js → chunk-KEN3N2TN.js} +310 -66
- package/{chunk-LEC5ALIN.js → chunk-KEPOVMF4.js} +1 -1
- package/{chunk-Y6ORVLSS.js → chunk-KN3HEZIQ.js} +1 -1
- package/{chunk-D5RCRX4A.js → chunk-KO63FPG3.js} +9415 -5169
- package/{chunk-OHNELDTO.js → chunk-KOXKKHFE.js} +11 -152
- package/{chunk-4VJAC32I.js → chunk-L5I543VB.js} +3 -2
- package/{chunk-SM3NSZJV.js → chunk-LE6LGAJE.js} +20 -1
- package/chunk-LKA64WH4.js +227 -0
- package/{chunk-VL5KOY2C.js → chunk-MK2Q7ZJD.js} +67 -5
- package/{chunk-22CIEBYO.js → chunk-MKQ2UTTX.js} +50 -48
- package/chunk-MOMR7NMG.js +226 -0
- package/{chunk-PDGKOTO7.js → chunk-N3J4VDGV.js} +33 -22
- package/{chunk-AZMYUSVF.js → chunk-N5Z2V73W.js} +1 -1
- package/{chunk-5RYBGBQH.js → chunk-N7HVLYOY.js} +14 -9
- package/{chunk-GPO7FCEZ.js → chunk-O2CYENYJ.js} +1331 -1725
- package/{chunk-3RQVYR4B.js → chunk-OB6DVWPF.js} +197 -65
- package/{chunk-HRMJUN5J.js → chunk-OGHP3CTL.js} +1 -1
- package/{chunk-XJWWBO34.js → chunk-OJKUU3LP.js} +5 -7
- package/{chunk-G7MLNNEX.js → chunk-OOF7XDZF.js} +5 -5
- package/{chunk-CJRONOYL.js → chunk-OXKUPBAQ.js} +19 -75
- package/{chunk-6XIE5ZGI.js → chunk-PDCV7P5W.js} +1 -1
- package/{chunk-UTV2AYEG.js → chunk-PFJNLBRU.js} +2 -2
- package/{chunk-CKAHAVMK.js → chunk-PPJYZRSQ.js} +40 -26
- package/chunk-PVZY6P3S.js +271 -0
- package/{chunk-ZL5RAEEB.js → chunk-Q6HOUF4O.js} +1 -1
- package/{chunk-QT6PKHYJ.js → chunk-Q7WP5RPC.js} +5 -5
- package/chunk-QHEN7NZ7.js +46 -0
- package/{chunk-JIT6FSXJ.js → chunk-QLFCTYRH.js} +3 -3
- package/{chunk-YGILMZ7N.js → chunk-QVBXJNZ2.js} +1 -1
- package/{chunk-YPD3VJZW.js → chunk-QWYFFHCJ.js} +20 -20
- package/{chunk-C6KNNXWU.js → chunk-RGQ4UUWZ.js} +25 -2
- package/{chunk-OWYYDMGJ.js → chunk-S2NTVGA2.js} +4 -2
- package/{chunk-YJMRHHGY.js → chunk-S7SB7L2I.js} +60 -30
- package/{chunk-W4S457LU.js → chunk-SASHAZ67.js} +41 -5
- package/{chunk-KC4XDTT3.js → chunk-SOF4OWDM.js} +6 -4
- package/{chunk-YWSEPJ7C.js → chunk-SRL56PI2.js} +3 -3
- package/{chunk-6NSSLV67.js → chunk-SYQR7FQS.js} +52 -50
- package/{chunk-JY5NGFFH.js → chunk-SYTHYBMI.js} +5 -5
- package/{chunk-CQ46IRNN.js → chunk-T3O6BLYU.js} +447 -203
- package/chunk-TLE77UJ5.js +230 -0
- package/{chunk-T43B7LB2.js → chunk-TRWT3EE3.js} +1 -1
- package/{chunk-FHU44LN3.js → chunk-TVFRV3UQ.js} +2179 -552
- package/{chunk-4VNS5WPM.js → chunk-U67V476Y.js} +1 -8
- package/{chunk-F7CI2ZC5.js → chunk-UAIHKQIA.js} +2 -1
- package/{chunk-LOEO7LRC.js → chunk-UJKTI5PG.js} +10 -7
- package/{chunk-UHJGXRJ4.js → chunk-UMRI2IRY.js} +3 -3
- package/{chunk-WPORQFYN.js → chunk-UVLYNWIE.js} +2 -2
- package/{chunk-YOIW77S2.js → chunk-UYOICCYG.js} +29 -19
- package/{chunk-GOO6G4PY.js → chunk-VALBGPM6.js} +106 -50
- package/{chunk-B7NJ3T4A.js → chunk-VHPAA6MT.js} +10 -10
- package/{chunk-4I7ERB7F.js → chunk-VREDDN25.js} +1 -1
- package/{chunk-SOHTHFV2.js → chunk-XFJ4ZPFC.js} +91 -132
- package/{chunk-TY3TIUJK.js → chunk-XI2BWJM5.js} +65 -0
- package/chunk-XWGDCWXY.js +526 -0
- package/{chunk-J5JTMQIA.js → chunk-YFLVRVYK.js} +1 -1
- package/{chunk-EYLGAEB4.js → chunk-YGMBIXCF.js} +132 -0
- package/chunk-YL3EFYL3.js +199 -0
- package/{chunk-MMA3LZ3W.js → chunk-YNIYE47Z.js} +1 -1
- package/chunk-YZMNK53S.js +68 -0
- package/{chunk-FY7F4Q6X.js → chunk-Z4PCXPUE.js} +2 -2
- package/{cliAgentConfigHelpers-WJBZQTLW.js → cliAgentConfigHelpers-PO3MVDME.js} +15 -16
- package/{cliAuthorityBrokerClient-PM3U6Q6J.js → cliAuthorityBrokerClient-XHH7MH2P.js} +1 -1
- package/{cliAuthorityStoreDriver-TKLXNNTG.js → cliAuthorityStoreDriver-6FE3BJNB.js} +1 -1
- package/{cliEnvHelpers-BVYTMUPJ.js → cliEnvHelpers-VPSJ4XWC.js} +3 -3
- package/{cliExecutor-BWBF2MTI.js → cliExecutor-4MAX3PZL.js} +2 -2
- package/cliLocalAgentRecordReader-Z7CH4K4R.js +90 -0
- package/{commandRegistry-VVMTPFAX.js → commandRegistry-SDSYBKMC.js} +106 -98
- package/{contentThunks-N52O67MI.js → contentThunks-G3TRPEAU.js} +47 -43
- package/{cooldownCommands-YXLWOXWR.js → cooldownCommands-X7P5M2V5.js} +5 -4
- package/{createAgentAutomationAction-ZC57YRSV.js → createAgentAutomationAction-KHA4MXUJ.js} +51 -49
- package/{createDialogAction-VQW5WDYX.js → createDialogAction-KWSBNAPJ.js} +46 -48
- package/{createPageAction-M5VDA7SC.js → createPageAction-HXKJ7OFG.js} +50 -48
- package/{cursorProvider-YGGNMVWX.js → cursorProvider-2RACMEMF.js} +1 -1
- package/{db-HUCI5R4G.js → db-CS4ZJQKV.js} +1 -1
- package/{dbSlice-HP7G4LX3.js → dbSlice-ZJPDIFER.js} +17 -16
- package/{deleteFile-7VQGLK2V.js → deleteFile-Q3YDB4ML.js} +9 -9
- package/{desktopFolderProjects-SFY5EZS3.js → desktopFolderProjects-4POAMVJN.js} +2 -2
- package/{dialogCommands-JHMR2N2Y.js → dialogCommands-6KQEBHSG.js} +64 -57
- package/dialogNotifyCommand-WIZFFEY3.js +36 -0
- package/{dialogSlice-GRSVGDTF.js → dialogSlice-HXPKFGRL.js} +42 -40
- package/{dialogUsageCommand-7KCPYGHG.js → dialogUsageCommand-HTVPR2CX.js} +11 -10
- package/{docCreateCommands-F2K3UPSQ.js → docCreateCommands-XZOLWBRC.js} +61 -54
- package/{docDeleteCommands-XGXB5RFT.js → docDeleteCommands-ZSO4LGWE.js} +63 -57
- package/{docReadCommands-7HWZZV6J.js → docReadCommands-TTMXCDER.js} +61 -54
- package/{docStore-KNZK6Y2G.js → docStore-A2B3GH33.js} +21 -20
- package/{docUpdateCommands-OZZ7NQII.js → docUpdateCommands-PRG6WOXL.js} +64 -57
- package/{fetchMessages-M3QU7ZCQ.js → fetchMessages-TQEUZD7H.js} +8 -7
- package/{getPricing-2MNMXEVG.js → getPricing-YH3VMSVU.js} +6 -6
- package/{handleSendMessageAction-SHIH74GJ.js → handleSendMessageAction-NWYG3Q72.js} +193 -301
- package/{hostCredentialCreate-X64WK4JD.js → hostCredentialCreate-WS6D3EHT.js} +123 -114
- package/index.js +29 -29
- package/{keys-BEGDOTRL.js → keys-RWF7UCB4.js} +5 -4
- package/legacyMigration-TF4SYJCZ.js +19 -0
- package/{lib-5KKIBFIT.js → lib-OT5OTXRU.js} +7087 -6664
- package/{localDialogRead-XRLAH4CZ.js → localDialogRead-SVTPA5GY.js} +3 -3
- package/{localFirstLog-DHNOY2NA.js → localFirstLog-OIETGK66.js} +1 -1
- package/localRecall-2J6QPOK2.js +15 -0
- package/{localRuntimeAdapter-A7K3ABA6.js → localRuntimeAdapter-TFYOA6YE.js} +119 -110
- package/{localRuntimeAuthority-OYH4AE4G.js → localRuntimeAuthority-IBJAT62G.js} +1 -1
- package/{localRuntimeDb-VBIMCWUC.js → localRuntimeDb-N7KHDXS2.js} +2 -2
- package/{machineCommands-DE3MR7CJ.js → machineCommands-WFWV25IR.js} +128 -119
- package/{machineInfo-UKPTZO5Y.js → machineInfo-LWHTEBHJ.js} +1 -1
- package/machineWsRunDispatch-ZGXC3F2R.js +191 -0
- package/{memberThunks-7WJAY5V6.js → memberThunks-JRYNONYV.js} +29 -28
- package/{memoryCommands-ASCE5STX.js → memoryCommands-5WC3T66U.js} +4 -4
- package/models-CXINDUJA.js +9 -0
- package/{oauthTokenStore-OEERZFUC.js → oauthTokenStore-RUYNYALS.js} +1 -1
- package/{offlineMarxistsAgentCommand-2QTHJCHV.js → offlineMarxistsAgentCommand-4IC3Y4C6.js} +4 -4
- package/overlay-THLKYIWY.js +11 -0
- package/package.json +2 -2
- package/{pdf-U6KSUEZZ.js → pdf-KE3QI2V7.js} +1 -1
- package/{processSpawn-ZU5QFM43.js → processSpawn-6GEO77KV.js} +1 -1
- package/{profileConfig-KN3N2BLF.js → profileConfig-KOWK4HOG.js} +1 -1
- package/{projectArchive-GGL5HLMD.js → projectArchive-ULJDLUA6.js} +52 -50
- package/{providerPresetApply-YXGV6NXB.js → providerPresetApply-SHT2SUVB.js} +19 -12
- package/{providerRegistry-S6UL6UNA.js → providerRegistry-TA7EGCVZ.js} +10 -10
- package/{read-4VZQODSN.js → read-Q7GOHGNP.js} +10 -10
- package/{readDocTool-AVD32RUJ.js → readDocTool-Z5OQ6422.js} +2 -2
- package/{readlineWorkspace-XKYKNL2I.js → readlineWorkspace-LTCV2BFW.js} +6505 -4634
- package/{removeDialogAgentAction-FKL4BYMR.js → removeDialogAgentAction-U3F2MNAY.js} +23 -22
- package/{runAgentClientLoop-V7E2WBVM.js → runAgentClientLoop-BVIEQUB3.js} +81 -79
- package/{runtimeDoctorCommands-QAI3MBKQ.js → runtimeDoctorCommands-I47JN4HS.js} +12 -12
- package/{runtimeModeArgs-2Y7BALTO.js → runtimeModeArgs-X7DL7PUN.js} +1 -1
- package/secretCommands-LJXOOYA7.js +24 -0
- package/{setDialogExtraReferencesAction-TLIOLWWI.js → setDialogExtraReferencesAction-G3WSJ7EM.js} +22 -21
- package/{setPrimaryDialogAgentAction-2OLWRFYR.js → setPrimaryDialogAgentAction-6FHAHZBB.js} +23 -22
- package/{settingThunks-UGBPCNYF.js → settingThunks-AXTBX3Q5.js} +97 -88
- package/{skillDiscovery-XKHROSH2.js → skillDiscovery-B5V23AXP.js} +4 -4
- package/{skillSummaryMarker-42HKSXYY.js → skillSummaryMarker-62UW7HI7.js} +1 -1
- package/{slateToRenderMarkdown-Y5IYN73U.js → slateToRenderMarkdown-R3X74MCX.js} +1 -1
- package/{slateUtils-NGV2NMKM.js → slateUtils-ESQAJ6RN.js} +1 -1
- package/{spaceCommands-4KSLKVNF.js → spaceCommands-IB6FKWIC.js} +61 -53
- package/store-JRVN62NM.js +46 -0
- package/{streamAgentChatTurn-7FR7X2NU.js → streamAgentChatTurn-DNYFHBJM.js} +875 -618
- package/{switchDialogAgentAction-UZSAG2N5.js → switchDialogAgentAction-UOFIAGPL.js} +21 -20
- package/{tableCommands-MP6VFSVT.js → tableCommands-HITDSLHS.js} +10 -10
- package/tombstones-FQQMEDOW.js +32 -0
- package/{toolApiClient-HGNO53TC.js → toolApiClient-OGQEBQVX.js} +4 -4
- package/{tools-ZLKCC25W.js → tools-JVOJ5HC4.js} +75 -74
- package/tuiSummaryLlmCaller-7LWYTHLM.js +44 -0
- package/{updateCommands-4744PL3P.js → updateCommands-RJVCRSBP.js} +10 -8
- package/{updateDialogTitleAction-U53ZT7PJ.js → updateDialogTitleAction-Q57BOSXG.js} +48 -46
- package/{usageCommand-F4IPVMIZ.js → usageCommand-RVKHEPLU.js} +11 -10
- package/{usageRebuildCommand-HAW2AD5N.js → usageRebuildCommand-GRAFOZF2.js} +12 -11
- package/userDataMerge-HT2ZVHBJ.js +13 -0
- package/{windowsSelfUpdate-XSQVF2GK.js → windowsSelfUpdate-KERHIAB4.js} +3 -3
- package/{workloadLifecycle-4BEQHMSD.js → workloadLifecycle-O2I3NZ2Q.js} +7 -6
- package/agentRecordCommands-L3QQ7HZ4.js +0 -167
- package/agentRunCommand-2IFGQHCO.js +0 -196
- package/chunk-3CGG2PAL.js +0 -594
- package/chunk-5XBUWM6I.js +0 -89
- package/chunk-BFM34N54.js +0 -842
- package/chunk-CJEIOP3E.js +0 -0
- package/chunk-CZM5YTZ7.js +0 -977
- package/chunk-EYUBHHFB.js +0 -636
- package/chunk-JTDORD5P.js +0 -415
- package/chunk-NRFKLKRU.js +0 -339
- package/chunk-VPAZOH2D.js +0 -115
- package/chunk-WJZOQR2J.js +0 -151
- package/chunk-ZCWRMUWT.js +0 -89
- package/dist-M676ULYG.js +0 -7314
- package/machineWsRunDispatch-R26P5V36.js +0 -182
- package/models-PJBE6JDV.js +0 -9
- package/tuiSummaryLlmCaller-WC54MVGP.js +0 -160
- package/{chunk-WACI5I6V.js → chunk-2THCNKE4.js} +3 -3
- package/{chunk-2QHFH3DR.js → chunk-47ITIXO7.js} +6 -6
- package/{chunk-OQHIVPG4.js → chunk-SNBZZPYH.js} +3 -3
- package/{chunk-AETZ7AD6.js → chunk-W6RFEDN4.js} +3 -3
|
@@ -1,21 +1,71 @@
|
|
|
1
|
-
import {
|
|
2
|
-
findPotentialSecrets
|
|
3
|
-
} from "./chunk-6QDYSCPW.js";
|
|
4
1
|
import {
|
|
5
2
|
parsePositiveFiniteNumberOrFallback
|
|
6
3
|
} from "./chunk-Y5GCAMGP.js";
|
|
7
4
|
import {
|
|
5
|
+
getReadableCliDb
|
|
6
|
+
} from "./chunk-YFLVRVYK.js";
|
|
7
|
+
import {
|
|
8
|
+
INSTABOX_RUN_CONFIG_ENV,
|
|
9
|
+
attachLocalCommandObservations,
|
|
8
10
|
buildLocalRunEnv,
|
|
11
|
+
captureLocalRunBase,
|
|
12
|
+
collectHostTaskPlannedWorkspace,
|
|
13
|
+
collectHostTaskWorkspace,
|
|
14
|
+
createCliLocalRuntimeAdapter,
|
|
15
|
+
createHostAuthorExecution,
|
|
16
|
+
detectCurrentMachineId,
|
|
17
|
+
formatLocalRunSummary,
|
|
18
|
+
getOrCreateSharedStore,
|
|
19
|
+
hashInstaboxDeliveryManifest,
|
|
20
|
+
hostTaskEventsRoot,
|
|
21
|
+
inspectLocalRunWorkspace,
|
|
22
|
+
isCliProviderAgentConfig,
|
|
23
|
+
isDockerRuntimeKey,
|
|
9
24
|
isFullstackCodingAgentRef,
|
|
25
|
+
isInstaboxBillingPolicy,
|
|
26
|
+
isLiveAgentRunObservation,
|
|
27
|
+
isMachineBoundLocalhostCustomProvider,
|
|
28
|
+
isSubtaskRun,
|
|
29
|
+
matchesHostReviewDispatch,
|
|
30
|
+
observeLocalCommandResult,
|
|
10
31
|
parseAgentRunArgs,
|
|
32
|
+
parseAgentRunEvent,
|
|
11
33
|
readFlagValue,
|
|
34
|
+
readHostTask,
|
|
35
|
+
readHostTaskAcceptancePlan,
|
|
36
|
+
redactSecrets,
|
|
37
|
+
resolveAuthToken as resolveAuthToken2,
|
|
38
|
+
resolveBoundMachineId,
|
|
39
|
+
resolveFileWriteGateEnabled,
|
|
12
40
|
resolveRawAgentInput,
|
|
13
41
|
resolveServerUrl,
|
|
42
|
+
safeAskText,
|
|
43
|
+
settleHostReviewsForScope,
|
|
44
|
+
shouldPrintLocalRunSummary,
|
|
45
|
+
unknownLocalRunAcceptance,
|
|
46
|
+
unknownTaskCompletion,
|
|
47
|
+
validateInstaboxWorkspaceSelection,
|
|
48
|
+
withHostReviewDispatch,
|
|
49
|
+
withholdIfSecretLike,
|
|
50
|
+
wrapLocalCommandWorkspaceObservation,
|
|
14
51
|
writeUsage
|
|
15
|
-
} from "./chunk-
|
|
52
|
+
} from "./chunk-KO63FPG3.js";
|
|
16
53
|
import {
|
|
17
|
-
|
|
18
|
-
|
|
54
|
+
clearCredentialAvailability,
|
|
55
|
+
readEffectiveCredentialEntry
|
|
56
|
+
} from "./chunk-FIYSMXHY.js";
|
|
57
|
+
import {
|
|
58
|
+
readDbRecord,
|
|
59
|
+
resolveAgentRecordFromHybridStore
|
|
60
|
+
} from "./chunk-6D7NVU66.js";
|
|
61
|
+
import {
|
|
62
|
+
boxGlyphs,
|
|
63
|
+
displayWidth,
|
|
64
|
+
resolveBoxCharset,
|
|
65
|
+
stripAnsi,
|
|
66
|
+
tokenizeAnsiLine,
|
|
67
|
+
visibleWidth
|
|
68
|
+
} from "./chunk-J6T25AJ6.js";
|
|
19
69
|
import {
|
|
20
70
|
_appendEntityBatch,
|
|
21
71
|
_appendEvidenceBatch,
|
|
@@ -29,59 +79,43 @@ import {
|
|
|
29
79
|
listMemoryStatesForEntityVNext,
|
|
30
80
|
loadMemoryVNextCatalog,
|
|
31
81
|
putMemoryEvidenceVNext
|
|
32
|
-
} from "./chunk-
|
|
82
|
+
} from "./chunk-XI2BWJM5.js";
|
|
33
83
|
import {
|
|
34
|
-
|
|
35
|
-
|
|
84
|
+
rankMemoryCandidates,
|
|
85
|
+
recallMemoryVNextLocal
|
|
86
|
+
} from "./chunk-YL3EFYL3.js";
|
|
36
87
|
import {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
isCliProviderAgentConfig,
|
|
42
|
-
isDockerRuntimeKey,
|
|
43
|
-
isInstaboxBillingPolicy,
|
|
44
|
-
isLiveAgentRunObservation,
|
|
45
|
-
isMachineBoundLocalhostCustomProvider,
|
|
46
|
-
isSubtaskRun,
|
|
47
|
-
parseAgentRunEvent,
|
|
48
|
-
resolveAuthToken as resolveAuthToken2,
|
|
49
|
-
resolveBoundMachineId,
|
|
50
|
-
resolveFileWriteGateEnabled,
|
|
51
|
-
validateInstaboxWorkspaceSelection
|
|
52
|
-
} from "./chunk-D5RCRX4A.js";
|
|
88
|
+
DEFAULT_MEMORY_OVERLAY_TOKEN_BUDGET,
|
|
89
|
+
EXPLICIT_REMEMBER_PREFIX_REGEX,
|
|
90
|
+
buildMemoryOverlay
|
|
91
|
+
} from "./chunk-EUCFKKDM.js";
|
|
53
92
|
import {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
} from "./chunk-GSQNH63I.js";
|
|
58
|
-
import {
|
|
59
|
-
readDbRecord,
|
|
60
|
-
resolveAgentRecordFromHybridStore
|
|
61
|
-
} from "./chunk-IF45XG7K.js";
|
|
93
|
+
buildLegacyMemoryEvidence,
|
|
94
|
+
resolveLegacyMemoryPrincipal
|
|
95
|
+
} from "./chunk-QHEN7NZ7.js";
|
|
62
96
|
import {
|
|
63
97
|
isBuiltinNoloAgentRef,
|
|
64
98
|
resolveLocalUserId
|
|
65
|
-
} from "./chunk-
|
|
66
|
-
import {
|
|
67
|
-
isLocalCliAgentKey
|
|
68
|
-
} from "./chunk-NBTY7YJF.js";
|
|
99
|
+
} from "./chunk-OOF7XDZF.js";
|
|
69
100
|
import {
|
|
70
101
|
CliProviderQuotaError
|
|
71
|
-
} from "./chunk-
|
|
102
|
+
} from "./chunk-MK2Q7ZJD.js";
|
|
103
|
+
import {
|
|
104
|
+
resolveMachineId
|
|
105
|
+
} from "./chunk-S73EPYNC.js";
|
|
106
|
+
import {
|
|
107
|
+
extractGoogleValidationLink
|
|
108
|
+
} from "./chunk-BMQ2MJUK.js";
|
|
72
109
|
import {
|
|
73
110
|
resolveCliLocalRuntimeKeyCapability
|
|
74
|
-
} from "./chunk-
|
|
111
|
+
} from "./chunk-T3O6BLYU.js";
|
|
75
112
|
import {
|
|
76
113
|
isTransientFetchError
|
|
77
114
|
} from "./chunk-KFHREHUQ.js";
|
|
78
|
-
import {
|
|
79
|
-
extractGoogleValidationLink
|
|
80
|
-
} from "./chunk-BMQ2MJUK.js";
|
|
81
115
|
import {
|
|
82
116
|
parseUiCard,
|
|
83
117
|
uiCardFallback
|
|
84
|
-
} from "./chunk-
|
|
118
|
+
} from "./chunk-3N4ASIP6.js";
|
|
85
119
|
import {
|
|
86
120
|
isGatewayHttpStatus
|
|
87
121
|
} from "./chunk-NF64D32W.js";
|
|
@@ -89,16 +123,19 @@ import {
|
|
|
89
123
|
buildMemorySubjectsForAgent,
|
|
90
124
|
chooseMemoryOwners,
|
|
91
125
|
loadMemoryCandidatesFromDb,
|
|
126
|
+
loadOwnerItemsFromDb,
|
|
92
127
|
resolveAgentMemoryPolicy
|
|
93
|
-
} from "./chunk-
|
|
128
|
+
} from "./chunk-7UH3DGV6.js";
|
|
94
129
|
import {
|
|
95
130
|
API_REPORTED_COST_MULTIPLIER,
|
|
96
131
|
estimateMessagesTokens,
|
|
132
|
+
isAgentRunStartFailureStatus,
|
|
133
|
+
isAgentRunStatusNormal,
|
|
97
134
|
parseUiAskChoiceContent,
|
|
98
135
|
resolveAgentContextWindow,
|
|
99
136
|
resolveOccupancy,
|
|
100
137
|
resolveOccupancyWindow
|
|
101
|
-
} from "./chunk-
|
|
138
|
+
} from "./chunk-FVZW66K4.js";
|
|
102
139
|
import {
|
|
103
140
|
isCliAuthorityBrokerProtocolError,
|
|
104
141
|
isCliAuthorityBrokerTimeoutError,
|
|
@@ -106,48 +143,43 @@ import {
|
|
|
106
143
|
} from "./chunk-5ZMIIR23.js";
|
|
107
144
|
import {
|
|
108
145
|
getDefaultCliLocalRuntimeDb
|
|
109
|
-
} from "./chunk-
|
|
146
|
+
} from "./chunk-N5Z2V73W.js";
|
|
110
147
|
import {
|
|
111
|
-
|
|
112
|
-
} from "./chunk-
|
|
113
|
-
import {
|
|
114
|
-
parseExternalSkillMarkdown,
|
|
115
|
-
parseSkillDocProtocol
|
|
116
|
-
} from "./chunk-AETZ7AD6.js";
|
|
148
|
+
isLocalCliAgentKey
|
|
149
|
+
} from "./chunk-BR3GT6MR.js";
|
|
117
150
|
import {
|
|
118
151
|
LOCAL_AGENT_CONFIG_MISSING_CODE,
|
|
119
152
|
LOCAL_TURN_ABORTED_CODE,
|
|
153
|
+
evaluateTaskExecutionContract,
|
|
154
|
+
markCliUserBatchPhase,
|
|
120
155
|
readActionGate
|
|
121
|
-
} from "./chunk-
|
|
156
|
+
} from "./chunk-TVFRV3UQ.js";
|
|
122
157
|
import {
|
|
123
158
|
resolveAgentRuntimeConfigFromRecord
|
|
124
|
-
} from "./chunk-
|
|
159
|
+
} from "./chunk-SASHAZ67.js";
|
|
125
160
|
import {
|
|
126
161
|
createThinkParserState,
|
|
127
162
|
flushThinkParser,
|
|
128
163
|
processThinkChunk
|
|
129
164
|
} from "./chunk-56GBUMO5.js";
|
|
130
165
|
import {
|
|
131
|
-
PROBE_INTERVAL_MS,
|
|
132
|
-
QUOTA_ERROR_PATTERNS,
|
|
133
166
|
classifyFailureSubclass,
|
|
134
167
|
isCapacitySaturatedRateLimit,
|
|
135
|
-
isQuotaExhaustedError,
|
|
136
168
|
isQuotaExhaustedText,
|
|
137
|
-
|
|
138
|
-
resolveCooldownGate,
|
|
169
|
+
resolveAvailabilityAction,
|
|
139
170
|
resolveCredentialKeyWithFallback
|
|
140
|
-
} from "./chunk-
|
|
171
|
+
} from "./chunk-HOCHUZQ7.js";
|
|
141
172
|
import {
|
|
142
173
|
ATTACHMENT_PART_TYPE,
|
|
143
174
|
ATTACHMENT_PART_VERSION,
|
|
144
175
|
describeAttachmentForModel,
|
|
145
176
|
normalizeAttachmentPart
|
|
146
|
-
} from "./chunk-
|
|
177
|
+
} from "./chunk-XWGDCWXY.js";
|
|
147
178
|
import {
|
|
179
|
+
findCodexOAuthPinnedContextWindow,
|
|
148
180
|
normalizeUsage,
|
|
149
181
|
readCacheReadInputTokensOrNull
|
|
150
|
-
} from "./chunk-
|
|
182
|
+
} from "./chunk-HCJFGH6Y.js";
|
|
151
183
|
import {
|
|
152
184
|
isOAuthApiKeyRef
|
|
153
185
|
} from "./chunk-UKZX3NHN.js";
|
|
@@ -157,37 +189,65 @@ import {
|
|
|
157
189
|
import {
|
|
158
190
|
normalizeRuntimeToolPolicyOverride,
|
|
159
191
|
resolveEffectiveRuntimeToolPolicy
|
|
160
|
-
} from "./chunk-
|
|
192
|
+
} from "./chunk-47ITIXO7.js";
|
|
161
193
|
import {
|
|
162
194
|
compactWhitespace
|
|
163
195
|
} from "./chunk-DWLEOOGR.js";
|
|
164
196
|
import {
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
} from "./chunk-ZRSNONOB.js";
|
|
197
|
+
isAntigravityOAuthAgent
|
|
198
|
+
} from "./chunk-JC5XLWZK.js";
|
|
199
|
+
import {
|
|
200
|
+
parseExternalSkillMarkdown,
|
|
201
|
+
parseSkillDocProtocol
|
|
202
|
+
} from "./chunk-W6RFEDN4.js";
|
|
172
203
|
import {
|
|
173
204
|
BUILTIN_NOLO_AGENT_KEY,
|
|
174
205
|
BUILTIN_NOLO_AGENT_NAME,
|
|
175
206
|
builtinAgentCatalogEntryById,
|
|
176
207
|
parseBuiltinPlatformAgentId
|
|
177
|
-
} from "./chunk-
|
|
208
|
+
} from "./chunk-UJKTI5PG.js";
|
|
178
209
|
import {
|
|
179
210
|
parsePublicAgentId
|
|
180
211
|
} from "./chunk-M2EJHDJP.js";
|
|
181
212
|
import {
|
|
182
|
-
|
|
183
|
-
} from "./chunk-
|
|
213
|
+
createMemoryKey
|
|
214
|
+
} from "./chunk-SYTHYBMI.js";
|
|
215
|
+
import {
|
|
216
|
+
ulid
|
|
217
|
+
} from "./chunk-OJKUU3LP.js";
|
|
184
218
|
import {
|
|
219
|
+
buildSkillDiscoveryContextLayer
|
|
220
|
+
} from "./chunk-CKT6QUE2.js";
|
|
221
|
+
import {
|
|
222
|
+
buildAgentsMdLayer,
|
|
223
|
+
buildAgentsMdLayerHeader,
|
|
224
|
+
buildMemoryOverlayLayer,
|
|
225
|
+
buildMemoryUseGuidanceLayer,
|
|
226
|
+
partitionScopedBlocks,
|
|
227
|
+
renderTurnContextBlocksWithScope
|
|
228
|
+
} from "./chunk-JWXITTQB.js";
|
|
229
|
+
import {
|
|
230
|
+
exitCliFromWatchdog,
|
|
231
|
+
getLogger,
|
|
232
|
+
normalizeError
|
|
233
|
+
} from "./chunk-YGMBIXCF.js";
|
|
234
|
+
import {
|
|
235
|
+
agentRunCardLabels,
|
|
236
|
+
getCliLocale,
|
|
237
|
+
t,
|
|
238
|
+
toolLabel,
|
|
239
|
+
toolLabelVariants
|
|
240
|
+
} from "./chunk-OB6DVWPF.js";
|
|
241
|
+
import {
|
|
242
|
+
awaitLocalWriterChild,
|
|
185
243
|
createRunActivityTracker,
|
|
186
244
|
createShellApprovalChild,
|
|
187
245
|
getRunResultHeaderMeta,
|
|
246
|
+
isHistoryIntegrityFailure,
|
|
188
247
|
popSingleQueueMessage,
|
|
189
248
|
readRunRecord,
|
|
190
249
|
recordRunResultHeaderMeta,
|
|
250
|
+
registerLocalForegroundWriter,
|
|
191
251
|
reportRunProcessIdentity,
|
|
192
252
|
resolveResultServerMeta,
|
|
193
253
|
resolveRunQueuePath,
|
|
@@ -195,65 +255,52 @@ import {
|
|
|
195
255
|
serverOriginForDialog,
|
|
196
256
|
settleRunTerminalAuthoritatively,
|
|
197
257
|
spawnLocalBackgroundRun
|
|
198
|
-
} from "./chunk-
|
|
258
|
+
} from "./chunk-K5FNYHZC.js";
|
|
199
259
|
import {
|
|
200
260
|
formatAgentListCard,
|
|
201
261
|
formatFinishedRunCard,
|
|
262
|
+
formatIdentityRow,
|
|
202
263
|
formatListRunsCard,
|
|
203
264
|
formatNotFoundRunCard,
|
|
204
|
-
formatStartRunCard,
|
|
205
265
|
formatStatusRunCard,
|
|
206
266
|
formatStopRunCard,
|
|
267
|
+
getAgentRunStatusIcon,
|
|
207
268
|
isAgentRunTerminalStatus
|
|
208
|
-
} from "./chunk-
|
|
269
|
+
} from "./chunk-AMEOV5VZ.js";
|
|
209
270
|
import {
|
|
210
|
-
|
|
211
|
-
|
|
271
|
+
QUOTA_ERROR_PATTERNS,
|
|
272
|
+
isQuotaExhaustedError
|
|
273
|
+
} from "./chunk-EWQ3HGNZ.js";
|
|
212
274
|
import {
|
|
213
|
-
|
|
214
|
-
} from "./chunk-
|
|
275
|
+
resolveClientVersion
|
|
276
|
+
} from "./chunk-2OLYKYNY.js";
|
|
215
277
|
import {
|
|
216
278
|
toErrorMessage
|
|
217
279
|
} from "./chunk-HNMXYYJR.js";
|
|
280
|
+
import {
|
|
281
|
+
asTrimmedString
|
|
282
|
+
} from "./chunk-3EUW3WEO.js";
|
|
283
|
+
import {
|
|
284
|
+
findModelConfig
|
|
285
|
+
} from "./chunk-LE6LGAJE.js";
|
|
218
286
|
import {
|
|
219
287
|
CLIENT_VERSION_TOO_OLD_CODE,
|
|
220
288
|
NOLO_CLIENT_VERSION_HEADER,
|
|
221
289
|
buildClientVersionUpgradeMessage
|
|
222
|
-
} from "./chunk-
|
|
290
|
+
} from "./chunk-VALBGPM6.js";
|
|
223
291
|
import {
|
|
224
292
|
asTrimmedLowercaseString
|
|
225
293
|
} from "./chunk-QSJ3HFEF.js";
|
|
226
|
-
import {
|
|
227
|
-
getLogger,
|
|
228
|
-
normalizeError
|
|
229
|
-
} from "./chunk-EYLGAEB4.js";
|
|
230
294
|
import {
|
|
231
295
|
resolveAuthToken
|
|
232
|
-
} from "./chunk-
|
|
233
|
-
import {
|
|
234
|
-
readPipeText,
|
|
235
|
-
spawnProcess
|
|
236
|
-
} from "./chunk-4O22PGNQ.js";
|
|
237
|
-
import {
|
|
238
|
-
agentRunCardLabels,
|
|
239
|
-
getCliLocale,
|
|
240
|
-
t,
|
|
241
|
-
toolLabel,
|
|
242
|
-
toolLabelVariants
|
|
243
|
-
} from "./chunk-3RQVYR4B.js";
|
|
244
|
-
import {
|
|
245
|
-
createMemoryKey
|
|
246
|
-
} from "./chunk-JY5NGFFH.js";
|
|
247
|
-
import {
|
|
248
|
-
ulid
|
|
249
|
-
} from "./chunk-XJWWBO34.js";
|
|
250
|
-
import {
|
|
251
|
-
asTrimmedString
|
|
252
|
-
} from "./chunk-3EUW3WEO.js";
|
|
296
|
+
} from "./chunk-2THCNKE4.js";
|
|
253
297
|
import {
|
|
254
298
|
asOptionalTrimmedString
|
|
255
299
|
} from "./chunk-G3SUCT4W.js";
|
|
256
300
|
|
|
301
|
+
// packages/cli/agentRunCommand.ts
|
|
302
|
+
import { createHash } from "node:crypto";
|
|
303
|
+
|
|
257
304
|
// packages/cli/client/instaboxRunConfigWrite.ts
|
|
258
305
|
import { randomUUID } from "node:crypto";
|
|
259
306
|
import { lstatSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
@@ -396,6 +443,151 @@ function writeInstaboxRunConfig(options) {
|
|
|
396
443
|
return { configPath: targetPath, config };
|
|
397
444
|
}
|
|
398
445
|
|
|
446
|
+
// packages/cli/client/contextRefusal.ts
|
|
447
|
+
function contextRefusalDiagnostics(error) {
|
|
448
|
+
return error && typeof error === "object" ? error.diagnostics : void 0;
|
|
449
|
+
}
|
|
450
|
+
var tokens = (value) => value >= 1e3 ? `${Math.round(value / 100) / 10}k` : String(value);
|
|
451
|
+
function describeContextRefusal(refusal) {
|
|
452
|
+
const budgetDetail = refusal && Number.isFinite(refusal.historyTokens) && refusal.historyTokens >= 0 && Number.isFinite(refusal.budget) && refusal.budget > 0 ? t("contextRefusalBudgetDetail", tokens(refusal.historyTokens), tokens(refusal.budget)) : "";
|
|
453
|
+
switch (refusal?.reason) {
|
|
454
|
+
case "summary-provider-busy":
|
|
455
|
+
return t("contextRefusalSummaryBusy", budgetDetail);
|
|
456
|
+
case "summary-failed":
|
|
457
|
+
return t("contextRefusalSummaryFailed", budgetDetail);
|
|
458
|
+
case "no-compactable-content":
|
|
459
|
+
return t("contextRefusalNoCompactableContent");
|
|
460
|
+
case "single-message-too-large":
|
|
461
|
+
if (refusal.largestMessageTokens >= 0 && Number.isFinite(refusal.largestMessageTokens)) {
|
|
462
|
+
return t("contextRefusalSingleMessageTooLarge", tokens(refusal.largestMessageTokens), tokens(refusal.budget));
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
return t("contextPreflightBlockedHint");
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
// packages/cli/client/cliBatchIdentity.ts
|
|
469
|
+
function cliBatchPhaseFailure(args) {
|
|
470
|
+
const { phase, batchId, requestStarted, replyPersisted, cause } = args;
|
|
471
|
+
const message = cause instanceof Error ? cause.message : String(cause);
|
|
472
|
+
const error = new Error(
|
|
473
|
+
`cli batch phase ${phase} failed for ${batchId} (requestStarted=${requestStarted}, replyPersisted=${replyPersisted}): ${message}`
|
|
474
|
+
);
|
|
475
|
+
error.code = "cli_batch_phase_failed";
|
|
476
|
+
error.phase = phase;
|
|
477
|
+
error.batchId = batchId;
|
|
478
|
+
error.requestStarted = requestStarted;
|
|
479
|
+
error.replyPersisted = replyPersisted;
|
|
480
|
+
error.cause = cause;
|
|
481
|
+
return error;
|
|
482
|
+
}
|
|
483
|
+
function resolveCliBatchIdentity(options) {
|
|
484
|
+
const batchId = options.cliBatchId?.trim();
|
|
485
|
+
if (!batchId) return void 0;
|
|
486
|
+
const userMessages = options.userMessages;
|
|
487
|
+
if (!userMessages || userMessages.length === 0) {
|
|
488
|
+
throw cliBatchPhaseFailure({
|
|
489
|
+
phase: "requested",
|
|
490
|
+
batchId,
|
|
491
|
+
requestStarted: false,
|
|
492
|
+
replyPersisted: false,
|
|
493
|
+
cause: new Error("batch identity requires userMessages")
|
|
494
|
+
});
|
|
495
|
+
}
|
|
496
|
+
const tailId = userMessages[userMessages.length - 1]?.cliMessageId;
|
|
497
|
+
if (tailId !== batchId) {
|
|
498
|
+
throw cliBatchPhaseFailure({
|
|
499
|
+
phase: "requested",
|
|
500
|
+
batchId,
|
|
501
|
+
requestStarted: false,
|
|
502
|
+
replyPersisted: false,
|
|
503
|
+
cause: new Error(`batch identity mismatch: tail=${tailId ?? "none"}`)
|
|
504
|
+
});
|
|
505
|
+
}
|
|
506
|
+
const messageIds = userMessages.map((message) => message.cliMessageId);
|
|
507
|
+
if (messageIds.some((id) => !id)) {
|
|
508
|
+
throw cliBatchPhaseFailure({
|
|
509
|
+
phase: "requested",
|
|
510
|
+
batchId,
|
|
511
|
+
requestStarted: false,
|
|
512
|
+
replyPersisted: false,
|
|
513
|
+
cause: new Error("batch user message missing cliMessageId")
|
|
514
|
+
});
|
|
515
|
+
}
|
|
516
|
+
return { batchId, messageIds };
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
// packages/cli/client/agentRun.ts
|
|
520
|
+
import { resolve as resolveHostReviewPath } from "node:path";
|
|
521
|
+
|
|
522
|
+
// packages/cli/client/hostTaskBinding.ts
|
|
523
|
+
import { resolve as resolve2 } from "node:path";
|
|
524
|
+
function bindHostTask(args) {
|
|
525
|
+
let latest;
|
|
526
|
+
let completion;
|
|
527
|
+
function load() {
|
|
528
|
+
if (!args.reference) return void 0;
|
|
529
|
+
if (resolve2(args.reference.workspace) !== resolve2(args.workspace) || args.reference.dialogId !== args.dialogId) {
|
|
530
|
+
return { authorization: "unknown", reason: "scope_mismatch" };
|
|
531
|
+
}
|
|
532
|
+
return readHostTask(hostTaskEventsRoot(args.env), args.reference);
|
|
533
|
+
}
|
|
534
|
+
latest = load();
|
|
535
|
+
const contract = args.completionEvidenceProvider && latest && latest.authorization !== "unknown" ? latest.contract : void 0;
|
|
536
|
+
const adapter = !args.reference ? args.adapter : {
|
|
537
|
+
...args.adapter,
|
|
538
|
+
// Re-read authority before each protected action. A review-only binding owns
|
|
539
|
+
// typed review tools, not ordinary chat tools or their existing permission gates.
|
|
540
|
+
// Explicit completion tasks retain their all-tool stop semantics; unknown scope
|
|
541
|
+
// fails closed. Already running tools are not cancelled by this entry guard.
|
|
542
|
+
executeTool: async (call, opts) => {
|
|
543
|
+
latest = load();
|
|
544
|
+
const authorization = latest?.authorization ?? "unknown";
|
|
545
|
+
const protectedTool = call.name === "requestTaskReview" || call.name === "recordTaskReviewDecision";
|
|
546
|
+
if (authorization !== "active" && (args.completionEvidenceProvider || protectedTool || authorization === "unknown")) {
|
|
547
|
+
const code = authorization === "paused" ? "authorization_paused" : authorization === "revoked" ? "authorization_revoked" : "authorization_unknown";
|
|
548
|
+
throw Object.assign(new Error(`host task authority ${authorization}: tool "${call.name}" was not executed`), { code });
|
|
549
|
+
}
|
|
550
|
+
return args.adapter.executeTool(call, opts);
|
|
551
|
+
},
|
|
552
|
+
saveTurn: async (input) => {
|
|
553
|
+
latest = load();
|
|
554
|
+
const stopped = args.signal?.aborted || input.result.businessCompletion?.reasons.includes("stopped");
|
|
555
|
+
if (args.completionEvidenceProvider) {
|
|
556
|
+
const snapshot = latest && latest.authorization !== "unknown" ? latest.contract : void 0;
|
|
557
|
+
let evidence;
|
|
558
|
+
try {
|
|
559
|
+
evidence = snapshot ? await args.completionEvidenceProvider(snapshot) : void 0;
|
|
560
|
+
} catch {
|
|
561
|
+
}
|
|
562
|
+
latest = load();
|
|
563
|
+
const current = latest && latest.authorization !== "unknown" ? latest.contract : void 0;
|
|
564
|
+
completion = !current || !evidence || evidence.taskId !== current.taskId ? stopped ? { taskId: args.reference.taskId, status: "blocked", reasons: ["stopped"] } : unknownTaskCompletion(args.reference.taskId) : evaluateTaskExecutionContract({ ...evidence, authorization: current.authorization }, {
|
|
565
|
+
stopped,
|
|
566
|
+
executionFailed: input.result.error === true || !!input.result.runtimeProviderFailure || !!input.result.emptyAssistantFallbackReason,
|
|
567
|
+
budgetExhausted: input.result.businessCompletion?.reasons.includes("budget_exhausted")
|
|
568
|
+
});
|
|
569
|
+
}
|
|
570
|
+
const result = { ...input.result };
|
|
571
|
+
delete result.businessCompletion;
|
|
572
|
+
if (completion) result.businessCompletion = completion;
|
|
573
|
+
try {
|
|
574
|
+
return await args.adapter.saveTurn({ ...input, result });
|
|
575
|
+
} catch (error) {
|
|
576
|
+
if (args.completionEvidenceProvider) completion = { taskId: args.reference.taskId, status: "blocked", reasons: ["execution_failed"] };
|
|
577
|
+
throw error;
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
};
|
|
581
|
+
return {
|
|
582
|
+
adapter,
|
|
583
|
+
contract,
|
|
584
|
+
result: () => args.reference ? {
|
|
585
|
+
taskAuthorization: latest?.authorization ?? "unknown",
|
|
586
|
+
...args.completionEvidenceProvider ? { businessCompletion: completion ?? unknownTaskCompletion(args.reference.taskId) } : {}
|
|
587
|
+
} : {}
|
|
588
|
+
};
|
|
589
|
+
}
|
|
590
|
+
|
|
399
591
|
// packages/agent-runtime/modelLayerOverride.ts
|
|
400
592
|
var MODEL_LAYER_KEYS = [
|
|
401
593
|
"provider",
|
|
@@ -644,6 +836,8 @@ function parseUsageRecord(usage) {
|
|
|
644
836
|
function resolveContextWindow(model) {
|
|
645
837
|
const raw = model?.trim();
|
|
646
838
|
if (!raw) return void 0;
|
|
839
|
+
const oauthPinned = findCodexOAuthPinnedContextWindow(raw);
|
|
840
|
+
if (oauthPinned !== void 0) return oauthPinned;
|
|
647
841
|
for (const provider of PROVIDER_LOOKUP_ORDER) {
|
|
648
842
|
const config = findModelConfig(provider, raw);
|
|
649
843
|
if (config?.contextWindow) return config.contextWindow;
|
|
@@ -682,10 +876,10 @@ function platformCreditsFromUsage(usage) {
|
|
|
682
876
|
const cost = typeof usage.cost === "number" ? usage.cost : 0;
|
|
683
877
|
return Number.isFinite(cost) && cost > 0 ? cost : 0;
|
|
684
878
|
}
|
|
685
|
-
function withTurnCredits(
|
|
686
|
-
if (!
|
|
687
|
-
if (credits === void 0) return
|
|
688
|
-
return { ...
|
|
879
|
+
function withTurnCredits(tokens2, credits) {
|
|
880
|
+
if (!tokens2) return tokens2;
|
|
881
|
+
if (credits === void 0) return tokens2;
|
|
882
|
+
return { ...tokens2, credits };
|
|
689
883
|
}
|
|
690
884
|
function formatCreditsChip(credits, options) {
|
|
691
885
|
return options?.compact ? `\u26A1${credits.toFixed(2)}` : `\u26A1 ${credits.toFixed(2)} \u79EF\u5206`;
|
|
@@ -718,10 +912,18 @@ function computeBaselineContextTokens(options) {
|
|
|
718
912
|
}
|
|
719
913
|
return typeof fallbackEstimate === "function" ? fallbackEstimate() : fallbackEstimate;
|
|
720
914
|
}
|
|
915
|
+
function preserveContextUsageWithoutReceipt(previous, estimatedContextTokens) {
|
|
916
|
+
return {
|
|
917
|
+
turnTokens: previous.turnTokens,
|
|
918
|
+
lastAuthorityTurnCount: previous.lastAuthorityTurnCount,
|
|
919
|
+
estimatedContextTokens,
|
|
920
|
+
liveTurnEstimatedTokens: previous.turnTokens && previous.turnTokens.input > 0 ? Math.max(0, estimatedContextTokens - previous.turnTokens.input) || void 0 : void 0
|
|
921
|
+
};
|
|
922
|
+
}
|
|
721
923
|
function resolveContextUsage(opts = {}) {
|
|
722
|
-
const
|
|
723
|
-
const contextWindow =
|
|
724
|
-
const authoritativeInput =
|
|
924
|
+
const tokens2 = opts.tokens;
|
|
925
|
+
const contextWindow = tokens2?.contextWindow ?? opts.fallbackContextWindow;
|
|
926
|
+
const authoritativeInput = tokens2 && tokens2.input > 0 ? tokens2.input : void 0;
|
|
725
927
|
const baselineEstimate = opts.estimatedContextTokens != null && opts.estimatedContextTokens > 0 ? opts.estimatedContextTokens : void 0;
|
|
726
928
|
const generatedSinceAuthority = opts.turnEstimatedTokens != null && opts.turnEstimatedTokens > 0 ? opts.turnEstimatedTokens : void 0;
|
|
727
929
|
const occupancy = resolveOccupancy({
|
|
@@ -740,27 +942,27 @@ function resolveContextUsage(opts = {}) {
|
|
|
740
942
|
}
|
|
741
943
|
return usage;
|
|
742
944
|
}
|
|
743
|
-
function renderTokenStatus(
|
|
945
|
+
function renderTokenStatus(tokens2, fallback) {
|
|
744
946
|
const usage = resolveContextUsage({
|
|
745
|
-
tokens,
|
|
947
|
+
tokens: tokens2,
|
|
746
948
|
fallbackContextWindow: fallback?.contextWindow,
|
|
747
949
|
estimatedContextTokens: fallback?.estimatedContextTokens,
|
|
748
950
|
turnEstimatedTokens: fallback?.turnEstimatedTokens
|
|
749
951
|
});
|
|
750
|
-
const cache =
|
|
952
|
+
const cache = tokens2?.cacheRead != null && tokens2.cacheRead > 0 ? ` (cache ${formatTokenCount(tokens2.cacheRead)})` : "";
|
|
751
953
|
if (usage.contextWindow === void 0) {
|
|
752
954
|
const inStr = usage.used !== void 0 ? `${usage.estimated ? "~" : ""}${formatTokenCount(usage.used)}` : "\u2014";
|
|
753
|
-
const outStr =
|
|
955
|
+
const outStr = tokens2 ? formatTokenCount(tokens2.output) : "\u2014";
|
|
754
956
|
return `in ${inStr}${cache} out ${outStr} left \u2014`;
|
|
755
957
|
}
|
|
756
|
-
if (!
|
|
958
|
+
if (!tokens2) {
|
|
757
959
|
if (usage.used === void 0) return "in \u2014 out \u2014 left \u2014";
|
|
758
960
|
const left2 = usage.left !== void 0 ? `~${formatTokenCount(usage.left)}` : "\u2014";
|
|
759
961
|
return `in ~${formatTokenCount(usage.used)} out \u2014 left ${left2}`;
|
|
760
962
|
}
|
|
761
|
-
const inputText =
|
|
762
|
-
const left =
|
|
763
|
-
return `in ${inputText}${cache} out ${formatTokenCount(
|
|
963
|
+
const inputText = tokens2.input > 0 || usage.used === void 0 ? formatTokenCount(tokens2.input) : `~${formatTokenCount(usage.used)}`;
|
|
964
|
+
const left = tokens2.remaining != null ? formatTokenCount(tokens2.remaining) : usage.left !== void 0 ? `${usage.estimated ? "~" : ""}${formatTokenCount(usage.left)}` : "\u2014";
|
|
965
|
+
return `in ${inputText}${cache} out ${formatTokenCount(tokens2.output)} left ${left}`;
|
|
764
966
|
}
|
|
765
967
|
function shouldShowUsage(env) {
|
|
766
968
|
return env.NOLO_DEBUG === "1" || env.NOLO_SHOW_USAGE === "1";
|
|
@@ -845,754 +1047,6 @@ function formatCliHyperlink(url, label, enabled = resolveCliHyperlinkEnabled())
|
|
|
845
1047
|
return `${OSC8_OPEN}${url}${OSC8_CLOSE}${safeLabel}${OSC8_OPEN}${OSC8_CLOSE}`;
|
|
846
1048
|
}
|
|
847
1049
|
|
|
848
|
-
// node_modules/ansi-regex/index.js
|
|
849
|
-
function ansiRegex({ onlyFirst = false } = {}) {
|
|
850
|
-
const ST2 = "(?:\\u0007|\\u001B\\u005C|\\u009C)";
|
|
851
|
-
const osc = `(?:\\u001B\\][^\\u0007\\u001B\\u009C]*${ST2})`;
|
|
852
|
-
const csi = "[\\u001B\\u009B][[\\]()#;?]*(?:\\d{1,4}(?:[;:]\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]";
|
|
853
|
-
const pattern = `${osc}|${csi}`;
|
|
854
|
-
return new RegExp(pattern, onlyFirst ? void 0 : "g");
|
|
855
|
-
}
|
|
856
|
-
|
|
857
|
-
// node_modules/strip-ansi/index.js
|
|
858
|
-
var regex = ansiRegex();
|
|
859
|
-
function stripAnsi(string) {
|
|
860
|
-
if (typeof string !== "string") {
|
|
861
|
-
throw new TypeError(`Expected a \`string\`, got \`${typeof string}\``);
|
|
862
|
-
}
|
|
863
|
-
if (!string.includes("\x1B") && !string.includes("\x9B")) {
|
|
864
|
-
return string;
|
|
865
|
-
}
|
|
866
|
-
return string.replace(regex, "");
|
|
867
|
-
}
|
|
868
|
-
|
|
869
|
-
// node_modules/get-east-asian-width/lookup-data.js
|
|
870
|
-
var ambiguousMinimalCodePoint = 161;
|
|
871
|
-
var ambiguousMaximumCodePoint = 1114109;
|
|
872
|
-
var ambiguousRanges = [161, 161, 164, 164, 167, 168, 170, 170, 173, 174, 176, 180, 182, 186, 188, 191, 198, 198, 208, 208, 215, 216, 222, 225, 230, 230, 232, 234, 236, 237, 240, 240, 242, 243, 247, 250, 252, 252, 254, 254, 257, 257, 273, 273, 275, 275, 283, 283, 294, 295, 299, 299, 305, 307, 312, 312, 319, 322, 324, 324, 328, 331, 333, 333, 338, 339, 358, 359, 363, 363, 462, 462, 464, 464, 466, 466, 468, 468, 470, 470, 472, 472, 474, 474, 476, 476, 593, 593, 609, 609, 708, 708, 711, 711, 713, 715, 717, 717, 720, 720, 728, 731, 733, 733, 735, 735, 768, 879, 913, 929, 931, 937, 945, 961, 963, 969, 1025, 1025, 1040, 1103, 1105, 1105, 8208, 8208, 8211, 8214, 8216, 8217, 8220, 8221, 8224, 8226, 8228, 8231, 8240, 8240, 8242, 8243, 8245, 8245, 8251, 8251, 8254, 8254, 8308, 8308, 8319, 8319, 8321, 8324, 8364, 8364, 8451, 8451, 8453, 8453, 8457, 8457, 8467, 8467, 8470, 8470, 8481, 8482, 8486, 8486, 8491, 8491, 8531, 8532, 8539, 8542, 8544, 8555, 8560, 8569, 8585, 8585, 8592, 8601, 8632, 8633, 8658, 8658, 8660, 8660, 8679, 8679, 8704, 8704, 8706, 8707, 8711, 8712, 8715, 8715, 8719, 8719, 8721, 8721, 8725, 8725, 8730, 8730, 8733, 8736, 8739, 8739, 8741, 8741, 8743, 8748, 8750, 8750, 8756, 8759, 8764, 8765, 8776, 8776, 8780, 8780, 8786, 8786, 8800, 8801, 8804, 8807, 8810, 8811, 8814, 8815, 8834, 8835, 8838, 8839, 8853, 8853, 8857, 8857, 8869, 8869, 8895, 8895, 8978, 8978, 9312, 9449, 9451, 9547, 9552, 9587, 9600, 9615, 9618, 9621, 9632, 9633, 9635, 9641, 9650, 9651, 9654, 9655, 9660, 9661, 9664, 9665, 9670, 9672, 9675, 9675, 9678, 9681, 9698, 9701, 9711, 9711, 9733, 9734, 9737, 9737, 9742, 9743, 9756, 9756, 9758, 9758, 9792, 9792, 9794, 9794, 9824, 9825, 9827, 9829, 9831, 9834, 9836, 9837, 9839, 9839, 9886, 9887, 9919, 9919, 9926, 9933, 9935, 9939, 9941, 9953, 9955, 9955, 9960, 9961, 9963, 9969, 9972, 9972, 9974, 9977, 9979, 9980, 9982, 9983, 10045, 10045, 10102, 10111, 11094, 11097, 12872, 12879, 57344, 63743, 65024, 65039, 65533, 65533, 127232, 127242, 127248, 127277, 127280, 127337, 127344, 127373, 127375, 127376, 127387, 127404, 917760, 917999, 983040, 1048573, 1048576, 1114109];
|
|
873
|
-
var fullwidthMinimalCodePoint = 12288;
|
|
874
|
-
var fullwidthMaximumCodePoint = 65510;
|
|
875
|
-
var fullwidthRanges = [12288, 12288, 65281, 65376, 65504, 65510];
|
|
876
|
-
var wideMinimalCodePoint = 4352;
|
|
877
|
-
var wideMaximumCodePoint = 262141;
|
|
878
|
-
var wideRanges = [4352, 4447, 8986, 8987, 9001, 9002, 9193, 9196, 9200, 9200, 9203, 9203, 9725, 9726, 9748, 9749, 9776, 9783, 9800, 9811, 9855, 9855, 9866, 9871, 9875, 9875, 9889, 9889, 9898, 9899, 9917, 9918, 9924, 9925, 9934, 9934, 9940, 9940, 9962, 9962, 9970, 9971, 9973, 9973, 9978, 9978, 9981, 9981, 9989, 9989, 9994, 9995, 10024, 10024, 10060, 10060, 10062, 10062, 10067, 10069, 10071, 10071, 10133, 10135, 10160, 10160, 10175, 10175, 11035, 11036, 11088, 11088, 11093, 11093, 11904, 11929, 11931, 12019, 12032, 12245, 12272, 12287, 12289, 12350, 12353, 12438, 12441, 12543, 12549, 12591, 12593, 12686, 12688, 12773, 12783, 12830, 12832, 12871, 12880, 42124, 42128, 42182, 43360, 43388, 44032, 55203, 63744, 64255, 65040, 65049, 65072, 65106, 65108, 65126, 65128, 65131, 94176, 94180, 94192, 94198, 94208, 101594, 101631, 101664, 101760, 101874, 101888, 102801, 102816, 102866, 110576, 110579, 110581, 110587, 110589, 110590, 110592, 110888, 110898, 110898, 110928, 110930, 110933, 110933, 110948, 110952, 110960, 111355, 119552, 119638, 119648, 119670, 126980, 126980, 127183, 127183, 127374, 127374, 127377, 127386, 127406, 127406, 127488, 127490, 127504, 127547, 127552, 127560, 127568, 127569, 127584, 127589, 127744, 127776, 127789, 127797, 127799, 127868, 127870, 127891, 127904, 127946, 127951, 127955, 127968, 127984, 127988, 127988, 127992, 128062, 128064, 128064, 128066, 128252, 128255, 128317, 128331, 128334, 128336, 128359, 128378, 128378, 128405, 128406, 128420, 128420, 128507, 128591, 128640, 128709, 128716, 128716, 128720, 128722, 128725, 128729, 128732, 128735, 128747, 128748, 128756, 128764, 128986, 128986, 128992, 129003, 129008, 129008, 129292, 129338, 129340, 129349, 129351, 129535, 129648, 129660, 129664, 129734, 129736, 129736, 129740, 129757, 129759, 129771, 129775, 129786, 131072, 196605, 196608, 262141];
|
|
879
|
-
|
|
880
|
-
// node_modules/get-east-asian-width/utilities.js
|
|
881
|
-
var isInRange = (ranges, codePoint) => {
|
|
882
|
-
let low = 0;
|
|
883
|
-
let high = Math.floor(ranges.length / 2) - 1;
|
|
884
|
-
while (low <= high) {
|
|
885
|
-
const mid = Math.floor((low + high) / 2);
|
|
886
|
-
const i = mid * 2;
|
|
887
|
-
if (codePoint < ranges[i]) {
|
|
888
|
-
high = mid - 1;
|
|
889
|
-
} else if (codePoint > ranges[i + 1]) {
|
|
890
|
-
low = mid + 1;
|
|
891
|
-
} else {
|
|
892
|
-
return true;
|
|
893
|
-
}
|
|
894
|
-
}
|
|
895
|
-
return false;
|
|
896
|
-
};
|
|
897
|
-
|
|
898
|
-
// node_modules/get-east-asian-width/lookup.js
|
|
899
|
-
var commonCjkCodePoint = 19968;
|
|
900
|
-
var [wideFastPathStart, wideFastPathEnd] = /* @__PURE__ */ findWideFastPathRange(wideRanges);
|
|
901
|
-
function findWideFastPathRange(ranges) {
|
|
902
|
-
let fastPathStart = ranges[0];
|
|
903
|
-
let fastPathEnd = ranges[1];
|
|
904
|
-
for (let index = 0; index < ranges.length; index += 2) {
|
|
905
|
-
const start = ranges[index];
|
|
906
|
-
const end = ranges[index + 1];
|
|
907
|
-
if (commonCjkCodePoint >= start && commonCjkCodePoint <= end) {
|
|
908
|
-
return [start, end];
|
|
909
|
-
}
|
|
910
|
-
if (end - start > fastPathEnd - fastPathStart) {
|
|
911
|
-
fastPathStart = start;
|
|
912
|
-
fastPathEnd = end;
|
|
913
|
-
}
|
|
914
|
-
}
|
|
915
|
-
return [fastPathStart, fastPathEnd];
|
|
916
|
-
}
|
|
917
|
-
var isAmbiguous = (codePoint) => {
|
|
918
|
-
if (codePoint < ambiguousMinimalCodePoint || codePoint > ambiguousMaximumCodePoint) {
|
|
919
|
-
return false;
|
|
920
|
-
}
|
|
921
|
-
return isInRange(ambiguousRanges, codePoint);
|
|
922
|
-
};
|
|
923
|
-
var isFullwidth = (codePoint) => {
|
|
924
|
-
if (codePoint < fullwidthMinimalCodePoint || codePoint > fullwidthMaximumCodePoint) {
|
|
925
|
-
return false;
|
|
926
|
-
}
|
|
927
|
-
return isInRange(fullwidthRanges, codePoint);
|
|
928
|
-
};
|
|
929
|
-
var isWide = (codePoint) => {
|
|
930
|
-
if (codePoint >= wideFastPathStart && codePoint <= wideFastPathEnd) {
|
|
931
|
-
return true;
|
|
932
|
-
}
|
|
933
|
-
if (codePoint < wideMinimalCodePoint || codePoint > wideMaximumCodePoint) {
|
|
934
|
-
return false;
|
|
935
|
-
}
|
|
936
|
-
return isInRange(wideRanges, codePoint);
|
|
937
|
-
};
|
|
938
|
-
|
|
939
|
-
// node_modules/get-east-asian-width/index.js
|
|
940
|
-
function validate(codePoint) {
|
|
941
|
-
if (!Number.isSafeInteger(codePoint)) {
|
|
942
|
-
throw new TypeError(`Expected a code point, got \`${typeof codePoint}\`.`);
|
|
943
|
-
}
|
|
944
|
-
}
|
|
945
|
-
function eastAsianWidth(codePoint, { ambiguousAsWide = false } = {}) {
|
|
946
|
-
validate(codePoint);
|
|
947
|
-
if (isFullwidth(codePoint) || isWide(codePoint) || ambiguousAsWide && isAmbiguous(codePoint)) {
|
|
948
|
-
return 2;
|
|
949
|
-
}
|
|
950
|
-
return 1;
|
|
951
|
-
}
|
|
952
|
-
|
|
953
|
-
// node_modules/string-width/index.js
|
|
954
|
-
var segmenter = new Intl.Segmenter();
|
|
955
|
-
var zeroWidthClusterRegex = new RegExp("^(?:\\p{Default_Ignorable_Code_Point}|\\p{Control}|\\p{Format}|\\p{Nonspacing_Mark}|\\p{Enclosing_Mark}|\\p{Surrogate})+$", "v");
|
|
956
|
-
var leadingNonPrintingRegex = new RegExp("^[\\p{Default_Ignorable_Code_Point}\\p{Control}\\p{Format}\\p{Nonspacing_Mark}\\p{Enclosing_Mark}\\p{Surrogate}]+", "v");
|
|
957
|
-
var spacingMarkRegex = new RegExp("\\p{Spacing_Mark}", "v");
|
|
958
|
-
var rgiEmojiRegex = new RegExp("^\\p{RGI_Emoji}$", "v");
|
|
959
|
-
var unqualifiedKeycapRegex = /^[\d#*]\u20E3$/;
|
|
960
|
-
var extendedPictographicRegex = new RegExp("\\p{Extended_Pictographic}", "gu");
|
|
961
|
-
function isDoubleWidthNonRgiEmojiSequence(segment) {
|
|
962
|
-
if (segment.length > 50) {
|
|
963
|
-
return false;
|
|
964
|
-
}
|
|
965
|
-
if (unqualifiedKeycapRegex.test(segment)) {
|
|
966
|
-
return true;
|
|
967
|
-
}
|
|
968
|
-
if (segment.includes("\u200D")) {
|
|
969
|
-
const pictographics = segment.match(extendedPictographicRegex);
|
|
970
|
-
return pictographics !== null && pictographics.length >= 2;
|
|
971
|
-
}
|
|
972
|
-
return false;
|
|
973
|
-
}
|
|
974
|
-
function baseVisible(segment) {
|
|
975
|
-
return segment.replace(leadingNonPrintingRegex, "");
|
|
976
|
-
}
|
|
977
|
-
function isZeroWidthCluster(segment) {
|
|
978
|
-
return zeroWidthClusterRegex.test(segment);
|
|
979
|
-
}
|
|
980
|
-
function isHangulLeadingJamo(codePoint) {
|
|
981
|
-
return codePoint >= 4352 && codePoint <= 4447 || codePoint >= 43360 && codePoint <= 43388;
|
|
982
|
-
}
|
|
983
|
-
function isHangulVowelJamo(codePoint) {
|
|
984
|
-
return codePoint >= 4448 && codePoint <= 4519 || codePoint >= 55216 && codePoint <= 55238;
|
|
985
|
-
}
|
|
986
|
-
function isHangulTrailingJamo(codePoint) {
|
|
987
|
-
return codePoint >= 4520 && codePoint <= 4607 || codePoint >= 55243 && codePoint <= 55291;
|
|
988
|
-
}
|
|
989
|
-
function isHangulJamo(codePoint) {
|
|
990
|
-
return isHangulLeadingJamo(codePoint) || isHangulVowelJamo(codePoint) || isHangulTrailingJamo(codePoint);
|
|
991
|
-
}
|
|
992
|
-
function hangulClusterWidth(visibleSegment, eastAsianWidthOptions) {
|
|
993
|
-
const codePoints = [];
|
|
994
|
-
for (const character of visibleSegment) {
|
|
995
|
-
if (zeroWidthClusterRegex.test(character)) {
|
|
996
|
-
continue;
|
|
997
|
-
}
|
|
998
|
-
codePoints.push(character.codePointAt(0));
|
|
999
|
-
}
|
|
1000
|
-
if (codePoints.length === 0) {
|
|
1001
|
-
return void 0;
|
|
1002
|
-
}
|
|
1003
|
-
let width = 0;
|
|
1004
|
-
for (let index = 0; index < codePoints.length; index++) {
|
|
1005
|
-
const codePoint = codePoints[index];
|
|
1006
|
-
if (!isHangulJamo(codePoint)) {
|
|
1007
|
-
if (width === 0) {
|
|
1008
|
-
return void 0;
|
|
1009
|
-
}
|
|
1010
|
-
for (let remaining = index; remaining < codePoints.length; remaining++) {
|
|
1011
|
-
width += eastAsianWidth(codePoints[remaining], eastAsianWidthOptions);
|
|
1012
|
-
}
|
|
1013
|
-
return width;
|
|
1014
|
-
}
|
|
1015
|
-
if (isHangulLeadingJamo(codePoint) && isHangulVowelJamo(codePoints[index + 1])) {
|
|
1016
|
-
width += 2;
|
|
1017
|
-
index += isHangulTrailingJamo(codePoints[index + 2]) ? 2 : 1;
|
|
1018
|
-
continue;
|
|
1019
|
-
}
|
|
1020
|
-
width += eastAsianWidth(codePoint, eastAsianWidthOptions);
|
|
1021
|
-
}
|
|
1022
|
-
return width;
|
|
1023
|
-
}
|
|
1024
|
-
function trailingWidth(visibleSegment, eastAsianWidthOptions) {
|
|
1025
|
-
let extra = 0;
|
|
1026
|
-
let first = true;
|
|
1027
|
-
for (const character of visibleSegment) {
|
|
1028
|
-
if (first) {
|
|
1029
|
-
first = false;
|
|
1030
|
-
continue;
|
|
1031
|
-
}
|
|
1032
|
-
if (spacingMarkRegex.test(character) || character >= "\uFF00" && character <= "\uFFEF") {
|
|
1033
|
-
extra += eastAsianWidth(character.codePointAt(0), eastAsianWidthOptions);
|
|
1034
|
-
}
|
|
1035
|
-
}
|
|
1036
|
-
return extra;
|
|
1037
|
-
}
|
|
1038
|
-
function stringWidth(input, options = {}) {
|
|
1039
|
-
if (typeof input !== "string" || input.length === 0) {
|
|
1040
|
-
return 0;
|
|
1041
|
-
}
|
|
1042
|
-
const {
|
|
1043
|
-
ambiguousIsNarrow = true,
|
|
1044
|
-
countAnsiEscapeCodes = false
|
|
1045
|
-
} = options;
|
|
1046
|
-
let string = input;
|
|
1047
|
-
if (!countAnsiEscapeCodes && (string.includes("\x1B") || string.includes("\x9B"))) {
|
|
1048
|
-
string = stripAnsi(string);
|
|
1049
|
-
}
|
|
1050
|
-
if (string.length === 0) {
|
|
1051
|
-
return 0;
|
|
1052
|
-
}
|
|
1053
|
-
if (/^[\u0020-\u007E]*$/.test(string)) {
|
|
1054
|
-
return string.length;
|
|
1055
|
-
}
|
|
1056
|
-
let width = 0;
|
|
1057
|
-
const eastAsianWidthOptions = { ambiguousAsWide: !ambiguousIsNarrow };
|
|
1058
|
-
for (const { segment } of segmenter.segment(string)) {
|
|
1059
|
-
if (isZeroWidthCluster(segment)) {
|
|
1060
|
-
continue;
|
|
1061
|
-
}
|
|
1062
|
-
if (rgiEmojiRegex.test(segment) || isDoubleWidthNonRgiEmojiSequence(segment)) {
|
|
1063
|
-
width += 2;
|
|
1064
|
-
continue;
|
|
1065
|
-
}
|
|
1066
|
-
const visibleSegment = baseVisible(segment);
|
|
1067
|
-
const hangulWidth = hangulClusterWidth(visibleSegment, eastAsianWidthOptions);
|
|
1068
|
-
if (hangulWidth !== void 0) {
|
|
1069
|
-
width += hangulWidth;
|
|
1070
|
-
continue;
|
|
1071
|
-
}
|
|
1072
|
-
const codePoint = visibleSegment.codePointAt(0);
|
|
1073
|
-
width += eastAsianWidth(codePoint, eastAsianWidthOptions);
|
|
1074
|
-
width += trailingWidth(visibleSegment, eastAsianWidthOptions);
|
|
1075
|
-
}
|
|
1076
|
-
return width;
|
|
1077
|
-
}
|
|
1078
|
-
|
|
1079
|
-
// packages/cli/tui/tuiAnsi.ts
|
|
1080
|
-
var ANSI_ESCAPE_REGEX = /\x1b\[[\x30-\x3f]*[\x20-\x2f]*[\x40-\x7e]/g;
|
|
1081
|
-
var OSC8_HYPERLINK_REGEX = /\x1b\]8;;[^\x1b]*\x1b\\/g;
|
|
1082
|
-
var ALL_ANSI_ESCAPE_REGEX = ansiRegex();
|
|
1083
|
-
var FIRST_ANSI_ESCAPE_REGEX = ansiRegex({ onlyFirst: true });
|
|
1084
|
-
function stripOsc8Hyperlinks(text) {
|
|
1085
|
-
return text.replace(OSC8_HYPERLINK_REGEX, "");
|
|
1086
|
-
}
|
|
1087
|
-
function stripAnsi2(text) {
|
|
1088
|
-
return text.replace(ANSI_ESCAPE_REGEX, "").replace(ALL_ANSI_ESCAPE_REGEX, "");
|
|
1089
|
-
}
|
|
1090
|
-
var SGR_SEQUENCE_REGEX = /^\x1b\[[0-9;]*m/;
|
|
1091
|
-
var TRAILING_SGR_REGEX = /(?:\x1b\[[0-9;]*m)+$/;
|
|
1092
|
-
function applyTerminalOutputToText(existing, chunk) {
|
|
1093
|
-
if (!chunk) return existing;
|
|
1094
|
-
let text = existing;
|
|
1095
|
-
let index = 0;
|
|
1096
|
-
while (index < chunk.length) {
|
|
1097
|
-
if (chunk[index] === "\x1B") {
|
|
1098
|
-
const sgr = SGR_SEQUENCE_REGEX.exec(chunk.slice(index));
|
|
1099
|
-
if (sgr) {
|
|
1100
|
-
text += sgr[0];
|
|
1101
|
-
index += sgr[0].length;
|
|
1102
|
-
continue;
|
|
1103
|
-
}
|
|
1104
|
-
const osc = chunk.slice(index).match(/^\x1b\]8;;[^\x07\x1b]*(?:\x07|\x1b\\)/);
|
|
1105
|
-
if (osc) {
|
|
1106
|
-
index += osc[0].length;
|
|
1107
|
-
continue;
|
|
1108
|
-
}
|
|
1109
|
-
const csi = chunk.slice(index).match(/^\x1b\[[\x30-\x3f]*[\x20-\x2f]*[\x40-\x7e]/);
|
|
1110
|
-
if (csi) {
|
|
1111
|
-
index += csi[0].length;
|
|
1112
|
-
continue;
|
|
1113
|
-
}
|
|
1114
|
-
index += 1;
|
|
1115
|
-
continue;
|
|
1116
|
-
}
|
|
1117
|
-
const ch = chunk[index];
|
|
1118
|
-
if (ch === "\r") {
|
|
1119
|
-
const lastNl = text.lastIndexOf("\n");
|
|
1120
|
-
text = lastNl === -1 ? "" : text.slice(0, lastNl + 1);
|
|
1121
|
-
index += 1;
|
|
1122
|
-
continue;
|
|
1123
|
-
}
|
|
1124
|
-
if (ch === "\n") {
|
|
1125
|
-
text += "\n";
|
|
1126
|
-
index += 1;
|
|
1127
|
-
continue;
|
|
1128
|
-
}
|
|
1129
|
-
if (ch === "\b") {
|
|
1130
|
-
const trailing = TRAILING_SGR_REGEX.exec(text);
|
|
1131
|
-
const sgrTail = trailing ? trailing[0] : "";
|
|
1132
|
-
const head = sgrTail ? text.slice(0, -sgrTail.length) : text;
|
|
1133
|
-
if (head.length > 0 && head[head.length - 1] !== "\n") {
|
|
1134
|
-
text = head.slice(0, -1) + sgrTail;
|
|
1135
|
-
}
|
|
1136
|
-
index += 1;
|
|
1137
|
-
continue;
|
|
1138
|
-
}
|
|
1139
|
-
const code = ch.charCodeAt(0);
|
|
1140
|
-
if (code < 32 && ch !== " " || code === 127) {
|
|
1141
|
-
index += 1;
|
|
1142
|
-
continue;
|
|
1143
|
-
}
|
|
1144
|
-
text += ch;
|
|
1145
|
-
index += 1;
|
|
1146
|
-
}
|
|
1147
|
-
return text;
|
|
1148
|
-
}
|
|
1149
|
-
function resolveAmbiguousWidth(explicit, env = process.env) {
|
|
1150
|
-
if (explicit === "wide" || explicit === "narrow") return explicit;
|
|
1151
|
-
const raw = env.NOLO_TUI_AMBIGUOUS_WIDTH;
|
|
1152
|
-
if (typeof raw === "string") {
|
|
1153
|
-
const trimmed = raw.trim().toLowerCase();
|
|
1154
|
-
if (trimmed === "wide") return "wide";
|
|
1155
|
-
if (trimmed === "narrow") return "narrow";
|
|
1156
|
-
}
|
|
1157
|
-
return "narrow";
|
|
1158
|
-
}
|
|
1159
|
-
function isAmbiguousWideSymbolCode(code) {
|
|
1160
|
-
return code >= 8592 && code <= 8597 || // ←↑→↓↔↕
|
|
1161
|
-
code === 8656 || code === 8658 || code === 8660 || // ⇐⇒⇔
|
|
1162
|
-
code === 215 || code === 247 || code === 177 || // ×÷±
|
|
1163
|
-
code === 8226 || code === 183 || // • ·
|
|
1164
|
-
code === 176 || code === 8451 || // ° ℃
|
|
1165
|
-
code >= 8208 && code <= 8213 || // ‐‑‒–—―
|
|
1166
|
-
code >= 9312 && code <= 9471 || // ①②④⑤ 圈数字/括号序号
|
|
1167
|
-
code === 8986 || code === 8987 || // ⌚ ⌛
|
|
1168
|
-
code >= 9193 && code <= 9210;
|
|
1169
|
-
}
|
|
1170
|
-
function isForceWideSymbolCode(code) {
|
|
1171
|
-
return code >= 9728 && code <= 10175 && !(code >= 10088 && code <= 10101) || code >= 11008 && code <= 11263 || code >= 127744 && code <= 129791 || isAmbiguousWideSymbolCode(code);
|
|
1172
|
-
}
|
|
1173
|
-
function isCjkQuoteCode(code) {
|
|
1174
|
-
return code === 8220 || code === 8221 || code === 8216 || code === 8217;
|
|
1175
|
-
}
|
|
1176
|
-
function scanWidthNeeds(plain, locale, ambiguousWidth) {
|
|
1177
|
-
let hasNonAscii = false;
|
|
1178
|
-
const isWideMode = ambiguousWidth === "wide";
|
|
1179
|
-
for (let i = 0; i < plain.length; i++) {
|
|
1180
|
-
const cc = plain.charCodeAt(i);
|
|
1181
|
-
if (isWideMode && isAmbiguousWideSymbolCode(cc)) {
|
|
1182
|
-
return { hasNonAscii: true, hasCandidate: true };
|
|
1183
|
-
}
|
|
1184
|
-
if (cc < 8192) {
|
|
1185
|
-
if (cc >= 128) hasNonAscii = true;
|
|
1186
|
-
continue;
|
|
1187
|
-
}
|
|
1188
|
-
hasNonAscii = true;
|
|
1189
|
-
let code = cc;
|
|
1190
|
-
if (cc >= 55296 && cc <= 56319 && i + 1 < plain.length) {
|
|
1191
|
-
const lo = plain.charCodeAt(i + 1);
|
|
1192
|
-
if (lo >= 56320 && lo <= 57343) {
|
|
1193
|
-
code = (cc - 55296) * 1024 + (lo - 56320) + 65536;
|
|
1194
|
-
i += 1;
|
|
1195
|
-
}
|
|
1196
|
-
}
|
|
1197
|
-
const isSymbolCandidate = isWideMode && isForceWideSymbolCode(code);
|
|
1198
|
-
const isQuoteCandidate = locale === "zh" && isCjkQuoteCode(code);
|
|
1199
|
-
if (isSymbolCandidate || isQuoteCandidate) {
|
|
1200
|
-
return { hasNonAscii: true, hasCandidate: true };
|
|
1201
|
-
}
|
|
1202
|
-
}
|
|
1203
|
-
return { hasNonAscii, hasCandidate: false };
|
|
1204
|
-
}
|
|
1205
|
-
var displayWidthCache = /* @__PURE__ */ new Map();
|
|
1206
|
-
var DISPLAY_WIDTH_CACHE_MAX = 4096;
|
|
1207
|
-
function displayWidth(str, ambiguousWidth = resolveAmbiguousWidth()) {
|
|
1208
|
-
const plain = stripAnsi2(str);
|
|
1209
|
-
const locale = getCliLocale();
|
|
1210
|
-
const needs = scanWidthNeeds(plain, locale, ambiguousWidth);
|
|
1211
|
-
if (!needs.hasNonAscii) {
|
|
1212
|
-
return stringWidth(plain);
|
|
1213
|
-
}
|
|
1214
|
-
const key = locale + "\0" + ambiguousWidth + "\0" + plain;
|
|
1215
|
-
const cached = displayWidthCache.get(key);
|
|
1216
|
-
if (cached !== void 0) return cached;
|
|
1217
|
-
const base = stringWidth(plain);
|
|
1218
|
-
if (!needs.hasCandidate) {
|
|
1219
|
-
if (displayWidthCache.size >= DISPLAY_WIDTH_CACHE_MAX) {
|
|
1220
|
-
const eldest = displayWidthCache.keys().next().value;
|
|
1221
|
-
if (eldest !== void 0) displayWidthCache.delete(eldest);
|
|
1222
|
-
}
|
|
1223
|
-
displayWidthCache.set(key, base);
|
|
1224
|
-
return base;
|
|
1225
|
-
}
|
|
1226
|
-
let width = base;
|
|
1227
|
-
const isWideMode = ambiguousWidth === "wide";
|
|
1228
|
-
for (const { segment } of graphemeSegmenter.segment(plain)) {
|
|
1229
|
-
const code = segment.codePointAt(0) ?? 0;
|
|
1230
|
-
const isSymbol = isWideMode && isForceWideSymbolCode(code);
|
|
1231
|
-
const isQuote = locale === "zh" && isCjkQuoteCode(code);
|
|
1232
|
-
if (isSymbol || isQuote) {
|
|
1233
|
-
if (stringWidth(segment) === 1) width += 1;
|
|
1234
|
-
}
|
|
1235
|
-
}
|
|
1236
|
-
if (displayWidthCache.size >= DISPLAY_WIDTH_CACHE_MAX) {
|
|
1237
|
-
const eldest = displayWidthCache.keys().next().value;
|
|
1238
|
-
if (eldest !== void 0) displayWidthCache.delete(eldest);
|
|
1239
|
-
}
|
|
1240
|
-
displayWidthCache.set(key, width);
|
|
1241
|
-
return width;
|
|
1242
|
-
}
|
|
1243
|
-
function visibleWidth(str) {
|
|
1244
|
-
return displayWidth(stripAnsi2(str));
|
|
1245
|
-
}
|
|
1246
|
-
function truncateAnsi(text, maxWidth) {
|
|
1247
|
-
if (maxWidth <= 0) return "";
|
|
1248
|
-
text = stripOsc8Hyperlinks(text);
|
|
1249
|
-
if (visibleWidth(text) <= maxWidth) return text;
|
|
1250
|
-
let width = 0;
|
|
1251
|
-
let out = "";
|
|
1252
|
-
let i = 0;
|
|
1253
|
-
let sawAnsi = false;
|
|
1254
|
-
while (i < text.length) {
|
|
1255
|
-
if (text[i] === "\x1B" && text[i + 1] === "[") {
|
|
1256
|
-
sawAnsi = true;
|
|
1257
|
-
let j = i + 2;
|
|
1258
|
-
while (j < text.length) {
|
|
1259
|
-
const code = text.charCodeAt(j);
|
|
1260
|
-
j += 1;
|
|
1261
|
-
if (code >= 64 && code <= 126) break;
|
|
1262
|
-
}
|
|
1263
|
-
out += text.slice(i, j);
|
|
1264
|
-
i = j;
|
|
1265
|
-
continue;
|
|
1266
|
-
}
|
|
1267
|
-
const codePoint = text.codePointAt(i) ?? 0;
|
|
1268
|
-
const char = String.fromCodePoint(codePoint);
|
|
1269
|
-
const charWidth = displayWidth(char);
|
|
1270
|
-
if (width + charWidth > maxWidth) break;
|
|
1271
|
-
out += char;
|
|
1272
|
-
width += charWidth;
|
|
1273
|
-
i += char.length;
|
|
1274
|
-
}
|
|
1275
|
-
return sawAnsi ? `${out}\x1B[0m` : out;
|
|
1276
|
-
}
|
|
1277
|
-
function fitAnsiLine(text, width, ellipsis = "\u2026") {
|
|
1278
|
-
if (width <= 0) return "";
|
|
1279
|
-
if (visibleWidth(text) <= width) return text;
|
|
1280
|
-
const ellipsisWidth = displayWidth(ellipsis);
|
|
1281
|
-
if (width < ellipsisWidth) return truncateAnsi(text, width);
|
|
1282
|
-
if (width === ellipsisWidth) return truncateAnsi(ellipsis, width) || truncateAnsi(text, width);
|
|
1283
|
-
return `${truncateAnsi(text, width - ellipsisWidth)}${ellipsis}`;
|
|
1284
|
-
}
|
|
1285
|
-
function countPhysicalLines(text, columns) {
|
|
1286
|
-
const lines = text.split("\n");
|
|
1287
|
-
let total = 0;
|
|
1288
|
-
for (const line of lines) {
|
|
1289
|
-
const width = visibleWidth(stripOsc8Hyperlinks(line));
|
|
1290
|
-
total += Math.max(1, Math.ceil(width / columns));
|
|
1291
|
-
}
|
|
1292
|
-
return Math.max(total, 1);
|
|
1293
|
-
}
|
|
1294
|
-
function takeDisplayWidth(text, width) {
|
|
1295
|
-
let used = 0;
|
|
1296
|
-
let index = 0;
|
|
1297
|
-
for (const char of text) {
|
|
1298
|
-
const charWidth = displayWidth(char);
|
|
1299
|
-
if (used + charWidth > width && used > 0) break;
|
|
1300
|
-
used += charWidth;
|
|
1301
|
-
index += char.length;
|
|
1302
|
-
}
|
|
1303
|
-
return { prefix: text.slice(0, index), rest: text.slice(index) };
|
|
1304
|
-
}
|
|
1305
|
-
function padOrTruncateToWidth(text, width) {
|
|
1306
|
-
const textWidth = visibleWidth(text);
|
|
1307
|
-
if (textWidth > width) {
|
|
1308
|
-
return truncateAnsi(text, width);
|
|
1309
|
-
}
|
|
1310
|
-
return `${text}${" ".repeat(width - textWidth)}`;
|
|
1311
|
-
}
|
|
1312
|
-
var SGR_RESET_REGEX = /^\x1b\[0?m$/;
|
|
1313
|
-
var graphemeSegmenter = new Intl.Segmenter(void 0, { granularity: "grapheme" });
|
|
1314
|
-
function tokenizeAnsiLine(line) {
|
|
1315
|
-
const tokens = [];
|
|
1316
|
-
let index = 0;
|
|
1317
|
-
while (index < line.length) {
|
|
1318
|
-
if (line[index] === "\x1B") {
|
|
1319
|
-
const osc = line.slice(index).match(/^\x1b\]8;;[^\x07\x1b]*(?:\x07|\x1b\\)/);
|
|
1320
|
-
if (osc) {
|
|
1321
|
-
tokens.push({ kind: "sgr", value: osc[0], width: 0, charIndex: index });
|
|
1322
|
-
index += osc[0].length;
|
|
1323
|
-
continue;
|
|
1324
|
-
}
|
|
1325
|
-
const sgr = SGR_SEQUENCE_REGEX.exec(line.slice(index));
|
|
1326
|
-
if (sgr) {
|
|
1327
|
-
tokens.push({ kind: "sgr", value: sgr[0], width: 0, charIndex: index });
|
|
1328
|
-
index += sgr[0].length;
|
|
1329
|
-
continue;
|
|
1330
|
-
}
|
|
1331
|
-
const csi = line.slice(index).match(/^\x1b\[[\x30-\x3f]*[\x20-\x2f]*[\x40-\x7e]/);
|
|
1332
|
-
if (csi) {
|
|
1333
|
-
index += csi[0].length;
|
|
1334
|
-
continue;
|
|
1335
|
-
}
|
|
1336
|
-
const escape = FIRST_ANSI_ESCAPE_REGEX.exec(line.slice(index));
|
|
1337
|
-
if (escape?.index === 0) {
|
|
1338
|
-
index += escape[0].length;
|
|
1339
|
-
continue;
|
|
1340
|
-
}
|
|
1341
|
-
index += 1;
|
|
1342
|
-
continue;
|
|
1343
|
-
}
|
|
1344
|
-
let nextEsc = line.indexOf("\x1B", index);
|
|
1345
|
-
if (nextEsc === -1) nextEsc = line.length;
|
|
1346
|
-
const chunk = line.slice(index, nextEsc);
|
|
1347
|
-
for (const item of graphemeSegmenter.segment(chunk)) {
|
|
1348
|
-
tokens.push({
|
|
1349
|
-
kind: "char",
|
|
1350
|
-
value: item.segment,
|
|
1351
|
-
width: displayWidth(item.segment),
|
|
1352
|
-
charIndex: index + item.index
|
|
1353
|
-
});
|
|
1354
|
-
}
|
|
1355
|
-
index = nextEsc;
|
|
1356
|
-
}
|
|
1357
|
-
return tokens;
|
|
1358
|
-
}
|
|
1359
|
-
function buildSourceMapping(rawLine, styledLine, prefixCharCount) {
|
|
1360
|
-
let contentStart = 0;
|
|
1361
|
-
const headingMatch = rawLine.match(/^(#{1,3})\s+(.+)$/);
|
|
1362
|
-
let lineToParse = rawLine;
|
|
1363
|
-
if (headingMatch) {
|
|
1364
|
-
contentStart = headingMatch[1].length + 1;
|
|
1365
|
-
while (contentStart < rawLine.length && rawLine[contentStart] === " ") contentStart++;
|
|
1366
|
-
lineToParse = rawLine.slice(contentStart);
|
|
1367
|
-
}
|
|
1368
|
-
const INLINE_RE = /(\[([^\]]+)\]\(([^)\s]+)\)|`([^`]+)`|\*\*(.+?)\*\*|(?<!\*)\*([^*]+?)\*(?!\*)|~~([^~]+?)~~)/g;
|
|
1369
|
-
const mapping = [];
|
|
1370
|
-
let lastIdx = 0;
|
|
1371
|
-
let match;
|
|
1372
|
-
while ((match = INLINE_RE.exec(lineToParse)) !== null) {
|
|
1373
|
-
const plainBefore = lineToParse.slice(lastIdx, match.index);
|
|
1374
|
-
for (let c = 0; c < plainBefore.length; c++) {
|
|
1375
|
-
mapping.push(contentStart + lastIdx + c);
|
|
1376
|
-
}
|
|
1377
|
-
const fullMatch = match[0];
|
|
1378
|
-
if (match[2] !== void 0 && match[3] !== void 0) {
|
|
1379
|
-
const linkText = match[2];
|
|
1380
|
-
const linkUrl = match[3];
|
|
1381
|
-
const textOffset = contentStart + match.index + 1;
|
|
1382
|
-
for (let c = 0; c < linkText.length; c++) {
|
|
1383
|
-
mapping.push(textOffset + c);
|
|
1384
|
-
}
|
|
1385
|
-
const parenOffset = textOffset + linkText.length;
|
|
1386
|
-
mapping.push(parenOffset);
|
|
1387
|
-
mapping.push(parenOffset + 1);
|
|
1388
|
-
const urlOffset = parenOffset + 2;
|
|
1389
|
-
for (let c = 0; c < linkUrl.length; c++) {
|
|
1390
|
-
mapping.push(urlOffset + c);
|
|
1391
|
-
}
|
|
1392
|
-
mapping.push(urlOffset + linkUrl.length);
|
|
1393
|
-
} else if (match[4] !== void 0) {
|
|
1394
|
-
const codeText = match[4];
|
|
1395
|
-
const codeOffset = contentStart + match.index + 1;
|
|
1396
|
-
for (let c = 0; c < codeText.length; c++) {
|
|
1397
|
-
mapping.push(codeOffset + c);
|
|
1398
|
-
}
|
|
1399
|
-
} else if (match[5] !== void 0) {
|
|
1400
|
-
const boldText = match[5];
|
|
1401
|
-
const boldOffset = contentStart + match.index + 2;
|
|
1402
|
-
for (let c = 0; c < boldText.length; c++) {
|
|
1403
|
-
mapping.push(boldOffset + c);
|
|
1404
|
-
}
|
|
1405
|
-
} else if (match[6] !== void 0) {
|
|
1406
|
-
const italicText = match[6];
|
|
1407
|
-
const italicOffset = contentStart + match.index + 1;
|
|
1408
|
-
for (let c = 0; c < italicText.length; c++) {
|
|
1409
|
-
mapping.push(italicOffset + c);
|
|
1410
|
-
}
|
|
1411
|
-
} else if (match[7] !== void 0) {
|
|
1412
|
-
const strikeText = match[7];
|
|
1413
|
-
const strikeOffset = contentStart + match.index + 2;
|
|
1414
|
-
for (let c = 0; c < strikeText.length; c++) {
|
|
1415
|
-
mapping.push(strikeOffset + c);
|
|
1416
|
-
}
|
|
1417
|
-
}
|
|
1418
|
-
lastIdx = match.index + fullMatch.length;
|
|
1419
|
-
}
|
|
1420
|
-
const plainRest = lineToParse.slice(lastIdx);
|
|
1421
|
-
for (let c = 0; c < plainRest.length; c++) {
|
|
1422
|
-
mapping.push(contentStart + lastIdx + c);
|
|
1423
|
-
}
|
|
1424
|
-
return mapping;
|
|
1425
|
-
}
|
|
1426
|
-
function wrapTranscriptLineWithLayout(line, columns, hangingIndent = "", lineSourceStart = 0, prefixWidth = 0, prefixCharCount = 0, sourceMapping, rawLineLength) {
|
|
1427
|
-
if (line === "") {
|
|
1428
|
-
const rawLen = rawLineLength ?? 0;
|
|
1429
|
-
return [
|
|
1430
|
-
{
|
|
1431
|
-
rendered: "",
|
|
1432
|
-
sourceStart: lineSourceStart,
|
|
1433
|
-
sourceEnd: lineSourceStart + rawLen,
|
|
1434
|
-
prefixWidth
|
|
1435
|
-
}
|
|
1436
|
-
];
|
|
1437
|
-
}
|
|
1438
|
-
const tokens = tokenizeAnsiLine(line);
|
|
1439
|
-
const rows = [];
|
|
1440
|
-
let activeStyles = [];
|
|
1441
|
-
const applyStyleToken = (value) => {
|
|
1442
|
-
if (SGR_RESET_REGEX.test(value)) {
|
|
1443
|
-
activeStyles = [];
|
|
1444
|
-
} else {
|
|
1445
|
-
activeStyles.push(value);
|
|
1446
|
-
}
|
|
1447
|
-
};
|
|
1448
|
-
let lastContentTokenIndex = -1;
|
|
1449
|
-
for (let i = tokens.length - 1; i >= 0; i -= 1) {
|
|
1450
|
-
if (tokens[i].kind !== "sgr") {
|
|
1451
|
-
lastContentTokenIndex = i;
|
|
1452
|
-
break;
|
|
1453
|
-
}
|
|
1454
|
-
}
|
|
1455
|
-
let plainCharIndexAtStart = 0;
|
|
1456
|
-
let start = 0;
|
|
1457
|
-
while (start < tokens.length) {
|
|
1458
|
-
if (start > lastContentTokenIndex && rows.length > 0) break;
|
|
1459
|
-
const openingStyles = [...activeStyles];
|
|
1460
|
-
const isContinuation = rows.length > 0;
|
|
1461
|
-
const currentPrefixWidth = isContinuation ? visibleWidth(hangingIndent) : prefixWidth;
|
|
1462
|
-
const indentWidth = isContinuation ? visibleWidth(hangingIndent) : 0;
|
|
1463
|
-
const maxSegmentWidth = Math.max(1, columns - indentWidth);
|
|
1464
|
-
let width = 0;
|
|
1465
|
-
let end = start;
|
|
1466
|
-
let lastBreak2 = -1;
|
|
1467
|
-
while (end < tokens.length) {
|
|
1468
|
-
const token = tokens[end];
|
|
1469
|
-
if (token.kind === "sgr") {
|
|
1470
|
-
end += 1;
|
|
1471
|
-
continue;
|
|
1472
|
-
}
|
|
1473
|
-
if (width + token.width > maxSegmentWidth && width > 0) break;
|
|
1474
|
-
width += token.width;
|
|
1475
|
-
end += 1;
|
|
1476
|
-
if ((token.value === " " || token.value === " ") && token.charIndex >= prefixCharCount) {
|
|
1477
|
-
lastBreak2 = end;
|
|
1478
|
-
}
|
|
1479
|
-
}
|
|
1480
|
-
let segmentEnd = end;
|
|
1481
|
-
if (end < tokens.length && lastBreak2 > start) {
|
|
1482
|
-
const overflowToken = tokens[end];
|
|
1483
|
-
if (overflowToken.kind === "char" && overflowToken.value !== " " && overflowToken.width === 1) {
|
|
1484
|
-
segmentEnd = lastBreak2;
|
|
1485
|
-
}
|
|
1486
|
-
}
|
|
1487
|
-
if (segmentEnd === start) segmentEnd = start + 1;
|
|
1488
|
-
let segment = "";
|
|
1489
|
-
let sawStyle = openingStyles.length > 0;
|
|
1490
|
-
for (let i = start; i < segmentEnd; i += 1) {
|
|
1491
|
-
const token = tokens[i];
|
|
1492
|
-
segment += token.value;
|
|
1493
|
-
if (token.kind === "sgr") {
|
|
1494
|
-
sawStyle = true;
|
|
1495
|
-
applyStyleToken(token.value);
|
|
1496
|
-
}
|
|
1497
|
-
}
|
|
1498
|
-
const prefix = openingStyles.join("");
|
|
1499
|
-
const needsReset = (sawStyle || activeStyles.length > 0) && !segment.endsWith("\x1B[0m");
|
|
1500
|
-
const lineContent = `${prefix}${segment}${needsReset ? "\x1B[0m" : ""}`;
|
|
1501
|
-
const rowRendered = isContinuation && hangingIndent.length > 0 ? `${hangingIndent}${lineContent}` : lineContent;
|
|
1502
|
-
let segSourceStart = lineSourceStart;
|
|
1503
|
-
let segSourceEnd = lineSourceStart;
|
|
1504
|
-
let foundFirst = false;
|
|
1505
|
-
const rowMapping = [];
|
|
1506
|
-
let plainCharIndex = plainCharIndexAtStart;
|
|
1507
|
-
for (let i = start; i < segmentEnd; i++) {
|
|
1508
|
-
const tok = tokens[i];
|
|
1509
|
-
if (tok.kind === "char" && tok.charIndex >= prefixCharCount) {
|
|
1510
|
-
const mappedOffset = sourceMapping && sourceMapping[plainCharIndex] !== void 0 ? sourceMapping[plainCharIndex] : plainCharIndex;
|
|
1511
|
-
if (!foundFirst) {
|
|
1512
|
-
segSourceStart = lineSourceStart + mappedOffset;
|
|
1513
|
-
foundFirst = true;
|
|
1514
|
-
}
|
|
1515
|
-
for (let c = 0; c < tok.value.length; c++) {
|
|
1516
|
-
const idx = plainCharIndex + c;
|
|
1517
|
-
const mapped = sourceMapping && sourceMapping[idx] !== void 0 ? sourceMapping[idx] : idx;
|
|
1518
|
-
rowMapping.push(lineSourceStart + mapped);
|
|
1519
|
-
}
|
|
1520
|
-
const lastCharIdx = plainCharIndex + tok.value.length - 1;
|
|
1521
|
-
const mappedEndOffset = sourceMapping && sourceMapping[lastCharIdx] !== void 0 ? sourceMapping[lastCharIdx] + 1 : plainCharIndex + tok.value.length;
|
|
1522
|
-
segSourceEnd = lineSourceStart + mappedEndOffset;
|
|
1523
|
-
plainCharIndex += tok.value.length;
|
|
1524
|
-
}
|
|
1525
|
-
}
|
|
1526
|
-
start = segmentEnd;
|
|
1527
|
-
let softWrapJoiner = "";
|
|
1528
|
-
while (start < tokens.length) {
|
|
1529
|
-
const token = tokens[start];
|
|
1530
|
-
if (token.kind === "char" && token.value === " " && token.charIndex >= prefixCharCount) {
|
|
1531
|
-
softWrapJoiner += token.value;
|
|
1532
|
-
const mappedOffset = sourceMapping && sourceMapping[plainCharIndex] !== void 0 ? sourceMapping[plainCharIndex] + 1 : plainCharIndex + 1;
|
|
1533
|
-
segSourceEnd = lineSourceStart + mappedOffset;
|
|
1534
|
-
plainCharIndex += token.value.length;
|
|
1535
|
-
start += 1;
|
|
1536
|
-
continue;
|
|
1537
|
-
}
|
|
1538
|
-
break;
|
|
1539
|
-
}
|
|
1540
|
-
if (start >= tokens.length && rawLineLength !== void 0) {
|
|
1541
|
-
segSourceEnd = lineSourceStart + rawLineLength;
|
|
1542
|
-
}
|
|
1543
|
-
plainCharIndexAtStart = plainCharIndex;
|
|
1544
|
-
rows.push({
|
|
1545
|
-
rendered: rowRendered,
|
|
1546
|
-
sourceStart: segSourceStart,
|
|
1547
|
-
sourceEnd: segSourceEnd,
|
|
1548
|
-
prefixWidth: currentPrefixWidth,
|
|
1549
|
-
sourceMapping: rowMapping.length > 0 ? rowMapping : void 0,
|
|
1550
|
-
softWrapped: start < tokens.length,
|
|
1551
|
-
softWrapJoiner
|
|
1552
|
-
});
|
|
1553
|
-
}
|
|
1554
|
-
return rows.length > 0 ? rows : [
|
|
1555
|
-
{
|
|
1556
|
-
rendered: "",
|
|
1557
|
-
sourceStart: lineSourceStart,
|
|
1558
|
-
sourceEnd: lineSourceStart + (rawLineLength ?? 0),
|
|
1559
|
-
prefixWidth
|
|
1560
|
-
}
|
|
1561
|
-
];
|
|
1562
|
-
}
|
|
1563
|
-
function wrapTranscriptLine(line, columns, hangingIndent = "") {
|
|
1564
|
-
return wrapTranscriptLineWithLayout(line, columns, hangingIndent).map((r) => r.rendered);
|
|
1565
|
-
}
|
|
1566
|
-
function buildWindowTitle(title) {
|
|
1567
|
-
const plain = stripAnsi2(title).replace(/[\x00-\x1f\x7f]+/g, " ");
|
|
1568
|
-
let truncated = "";
|
|
1569
|
-
let width = 0;
|
|
1570
|
-
const maxCols = 80;
|
|
1571
|
-
for (const char of plain) {
|
|
1572
|
-
const charWidth = displayWidth(char);
|
|
1573
|
-
if (width + charWidth > maxCols) break;
|
|
1574
|
-
truncated += char;
|
|
1575
|
-
width += charWidth;
|
|
1576
|
-
}
|
|
1577
|
-
return `\x1B]0;${truncated}\x07\x1B]2;${truncated}\x07`;
|
|
1578
|
-
}
|
|
1579
|
-
function wrapTextToLines(text, columns) {
|
|
1580
|
-
const result = [];
|
|
1581
|
-
for (const logicalLine of text.split("\n")) {
|
|
1582
|
-
if (logicalLine === "") {
|
|
1583
|
-
result.push("");
|
|
1584
|
-
continue;
|
|
1585
|
-
}
|
|
1586
|
-
let remaining = logicalLine;
|
|
1587
|
-
while (remaining.length > 0) {
|
|
1588
|
-
const { prefix, rest } = takeDisplayWidth(remaining, columns);
|
|
1589
|
-
result.push(prefix);
|
|
1590
|
-
remaining = rest;
|
|
1591
|
-
}
|
|
1592
|
-
}
|
|
1593
|
-
return result;
|
|
1594
|
-
}
|
|
1595
|
-
|
|
1596
1050
|
// packages/cli/tui/theme.ts
|
|
1597
1051
|
var THEME_PALETTES = {
|
|
1598
1052
|
trail: {
|
|
@@ -2991,7 +2445,7 @@ var WIDTHS = [
|
|
|
2991
2445
|
];
|
|
2992
2446
|
|
|
2993
2447
|
// node_modules/lovely-mermaid/dist/width.js
|
|
2994
|
-
var
|
|
2448
|
+
var segmenter = new Intl.Segmenter("en", { granularity: "grapheme" });
|
|
2995
2449
|
var VS16 = 65039;
|
|
2996
2450
|
var isRegionalIndicator = (cp) => cp >= 127462 && cp <= 127487;
|
|
2997
2451
|
function codePointWidth(cp) {
|
|
@@ -3026,12 +2480,12 @@ function clusterWidth(cluster) {
|
|
|
3026
2480
|
return vs16 || regional >= 2 ? 2 : w;
|
|
3027
2481
|
}
|
|
3028
2482
|
function* measured(s) {
|
|
3029
|
-
for (const { segment } of
|
|
2483
|
+
for (const { segment } of segmenter.segment(s))
|
|
3030
2484
|
yield [segment, clusterWidth(segment)];
|
|
3031
2485
|
}
|
|
3032
|
-
function
|
|
2486
|
+
function stringWidth(s) {
|
|
3033
2487
|
let w = 0;
|
|
3034
|
-
for (const { segment } of
|
|
2488
|
+
for (const { segment } of segmenter.segment(s))
|
|
3035
2489
|
w += clusterWidth(segment);
|
|
3036
2490
|
return w;
|
|
3037
2491
|
}
|
|
@@ -3228,7 +2682,7 @@ function wrapLabel(label, width, maxLines) {
|
|
|
3228
2682
|
let cur = "";
|
|
3229
2683
|
let curW = 0;
|
|
3230
2684
|
for (const word of label.split(/\s+/).filter((w) => w !== "")) {
|
|
3231
|
-
const ww =
|
|
2685
|
+
const ww = stringWidth(word);
|
|
3232
2686
|
if (ww > width) {
|
|
3233
2687
|
if (cur !== "") {
|
|
3234
2688
|
lines.push(cur);
|
|
@@ -3242,7 +2696,7 @@ function wrapLabel(label, width, maxLines) {
|
|
|
3242
2696
|
const carry = p === -1 ? "" : chunk.slice(p + 1);
|
|
3243
2697
|
lines.push(p === -1 ? chunk : chunk.slice(0, p + 1));
|
|
3244
2698
|
chunk = carry;
|
|
3245
|
-
chunkW =
|
|
2699
|
+
chunkW = stringWidth(carry);
|
|
3246
2700
|
}
|
|
3247
2701
|
chunk += ch;
|
|
3248
2702
|
chunkW += cw;
|
|
@@ -3281,7 +2735,7 @@ function wrapLabel(label, width, maxLines) {
|
|
|
3281
2735
|
return lines;
|
|
3282
2736
|
}
|
|
3283
2737
|
function fitLabel(label, inner) {
|
|
3284
|
-
if (
|
|
2738
|
+
if (stringWidth(label) <= inner)
|
|
3285
2739
|
return label;
|
|
3286
2740
|
let out = "";
|
|
3287
2741
|
let used = 0;
|
|
@@ -4073,7 +3527,7 @@ function placeTd(ranks, maxRank, byRank, sizes, graph, placed) {
|
|
|
4073
3527
|
const edgeLabelLeft = new Array(graph.edges.length).fill(false);
|
|
4074
3528
|
const labelW = (e) => {
|
|
4075
3529
|
const parts = [e.label, e.cardTo].filter((p) => p != null);
|
|
4076
|
-
return parts.length === 0 ? -1 : Math.max(...parts.map((p) => Math.min(
|
|
3530
|
+
return parts.length === 0 ? -1 : Math.max(...parts.map((p) => Math.min(stringWidth(p), MAX_LABEL)));
|
|
4077
3531
|
};
|
|
4078
3532
|
const skipsInto = graph.nodes.map(() => []);
|
|
4079
3533
|
const fwdsInto = graph.nodes.map(() => []);
|
|
@@ -4241,21 +3695,21 @@ function placeTd(ranks, maxRank, byRank, sizes, graph, placed) {
|
|
|
4241
3695
|
if (ranks[e.to] === ranks[e.from] + 1) {
|
|
4242
3696
|
const parts = [e.label, e.cardTo].filter((part) => part != null);
|
|
4243
3697
|
for (const part of parts) {
|
|
4244
|
-
const lw = Math.min(
|
|
3698
|
+
const lw = Math.min(stringWidth(part), MAX_LABEL);
|
|
4245
3699
|
contentW = Math.max(contentW, placed[e.to].cx + 2 + lw);
|
|
4246
3700
|
}
|
|
4247
3701
|
if (e.cardFrom !== void 0) {
|
|
4248
|
-
contentW = Math.max(contentW, placed[e.from].cx + 2 +
|
|
3702
|
+
contentW = Math.max(contentW, placed[e.from].cx + 2 + stringWidth(e.cardFrom));
|
|
4249
3703
|
}
|
|
4250
3704
|
} else if (isAdjacentBack(ranks, e)) {
|
|
4251
3705
|
const text = edgeText(e);
|
|
4252
3706
|
if (text !== null) {
|
|
4253
|
-
contentW = Math.max(contentW, placed[e.to].cx + 2 + Math.min(
|
|
3707
|
+
contentW = Math.max(contentW, placed[e.to].cx + 2 + Math.min(stringWidth(text), MAX_LABEL));
|
|
4254
3708
|
}
|
|
4255
3709
|
} else {
|
|
4256
3710
|
const text = edgeText(e);
|
|
4257
3711
|
if (text !== null) {
|
|
4258
|
-
contentW = Math.max(contentW, diagramW + Math.min(
|
|
3712
|
+
contentW = Math.max(contentW, diagramW + Math.min(stringWidth(text), MAX_LABEL) + 1);
|
|
4259
3713
|
}
|
|
4260
3714
|
}
|
|
4261
3715
|
}
|
|
@@ -4309,8 +3763,8 @@ function placeLr(ranks, maxRank, byRank, sizes, graph, placed) {
|
|
|
4309
3763
|
return;
|
|
4310
3764
|
if (ranks[e.to] !== ranks[e.from] + 1 && !edgeStraight[i])
|
|
4311
3765
|
return;
|
|
4312
|
-
const verb = e.label === null ? 0 : Math.min(
|
|
4313
|
-
const cards = [e.cardFrom, e.cardTo].filter((c) => c !== void 0).reduce((w, c) => w +
|
|
3766
|
+
const verb = e.label === null ? 0 : Math.min(stringWidth(e.label), MAX_LABEL);
|
|
3767
|
+
const cards = [e.cardFrom, e.cardTo].filter((c) => c !== void 0).reduce((w, c) => w + stringWidth(c) + 1, 0);
|
|
4314
3768
|
bandLabel[ranks[e.from]] = Math.max(bandLabel[ranks[e.from]], verb + cards);
|
|
4315
3769
|
});
|
|
4316
3770
|
const edgeBus = new Array(graph.edges.length).fill(0);
|
|
@@ -4421,10 +3875,10 @@ function layoutCanvas(graph, extras) {
|
|
|
4421
3875
|
for (const row of byRank)
|
|
4422
3876
|
row.sort((a, b) => Number(inLane[a]) - Number(inLane[b]));
|
|
4423
3877
|
const wrapped = graph.nodes.map((node) => wrapLabel(node.label, WRAP_WIDTH, MAX_LINES));
|
|
4424
|
-
const widest = (lines) => Math.max(1, lines.length === 0 ? 1 : Math.max(...lines.map(
|
|
3878
|
+
const widest = (lines) => Math.max(1, lines.length === 0 ? 1 : Math.max(...lines.map(stringWidth)));
|
|
4425
3879
|
const boxW = extras.map((extra, i) => {
|
|
4426
3880
|
if (extra.kind === "frame") {
|
|
4427
|
-
return Math.max(extra.sub.w + 2,
|
|
3881
|
+
return Math.max(extra.sub.w + 2, stringWidth(fitLabel(graph.nodes[i].label, WRAP_WIDTH)) + 4);
|
|
4428
3882
|
}
|
|
4429
3883
|
if (extra.kind === "compartments")
|
|
4430
3884
|
return widest(extra.sections.flat()) + 2 * PAD + 2;
|
|
@@ -4447,7 +3901,7 @@ function layoutCanvas(graph, extras) {
|
|
|
4447
3901
|
extraH[e.from] = 2;
|
|
4448
3902
|
const text = edgeText(e);
|
|
4449
3903
|
if (text !== null) {
|
|
4450
|
-
selfLabelW[e.from] = Math.max(selfLabelW[e.from], Math.min(
|
|
3904
|
+
selfLabelW[e.from] = Math.max(selfLabelW[e.from], Math.min(stringWidth(text), MAX_LABEL));
|
|
4451
3905
|
}
|
|
4452
3906
|
}
|
|
4453
3907
|
for (let i = 0; i < n; i++)
|
|
@@ -4713,7 +4167,7 @@ function drawBox(canvas, p, lines, shape, mirrored = false) {
|
|
|
4713
4167
|
const ordered = mirrored ? [...lines].reverse() : lines;
|
|
4714
4168
|
ordered.forEach((line, li) => {
|
|
4715
4169
|
const text = fitLabel(line, inner);
|
|
4716
|
-
const textX = x + 1 + PAD + half(sat(inner,
|
|
4170
|
+
const textX = x + 1 + PAD + half(sat(inner, stringWidth(text)));
|
|
4717
4171
|
drawText(canvas, text, textX, y + 1 + li, "text");
|
|
4718
4172
|
});
|
|
4719
4173
|
}
|
|
@@ -4739,7 +4193,7 @@ function drawClassBox(canvas, p, sections, mirrored = false) {
|
|
|
4739
4193
|
canvas.set(x, row, "\u2500", "border");
|
|
4740
4194
|
canvas.set(p.x + p.w - 1, row, "\u2524", "border");
|
|
4741
4195
|
} else {
|
|
4742
|
-
const tx = r.center ? p.x + 1 + PAD + half(sat(inner,
|
|
4196
|
+
const tx = r.center ? p.x + 1 + PAD + half(sat(inner, stringWidth(r.text))) : p.x + 1 + PAD;
|
|
4743
4197
|
drawTextOverEdges(canvas, r.text, tx, row, "text");
|
|
4744
4198
|
}
|
|
4745
4199
|
});
|
|
@@ -4789,7 +4243,7 @@ function routeForward(canvas, from, to, edge, bus, entryX = -1, labelLeft = fals
|
|
|
4789
4243
|
canvas.set(bx, by, headGlyph(edge.headFrom, "\u25B2"), "edge");
|
|
4790
4244
|
if (edge.cardFrom === void 0 && edge.cardTo === void 0) {
|
|
4791
4245
|
if (edge.label !== null) {
|
|
4792
|
-
const start = labelLeft ? sat(tx, Math.min(
|
|
4246
|
+
const start = labelLeft ? sat(tx, Math.min(stringWidth(edge.label), MAX_LABEL)) : tx + 1;
|
|
4793
4247
|
placeLabel(canvas, edge.label, headRow, start);
|
|
4794
4248
|
}
|
|
4795
4249
|
return;
|
|
@@ -4805,7 +4259,7 @@ function routeForward(canvas, from, to, edge, bus, entryX = -1, labelLeft = fals
|
|
|
4805
4259
|
const lineX = midRow > bus ? tx : bx;
|
|
4806
4260
|
placeLabel(canvas, edge.label, midRow, lineX + 1);
|
|
4807
4261
|
} else {
|
|
4808
|
-
placeLabel(canvas, edge.label, headRow, tx + 1 + (edge.cardTo === void 0 ? 0 :
|
|
4262
|
+
placeLabel(canvas, edge.label, headRow, tx + 1 + (edge.cardTo === void 0 ? 0 : stringWidth(edge.cardTo) + 1));
|
|
4809
4263
|
}
|
|
4810
4264
|
}
|
|
4811
4265
|
}
|
|
@@ -4874,7 +4328,7 @@ function routeSkip(canvas, from, to, edge, at) {
|
|
|
4874
4328
|
canvas.set(bx, bottom, headGlyph(edge.headFrom, "\u25B2"), "edge");
|
|
4875
4329
|
const text = edgeText(edge);
|
|
4876
4330
|
if (text !== null) {
|
|
4877
|
-
const start = labelLeft ? sat(entryX, Math.min(
|
|
4331
|
+
const start = labelLeft ? sat(entryX, Math.min(stringWidth(text), MAX_LABEL)) : entryX + 1;
|
|
4878
4332
|
placeLabel(canvas, text, to.y - 1, start);
|
|
4879
4333
|
}
|
|
4880
4334
|
}
|
|
@@ -4895,7 +4349,7 @@ function routeBack(canvas, from, to, edge, laneX) {
|
|
|
4895
4349
|
else
|
|
4896
4350
|
canvas.set(tx + 1, tyc, headGlyph(edge.headTo, "\u25C4"), "edge");
|
|
4897
4351
|
if (backText !== null) {
|
|
4898
|
-
placeLabel(canvas, backText, sat(tyc, 1), sat(laneX,
|
|
4352
|
+
placeLabel(canvas, backText, sat(tyc, 1), sat(laneX, stringWidth(backText) + 1));
|
|
4899
4353
|
}
|
|
4900
4354
|
}
|
|
4901
4355
|
function routeForwardLr(canvas, from, to, edge, bus) {
|
|
@@ -4922,7 +4376,7 @@ function routeForwardLr(canvas, from, to, edge, bus) {
|
|
|
4922
4376
|
if (edge.cardFrom !== void 0)
|
|
4923
4377
|
placeLabel(canvas, edge.cardFrom, sat(ry, 1), rx + 1);
|
|
4924
4378
|
if (edge.cardTo !== void 0) {
|
|
4925
|
-
placeLabel(canvas, edge.cardTo, sat(ly, 1), sat(headCol,
|
|
4379
|
+
placeLabel(canvas, edge.cardTo, sat(ly, 1), sat(headCol, stringWidth(edge.cardTo)));
|
|
4926
4380
|
}
|
|
4927
4381
|
}
|
|
4928
4382
|
function routeSkipLr(canvas, from, to, edge, bus) {
|
|
@@ -4972,7 +4426,7 @@ function routeBackLr(canvas, from, to, edge, laneY, laneLabels) {
|
|
|
4972
4426
|
}
|
|
4973
4427
|
function placeLaneLabels(canvas, labels) {
|
|
4974
4428
|
for (const { text, y, lo, hi } of labels) {
|
|
4975
|
-
const tw =
|
|
4429
|
+
const tw = stringWidth(text);
|
|
4976
4430
|
const lastStart = hi - 1 - tw;
|
|
4977
4431
|
if (lastStart < lo + 1 || y >= canvas.h)
|
|
4978
4432
|
continue;
|
|
@@ -5482,10 +4936,10 @@ function parseEr(src) {
|
|
|
5482
4936
|
}
|
|
5483
4937
|
const rel = splitErRelationship(st);
|
|
5484
4938
|
if (rel) {
|
|
5485
|
-
const
|
|
5486
|
-
const op =
|
|
5487
|
-
const f = op === null ? null : erEntity(graph,
|
|
5488
|
-
const t2 = f === null ? null : erEntity(graph,
|
|
4939
|
+
const tokens2 = erTokens(rel.rel);
|
|
4940
|
+
const op = tokens2.length === 3 ? parseErOp(tokens2[1]) : null;
|
|
4941
|
+
const f = op === null ? null : erEntity(graph, tokens2[0]);
|
|
4942
|
+
const t2 = f === null ? null : erEntity(graph, tokens2[2]);
|
|
5489
4943
|
if (op === null || f === null || t2 === null) {
|
|
5490
4944
|
graph.drop(st);
|
|
5491
4945
|
} else {
|
|
@@ -6070,7 +5524,7 @@ var gitgraph = {
|
|
|
6070
5524
|
parts.push([`\u21D0 ${branches[c.mergeFrom]}`, "edgeLabel"]);
|
|
6071
5525
|
return parts;
|
|
6072
5526
|
});
|
|
6073
|
-
const width = graphW + Math.max(1, ...labels.map((parts) => parts === null ? 0 : parts.reduce((w, [t2]) => w +
|
|
5527
|
+
const width = graphW + Math.max(1, ...labels.map((parts) => parts === null ? 0 : parts.reduce((w, [t2]) => w + stringWidth(t2) + 1, 0) - 1));
|
|
6074
5528
|
const canvas = new Canvas(width, rows.length);
|
|
6075
5529
|
const live = /* @__PURE__ */ new Set();
|
|
6076
5530
|
rows.forEach((row, y) => {
|
|
@@ -6085,7 +5539,7 @@ var gitgraph = {
|
|
|
6085
5539
|
let x = graphW;
|
|
6086
5540
|
for (const [text, role] of labels[y] ?? []) {
|
|
6087
5541
|
drawText(canvas, text, x, y, role);
|
|
6088
|
-
x +=
|
|
5542
|
+
x += stringWidth(text) + 1;
|
|
6089
5543
|
}
|
|
6090
5544
|
return;
|
|
6091
5545
|
}
|
|
@@ -6216,11 +5670,11 @@ var mindmap = {
|
|
|
6216
5670
|
};
|
|
6217
5671
|
for (const root of roots)
|
|
6218
5672
|
walk(root, "", "");
|
|
6219
|
-
const width = Math.max(...rows.map(([p, t2]) =>
|
|
5673
|
+
const width = Math.max(...rows.map(([p, t2]) => stringWidth(p) + stringWidth(t2)));
|
|
6220
5674
|
const canvas = new Canvas(width, rows.length);
|
|
6221
5675
|
rows.forEach(([prefix, text], y) => {
|
|
6222
5676
|
drawText(canvas, prefix, 0, y, "edge");
|
|
6223
|
-
drawText(canvas, text,
|
|
5677
|
+
drawText(canvas, text, stringWidth(prefix), y, "text");
|
|
6224
5678
|
});
|
|
6225
5679
|
return { canvas, warnings, classDefs: {} };
|
|
6226
5680
|
}
|
|
@@ -6295,7 +5749,7 @@ var pie = {
|
|
|
6295
5749
|
if (parsed === null)
|
|
6296
5750
|
return null;
|
|
6297
5751
|
const { title, slices, showData, warnings } = parsed;
|
|
6298
|
-
const labelW = Math.max(...slices.map((s) =>
|
|
5752
|
+
const labelW = Math.max(...slices.map((s) => stringWidth(s.label)));
|
|
6299
5753
|
const total = slices.reduce((sum, s) => sum + s.value, 0);
|
|
6300
5754
|
const rows = slices.map((s) => {
|
|
6301
5755
|
const share = total === 0 ? 0 : s.value / total;
|
|
@@ -6305,11 +5759,11 @@ var pie = {
|
|
|
6305
5759
|
});
|
|
6306
5760
|
const barX = labelW + 2;
|
|
6307
5761
|
const suffixX = barX + BAR_W + 1;
|
|
6308
|
-
const width = suffixX + Math.max(...rows.map((r) =>
|
|
5762
|
+
const width = suffixX + Math.max(...rows.map((r) => stringWidth(r.suffix)));
|
|
6309
5763
|
const top = title === null ? 0 : 1;
|
|
6310
5764
|
const canvas = new Canvas(width, top + rows.length);
|
|
6311
5765
|
if (title !== null) {
|
|
6312
|
-
drawText(canvas, title, Math.max(0, Math.floor((width -
|
|
5766
|
+
drawText(canvas, title, Math.max(0, Math.floor((width - stringWidth(title)) / 2)), 0, "title");
|
|
6313
5767
|
}
|
|
6314
5768
|
rows.forEach((r, i) => {
|
|
6315
5769
|
const y = top + i;
|
|
@@ -6319,7 +5773,7 @@ var pie = {
|
|
|
6319
5773
|
if (bar === "" && r.value > 0)
|
|
6320
5774
|
bar = "\u258F";
|
|
6321
5775
|
drawText(canvas, bar, barX, y, "edge");
|
|
6322
|
-
drawText(canvas, "\u2591".repeat(BAR_W -
|
|
5776
|
+
drawText(canvas, "\u2591".repeat(BAR_W - stringWidth(bar)), barX + stringWidth(bar), y, "border");
|
|
6323
5777
|
drawText(canvas, r.suffix, suffixX, y, "edgeLabel");
|
|
6324
5778
|
});
|
|
6325
5779
|
return { canvas, warnings, classDefs: {} };
|
|
@@ -6383,11 +5837,11 @@ function noteGeometry(xs, anchor, textW) {
|
|
|
6383
5837
|
return { x: sat(xs[anchor.at], 2 + w - 1), w };
|
|
6384
5838
|
return { x: xs[anchor.at] + 2, w };
|
|
6385
5839
|
}
|
|
6386
|
-
var itemTextW = (text) => text === null ? 0 :
|
|
5840
|
+
var itemTextW = (text) => text === null ? 0 : stringWidth(text);
|
|
6387
5841
|
function layoutSequence(seq) {
|
|
6388
5842
|
const n = seq.labels.length;
|
|
6389
5843
|
const labels = seq.labels.map((l) => fitLabel(l, WRAP_WIDTH));
|
|
6390
|
-
const boxW = labels.map((l) => Math.max(1,
|
|
5844
|
+
const boxW = labels.map((l) => Math.max(1, stringWidth(l)) + 2 * PAD + 2);
|
|
6391
5845
|
const boxH = 3;
|
|
6392
5846
|
const gaps = Array.from({ length: sat(n, 1) }, (_, i) => Math.max(SEQ_GAP, Math.ceil(boxW[i] / 2) + Math.ceil(boxW[i + 1] / 2) + 1));
|
|
6393
5847
|
const reqs = [];
|
|
@@ -6400,7 +5854,7 @@ function layoutSequence(seq) {
|
|
|
6400
5854
|
reqs.push([item.from, item.from + 1, 5 + tw + 2]);
|
|
6401
5855
|
}
|
|
6402
5856
|
} else if (item.kind === "note") {
|
|
6403
|
-
const tw =
|
|
5857
|
+
const tw = stringWidth(item.text);
|
|
6404
5858
|
const a = item.anchor;
|
|
6405
5859
|
if (a.kind === "over" && a.from < a.to) {
|
|
6406
5860
|
reqs.push([a.from, a.to, sat(tw, 1)]);
|
|
@@ -6432,7 +5886,7 @@ function layoutSequence(seq) {
|
|
|
6432
5886
|
let leftPad = 0;
|
|
6433
5887
|
for (const item of seq.items) {
|
|
6434
5888
|
if (item.kind === "note" && item.anchor.kind === "left" && item.anchor.at === 0) {
|
|
6435
|
-
const w =
|
|
5889
|
+
const w = stringWidth(item.text) + 2 * PAD + 2;
|
|
6436
5890
|
leftPad = Math.max(leftPad, sat(w + 1, xs[0]));
|
|
6437
5891
|
}
|
|
6438
5892
|
}
|
|
@@ -6444,10 +5898,10 @@ function layoutSequence(seq) {
|
|
|
6444
5898
|
if (item.kind === "message" && item.from === item.to) {
|
|
6445
5899
|
canvasW = Math.max(canvasW, xs[item.from] + 5 + itemTextW(item.text) + 1);
|
|
6446
5900
|
} else if (item.kind === "note") {
|
|
6447
|
-
const g = noteGeometry(xs, item.anchor,
|
|
5901
|
+
const g = noteGeometry(xs, item.anchor, stringWidth(item.text));
|
|
6448
5902
|
canvasW = Math.max(canvasW, g.x + g.w + 1);
|
|
6449
5903
|
} else if (item.kind === "divider") {
|
|
6450
|
-
canvasW = Math.max(canvasW,
|
|
5904
|
+
canvasW = Math.max(canvasW, stringWidth(item.text) + 4);
|
|
6451
5905
|
}
|
|
6452
5906
|
}
|
|
6453
5907
|
const rows = [];
|
|
@@ -6469,7 +5923,7 @@ function layoutSequence(seq) {
|
|
|
6469
5923
|
seq.items.forEach((item, k) => {
|
|
6470
5924
|
if (item.kind !== "note")
|
|
6471
5925
|
return;
|
|
6472
|
-
const g = noteGeometry(xs, item.anchor,
|
|
5926
|
+
const g = noteGeometry(xs, item.anchor, stringWidth(item.text));
|
|
6473
5927
|
drawBox(canvas, box(g.x, rows[k], g.w, 3), [item.text], "rect");
|
|
6474
5928
|
});
|
|
6475
5929
|
for (const x of xs) {
|
|
@@ -6552,7 +6006,7 @@ function drawMessage(canvas, item, xs, r) {
|
|
|
6552
6006
|
if (item.text !== null) {
|
|
6553
6007
|
const span = hi - lo - 1;
|
|
6554
6008
|
const t2 = fitLabel(item.text, Math.max(1, span));
|
|
6555
|
-
drawTextOverEdges(canvas, t2, lo + 1 + half(sat(span,
|
|
6009
|
+
drawTextOverEdges(canvas, t2, lo + 1 + half(sat(span, stringWidth(t2))), r, "text");
|
|
6556
6010
|
}
|
|
6557
6011
|
}
|
|
6558
6012
|
function drawDivider(canvas, text, r, canvasW) {
|
|
@@ -7052,16 +6506,16 @@ var timeline = {
|
|
|
7052
6506
|
if (parsed === null)
|
|
7053
6507
|
return null;
|
|
7054
6508
|
const { title, rows, warnings } = parsed;
|
|
7055
|
-
const periodW = Math.max(...rows.map((r) => r.section ? 0 :
|
|
6509
|
+
const periodW = Math.max(...rows.map((r) => r.section ? 0 : stringWidth(r.period)));
|
|
7056
6510
|
const top = title === null ? 0 : 1;
|
|
7057
|
-
const width = Math.max(title === null ? 0 :
|
|
6511
|
+
const width = Math.max(title === null ? 0 : stringWidth(title) + 6, ...rows.map((r) => r.section ? stringWidth(r.event) : periodW + 3 + stringWidth(r.event)));
|
|
7058
6512
|
const canvas = new Canvas(width, top + rows.length);
|
|
7059
6513
|
if (title !== null) {
|
|
7060
6514
|
const t2 = ` ${title} `;
|
|
7061
|
-
const x = Math.max(0, Math.floor((width -
|
|
6515
|
+
const x = Math.max(0, Math.floor((width - stringWidth(t2) - 4) / 2));
|
|
7062
6516
|
drawText(canvas, "\u2500\u2500", x, 0, "edge");
|
|
7063
6517
|
drawText(canvas, t2, x + 2, 0, "title");
|
|
7064
|
-
drawText(canvas, "\u2500\u2500", x + 2 +
|
|
6518
|
+
drawText(canvas, "\u2500\u2500", x + 2 + stringWidth(t2), 0, "edge");
|
|
7065
6519
|
}
|
|
7066
6520
|
rows.forEach((row, i) => {
|
|
7067
6521
|
const y = top + i;
|
|
@@ -7388,11 +6842,11 @@ function sourceBox(src, maxWidth) {
|
|
|
7388
6842
|
acc.lines.push(...chunkLine(l, limit));
|
|
7389
6843
|
return acc;
|
|
7390
6844
|
}, { started: false, lines: [] }).lines;
|
|
7391
|
-
const contentW = body.reduce((w, l) => Math.max(w,
|
|
6845
|
+
const contentW = body.reduce((w, l) => Math.max(w, stringWidth(l)), stringWidth(title));
|
|
7392
6846
|
const inner = contentW + 2;
|
|
7393
6847
|
const plain = [];
|
|
7394
6848
|
const styled = [];
|
|
7395
|
-
const rule = "\u2500".repeat(sat(inner,
|
|
6849
|
+
const rule = "\u2500".repeat(sat(inner, stringWidth(title)));
|
|
7396
6850
|
plain.push(`\u256D${title}${rule}\u256E`);
|
|
7397
6851
|
styled.push([
|
|
7398
6852
|
{ text: "\u256D", role: "border" },
|
|
@@ -7400,7 +6854,7 @@ function sourceBox(src, maxWidth) {
|
|
|
7400
6854
|
{ text: `${rule}\u256E`, role: "border" }
|
|
7401
6855
|
]);
|
|
7402
6856
|
for (const line of body) {
|
|
7403
|
-
const pad = " ".repeat(sat(contentW,
|
|
6857
|
+
const pad = " ".repeat(sat(contentW, stringWidth(line)));
|
|
7404
6858
|
plain.push(`\u2502 ${line}${pad} \u2502`);
|
|
7405
6859
|
styled.push([
|
|
7406
6860
|
{ text: "\u2502 ", role: "border" },
|
|
@@ -7431,7 +6885,7 @@ function expandTabs(line) {
|
|
|
7431
6885
|
return out;
|
|
7432
6886
|
}
|
|
7433
6887
|
function chunkLine(line, limit) {
|
|
7434
|
-
if (limit === void 0 ||
|
|
6888
|
+
if (limit === void 0 || stringWidth(line) <= limit)
|
|
7435
6889
|
return [line];
|
|
7436
6890
|
const out = [];
|
|
7437
6891
|
let cur = "";
|
|
@@ -7461,7 +6915,7 @@ function render(src) {
|
|
|
7461
6915
|
const art = drawn.canvas.toLines();
|
|
7462
6916
|
const title = frontmatterTitle(src);
|
|
7463
6917
|
if (title !== null) {
|
|
7464
|
-
const tw =
|
|
6918
|
+
const tw = stringWidth(title);
|
|
7465
6919
|
art.width = Math.max(art.width, tw);
|
|
7466
6920
|
const pad = " ".repeat(Math.floor((art.width - tw) / 2));
|
|
7467
6921
|
art.plain.unshift(pad + title, "");
|
|
@@ -7930,7 +7384,7 @@ function renderMathBlock(latex, options = {}) {
|
|
|
7930
7384
|
const den = transpileLatexToUnicode(fracMatch[2] ?? "");
|
|
7931
7385
|
if (num.length > 8 || den.length > 8 || num.includes("+") || den.includes("+") || num.includes("-") || den.includes("-")) {
|
|
7932
7386
|
const width = Math.max(visibleWidth(num), visibleWidth(den)) + 2;
|
|
7933
|
-
const bar =
|
|
7387
|
+
const bar = boxGlyphs(resolveBoxCharset()).h.repeat(width);
|
|
7934
7388
|
const padNum = " ".repeat(Math.max(0, Math.floor((width - visibleWidth(num)) / 2)));
|
|
7935
7389
|
const padDen = " ".repeat(Math.max(0, Math.floor((width - visibleWidth(den)) / 2)));
|
|
7936
7390
|
const l1 = padNum + num;
|
|
@@ -8177,21 +7631,21 @@ function resolveTableWidth(explicit, env = process.env) {
|
|
|
8177
7631
|
}
|
|
8178
7632
|
function wrapCellToWidth(text, max) {
|
|
8179
7633
|
if (max <= 0 || displayWidth(text) <= max) return [text];
|
|
8180
|
-
const
|
|
7634
|
+
const tokens2 = tokenizeAnsiLine(text);
|
|
8181
7635
|
const charTokenIdx = [];
|
|
8182
|
-
|
|
7636
|
+
tokens2.forEach((t2, i) => {
|
|
8183
7637
|
if (t2.kind === "char") charTokenIdx.push(i);
|
|
8184
7638
|
});
|
|
8185
7639
|
const n = charTokenIdx.length;
|
|
8186
7640
|
if (n === 0) return [text];
|
|
8187
|
-
const widths = charTokenIdx.map((i) =>
|
|
7641
|
+
const widths = charTokenIdx.map((i) => tokens2[i].width);
|
|
8188
7642
|
const prefix = [0];
|
|
8189
7643
|
for (let i = 0; i < widths.length; i += 1) prefix.push(prefix[i] + widths[i]);
|
|
8190
7644
|
const segWidth = (a, b) => prefix[b] - prefix[a];
|
|
8191
7645
|
const sliceTokens = (a, b) => {
|
|
8192
7646
|
const startTok = a === 0 ? 0 : charTokenIdx[a - 1] + 1;
|
|
8193
|
-
const endTok = b < n ? charTokenIdx[b] - 1 :
|
|
8194
|
-
return
|
|
7647
|
+
const endTok = b < n ? charTokenIdx[b] - 1 : tokens2.length - 1;
|
|
7648
|
+
return tokens2.slice(startTok, endTok + 1);
|
|
8195
7649
|
};
|
|
8196
7650
|
const applyStyles = (slice, state2) => {
|
|
8197
7651
|
const next = [...state2];
|
|
@@ -8206,7 +7660,7 @@ function wrapCellToWidth(text, max) {
|
|
|
8206
7660
|
}
|
|
8207
7661
|
} else if (OSC8_OPENER_REGEX.test(t2.value)) {
|
|
8208
7662
|
next.push(t2.value);
|
|
8209
|
-
} else if (
|
|
7663
|
+
} else if (SGR_RESET_REGEX.test(t2.value)) {
|
|
8210
7664
|
for (let i = next.length - 1; i >= 0; i -= 1) {
|
|
8211
7665
|
if (!OSC8_OPENER_REGEX.test(next[i]) && !OSC8_CLOSER_REGEX.test(next[i])) {
|
|
8212
7666
|
next.splice(i, 1);
|
|
@@ -8238,7 +7692,7 @@ function wrapCellToWidth(text, max) {
|
|
|
8238
7692
|
if (segWidth(start, i + 1) <= max) continue;
|
|
8239
7693
|
let cut = -1;
|
|
8240
7694
|
for (let j = i - 1; j > start; j -= 1) {
|
|
8241
|
-
if (
|
|
7695
|
+
if (tokens2[charTokenIdx[j]].value !== " ") continue;
|
|
8242
7696
|
if (segWidth(start, j) <= max && segWidth(j + 1, i + 1) <= max) {
|
|
8243
7697
|
cut = j;
|
|
8244
7698
|
break;
|
|
@@ -8269,7 +7723,7 @@ function wrapCellToWidth(text, max) {
|
|
|
8269
7723
|
}
|
|
8270
7724
|
return segments.length > 0 ? segments : [text];
|
|
8271
7725
|
}
|
|
8272
|
-
var
|
|
7726
|
+
var SGR_RESET_REGEX = /^\x1b\[0?m$/;
|
|
8273
7727
|
var OSC8_OPENER_REGEX = /^\x1b\]8;;[^\x07\x1b]+(?:\x07|\x1b\\)$/;
|
|
8274
7728
|
var OSC8_CLOSER_REGEX = /^\x1b\]8;;\x1b\\$/;
|
|
8275
7729
|
function padCell(text, width, align) {
|
|
@@ -8324,21 +7778,22 @@ function makeStyle(brightness, headerToken) {
|
|
|
8324
7778
|
const paint = (t2) => `${color}${boldOn}${t2}${reset}`;
|
|
8325
7779
|
return { header: paint, label: paint };
|
|
8326
7780
|
}
|
|
8327
|
-
function boxLine(left, mid, right, widths) {
|
|
8328
|
-
const seg = widths.map((w) =>
|
|
7781
|
+
function boxLine(glyphs, left, mid, right, widths) {
|
|
7782
|
+
const seg = widths.map((w) => glyphs.h.repeat(w + 2));
|
|
8329
7783
|
return `${left}${seg.join(mid)}${right}`;
|
|
8330
7784
|
}
|
|
8331
|
-
function dataRow(cells, aligns, widths, style, header) {
|
|
7785
|
+
function dataRow(cells, aligns, widths, style, header, glyphs) {
|
|
8332
7786
|
const parts = cells.map((cell, i) => {
|
|
8333
7787
|
const width = widths[i] ?? 0;
|
|
8334
7788
|
const align = aligns[i] ?? "left";
|
|
8335
7789
|
const padded = padCell(cell, width, align);
|
|
8336
7790
|
const styled = header ? style.header(padded) : padded;
|
|
8337
|
-
return ` ${styled}
|
|
7791
|
+
return ` ${styled} ${glyphs.v}`;
|
|
8338
7792
|
});
|
|
8339
|
-
return
|
|
7793
|
+
return `${glyphs.v}${parts.join("")}`;
|
|
8340
7794
|
}
|
|
8341
|
-
function renderBoxTable(table, width, style) {
|
|
7795
|
+
function renderBoxTable(table, width, style, charset = resolveBoxCharset()) {
|
|
7796
|
+
const glyphs = boxGlyphs(charset);
|
|
8342
7797
|
const colCount = table.headers.length;
|
|
8343
7798
|
const widths = computeColumnWidths(table.headers, table.rows, width);
|
|
8344
7799
|
const headerGrid = table.headers.map(
|
|
@@ -8352,7 +7807,7 @@ function renderBoxTable(table, width, style) {
|
|
|
8352
7807
|
(r) => Math.max(1, ...r.map((g) => g.length))
|
|
8353
7808
|
);
|
|
8354
7809
|
const lines = [];
|
|
8355
|
-
lines.push(boxLine(
|
|
7810
|
+
lines.push(boxLine(glyphs, glyphs.tl, glyphs.tm, glyphs.tr, widths));
|
|
8356
7811
|
for (let r = 0; r < headerDisplayRows; r += 1) {
|
|
8357
7812
|
lines.push(
|
|
8358
7813
|
dataRow(
|
|
@@ -8360,15 +7815,16 @@ function renderBoxTable(table, width, style) {
|
|
|
8360
7815
|
table.aligns,
|
|
8361
7816
|
widths,
|
|
8362
7817
|
style,
|
|
8363
|
-
true
|
|
7818
|
+
true,
|
|
7819
|
+
glyphs
|
|
8364
7820
|
)
|
|
8365
7821
|
);
|
|
8366
7822
|
}
|
|
8367
|
-
lines.push(boxLine(
|
|
7823
|
+
lines.push(boxLine(glyphs, glyphs.ml, glyphs.mm, glyphs.mr, widths));
|
|
8368
7824
|
const hasMultiLineRecord = bodyDisplayRows.some((rows) => rows > 1);
|
|
8369
7825
|
bodyGrids.forEach((_, rec) => {
|
|
8370
7826
|
if (hasMultiLineRecord && rec > 0) {
|
|
8371
|
-
lines.push(boxLine(
|
|
7827
|
+
lines.push(boxLine(glyphs, glyphs.ml, glyphs.mm, glyphs.mr, widths));
|
|
8372
7828
|
}
|
|
8373
7829
|
for (let r = 0; r < bodyDisplayRows[rec]; r += 1) {
|
|
8374
7830
|
lines.push(
|
|
@@ -8380,12 +7836,13 @@ function renderBoxTable(table, width, style) {
|
|
|
8380
7836
|
table.aligns,
|
|
8381
7837
|
widths,
|
|
8382
7838
|
style,
|
|
8383
|
-
false
|
|
7839
|
+
false,
|
|
7840
|
+
glyphs
|
|
8384
7841
|
)
|
|
8385
7842
|
);
|
|
8386
7843
|
}
|
|
8387
7844
|
});
|
|
8388
|
-
lines.push(boxLine(
|
|
7845
|
+
lines.push(boxLine(glyphs, glyphs.bl, glyphs.bm, glyphs.br, widths));
|
|
8389
7846
|
return lines.join("\n");
|
|
8390
7847
|
}
|
|
8391
7848
|
function renderRecordCards(table, width, style) {
|
|
@@ -8429,7 +7886,12 @@ function renderMarkdownTable(table, options = {}) {
|
|
|
8429
7886
|
if (width < 40 || table.headers.length > 6) {
|
|
8430
7887
|
return renderRecordCards(styledTable, width, style);
|
|
8431
7888
|
}
|
|
8432
|
-
return renderBoxTable(
|
|
7889
|
+
return renderBoxTable(
|
|
7890
|
+
styledTable,
|
|
7891
|
+
width,
|
|
7892
|
+
style,
|
|
7893
|
+
options.boxCharset ?? resolveBoxCharset()
|
|
7894
|
+
);
|
|
8433
7895
|
}
|
|
8434
7896
|
|
|
8435
7897
|
// packages/cli/client/assistantOutput.ts
|
|
@@ -8678,11 +8140,10 @@ function normalizeListLine(line) {
|
|
|
8678
8140
|
}
|
|
8679
8141
|
return line;
|
|
8680
8142
|
}
|
|
8681
|
-
var TOOL_TREE_HEADER_RE = /^•\s+(.+?)\s+\((\d+)\)
|
|
8682
|
-
var TOOL_TREE_LEAF_RE = /^([├└]──\s+)(.*?)\s{2}(✓|✗|!)(?:\s+(.*))?$/;
|
|
8143
|
+
var TOOL_TREE_HEADER_RE = /^•\s+(.+?)\s+\((\d+)\) · (.*?) ✓$/;
|
|
8683
8144
|
var TOOL_SINGLE_RE = /^▸\s+(.+?)(?:\s+·\s+(.*?))?(?:\s{2}(✓|✗|!)(?:\s+(.*))?)$/;
|
|
8684
8145
|
function plainToolLine(line) {
|
|
8685
|
-
return
|
|
8146
|
+
return stripAnsi(line);
|
|
8686
8147
|
}
|
|
8687
8148
|
var TOOL_TREE_GROUP_LABELS = new Set(
|
|
8688
8149
|
["execShell", "readFile", "fetchWebpage", "exa_search"].flatMap(toolLabelVariants)
|
|
@@ -8697,9 +8158,6 @@ function toolTreeHeaderMatch(line) {
|
|
|
8697
8158
|
function isToolTreeHeaderLine(line) {
|
|
8698
8159
|
return toolTreeHeaderMatch(line) !== null;
|
|
8699
8160
|
}
|
|
8700
|
-
function isToolTreeLeafLine(line) {
|
|
8701
|
-
return TOOL_TREE_LEAF_RE.test(plainToolLine(line));
|
|
8702
|
-
}
|
|
8703
8161
|
function isToolSingleLine(line) {
|
|
8704
8162
|
return TOOL_SINGLE_RE.test(plainToolLine(line));
|
|
8705
8163
|
}
|
|
@@ -8718,17 +8176,10 @@ function toolGroupKeyOf(line) {
|
|
|
8718
8176
|
return null;
|
|
8719
8177
|
}
|
|
8720
8178
|
function toolRowBoundary(cur, next) {
|
|
8721
|
-
const curLeaf = isToolTreeLeafLine(cur);
|
|
8722
|
-
const curHeader = isToolTreeHeaderLine(cur);
|
|
8723
|
-
const nextLeaf = isToolTreeLeafLine(next);
|
|
8724
8179
|
const curKey = toolGroupKeyOf(cur);
|
|
8725
8180
|
const nextKey = toolGroupKeyOf(next);
|
|
8726
|
-
if (curKey === null
|
|
8727
|
-
|
|
8728
|
-
if (curLeaf) return !nextLeaf;
|
|
8729
|
-
if (curHeader && nextLeaf) return false;
|
|
8730
|
-
if (curKey !== null && nextKey !== null) return curKey !== nextKey;
|
|
8731
|
-
return true;
|
|
8181
|
+
if (curKey === null || nextKey === null) return null;
|
|
8182
|
+
return isToolTreeHeaderLine(cur) || isToolTreeHeaderLine(next) || curKey !== nextKey;
|
|
8732
8183
|
}
|
|
8733
8184
|
function statusColorSeq(marker, brightness) {
|
|
8734
8185
|
if (marker === "\u2713") return colorSeq("success", brightness);
|
|
@@ -8741,18 +8192,7 @@ function styleTuiToolLine(line, brightness) {
|
|
|
8741
8192
|
const muted = colorSeq("muted", brightness);
|
|
8742
8193
|
const header = toolTreeHeaderMatch(plain);
|
|
8743
8194
|
if (header) {
|
|
8744
|
-
return `${chrome}\u2022${STYLE.reset} ${STYLE.bold}${muted}${header[1]}${STYLE.reset} ${chrome}${STYLE.dim}(${header[2]})${STYLE.reset}`;
|
|
8745
|
-
}
|
|
8746
|
-
const leaf = plain.match(TOOL_TREE_LEAF_RE);
|
|
8747
|
-
if (leaf) {
|
|
8748
|
-
const [, connector, detail, marker, statusDetail] = leaf;
|
|
8749
|
-
let rendered = `${chrome}${connector}${STYLE.reset}${chrome}${detail}${STYLE.reset}`;
|
|
8750
|
-
rendered += ` ${statusColorSeq(marker, brightness)}${marker}${STYLE.reset}`;
|
|
8751
|
-
if (statusDetail) {
|
|
8752
|
-
const metaSeq = marker === "\u2713" ? chrome : statusColorSeq(marker, brightness);
|
|
8753
|
-
rendered += ` ${metaSeq}${STYLE.dim}${statusDetail}${STYLE.reset}`;
|
|
8754
|
-
}
|
|
8755
|
-
return rendered;
|
|
8195
|
+
return `${chrome}\u2022${STYLE.reset} ${STYLE.bold}${muted}${header[1]}${STYLE.reset} ${chrome}${STYLE.dim}(${header[2]})${STYLE.reset} ${chrome}\xB7 ${header[3]}${STYLE.reset} ${statusColorSeq("\u2713", brightness)}\u2713${STYLE.reset}`;
|
|
8756
8196
|
}
|
|
8757
8197
|
const single = plain.match(TOOL_SINGLE_RE);
|
|
8758
8198
|
if (single) {
|
|
@@ -8776,14 +8216,14 @@ function isPolishFenceInteriorLine(line) {
|
|
|
8776
8216
|
return /^\x00F\d+\x00$/.test(line);
|
|
8777
8217
|
}
|
|
8778
8218
|
function polishHeadingLevel(line) {
|
|
8779
|
-
const match =
|
|
8219
|
+
const match = stripAnsi(line).match(/^(#{1,6})\s/);
|
|
8780
8220
|
return match ? match[1].length : null;
|
|
8781
8221
|
}
|
|
8782
8222
|
function isPolishHeadingLine(line) {
|
|
8783
8223
|
return polishHeadingLevel(line) !== null;
|
|
8784
8224
|
}
|
|
8785
8225
|
function isPolishIntroLine(line) {
|
|
8786
|
-
const plain =
|
|
8226
|
+
const plain = stripAnsi(line).trimEnd();
|
|
8787
8227
|
return plain.endsWith("\uFF1A") || plain.endsWith(":");
|
|
8788
8228
|
}
|
|
8789
8229
|
function polishBreathInsertsBlankBetween(cur, next) {
|
|
@@ -8911,7 +8351,7 @@ function styleRichMarkdownLine(line, brightness) {
|
|
|
8911
8351
|
return `${border}\u2502${STYLE.reset} ${STYLE.dim}${styled}${STYLE.reset}`;
|
|
8912
8352
|
}
|
|
8913
8353
|
if (THEMATIC_BREAK_RE.test(line)) {
|
|
8914
|
-
return `${colorSeq("chrome", brightness)}${STYLE.dim}${
|
|
8354
|
+
return `${colorSeq("chrome", brightness)}${STYLE.dim}${boxGlyphs(resolveBoxCharset()).h.repeat(36)}${STYLE.reset}`;
|
|
8915
8355
|
}
|
|
8916
8356
|
const bullet = line.match(/^(\s*)(•)\s(.+)$/);
|
|
8917
8357
|
if (bullet) {
|
|
@@ -9085,7 +8525,6 @@ function classifyStreamLine(line) {
|
|
|
9085
8525
|
if (line === "") return "blank";
|
|
9086
8526
|
const plain = plainToolLine(line);
|
|
9087
8527
|
if (isToolTreeHeaderLine(plain)) return "tool-header";
|
|
9088
|
-
if (isToolTreeLeafLine(plain)) return "tool-leaf";
|
|
9089
8528
|
if (isToolSingleLine(plain)) return "tool";
|
|
9090
8529
|
if (TASK_LIST_RE.test(plain) || UNORDERED_LIST_RE.test(plain) || ORDERED_LIST_RE.test(plain) || /^\s*(?:•|◦|☐|☑)\s/.test(plain) || /^\s*[\u2460-\u2473]/.test(plain)) {
|
|
9091
8530
|
return "list";
|
|
@@ -9095,10 +8534,10 @@ function classifyStreamLine(line) {
|
|
|
9095
8534
|
return "prose";
|
|
9096
8535
|
}
|
|
9097
8536
|
function isStreamToolKind(kind) {
|
|
9098
|
-
return kind === "tool-header" || kind === "tool
|
|
8537
|
+
return kind === "tool-header" || kind === "tool";
|
|
9099
8538
|
}
|
|
9100
8539
|
function isStreamListLike(kind) {
|
|
9101
|
-
return kind === "list" || kind === "tool-header" || kind === "tool
|
|
8540
|
+
return kind === "list" || kind === "tool-header" || kind === "tool";
|
|
9102
8541
|
}
|
|
9103
8542
|
function needsListProseBreath(prev, next, prevLine = "", nextLine = "") {
|
|
9104
8543
|
if (prev === null || prev === "blank" || next === "blank") return false;
|
|
@@ -9294,44 +8733,35 @@ function formatAssistantTextForCli(text) {
|
|
|
9294
8733
|
return text.replace(/\u003cthink\u003e[\s\S]*?\u003c\/think\u003e\s*/gi, "").replace(/\n{3,}/g, "\n\n").trim();
|
|
9295
8734
|
}
|
|
9296
8735
|
|
|
9297
|
-
// packages/cli/tui/
|
|
9298
|
-
var
|
|
9299
|
-
|
|
9300
|
-
|
|
9301
|
-
|
|
9302
|
-
|
|
9303
|
-
|
|
9304
|
-
|
|
9305
|
-
|
|
9306
|
-
|
|
9307
|
-
|
|
9308
|
-
|
|
9309
|
-
|
|
9310
|
-
|
|
9311
|
-
|
|
9312
|
-
|
|
9313
|
-
|
|
9314
|
-
|
|
9315
|
-
|
|
9316
|
-
|
|
9317
|
-
|
|
9318
|
-
|
|
9319
|
-
|
|
9320
|
-
if (findPotentialSecrets(gist).length > 0) return "";
|
|
9321
|
-
if (NORMAL_GIST_SECRET_PATTERNS.some((pattern) => pattern.test(gist))) return "";
|
|
9322
|
-
return gist;
|
|
9323
|
-
}
|
|
9324
|
-
function toText(value) {
|
|
9325
|
-
return typeof value === "string" ? value : String(value ?? "");
|
|
9326
|
-
}
|
|
9327
|
-
function cleanAskText(value) {
|
|
9328
|
-
return stripAnsi2(toText(value)).replace(/[\r\n]+/g, " ").replace(/\s+/g, " ").replace(C0_C1_CONTROL_REGEX, "").replace(/\s+/g, " ").trim();
|
|
8736
|
+
// packages/cli/tui/tuiLayout.ts
|
|
8737
|
+
var DEFAULT_TERMINAL_ROWS = 24;
|
|
8738
|
+
var DEFAULT_TERMINAL_COLUMNS = 80;
|
|
8739
|
+
var TUI_MARGIN_LEFT = 1;
|
|
8740
|
+
var TUI_MARGIN_RIGHT = 1;
|
|
8741
|
+
var TUI_MARGIN_RESPONSIVE_MIN_COLUMNS = 40;
|
|
8742
|
+
function resolveHistoryLayoutGeometry(columns) {
|
|
8743
|
+
const cols = Math.max(1, (columns ?? 0) > 0 ? columns : DEFAULT_TERMINAL_COLUMNS);
|
|
8744
|
+
if (cols <= TUI_MARGIN_RESPONSIVE_MIN_COLUMNS) {
|
|
8745
|
+
return {
|
|
8746
|
+
contentWidth: Math.max(1, cols - 1),
|
|
8747
|
+
marginLeft: 0,
|
|
8748
|
+
marginRight: 0
|
|
8749
|
+
};
|
|
8750
|
+
}
|
|
8751
|
+
const marginLeft = TUI_MARGIN_LEFT;
|
|
8752
|
+
const marginRight = TUI_MARGIN_RIGHT;
|
|
8753
|
+
const contentWidth = Math.max(1, cols - 1 - marginLeft - marginRight);
|
|
8754
|
+
return {
|
|
8755
|
+
contentWidth,
|
|
8756
|
+
marginLeft,
|
|
8757
|
+
marginRight
|
|
8758
|
+
};
|
|
9329
8759
|
}
|
|
9330
|
-
function
|
|
9331
|
-
const
|
|
9332
|
-
|
|
9333
|
-
const
|
|
9334
|
-
return max
|
|
8760
|
+
function resolveHistoryViewportHeight(terminalRows, composerRows, foregroundReservedRows = 0) {
|
|
8761
|
+
const rows = Math.max(1, terminalRows > 0 ? terminalRows : DEFAULT_TERMINAL_ROWS);
|
|
8762
|
+
const composer = Math.max(0, composerRows);
|
|
8763
|
+
const reserved = Math.max(0, foregroundReservedRows);
|
|
8764
|
+
return Math.max(0, rows - composer - reserved);
|
|
9335
8765
|
}
|
|
9336
8766
|
|
|
9337
8767
|
// node_modules/diff/libesm/diff/base.js
|
|
@@ -9675,14 +9105,11 @@ function clip(value, max = 72) {
|
|
|
9675
9105
|
return clipCompactText(value, max, "\u2026");
|
|
9676
9106
|
}
|
|
9677
9107
|
function formatConservativeActiveToolLabel(event) {
|
|
9678
|
-
return toolLabel(event.toolName || "tool");
|
|
9108
|
+
return event.toolName === "startAgentRun" ? t("agentStartingLabel") : toolLabel(event.toolName || "tool");
|
|
9679
9109
|
}
|
|
9680
9110
|
function isRunToolName(name) {
|
|
9681
9111
|
return name === "execShell" || name === "runCommand" || name === "launchProcess";
|
|
9682
9112
|
}
|
|
9683
|
-
function isReadToolName(name) {
|
|
9684
|
-
return name === "readFile";
|
|
9685
|
-
}
|
|
9686
9113
|
function isFailedToolResult(event) {
|
|
9687
9114
|
const exitCode = event.metadata?.exitCode;
|
|
9688
9115
|
if (event.metadata?.actionGate) return false;
|
|
@@ -9874,7 +9301,7 @@ function formatToolTraceLine(text, colorEnabled, accent = "none") {
|
|
|
9874
9301
|
return `${dimCliText(text, true)}
|
|
9875
9302
|
`;
|
|
9876
9303
|
}
|
|
9877
|
-
var cleanUserText = (value) =>
|
|
9304
|
+
var cleanUserText = (value) => stripAnsi(value).replace(/[\r\n]+/g, " ").replace(/\s+/g, " ").trim();
|
|
9878
9305
|
function renderRunCard(snapshot, opts) {
|
|
9879
9306
|
const labels = agentRunCardLabels();
|
|
9880
9307
|
const timing = { startedAt: snapshot.startedAt, finishedAt: snapshot.finishedAt };
|
|
@@ -9925,8 +9352,9 @@ function recoverOrchestrationCard(event, toolName, opts) {
|
|
|
9925
9352
|
if (toolName === "listAgents") {
|
|
9926
9353
|
try {
|
|
9927
9354
|
const parsed = JSON.parse(trimmed);
|
|
9928
|
-
|
|
9929
|
-
const
|
|
9355
|
+
if (parsed.success === false || !Array.isArray(parsed.agents)) return null;
|
|
9356
|
+
const agents = parsed.agents;
|
|
9357
|
+
const card = formatAgentListCard(agents, 8, /* @__PURE__ */ new Date(), !safe);
|
|
9930
9358
|
const lines = card.split("\n");
|
|
9931
9359
|
lines[0] = t("agentsListLabel", String(agents.length));
|
|
9932
9360
|
return lines.join("\n");
|
|
@@ -9954,12 +9382,18 @@ function recoverOrchestrationCard(event, toolName, opts) {
|
|
|
9954
9382
|
const name = safe ? cleanUserText(snapshot.agentName ?? "agent") : snapshot.agentName ?? "agent";
|
|
9955
9383
|
const task = snapshot.taskPreview ? safe ? cleanUserText(snapshot.taskPreview) : snapshot.taskPreview : snapshot.taskPreview;
|
|
9956
9384
|
const title = snapshot.title ? safe ? cleanUserText(snapshot.title) : snapshot.title : snapshot.title;
|
|
9957
|
-
|
|
9958
|
-
|
|
9959
|
-
|
|
9960
|
-
...title ? { title } : {},
|
|
9961
|
-
labels
|
|
9385
|
+
const identity = formatIdentityRow(name, snapshot.runId, {
|
|
9386
|
+
title,
|
|
9387
|
+
unnamedAgent: labels.unnamedAgent
|
|
9962
9388
|
});
|
|
9389
|
+
const status = `${getAgentRunStatusIcon(snapshot.status)} ${labels.statusWord(snapshot.status)}`;
|
|
9390
|
+
const oneLine = identity ? `${identity} \xB7 ${status}` : status;
|
|
9391
|
+
const columns = process.stdout.columns || 80;
|
|
9392
|
+
const secondary = formatIdentityRow(name, snapshot.runId, { title, titleOnOwnLine: true, unnamedAgent: labels.unnamedAgent });
|
|
9393
|
+
const rows = identity && title && displayWidth(` ${oneLine}`) > columns ? [title, ` ${secondary ? `${secondary} \xB7 ` : ""}${status}`] : [oneLine];
|
|
9394
|
+
if (task && !title) rows.push(` ${labels.rows.task}${task}`);
|
|
9395
|
+
if (snapshot.errorMessage) rows.push(` ${labels.rows.error}${redactSecrets(cleanUserText(snapshot.errorMessage.split("\n")[0]))}`);
|
|
9396
|
+
return rows.join("\n");
|
|
9963
9397
|
}
|
|
9964
9398
|
if (kind === "gone") return formatNotFoundRunCard(labels);
|
|
9965
9399
|
if (kind === "stop") return formatStopRunCard(snapshot.status, labels);
|
|
@@ -9969,10 +9403,20 @@ function formatOrchestrationCardBlock(event, toolName, colorEnabled, opts) {
|
|
|
9969
9403
|
const safe = opts?.safe === true;
|
|
9970
9404
|
const rawLabel = toolLabel(toolName);
|
|
9971
9405
|
const bakedCard = typeof event.metadata?.displayData === "string" && event.metadata.displayData.trim() ? event.metadata.displayData : "";
|
|
9972
|
-
|
|
9973
|
-
|
|
9406
|
+
let listPayload;
|
|
9407
|
+
if (toolName === "listAgents" && typeof event.content === "string") {
|
|
9408
|
+
try {
|
|
9409
|
+
const value = JSON.parse(event.content);
|
|
9410
|
+
if (value && typeof value === "object" && !Array.isArray(value)) listPayload = value;
|
|
9411
|
+
} catch {
|
|
9412
|
+
}
|
|
9413
|
+
}
|
|
9414
|
+
const listFailed = listPayload?.success === false;
|
|
9415
|
+
const rawDataStr = listFailed ? typeof listPayload?.error === "string" ? listPayload.error : event.content || bakedCard : recoverOrchestrationCard(event, toolName, { safe }) || bakedCard || (typeof event.content === "string" ? event.content : "");
|
|
9416
|
+
const failed = event.type === "tool-error" || isFailedToolResult(event) || Boolean(event.metadata?.failed) || listFailed || /^Error:/i.test(rawDataStr.trim());
|
|
9974
9417
|
if (failed) {
|
|
9975
|
-
const
|
|
9418
|
+
const failureSnapshot = toolName === "startAgentRun" ? parseAgentRunEvent(event)?.snapshot : void 0;
|
|
9419
|
+
const firstLine = stripAnsi(failureSnapshot?.errorMessage || rawDataStr.trim().split("\n")[0] || event.summary || event.message || t("toolFailed"));
|
|
9976
9420
|
const message = clip(redactSecrets(firstLine), 96);
|
|
9977
9421
|
if (!colorEnabled) {
|
|
9978
9422
|
return `\u2717 ${rawLabel} ${message}
|
|
@@ -9984,11 +9428,59 @@ function formatOrchestrationCardBlock(event, toolName, colorEnabled, opts) {
|
|
|
9984
9428
|
return `${cross} ${labelPart2} ${msgPart}
|
|
9985
9429
|
`;
|
|
9986
9430
|
}
|
|
9431
|
+
if (opts?.visibleRunIds && toolName === "startAgentRun") {
|
|
9432
|
+
const started = parseAgentRunEvent(event);
|
|
9433
|
+
const runId = started?.snapshot.runId;
|
|
9434
|
+
const startedStatus = started?.snapshot.status;
|
|
9435
|
+
if (started?.kind === "start" && typeof runId === "string" && runId.length > 0 && !started.snapshot.errorMessage && // 只认 core 定义的已知正常态。unknown/cancelling/not_found/未来新增状态
|
|
9436
|
+
// 都不算正常 → 保留回执。
|
|
9437
|
+
isAgentRunStatusNormal(startedStatus)) {
|
|
9438
|
+
let visible;
|
|
9439
|
+
try {
|
|
9440
|
+
visible = opts.visibleRunIds();
|
|
9441
|
+
} catch {
|
|
9442
|
+
visible = void 0;
|
|
9443
|
+
}
|
|
9444
|
+
if (visible?.has(runId)) return "";
|
|
9445
|
+
}
|
|
9446
|
+
}
|
|
9447
|
+
const parsedStart = toolName === "startAgentRun" ? parseAgentRunEvent(event) : null;
|
|
9448
|
+
const startFailed = parsedStart && isAgentRunStartFailureStatus(parsedStart.snapshot.status);
|
|
9449
|
+
let heading = parsedStart ? t(startFailed ? "agentStartFailedLabel" : "agentStartedLabel") : rawLabel;
|
|
9987
9450
|
const displayData = rawDataStr.trim();
|
|
9988
9451
|
const lines = displayData ? displayData.split("\n") : [];
|
|
9989
|
-
|
|
9452
|
+
if (toolName === "startAgentRun" && ["Run started", "\u8FD0\u884C\u5DF2\u542F\u52A8"].includes(lines[0]?.trim())) lines.shift();
|
|
9453
|
+
let projected = safe ? sanitizeRunCardForNormal(lines) : lines;
|
|
9454
|
+
if (safe && toolName === "listAgents") {
|
|
9455
|
+
if (Array.isArray(listPayload?.agents)) {
|
|
9456
|
+
const count = listPayload.agents.length;
|
|
9457
|
+
const total = typeof listPayload.total === "number" && Number.isSafeInteger(listPayload.total) && listPayload.total >= count ? listPayload.total : count;
|
|
9458
|
+
heading = t("agentsCompactCount", String(total));
|
|
9459
|
+
if (total !== count) heading += ` \xB7 ${t("agentsPageCount", String(count))}`;
|
|
9460
|
+
if (listPayload.truncated === true) heading += ` \xB7 ${t("agentsTruncated")}`;
|
|
9461
|
+
if (/^(?:Agents|智能体|🤖)\s*\(\d+\)$/.test(projected[0]?.trim() ?? "")) {
|
|
9462
|
+
projected = projected.slice(1);
|
|
9463
|
+
}
|
|
9464
|
+
} else {
|
|
9465
|
+
const bakedHeader = /^(?:Agents|智能体|🤖)\s*\((\d+)\)$/.exec(projected[0]?.trim() ?? "");
|
|
9466
|
+
if (bakedHeader) {
|
|
9467
|
+
heading = t("agentsCompactCount", bakedHeader[1]);
|
|
9468
|
+
projected = projected.slice(1);
|
|
9469
|
+
}
|
|
9470
|
+
}
|
|
9471
|
+
projected = projected.map((line) => line.replace(/\s{2,}(?:agent-pub-[a-z0-9]+|agent-system-[a-z0-9]+|agent-[0-9a-f]{6,}-[a-z0-9-]+|\(agentKey unavailable\))\s*$/i, ""));
|
|
9472
|
+
}
|
|
9473
|
+
if (safe && toolName === "controlAgentRun" && projected.length > 0) {
|
|
9474
|
+
const first = projected[0].trim();
|
|
9475
|
+
const recognized = ["Run status", "\u8FD0\u884C\u72B6\u6001", "Run finished", "\u8FD0\u884C\u5DF2\u7ED3\u675F", "Run stopped", "\u8FD0\u884C\u5DF2\u505C\u6B62"];
|
|
9476
|
+
const merged = `${heading} \xB7 ${first}`;
|
|
9477
|
+
if (recognized.includes(first) && displayWidth(`\u25CF ${merged}`) <= (process.stdout.columns || 80)) {
|
|
9478
|
+
heading = merged;
|
|
9479
|
+
projected = projected.slice(1);
|
|
9480
|
+
}
|
|
9481
|
+
}
|
|
9990
9482
|
if (!colorEnabled) {
|
|
9991
|
-
let out2 = `\u25CF ${
|
|
9483
|
+
let out2 = `\u25CF ${heading}
|
|
9992
9484
|
`;
|
|
9993
9485
|
for (const line of projected) {
|
|
9994
9486
|
out2 += ` ${line}
|
|
@@ -9997,7 +9489,7 @@ function formatOrchestrationCardBlock(event, toolName, colorEnabled, opts) {
|
|
|
9997
9489
|
return out2;
|
|
9998
9490
|
}
|
|
9999
9491
|
const bullet = themeText("\u25CF", "success", true);
|
|
10000
|
-
const labelPart = themeText(
|
|
9492
|
+
const labelPart = themeText(heading, "muted", true);
|
|
10001
9493
|
let out = `${bullet} ${labelPart}
|
|
10002
9494
|
`;
|
|
10003
9495
|
for (const line of projected) {
|
|
@@ -10015,7 +9507,7 @@ function sanitizeRunCardForNormal(lines) {
|
|
|
10015
9507
|
break;
|
|
10016
9508
|
}
|
|
10017
9509
|
if (/^\s*error\b/i.test(line)) {
|
|
10018
|
-
out.push(clip(redactSecrets(
|
|
9510
|
+
out.push(clip(redactSecrets(stripAnsi(line)), 160));
|
|
10019
9511
|
errorIndent = line.length - line.trimStart().length;
|
|
10020
9512
|
continue;
|
|
10021
9513
|
}
|
|
@@ -10248,7 +9740,7 @@ function formatNormalToolDuration(elapsedMs) {
|
|
|
10248
9740
|
if (elapsedMs < 1e3) return `${Math.round(elapsedMs)}ms`;
|
|
10249
9741
|
return `${(elapsedMs / 1e3).toFixed(1)}s`;
|
|
10250
9742
|
}
|
|
10251
|
-
function formatNormalToolLine(event, pending, colorEnabled) {
|
|
9743
|
+
function formatNormalToolLine(event, pending, colorEnabled, opts) {
|
|
10252
9744
|
if (event.type === "tool-call") return "";
|
|
10253
9745
|
const toolName = event.toolName || pending?.toolName || "tool";
|
|
10254
9746
|
if (event.type === "tool-result" && (event.toolName === "ask_user" || event.metadata?.uiAskChoice)) {
|
|
@@ -10256,10 +9748,13 @@ function formatNormalToolLine(event, pending, colorEnabled) {
|
|
|
10256
9748
|
if (block) return block;
|
|
10257
9749
|
}
|
|
10258
9750
|
if (event.type === "tool-result" && (toolName === "listAgents" || toolName === "startAgentRun" || toolName === "controlAgentRun")) {
|
|
10259
|
-
return formatOrchestrationCardBlock(event, toolName, colorEnabled, {
|
|
9751
|
+
return formatOrchestrationCardBlock(event, toolName, colorEnabled, {
|
|
9752
|
+
safe: true,
|
|
9753
|
+
visibleRunIds: opts?.visibleRunIds
|
|
9754
|
+
});
|
|
10260
9755
|
}
|
|
10261
9756
|
if (event.type === "tool-result" && toolName === "loadSkill") {
|
|
10262
|
-
return formatLoadSkillBlock(event, colorEnabled, { safe: true }) ?? "";
|
|
9757
|
+
return formatLoadSkillBlock({ ...event, argumentsPreview: event.argumentsPreview || pending?.argumentsPreview }, colorEnabled, { safe: true }) ?? "";
|
|
10263
9758
|
}
|
|
10264
9759
|
if (event.type === "tool-result" && toolName === "show_interaction") {
|
|
10265
9760
|
return formatShowInteractionBlock(event, colorEnabled);
|
|
@@ -10304,24 +9799,56 @@ function toolFailureReason(event) {
|
|
|
10304
9799
|
return lines.slice(start + 1, end < 0 ? lines.length : end);
|
|
10305
9800
|
};
|
|
10306
9801
|
const reasonLine = sectionLines("stderr")[0] ?? sectionLines("stdout")[0] ?? lines.find((line) => !/^(stdout|stderr|exitCode)\s*:/i.test(line)) ?? lines[0] ?? "";
|
|
10307
|
-
return reasonLine ? clip(redactSecrets(
|
|
9802
|
+
return reasonLine ? clip(redactSecrets(stripAnsi(reasonLine)), 96) : "";
|
|
10308
9803
|
}
|
|
10309
9804
|
function resolveLoadSkillName(event) {
|
|
10310
|
-
const metaName = typeof event.metadata?.name === "string" ? event.metadata.name : void 0;
|
|
10311
|
-
if (metaName) return metaName;
|
|
10312
|
-
const argName = event.argumentsPreview?.trim();
|
|
10313
|
-
if (argName && !argName.startsWith("{")) return argName;
|
|
10314
9805
|
const content = typeof event.content === "string" ? event.content : "";
|
|
10315
|
-
|
|
10316
|
-
|
|
10317
|
-
|
|
9806
|
+
let result;
|
|
9807
|
+
try {
|
|
9808
|
+
const value = JSON.parse(content);
|
|
9809
|
+
if (value && typeof value === "object" && !Array.isArray(value)) result = value;
|
|
9810
|
+
} catch {
|
|
9811
|
+
}
|
|
9812
|
+
const preview = event.argumentsPreview?.trim() ?? "";
|
|
9813
|
+
let args = {};
|
|
9814
|
+
if (preview.startsWith("{")) {
|
|
9815
|
+
try {
|
|
9816
|
+
const value = JSON.parse(preview);
|
|
9817
|
+
if (value && typeof value === "object" && !Array.isArray(value)) args = value;
|
|
9818
|
+
} catch {
|
|
9819
|
+
}
|
|
9820
|
+
} else if (/^(?:name|source|slug|dbKey|projectBinding|relativePath)=/.test(preview)) {
|
|
9821
|
+
for (const match of preview.matchAll(/(?:^|\s)(name|source|slug|dbKey|projectBinding|relativePath)=([^\s]+)/g)) args[match[1]] = match[2];
|
|
9822
|
+
} else if (preview) {
|
|
9823
|
+
args.name = preview;
|
|
9824
|
+
}
|
|
9825
|
+
const textName = content.match(/^Skill "([^"\n]+)" loaded inline\./)?.[1];
|
|
9826
|
+
const name = result?.name ?? textName ?? event.metadata?.name ?? args.name;
|
|
9827
|
+
const source = result?.source ?? event.metadata?.source ?? args.source;
|
|
9828
|
+
const slug = result?.slug ?? event.metadata?.slug ?? args.slug;
|
|
9829
|
+
const dbKey = result?.dbKey ?? event.metadata?.dbKey ?? args.dbKey;
|
|
9830
|
+
const relativePath2 = result?.relativePath ?? event.metadata?.relativePath ?? args.relativePath;
|
|
9831
|
+
const shortReference = (value) => {
|
|
9832
|
+
if (typeof value !== "string" || !value.trim()) return void 0;
|
|
9833
|
+
const normalized = value.trim().replace(/\\/g, "/");
|
|
9834
|
+
const parts = normalized.split("/").filter(Boolean);
|
|
9835
|
+
return parts.at(-1) === "SKILL.md" && parts.length > 1 ? parts.at(-2) : parts.at(-1);
|
|
9836
|
+
};
|
|
9837
|
+
const candidate = shortReference(name) ?? shortReference(slug) ?? shortReference(dbKey) ?? shortReference(relativePath2) ?? shortReference(source) ?? t("unnamedSkillReference");
|
|
9838
|
+
return clip(redactSecrets(cleanUserText(candidate)), 80);
|
|
10318
9839
|
}
|
|
10319
9840
|
function formatLoadSkillBlock(event, colorEnabled, opts) {
|
|
10320
9841
|
if (event.type !== "tool-result" || event.toolName !== "loadSkill") return null;
|
|
10321
9842
|
const skillName = resolveLoadSkillName(event);
|
|
10322
9843
|
const content = typeof event.content === "string" ? event.content : "";
|
|
10323
|
-
|
|
10324
|
-
|
|
9844
|
+
let result;
|
|
9845
|
+
try {
|
|
9846
|
+
const value = JSON.parse(content);
|
|
9847
|
+
if (value && typeof value === "object" && !Array.isArray(value)) result = value;
|
|
9848
|
+
} catch {
|
|
9849
|
+
}
|
|
9850
|
+
const failed = /^Skill\s+"[^"]*"\s+not found/i.test(content) || /^Skill reference rejected:/i.test(content) || event.metadata?.resolved === false || Boolean(event.metadata?.failed) || result?.success === false || isFailedToolResult(event);
|
|
9851
|
+
const labelText = t(failed ? "loadSkillLabel" : "usedSkillLabel");
|
|
10325
9852
|
if (failed) {
|
|
10326
9853
|
const message = opts?.safe === true ? t("toolFailed") : clip(content.split("\n")[0] || t("toolFailed"), 96);
|
|
10327
9854
|
return formatToolTraceLine(`\u25B8 ${labelText} (${skillName}) \u2717 ${message}`, colorEnabled, "error");
|
|
@@ -10338,14 +9865,34 @@ function formatLoadSkillBlock(event, colorEnabled, opts) {
|
|
|
10338
9865
|
}
|
|
10339
9866
|
var TUI_TREE_MARKER = "TUI_TREE\n";
|
|
10340
9867
|
var TUI_TREE_END = "";
|
|
9868
|
+
var TUI_TREE_TOOLS = {
|
|
9869
|
+
Run: ["execShell", "runCommand", "launchProcess"],
|
|
9870
|
+
Read: ["readFile"],
|
|
9871
|
+
Search: ["exa_search"],
|
|
9872
|
+
Fetch: ["fetchWebpage"]
|
|
9873
|
+
};
|
|
10341
9874
|
function createToolEventFormatter(colorEnabled = resolveCliColorEnabled(), opts = {}) {
|
|
10342
9875
|
const pending = /* @__PURE__ */ new Map();
|
|
10343
9876
|
let tree = null;
|
|
10344
|
-
const treeKind = (name) =>
|
|
10345
|
-
const treeLine = (kind, items) => {
|
|
9877
|
+
const treeKind = (name) => Object.keys(TUI_TREE_TOOLS).find((kind) => TUI_TREE_TOOLS[kind].includes(name)) ?? null;
|
|
9878
|
+
const treeLine = (kind, items, fallback) => {
|
|
10346
9879
|
const label = kind === "Run" ? toolLabel("execShell") : kind === "Read" ? toolLabel("readFile") : kind === "Fetch" ? toolLabel("fetchWebpage") : toolLabel("exa_search");
|
|
10347
|
-
|
|
10348
|
-
|
|
9880
|
+
const header = `${label} (${items.length}) \xB7 `;
|
|
9881
|
+
const columns = resolveHistoryLayoutGeometry(process.stdout.columns).contentWidth - displayWidth("\u25C8 ");
|
|
9882
|
+
let shown = 1;
|
|
9883
|
+
for (let count = 2; count <= items.length; count++) {
|
|
9884
|
+
const omitted2 = items.length - count;
|
|
9885
|
+
const suffix = omitted2 ? `, \u2026 +${omitted2}` : "";
|
|
9886
|
+
if (displayWidth(`\u2022 ${header}${items.slice(0, count).join(", ")}${suffix} \u2713`) > columns) break;
|
|
9887
|
+
shown = count;
|
|
9888
|
+
}
|
|
9889
|
+
const omitted = items.length - shown;
|
|
9890
|
+
const payload = {
|
|
9891
|
+
kind,
|
|
9892
|
+
summary: `${header}${items.slice(0, shown).join(", ")}${omitted ? `, \u2026 +${omitted}` : ""} \u2713`,
|
|
9893
|
+
fallback
|
|
9894
|
+
};
|
|
9895
|
+
return `${TUI_TREE_MARKER}${JSON.stringify(payload)}${TUI_TREE_END}
|
|
10349
9896
|
`;
|
|
10350
9897
|
};
|
|
10351
9898
|
const formatTreeEvent = (event, call) => {
|
|
@@ -10372,8 +9919,8 @@ ${items.map((item, i) => `${i === items.length - 1 ? "\u2514\u2500\u2500 " : "\u
|
|
|
10372
9919
|
item = withholdIfSecretLike(item) || toolLabel(name);
|
|
10373
9920
|
if (tree?.kind !== kind) tree = { kind, items: [] };
|
|
10374
9921
|
tree.items.push(item);
|
|
10375
|
-
if (tree.items.length < 2) return formatNormalToolLine(event, call, colorEnabled);
|
|
10376
|
-
return treeLine(kind, tree.items);
|
|
9922
|
+
if (tree.items.length < 2) return formatNormalToolLine(event, call, colorEnabled, opts);
|
|
9923
|
+
return treeLine(kind, tree.items, formatNormalToolLine(event, call, colorEnabled, opts));
|
|
10377
9924
|
};
|
|
10378
9925
|
const format = (event) => {
|
|
10379
9926
|
if (event.type === "tool-call") {
|
|
@@ -10387,7 +9934,7 @@ ${items.map((item, i) => `${i === items.length - 1 ? "\u2514\u2500\u2500 " : "\u
|
|
|
10387
9934
|
pending.delete(event.toolCallId);
|
|
10388
9935
|
const treeOutput = formatTreeEvent(event, call);
|
|
10389
9936
|
if (treeOutput !== null) return treeOutput;
|
|
10390
|
-
return formatNormalToolLine(event, call, colorEnabled);
|
|
9937
|
+
return formatNormalToolLine(event, call, colorEnabled, opts);
|
|
10391
9938
|
};
|
|
10392
9939
|
format.reset = () => {
|
|
10393
9940
|
tree = null;
|
|
@@ -10583,7 +10130,7 @@ function formatCompactionSummaryLine(event) {
|
|
|
10583
10130
|
if (!event) return "";
|
|
10584
10131
|
if (event.failed) {
|
|
10585
10132
|
const reason = event.detail ? `\uFF1A${event.detail}` : "";
|
|
10586
|
-
return `${STYLE.dim}\u81EA\u52A8\u4E0A\u4E0B\u6587\u538B\u7F29\u5931\u8D25${reason}\uFF0C\
|
|
10133
|
+
return `${STYLE.dim}\u81EA\u52A8\u4E0A\u4E0B\u6587\u538B\u7F29\u5931\u8D25${reason}\uFF0C\u4FDD\u7559\u5DF2\u6709\u5386\u53F2\uFF1B\u8D85\u51FA\u8BF7\u6C42\u9884\u7B97\u65F6\u5C06\u505C\u6B62\u53D1\u9001\u3002\u53EF\u624B\u52A8 /compact \u91CD\u8BD5\u3002${STYLE.reset}
|
|
10587
10134
|
`;
|
|
10588
10135
|
}
|
|
10589
10136
|
if (event.skipped) {
|
|
@@ -10639,7 +10186,7 @@ function shouldPromoteTuiNarration(text) {
|
|
|
10639
10186
|
return /(^|\n)\s*(?:#{1,3}\s|```|[-*+]\s|\d+[.)]\s)/.test(text);
|
|
10640
10187
|
}
|
|
10641
10188
|
function narrationActivityLabel(text) {
|
|
10642
|
-
const oneLine =
|
|
10189
|
+
const oneLine = stripAnsi(text).replace(/[`*_#>]/g, "").replace(/\s+/g, " ").trim();
|
|
10643
10190
|
return truncateThinkingHint(oneLine, 60);
|
|
10644
10191
|
}
|
|
10645
10192
|
function createCliTurnOutput(params) {
|
|
@@ -10647,7 +10194,8 @@ function createCliTurnOutput(params) {
|
|
|
10647
10194
|
const workingLabel = params.workingLabel ?? `${options.agentName} -> working`;
|
|
10648
10195
|
const spinner = params.spinner ?? new Spinner(options.output, workingLabel, Boolean(options.activityReporter));
|
|
10649
10196
|
const formatToolEvent = createToolEventFormatter(void 0, {
|
|
10650
|
-
tuiTrees: options.output.tuiTrees === true
|
|
10197
|
+
tuiTrees: options.output.tuiTrees === true,
|
|
10198
|
+
visibleRunIds: options.output.visibleRunIds
|
|
10651
10199
|
});
|
|
10652
10200
|
const eventMode = resolveAgentEventMode(options);
|
|
10653
10201
|
const assistantLabelManaged = options.output.assistantLabelManaged === true;
|
|
@@ -10876,8 +10424,17 @@ ${options.agentName}${IDENTITY_LABEL_SEPARATOR}`);
|
|
|
10876
10424
|
*/
|
|
10877
10425
|
showPhase(phase) {
|
|
10878
10426
|
const label = phase === "validating-context" ? t("contextChecking") : phase === "compacting" ? t("contextCompacting") : t("waitingForModel");
|
|
10879
|
-
|
|
10880
|
-
|
|
10427
|
+
this.showWorking(label);
|
|
10428
|
+
},
|
|
10429
|
+
handleCompactionActivity(event) {
|
|
10430
|
+
if (event.kind === "compaction-retry") {
|
|
10431
|
+
this.showWorking(t("contextCompactingRetry", String(event.attempt), String(event.maxAttempts)));
|
|
10432
|
+
} else if (event.kind === "compaction-start") {
|
|
10433
|
+
this.showPhase("compacting");
|
|
10434
|
+
} else if (event.kind === "compaction-end" || // Failed compaction continues with trimmed history; abort owns its terminal cleanup.
|
|
10435
|
+
event.kind === "compaction-failed" && event.reason !== "aborted") {
|
|
10436
|
+
this.showPhase("waiting-provider");
|
|
10437
|
+
}
|
|
10881
10438
|
},
|
|
10882
10439
|
finish(fallbackContent) {
|
|
10883
10440
|
const flushedThink = flushThinkParser(thinkState);
|
|
@@ -11412,9 +10969,57 @@ function isBalanceExhaustedError(error) {
|
|
|
11412
10969
|
return matchesBalanceError(message);
|
|
11413
10970
|
}
|
|
11414
10971
|
|
|
10972
|
+
// packages/cli/client/hostTaskWorkspaceAssessment.ts
|
|
10973
|
+
import { resolve as resolve3 } from "node:path";
|
|
10974
|
+
var object = (value) => value !== null && typeof value === "object" && !Array.isArray(value) ? value : void 0;
|
|
10975
|
+
var present = (value) => typeof value === "string" && value.trim().length > 0;
|
|
10976
|
+
function resolveCurrentHostTaskReference(input) {
|
|
10977
|
+
const ref = input.reference;
|
|
10978
|
+
if (!ref || !present(ref.taskId) || !present(ref.workspace) || !present(ref.dialogId) || ref.dialogId !== input.dialogId || resolve3(ref.workspace) !== resolve3(input.workspace) || readHostTask(hostTaskEventsRoot(input.env), ref).authorization === "unknown") return void 0;
|
|
10979
|
+
return structuredClone(ref);
|
|
10980
|
+
}
|
|
10981
|
+
async function assessHostTaskWorkspace(input) {
|
|
10982
|
+
const ref = resolveCurrentHostTaskReference(input);
|
|
10983
|
+
if (!ref) return void 0;
|
|
10984
|
+
const root = hostTaskEventsRoot(input.env);
|
|
10985
|
+
const blocked = (reason, businessReason = "invalid_contract") => ({
|
|
10986
|
+
exitCode: 1,
|
|
10987
|
+
hostTaskWorkspaceBlocker: reason,
|
|
10988
|
+
businessCompletion: { taskId: ref.taskId, status: "blocked", reasons: [businessReason] }
|
|
10989
|
+
});
|
|
10990
|
+
const fresh = await collectHostTaskWorkspace(ref, input.env);
|
|
10991
|
+
const plan = readHostTaskAcceptancePlan(ref, input.env);
|
|
10992
|
+
let planned;
|
|
10993
|
+
if (plan) {
|
|
10994
|
+
try {
|
|
10995
|
+
planned = { status: "ready", context: await collectHostTaskPlannedWorkspace(ref, input.env) };
|
|
10996
|
+
} catch {
|
|
10997
|
+
planned = { status: "blocked", reason: "task_planned_workspace_unavailable" };
|
|
10998
|
+
}
|
|
10999
|
+
}
|
|
11000
|
+
const authority = readHostTask(root, ref).authorization;
|
|
11001
|
+
if (authority === "paused" || authority === "revoked") return blocked(`authorization_${authority}`, `authorization_${authority}`);
|
|
11002
|
+
if (authority !== "active") return blocked("task_authority_unavailable");
|
|
11003
|
+
const supplied = object(input.evidence);
|
|
11004
|
+
if (supplied?.status === "blocked") return blocked(present(supplied.reason) ? supplied.reason : "workspace_blocked");
|
|
11005
|
+
if (fresh.status === "blocked") return blocked(fresh.reason);
|
|
11006
|
+
if (planned?.status === "blocked") return blocked(planned.reason);
|
|
11007
|
+
if (planned?.status === "ready" && planned.context.baseline !== fresh.context.baseline) {
|
|
11008
|
+
return blocked("task_plan_baseline_mismatch");
|
|
11009
|
+
}
|
|
11010
|
+
const context = object(supplied?.context);
|
|
11011
|
+
const scope = object(context?.scope);
|
|
11012
|
+
if (supplied?.status !== "ready" || !context || !scope || scope.taskId !== ref.taskId || scope.dialogId !== ref.dialogId || scope.taskInstanceId !== ref.taskInstanceId || !present(scope.workspace) || resolve3(scope.workspace) !== resolve3(ref.workspace)) return blocked("workspace_evidence_mismatch");
|
|
11013
|
+
const matches = (canonical) => context.baseline === canonical.baseline && context.revision === canonical.revision && Array.isArray(context.taskPaths) && context.taskPaths.length === canonical.taskPaths.length && context.taskPaths.every((path2, index) => path2 === canonical.taskPaths[index]);
|
|
11014
|
+
if (!matches(fresh.context) && !(planned?.status === "ready" && matches(planned.context))) {
|
|
11015
|
+
return blocked("workspace_evidence_mismatch");
|
|
11016
|
+
}
|
|
11017
|
+
return void 0;
|
|
11018
|
+
}
|
|
11019
|
+
|
|
11415
11020
|
// packages/cli/client/agentRun.ts
|
|
11416
11021
|
async function loadRunLocalAgentTurn() {
|
|
11417
|
-
const { runLocalAgentTurn } = await import("./agentRuntimeLocal-
|
|
11022
|
+
const { runLocalAgentTurn } = await import("./agentRuntimeLocal-SD7U2EGY.js");
|
|
11418
11023
|
return runLocalAgentTurn;
|
|
11419
11024
|
}
|
|
11420
11025
|
var stripDebugNoise = (s) => s.replace(/\s*raw="[\s\S]*"/g, "").replace(/\s*raw=\S+/g, "").replace(/\s*headers=\[[^\]]*\]/g, "").replace(/\s*headers=\S+/g, "").trim();
|
|
@@ -11690,6 +11295,7 @@ function looksLikeQuotaExhaustedText(message) {
|
|
|
11690
11295
|
}
|
|
11691
11296
|
var BARE_UPSTREAM_5XX_RE = /\bHTTP[:\s]+(5\d\d)\b|\bstatus[:\s=]+(5\d\d)\b|\breturned error\s+(5\d\d)\b/i;
|
|
11692
11297
|
function classifyLocalRunError(message) {
|
|
11298
|
+
if (isHistoryIntegrityFailure(message)) return { kind: "history_integrity" };
|
|
11693
11299
|
const m = message.match(PROVIDER_HTTP_FAILED_RE);
|
|
11694
11300
|
if (m) {
|
|
11695
11301
|
const status = Number(m[2]);
|
|
@@ -11982,8 +11588,7 @@ function buildRateLimitFailure(ctx) {
|
|
|
11982
11588
|
t(
|
|
11983
11589
|
"localRunRateLimitCooldown",
|
|
11984
11590
|
formatCooldownUntilLocal(cooldownUntil),
|
|
11985
|
-
resetValue ? t("localRunRateLimitResetNote", resetValue) : ""
|
|
11986
|
-
String(Math.round(PROBE_INTERVAL_MS / 6e4))
|
|
11591
|
+
resetValue ? t("localRunRateLimitResetNote", resetValue) : ""
|
|
11987
11592
|
)
|
|
11988
11593
|
);
|
|
11989
11594
|
}
|
|
@@ -12066,8 +11671,52 @@ function buildUpstreamFailure(ctx) {
|
|
|
12066
11671
|
return `${RUN_UNAVAILABLE_PREFIX} (${ctx.where} returned HTTP ${ctx.status}). Detail: ${ctx.message} ${NO_FALLBACK} ${fix}, ${SERVER_FALLBACK_HINT}
|
|
12067
11672
|
`;
|
|
12068
11673
|
}
|
|
11674
|
+
function describeHistoryIntegrityFailure(message) {
|
|
11675
|
+
const ids = [...new Set(message.match(/\bcall_[A-Za-z0-9_-]+\b/g) ?? [])];
|
|
11676
|
+
const pairing = ids.length ? ` Missing tool result pairing: ${ids.join(", ")}.` : "";
|
|
11677
|
+
return `[nolo] history_integrity: Strict continuation history could not be verified.${pairing} Restore verified complete history from the original host or finish verified history recovery before retrying. No history was discarded or fabricated; blind retry will not repair coverage.
|
|
11678
|
+
`;
|
|
11679
|
+
}
|
|
11680
|
+
var LOCAL_CONTEXT_COVERAGE_TEXT = "Context protection: history cannot fit without losing messages";
|
|
11681
|
+
function isLocalContextCoverageFailure(error) {
|
|
11682
|
+
return error?.code === "LOCAL_CONTEXT_COVERAGE_REQUIRED" || toErrorMessage(error).includes(LOCAL_CONTEXT_COVERAGE_TEXT);
|
|
11683
|
+
}
|
|
11684
|
+
var BATCH_RECEIPT_MISSING_TEXT = "Missing durable batch receipt";
|
|
11685
|
+
function isMissingBatchReceiptFailure(message) {
|
|
11686
|
+
return message.includes(BATCH_RECEIPT_MISSING_TEXT);
|
|
11687
|
+
}
|
|
11688
|
+
function describeMissingBatchReceipt() {
|
|
11689
|
+
return "this turn's queued message batch has no durable admission receipt in this dialog, so the send state cannot be verified from local records. Your messages are kept. Re-send only if the previous reply never arrived; if it repeats, restart the TUI to restore the queue. This is not a credential or config problem";
|
|
11690
|
+
}
|
|
11691
|
+
function describeCliBatchPhaseFailure(error) {
|
|
11692
|
+
const cause = error.cause instanceof Error ? error.cause.message : String(error.cause ?? "");
|
|
11693
|
+
if (!error.requestStarted) {
|
|
11694
|
+
if (/already requested/i.test(cause)) {
|
|
11695
|
+
return `[nolo] queued batch ${error.batchId} was already requested; this attempt was blocked and not re-sent. The earlier attempt may have been sent and billed \u2014 check the dialog history before resending.
|
|
11696
|
+
`;
|
|
11697
|
+
}
|
|
11698
|
+
return `[nolo] queued batch ${error.batchId} was blocked before the model was called; this attempt was not sent and was not re-sent. The prior send state is unknown. ${cause} Your messages are kept.
|
|
11699
|
+
`;
|
|
11700
|
+
}
|
|
11701
|
+
return `[nolo] queued batch ${error.batchId}: the model was called but the reply/completion evidence was not confirmed saved. It was not re-sent. Check the dialog history before resending. ${cause}
|
|
11702
|
+
`;
|
|
11703
|
+
}
|
|
11704
|
+
function isCliBatchPhaseFailure(error) {
|
|
11705
|
+
return error?.code === "cli_batch_phase_failed";
|
|
11706
|
+
}
|
|
12069
11707
|
function formatLocalTurnFailureLine(error) {
|
|
12070
11708
|
const message = toErrorMessage(error);
|
|
11709
|
+
if (isCliBatchPhaseFailure(error)) {
|
|
11710
|
+
return describeCliBatchPhaseFailure(error);
|
|
11711
|
+
}
|
|
11712
|
+
if (isLocalContextCoverageFailure(error)) {
|
|
11713
|
+
return `[nolo] ${describeContextRefusal(contextRefusalDiagnostics(error))}
|
|
11714
|
+
`;
|
|
11715
|
+
}
|
|
11716
|
+
if (isMissingBatchReceiptFailure(message)) {
|
|
11717
|
+
return `[nolo] ${describeMissingBatchReceipt()}.
|
|
11718
|
+
`;
|
|
11719
|
+
}
|
|
12071
11720
|
if (error?.code === "LLM_REQUEST_TIMEOUT") {
|
|
12072
11721
|
const msMatch = /after (\d+)ms/.exec(message);
|
|
12073
11722
|
const deadline = msMatch && Number.isFinite(Number(msMatch[1])) ? formatElapsed(Math.round(Number(msMatch[1]) / 1e3)) : "the configured window";
|
|
@@ -12075,6 +11724,7 @@ function formatLocalTurnFailureLine(error) {
|
|
|
12075
11724
|
`;
|
|
12076
11725
|
}
|
|
12077
11726
|
const cls = classifyLocalRunError(message);
|
|
11727
|
+
if (cls.kind === "history_integrity") return describeHistoryIntegrityFailure(message);
|
|
12078
11728
|
if (cls.kind === "rate-limit") {
|
|
12079
11729
|
const rawCooldownUntil = error && typeof error === "object" ? error.cooldownUntil : void 0;
|
|
12080
11730
|
return buildRateLimitFailure({
|
|
@@ -12153,9 +11803,21 @@ function describeLocalRunFailure(message, rawError) {
|
|
|
12153
11803
|
if (isCliAuthorityBrokerProtocolError(rawError) || /CLI authority broker protocol|CLI authority broker .* returned malformed response/i.test(message)) {
|
|
12154
11804
|
const cleaned = stripDebugNoise(message);
|
|
12155
11805
|
return `${RUN_UNAVAILABLE_PREFIX} (${cleaned}). ${NO_FALLBACK} The local authority broker returned a protocol or malformed response error. Check the running broker process and retry, ${SERVER_FALLBACK_HINT}
|
|
11806
|
+
`;
|
|
11807
|
+
}
|
|
11808
|
+
if (isCliBatchPhaseFailure(rawError)) {
|
|
11809
|
+
return describeCliBatchPhaseFailure(rawError);
|
|
11810
|
+
}
|
|
11811
|
+
if (isLocalContextCoverageFailure(rawError ?? message)) {
|
|
11812
|
+
return `[nolo] ${describeContextRefusal(contextRefusalDiagnostics(rawError))}
|
|
11813
|
+
`;
|
|
11814
|
+
}
|
|
11815
|
+
if (isMissingBatchReceiptFailure(message)) {
|
|
11816
|
+
return `[nolo] ${describeMissingBatchReceipt()}.
|
|
12156
11817
|
`;
|
|
12157
11818
|
}
|
|
12158
11819
|
const cls = classifyLocalRunError(message);
|
|
11820
|
+
if (cls.kind === "history_integrity") return describeHistoryIntegrityFailure(message);
|
|
12159
11821
|
if (cls.kind === "generic") {
|
|
12160
11822
|
if (/owner-required route not acknowledged/i.test(message)) {
|
|
12161
11823
|
return `${RUN_UNAVAILABLE_PREFIX} (${message}). ${NO_FALLBACK} The server returned a successful response but did not acknowledge the owner route. Check server version or proxy configuration, ${SERVER_FALLBACK_HINT}
|
|
@@ -12344,7 +12006,7 @@ async function runHttpAgentTurn(options, authToken) {
|
|
|
12344
12006
|
const contentType = res.headers.get("content-type") || "";
|
|
12345
12007
|
if (contentType.includes("text/event-stream") && res.body) {
|
|
12346
12008
|
const result = await readStreamingAgentRun(options, res, spinner);
|
|
12347
|
-
return result;
|
|
12009
|
+
return { ...result, httpOutcome: { status: res.status } };
|
|
12348
12010
|
}
|
|
12349
12011
|
spinner.stop();
|
|
12350
12012
|
let data = {};
|
|
@@ -12431,7 +12093,7 @@ ${options.agentName} > (no text response)
|
|
|
12431
12093
|
model: typeof data?.model === "string" ? data.model : void 0,
|
|
12432
12094
|
dialogServer: serverOriginForDialog(options.serverUrl)
|
|
12433
12095
|
});
|
|
12434
|
-
return serverResult;
|
|
12096
|
+
return { ...serverResult, httpOutcome: { status: res.status, body: data } };
|
|
12435
12097
|
}
|
|
12436
12098
|
async function runInjectedLocalAgentTurn(options) {
|
|
12437
12099
|
return runLocalAgentTurnForCli(options, { reportFailure: true });
|
|
@@ -12527,14 +12189,189 @@ async function executeLocalAgentTurnForCliWithAdapter(options, settings, resolve
|
|
|
12527
12189
|
} : void 0;
|
|
12528
12190
|
const currentDialogId = options.continueDialogId ?? ulid2();
|
|
12529
12191
|
const freshDialog = options.freshDialog ?? !options.continueDialogId;
|
|
12192
|
+
options = { ...options, hostTaskRef: resolveCurrentHostTaskReference({
|
|
12193
|
+
reference: options.hostTaskRef,
|
|
12194
|
+
workspace: options.localRuntimeCwd ?? process.cwd(),
|
|
12195
|
+
dialogId: currentDialogId,
|
|
12196
|
+
env: options.env
|
|
12197
|
+
}) };
|
|
12530
12198
|
const turnId = `turn-${ulid2()}`;
|
|
12531
12199
|
const runtimeContextWithOwnership = {
|
|
12532
12200
|
...runtimeContext ?? {},
|
|
12533
12201
|
dialogId: currentDialogId,
|
|
12534
|
-
turnId
|
|
12202
|
+
turnId,
|
|
12203
|
+
getProcessCausalDepth: options.getProcessCausalDepth
|
|
12204
|
+
};
|
|
12205
|
+
const installReviewHost = baseAdapter.installTaskReviewHost;
|
|
12206
|
+
if (options.hostTaskRef && installReviewHost) {
|
|
12207
|
+
const scope = structuredClone(options.hostTaskRef);
|
|
12208
|
+
const authorExecutionId = createHostAuthorExecution(options.env, scope, turnId);
|
|
12209
|
+
installReviewHost({ scope, authorExecutionId, authorize: async () => {
|
|
12210
|
+
if (!scope.taskId?.trim() || !scope.workspace?.trim() || !scope.dialogId?.trim() || scope.dialogId !== currentDialogId || resolveHostReviewPath(scope.workspace) !== resolveHostReviewPath(options.localRuntimeCwd ?? process.cwd())) throw new Error("task_review_host_scope_mismatch");
|
|
12211
|
+
} });
|
|
12212
|
+
}
|
|
12213
|
+
let reviewContext;
|
|
12214
|
+
const requestedReview = options.hostReviewDispatch;
|
|
12215
|
+
if (requestedReview && options.hostTaskRef && requestedReview.scope.taskId === options.hostTaskRef.taskId && requestedReview.scope.dialogId === currentDialogId && resolveHostReviewPath(requestedReview.scope.workspace) === resolveHostReviewPath(options.hostTaskRef.workspace)) {
|
|
12216
|
+
reviewContext = { ...requestedReview, authorExecutionId: createHostAuthorExecution(options.env, options.hostTaskRef, turnId) };
|
|
12217
|
+
}
|
|
12218
|
+
const commandVersionBindings = /* @__PURE__ */ new Map();
|
|
12219
|
+
const commandAdapter = !options.runtimeKey || options.runtimeKey === "local" ? wrapLocalCommandWorkspaceObservation(baseAdapter, options.localRuntimeCwd ?? process.cwd(), commandVersionBindings, void 0, options.abortSignal) : baseAdapter;
|
|
12220
|
+
const reviewAdapter = {
|
|
12221
|
+
...commandAdapter,
|
|
12222
|
+
executeTool: async (call, opts) => {
|
|
12223
|
+
let args = {};
|
|
12224
|
+
try {
|
|
12225
|
+
args = typeof call.arguments === "string" ? JSON.parse(call.arguments) : call.arguments ?? {};
|
|
12226
|
+
} catch {
|
|
12227
|
+
}
|
|
12228
|
+
const matched = call.name === "startAgentRun" && matchesHostReviewDispatch(reviewContext, call, args);
|
|
12229
|
+
const result = await withHostReviewDispatch(matched ? reviewContext : void 0, () => commandAdapter.executeTool(call, opts));
|
|
12230
|
+
return result;
|
|
12231
|
+
}
|
|
12232
|
+
};
|
|
12233
|
+
const completionEvidenceProvider = options.hostTaskRef ? options.hostTaskCompletionEvidenceProvider : void 0;
|
|
12234
|
+
let hostTask = bindHostTask({
|
|
12235
|
+
adapter: reviewAdapter,
|
|
12236
|
+
reference: options.hostTaskRef,
|
|
12237
|
+
workspace: options.localRuntimeCwd ?? process.cwd(),
|
|
12238
|
+
dialogId: currentDialogId,
|
|
12239
|
+
env: options.env,
|
|
12240
|
+
signal: options.abortSignal,
|
|
12241
|
+
completionEvidenceProvider
|
|
12242
|
+
});
|
|
12243
|
+
if (options.hostTaskRef && options.hostTaskWorkspaceEvidence !== void 0 && readHostTask(hostTaskEventsRoot(options.env), options.hostTaskRef).authorization === "active") {
|
|
12244
|
+
const blocker = await assessHostTaskWorkspace({
|
|
12245
|
+
reference: options.hostTaskRef,
|
|
12246
|
+
workspace: options.localRuntimeCwd ?? process.cwd(),
|
|
12247
|
+
dialogId: currentDialogId,
|
|
12248
|
+
env: options.env,
|
|
12249
|
+
evidence: options.hostTaskWorkspaceEvidence
|
|
12250
|
+
});
|
|
12251
|
+
if (blocker) {
|
|
12252
|
+
options.output.write(`[auto-review] blocked: ${blocker.hostTaskWorkspaceBlocker}
|
|
12253
|
+
`);
|
|
12254
|
+
try {
|
|
12255
|
+
const saved = await reviewAdapter.saveTurn({
|
|
12256
|
+
agentKey: options.agentKey,
|
|
12257
|
+
messages: [{ role: "user", content: options.message }],
|
|
12258
|
+
continueDialogId: currentDialogId,
|
|
12259
|
+
runtimeContext: runtimeContextWithOwnership,
|
|
12260
|
+
result: {
|
|
12261
|
+
model: "host-workspace-assessment",
|
|
12262
|
+
content: "",
|
|
12263
|
+
error: true,
|
|
12264
|
+
businessCompletion: blocker.businessCompletion
|
|
12265
|
+
}
|
|
12266
|
+
});
|
|
12267
|
+
return {
|
|
12268
|
+
...blocker,
|
|
12269
|
+
hostTaskRef: options.hostTaskRef,
|
|
12270
|
+
dialogId: saved.dialogId,
|
|
12271
|
+
taskAuthorization: readHostTask(hostTaskEventsRoot(options.env), options.hostTaskRef).authorization
|
|
12272
|
+
};
|
|
12273
|
+
} catch (localError) {
|
|
12274
|
+
return { ...blocker, hostTaskRef: options.hostTaskRef, localError };
|
|
12275
|
+
}
|
|
12276
|
+
}
|
|
12277
|
+
}
|
|
12278
|
+
let usedReviewTool = false;
|
|
12279
|
+
let batchProviderStarted = false;
|
|
12280
|
+
let mainProviderStarted = false;
|
|
12281
|
+
let refusalModel = "";
|
|
12282
|
+
let turnPersisted = false;
|
|
12283
|
+
let batchIdentity;
|
|
12284
|
+
try {
|
|
12285
|
+
batchIdentity = resolveCliBatchIdentity(options);
|
|
12286
|
+
} catch (error) {
|
|
12287
|
+
options.output.write(`[nolo] ${error instanceof Error ? error.message : String(error)}
|
|
12288
|
+
`);
|
|
12289
|
+
return { exitCode: 1, localError: error };
|
|
12290
|
+
}
|
|
12291
|
+
const markBatch = async (phase) => {
|
|
12292
|
+
if (!batchIdentity) return;
|
|
12293
|
+
const store = await getOrCreateSharedStore({ env: options.env, cwd: options.localRuntimeCwd, fetchImpl: options.fetchImpl });
|
|
12294
|
+
try {
|
|
12295
|
+
await markCliUserBatchPhase(store, currentDialogId, batchIdentity.batchId, phase, batchIdentity.messageIds, phase === "requested" ? options.userMessages : void 0);
|
|
12296
|
+
} catch (error) {
|
|
12297
|
+
throw cliBatchPhaseFailure({ phase, batchId: batchIdentity.batchId, requestStarted: false, replyPersisted: false, cause: error });
|
|
12298
|
+
}
|
|
12299
|
+
};
|
|
12300
|
+
const adapter = {
|
|
12301
|
+
...hostTask.adapter,
|
|
12302
|
+
resolveProvider: async (...args) => {
|
|
12303
|
+
const provider = await hostTask.adapter.resolveProvider(...args);
|
|
12304
|
+
const isTextOnly = Boolean(args[1]?.textOnly);
|
|
12305
|
+
if (!isTextOnly) refusalModel = provider.model;
|
|
12306
|
+
return {
|
|
12307
|
+
...provider,
|
|
12308
|
+
complete: async (...completeArgs) => {
|
|
12309
|
+
if (!isTextOnly) {
|
|
12310
|
+
mainProviderStarted = true;
|
|
12311
|
+
}
|
|
12312
|
+
if (batchIdentity && !isTextOnly && !batchProviderStarted) {
|
|
12313
|
+
await markBatch("requested");
|
|
12314
|
+
batchProviderStarted = true;
|
|
12315
|
+
}
|
|
12316
|
+
return provider.complete(...completeArgs);
|
|
12317
|
+
}
|
|
12318
|
+
};
|
|
12319
|
+
},
|
|
12320
|
+
executeTool: async (call, opts) => {
|
|
12321
|
+
const protectedReview = call.name === "requestTaskReview" || call.name === "recordTaskReviewDecision";
|
|
12322
|
+
if (!protectedReview) return reviewAdapter.executeTool(call, opts);
|
|
12323
|
+
usedReviewTool = true;
|
|
12324
|
+
if (options.hostTaskRef?.taskInstanceId) {
|
|
12325
|
+
const authorize = baseAdapter.authorizeAccountTask;
|
|
12326
|
+
if (!authorize) throw new Error("task_review_account_authorization_unavailable");
|
|
12327
|
+
await authorize(options.hostTaskRef);
|
|
12328
|
+
}
|
|
12329
|
+
if (!options.hostTaskRef && ["requestTaskReview", "recordTaskReviewDecision"].includes(call.name)) {
|
|
12330
|
+
const admit = baseAdapter.admitAccountReviewTurn;
|
|
12331
|
+
if (!admit) throw new Error("task_review_account_admission_unavailable");
|
|
12332
|
+
const reference = await admit(currentDialogId, turnId);
|
|
12333
|
+
options = { ...options, hostTaskRef: reference };
|
|
12334
|
+
hostTask = bindHostTask({ adapter: reviewAdapter, reference, workspace: options.localRuntimeCwd ?? process.cwd(), dialogId: currentDialogId, env: options.env, signal: options.abortSignal });
|
|
12335
|
+
}
|
|
12336
|
+
return hostTask.adapter.executeTool(call, opts);
|
|
12337
|
+
},
|
|
12338
|
+
saveTurn: async (input) => {
|
|
12339
|
+
if (usedReviewTool && options.hostTaskRef) await settleHostReviewsForScope(options.hostTaskRef, options.env, options.hostReviewContentAcceptance);
|
|
12340
|
+
const completeBatch = Boolean(batchIdentity && batchProviderStarted && !input.result.error);
|
|
12341
|
+
const injectedBatches = options.drainInjectedBatches ?? [];
|
|
12342
|
+
const injectedMessageIds = new Set(injectedBatches.flatMap((batch) => batch.messageIds));
|
|
12343
|
+
const completeBatchIds = [
|
|
12344
|
+
...completeBatch ? [batchIdentity.batchId] : [],
|
|
12345
|
+
...!input.result.error ? injectedBatches.map((batch) => batch.batchId) : []
|
|
12346
|
+
];
|
|
12347
|
+
try {
|
|
12348
|
+
const saved = await hostTask.adapter.saveTurn({
|
|
12349
|
+
...input,
|
|
12350
|
+
messages: input.messages.filter((message) => {
|
|
12351
|
+
const cliMessageId = message.cliMessageId;
|
|
12352
|
+
if (!cliMessageId) return true;
|
|
12353
|
+
if (options.userMessages?.some((user) => user.cliMessageId === cliMessageId)) return false;
|
|
12354
|
+
if (injectedMessageIds.has(cliMessageId)) return false;
|
|
12355
|
+
return true;
|
|
12356
|
+
}),
|
|
12357
|
+
...completeBatchIds.length ? { cliBatchCompletion: { batchIds: completeBatchIds } } : {}
|
|
12358
|
+
});
|
|
12359
|
+
turnPersisted = true;
|
|
12360
|
+
return saved;
|
|
12361
|
+
} catch (error) {
|
|
12362
|
+
if (batchIdentity && batchProviderStarted) {
|
|
12363
|
+
throw cliBatchPhaseFailure({ phase: "completed", batchId: batchIdentity.batchId, requestStarted: true, replyPersisted: false, cause: error });
|
|
12364
|
+
}
|
|
12365
|
+
throw error;
|
|
12366
|
+
}
|
|
12367
|
+
}
|
|
12535
12368
|
};
|
|
12536
|
-
const adapter = baseAdapter;
|
|
12537
12369
|
const expandedMessage = options.pastedTextStore?.items.size ? expandCollapsedPastes(options.message, options.pastedTextStore) : options.message;
|
|
12370
|
+
const commandObservations = [];
|
|
12371
|
+
const retainCommandObservations = (result) => {
|
|
12372
|
+
recordRunResultHeaderMeta(result, { commandObservations });
|
|
12373
|
+
return result;
|
|
12374
|
+
};
|
|
12538
12375
|
const workingLabel = `${options.agentName} -> working locally`;
|
|
12539
12376
|
const turnOutput = createCliTurnOutput({
|
|
12540
12377
|
options,
|
|
@@ -12556,9 +12393,11 @@ async function executeLocalAgentTurnForCliWithAdapter(options, settings, resolve
|
|
|
12556
12393
|
const runLocalAgentTurn = await loadRunLocalAgentTurn();
|
|
12557
12394
|
const result = await runLocalAgentTurn({
|
|
12558
12395
|
adapter,
|
|
12396
|
+
...hostTask.contract ? { taskExecutionContract: hostTask.contract } : {},
|
|
12559
12397
|
agentRef: options.agentKey,
|
|
12560
12398
|
userLanguage: options.userLanguage ?? options.env.NOLO_LANG ?? null,
|
|
12561
12399
|
input: buildUserInputContent(messageForLocal, options.imageUrls),
|
|
12400
|
+
userMessages: options.userMessages,
|
|
12562
12401
|
...expandedMessage !== options.message || localAttachmentCard !== "" ? {
|
|
12563
12402
|
persistedInput: hasDurableAttachments ? buildUserInputContent(
|
|
12564
12403
|
expandedMessage,
|
|
@@ -12606,15 +12445,7 @@ async function executeLocalAgentTurnForCliWithAdapter(options, settings, resolve
|
|
|
12606
12445
|
if (event.kind === "turn-phase") {
|
|
12607
12446
|
turnOutput.showPhase(event.phase);
|
|
12608
12447
|
}
|
|
12609
|
-
|
|
12610
|
-
turnOutput.showPhase("compacting");
|
|
12611
|
-
}
|
|
12612
|
-
if (event.kind === "compaction-end" || // 压缩失败(timeout/provider-error)时 localLoop 按失败原子性语义
|
|
12613
|
-
// 带着裁剪后的历史继续本轮,切回等待模型文案;aborted 时 turn 随即
|
|
12614
|
-
// 结束,不再切文案(终态由 abort 路径收尾)。
|
|
12615
|
-
event.kind === "compaction-failed" && event.reason !== "aborted") {
|
|
12616
|
-
turnOutput.showPhase("waiting-provider");
|
|
12617
|
-
}
|
|
12448
|
+
turnOutput.handleCompactionActivity(event);
|
|
12618
12449
|
if (event.kind === "image-downgraded") {
|
|
12619
12450
|
options.output.write(
|
|
12620
12451
|
"[nolo] \u5F53\u524D agent \u88AB\u914D\u7F6E\u4E3A\u4E0D\u652F\u6301\u56FE\u7247\u8F93\u5165\uFF0C\u56FE\u7247\u5DF2\u7528\u5360\u4F4D\u6587\u672C\u66FF\u4EE3\u3002\u8BF7\u68C0\u67E5\u6A21\u578B\u7684\u56FE\u7247\u80FD\u529B\u914D\u7F6E\uFF0C\u6216\u7528 /switch \u9009\u62E9\u652F\u6301\u56FE\u7247\u7684 agent \u540E\u91CD\u65B0\u53D1\u9001\u56FE\u7247\u3002\n"
|
|
@@ -12631,6 +12462,8 @@ async function executeLocalAgentTurnForCliWithAdapter(options, settings, resolve
|
|
|
12631
12462
|
// tool-gist-fold 后 onToolEvent 无条件挂载(不再受 traceLocalTools 开关
|
|
12632
12463
|
// 控制,显示模式合并为单一 gist/折叠通道)——保留 alpha 的新形态。
|
|
12633
12464
|
onToolEvent: (event) => {
|
|
12465
|
+
const observation = observeLocalCommandResult(event, options.localRuntimeCwd ?? process.cwd());
|
|
12466
|
+
if (observation) commandObservations.push({ ...observation, ...commandVersionBindings.get(event.toolCallId) });
|
|
12634
12467
|
turnOutput.handleToolEvent(event);
|
|
12635
12468
|
},
|
|
12636
12469
|
...!options.noStream ? {
|
|
@@ -12643,21 +12476,30 @@ async function executeLocalAgentTurnForCliWithAdapter(options, settings, resolve
|
|
|
12643
12476
|
} : {}
|
|
12644
12477
|
});
|
|
12645
12478
|
turnOutput.finish(result.content);
|
|
12479
|
+
const usageRecords = result.usageRecords?.filter(
|
|
12480
|
+
(record) => Object.keys(record.usage ?? {}).length > 0
|
|
12481
|
+
);
|
|
12646
12482
|
const turnCredits = sumPlatformCredits(result.usageRecords);
|
|
12483
|
+
const turnTokens = withTurnCredits(buildTurnTokenUsage(result.usage, result.model), turnCredits);
|
|
12647
12484
|
const turnResult = {
|
|
12485
|
+
savedTurnPersisted: turnPersisted,
|
|
12486
|
+
mainProviderAttempted: mainProviderStarted,
|
|
12648
12487
|
exitCode: 0,
|
|
12488
|
+
stopReason: result.stopReason,
|
|
12489
|
+
...hostTask.result(),
|
|
12490
|
+
...options.hostTaskRef ? { hostTaskRef: options.hostTaskRef } : {},
|
|
12649
12491
|
dialogId: result.dialogId,
|
|
12650
12492
|
...typeof result.content === "string" && result.content.trim() ? { finalText: result.content } : {},
|
|
12651
|
-
title: result.title,
|
|
12493
|
+
...result.title !== void 0 ? { title: result.title } : {},
|
|
12652
12494
|
...result.titlePatchPromise ? { titlePatchPromise: result.titlePatchPromise } : {},
|
|
12653
12495
|
...pickEmptyAssistantFlags(result),
|
|
12654
12496
|
// 积分口径按「全轮」而非「最后一次调用」:result.usage 只是收尾那次
|
|
12655
12497
|
// provider 调用的 usage,本轮前面 N-1 次工具循环调用(以及自动压缩摘要)
|
|
12656
12498
|
// 的 cost 都只存在于 usageRecords 里。token 字段仍取 result.usage——
|
|
12657
12499
|
// 上下文占用本来就该看最后一次调用的累计输入,不是各次相加。
|
|
12658
|
-
turnTokens
|
|
12500
|
+
...turnTokens !== void 0 ? { turnTokens } : {},
|
|
12659
12501
|
...turnCredits !== void 0 ? { turnCredits } : {},
|
|
12660
|
-
...
|
|
12502
|
+
...usageRecords?.length ? { usageRecords } : {}
|
|
12661
12503
|
};
|
|
12662
12504
|
const serverMeta = resolveResultServerMeta({
|
|
12663
12505
|
env: options.env ?? {},
|
|
@@ -12665,6 +12507,7 @@ async function executeLocalAgentTurnForCliWithAdapter(options, settings, resolve
|
|
|
12665
12507
|
hasSubjectRefs: (buildSubjectRefs(options)?.length ?? 0) > 0
|
|
12666
12508
|
});
|
|
12667
12509
|
recordRunResultHeaderMeta(turnResult, {
|
|
12510
|
+
commandObservations,
|
|
12668
12511
|
model: result.model,
|
|
12669
12512
|
dialogServer: serverMeta.server,
|
|
12670
12513
|
serverSync: serverMeta.serverSync
|
|
@@ -12680,14 +12523,18 @@ async function executeLocalAgentTurnForCliWithAdapter(options, settings, resolve
|
|
|
12680
12523
|
const abortedTurnCredits = sumPlatformCredits(abortedUsageRecords);
|
|
12681
12524
|
if (error?.code === LOCAL_TURN_ABORTED_CODE || options.abortSignal?.aborted) {
|
|
12682
12525
|
const pendingToolName = error?.pendingToolName;
|
|
12683
|
-
return {
|
|
12526
|
+
return retainCommandObservations({
|
|
12684
12527
|
exitCode: 0,
|
|
12528
|
+
...hostTask.result(),
|
|
12529
|
+
savedTurnPersisted: turnPersisted,
|
|
12530
|
+
mainProviderAttempted: mainProviderStarted,
|
|
12531
|
+
...options.hostTaskRef ? { hostTaskRef: options.hostTaskRef } : {},
|
|
12685
12532
|
streamInterrupted: true,
|
|
12686
12533
|
...savedDialogId ? { dialogId: savedDialogId } : {},
|
|
12687
12534
|
...pendingToolName ? { pendingToolName } : {},
|
|
12688
12535
|
...abortedTurnCredits !== void 0 ? { turnCredits: abortedTurnCredits } : {},
|
|
12689
12536
|
...abortedUsageRecords?.length ? { usageRecords: abortedUsageRecords } : {}
|
|
12690
|
-
};
|
|
12537
|
+
});
|
|
12691
12538
|
}
|
|
12692
12539
|
const cooldownUntil = await markStartupRateLimitCooldown(
|
|
12693
12540
|
options,
|
|
@@ -12698,27 +12545,59 @@ async function executeLocalAgentTurnForCliWithAdapter(options, settings, resolve
|
|
|
12698
12545
|
error.cooldownUntil = cooldownUntil;
|
|
12699
12546
|
}
|
|
12700
12547
|
if (settings.reportFailure) {
|
|
12701
|
-
const
|
|
12702
|
-
if (
|
|
12703
|
-
|
|
12704
|
-
|
|
12705
|
-
|
|
12548
|
+
const suppressOutput = options.interactiveHost && isLocalContextCoverageFailure(error);
|
|
12549
|
+
if (!suppressOutput) {
|
|
12550
|
+
const failureLine = formatLocalTurnFailureLine(error);
|
|
12551
|
+
if (typeof options.output.writeErr === "function") {
|
|
12552
|
+
options.output.writeErr(failureLine);
|
|
12553
|
+
} else {
|
|
12554
|
+
options.output.write(failureLine);
|
|
12555
|
+
}
|
|
12706
12556
|
}
|
|
12707
12557
|
}
|
|
12708
|
-
|
|
12558
|
+
const isCoverage = isLocalContextCoverageFailure(error);
|
|
12559
|
+
const persisted = turnPersisted;
|
|
12560
|
+
const isTruePreflight = isCoverage && !persisted && !mainProviderStarted;
|
|
12561
|
+
const refusal = isCoverage ? contextRefusalDiagnostics(error) : void 0;
|
|
12562
|
+
if (isCoverage) {
|
|
12563
|
+
console.warn(`[nolo] context-refusal ${JSON.stringify({
|
|
12564
|
+
dialogId: savedDialogId ?? currentDialogId,
|
|
12565
|
+
agentKey: options.agentKey,
|
|
12566
|
+
model: refusalModel,
|
|
12567
|
+
reason: refusal?.reason ?? "unknown",
|
|
12568
|
+
historyTokens: refusal?.historyTokens ?? -1,
|
|
12569
|
+
budget: refusal?.budget ?? -1,
|
|
12570
|
+
largestMessageTokens: refusal?.largestMessageTokens ?? -1,
|
|
12571
|
+
droppedCount: refusal?.droppedCount ?? 0,
|
|
12572
|
+
detail: refusal?.detail ?? "diagnostics-unavailable"
|
|
12573
|
+
})}`);
|
|
12574
|
+
}
|
|
12575
|
+
return retainCommandObservations({
|
|
12709
12576
|
exitCode: 1,
|
|
12577
|
+
...hostTask.result(),
|
|
12710
12578
|
localError: error,
|
|
12579
|
+
savedTurnPersisted: persisted,
|
|
12580
|
+
mainProviderAttempted: mainProviderStarted,
|
|
12711
12581
|
failureSubclass: classifyFailureSubclass({
|
|
12712
12582
|
message: toErrorMessage(error),
|
|
12713
12583
|
body: error
|
|
12714
12584
|
}),
|
|
12715
|
-
...savedDialogId ? { dialogId: savedDialogId } : {},
|
|
12585
|
+
...savedDialogId ? { dialogId: savedDialogId } : isCoverage ? { dialogId: currentDialogId } : {},
|
|
12586
|
+
...isTruePreflight ? {
|
|
12587
|
+
preflightBlocked: {
|
|
12588
|
+
code: "LOCAL_CONTEXT_COVERAGE_REQUIRED",
|
|
12589
|
+
phase: "preflight",
|
|
12590
|
+
retryable: true,
|
|
12591
|
+
mainRequestSent: false,
|
|
12592
|
+
...refusal ? { refusal } : {}
|
|
12593
|
+
}
|
|
12594
|
+
} : {},
|
|
12716
12595
|
...abortedTurnCredits !== void 0 ? { turnCredits: abortedTurnCredits } : {},
|
|
12717
12596
|
...abortedUsageRecords?.length ? { usageRecords: abortedUsageRecords } : {}
|
|
12718
|
-
};
|
|
12597
|
+
});
|
|
12719
12598
|
}
|
|
12720
12599
|
}
|
|
12721
|
-
async function
|
|
12600
|
+
async function resolveLocalCredentialKeysForDispatch(options) {
|
|
12722
12601
|
if (options.runtimeKey && !isDockerRuntimeKey(options.runtimeKey)) return null;
|
|
12723
12602
|
const adapter = resolveLocalRuntimeAdapter(options);
|
|
12724
12603
|
if (!adapter || typeof adapter.loadAgentConfig !== "function") return null;
|
|
@@ -12737,54 +12616,33 @@ async function checkLocalAvailabilityBeforeHttpDispatch(options) {
|
|
|
12737
12616
|
config,
|
|
12738
12617
|
options
|
|
12739
12618
|
)) {
|
|
12740
|
-
|
|
12741
|
-
}
|
|
12742
|
-
const agentLevelAt = baseRecord.nextAvailableAt;
|
|
12743
|
-
const agentLevelNextAvailableAt = typeof agentLevelAt === "number" && Number.isFinite(agentLevelAt) ? agentLevelAt : void 0;
|
|
12744
|
-
if (!credentialKey && agentLevelNextAvailableAt === void 0) {
|
|
12745
|
-
return { credentialKey };
|
|
12619
|
+
return null;
|
|
12746
12620
|
}
|
|
12747
12621
|
const env = options.env;
|
|
12748
12622
|
const now = Date.now();
|
|
12749
|
-
|
|
12750
|
-
|
|
12751
|
-
|
|
12752
|
-
|
|
12753
|
-
|
|
12754
|
-
|
|
12755
|
-
|
|
12756
|
-
|
|
12757
|
-
}
|
|
12758
|
-
|
|
12759
|
-
|
|
12760
|
-
|
|
12761
|
-
|
|
12762
|
-
|
|
12763
|
-
|
|
12764
|
-
|
|
12765
|
-
|
|
12766
|
-
now
|
|
12767
|
-
);
|
|
12768
|
-
if (gateDecision === "probe" && activeKey) {
|
|
12769
|
-
await recordCredentialProbe(activeKey, env, now).catch(() => void 0);
|
|
12770
|
-
return { credentialKey: credentialKey || activeKey, matchedKey };
|
|
12771
|
-
}
|
|
12772
|
-
if (gateDecision !== "blocked") return { credentialKey: credentialKey || activeKey, matchedKey };
|
|
12773
|
-
options.output.write(
|
|
12774
|
-
`${t(
|
|
12775
|
-
"agentCooldownBlocked",
|
|
12776
|
-
options.agentName || options.agentKey,
|
|
12777
|
-
formatCooldownUntilLocal(
|
|
12778
|
-
new Date(Number(effectiveNextAvailableAt)).toISOString()
|
|
12779
|
-
)
|
|
12780
|
-
)}
|
|
12781
|
-
`
|
|
12782
|
-
);
|
|
12783
|
-
return { exitCode: 1, failureSubclass: "rate_limit" };
|
|
12623
|
+
const entry = credentialKey ? await readEffectiveCredentialEntry(credentialKey, env, now).catch(() => void 0) : void 0;
|
|
12624
|
+
const recorder = adapter;
|
|
12625
|
+
return {
|
|
12626
|
+
credentialKey,
|
|
12627
|
+
matchedKey: entry?.matchedKey,
|
|
12628
|
+
// 真实 status/body 由调用方透传(不再固定 200 无 body):HTTP 2xx 的 body 里
|
|
12629
|
+
// 也可能带配额错误码,固定成功的判定会把这类响应当成恢复而清掉冷却。
|
|
12630
|
+
recordSuccess: recorder.recordStartupAvailabilityForAgent ? (status, body) => recorder.recordStartupAvailabilityForAgent(options.agentKey, status, body) : void 0
|
|
12631
|
+
};
|
|
12632
|
+
}
|
|
12633
|
+
function projectLocalTurnFacts(result) {
|
|
12634
|
+
return {
|
|
12635
|
+
...result.savedTurnPersisted !== void 0 ? { savedTurnPersisted: result.savedTurnPersisted } : {},
|
|
12636
|
+
...result.mainProviderAttempted !== void 0 ? { mainProviderAttempted: result.mainProviderAttempted } : {},
|
|
12637
|
+
...result.preflightBlocked !== void 0 ? { preflightBlocked: result.preflightBlocked } : {},
|
|
12638
|
+
...result.localError !== void 0 ? { localError: result.localError } : {}
|
|
12639
|
+
};
|
|
12784
12640
|
}
|
|
12785
12641
|
function foldLocalResultForTui(localResult) {
|
|
12786
12642
|
const folded = {
|
|
12787
12643
|
exitCode: localResult.exitCode,
|
|
12644
|
+
...projectLocalTurnFacts(localResult),
|
|
12645
|
+
...localResult.hostTaskRef ? { hostTaskRef: localResult.hostTaskRef } : {},
|
|
12788
12646
|
...localResult.dialogId ? { dialogId: localResult.dialogId } : {},
|
|
12789
12647
|
title: localResult.title,
|
|
12790
12648
|
...localResult.titlePatchPromise ? { titlePatchPromise: localResult.titlePatchPromise } : {},
|
|
@@ -12854,7 +12712,7 @@ async function runAgentTurn(options) {
|
|
|
12854
12712
|
}
|
|
12855
12713
|
const skipLocal = await shouldSkipAutoLocalForServerPlatformTools(options);
|
|
12856
12714
|
if (!skipLocal) {
|
|
12857
|
-
|
|
12715
|
+
let localResult = await runLocalAgentTurnForCli(options, {
|
|
12858
12716
|
reportFailure: false
|
|
12859
12717
|
});
|
|
12860
12718
|
if (localResult.exitCode === 0) {
|
|
@@ -12872,6 +12730,7 @@ async function runAgentTurn(options) {
|
|
|
12872
12730
|
const retriedLocalResult = await runLocalAgentTurnForCli(options, {
|
|
12873
12731
|
reportFailure: false
|
|
12874
12732
|
});
|
|
12733
|
+
localResult = retriedLocalResult;
|
|
12875
12734
|
if (retriedLocalResult.exitCode === 0) {
|
|
12876
12735
|
return foldLocalResultForTui(retriedLocalResult);
|
|
12877
12736
|
}
|
|
@@ -12886,19 +12745,30 @@ async function runAgentTurn(options) {
|
|
|
12886
12745
|
message: localErrorMessage,
|
|
12887
12746
|
body: localResult.localError
|
|
12888
12747
|
});
|
|
12889
|
-
options.
|
|
12890
|
-
|
|
12748
|
+
const suppressAutoFailureOutput = options.interactiveHost && Boolean(localResult.preflightBlocked || isLocalContextCoverageFailure(localResult.localError));
|
|
12749
|
+
if (!suppressAutoFailureOutput) {
|
|
12750
|
+
options.output.write(describeLocalRunFailure(localErrorMessage, localResult.localError));
|
|
12751
|
+
}
|
|
12752
|
+
const failureCoverageUsage = localResult.localError?.compactionUsage;
|
|
12753
|
+
const failureUsageRecords = failureCoverageUsage ? [...localResult.usageRecords ?? [], {
|
|
12754
|
+
// 形状对齐逐帧明细:callId 必填且本轮只有这一条救援摘要,
|
|
12755
|
+
// model 用固定标签(摘要走平台托管或当前 provider,无法从错误取得)。
|
|
12756
|
+
callId: "compaction-rescue",
|
|
12757
|
+
usage: failureCoverageUsage,
|
|
12758
|
+
model: "context-compaction"
|
|
12759
|
+
}] : localResult.usageRecords;
|
|
12760
|
+
const failedResult = {
|
|
12891
12761
|
exitCode: 1,
|
|
12762
|
+
...projectLocalTurnFacts(localResult),
|
|
12892
12763
|
failureSubclass,
|
|
12893
12764
|
...localResult.dialogId ? { dialogId: localResult.dialogId } : {},
|
|
12894
|
-
// Keep localError so TUI can show balance/quota/dialog-preserved hints
|
|
12895
|
-
// instead of only the raw auto-runtime line.
|
|
12896
|
-
...localResult.localError ? { localError: localResult.localError } : {},
|
|
12897
12765
|
// 失败轮同样可能已发生平台计费(abort/失败照样扣费):turnCredits 与
|
|
12898
12766
|
// 逐帧明细一起随行,否则审计日志在 auto 失败路径上缺账。
|
|
12899
12767
|
...localResult.turnCredits !== void 0 ? { turnCredits: localResult.turnCredits } : {},
|
|
12900
|
-
...
|
|
12768
|
+
...failureUsageRecords?.length ? { usageRecords: failureUsageRecords } : {}
|
|
12901
12769
|
};
|
|
12770
|
+
recordRunResultHeaderMeta(failedResult, getRunResultHeaderMeta(localResult));
|
|
12771
|
+
return failedResult;
|
|
12902
12772
|
}
|
|
12903
12773
|
}
|
|
12904
12774
|
if (!authToken) {
|
|
@@ -12907,20 +12777,22 @@ async function runAgentTurn(options) {
|
|
|
12907
12777
|
);
|
|
12908
12778
|
return { exitCode: 1 };
|
|
12909
12779
|
}
|
|
12910
|
-
const localAvailability = await
|
|
12911
|
-
|
|
12912
|
-
|
|
12913
|
-
|
|
12914
|
-
|
|
12915
|
-
|
|
12916
|
-
|
|
12917
|
-
|
|
12918
|
-
|
|
12919
|
-
|
|
12920
|
-
|
|
12921
|
-
|
|
12922
|
-
|
|
12923
|
-
|
|
12780
|
+
const localAvailability = await resolveLocalCredentialKeysForDispatch(options);
|
|
12781
|
+
const { httpOutcome, ...httpResult } = await runHttpAgentTurn(options, authToken);
|
|
12782
|
+
if (httpResult.exitCode === 0 && !httpResult.streamInterrupted && localAvailability) {
|
|
12783
|
+
const action = httpOutcome ? resolveAvailabilityAction(httpOutcome.status, httpOutcome.body, Date.now()) : void 0;
|
|
12784
|
+
if (action?.kind === "clear") {
|
|
12785
|
+
const keyToClear = localAvailability.credentialKey || localAvailability.matchedKey;
|
|
12786
|
+
if (keyToClear) {
|
|
12787
|
+
await clearCredentialAvailability(
|
|
12788
|
+
keyToClear,
|
|
12789
|
+
options.env
|
|
12790
|
+
).catch(() => void 0);
|
|
12791
|
+
}
|
|
12792
|
+
}
|
|
12793
|
+
if (httpOutcome) {
|
|
12794
|
+
await localAvailability.recordSuccess?.(httpOutcome.status, httpOutcome.body).catch(() => void 0);
|
|
12795
|
+
}
|
|
12924
12796
|
}
|
|
12925
12797
|
return httpResult;
|
|
12926
12798
|
}
|
|
@@ -13114,7 +12986,7 @@ function buildHostEnvironmentLayer(options) {
|
|
|
13114
12986
|
|
|
13115
12987
|
// packages/agent-runtime/agentsMd.ts
|
|
13116
12988
|
import { existsSync as existsSync2, readFileSync as readFileSync3 } from "node:fs";
|
|
13117
|
-
import { resolve as
|
|
12989
|
+
import { resolve as resolve4 } from "node:path";
|
|
13118
12990
|
var AGENTS_MD_MAX_BYTES = 8192;
|
|
13119
12991
|
var AGENTS_MD_MARKER_RESERVE_BYTES = 512;
|
|
13120
12992
|
var AGENTS_MD_CANDIDATES = ["AGENTS.md", "CLAUDE.md"];
|
|
@@ -13174,6 +13046,37 @@ var parseAgentsMdItem = (body) => {
|
|
|
13174
13046
|
rest: body.slice(firstClause.length).replace(/^[::\s]+/, "")
|
|
13175
13047
|
};
|
|
13176
13048
|
};
|
|
13049
|
+
var AGENTS_MD_COMMAND_TOKEN_PREFIX = /^(bunx?|npx|node|npm|pnpm|yarn|git|gh|tsc|deno)\b\s/;
|
|
13050
|
+
var extractAgentsMdCommandTokens = (body) => {
|
|
13051
|
+
const tokens2 = [];
|
|
13052
|
+
const seen = /* @__PURE__ */ new Set();
|
|
13053
|
+
for (const match of body.matchAll(/`([^`\n]+)`/g)) {
|
|
13054
|
+
const raw = match[1];
|
|
13055
|
+
if (!AGENTS_MD_COMMAND_TOKEN_PREFIX.test(raw)) continue;
|
|
13056
|
+
if (seen.has(raw)) continue;
|
|
13057
|
+
seen.add(raw);
|
|
13058
|
+
tokens2.push(raw);
|
|
13059
|
+
}
|
|
13060
|
+
return tokens2;
|
|
13061
|
+
};
|
|
13062
|
+
var buildAgentsMdItemGist = (firstSentence, bulletBody) => {
|
|
13063
|
+
const max = AGENTS_MD_SUMMARY_ITEM_MAX_CHARS;
|
|
13064
|
+
const clipped = clipToChars(firstSentence, max);
|
|
13065
|
+
const missing = extractAgentsMdCommandTokens(bulletBody).filter(
|
|
13066
|
+
(token) => !clipped.includes(token)
|
|
13067
|
+
);
|
|
13068
|
+
if (missing.length === 0) return clipped;
|
|
13069
|
+
let tail = "";
|
|
13070
|
+
for (const token of missing) {
|
|
13071
|
+
const candidate = tail ? `${tail} \`${token}\`` : `\`${token}\``;
|
|
13072
|
+
if (candidate.length > max) continue;
|
|
13073
|
+
tail = candidate;
|
|
13074
|
+
}
|
|
13075
|
+
if (!tail) return clipped;
|
|
13076
|
+
const room = max - tail.length - 2;
|
|
13077
|
+
const head = room > 0 ? clipToChars(firstSentence, room) : "";
|
|
13078
|
+
return head ? `${head} ${tail}` : tail;
|
|
13079
|
+
};
|
|
13177
13080
|
var priorityOf = (label) => {
|
|
13178
13081
|
const lowered = label.toLowerCase();
|
|
13179
13082
|
for (let i = 0; i < AGENTS_MD_SUMMARY_PRIORITY_KEYWORDS.length; i += 1) {
|
|
@@ -13207,7 +13110,7 @@ var collectAgentsMdSummaryItems = (content) => {
|
|
|
13207
13110
|
items.push({
|
|
13208
13111
|
section,
|
|
13209
13112
|
label,
|
|
13210
|
-
gist:
|
|
13113
|
+
gist: buildAgentsMdItemGist(firstSentence, bullet[1]),
|
|
13211
13114
|
priority: priorityOf(label)
|
|
13212
13115
|
});
|
|
13213
13116
|
}
|
|
@@ -13230,8 +13133,9 @@ ${AGENTS_MD_SUMMARY_DELETE_REFERENCE}
|
|
|
13230
13133
|
...items.filter((item) => item.priority >= 0).sort((a, b) => a.priority - b.priority),
|
|
13231
13134
|
...items.filter((item) => item.priority < 0)
|
|
13232
13135
|
];
|
|
13233
|
-
const
|
|
13234
|
-
|
|
13136
|
+
const noteBlock = `
|
|
13137
|
+
\u2026\uFF08\u7D22\u5F15\u5DF2\u622A\u65AD\uFF0C\u5176\u4F59\u951A\u70B9\u89C1\u5B8C\u6574\u6587\u4EF6\uFF09`;
|
|
13138
|
+
const noteBytes = Buffer.byteLength(noteBlock, "utf8");
|
|
13235
13139
|
let used = Buffer.byteLength(head, "utf8");
|
|
13236
13140
|
const admitted = [];
|
|
13237
13141
|
const seenSections = /* @__PURE__ */ new Set();
|
|
@@ -13265,8 +13169,7 @@ ${line}`, "utf8");
|
|
|
13265
13169
|
}
|
|
13266
13170
|
}
|
|
13267
13171
|
if (admitted.length === 0) return null;
|
|
13268
|
-
return `${head}${renderSummarySections(frozen)}${truncated ?
|
|
13269
|
-
${note}` : ""}`;
|
|
13172
|
+
return `${head}${renderSummarySections(frozen)}${truncated ? noteBlock : ""}`;
|
|
13270
13173
|
}
|
|
13271
13174
|
var renderSummarySections = (entries) => {
|
|
13272
13175
|
let rendered = "";
|
|
@@ -13284,7 +13187,7 @@ ${entry.line}`;
|
|
|
13284
13187
|
};
|
|
13285
13188
|
function readAgentsMdLayerFromDisk(cwd) {
|
|
13286
13189
|
for (const name of AGENTS_MD_CANDIDATES) {
|
|
13287
|
-
const filePath =
|
|
13190
|
+
const filePath = resolve4(cwd, name);
|
|
13288
13191
|
if (!existsSync2(filePath)) continue;
|
|
13289
13192
|
try {
|
|
13290
13193
|
const raw = readFileSync3(filePath, "utf8");
|
|
@@ -13426,16 +13329,16 @@ function runDoDCommands(commands, cwd, deps = {}) {
|
|
|
13426
13329
|
|
|
13427
13330
|
// packages/cli/agentRunPrompts.ts
|
|
13428
13331
|
import { existsSync as existsSync3, readFileSync as readFileSync4, readdirSync, statSync as statSync2 } from "node:fs";
|
|
13429
|
-
import { dirname, extname, isAbsolute as isAbsolute2, join as join2, relative as relativePath, resolve as
|
|
13332
|
+
import { dirname, extname, isAbsolute as isAbsolute2, join as join2, relative as relativePath, resolve as resolve5, sep } from "node:path";
|
|
13430
13333
|
function workflowRefToCandidatePath(cwd, ref) {
|
|
13431
13334
|
const normalized = ref.trim();
|
|
13432
13335
|
if (!normalized) return "";
|
|
13433
13336
|
if (normalized.endsWith(".md") || normalized.includes("/") || normalized.includes("\\")) {
|
|
13434
|
-
const directPath =
|
|
13337
|
+
const directPath = resolve5(cwd, normalized);
|
|
13435
13338
|
if (existsSync3(directPath)) return directPath;
|
|
13436
13339
|
}
|
|
13437
13340
|
const fileName = normalized.replace(/[^a-zA-Z0-9一-鿿]+/g, "-").replace(/^-+|-+$/g, "");
|
|
13438
|
-
return
|
|
13341
|
+
return resolve5(cwd, "docs", "workflows", `${fileName}.md`);
|
|
13439
13342
|
}
|
|
13440
13343
|
var SKILL_SEARCH_DIRS = [
|
|
13441
13344
|
".agents/skills"
|
|
@@ -13444,15 +13347,15 @@ function skillRefToCandidatePath(cwd, ref) {
|
|
|
13444
13347
|
const normalized = ref.trim();
|
|
13445
13348
|
if (!normalized) return "";
|
|
13446
13349
|
if (normalized.endsWith(".md") || normalized.includes("/") || normalized.includes("\\")) {
|
|
13447
|
-
const directPath =
|
|
13350
|
+
const directPath = resolve5(cwd, normalized);
|
|
13448
13351
|
if (existsSync3(directPath)) return directPath;
|
|
13449
13352
|
}
|
|
13450
13353
|
const fileName = normalized.replace(/[^a-zA-Z0-9一-鿿]+/g, "-").replace(/^-+|-+$/g, "");
|
|
13451
13354
|
for (const dir of SKILL_SEARCH_DIRS) {
|
|
13452
|
-
const skillMdPath =
|
|
13355
|
+
const skillMdPath = resolve5(cwd, dir, fileName, "SKILL.md");
|
|
13453
13356
|
if (existsSync3(skillMdPath)) return skillMdPath;
|
|
13454
13357
|
}
|
|
13455
|
-
return
|
|
13358
|
+
return resolve5(cwd, ".agents", "skills", fileName, "SKILL.md");
|
|
13456
13359
|
}
|
|
13457
13360
|
async function resolveWorkflowReference(ref, cwd = process.cwd()) {
|
|
13458
13361
|
const path2 = workflowRefToCandidatePath(cwd, ref);
|
|
@@ -13469,11 +13372,11 @@ async function resolveWorkflowReference(ref, cwd = process.cwd()) {
|
|
|
13469
13372
|
}
|
|
13470
13373
|
function inlineRelativeRefs(body, skillDir) {
|
|
13471
13374
|
const refPattern = /\[([^\]]+)\]\((\.\/[^)]+|[^)]+\/[^)]+)\)/g;
|
|
13472
|
-
const normalizedSkillDir =
|
|
13375
|
+
const normalizedSkillDir = resolve5(skillDir) + sep;
|
|
13473
13376
|
return body.replace(refPattern, (match, label, relPath) => {
|
|
13474
13377
|
const cleaned = relPath.trim();
|
|
13475
13378
|
if (!cleaned.startsWith("./") && !cleaned.startsWith("../")) return match;
|
|
13476
|
-
const absPath =
|
|
13379
|
+
const absPath = resolve5(skillDir, cleaned);
|
|
13477
13380
|
const relative = relativePath(normalizedSkillDir, absPath);
|
|
13478
13381
|
if (relative.startsWith("..") || isAbsolute2(relative)) return match;
|
|
13479
13382
|
if (!existsSync3(absPath) || !absPath.endsWith(".md")) return match;
|
|
@@ -13623,7 +13526,7 @@ function prependSubjectDialogMarker(message, subjectDialogKey) {
|
|
|
13623
13526
|
}
|
|
13624
13527
|
function normalizeCliImageInput(input) {
|
|
13625
13528
|
if (/^(https?:|data:|file:)/i.test(input)) return input;
|
|
13626
|
-
const absolutePath =
|
|
13529
|
+
const absolutePath = resolve5(input);
|
|
13627
13530
|
if (!existsSync3(absolutePath)) return input;
|
|
13628
13531
|
const base64 = readFileSync4(absolutePath).toString("base64");
|
|
13629
13532
|
return `data:${imageMimeTypeForPath(absolutePath)};base64,${base64}`;
|
|
@@ -13642,55 +13545,6 @@ function imageMimeTypeForPath(path2) {
|
|
|
13642
13545
|
}
|
|
13643
13546
|
}
|
|
13644
13547
|
|
|
13645
|
-
// packages/cli/agentRunLocalWorkspace.ts
|
|
13646
|
-
async function runGitForLocalSummary(args, deps = {}) {
|
|
13647
|
-
const spawn = deps.spawnProcess ?? spawnProcess;
|
|
13648
|
-
const read = deps.readPipeText ?? readPipeText;
|
|
13649
|
-
const proc = spawn({
|
|
13650
|
-
cmd: ["git", ...args.gitArgs],
|
|
13651
|
-
cwd: args.cwd,
|
|
13652
|
-
stdout: "pipe",
|
|
13653
|
-
stderr: "pipe"
|
|
13654
|
-
});
|
|
13655
|
-
const [stdout, stderr, exitCode] = await Promise.all([
|
|
13656
|
-
read(proc.stdout),
|
|
13657
|
-
read(proc.stderr),
|
|
13658
|
-
proc.exited
|
|
13659
|
-
]);
|
|
13660
|
-
if (exitCode !== 0) {
|
|
13661
|
-
throw new Error((stderr || stdout || `git ${args.gitArgs.join(" ")} failed`).trim());
|
|
13662
|
-
}
|
|
13663
|
-
return stdout.trim();
|
|
13664
|
-
}
|
|
13665
|
-
async function inspectLocalRunWorkspace(cwd, deps = {}) {
|
|
13666
|
-
const run = (gitArgs) => runGitForLocalSummary({ cwd, gitArgs }, deps);
|
|
13667
|
-
const status = await run(["status", "--short"]);
|
|
13668
|
-
const rawCommit = await run(["log", "-1", "--format=%h%x00%s"]).catch(() => "");
|
|
13669
|
-
const [hash, subject] = rawCommit.split("\0");
|
|
13670
|
-
return {
|
|
13671
|
-
cwd,
|
|
13672
|
-
clean: status.trim() === "",
|
|
13673
|
-
status,
|
|
13674
|
-
...hash ? { commit: { hash, subject: subject ?? "" } } : {}
|
|
13675
|
-
};
|
|
13676
|
-
}
|
|
13677
|
-
function shouldPrintLocalRunSummary(args) {
|
|
13678
|
-
return Boolean(args.localRuntimeCwd && args.parsed.runtimeMode === "local");
|
|
13679
|
-
}
|
|
13680
|
-
function formatLocalRunSummary(args) {
|
|
13681
|
-
return [
|
|
13682
|
-
"",
|
|
13683
|
-
"[nolo] local run summary",
|
|
13684
|
-
`workspace: ${args.inspection.cwd}`,
|
|
13685
|
-
...args.dialogId ? [`dialog: ${args.dialogId}`] : [],
|
|
13686
|
-
...args.inspection.commit ? [`commit: ${args.inspection.commit.hash} ${args.inspection.commit.subject}`] : [],
|
|
13687
|
-
`dirty: ${args.inspection.clean ? "clean" : "dirty"}`,
|
|
13688
|
-
...!args.inspection.clean && args.inspection.status.trim() ? [`status:
|
|
13689
|
-
${args.inspection.status.trim()}`] : [],
|
|
13690
|
-
""
|
|
13691
|
-
].join("\n");
|
|
13692
|
-
}
|
|
13693
|
-
|
|
13694
13548
|
// packages/ai/memory/storeShared.ts
|
|
13695
13549
|
var retrievalCountOf = (item) => item.activationCount ?? 0;
|
|
13696
13550
|
var touchMemoryItemsInDb = async (db, items, now = (/* @__PURE__ */ new Date()).toISOString()) => {
|
|
@@ -13707,367 +13561,6 @@ var touchMemoryItemsInDb = async (db, items, now = (/* @__PURE__ */ new Date()).
|
|
|
13707
13561
|
await batch.write();
|
|
13708
13562
|
};
|
|
13709
13563
|
|
|
13710
|
-
// packages/ai/memory/constants.ts
|
|
13711
|
-
var EXPLICIT_REMEMBER_PREFIX_REGEX = /^(你要记住|请记住|以后记住|记住)[,,。.\s::]*/u;
|
|
13712
|
-
|
|
13713
|
-
// packages/ai/memory/source.ts
|
|
13714
|
-
var getMemorySourceKind = (item) => {
|
|
13715
|
-
if (item.sourceKind) return item.sourceKind;
|
|
13716
|
-
if (item.patternKey === "explicit-remember") return "explicit-user-directive";
|
|
13717
|
-
if (item.patternKey === "agent-remember" || item.patternKey === "procedural-runbook")
|
|
13718
|
-
return "agent-tool";
|
|
13719
|
-
if (item.patternKey?.startsWith("dialog-learning:"))
|
|
13720
|
-
return "dialog-learning";
|
|
13721
|
-
if (item.tags?.includes("understanding-memory"))
|
|
13722
|
-
return "inferred-understanding";
|
|
13723
|
-
return "agent-tool";
|
|
13724
|
-
};
|
|
13725
|
-
|
|
13726
|
-
// packages/ai/memory/overlay.ts
|
|
13727
|
-
var KIND_TITLES = {
|
|
13728
|
-
episodic: "Episodic",
|
|
13729
|
-
semantic: "Semantic",
|
|
13730
|
-
procedural: "Procedural"
|
|
13731
|
-
};
|
|
13732
|
-
var estimateTokens = (text) => {
|
|
13733
|
-
let cjk = 0;
|
|
13734
|
-
let ascii = 0;
|
|
13735
|
-
for (const ch of text) {
|
|
13736
|
-
const code = ch.codePointAt(0) ?? 0;
|
|
13737
|
-
if (code >= 13312 && code <= 40959) cjk += 1;
|
|
13738
|
-
else ascii += 1;
|
|
13739
|
-
}
|
|
13740
|
-
return Math.ceil(cjk * 1.5 + ascii / 4);
|
|
13741
|
-
};
|
|
13742
|
-
var OVERLAY_HEADER_LINES = [
|
|
13743
|
-
"--- Memory (\u76F8\u5173\u65F6\u53C2\u8003\uFF0C\u7528\u6237\u8F93\u5165\u4F18\u5148) ---",
|
|
13744
|
-
""
|
|
13745
|
-
];
|
|
13746
|
-
var OVERLAY_HEADER_TOKENS = estimateTokens(OVERLAY_HEADER_LINES.join("\n"));
|
|
13747
|
-
var KIND_PRIORITY = {
|
|
13748
|
-
semantic: 0,
|
|
13749
|
-
procedural: 1,
|
|
13750
|
-
episodic: 2
|
|
13751
|
-
};
|
|
13752
|
-
var FACET_DISPLAY = {
|
|
13753
|
-
unfinished: { label: "\u8FD8\u6CA1\u5B9A\u4E0B", strip: "\u8FD8\u6CA1\u51B3\u5B9A" },
|
|
13754
|
-
tension: { label: "\u5728\u6743\u8861", strip: "\u5728\u6743\u8861" },
|
|
13755
|
-
preference: { label: "\u66F4\u5728\u610F", strip: "\u66F4\u5728\u610F" },
|
|
13756
|
-
style: { label: "\u66F4\u504F\u597D", strip: "\u66F4\u559C\u6B22" },
|
|
13757
|
-
goal: { label: "\u60F3\u63A8\u8FDB", strip: "\u60F3\u63A8\u8FDB" }
|
|
13758
|
-
};
|
|
13759
|
-
var INFERRED_SOURCE_KINDS = /* @__PURE__ */ new Set(["inferred-understanding", "dialog-learning"]);
|
|
13760
|
-
var isInferredMemory = (item) => INFERRED_SOURCE_KINDS.has(getMemorySourceKind(item));
|
|
13761
|
-
var formatFacetContent = (facet, normalized, prefix) => {
|
|
13762
|
-
const { label, strip } = FACET_DISPLAY[facet];
|
|
13763
|
-
const stripped = normalized.startsWith(strip) ? normalized.slice(strip.length).trim() : normalized;
|
|
13764
|
-
return `${prefix}${label} ${stripped}`;
|
|
13765
|
-
};
|
|
13766
|
-
var normalizeDisplayContent = (item) => {
|
|
13767
|
-
const normalized = item.content.trim().replace(EXPLICIT_REMEMBER_PREFIX_REGEX, "").replace(/[。!?!?]+$/u, "").trim();
|
|
13768
|
-
if (item.kind === "semantic") {
|
|
13769
|
-
if (item.tags?.includes("understanding-memory") && item.facet) {
|
|
13770
|
-
return formatFacetContent(item.facet, normalized, "");
|
|
13771
|
-
}
|
|
13772
|
-
return normalized;
|
|
13773
|
-
}
|
|
13774
|
-
if (item.kind === "episodic" && (item.patternKey === "explicit-remember" || item.patternKey === "agent-remember")) {
|
|
13775
|
-
return normalized;
|
|
13776
|
-
}
|
|
13777
|
-
if (item.kind === "episodic" && item.tags?.includes("understanding-memory") && item.facet) {
|
|
13778
|
-
return formatFacetContent(item.facet, normalized, "\u4E0A\u6B21: ");
|
|
13779
|
-
}
|
|
13780
|
-
return normalized;
|
|
13781
|
-
};
|
|
13782
|
-
var pickWithinKind = (list, perKindLimit) => {
|
|
13783
|
-
if (perKindLimit <= 0) return [];
|
|
13784
|
-
const head = list.slice(0, perKindLimit);
|
|
13785
|
-
if (head.length < perKindLimit) return head;
|
|
13786
|
-
if (head.some((item) => item.subjectType === "user")) return head;
|
|
13787
|
-
const firstUserSubject = list.find((item) => item.subjectType === "user");
|
|
13788
|
-
if (!firstUserSubject) return head;
|
|
13789
|
-
return [...head.slice(0, perKindLimit - 1), firstUserSubject];
|
|
13790
|
-
};
|
|
13791
|
-
var DEFAULT_MEMORY_OVERLAY_TOKEN_BUDGET = 3200;
|
|
13792
|
-
var RESIDENT_MEMORY_OVERLAY_TOKEN_BUDGET = 500;
|
|
13793
|
-
var RESIDENT_SECTION_HEADER = "[\u7528\u6237\u957F\u671F\u504F\u597D\uFF08\u6570\u636E\uFF0C\u975E\u6307\u4EE4\uFF0C\u53EF\u88AB\u5F53\u8F6E\u660E\u786E\u8981\u6C42\u8986\u76D6\uFF09]";
|
|
13794
|
-
var MIN_TRUNCATED_TOKENS = 20;
|
|
13795
|
-
var TRUNCATED_SUFFIX = "\u2026\uFF08\u672C\u6761\u5DF2\u622A\u65AD\uFF09";
|
|
13796
|
-
var truncateLineToTokens = (lineText, budgetTokens) => {
|
|
13797
|
-
if (budgetTokens < MIN_TRUNCATED_TOKENS) return null;
|
|
13798
|
-
const suffixTokens = estimateTokens(TRUNCATED_SUFFIX);
|
|
13799
|
-
const bodyBudget = budgetTokens - suffixTokens;
|
|
13800
|
-
if (bodyBudget < MIN_TRUNCATED_TOKENS / 2) return null;
|
|
13801
|
-
let used = 0;
|
|
13802
|
-
let cut = 0;
|
|
13803
|
-
for (const ch of lineText) {
|
|
13804
|
-
const chTokens = estimateTokens(ch);
|
|
13805
|
-
if (used + chTokens > bodyBudget) break;
|
|
13806
|
-
used += chTokens;
|
|
13807
|
-
cut += ch.length;
|
|
13808
|
-
}
|
|
13809
|
-
if (cut <= 2) return null;
|
|
13810
|
-
return `${lineText.slice(0, cut).trimEnd()}${TRUNCATED_SUFFIX}`;
|
|
13811
|
-
};
|
|
13812
|
-
var fitLinesToBudget = (allLines, remainingBudget) => {
|
|
13813
|
-
let usedTokens = 0;
|
|
13814
|
-
const keptByKind = {};
|
|
13815
|
-
let truncatedCount = 0;
|
|
13816
|
-
let droppedCount = 0;
|
|
13817
|
-
const pushLine = (kind, lineText) => {
|
|
13818
|
-
if (!keptByKind[kind]) keptByKind[kind] = [];
|
|
13819
|
-
keptByKind[kind].push(lineText);
|
|
13820
|
-
};
|
|
13821
|
-
for (const candidate of allLines) {
|
|
13822
|
-
const remaining = remainingBudget - usedTokens;
|
|
13823
|
-
if (remaining <= 0) {
|
|
13824
|
-
droppedCount += 1;
|
|
13825
|
-
continue;
|
|
13826
|
-
}
|
|
13827
|
-
if (candidate.lineTokens <= remaining) {
|
|
13828
|
-
usedTokens += candidate.lineTokens;
|
|
13829
|
-
pushLine(candidate.kind, candidate.lineText);
|
|
13830
|
-
continue;
|
|
13831
|
-
}
|
|
13832
|
-
const truncated = truncateLineToTokens(candidate.lineText, remaining);
|
|
13833
|
-
if (!truncated) {
|
|
13834
|
-
droppedCount += 1;
|
|
13835
|
-
continue;
|
|
13836
|
-
}
|
|
13837
|
-
usedTokens += estimateTokens(truncated);
|
|
13838
|
-
pushLine(candidate.kind, truncated);
|
|
13839
|
-
truncatedCount += 1;
|
|
13840
|
-
}
|
|
13841
|
-
return { keptByKind, truncatedCount, droppedCount };
|
|
13842
|
-
};
|
|
13843
|
-
var EMPTY_RETRIEVAL_FIT = {
|
|
13844
|
-
keptByKind: {},
|
|
13845
|
-
truncatedCount: 0,
|
|
13846
|
-
droppedCount: 0
|
|
13847
|
-
};
|
|
13848
|
-
var EMPTY_RESIDENT_FIT = {
|
|
13849
|
-
keptLines: [],
|
|
13850
|
-
truncatedCount: 0,
|
|
13851
|
-
droppedCount: 0
|
|
13852
|
-
};
|
|
13853
|
-
var fitResidentLines = (lines, remainingBudget) => {
|
|
13854
|
-
let usedTokens = 0;
|
|
13855
|
-
const keptLines = [];
|
|
13856
|
-
let truncatedCount = 0;
|
|
13857
|
-
let droppedCount = 0;
|
|
13858
|
-
for (const candidate of lines) {
|
|
13859
|
-
const remaining = remainingBudget - usedTokens;
|
|
13860
|
-
if (remaining <= 0) {
|
|
13861
|
-
droppedCount += 1;
|
|
13862
|
-
continue;
|
|
13863
|
-
}
|
|
13864
|
-
if (candidate.lineTokens <= remaining) {
|
|
13865
|
-
usedTokens += candidate.lineTokens;
|
|
13866
|
-
keptLines.push(candidate.lineText);
|
|
13867
|
-
continue;
|
|
13868
|
-
}
|
|
13869
|
-
const truncated = truncateLineToTokens(candidate.lineText, remaining);
|
|
13870
|
-
if (!truncated) {
|
|
13871
|
-
droppedCount += 1;
|
|
13872
|
-
continue;
|
|
13873
|
-
}
|
|
13874
|
-
usedTokens += estimateTokens(truncated);
|
|
13875
|
-
keptLines.push(truncated);
|
|
13876
|
-
truncatedCount += 1;
|
|
13877
|
-
}
|
|
13878
|
-
return { keptLines, truncatedCount, droppedCount };
|
|
13879
|
-
};
|
|
13880
|
-
var buildBudgetFooter = (fit, residentFit) => {
|
|
13881
|
-
const notices = [];
|
|
13882
|
-
if (residentFit.truncatedCount > 0) {
|
|
13883
|
-
notices.push(`${residentFit.truncatedCount} \u6761\u957F\u671F\u504F\u597D\u56E0\u9884\u7B97\u88AB\u622A\u65AD`);
|
|
13884
|
-
}
|
|
13885
|
-
if (residentFit.droppedCount > 0) {
|
|
13886
|
-
notices.push(`${residentFit.droppedCount} \u6761\u957F\u671F\u504F\u597D\u672A\u663E\u793A`);
|
|
13887
|
-
}
|
|
13888
|
-
if (fit.truncatedCount > 0) {
|
|
13889
|
-
notices.push(`${fit.truncatedCount} \u6761\u56E0\u9884\u7B97\u88AB\u622A\u65AD`);
|
|
13890
|
-
}
|
|
13891
|
-
if (fit.droppedCount > 0) {
|
|
13892
|
-
notices.push(`${fit.droppedCount} \u6761\u672A\u663E\u793A`);
|
|
13893
|
-
}
|
|
13894
|
-
if (notices.length === 0) return [];
|
|
13895
|
-
return [`\uFF08${notices.join("\u3001")}\uFF1B\u9700\u8981\u5B8C\u6574\u5185\u5BB9\u6216\u66F4\u591A\u76F8\u5173\u8BB0\u5FC6\u65F6\u7528 queryMemory \u68C0\u7D22\uFF09`];
|
|
13896
|
-
};
|
|
13897
|
-
var buildMemoryOverlay = (items, options) => {
|
|
13898
|
-
if (items.length === 0) return null;
|
|
13899
|
-
const maxTokens = options?.maxTokens ?? DEFAULT_MEMORY_OVERLAY_TOKEN_BUDGET;
|
|
13900
|
-
const perKindLimit = options?.perKindLimit ?? 3;
|
|
13901
|
-
const residentMaxTokens = options?.residentMaxTokens ?? RESIDENT_MEMORY_OVERLAY_TOKEN_BUDGET;
|
|
13902
|
-
const residentItems = items.filter((item) => item.resident === true).sort((a, b) => b.createdAt.localeCompare(a.createdAt));
|
|
13903
|
-
const retrievalItems = items.filter((item) => item.resident !== true);
|
|
13904
|
-
const residentFit = residentItems.length === 0 ? EMPTY_RESIDENT_FIT : fitResidentLines(
|
|
13905
|
-
residentItems.map((item) => {
|
|
13906
|
-
const lineText = `- ${isInferredMemory(item) ? "\uFF08\u63A8\u65AD\uFF09" : ""}${normalizeDisplayContent(item)}`;
|
|
13907
|
-
return { kind: item.kind, lineText, lineTokens: estimateTokens(lineText) };
|
|
13908
|
-
}),
|
|
13909
|
-
residentMaxTokens - estimateTokens(RESIDENT_SECTION_HEADER)
|
|
13910
|
-
);
|
|
13911
|
-
const byKind = {
|
|
13912
|
-
episodic: [],
|
|
13913
|
-
semantic: [],
|
|
13914
|
-
procedural: []
|
|
13915
|
-
};
|
|
13916
|
-
for (const item of retrievalItems) {
|
|
13917
|
-
byKind[item.kind].push(item);
|
|
13918
|
-
}
|
|
13919
|
-
const remainingBudget = maxTokens - OVERLAY_HEADER_TOKENS;
|
|
13920
|
-
let retrievalFit = EMPTY_RETRIEVAL_FIT;
|
|
13921
|
-
let retrievalSections = [];
|
|
13922
|
-
if (remainingBudget > 0 && retrievalItems.length > 0) {
|
|
13923
|
-
const allLines = Object.entries(byKind).filter(([, list]) => list.length > 0).flatMap(
|
|
13924
|
-
([kind, list]) => pickWithinKind(list, perKindLimit).map((item) => {
|
|
13925
|
-
const lineText = `- ${isInferredMemory(item) ? "\uFF08\u63A8\u65AD\uFF09" : ""}${normalizeDisplayContent(item)}`;
|
|
13926
|
-
return { kind, lineText, lineTokens: estimateTokens(lineText) };
|
|
13927
|
-
})
|
|
13928
|
-
).sort((a, b) => (KIND_PRIORITY[a.kind] ?? 99) - (KIND_PRIORITY[b.kind] ?? 99));
|
|
13929
|
-
retrievalFit = fitLinesToBudget(allLines, remainingBudget);
|
|
13930
|
-
const kindOrder = ["semantic", "procedural", "episodic"];
|
|
13931
|
-
retrievalSections = kindOrder.filter(
|
|
13932
|
-
(kind) => retrievalFit.keptByKind[kind] && retrievalFit.keptByKind[kind].length > 0
|
|
13933
|
-
).map((kind) => {
|
|
13934
|
-
return [`[${KIND_TITLES[kind]}]`, ...retrievalFit.keptByKind[kind]].join("\n");
|
|
13935
|
-
});
|
|
13936
|
-
}
|
|
13937
|
-
const sections = [
|
|
13938
|
-
...residentFit.keptLines.length > 0 ? [[RESIDENT_SECTION_HEADER, ...residentFit.keptLines].join("\n")] : [],
|
|
13939
|
-
...retrievalSections
|
|
13940
|
-
];
|
|
13941
|
-
if (sections.length === 0) {
|
|
13942
|
-
return OVERLAY_HEADER_LINES.join("\n");
|
|
13943
|
-
}
|
|
13944
|
-
return [
|
|
13945
|
-
...OVERLAY_HEADER_LINES,
|
|
13946
|
-
...sections,
|
|
13947
|
-
...buildBudgetFooter(retrievalFit, residentFit)
|
|
13948
|
-
].join("\n");
|
|
13949
|
-
};
|
|
13950
|
-
|
|
13951
|
-
// packages/ai/memory/rank.ts
|
|
13952
|
-
var CJK_SEQUENCE_REGEX = /[\u3400-\u4dbf\u4e00-\u9fff]+/g;
|
|
13953
|
-
var MEMORY_IDENTIFIER_REGEX = /\b(?:memory|noise)-[a-z0-9][a-z0-9-]*/gi;
|
|
13954
|
-
var buildCjkTokens = (text) => {
|
|
13955
|
-
const sequences = text.match(CJK_SEQUENCE_REGEX) ?? [];
|
|
13956
|
-
const tokens = [];
|
|
13957
|
-
for (const sequence2 of sequences) {
|
|
13958
|
-
if (sequence2.length >= 2) {
|
|
13959
|
-
tokens.push(sequence2);
|
|
13960
|
-
}
|
|
13961
|
-
for (let index = 0; index < sequence2.length - 1; index += 1) {
|
|
13962
|
-
tokens.push(sequence2.slice(index, index + 2));
|
|
13963
|
-
}
|
|
13964
|
-
}
|
|
13965
|
-
return tokens;
|
|
13966
|
-
};
|
|
13967
|
-
var tokenize2 = (text) => {
|
|
13968
|
-
const normalized = text.toLowerCase();
|
|
13969
|
-
const wordTokens = normalized.split(/[\s,.;:!?()[\]{}"'`,。!?:;、]+/).map((token) => token.trim()).filter((token) => token.length >= 2);
|
|
13970
|
-
return [...wordTokens, ...buildCjkTokens(normalized)];
|
|
13971
|
-
};
|
|
13972
|
-
var keywordScore = (query, item) => {
|
|
13973
|
-
const queryTokens = new Set(tokenize2(query));
|
|
13974
|
-
if (queryTokens.size === 0) return 0;
|
|
13975
|
-
const haystack = /* @__PURE__ */ new Set([
|
|
13976
|
-
...tokenize2(item.content),
|
|
13977
|
-
...(item.tags ?? []).map((tag) => tag.toLowerCase()),
|
|
13978
|
-
item.patternKey?.toLowerCase() ?? ""
|
|
13979
|
-
]);
|
|
13980
|
-
let matches = 0;
|
|
13981
|
-
for (const token of queryTokens) {
|
|
13982
|
-
if (haystack.has(token)) matches += 1;
|
|
13983
|
-
}
|
|
13984
|
-
return Math.min(1, matches / Math.max(2, queryTokens.size));
|
|
13985
|
-
};
|
|
13986
|
-
var identifierScore = (query, item) => {
|
|
13987
|
-
const identifiers = query.match(MEMORY_IDENTIFIER_REGEX) ?? [];
|
|
13988
|
-
if (identifiers.length === 0) return 0;
|
|
13989
|
-
const content = item.content.toLowerCase();
|
|
13990
|
-
const matches = identifiers.filter(
|
|
13991
|
-
(identifier) => content.includes(identifier.toLowerCase())
|
|
13992
|
-
).length;
|
|
13993
|
-
return matches / identifiers.length;
|
|
13994
|
-
};
|
|
13995
|
-
var DAY_MS = 864e5;
|
|
13996
|
-
var UNRETRIEVED_MEMORY_GRACE_DAYS = 3;
|
|
13997
|
-
var MIN_UNRETRIEVED_SCORE_FACTOR = 0.3;
|
|
13998
|
-
var UNRETRIEVED_DECAY_HALF_LIFE_DAYS = 7;
|
|
13999
|
-
var retrievalFrequencyScore = (item, nowMs) => {
|
|
14000
|
-
const lastRetrievedMs = Date.parse(item.lastActivatedAt || item.createdAt);
|
|
14001
|
-
const ageDays = Math.max(0, (nowMs - lastRetrievedMs) / DAY_MS);
|
|
14002
|
-
const recency = 1 / (1 + ageDays / 7);
|
|
14003
|
-
const frequency = Math.min(1, Math.log1p(item.activationCount ?? 0) / 3);
|
|
14004
|
-
return 0.7 * recency + 0.3 * frequency;
|
|
14005
|
-
};
|
|
14006
|
-
var unretrievedDecayFactor = (item, nowMs) => {
|
|
14007
|
-
if ((item.activationCount ?? 0) !== 0) return 1;
|
|
14008
|
-
const createdAgeDays = Math.max(0, (nowMs - Date.parse(item.createdAt)) / DAY_MS);
|
|
14009
|
-
if (createdAgeDays <= UNRETRIEVED_MEMORY_GRACE_DAYS) return 1;
|
|
14010
|
-
const overdue = createdAgeDays - UNRETRIEVED_MEMORY_GRACE_DAYS;
|
|
14011
|
-
return Math.max(
|
|
14012
|
-
MIN_UNRETRIEVED_SCORE_FACTOR,
|
|
14013
|
-
1 / (1 + overdue / UNRETRIEVED_DECAY_HALF_LIFE_DAYS)
|
|
14014
|
-
);
|
|
14015
|
-
};
|
|
14016
|
-
var retrievalScore = (item, nowMs) => retrievalFrequencyScore(item, nowMs) * unretrievedDecayFactor(item, nowMs);
|
|
14017
|
-
var creationRecencyScore = (item, nowMs) => {
|
|
14018
|
-
const createdMs = Date.parse(item.createdAt);
|
|
14019
|
-
const ageDays = Math.max(0, (nowMs - createdMs) / 864e5);
|
|
14020
|
-
return 1 / (1 + ageDays / 7);
|
|
14021
|
-
};
|
|
14022
|
-
var typeFitScore = (item) => {
|
|
14023
|
-
if (item.kind === "episodic") return 0.75;
|
|
14024
|
-
if (item.kind === "semantic") return 0.9;
|
|
14025
|
-
return 0.85;
|
|
14026
|
-
};
|
|
14027
|
-
var understandingScore = (item) => {
|
|
14028
|
-
if (!item.tags?.includes("understanding-memory")) return 0;
|
|
14029
|
-
if (item.facet === "unfinished") return 1;
|
|
14030
|
-
if (item.facet === "tension") return 0.95;
|
|
14031
|
-
if (item.facet === "preference") return 0.85;
|
|
14032
|
-
if (item.facet === "style") return 0.75;
|
|
14033
|
-
return 0.8;
|
|
14034
|
-
};
|
|
14035
|
-
var pathScore = (item, context) => {
|
|
14036
|
-
let score = 0;
|
|
14037
|
-
if (context?.currentOwner && item.ownerType === context.currentOwner.ownerType && item.ownerId === context.currentOwner.ownerId) {
|
|
14038
|
-
score += 0.65;
|
|
14039
|
-
}
|
|
14040
|
-
if (context?.currentSubject && item.subjectType === context.currentSubject.subjectType && item.subjectId === context.currentSubject.subjectId) {
|
|
14041
|
-
score += 0.85;
|
|
14042
|
-
}
|
|
14043
|
-
return Math.min(1, score);
|
|
14044
|
-
};
|
|
14045
|
-
var scoreMemoryItem = (item, query, nowMs = Date.now(), context) => {
|
|
14046
|
-
const queryMatch = keywordScore(query, item);
|
|
14047
|
-
const identifierMatch = identifierScore(query, item);
|
|
14048
|
-
const retrieval = retrievalScore(item, nowMs);
|
|
14049
|
-
const createdRecency = creationRecencyScore(item, nowMs);
|
|
14050
|
-
const importance = item.importance ?? 0;
|
|
14051
|
-
const confidence = item.confidence ?? 0;
|
|
14052
|
-
const typeFit = typeFitScore(item);
|
|
14053
|
-
const understanding = understandingScore(item);
|
|
14054
|
-
const path2 = pathScore(item, context);
|
|
14055
|
-
return 0.25 * queryMatch + 0.2 * identifierMatch + 0.2 * path2 + 0.09 * retrieval + // weak retrieval signal, NOT successful-use reinforcement
|
|
14056
|
-
0.16 * createdRecency + 0.06 * importance + 0.03 * confidence + 0.02 * typeFit + 0.01 * understanding;
|
|
14057
|
-
};
|
|
14058
|
-
var rankMemoryCandidates = (items, query, context) => {
|
|
14059
|
-
const nowMs = Date.now();
|
|
14060
|
-
return [...items].sort((a, b) => {
|
|
14061
|
-
const aExplicit = a.sourceKind === "explicit-user-directive";
|
|
14062
|
-
const bExplicit = b.sourceKind === "explicit-user-directive";
|
|
14063
|
-
if (aExplicit !== bExplicit) return bExplicit ? 1 : -1;
|
|
14064
|
-
if (aExplicit) {
|
|
14065
|
-
return Date.parse(b.createdAt) - Date.parse(a.createdAt);
|
|
14066
|
-
}
|
|
14067
|
-
return scoreMemoryItem(b, query, nowMs, context) - scoreMemoryItem(a, query, nowMs, context);
|
|
14068
|
-
});
|
|
14069
|
-
};
|
|
14070
|
-
|
|
14071
13564
|
// packages/ai/memory/vnext/detachedThrottle.ts
|
|
14072
13565
|
var DEFAULT_DETACHED_MEMORY_COOLDOWN_MS = 10 * 60 * 1e3;
|
|
14073
13566
|
var MAX_COOLDOWN_KEYS = 512;
|
|
@@ -14236,43 +13729,6 @@ ${catalogText(entities, states)}`
|
|
|
14236
13729
|
};
|
|
14237
13730
|
};
|
|
14238
13731
|
|
|
14239
|
-
// packages/ai/memory/vnext/legacyMigration.ts
|
|
14240
|
-
import { createHash } from "crypto";
|
|
14241
|
-
var LEGACY_MEMORY_SOURCE_REF_PREFIX = "legacy-memory";
|
|
14242
|
-
var LEGACY_MEMORY_EVIDENCE_ID_PREFIX = "mem-legacy-";
|
|
14243
|
-
var resolveLegacyMemoryPrincipal = (item) => ({
|
|
14244
|
-
ownerType: item.ownerType,
|
|
14245
|
-
ownerId: item.ownerId,
|
|
14246
|
-
principalId: `${item.ownerType}:${encodeURIComponent(item.ownerId)}`
|
|
14247
|
-
});
|
|
14248
|
-
var buildLegacyMemorySourceRef = (item) => {
|
|
14249
|
-
const { principalId } = resolveLegacyMemoryPrincipal(item);
|
|
14250
|
-
return `${LEGACY_MEMORY_SOURCE_REF_PREFIX}:${principalId}:${encodeURIComponent(item.id)}`;
|
|
14251
|
-
};
|
|
14252
|
-
var legacyEvidenceSeed = (principalId, itemId) => JSON.stringify([principalId, itemId]);
|
|
14253
|
-
var buildLegacyEvidenceId = (item) => {
|
|
14254
|
-
const { principalId } = resolveLegacyMemoryPrincipal(item);
|
|
14255
|
-
const digest = createHash("sha256").update(legacyEvidenceSeed(principalId, item.id)).digest("hex");
|
|
14256
|
-
return `${LEGACY_MEMORY_EVIDENCE_ID_PREFIX}${digest.slice(0, 32)}`;
|
|
14257
|
-
};
|
|
14258
|
-
var clampLegacyConfidence = (value) => {
|
|
14259
|
-
if (typeof value !== "number" || !Number.isFinite(value)) return 0;
|
|
14260
|
-
if (value < 0) return 0;
|
|
14261
|
-
if (value > 1) return 1;
|
|
14262
|
-
return value;
|
|
14263
|
-
};
|
|
14264
|
-
var buildLegacyMemoryEvidence = (item) => {
|
|
14265
|
-
const { principalId } = resolveLegacyMemoryPrincipal(item);
|
|
14266
|
-
return {
|
|
14267
|
-
id: buildLegacyEvidenceId(item),
|
|
14268
|
-
ownerId: principalId,
|
|
14269
|
-
text: item.content,
|
|
14270
|
-
sourceRef: buildLegacyMemorySourceRef(item),
|
|
14271
|
-
confidence: clampLegacyConfidence(item.confidence),
|
|
14272
|
-
createdAt: item.createdAt
|
|
14273
|
-
};
|
|
14274
|
-
};
|
|
14275
|
-
|
|
14276
13732
|
// packages/ai/memory/vnext/shadowRead.ts
|
|
14277
13733
|
var SHADOW_TIMEOUT_MS = 2e4;
|
|
14278
13734
|
var ERROR_MESSAGE_MAX = 120;
|
|
@@ -14686,7 +14142,7 @@ var MEMORY_RELATION_TYPES = [
|
|
|
14686
14142
|
var isObject = (value) => !!value && typeof value === "object" && !Array.isArray(value);
|
|
14687
14143
|
var isString = (value) => typeof value === "string" && value.trim().length > 0;
|
|
14688
14144
|
var isStringArray = (value) => Array.isArray(value) && value.every(isString);
|
|
14689
|
-
var optionalArray = (value,
|
|
14145
|
+
var optionalArray = (value, validate) => value === void 0 || Array.isArray(value) && value.every(validate);
|
|
14690
14146
|
var ACTIONS = /* @__PURE__ */ new Set([
|
|
14691
14147
|
"no_op",
|
|
14692
14148
|
"create",
|
|
@@ -15269,46 +14725,15 @@ var isMemoryVNextLazyPromotionEnabled = (env = typeof process !== "undefined" ?
|
|
|
15269
14725
|
// packages/ai/memory/vnext/pureReadGate.ts
|
|
15270
14726
|
var isMemoryVNextPureReadEnabled = (env = typeof process !== "undefined" ? process.env : {}) => env.NOLO_MEMORY_VNEXT_PURE_READ === "1" || env.NOLO_MEMORY_VNEXT_PURE_READ === "true";
|
|
15271
14727
|
|
|
15272
|
-
// packages/ai/memory/
|
|
15273
|
-
var
|
|
15274
|
-
var MAX_LOCAL_RECALL_STATES = 8;
|
|
15275
|
-
var SAFE_TECHNICAL_SYNONYMS = {
|
|
15276
|
-
pr: ["\u5BA1\u67E5", "\u4EE3\u7801\u5BA1\u67E5", "diff"],
|
|
15277
|
-
diff: ["\u5BA1\u67E5", "\u4EE3\u7801\u5BA1\u67E5"],
|
|
15278
|
-
review: ["\u5BA1\u67E5", "\u4EE3\u7801\u5BA1\u67E5"],
|
|
15279
|
-
deploy: ["\u90E8\u7F72", "\u53D1\u7248"],
|
|
15280
|
-
release: ["\u53D1\u7248", "\u53D1\u5E03"],
|
|
15281
|
-
desktop: ["\u684C\u9762", "\u684C\u9762\u7AEF"]
|
|
15282
|
-
};
|
|
15283
|
-
var distinctTokens = (text) => new Set(tokenize2(text).filter((token) => token.length >= 2));
|
|
15284
|
-
var recallMemoryVNextLocal = (input) => {
|
|
15285
|
-
const rawTokens = distinctTokens(input.query);
|
|
15286
|
-
if (rawTokens.size === 0) return [];
|
|
15287
|
-
const queryTokens = new Set(rawTokens);
|
|
15288
|
-
for (const token of rawTokens) {
|
|
15289
|
-
const syns = SAFE_TECHNICAL_SYNONYMS[token.toLowerCase()];
|
|
15290
|
-
if (syns) {
|
|
15291
|
-
for (const syn of syns) {
|
|
15292
|
-
for (const t2 of distinctTokens(syn)) queryTokens.add(t2);
|
|
15293
|
-
}
|
|
15294
|
-
}
|
|
15295
|
-
}
|
|
15296
|
-
const entityById = new Map(input.entities.map((entity) => [entity.id, entity]));
|
|
15297
|
-
const hits = [];
|
|
15298
|
-
for (const state2 of input.states) {
|
|
15299
|
-
if (state2.retiredAt || !state2.text.trim()) continue;
|
|
15300
|
-
const entity = entityById.get(state2.entityId);
|
|
15301
|
-
const haystack = distinctTokens(
|
|
15302
|
-
[state2.facet, state2.text, entity?.name ?? "", ...entity?.aliases ?? []].join(" ")
|
|
15303
|
-
);
|
|
15304
|
-
let sharedTokens = 0;
|
|
15305
|
-
for (const token of queryTokens) if (haystack.has(token)) sharedTokens++;
|
|
15306
|
-
if (sharedTokens >= MIN_SHARED_TOKENS) hits.push({ state: state2, sharedTokens });
|
|
15307
|
-
}
|
|
15308
|
-
return hits.sort((a, b) => b.sharedTokens - a.sharedTokens || a.state.id.localeCompare(b.state.id)).slice(0, input.limit ?? MAX_LOCAL_RECALL_STATES);
|
|
15309
|
-
};
|
|
14728
|
+
// packages/ai/memory/remember.ts
|
|
14729
|
+
var RESIDENT_MAX_CONTENT_CHARS = 240;
|
|
15310
14730
|
|
|
15311
14731
|
// packages/ai/memory/vnext/pureVNextRuntime.ts
|
|
14732
|
+
function deriveStateResident(state2, ownerType) {
|
|
14733
|
+
if (ownerType !== "user") return false;
|
|
14734
|
+
if (state2.text.trim().length > RESIDENT_MAX_CONTENT_CHARS) return false;
|
|
14735
|
+
return state2.facet === "preference" || state2.facet === "style";
|
|
14736
|
+
}
|
|
15312
14737
|
var buildSynthesizedStateItem = (state2, entity, ownerType, ownerId) => ({
|
|
15313
14738
|
id: `vnext-state-${state2.id}`,
|
|
15314
14739
|
ownerType,
|
|
@@ -15323,7 +14748,7 @@ var buildSynthesizedStateItem = (state2, entity, ownerType, ownerId) => ({
|
|
|
15323
14748
|
activationCount: 1,
|
|
15324
14749
|
importance: 0.9,
|
|
15325
14750
|
confidence: 0.9,
|
|
15326
|
-
resident: state2
|
|
14751
|
+
resident: deriveStateResident(state2, ownerType)
|
|
15327
14752
|
});
|
|
15328
14753
|
async function resolvePureVNextRuntime(input) {
|
|
15329
14754
|
const { db, owners, userInput } = input;
|
|
@@ -15562,12 +14987,106 @@ var resolveMemoryRuntime = async (input) => {
|
|
|
15562
14987
|
return { selectedItems: [], promptBlock: null };
|
|
15563
14988
|
}
|
|
15564
14989
|
if (isMemoryVNextPureReadEnabled()) {
|
|
15565
|
-
const
|
|
15566
|
-
|
|
15567
|
-
|
|
15568
|
-
|
|
15569
|
-
|
|
15570
|
-
|
|
14990
|
+
const pureStartedAt = performance.now();
|
|
14991
|
+
let pure;
|
|
14992
|
+
let pureError = null;
|
|
14993
|
+
try {
|
|
14994
|
+
pure = await resolvePureVNextRuntime({
|
|
14995
|
+
db: input.db,
|
|
14996
|
+
owners,
|
|
14997
|
+
userInput: input.userInput,
|
|
14998
|
+
maxTokens: MEMORY_OVERLAY_TOKEN_BUDGET
|
|
14999
|
+
});
|
|
15000
|
+
} catch (error) {
|
|
15001
|
+
pureError = error;
|
|
15002
|
+
pure = { selectedItems: [], promptBlock: null, recalledStateCount: 0 };
|
|
15003
|
+
}
|
|
15004
|
+
const pureLatencyMs = Math.round((performance.now() - pureStartedAt) * 10) / 10;
|
|
15005
|
+
const emitPureRead = (observation) => {
|
|
15006
|
+
try {
|
|
15007
|
+
if (input.pureReadEmit) {
|
|
15008
|
+
input.pureReadEmit(observation);
|
|
15009
|
+
} else if (input.primaryReadEmit) {
|
|
15010
|
+
input.primaryReadEmit({
|
|
15011
|
+
source: observation.source === "vnext" ? "vnext" : "none",
|
|
15012
|
+
legacyHitCount: 0,
|
|
15013
|
+
recalledStateCount: observation.vnextItemCount,
|
|
15014
|
+
vnextLatencyMs: observation.vnextLatencyMs,
|
|
15015
|
+
legacyLatencyMs: 0,
|
|
15016
|
+
contextChars: observation.contextChars,
|
|
15017
|
+
fallbackReason: observation.fallbackReason,
|
|
15018
|
+
error: observation.error
|
|
15019
|
+
});
|
|
15020
|
+
} else {
|
|
15021
|
+
console.info("[memory] vnext pure read", {
|
|
15022
|
+
event: "memory_vnext_pure_read",
|
|
15023
|
+
...observation
|
|
15024
|
+
});
|
|
15025
|
+
}
|
|
15026
|
+
} catch {
|
|
15027
|
+
}
|
|
15028
|
+
};
|
|
15029
|
+
if (pureError != null) {
|
|
15030
|
+
emitPureRead({
|
|
15031
|
+
source: "none",
|
|
15032
|
+
itemCount: 0,
|
|
15033
|
+
vnextItemCount: 0,
|
|
15034
|
+
vnextLatencyMs: pureLatencyMs,
|
|
15035
|
+
contextChars: 0,
|
|
15036
|
+
fallbackReason: "vnext_error",
|
|
15037
|
+
error: pureError instanceof Error ? pureError.message : String(pureError)
|
|
15038
|
+
});
|
|
15039
|
+
} else if (pure.selectedItems.length === 0) {
|
|
15040
|
+
emitPureRead({
|
|
15041
|
+
source: "none",
|
|
15042
|
+
itemCount: 0,
|
|
15043
|
+
vnextItemCount: 0,
|
|
15044
|
+
vnextLatencyMs: pureLatencyMs,
|
|
15045
|
+
contextChars: 0,
|
|
15046
|
+
fallbackReason: "no_vnext_context"
|
|
15047
|
+
});
|
|
15048
|
+
} else {
|
|
15049
|
+
emitPureRead({
|
|
15050
|
+
source: "vnext",
|
|
15051
|
+
itemCount: pure.selectedItems.length,
|
|
15052
|
+
vnextItemCount: pure.recalledStateCount,
|
|
15053
|
+
vnextLatencyMs: pureLatencyMs,
|
|
15054
|
+
contextChars: pure.promptBlock?.length ?? 0
|
|
15055
|
+
});
|
|
15056
|
+
}
|
|
15057
|
+
const lazyPromotionEnabled2 = input.vNextShadowProvider != null && isMemoryVNextLazyPromotionEnabled();
|
|
15058
|
+
if (lazyPromotionEnabled2) {
|
|
15059
|
+
void (async () => {
|
|
15060
|
+
const ownerItems = await Promise.all(
|
|
15061
|
+
owners.map(
|
|
15062
|
+
(owner) => loadOwnerItemsFromDb(
|
|
15063
|
+
input.db,
|
|
15064
|
+
owner,
|
|
15065
|
+
input.ownerLimit ?? DEFAULT_MEMORY_RUNTIME_OWNER_LIMIT
|
|
15066
|
+
)
|
|
15067
|
+
)
|
|
15068
|
+
);
|
|
15069
|
+
const legacyCandidates = ownerItems.flat();
|
|
15070
|
+
if (legacyCandidates.length > 0) {
|
|
15071
|
+
const promotionPick = await pickFirstUncoveredLazyPromotionItem(
|
|
15072
|
+
input.db,
|
|
15073
|
+
legacyCandidates
|
|
15074
|
+
);
|
|
15075
|
+
if (promotionPick) {
|
|
15076
|
+
await runMemoryVNextLazyPromotion({
|
|
15077
|
+
db: input.db,
|
|
15078
|
+
item: promotionPick.item,
|
|
15079
|
+
selectedIndex: promotionPick.selectedIndex,
|
|
15080
|
+
skippedCoveredCount: promotionPick.skippedCoveredCount,
|
|
15081
|
+
skippedNoOpCount: promotionPick.skippedNoOpCount,
|
|
15082
|
+
provider: input.vNextShadowProvider,
|
|
15083
|
+
...input.lazyPromotionEmit ? { emit: input.lazyPromotionEmit } : {}
|
|
15084
|
+
});
|
|
15085
|
+
}
|
|
15086
|
+
}
|
|
15087
|
+
})().catch(() => {
|
|
15088
|
+
});
|
|
15089
|
+
}
|
|
15571
15090
|
return {
|
|
15572
15091
|
selectedItems: pure.selectedItems,
|
|
15573
15092
|
promptBlock: pure.promptBlock
|
|
@@ -15908,11 +15427,49 @@ async function runAgentRunCommand(args, deps) {
|
|
|
15908
15427
|
writeUsage(output, deps.commandPath);
|
|
15909
15428
|
return 1;
|
|
15910
15429
|
}
|
|
15911
|
-
const
|
|
15430
|
+
const rawRunner = deps.runner ?? runAgentTurn;
|
|
15431
|
+
const watchdogAbort = new AbortController();
|
|
15432
|
+
let activeRunner;
|
|
15433
|
+
const runner = (options) => {
|
|
15434
|
+
activeRunner = Promise.resolve().then(() => rawRunner({ ...options, abortSignal: watchdogAbort.signal })).then((result) => {
|
|
15435
|
+
watchdogAbort.signal.throwIfAborted();
|
|
15436
|
+
return result;
|
|
15437
|
+
});
|
|
15438
|
+
return activeRunner;
|
|
15439
|
+
};
|
|
15440
|
+
const stopWatchdogRunner = async () => {
|
|
15441
|
+
watchdogAbort.abort(new Error("watchdog_stop"));
|
|
15442
|
+
if (!activeRunner) return true;
|
|
15443
|
+
let timer;
|
|
15444
|
+
try {
|
|
15445
|
+
return await Promise.race([
|
|
15446
|
+
activeRunner.then(() => true, () => true),
|
|
15447
|
+
new Promise((resolve6) => {
|
|
15448
|
+
timer = setTimeout(() => resolve6(false), 100);
|
|
15449
|
+
})
|
|
15450
|
+
]);
|
|
15451
|
+
} finally {
|
|
15452
|
+
if (timer) clearTimeout(timer);
|
|
15453
|
+
}
|
|
15454
|
+
};
|
|
15912
15455
|
const nowMs = () => deps.now ? deps.now().getTime() : Date.now();
|
|
15913
|
-
|
|
15914
|
-
|
|
15915
|
-
|
|
15456
|
+
let childRunId = env.NOLO_AGENT_RUN_ID;
|
|
15457
|
+
let hasRegistry = typeof childRunId === "string" && childRunId.length > 0;
|
|
15458
|
+
const hostPolicy = () => ({
|
|
15459
|
+
runtimeKey: "local",
|
|
15460
|
+
hostWritesAuthorized: args.includes("--allow-host-writes"),
|
|
15461
|
+
readOnly: args.includes("--read-only"),
|
|
15462
|
+
...parsed.allowedToolNames ? { allowedToolNames: parsed.allowedToolNames } : {},
|
|
15463
|
+
...parsed.blockedToolNames ? { blockedToolNames: parsed.blockedToolNames } : {},
|
|
15464
|
+
provenance: "cli-command-authorized"
|
|
15465
|
+
});
|
|
15466
|
+
const locatedExecution = hasRegistry ? readRunRecord(childRunId, { env, homedir: deps.homedir, fs: deps.fs })?.execution : void 0;
|
|
15467
|
+
if (hasRegistry && (parsed.runtimeKey?.trim() === "local" || locatedExecution?.state === "known")) {
|
|
15468
|
+
const implicitReadonlyHost = !parsed.runtimeKey && args.includes("--read-only") && locatedExecution?.state === "known" && locatedExecution.runtimeKey === "local" && locatedExecution.permissions.readOnly;
|
|
15469
|
+
if (parsed.runtimeKey?.trim() !== "local" && !implicitReadonlyHost) throw new Error("[local-writer-resource] child binding runtime mismatch");
|
|
15470
|
+
await awaitLocalWriterChild(childRunId, parsed.cwd ?? process.cwd(), hostPolicy(), { env, homedir: deps.homedir, fs: deps.fs });
|
|
15471
|
+
}
|
|
15472
|
+
if (hasRegistry && parsed.runtimeKey?.trim() !== "local" && locatedExecution?.state !== "known") reportRunProcessIdentity(childRunId, { env, homedir: deps.homedir, fs: deps.fs, now: deps.now });
|
|
15916
15473
|
const processExit = deps.processExit ?? ((code) => process.exit(code));
|
|
15917
15474
|
const stallTimeoutMs = resolvePositiveMs(
|
|
15918
15475
|
deps.stallTimeoutMs ?? env.NOLO_LOCAL_RUN_STALL_TIMEOUT_MS,
|
|
@@ -15954,9 +15511,9 @@ async function runAgentRunCommand(args, deps) {
|
|
|
15954
15511
|
throw error;
|
|
15955
15512
|
});
|
|
15956
15513
|
};
|
|
15957
|
-
const exitFromWatchdog = (code) => {
|
|
15514
|
+
const exitFromWatchdog = async (code) => {
|
|
15958
15515
|
try {
|
|
15959
|
-
|
|
15516
|
+
await exitCliFromWatchdog(code, processExit, stopWatchdogRunner);
|
|
15960
15517
|
} catch {
|
|
15961
15518
|
}
|
|
15962
15519
|
};
|
|
@@ -16003,8 +15560,8 @@ async function runAgentRunCommand(args, deps) {
|
|
|
16003
15560
|
failureReason: "stalled",
|
|
16004
15561
|
toolCallCount: currentActivity?.counters?.toolCalls
|
|
16005
15562
|
});
|
|
15563
|
+
await exitFromWatchdog(outcome.exitCode);
|
|
16006
15564
|
rejectOnWatchdogFailure?.(new Error(`[nolo] local run ${note}`));
|
|
16007
|
-
exitFromWatchdog(outcome.exitCode);
|
|
16008
15565
|
}
|
|
16009
15566
|
}, Math.min(stallTimeoutMs, 1e4));
|
|
16010
15567
|
}
|
|
@@ -16018,8 +15575,8 @@ async function runAgentRunCommand(args, deps) {
|
|
|
16018
15575
|
terminalStatus.fail();
|
|
16019
15576
|
const outcome = resolveRunOutcome({ kind: "timeout" });
|
|
16020
15577
|
await finalizeWatchdogOutcome(outcome, note);
|
|
15578
|
+
await exitFromWatchdog(outcome.exitCode);
|
|
16021
15579
|
rejectOnWatchdogFailure?.(new Error(`[nolo] local run ${note}`));
|
|
16022
|
-
exitFromWatchdog(outcome.exitCode);
|
|
16023
15580
|
}, parsed.timeoutMs);
|
|
16024
15581
|
}
|
|
16025
15582
|
const wantsFallbackSuggestions = parsed.fallbackAgentKeys && parsed.fallbackAgentKeys.length > 0;
|
|
@@ -16028,8 +15585,8 @@ async function runAgentRunCommand(args, deps) {
|
|
|
16028
15585
|
const explicitLocalCli = isLocalCliAgentKey(parsed.agentKey);
|
|
16029
15586
|
const dockerRuntimeLocal = typeof parsed.runtimeKey === "string" && /^docker(:.+)?$/.test(parsed.runtimeKey.trim());
|
|
16030
15587
|
const instaboxRuntimeLocal = typeof parsed.runtimeKey === "string" && parsed.runtimeKey.trim() === "instabox";
|
|
16031
|
-
const hostRuntimeLocal = typeof parsed.runtimeKey === "string" && parsed.runtimeKey.trim() === "local";
|
|
16032
|
-
if (hostRuntimeLocal && !args.includes("--allow-host-writes")) {
|
|
15588
|
+
const hostRuntimeLocal = typeof parsed.runtimeKey === "string" && parsed.runtimeKey.trim() === "local" || !parsed.runtimeKey && args.includes("--read-only") && locatedExecution?.state === "known" && locatedExecution.runtimeKey === "local" && locatedExecution.permissions.readOnly;
|
|
15589
|
+
if (hostRuntimeLocal && !args.includes("--read-only") && !args.includes("--allow-host-writes")) {
|
|
16033
15590
|
output.write(t("agentRun.hostWriteGuard"));
|
|
16034
15591
|
return 1;
|
|
16035
15592
|
}
|
|
@@ -16166,6 +15723,9 @@ async function runAgentRunCommand(args, deps) {
|
|
|
16166
15723
|
if (!localRuntimeCwd && (parsed.runtimeMode === "local" || hostRuntimeLocal)) {
|
|
16167
15724
|
localRuntimeCwd = process.cwd();
|
|
16168
15725
|
}
|
|
15726
|
+
const acceptanceCwd = localRuntimeCwd && (parsed.runtimeMode === "local" || hostRuntimeLocal) ? localRuntimeCwd : void 0;
|
|
15727
|
+
const acceptanceBase = acceptanceCwd ? await (deps.captureLocalRunBase ?? captureLocalRunBase)(acceptanceCwd, deps.localRunBaseCaptureOptions) : null;
|
|
15728
|
+
let finalWorkspaceInspection;
|
|
16169
15729
|
if (parsed.runtimeKey === "instabox") {
|
|
16170
15730
|
try {
|
|
16171
15731
|
writeInstaboxRunConfig({
|
|
@@ -16193,9 +15753,20 @@ async function runAgentRunCommand(args, deps) {
|
|
|
16193
15753
|
cliEntrypointPath: deps.cliEntrypointPath,
|
|
16194
15754
|
agentKey,
|
|
16195
15755
|
cwd: localRuntimeCwd,
|
|
15756
|
+
...hostRuntimeLocal ? { localExecution: {
|
|
15757
|
+
runtimeKey: "local",
|
|
15758
|
+
hostWritesAuthorized: args.includes("--allow-host-writes"),
|
|
15759
|
+
readOnly: args.includes("--read-only"),
|
|
15760
|
+
...parsed.allowedToolNames ? { allowedToolNames: parsed.allowedToolNames } : {},
|
|
15761
|
+
...parsed.blockedToolNames ? { blockedToolNames: parsed.blockedToolNames } : {},
|
|
15762
|
+
provenance: "cli-command-authorized"
|
|
15763
|
+
} } : {},
|
|
15764
|
+
// Explicit host target is authorized above; read-only retains its existing tool restrictions.
|
|
15765
|
+
...hostRuntimeLocal && !args.includes("--read-only") ? { claimLocalWrites: true } : {},
|
|
16196
15766
|
msgFile: readFlagValue(args, "--msg-file"),
|
|
16197
15767
|
message: parsed.message,
|
|
16198
15768
|
timeoutMs: parsed.timeoutMs,
|
|
15769
|
+
...parsed.ephemeral ? { ephemeral: true } : {},
|
|
16199
15770
|
...parsed.dodCommands?.length ? { dodCommands: parsed.dodCommands } : {},
|
|
16200
15771
|
output
|
|
16201
15772
|
},
|
|
@@ -16225,6 +15796,15 @@ async function runAgentRunCommand(args, deps) {
|
|
|
16225
15796
|
const isSubtask = isSubtaskRun(env);
|
|
16226
15797
|
const scopedLayers = [];
|
|
16227
15798
|
const skillContentBlocks = [];
|
|
15799
|
+
if (hostRuntimeLocal && !parsed.background) {
|
|
15800
|
+
const policy = { ...hostPolicy(), ...skillAllowedToolOverride !== void 0 ? { allowedToolNames: skillAllowedToolOverride } : {} };
|
|
15801
|
+
if (hasRegistry) {
|
|
15802
|
+
await awaitLocalWriterChild(childRunId, localRuntimeCwd, policy, { env, homedir: deps.homedir, fs: deps.fs });
|
|
15803
|
+
} else if (!policy.readOnly) {
|
|
15804
|
+
childRunId = registerLocalForegroundWriter(localRuntimeCwd, policy, agentKey, { env, homedir: deps.homedir, fs: deps.fs, now: deps.now });
|
|
15805
|
+
hasRegistry = true;
|
|
15806
|
+
}
|
|
15807
|
+
}
|
|
16228
15808
|
const extraContextBlocks = [];
|
|
16229
15809
|
const contextBlockScopes = [];
|
|
16230
15810
|
let memoryPromptBlock = null;
|
|
@@ -16355,6 +15935,7 @@ async function runAgentRunCommand(args, deps) {
|
|
|
16355
15935
|
})
|
|
16356
15936
|
);
|
|
16357
15937
|
clearWatchdogs();
|
|
15938
|
+
const runCommandObservations = [...getRunResultHeaderMeta(result).commandObservations ?? []];
|
|
16358
15939
|
let runCreditsTotal = result.turnCredits;
|
|
16359
15940
|
let runCacheUsage = summarizeCacheUsageRecords(result.usageRecords);
|
|
16360
15941
|
if (result.exitCode !== 0 && isQuotaExhaustedError(result.localError) && isLocalRun && parsed.fallbackAgentKeys && parsed.fallbackAgentKeys.length > 0) {
|
|
@@ -16370,6 +15951,7 @@ async function runAgentRunCommand(args, deps) {
|
|
|
16370
15951
|
})
|
|
16371
15952
|
);
|
|
16372
15953
|
clearWatchdogs();
|
|
15954
|
+
runCommandObservations.push(...getRunResultHeaderMeta(fallbackResult).commandObservations ?? []);
|
|
16373
15955
|
if (fallbackResult.exitCode === 0) {
|
|
16374
15956
|
result = fallbackResult;
|
|
16375
15957
|
}
|
|
@@ -16422,6 +16004,7 @@ async function runAgentRunCommand(args, deps) {
|
|
|
16422
16004
|
})
|
|
16423
16005
|
);
|
|
16424
16006
|
clearWatchdogs();
|
|
16007
|
+
runCommandObservations.push(...getRunResultHeaderMeta(turnResult).commandObservations ?? []);
|
|
16425
16008
|
result = turnResult;
|
|
16426
16009
|
if (turnResult.turnCredits !== void 0) {
|
|
16427
16010
|
runCreditsTotal = (runCreditsTotal ?? 0) + turnResult.turnCredits;
|
|
@@ -16450,11 +16033,6 @@ async function runAgentRunCommand(args, deps) {
|
|
|
16450
16033
|
);
|
|
16451
16034
|
}
|
|
16452
16035
|
}
|
|
16453
|
-
terminalStatus.settle({
|
|
16454
|
-
exitCode: result.exitCode,
|
|
16455
|
-
streamInterrupted: result.streamInterrupted,
|
|
16456
|
-
stalledOrTruncated: isRunResultStalledOrTruncated(result)
|
|
16457
|
-
});
|
|
16458
16036
|
if (result.dialogId) {
|
|
16459
16037
|
if (parsed.background) {
|
|
16460
16038
|
output.write(`
|
|
@@ -16468,11 +16046,12 @@ async function runAgentRunCommand(args, deps) {
|
|
|
16468
16046
|
`);
|
|
16469
16047
|
}
|
|
16470
16048
|
}
|
|
16471
|
-
if (shouldPrintLocalRunSummary({ parsed, localRuntimeCwd })) {
|
|
16049
|
+
if (acceptanceCwd || shouldPrintLocalRunSummary({ parsed, localRuntimeCwd })) {
|
|
16472
16050
|
try {
|
|
16473
16051
|
const inspect = deps.inspectLocalRunWorkspace ?? inspectLocalRunWorkspace;
|
|
16474
|
-
const inspection = await inspect(localRuntimeCwd);
|
|
16475
|
-
|
|
16052
|
+
const inspection = await inspect(localRuntimeCwd, {}, acceptanceCwd ? acceptanceBase : void 0);
|
|
16053
|
+
finalWorkspaceInspection = inspection;
|
|
16054
|
+
if (shouldPrintLocalRunSummary({ parsed, localRuntimeCwd })) output.write(formatLocalRunSummary({
|
|
16476
16055
|
dialogId: result.dialogId,
|
|
16477
16056
|
inspection
|
|
16478
16057
|
}));
|
|
@@ -16511,6 +16090,8 @@ async function runAgentRunCommand(args, deps) {
|
|
|
16511
16090
|
if (outcome.status === "failed") {
|
|
16512
16091
|
if (result.emptyAssistantFallbackReason === "repetition_loop" || result.emptyAssistantFallbackReason === "stagnant_tool_calls") {
|
|
16513
16092
|
failureReason = "stalled";
|
|
16093
|
+
} else if (result.localError && isHistoryIntegrityFailure(toErrorMessage(result.localError))) {
|
|
16094
|
+
failureReason = "history_integrity";
|
|
16514
16095
|
} else if (result.localError && isQuotaExhaustedError(result.localError)) {
|
|
16515
16096
|
failureReason = "provider_rate_limited";
|
|
16516
16097
|
} else if (result.localError) {
|
|
@@ -16527,37 +16108,74 @@ async function runAgentRunCommand(args, deps) {
|
|
|
16527
16108
|
toolCallCount = rawToolCount;
|
|
16528
16109
|
}
|
|
16529
16110
|
}
|
|
16530
|
-
|
|
16531
|
-
|
|
16532
|
-
{
|
|
16533
|
-
|
|
16534
|
-
|
|
16535
|
-
|
|
16536
|
-
|
|
16537
|
-
|
|
16538
|
-
|
|
16539
|
-
|
|
16540
|
-
|
|
16541
|
-
|
|
16542
|
-
|
|
16543
|
-
|
|
16544
|
-
|
|
16545
|
-
|
|
16546
|
-
// 仅用于 .result.md 头(front matter):旁路读取,不改 result 形状。
|
|
16547
|
-
...getRunResultHeaderMeta(result),
|
|
16548
|
-
...truncationNote
|
|
16549
|
-
},
|
|
16550
|
-
{
|
|
16551
|
-
env,
|
|
16552
|
-
homedir: deps.homedir,
|
|
16553
|
-
fs: deps.fs,
|
|
16554
|
-
now: deps.now,
|
|
16555
|
-
sleep: deps.sleep
|
|
16556
|
-
},
|
|
16557
|
-
deps.transitionRunToTerminal
|
|
16111
|
+
const acceptance = acceptanceCwd ? finalWorkspaceInspection?.acceptance ?? unknownLocalRunAcceptance(acceptanceCwd, acceptanceBase) : void 0;
|
|
16112
|
+
if (acceptance && dodResults?.length) {
|
|
16113
|
+
acceptance.checks.observations = dodResults.map((check, index) => ({
|
|
16114
|
+
// Command lines/output can contain credentials. Persist only a digest
|
|
16115
|
+
// here; the pre-existing registry is the execution evidence reference.
|
|
16116
|
+
commandFingerprint: `sha256:${createHash("sha256").update(check.command).digest("hex")}`,
|
|
16117
|
+
cwd: childRecordForDoD?.cwd || process.cwd(),
|
|
16118
|
+
exitCode: check.exitCode,
|
|
16119
|
+
evidence: `${childRunId}.json#/dodResults/${index}`,
|
|
16120
|
+
versionBinding: "unknown"
|
|
16121
|
+
}));
|
|
16122
|
+
}
|
|
16123
|
+
if (acceptance) attachLocalCommandObservations(
|
|
16124
|
+
acceptance,
|
|
16125
|
+
runCommandObservations,
|
|
16126
|
+
`${childRunId}.result.md`
|
|
16558
16127
|
);
|
|
16128
|
+
let settlement;
|
|
16129
|
+
try {
|
|
16130
|
+
settlement = await settleRunTerminalAuthoritatively(
|
|
16131
|
+
childRunId,
|
|
16132
|
+
{
|
|
16133
|
+
status: outcome.status,
|
|
16134
|
+
exitCode: outcome.exitCode,
|
|
16135
|
+
dialogId: result.dialogId,
|
|
16136
|
+
...dodResults ? { dodResults } : {},
|
|
16137
|
+
// run 级累计的平台积分(主轮 + fallback + drain 轮):dock 行据此显示
|
|
16138
|
+
// 「⚡ x.xx」,让派发任务的消耗可见。undefined = 全程无平台计费。
|
|
16139
|
+
...runCreditsTotal !== void 0 ? { credits: runCreditsTotal } : {},
|
|
16140
|
+
// run 级缓存命中汇总:只进 .result.md 的 front matter(cached_tokens
|
|
16141
|
+
// 为 null 表示 provider 未报缓存指标,与「命中 0」严格区分)。
|
|
16142
|
+
...runCacheUsage ? { cacheUsage: runCacheUsage } : {},
|
|
16143
|
+
...failureReason ? { failureReason } : {},
|
|
16144
|
+
...toolCallCount !== void 0 ? { toolCallCount } : {},
|
|
16145
|
+
...acceptance ? { acceptance } : {},
|
|
16146
|
+
...result.finalText ? { lastAssistantText: result.finalText } : {},
|
|
16147
|
+
// 仅用于 .result.md 头(front matter):旁路读取,不改 result 形状。
|
|
16148
|
+
...getRunResultHeaderMeta(result),
|
|
16149
|
+
...truncationNote
|
|
16150
|
+
},
|
|
16151
|
+
{
|
|
16152
|
+
env,
|
|
16153
|
+
homedir: deps.homedir,
|
|
16154
|
+
fs: deps.fs,
|
|
16155
|
+
now: deps.now,
|
|
16156
|
+
sleep: deps.sleep
|
|
16157
|
+
},
|
|
16158
|
+
deps.transitionRunToTerminal
|
|
16159
|
+
);
|
|
16160
|
+
} catch (error) {
|
|
16161
|
+
terminalStatus.fail();
|
|
16162
|
+
output.write(`[nolo] terminal settlement failed: ${error instanceof Error ? error.message : String(error)}
|
|
16163
|
+
`);
|
|
16164
|
+
return 1;
|
|
16165
|
+
}
|
|
16166
|
+
if (settlement && (settlement.kind === "transitioned" || settlement.kind === "kept" || settlement.kind === "contended") && settlement.record.status !== "done" && result.exitCode === 0) {
|
|
16167
|
+
result = { ...result, exitCode: settlement.record.exitCode || 1 };
|
|
16168
|
+
}
|
|
16559
16169
|
}
|
|
16170
|
+
terminalStatus.settle({
|
|
16171
|
+
exitCode: result.exitCode,
|
|
16172
|
+
streamInterrupted: result.streamInterrupted,
|
|
16173
|
+
stalledOrTruncated: isRunResultStalledOrTruncated(result)
|
|
16174
|
+
});
|
|
16560
16175
|
return result.exitCode;
|
|
16176
|
+
} catch (error) {
|
|
16177
|
+
terminalStatus.fail();
|
|
16178
|
+
throw error;
|
|
16561
16179
|
} finally {
|
|
16562
16180
|
shellApprovalChild?.close();
|
|
16563
16181
|
if (shellApprovalChild && process.connected) process.disconnect();
|
|
@@ -16567,22 +16185,6 @@ async function runAgentRunCommand(args, deps) {
|
|
|
16567
16185
|
export {
|
|
16568
16186
|
resolveCliColorEnabled,
|
|
16569
16187
|
dimCliText,
|
|
16570
|
-
ANSI_ESCAPE_REGEX,
|
|
16571
|
-
stripAnsi2 as stripAnsi,
|
|
16572
|
-
applyTerminalOutputToText,
|
|
16573
|
-
displayWidth,
|
|
16574
|
-
visibleWidth,
|
|
16575
|
-
truncateAnsi,
|
|
16576
|
-
fitAnsiLine,
|
|
16577
|
-
countPhysicalLines,
|
|
16578
|
-
takeDisplayWidth,
|
|
16579
|
-
padOrTruncateToWidth,
|
|
16580
|
-
tokenizeAnsiLine,
|
|
16581
|
-
buildSourceMapping,
|
|
16582
|
-
wrapTranscriptLineWithLayout,
|
|
16583
|
-
wrapTranscriptLine,
|
|
16584
|
-
buildWindowTitle,
|
|
16585
|
-
wrapTextToLines,
|
|
16586
16188
|
THEME_PALETTES,
|
|
16587
16189
|
getActiveThemeName,
|
|
16588
16190
|
setActiveThemeName,
|
|
@@ -16604,9 +16206,10 @@ export {
|
|
|
16604
16206
|
setMathRenderingEnabled,
|
|
16605
16207
|
polishBreathInsertsBlankBetween,
|
|
16606
16208
|
formatAssistantDisplay,
|
|
16607
|
-
|
|
16608
|
-
|
|
16209
|
+
resolveHistoryLayoutGeometry,
|
|
16210
|
+
resolveHistoryViewportHeight,
|
|
16609
16211
|
TUI_TREE_MARKER,
|
|
16212
|
+
TUI_TREE_TOOLS,
|
|
16610
16213
|
resolveAgentModelIdentity,
|
|
16611
16214
|
resolveAgentContextWindow2 as resolveAgentContextWindow,
|
|
16612
16215
|
platformCreditsFromUsage,
|
|
@@ -16614,6 +16217,7 @@ export {
|
|
|
16614
16217
|
formatTokenCount,
|
|
16615
16218
|
resolveAuthorityTurnCount,
|
|
16616
16219
|
computeBaselineContextTokens,
|
|
16220
|
+
preserveContextUsageWithoutReceipt,
|
|
16617
16221
|
resolveContextUsage,
|
|
16618
16222
|
renderTokenStatus,
|
|
16619
16223
|
createIdleHeapReleaser,
|
|
@@ -16629,10 +16233,13 @@ export {
|
|
|
16629
16233
|
findCollapsedPasteSpanAt,
|
|
16630
16234
|
readAgentsMdLayerFromDisk,
|
|
16631
16235
|
emitTerminalProgramStatus,
|
|
16236
|
+
contextRefusalDiagnostics,
|
|
16237
|
+
describeContextRefusal,
|
|
16632
16238
|
isBalanceExhaustedError,
|
|
16633
16239
|
OWNER_OAUTH_UNAVAILABLE_HINT,
|
|
16634
16240
|
isOwnerOAuthUnavailableError,
|
|
16635
16241
|
isInvalidGrantError,
|
|
16242
|
+
isLocalContextCoverageFailure,
|
|
16636
16243
|
runAgentTurn,
|
|
16637
16244
|
resolveWorkflowReference,
|
|
16638
16245
|
resolveSkillReference,
|
|
@@ -16644,7 +16251,6 @@ export {
|
|
|
16644
16251
|
FAILED_EMPTY_ASSISTANT_REASONS,
|
|
16645
16252
|
isRunResultStalledOrTruncated,
|
|
16646
16253
|
resolveTerminalProgramStatusState,
|
|
16647
|
-
inspectLocalRunWorkspace,
|
|
16648
16254
|
resolveRunOutcome,
|
|
16649
16255
|
resolveRunSettlementNote,
|
|
16650
16256
|
runAgentRunCommand
|