@qwen-code/qwen-code 0.23.2 → 0.23.3-nightly.20260911.aaa6a32aae
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 +35 -15
- package/bundled/computer-use/SKILL.md +1 -1
- package/bundled/goal-draft/SKILL.md +10 -10
- package/bundled/qc-helper/docs/configuration/model-providers.md +66 -28
- package/bundled/qc-helper/docs/configuration/settings.md +8 -3
- package/bundled/qc-helper/docs/features/_meta.ts +1 -0
- package/bundled/qc-helper/docs/features/channels/dingtalk.md +0 -20
- package/bundled/qc-helper/docs/features/channels/dws.md +7 -1
- package/bundled/qc-helper/docs/features/channels/overview.md +5 -6
- package/bundled/qc-helper/docs/features/commands.md +62 -9
- package/bundled/qc-helper/docs/features/computer-use.md +1 -1
- package/bundled/qc-helper/docs/features/cross-session-protocol.md +338 -0
- package/bundled/qc-helper/docs/features/goals.md +22 -18
- package/bundled/qc-helper/docs/features/hooks.md +28 -22
- package/bundled/qc-helper/docs/features/sub-agents.md +27 -0
- package/bundled/qc-helper/docs/qwen-serve.md +23 -6
- package/bundled/review/SKILL.md +93 -80
- package/bundled/review/references/persistence.md +2 -0
- package/bundled/review/references/posting.md +31 -14
- package/bundled/workflow-authoring/SKILL.md +410 -0
- package/bundled/workflow-creator/SKILL.md +1 -1
- package/chunks/{MaxSizedBox-4C3BKKKY.js → MaxSizedBox-7C5XTBZI.js} +64 -53
- package/chunks/{StandaloneSessionPicker-TXVF65YW.js → StandaloneSessionPicker-IGTT3ZRX.js} +88 -76
- package/chunks/{acp-startup-profiler-KEU6VAYR.js → acp-startup-profiler-RUQNTNU5.js} +2 -2
- package/chunks/acp-subagent-executor-IUHVNVVO.js +140 -0
- package/chunks/{acpAgent-H5XBKGB4.js → acpAgent-W43WM2K4.js} +957 -243
- package/chunks/{agent-T5LEFJIU.js → agent-2XMXC5JW.js} +48 -38
- package/chunks/{agent-headless-VZKSRH36.js → agent-headless-2HHBVCP6.js} +48 -38
- package/chunks/{anthropicContentGenerator-PRJWWVYJ.js → anthropicContentGenerator-7RI3MPIW.js} +69 -36
- package/chunks/{artifact-tool-G5LHNECG.js → artifact-tool-HHVHCPNG.js} +59 -109
- package/chunks/{askUserQuestion-I5W5S3D6.js → askUserQuestion-RFMXTD3B.js} +2 -2
- package/chunks/{bridge-AOX5IY44.js → bridge-ID6N4IH5.js} +69 -58
- package/chunks/{ca-KC2AISNS.js → ca-MX3WCEEG.js} +1 -1
- package/chunks/{channel-management-service-MWQGHPAS.js → channel-management-service-ASCXI7FR.js} +6 -6
- package/chunks/{channel-settings-store-XZCGDGHW.js → channel-settings-store-TPJFQAZY.js} +76 -65
- package/chunks/{channel-worker-group-SQ5FRWOH.js → channel-worker-group-JR6JOELM.js} +9 -9
- package/chunks/{channel-worker-manager-TU4ZNWOE.js → channel-worker-manager-AVKJEZFL.js} +19 -10
- package/chunks/{channel-worker-supervisor-EMITFMCP.js → channel-worker-supervisor-OOYY7BAQ.js} +7 -7
- package/chunks/{chunk-4WMGYG3F.js → chunk-22FWWGSM.js} +2 -2
- package/chunks/{chunk-LWX4WDFF.js → chunk-2S5RIGZJ.js} +43 -15
- package/chunks/{chunk-CLKE4IY3.js → chunk-2SZH22YO.js} +1 -1
- package/chunks/{chunk-HJ5UJQQL.js → chunk-2UKKQGRA.js} +3639 -1804
- package/chunks/{chunk-MWIO7MF6.js → chunk-2WSLXP3W.js} +4 -0
- package/chunks/{chunk-HNLMYDQE.js → chunk-33LYAC4R.js} +10 -6
- package/chunks/{chunk-VBLAI2HA.js → chunk-3FPYT6QC.js} +0 -31
- package/chunks/{chunk-F53KKZUD.js → chunk-3LMDSCLU.js} +158 -10
- package/chunks/{chunk-WXFCI3O5.js → chunk-3MAUPOZ4.js} +2 -2
- package/chunks/{chunk-CRZBDVP2.js → chunk-432JQKIO.js} +10 -10
- package/chunks/{chunk-IRGDIDGJ.js → chunk-43RQ552L.js} +364 -84
- package/chunks/{chunk-PFKGV6PO.js → chunk-465USTVK.js} +9 -15
- package/chunks/{chunk-WG7BL3FY.js → chunk-473RJLIH.js} +1 -1
- package/chunks/{chunk-J3VZF2AL.js → chunk-4O2AXZXU.js} +2 -2
- package/chunks/{chunk-N6S3NUYJ.js → chunk-55VOWZ4C.js} +1 -1
- package/chunks/{chunk-OWCFKIFQ.js → chunk-5CZMWDJI.js} +2 -2
- package/chunks/{chunk-7NDZKE2M.js → chunk-5MUIHID6.js} +5 -5
- package/chunks/{chunk-RM244SCQ.js → chunk-5Z74GE4N.js} +1 -1
- package/chunks/{chunk-G5VOXCRX.js → chunk-6375QMAO.js} +2 -2
- package/chunks/{chunk-3LPJ776W.js → chunk-63GQZKXL.js} +164 -31
- package/chunks/{chunk-O2FEO2CB.js → chunk-6GDELAVL.js} +18 -2
- package/chunks/{chunk-7PD7ZMX5.js → chunk-6HI2I3OM.js} +168 -6
- package/chunks/{chunk-CALNF3Z3.js → chunk-7C57HCOR.js} +1 -1
- package/chunks/{chunk-UYDQYDW2.js → chunk-7IBS746B.js} +1 -1
- package/chunks/{chunk-AUTUFD5X.js → chunk-ABNX6E6K.js} +1 -1
- package/chunks/chunk-ACHCT36C.js +28 -0
- package/chunks/{chunk-2WC3Y7YY.js → chunk-AEY27Z35.js} +401 -23
- package/chunks/{chunk-AO2VMS72.js → chunk-AQFRRH73.js} +3 -3
- package/chunks/{chunk-PDN7FJZV.js → chunk-ASWEMQIZ.js} +4 -4
- package/chunks/chunk-AYEJOTIU.js +43 -0
- package/chunks/{chunk-QFJZAY7W.js → chunk-BKFRA4F5.js} +5 -5
- package/chunks/{chunk-KCF2436G.js → chunk-BNLW5N6U.js} +4 -4
- package/chunks/{chunk-GOKAOSCN.js → chunk-BRFOZEPA.js} +2 -2
- package/chunks/{process-registry-OAEG6WGC.js → chunk-BYUAT5OC.js} +1 -0
- package/chunks/chunk-C5CECJ46.js +340 -0
- package/chunks/{chunk-NOO4QFXM.js → chunk-C75BXMPM.js} +1 -3
- package/chunks/chunk-CAAMI77K.js +937 -0
- package/chunks/{chunk-QTB4VP4K.js → chunk-CBGHRAWM.js} +304 -23
- package/chunks/chunk-CF5KXZZX.js +150 -0
- package/chunks/chunk-CFMZLE3L.js +75 -0
- package/chunks/{chunk-TGNNLRC3.js → chunk-CJ3DHN5I.js} +1 -0
- package/chunks/{chunk-ERXNTINK.js → chunk-CQZJYGRX.js} +1 -1
- package/chunks/{chunk-WBU2PIZ5.js → chunk-CSDKDHWV.js} +23 -16
- package/chunks/{chunk-2EKVPSIJ.js → chunk-D754KKNZ.js} +9 -2
- package/chunks/{chunk-E6TI726I.js → chunk-DGC7BKEZ.js} +1 -1
- package/chunks/{chunk-7SVM3RP2.js → chunk-DMMOQWRF.js} +4 -6
- package/chunks/{chunk-J3TJH52D.js → chunk-DOTF2PF2.js} +1 -1
- package/chunks/{chunk-2BMXHB6N.js → chunk-DWBNQR53.js} +7 -7
- package/chunks/{chunk-ZN5TKAVR.js → chunk-E5LTUWKZ.js} +3 -3
- package/chunks/chunk-EGW3ZP6Y.js +32 -0
- package/chunks/chunk-ELRMZTPF.js +374 -0
- package/chunks/{chunk-RNAJVXUG.js → chunk-ENAUXRPG.js} +6 -6
- package/chunks/{chunk-WXD7INFV.js → chunk-EO4U2X47.js} +10 -8
- package/chunks/{chunk-WDVV3LRM.js → chunk-EPVEPTI3.js} +45 -152
- package/chunks/chunk-ERU3SDXT.js +27 -0
- package/chunks/{chunk-4HOEU2OR.js → chunk-EWJTAP3Y.js} +1 -19
- package/chunks/{chunk-GSFV5RQW.js → chunk-EYN3G5XD.js} +328 -4
- package/chunks/{chunk-QB3KS3N3.js → chunk-FGROOEKM.js} +5 -40
- package/chunks/{chunk-TOOOLHVS.js → chunk-FH5AVEWJ.js} +3 -3
- package/chunks/{chunk-DAI65CMX.js → chunk-FJZWRNEW.js} +1 -1
- package/chunks/{chunk-GNY7B3CA.js → chunk-FUQK5ZNL.js} +1 -1
- package/chunks/{chunk-GOEVQADN.js → chunk-GDIPPCW6.js} +330 -175
- package/chunks/{chunk-ALMR3E6Q.js → chunk-GDWE23OR.js} +3 -3
- package/chunks/{chunk-LNYV4GXX.js → chunk-GSKX53AN.js} +0 -139
- package/chunks/{chunk-ELD3OBPU.js → chunk-GWOVD63C.js} +3 -3
- package/chunks/{chunk-IWABUX6T.js → chunk-GX5FF2IE.js} +6 -6
- package/chunks/{chunk-22GORRNY.js → chunk-GZMNHAYC.js} +1 -1
- package/chunks/{chunk-YZTGGCEE.js → chunk-H3TFIFX3.js} +1 -1
- package/chunks/{chunk-6G4V7SE4.js → chunk-HG46TTAG.js} +1 -1
- package/chunks/{chunk-FETY36NQ.js → chunk-HGEUHUEV.js} +1 -1
- package/chunks/{chunk-KEPC5BOL.js → chunk-IBRQG2MP.js} +12 -15
- package/chunks/{chunk-OXR34GCD.js → chunk-IILWL3KY.js} +2054 -146
- package/chunks/{chunk-IW6RQPQB.js → chunk-IJOS26LH.js} +1 -3
- package/chunks/{chunk-ORFIYTI2.js → chunk-IK2MWJP5.js} +1 -1
- package/chunks/{chunk-CMWU6P4D.js → chunk-IRJRB3OD.js} +1 -1
- package/chunks/{chunk-QHLHE2OT.js → chunk-IUN5ZMFY.js} +1 -1
- package/chunks/{chunk-LYT2OU7D.js → chunk-IXXV6BVB.js} +172 -6
- package/chunks/{chunk-R3JIDRUL.js → chunk-J6H4JP25.js} +4 -4
- package/chunks/{chunk-NB3NDQQK.js → chunk-J6SBP5G2.js} +1 -1
- package/chunks/{chunk-TRQNRP2H.js → chunk-J7LBAKDH.js} +46 -3
- package/chunks/{chunk-67XTVRVB.js → chunk-JJFHISXU.js} +30 -25
- package/chunks/chunk-JL6APGBX.js +43 -0
- package/chunks/{chunk-NX7ZTXFF.js → chunk-JSKEW4E7.js} +2 -1
- package/chunks/{chunk-BK7D2JR6.js → chunk-JVTXAA35.js} +3 -3
- package/chunks/chunk-K2OJUPOE.js +78 -0
- package/chunks/{chunk-G3ZUMSFS.js → chunk-K3U6VB3O.js} +6 -6
- package/chunks/{chunk-4I3WFI3U.js → chunk-K4KWLF7Q.js} +12 -12
- package/chunks/{chunk-WXPPUPHM.js → chunk-KWFFJ6AK.js} +1 -1
- package/chunks/{chunk-46MMBZHI.js → chunk-KZYOFJ6V.js} +4 -4
- package/chunks/{chunk-ULZECEIP.js → chunk-LDQHA6L4.js} +2 -20
- package/chunks/{chunk-7LTCFO6T.js → chunk-LQBAFO5D.js} +6 -5
- package/chunks/{chunk-SOA4HKRJ.js → chunk-LT2XFADM.js} +2 -2
- package/chunks/{chunk-JYGIJA4W.js → chunk-LWWRJRCD.js} +1 -1
- package/chunks/{chunk-YQGW3M6Z.js → chunk-MFQWRBFB.js} +5 -5
- package/chunks/{chunk-TODNHE76.js → chunk-MUFGTWQH.js} +5 -5
- package/chunks/{chunk-5DQ4YTIZ.js → chunk-MV5XRRML.js} +3 -3
- package/chunks/{chunk-IR6JKBAP.js → chunk-NOUK63IR.js} +2 -2
- package/chunks/{chunk-XQ4RDO5B.js → chunk-NV77SEX3.js} +1 -1
- package/chunks/{chunk-OFVAS4AR.js → chunk-NWDPOFJI.js} +2 -2
- package/chunks/chunk-NY6OPAPS.js +820 -0
- package/chunks/{chunk-WDN64MVT.js → chunk-O5VX66FB.js} +127 -18
- package/chunks/{chunk-MV5DTLJV.js → chunk-OHCR4O3U.js} +1 -1
- package/chunks/{chunk-LEAOJ43M.js → chunk-OKOPKQ2X.js} +1310 -2107
- package/chunks/{chunk-B25JYXZE.js → chunk-ONLJBOI2.js} +971 -17
- package/chunks/{chunk-QQK4L3UU.js → chunk-OWUAZXXN.js} +132 -26
- package/chunks/{chunk-R457KFV7.js → chunk-P42IUOAO.js} +3 -3
- package/chunks/{chunk-LUNC5KCL.js → chunk-PRELUGCQ.js} +214 -39
- package/chunks/{chunk-5OZUKLL7.js → chunk-QSMQKTXV.js} +4 -4
- package/chunks/{chunk-FAJPLSYF.js → chunk-QTQYLQ5A.js} +85 -81
- package/chunks/{chunk-CALTQWTZ.js → chunk-QVZDV4ZS.js} +2 -2
- package/chunks/{chunk-J6MB5ZHZ.js → chunk-QZW6WRB7.js} +2 -1
- package/chunks/{chunk-KFECPHLV.js → chunk-RBWAGV73.js} +3 -3
- package/chunks/{chunk-4VY3ITHR.js → chunk-RF5RQRTD.js} +3 -3
- package/chunks/{chunk-HIXUUCGY.js → chunk-RPMXMR6U.js} +2 -2
- package/chunks/{chunk-3OAXF3UK.js → chunk-RRQEZBL2.js} +3756 -1343
- package/chunks/{chunk-4ALNJDHL.js → chunk-RSGEAWFJ.js} +19 -1
- package/chunks/{chunk-5BH2AIEY.js → chunk-RUE62UH6.js} +2 -2
- package/chunks/{chunk-PQEISIKS.js → chunk-SAH4BD2J.js} +0 -67
- package/chunks/{chunk-A7EFXK7P.js → chunk-SAOJHRWY.js} +2 -2
- package/chunks/{chunk-JO77FGNZ.js → chunk-SDUIETBG.js} +19 -7
- package/chunks/{chunk-6RZX2HIH.js → chunk-TBEXLLAO.js} +2 -2
- package/chunks/{chunk-PSPAM24S.js → chunk-TBSCTWKF.js} +6 -0
- package/chunks/{chunk-HRPFBHW7.js → chunk-TPKQIA7G.js} +1 -0
- package/chunks/{chunk-XDNFODER.js → chunk-TUIW5LLK.js} +1 -1
- package/chunks/{chunk-APXIW2TF.js → chunk-TVV5FA3G.js} +4 -4
- package/chunks/chunk-U6H3XTFA.js +95 -0
- package/chunks/{chunk-S5QR6CB5.js → chunk-UKMWZ5NS.js} +108 -887
- package/chunks/{chunk-U6REWGVR.js → chunk-VG2BRSEK.js} +2 -2
- package/chunks/chunk-VGBOJH2D.js +127 -0
- package/chunks/chunk-VGY2RGXL.js +100 -0
- package/chunks/{chunk-ZP5XDLSA.js → chunk-VLWG3EHY.js} +12 -12
- package/chunks/{chunk-4JNHNVAZ.js → chunk-W547PYQ7.js} +9 -4
- package/chunks/{chunk-7VEYUF3N.js → chunk-W5ZQMAEM.js} +1 -1
- package/chunks/{chunk-QAZ2MGYT.js → chunk-W7JJLUSB.js} +2 -2
- package/chunks/{chunk-CCBTNJB4.js → chunk-W7Q7XDQI.js} +39 -27
- package/chunks/{chunk-DARWOZY6.js → chunk-WD6YQI5M.js} +1 -1
- package/chunks/{chunk-F2NYVASI.js → chunk-WXAWG3JS.js} +30 -13
- package/chunks/{chunk-NPKCVSXX.js → chunk-XB5JRCAM.js} +11 -9
- package/chunks/{chunk-XSOXPG2L.js → chunk-XE46RQFI.js} +136 -8
- package/chunks/{chunk-QTNCGZHQ.js → chunk-XX5HQLCZ.js} +16 -0
- package/chunks/{chunk-2Z3T52OC.js → chunk-Y5TM7SBV.js} +7 -2
- package/chunks/chunk-YC6XOB5N.js +691 -0
- package/chunks/{chunk-CWVZBIZJ.js → chunk-YDW4ERSS.js} +1 -1
- package/chunks/{chunk-TRWQQBVH.js → chunk-YGCTOXUT.js} +10 -24
- package/chunks/{chunk-WK7P62DV.js → chunk-YKC67ZEF.js} +6 -6
- package/chunks/{chunk-KA5HR3G2.js → chunk-YKM6MITI.js} +5 -5
- package/chunks/{chunk-X7LFJF5D.js → chunk-YM6KUQ2S.js} +36 -84
- package/chunks/{chunk-HZ2HUXX7.js → chunk-YS2ZJSOA.js} +29 -12
- package/chunks/{chunk-G37O7YO6.js → chunk-ZAWM6KRF.js} +3 -3
- package/chunks/{chunk-H3Q3RSKZ.js → chunk-ZFIWHBJ3.js} +1 -1
- package/chunks/{chunk-XBVNNDPK.js → chunk-ZHKTKHMO.js} +8 -1
- package/chunks/{chunk-YLOHCA6I.js → chunk-ZKWO4CF4.js} +2 -2
- package/chunks/{chunk-VJJXG73H.js → chunk-ZMQL5BL5.js} +21 -6
- package/chunks/{chunk-FGHPZGOP.js → chunk-ZMUYBOYB.js} +39 -55
- package/chunks/{chunk-FV4DM2M4.js → chunk-ZNI3YJHS.js} +26 -6
- package/chunks/{chunk-565U2ANU.js → chunk-ZTTC7T4X.js} +1 -1
- package/chunks/{chunk-7OCIQNKX.js → chunk-ZW2EUO2A.js} +1 -1
- package/chunks/codex-subagent-executor-26XOHVKH.js +585 -0
- package/chunks/{config-utils-GPLIABL2.js → config-utils-JUG3MOYN.js} +68 -57
- package/chunks/{contextCommand-NCUQUDBY.js → contextCommand-6K3POZFA.js} +65 -54
- package/chunks/{core-runtime-WKYKWVYU.js → core-runtime-XQFZLA2V.js} +66 -55
- package/chunks/{create-sub-session-TGIX63YU.js → create-sub-session-4UJ6RM6W.js} +5 -2
- package/chunks/{create-sub-session-PPLXB3JJ.js → create-sub-session-T4IYIOC7.js} +178 -91
- package/chunks/{cron-create-GTPVMJCF.js → cron-create-6466RWSO.js} +2 -2
- package/chunks/{cron-delete-ZBK27Z4K.js → cron-delete-W4QUWHOA.js} +2 -2
- package/chunks/{cron-list-KTFKFDKC.js → cron-list-Q5LJ5PZE.js} +2 -2
- package/chunks/{daemon-2CKIAO3I.js → daemon-PHPJUXDZ.js} +4 -2
- package/chunks/{daemon-git-worktree-guard-73ZWOLKL.js → daemon-git-worktree-guard-5WEMZ64U.js} +65 -54
- package/chunks/{daemon-status-provider-OK7VONJG.js → daemon-status-provider-GMD7QD4T.js} +74 -63
- package/chunks/{daemon-trust-policy-CAUCREG2.js → daemon-trust-policy-IPBZES2Z.js} +71 -60
- package/chunks/{daemon-trust-policy-monitor-3Y36OOEQ.js → daemon-trust-policy-monitor-MHYEN7X7.js} +71 -60
- package/chunks/{de-UU2YTO37.js → de-OOLZAU2U.js} +1 -1
- package/chunks/{deferred-core-runtime-Q7WFWYD3.js → deferred-core-runtime-CY43FZNZ.js} +63 -52
- package/chunks/{discovery-XP4RMDUM.js → discovery-5KUEPR65.js} +2 -2
- package/chunks/{display-image-CTNHJRZC.js → display-image-6AZIHP3J.js} +3 -3
- package/chunks/{dist-F34J4FZX.js → dist-2QYIVNS6.js} +2 -5
- package/chunks/{dist-6YDUH3BB.js → dist-GIMQXYLI.js} +10 -631
- package/chunks/{dist-NP7QKLVG.js → dist-GUB7QRYA.js} +3 -6
- package/chunks/{dist-Y5KC3IHW.js → dist-L45UB6DG.js} +233 -35
- package/chunks/{dist-XLV33CLY.js → dist-MPUZZOG5.js} +5 -18
- package/chunks/{dist-ZDNJK74R.js → dist-PA7WPFVE.js} +6 -37
- package/chunks/{dist-F6JLAJLE.js → dist-T6DDPDLQ.js} +16 -36
- package/chunks/{dist-BNQVF565.js → dist-TFGETXFN.js} +14 -37
- package/chunks/{dist-UFTFGI6I.js → dist-VDLSBCLM.js} +2 -6
- package/chunks/{edit-YJD6IETK.js → edit-6NUP5IPX.js} +48 -38
- package/chunks/{en-YJNRUQG4.js → en-ZSZW3PZX.js} +4 -1
- package/chunks/{enter-worktree-YFTKHXHZ.js → enter-worktree-EETDMJRF.js} +5 -5
- package/chunks/{enterPlanMode-EFPVTWIH.js → enterPlanMode-AZHYHEII.js} +48 -38
- package/chunks/{environment-HP3AXFTB.js → environment-ON6GIQ4F.js} +66 -55
- package/chunks/{errors-22ON46G7.js → errors-DQE63SCC.js} +65 -54
- package/chunks/exec-66WQIVYU.js +505 -0
- package/chunks/{exit-worktree-NF2XEMES.js → exit-worktree-DIPJ6S55.js} +5 -5
- package/chunks/{exitPlanMode-MOQUNCBH.js → exitPlanMode-NHBV6LAI.js} +48 -38
- package/chunks/{fast-path-2X7BPMXX.js → fast-path-EPJSUZZC.js} +7 -7
- package/chunks/{fast-path-settings-SATXY3PD.js → fast-path-settings-XDYX7X5Z.js} +2 -2
- package/chunks/{fr-HKNWVXRJ.js → fr-JJWM2HUS.js} +1 -1
- package/chunks/{glob-Y7ACIB3P.js → glob-MNEXQ2NV.js} +51 -41
- package/chunks/{goal-tools-DABMICUC.js → goal-tools-D2A4QBCJ.js} +54 -40
- package/chunks/{grep-BLHF2S5D.js → grep-EFWPV3MM.js} +2 -2
- package/chunks/{handleAutoUpdate-MCAMHYDI.js → handleAutoUpdate-2RY3OQA6.js} +67 -56
- package/chunks/{i18n-C3GDCALP.js → i18n-HTHDB3I7.js} +64 -53
- package/chunks/{image-gen-XP4NNIYG.js → image-gen-2PHED3P4.js} +8 -6
- package/chunks/{initializer-4URDQL2G.js → initializer-JEVLJCQA.js} +71 -60
- package/chunks/{installationInfo-LBOL6SBV.js → installationInfo-ITRB6J4L.js} +63 -52
- package/chunks/{ja-GJS5RZGU.js → ja-L67TXFDJ.js} +1 -1
- package/chunks/list-KOUIMHT5.js +133 -0
- package/chunks/{list-agents-2CXPGJUE.js → list-agents-IY4NEWLP.js} +17 -7
- package/chunks/{llm-2KPNSAVY.js → llm-F7WHGESY.js} +132 -120
- package/chunks/{llm-content-generator-GR3FOHLB.js → llm-content-generator-NYQ2NAVA.js} +6 -5
- package/chunks/{loadedSettingsAdapter-DVKROEJD.js → loadedSettingsAdapter-HZUAX5CX.js} +71 -60
- package/chunks/{loggingContentGenerator-P4K6K5W4.js → loggingContentGenerator-WMNU7C5J.js} +70 -59
- package/chunks/{loop-wakeup-HL6XOWI4.js → loop-wakeup-ANX25YW2.js} +3 -3
- package/chunks/{ls-YV7RKLKY.js → ls-4XCMJNZF.js} +4 -4
- package/chunks/{lsp-NO3AMRZT.js → lsp-K5E2Y64R.js} +1 -1
- package/chunks/{managed-npm-update-VWBKHNIN.js → managed-npm-update-EJJB65QI.js} +63 -52
- package/chunks/mcp-I73R6HS3.js +127 -0
- package/chunks/{monitor-A255TNZR.js → monitor-T56GJNA4.js} +50 -40
- package/chunks/{nonInteractiveCli-LXGIKQAT.js → nonInteractiveCli-CKHHJ423.js} +120 -109
- package/chunks/{notebook-edit-5UYHS2DM.js → notebook-edit-W5TU3EZ3.js} +48 -38
- package/chunks/openai-WX26N5OJ.js +47 -0
- package/chunks/{openaiContentGenerator-A6MAMEO5.js → openaiContentGenerator-TH6YAWAH.js} +33 -25
- package/chunks/openaiResponsesContentGenerator-EWLWQPKS.js +1738 -0
- package/chunks/{pidfile-B7DZC4TP.js → pidfile-RCC6TCEM.js} +63 -52
- package/chunks/process-registry-X6ZCASEN.js +10 -0
- package/chunks/{processUtils-BPZ2MCZS.js → processUtils-DQDQBRMC.js} +2 -2
- package/chunks/{prompt-terminal-ledger-FYYTAOXS.js → prompt-terminal-ledger-2LXWAGWU.js} +64 -53
- package/chunks/{pt-FXMYXEUV.js → pt-77SBDL4B.js} +1 -1
- package/chunks/{qwenContentGenerator-4IOJFD4S.js → qwenContentGenerator-LG65Z2YV.js} +61 -49
- package/chunks/{qwenOAuth2-KX6LVYQ3.js → qwenOAuth2-PJ63CCFD.js} +7 -5
- package/chunks/{read-file-A4H4O3VQ.js → read-file-72HMRUT4.js} +12 -9
- package/chunks/{read-mcp-resource-D3N75DGF.js → read-mcp-resource-NPF44YSC.js} +1 -1
- package/chunks/{record-artifact-Q5CRGJTP.js → record-artifact-MDXCCW2J.js} +3 -3
- package/chunks/record-source-VJLKDGGR.js +22 -0
- package/chunks/{report-findings-TJ34R7QK.js → report-findings-CZTYMZTC.js} +4 -4
- package/chunks/{request-shutdown-LRKMTBAD.js → request-shutdown-KOZHPVZU.js} +5 -5
- package/chunks/{resumeHistoryUtils-YQQ43E4N.js → resumeHistoryUtils-S2Q3M3EH.js} +69 -58
- package/chunks/{ripGrep-W32NWFTA.js → ripGrep-B2I3L5CO.js} +17 -13
- package/chunks/{ru-RMHURE5U.js → ru-UYWHKWF2.js} +1 -1
- package/chunks/{run-qwen-serve-WBSWWIRV.js → run-qwen-serve-AOPYFCVP.js} +305 -132
- package/chunks/{runtime-VRVBX2E5.js → runtime-TZMHKZAP.js} +77 -66
- package/chunks/{scheduled-tasks-D65KJDA3.js → scheduled-tasks-7RL6ZOYT.js} +72 -60
- package/chunks/{scheduler-M2YPN7Z7.js → scheduler-D6RLOFNU.js} +65 -54
- package/chunks/{sdk-exporters-grpc-MXTVSE3C.js → sdk-exporters-grpc-Y2ZUQDUQ.js} +2 -2
- package/chunks/{sdk-exporters-http-7R2ARBPV.js → sdk-exporters-http-VWTF4W6K.js} +3 -3
- package/chunks/{sdk-impl-YOLO7LV4.js → sdk-impl-G6FVTBQZ.js} +9 -9
- package/chunks/{send-message-76BKWKFZ.js → send-message-MMZVSS7P.js} +12 -9
- package/chunks/{serve-BE3H2P6P.js → serve-HWWDYI37.js} +72 -61
- package/chunks/{server-FLY5JERG.js → server-MD2X5U5L.js} +3156 -564
- package/chunks/{session-JVN62R5K.js → session-AFUMFNN7.js} +124 -113
- package/chunks/{session-attachments-root-7ACGLHXA.js → session-attachments-root-QPN3YWTY.js} +63 -52
- package/chunks/{session-pr-refresh-TQS57SDK.js → session-pr-refresh-4Y2ANMJX.js} +72 -60
- package/chunks/{settings-D44YMZFT.js → settings-QQRQ2LR7.js} +74 -63
- package/chunks/{shell-3VE6I4V5.js → shell-NUYUYMVI.js} +48 -38
- package/chunks/{skill-FHEGRRZU.js → skill-KHLDVOXW.js} +68 -30
- package/chunks/{skill-settings-VHEJMBFL.js → skill-settings-INLEGDEZ.js} +70 -59
- package/chunks/{spawnChannel-T6MX2ZDN.js → spawnChannel-KBGZHW2G.js} +67 -56
- package/chunks/{standalone-update-QUGHFMCS.js → standalone-update-3QP5NDVJ.js} +65 -54
- package/chunks/{start-opentui-ui-IHIIZ2LE.js → start-opentui-ui-VBT3XDWN.js} +2682 -2153
- package/chunks/{startInteractiveUI-LR7K2ARZ.js → startInteractiveUI-AZHKCHMR.js} +1562 -2317
- package/chunks/{syntheticOutput-D2P5V6RG.js → syntheticOutput-KRASPDE3.js} +2 -2
- package/chunks/{task-create-MWXJFRRM.js → task-create-TNXNT7ZD.js} +8 -8
- package/chunks/{task-list-EYO3FE57.js → task-list-FHNIJDKT.js} +1 -1
- package/chunks/{task-stop-BFSKRTGV.js → task-stop-MG4ZMTEI.js} +1 -1
- package/chunks/{task-update-2JJJRHMT.js → task-update-4HU62CJT.js} +8 -8
- package/chunks/{team-create-GY3VFY47.js → team-create-K5DNSJXR.js} +50 -40
- package/chunks/{team-delete-IQZ6XGFI.js → team-delete-2T44GUNN.js} +1 -1
- package/chunks/{team-plan-approval-BQPGZOT5.js → team-plan-approval-2ZNAQT2A.js} +48 -38
- package/chunks/{terminal-image-renderer-YNYW5CQG.js → terminal-image-renderer-23CW4A6Q.js} +65 -54
- package/chunks/{theme-manager-U6CIK3GM.js → theme-manager-G2333AMH.js} +63 -52
- package/chunks/{todoWrite-5ERKFWAK.js → todoWrite-BO2GR5MN.js} +4 -4
- package/chunks/{tool-search-XI3QWD5I.js → tool-search-MKQCKXN5.js} +22 -15
- package/chunks/{total-session-admission-3SNSJJ32.js → total-session-admission-ENKTM2KX.js} +69 -58
- package/chunks/{trustedFolders-OVAQKNV5.js → trustedFolders-2ETDL7OD.js} +64 -53
- package/chunks/{update-relaunch-XV5O74E3.js → update-relaunch-FMVNN5KA.js} +5 -5
- package/chunks/{updateCheck-CHUYWD6L.js → updateCheck-KWRV5KLJ.js} +66 -55
- package/chunks/{useAutoAcceptIndicator-VKSVIXZC.js → useAutoAcceptIndicator-7AUXAIQF.js} +73 -62
- package/chunks/{validateNonInterActiveAuth-ZNUTD3E5.js → validateNonInterActiveAuth-NETKLLDV.js} +117 -106
- package/chunks/{version-EK7VAGSI.js → version-DACNN2ZM.js} +1 -1
- package/chunks/{web-fetch-24KZO763.js → web-fetch-CIVCRET4.js} +16 -12
- package/chunks/{web-search-CRNXKZ2X.js → web-search-GOHZRGMM.js} +389 -327
- package/chunks/{web-shell-static-BFDESDD4.js → web-shell-static-T7UGLVE4.js} +2 -7
- package/chunks/workflow-IL2FOALZ.js +1324 -0
- package/chunks/workspace-providers-status-YGXL6N5U.js +131 -0
- package/chunks/{workspace-registration-store-HKLJEDQX.js → workspace-registration-store-E4IAOFFZ.js} +3 -1
- package/chunks/{workspace-registry-7RDDOBLN.js → workspace-registry-KX6BIBYK.js} +69 -58
- package/chunks/{workspace-runtime-coordinator-LEPDPXJO.js → workspace-runtime-coordinator-2KYYGDDR.js} +72 -59
- package/chunks/{workspace-service-5IFDCNN3.js → workspace-service-5Q6LWBYR.js} +76 -65
- package/chunks/{workspace-skills-status-FJ3HNH4H.js → workspace-skills-status-PJZTFPVV.js} +72 -61
- package/chunks/{workspace-trust-reconciler-PQFHIWLR.js → workspace-trust-reconciler-HS6PWNEA.js} +77 -66
- package/chunks/{write-file-ERG67ZFX.js → write-file-JB3DRM7O.js} +50 -40
- package/chunks/{zh-VBFCRQBL.js → zh-7UJA4ICT.js} +4 -1
- package/chunks/{zh-TW-N2TBF2F2.js → zh-TW-RV24PWUI.js} +4 -1
- package/chunks/{zoom-image-WQYEC3SR.js → zoom-image-AVHQFOOQ.js} +12 -9
- package/cli.js +16 -16
- package/codeModeHost.js +4425 -0
- package/export-transcript-document.css +1 -0
- package/export-transcript-document.js +164 -165
- package/locales/ca.js +2 -2
- package/locales/de.js +2 -2
- package/locales/en.js +5 -2
- package/locales/fr.js +2 -2
- package/locales/ja.js +2 -2
- package/locales/pt.js +2 -2
- package/locales/ru.js +2 -2
- package/locales/zh-TW.js +5 -2
- package/locales/zh.js +5 -2
- package/package.json +6 -4
- package/web-shell/assets/{abnfDiagram-VCTEODGH-BRLgQbnT.js → abnfDiagram-VCTEODGH-BH2nK5Z_.js} +1 -1
- package/web-shell/assets/{arc-qAF9_XsR.js → arc-CUUQ6krv.js} +1 -1
- package/web-shell/assets/{architectureDiagram-5GKGNRK7-BorUttEz.js → architectureDiagram-5GKGNRK7-CJjiRuGx.js} +1 -1
- package/web-shell/assets/{blockDiagram-NRAW4CY4-Bj0qZVxu.js → blockDiagram-NRAW4CY4-GCDyU9ZX.js} +1 -1
- package/web-shell/assets/{c4Diagram-UCG6FXSJ-BTqJis32.js → c4Diagram-UCG6FXSJ-C68MiN6h.js} +1 -1
- package/web-shell/assets/channel-DauVlmdF.js +1 -0
- package/web-shell/assets/{chunk-2Q5K7J3B-RrQ5X8m-.js → chunk-2Q5K7J3B-_8B6frXZ.js} +1 -1
- package/web-shell/assets/{chunk-5VM5RSS4-uUjDl8wO.js → chunk-5VM5RSS4-CroSinX7.js} +1 -1
- package/web-shell/assets/{chunk-F27PBJKO-C3JhpyzI.js → chunk-F27PBJKO-CGn4Z0Fx.js} +1 -1
- package/web-shell/assets/{chunk-G27WJ6UU-C8ZNFs7F.js → chunk-G27WJ6UU-BI5nLQcf.js} +1 -1
- package/web-shell/assets/{chunk-JWPE2WC7-DNpXtEOs.js → chunk-JWPE2WC7-CYJH0FuH.js} +1 -1
- package/web-shell/assets/{chunk-LCL6LL3I-DagA2ZLw.js → chunk-LCL6LL3I-DjWZUqA1.js} +1 -1
- package/web-shell/assets/{chunk-POPQ4Y6H-R23uH7Xm.js → chunk-POPQ4Y6H-DcTkIHm8.js} +1 -1
- package/web-shell/assets/{chunk-SVP7TREG-Qz9RN_BR.js → chunk-SVP7TREG-E8sZT5uK.js} +1 -1
- package/web-shell/assets/{chunk-XXDRQBXY-jYb1_hni.js → chunk-XXDRQBXY-CurjPKw_.js} +1 -1
- package/web-shell/assets/classDiagram-DTDB5LWJ-BuIh7bj1.js +1 -0
- package/web-shell/assets/classDiagram-v2-JRS7N3AN-BuIh7bj1.js +1 -0
- package/web-shell/assets/{cose-bilkent-JH36ORCC-Cv2OunpE.js → cose-bilkent-JH36ORCC-CJEnNhth.js} +1 -1
- package/web-shell/assets/{cynefin-OW5HDTMX-LH42KFJx.js → cynefin-OW5HDTMX-jwEkm0yw.js} +1 -1
- package/web-shell/assets/{cynefinDiagram-5FMLGOSQ-Dha4_OoR.js → cynefinDiagram-5FMLGOSQ-B-OVQ6AO.js} +1 -1
- package/web-shell/assets/{dagre-3AP2YEHR-Br5lnUKD.js → dagre-3AP2YEHR-CKKK9WNR.js} +1 -1
- package/web-shell/assets/{diagram-S7CK7UJ4-dpKq2bBX.js → diagram-S7CK7UJ4-D486veFQ.js} +1 -1
- package/web-shell/assets/{diagram-UQ7AKVKN-BAgHWpXr.js → diagram-UQ7AKVKN-C3GujqHv.js} +1 -1
- package/web-shell/assets/{diagram-VSXAHHWV-GRRzpyE2.js → diagram-VSXAHHWV-BrOTDwuU.js} +1 -1
- package/web-shell/assets/{diagram-VX7I27RA-BNFiaYpG.js → diagram-VX7I27RA-C4D9kWE3.js} +1 -1
- package/web-shell/assets/{diagram-Z3DM3KII-BisZzB_h.js → diagram-Z3DM3KII-7rAManT0.js} +1 -1
- package/web-shell/assets/{ebnfDiagram-PWID7BFC-B1xbwycf.js → ebnfDiagram-PWID7BFC-CqVzKOdr.js} +1 -1
- package/web-shell/assets/{erDiagram-SSCWMZ5O-CQMzbGE5.js → erDiagram-SSCWMZ5O-D2s08fc_.js} +1 -1
- package/web-shell/assets/{flowDiagram-A5DVABFB-CZ_Zondl.js → flowDiagram-A5DVABFB-CrKtBxB2.js} +1 -1
- package/web-shell/assets/{ganttDiagram-EL5Y4UJY-BTh2ShxS.js → ganttDiagram-EL5Y4UJY-CD1CKdlt.js} +1 -1
- package/web-shell/assets/{gitGraphDiagram-WWUBYQGX-oHOB-Uxt.js → gitGraphDiagram-WWUBYQGX-CHDXdVNn.js} +1 -1
- package/web-shell/assets/index-D8tzgUOC.css +36 -0
- package/web-shell/assets/{index-DWoFMu5x.js → index-DWz95m74.js} +1 -1
- package/web-shell/assets/index-cDFf68Wd.js +2204 -0
- package/web-shell/assets/{infoDiagram-RXCK75RN-C0QpudbG.js → infoDiagram-RXCK75RN-Cr1oLCwe.js} +1 -1
- package/web-shell/assets/{ishikawaDiagram-5VMMS53U-a6B741uT.js → ishikawaDiagram-5VMMS53U--RghV1mm.js} +1 -1
- package/web-shell/assets/{journeyDiagram-EYS64GPL-Dbht9ICp.js → journeyDiagram-EYS64GPL-MN1ZkGW8.js} +1 -1
- package/web-shell/assets/{kanban-definition-3QL26DDD-D4OFR8-h.js → kanban-definition-3QL26DDD-DL05VTn0.js} +1 -1
- package/web-shell/assets/{layout-Dvdh5jRH.js → layout-D_TvQzvn.js} +1 -1
- package/web-shell/assets/{linear-Dvc6KIW2.js → linear-B_0OH6XF.js} +1 -1
- package/web-shell/assets/{mermaid.core-CB36RfIb.js → mermaid.core-B9Nklh9I.js} +6 -6
- package/web-shell/assets/{mindmap-definition-FBJOCRG2-Fmqo1CjP.js → mindmap-definition-FBJOCRG2-CevIQ0LR.js} +1 -1
- package/web-shell/assets/{pegDiagram-XKGWAZYB-CCxYBoA4.js → pegDiagram-XKGWAZYB-DQ8PIv0d.js} +1 -1
- package/web-shell/assets/{pieDiagram-E7YTZNPT-BVHKQFzt.js → pieDiagram-E7YTZNPT-BVTV1pPe.js} +1 -1
- package/web-shell/assets/{quadrantDiagram-AXDQQJYC-l95IznwR.js → quadrantDiagram-AXDQQJYC-DHN6nhpe.js} +1 -1
- package/web-shell/assets/qwen-code-notification-BRVagufF.png +0 -0
- package/web-shell/assets/{railroadDiagram-O6MQD6OU-BlLdRdXp.js → railroadDiagram-O6MQD6OU-8HOyX0u-.js} +1 -1
- package/web-shell/assets/{requirementDiagram-EFPCY7ZU-BkDLBR5w.js → requirementDiagram-EFPCY7ZU-9W4_14i8.js} +1 -1
- package/web-shell/assets/{sankeyDiagram-P5KCCOFB-jAIqRp65.js → sankeyDiagram-P5KCCOFB-DSUBB2XP.js} +1 -1
- package/web-shell/assets/{sequenceDiagram-WJ2MYXX4-f-soZYPr.js → sequenceDiagram-WJ2MYXX4-DD3jH6Jn.js} +1 -1
- package/web-shell/assets/{sizeCapture-X5ZJPWSS-BzOuAfB2.js → sizeCapture-X5ZJPWSS-RAFTU3Cz.js} +1 -1
- package/web-shell/assets/{stateDiagram-HBIQ2CUA-BPLSs12r.js → stateDiagram-HBIQ2CUA-Drk-oZ2x.js} +1 -1
- package/web-shell/assets/stateDiagram-v2-4QOOHH4V-QzYteVIm.js +1 -0
- package/web-shell/assets/{swimlanes-XN3QIQJK-D-9E_RIR.js → swimlanes-XN3QIQJK-Cy2nlOGx.js} +1 -1
- package/web-shell/assets/swimlanesDiagram-VK2B7HYN-xTr-HG26.js +8 -0
- package/web-shell/assets/{timeline-definition-24CTP7MA-CT56K-gV.js → timeline-definition-24CTP7MA-B7outYof.js} +1 -1
- package/web-shell/assets/{vennDiagram-4TSXK5OY-B-vi4IyO.js → vennDiagram-4TSXK5OY-Di_u1Ic6.js} +1 -1
- package/web-shell/assets/{wardleyDiagram-VM6X3IG4-C9O7Ju98.js → wardleyDiagram-VM6X3IG4-DYocuCAM.js} +1 -1
- package/web-shell/assets/{xychartDiagram-S5SC5T6Z-6d8w3jg2.js → xychartDiagram-S5SC5T6Z-AADDse54.js} +1 -1
- package/web-shell/index.html +29 -5
- package/chunks/chunk-V7RNNPGC.js +0 -44
- package/chunks/list-JOGBAC2R.js +0 -122
- package/chunks/mcp-6YYNSYLK.js +0 -116
- package/chunks/workflow-HD5NYMW5.js +0 -2907
- package/chunks/workspace-providers-status-MAM42IZS.js +0 -120
- package/web-shell/assets/channel-COIuCrVH.js +0 -1
- package/web-shell/assets/classDiagram-DTDB5LWJ-DoX6OYqu.js +0 -1
- package/web-shell/assets/classDiagram-v2-JRS7N3AN-DoX6OYqu.js +0 -1
- package/web-shell/assets/index-CI1ysIEv.js +0 -2154
- package/web-shell/assets/index-CpxXGH-8.css +0 -36
- package/web-shell/assets/stateDiagram-v2-4QOOHH4V-IRul-LaT.js +0 -1
- package/web-shell/assets/swimlanesDiagram-VK2B7HYN-D6lgKepA.js +0 -8
- package/chunks/{chunk-JA5CBKRP.js → chunk-7NXSVSFB.js} +0 -0
- package/chunks/{open-with-auth-6MVIHMXB.js → open-with-auth-XFCCJOO6.js} +3 -3
|
@@ -1,16 +1,54 @@
|
|
|
1
1
|
// Force strict mode and setup for ESM
|
|
2
2
|
"use strict";
|
|
3
3
|
import {
|
|
4
|
+
AgentEventEmitter,
|
|
5
|
+
attachJsonlTranscriptWriter,
|
|
6
|
+
buildAgentTranscriptAttach,
|
|
7
|
+
deriveApprovalModeConfig,
|
|
8
|
+
deriveConfig,
|
|
9
|
+
deriveWorktreeConfig,
|
|
10
|
+
installSessionWorkflowRevisionWriteThrough,
|
|
4
11
|
isActiveWorkflowStatus,
|
|
5
12
|
isTerminalWorkflowStatus,
|
|
6
|
-
isWorkflowRunPersistenceActive
|
|
7
|
-
|
|
13
|
+
isWorkflowRunPersistenceActive,
|
|
14
|
+
parseSkillContent,
|
|
15
|
+
rebuildToolRegistryOnOverride,
|
|
16
|
+
resolveExternalWorktreeDir,
|
|
17
|
+
toModelVisibleSubagentResult
|
|
18
|
+
} from "./chunk-2UKKQGRA.js";
|
|
19
|
+
import {
|
|
20
|
+
parsePositiveIntegerEnv
|
|
21
|
+
} from "./chunk-6PVPNMXU.js";
|
|
22
|
+
import {
|
|
23
|
+
GitWorktreeService,
|
|
24
|
+
generateAgentWorktreeSlug,
|
|
25
|
+
writeWorktreeSessionMarker
|
|
26
|
+
} from "./chunk-RPMXMR6U.js";
|
|
27
|
+
import {
|
|
28
|
+
resolveBundleDir
|
|
29
|
+
} from "./chunk-ACHCT36C.js";
|
|
30
|
+
import {
|
|
31
|
+
SUBAGENT_PLAN_LIFECYCLE_TOOLS
|
|
32
|
+
} from "./chunk-W7JJLUSB.js";
|
|
33
|
+
import {
|
|
34
|
+
runWithAgentContext
|
|
35
|
+
} from "./chunk-ZFIWHBJ3.js";
|
|
36
|
+
import {
|
|
37
|
+
read,
|
|
38
|
+
writeLine
|
|
39
|
+
} from "./chunk-WXAWG3JS.js";
|
|
8
40
|
import {
|
|
9
41
|
atomicWriteFile
|
|
10
42
|
} from "./chunk-XFFRI3WM.js";
|
|
11
43
|
import {
|
|
12
44
|
stripAnsiAndControl
|
|
13
|
-
} from "./chunk-
|
|
45
|
+
} from "./chunk-W5ZQMAEM.js";
|
|
46
|
+
import {
|
|
47
|
+
SyntheticOutputTool
|
|
48
|
+
} from "./chunk-DGC7BKEZ.js";
|
|
49
|
+
import {
|
|
50
|
+
ToolNames
|
|
51
|
+
} from "./chunk-2WSLXP3W.js";
|
|
14
52
|
import {
|
|
15
53
|
Storage,
|
|
16
54
|
createDebugLogger
|
|
@@ -565,6 +603,7 @@ var MAX_LOG_LINES = 1e4;
|
|
|
565
603
|
var MAX_PHASE_ENTRIES = 1e4;
|
|
566
604
|
var ARGS_MAX_DEPTH = 64;
|
|
567
605
|
var DEFAULT_MAX_WALL_CLOCK_MS = 30 * 60 * 1e3;
|
|
606
|
+
var WORKFLOW_SYNC_EVALUATION_TIMEOUT_MS = 3e4;
|
|
568
607
|
function resolveMaxWallClockMs(opts) {
|
|
569
608
|
if (typeof opts.maxWallClockMs === "number" && opts.maxWallClockMs > 0) {
|
|
570
609
|
return opts.maxWallClockMs;
|
|
@@ -1548,7 +1587,7 @@ function createWorkflowSandbox(opts) {
|
|
|
1548
1587
|
throw workflowCancelledError();
|
|
1549
1588
|
}
|
|
1550
1589
|
const runOpts = {
|
|
1551
|
-
timeout:
|
|
1590
|
+
timeout: WORKFLOW_SYNC_EVALUATION_TIMEOUT_MS
|
|
1552
1591
|
};
|
|
1553
1592
|
const result = script.runInContext(ctx, runOpts);
|
|
1554
1593
|
const timeoutPromise = new Promise((_, reject) => {
|
|
@@ -1612,11 +1651,96 @@ function createWorkflowSandbox(opts) {
|
|
|
1612
1651
|
}
|
|
1613
1652
|
__name(createWorkflowSandbox, "createWorkflowSandbox");
|
|
1614
1653
|
|
|
1654
|
+
// packages/core/src/agents/runtime/workflow-budget.ts
|
|
1655
|
+
init_esbuild_shims();
|
|
1656
|
+
var debugLogger2 = createDebugLogger("WORKFLOW_BUDGET");
|
|
1657
|
+
var MAX_TOKENS_PER_WORKFLOW_ENV = "QWEN_CODE_MAX_TOKENS_PER_WORKFLOW";
|
|
1658
|
+
var HARD_MAX_TOKENS_CEILING = 1e8;
|
|
1659
|
+
function resolveMaxTokensPerWorkflow(env = process.env) {
|
|
1660
|
+
const raw = env[MAX_TOKENS_PER_WORKFLOW_ENV];
|
|
1661
|
+
if (raw === void 0 || raw.trim() === "") {
|
|
1662
|
+
return null;
|
|
1663
|
+
}
|
|
1664
|
+
const parsed = parsePositiveIntegerEnv(raw, 0);
|
|
1665
|
+
if (parsed < 1) {
|
|
1666
|
+
debugLogger2.warn(
|
|
1667
|
+
`Invalid ${MAX_TOKENS_PER_WORKFLOW_ENV}=${JSON.stringify(raw)}, treating as unset (no cap)`
|
|
1668
|
+
);
|
|
1669
|
+
return null;
|
|
1670
|
+
}
|
|
1671
|
+
if (parsed > HARD_MAX_TOKENS_CEILING) {
|
|
1672
|
+
debugLogger2.warn(
|
|
1673
|
+
`${MAX_TOKENS_PER_WORKFLOW_ENV}=${parsed} exceeds hard ceiling (${HARD_MAX_TOKENS_CEILING}); clamping.`
|
|
1674
|
+
);
|
|
1675
|
+
return HARD_MAX_TOKENS_CEILING;
|
|
1676
|
+
}
|
|
1677
|
+
return parsed;
|
|
1678
|
+
}
|
|
1679
|
+
__name(resolveMaxTokensPerWorkflow, "resolveMaxTokensPerWorkflow");
|
|
1680
|
+
var WorkflowBudgetImpl = class _WorkflowBudgetImpl {
|
|
1681
|
+
static {
|
|
1682
|
+
__name(this, "WorkflowBudgetImpl");
|
|
1683
|
+
}
|
|
1684
|
+
total;
|
|
1685
|
+
_spent;
|
|
1686
|
+
constructor(total) {
|
|
1687
|
+
this.total = total;
|
|
1688
|
+
this._spent = 0;
|
|
1689
|
+
}
|
|
1690
|
+
spent() {
|
|
1691
|
+
return this._spent;
|
|
1692
|
+
}
|
|
1693
|
+
remaining() {
|
|
1694
|
+
if (this.total === null) return Infinity;
|
|
1695
|
+
return Math.max(0, this.total - this._spent);
|
|
1696
|
+
}
|
|
1697
|
+
/**
|
|
1698
|
+
* Host-side increment. NOT exposed to the script — the
|
|
1699
|
+
* `WorkflowBudget` interface deliberately omits any setter so a
|
|
1700
|
+
* malicious workflow cannot inflate / deflate the budget. Only the
|
|
1701
|
+
* orchestrator (in `countedDispatch`) calls this after a dispatch
|
|
1702
|
+
* resolves with the agent's output token count.
|
|
1703
|
+
*
|
|
1704
|
+
* Non-positive deltas are silently dropped (some dispatches return
|
|
1705
|
+
* `output_tokens: 0` on early failures); negative deltas would be a
|
|
1706
|
+
* caller bug and are also dropped rather than silently rewinding
|
|
1707
|
+
* the counter.
|
|
1708
|
+
*/
|
|
1709
|
+
recordSpent(deltaTokens) {
|
|
1710
|
+
if (!Number.isFinite(deltaTokens) || deltaTokens <= 0) return;
|
|
1711
|
+
this._spent += deltaTokens;
|
|
1712
|
+
}
|
|
1713
|
+
/**
|
|
1714
|
+
* Factory: build a budget from the current environment. Convenience
|
|
1715
|
+
* over `new WorkflowBudgetImpl(resolveMaxTokensPerWorkflow(env))`.
|
|
1716
|
+
*/
|
|
1717
|
+
static fromEnv(env = process.env) {
|
|
1718
|
+
return new _WorkflowBudgetImpl(resolveMaxTokensPerWorkflow(env));
|
|
1719
|
+
}
|
|
1720
|
+
};
|
|
1721
|
+
var WorkflowBudgetExceededError = class extends Error {
|
|
1722
|
+
static {
|
|
1723
|
+
__name(this, "WorkflowBudgetExceededError");
|
|
1724
|
+
}
|
|
1725
|
+
name = "WorkflowBudgetExceededError";
|
|
1726
|
+
runId;
|
|
1727
|
+
budgetTotal;
|
|
1728
|
+
spent;
|
|
1729
|
+
constructor(runId, budgetTotal, spent) {
|
|
1730
|
+
super(
|
|
1731
|
+
`Workflow ${runId} exceeded the token budget (${spent} / ${budgetTotal} output tokens spent).`
|
|
1732
|
+
);
|
|
1733
|
+
this.runId = runId;
|
|
1734
|
+
this.budgetTotal = budgetTotal;
|
|
1735
|
+
this.spent = spent;
|
|
1736
|
+
}
|
|
1737
|
+
};
|
|
1738
|
+
|
|
1615
1739
|
// packages/core/src/agents/runtime/workflow-saved.ts
|
|
1616
1740
|
init_esbuild_shims();
|
|
1617
1741
|
import { promises as fs } from "node:fs";
|
|
1618
1742
|
import * as path from "node:path";
|
|
1619
|
-
var
|
|
1743
|
+
var debugLogger3 = createDebugLogger("WORKFLOW_SAVED");
|
|
1620
1744
|
var WORKFLOW_NAME_PATTERN = /^[a-z][a-z0-9-]{0,40}$/;
|
|
1621
1745
|
function validateWorkflowName(name) {
|
|
1622
1746
|
if (!name) return "Workflow name is required.";
|
|
@@ -1646,7 +1770,7 @@ async function isSymlinkedRoot(dir) {
|
|
|
1646
1770
|
__name(isSymlinkedRoot, "isSymlinkedRoot");
|
|
1647
1771
|
async function listJsFiles(dir) {
|
|
1648
1772
|
if (await isSymlinkedRoot(dir)) {
|
|
1649
|
-
|
|
1773
|
+
debugLogger3.warn(`refusing symlinked saved-workflow dir: ${dir}`);
|
|
1650
1774
|
return [];
|
|
1651
1775
|
}
|
|
1652
1776
|
try {
|
|
@@ -1662,7 +1786,7 @@ async function listJsFiles(dir) {
|
|
|
1662
1786
|
} catch (e) {
|
|
1663
1787
|
const code = e?.code;
|
|
1664
1788
|
if (code !== "ENOENT") {
|
|
1665
|
-
|
|
1789
|
+
debugLogger3.warn(`listJsFiles failed for ${dir}: ${e}`);
|
|
1666
1790
|
}
|
|
1667
1791
|
return [];
|
|
1668
1792
|
}
|
|
@@ -1809,7 +1933,7 @@ __name(saveWorkflowScript, "saveWorkflowScript");
|
|
|
1809
1933
|
var INLINE_RUN_ID_PATTERN = /^wf_[0-9a-f]+$/;
|
|
1810
1934
|
async function persistInlineWorkflowScript(config, runId, script) {
|
|
1811
1935
|
if (!INLINE_RUN_ID_PATTERN.test(runId)) {
|
|
1812
|
-
|
|
1936
|
+
debugLogger3.warn(`refusing to persist a script for run id: ${runId}`);
|
|
1813
1937
|
return null;
|
|
1814
1938
|
}
|
|
1815
1939
|
const storage = config.storage;
|
|
@@ -1818,7 +1942,7 @@ async function persistInlineWorkflowScript(config, runId, script) {
|
|
|
1818
1942
|
const filePath = storage.getInlineWorkflowScriptPath(runId);
|
|
1819
1943
|
const dir = path.dirname(filePath);
|
|
1820
1944
|
if (await isSymlinkedRoot(storage.getGeneratedWorkflowsDir()) || await isSymlinkedRoot(dir)) {
|
|
1821
|
-
|
|
1945
|
+
debugLogger3.warn(
|
|
1822
1946
|
`refusing to persist an inline workflow script into a symlinked root: '${dir}'.`
|
|
1823
1947
|
);
|
|
1824
1948
|
return null;
|
|
@@ -1832,7 +1956,7 @@ async function persistInlineWorkflowScript(config, runId, script) {
|
|
|
1832
1956
|
});
|
|
1833
1957
|
return filePath;
|
|
1834
1958
|
} catch (error) {
|
|
1835
|
-
|
|
1959
|
+
debugLogger3.warn(
|
|
1836
1960
|
`failed to persist inline workflow script for ${runId}: ${error}`
|
|
1837
1961
|
);
|
|
1838
1962
|
return null;
|
|
@@ -1847,7 +1971,7 @@ async function deleteInlineWorkflowScript(config, runId) {
|
|
|
1847
1971
|
await fs.rm(storage.getInlineWorkflowScriptPath(runId), { force: true });
|
|
1848
1972
|
return true;
|
|
1849
1973
|
} catch (error) {
|
|
1850
|
-
|
|
1974
|
+
debugLogger3.warn(
|
|
1851
1975
|
`failed to delete inline workflow script for ${runId}: ${error}`
|
|
1852
1976
|
);
|
|
1853
1977
|
return false;
|
|
@@ -1855,160 +1979,1774 @@ async function deleteInlineWorkflowScript(config, runId) {
|
|
|
1855
1979
|
}
|
|
1856
1980
|
__name(deleteInlineWorkflowScript, "deleteInlineWorkflowScript");
|
|
1857
1981
|
|
|
1858
|
-
// packages/core/src/agents/workflow-
|
|
1982
|
+
// packages/core/src/agents/runtime/workflow-orchestrator.ts
|
|
1859
1983
|
init_esbuild_shims();
|
|
1860
|
-
import {
|
|
1861
|
-
import
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1984
|
+
import { randomBytes } from "node:crypto";
|
|
1985
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
1986
|
+
import * as os from "node:os";
|
|
1987
|
+
|
|
1988
|
+
// packages/core/src/agents/runtime/workflow-agent-failure.ts
|
|
1989
|
+
init_esbuild_shims();
|
|
1990
|
+
var WorkflowAgentFailedError = class extends Error {
|
|
1991
|
+
static {
|
|
1992
|
+
__name(this, "WorkflowAgentFailedError");
|
|
1993
|
+
}
|
|
1994
|
+
name = "WorkflowAgentFailedError";
|
|
1995
|
+
kind;
|
|
1996
|
+
terminateMode;
|
|
1997
|
+
constructor(message, kind, terminateMode) {
|
|
1998
|
+
super(message);
|
|
1999
|
+
this.kind = kind;
|
|
2000
|
+
this.terminateMode = terminateMode;
|
|
1867
2001
|
}
|
|
2002
|
+
};
|
|
2003
|
+
function isWorkflowAgentFailedError(error) {
|
|
2004
|
+
return typeof error === "object" && error !== null && error.name === "WorkflowAgentFailedError";
|
|
2005
|
+
}
|
|
2006
|
+
__name(isWorkflowAgentFailedError, "isWorkflowAgentFailedError");
|
|
2007
|
+
var WorkflowAgentCapExceededError = class extends Error {
|
|
2008
|
+
static {
|
|
2009
|
+
__name(this, "WorkflowAgentCapExceededError");
|
|
2010
|
+
}
|
|
2011
|
+
name = "WorkflowAgentCapExceededError";
|
|
2012
|
+
constructor(maxAgents) {
|
|
2013
|
+
super(
|
|
2014
|
+
`Workflow exceeded the maximum of ${maxAgents} agent() calls per run.`
|
|
2015
|
+
);
|
|
2016
|
+
}
|
|
2017
|
+
};
|
|
2018
|
+
function isWorkflowRunLevelError(error) {
|
|
2019
|
+
if (typeof error !== "object" || error === null) return false;
|
|
2020
|
+
const name = error.name;
|
|
2021
|
+
return name === "WorkflowBudgetExceededError" || name === "WorkflowAgentCapExceededError";
|
|
2022
|
+
}
|
|
2023
|
+
__name(isWorkflowRunLevelError, "isWorkflowRunLevelError");
|
|
2024
|
+
var WORKFLOW_ABORT_REASON_STALLED = "stalled";
|
|
2025
|
+
|
|
2026
|
+
// packages/core/src/agents/runtime/workflow-stall.ts
|
|
2027
|
+
init_esbuild_shims();
|
|
2028
|
+
var DEFAULT_STALL_MS = 18e4;
|
|
2029
|
+
var MAX_STALL_ATTEMPTS = 3;
|
|
2030
|
+
var MAX_WORKFLOW_STALL_MS_ENV = "QWEN_CODE_WORKFLOW_STALL_SECONDS";
|
|
2031
|
+
function resolveStallMs(perCall, env = process.env) {
|
|
2032
|
+
if (typeof perCall === "number" && Number.isFinite(perCall)) {
|
|
2033
|
+
if (perCall === 0) return 0;
|
|
2034
|
+
if (perCall > 0) return perCall;
|
|
2035
|
+
}
|
|
2036
|
+
const raw = env[MAX_WORKFLOW_STALL_MS_ENV];
|
|
2037
|
+
const trimmed = raw?.trim();
|
|
2038
|
+
if (trimmed) {
|
|
2039
|
+
if (trimmed === "0") return 0;
|
|
2040
|
+
const sec = parsePositiveIntegerEnv(trimmed, 0);
|
|
2041
|
+
if (sec > 0) return sec * 1e3;
|
|
2042
|
+
}
|
|
2043
|
+
return DEFAULT_STALL_MS;
|
|
2044
|
+
}
|
|
2045
|
+
__name(resolveStallMs, "resolveStallMs");
|
|
2046
|
+
var debugLogger4 = createDebugLogger("WORKFLOW_STALL");
|
|
2047
|
+
function attachStallWatchdog(emitter, controller, stallMs) {
|
|
2048
|
+
if (stallMs <= 0) {
|
|
2049
|
+
return { stalled: /* @__PURE__ */ __name(() => false, "stalled"), dispose: /* @__PURE__ */ __name(() => {
|
|
2050
|
+
}, "dispose") };
|
|
2051
|
+
}
|
|
2052
|
+
let inFlightTools = 0;
|
|
2053
|
+
let fired = false;
|
|
2054
|
+
let timer;
|
|
2055
|
+
let disposed = false;
|
|
2056
|
+
const clear = /* @__PURE__ */ __name(() => {
|
|
2057
|
+
if (timer) {
|
|
2058
|
+
clearTimeout(timer);
|
|
2059
|
+
timer = void 0;
|
|
2060
|
+
}
|
|
2061
|
+
}, "clear");
|
|
2062
|
+
const arm = /* @__PURE__ */ __name(() => {
|
|
2063
|
+
clear();
|
|
2064
|
+
if (disposed || fired) return;
|
|
2065
|
+
if (inFlightTools > 0) return;
|
|
2066
|
+
timer = setTimeout(() => {
|
|
2067
|
+
if (disposed || fired) return;
|
|
2068
|
+
fired = true;
|
|
2069
|
+
debugLogger4.warn(
|
|
2070
|
+
`[Workflow] agent dispatch stalled \u2014 no progress for ${stallMs}ms; aborting.`
|
|
2071
|
+
);
|
|
2072
|
+
try {
|
|
2073
|
+
controller.abort(WORKFLOW_ABORT_REASON_STALLED);
|
|
2074
|
+
} catch (e) {
|
|
2075
|
+
debugLogger4.warn("stall watchdog abort threw:", e);
|
|
2076
|
+
}
|
|
2077
|
+
}, stallMs);
|
|
2078
|
+
if (typeof timer.unref === "function") {
|
|
2079
|
+
timer.unref();
|
|
2080
|
+
}
|
|
2081
|
+
}, "arm");
|
|
2082
|
+
const onActivity = /* @__PURE__ */ __name(() => arm(), "onActivity");
|
|
2083
|
+
const onToolCall = /* @__PURE__ */ __name(() => {
|
|
2084
|
+
inFlightTools += 1;
|
|
2085
|
+
clear();
|
|
2086
|
+
}, "onToolCall");
|
|
2087
|
+
const onToolResult = /* @__PURE__ */ __name(() => {
|
|
2088
|
+
inFlightTools = Math.max(0, inFlightTools - 1);
|
|
2089
|
+
arm();
|
|
2090
|
+
}, "onToolResult");
|
|
2091
|
+
emitter.on("round_start" /* ROUND_START */, onActivity);
|
|
2092
|
+
emitter.on("round_end" /* ROUND_END */, onActivity);
|
|
2093
|
+
emitter.on("stream_text" /* STREAM_TEXT */, onActivity);
|
|
2094
|
+
emitter.on("usage_metadata" /* USAGE_METADATA */, onActivity);
|
|
2095
|
+
emitter.on("tool_call" /* TOOL_CALL */, onToolCall);
|
|
2096
|
+
emitter.on("tool_result" /* TOOL_RESULT */, onToolResult);
|
|
1868
2097
|
return {
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
dispatches: task.dispatches.map((dispatch) => ({
|
|
1882
|
-
...dispatch,
|
|
1883
|
-
dependsOn: [...dispatch.dependsOn]
|
|
1884
|
-
})),
|
|
1885
|
-
agentsDispatched: task.agentsDispatched,
|
|
1886
|
-
agentsCompleted: task.agentsCompleted,
|
|
1887
|
-
agentsRespawned: task.agentsRespawned ?? 0,
|
|
1888
|
-
tokensSpent: task.tokensSpent,
|
|
1889
|
-
tokenBudgetTotal: task.tokenBudgetTotal,
|
|
1890
|
-
perPhaseTokens: Array.from(task.perPhaseTokens.entries()),
|
|
1891
|
-
recentLogs: [...task.recentLogs],
|
|
1892
|
-
events: task.events.map((event) => ({ ...event })),
|
|
1893
|
-
startTime: task.startTime,
|
|
1894
|
-
endTime: task.endTime,
|
|
1895
|
-
result: safeResult(task.result),
|
|
1896
|
-
error: task.error
|
|
2098
|
+
stalled: /* @__PURE__ */ __name(() => fired, "stalled"),
|
|
2099
|
+
dispose: /* @__PURE__ */ __name(() => {
|
|
2100
|
+
if (disposed) return;
|
|
2101
|
+
disposed = true;
|
|
2102
|
+
clear();
|
|
2103
|
+
emitter.off("round_start" /* ROUND_START */, onActivity);
|
|
2104
|
+
emitter.off("round_end" /* ROUND_END */, onActivity);
|
|
2105
|
+
emitter.off("stream_text" /* STREAM_TEXT */, onActivity);
|
|
2106
|
+
emitter.off("usage_metadata" /* USAGE_METADATA */, onActivity);
|
|
2107
|
+
emitter.off("tool_call" /* TOOL_CALL */, onToolCall);
|
|
2108
|
+
emitter.off("tool_result" /* TOOL_RESULT */, onToolResult);
|
|
2109
|
+
}, "dispose")
|
|
1897
2110
|
};
|
|
1898
2111
|
}
|
|
1899
|
-
__name(
|
|
1900
|
-
function
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
return
|
|
1905
|
-
}
|
|
1906
|
-
|
|
2112
|
+
__name(attachStallWatchdog, "attachStallWatchdog");
|
|
2113
|
+
async function runStallResilient(attemptFn, opts) {
|
|
2114
|
+
const { stallMs, signal, label } = opts;
|
|
2115
|
+
if (stallMs <= 0) {
|
|
2116
|
+
const emitter = new AgentEventEmitter();
|
|
2117
|
+
return attemptFn(signal ?? new AbortController().signal, emitter);
|
|
2118
|
+
}
|
|
2119
|
+
let attempt = 0;
|
|
2120
|
+
for (; ; ) {
|
|
2121
|
+
attempt += 1;
|
|
2122
|
+
const controller = new AbortController();
|
|
2123
|
+
let onParentAbort;
|
|
2124
|
+
if (signal) {
|
|
2125
|
+
if (signal.aborted) {
|
|
2126
|
+
controller.abort(signal.reason);
|
|
2127
|
+
} else {
|
|
2128
|
+
onParentAbort = /* @__PURE__ */ __name(() => controller.abort(signal.reason), "onParentAbort");
|
|
2129
|
+
signal.addEventListener("abort", onParentAbort);
|
|
2130
|
+
}
|
|
2131
|
+
}
|
|
2132
|
+
const emitter = new AgentEventEmitter();
|
|
2133
|
+
const watchdog = attachStallWatchdog(emitter, controller, stallMs);
|
|
2134
|
+
try {
|
|
2135
|
+
return await attemptFn(controller.signal, emitter);
|
|
2136
|
+
} catch (err) {
|
|
2137
|
+
if (signal?.aborted) throw err;
|
|
2138
|
+
if (watchdog.stalled() && attempt < MAX_STALL_ATTEMPTS) {
|
|
2139
|
+
debugLogger4.warn(
|
|
2140
|
+
`[Workflow] agent "${label ?? "workflow-agent"}" stalled (attempt ${attempt}/${MAX_STALL_ATTEMPTS}) \u2014 retrying.`
|
|
2141
|
+
);
|
|
2142
|
+
continue;
|
|
2143
|
+
}
|
|
2144
|
+
if (watchdog.stalled()) {
|
|
2145
|
+
throw new WorkflowAgentFailedError(
|
|
2146
|
+
`agent "${label ?? "workflow-agent"}" stalled on all ${MAX_STALL_ATTEMPTS} attempts (no progress for ${stallMs}ms each).`,
|
|
2147
|
+
"stalled"
|
|
2148
|
+
);
|
|
2149
|
+
}
|
|
2150
|
+
throw err;
|
|
2151
|
+
} finally {
|
|
2152
|
+
watchdog.dispose();
|
|
2153
|
+
if (onParentAbort && signal) {
|
|
2154
|
+
signal.removeEventListener("abort", onParentAbort);
|
|
2155
|
+
}
|
|
2156
|
+
}
|
|
1907
2157
|
}
|
|
1908
2158
|
}
|
|
1909
|
-
__name(
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
2159
|
+
__name(runStallResilient, "runStallResilient");
|
|
2160
|
+
|
|
2161
|
+
// packages/core/src/agents/runtime/workflow-journal.ts
|
|
2162
|
+
init_esbuild_shims();
|
|
2163
|
+
import { createHash } from "node:crypto";
|
|
2164
|
+
import { constants, promises as fs2 } from "node:fs";
|
|
2165
|
+
import path2 from "node:path";
|
|
2166
|
+
var debugLogger5 = createDebugLogger("WORKFLOW_JOURNAL");
|
|
2167
|
+
var JOURNAL_KEY_VERSION = "v2";
|
|
2168
|
+
function canonicalizeAgentOpts(opts) {
|
|
2169
|
+
const projected = {};
|
|
2170
|
+
for (const k of [
|
|
2171
|
+
"schema",
|
|
2172
|
+
"model",
|
|
2173
|
+
"isolation",
|
|
2174
|
+
"agentType",
|
|
2175
|
+
"workingDir"
|
|
2176
|
+
]) {
|
|
2177
|
+
const v = opts[k];
|
|
2178
|
+
if (v === void 0 || typeof v === "function") continue;
|
|
2179
|
+
projected[k] = v;
|
|
2180
|
+
}
|
|
2181
|
+
const sortDeep = /* @__PURE__ */ __name((val) => {
|
|
2182
|
+
if (typeof val === "function") return void 0;
|
|
2183
|
+
if (Array.isArray(val)) return val.map(sortDeep);
|
|
2184
|
+
if (val && typeof val === "object") {
|
|
2185
|
+
const out = {};
|
|
2186
|
+
for (const key of Object.keys(val).sort()) {
|
|
2187
|
+
if (key === "__proto__") continue;
|
|
2188
|
+
out[key] = sortDeep(val[key]);
|
|
2189
|
+
}
|
|
2190
|
+
return out;
|
|
2191
|
+
}
|
|
2192
|
+
return val;
|
|
2193
|
+
}, "sortDeep");
|
|
1913
2194
|
try {
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
await fs2.writeFile(
|
|
1918
|
-
storage.getWorkflowRunSnapshotPath(task.runId),
|
|
1919
|
-
JSON.stringify(snapshot, null, 2),
|
|
1920
|
-
"utf8"
|
|
1921
|
-
);
|
|
1922
|
-
await pruneSnapshots(config, dir);
|
|
1923
|
-
return true;
|
|
1924
|
-
} catch (e) {
|
|
1925
|
-
debugLogger3.warn(`writeWorkflowSnapshot failed for ${task.runId}: ${e}`);
|
|
1926
|
-
return false;
|
|
2195
|
+
return JSON.stringify(sortDeep(projected));
|
|
2196
|
+
} catch {
|
|
2197
|
+
return "{}";
|
|
1927
2198
|
}
|
|
1928
2199
|
}
|
|
1929
|
-
__name(
|
|
1930
|
-
|
|
1931
|
-
const
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
2200
|
+
__name(canonicalizeAgentOpts, "canonicalizeAgentOpts");
|
|
2201
|
+
function deriveAgentKey(prefixHash, prompt, opts) {
|
|
2202
|
+
const hash = createHash("sha256");
|
|
2203
|
+
hash.update(prefixHash);
|
|
2204
|
+
hash.update("\0");
|
|
2205
|
+
hash.update(prompt);
|
|
2206
|
+
hash.update("\0");
|
|
2207
|
+
hash.update(canonicalizeAgentOpts(opts));
|
|
2208
|
+
return `${JOURNAL_KEY_VERSION}:${hash.digest("hex")}`;
|
|
2209
|
+
}
|
|
2210
|
+
__name(deriveAgentKey, "deriveAgentKey");
|
|
2211
|
+
function deriveArgsSeed(args) {
|
|
2212
|
+
const hash = createHash("sha256");
|
|
2213
|
+
let serialized;
|
|
1935
2214
|
try {
|
|
1936
|
-
|
|
2215
|
+
serialized = JSON.stringify(args ?? null) ?? "null";
|
|
1937
2216
|
} catch {
|
|
1938
|
-
|
|
2217
|
+
serialized = "non-serializable-args";
|
|
1939
2218
|
}
|
|
1940
|
-
|
|
1941
|
-
|
|
2219
|
+
hash.update(serialized);
|
|
2220
|
+
return `${JOURNAL_KEY_VERSION}:${hash.digest("hex")}`;
|
|
2221
|
+
}
|
|
2222
|
+
__name(deriveArgsSeed, "deriveArgsSeed");
|
|
2223
|
+
function buildReplay(entries) {
|
|
2224
|
+
const results = /* @__PURE__ */ new Map();
|
|
2225
|
+
const started = /* @__PURE__ */ new Map();
|
|
2226
|
+
const failed = /* @__PURE__ */ new Set();
|
|
2227
|
+
for (const e of entries) {
|
|
2228
|
+
if (e.type === "result") {
|
|
2229
|
+
results.set(e.key, e);
|
|
2230
|
+
} else if (e.type === "started") {
|
|
2231
|
+
failed.delete(e.key);
|
|
2232
|
+
const list = started.get(e.key);
|
|
2233
|
+
if (list) list.push(e);
|
|
2234
|
+
else started.set(e.key, [e]);
|
|
2235
|
+
} else if (e.type === "failed") {
|
|
2236
|
+
failed.add(e.key);
|
|
2237
|
+
}
|
|
2238
|
+
}
|
|
2239
|
+
return { results, started, failed };
|
|
2240
|
+
}
|
|
2241
|
+
__name(buildReplay, "buildReplay");
|
|
2242
|
+
var WorkflowJournal = class {
|
|
2243
|
+
constructor(journalPath, root = path2.dirname(path2.dirname(journalPath))) {
|
|
2244
|
+
this.root = root;
|
|
2245
|
+
this.path = journalPath;
|
|
2246
|
+
}
|
|
2247
|
+
static {
|
|
2248
|
+
__name(this, "WorkflowJournal");
|
|
2249
|
+
}
|
|
2250
|
+
pending = Promise.resolve();
|
|
2251
|
+
path;
|
|
2252
|
+
async hasSymlinkedPath() {
|
|
2253
|
+
if (await isSymlinkedRoot(this.root) || await isSymlinkedRoot(path2.dirname(this.path))) {
|
|
2254
|
+
return true;
|
|
2255
|
+
}
|
|
2256
|
+
return fs2.lstat(this.path).then((stat) => stat.isSymbolicLink()).catch(() => false);
|
|
2257
|
+
}
|
|
2258
|
+
/** Ensure the advertised journal path exists without affecting the run. */
|
|
2259
|
+
async ensureExists() {
|
|
1942
2260
|
try {
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
if (
|
|
1946
|
-
|
|
1947
|
-
|
|
2261
|
+
if (await this.hasSymlinkedPath()) return false;
|
|
2262
|
+
await fs2.mkdir(path2.dirname(this.path), { recursive: true });
|
|
2263
|
+
if (await this.hasSymlinkedPath()) return false;
|
|
2264
|
+
const noFollow = process.platform === "win32" ? 0 : constants.O_NOFOLLOW;
|
|
2265
|
+
const file = await fs2.open(
|
|
2266
|
+
this.path,
|
|
2267
|
+
constants.O_APPEND | constants.O_CREAT | constants.O_WRONLY | noFollow,
|
|
2268
|
+
384
|
|
2269
|
+
);
|
|
2270
|
+
try {
|
|
2271
|
+
await file.chmod(384);
|
|
2272
|
+
} finally {
|
|
2273
|
+
await file.close();
|
|
1948
2274
|
}
|
|
1949
|
-
|
|
2275
|
+
return true;
|
|
2276
|
+
} catch (error) {
|
|
2277
|
+
debugLogger5.warn(
|
|
2278
|
+
`WorkflowJournal.ensureExists failed for ${this.path}: ${error}`
|
|
2279
|
+
);
|
|
2280
|
+
return false;
|
|
2281
|
+
}
|
|
2282
|
+
}
|
|
2283
|
+
/** Remove a never-registered run's journal file, best-effort. */
|
|
2284
|
+
async remove() {
|
|
2285
|
+
try {
|
|
2286
|
+
if (await this.hasSymlinkedPath()) return;
|
|
2287
|
+
await fs2.rm(this.path, { force: true });
|
|
2288
|
+
await fs2.rmdir(path2.dirname(this.path)).catch((error) => {
|
|
2289
|
+
const code = error.code;
|
|
2290
|
+
if (code !== "ENOENT" && code !== "ENOTEMPTY") throw error;
|
|
2291
|
+
});
|
|
2292
|
+
} catch (error) {
|
|
2293
|
+
debugLogger5.warn(
|
|
2294
|
+
`WorkflowJournal.remove failed for ${this.path}: ${error}`
|
|
2295
|
+
);
|
|
2296
|
+
}
|
|
2297
|
+
}
|
|
2298
|
+
/** Load + parse all entries into replay maps. Empty maps if no file. */
|
|
2299
|
+
async load() {
|
|
2300
|
+
try {
|
|
2301
|
+
const entries = await read(this.path);
|
|
2302
|
+
return buildReplay(entries);
|
|
1950
2303
|
} catch (e) {
|
|
1951
|
-
|
|
2304
|
+
debugLogger5.warn(`WorkflowJournal.load failed for ${this.path}: ${e}`);
|
|
2305
|
+
return { results: /* @__PURE__ */ new Map(), started: /* @__PURE__ */ new Map(), failed: /* @__PURE__ */ new Set() };
|
|
1952
2306
|
}
|
|
1953
2307
|
}
|
|
1954
|
-
|
|
1955
|
-
|
|
2308
|
+
/** Append one entry. Rejects only on I/O error (callers `.catch`). */
|
|
2309
|
+
append(entry) {
|
|
2310
|
+
const operation = this.pending.then(() => writeLine(this.path, entry));
|
|
2311
|
+
this.pending = operation.catch(() => void 0);
|
|
2312
|
+
return operation;
|
|
2313
|
+
}
|
|
2314
|
+
/** Wait until every append issued so far has settled. */
|
|
2315
|
+
drain() {
|
|
2316
|
+
return this.pending;
|
|
2317
|
+
}
|
|
2318
|
+
};
|
|
2319
|
+
|
|
2320
|
+
// packages/core/src/agents/runtime/workflow-prompts.ts
|
|
2321
|
+
init_esbuild_shims();
|
|
2322
|
+
var WORKFLOW_SUBAGENT_SYSTEM_PROMPT = 'You are a subagent spawned by a workflow orchestration script. Use the tools available to complete the task.\nCRITICAL: Your final text response is returned **verbatim** as a string to the calling script \u2014 it is your return value, not a message to a human.\n- Output the literal result (data, JSON, text). Do NOT output confirmations like "Done." or "Sent."\n- If asked for JSON, return ONLY the raw JSON \u2014 no code fences, no prose, no markdown.\n- Do NOT use SendUserMessage to deliver your answer. Put your answer in your final text response.\n- Be concise. The script will parse your output.';
|
|
2323
|
+
var WORKFLOW_SUBAGENT_SYSTEM_PROMPT_WITH_SCHEMA = "You are a subagent spawned by a workflow orchestration script. Use the tools available to complete the task.\nCRITICAL: You MUST deliver your final answer by calling the `structured_output` tool with arguments that conform to its parameter schema. Plain-text final answers are DISCARDED \u2014 only a valid `structured_output` call returns a result to the calling script.\n- Use other tools (Read, Grep, etc.) to gather information first.\n- When ready, call `structured_output` ONCE with the conforming JSON object.\n- If validation fails, the error tells you what to fix. Try again with corrected fields.\n- After two failed attempts, the run terminates \u2014 get the arguments right.\n- Do NOT use SendUserMessage to deliver your answer.\n- Be concise; the script reads only the structured payload, not your prose.";
|
|
2324
|
+
|
|
2325
|
+
// packages/core/src/agents/runtime/workflow-dispatch-scheduler.ts
|
|
2326
|
+
init_esbuild_shims();
|
|
2327
|
+
function abortError() {
|
|
2328
|
+
return new DOMException("Workflow dispatch scheduler aborted.", "AbortError");
|
|
1956
2329
|
}
|
|
1957
|
-
__name(
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
2330
|
+
__name(abortError, "abortError");
|
|
2331
|
+
var WorkflowDispatchScheduler = class {
|
|
2332
|
+
constructor(limit, signal, onStateChange) {
|
|
2333
|
+
this.limit = limit;
|
|
2334
|
+
this.signal = signal;
|
|
2335
|
+
if (!Number.isInteger(limit) || limit < 1) {
|
|
2336
|
+
throw new Error(
|
|
2337
|
+
`Workflow dispatch limit must be a positive integer, got ${String(limit)}.`
|
|
2338
|
+
);
|
|
2339
|
+
}
|
|
2340
|
+
if (onStateChange) this.stateListeners.add(onStateChange);
|
|
2341
|
+
if (signal && !signal.aborted) {
|
|
2342
|
+
signal.addEventListener("abort", () => this.abortPending(), {
|
|
2343
|
+
once: true
|
|
2344
|
+
});
|
|
2345
|
+
}
|
|
2346
|
+
}
|
|
2347
|
+
static {
|
|
2348
|
+
__name(this, "WorkflowDispatchScheduler");
|
|
2349
|
+
}
|
|
2350
|
+
state = "running";
|
|
2351
|
+
inFlight = 0;
|
|
2352
|
+
queue = [];
|
|
2353
|
+
gateWaiters = [];
|
|
2354
|
+
stateListeners = /* @__PURE__ */ new Set();
|
|
2355
|
+
/**
|
|
2356
|
+
* Subscribe to state transitions. Returns an unsubscribe function.
|
|
2357
|
+
* The constructor callback (when given) is registered as the first
|
|
2358
|
+
* listener; this method lets additional observers — e.g. the sandbox's
|
|
2359
|
+
* pause-aware wall-clock watchdog — hook the same transitions.
|
|
2360
|
+
*/
|
|
2361
|
+
onStateChange(listener) {
|
|
2362
|
+
this.stateListeners.add(listener);
|
|
2363
|
+
return () => {
|
|
2364
|
+
this.stateListeners.delete(listener);
|
|
2365
|
+
};
|
|
2366
|
+
}
|
|
2367
|
+
run(thunk) {
|
|
2368
|
+
return new Promise((resolve2, reject) => {
|
|
2369
|
+
if (this.signal?.aborted) {
|
|
2370
|
+
reject(abortError());
|
|
2371
|
+
return;
|
|
2372
|
+
}
|
|
2373
|
+
this.queue.push({
|
|
2374
|
+
thunk,
|
|
2375
|
+
resolve: resolve2,
|
|
2376
|
+
reject
|
|
2377
|
+
});
|
|
2378
|
+
this.pump();
|
|
1965
2379
|
});
|
|
1966
|
-
} catch (error) {
|
|
1967
|
-
debugLogger3.warn(`delete workflow journal failed for ${runId}: ${error}`);
|
|
1968
|
-
return false;
|
|
1969
2380
|
}
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
2381
|
+
pause() {
|
|
2382
|
+
if (this.state !== "running" || this.signal?.aborted) return false;
|
|
2383
|
+
this.setState("pausing");
|
|
2384
|
+
if (this.inFlight === 0) this.setState("paused");
|
|
2385
|
+
return true;
|
|
2386
|
+
}
|
|
2387
|
+
resume() {
|
|
2388
|
+
if (this.state !== "paused" || this.signal?.aborted) return false;
|
|
2389
|
+
this.setState("running");
|
|
2390
|
+
while (this.gateWaiters.length > 0) {
|
|
2391
|
+
this.gateWaiters.shift().resolve();
|
|
1977
2392
|
}
|
|
2393
|
+
this.pump();
|
|
2394
|
+
return true;
|
|
1978
2395
|
}
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
2396
|
+
waitUntilRunning() {
|
|
2397
|
+
if (this.signal?.aborted) return Promise.reject(abortError());
|
|
2398
|
+
if (this.state === "running") return Promise.resolve();
|
|
2399
|
+
return new Promise((resolve2, reject) => {
|
|
2400
|
+
this.gateWaiters.push({ resolve: resolve2, reject });
|
|
2401
|
+
});
|
|
2402
|
+
}
|
|
2403
|
+
snapshot() {
|
|
2404
|
+
return {
|
|
2405
|
+
state: this.state,
|
|
2406
|
+
queued: this.queue.length,
|
|
2407
|
+
inFlight: this.inFlight
|
|
2408
|
+
};
|
|
2409
|
+
}
|
|
2410
|
+
pump() {
|
|
2411
|
+
while (this.state === "running" && this.inFlight < this.limit && this.queue.length > 0) {
|
|
2412
|
+
const job = this.queue.shift();
|
|
2413
|
+
if (this.signal?.aborted) {
|
|
2414
|
+
job.reject(abortError());
|
|
2415
|
+
continue;
|
|
2416
|
+
}
|
|
2417
|
+
this.inFlight++;
|
|
2418
|
+
Promise.resolve().then(job.thunk).then(job.resolve, job.reject).finally(() => {
|
|
2419
|
+
this.inFlight--;
|
|
2420
|
+
if (this.state === "pausing" && this.inFlight === 0) {
|
|
2421
|
+
this.setState("paused");
|
|
2422
|
+
}
|
|
2423
|
+
this.pump();
|
|
2424
|
+
});
|
|
2425
|
+
}
|
|
2426
|
+
}
|
|
2427
|
+
setState(state) {
|
|
2428
|
+
if (this.state === state) return;
|
|
2429
|
+
this.state = state;
|
|
2430
|
+
const snapshot = this.snapshot();
|
|
2431
|
+
for (const listener of [...this.stateListeners]) listener(snapshot);
|
|
2432
|
+
}
|
|
2433
|
+
abortPending() {
|
|
2434
|
+
const error = abortError();
|
|
2435
|
+
while (this.queue.length > 0) this.queue.shift().reject(error);
|
|
2436
|
+
while (this.gateWaiters.length > 0) {
|
|
2437
|
+
this.gateWaiters.shift().reject(error);
|
|
2438
|
+
}
|
|
2439
|
+
}
|
|
2440
|
+
};
|
|
2441
|
+
|
|
2442
|
+
// packages/core/src/agents/runtime/workflow-orchestrator.ts
|
|
2443
|
+
var DEFAULT_MAX_AGENTS_PER_RUN = 1e3;
|
|
2444
|
+
var MAX_WORKFLOW_AGENTS_ENV = "QWEN_CODE_MAX_WORKFLOW_AGENTS";
|
|
2445
|
+
var HARD_MAX_AGENTS_PER_RUN_CEILING = 1e4;
|
|
2446
|
+
function resolveMaxAgentsPerRun(env = process.env) {
|
|
2447
|
+
const raw = env[MAX_WORKFLOW_AGENTS_ENV];
|
|
2448
|
+
if (raw === void 0 || raw.trim() === "") {
|
|
2449
|
+
return DEFAULT_MAX_AGENTS_PER_RUN;
|
|
2450
|
+
}
|
|
2451
|
+
const parsed = parsePositiveIntegerEnv(raw, 0);
|
|
2452
|
+
if (parsed < 1) {
|
|
2453
|
+
debugLogger.warn(
|
|
2454
|
+
`Invalid ${MAX_WORKFLOW_AGENTS_ENV}=${JSON.stringify(raw)}, using default (${DEFAULT_MAX_AGENTS_PER_RUN})`
|
|
2455
|
+
);
|
|
2456
|
+
return DEFAULT_MAX_AGENTS_PER_RUN;
|
|
2457
|
+
}
|
|
2458
|
+
if (parsed > HARD_MAX_AGENTS_PER_RUN_CEILING) {
|
|
2459
|
+
debugLogger.warn(
|
|
2460
|
+
`${MAX_WORKFLOW_AGENTS_ENV}=${parsed} exceeds hard ceiling (${HARD_MAX_AGENTS_PER_RUN_CEILING}); clamping.`
|
|
2461
|
+
);
|
|
2462
|
+
return HARD_MAX_AGENTS_PER_RUN_CEILING;
|
|
2463
|
+
}
|
|
2464
|
+
return parsed;
|
|
1984
2465
|
}
|
|
1985
|
-
__name(
|
|
1986
|
-
|
|
1987
|
-
|
|
2466
|
+
__name(resolveMaxAgentsPerRun, "resolveMaxAgentsPerRun");
|
|
2467
|
+
var MAX_WORKFLOW_CONCURRENCY_ENV = "QWEN_CODE_MAX_WORKFLOW_CONCURRENCY";
|
|
2468
|
+
var HARD_MAX_CONCURRENCY_CEILING = 64;
|
|
2469
|
+
function resolveConcurrencyLimit(env = process.env, availableParallelism2 = os.availableParallelism) {
|
|
2470
|
+
const raw = env[MAX_WORKFLOW_CONCURRENCY_ENV];
|
|
2471
|
+
if (raw !== void 0 && raw.trim() !== "") {
|
|
2472
|
+
const parsed = parsePositiveIntegerEnv(raw, 0);
|
|
2473
|
+
if (parsed >= 1) {
|
|
2474
|
+
if (parsed > HARD_MAX_CONCURRENCY_CEILING) {
|
|
2475
|
+
debugLogger.warn(
|
|
2476
|
+
`${MAX_WORKFLOW_CONCURRENCY_ENV}=${parsed} exceeds hard ceiling (${HARD_MAX_CONCURRENCY_CEILING}); clamping.`
|
|
2477
|
+
);
|
|
2478
|
+
return HARD_MAX_CONCURRENCY_CEILING;
|
|
2479
|
+
}
|
|
2480
|
+
return parsed;
|
|
2481
|
+
}
|
|
2482
|
+
debugLogger.warn(
|
|
2483
|
+
`Invalid ${MAX_WORKFLOW_CONCURRENCY_ENV}=${JSON.stringify(raw)}, using cpu-derived default`
|
|
2484
|
+
);
|
|
2485
|
+
}
|
|
2486
|
+
return Math.max(2, Math.min(16, availableParallelism2() - 2));
|
|
1988
2487
|
}
|
|
1989
|
-
__name(
|
|
1990
|
-
|
|
1991
|
-
|
|
2488
|
+
__name(resolveConcurrencyLimit, "resolveConcurrencyLimit");
|
|
2489
|
+
var DEFAULT_WORKFLOW_SUBAGENT_MAX_TURNS = 50;
|
|
2490
|
+
var DEFAULT_WORKFLOW_SUBAGENT_MAX_TIME_MINUTES = 10;
|
|
2491
|
+
var WORKFLOW_SUBAGENT_MAX_TURNS_ENV = "QWEN_CODE_WORKFLOW_AGENT_MAX_TURNS";
|
|
2492
|
+
var WORKFLOW_SUBAGENT_MAX_MINUTES_ENV = "QWEN_CODE_WORKFLOW_AGENT_MAX_MINUTES";
|
|
2493
|
+
var HARD_WORKFLOW_SUBAGENT_MAX_TURNS_CEILING = 500;
|
|
2494
|
+
var HARD_WORKFLOW_SUBAGENT_MAX_MINUTES_CEILING = 100;
|
|
2495
|
+
function resolveSubagentBound(envName, defaultValue, ceiling, env) {
|
|
2496
|
+
const raw = env[envName];
|
|
2497
|
+
if (raw === void 0 || raw.trim() === "") return defaultValue;
|
|
2498
|
+
const parsed = parsePositiveIntegerEnv(raw, 0);
|
|
2499
|
+
if (parsed < 1) {
|
|
2500
|
+
debugLogger.warn(
|
|
2501
|
+
`Invalid ${envName}=${JSON.stringify(raw)}, using default (${defaultValue})`
|
|
2502
|
+
);
|
|
2503
|
+
return defaultValue;
|
|
2504
|
+
}
|
|
2505
|
+
if (parsed > ceiling) {
|
|
2506
|
+
debugLogger.warn(
|
|
2507
|
+
`${envName}=${parsed} exceeds hard ceiling (${ceiling}); clamping.`
|
|
2508
|
+
);
|
|
2509
|
+
return ceiling;
|
|
2510
|
+
}
|
|
2511
|
+
return parsed;
|
|
1992
2512
|
}
|
|
1993
|
-
__name(
|
|
1994
|
-
function
|
|
1995
|
-
return
|
|
2513
|
+
__name(resolveSubagentBound, "resolveSubagentBound");
|
|
2514
|
+
function resolveSubagentMaxTurns(env = process.env, defaultValue = DEFAULT_WORKFLOW_SUBAGENT_MAX_TURNS) {
|
|
2515
|
+
return resolveSubagentBound(
|
|
2516
|
+
WORKFLOW_SUBAGENT_MAX_TURNS_ENV,
|
|
2517
|
+
defaultValue,
|
|
2518
|
+
HARD_WORKFLOW_SUBAGENT_MAX_TURNS_CEILING,
|
|
2519
|
+
env
|
|
2520
|
+
);
|
|
1996
2521
|
}
|
|
1997
|
-
__name(
|
|
1998
|
-
function
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
const phases = value["phases"];
|
|
2005
|
-
return phases === void 0 || Array.isArray(phases) && phases.every(
|
|
2006
|
-
(phase) => isRecord(phase) && typeof phase["title"] === "string" && isOptionalString(phase["detail"]) && isOptionalString(phase["model"])
|
|
2522
|
+
__name(resolveSubagentMaxTurns, "resolveSubagentMaxTurns");
|
|
2523
|
+
function resolveSubagentMaxTimeMinutes(env = process.env, defaultValue = DEFAULT_WORKFLOW_SUBAGENT_MAX_TIME_MINUTES) {
|
|
2524
|
+
return resolveSubagentBound(
|
|
2525
|
+
WORKFLOW_SUBAGENT_MAX_MINUTES_ENV,
|
|
2526
|
+
defaultValue,
|
|
2527
|
+
HARD_WORKFLOW_SUBAGENT_MAX_MINUTES_CEILING,
|
|
2528
|
+
env
|
|
2007
2529
|
);
|
|
2008
2530
|
}
|
|
2009
|
-
__name(
|
|
2010
|
-
|
|
2011
|
-
|
|
2531
|
+
__name(resolveSubagentMaxTimeMinutes, "resolveSubagentMaxTimeMinutes");
|
|
2532
|
+
var WORKFLOW_SUBAGENT_DISALLOWED_TOOLS = [
|
|
2533
|
+
ToolNames.ASK_USER_QUESTION,
|
|
2534
|
+
ToolNames.SEND_MESSAGE,
|
|
2535
|
+
ToolNames.MONITOR,
|
|
2536
|
+
...SUBAGENT_PLAN_LIFECYCLE_TOOLS,
|
|
2537
|
+
// AgentTool: workflow subagents must not spawn sub-agents even where
|
|
2538
|
+
// maxSubagentDepth would permit nesting — a leaf-spawned agent would run
|
|
2539
|
+
// outside the orchestrator's concurrency cap, agent counter, and token
|
|
2540
|
+
// budget, and its result would bypass the script's return-value contract.
|
|
2541
|
+
// The WorkflowTool itself is already excluded from every subagent; this
|
|
2542
|
+
// closes the same loop for plain `agent` calls (review #6189).
|
|
2543
|
+
ToolNames.AGENT
|
|
2544
|
+
];
|
|
2545
|
+
var WorkflowExecutionError = class extends Error {
|
|
2546
|
+
constructor(message, phases, logs, meta = null) {
|
|
2547
|
+
super(message);
|
|
2548
|
+
this.phases = phases;
|
|
2549
|
+
this.logs = logs;
|
|
2550
|
+
this.meta = meta;
|
|
2551
|
+
}
|
|
2552
|
+
static {
|
|
2553
|
+
__name(this, "WorkflowExecutionError");
|
|
2554
|
+
}
|
|
2555
|
+
name = "WorkflowExecutionError";
|
|
2556
|
+
};
|
|
2557
|
+
function generateRunId() {
|
|
2558
|
+
return `wf_${randomBytes(8).toString("hex")}`;
|
|
2559
|
+
}
|
|
2560
|
+
__name(generateRunId, "generateRunId");
|
|
2561
|
+
function sanitizeForErrorMessage(value) {
|
|
2562
|
+
return stripAnsiAndControl(value);
|
|
2563
|
+
}
|
|
2564
|
+
__name(sanitizeForErrorMessage, "sanitizeForErrorMessage");
|
|
2565
|
+
function createProductionDispatch(config, signal, onTokens, bridgeApprovalEvents, subagentBounds) {
|
|
2566
|
+
return async (prompt, opts, dispatchId) => {
|
|
2567
|
+
if (typeof prompt !== "string" || prompt.length === 0) {
|
|
2568
|
+
throw new Error("agent() requires a non-empty string prompt.");
|
|
2569
|
+
}
|
|
2570
|
+
const stallMs = resolveStallMs(
|
|
2571
|
+
typeof opts.stallMs === "number" ? opts.stallMs : void 0
|
|
2572
|
+
);
|
|
2573
|
+
const workflowAgentId = `workflow-agent-${randomBytes(8).toString("hex")}`;
|
|
2574
|
+
const agentIdentity = await resolveWorkflowAgentIdentity(config, opts);
|
|
2575
|
+
if (agentIdentity.resolvedAgentType?.executor !== void 0) {
|
|
2576
|
+
throw new Error(
|
|
2577
|
+
"Workflow agent() does not support external-executor agents: token budgets, schema output, and workflow tool restrictions cannot be enforced. Use an in-process agent definition instead."
|
|
2578
|
+
);
|
|
2579
|
+
}
|
|
2580
|
+
let attempt = 0;
|
|
2581
|
+
return runStallResilient(
|
|
2582
|
+
async (attemptSignal, emitter) => {
|
|
2583
|
+
attempt += 1;
|
|
2584
|
+
const cleanupApprovalBridge = bridgeApprovalEvents?.(
|
|
2585
|
+
emitter,
|
|
2586
|
+
dispatchId
|
|
2587
|
+
);
|
|
2588
|
+
const cleanupTranscript = attachDispatchTranscript(
|
|
2589
|
+
config,
|
|
2590
|
+
workflowAgentId,
|
|
2591
|
+
prompt,
|
|
2592
|
+
agentIdentity.name,
|
|
2593
|
+
emitter,
|
|
2594
|
+
attempt
|
|
2595
|
+
);
|
|
2596
|
+
try {
|
|
2597
|
+
return await runSingleDispatch(
|
|
2598
|
+
config,
|
|
2599
|
+
prompt,
|
|
2600
|
+
opts,
|
|
2601
|
+
attemptSignal,
|
|
2602
|
+
emitter,
|
|
2603
|
+
workflowAgentId,
|
|
2604
|
+
agentIdentity,
|
|
2605
|
+
onTokens,
|
|
2606
|
+
subagentBounds
|
|
2607
|
+
);
|
|
2608
|
+
} finally {
|
|
2609
|
+
cleanupTranscript();
|
|
2610
|
+
cleanupApprovalBridge?.();
|
|
2611
|
+
}
|
|
2612
|
+
},
|
|
2613
|
+
{
|
|
2614
|
+
stallMs,
|
|
2615
|
+
signal,
|
|
2616
|
+
// The name can carry a model-authored agentType spelling — keep
|
|
2617
|
+
// the stall log / abandoned error single-line the same way the
|
|
2618
|
+
// "not found" throw site sanitizes it.
|
|
2619
|
+
label: sanitizeForErrorMessage(agentIdentity.name)
|
|
2620
|
+
}
|
|
2621
|
+
);
|
|
2622
|
+
};
|
|
2623
|
+
}
|
|
2624
|
+
__name(createProductionDispatch, "createProductionDispatch");
|
|
2625
|
+
async function resolveWorkflowAgentIdentity(config, opts) {
|
|
2626
|
+
if (opts.agentType) {
|
|
2627
|
+
const resolved = await config.getSubagentManager().findSubagentByName(opts.agentType);
|
|
2628
|
+
if (resolved) {
|
|
2629
|
+
return { name: resolved.name, resolvedAgentType: resolved };
|
|
2630
|
+
}
|
|
2631
|
+
}
|
|
2632
|
+
if (typeof opts.label === "string" && opts.label) {
|
|
2633
|
+
return { name: opts.label };
|
|
2634
|
+
}
|
|
2635
|
+
return { name: opts.agentType || "workflow-agent" };
|
|
2636
|
+
}
|
|
2637
|
+
__name(resolveWorkflowAgentIdentity, "resolveWorkflowAgentIdentity");
|
|
2638
|
+
function attachDispatchTranscript(config, agentId, prompt, agentName, emitter, attempt) {
|
|
2639
|
+
const append = attempt > 1;
|
|
2640
|
+
try {
|
|
2641
|
+
const { jsonlPath, options } = buildAgentTranscriptAttach(config, agentId, {
|
|
2642
|
+
agentName,
|
|
2643
|
+
// The prompt the SCRIPT dispatched, seeded as the transcript's first
|
|
2644
|
+
// user record — the same shape AgentTool writes, so a reader that
|
|
2645
|
+
// recovers a launch prompt from a transcript needs no workflow-
|
|
2646
|
+
// specific branch. A retry re-uses the first attempt's record rather
|
|
2647
|
+
// than seeding a second one.
|
|
2648
|
+
initialUserPrompt: append ? void 0 : prompt,
|
|
2649
|
+
appendToExisting: append,
|
|
2650
|
+
retryAttempt: append ? attempt : void 0
|
|
2651
|
+
});
|
|
2652
|
+
return attachJsonlTranscriptWriter(emitter, jsonlPath, options).cleanup;
|
|
2653
|
+
} catch (error) {
|
|
2654
|
+
debugLogger.warn(
|
|
2655
|
+
`[Workflow] failed to attach transcript for ${agentId}: ${error}`
|
|
2656
|
+
);
|
|
2657
|
+
return () => {
|
|
2658
|
+
};
|
|
2659
|
+
}
|
|
2660
|
+
}
|
|
2661
|
+
__name(attachDispatchTranscript, "attachDispatchTranscript");
|
|
2662
|
+
function terminalDispatchError(workflowAgentId, mode) {
|
|
2663
|
+
const message = `Workflow subagent ${workflowAgentId} did not complete (terminate mode: ${mode}).`;
|
|
2664
|
+
switch (mode) {
|
|
2665
|
+
case "MAX_TURNS" /* MAX_TURNS */:
|
|
2666
|
+
return new WorkflowAgentFailedError(message, "max_turns", mode);
|
|
2667
|
+
case "TIMEOUT" /* TIMEOUT */:
|
|
2668
|
+
return new WorkflowAgentFailedError(message, "timeout", mode);
|
|
2669
|
+
case "ERROR" /* ERROR */:
|
|
2670
|
+
return new WorkflowAgentFailedError(message, "error", mode);
|
|
2671
|
+
default:
|
|
2672
|
+
return new Error(message);
|
|
2673
|
+
}
|
|
2674
|
+
}
|
|
2675
|
+
__name(terminalDispatchError, "terminalDispatchError");
|
|
2676
|
+
async function runSingleDispatch(config, prompt, opts, attemptSignal, emitter, workflowAgentId, agentIdentity, onTokens, subagentBounds) {
|
|
2677
|
+
const { AgentHeadless, ContextState } = await import("./agent-headless-2HHBVCP6.js");
|
|
2678
|
+
const ctx = new ContextState();
|
|
2679
|
+
ctx.set("task_prompt", prompt);
|
|
2680
|
+
debugLogger.debug(`[workflow] Dispatch ${workflowAgentId}`);
|
|
2681
|
+
if (opts.agentType === void 0 && opts.model === void 0 && opts.isolation === void 0 && opts.schema === void 0 && opts.workingDir === void 0) {
|
|
2682
|
+
const subagent = await AgentHeadless.create(
|
|
2683
|
+
agentIdentity.name,
|
|
2684
|
+
config,
|
|
2685
|
+
{
|
|
2686
|
+
systemPrompt: WORKFLOW_SUBAGENT_SYSTEM_PROMPT
|
|
2687
|
+
},
|
|
2688
|
+
{},
|
|
2689
|
+
// T11 (PR #4732 R1): bound resource ceiling so a single agent() call
|
|
2690
|
+
// cannot loop the model indefinitely. Without this, runConfig was {}
|
|
2691
|
+
// and the loop guards never tripped — combined with the cancellation
|
|
2692
|
+
// bug below, workflows were effectively unkillable.
|
|
2693
|
+
subagentBounds ?? {
|
|
2694
|
+
max_turns: resolveSubagentMaxTurns(),
|
|
2695
|
+
max_time_minutes: resolveSubagentMaxTimeMinutes()
|
|
2696
|
+
},
|
|
2697
|
+
// T11 (PR #4732 R1): disallow SendMessage / ExitPlanMode to align with
|
|
2698
|
+
// upstream Tg8 — closes the back-channel that would let a subagent
|
|
2699
|
+
// deliver its answer via user message instead of the script's read.
|
|
2700
|
+
{ tools: ["*"], disallowedTools: WORKFLOW_SUBAGENT_DISALLOWED_TOOLS },
|
|
2701
|
+
// P-stall: the stall-watchdog emitter observes reasoning-loop events
|
|
2702
|
+
// (round/tool/usage) to detect a hang and abort `attemptSignal`.
|
|
2703
|
+
emitter,
|
|
2704
|
+
void 0,
|
|
2705
|
+
void 0,
|
|
2706
|
+
prompt,
|
|
2707
|
+
workflowAgentId
|
|
2708
|
+
);
|
|
2709
|
+
try {
|
|
2710
|
+
await runWithAgentContext(
|
|
2711
|
+
workflowAgentId,
|
|
2712
|
+
() => subagent.execute(ctx, attemptSignal)
|
|
2713
|
+
);
|
|
2714
|
+
} finally {
|
|
2715
|
+
reportTokens(subagent, opts, onTokens);
|
|
2716
|
+
}
|
|
2717
|
+
const mode = subagent.getTerminateMode();
|
|
2718
|
+
if (mode !== "GOAL" /* GOAL */) {
|
|
2719
|
+
throw terminalDispatchError(workflowAgentId, mode);
|
|
2720
|
+
}
|
|
2721
|
+
return toModelVisibleSubagentResult(subagent.getFinalText(), mode);
|
|
2722
|
+
}
|
|
2723
|
+
return runOverridePath(
|
|
2724
|
+
config,
|
|
2725
|
+
ctx,
|
|
2726
|
+
opts,
|
|
2727
|
+
attemptSignal,
|
|
2728
|
+
workflowAgentId,
|
|
2729
|
+
agentIdentity,
|
|
2730
|
+
onTokens,
|
|
2731
|
+
emitter,
|
|
2732
|
+
subagentBounds
|
|
2733
|
+
);
|
|
2734
|
+
}
|
|
2735
|
+
__name(runSingleDispatch, "runSingleDispatch");
|
|
2736
|
+
function reportTokens(subagent, opts, onTokens) {
|
|
2737
|
+
if (!onTokens) return;
|
|
2738
|
+
try {
|
|
2739
|
+
const summary = subagent.getExecutionSummary();
|
|
2740
|
+
onTokens(summary.outputTokens, opts);
|
|
2741
|
+
} catch (e) {
|
|
2742
|
+
debugLogger.warn("onTokens callback threw:", e);
|
|
2743
|
+
}
|
|
2744
|
+
}
|
|
2745
|
+
__name(reportTokens, "reportTokens");
|
|
2746
|
+
async function runOverridePath(config, ctx, opts, signal, workflowAgentId, agentIdentity, onTokens, emitter, subagentBounds) {
|
|
2747
|
+
if (opts.isolation === "remote") {
|
|
2748
|
+
throw new Error(
|
|
2749
|
+
"agent({isolation:'remote'}) is not available in this build."
|
|
2750
|
+
);
|
|
2751
|
+
}
|
|
2752
|
+
const subagentMgr = config.getSubagentManager();
|
|
2753
|
+
let baseConfig;
|
|
2754
|
+
if (opts.agentType !== void 0) {
|
|
2755
|
+
const resolved = agentIdentity.resolvedAgentType;
|
|
2756
|
+
if (!resolved) {
|
|
2757
|
+
const safeAgentType = sanitizeForErrorMessage(opts.agentType);
|
|
2758
|
+
throw new Error(
|
|
2759
|
+
`agent({agentType}): agent type '${safeAgentType}' not found.`
|
|
2760
|
+
);
|
|
2761
|
+
}
|
|
2762
|
+
baseConfig = resolved;
|
|
2763
|
+
} else {
|
|
2764
|
+
baseConfig = {
|
|
2765
|
+
name: agentIdentity.name,
|
|
2766
|
+
description: "Default workflow subagent (per-call overrides).",
|
|
2767
|
+
systemPrompt: WORKFLOW_SUBAGENT_SYSTEM_PROMPT,
|
|
2768
|
+
level: "session",
|
|
2769
|
+
isBuiltin: false
|
|
2770
|
+
};
|
|
2771
|
+
}
|
|
2772
|
+
let schemaSystemPrompt;
|
|
2773
|
+
if (opts.schema !== void 0) {
|
|
2774
|
+
schemaSystemPrompt = opts.agentType !== void 0 && baseConfig.systemPrompt ? `${baseConfig.systemPrompt}
|
|
2775
|
+
|
|
2776
|
+
${WORKFLOW_SUBAGENT_SYSTEM_PROMPT_WITH_SCHEMA}` : WORKFLOW_SUBAGENT_SYSTEM_PROMPT_WITH_SCHEMA;
|
|
2777
|
+
}
|
|
2778
|
+
let schemaTools;
|
|
2779
|
+
if (opts.schema !== void 0 && baseConfig.tools && baseConfig.tools.length > 0 && !baseConfig.tools.includes("*") && !baseConfig.tools.includes(ToolNames.STRUCTURED_OUTPUT)) {
|
|
2780
|
+
schemaTools = [...baseConfig.tools, ToolNames.STRUCTURED_OUTPUT];
|
|
2781
|
+
}
|
|
2782
|
+
const augmented = {
|
|
2783
|
+
...baseConfig,
|
|
2784
|
+
...opts.model !== void 0 ? { model: opts.model } : {},
|
|
2785
|
+
...schemaSystemPrompt !== void 0 ? { systemPrompt: schemaSystemPrompt } : {},
|
|
2786
|
+
...schemaTools !== void 0 ? { tools: schemaTools } : {},
|
|
2787
|
+
disallowedTools: Array.from(
|
|
2788
|
+
/* @__PURE__ */ new Set([
|
|
2789
|
+
...baseConfig.disallowedTools ?? [],
|
|
2790
|
+
...WORKFLOW_SUBAGENT_DISALLOWED_TOOLS
|
|
2791
|
+
])
|
|
2792
|
+
)
|
|
2793
|
+
};
|
|
2794
|
+
let worktreeIsolation = null;
|
|
2795
|
+
let effectiveContext = config;
|
|
2796
|
+
let approvalCleanup;
|
|
2797
|
+
if (opts.isolation !== void 0 && opts.workingDir !== void 0) {
|
|
2798
|
+
throw new Error(
|
|
2799
|
+
"agent({workingDir, isolation}): incompatible options. workingDir pins the agent to a worktree you already own; isolation creates a fresh one and removes it afterwards. Pass one."
|
|
2800
|
+
);
|
|
2801
|
+
}
|
|
2802
|
+
if (opts.isolation === "worktree") {
|
|
2803
|
+
worktreeIsolation = await provisionWorkflowWorktree(config);
|
|
2804
|
+
effectiveContext = deriveWorktreeConfig(config, worktreeIsolation.path, {
|
|
2805
|
+
customIgnoreFiles: config.getFileFilteringOptions().customIgnoreFiles
|
|
2806
|
+
});
|
|
2807
|
+
installSessionWorkflowRevisionWriteThrough(effectiveContext, config);
|
|
2808
|
+
} else if (opts.workingDir !== void 0) {
|
|
2809
|
+
if (typeof opts.workingDir !== "string" || opts.workingDir.trim().length === 0) {
|
|
2810
|
+
throw new Error(
|
|
2811
|
+
"agent({workingDir}): must be a non-empty string naming an existing git worktree of this repository."
|
|
2812
|
+
);
|
|
2813
|
+
}
|
|
2814
|
+
const resolved = await resolveExternalWorktreeDir(
|
|
2815
|
+
config,
|
|
2816
|
+
opts.workingDir,
|
|
2817
|
+
"workingDir"
|
|
2818
|
+
);
|
|
2819
|
+
if ("error" in resolved) {
|
|
2820
|
+
throw new Error(
|
|
2821
|
+
`agent({workingDir: ${sanitizeForErrorMessage(JSON.stringify(opts.workingDir))}}): ${sanitizeForErrorMessage(resolved.error)}`
|
|
2822
|
+
);
|
|
2823
|
+
}
|
|
2824
|
+
effectiveContext = deriveWorktreeConfig(config, resolved.path, {
|
|
2825
|
+
customIgnoreFiles: config.getFileFilteringOptions().customIgnoreFiles
|
|
2826
|
+
});
|
|
2827
|
+
installSessionWorkflowRevisionWriteThrough(effectiveContext, config);
|
|
2828
|
+
}
|
|
2829
|
+
if (effectiveContext !== config) {
|
|
2830
|
+
const approvalHandle = deriveApprovalModeConfig(
|
|
2831
|
+
effectiveContext,
|
|
2832
|
+
config.getApprovalMode()
|
|
2833
|
+
);
|
|
2834
|
+
approvalCleanup = approvalHandle.cleanup;
|
|
2835
|
+
effectiveContext = approvalHandle.config;
|
|
2836
|
+
}
|
|
2837
|
+
let onParentAbort;
|
|
2838
|
+
try {
|
|
2839
|
+
let schemaState = null;
|
|
2840
|
+
if (opts.schema !== void 0) {
|
|
2841
|
+
effectiveContext = await createSchemaConfigOverride(
|
|
2842
|
+
effectiveContext,
|
|
2843
|
+
opts.schema
|
|
2844
|
+
);
|
|
2845
|
+
schemaState = createSchemaModeState();
|
|
2846
|
+
}
|
|
2847
|
+
let dispatchSignal = signal;
|
|
2848
|
+
if (schemaState) {
|
|
2849
|
+
const child = new AbortController();
|
|
2850
|
+
if (signal) {
|
|
2851
|
+
if (signal.aborted) {
|
|
2852
|
+
child.abort(signal.reason);
|
|
2853
|
+
} else {
|
|
2854
|
+
onParentAbort = /* @__PURE__ */ __name(() => child.abort(signal.reason), "onParentAbort");
|
|
2855
|
+
signal.addEventListener("abort", onParentAbort);
|
|
2856
|
+
}
|
|
2857
|
+
}
|
|
2858
|
+
schemaState.abortController = child;
|
|
2859
|
+
dispatchSignal = child.signal;
|
|
2860
|
+
}
|
|
2861
|
+
const eventEmitter = emitter ?? (schemaState ? new AgentEventEmitter() : void 0);
|
|
2862
|
+
if (schemaState && eventEmitter) {
|
|
2863
|
+
attachSchemaListeners(eventEmitter, schemaState);
|
|
2864
|
+
}
|
|
2865
|
+
const { subagent, dispose } = await subagentMgr.createAgentHeadless(
|
|
2866
|
+
augmented,
|
|
2867
|
+
effectiveContext,
|
|
2868
|
+
{
|
|
2869
|
+
// Workflow always bounds resource ceiling regardless of agentType's
|
|
2870
|
+
// own runConfig / maxTurns — these are workflow-level safety bounds,
|
|
2871
|
+
// not subagent-level preferences. P5 will refine via budget.
|
|
2872
|
+
runConfigOverrides: subagentBounds ?? {
|
|
2873
|
+
max_turns: resolveSubagentMaxTurns(),
|
|
2874
|
+
max_time_minutes: resolveSubagentMaxTimeMinutes()
|
|
2875
|
+
},
|
|
2876
|
+
eventEmitter,
|
|
2877
|
+
taskName: String(ctx.get("task_prompt")),
|
|
2878
|
+
subagentId: workflowAgentId
|
|
2879
|
+
}
|
|
2880
|
+
);
|
|
2881
|
+
try {
|
|
2882
|
+
try {
|
|
2883
|
+
await runWithAgentContext(
|
|
2884
|
+
workflowAgentId,
|
|
2885
|
+
() => subagent.execute(ctx, dispatchSignal)
|
|
2886
|
+
);
|
|
2887
|
+
} finally {
|
|
2888
|
+
reportTokens(subagent, opts, onTokens);
|
|
2889
|
+
}
|
|
2890
|
+
if (schemaState) {
|
|
2891
|
+
if (schemaState.result !== null) {
|
|
2892
|
+
if (worktreeIsolation) {
|
|
2893
|
+
const isolation = worktreeIsolation;
|
|
2894
|
+
worktreeIsolation = null;
|
|
2895
|
+
const preserved = await cleanupWorkflowWorktree(isolation);
|
|
2896
|
+
if (preserved) {
|
|
2897
|
+
debugLogger.info(
|
|
2898
|
+
`[Workflow] Schema-mode subagent preserved worktree at ${preserved.path ?? "(directory removed)"} on branch ${preserved.branch}. The structured payload is returned verbatim; recover the work from the preserved path / branch.`
|
|
2899
|
+
);
|
|
2900
|
+
}
|
|
2901
|
+
}
|
|
2902
|
+
return schemaState.result;
|
|
2903
|
+
}
|
|
2904
|
+
if (signal?.aborted) {
|
|
2905
|
+
throw new DOMException("Workflow aborted.", "AbortError");
|
|
2906
|
+
}
|
|
2907
|
+
const mode2 = subagent.getTerminateMode();
|
|
2908
|
+
if (mode2 !== "GOAL" /* GOAL */ && mode2 !== "CANCELLED" /* CANCELLED */) {
|
|
2909
|
+
throw terminalDispatchError(workflowAgentId, mode2);
|
|
2910
|
+
}
|
|
2911
|
+
if (schemaState.attempts > 2) {
|
|
2912
|
+
throw new WorkflowAgentFailedError(
|
|
2913
|
+
"subagent completed without calling StructuredOutput (after 2 in-conversation nudges).",
|
|
2914
|
+
"no_structured_output"
|
|
2915
|
+
);
|
|
2916
|
+
}
|
|
2917
|
+
throw new WorkflowAgentFailedError(
|
|
2918
|
+
"subagent completed without calling structured_output (no validation attempt \u2014 model produced plain-text content).",
|
|
2919
|
+
"no_structured_output"
|
|
2920
|
+
);
|
|
2921
|
+
}
|
|
2922
|
+
const mode = subagent.getTerminateMode();
|
|
2923
|
+
if (mode !== "GOAL" /* GOAL */) {
|
|
2924
|
+
throw terminalDispatchError(workflowAgentId, mode);
|
|
2925
|
+
}
|
|
2926
|
+
let finalText = toModelVisibleSubagentResult(
|
|
2927
|
+
subagent.getFinalText(),
|
|
2928
|
+
mode
|
|
2929
|
+
);
|
|
2930
|
+
if (worktreeIsolation) {
|
|
2931
|
+
const isolation = worktreeIsolation;
|
|
2932
|
+
worktreeIsolation = null;
|
|
2933
|
+
const preserved = await cleanupWorkflowWorktree(isolation);
|
|
2934
|
+
if (preserved && typeof finalText === "string") {
|
|
2935
|
+
finalText = appendWorktreePreservedSuffix(finalText, preserved);
|
|
2936
|
+
}
|
|
2937
|
+
}
|
|
2938
|
+
return finalText;
|
|
2939
|
+
} finally {
|
|
2940
|
+
await dispose();
|
|
2941
|
+
}
|
|
2942
|
+
} finally {
|
|
2943
|
+
if (onParentAbort && signal) {
|
|
2944
|
+
signal.removeEventListener("abort", onParentAbort);
|
|
2945
|
+
}
|
|
2946
|
+
approvalCleanup?.();
|
|
2947
|
+
if (worktreeIsolation) {
|
|
2948
|
+
try {
|
|
2949
|
+
await cleanupWorkflowWorktree(worktreeIsolation);
|
|
2950
|
+
} catch (error) {
|
|
2951
|
+
debugLogger.warn(
|
|
2952
|
+
`Workflow worktree cleanup in fallback finally failed for ${worktreeIsolation.path}: ${error instanceof Error ? error.message : String(error)}`
|
|
2953
|
+
);
|
|
2954
|
+
}
|
|
2955
|
+
}
|
|
2956
|
+
}
|
|
2957
|
+
}
|
|
2958
|
+
__name(runOverridePath, "runOverridePath");
|
|
2959
|
+
async function provisionWorkflowWorktree(config) {
|
|
2960
|
+
const cwd = config.getTargetDir();
|
|
2961
|
+
if (/\.qwen[\\/]worktrees[\\/]/.test(cwd)) {
|
|
2962
|
+
throw new Error(
|
|
2963
|
+
`agent({isolation:'worktree'}): parent is already inside a worktree (${cwd}). Nested isolation worktrees are not supported \u2014 the subagent's inherited paths would still reference the outer worktree.`
|
|
2964
|
+
);
|
|
2965
|
+
}
|
|
2966
|
+
const probe = new GitWorktreeService(cwd);
|
|
2967
|
+
const gitCheck = await probe.checkGitAvailable();
|
|
2968
|
+
if (!gitCheck.available) {
|
|
2969
|
+
throw new Error(
|
|
2970
|
+
`agent({isolation:'worktree'}): ${gitCheck.error ?? "git is not available"}.`
|
|
2971
|
+
);
|
|
2972
|
+
}
|
|
2973
|
+
if (!await probe.isGitRepository()) {
|
|
2974
|
+
throw new Error(
|
|
2975
|
+
`agent({isolation:'worktree'}): ${cwd} is not a git repository.`
|
|
2976
|
+
);
|
|
2977
|
+
}
|
|
2978
|
+
const projectRoot = await probe.getRepoTopLevel() ?? cwd;
|
|
2979
|
+
const wtService = projectRoot === cwd ? probe : new GitWorktreeService(projectRoot);
|
|
2980
|
+
let parentDirty = false;
|
|
2981
|
+
try {
|
|
2982
|
+
parentDirty = await wtService.hasWorktreeChanges(projectRoot);
|
|
2983
|
+
} catch (error) {
|
|
2984
|
+
debugLogger.warn(
|
|
2985
|
+
`[Workflow] hasWorktreeChanges failed at ${projectRoot}: ${error}`
|
|
2986
|
+
);
|
|
2987
|
+
parentDirty = true;
|
|
2988
|
+
}
|
|
2989
|
+
if (parentDirty) {
|
|
2990
|
+
throw new Error(
|
|
2991
|
+
`agent({isolation:'worktree'}): parent working tree at ${projectRoot} has uncommitted changes that would not propagate into the isolated worktree. The subagent would see the prior HEAD instead of the current state. Commit or stash the changes, then re-run.`
|
|
2992
|
+
);
|
|
2993
|
+
}
|
|
2994
|
+
const slug = generateAgentWorktreeSlug();
|
|
2995
|
+
let parentBranch;
|
|
2996
|
+
try {
|
|
2997
|
+
parentBranch = await wtService.getCurrentBranch();
|
|
2998
|
+
} catch (error) {
|
|
2999
|
+
debugLogger.warn(
|
|
3000
|
+
`[Workflow] getCurrentBranch failed at ${projectRoot}: ${error}`
|
|
3001
|
+
);
|
|
3002
|
+
}
|
|
3003
|
+
const created = await wtService.createUserWorktree(slug, parentBranch, {
|
|
3004
|
+
symlinkDirectories: config.getWorktreeSymlinkDirectories()
|
|
3005
|
+
});
|
|
3006
|
+
if (!created.success || !created.worktree) {
|
|
3007
|
+
throw new Error(
|
|
3008
|
+
`agent({isolation:'worktree'}): failed to create worktree: ${created.error ?? "unknown error"}.`
|
|
3009
|
+
);
|
|
3010
|
+
}
|
|
3011
|
+
try {
|
|
3012
|
+
await writeWorktreeSessionMarker(
|
|
3013
|
+
created.worktree.path,
|
|
3014
|
+
config.getSessionId()
|
|
3015
|
+
);
|
|
3016
|
+
} catch (error) {
|
|
3017
|
+
debugLogger.warn(
|
|
3018
|
+
`[Workflow] failed to write session marker at ${created.worktree.path}: ${error}`
|
|
3019
|
+
);
|
|
3020
|
+
}
|
|
3021
|
+
return {
|
|
3022
|
+
slug,
|
|
3023
|
+
path: created.worktree.path,
|
|
3024
|
+
branch: created.worktree.branch,
|
|
3025
|
+
repoRoot: projectRoot
|
|
3026
|
+
};
|
|
3027
|
+
}
|
|
3028
|
+
__name(provisionWorkflowWorktree, "provisionWorkflowWorktree");
|
|
3029
|
+
async function cleanupWorkflowWorktree(isolation) {
|
|
3030
|
+
const wtService = new GitWorktreeService(isolation.repoRoot);
|
|
3031
|
+
const [hasChanges, hasUnmerged] = await Promise.all([
|
|
3032
|
+
wtService.hasWorktreeChanges(isolation.path).catch((error) => {
|
|
3033
|
+
debugLogger.warn(
|
|
3034
|
+
`[Workflow] hasWorktreeChanges failed for ${isolation.path}: ${error}`
|
|
3035
|
+
);
|
|
3036
|
+
return true;
|
|
3037
|
+
}),
|
|
3038
|
+
wtService.hasUnmergedWorktreeCommits(isolation.slug).catch((error) => {
|
|
3039
|
+
debugLogger.warn(
|
|
3040
|
+
`[Workflow] hasUnmergedWorktreeCommits failed for ${isolation.slug}: ${error}`
|
|
3041
|
+
);
|
|
3042
|
+
return true;
|
|
3043
|
+
})
|
|
3044
|
+
]);
|
|
3045
|
+
if (hasChanges || hasUnmerged) {
|
|
3046
|
+
debugLogger.info(
|
|
3047
|
+
`[Workflow] Preserving isolation worktree ${isolation.path} (branch ${isolation.branch}, hasChanges=${hasChanges}, hasUnmerged=${hasUnmerged})`
|
|
3048
|
+
);
|
|
3049
|
+
return { path: isolation.path, branch: isolation.branch };
|
|
3050
|
+
}
|
|
3051
|
+
try {
|
|
3052
|
+
const result = await wtService.removeUserWorktree(isolation.slug, {
|
|
3053
|
+
deleteBranch: true
|
|
3054
|
+
});
|
|
3055
|
+
if (!result.success) {
|
|
3056
|
+
debugLogger.warn(
|
|
3057
|
+
`[Workflow] Failed to remove ephemeral worktree ${isolation.path}: ${result.error}`
|
|
3058
|
+
);
|
|
3059
|
+
return { path: isolation.path, branch: isolation.branch };
|
|
3060
|
+
}
|
|
3061
|
+
if (result.branchPreserved) {
|
|
3062
|
+
debugLogger.warn(
|
|
3063
|
+
`[Workflow] Removed worktree directory ${isolation.path} but kept branch ${isolation.branch} (unmerged commits at delete time)`
|
|
3064
|
+
);
|
|
3065
|
+
return { branch: isolation.branch };
|
|
3066
|
+
}
|
|
3067
|
+
} catch (error) {
|
|
3068
|
+
debugLogger.warn(
|
|
3069
|
+
`[Workflow] Failed to remove ephemeral worktree ${isolation.path}: ${error}`
|
|
3070
|
+
);
|
|
3071
|
+
return { path: isolation.path, branch: isolation.branch };
|
|
3072
|
+
}
|
|
3073
|
+
return null;
|
|
3074
|
+
}
|
|
3075
|
+
__name(cleanupWorkflowWorktree, "cleanupWorkflowWorktree");
|
|
3076
|
+
function appendWorktreePreservedSuffix(finalText, preserved) {
|
|
3077
|
+
const sep2 = finalText.endsWith("\n") ? "\n" : "\n\n";
|
|
3078
|
+
if (preserved.path) {
|
|
3079
|
+
return `${finalText}${sep2}[worktree preserved: ${preserved.path} (branch ${preserved.branch})]`;
|
|
3080
|
+
}
|
|
3081
|
+
return `${finalText}${sep2}[worktree directory removed; branch ${preserved.branch} preserved \u2014 recover with \`git worktree add <path> ${preserved.branch}\`]`;
|
|
3082
|
+
}
|
|
3083
|
+
__name(appendWorktreePreservedSuffix, "appendWorktreePreservedSuffix");
|
|
3084
|
+
function createSchemaModeState() {
|
|
3085
|
+
return {
|
|
3086
|
+
result: null,
|
|
3087
|
+
attempts: 0,
|
|
3088
|
+
pendingArgs: /* @__PURE__ */ new Map(),
|
|
3089
|
+
abortController: new AbortController()
|
|
3090
|
+
};
|
|
3091
|
+
}
|
|
3092
|
+
__name(createSchemaModeState, "createSchemaModeState");
|
|
3093
|
+
function attachSchemaListeners(emitter, state) {
|
|
3094
|
+
const targetTool = ToolNames.STRUCTURED_OUTPUT;
|
|
3095
|
+
emitter.on("tool_call" /* TOOL_CALL */, (evt) => {
|
|
3096
|
+
if (evt.name !== targetTool) return;
|
|
3097
|
+
state.pendingArgs.set(evt.callId, evt.args);
|
|
3098
|
+
});
|
|
3099
|
+
emitter.on("tool_result" /* TOOL_RESULT */, (evt) => {
|
|
3100
|
+
if (evt.name !== targetTool) return;
|
|
3101
|
+
const args = state.pendingArgs.get(evt.callId);
|
|
3102
|
+
state.pendingArgs.delete(evt.callId);
|
|
3103
|
+
if (evt.success) {
|
|
3104
|
+
if (args !== void 0 && state.result === null) {
|
|
3105
|
+
state.result = args;
|
|
3106
|
+
state.abortController.abort();
|
|
3107
|
+
}
|
|
3108
|
+
return;
|
|
3109
|
+
}
|
|
3110
|
+
state.attempts += 1;
|
|
3111
|
+
if (state.attempts > 2 && state.result === null) {
|
|
3112
|
+
state.abortController.abort();
|
|
3113
|
+
}
|
|
3114
|
+
});
|
|
3115
|
+
}
|
|
3116
|
+
__name(attachSchemaListeners, "attachSchemaListeners");
|
|
3117
|
+
async function createSchemaConfigOverride(base, schema) {
|
|
3118
|
+
const override = deriveConfig(base);
|
|
3119
|
+
installSessionWorkflowRevisionWriteThrough(override, base);
|
|
3120
|
+
await rebuildToolRegistryOnOverride(override, base);
|
|
3121
|
+
const registry = override.getToolRegistry();
|
|
3122
|
+
registry.registerTool(new SyntheticOutputTool(schema));
|
|
3123
|
+
return override;
|
|
3124
|
+
}
|
|
3125
|
+
__name(createSchemaConfigOverride, "createSchemaConfigOverride");
|
|
3126
|
+
var WorkflowOrchestrator = class {
|
|
3127
|
+
constructor(dispatch) {
|
|
3128
|
+
this.dispatch = dispatch;
|
|
3129
|
+
}
|
|
3130
|
+
static {
|
|
3131
|
+
__name(this, "WorkflowOrchestrator");
|
|
3132
|
+
}
|
|
3133
|
+
async run(req) {
|
|
3134
|
+
const runId = req.runId ?? generateRunId();
|
|
3135
|
+
const maxAgents = resolveMaxAgentsPerRun();
|
|
3136
|
+
const signal = req.abortOnTimeout?.signal;
|
|
3137
|
+
const scheduler = req.scheduler ?? new WorkflowDispatchScheduler(resolveConcurrencyLimit(), signal);
|
|
3138
|
+
const rejectThroughPauseGate = /* @__PURE__ */ __name((error) => scheduler.waitUntilRunning().then(
|
|
3139
|
+
() => {
|
|
3140
|
+
throw error;
|
|
3141
|
+
},
|
|
3142
|
+
() => {
|
|
3143
|
+
throw error;
|
|
3144
|
+
}
|
|
3145
|
+
), "rejectThroughPauseGate");
|
|
3146
|
+
let agentCount = 0;
|
|
3147
|
+
let dispatchTraceCount = 0;
|
|
3148
|
+
const emitter = req.emitter;
|
|
3149
|
+
const budget = req.budget;
|
|
3150
|
+
const dependencyContext = new AsyncLocalStorage();
|
|
3151
|
+
const issueDispatchTrace = /* @__PURE__ */ __name((prompt, opts, cached = false) => {
|
|
3152
|
+
const id = `dispatch-${dispatchTraceCount += 1}`;
|
|
3153
|
+
const store = dependencyContext.getStore();
|
|
3154
|
+
const dependsOn = Array.from(new Set(store?.tails ?? []));
|
|
3155
|
+
if (store) store.tails = [id];
|
|
3156
|
+
try {
|
|
3157
|
+
emitter?.dispatchQueued?.({
|
|
3158
|
+
id,
|
|
3159
|
+
...typeof opts.label === "string" ? { label: opts.label } : {},
|
|
3160
|
+
prompt,
|
|
3161
|
+
dependsOn,
|
|
3162
|
+
queuedAt: Date.now(),
|
|
3163
|
+
...cached ? { cached: true } : {}
|
|
3164
|
+
});
|
|
3165
|
+
} catch (e) {
|
|
3166
|
+
debugLogger.warn("emitter.dispatchQueued threw:", e);
|
|
3167
|
+
}
|
|
3168
|
+
return id;
|
|
3169
|
+
}, "issueDispatchTrace");
|
|
3170
|
+
const journal = req.journal;
|
|
3171
|
+
const replay = req.resumeReplay;
|
|
3172
|
+
let prefixHash = deriveArgsSeed(req.args);
|
|
3173
|
+
let hadMiss = false;
|
|
3174
|
+
let journalAgentId = 0;
|
|
3175
|
+
const parentSandboxRef = {
|
|
3176
|
+
current: void 0
|
|
3177
|
+
};
|
|
3178
|
+
const countedDispatch = /* @__PURE__ */ __name((prompt, opts) => {
|
|
3179
|
+
if (typeof prompt !== "string" || prompt.length === 0) {
|
|
3180
|
+
return rejectThroughPauseGate(
|
|
3181
|
+
new Error("agent() requires a non-empty string prompt.")
|
|
3182
|
+
);
|
|
3183
|
+
}
|
|
3184
|
+
let journalKey;
|
|
3185
|
+
let journalEntryId;
|
|
3186
|
+
let respawnLine;
|
|
3187
|
+
if (journal) {
|
|
3188
|
+
journalKey = deriveAgentKey(prefixHash, prompt, opts);
|
|
3189
|
+
prefixHash = journalKey;
|
|
3190
|
+
if (!hadMiss && replay) {
|
|
3191
|
+
const cached = replay.results.get(journalKey);
|
|
3192
|
+
if (cached !== void 0) {
|
|
3193
|
+
const respawns = replay.started.get(journalKey);
|
|
3194
|
+
if (respawns && respawns.length > 0) {
|
|
3195
|
+
debugLogger.info(
|
|
3196
|
+
`[Workflow] resume cache hit after ${respawns.length} prior respawn(s) for runId=${runId}.`
|
|
3197
|
+
);
|
|
3198
|
+
}
|
|
3199
|
+
const label2 = typeof opts.label === "string" ? opts.label : void 0;
|
|
3200
|
+
const dispatchId2 = issueDispatchTrace(prompt, opts, true);
|
|
3201
|
+
try {
|
|
3202
|
+
emitter?.agentDispatched?.(label2);
|
|
3203
|
+
} catch (e) {
|
|
3204
|
+
debugLogger.warn("emitter.agentDispatched threw:", e);
|
|
3205
|
+
}
|
|
3206
|
+
try {
|
|
3207
|
+
emitter?.agentCompleted?.(label2);
|
|
3208
|
+
} catch (e) {
|
|
3209
|
+
debugLogger.warn("emitter.agentCompleted threw:", e);
|
|
3210
|
+
}
|
|
3211
|
+
try {
|
|
3212
|
+
emitter?.dispatchSettled?.(dispatchId2, void 0, Date.now());
|
|
3213
|
+
} catch (e) {
|
|
3214
|
+
debugLogger.warn("emitter.dispatchSettled threw:", e);
|
|
3215
|
+
}
|
|
3216
|
+
return scheduler.waitUntilRunning().then(
|
|
3217
|
+
() => cached.result,
|
|
3218
|
+
() => cached.result
|
|
3219
|
+
);
|
|
3220
|
+
}
|
|
3221
|
+
}
|
|
3222
|
+
const priorStarts = replay?.started.get(journalKey);
|
|
3223
|
+
if (priorStarts && priorStarts.length > 0 && !replay?.results.has(journalKey)) {
|
|
3224
|
+
const name = typeof opts.label === "string" ? `"${stripAnsiAndControl(opts.label)}"` : "an agent";
|
|
3225
|
+
respawnLine = replay?.failed.has(journalKey) ? `[resume] re-running ${name}: it failed in the previous run` : `[resume] respawning ${name}: interrupted in a previous run (${priorStarts.length} prior attempt${priorStarts.length === 1 ? "" : "s"})`;
|
|
3226
|
+
}
|
|
3227
|
+
hadMiss = true;
|
|
3228
|
+
}
|
|
3229
|
+
if (budget && budget.total !== null && budget.remaining() <= 0) {
|
|
3230
|
+
debugLogger.warn(
|
|
3231
|
+
`[Workflow] budget gate refused dispatch at entry: runId=${runId} spent=${budget.spent()} total=${budget.total}`
|
|
3232
|
+
);
|
|
3233
|
+
return rejectThroughPauseGate(
|
|
3234
|
+
new WorkflowBudgetExceededError(runId, budget.total, budget.spent())
|
|
3235
|
+
);
|
|
3236
|
+
}
|
|
3237
|
+
if (agentCount >= maxAgents) {
|
|
3238
|
+
return rejectThroughPauseGate(
|
|
3239
|
+
new WorkflowAgentCapExceededError(maxAgents)
|
|
3240
|
+
);
|
|
3241
|
+
}
|
|
3242
|
+
agentCount += 1;
|
|
3243
|
+
if (journal && journalKey !== void 0) {
|
|
3244
|
+
journalEntryId = String(journalAgentId += 1);
|
|
3245
|
+
}
|
|
3246
|
+
const label = typeof opts.label === "string" ? opts.label : void 0;
|
|
3247
|
+
const dispatchId = issueDispatchTrace(prompt, opts);
|
|
3248
|
+
try {
|
|
3249
|
+
emitter?.agentDispatched?.(label);
|
|
3250
|
+
} catch (e) {
|
|
3251
|
+
debugLogger.warn("emitter.agentDispatched threw:", e);
|
|
3252
|
+
}
|
|
3253
|
+
let completionEmitted = false;
|
|
3254
|
+
const emitCompletion = /* @__PURE__ */ __name((error) => {
|
|
3255
|
+
if (completionEmitted) return;
|
|
3256
|
+
completionEmitted = true;
|
|
3257
|
+
const message = error === void 0 ? void 0 : error instanceof Error ? error.message : String(error);
|
|
3258
|
+
try {
|
|
3259
|
+
emitter?.agentCompleted?.(label, message);
|
|
3260
|
+
} catch (e) {
|
|
3261
|
+
debugLogger.warn("emitter.agentCompleted threw:", e);
|
|
3262
|
+
}
|
|
3263
|
+
try {
|
|
3264
|
+
emitter?.dispatchSettled?.(dispatchId, message, Date.now());
|
|
3265
|
+
} catch (e) {
|
|
3266
|
+
debugLogger.warn("emitter.dispatchSettled threw:", e);
|
|
3267
|
+
}
|
|
3268
|
+
}, "emitCompletion");
|
|
3269
|
+
return scheduler.run(async () => {
|
|
3270
|
+
try {
|
|
3271
|
+
try {
|
|
3272
|
+
emitter?.dispatchStarted?.(dispatchId, Date.now());
|
|
3273
|
+
} catch (e) {
|
|
3274
|
+
debugLogger.warn("emitter.dispatchStarted threw:", e);
|
|
3275
|
+
}
|
|
3276
|
+
if (budget && budget.total !== null && budget.remaining() <= 0) {
|
|
3277
|
+
debugLogger.warn(
|
|
3278
|
+
`[Workflow] budget gate refused dispatch at slot-acquire: runId=${runId} spent=${budget.spent()} total=${budget.total}`
|
|
3279
|
+
);
|
|
3280
|
+
throw new WorkflowBudgetExceededError(
|
|
3281
|
+
runId,
|
|
3282
|
+
budget.total,
|
|
3283
|
+
budget.spent()
|
|
3284
|
+
);
|
|
3285
|
+
}
|
|
3286
|
+
if (journal && journalKey !== void 0 && journalEntryId !== void 0) {
|
|
3287
|
+
journal.append({
|
|
3288
|
+
type: "started",
|
|
3289
|
+
key: journalKey,
|
|
3290
|
+
agentId: journalEntryId
|
|
3291
|
+
}).catch(
|
|
3292
|
+
(e) => debugLogger.warn(`journal started-append failed: ${e}`)
|
|
3293
|
+
);
|
|
3294
|
+
}
|
|
3295
|
+
if (respawnLine) {
|
|
3296
|
+
parentSandboxRef.current?.appendLog(respawnLine);
|
|
3297
|
+
try {
|
|
3298
|
+
emitter?.resumeRespawn?.(respawnLine);
|
|
3299
|
+
} catch (e) {
|
|
3300
|
+
debugLogger.warn("emitter.resumeRespawn threw:", e);
|
|
3301
|
+
}
|
|
3302
|
+
}
|
|
3303
|
+
const result = await this.dispatch(prompt, opts, dispatchId);
|
|
3304
|
+
emitCompletion();
|
|
3305
|
+
if (journal && journalKey !== void 0) {
|
|
3306
|
+
journal.append({
|
|
3307
|
+
type: "result",
|
|
3308
|
+
key: journalKey,
|
|
3309
|
+
agentId: journalEntryId ?? "",
|
|
3310
|
+
result
|
|
3311
|
+
}).catch(
|
|
3312
|
+
(e) => debugLogger.warn(`journal result-append failed: ${e}`)
|
|
3313
|
+
);
|
|
3314
|
+
}
|
|
3315
|
+
if (budget) {
|
|
3316
|
+
try {
|
|
3317
|
+
emitter?.budgetUpdated?.(budget.spent(), budget.total);
|
|
3318
|
+
} catch (e) {
|
|
3319
|
+
debugLogger.warn("emitter.budgetUpdated threw:", e);
|
|
3320
|
+
}
|
|
3321
|
+
}
|
|
3322
|
+
return result;
|
|
3323
|
+
} catch (err) {
|
|
3324
|
+
emitCompletion(err);
|
|
3325
|
+
if (budget) {
|
|
3326
|
+
try {
|
|
3327
|
+
emitter?.budgetUpdated?.(budget.spent(), budget.total);
|
|
3328
|
+
} catch (e) {
|
|
3329
|
+
debugLogger.warn("emitter.budgetUpdated threw:", e);
|
|
3330
|
+
}
|
|
3331
|
+
}
|
|
3332
|
+
if (journal && journalKey !== void 0 && !signal?.aborted && !isWorkflowRunLevelError(err)) {
|
|
3333
|
+
journal.append({
|
|
3334
|
+
type: "failed",
|
|
3335
|
+
key: journalKey,
|
|
3336
|
+
agentId: journalEntryId ?? ""
|
|
3337
|
+
}).catch(
|
|
3338
|
+
(e) => debugLogger.warn(`journal failed-append failed: ${e}`)
|
|
3339
|
+
);
|
|
3340
|
+
}
|
|
3341
|
+
if (signal?.aborted || isWorkflowRunLevelError(err)) throw err;
|
|
3342
|
+
if (isWorkflowAgentFailedError(err)) {
|
|
3343
|
+
debugLogger.warn(
|
|
3344
|
+
`[Workflow] agent settled to null (${err.kind}): ${err.message}`
|
|
3345
|
+
);
|
|
3346
|
+
} else {
|
|
3347
|
+
debugLogger.warn(
|
|
3348
|
+
`[Workflow] agent settled to null: ${extractErrorMessage(err)}`
|
|
3349
|
+
);
|
|
3350
|
+
}
|
|
3351
|
+
return null;
|
|
3352
|
+
}
|
|
3353
|
+
}).then(
|
|
3354
|
+
// Resolve even if the gate aborts: a successful dispatch must not
|
|
3355
|
+
// turn into a teardown rejection — for a fire-and-forget call the
|
|
3356
|
+
// script never attached a handler, so the rejection would surface
|
|
3357
|
+
// as a spurious process-level unhandledRejection alarm on a
|
|
3358
|
+
// correctly-cancelled run.
|
|
3359
|
+
(result) => scheduler.waitUntilRunning().then(
|
|
3360
|
+
() => result,
|
|
3361
|
+
() => result
|
|
3362
|
+
),
|
|
3363
|
+
(error) => {
|
|
3364
|
+
emitCompletion(error);
|
|
3365
|
+
return scheduler.waitUntilRunning().then(
|
|
3366
|
+
() => {
|
|
3367
|
+
throw error;
|
|
3368
|
+
},
|
|
3369
|
+
() => {
|
|
3370
|
+
throw error;
|
|
3371
|
+
}
|
|
3372
|
+
);
|
|
3373
|
+
}
|
|
3374
|
+
);
|
|
3375
|
+
}, "countedDispatch");
|
|
3376
|
+
const parallelImpl = makeParallelImpl(signal, dependencyContext);
|
|
3377
|
+
const pipelineImpl = makePipelineImpl(signal, dependencyContext);
|
|
3378
|
+
const resolveSavedWorkflow = req.resolveSavedWorkflow;
|
|
3379
|
+
const workflowImpl = resolveSavedWorkflow ? async (nameOrRef, nestedArgs) => {
|
|
3380
|
+
const resolved = await resolveSavedWorkflow(nameOrRef);
|
|
3381
|
+
const nestedSandbox = createWorkflowSandbox({
|
|
3382
|
+
args: nestedArgs,
|
|
3383
|
+
runId,
|
|
3384
|
+
dispatch: countedDispatch,
|
|
3385
|
+
parallel: parallelImpl,
|
|
3386
|
+
pipeline: pipelineImpl,
|
|
3387
|
+
abortOnTimeout: req.abortOnTimeout,
|
|
3388
|
+
emitter,
|
|
3389
|
+
budget,
|
|
3390
|
+
scheduler
|
|
3391
|
+
// No `workflow` — single-level nesting limit.
|
|
3392
|
+
});
|
|
3393
|
+
try {
|
|
3394
|
+
return await nestedSandbox.run(resolved.script);
|
|
3395
|
+
} finally {
|
|
3396
|
+
for (const line of nestedSandbox.getLogs()) {
|
|
3397
|
+
parentSandboxRef.current?.appendLog(line);
|
|
3398
|
+
}
|
|
3399
|
+
}
|
|
3400
|
+
} : void 0;
|
|
3401
|
+
const sandbox = createWorkflowSandbox({
|
|
3402
|
+
args: req.args,
|
|
3403
|
+
maxWallClockMs: req.maxWallClockMs,
|
|
3404
|
+
runId,
|
|
3405
|
+
dispatch: countedDispatch,
|
|
3406
|
+
parallel: parallelImpl,
|
|
3407
|
+
pipeline: pipelineImpl,
|
|
3408
|
+
workflow: workflowImpl,
|
|
3409
|
+
abortOnTimeout: req.abortOnTimeout,
|
|
3410
|
+
emitter,
|
|
3411
|
+
budget,
|
|
3412
|
+
scheduler
|
|
3413
|
+
});
|
|
3414
|
+
parentSandboxRef.current = sandbox;
|
|
3415
|
+
try {
|
|
3416
|
+
const result = await dependencyContext.run(
|
|
3417
|
+
{ tails: [] },
|
|
3418
|
+
() => sandbox.run(req.script)
|
|
3419
|
+
);
|
|
3420
|
+
return {
|
|
3421
|
+
runId,
|
|
3422
|
+
result,
|
|
3423
|
+
phases: sandbox.getPhases(),
|
|
3424
|
+
logs: sandbox.getLogs(),
|
|
3425
|
+
meta: sandbox.getMeta()
|
|
3426
|
+
};
|
|
3427
|
+
} catch (err) {
|
|
3428
|
+
throw new WorkflowExecutionError(
|
|
3429
|
+
extractErrorMessage(err),
|
|
3430
|
+
sandbox.getPhases(),
|
|
3431
|
+
sandbox.getLogs(),
|
|
3432
|
+
sandbox.getMeta()
|
|
3433
|
+
);
|
|
3434
|
+
}
|
|
3435
|
+
}
|
|
3436
|
+
};
|
|
3437
|
+
async function settleToNullArray(thunks, signal) {
|
|
3438
|
+
const settled = await Promise.allSettled(
|
|
3439
|
+
thunks.map((t) => Promise.resolve().then(t))
|
|
3440
|
+
);
|
|
3441
|
+
if (signal?.aborted)
|
|
3442
|
+
throw new DOMException("Workflow run aborted.", "AbortError");
|
|
3443
|
+
const visitedReasons = /* @__PURE__ */ new WeakSet();
|
|
3444
|
+
const findRunFailureReason = /* @__PURE__ */ __name((reason) => {
|
|
3445
|
+
if (reason === null || typeof reason !== "object") return void 0;
|
|
3446
|
+
if (visitedReasons.has(reason)) return void 0;
|
|
3447
|
+
visitedReasons.add(reason);
|
|
3448
|
+
try {
|
|
3449
|
+
if (reason.__wfRunFailure === true) {
|
|
3450
|
+
return reason;
|
|
3451
|
+
}
|
|
3452
|
+
const errors = reason?.errors;
|
|
3453
|
+
if (!Array.isArray(errors)) return void 0;
|
|
3454
|
+
for (const error of errors) {
|
|
3455
|
+
const runFailure = findRunFailureReason(error);
|
|
3456
|
+
if (runFailure !== void 0) return runFailure;
|
|
3457
|
+
}
|
|
3458
|
+
} catch {
|
|
3459
|
+
return void 0;
|
|
3460
|
+
}
|
|
3461
|
+
return void 0;
|
|
3462
|
+
}, "findRunFailureReason");
|
|
3463
|
+
for (const result of settled) {
|
|
3464
|
+
if (result.status !== "rejected") continue;
|
|
3465
|
+
const runFailure = findRunFailureReason(result.reason);
|
|
3466
|
+
if (runFailure !== void 0) throw runFailure;
|
|
3467
|
+
}
|
|
3468
|
+
return settled.map((r, i) => {
|
|
3469
|
+
if (r.status === "fulfilled") return r.value;
|
|
3470
|
+
const reason = r.reason;
|
|
3471
|
+
debugLogger.warn(
|
|
3472
|
+
`Workflow thunk at index ${i} rejected: ${String(reason?.message ?? r.reason)}`
|
|
3473
|
+
);
|
|
3474
|
+
return null;
|
|
3475
|
+
});
|
|
3476
|
+
}
|
|
3477
|
+
__name(settleToNullArray, "settleToNullArray");
|
|
3478
|
+
function makeParallelImpl(signal, dependencyContext) {
|
|
3479
|
+
return (thunks) => {
|
|
3480
|
+
if (!Array.isArray(thunks)) {
|
|
3481
|
+
return Promise.reject(
|
|
3482
|
+
new Error(
|
|
3483
|
+
"parallel() expects an array of thunks (functions returning promises)."
|
|
3484
|
+
)
|
|
3485
|
+
);
|
|
3486
|
+
}
|
|
3487
|
+
for (const t of thunks) {
|
|
3488
|
+
if (typeof t !== "function") {
|
|
3489
|
+
return Promise.reject(
|
|
3490
|
+
new Error(
|
|
3491
|
+
"parallel() expects an array of functions, not values \u2014 wrap each call: parallel([() => agent(...), () => agent(...)])."
|
|
3492
|
+
)
|
|
3493
|
+
);
|
|
3494
|
+
}
|
|
3495
|
+
}
|
|
3496
|
+
const parent = dependencyContext.getStore();
|
|
3497
|
+
const inheritedTails = parent?.tails ?? [];
|
|
3498
|
+
const branches = thunks.map((thunk) => {
|
|
3499
|
+
const store = { tails: [...inheritedTails] };
|
|
3500
|
+
return {
|
|
3501
|
+
store,
|
|
3502
|
+
thunk: /* @__PURE__ */ __name(() => dependencyContext.run(store, thunk), "thunk")
|
|
3503
|
+
};
|
|
3504
|
+
});
|
|
3505
|
+
return settleToNullArray(
|
|
3506
|
+
branches.map(({ thunk }) => thunk),
|
|
3507
|
+
signal
|
|
3508
|
+
).then((result) => {
|
|
3509
|
+
if (parent && branches.length > 0) {
|
|
3510
|
+
parent.tails = mergeFanoutTails(
|
|
3511
|
+
parent.tails,
|
|
3512
|
+
inheritedTails,
|
|
3513
|
+
branches.flatMap(({ store }) => store.tails)
|
|
3514
|
+
);
|
|
3515
|
+
}
|
|
3516
|
+
return result;
|
|
3517
|
+
});
|
|
3518
|
+
};
|
|
3519
|
+
}
|
|
3520
|
+
__name(makeParallelImpl, "makeParallelImpl");
|
|
3521
|
+
function makePipelineImpl(signal, dependencyContext) {
|
|
3522
|
+
return (items, ...stages) => {
|
|
3523
|
+
if (!Array.isArray(items)) {
|
|
3524
|
+
return Promise.reject(
|
|
3525
|
+
new Error(
|
|
3526
|
+
"pipeline() expects an array of items as its first argument."
|
|
3527
|
+
)
|
|
3528
|
+
);
|
|
3529
|
+
}
|
|
3530
|
+
for (const s of stages) {
|
|
3531
|
+
if (typeof s !== "function") {
|
|
3532
|
+
return Promise.reject(
|
|
3533
|
+
new Error(
|
|
3534
|
+
"pipeline() stages must be functions: pipeline(items, item => ..., result => ...)."
|
|
3535
|
+
)
|
|
3536
|
+
);
|
|
3537
|
+
}
|
|
3538
|
+
}
|
|
3539
|
+
const parent = dependencyContext.getStore();
|
|
3540
|
+
const inheritedTails = parent?.tails ?? [];
|
|
3541
|
+
const branches = items.map((item, idx) => {
|
|
3542
|
+
const store = { tails: [...inheritedTails] };
|
|
3543
|
+
return {
|
|
3544
|
+
store,
|
|
3545
|
+
thunk: /* @__PURE__ */ __name(() => dependencyContext.run(
|
|
3546
|
+
store,
|
|
3547
|
+
() => runPipelineChain(item, idx, stages)
|
|
3548
|
+
), "thunk")
|
|
3549
|
+
};
|
|
3550
|
+
});
|
|
3551
|
+
return settleToNullArray(
|
|
3552
|
+
branches.map(({ thunk }) => thunk),
|
|
3553
|
+
signal
|
|
3554
|
+
).then((result) => {
|
|
3555
|
+
if (parent && branches.length > 0) {
|
|
3556
|
+
parent.tails = mergeFanoutTails(
|
|
3557
|
+
parent.tails,
|
|
3558
|
+
inheritedTails,
|
|
3559
|
+
branches.flatMap(({ store }) => store.tails)
|
|
3560
|
+
);
|
|
3561
|
+
}
|
|
3562
|
+
return result;
|
|
3563
|
+
});
|
|
3564
|
+
};
|
|
3565
|
+
}
|
|
3566
|
+
__name(makePipelineImpl, "makePipelineImpl");
|
|
3567
|
+
function mergeFanoutTails(currentParentTails, inheritedTails, branchTails) {
|
|
3568
|
+
const inherited = new Set(inheritedTails);
|
|
3569
|
+
const newBranchTails = branchTails.filter((tail) => !inherited.has(tail));
|
|
3570
|
+
const merged = newBranchTails.length > 0 ? [
|
|
3571
|
+
...newBranchTails,
|
|
3572
|
+
...currentParentTails.filter((tail) => !inherited.has(tail))
|
|
3573
|
+
] : currentParentTails;
|
|
3574
|
+
return Array.from(new Set(merged));
|
|
3575
|
+
}
|
|
3576
|
+
__name(mergeFanoutTails, "mergeFanoutTails");
|
|
3577
|
+
async function runPipelineChain(item, idx, stages) {
|
|
3578
|
+
let prev = item;
|
|
3579
|
+
for (const stage of stages) {
|
|
3580
|
+
if (prev === null) break;
|
|
3581
|
+
prev = await stage(prev, item, idx);
|
|
3582
|
+
}
|
|
3583
|
+
return prev;
|
|
3584
|
+
}
|
|
3585
|
+
__name(runPipelineChain, "runPipelineChain");
|
|
3586
|
+
function extractErrorMessage(err) {
|
|
3587
|
+
if (err && typeof err === "object" && "message" in err) {
|
|
3588
|
+
const m = err.message;
|
|
3589
|
+
if (typeof m === "string") return m;
|
|
3590
|
+
return String(m);
|
|
3591
|
+
}
|
|
3592
|
+
return String(err);
|
|
3593
|
+
}
|
|
3594
|
+
__name(extractErrorMessage, "extractErrorMessage");
|
|
3595
|
+
|
|
3596
|
+
// packages/core/src/agents/workflow-snapshot.ts
|
|
3597
|
+
init_esbuild_shims();
|
|
3598
|
+
import { promises as fs3 } from "node:fs";
|
|
3599
|
+
import path3 from "node:path";
|
|
3600
|
+
var debugLogger6 = createDebugLogger("WORKFLOW_SNAPSHOT");
|
|
3601
|
+
var MAX_RETAINED_SNAPSHOTS = 30;
|
|
3602
|
+
function toSnapshot(task) {
|
|
3603
|
+
if (!isTerminalWorkflowStatus(task.status)) {
|
|
3604
|
+
throw new Error(`Cannot snapshot active workflow ${task.runId}.`);
|
|
3605
|
+
}
|
|
3606
|
+
return {
|
|
3607
|
+
runId: task.runId,
|
|
3608
|
+
...task.toolUseId ? { toolUseId: task.toolUseId } : {},
|
|
3609
|
+
description: task.description,
|
|
3610
|
+
...task.workflowName ? { workflowName: task.workflowName } : {},
|
|
3611
|
+
sourceRunId: task.sourceRunId,
|
|
3612
|
+
startMode: task.startMode,
|
|
3613
|
+
meta: task.meta,
|
|
3614
|
+
status: task.status,
|
|
3615
|
+
script: task.script ?? "",
|
|
3616
|
+
scriptPath: task.scriptPath,
|
|
3617
|
+
phases: [...task.phases],
|
|
3618
|
+
phaseVisits: task.phaseVisits.map((visit) => ({ ...visit })),
|
|
3619
|
+
dispatches: task.dispatches.map((dispatch) => ({
|
|
3620
|
+
...dispatch,
|
|
3621
|
+
dependsOn: [...dispatch.dependsOn]
|
|
3622
|
+
})),
|
|
3623
|
+
agentsDispatched: task.agentsDispatched,
|
|
3624
|
+
agentsCompleted: task.agentsCompleted,
|
|
3625
|
+
agentsRespawned: task.agentsRespawned ?? 0,
|
|
3626
|
+
tokensSpent: task.tokensSpent,
|
|
3627
|
+
tokenBudgetTotal: task.tokenBudgetTotal,
|
|
3628
|
+
perPhaseTokens: Array.from(task.perPhaseTokens.entries()),
|
|
3629
|
+
recentLogs: [...task.recentLogs],
|
|
3630
|
+
events: task.events.map((event) => ({ ...event })),
|
|
3631
|
+
startTime: task.startTime,
|
|
3632
|
+
endTime: task.endTime,
|
|
3633
|
+
result: safeResult(task.result),
|
|
3634
|
+
error: task.error
|
|
3635
|
+
};
|
|
3636
|
+
}
|
|
3637
|
+
__name(toSnapshot, "toSnapshot");
|
|
3638
|
+
function safeResult(result) {
|
|
3639
|
+
if (result === void 0) return void 0;
|
|
3640
|
+
try {
|
|
3641
|
+
JSON.stringify(result);
|
|
3642
|
+
return result;
|
|
3643
|
+
} catch {
|
|
3644
|
+
return `(non-JSON-serializable ${typeof result})`;
|
|
3645
|
+
}
|
|
3646
|
+
}
|
|
3647
|
+
__name(safeResult, "safeResult");
|
|
3648
|
+
async function writeWorkflowSnapshot(config, task) {
|
|
3649
|
+
const storage = config.storage;
|
|
3650
|
+
if (!storage) return false;
|
|
3651
|
+
try {
|
|
3652
|
+
const snapshot = toSnapshot(task);
|
|
3653
|
+
const dir = storage.getWorkflowRunsDir();
|
|
3654
|
+
await fs3.mkdir(dir, { recursive: true });
|
|
3655
|
+
await fs3.writeFile(
|
|
3656
|
+
storage.getWorkflowRunSnapshotPath(task.runId),
|
|
3657
|
+
JSON.stringify(snapshot, null, 2),
|
|
3658
|
+
"utf8"
|
|
3659
|
+
);
|
|
3660
|
+
await pruneSnapshots(config, dir);
|
|
3661
|
+
return true;
|
|
3662
|
+
} catch (e) {
|
|
3663
|
+
debugLogger6.warn(`writeWorkflowSnapshot failed for ${task.runId}: ${e}`);
|
|
3664
|
+
return false;
|
|
3665
|
+
}
|
|
3666
|
+
}
|
|
3667
|
+
__name(writeWorkflowSnapshot, "writeWorkflowSnapshot");
|
|
3668
|
+
async function listWorkflowSnapshots(config) {
|
|
3669
|
+
const storage = config.storage;
|
|
3670
|
+
if (!storage) return [];
|
|
3671
|
+
const dir = storage.getWorkflowRunsDir();
|
|
3672
|
+
let files;
|
|
3673
|
+
try {
|
|
3674
|
+
files = (await fs3.readdir(dir)).filter((f) => f.endsWith(".json"));
|
|
3675
|
+
} catch {
|
|
3676
|
+
return [];
|
|
3677
|
+
}
|
|
3678
|
+
const snapshots = [];
|
|
3679
|
+
for (const file of files) {
|
|
3680
|
+
try {
|
|
3681
|
+
const raw = await fs3.readFile(`${dir}/${file}`, "utf8");
|
|
3682
|
+
const parsed = JSON.parse(raw);
|
|
3683
|
+
if (!isWorkflowSnapshot(parsed)) {
|
|
3684
|
+
debugLogger6.warn(`skipping invalid workflow snapshot ${file}`);
|
|
3685
|
+
continue;
|
|
3686
|
+
}
|
|
3687
|
+
snapshots.push(parsed);
|
|
3688
|
+
} catch (e) {
|
|
3689
|
+
debugLogger6.warn(`skipping unparseable snapshot ${file}: ${e}`);
|
|
3690
|
+
}
|
|
3691
|
+
}
|
|
3692
|
+
snapshots.sort((a, b) => (b.startTime ?? 0) - (a.startTime ?? 0));
|
|
3693
|
+
return snapshots;
|
|
3694
|
+
}
|
|
3695
|
+
__name(listWorkflowSnapshots, "listWorkflowSnapshots");
|
|
3696
|
+
async function deleteWorkflowSnapshot(config, runId) {
|
|
3697
|
+
const storage = config.storage;
|
|
3698
|
+
if (!storage || !/^wf_[0-9a-f]+$/.test(runId)) return false;
|
|
3699
|
+
try {
|
|
3700
|
+
await fs3.rm(path3.dirname(storage.getWorkflowRunJournalPath(runId)), {
|
|
3701
|
+
recursive: true,
|
|
3702
|
+
force: true
|
|
3703
|
+
});
|
|
3704
|
+
} catch (error) {
|
|
3705
|
+
debugLogger6.warn(`delete workflow journal failed for ${runId}: ${error}`);
|
|
3706
|
+
return false;
|
|
3707
|
+
}
|
|
3708
|
+
if (!await deleteInlineWorkflowScript(config, runId)) return false;
|
|
3709
|
+
try {
|
|
3710
|
+
await fs3.unlink(storage.getWorkflowRunSnapshotPath(runId));
|
|
3711
|
+
} catch (error) {
|
|
3712
|
+
if (error.code !== "ENOENT") {
|
|
3713
|
+
debugLogger6.warn(`deleteWorkflowSnapshot failed for ${runId}: ${error}`);
|
|
3714
|
+
return false;
|
|
3715
|
+
}
|
|
3716
|
+
}
|
|
3717
|
+
return true;
|
|
3718
|
+
}
|
|
3719
|
+
__name(deleteWorkflowSnapshot, "deleteWorkflowSnapshot");
|
|
3720
|
+
function isRecord(value) {
|
|
3721
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
3722
|
+
}
|
|
3723
|
+
__name(isRecord, "isRecord");
|
|
3724
|
+
function isFiniteNumber(value) {
|
|
3725
|
+
return typeof value === "number" && Number.isFinite(value);
|
|
3726
|
+
}
|
|
3727
|
+
__name(isFiniteNumber, "isFiniteNumber");
|
|
3728
|
+
function isOptionalString(value) {
|
|
3729
|
+
return value === void 0 || typeof value === "string";
|
|
3730
|
+
}
|
|
3731
|
+
__name(isOptionalString, "isOptionalString");
|
|
3732
|
+
function isStringArray(value) {
|
|
3733
|
+
return Array.isArray(value) && value.every((item) => typeof item === "string");
|
|
3734
|
+
}
|
|
3735
|
+
__name(isStringArray, "isStringArray");
|
|
3736
|
+
function isWorkflowMeta(value) {
|
|
3737
|
+
if (value === null) return true;
|
|
3738
|
+
if (!isRecord(value)) return false;
|
|
3739
|
+
if (typeof value["name"] !== "string" || typeof value["description"] !== "string" || !isOptionalString(value["whenToUse"])) {
|
|
3740
|
+
return false;
|
|
3741
|
+
}
|
|
3742
|
+
const phases = value["phases"];
|
|
3743
|
+
return phases === void 0 || Array.isArray(phases) && phases.every(
|
|
3744
|
+
(phase) => isRecord(phase) && typeof phase["title"] === "string" && isOptionalString(phase["detail"]) && isOptionalString(phase["model"])
|
|
3745
|
+
);
|
|
3746
|
+
}
|
|
3747
|
+
__name(isWorkflowMeta, "isWorkflowMeta");
|
|
3748
|
+
function isWorkflowPhaseVisit(value) {
|
|
3749
|
+
return isRecord(value) && typeof value["id"] === "string" && isFiniteNumber(value["index"]) && typeof value["title"] === "string" && isFiniteNumber(value["startedAt"]) && (value["endedAt"] === void 0 || isFiniteNumber(value["endedAt"]));
|
|
2012
3750
|
}
|
|
2013
3751
|
__name(isWorkflowPhaseVisit, "isWorkflowPhaseVisit");
|
|
2014
3752
|
function isWorkflowDispatch(value) {
|
|
@@ -2070,7 +3808,7 @@ __name(isWorkflowSnapshot, "isWorkflowSnapshot");
|
|
|
2070
3808
|
async function pruneSnapshots(config, dir) {
|
|
2071
3809
|
let files;
|
|
2072
3810
|
try {
|
|
2073
|
-
files = (await
|
|
3811
|
+
files = (await fs3.readdir(dir)).filter((f) => f.endsWith(".json"));
|
|
2074
3812
|
} catch {
|
|
2075
3813
|
return;
|
|
2076
3814
|
}
|
|
@@ -2078,7 +3816,7 @@ async function pruneSnapshots(config, dir) {
|
|
|
2078
3816
|
const stats = await Promise.all(
|
|
2079
3817
|
files.map(async (f) => {
|
|
2080
3818
|
try {
|
|
2081
|
-
const s = await
|
|
3819
|
+
const s = await fs3.stat(`${dir}/${f}`);
|
|
2082
3820
|
return { f, mtime: s.mtimeMs };
|
|
2083
3821
|
} catch {
|
|
2084
3822
|
return { f, mtime: 0 };
|
|
@@ -2098,15 +3836,15 @@ async function pruneSnapshots(config, dir) {
|
|
|
2098
3836
|
const isRunDir = /^wf_[0-9a-f]+$/.test(runId);
|
|
2099
3837
|
const deleteArtifacts = isRunDir && !protectedRunIds.has(runId) && !isWorkflowRunPersistenceActive(config, runId);
|
|
2100
3838
|
return Promise.all([
|
|
2101
|
-
|
|
2102
|
-
(e) =>
|
|
3839
|
+
fs3.unlink(`${dir}/${s.f}`).catch(
|
|
3840
|
+
(e) => debugLogger6.warn(`prune unlink failed for ${s.f}: ${e}`)
|
|
2103
3841
|
),
|
|
2104
3842
|
...deleteArtifacts ? [
|
|
2105
|
-
|
|
2106
|
-
|
|
3843
|
+
fs3.rm(
|
|
3844
|
+
path3.dirname(config.storage.getWorkflowRunJournalPath(runId)),
|
|
2107
3845
|
{ recursive: true, force: true }
|
|
2108
3846
|
).catch(
|
|
2109
|
-
(e) =>
|
|
3847
|
+
(e) => debugLogger6.warn(
|
|
2110
3848
|
`prune journal dir failed for ${runId}: ${e}`
|
|
2111
3849
|
)
|
|
2112
3850
|
),
|
|
@@ -2118,12 +3856,162 @@ async function pruneSnapshots(config, dir) {
|
|
|
2118
3856
|
}
|
|
2119
3857
|
__name(pruneSnapshots, "pruneSnapshots");
|
|
2120
3858
|
|
|
3859
|
+
// packages/core/src/skills/workflow-authoring-skill.ts
|
|
3860
|
+
init_esbuild_shims();
|
|
3861
|
+
import { readFileSync } from "node:fs";
|
|
3862
|
+
import * as path4 from "node:path";
|
|
3863
|
+
var debugLogger7 = createDebugLogger("WORKFLOW_AUTHORING_SKILL");
|
|
3864
|
+
var WORKFLOW_AUTHORING_SKILL_NAME = "workflow-authoring";
|
|
3865
|
+
var cachedReference;
|
|
3866
|
+
function referencePath() {
|
|
3867
|
+
return path4.join(
|
|
3868
|
+
resolveBundleDir(import.meta.url),
|
|
3869
|
+
"bundled",
|
|
3870
|
+
WORKFLOW_AUTHORING_SKILL_NAME,
|
|
3871
|
+
"SKILL.md"
|
|
3872
|
+
);
|
|
3873
|
+
}
|
|
3874
|
+
__name(referencePath, "referencePath");
|
|
3875
|
+
function readWorkflowAuthoringReference() {
|
|
3876
|
+
if (cachedReference !== void 0) return cachedReference;
|
|
3877
|
+
try {
|
|
3878
|
+
const filePath = referencePath();
|
|
3879
|
+
const parsed = parseSkillContent(readFileSync(filePath, "utf8"), filePath);
|
|
3880
|
+
cachedReference = { body: parsed.body, baseDir: path4.dirname(filePath) };
|
|
3881
|
+
} catch (error) {
|
|
3882
|
+
debugLogger7.warn(`cannot read the workflow-authoring reference: ${error}`);
|
|
3883
|
+
cachedReference = null;
|
|
3884
|
+
}
|
|
3885
|
+
return cachedReference;
|
|
3886
|
+
}
|
|
3887
|
+
__name(readWorkflowAuthoringReference, "readWorkflowAuthoringReference");
|
|
3888
|
+
function resolveWorkflowAuthoringRoute(config) {
|
|
3889
|
+
try {
|
|
3890
|
+
if (config.getDisabledSkillLevels?.()?.has("bundled")) return "withheld";
|
|
3891
|
+
if (config.isSkillEnabled?.({
|
|
3892
|
+
name: WORKFLOW_AUTHORING_SKILL_NAME,
|
|
3893
|
+
level: "bundled"
|
|
3894
|
+
}) === false) {
|
|
3895
|
+
return "withheld";
|
|
3896
|
+
}
|
|
3897
|
+
if (!config.getSkillManager?.()) return "inline";
|
|
3898
|
+
const registry = config.getToolRegistry?.();
|
|
3899
|
+
const toolNames = registry?.getAllToolNames?.();
|
|
3900
|
+
if (!Array.isArray(toolNames)) return "skill";
|
|
3901
|
+
if (!toolNames.includes(ToolNames.SKILL)) return "inline";
|
|
3902
|
+
if (isToolDeferredBehindToolSearch(config, ToolNames.SKILL)) {
|
|
3903
|
+
return toolNames.includes(ToolNames.TOOL_SEARCH) ? "skill-via-tool-search" : "inline";
|
|
3904
|
+
}
|
|
3905
|
+
return "skill";
|
|
3906
|
+
} catch (error) {
|
|
3907
|
+
debugLogger7.warn(`cannot resolve the workflow-authoring route: ${error}`);
|
|
3908
|
+
return "skill";
|
|
3909
|
+
}
|
|
3910
|
+
}
|
|
3911
|
+
__name(resolveWorkflowAuthoringRoute, "resolveWorkflowAuthoringRoute");
|
|
3912
|
+
function resolveWorkflowAuthoringSurface(config) {
|
|
3913
|
+
const route = resolveWorkflowAuthoringRoute(config);
|
|
3914
|
+
switch (route) {
|
|
3915
|
+
case "skill":
|
|
3916
|
+
return "pointer";
|
|
3917
|
+
case "skill-via-tool-search":
|
|
3918
|
+
return "pointer-via-tool-search";
|
|
3919
|
+
case "withheld":
|
|
3920
|
+
return "withheld";
|
|
3921
|
+
case "inline":
|
|
3922
|
+
return readWorkflowAuthoringReference() ? "inline" : "pointer";
|
|
3923
|
+
default: {
|
|
3924
|
+
const unhandled = route;
|
|
3925
|
+
return unhandled;
|
|
3926
|
+
}
|
|
3927
|
+
}
|
|
3928
|
+
}
|
|
3929
|
+
__name(resolveWorkflowAuthoringSurface, "resolveWorkflowAuthoringSurface");
|
|
3930
|
+
function isToolDeferredBehindToolSearch(config, name) {
|
|
3931
|
+
if (!config.getToolRegistry?.()?.isPermissionDeferred?.(name)) return false;
|
|
3932
|
+
return !config.getVisibleTools?.()?.has(name);
|
|
3933
|
+
}
|
|
3934
|
+
__name(isToolDeferredBehindToolSearch, "isToolDeferredBehindToolSearch");
|
|
3935
|
+
function isToolHiddenBehindToolSearch(config, name) {
|
|
3936
|
+
if (!isToolDeferredBehindToolSearch(config, name)) return false;
|
|
3937
|
+
return !config.getToolRegistry?.()?.isDeferredToolRevealed?.(name);
|
|
3938
|
+
}
|
|
3939
|
+
__name(isToolHiddenBehindToolSearch, "isToolHiddenBehindToolSearch");
|
|
3940
|
+
function toolSearchRevealSentence(toolDisplayName) {
|
|
3941
|
+
return `If the ${toolDisplayName} tool is not in your tool list, reveal it with ToolSearch first.`;
|
|
3942
|
+
}
|
|
3943
|
+
__name(toolSearchRevealSentence, "toolSearchRevealSentence");
|
|
3944
|
+
|
|
3945
|
+
// packages/core/src/agents/runtime/review-workflow.ts
|
|
3946
|
+
init_esbuild_shims();
|
|
3947
|
+
import { createHash as createHash2 } from "node:crypto";
|
|
3948
|
+
import { promises as fs4 } from "node:fs";
|
|
3949
|
+
import path5 from "node:path";
|
|
3950
|
+
var debugLogger8 = createDebugLogger("REVIEW_WORKFLOW");
|
|
3951
|
+
function resolveReviewWorkflowConcurrency(env = process.env) {
|
|
3952
|
+
const configured = parsePositiveIntegerEnv(env[MAX_WORKFLOW_CONCURRENCY_ENV], 0) || parsePositiveIntegerEnv(env["QWEN_CODE_MAX_TOOL_CONCURRENCY"], 10);
|
|
3953
|
+
return resolveConcurrencyLimit({
|
|
3954
|
+
[MAX_WORKFLOW_CONCURRENCY_ENV]: String(configured)
|
|
3955
|
+
});
|
|
3956
|
+
}
|
|
3957
|
+
__name(resolveReviewWorkflowConcurrency, "resolveReviewWorkflowConcurrency");
|
|
3958
|
+
async function resolveReviewWorkflowLimits(scriptPath, generatedDir, scriptContent, env = process.env, nowMs = Date.now()) {
|
|
3959
|
+
let canonicalScript;
|
|
3960
|
+
try {
|
|
3961
|
+
if ((await fs4.lstat(generatedDir)).isSymbolicLink()) return void 0;
|
|
3962
|
+
const generatedRoot = await fs4.realpath(generatedDir);
|
|
3963
|
+
canonicalScript = await fs4.realpath(scriptPath);
|
|
3964
|
+
if (!canonicalScript.startsWith(path5.join(generatedRoot, "review") + path5.sep)) {
|
|
3965
|
+
return void 0;
|
|
3966
|
+
}
|
|
3967
|
+
} catch (error) {
|
|
3968
|
+
if (error.code !== "ENOENT") {
|
|
3969
|
+
debugLogger8.warn(
|
|
3970
|
+
"Cannot classify review workflow; using generic limits:",
|
|
3971
|
+
error
|
|
3972
|
+
);
|
|
3973
|
+
}
|
|
3974
|
+
return void 0;
|
|
3975
|
+
}
|
|
3976
|
+
const digest = /^qwen-review-[a-f0-9]{10}-([a-f0-9]{64})\.js$/.exec(
|
|
3977
|
+
path5.basename(canonicalScript)
|
|
3978
|
+
)?.[1];
|
|
3979
|
+
if (!digest || createHash2("sha256").update(scriptContent).digest("hex") !== digest) {
|
|
3980
|
+
return void 0;
|
|
3981
|
+
}
|
|
3982
|
+
const seconds = Number(env["QWEN_CODE_MAX_WORKFLOW_SECONDS"]);
|
|
3983
|
+
let maxWallClockMs = (Number.isFinite(seconds) && seconds > 0 ? seconds : 6 * 60 * 60) * 1e3;
|
|
3984
|
+
const deadline = Number(env["QWEN_REVIEW_DEADLINE_EPOCH"]);
|
|
3985
|
+
if (Number.isFinite(deadline) && deadline > 0) {
|
|
3986
|
+
const rawFloor = env["QWEN_REVIEW_DEADLINE_COMPOSE_FLOOR_SECONDS"];
|
|
3987
|
+
const floor = Number(rawFloor);
|
|
3988
|
+
const floorSeconds = rawFloor?.trim() && Number.isFinite(floor) && floor >= 0 ? floor : 1200;
|
|
3989
|
+
const remainingMs = deadline * 1e3 - nowMs - floorSeconds * 1e3;
|
|
3990
|
+
if (remainingMs <= 0) {
|
|
3991
|
+
throw new Error(
|
|
3992
|
+
"Review workflow was not launched: the review deadline has reached the compose reserve floor. Recover completed findings and compose now."
|
|
3993
|
+
);
|
|
3994
|
+
}
|
|
3995
|
+
maxWallClockMs = Math.min(maxWallClockMs, remainingMs);
|
|
3996
|
+
}
|
|
3997
|
+
return {
|
|
3998
|
+
subagent: {
|
|
3999
|
+
max_turns: resolveSubagentMaxTurns(env, 500),
|
|
4000
|
+
max_time_minutes: resolveSubagentMaxTimeMinutes(env, 100)
|
|
4001
|
+
},
|
|
4002
|
+
concurrency: resolveReviewWorkflowConcurrency(env),
|
|
4003
|
+
maxWallClockMs
|
|
4004
|
+
};
|
|
4005
|
+
}
|
|
4006
|
+
__name(resolveReviewWorkflowLimits, "resolveReviewWorkflowLimits");
|
|
4007
|
+
|
|
2121
4008
|
export {
|
|
2122
4009
|
extractAndStripMeta,
|
|
2123
4010
|
compileWorkflowScript,
|
|
2124
4011
|
describeWorkflowCompileError,
|
|
2125
|
-
|
|
2126
|
-
|
|
4012
|
+
MAX_TOKENS_PER_WORKFLOW_ENV,
|
|
4013
|
+
resolveMaxTokensPerWorkflow,
|
|
4014
|
+
WorkflowBudgetImpl,
|
|
2127
4015
|
validateWorkflowName,
|
|
2128
4016
|
isSymlinkedRoot,
|
|
2129
4017
|
listSavedWorkflows,
|
|
@@ -2131,11 +4019,31 @@ export {
|
|
|
2131
4019
|
saveWorkflowScript,
|
|
2132
4020
|
persistInlineWorkflowScript,
|
|
2133
4021
|
deleteInlineWorkflowScript,
|
|
4022
|
+
WorkflowJournal,
|
|
4023
|
+
WorkflowDispatchScheduler,
|
|
4024
|
+
DEFAULT_MAX_AGENTS_PER_RUN,
|
|
4025
|
+
MAX_WORKFLOW_AGENTS_ENV,
|
|
4026
|
+
MAX_WORKFLOW_CONCURRENCY_ENV,
|
|
4027
|
+
resolveConcurrencyLimit,
|
|
4028
|
+
DEFAULT_WORKFLOW_SUBAGENT_MAX_TURNS,
|
|
4029
|
+
DEFAULT_WORKFLOW_SUBAGENT_MAX_TIME_MINUTES,
|
|
4030
|
+
WORKFLOW_SUBAGENT_MAX_TURNS_ENV,
|
|
4031
|
+
WORKFLOW_SUBAGENT_MAX_MINUTES_ENV,
|
|
4032
|
+
WorkflowExecutionError,
|
|
4033
|
+
createProductionDispatch,
|
|
4034
|
+
WorkflowOrchestrator,
|
|
2134
4035
|
MAX_RETAINED_SNAPSHOTS,
|
|
2135
4036
|
toSnapshot,
|
|
2136
4037
|
writeWorkflowSnapshot,
|
|
2137
4038
|
listWorkflowSnapshots,
|
|
2138
|
-
deleteWorkflowSnapshot
|
|
4039
|
+
deleteWorkflowSnapshot,
|
|
4040
|
+
resolveReviewWorkflowConcurrency,
|
|
4041
|
+
resolveReviewWorkflowLimits,
|
|
4042
|
+
WORKFLOW_AUTHORING_SKILL_NAME,
|
|
4043
|
+
readWorkflowAuthoringReference,
|
|
4044
|
+
resolveWorkflowAuthoringSurface,
|
|
4045
|
+
isToolHiddenBehindToolSearch,
|
|
4046
|
+
toolSearchRevealSentence
|
|
2139
4047
|
};
|
|
2140
4048
|
/**
|
|
2141
4049
|
* @license
|