@qwen-code/qwen-code 0.24.2 → 0.24.3
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 +4 -0
- package/bundled/qc-helper/docs/configuration/settings.md +1 -1
- package/bundled/qc-helper/docs/features/channels/overview.md +1 -1
- package/bundled/qc-helper/docs/features/code-review.md +3 -1
- package/bundled/qc-helper/docs/qwen-serve.md +1 -1
- package/bundled/qc-helper/docs/support/tos-privacy.md +29 -1
- package/bundled/review/SKILL.md +8 -7
- package/chunks/{MaxSizedBox-ME5JA4KF.js → MaxSizedBox-PVOJQQE2.js} +56 -49
- package/chunks/{StandaloneSessionPicker-W3GFW47V.js → StandaloneSessionPicker-RFTENTTJ.js} +74 -67
- package/chunks/{acp-subagent-executor-ZFDOLQUK.js → acp-subagent-executor-TQP6HLTE.js} +59 -52
- package/chunks/{acpAgent-GRN3VRGG.js → acpAgent-MHLAESGM.js} +203 -162
- package/chunks/{agent-I7GJXDQ2.js → agent-XFGNPR4N.js} +38 -32
- package/chunks/{agent-headless-CHQTBAY4.js → agent-headless-HXOWC5DL.js} +38 -32
- package/chunks/{anthropicContentGenerator-P3PBOK2C.js → anthropicContentGenerator-J22BAFBQ.js} +3 -3
- package/chunks/{artifact-tool-3B3YPLNI.js → artifact-tool-WR4WGBUS.js} +3 -2
- package/chunks/{askUserQuestion-YIK445UI.js → askUserQuestion-X4DR32XO.js} +3 -2
- package/chunks/{bridge-FPDMUBTB.js → bridge-GHWETITW.js} +59 -52
- package/chunks/bwrap-execution-LSZQILPP.js +34 -0
- package/chunks/{caption-audio-V6S7IOLZ.js → caption-audio-MORSEOKW.js} +5 -4
- package/chunks/{caption-image-LKRZR2BO.js → caption-image-XBQMQEWA.js} +5 -4
- package/chunks/{channel-management-service-B5JCH6G4.js → channel-management-service-DISO7Z3P.js} +2 -2
- package/chunks/{channel-settings-store-3QLN4ATE.js → channel-settings-store-7BHSX2TC.js} +63 -56
- package/chunks/{channel-worker-group-M4MSCXVZ.js → channel-worker-group-EJEMLDPE.js} +5 -5
- package/chunks/{channel-worker-manager-UEAF66Y2.js → channel-worker-manager-GI3GMPHV.js} +5 -5
- package/chunks/{channel-worker-supervisor-KNSB6NQS.js → channel-worker-supervisor-GGTS6MM5.js} +4 -4
- package/chunks/{chunk-JQ67JJHH.js → chunk-24TLKGI4.js} +21 -19
- package/chunks/{chunk-MOWCV77B.js → chunk-2FZL7GEG.js} +1 -1
- package/chunks/{chunk-3UOW7K5U.js → chunk-2PZPYVGY.js} +61 -53
- package/chunks/chunk-2SENA3WV.js +2808 -0
- package/chunks/{chunk-WLEIIPES.js → chunk-33E234BQ.js} +2 -2
- package/chunks/{chunk-JPRL7GPK.js → chunk-3QXU5BXM.js} +6 -6
- package/chunks/{chunk-MR5FRME7.js → chunk-3RXCA7OA.js} +2 -2
- package/chunks/{chunk-QBVHHMV4.js → chunk-4BKX4QZQ.js} +5 -5
- package/chunks/chunk-4M7RD5QQ.js +58 -0
- package/chunks/{chunk-2GM7XM6X.js → chunk-4TXKQWKL.js} +1 -1
- package/chunks/{chunk-FMJWXNYH.js → chunk-52TZ7P6X.js} +4 -4
- package/chunks/{chunk-JU5DOXQM.js → chunk-52YTEDEN.js} +1 -1
- package/chunks/{chunk-VE2U4MWB.js → chunk-5AMF3QJJ.js} +58 -32
- package/chunks/{chunk-QEPQKAUY.js → chunk-5E4BPDCX.js} +1 -1
- package/chunks/{chunk-4XNECBYG.js → chunk-5GYRIOWK.js} +1 -1
- package/chunks/{chunk-UKCBRQY5.js → chunk-5HNRXVPC.js} +4 -4
- package/chunks/chunk-5R36APDE.js +70 -0
- package/chunks/{chunk-RJNH4CSX.js → chunk-5VNH3GBD.js} +35 -5
- package/chunks/{chunk-TPDNW6O5.js → chunk-5XEZQQG3.js} +0 -8
- package/chunks/{chunk-D4JFXQ6K.js → chunk-64T2EGVQ.js} +3 -3
- package/chunks/{chunk-3J43HE2J.js → chunk-6GI7NAZS.js} +1 -1
- package/chunks/{chunk-GPKTOXFJ.js → chunk-6LXGKCPH.js} +2 -2
- package/chunks/{chunk-UE4ZRIXK.js → chunk-6XGXRH2Q.js} +1 -1
- package/chunks/{chunk-UZTJ5WJA.js → chunk-73R6BAOK.js} +1 -1
- package/chunks/{chunk-ICISMV7V.js → chunk-7GHC7XR7.js} +4 -4
- package/chunks/{chunk-AB5N5FEG.js → chunk-7HI22VYF.js} +1 -1
- package/chunks/{chunk-U5JK32FE.js → chunk-7JDVJX7A.js} +28 -5857
- package/chunks/{chunk-6GB4CDE4.js → chunk-A5UPWU53.js} +2 -2
- package/chunks/{chunk-7HMBOUQG.js → chunk-A5XFEBME.js} +3 -3
- package/chunks/{chunk-JG23BJ7Y.js → chunk-AJSG5SMC.js} +2 -2
- package/chunks/{chunk-7PQVNBGJ.js → chunk-AJTDW2YD.js} +6 -6
- package/chunks/{chunk-TICLGWQT.js → chunk-AOYY54ZY.js} +1 -1
- package/chunks/{chunk-E6UTJIPI.js → chunk-ATZ4RQ6I.js} +1 -1
- package/chunks/{chunk-QCCRC27E.js → chunk-AV3FOXNF.js} +1 -1
- package/chunks/{chunk-EDJCJMEW.js → chunk-B3UM2NWK.js} +1 -1
- package/chunks/{chunk-MJJQ5LM4.js → chunk-BC2TGXIK.js} +2 -2
- package/chunks/{chunk-T4D3QLUZ.js → chunk-BHU5SD32.js} +1 -1
- package/chunks/{chunk-2G3I5XLI.js → chunk-BTDQWQE7.js} +3 -3
- package/chunks/{chunk-42QJ7NLB.js → chunk-BVNEEYJM.js} +4 -55
- package/chunks/{chunk-XXXA63AB.js → chunk-CEG3V62N.js} +1 -1
- package/chunks/{chunk-GT3O7YG4.js → chunk-CGIKEQFI.js} +6 -6
- package/chunks/{chunk-65I7S4Z3.js → chunk-CHBZHMBA.js} +2 -35
- package/chunks/{chunk-GSMPCYYA.js → chunk-CJ2NHFIU.js} +8 -8
- package/chunks/{chunk-M64HFJ3A.js → chunk-D42TSQKU.js} +1 -1
- package/chunks/{chunk-NRWMNRBC.js → chunk-D4K23BD4.js} +1 -1
- package/chunks/{chunk-FSEZM6ZQ.js → chunk-DACSVV23.js} +1 -1
- package/chunks/{chunk-SHLIELH4.js → chunk-DBYIRDFG.js} +4 -4
- package/chunks/{chunk-ISF3Z6VK.js → chunk-DEY4A6ZJ.js} +1 -1
- package/chunks/{chunk-ES2Y3FEA.js → chunk-EJUVYCCB.js} +1 -1
- package/chunks/chunk-ELYIK7SN.js +47 -0
- package/chunks/{chunk-TSVKTGQ4.js → chunk-EPBR5TO4.js} +2 -2
- package/chunks/{chunk-4LDMRC23.js → chunk-EVNJAS37.js} +10 -7
- package/chunks/{chunk-UGLJ75YV.js → chunk-F2VBZ6LC.js} +4 -4
- package/chunks/{chunk-CCOIMIDP.js → chunk-F3JJ5TAQ.js} +9 -7
- package/chunks/{chunk-CK267TVO.js → chunk-FPFIAK47.js} +2 -2
- package/chunks/{chunk-PETY4UMR.js → chunk-FRC4RVRG.js} +1 -1
- package/chunks/{chunk-Q554UD37.js → chunk-FS5KMPLT.js} +1 -1
- package/chunks/{chunk-RAHX5SNW.js → chunk-FTJYHKI7.js} +1 -1
- package/chunks/{chunk-LKV5IRBA.js → chunk-FVACI3OI.js} +3 -3
- package/chunks/{chunk-QTEONSAO.js → chunk-G4DQHGSF.js} +3 -3
- package/chunks/{chunk-3SQIYYDQ.js → chunk-G7CUNATW.js} +1 -1
- package/chunks/{chunk-INLMCZR4.js → chunk-GKFEDGAE.js} +2 -2
- package/chunks/{chunk-MYXULCXF.js → chunk-GNGQGEZD.js} +1 -1
- package/chunks/{chunk-N63V7CTG.js → chunk-H5VUUFVD.js} +1 -1
- package/chunks/{chunk-RFVQJSIW.js → chunk-HDRYBFLF.js} +2 -2
- package/chunks/{chunk-EMG7QXJD.js → chunk-HZ5VA3H3.js} +5 -5
- package/chunks/{chunk-IXWDQRM4.js → chunk-HZU2DMPO.js} +12 -12
- package/chunks/{chunk-FDW5VK44.js → chunk-I3K2QRZ5.js} +1 -1
- package/chunks/{chunk-OMHE7I7L.js → chunk-IODSADQ4.js} +1 -1
- package/chunks/{chunk-ANKISCKU.js → chunk-JBUMBQAO.js} +12 -2
- package/chunks/{chunk-3TJ7LPMA.js → chunk-JCTHL2AB.js} +2 -2
- package/chunks/{chunk-2TK7KLDO.js → chunk-JXNPH2EP.js} +2 -2
- package/chunks/{chunk-SA4UQS3Y.js → chunk-KEIOGBLQ.js} +1 -1
- package/chunks/{chunk-XBOKF4YG.js → chunk-KL2BAPK7.js} +2180 -594
- package/chunks/{chunk-W2GM3FPJ.js → chunk-KORAYUXN.js} +16 -14
- package/chunks/{chunk-FJWGA4KA.js → chunk-KTKMSEN2.js} +5 -5
- package/chunks/{chunk-TAANUOHC.js → chunk-LFIKUSEE.js} +1 -1
- package/chunks/{chunk-VQUX7GWP.js → chunk-LWQKWO5I.js} +1710 -3754
- package/chunks/{chunk-ZHJSA55C.js → chunk-MHDXEHU5.js} +1 -1
- package/chunks/{chunk-LCMK6QMW.js → chunk-MJY6NCQF.js} +19 -17
- package/chunks/{chunk-DYGOUAKK.js → chunk-MNM5AZTY.js} +1 -1
- package/chunks/{chunk-UVZY7QW2.js → chunk-MSX7BUUO.js} +2 -2
- package/chunks/{chunk-REXIMUUM.js → chunk-N6APTOMX.js} +1 -1
- package/chunks/{chunk-QO2IAC7M.js → chunk-NAH3EHAD.js} +4 -4
- package/chunks/{chunk-D2YMJSVP.js → chunk-NBAZASOT.js} +16 -16
- package/chunks/{chunk-JPYUKGCM.js → chunk-NL5EDW4G.js} +3 -3
- package/chunks/{chunk-RGD7JAX6.js → chunk-NOTDB3KX.js} +34 -21
- package/chunks/{chunk-U6YCUEJQ.js → chunk-NSQYCACH.js} +2 -2
- package/chunks/chunk-NXRQI7RF.js +5861 -0
- package/chunks/{chunk-7WIDY7UD.js → chunk-O4OOA2XB.js} +4 -4
- package/chunks/{chunk-SZBKX3U3.js → chunk-ONVXBTN3.js} +4 -4
- package/chunks/{chunk-3GH6T7SH.js → chunk-OOBJCVOC.js} +11 -11
- package/chunks/{chunk-64LX7PWR.js → chunk-OOGQBSTQ.js} +99 -55
- package/chunks/{chunk-DPZAQ4XR.js → chunk-OTKB5NBZ.js} +8 -8
- package/chunks/{chunk-TDWH5KJE.js → chunk-OU26ZZOL.js} +1 -1
- package/chunks/{chunk-5YJEHFWB.js → chunk-OUKL6WIM.js} +2 -2
- package/chunks/{chunk-LELCSQ67.js → chunk-PI3663GU.js} +3 -3
- package/chunks/{chunk-E5JQUFYU.js → chunk-PPLSJANE.js} +2 -2
- package/chunks/{chunk-EMK56JRM.js → chunk-PYFGVKPR.js} +2 -2
- package/chunks/{chunk-X5N23GYD.js → chunk-Q2TJZRNE.js} +2 -2
- package/chunks/{chunk-TOCM6MGP.js → chunk-QQSN6DYY.js} +2 -2
- package/chunks/{chunk-5FATGXYO.js → chunk-SCCA4KIA.js} +8 -8
- package/chunks/{chunk-2PZMELFA.js → chunk-T4EEDGIV.js} +8 -8
- package/chunks/{chunk-QHBVY32Y.js → chunk-TEFMMDNL.js} +11 -11
- package/chunks/{chunk-DBOYH5UO.js → chunk-TK5X3N6Z.js} +1 -1
- package/chunks/{chunk-K2PTCHZG.js → chunk-TNANUFVW.js} +33 -27
- package/chunks/{chunk-MXOOWEZK.js → chunk-TTAC3FUB.js} +1 -1
- package/chunks/{chunk-5ROHUAQL.js → chunk-TULCOWNT.js} +8 -8
- package/chunks/{chunk-BJEZBTUO.js → chunk-TUYJ6S3L.js} +1 -1
- package/chunks/{chunk-KLL6VL42.js → chunk-TW7KLLRI.js} +46 -21
- package/chunks/{chunk-AK35QRVW.js → chunk-U5P7R5TF.js} +2 -2
- package/chunks/{chunk-PGYKW4PY.js → chunk-UI5A24EA.js} +1 -1
- package/chunks/{chunk-VYCIVHT7.js → chunk-URFKH5UA.js} +50 -29
- package/chunks/{chunk-AFLJYB2T.js → chunk-UYW4ZR6P.js} +5 -5
- package/chunks/{chunk-R6MPLPS7.js → chunk-V4VSJQKD.js} +2 -2
- package/chunks/{chunk-GZJLGE6Y.js → chunk-VBEEYWD5.js} +3 -3
- package/chunks/{chunk-TCO2ZOLV.js → chunk-VD66W3RA.js} +3 -3
- package/chunks/{chunk-5XWVWTLB.js → chunk-VM3RQNIN.js} +2 -2
- package/chunks/{chunk-HYLPVFWL.js → chunk-VT3MGD7H.js} +1 -1
- package/chunks/{chunk-6FZEVPBU.js → chunk-VZ6YDHDV.js} +1 -1
- package/chunks/{chunk-BIQXRY5B.js → chunk-W4T4DHDJ.js} +86 -5
- package/chunks/{chunk-GULGI7D3.js → chunk-WJ4NNSW7.js} +6 -6
- package/chunks/{chunk-GI7MRANQ.js → chunk-WJ6HMAU7.js} +3 -3
- package/chunks/{chunk-KVMLTZTU.js → chunk-WK5KFFP6.js} +1 -1
- package/chunks/{chunk-MOTCWW3N.js → chunk-WMHO25KU.js} +2 -2
- package/chunks/{chunk-TBVO3WMD.js → chunk-WQ7QSGFJ.js} +1 -1
- package/chunks/{chunk-4ZYD4QI5.js → chunk-WXHBA2D3.js} +1 -1
- package/chunks/{chunk-2I5YG2XF.js → chunk-X4ILFHRH.js} +1 -1
- package/chunks/{chunk-O6NXPJIT.js → chunk-XLN46XQ2.js} +11 -11
- package/chunks/{chunk-CXXHL3XJ.js → chunk-XPXMRRG3.js} +1 -1
- package/chunks/{chunk-ZJSCBHAJ.js → chunk-Y62EC3SO.js} +7 -7
- package/chunks/{chunk-S564PKIP.js → chunk-YAQ6GGRB.js} +1 -1
- package/chunks/{chunk-2VYTJ4MO.js → chunk-YDX2EK5J.js} +4 -4
- package/chunks/{chunk-PKX5AAEO.js → chunk-YIVRT5RA.js} +1 -1
- package/chunks/chunk-YPKYQHFS.js +25 -0
- package/chunks/{chunk-LCIR5C23.js → chunk-YWRTS5OJ.js} +3 -3
- package/chunks/{chunk-N75DNP5S.js → chunk-YYNQG3JO.js} +1 -1
- package/chunks/{chunk-IE7SAZGL.js → chunk-Z6Y6SFX7.js} +1 -1
- package/chunks/chunk-ZWMLPCLV.js +168 -0
- package/chunks/{clip-audio-OL5ZHBOH.js → clip-audio-4GTC7XXJ.js} +3 -2
- package/chunks/{clip-image-GKDHKWSA.js → clip-image-CVP6R7WG.js} +3 -2
- package/chunks/{clip-video-OE4GBBS2.js → clip-video-RMIOCVAT.js} +3 -2
- package/chunks/{codex-subagent-executor-XTYEHFTH.js → codex-subagent-executor-JQPB5UH6.js} +61 -54
- package/chunks/{config-utils-A7FSZDCO.js → config-utils-3PL3OQOI.js} +57 -50
- package/chunks/{container-execution-environment-XS6X47MH.js → container-execution-environment-RPXKL3HT.js} +9 -0
- package/chunks/{contextCommand-ODDENDGH.js → contextCommand-Z6ZTWN7F.js} +57 -50
- package/chunks/{convert-image-JT75DK5E.js → convert-image-24SLHDCH.js} +3 -2
- package/chunks/{core-runtime-7OWIKZP7.js → core-runtime-5KHWEMVQ.js} +55 -48
- package/chunks/{create-sub-session-MNPEQ4J2.js → create-sub-session-3RVVDCXG.js} +3 -2
- package/chunks/{create-sub-session-YFYNWAU3.js → create-sub-session-FB5YJFI5.js} +56 -49
- package/chunks/{cron-create-RHRWMLNX.js → cron-create-NXQ27MQQ.js} +2 -1
- package/chunks/{cron-delete-CTZBKOT2.js → cron-delete-2F75IAB5.js} +2 -1
- package/chunks/{cron-list-SGNRBA52.js → cron-list-7IEDSU4D.js} +2 -1
- package/chunks/{daemon-BPTR7VCR.js → daemon-25CH5S3X.js} +4 -1
- package/chunks/{daemon-git-worktree-guard-SJ7YWRBD.js → daemon-git-worktree-guard-LQ3XGSBU.js} +57 -50
- package/chunks/{daemon-status-provider-MCQ3OGR5.js → daemon-status-provider-PCJP7L7Z.js} +64 -57
- package/chunks/{daemon-trust-policy-BUGBZHZX.js → daemon-trust-policy-KXZY6JQN.js} +61 -54
- package/chunks/{daemon-trust-policy-monitor-7Q7XOMIB.js → daemon-trust-policy-monitor-QAZ4KXVK.js} +61 -54
- package/chunks/{deferred-core-runtime-Q2534BF7.js → deferred-core-runtime-UCXREDYD.js} +55 -48
- package/chunks/{display-image-XBM4DXNT.js → display-image-WYMDGOWV.js} +3 -2
- package/chunks/{downsample-audio-ZVH75DNJ.js → downsample-audio-T5P5IEPZ.js} +3 -2
- package/chunks/{downsample-image-4D6XYIRR.js → downsample-image-6L67FEII.js} +3 -2
- package/chunks/{downscale-video-CPSH7IDV.js → downscale-video-RYVKNSAU.js} +3 -2
- package/chunks/{edit-H5N6BDMS.js → edit-VPPFWFX7.js} +40 -33
- package/chunks/{enter-worktree-4TWVSLRD.js → enter-worktree-UF4HQH7B.js} +7 -5
- package/chunks/{enterPlanMode-WTIJMZPK.js → enterPlanMode-6TDM4B6A.js} +38 -32
- package/chunks/{environment-BHQMXGGR.js → environment-FXLJ7ENW.js} +57 -50
- package/chunks/{errors-Q3CZYRPL.js → errors-S6CL7DPU.js} +57 -50
- package/chunks/{exec-YFYZG5FI.js → exec-G6SFU4KT.js} +2 -1
- package/chunks/{execution-tool-RXGXRHKL.js → execution-tool-5OEN4XN4.js} +41 -34
- package/chunks/{execution-worker-5FBYMFHO.js → execution-worker-SNHQA7RC.js} +49 -42
- package/chunks/{exit-worktree-X5TWEER7.js → exit-worktree-KGKIHZF7.js} +7 -5
- package/chunks/{exitPlanMode-55IBAAUE.js → exitPlanMode-ZCPQQO2Q.js} +38 -32
- package/chunks/{extract-audio-WMI3JVZW.js → extract-audio-5YD7BSS3.js} +3 -2
- package/chunks/{extract-keyframes-XWYFKXJY.js → extract-keyframes-6SMSQOK5.js} +3 -2
- package/chunks/{fast-path-2QQ5KBFD.js → fast-path-VTQRLIDS.js} +6 -6
- package/chunks/{fast-path-settings-TLOSL5ML.js → fast-path-settings-4BKAJEUA.js} +3 -2
- package/chunks/{glob-VTPB5X62.js → glob-WUNZEBU7.js} +39 -33
- package/chunks/{goal-tools-YHMFTEOO.js → goal-tools-FWW63AA2.js} +38 -32
- package/chunks/{grep-AXABIEJD.js → grep-AIFXREQI.js} +4 -3
- package/chunks/{handleAutoUpdate-C3NOVKTN.js → handleAutoUpdate-H5X5JCSF.js} +58 -51
- package/chunks/{i18n-MSGWV3QQ.js → i18n-BRMNE6B6.js} +56 -49
- package/chunks/{image-gen-JK7PLS5E.js → image-gen-F4QUJLNV.js} +2 -1
- package/chunks/{initializer-HWN6XOPB.js → initializer-ZUO7ORBA.js} +61 -54
- package/chunks/{installationInfo-ABC2KRUN.js → installationInfo-DTMVU7BI.js} +55 -48
- package/chunks/{list-LF3J3XDD.js → list-EEGHEIRM.js} +64 -57
- package/chunks/{list-agents-6EQJPTZS.js → list-agents-QYEGD7BM.js} +2 -1
- package/chunks/{llm-NO6O6P34.js → llm-5E4HK3VQ.js} +144 -118
- package/chunks/{llm-content-generator-7HAG22CO.js → llm-content-generator-Z772NKES.js} +3 -3
- package/chunks/{loadedSettingsAdapter-AVY5HFYC.js → loadedSettingsAdapter-BCWAHAEI.js} +61 -54
- package/chunks/{local-execution-environment-APGBUWE4.js → local-execution-environment-W6LZ7CUB.js} +49 -42
- package/chunks/{loggingContentGenerator-4L2WNHZ6.js → loggingContentGenerator-OOHXYIMS.js} +40 -34
- package/chunks/{loop-wakeup-RF3XTGKT.js → loop-wakeup-76JNT4WU.js} +2 -1
- package/chunks/{ls-FDTLJBRV.js → ls-D7KTHDNN.js} +3 -2
- package/chunks/{lsp-DFJWXIPB.js → lsp-6UUCOSFX.js} +2 -1
- package/chunks/{managed-npm-update-J2ZPD66O.js → managed-npm-update-TDTR2CXP.js} +55 -48
- package/chunks/{mcp-3PIE3HYX.js → mcp-H7KOGB3R.js} +61 -54
- package/chunks/{model-call-collection-ZGJESJQG.js → model-call-collection-6XWFC7TH.js} +4 -3
- package/chunks/{model-configuration-TIUNBSA7.js → model-configuration-LQV2CJZZ.js} +61 -54
- package/chunks/{modelConfigUtils-5AOF7V2F.js → modelConfigUtils-3MJ6OTIS.js} +56 -49
- package/chunks/{monitor-KQQHCVPC.js → monitor-SXFWYHEN.js} +147 -80
- package/chunks/{nonInteractiveCli-DRHFARV2.js → nonInteractiveCli-JUWSNYL2.js} +100 -93
- package/chunks/{nonInteractiveToolExecutor-ZT47OSWE.js → nonInteractiveToolExecutor-3M2TJ5RN.js} +39 -33
- package/chunks/{notebook-edit-W2BQ4QPF.js → notebook-edit-BSQYYXUQ.js} +39 -33
- package/chunks/{ocr-image-2PSF2IAR.js → ocr-image-5S3CK7CF.js} +5 -4
- package/chunks/{omni-TNXXOXEW.js → omni-VT3TTIHP.js} +13 -12
- package/chunks/{openaiContentGenerator-G73YTTX6.js → openaiContentGenerator-4QM3346J.js} +17 -14
- package/chunks/{openaiResponsesContentGenerator-GT2QA7HT.js → openaiResponsesContentGenerator-KNBUZDP3.js} +2 -2
- package/chunks/{pidfile-65TYNQZO.js → pidfile-3HRF6UJA.js} +55 -48
- package/chunks/{processUtils-OYVVZD7E.js → processUtils-V56V4PBU.js} +2 -2
- package/chunks/{prompt-terminal-ledger-SOHAMM2Z.js → prompt-terminal-ledger-WOPLWLBQ.js} +56 -49
- package/chunks/{qwenContentGenerator-3FMMD3SU.js → qwenContentGenerator-VQ7N3TOC.js} +41 -35
- package/chunks/{reactive-degrade-RCHTZLHO.js → reactive-degrade-FPODY2BC.js} +10 -9
- package/chunks/{read-file-ZO5MAQRF.js → read-file-GQLJ3M7Z.js} +10 -7
- package/chunks/{read-mcp-resource-B2GMAZPJ.js → read-mcp-resource-5LHGYLKO.js} +2 -1
- package/chunks/{recall-media-memory-tool-LV4MEI4V.js → recall-media-memory-tool-KJSYTPWC.js} +2 -1
- package/chunks/{record-artifact-YZC2JO6M.js → record-artifact-HBLFENQR.js} +5 -3
- package/chunks/{record-source-UD4VB654.js → record-source-R573ATSB.js} +6 -5
- package/chunks/{report-findings-3VDQHUWI.js → report-findings-KJ4TYZ36.js} +6 -4
- package/chunks/{request-shutdown-IIQL6AP6.js → request-shutdown-NO5ZWADD.js} +5 -4
- package/chunks/{resumeHistoryUtils-WVAODL3D.js → resumeHistoryUtils-7LZ5SWKC.js} +61 -54
- package/chunks/{ripGrep-ICSMQC67.js → ripGrep-TBN4ADUY.js} +13 -10
- package/chunks/{run-qwen-serve-7JVXBD5X.js → run-qwen-serve-6GXQP7DD.js} +345 -122
- package/chunks/{runtime-SPDHMWL2.js → runtime-PBC4QVLS.js} +64 -57
- package/chunks/{sandbox-AGO4URGF.js → sandbox-SXY2ZJDN.js} +63 -56
- package/chunks/{sandboxConfig-GQSKEK3A.js → sandboxConfig-WZHAEK3H.js} +56 -49
- package/chunks/{scheduled-tasks-NESFIYHB.js → scheduled-tasks-WEC66H2D.js} +62 -55
- package/chunks/{scheduler-IMSC6H47.js → scheduler-MPMBQKNN.js} +57 -50
- package/chunks/{sdk-exporters-http-33ZUNG6F.js → sdk-exporters-http-LOJRQMTP.js} +2 -1
- package/chunks/{sdk-impl-UDJ5SKN5.js → sdk-impl-GRYEDRD7.js} +4 -3
- package/chunks/{send-message-5VICTSBX.js → send-message-POBGHN4M.js} +5 -4
- package/chunks/{serve-GE2YQFZW.js → serve-EV4HTTAM.js} +61 -54
- package/chunks/{server-LZDC5WLZ.js → server-KQJAQD55.js} +322 -189
- package/chunks/{session-NAL5T5QR.js → session-IRBWRKQX.js} +101 -94
- package/chunks/{session-attachments-root-SDTVDDHX.js → session-attachments-root-L75Y47VK.js} +55 -48
- package/chunks/{session-pr-refresh-QLHN7R76.js → session-pr-refresh-5MHLCSC2.js} +61 -54
- package/chunks/{settings-WC7MAKFU.js → settings-MI63DAKE.js} +60 -53
- package/chunks/{shell-UE45BTE7.js → shell-AQVVGISM.js} +38 -32
- package/chunks/{skill-NDQFTO4T.js → skill-VBSS653C.js} +12 -9
- package/chunks/{skill-settings-5QJZJXOA.js → skill-settings-MNLFQXDX.js} +61 -54
- package/chunks/{spawnChannel-DOUIQJXZ.js → spawnChannel-DMP56IUE.js} +58 -51
- package/chunks/{standalone-update-2DN4ELDA.js → standalone-update-I3RV7IE7.js} +57 -50
- package/chunks/{start-opentui-ui-LA3LPF6Y.js → start-opentui-ui-GJOXXN5L.js} +133 -124
- package/chunks/{startInteractiveUI-FESZ72F3.js → startInteractiveUI-TBIQDZLE.js} +139 -131
- package/chunks/{syntheticOutput-IBR4IZUU.js → syntheticOutput-DTUQ3N3J.js} +3 -2
- package/chunks/{task-create-LTAMU773.js → task-create-2LMS6ZFJ.js} +6 -5
- package/chunks/{task-list-JROVWKLY.js → task-list-D22BRKR6.js} +2 -1
- package/chunks/{task-stop-MHQKQDFQ.js → task-stop-UZDE2G5W.js} +3 -2
- package/chunks/{task-update-RMYMZM6A.js → task-update-RHBIB6YU.js} +6 -5
- package/chunks/{team-create-YNUMJ5GO.js → team-create-K7QPZ6P2.js} +40 -34
- package/chunks/{team-delete-EX7BR2LA.js → team-delete-WG4S3QD4.js} +2 -1
- package/chunks/{team-plan-approval-AZXG3HFN.js → team-plan-approval-LMMXJ44D.js} +38 -32
- package/chunks/{terminal-image-renderer-ZNSJFZVA.js → terminal-image-renderer-SU2YYNAJ.js} +57 -50
- package/chunks/{theme-manager-5HQOVK6C.js → theme-manager-BC6DCE6C.js} +55 -48
- package/chunks/{todoWrite-BF3INMCU.js → todoWrite-2DRDC5EG.js} +2 -1
- package/chunks/{tool-call-ZVU2G5XX.js → tool-call-WBTV7ZZW.js} +6 -5
- package/chunks/{tool-result-media-CGSR3JMM.js → tool-result-media-DACFNH2O.js} +10 -9
- package/chunks/{tool-search-ANXFKRMW.js → tool-search-Y3NA5GTO.js} +13 -10
- package/chunks/{total-session-admission-YBOZM7OG.js → total-session-admission-VXAFAHGR.js} +59 -52
- package/chunks/{transcribe-audio-AQZWRIF5.js → transcribe-audio-HGBJBFP4.js} +4 -3
- package/chunks/{trustedFolders-4ANVY47B.js → trustedFolders-PGLKXLUG.js} +56 -49
- package/chunks/{understand-video-segments-R2UXRHKY.js → understand-video-segments-5NFKV5QK.js} +5 -4
- package/chunks/{update-relaunch-A66PFRWV.js → update-relaunch-35THHY6N.js} +5 -5
- package/chunks/{updateCheck-CGW4ZICA.js → updateCheck-AU6FFINN.js} +57 -50
- package/chunks/{upload-config-53PGAD6C.js → upload-config-2DB2HD4X.js} +4 -4
- package/chunks/{useAutoAcceptIndicator-LCCWXBQX.js → useAutoAcceptIndicator-K3M2TEIO.js} +62 -55
- package/chunks/{validateNonInterActiveAuth-HGHZE5G5.js → validateNonInterActiveAuth-KTKBE2G4.js} +97 -90
- package/chunks/{version-AYPF2XZG.js → version-SGFPFOBG.js} +1 -1
- package/chunks/{web-fetch-BCIFCTLU.js → web-fetch-ME4GDH77.js} +12 -9
- package/chunks/{web-search-E262B3IC.js → web-search-7EZABURD.js} +6 -5
- package/chunks/{web-shell-static-G654DFN2.js → web-shell-static-4SY6HOTM.js} +4 -3
- package/chunks/{workflow-5UJVVBKP.js → workflow-IZZNKNON.js} +41 -35
- package/chunks/{workspace-providers-status-ZNWPVLFH.js → workspace-providers-status-AA7TXXGS.js} +66 -59
- package/chunks/{workspace-registration-store-CSOD2L3Q.js → workspace-registration-store-OLL5737M.js} +1 -1
- package/chunks/{workspace-registry-YLT7CXIQ.js → workspace-registry-7M2GJXVY.js} +59 -52
- package/chunks/{workspace-runtime-coordinator-VRJNYOYA.js → workspace-runtime-coordinator-644IZPWD.js} +60 -53
- package/chunks/{workspace-service-LD63VWNX.js → workspace-service-RJOV7URE.js} +65 -58
- package/chunks/{workspace-skills-status-OXAHXVR5.js → workspace-skills-status-TYYFTIPU.js} +64 -57
- package/chunks/{workspace-trust-reconciler-EMAYOLR6.js → workspace-trust-reconciler-64FF3I3X.js} +65 -58
- package/chunks/{write-file-GSN6CT5R.js → write-file-GWRXJDPC.js} +41 -34
- package/chunks/{zoom-image-5CPVN2KD.js → zoom-image-CNMQP3QF.js} +12 -9
- package/cli.js +12 -12
- package/execution-worker.js +1 -1
- package/export-transcript-document.css +1 -1
- package/export-transcript-document.js +105 -101
- package/package.json +3 -3
- package/sandboxBwrapRelay.js +29 -3
- package/web-shell/assets/{abnfDiagram-VCTEODGH-BoGedP8r.js → abnfDiagram-VCTEODGH-DjZkVYSo.js} +1 -1
- package/web-shell/assets/{arc-B0xm-EAq.js → arc-BVsUeysQ.js} +1 -1
- package/web-shell/assets/{architectureDiagram-5GKGNRK7-DiNagfRJ.js → architectureDiagram-5GKGNRK7-Ctfncb9S.js} +1 -1
- package/web-shell/assets/{blockDiagram-NRAW4CY4-EEcQWUWl.js → blockDiagram-NRAW4CY4-jFV9xKqs.js} +1 -1
- package/web-shell/assets/{c4Diagram-UCG6FXSJ-BvW_nn93.js → c4Diagram-UCG6FXSJ-CU_A3x5O.js} +1 -1
- package/web-shell/assets/capture-worklet-DvBxuiSL.js +76 -0
- package/web-shell/assets/channel-CE8bZRZ2.js +1 -0
- package/web-shell/assets/{chunk-2Q5K7J3B-B4jI17Cn.js → chunk-2Q5K7J3B-CDlmNk5p.js} +1 -1
- package/web-shell/assets/{chunk-5VM5RSS4-BJqaAvlZ.js → chunk-5VM5RSS4-BMiAkn3U.js} +1 -1
- package/web-shell/assets/{chunk-F27PBJKO-C0Ju4Hf-.js → chunk-F27PBJKO-Bvz9m7YM.js} +1 -1
- package/web-shell/assets/{chunk-G27WJ6UU-I1BYIJwg.js → chunk-G27WJ6UU-CGs4AxN_.js} +1 -1
- package/web-shell/assets/{chunk-JWPE2WC7-Cnyab3JU.js → chunk-JWPE2WC7-CKPFVJ7h.js} +1 -1
- package/web-shell/assets/{chunk-LCL6LL3I-DV-HUbga.js → chunk-LCL6LL3I-Dt_Ff67h.js} +1 -1
- package/web-shell/assets/{chunk-POPQ4Y6H-zromK3LN.js → chunk-POPQ4Y6H-D3wHu3Ch.js} +1 -1
- package/web-shell/assets/{chunk-SVP7TREG-CRTcS0Li.js → chunk-SVP7TREG-NFtvrgz1.js} +1 -1
- package/web-shell/assets/{chunk-XXDRQBXY-C7t9Y5dp.js → chunk-XXDRQBXY-Cw03Ej3w.js} +1 -1
- package/web-shell/assets/classDiagram-DTDB5LWJ-1hCsbRjl.js +1 -0
- package/web-shell/assets/classDiagram-v2-JRS7N3AN-1hCsbRjl.js +1 -0
- package/web-shell/assets/{cose-bilkent-JH36ORCC-pYqimMDR.js → cose-bilkent-JH36ORCC-DFD3DmsV.js} +1 -1
- package/web-shell/assets/{cynefin-OW5HDTMX-CZE7POLH.js → cynefin-OW5HDTMX-Daym82U1.js} +1 -1
- package/web-shell/assets/{cynefinDiagram-5FMLGOSQ-DAiwFQTo.js → cynefinDiagram-5FMLGOSQ-CTa5PgQ3.js} +1 -1
- package/web-shell/assets/{dagre-3AP2YEHR-CujXJf4M.js → dagre-3AP2YEHR-CuORvpUv.js} +1 -1
- package/web-shell/assets/{diagram-S7CK7UJ4-jA7L0GxC.js → diagram-S7CK7UJ4-Ds71He45.js} +1 -1
- package/web-shell/assets/{diagram-UQ7AKVKN-Cq-AJp-u.js → diagram-UQ7AKVKN-DEWbfBhf.js} +1 -1
- package/web-shell/assets/{diagram-VSXAHHWV-Drk-2m9j.js → diagram-VSXAHHWV-moxkWVTb.js} +1 -1
- package/web-shell/assets/{diagram-VX7I27RA-BvjF2q85.js → diagram-VX7I27RA-DMtWByXT.js} +1 -1
- package/web-shell/assets/{diagram-Z3DM3KII-DFFJyEWC.js → diagram-Z3DM3KII-D8csrww3.js} +1 -1
- package/web-shell/assets/{ebnfDiagram-PWID7BFC-552tv6tR.js → ebnfDiagram-PWID7BFC-CijCPSwq.js} +1 -1
- package/web-shell/assets/{erDiagram-SSCWMZ5O-BO6qRo35.js → erDiagram-SSCWMZ5O-Bz0f1Ytn.js} +1 -1
- package/web-shell/assets/{flowDiagram-A5DVABFB-DCxuaOR6.js → flowDiagram-A5DVABFB-BjN3xBgP.js} +1 -1
- package/web-shell/assets/{ganttDiagram-EL5Y4UJY-BkKh0yeR.js → ganttDiagram-EL5Y4UJY-CossRCD9.js} +1 -1
- package/web-shell/assets/{gitGraphDiagram-WWUBYQGX-BQlQLZ8w.js → gitGraphDiagram-WWUBYQGX-BCpZDwQX.js} +1 -1
- package/web-shell/assets/{index-lb-zgZOV.js → index-C-WVh8Fm.js} +1 -1
- package/web-shell/assets/{index-B0bERnDx.js → index-CIE7rUer.js} +524 -489
- package/web-shell/assets/index-LyplXTTk.css +36 -0
- package/web-shell/assets/{infoDiagram-RXCK75RN-7Ba9Yqy8.js → infoDiagram-RXCK75RN-C2Vwsw4Z.js} +1 -1
- package/web-shell/assets/{ishikawaDiagram-5VMMS53U-I6Gp1QB4.js → ishikawaDiagram-5VMMS53U-DkDEBYFn.js} +1 -1
- package/web-shell/assets/{journeyDiagram-EYS64GPL-BhgZwHgO.js → journeyDiagram-EYS64GPL-DCTEMRE3.js} +1 -1
- package/web-shell/assets/{kanban-definition-3QL26DDD-D9Dp43hm.js → kanban-definition-3QL26DDD-D1r1XE8n.js} +1 -1
- package/web-shell/assets/{layout-CgsZclxS.js → layout-CX0-JUt4.js} +1 -1
- package/web-shell/assets/{linear-Drh5DEW5.js → linear-Bg6PoA8B.js} +1 -1
- package/web-shell/assets/{mermaid.core-CDSrg0Wk.js → mermaid.core-q6WTQapr.js} +6 -6
- package/web-shell/assets/{mindmap-definition-FBJOCRG2-C6EqGkzE.js → mindmap-definition-FBJOCRG2-CsQVNPfK.js} +1 -1
- package/web-shell/assets/{pegDiagram-XKGWAZYB-pZrH8Go8.js → pegDiagram-XKGWAZYB-CvJB7Sma.js} +1 -1
- package/web-shell/assets/{pieDiagram-E7YTZNPT-BMOrGNAB.js → pieDiagram-E7YTZNPT-CBLnv-fW.js} +1 -1
- package/web-shell/assets/{quadrantDiagram-AXDQQJYC-aOjXRFWV.js → quadrantDiagram-AXDQQJYC-B9u2xeJG.js} +1 -1
- package/web-shell/assets/{railroadDiagram-O6MQD6OU-C4V6eoOZ.js → railroadDiagram-O6MQD6OU-DLTUxIOO.js} +1 -1
- package/web-shell/assets/{requirementDiagram-EFPCY7ZU-C6NZbgbz.js → requirementDiagram-EFPCY7ZU-Dfl6QlBf.js} +1 -1
- package/web-shell/assets/{sankeyDiagram-P5KCCOFB-C7lEEAPR.js → sankeyDiagram-P5KCCOFB-CGw1J6DR.js} +1 -1
- package/web-shell/assets/{sequenceDiagram-WJ2MYXX4-DSM8FnIj.js → sequenceDiagram-WJ2MYXX4-DNaPdQin.js} +1 -1
- package/web-shell/assets/{sizeCapture-X5ZJPWSS-BUvKK3KC.js → sizeCapture-X5ZJPWSS-C0lEm8df.js} +1 -1
- package/web-shell/assets/{stateDiagram-HBIQ2CUA-BnMNYnSz.js → stateDiagram-HBIQ2CUA-DPzGUm1p.js} +1 -1
- package/web-shell/assets/stateDiagram-v2-4QOOHH4V-jD2z0tDM.js +1 -0
- package/web-shell/assets/{swimlanes-XN3QIQJK-5wCXDaoD.js → swimlanes-XN3QIQJK-BQiJmDZ1.js} +1 -1
- package/web-shell/assets/swimlanesDiagram-VK2B7HYN-BdBIJlun.js +8 -0
- package/web-shell/assets/{timeline-definition-24CTP7MA-HwXl1O0d.js → timeline-definition-24CTP7MA-K5AxZP5Q.js} +1 -1
- package/web-shell/assets/{vennDiagram-4TSXK5OY-lz3VObUA.js → vennDiagram-4TSXK5OY-EBtlVIkN.js} +1 -1
- package/web-shell/assets/{wardleyDiagram-VM6X3IG4-29xS19u_.js → wardleyDiagram-VM6X3IG4-DVFZJsSs.js} +1 -1
- package/web-shell/assets/{xychartDiagram-S5SC5T6Z-BY8S5eJH.js → xychartDiagram-S5SC5T6Z-BVdZgHjH.js} +1 -1
- package/web-shell/index.html +2 -2
- package/web-shell/sw.js +1 -1
- package/web-shell/assets/channel-B_cQkC7L.js +0 -1
- package/web-shell/assets/classDiagram-DTDB5LWJ-Cun05rpU.js +0 -1
- package/web-shell/assets/classDiagram-v2-JRS7N3AN-Cun05rpU.js +0 -1
- package/web-shell/assets/index-iUOVxoEW.css +0 -36
- package/web-shell/assets/stateDiagram-v2-4QOOHH4V-D9jbQn8y.js +0 -1
- package/web-shell/assets/swimlanesDiagram-VK2B7HYN-DX2chy2x.js +0 -8
- package/chunks/{chunk-I2GU2HMQ.js → chunk-M6SELBSG.js} +5 -5
- /package/chunks/{chunk-JRP4GQAF.js → chunk-S5SS7OXV.js} +0 -0
- /package/chunks/{chunk-KA72THKQ.js → chunk-TOLTIUAR.js} +0 -0
|
@@ -0,0 +1,2808 @@
|
|
|
1
|
+
// Force strict mode and setup for ESM
|
|
2
|
+
"use strict";
|
|
3
|
+
import {
|
|
4
|
+
isInternalSecretEnvVar,
|
|
5
|
+
sanitizeChildEnv
|
|
6
|
+
} from "./chunk-ELYIK7SN.js";
|
|
7
|
+
import {
|
|
8
|
+
stripAnsi
|
|
9
|
+
} from "./chunk-TWPJO254.js";
|
|
10
|
+
import {
|
|
11
|
+
promptIdContext
|
|
12
|
+
} from "./chunk-O6GEWCJA.js";
|
|
13
|
+
import {
|
|
14
|
+
formatMemoryUsage
|
|
15
|
+
} from "./chunk-CHEIIBT3.js";
|
|
16
|
+
import {
|
|
17
|
+
resolveBundleDir
|
|
18
|
+
} from "./chunk-ACHCT36C.js";
|
|
19
|
+
import {
|
|
20
|
+
getShellConfiguration
|
|
21
|
+
} from "./chunk-I3K2QRZ5.js";
|
|
22
|
+
import {
|
|
23
|
+
getCurrentAgentId
|
|
24
|
+
} from "./chunk-6GI7NAZS.js";
|
|
25
|
+
import {
|
|
26
|
+
getCachedEncodingForBuffer
|
|
27
|
+
} from "./chunk-NXRQI7RF.js";
|
|
28
|
+
import {
|
|
29
|
+
isBinary
|
|
30
|
+
} from "./chunk-5R36APDE.js";
|
|
31
|
+
import {
|
|
32
|
+
createDebugLogger,
|
|
33
|
+
formatTraceparent,
|
|
34
|
+
getSessionModel,
|
|
35
|
+
getSessionModelIdentity,
|
|
36
|
+
getSessionProjectDir,
|
|
37
|
+
getTraceContext,
|
|
38
|
+
isShellTracePropagationEnabled,
|
|
39
|
+
isSubpath,
|
|
40
|
+
realpathNearestExisting,
|
|
41
|
+
sessionIdContext
|
|
42
|
+
} from "./chunk-GYAL5QAR.js";
|
|
43
|
+
import {
|
|
44
|
+
getErrorMessage
|
|
45
|
+
} from "./chunk-S34QJ6IR.js";
|
|
46
|
+
import {
|
|
47
|
+
init_esbuild_shims
|
|
48
|
+
} from "./chunk-5O2XNYP6.js";
|
|
49
|
+
import {
|
|
50
|
+
__name
|
|
51
|
+
} from "./chunk-J2S4EL5Y.js";
|
|
52
|
+
|
|
53
|
+
// packages/core/src/sandbox/bwrap-execution.ts
|
|
54
|
+
init_esbuild_shims();
|
|
55
|
+
import { existsSync, mkdirSync, realpathSync, statSync as statSync2 } from "node:fs";
|
|
56
|
+
import { mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
|
|
57
|
+
import os3 from "node:os";
|
|
58
|
+
import path2 from "node:path";
|
|
59
|
+
import { fileURLToPath } from "node:url";
|
|
60
|
+
|
|
61
|
+
// packages/core/src/services/shellExecutionService.ts
|
|
62
|
+
init_esbuild_shims();
|
|
63
|
+
|
|
64
|
+
// packages/core/src/utils/getPty.ts
|
|
65
|
+
init_esbuild_shims();
|
|
66
|
+
var loadPty = /* @__PURE__ */ __name(async () => {
|
|
67
|
+
if ("bun" in process.versions) {
|
|
68
|
+
return {
|
|
69
|
+
impl: null,
|
|
70
|
+
loadError: "the PTY backend is disabled under the Bun runtime; use the Node runtime"
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
try {
|
|
74
|
+
const lydell = "@lydell/node-pty";
|
|
75
|
+
const module = await import(lydell);
|
|
76
|
+
return { impl: { module, name: "lydell-node-pty" }, loadError: null };
|
|
77
|
+
} catch (lydellError) {
|
|
78
|
+
try {
|
|
79
|
+
const nodePty = "node-pty";
|
|
80
|
+
const module = await import(nodePty);
|
|
81
|
+
return { impl: { module, name: "node-pty" }, loadError: null };
|
|
82
|
+
} catch (nodePtyError) {
|
|
83
|
+
return {
|
|
84
|
+
impl: null,
|
|
85
|
+
loadError: [lydellError, nodePtyError].map((error) => getErrorMessage(error)).join("; ")
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}, "loadPty");
|
|
90
|
+
var getPty = /* @__PURE__ */ __name(async () => (await loadPty()).impl, "getPty");
|
|
91
|
+
|
|
92
|
+
// packages/core/src/services/shellExecutionService.ts
|
|
93
|
+
import { spawn as cpSpawn, spawnSync } from "node:child_process";
|
|
94
|
+
import { TextDecoder } from "node:util";
|
|
95
|
+
import os2 from "node:os";
|
|
96
|
+
import path from "node:path";
|
|
97
|
+
|
|
98
|
+
// packages/core/src/utils/load-xterm-headless.ts
|
|
99
|
+
init_esbuild_shims();
|
|
100
|
+
var xtermHeadlessModulePromise;
|
|
101
|
+
function isXtermHeadlessModule(candidate) {
|
|
102
|
+
return candidate !== void 0 && "Terminal" in candidate && typeof candidate.Terminal === "function";
|
|
103
|
+
}
|
|
104
|
+
__name(isXtermHeadlessModule, "isXtermHeadlessModule");
|
|
105
|
+
function loadXtermHeadless() {
|
|
106
|
+
xtermHeadlessModulePromise ??= import("./xterm-headless-OSLAQIKV.js").then((module) => {
|
|
107
|
+
const imported = module;
|
|
108
|
+
const candidate = isXtermHeadlessModule(imported) ? imported : "default" in imported ? imported.default : void 0;
|
|
109
|
+
if (!isXtermHeadlessModule(candidate)) {
|
|
110
|
+
throw new Error("@xterm/headless module does not match the expected API");
|
|
111
|
+
}
|
|
112
|
+
return candidate;
|
|
113
|
+
});
|
|
114
|
+
return xtermHeadlessModulePromise;
|
|
115
|
+
}
|
|
116
|
+
__name(loadXtermHeadless, "loadXtermHeadless");
|
|
117
|
+
|
|
118
|
+
// packages/core/src/utils/terminalSerializer.ts
|
|
119
|
+
init_esbuild_shims();
|
|
120
|
+
var canMergeAnsiTokens = /* @__PURE__ */ __name((left, right) => left.bold === right.bold && left.italic === right.italic && left.underline === right.underline && left.dim === right.dim && left.inverse === right.inverse && left.fg === right.fg && left.bg === right.bg, "canMergeAnsiTokens");
|
|
121
|
+
var appendAnsiLineTokens = /* @__PURE__ */ __name((target, source) => {
|
|
122
|
+
for (const token of source) {
|
|
123
|
+
const previous = target[target.length - 1];
|
|
124
|
+
if (previous && canMergeAnsiTokens(previous, token)) {
|
|
125
|
+
previous.text += token.text;
|
|
126
|
+
} else {
|
|
127
|
+
target.push({ ...token });
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}, "appendAnsiLineTokens");
|
|
131
|
+
function serializeTerminalToText(terminal) {
|
|
132
|
+
const buffer = terminal.buffer.active;
|
|
133
|
+
const lines = [];
|
|
134
|
+
for (let i = 0; i < buffer.length; i++) {
|
|
135
|
+
const line = buffer.getLine(i);
|
|
136
|
+
const lineContent = line ? line.translateToString(true) : "";
|
|
137
|
+
if (line?.isWrapped && lines.length > 0) {
|
|
138
|
+
lines[lines.length - 1] += lineContent;
|
|
139
|
+
continue;
|
|
140
|
+
}
|
|
141
|
+
lines.push(lineContent);
|
|
142
|
+
}
|
|
143
|
+
return lines.join("\n").trimEnd();
|
|
144
|
+
}
|
|
145
|
+
__name(serializeTerminalToText, "serializeTerminalToText");
|
|
146
|
+
var Cell = class {
|
|
147
|
+
static {
|
|
148
|
+
__name(this, "Cell");
|
|
149
|
+
}
|
|
150
|
+
cell;
|
|
151
|
+
x;
|
|
152
|
+
y;
|
|
153
|
+
cursorX;
|
|
154
|
+
cursorY;
|
|
155
|
+
attributes = 0;
|
|
156
|
+
fg = 0;
|
|
157
|
+
bg = 0;
|
|
158
|
+
fgColorMode = 0 /* DEFAULT */;
|
|
159
|
+
bgColorMode = 0 /* DEFAULT */;
|
|
160
|
+
constructor(cell, x, y, cursorX, cursorY) {
|
|
161
|
+
this.cell = cell;
|
|
162
|
+
this.x = x;
|
|
163
|
+
this.y = y;
|
|
164
|
+
this.cursorX = cursorX;
|
|
165
|
+
this.cursorY = cursorY;
|
|
166
|
+
if (!cell) {
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
if (cell.isInverse()) {
|
|
170
|
+
this.attributes += 1 /* inverse */;
|
|
171
|
+
}
|
|
172
|
+
if (cell.isBold()) {
|
|
173
|
+
this.attributes += 2 /* bold */;
|
|
174
|
+
}
|
|
175
|
+
if (cell.isItalic()) {
|
|
176
|
+
this.attributes += 4 /* italic */;
|
|
177
|
+
}
|
|
178
|
+
if (cell.isUnderline()) {
|
|
179
|
+
this.attributes += 8 /* underline */;
|
|
180
|
+
}
|
|
181
|
+
if (cell.isDim()) {
|
|
182
|
+
this.attributes += 16 /* dim */;
|
|
183
|
+
}
|
|
184
|
+
if (cell.isFgRGB()) {
|
|
185
|
+
this.fgColorMode = 2 /* RGB */;
|
|
186
|
+
} else if (cell.isFgPalette()) {
|
|
187
|
+
this.fgColorMode = 1 /* PALETTE */;
|
|
188
|
+
} else {
|
|
189
|
+
this.fgColorMode = 0 /* DEFAULT */;
|
|
190
|
+
}
|
|
191
|
+
if (cell.isBgRGB()) {
|
|
192
|
+
this.bgColorMode = 2 /* RGB */;
|
|
193
|
+
} else if (cell.isBgPalette()) {
|
|
194
|
+
this.bgColorMode = 1 /* PALETTE */;
|
|
195
|
+
} else {
|
|
196
|
+
this.bgColorMode = 0 /* DEFAULT */;
|
|
197
|
+
}
|
|
198
|
+
if (this.fgColorMode === 0 /* DEFAULT */) {
|
|
199
|
+
this.fg = -1;
|
|
200
|
+
} else {
|
|
201
|
+
this.fg = cell.getFgColor();
|
|
202
|
+
}
|
|
203
|
+
if (this.bgColorMode === 0 /* DEFAULT */) {
|
|
204
|
+
this.bg = -1;
|
|
205
|
+
} else {
|
|
206
|
+
this.bg = cell.getBgColor();
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
isCursor() {
|
|
210
|
+
return this.x === this.cursorX && this.y === this.cursorY;
|
|
211
|
+
}
|
|
212
|
+
getChars() {
|
|
213
|
+
return this.cell?.getChars() || " ";
|
|
214
|
+
}
|
|
215
|
+
isAttribute(attribute) {
|
|
216
|
+
return (this.attributes & attribute) !== 0;
|
|
217
|
+
}
|
|
218
|
+
equals(other) {
|
|
219
|
+
return this.attributes === other.attributes && this.fg === other.fg && this.bg === other.bg && this.fgColorMode === other.fgColorMode && this.bgColorMode === other.bgColorMode && this.isCursor() === other.isCursor();
|
|
220
|
+
}
|
|
221
|
+
};
|
|
222
|
+
function serializeTerminalToObject(terminal, scrollOffset = 0, options = {}) {
|
|
223
|
+
const buffer = terminal.buffer.active;
|
|
224
|
+
const defaultFg = "";
|
|
225
|
+
const defaultBg = "";
|
|
226
|
+
const clampedOffset = Math.max(0, Math.min(scrollOffset, buffer.viewportY));
|
|
227
|
+
const startRow = buffer.viewportY - clampedOffset;
|
|
228
|
+
const cursorX = clampedOffset === 0 ? buffer.cursorX : -1;
|
|
229
|
+
const cursorY = clampedOffset === 0 ? buffer.cursorY : -1;
|
|
230
|
+
const result = [];
|
|
231
|
+
for (let y = 0; y < terminal.rows; y++) {
|
|
232
|
+
const line = buffer.getLine(startRow + y);
|
|
233
|
+
const currentLine = [];
|
|
234
|
+
if (!line) {
|
|
235
|
+
result.push(currentLine);
|
|
236
|
+
continue;
|
|
237
|
+
}
|
|
238
|
+
let lastCell = new Cell(null, -1, -1, cursorX, cursorY);
|
|
239
|
+
let currentText = "";
|
|
240
|
+
for (let x = 0; x < terminal.cols; x++) {
|
|
241
|
+
const cellData = line.getCell(x);
|
|
242
|
+
const cell = new Cell(cellData || null, x, y, cursorX, cursorY);
|
|
243
|
+
if (x > 0 && !cell.equals(lastCell)) {
|
|
244
|
+
if (currentText) {
|
|
245
|
+
const token = {
|
|
246
|
+
text: currentText,
|
|
247
|
+
bold: lastCell.isAttribute(2 /* bold */),
|
|
248
|
+
italic: lastCell.isAttribute(4 /* italic */),
|
|
249
|
+
underline: lastCell.isAttribute(8 /* underline */),
|
|
250
|
+
dim: lastCell.isAttribute(16 /* dim */),
|
|
251
|
+
inverse: lastCell.isAttribute(1 /* inverse */) || lastCell.isCursor(),
|
|
252
|
+
fg: convertColorToHex(lastCell.fg, lastCell.fgColorMode, defaultFg),
|
|
253
|
+
bg: convertColorToHex(lastCell.bg, lastCell.bgColorMode, defaultBg)
|
|
254
|
+
};
|
|
255
|
+
currentLine.push(token);
|
|
256
|
+
}
|
|
257
|
+
currentText = "";
|
|
258
|
+
}
|
|
259
|
+
currentText += cell.getChars();
|
|
260
|
+
lastCell = cell;
|
|
261
|
+
}
|
|
262
|
+
if (currentText) {
|
|
263
|
+
const token = {
|
|
264
|
+
text: currentText,
|
|
265
|
+
bold: lastCell.isAttribute(2 /* bold */),
|
|
266
|
+
italic: lastCell.isAttribute(4 /* italic */),
|
|
267
|
+
underline: lastCell.isAttribute(8 /* underline */),
|
|
268
|
+
dim: lastCell.isAttribute(16 /* dim */),
|
|
269
|
+
inverse: lastCell.isAttribute(1 /* inverse */) || lastCell.isCursor(),
|
|
270
|
+
fg: convertColorToHex(lastCell.fg, lastCell.fgColorMode, defaultFg),
|
|
271
|
+
bg: convertColorToHex(lastCell.bg, lastCell.bgColorMode, defaultBg)
|
|
272
|
+
};
|
|
273
|
+
currentLine.push(token);
|
|
274
|
+
}
|
|
275
|
+
if (options.unwrapWrappedLines && line.isWrapped && result.length > 0) {
|
|
276
|
+
appendAnsiLineTokens(result[result.length - 1], currentLine);
|
|
277
|
+
} else {
|
|
278
|
+
result.push(currentLine);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
return result;
|
|
282
|
+
}
|
|
283
|
+
__name(serializeTerminalToObject, "serializeTerminalToObject");
|
|
284
|
+
var ANSI_COLORS = [
|
|
285
|
+
"#000000",
|
|
286
|
+
"#800000",
|
|
287
|
+
"#008000",
|
|
288
|
+
"#808000",
|
|
289
|
+
"#000080",
|
|
290
|
+
"#800080",
|
|
291
|
+
"#008080",
|
|
292
|
+
"#c0c0c0",
|
|
293
|
+
"#808080",
|
|
294
|
+
"#ff0000",
|
|
295
|
+
"#00ff00",
|
|
296
|
+
"#ffff00",
|
|
297
|
+
"#0000ff",
|
|
298
|
+
"#ff00ff",
|
|
299
|
+
"#00ffff",
|
|
300
|
+
"#ffffff",
|
|
301
|
+
"#000000",
|
|
302
|
+
"#00005f",
|
|
303
|
+
"#000087",
|
|
304
|
+
"#0000af",
|
|
305
|
+
"#0000d7",
|
|
306
|
+
"#0000ff",
|
|
307
|
+
"#005f00",
|
|
308
|
+
"#005f5f",
|
|
309
|
+
"#005f87",
|
|
310
|
+
"#005faf",
|
|
311
|
+
"#005fd7",
|
|
312
|
+
"#005fff",
|
|
313
|
+
"#008700",
|
|
314
|
+
"#00875f",
|
|
315
|
+
"#008787",
|
|
316
|
+
"#0087af",
|
|
317
|
+
"#0087d7",
|
|
318
|
+
"#0087ff",
|
|
319
|
+
"#00af00",
|
|
320
|
+
"#00af5f",
|
|
321
|
+
"#00af87",
|
|
322
|
+
"#00afaf",
|
|
323
|
+
"#00afd7",
|
|
324
|
+
"#00afff",
|
|
325
|
+
"#00d700",
|
|
326
|
+
"#00d75f",
|
|
327
|
+
"#00d787",
|
|
328
|
+
"#00d7af",
|
|
329
|
+
"#00d7d7",
|
|
330
|
+
"#00d7ff",
|
|
331
|
+
"#00ff00",
|
|
332
|
+
"#00ff5f",
|
|
333
|
+
"#00ff87",
|
|
334
|
+
"#00ffaf",
|
|
335
|
+
"#00ffd7",
|
|
336
|
+
"#00ffff",
|
|
337
|
+
"#5f0000",
|
|
338
|
+
"#5f005f",
|
|
339
|
+
"#5f0087",
|
|
340
|
+
"#5f00af",
|
|
341
|
+
"#5f00d7",
|
|
342
|
+
"#5f00ff",
|
|
343
|
+
"#5f5f00",
|
|
344
|
+
"#5f5f5f",
|
|
345
|
+
"#5f5f87",
|
|
346
|
+
"#5f5faf",
|
|
347
|
+
"#5f5fd7",
|
|
348
|
+
"#5f5fff",
|
|
349
|
+
"#5f8700",
|
|
350
|
+
"#5f875f",
|
|
351
|
+
"#5f8787",
|
|
352
|
+
"#5f87af",
|
|
353
|
+
"#5f87d7",
|
|
354
|
+
"#5f87ff",
|
|
355
|
+
"#5faf00",
|
|
356
|
+
"#5faf5f",
|
|
357
|
+
"#5faf87",
|
|
358
|
+
"#5fafaf",
|
|
359
|
+
"#5fafd7",
|
|
360
|
+
"#5fafff",
|
|
361
|
+
"#5fd700",
|
|
362
|
+
"#5fd75f",
|
|
363
|
+
"#5fd787",
|
|
364
|
+
"#5fd7af",
|
|
365
|
+
"#5fd7d7",
|
|
366
|
+
"#5fd7ff",
|
|
367
|
+
"#5fff00",
|
|
368
|
+
"#5fff5f",
|
|
369
|
+
"#5fff87",
|
|
370
|
+
"#5fffaf",
|
|
371
|
+
"#5fffd7",
|
|
372
|
+
"#5fffff",
|
|
373
|
+
"#870000",
|
|
374
|
+
"#87005f",
|
|
375
|
+
"#870087",
|
|
376
|
+
"#8700af",
|
|
377
|
+
"#8700d7",
|
|
378
|
+
"#8700ff",
|
|
379
|
+
"#875f00",
|
|
380
|
+
"#875f5f",
|
|
381
|
+
"#875f87",
|
|
382
|
+
"#875faf",
|
|
383
|
+
"#875fd7",
|
|
384
|
+
"#875fff",
|
|
385
|
+
"#878700",
|
|
386
|
+
"#87875f",
|
|
387
|
+
"#878787",
|
|
388
|
+
"#8787af",
|
|
389
|
+
"#8787d7",
|
|
390
|
+
"#8787ff",
|
|
391
|
+
"#87af00",
|
|
392
|
+
"#87af5f",
|
|
393
|
+
"#87af87",
|
|
394
|
+
"#87afaf",
|
|
395
|
+
"#87afd7",
|
|
396
|
+
"#87afff",
|
|
397
|
+
"#87d700",
|
|
398
|
+
"#87d75f",
|
|
399
|
+
"#87d787",
|
|
400
|
+
"#87d7af",
|
|
401
|
+
"#87d7d7",
|
|
402
|
+
"#87d7ff",
|
|
403
|
+
"#87ff00",
|
|
404
|
+
"#87ff5f",
|
|
405
|
+
"#87ff87",
|
|
406
|
+
"#87ffaf",
|
|
407
|
+
"#87ffd7",
|
|
408
|
+
"#87ffff",
|
|
409
|
+
"#af0000",
|
|
410
|
+
"#af005f",
|
|
411
|
+
"#af0087",
|
|
412
|
+
"#af00af",
|
|
413
|
+
"#af00d7",
|
|
414
|
+
"#af00ff",
|
|
415
|
+
"#af5f00",
|
|
416
|
+
"#af5f5f",
|
|
417
|
+
"#af5f87",
|
|
418
|
+
"#af5faf",
|
|
419
|
+
"#af5fd7",
|
|
420
|
+
"#af5fff",
|
|
421
|
+
"#af8700",
|
|
422
|
+
"#af875f",
|
|
423
|
+
"#af8787",
|
|
424
|
+
"#af87af",
|
|
425
|
+
"#af87d7",
|
|
426
|
+
"#af87ff",
|
|
427
|
+
"#afaf00",
|
|
428
|
+
"#afaf5f",
|
|
429
|
+
"#afaf87",
|
|
430
|
+
"#afafaf",
|
|
431
|
+
"#afafd7",
|
|
432
|
+
"#afafff",
|
|
433
|
+
"#afd700",
|
|
434
|
+
"#afd75f",
|
|
435
|
+
"#afd787",
|
|
436
|
+
"#afd7af",
|
|
437
|
+
"#afd7d7",
|
|
438
|
+
"#afd7ff",
|
|
439
|
+
"#afff00",
|
|
440
|
+
"#afff5f",
|
|
441
|
+
"#afff87",
|
|
442
|
+
"#afffaf",
|
|
443
|
+
"#afffd7",
|
|
444
|
+
"#afffff",
|
|
445
|
+
"#d70000",
|
|
446
|
+
"#d7005f",
|
|
447
|
+
"#d70087",
|
|
448
|
+
"#d700af",
|
|
449
|
+
"#d700d7",
|
|
450
|
+
"#d700ff",
|
|
451
|
+
"#d75f00",
|
|
452
|
+
"#d75f5f",
|
|
453
|
+
"#d75f87",
|
|
454
|
+
"#d75faf",
|
|
455
|
+
"#d75fd7",
|
|
456
|
+
"#d75fff",
|
|
457
|
+
"#d78700",
|
|
458
|
+
"#d7875f",
|
|
459
|
+
"#d78787",
|
|
460
|
+
"#d787af",
|
|
461
|
+
"#d787d7",
|
|
462
|
+
"#d787ff",
|
|
463
|
+
"#d7af00",
|
|
464
|
+
"#d7af5f",
|
|
465
|
+
"#d7af87",
|
|
466
|
+
"#d7afaf",
|
|
467
|
+
"#d7afd7",
|
|
468
|
+
"#d7afff",
|
|
469
|
+
"#d7d700",
|
|
470
|
+
"#d7d75f",
|
|
471
|
+
"#d7d787",
|
|
472
|
+
"#d7d7af",
|
|
473
|
+
"#d7d7d7",
|
|
474
|
+
"#d7d7ff",
|
|
475
|
+
"#d7ff00",
|
|
476
|
+
"#d7ff5f",
|
|
477
|
+
"#d7ff87",
|
|
478
|
+
"#d7ffaf",
|
|
479
|
+
"#d7ffd7",
|
|
480
|
+
"#d7ffff",
|
|
481
|
+
"#ff0000",
|
|
482
|
+
"#ff005f",
|
|
483
|
+
"#ff0087",
|
|
484
|
+
"#ff00af",
|
|
485
|
+
"#ff00d7",
|
|
486
|
+
"#ff00ff",
|
|
487
|
+
"#ff5f00",
|
|
488
|
+
"#ff5f5f",
|
|
489
|
+
"#ff5f87",
|
|
490
|
+
"#ff5faf",
|
|
491
|
+
"#ff5fd7",
|
|
492
|
+
"#ff5fff",
|
|
493
|
+
"#ff8700",
|
|
494
|
+
"#ff875f",
|
|
495
|
+
"#ff8787",
|
|
496
|
+
"#ff87af",
|
|
497
|
+
"#ff87d7",
|
|
498
|
+
"#ff87ff",
|
|
499
|
+
"#ffaf00",
|
|
500
|
+
"#ffaf5f",
|
|
501
|
+
"#ffaf87",
|
|
502
|
+
"#ffafaf",
|
|
503
|
+
"#ffafd7",
|
|
504
|
+
"#ffafff",
|
|
505
|
+
"#ffd700",
|
|
506
|
+
"#ffd75f",
|
|
507
|
+
"#ffd787",
|
|
508
|
+
"#ffd7af",
|
|
509
|
+
"#ffd7d7",
|
|
510
|
+
"#ffd7ff",
|
|
511
|
+
"#ffff00",
|
|
512
|
+
"#ffff5f",
|
|
513
|
+
"#ffff87",
|
|
514
|
+
"#ffffaf",
|
|
515
|
+
"#ffffd7",
|
|
516
|
+
"#ffffff",
|
|
517
|
+
"#080808",
|
|
518
|
+
"#121212",
|
|
519
|
+
"#1c1c1c",
|
|
520
|
+
"#262626",
|
|
521
|
+
"#303030",
|
|
522
|
+
"#3a3a3a",
|
|
523
|
+
"#444444",
|
|
524
|
+
"#4e4e4e",
|
|
525
|
+
"#585858",
|
|
526
|
+
"#626262",
|
|
527
|
+
"#6c6c6c",
|
|
528
|
+
"#767676",
|
|
529
|
+
"#808080",
|
|
530
|
+
"#8a8a8a",
|
|
531
|
+
"#949494",
|
|
532
|
+
"#9e9e9e",
|
|
533
|
+
"#a8a8a8",
|
|
534
|
+
"#b2b2b2",
|
|
535
|
+
"#bcbcbc",
|
|
536
|
+
"#c6c6c6",
|
|
537
|
+
"#d0d0d0",
|
|
538
|
+
"#dadada",
|
|
539
|
+
"#e4e4e4",
|
|
540
|
+
"#eeeeee"
|
|
541
|
+
];
|
|
542
|
+
function convertColorToHex(color, colorMode, defaultColor) {
|
|
543
|
+
if (colorMode === 2 /* RGB */) {
|
|
544
|
+
const r = color >> 16 & 255;
|
|
545
|
+
const g = color >> 8 & 255;
|
|
546
|
+
const b = color & 255;
|
|
547
|
+
return `#${r.toString(16).padStart(2, "0")}${g.toString(16).padStart(2, "0")}${b.toString(16).padStart(2, "0")}`;
|
|
548
|
+
}
|
|
549
|
+
if (colorMode === 1 /* PALETTE */) {
|
|
550
|
+
return ANSI_COLORS[color] || defaultColor;
|
|
551
|
+
}
|
|
552
|
+
return defaultColor;
|
|
553
|
+
}
|
|
554
|
+
__name(convertColorToHex, "convertColorToHex");
|
|
555
|
+
|
|
556
|
+
// packages/core/src/utils/windowsPath.ts
|
|
557
|
+
init_esbuild_shims();
|
|
558
|
+
var WINDOWS_PATH_DELIMITER = ";";
|
|
559
|
+
var cachedWindowsPathFingerprint;
|
|
560
|
+
var cachedMergedWindowsPath;
|
|
561
|
+
function mergeWindowsPathValues(env, pathKeys) {
|
|
562
|
+
const mergedEntries = [];
|
|
563
|
+
const seenEntries = /* @__PURE__ */ new Set();
|
|
564
|
+
for (const key of pathKeys) {
|
|
565
|
+
const value = env[key];
|
|
566
|
+
if (value === void 0) {
|
|
567
|
+
continue;
|
|
568
|
+
}
|
|
569
|
+
for (const entry of value.split(WINDOWS_PATH_DELIMITER)) {
|
|
570
|
+
if (seenEntries.has(entry)) {
|
|
571
|
+
continue;
|
|
572
|
+
}
|
|
573
|
+
seenEntries.add(entry);
|
|
574
|
+
mergedEntries.push(entry);
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
return mergedEntries.length > 0 ? mergedEntries.join(WINDOWS_PATH_DELIMITER) : void 0;
|
|
578
|
+
}
|
|
579
|
+
__name(mergeWindowsPathValues, "mergeWindowsPathValues");
|
|
580
|
+
function getWindowsPathFingerprint(env, pathKeys) {
|
|
581
|
+
return pathKeys.map((key) => `${key}=${env[key] ?? ""}`).join("\0");
|
|
582
|
+
}
|
|
583
|
+
__name(getWindowsPathFingerprint, "getWindowsPathFingerprint");
|
|
584
|
+
function sortPathKeys(pathKeys) {
|
|
585
|
+
return [...pathKeys].sort((left, right) => {
|
|
586
|
+
if (left === "PATH") {
|
|
587
|
+
return -1;
|
|
588
|
+
}
|
|
589
|
+
if (right === "PATH") {
|
|
590
|
+
return 1;
|
|
591
|
+
}
|
|
592
|
+
return left.localeCompare(right);
|
|
593
|
+
});
|
|
594
|
+
}
|
|
595
|
+
__name(sortPathKeys, "sortPathKeys");
|
|
596
|
+
function normalizePathEnvForWindows(env) {
|
|
597
|
+
if (process.platform !== "win32") {
|
|
598
|
+
return env;
|
|
599
|
+
}
|
|
600
|
+
const normalized = { ...env };
|
|
601
|
+
const pathKeys = Object.keys(normalized).filter(
|
|
602
|
+
(key) => key.toLowerCase() === "path"
|
|
603
|
+
);
|
|
604
|
+
if (pathKeys.length === 0) {
|
|
605
|
+
return normalized;
|
|
606
|
+
}
|
|
607
|
+
const orderedPathKeys = sortPathKeys(pathKeys);
|
|
608
|
+
const fingerprint = getWindowsPathFingerprint(normalized, orderedPathKeys);
|
|
609
|
+
const canonicalValue = fingerprint === cachedWindowsPathFingerprint ? cachedMergedWindowsPath : mergeWindowsPathValues(normalized, orderedPathKeys);
|
|
610
|
+
if (fingerprint !== cachedWindowsPathFingerprint) {
|
|
611
|
+
cachedWindowsPathFingerprint = fingerprint;
|
|
612
|
+
cachedMergedWindowsPath = canonicalValue;
|
|
613
|
+
}
|
|
614
|
+
for (const key of pathKeys) {
|
|
615
|
+
if (key !== "PATH") {
|
|
616
|
+
delete normalized[key];
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
if (canonicalValue !== void 0) {
|
|
620
|
+
normalized["PATH"] = canonicalValue;
|
|
621
|
+
}
|
|
622
|
+
return normalized;
|
|
623
|
+
}
|
|
624
|
+
__name(normalizePathEnvForWindows, "normalizePathEnvForWindows");
|
|
625
|
+
|
|
626
|
+
// packages/core/src/services/shellContextEnv.ts
|
|
627
|
+
init_esbuild_shims();
|
|
628
|
+
import {
|
|
629
|
+
accessSync,
|
|
630
|
+
closeSync,
|
|
631
|
+
constants,
|
|
632
|
+
openSync,
|
|
633
|
+
readSync,
|
|
634
|
+
statSync
|
|
635
|
+
} from "node:fs";
|
|
636
|
+
var SCRIPT_ENTRY_RE = /\.(?:mjs|cjs|js|mts|cts|ts|tsx|jsx)$/i;
|
|
637
|
+
var unusableCache = /* @__PURE__ */ new Map();
|
|
638
|
+
function isUnusableScriptEntry(path3) {
|
|
639
|
+
const cached = unusableCache.get(path3);
|
|
640
|
+
if (cached !== void 0) return cached;
|
|
641
|
+
let unusable;
|
|
642
|
+
try {
|
|
643
|
+
if (!statSync(path3).isFile()) {
|
|
644
|
+
unusable = true;
|
|
645
|
+
} else {
|
|
646
|
+
accessSync(path3, constants.X_OK);
|
|
647
|
+
const fd = openSync(path3, "r");
|
|
648
|
+
try {
|
|
649
|
+
const head = Buffer.alloc(2);
|
|
650
|
+
const read = readSync(fd, head, 0, 2, 0);
|
|
651
|
+
const shebang = read === 2 && head.toString("utf8") === "#!";
|
|
652
|
+
unusable = shebang ? false : SCRIPT_ENTRY_RE.test(path3);
|
|
653
|
+
} finally {
|
|
654
|
+
closeSync(fd);
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
} catch {
|
|
658
|
+
unusable = true;
|
|
659
|
+
}
|
|
660
|
+
unusableCache.set(path3, unusable);
|
|
661
|
+
return unusable;
|
|
662
|
+
}
|
|
663
|
+
__name(isUnusableScriptEntry, "isUnusableScriptEntry");
|
|
664
|
+
function identityDescribes(identity, model) {
|
|
665
|
+
const head = /^(.*)@[0-9a-f]{8}$/.exec(identity)?.[1] ?? identity;
|
|
666
|
+
return head === model;
|
|
667
|
+
}
|
|
668
|
+
__name(identityDescribes, "identityDescribes");
|
|
669
|
+
function getShellContextEnvVars() {
|
|
670
|
+
const env = {};
|
|
671
|
+
const sessionId = sessionIdContext.getStore() ?? process.env["QWEN_CODE_SESSION_ID"];
|
|
672
|
+
if (sessionId) {
|
|
673
|
+
env["QWEN_CODE_SESSION_ID"] = sessionId;
|
|
674
|
+
}
|
|
675
|
+
const projectDir = (sessionId ? getSessionProjectDir(sessionId) : void 0) ?? process.env["QWEN_CODE_PROJECT_DIR"];
|
|
676
|
+
if (projectDir) {
|
|
677
|
+
env["QWEN_CODE_PROJECT_DIR"] = projectDir;
|
|
678
|
+
}
|
|
679
|
+
const cliEntry = process.env["QWEN_CODE_CLI"];
|
|
680
|
+
if (cliEntry) {
|
|
681
|
+
env["QWEN_CODE_CLI"] = isUnusableScriptEntry(cliEntry) ? "" : cliEntry;
|
|
682
|
+
}
|
|
683
|
+
const model = (sessionId ? getSessionModel(sessionId) : void 0) ?? process.env["QWEN_CODE_MODEL"];
|
|
684
|
+
if (model) {
|
|
685
|
+
env["QWEN_CODE_MODEL"] = model;
|
|
686
|
+
}
|
|
687
|
+
const globalIdentity = process.env["QWEN_CODE_MODEL_IDENTITY"];
|
|
688
|
+
const modelIdentity = (sessionId ? getSessionModelIdentity(sessionId) : void 0) ?? (globalIdentity && model && identityDescribes(globalIdentity, model) ? globalIdentity : void 0);
|
|
689
|
+
env["QWEN_CODE_MODEL_IDENTITY"] = modelIdentity ?? "";
|
|
690
|
+
const agentId = getCurrentAgentId();
|
|
691
|
+
env["QWEN_CODE_AGENT_ID"] = agentId ?? "";
|
|
692
|
+
const promptId = promptIdContext.getStore();
|
|
693
|
+
env["QWEN_CODE_PROMPT_ID"] = promptId ?? "";
|
|
694
|
+
if (isShellTracePropagationEnabled()) {
|
|
695
|
+
const ctx = getTraceContext();
|
|
696
|
+
env["TRACEPARENT"] = ctx ? formatTraceparent(ctx) : "";
|
|
697
|
+
env["TRACESTATE"] = "";
|
|
698
|
+
}
|
|
699
|
+
return env;
|
|
700
|
+
}
|
|
701
|
+
__name(getShellContextEnvVars, "getShellContextEnvVars");
|
|
702
|
+
|
|
703
|
+
// packages/core/src/services/conpty-host.ts
|
|
704
|
+
init_esbuild_shims();
|
|
705
|
+
import os from "node:os";
|
|
706
|
+
var debugLogger = createDebugLogger("CONPTY_HOST");
|
|
707
|
+
var releasedHosts = /* @__PURE__ */ new WeakSet();
|
|
708
|
+
var asPtyObject = /* @__PURE__ */ __name((ptyProcess) => typeof ptyProcess === "object" && ptyProcess !== null ? ptyProcess : void 0, "asPtyObject");
|
|
709
|
+
var noteConPtyHostReleased = /* @__PURE__ */ __name((ptyProcess) => {
|
|
710
|
+
const key = asPtyObject(ptyProcess);
|
|
711
|
+
if (key) {
|
|
712
|
+
releasedHosts.add(key);
|
|
713
|
+
}
|
|
714
|
+
}, "noteConPtyHostReleased");
|
|
715
|
+
var disposeConoutWorker = /* @__PURE__ */ __name((ptyProcess) => {
|
|
716
|
+
if (os.platform() !== "win32") {
|
|
717
|
+
return;
|
|
718
|
+
}
|
|
719
|
+
const agent = ptyProcess?._agent;
|
|
720
|
+
if (!agent) {
|
|
721
|
+
return;
|
|
722
|
+
}
|
|
723
|
+
try {
|
|
724
|
+
agent._conoutSocketWorker?.dispose?.();
|
|
725
|
+
} catch (e) {
|
|
726
|
+
debugLogger.warn(
|
|
727
|
+
`disposeConoutWorker: conout worker dispose threw: ${e instanceof Error ? e.message : String(e)}`
|
|
728
|
+
);
|
|
729
|
+
}
|
|
730
|
+
}, "disposeConoutWorker");
|
|
731
|
+
var releaseConPtyHost = /* @__PURE__ */ __name((ptyProcess) => {
|
|
732
|
+
if (os.platform() !== "win32") {
|
|
733
|
+
return;
|
|
734
|
+
}
|
|
735
|
+
const key = asPtyObject(ptyProcess);
|
|
736
|
+
if (!key) {
|
|
737
|
+
return;
|
|
738
|
+
}
|
|
739
|
+
const agent = ptyProcess?._agent;
|
|
740
|
+
if (releasedHosts.has(key)) {
|
|
741
|
+
if (agent?._useConptyDll) {
|
|
742
|
+
disposeConoutWorker(ptyProcess);
|
|
743
|
+
}
|
|
744
|
+
return;
|
|
745
|
+
}
|
|
746
|
+
releasedHosts.add(key);
|
|
747
|
+
const ptyId = agent?._pty;
|
|
748
|
+
const nativeKill = agent?._ptyNative?.kill;
|
|
749
|
+
if (!agent) {
|
|
750
|
+
debugLogger.warn(
|
|
751
|
+
"releaseConPtyHost: no node-pty agent; nothing released (see #11303)"
|
|
752
|
+
);
|
|
753
|
+
return;
|
|
754
|
+
}
|
|
755
|
+
if (typeof nativeKill === "function" && typeof ptyId === "number") {
|
|
756
|
+
try {
|
|
757
|
+
nativeKill.call(agent._ptyNative, ptyId, agent._useConptyDll ?? false);
|
|
758
|
+
} catch (e) {
|
|
759
|
+
debugLogger.warn(
|
|
760
|
+
`releaseConPtyHost: the native pty kill threw: ${e instanceof Error ? e.message : String(e)}`
|
|
761
|
+
);
|
|
762
|
+
}
|
|
763
|
+
} else {
|
|
764
|
+
debugLogger.warn(
|
|
765
|
+
"releaseConPtyHost: native pty shape changed; skipping the pseudo-console close (see #11303)"
|
|
766
|
+
);
|
|
767
|
+
}
|
|
768
|
+
try {
|
|
769
|
+
agent._conoutSocketWorker?.dispose?.();
|
|
770
|
+
} catch (e) {
|
|
771
|
+
debugLogger.warn(
|
|
772
|
+
`releaseConPtyHost: conout worker dispose threw: ${e instanceof Error ? e.message : String(e)}`
|
|
773
|
+
);
|
|
774
|
+
}
|
|
775
|
+
}, "releaseConPtyHost");
|
|
776
|
+
|
|
777
|
+
// packages/core/src/utils/shell-pager-env.ts
|
|
778
|
+
init_esbuild_shims();
|
|
779
|
+
function getDefaultShellPager(platform = process.platform) {
|
|
780
|
+
return platform === "win32" ? void 0 : "cat";
|
|
781
|
+
}
|
|
782
|
+
__name(getDefaultShellPager, "getDefaultShellPager");
|
|
783
|
+
function getShellPagerEnv(pager, options = {}) {
|
|
784
|
+
const effectivePager = pager ?? getDefaultShellPager(options.platform);
|
|
785
|
+
if (!effectivePager) {
|
|
786
|
+
return {
|
|
787
|
+
PAGER: "",
|
|
788
|
+
...options.includeGitPager ? { GIT_PAGER: "" } : {}
|
|
789
|
+
};
|
|
790
|
+
}
|
|
791
|
+
return {
|
|
792
|
+
PAGER: effectivePager,
|
|
793
|
+
...options.includeGitPager ? { GIT_PAGER: effectivePager } : {}
|
|
794
|
+
};
|
|
795
|
+
}
|
|
796
|
+
__name(getShellPagerEnv, "getShellPagerEnv");
|
|
797
|
+
|
|
798
|
+
// packages/core/src/services/shellExecutionService.ts
|
|
799
|
+
var debugLogger2 = createDebugLogger("SHELL_EXECUTION");
|
|
800
|
+
var DEFAULT_MAX_BUFFERED_OUTPUT_BYTES = 64 * 1024 * 1024;
|
|
801
|
+
var MAX_BUFFERED_OUTPUT_BYTES_CEILING = 256 * 1024 * 1024;
|
|
802
|
+
var SIGKILL_TIMEOUT_MS = 200;
|
|
803
|
+
var POST_EXIT_STREAM_DRAIN_MS = 1e3;
|
|
804
|
+
var MAX_LIVE_TERMINAL_SCROLLBACK_LINES = 200;
|
|
805
|
+
var PROMOTE_DRAIN_TIMEOUT_MS = 200;
|
|
806
|
+
function getShellAbortReasonKind(reason) {
|
|
807
|
+
if (reason !== null && typeof reason === "object") {
|
|
808
|
+
try {
|
|
809
|
+
if (Object.prototype.hasOwnProperty.call(reason, "kind")) {
|
|
810
|
+
const kind = reason.kind;
|
|
811
|
+
if (kind === "background" || kind === "cancel") return kind;
|
|
812
|
+
}
|
|
813
|
+
} catch {
|
|
814
|
+
}
|
|
815
|
+
}
|
|
816
|
+
return "cancel";
|
|
817
|
+
}
|
|
818
|
+
__name(getShellAbortReasonKind, "getShellAbortReasonKind");
|
|
819
|
+
var CHCP = `${process.env["SystemRoot"] || "C:\\Windows"}\\System32\\chcp.com`;
|
|
820
|
+
function applyUtf8Prefix(command, shell) {
|
|
821
|
+
if (os2.platform() !== "win32") return command;
|
|
822
|
+
switch (shell) {
|
|
823
|
+
case "powershell":
|
|
824
|
+
return "[Console]::OutputEncoding=[System.Text.Encoding]::UTF8;" + command;
|
|
825
|
+
case "cmd":
|
|
826
|
+
return `${CHCP} 65001 >nul 2>nul & ${command}`;
|
|
827
|
+
case "bash":
|
|
828
|
+
return command;
|
|
829
|
+
default: {
|
|
830
|
+
const _exhaustive = shell;
|
|
831
|
+
return _exhaustive;
|
|
832
|
+
}
|
|
833
|
+
}
|
|
834
|
+
}
|
|
835
|
+
__name(applyUtf8Prefix, "applyUtf8Prefix");
|
|
836
|
+
function isSignalTermination(signal) {
|
|
837
|
+
return signal !== null && signal !== 0;
|
|
838
|
+
}
|
|
839
|
+
__name(isSignalTermination, "isSignalTermination");
|
|
840
|
+
function launchCommand(input) {
|
|
841
|
+
if (typeof input !== "string") {
|
|
842
|
+
return {
|
|
843
|
+
executable: input.executable,
|
|
844
|
+
args: [...input.args],
|
|
845
|
+
shell: void 0
|
|
846
|
+
};
|
|
847
|
+
}
|
|
848
|
+
const { executable, argsPrefix, shell } = getShellConfiguration();
|
|
849
|
+
return {
|
|
850
|
+
executable,
|
|
851
|
+
args: [...argsPrefix, applyUtf8Prefix(input, shell)],
|
|
852
|
+
shell
|
|
853
|
+
};
|
|
854
|
+
}
|
|
855
|
+
__name(launchCommand, "launchCommand");
|
|
856
|
+
function createPreSpawnAbortedHandle() {
|
|
857
|
+
return {
|
|
858
|
+
pid: void 0,
|
|
859
|
+
result: Promise.resolve({
|
|
860
|
+
rawOutput: Buffer.alloc(0),
|
|
861
|
+
output: "",
|
|
862
|
+
exitCode: null,
|
|
863
|
+
signal: null,
|
|
864
|
+
error: null,
|
|
865
|
+
aborted: true,
|
|
866
|
+
pid: void 0,
|
|
867
|
+
executionMethod: "none"
|
|
868
|
+
})
|
|
869
|
+
};
|
|
870
|
+
}
|
|
871
|
+
__name(createPreSpawnAbortedHandle, "createPreSpawnAbortedHandle");
|
|
872
|
+
function getMaxBufferedOutputBytes(config) {
|
|
873
|
+
const configured = config.maxBufferedOutputBytes;
|
|
874
|
+
const floored = typeof configured === "number" && Number.isFinite(configured) ? Math.floor(configured) : 0;
|
|
875
|
+
return floored > 0 ? Math.min(floored, MAX_BUFFERED_OUTPUT_BYTES_CEILING) : DEFAULT_MAX_BUFFERED_OUTPUT_BYTES;
|
|
876
|
+
}
|
|
877
|
+
__name(getMaxBufferedOutputBytes, "getMaxBufferedOutputBytes");
|
|
878
|
+
function decodeBufferedOutput(finalBuffer) {
|
|
879
|
+
const fallbackEncoding = getCachedEncodingForBuffer(finalBuffer);
|
|
880
|
+
return new TextDecoder(fallbackEncoding).decode(finalBuffer);
|
|
881
|
+
}
|
|
882
|
+
__name(decodeBufferedOutput, "decodeBufferedOutput");
|
|
883
|
+
function appendOutputCaptureLimitNotice(output, didExceedLimit, totalBytesReceived, maxBufferedOutputBytes) {
|
|
884
|
+
if (!didExceedLimit) {
|
|
885
|
+
return output;
|
|
886
|
+
}
|
|
887
|
+
const notice = `[Output exceeded the maximum captured size of ${formatMemoryUsage(maxBufferedOutputBytes)}; captured the first ${formatMemoryUsage(maxBufferedOutputBytes)} of ${formatMemoryUsage(totalBytesReceived)} and discarded the rest to avoid constructing an oversized JavaScript string.]`;
|
|
888
|
+
return output ? `${output}
|
|
889
|
+
|
|
890
|
+
${notice}` : notice;
|
|
891
|
+
}
|
|
892
|
+
__name(appendOutputCaptureLimitNotice, "appendOutputCaptureLimitNotice");
|
|
893
|
+
var getErrnoCode = /* @__PURE__ */ __name((error) => {
|
|
894
|
+
if (!error || typeof error !== "object" || !("code" in error)) {
|
|
895
|
+
return void 0;
|
|
896
|
+
}
|
|
897
|
+
const code = error.code;
|
|
898
|
+
return typeof code === "string" ? code : void 0;
|
|
899
|
+
}, "getErrnoCode");
|
|
900
|
+
var getErrorMessage2 = /* @__PURE__ */ __name((error) => error instanceof Error ? error.message : String(error), "getErrorMessage");
|
|
901
|
+
var isExpectedPtyReadExitError = /* @__PURE__ */ __name((error) => {
|
|
902
|
+
const code = getErrnoCode(error);
|
|
903
|
+
if (code === "EIO" || code === "EAGAIN") {
|
|
904
|
+
return true;
|
|
905
|
+
}
|
|
906
|
+
const message = getErrorMessage2(error);
|
|
907
|
+
return message.includes("read EIO") || message.includes("EAGAIN");
|
|
908
|
+
}, "isExpectedPtyReadExitError");
|
|
909
|
+
var isExpectedPtyExitRaceError = /* @__PURE__ */ __name((error) => {
|
|
910
|
+
const code = getErrnoCode(error);
|
|
911
|
+
if (code === "ESRCH" || code === "EBADF") {
|
|
912
|
+
return true;
|
|
913
|
+
}
|
|
914
|
+
const message = getErrorMessage2(error);
|
|
915
|
+
return message.includes("ioctl(2) failed, EBADF") || message.includes("Cannot resize a pty that has already exited");
|
|
916
|
+
}, "isExpectedPtyExitRaceError");
|
|
917
|
+
var replayTerminalOutput = /* @__PURE__ */ __name(async (output, cols, rows, Terminal) => {
|
|
918
|
+
const replayTerminal = new Terminal({
|
|
919
|
+
allowProposedApi: true,
|
|
920
|
+
cols,
|
|
921
|
+
rows,
|
|
922
|
+
scrollback: 1e4,
|
|
923
|
+
convertEol: true,
|
|
924
|
+
// This headless terminal only captures output, so suppress parser diagnostics.
|
|
925
|
+
logLevel: "off"
|
|
926
|
+
});
|
|
927
|
+
try {
|
|
928
|
+
await new Promise((resolve) => {
|
|
929
|
+
replayTerminal.write(output, () => resolve());
|
|
930
|
+
});
|
|
931
|
+
return serializeTerminalToText(replayTerminal);
|
|
932
|
+
} finally {
|
|
933
|
+
replayTerminal.dispose();
|
|
934
|
+
}
|
|
935
|
+
}, "replayTerminalOutput");
|
|
936
|
+
var getLastNonEmptyAnsiLineIndex = /* @__PURE__ */ __name((output) => {
|
|
937
|
+
for (let i = output.length - 1; i >= 0; i--) {
|
|
938
|
+
const line = output[i];
|
|
939
|
+
if (line.map((segment) => segment.text).join("").trim().length > 0) {
|
|
940
|
+
return i;
|
|
941
|
+
}
|
|
942
|
+
}
|
|
943
|
+
return -1;
|
|
944
|
+
}, "getLastNonEmptyAnsiLineIndex");
|
|
945
|
+
var trimTrailingEmptyAnsiLines = /* @__PURE__ */ __name((output) => output.slice(0, getLastNonEmptyAnsiLineIndex(output) + 1), "trimTrailingEmptyAnsiLines");
|
|
946
|
+
var areAnsiOutputsEqual = /* @__PURE__ */ __name((left, right) => {
|
|
947
|
+
if (!left || left.length !== right.length) {
|
|
948
|
+
return false;
|
|
949
|
+
}
|
|
950
|
+
return left.every((leftLine, lineIndex) => {
|
|
951
|
+
const rightLine = right[lineIndex];
|
|
952
|
+
if (leftLine.length !== rightLine.length) {
|
|
953
|
+
return false;
|
|
954
|
+
}
|
|
955
|
+
return leftLine.every((leftToken, tokenIndex) => {
|
|
956
|
+
const rightToken = rightLine[tokenIndex];
|
|
957
|
+
return leftToken.text === rightToken.text && leftToken.bold === rightToken.bold && leftToken.italic === rightToken.italic && leftToken.underline === rightToken.underline && leftToken.dim === rightToken.dim && leftToken.inverse === rightToken.inverse && leftToken.fg === rightToken.fg && leftToken.bg === rightToken.bg;
|
|
958
|
+
});
|
|
959
|
+
});
|
|
960
|
+
}, "areAnsiOutputsEqual");
|
|
961
|
+
var createPlainAnsiLine = /* @__PURE__ */ __name((text) => [
|
|
962
|
+
{
|
|
963
|
+
text,
|
|
964
|
+
bold: false,
|
|
965
|
+
italic: false,
|
|
966
|
+
underline: false,
|
|
967
|
+
dim: false,
|
|
968
|
+
inverse: false,
|
|
969
|
+
fg: "",
|
|
970
|
+
bg: ""
|
|
971
|
+
}
|
|
972
|
+
], "createPlainAnsiLine");
|
|
973
|
+
var serializePlainViewportToAnsiOutput = /* @__PURE__ */ __name((terminal, unwrapWrappedLines = false) => {
|
|
974
|
+
const buffer = terminal.buffer.active;
|
|
975
|
+
const lines = [];
|
|
976
|
+
for (let y = 0; y < terminal.rows; y++) {
|
|
977
|
+
const line = buffer.getLine(buffer.viewportY + y);
|
|
978
|
+
const lineContent = line ? line.translateToString(true) : "";
|
|
979
|
+
if (unwrapWrappedLines && line?.isWrapped && lines.length > 0) {
|
|
980
|
+
lines[lines.length - 1][0].text += lineContent;
|
|
981
|
+
} else {
|
|
982
|
+
lines.push(createPlainAnsiLine(lineContent));
|
|
983
|
+
}
|
|
984
|
+
}
|
|
985
|
+
return lines;
|
|
986
|
+
}, "serializePlainViewportToAnsiOutput");
|
|
987
|
+
var WINDOWS_TASKKILL = `${process.env["SystemRoot"] || "C:\\Windows"}\\System32\\taskkill.exe`;
|
|
988
|
+
var WINDOWS_TASKKILL_OPTIONS = { windowsHide: true };
|
|
989
|
+
var windowsKillPid = /* @__PURE__ */ __name((pid, tree) => {
|
|
990
|
+
try {
|
|
991
|
+
const args = tree ? ["/f", "/t", "/pid", pid.toString()] : ["/f", "/pid", pid.toString()];
|
|
992
|
+
const killer = cpSpawn(WINDOWS_TASKKILL, args, WINDOWS_TASKKILL_OPTIONS);
|
|
993
|
+
killer.on("error", (e) => {
|
|
994
|
+
debugLogger2.warn(
|
|
995
|
+
`windowsKillPid: taskkill failed to launch for pid ${pid}: ${e.message}`
|
|
996
|
+
);
|
|
997
|
+
});
|
|
998
|
+
killer.on("exit", (code, signal) => {
|
|
999
|
+
if (code !== 0 || signal) {
|
|
1000
|
+
debugLogger2.warn(
|
|
1001
|
+
`windowsKillPid: taskkill exited non-zero for pid ${pid}: ${signal ? `signal ${signal}` : `exit ${code}`}`
|
|
1002
|
+
);
|
|
1003
|
+
}
|
|
1004
|
+
});
|
|
1005
|
+
} catch (e) {
|
|
1006
|
+
debugLogger2.warn(
|
|
1007
|
+
`windowsKillPid: taskkill spawn threw for pid ${pid}: ${e instanceof Error ? e.message : String(e)}`
|
|
1008
|
+
);
|
|
1009
|
+
}
|
|
1010
|
+
}, "windowsKillPid");
|
|
1011
|
+
var windowsStrategy = {
|
|
1012
|
+
killPty: /* @__PURE__ */ __name((pid, pty) => {
|
|
1013
|
+
try {
|
|
1014
|
+
spawnSync(
|
|
1015
|
+
WINDOWS_TASKKILL,
|
|
1016
|
+
["/f", "/t", "/pid", pid.toString()],
|
|
1017
|
+
WINDOWS_TASKKILL_OPTIONS
|
|
1018
|
+
);
|
|
1019
|
+
} catch {
|
|
1020
|
+
}
|
|
1021
|
+
try {
|
|
1022
|
+
pty.ptyProcess.kill();
|
|
1023
|
+
} catch {
|
|
1024
|
+
}
|
|
1025
|
+
noteConPtyHostReleased(pty.ptyProcess);
|
|
1026
|
+
}, "killPty"),
|
|
1027
|
+
killChildProcesses: /* @__PURE__ */ __name((pids) => {
|
|
1028
|
+
if (pids.size > 0) {
|
|
1029
|
+
try {
|
|
1030
|
+
const args = ["/f", "/t"];
|
|
1031
|
+
for (const pid of pids) {
|
|
1032
|
+
args.push("/pid", pid.toString());
|
|
1033
|
+
}
|
|
1034
|
+
spawnSync(WINDOWS_TASKKILL, args, WINDOWS_TASKKILL_OPTIONS);
|
|
1035
|
+
} catch {
|
|
1036
|
+
}
|
|
1037
|
+
}
|
|
1038
|
+
}, "killChildProcesses")
|
|
1039
|
+
};
|
|
1040
|
+
var posixStrategy = {
|
|
1041
|
+
killPty: /* @__PURE__ */ __name((pid, _pty) => {
|
|
1042
|
+
process.kill(-pid, "SIGKILL");
|
|
1043
|
+
}, "killPty"),
|
|
1044
|
+
killChildProcesses: /* @__PURE__ */ __name((pids) => {
|
|
1045
|
+
for (const pid of pids) {
|
|
1046
|
+
try {
|
|
1047
|
+
process.kill(-pid, "SIGKILL");
|
|
1048
|
+
} catch {
|
|
1049
|
+
}
|
|
1050
|
+
}
|
|
1051
|
+
}, "killChildProcesses")
|
|
1052
|
+
};
|
|
1053
|
+
var getCleanupStrategy = /* @__PURE__ */ __name(() => os2.platform() === "win32" ? windowsStrategy : posixStrategy, "getCleanupStrategy");
|
|
1054
|
+
var ShellExecutionService = class _ShellExecutionService {
|
|
1055
|
+
static {
|
|
1056
|
+
__name(this, "ShellExecutionService");
|
|
1057
|
+
}
|
|
1058
|
+
static activePtys = /* @__PURE__ */ new Map();
|
|
1059
|
+
static activeChildProcesses = /* @__PURE__ */ new Set();
|
|
1060
|
+
static cleanup() {
|
|
1061
|
+
const strategy = getCleanupStrategy();
|
|
1062
|
+
for (const [pid, pty] of this.activePtys) {
|
|
1063
|
+
try {
|
|
1064
|
+
strategy.killPty(pid, pty);
|
|
1065
|
+
} catch {
|
|
1066
|
+
}
|
|
1067
|
+
try {
|
|
1068
|
+
pty.headlessTerminal.dispose();
|
|
1069
|
+
} catch {
|
|
1070
|
+
}
|
|
1071
|
+
}
|
|
1072
|
+
strategy.killChildProcesses(this.activeChildProcesses);
|
|
1073
|
+
}
|
|
1074
|
+
static {
|
|
1075
|
+
process.on("exit", () => {
|
|
1076
|
+
_ShellExecutionService.cleanup();
|
|
1077
|
+
});
|
|
1078
|
+
}
|
|
1079
|
+
/**
|
|
1080
|
+
* Executes a shell command using `node-pty`, capturing all output and lifecycle events.
|
|
1081
|
+
*
|
|
1082
|
+
* @param commandToExecute The exact command string to run.
|
|
1083
|
+
* @param cwd The working directory to execute the command in.
|
|
1084
|
+
* @param onOutputEvent A callback for streaming structured events about the execution, including data chunks and status updates.
|
|
1085
|
+
* @param abortSignal An AbortSignal to terminate the process and its children.
|
|
1086
|
+
* @returns An object containing the process ID (pid) and a promise that
|
|
1087
|
+
* resolves with the complete execution result.
|
|
1088
|
+
*/
|
|
1089
|
+
static async execute(commandToExecute, cwd, onOutputEvent, abortSignal, shouldUseNodePty, shellExecutionConfig, options = {}) {
|
|
1090
|
+
return this.executeInternal(
|
|
1091
|
+
commandToExecute,
|
|
1092
|
+
cwd,
|
|
1093
|
+
onOutputEvent,
|
|
1094
|
+
abortSignal,
|
|
1095
|
+
shouldUseNodePty,
|
|
1096
|
+
shellExecutionConfig,
|
|
1097
|
+
options
|
|
1098
|
+
);
|
|
1099
|
+
}
|
|
1100
|
+
static async executeLaunch(launch, onOutputEvent, abortSignal, shouldUseNodePty, shellExecutionConfig, options = {}) {
|
|
1101
|
+
const snapshot = {
|
|
1102
|
+
executable: launch.executable,
|
|
1103
|
+
args: [...launch.args],
|
|
1104
|
+
cwd: launch.cwd,
|
|
1105
|
+
env: { ...launch.env },
|
|
1106
|
+
stdin: Buffer.isBuffer(launch.stdin) ? Buffer.from(launch.stdin) : launch.stdin
|
|
1107
|
+
};
|
|
1108
|
+
if (!path.isAbsolute(snapshot.executable) || !path.isAbsolute(snapshot.cwd)) {
|
|
1109
|
+
throw new Error("Process executable and cwd must be absolute.");
|
|
1110
|
+
}
|
|
1111
|
+
if ([
|
|
1112
|
+
snapshot.executable,
|
|
1113
|
+
snapshot.cwd,
|
|
1114
|
+
...snapshot.args,
|
|
1115
|
+
...Object.values(snapshot.env)
|
|
1116
|
+
].some((value) => value.includes("\0")) || Object.keys(snapshot.env).some(
|
|
1117
|
+
(key) => !key || key.includes("=") || key.includes("\0")
|
|
1118
|
+
)) {
|
|
1119
|
+
throw new Error("Invalid process launch argument or environment.");
|
|
1120
|
+
}
|
|
1121
|
+
if (shouldUseNodePty && snapshot.stdin !== void 0) {
|
|
1122
|
+
throw new Error("Process stdin requires pipe execution.");
|
|
1123
|
+
}
|
|
1124
|
+
if (shouldUseNodePty && !snapshot.env["TERM"]) {
|
|
1125
|
+
throw new Error(
|
|
1126
|
+
"PTY launch requires an explicit TERM environment value."
|
|
1127
|
+
);
|
|
1128
|
+
}
|
|
1129
|
+
if (shouldUseNodePty && os2.platform() !== "win32" && snapshot.env["PWD"] !== snapshot.cwd) {
|
|
1130
|
+
throw new Error("PTY launch requires PWD to match cwd.");
|
|
1131
|
+
}
|
|
1132
|
+
return this.executeInternal(
|
|
1133
|
+
snapshot,
|
|
1134
|
+
snapshot.cwd,
|
|
1135
|
+
onOutputEvent,
|
|
1136
|
+
abortSignal,
|
|
1137
|
+
shouldUseNodePty,
|
|
1138
|
+
shellExecutionConfig,
|
|
1139
|
+
options
|
|
1140
|
+
);
|
|
1141
|
+
}
|
|
1142
|
+
static async executeInternal(commandToExecute, cwd, onOutputEvent, abortSignal, shouldUseNodePty, shellExecutionConfig, options) {
|
|
1143
|
+
if (abortSignal.aborted) {
|
|
1144
|
+
return createPreSpawnAbortedHandle();
|
|
1145
|
+
}
|
|
1146
|
+
if (shouldUseNodePty) {
|
|
1147
|
+
let removeAbortListener;
|
|
1148
|
+
const ptyResult = Promise.resolve(getPty()).then(
|
|
1149
|
+
(value) => ({ kind: "resolved", value }),
|
|
1150
|
+
(error) => ({ kind: "rejected", error })
|
|
1151
|
+
);
|
|
1152
|
+
const aborted = new Promise((resolve) => {
|
|
1153
|
+
const onAbort = /* @__PURE__ */ __name(() => resolve({ kind: "aborted" }), "onAbort");
|
|
1154
|
+
abortSignal.addEventListener("abort", onAbort, { once: true });
|
|
1155
|
+
removeAbortListener = /* @__PURE__ */ __name(() => abortSignal.removeEventListener("abort", onAbort), "removeAbortListener");
|
|
1156
|
+
if (abortSignal.aborted) onAbort();
|
|
1157
|
+
});
|
|
1158
|
+
const ptyOutcome = await Promise.race([ptyResult, aborted]);
|
|
1159
|
+
removeAbortListener?.();
|
|
1160
|
+
if (ptyOutcome.kind === "aborted") {
|
|
1161
|
+
return createPreSpawnAbortedHandle();
|
|
1162
|
+
}
|
|
1163
|
+
if (ptyOutcome.kind === "rejected") {
|
|
1164
|
+
throw ptyOutcome.error;
|
|
1165
|
+
}
|
|
1166
|
+
if (abortSignal.aborted) {
|
|
1167
|
+
return createPreSpawnAbortedHandle();
|
|
1168
|
+
}
|
|
1169
|
+
const ptyInfo = ptyOutcome.value;
|
|
1170
|
+
if (ptyInfo) {
|
|
1171
|
+
try {
|
|
1172
|
+
const { Terminal } = await loadXtermHeadless();
|
|
1173
|
+
if (abortSignal.aborted) {
|
|
1174
|
+
return createPreSpawnAbortedHandle();
|
|
1175
|
+
}
|
|
1176
|
+
return this.executeWithPty(
|
|
1177
|
+
commandToExecute,
|
|
1178
|
+
cwd,
|
|
1179
|
+
onOutputEvent,
|
|
1180
|
+
abortSignal,
|
|
1181
|
+
shellExecutionConfig,
|
|
1182
|
+
ptyInfo,
|
|
1183
|
+
Terminal,
|
|
1184
|
+
options.postPromote
|
|
1185
|
+
);
|
|
1186
|
+
} catch (_e) {
|
|
1187
|
+
}
|
|
1188
|
+
}
|
|
1189
|
+
}
|
|
1190
|
+
if (abortSignal.aborted) return createPreSpawnAbortedHandle();
|
|
1191
|
+
return this.childProcessFallback(
|
|
1192
|
+
commandToExecute,
|
|
1193
|
+
cwd,
|
|
1194
|
+
onOutputEvent,
|
|
1195
|
+
abortSignal,
|
|
1196
|
+
options.streamStdout ?? false,
|
|
1197
|
+
getMaxBufferedOutputBytes(shellExecutionConfig),
|
|
1198
|
+
shellExecutionConfig.pager,
|
|
1199
|
+
options.postPromote,
|
|
1200
|
+
shellExecutionConfig.streamBufferedOutput
|
|
1201
|
+
);
|
|
1202
|
+
}
|
|
1203
|
+
static childProcessFallback(commandToExecute, cwd, onOutputEvent, abortSignal, streamStdout, maxBufferedOutputBytes, pager, postPromote, streamBufferedOutput = false) {
|
|
1204
|
+
try {
|
|
1205
|
+
const isWindows = os2.platform() === "win32";
|
|
1206
|
+
const launch = typeof commandToExecute === "string" ? void 0 : commandToExecute;
|
|
1207
|
+
const {
|
|
1208
|
+
executable,
|
|
1209
|
+
args: shellArgs,
|
|
1210
|
+
shell
|
|
1211
|
+
} = launchCommand(commandToExecute);
|
|
1212
|
+
const child = cpSpawn(executable, shellArgs, {
|
|
1213
|
+
cwd,
|
|
1214
|
+
stdio: [
|
|
1215
|
+
launch?.stdin === void 0 ? "ignore" : "pipe",
|
|
1216
|
+
"pipe",
|
|
1217
|
+
"pipe"
|
|
1218
|
+
],
|
|
1219
|
+
windowsVerbatimArguments: isWindows && shell === "cmd",
|
|
1220
|
+
detached: !isWindows,
|
|
1221
|
+
windowsHide: isWindows,
|
|
1222
|
+
env: launch ? { ...launch.env } : {
|
|
1223
|
+
...normalizePathEnvForWindows(sanitizeChildEnv(process.env)),
|
|
1224
|
+
QWEN_CODE: "1",
|
|
1225
|
+
TERM: "xterm-256color",
|
|
1226
|
+
...getShellPagerEnv(pager, {
|
|
1227
|
+
includeGitPager: false,
|
|
1228
|
+
platform: os2.platform()
|
|
1229
|
+
}),
|
|
1230
|
+
...getShellContextEnvVars()
|
|
1231
|
+
}
|
|
1232
|
+
});
|
|
1233
|
+
const result = new Promise((resolve) => {
|
|
1234
|
+
let stdoutDecoder = null;
|
|
1235
|
+
let stderrDecoder = null;
|
|
1236
|
+
let stdout = "";
|
|
1237
|
+
let stderr = "";
|
|
1238
|
+
let stdoutPreview = "";
|
|
1239
|
+
let stderrPreview = "";
|
|
1240
|
+
const outputChunks = [];
|
|
1241
|
+
const sniffChunks = [];
|
|
1242
|
+
let error = null;
|
|
1243
|
+
let stdinError = null;
|
|
1244
|
+
let exited = false;
|
|
1245
|
+
let settled = false;
|
|
1246
|
+
let recordedExit = null;
|
|
1247
|
+
let drainTimer = null;
|
|
1248
|
+
let isStreamingRawContent = true;
|
|
1249
|
+
const MAX_SNIFF_SIZE = 4096;
|
|
1250
|
+
let sniffedBytes = 0;
|
|
1251
|
+
let capturedOutputBytes = 0;
|
|
1252
|
+
let totalOutputBytes = 0;
|
|
1253
|
+
let outputCaptureLimitExceeded = false;
|
|
1254
|
+
let outputCaptureLimitWarningEmitted = false;
|
|
1255
|
+
const markOutputCaptureLimitExceeded = /* @__PURE__ */ __name(() => {
|
|
1256
|
+
outputCaptureLimitExceeded = true;
|
|
1257
|
+
if (outputCaptureLimitWarningEmitted) {
|
|
1258
|
+
return;
|
|
1259
|
+
}
|
|
1260
|
+
outputCaptureLimitWarningEmitted = true;
|
|
1261
|
+
debugLogger2.warn(
|
|
1262
|
+
`Shell output capture exceeded maxBufferedOutputBytes (${maxBufferedOutputBytes} bytes). Total bytes: ${totalOutputBytes}. Discarding excess.`
|
|
1263
|
+
);
|
|
1264
|
+
}, "markOutputCaptureLimitExceeded");
|
|
1265
|
+
const captureOutputData = /* @__PURE__ */ __name((data) => {
|
|
1266
|
+
if (capturedOutputBytes >= maxBufferedOutputBytes) {
|
|
1267
|
+
markOutputCaptureLimitExceeded();
|
|
1268
|
+
return null;
|
|
1269
|
+
}
|
|
1270
|
+
const remainingBytes = maxBufferedOutputBytes - capturedOutputBytes;
|
|
1271
|
+
const captured = data.length > remainingBytes ? data.subarray(0, remainingBytes) : data;
|
|
1272
|
+
if (captured.length > 0) {
|
|
1273
|
+
outputChunks.push(captured);
|
|
1274
|
+
capturedOutputBytes += captured.length;
|
|
1275
|
+
}
|
|
1276
|
+
if (captured.length < data.length) {
|
|
1277
|
+
markOutputCaptureLimitExceeded();
|
|
1278
|
+
}
|
|
1279
|
+
return captured.length > 0 ? captured : null;
|
|
1280
|
+
}, "captureOutputData");
|
|
1281
|
+
const handleOutput = /* @__PURE__ */ __name((data, stream) => {
|
|
1282
|
+
if (!stdoutDecoder || !stderrDecoder) {
|
|
1283
|
+
const encoding = getCachedEncodingForBuffer(data);
|
|
1284
|
+
try {
|
|
1285
|
+
stdoutDecoder = new TextDecoder(encoding);
|
|
1286
|
+
stderrDecoder = new TextDecoder(encoding);
|
|
1287
|
+
} catch {
|
|
1288
|
+
stdoutDecoder = new TextDecoder("utf-8");
|
|
1289
|
+
stderrDecoder = new TextDecoder("utf-8");
|
|
1290
|
+
}
|
|
1291
|
+
}
|
|
1292
|
+
if (isStreamingRawContent && sniffedBytes < MAX_SNIFF_SIZE) {
|
|
1293
|
+
const sniffSlice = data.subarray(
|
|
1294
|
+
0,
|
|
1295
|
+
Math.min(data.length, MAX_SNIFF_SIZE - sniffedBytes)
|
|
1296
|
+
);
|
|
1297
|
+
if (sniffSlice.length > 0) {
|
|
1298
|
+
sniffChunks.push(sniffSlice);
|
|
1299
|
+
sniffedBytes += sniffSlice.length;
|
|
1300
|
+
}
|
|
1301
|
+
const sniffBuffer = Buffer.concat(sniffChunks);
|
|
1302
|
+
if (isBinary(sniffBuffer)) {
|
|
1303
|
+
isStreamingRawContent = false;
|
|
1304
|
+
if (streamStdout) {
|
|
1305
|
+
onOutputEvent({ type: "binary_detected" });
|
|
1306
|
+
sniffChunks.length = 0;
|
|
1307
|
+
}
|
|
1308
|
+
} else if (streamStdout && sniffedBytes >= MAX_SNIFF_SIZE) {
|
|
1309
|
+
sniffChunks.length = 0;
|
|
1310
|
+
}
|
|
1311
|
+
}
|
|
1312
|
+
totalOutputBytes += data.length;
|
|
1313
|
+
const capturedData = captureOutputData(data);
|
|
1314
|
+
if (!isStreamingRawContent) {
|
|
1315
|
+
return;
|
|
1316
|
+
}
|
|
1317
|
+
const decoder = stream === "stdout" ? stdoutDecoder : stderrDecoder;
|
|
1318
|
+
if (streamStdout) {
|
|
1319
|
+
const decodedChunk2 = decoder.decode(data, { stream: true });
|
|
1320
|
+
onOutputEvent({ type: "data", chunk: decodedChunk2, stream });
|
|
1321
|
+
return;
|
|
1322
|
+
}
|
|
1323
|
+
if (!capturedData) {
|
|
1324
|
+
return;
|
|
1325
|
+
}
|
|
1326
|
+
const decodedChunk = decoder.decode(capturedData, { stream: true });
|
|
1327
|
+
if (stream === "stdout") {
|
|
1328
|
+
stdout += decodedChunk;
|
|
1329
|
+
} else {
|
|
1330
|
+
stderr += decodedChunk;
|
|
1331
|
+
}
|
|
1332
|
+
if (streamBufferedOutput) {
|
|
1333
|
+
if (stream === "stdout") {
|
|
1334
|
+
stdoutPreview = (stdoutPreview + decodedChunk.slice(-65536)).slice(-65536);
|
|
1335
|
+
} else {
|
|
1336
|
+
stderrPreview = (stderrPreview + decodedChunk.slice(-65536)).slice(-65536);
|
|
1337
|
+
}
|
|
1338
|
+
const separator = stdoutPreview.endsWith("\n") ? "" : "\n";
|
|
1339
|
+
const snapshot = stdoutPreview + (stderrPreview ? (stdoutPreview ? separator : "") + stderrPreview : "");
|
|
1340
|
+
onOutputEvent({
|
|
1341
|
+
type: "data",
|
|
1342
|
+
chunk: stripAnsi(snapshot).slice(-65536)
|
|
1343
|
+
});
|
|
1344
|
+
}
|
|
1345
|
+
}, "handleOutput");
|
|
1346
|
+
const handleExit = /* @__PURE__ */ __name((code, signal) => {
|
|
1347
|
+
if (settled) return;
|
|
1348
|
+
settled = true;
|
|
1349
|
+
if (drainTimer) {
|
|
1350
|
+
clearTimeout(drainTimer);
|
|
1351
|
+
drainTimer = null;
|
|
1352
|
+
}
|
|
1353
|
+
const { finalBuffer } = cleanup();
|
|
1354
|
+
const separator = stdout.endsWith("\n") ? "" : "\n";
|
|
1355
|
+
const combinedOutput = stdout + (stderr ? (stdout ? separator : "") + stderr : "");
|
|
1356
|
+
const finalStrippedOutput = stripAnsi(combinedOutput).trim();
|
|
1357
|
+
const boundedOutput = appendOutputCaptureLimitNotice(
|
|
1358
|
+
finalStrippedOutput,
|
|
1359
|
+
outputCaptureLimitExceeded,
|
|
1360
|
+
totalOutputBytes,
|
|
1361
|
+
maxBufferedOutputBytes
|
|
1362
|
+
);
|
|
1363
|
+
if (isStreamingRawContent) {
|
|
1364
|
+
if (!streamStdout && boundedOutput) {
|
|
1365
|
+
onOutputEvent({ type: "data", chunk: boundedOutput });
|
|
1366
|
+
}
|
|
1367
|
+
} else {
|
|
1368
|
+
onOutputEvent({ type: "binary_detected" });
|
|
1369
|
+
}
|
|
1370
|
+
resolve({
|
|
1371
|
+
rawOutput: finalBuffer,
|
|
1372
|
+
output: boundedOutput,
|
|
1373
|
+
exitCode: code,
|
|
1374
|
+
signal: signal ? os2.constants.signals[signal] : null,
|
|
1375
|
+
error: error ?? (code === null && signal === null ? stdinError : null),
|
|
1376
|
+
aborted: abortSignal.aborted,
|
|
1377
|
+
pid: void 0,
|
|
1378
|
+
executionMethod: "child_process"
|
|
1379
|
+
});
|
|
1380
|
+
}, "handleExit");
|
|
1381
|
+
const stdoutHandler = /* @__PURE__ */ __name((data) => handleOutput(data, "stdout"), "stdoutHandler");
|
|
1382
|
+
const stderrHandler = /* @__PURE__ */ __name((data) => handleOutput(data, "stderr"), "stderrHandler");
|
|
1383
|
+
const errorHandler = /* @__PURE__ */ __name((err) => {
|
|
1384
|
+
error = err;
|
|
1385
|
+
handleExit(1, null);
|
|
1386
|
+
}, "errorHandler");
|
|
1387
|
+
const exitHandler = /* @__PURE__ */ __name((code, signal) => {
|
|
1388
|
+
if (child.pid) {
|
|
1389
|
+
this.activeChildProcesses.delete(child.pid);
|
|
1390
|
+
}
|
|
1391
|
+
if (!streamStdout) {
|
|
1392
|
+
handleExit(code, signal);
|
|
1393
|
+
return;
|
|
1394
|
+
}
|
|
1395
|
+
if (recordedExit) return;
|
|
1396
|
+
recordedExit = { code, signal };
|
|
1397
|
+
exited = true;
|
|
1398
|
+
drainTimer = setTimeout(() => {
|
|
1399
|
+
drainTimer = null;
|
|
1400
|
+
const recorded = recordedExit;
|
|
1401
|
+
if (recorded) handleExit(recorded.code, recorded.signal);
|
|
1402
|
+
}, POST_EXIT_STREAM_DRAIN_MS);
|
|
1403
|
+
drainTimer.unref?.();
|
|
1404
|
+
}, "exitHandler");
|
|
1405
|
+
const closeHandler = /* @__PURE__ */ __name((code, signal) => {
|
|
1406
|
+
const recorded = recordedExit ?? { code, signal };
|
|
1407
|
+
handleExit(recorded.code, recorded.signal);
|
|
1408
|
+
}, "closeHandler");
|
|
1409
|
+
child.stdout?.on("data", stdoutHandler);
|
|
1410
|
+
child.stderr?.on("data", stderrHandler);
|
|
1411
|
+
child.on("error", errorHandler);
|
|
1412
|
+
const detachServiceListeners = /* @__PURE__ */ __name(() => {
|
|
1413
|
+
child.stdout?.off("data", stdoutHandler);
|
|
1414
|
+
child.stderr?.off("data", stderrHandler);
|
|
1415
|
+
child.off("error", errorHandler);
|
|
1416
|
+
child.off("exit", exitHandler);
|
|
1417
|
+
child.off("close", closeHandler);
|
|
1418
|
+
}, "detachServiceListeners");
|
|
1419
|
+
const performBackgroundPromote = /* @__PURE__ */ __name(() => {
|
|
1420
|
+
if (!child.pid || exited) return;
|
|
1421
|
+
if (child.exitCode !== null || child.signalCode !== null) {
|
|
1422
|
+
debugLogger2.debug(
|
|
1423
|
+
`Background-promote requested for pid ${child.pid} but child is already terminal (exitCode=${child.exitCode}, signalCode=${child.signalCode}); falling through to the normal exit-handled resolution.`
|
|
1424
|
+
);
|
|
1425
|
+
return;
|
|
1426
|
+
}
|
|
1427
|
+
if (streamStdout) {
|
|
1428
|
+
debugLogger2.warn(
|
|
1429
|
+
"Background-promote on a streamStdout=true child_process: snapshot accumulators were never populated (output went through onOutputEvent), so result.output will be empty. Caller should fall back to rawOutput, or assemble its own snapshot from the data events it received."
|
|
1430
|
+
);
|
|
1431
|
+
}
|
|
1432
|
+
this.activeChildProcesses.delete(child.pid);
|
|
1433
|
+
detachServiceListeners();
|
|
1434
|
+
const {
|
|
1435
|
+
stdout: snapStdout,
|
|
1436
|
+
stderr: snapStderr,
|
|
1437
|
+
finalBuffer
|
|
1438
|
+
} = cleanup();
|
|
1439
|
+
const separator = snapStdout.endsWith("\n") ? "" : "\n";
|
|
1440
|
+
const combined = snapStdout + (snapStderr ? (snapStdout ? separator : "") + snapStderr : "");
|
|
1441
|
+
const boundedOutput = appendOutputCaptureLimitNotice(
|
|
1442
|
+
stripAnsi(combined).trim(),
|
|
1443
|
+
outputCaptureLimitExceeded,
|
|
1444
|
+
totalOutputBytes,
|
|
1445
|
+
maxBufferedOutputBytes
|
|
1446
|
+
);
|
|
1447
|
+
const detectedEncoding = stdoutDecoder?.encoding ?? "utf-8";
|
|
1448
|
+
const safeDecoder = /* @__PURE__ */ __name((encoding) => {
|
|
1449
|
+
try {
|
|
1450
|
+
return new TextDecoder(encoding, { fatal: false });
|
|
1451
|
+
} catch {
|
|
1452
|
+
return new TextDecoder("utf-8", { fatal: false });
|
|
1453
|
+
}
|
|
1454
|
+
}, "safeDecoder");
|
|
1455
|
+
const postPromoteStdoutDecoder = postPromote?.onData ? safeDecoder(detectedEncoding) : null;
|
|
1456
|
+
const postPromoteStderrDecoder = postPromote?.onData ? safeDecoder(detectedEncoding) : null;
|
|
1457
|
+
let postPromoteStdoutHandler = null;
|
|
1458
|
+
let postPromoteStderrHandler = null;
|
|
1459
|
+
if (postPromote?.onData) {
|
|
1460
|
+
const onPostData = postPromote.onData;
|
|
1461
|
+
const safeData = /* @__PURE__ */ __name((decoder) => (chunk) => {
|
|
1462
|
+
try {
|
|
1463
|
+
onPostData({
|
|
1464
|
+
type: "data",
|
|
1465
|
+
chunk: decoder.decode(chunk, { stream: true })
|
|
1466
|
+
});
|
|
1467
|
+
} catch (cbErr) {
|
|
1468
|
+
debugLogger2.warn(
|
|
1469
|
+
`postPromote.onData threw: ${cbErr instanceof Error ? cbErr.message : String(cbErr)}`
|
|
1470
|
+
);
|
|
1471
|
+
}
|
|
1472
|
+
}, "safeData");
|
|
1473
|
+
try {
|
|
1474
|
+
if (postPromoteStdoutDecoder) {
|
|
1475
|
+
postPromoteStdoutHandler = safeData(postPromoteStdoutDecoder);
|
|
1476
|
+
child.stdout?.on("data", postPromoteStdoutHandler);
|
|
1477
|
+
}
|
|
1478
|
+
if (postPromoteStderrDecoder) {
|
|
1479
|
+
postPromoteStderrHandler = safeData(postPromoteStderrDecoder);
|
|
1480
|
+
child.stderr?.on("data", postPromoteStderrHandler);
|
|
1481
|
+
}
|
|
1482
|
+
} catch (e) {
|
|
1483
|
+
debugLogger2.warn(
|
|
1484
|
+
`re-attaching post-promote data listeners threw: ${e instanceof Error ? e.message : String(e)}`
|
|
1485
|
+
);
|
|
1486
|
+
}
|
|
1487
|
+
} else if (postPromote) {
|
|
1488
|
+
try {
|
|
1489
|
+
child.stdout?.resume();
|
|
1490
|
+
child.stderr?.resume();
|
|
1491
|
+
} catch (e) {
|
|
1492
|
+
debugLogger2.warn(
|
|
1493
|
+
`post-promote stdout/stderr resume() threw: ${e instanceof Error ? e.message : String(e)}`
|
|
1494
|
+
);
|
|
1495
|
+
}
|
|
1496
|
+
}
|
|
1497
|
+
let postPromoteSettleFired = false;
|
|
1498
|
+
const flushPostPromoteDecoders = /* @__PURE__ */ __name(() => {
|
|
1499
|
+
if (!postPromote?.onData) return;
|
|
1500
|
+
try {
|
|
1501
|
+
if (postPromoteStdoutDecoder) {
|
|
1502
|
+
const trailing = postPromoteStdoutDecoder.decode();
|
|
1503
|
+
if (trailing) {
|
|
1504
|
+
postPromote.onData({
|
|
1505
|
+
type: "data",
|
|
1506
|
+
chunk: trailing
|
|
1507
|
+
});
|
|
1508
|
+
}
|
|
1509
|
+
}
|
|
1510
|
+
if (postPromoteStderrDecoder) {
|
|
1511
|
+
const trailing = postPromoteStderrDecoder.decode();
|
|
1512
|
+
if (trailing) {
|
|
1513
|
+
postPromote.onData({
|
|
1514
|
+
type: "data",
|
|
1515
|
+
chunk: trailing
|
|
1516
|
+
});
|
|
1517
|
+
}
|
|
1518
|
+
}
|
|
1519
|
+
} catch (flushErr) {
|
|
1520
|
+
debugLogger2.warn(
|
|
1521
|
+
`post-promote decoder flush threw: ${flushErr instanceof Error ? flushErr.message : String(flushErr)}`
|
|
1522
|
+
);
|
|
1523
|
+
}
|
|
1524
|
+
}, "flushPostPromoteDecoders");
|
|
1525
|
+
const firePostSettle = /* @__PURE__ */ __name((info) => {
|
|
1526
|
+
if (postPromoteSettleFired) return;
|
|
1527
|
+
postPromoteSettleFired = true;
|
|
1528
|
+
flushPostPromoteDecoders();
|
|
1529
|
+
if (postPromoteStdoutHandler) {
|
|
1530
|
+
child.stdout?.off("data", postPromoteStdoutHandler);
|
|
1531
|
+
postPromoteStdoutHandler = null;
|
|
1532
|
+
}
|
|
1533
|
+
if (postPromoteStderrHandler) {
|
|
1534
|
+
child.stderr?.off("data", postPromoteStderrHandler);
|
|
1535
|
+
postPromoteStderrHandler = null;
|
|
1536
|
+
}
|
|
1537
|
+
if (!postPromote?.onSettle) return;
|
|
1538
|
+
try {
|
|
1539
|
+
postPromote.onSettle(info);
|
|
1540
|
+
} catch (cbErr) {
|
|
1541
|
+
debugLogger2.warn(
|
|
1542
|
+
`postPromote.onSettle threw: ${cbErr instanceof Error ? cbErr.message : String(cbErr)}`
|
|
1543
|
+
);
|
|
1544
|
+
}
|
|
1545
|
+
}, "firePostSettle");
|
|
1546
|
+
if (postPromote) {
|
|
1547
|
+
try {
|
|
1548
|
+
child.once(
|
|
1549
|
+
"close",
|
|
1550
|
+
(exitCode, signalCode) => {
|
|
1551
|
+
firePostSettle({
|
|
1552
|
+
exitCode,
|
|
1553
|
+
signal: signalCode,
|
|
1554
|
+
endTime: Date.now()
|
|
1555
|
+
});
|
|
1556
|
+
}
|
|
1557
|
+
);
|
|
1558
|
+
child.once("error", (err) => {
|
|
1559
|
+
firePostSettle({
|
|
1560
|
+
exitCode: null,
|
|
1561
|
+
signal: null,
|
|
1562
|
+
error: err,
|
|
1563
|
+
endTime: Date.now()
|
|
1564
|
+
});
|
|
1565
|
+
});
|
|
1566
|
+
} catch (e) {
|
|
1567
|
+
debugLogger2.warn(
|
|
1568
|
+
`re-attaching post-promote exit/error listeners threw: ${e instanceof Error ? e.message : String(e)}`
|
|
1569
|
+
);
|
|
1570
|
+
}
|
|
1571
|
+
}
|
|
1572
|
+
resolve({
|
|
1573
|
+
rawOutput: finalBuffer,
|
|
1574
|
+
output: boundedOutput,
|
|
1575
|
+
exitCode: null,
|
|
1576
|
+
signal: null,
|
|
1577
|
+
error: null,
|
|
1578
|
+
// `aborted: false` (despite the abort signal having fired) is
|
|
1579
|
+
// intentional — this is the result-shape decision settled in
|
|
1580
|
+
// #3831 design question 7 (raised by @tanzhenxin in the PR-1
|
|
1581
|
+
// review). The flag answers "should the caller emit cancel /
|
|
1582
|
+
// timeout copy?" not "did the abort signal fire?" — and a
|
|
1583
|
+
// promoted shell did NOT cancel (the child kept running), so
|
|
1584
|
+
// existing `if (result.aborted)` branches in callers (e.g.
|
|
1585
|
+
// `tools/shell.ts`) fall through naturally to the success-shape
|
|
1586
|
+
// arm where we then check `result.promoted`. Without this,
|
|
1587
|
+
// every consumer would have to remember to check `promoted`
|
|
1588
|
+
// before `aborted` to avoid emitting "cancelled" copy for a
|
|
1589
|
+
// process that's still running.
|
|
1590
|
+
aborted: false,
|
|
1591
|
+
promoted: true,
|
|
1592
|
+
pid: child.pid,
|
|
1593
|
+
executionMethod: "child_process"
|
|
1594
|
+
});
|
|
1595
|
+
}, "performBackgroundPromote");
|
|
1596
|
+
const performCancelKill = /* @__PURE__ */ __name(async () => {
|
|
1597
|
+
if (!child.pid || exited) return;
|
|
1598
|
+
if (isWindows) {
|
|
1599
|
+
const killer = cpSpawn(
|
|
1600
|
+
WINDOWS_TASKKILL,
|
|
1601
|
+
["/f", "/t", "/pid", child.pid.toString()],
|
|
1602
|
+
WINDOWS_TASKKILL_OPTIONS
|
|
1603
|
+
);
|
|
1604
|
+
const killChildFallback = /* @__PURE__ */ __name((why) => {
|
|
1605
|
+
debugLogger2.warn(
|
|
1606
|
+
`performCancelKill (child_process): taskkill ${why} for pid ${child.pid}; falling back to child.kill`
|
|
1607
|
+
);
|
|
1608
|
+
if (!exited) {
|
|
1609
|
+
try {
|
|
1610
|
+
child.kill("SIGKILL");
|
|
1611
|
+
} catch {
|
|
1612
|
+
}
|
|
1613
|
+
}
|
|
1614
|
+
}, "killChildFallback");
|
|
1615
|
+
killer.on(
|
|
1616
|
+
"error",
|
|
1617
|
+
(e) => killChildFallback(`failed to launch (${e.message})`)
|
|
1618
|
+
);
|
|
1619
|
+
killer.on("exit", (code) => {
|
|
1620
|
+
if (code !== 0) killChildFallback(`exited ${code}`);
|
|
1621
|
+
});
|
|
1622
|
+
} else {
|
|
1623
|
+
try {
|
|
1624
|
+
process.kill(-child.pid, "SIGTERM");
|
|
1625
|
+
await new Promise((res) => setTimeout(res, SIGKILL_TIMEOUT_MS));
|
|
1626
|
+
if (!exited) {
|
|
1627
|
+
process.kill(-child.pid, "SIGKILL");
|
|
1628
|
+
}
|
|
1629
|
+
} catch (_e) {
|
|
1630
|
+
if (!exited) child.kill("SIGKILL");
|
|
1631
|
+
}
|
|
1632
|
+
}
|
|
1633
|
+
}, "performCancelKill");
|
|
1634
|
+
const abortHandler = /* @__PURE__ */ __name(async () => {
|
|
1635
|
+
const kind = getShellAbortReasonKind(abortSignal.reason);
|
|
1636
|
+
switch (kind) {
|
|
1637
|
+
case "background":
|
|
1638
|
+
performBackgroundPromote();
|
|
1639
|
+
return;
|
|
1640
|
+
case "cancel":
|
|
1641
|
+
await performCancelKill();
|
|
1642
|
+
return;
|
|
1643
|
+
default: {
|
|
1644
|
+
const _exhaustive = kind;
|
|
1645
|
+
await performCancelKill();
|
|
1646
|
+
return _exhaustive;
|
|
1647
|
+
}
|
|
1648
|
+
}
|
|
1649
|
+
}, "abortHandler");
|
|
1650
|
+
abortSignal.addEventListener("abort", abortHandler, { once: true });
|
|
1651
|
+
if (child.pid) {
|
|
1652
|
+
this.activeChildProcesses.add(child.pid);
|
|
1653
|
+
}
|
|
1654
|
+
child.on("exit", exitHandler);
|
|
1655
|
+
if (streamStdout) {
|
|
1656
|
+
child.once("close", closeHandler);
|
|
1657
|
+
}
|
|
1658
|
+
if (launch?.stdin !== void 0 && child.stdin) {
|
|
1659
|
+
child.stdin.on("error", (err) => {
|
|
1660
|
+
stdinError = err;
|
|
1661
|
+
debugLogger2.warn(
|
|
1662
|
+
`stdin transport error for pid ${child.pid}: ${err.message}`
|
|
1663
|
+
);
|
|
1664
|
+
});
|
|
1665
|
+
child.stdin.end(launch.stdin);
|
|
1666
|
+
}
|
|
1667
|
+
function cleanup() {
|
|
1668
|
+
exited = true;
|
|
1669
|
+
abortSignal.removeEventListener("abort", abortHandler);
|
|
1670
|
+
if (stdoutDecoder) {
|
|
1671
|
+
const remaining = stdoutDecoder.decode();
|
|
1672
|
+
if (remaining) {
|
|
1673
|
+
if (streamStdout) {
|
|
1674
|
+
if (isStreamingRawContent)
|
|
1675
|
+
onOutputEvent({
|
|
1676
|
+
type: "data",
|
|
1677
|
+
chunk: remaining,
|
|
1678
|
+
stream: "stdout"
|
|
1679
|
+
});
|
|
1680
|
+
} else stdout += remaining;
|
|
1681
|
+
}
|
|
1682
|
+
}
|
|
1683
|
+
if (stderrDecoder) {
|
|
1684
|
+
const remaining = stderrDecoder.decode();
|
|
1685
|
+
if (remaining) {
|
|
1686
|
+
if (streamStdout) {
|
|
1687
|
+
if (isStreamingRawContent)
|
|
1688
|
+
onOutputEvent({
|
|
1689
|
+
type: "data",
|
|
1690
|
+
chunk: remaining,
|
|
1691
|
+
stream: "stderr"
|
|
1692
|
+
});
|
|
1693
|
+
} else stderr += remaining;
|
|
1694
|
+
}
|
|
1695
|
+
}
|
|
1696
|
+
const finalBuffer = Buffer.concat(outputChunks);
|
|
1697
|
+
return { stdout, stderr, finalBuffer };
|
|
1698
|
+
}
|
|
1699
|
+
__name(cleanup, "cleanup");
|
|
1700
|
+
});
|
|
1701
|
+
return { pid: child.pid, result };
|
|
1702
|
+
} catch (e) {
|
|
1703
|
+
const error = e;
|
|
1704
|
+
return {
|
|
1705
|
+
pid: void 0,
|
|
1706
|
+
result: Promise.resolve({
|
|
1707
|
+
error,
|
|
1708
|
+
rawOutput: Buffer.from(""),
|
|
1709
|
+
output: "",
|
|
1710
|
+
exitCode: 1,
|
|
1711
|
+
signal: null,
|
|
1712
|
+
aborted: false,
|
|
1713
|
+
pid: void 0,
|
|
1714
|
+
executionMethod: "none"
|
|
1715
|
+
})
|
|
1716
|
+
};
|
|
1717
|
+
}
|
|
1718
|
+
}
|
|
1719
|
+
static executeWithPty(commandToExecute, cwd, onOutputEvent, abortSignal, shellExecutionConfig, ptyInfo, Terminal, postPromote) {
|
|
1720
|
+
if (!ptyInfo) {
|
|
1721
|
+
throw new Error("PTY implementation not found");
|
|
1722
|
+
}
|
|
1723
|
+
const useBundledConpty = os2.platform() === "win32";
|
|
1724
|
+
let ptySpawned = false;
|
|
1725
|
+
try {
|
|
1726
|
+
const cols = shellExecutionConfig.terminalWidth ?? 80;
|
|
1727
|
+
const rows = shellExecutionConfig.terminalHeight ?? 30;
|
|
1728
|
+
const launch = typeof commandToExecute === "string" ? void 0 : commandToExecute;
|
|
1729
|
+
const {
|
|
1730
|
+
executable,
|
|
1731
|
+
args: launchArgs,
|
|
1732
|
+
shell
|
|
1733
|
+
} = launchCommand(commandToExecute);
|
|
1734
|
+
const args = os2.platform() === "win32" && shell === "cmd" ? launchArgs.join(" ") : launchArgs;
|
|
1735
|
+
const ptyProcess = ptyInfo.module.spawn(executable, args, {
|
|
1736
|
+
cwd,
|
|
1737
|
+
name: launch?.env["TERM"] ?? "xterm",
|
|
1738
|
+
cols,
|
|
1739
|
+
rows,
|
|
1740
|
+
env: launch ? { ...launch.env } : {
|
|
1741
|
+
...normalizePathEnvForWindows(sanitizeChildEnv(process.env)),
|
|
1742
|
+
QWEN_CODE: "1",
|
|
1743
|
+
TERM: "xterm-256color",
|
|
1744
|
+
...getShellPagerEnv(shellExecutionConfig.pager, {
|
|
1745
|
+
includeGitPager: true,
|
|
1746
|
+
platform: os2.platform()
|
|
1747
|
+
}),
|
|
1748
|
+
...getShellContextEnvVars()
|
|
1749
|
+
},
|
|
1750
|
+
handleFlowControl: true,
|
|
1751
|
+
// Windows: with the inbox ConPTY backend a natural shell exit orphans
|
|
1752
|
+
// the `conhost.exe --headless` that backend spawned — the native exit
|
|
1753
|
+
// watcher erases the pty baton before JS can reach ClosePseudoConsole
|
|
1754
|
+
// (microsoft/node-pty#965), so hosts accumulate until the CLI exits.
|
|
1755
|
+
// The bundled backend calls ConptyReleasePseudoConsole after spawn,
|
|
1756
|
+
// releasing the reference that otherwise keeps its host alive after
|
|
1757
|
+
// the last client exits. Windows verification must count both
|
|
1758
|
+
// `conhost.exe` and `OpenConsole.exe` (or all attributable children),
|
|
1759
|
+
// because the bundled backend normally launches `OpenConsole.exe`. Off
|
|
1760
|
+
// Windows the option is inert: `useConptyDll` appears nowhere in the
|
|
1761
|
+
// POSIX prebuilds.
|
|
1762
|
+
useConptyDll: useBundledConpty
|
|
1763
|
+
});
|
|
1764
|
+
ptySpawned = true;
|
|
1765
|
+
const result = new Promise((resolve) => {
|
|
1766
|
+
const headlessTerminal = new Terminal({
|
|
1767
|
+
allowProposedApi: true,
|
|
1768
|
+
cols,
|
|
1769
|
+
rows,
|
|
1770
|
+
scrollback: MAX_LIVE_TERMINAL_SCROLLBACK_LINES,
|
|
1771
|
+
// This headless terminal only captures output, so suppress parser diagnostics.
|
|
1772
|
+
logLevel: "off"
|
|
1773
|
+
});
|
|
1774
|
+
headlessTerminal.scrollToTop();
|
|
1775
|
+
const queryResponseDisposable = useBundledConpty ? headlessTerminal.onData((data) => {
|
|
1776
|
+
try {
|
|
1777
|
+
ptyProcess.write(data);
|
|
1778
|
+
} catch (e) {
|
|
1779
|
+
debugLogger2.warn(
|
|
1780
|
+
`writing terminal query reply to PTY threw: ${e instanceof Error ? e.message : String(e)}`
|
|
1781
|
+
);
|
|
1782
|
+
}
|
|
1783
|
+
}) : null;
|
|
1784
|
+
this.activePtys.set(ptyProcess.pid, { ptyProcess, headlessTerminal });
|
|
1785
|
+
let processingChain = Promise.resolve();
|
|
1786
|
+
let decoder = null;
|
|
1787
|
+
let outputComparison = null;
|
|
1788
|
+
const outputChunks = [];
|
|
1789
|
+
const sniffChunks = [];
|
|
1790
|
+
const error = null;
|
|
1791
|
+
let exited = false;
|
|
1792
|
+
let cancelKillDispatched = false;
|
|
1793
|
+
let isStreamingRawContent = true;
|
|
1794
|
+
const MAX_SNIFF_SIZE = 4096;
|
|
1795
|
+
let sniffedBytes = 0;
|
|
1796
|
+
let totalBytesReceived = 0;
|
|
1797
|
+
const maxBufferedOutputBytes = getMaxBufferedOutputBytes(shellExecutionConfig);
|
|
1798
|
+
let capturedOutputBytes = 0;
|
|
1799
|
+
let outputCaptureLimitExceeded = false;
|
|
1800
|
+
let outputCaptureLimitWarningEmitted = false;
|
|
1801
|
+
let isWriting = false;
|
|
1802
|
+
let hasStartedOutput = false;
|
|
1803
|
+
let renderTimeout = null;
|
|
1804
|
+
let listenersDetached = false;
|
|
1805
|
+
const RENDER_THROTTLE_MS = 100;
|
|
1806
|
+
const markOutputCaptureLimitExceeded = /* @__PURE__ */ __name(() => {
|
|
1807
|
+
outputCaptureLimitExceeded = true;
|
|
1808
|
+
if (outputCaptureLimitWarningEmitted) {
|
|
1809
|
+
return;
|
|
1810
|
+
}
|
|
1811
|
+
outputCaptureLimitWarningEmitted = true;
|
|
1812
|
+
debugLogger2.warn(
|
|
1813
|
+
`Shell output capture exceeded maxBufferedOutputBytes (${maxBufferedOutputBytes} bytes). Total bytes: ${totalBytesReceived}. Discarding excess.`
|
|
1814
|
+
);
|
|
1815
|
+
}, "markOutputCaptureLimitExceeded");
|
|
1816
|
+
const renderFn = /* @__PURE__ */ __name(() => {
|
|
1817
|
+
if (!isStreamingRawContent || listenersDetached) {
|
|
1818
|
+
return;
|
|
1819
|
+
}
|
|
1820
|
+
if (!shellExecutionConfig.disableDynamicLineTrimming) {
|
|
1821
|
+
if (!hasStartedOutput) {
|
|
1822
|
+
const bufferText = serializeTerminalToText(headlessTerminal);
|
|
1823
|
+
if (bufferText.trim().length === 0) {
|
|
1824
|
+
return;
|
|
1825
|
+
}
|
|
1826
|
+
hasStartedOutput = true;
|
|
1827
|
+
}
|
|
1828
|
+
}
|
|
1829
|
+
let newOutput;
|
|
1830
|
+
let newOutputComparison;
|
|
1831
|
+
if (shellExecutionConfig.showColor) {
|
|
1832
|
+
newOutput = serializeTerminalToObject(headlessTerminal);
|
|
1833
|
+
newOutputComparison = serializeTerminalToObject(
|
|
1834
|
+
headlessTerminal,
|
|
1835
|
+
0,
|
|
1836
|
+
{ unwrapWrappedLines: true }
|
|
1837
|
+
);
|
|
1838
|
+
} else {
|
|
1839
|
+
newOutput = serializePlainViewportToAnsiOutput(headlessTerminal);
|
|
1840
|
+
newOutputComparison = serializePlainViewportToAnsiOutput(
|
|
1841
|
+
headlessTerminal,
|
|
1842
|
+
true
|
|
1843
|
+
);
|
|
1844
|
+
}
|
|
1845
|
+
const trimmedOutput = trimTrailingEmptyAnsiLines(newOutput);
|
|
1846
|
+
const trimmedOutputComparison = trimTrailingEmptyAnsiLines(newOutputComparison);
|
|
1847
|
+
const finalOutput = shellExecutionConfig.disableDynamicLineTrimming ? newOutput : trimmedOutput;
|
|
1848
|
+
const finalOutputComparison = shellExecutionConfig.disableDynamicLineTrimming ? newOutputComparison : trimmedOutputComparison;
|
|
1849
|
+
if (!areAnsiOutputsEqual(outputComparison, finalOutputComparison)) {
|
|
1850
|
+
outputComparison = finalOutputComparison;
|
|
1851
|
+
onOutputEvent({
|
|
1852
|
+
type: "data",
|
|
1853
|
+
chunk: finalOutput
|
|
1854
|
+
});
|
|
1855
|
+
}
|
|
1856
|
+
}, "renderFn");
|
|
1857
|
+
let pendingTrailingRender = false;
|
|
1858
|
+
const render = /* @__PURE__ */ __name((finalRender = false) => {
|
|
1859
|
+
if (finalRender) {
|
|
1860
|
+
if (renderTimeout) {
|
|
1861
|
+
clearTimeout(renderTimeout);
|
|
1862
|
+
renderTimeout = null;
|
|
1863
|
+
}
|
|
1864
|
+
renderFn();
|
|
1865
|
+
return;
|
|
1866
|
+
}
|
|
1867
|
+
if (!renderTimeout) {
|
|
1868
|
+
renderFn();
|
|
1869
|
+
renderTimeout = setTimeout(() => {
|
|
1870
|
+
renderTimeout = null;
|
|
1871
|
+
if (pendingTrailingRender) {
|
|
1872
|
+
pendingTrailingRender = false;
|
|
1873
|
+
render();
|
|
1874
|
+
}
|
|
1875
|
+
}, RENDER_THROTTLE_MS);
|
|
1876
|
+
} else {
|
|
1877
|
+
pendingTrailingRender = true;
|
|
1878
|
+
}
|
|
1879
|
+
}, "render");
|
|
1880
|
+
headlessTerminal.onScroll(() => {
|
|
1881
|
+
if (!isWriting) {
|
|
1882
|
+
render();
|
|
1883
|
+
}
|
|
1884
|
+
});
|
|
1885
|
+
const ensureDecoder = /* @__PURE__ */ __name((data) => {
|
|
1886
|
+
if (decoder) {
|
|
1887
|
+
return;
|
|
1888
|
+
}
|
|
1889
|
+
const encoding = getCachedEncodingForBuffer(data);
|
|
1890
|
+
try {
|
|
1891
|
+
decoder = new TextDecoder(encoding);
|
|
1892
|
+
} catch {
|
|
1893
|
+
decoder = new TextDecoder("utf-8");
|
|
1894
|
+
}
|
|
1895
|
+
}, "ensureDecoder");
|
|
1896
|
+
const captureOutputData = /* @__PURE__ */ __name((data) => {
|
|
1897
|
+
if (capturedOutputBytes >= maxBufferedOutputBytes) {
|
|
1898
|
+
markOutputCaptureLimitExceeded();
|
|
1899
|
+
return;
|
|
1900
|
+
}
|
|
1901
|
+
const remainingBytes = maxBufferedOutputBytes - capturedOutputBytes;
|
|
1902
|
+
const captured = data.length > remainingBytes ? data.subarray(0, remainingBytes) : data;
|
|
1903
|
+
if (captured.length > 0) {
|
|
1904
|
+
outputChunks.push(captured);
|
|
1905
|
+
capturedOutputBytes += captured.length;
|
|
1906
|
+
}
|
|
1907
|
+
if (captured.length < data.length) {
|
|
1908
|
+
markOutputCaptureLimitExceeded();
|
|
1909
|
+
}
|
|
1910
|
+
}, "captureOutputData");
|
|
1911
|
+
const handleOutput = /* @__PURE__ */ __name((data) => {
|
|
1912
|
+
ensureDecoder(data);
|
|
1913
|
+
totalBytesReceived += data.length;
|
|
1914
|
+
captureOutputData(data);
|
|
1915
|
+
const bytesReceived = totalBytesReceived;
|
|
1916
|
+
processingChain = processingChain.then(
|
|
1917
|
+
() => new Promise((resolve2) => {
|
|
1918
|
+
if (isStreamingRawContent && sniffedBytes < MAX_SNIFF_SIZE) {
|
|
1919
|
+
const sniffSlice = data.subarray(
|
|
1920
|
+
0,
|
|
1921
|
+
Math.min(data.length, MAX_SNIFF_SIZE - sniffedBytes)
|
|
1922
|
+
);
|
|
1923
|
+
if (sniffSlice.length > 0) {
|
|
1924
|
+
sniffChunks.push(sniffSlice);
|
|
1925
|
+
sniffedBytes += sniffSlice.length;
|
|
1926
|
+
}
|
|
1927
|
+
const sniffBuffer = Buffer.concat(sniffChunks);
|
|
1928
|
+
if (isBinary(sniffBuffer)) {
|
|
1929
|
+
isStreamingRawContent = false;
|
|
1930
|
+
if (!listenersDetached) {
|
|
1931
|
+
onOutputEvent({ type: "binary_detected" });
|
|
1932
|
+
}
|
|
1933
|
+
}
|
|
1934
|
+
}
|
|
1935
|
+
if (isStreamingRawContent) {
|
|
1936
|
+
const decodedChunk = decoder.decode(data, { stream: true });
|
|
1937
|
+
isWriting = true;
|
|
1938
|
+
headlessTerminal.write(decodedChunk, () => {
|
|
1939
|
+
render();
|
|
1940
|
+
isWriting = false;
|
|
1941
|
+
resolve2();
|
|
1942
|
+
});
|
|
1943
|
+
} else {
|
|
1944
|
+
if (!listenersDetached) {
|
|
1945
|
+
onOutputEvent({
|
|
1946
|
+
type: "binary_progress",
|
|
1947
|
+
bytesReceived
|
|
1948
|
+
});
|
|
1949
|
+
}
|
|
1950
|
+
resolve2();
|
|
1951
|
+
}
|
|
1952
|
+
})
|
|
1953
|
+
);
|
|
1954
|
+
}, "handleOutput");
|
|
1955
|
+
const dataDisposable = ptyProcess.onData((data) => {
|
|
1956
|
+
const bufferData = Buffer.from(data, "utf-8");
|
|
1957
|
+
handleOutput(bufferData);
|
|
1958
|
+
});
|
|
1959
|
+
const ptyErrorHandler = /* @__PURE__ */ __name((err) => {
|
|
1960
|
+
if (isExpectedPtyReadExitError(err)) {
|
|
1961
|
+
return;
|
|
1962
|
+
}
|
|
1963
|
+
throw err;
|
|
1964
|
+
}, "ptyErrorHandler");
|
|
1965
|
+
ptyProcess.on("error", ptyErrorHandler);
|
|
1966
|
+
const disposeForegroundPtyResources = /* @__PURE__ */ __name(() => {
|
|
1967
|
+
listenersDetached = true;
|
|
1968
|
+
if (renderTimeout) {
|
|
1969
|
+
clearTimeout(renderTimeout);
|
|
1970
|
+
renderTimeout = null;
|
|
1971
|
+
}
|
|
1972
|
+
try {
|
|
1973
|
+
dataDisposable.dispose();
|
|
1974
|
+
} catch (e) {
|
|
1975
|
+
debugLogger2.warn(
|
|
1976
|
+
`dataDisposable.dispose() threw during PTY cleanup: ${e instanceof Error ? e.message : String(e)}`
|
|
1977
|
+
);
|
|
1978
|
+
}
|
|
1979
|
+
try {
|
|
1980
|
+
exitDisposable.dispose();
|
|
1981
|
+
} catch (e) {
|
|
1982
|
+
debugLogger2.warn(
|
|
1983
|
+
`exitDisposable.dispose() threw during PTY cleanup: ${e instanceof Error ? e.message : String(e)}`
|
|
1984
|
+
);
|
|
1985
|
+
}
|
|
1986
|
+
try {
|
|
1987
|
+
ptyProcess.removeListener("error", ptyErrorHandler);
|
|
1988
|
+
} catch (e) {
|
|
1989
|
+
debugLogger2.warn(
|
|
1990
|
+
`ptyProcess.removeListener('error') threw during PTY cleanup: ${e instanceof Error ? e.message : String(e)}`
|
|
1991
|
+
);
|
|
1992
|
+
}
|
|
1993
|
+
try {
|
|
1994
|
+
queryResponseDisposable?.dispose();
|
|
1995
|
+
} catch (e) {
|
|
1996
|
+
debugLogger2.warn(
|
|
1997
|
+
`queryResponseDisposable.dispose() threw during PTY cleanup: ${e instanceof Error ? e.message : String(e)}`
|
|
1998
|
+
);
|
|
1999
|
+
}
|
|
2000
|
+
try {
|
|
2001
|
+
headlessTerminal.dispose();
|
|
2002
|
+
} catch (e) {
|
|
2003
|
+
debugLogger2.warn(
|
|
2004
|
+
`headlessTerminal.dispose() threw during PTY cleanup: ${e instanceof Error ? e.message : String(e)}`
|
|
2005
|
+
);
|
|
2006
|
+
}
|
|
2007
|
+
if (os2.platform() === "win32" && _ShellExecutionService.isPtyActive(ptyProcess.pid)) {
|
|
2008
|
+
windowsKillPid(ptyProcess.pid, cancelKillDispatched);
|
|
2009
|
+
}
|
|
2010
|
+
releaseConPtyHost(ptyProcess);
|
|
2011
|
+
this.activePtys.delete(ptyProcess.pid);
|
|
2012
|
+
}, "disposeForegroundPtyResources");
|
|
2013
|
+
const exitDisposable = ptyProcess.onExit(
|
|
2014
|
+
({ exitCode, signal }) => {
|
|
2015
|
+
exited = true;
|
|
2016
|
+
abortSignal.removeEventListener("abort", abortHandler);
|
|
2017
|
+
const finalize = /* @__PURE__ */ __name(async () => {
|
|
2018
|
+
const finalBuffer = Buffer.concat(outputChunks);
|
|
2019
|
+
let fullOutput = "";
|
|
2020
|
+
try {
|
|
2021
|
+
try {
|
|
2022
|
+
render(true);
|
|
2023
|
+
} catch (e) {
|
|
2024
|
+
debugLogger2.warn(
|
|
2025
|
+
`Final PTY render threw during cleanup: ${e instanceof Error ? e.message : String(e)}`
|
|
2026
|
+
);
|
|
2027
|
+
}
|
|
2028
|
+
try {
|
|
2029
|
+
if (isStreamingRawContent) {
|
|
2030
|
+
const finalEncoding = getCachedEncodingForBuffer(finalBuffer);
|
|
2031
|
+
const decodedOutput = new TextDecoder(finalEncoding).decode(
|
|
2032
|
+
finalBuffer
|
|
2033
|
+
);
|
|
2034
|
+
fullOutput = await replayTerminalOutput(
|
|
2035
|
+
decodedOutput,
|
|
2036
|
+
cols,
|
|
2037
|
+
rows,
|
|
2038
|
+
Terminal
|
|
2039
|
+
);
|
|
2040
|
+
} else {
|
|
2041
|
+
fullOutput = serializeTerminalToText(headlessTerminal);
|
|
2042
|
+
}
|
|
2043
|
+
} catch {
|
|
2044
|
+
try {
|
|
2045
|
+
fullOutput = decodeBufferedOutput(finalBuffer);
|
|
2046
|
+
} catch {
|
|
2047
|
+
}
|
|
2048
|
+
}
|
|
2049
|
+
fullOutput = appendOutputCaptureLimitNotice(
|
|
2050
|
+
fullOutput,
|
|
2051
|
+
outputCaptureLimitExceeded,
|
|
2052
|
+
totalBytesReceived,
|
|
2053
|
+
maxBufferedOutputBytes
|
|
2054
|
+
);
|
|
2055
|
+
resolve({
|
|
2056
|
+
rawOutput: finalBuffer,
|
|
2057
|
+
output: fullOutput,
|
|
2058
|
+
exitCode,
|
|
2059
|
+
signal: signal === 0 ? null : signal ?? null,
|
|
2060
|
+
error,
|
|
2061
|
+
aborted: abortSignal.aborted,
|
|
2062
|
+
pid: ptyProcess.pid,
|
|
2063
|
+
executionMethod: ptyInfo?.name ?? "node-pty"
|
|
2064
|
+
});
|
|
2065
|
+
} finally {
|
|
2066
|
+
disposeForegroundPtyResources();
|
|
2067
|
+
}
|
|
2068
|
+
}, "finalize");
|
|
2069
|
+
const flushChain = /* @__PURE__ */ __name(() => processingChain.then(() => {
|
|
2070
|
+
}), "flushChain");
|
|
2071
|
+
const deadline = new Promise(
|
|
2072
|
+
(res) => setTimeout(res, SIGKILL_TIMEOUT_MS)
|
|
2073
|
+
);
|
|
2074
|
+
const drain = /* @__PURE__ */ __name(() => new Promise((res) => setImmediate(res)).then(flushChain), "drain");
|
|
2075
|
+
void Promise.race([
|
|
2076
|
+
flushChain().then(drain).then(drain),
|
|
2077
|
+
deadline
|
|
2078
|
+
]).then(() => {
|
|
2079
|
+
void finalize();
|
|
2080
|
+
});
|
|
2081
|
+
}
|
|
2082
|
+
);
|
|
2083
|
+
const performBackgroundPromote = /* @__PURE__ */ __name(async () => {
|
|
2084
|
+
if (!ptyProcess.pid || exited) return;
|
|
2085
|
+
if (!_ShellExecutionService.isPtyActive(ptyProcess.pid)) {
|
|
2086
|
+
debugLogger2.debug(
|
|
2087
|
+
`Background-promote requested for PTY pid ${ptyProcess.pid} but the process is no longer alive (process.kill(pid, 0) failed); falling through to normal exit-handled resolution.`
|
|
2088
|
+
);
|
|
2089
|
+
return;
|
|
2090
|
+
}
|
|
2091
|
+
exited = true;
|
|
2092
|
+
listenersDetached = true;
|
|
2093
|
+
abortSignal.removeEventListener("abort", abortHandler);
|
|
2094
|
+
try {
|
|
2095
|
+
dataDisposable.dispose();
|
|
2096
|
+
} catch (e) {
|
|
2097
|
+
debugLogger2.warn(
|
|
2098
|
+
`dataDisposable.dispose() threw during background-promote: ${e instanceof Error ? e.message : String(e)}`
|
|
2099
|
+
);
|
|
2100
|
+
}
|
|
2101
|
+
try {
|
|
2102
|
+
exitDisposable.dispose();
|
|
2103
|
+
} catch (e) {
|
|
2104
|
+
debugLogger2.warn(
|
|
2105
|
+
`exitDisposable.dispose() threw during background-promote: ${e instanceof Error ? e.message : String(e)}`
|
|
2106
|
+
);
|
|
2107
|
+
}
|
|
2108
|
+
try {
|
|
2109
|
+
ptyProcess.removeListener("error", ptyErrorHandler);
|
|
2110
|
+
} catch (e) {
|
|
2111
|
+
debugLogger2.warn(
|
|
2112
|
+
`ptyProcess.removeListener('error') threw during background-promote: ${e instanceof Error ? e.message : String(e)}`
|
|
2113
|
+
);
|
|
2114
|
+
}
|
|
2115
|
+
if (renderTimeout) {
|
|
2116
|
+
clearTimeout(renderTimeout);
|
|
2117
|
+
renderTimeout = null;
|
|
2118
|
+
}
|
|
2119
|
+
this.activePtys.delete(ptyProcess.pid);
|
|
2120
|
+
let postPromoteSettleFired = false;
|
|
2121
|
+
let postPromoteDataDisposable = null;
|
|
2122
|
+
let postPromoteExitDisposable = null;
|
|
2123
|
+
let postPromoteErrorListener = null;
|
|
2124
|
+
const disposePostPromoteListeners = /* @__PURE__ */ __name(() => {
|
|
2125
|
+
if (postPromoteDataDisposable) {
|
|
2126
|
+
try {
|
|
2127
|
+
postPromoteDataDisposable.dispose();
|
|
2128
|
+
} catch (e) {
|
|
2129
|
+
debugLogger2.warn(
|
|
2130
|
+
`disposing post-promote data listener threw: ${e instanceof Error ? e.message : String(e)}`
|
|
2131
|
+
);
|
|
2132
|
+
}
|
|
2133
|
+
postPromoteDataDisposable = null;
|
|
2134
|
+
}
|
|
2135
|
+
if (postPromoteExitDisposable) {
|
|
2136
|
+
try {
|
|
2137
|
+
postPromoteExitDisposable.dispose();
|
|
2138
|
+
} catch (e) {
|
|
2139
|
+
debugLogger2.warn(
|
|
2140
|
+
`disposing post-promote exit listener threw: ${e instanceof Error ? e.message : String(e)}`
|
|
2141
|
+
);
|
|
2142
|
+
}
|
|
2143
|
+
postPromoteExitDisposable = null;
|
|
2144
|
+
}
|
|
2145
|
+
if (postPromoteErrorListener) {
|
|
2146
|
+
try {
|
|
2147
|
+
ptyProcess.removeListener("error", postPromoteErrorListener);
|
|
2148
|
+
} catch (e) {
|
|
2149
|
+
debugLogger2.warn(
|
|
2150
|
+
`removing post-promote error listener threw: ${e instanceof Error ? e.message : String(e)}`
|
|
2151
|
+
);
|
|
2152
|
+
}
|
|
2153
|
+
postPromoteErrorListener = null;
|
|
2154
|
+
}
|
|
2155
|
+
}, "disposePostPromoteListeners");
|
|
2156
|
+
const firePostSettle = /* @__PURE__ */ __name((info) => {
|
|
2157
|
+
if (postPromoteSettleFired) return;
|
|
2158
|
+
postPromoteSettleFired = true;
|
|
2159
|
+
disposePostPromoteListeners();
|
|
2160
|
+
if (os2.platform() === "win32" && _ShellExecutionService.isPtyActive(ptyProcess.pid)) {
|
|
2161
|
+
windowsKillPid(ptyProcess.pid, false);
|
|
2162
|
+
}
|
|
2163
|
+
releaseConPtyHost(ptyProcess);
|
|
2164
|
+
if (!postPromote?.onSettle) return;
|
|
2165
|
+
try {
|
|
2166
|
+
postPromote.onSettle(info);
|
|
2167
|
+
} catch (cbErr) {
|
|
2168
|
+
debugLogger2.warn(
|
|
2169
|
+
`postPromote.onSettle threw: ${cbErr instanceof Error ? cbErr.message : String(cbErr)}`
|
|
2170
|
+
);
|
|
2171
|
+
}
|
|
2172
|
+
}, "firePostSettle");
|
|
2173
|
+
if (postPromote?.onData) {
|
|
2174
|
+
const onPostData = postPromote.onData;
|
|
2175
|
+
try {
|
|
2176
|
+
postPromoteDataDisposable = ptyProcess.onData((data) => {
|
|
2177
|
+
try {
|
|
2178
|
+
onPostData({ type: "data", chunk: data });
|
|
2179
|
+
} catch (cbErr) {
|
|
2180
|
+
debugLogger2.warn(
|
|
2181
|
+
`postPromote.onData threw: ${cbErr instanceof Error ? cbErr.message : String(cbErr)}`
|
|
2182
|
+
);
|
|
2183
|
+
}
|
|
2184
|
+
});
|
|
2185
|
+
} catch (e) {
|
|
2186
|
+
debugLogger2.warn(
|
|
2187
|
+
`re-attaching post-promote data listener threw: ${e instanceof Error ? e.message : String(e)}`
|
|
2188
|
+
);
|
|
2189
|
+
}
|
|
2190
|
+
}
|
|
2191
|
+
try {
|
|
2192
|
+
postPromoteExitDisposable = ptyProcess.onExit(
|
|
2193
|
+
({ exitCode, signal }) => {
|
|
2194
|
+
firePostSettle({
|
|
2195
|
+
exitCode,
|
|
2196
|
+
signal: signal === 0 ? null : signal ?? null,
|
|
2197
|
+
endTime: Date.now()
|
|
2198
|
+
});
|
|
2199
|
+
}
|
|
2200
|
+
);
|
|
2201
|
+
} catch (e) {
|
|
2202
|
+
debugLogger2.warn(
|
|
2203
|
+
`re-attaching post-promote exit listener threw: ${e instanceof Error ? e.message : String(e)}`
|
|
2204
|
+
);
|
|
2205
|
+
}
|
|
2206
|
+
try {
|
|
2207
|
+
postPromoteErrorListener = /* @__PURE__ */ __name((err) => {
|
|
2208
|
+
if (isExpectedPtyReadExitError(err)) {
|
|
2209
|
+
return;
|
|
2210
|
+
}
|
|
2211
|
+
firePostSettle({
|
|
2212
|
+
error: err,
|
|
2213
|
+
exitCode: null,
|
|
2214
|
+
signal: null,
|
|
2215
|
+
endTime: Date.now()
|
|
2216
|
+
});
|
|
2217
|
+
}, "postPromoteErrorListener");
|
|
2218
|
+
ptyProcess.on("error", postPromoteErrorListener);
|
|
2219
|
+
} catch (e) {
|
|
2220
|
+
debugLogger2.warn(
|
|
2221
|
+
`re-attaching post-promote error listener threw: ${e instanceof Error ? e.message : String(e)}`
|
|
2222
|
+
);
|
|
2223
|
+
}
|
|
2224
|
+
const TIMEOUT_SENTINEL = Symbol("drain-timeout");
|
|
2225
|
+
const drain = /* @__PURE__ */ __name(() => new Promise((res) => setImmediate(res)).then(
|
|
2226
|
+
() => processingChain
|
|
2227
|
+
), "drain");
|
|
2228
|
+
const winner = await Promise.race([
|
|
2229
|
+
processingChain.then(drain).then(drain).catch(() => void 0),
|
|
2230
|
+
new Promise(
|
|
2231
|
+
(res) => setTimeout(() => res(TIMEOUT_SENTINEL), PROMOTE_DRAIN_TIMEOUT_MS)
|
|
2232
|
+
)
|
|
2233
|
+
]);
|
|
2234
|
+
if (winner === TIMEOUT_SENTINEL) {
|
|
2235
|
+
debugLogger2.warn(
|
|
2236
|
+
`Background-promote drain hit the ${PROMOTE_DRAIN_TIMEOUT_MS}ms timeout before processingChain settled. The output snapshot may be missing the very last batch of bytes the PTY emitted before promote (rawOutput in the result still has the bounded captured buffer the caller can re-render).`
|
|
2237
|
+
);
|
|
2238
|
+
}
|
|
2239
|
+
const finalBuffer = Buffer.concat(outputChunks);
|
|
2240
|
+
let snapshot = "";
|
|
2241
|
+
try {
|
|
2242
|
+
if (isStreamingRawContent) {
|
|
2243
|
+
const finalEncoding = getCachedEncodingForBuffer(finalBuffer);
|
|
2244
|
+
const decodedOutput = new TextDecoder(finalEncoding).decode(
|
|
2245
|
+
finalBuffer
|
|
2246
|
+
);
|
|
2247
|
+
snapshot = await replayTerminalOutput(
|
|
2248
|
+
decodedOutput,
|
|
2249
|
+
cols,
|
|
2250
|
+
rows,
|
|
2251
|
+
Terminal
|
|
2252
|
+
);
|
|
2253
|
+
} else {
|
|
2254
|
+
snapshot = serializeTerminalToText(headlessTerminal) ?? "";
|
|
2255
|
+
}
|
|
2256
|
+
} catch (serErr) {
|
|
2257
|
+
debugLogger2.warn(
|
|
2258
|
+
`Background-promote snapshot replay failed: ${serErr instanceof Error ? serErr.message : String(serErr)}. Falling back to bounded raw buffer decode; if that also fails, output stays empty.`
|
|
2259
|
+
);
|
|
2260
|
+
try {
|
|
2261
|
+
snapshot = decodeBufferedOutput(finalBuffer);
|
|
2262
|
+
} catch {
|
|
2263
|
+
}
|
|
2264
|
+
}
|
|
2265
|
+
snapshot = appendOutputCaptureLimitNotice(
|
|
2266
|
+
snapshot,
|
|
2267
|
+
outputCaptureLimitExceeded,
|
|
2268
|
+
totalBytesReceived,
|
|
2269
|
+
maxBufferedOutputBytes
|
|
2270
|
+
);
|
|
2271
|
+
try {
|
|
2272
|
+
resolve({
|
|
2273
|
+
rawOutput: finalBuffer,
|
|
2274
|
+
output: snapshot,
|
|
2275
|
+
exitCode: null,
|
|
2276
|
+
signal: null,
|
|
2277
|
+
error,
|
|
2278
|
+
// See childProcessFallback for the full rationale — promoted
|
|
2279
|
+
// results are NOT user-cancellations, so callers' `if
|
|
2280
|
+
// (result.aborted)` branches must NOT trigger.
|
|
2281
|
+
aborted: false,
|
|
2282
|
+
promoted: true,
|
|
2283
|
+
pid: ptyProcess.pid,
|
|
2284
|
+
executionMethod: ptyInfo?.name ?? "node-pty"
|
|
2285
|
+
});
|
|
2286
|
+
} finally {
|
|
2287
|
+
try {
|
|
2288
|
+
queryResponseDisposable?.dispose();
|
|
2289
|
+
} catch (e) {
|
|
2290
|
+
debugLogger2.warn(
|
|
2291
|
+
`queryResponseDisposable.dispose() threw during background-promote cleanup: ${e instanceof Error ? e.message : String(e)}`
|
|
2292
|
+
);
|
|
2293
|
+
}
|
|
2294
|
+
try {
|
|
2295
|
+
headlessTerminal.dispose();
|
|
2296
|
+
} catch (e) {
|
|
2297
|
+
debugLogger2.warn(
|
|
2298
|
+
`headlessTerminal.dispose() threw during background-promote cleanup: ${e instanceof Error ? e.message : String(e)}`
|
|
2299
|
+
);
|
|
2300
|
+
}
|
|
2301
|
+
}
|
|
2302
|
+
}, "performBackgroundPromote");
|
|
2303
|
+
const performCancelKill = /* @__PURE__ */ __name(async () => {
|
|
2304
|
+
if (!ptyProcess.pid || exited) return;
|
|
2305
|
+
cancelKillDispatched = true;
|
|
2306
|
+
if (os2.platform() === "win32") {
|
|
2307
|
+
try {
|
|
2308
|
+
const r = spawnSync(
|
|
2309
|
+
WINDOWS_TASKKILL,
|
|
2310
|
+
["/f", "/t", "/pid", ptyProcess.pid.toString()],
|
|
2311
|
+
WINDOWS_TASKKILL_OPTIONS
|
|
2312
|
+
);
|
|
2313
|
+
if (r.error || typeof r.status === "number" && r.status !== 0) {
|
|
2314
|
+
debugLogger2.warn(
|
|
2315
|
+
`performCancelKill: taskkill failed for pid ${ptyProcess.pid}: ${r.error?.message ?? `exit ${r.status}`}`
|
|
2316
|
+
);
|
|
2317
|
+
}
|
|
2318
|
+
} catch (e) {
|
|
2319
|
+
debugLogger2.warn(
|
|
2320
|
+
`performCancelKill: taskkill spawn threw for pid ${ptyProcess.pid}: ${e instanceof Error ? e.message : String(e)}`
|
|
2321
|
+
);
|
|
2322
|
+
}
|
|
2323
|
+
try {
|
|
2324
|
+
ptyProcess.kill();
|
|
2325
|
+
if (ptyProcess._isReady !== false) {
|
|
2326
|
+
noteConPtyHostReleased(ptyProcess);
|
|
2327
|
+
}
|
|
2328
|
+
} catch {
|
|
2329
|
+
}
|
|
2330
|
+
} else {
|
|
2331
|
+
try {
|
|
2332
|
+
process.kill(-ptyProcess.pid, "SIGTERM");
|
|
2333
|
+
await new Promise((res) => setTimeout(res, SIGKILL_TIMEOUT_MS));
|
|
2334
|
+
if (!exited) {
|
|
2335
|
+
process.kill(-ptyProcess.pid, "SIGKILL");
|
|
2336
|
+
}
|
|
2337
|
+
} catch (_e) {
|
|
2338
|
+
if (!exited) {
|
|
2339
|
+
ptyProcess.kill();
|
|
2340
|
+
}
|
|
2341
|
+
}
|
|
2342
|
+
}
|
|
2343
|
+
}, "performCancelKill");
|
|
2344
|
+
const abortHandler = /* @__PURE__ */ __name(async () => {
|
|
2345
|
+
const kind = getShellAbortReasonKind(abortSignal.reason);
|
|
2346
|
+
switch (kind) {
|
|
2347
|
+
case "background":
|
|
2348
|
+
await performBackgroundPromote();
|
|
2349
|
+
return;
|
|
2350
|
+
case "cancel":
|
|
2351
|
+
await performCancelKill();
|
|
2352
|
+
return;
|
|
2353
|
+
default: {
|
|
2354
|
+
const _exhaustive = kind;
|
|
2355
|
+
await performCancelKill();
|
|
2356
|
+
return _exhaustive;
|
|
2357
|
+
}
|
|
2358
|
+
}
|
|
2359
|
+
}, "abortHandler");
|
|
2360
|
+
abortSignal.addEventListener("abort", abortHandler, { once: true });
|
|
2361
|
+
});
|
|
2362
|
+
return {
|
|
2363
|
+
pid: ptyProcess.pid,
|
|
2364
|
+
result: result.catch((error) => {
|
|
2365
|
+
try {
|
|
2366
|
+
if (os2.platform() === "win32") ptyProcess.kill();
|
|
2367
|
+
else process.kill(-ptyProcess.pid, "SIGKILL");
|
|
2368
|
+
} catch {
|
|
2369
|
+
}
|
|
2370
|
+
this.activePtys.get(ptyProcess.pid)?.headlessTerminal.dispose();
|
|
2371
|
+
this.activePtys.delete(ptyProcess.pid);
|
|
2372
|
+
throw error;
|
|
2373
|
+
})
|
|
2374
|
+
};
|
|
2375
|
+
} catch (e) {
|
|
2376
|
+
const error = e;
|
|
2377
|
+
if (!ptySpawned && useBundledConpty) {
|
|
2378
|
+
debugLogger2.warn(
|
|
2379
|
+
`Windows PTY spawn failed, falling back to child_process: ${error instanceof Error ? error.message : String(e)}`
|
|
2380
|
+
);
|
|
2381
|
+
throw e;
|
|
2382
|
+
}
|
|
2383
|
+
if (!ptySpawned && error.message.includes("posix_spawnp failed")) {
|
|
2384
|
+
onOutputEvent({
|
|
2385
|
+
type: "data",
|
|
2386
|
+
chunk: "[WARNING] PTY execution failed, falling back to child_process. This may be due to sandbox restrictions.\n"
|
|
2387
|
+
});
|
|
2388
|
+
throw e;
|
|
2389
|
+
} else {
|
|
2390
|
+
return {
|
|
2391
|
+
pid: void 0,
|
|
2392
|
+
result: Promise.resolve({
|
|
2393
|
+
error,
|
|
2394
|
+
rawOutput: Buffer.from(""),
|
|
2395
|
+
output: "",
|
|
2396
|
+
exitCode: 1,
|
|
2397
|
+
signal: null,
|
|
2398
|
+
aborted: false,
|
|
2399
|
+
pid: void 0,
|
|
2400
|
+
executionMethod: "none"
|
|
2401
|
+
})
|
|
2402
|
+
};
|
|
2403
|
+
}
|
|
2404
|
+
}
|
|
2405
|
+
}
|
|
2406
|
+
/**
|
|
2407
|
+
* Writes a string to the pseudo-terminal (PTY) of a running process.
|
|
2408
|
+
*
|
|
2409
|
+
* @param pid The process ID of the target PTY.
|
|
2410
|
+
* @param input The string to write to the terminal.
|
|
2411
|
+
*/
|
|
2412
|
+
static writeToPty(pid, input) {
|
|
2413
|
+
if (!this.isPtyActive(pid)) {
|
|
2414
|
+
return;
|
|
2415
|
+
}
|
|
2416
|
+
const activePty = this.activePtys.get(pid);
|
|
2417
|
+
if (activePty) {
|
|
2418
|
+
activePty.ptyProcess.write(input);
|
|
2419
|
+
}
|
|
2420
|
+
}
|
|
2421
|
+
static isPtyActive(pid) {
|
|
2422
|
+
try {
|
|
2423
|
+
return process.kill(pid, 0);
|
|
2424
|
+
} catch (_) {
|
|
2425
|
+
return false;
|
|
2426
|
+
}
|
|
2427
|
+
}
|
|
2428
|
+
/**
|
|
2429
|
+
* Resizes the pseudo-terminal (PTY) of a running process.
|
|
2430
|
+
*
|
|
2431
|
+
* @param pid The process ID of the target PTY.
|
|
2432
|
+
* @param cols The new number of columns.
|
|
2433
|
+
* @param rows The new number of rows.
|
|
2434
|
+
*/
|
|
2435
|
+
static resizePty(pid, cols, rows) {
|
|
2436
|
+
if (!this.isPtyActive(pid)) {
|
|
2437
|
+
return;
|
|
2438
|
+
}
|
|
2439
|
+
const activePty = this.activePtys.get(pid);
|
|
2440
|
+
if (activePty) {
|
|
2441
|
+
try {
|
|
2442
|
+
activePty.ptyProcess.resize(cols, rows);
|
|
2443
|
+
activePty.headlessTerminal.resize(cols, rows);
|
|
2444
|
+
} catch (e) {
|
|
2445
|
+
if (isExpectedPtyExitRaceError(e)) {
|
|
2446
|
+
} else {
|
|
2447
|
+
throw e;
|
|
2448
|
+
}
|
|
2449
|
+
}
|
|
2450
|
+
}
|
|
2451
|
+
}
|
|
2452
|
+
/**
|
|
2453
|
+
* Scrolls the pseudo-terminal (PTY) of a running process.
|
|
2454
|
+
*
|
|
2455
|
+
* @param pid The process ID of the target PTY.
|
|
2456
|
+
* @param lines The number of lines to scroll.
|
|
2457
|
+
*/
|
|
2458
|
+
static scrollPty(pid, lines) {
|
|
2459
|
+
if (!this.isPtyActive(pid)) {
|
|
2460
|
+
return;
|
|
2461
|
+
}
|
|
2462
|
+
const activePty = this.activePtys.get(pid);
|
|
2463
|
+
if (activePty) {
|
|
2464
|
+
try {
|
|
2465
|
+
activePty.headlessTerminal.scrollLines(lines);
|
|
2466
|
+
if (activePty.headlessTerminal.buffer.active.viewportY < 0) {
|
|
2467
|
+
activePty.headlessTerminal.scrollToTop();
|
|
2468
|
+
}
|
|
2469
|
+
} catch (e) {
|
|
2470
|
+
if (isExpectedPtyExitRaceError(e)) {
|
|
2471
|
+
} else {
|
|
2472
|
+
throw e;
|
|
2473
|
+
}
|
|
2474
|
+
}
|
|
2475
|
+
}
|
|
2476
|
+
}
|
|
2477
|
+
};
|
|
2478
|
+
|
|
2479
|
+
// packages/core/src/sandbox/bwrap-status.ts
|
|
2480
|
+
init_esbuild_shims();
|
|
2481
|
+
var MAX_STATUS_BYTES = 16 * 1024;
|
|
2482
|
+
function sandboxStatusError(status) {
|
|
2483
|
+
if (status.state === "unconfirmed") {
|
|
2484
|
+
if (status.payloadExitObserved === false) {
|
|
2485
|
+
return new Error(
|
|
2486
|
+
"Sandbox payload did not run: setup failed before execution (bubblewrap or the payload binary may be missing)."
|
|
2487
|
+
);
|
|
2488
|
+
}
|
|
2489
|
+
return new Error(
|
|
2490
|
+
"Sandbox execution status could not be confirmed. The command may have run; do not automatically retry it."
|
|
2491
|
+
);
|
|
2492
|
+
}
|
|
2493
|
+
if (status.state === "interrupted") {
|
|
2494
|
+
return new Error("Sandbox execution was interrupted.");
|
|
2495
|
+
}
|
|
2496
|
+
return void 0;
|
|
2497
|
+
}
|
|
2498
|
+
__name(sandboxStatusError, "sandboxStatusError");
|
|
2499
|
+
|
|
2500
|
+
// packages/core/src/sandbox/bwrap-execution.ts
|
|
2501
|
+
var debugLogger3 = createDebugLogger("BWRAP_EXECUTION");
|
|
2502
|
+
function sandboxAsset(name) {
|
|
2503
|
+
const sibling = path2.join(
|
|
2504
|
+
path2.dirname(fileURLToPath(import.meta.url)),
|
|
2505
|
+
`${name}.js`
|
|
2506
|
+
);
|
|
2507
|
+
const bundled = path2.join(
|
|
2508
|
+
resolveBundleDir(import.meta.url),
|
|
2509
|
+
name === "bwrap-relay" ? "sandboxBwrapRelay.js" : "sandboxFileWorker.js"
|
|
2510
|
+
);
|
|
2511
|
+
const asset = existsSync(sibling) ? sibling : bundled;
|
|
2512
|
+
if (!existsSync(asset))
|
|
2513
|
+
throw new Error(
|
|
2514
|
+
"Sandbox assets are missing. Run the build and bundle first."
|
|
2515
|
+
);
|
|
2516
|
+
return realpathSync(asset);
|
|
2517
|
+
}
|
|
2518
|
+
__name(sandboxAsset, "sandboxAsset");
|
|
2519
|
+
var overlaps = /* @__PURE__ */ __name((a, b) => isSubpath(a, b) || isSubpath(b, a), "overlaps");
|
|
2520
|
+
var directory = /* @__PURE__ */ __name((value) => {
|
|
2521
|
+
if (!path2.isAbsolute(value))
|
|
2522
|
+
throw new Error("Sandbox paths must be absolute.");
|
|
2523
|
+
const resolved = realpathSync(value);
|
|
2524
|
+
if (!statSync2(resolved).isDirectory())
|
|
2525
|
+
throw new Error("Expected sandbox directory.");
|
|
2526
|
+
return resolved;
|
|
2527
|
+
}, "directory");
|
|
2528
|
+
async function executeBwrap(policy, payload, onOutput, signal, usePty = false, config = {}, options = {}) {
|
|
2529
|
+
if (process.platform !== "linux")
|
|
2530
|
+
throw new Error("bwrap execution requires Linux.");
|
|
2531
|
+
if (!["read-only", "workspace-write"].includes(policy.filesystem) || !["open", "closed"].includes(policy.network)) {
|
|
2532
|
+
throw new Error("Unsupported sandbox policy.");
|
|
2533
|
+
}
|
|
2534
|
+
if (!path2.isAbsolute(payload.executable) || !path2.isAbsolute(payload.cwd))
|
|
2535
|
+
throw new Error("Payload paths must be absolute.");
|
|
2536
|
+
if (usePty && payload.stdin !== void 0)
|
|
2537
|
+
throw new Error("Process stdin requires pipe execution.");
|
|
2538
|
+
const workspace = directory(policy.workspace);
|
|
2539
|
+
const state = directory(policy.state);
|
|
2540
|
+
const relay = sandboxAsset("bwrap-relay");
|
|
2541
|
+
const node = realpathSync(process.execPath);
|
|
2542
|
+
const requestedBwrap = policy.bwrapPath ?? "/usr/bin/bwrap";
|
|
2543
|
+
if (!path2.isAbsolute(requestedBwrap))
|
|
2544
|
+
throw new Error("bwrap path must be absolute.");
|
|
2545
|
+
const bwrap = existsSync(requestedBwrap) ? realpathSync(requestedBwrap) : requestedBwrap;
|
|
2546
|
+
const protectedRoots = [
|
|
2547
|
+
directory(policy.installation),
|
|
2548
|
+
state,
|
|
2549
|
+
path2.dirname(relay),
|
|
2550
|
+
path2.dirname(node),
|
|
2551
|
+
path2.dirname(bwrap),
|
|
2552
|
+
...[
|
|
2553
|
+
"/proc",
|
|
2554
|
+
"/dev",
|
|
2555
|
+
"/sys",
|
|
2556
|
+
"/etc",
|
|
2557
|
+
"/usr",
|
|
2558
|
+
"/bin",
|
|
2559
|
+
"/sbin",
|
|
2560
|
+
"/lib",
|
|
2561
|
+
"/lib64"
|
|
2562
|
+
].filter(existsSync).map((value) => realpathSync(value))
|
|
2563
|
+
];
|
|
2564
|
+
const checkWritable = /* @__PURE__ */ __name((root) => {
|
|
2565
|
+
if (isSubpath(root, realpathSync(os3.homedir())) || protectedRoots.some((protectedRoot) => overlaps(root, protectedRoot))) {
|
|
2566
|
+
throw new Error("Writable directory overlaps a protected root.");
|
|
2567
|
+
}
|
|
2568
|
+
}, "checkWritable");
|
|
2569
|
+
checkWritable(workspace);
|
|
2570
|
+
const maskedPaths = (policy.maskedPaths ?? []).map((value) => {
|
|
2571
|
+
if (!path2.isAbsolute(value))
|
|
2572
|
+
throw new Error("Sandbox mask paths must be absolute.");
|
|
2573
|
+
const resolved = realpathNearestExisting(value);
|
|
2574
|
+
if (resolved === workspace || !isSubpath(workspace, resolved))
|
|
2575
|
+
throw new Error("Sandbox mask paths must remain inside the workspace.");
|
|
2576
|
+
return resolved;
|
|
2577
|
+
});
|
|
2578
|
+
const cwd = directory(payload.cwd);
|
|
2579
|
+
if (!isSubpath(workspace, cwd))
|
|
2580
|
+
throw new Error("Payload cwd must be inside the workspace.");
|
|
2581
|
+
const executable = payload.executable;
|
|
2582
|
+
const args = [...payload.args];
|
|
2583
|
+
const env = Object.fromEntries(
|
|
2584
|
+
Object.entries(payload.env).filter(([key]) => !isInternalSecretEnvVar(key))
|
|
2585
|
+
);
|
|
2586
|
+
const stdin = Buffer.isBuffer(payload.stdin) ? Buffer.from(payload.stdin) : payload.stdin;
|
|
2587
|
+
const filesystem = policy.filesystem;
|
|
2588
|
+
const network = policy.network;
|
|
2589
|
+
const control = await mkdtemp(path2.join(state, "sandbox-control-"));
|
|
2590
|
+
let scratch;
|
|
2591
|
+
const cleanup = /* @__PURE__ */ __name(async () => {
|
|
2592
|
+
const results = await Promise.allSettled([
|
|
2593
|
+
rm(control, { recursive: true, force: true }),
|
|
2594
|
+
...scratch ? [rm(scratch, { recursive: true, force: true })] : []
|
|
2595
|
+
]);
|
|
2596
|
+
for (const result of results) {
|
|
2597
|
+
if (result.status === "rejected")
|
|
2598
|
+
debugLogger3.warn(
|
|
2599
|
+
"Sandbox temporary directory cleanup failed",
|
|
2600
|
+
result.reason
|
|
2601
|
+
);
|
|
2602
|
+
}
|
|
2603
|
+
}, "cleanup");
|
|
2604
|
+
try {
|
|
2605
|
+
const requestedScratchRoot = os3.tmpdir();
|
|
2606
|
+
const scratchRoot = path2.isAbsolute(requestedScratchRoot) && existsSync(requestedScratchRoot) ? realpathSync(requestedScratchRoot) : realpathSync("/tmp");
|
|
2607
|
+
if (isSubpath(workspace, scratchRoot) || protectedRoots.some(
|
|
2608
|
+
(protectedRoot) => isSubpath(protectedRoot, scratchRoot)
|
|
2609
|
+
))
|
|
2610
|
+
throw new Error(
|
|
2611
|
+
`Temporary root ${scratchRoot} overlaps the workspace or a protected root.`
|
|
2612
|
+
);
|
|
2613
|
+
scratch = await mkdtemp(path2.join(scratchRoot, "qwen-sandbox-"));
|
|
2614
|
+
scratch = directory(scratch);
|
|
2615
|
+
checkWritable(scratch);
|
|
2616
|
+
if (overlaps(workspace, scratch))
|
|
2617
|
+
throw new Error("Workspace and scratch must be disjoint.");
|
|
2618
|
+
const payloadEnv = {
|
|
2619
|
+
...env,
|
|
2620
|
+
PWD: cwd,
|
|
2621
|
+
TMPDIR: scratch,
|
|
2622
|
+
TMP: scratch,
|
|
2623
|
+
TEMP: scratch,
|
|
2624
|
+
TERM: env["TERM"] || "xterm-256color"
|
|
2625
|
+
};
|
|
2626
|
+
for (const [key, value] of Object.entries(payloadEnv)) {
|
|
2627
|
+
if (!key || key.includes("=") || key.includes("\0") || value.includes("\0"))
|
|
2628
|
+
throw new Error("Invalid payload environment.");
|
|
2629
|
+
}
|
|
2630
|
+
const payloadEnvPath = path2.join(control, "payload-env.json");
|
|
2631
|
+
await writeFile(payloadEnvPath, JSON.stringify(payloadEnv), {
|
|
2632
|
+
encoding: "utf8",
|
|
2633
|
+
flag: "wx",
|
|
2634
|
+
mode: 384
|
|
2635
|
+
});
|
|
2636
|
+
const bwrapArgs = [
|
|
2637
|
+
"--ro-bind",
|
|
2638
|
+
"/",
|
|
2639
|
+
"/",
|
|
2640
|
+
"--unshare-pid",
|
|
2641
|
+
"--proc",
|
|
2642
|
+
"/proc",
|
|
2643
|
+
"--dev",
|
|
2644
|
+
"/dev",
|
|
2645
|
+
"--die-with-parent"
|
|
2646
|
+
];
|
|
2647
|
+
bwrapArgs.push("--bind", scratch, scratch);
|
|
2648
|
+
if (filesystem === "workspace-write")
|
|
2649
|
+
bwrapArgs.push("--bind", workspace, workspace);
|
|
2650
|
+
for (const maskedPath of maskedPaths) {
|
|
2651
|
+
if (!existsSync(maskedPath)) {
|
|
2652
|
+
if (filesystem === "read-only") continue;
|
|
2653
|
+
mkdirSync(maskedPath, { recursive: true });
|
|
2654
|
+
}
|
|
2655
|
+
if (!statSync2(maskedPath).isDirectory())
|
|
2656
|
+
throw new Error("Sandbox mask paths must be directories.");
|
|
2657
|
+
bwrapArgs.push("--tmpfs", maskedPath);
|
|
2658
|
+
}
|
|
2659
|
+
if (network === "closed") bwrapArgs.push("--unshare-net");
|
|
2660
|
+
bwrapArgs.push("--chdir", cwd, "--", executable, ...args);
|
|
2661
|
+
const statusPath = path2.join(control, "status.json");
|
|
2662
|
+
let complete;
|
|
2663
|
+
const settled = new Promise((resolve) => {
|
|
2664
|
+
complete = resolve;
|
|
2665
|
+
});
|
|
2666
|
+
let finalizing;
|
|
2667
|
+
const finalize = /* @__PURE__ */ __name((info) => finalizing ??= (async () => {
|
|
2668
|
+
let status = { state: "unconfirmed" };
|
|
2669
|
+
let receiptExisted = false;
|
|
2670
|
+
let receiptParsed = false;
|
|
2671
|
+
if (info.aborted || isSignalTermination(info.signal))
|
|
2672
|
+
status = { state: "interrupted" };
|
|
2673
|
+
else {
|
|
2674
|
+
try {
|
|
2675
|
+
const text = await readFile(statusPath, "utf8");
|
|
2676
|
+
receiptExisted = true;
|
|
2677
|
+
const record = JSON.parse(text);
|
|
2678
|
+
receiptParsed = true;
|
|
2679
|
+
if (!info.error && record["state"] === "confirmed" && record["exitCode"] === info.exitCode && typeof record["exitCode"] === "number" && Number.isInteger(record["exitCode"]) && record["exitCode"] >= 0 && record["exitCode"] <= 255)
|
|
2680
|
+
status = { state: "confirmed", exitCode: record["exitCode"] };
|
|
2681
|
+
else if (record["state"] === "interrupted")
|
|
2682
|
+
status = { state: "interrupted" };
|
|
2683
|
+
else {
|
|
2684
|
+
const attested = record["payloadExitObserved"];
|
|
2685
|
+
status = {
|
|
2686
|
+
state: "unconfirmed",
|
|
2687
|
+
...typeof attested === "boolean" ? { payloadExitObserved: attested } : {}
|
|
2688
|
+
};
|
|
2689
|
+
}
|
|
2690
|
+
} catch {
|
|
2691
|
+
}
|
|
2692
|
+
}
|
|
2693
|
+
const attestedNoExec = receiptExisted && receiptParsed && status.state === "unconfirmed" && status.payloadExitObserved === false;
|
|
2694
|
+
const relayDiedBeforeSpawn = !receiptExisted;
|
|
2695
|
+
const retain = status.state === "unconfirmed" && !attestedNoExec && !relayDiedBeforeSpawn;
|
|
2696
|
+
if (retain) {
|
|
2697
|
+
debugLogger3.warn(
|
|
2698
|
+
"Sandbox termination is unconfirmed; retaining temporary directories",
|
|
2699
|
+
{ control, scratch }
|
|
2700
|
+
);
|
|
2701
|
+
} else {
|
|
2702
|
+
await cleanup();
|
|
2703
|
+
}
|
|
2704
|
+
complete(status);
|
|
2705
|
+
return status;
|
|
2706
|
+
})(), "finalize");
|
|
2707
|
+
const handle = await ShellExecutionService.executeLaunch(
|
|
2708
|
+
{
|
|
2709
|
+
executable: node,
|
|
2710
|
+
args: [
|
|
2711
|
+
relay,
|
|
2712
|
+
String(process.pid),
|
|
2713
|
+
statusPath,
|
|
2714
|
+
payloadEnvPath,
|
|
2715
|
+
bwrap,
|
|
2716
|
+
...bwrapArgs
|
|
2717
|
+
],
|
|
2718
|
+
cwd,
|
|
2719
|
+
env: {
|
|
2720
|
+
PATH: "/usr/bin:/bin",
|
|
2721
|
+
LANG: "C.UTF-8",
|
|
2722
|
+
TERM: env["TERM"] || "xterm-256color",
|
|
2723
|
+
PWD: cwd
|
|
2724
|
+
},
|
|
2725
|
+
stdin
|
|
2726
|
+
},
|
|
2727
|
+
onOutput,
|
|
2728
|
+
signal,
|
|
2729
|
+
usePty,
|
|
2730
|
+
config,
|
|
2731
|
+
{
|
|
2732
|
+
...options,
|
|
2733
|
+
postPromote: {
|
|
2734
|
+
onData: options.postPromote?.onData,
|
|
2735
|
+
onSettle: /* @__PURE__ */ __name((info) => {
|
|
2736
|
+
void finalize(info).then((status) => {
|
|
2737
|
+
const error = info.error ?? sandboxStatusError(status);
|
|
2738
|
+
options.postPromote?.onSettle?.({ ...info, error });
|
|
2739
|
+
}).catch((settleError) => {
|
|
2740
|
+
debugLogger3.warn(
|
|
2741
|
+
`post-promote settle chain failed: ${settleError instanceof Error ? settleError.message : String(settleError)}`
|
|
2742
|
+
);
|
|
2743
|
+
});
|
|
2744
|
+
}, "onSettle")
|
|
2745
|
+
}
|
|
2746
|
+
}
|
|
2747
|
+
);
|
|
2748
|
+
return {
|
|
2749
|
+
pid: handle.pid,
|
|
2750
|
+
settled,
|
|
2751
|
+
result: handle.result.then(
|
|
2752
|
+
async (result) => {
|
|
2753
|
+
const sandboxStatus = result.promoted ? { state: "running" } : await finalize(result);
|
|
2754
|
+
return {
|
|
2755
|
+
...result,
|
|
2756
|
+
error: result.error ?? sandboxStatusError(sandboxStatus) ?? null,
|
|
2757
|
+
sandboxStatus
|
|
2758
|
+
};
|
|
2759
|
+
},
|
|
2760
|
+
async (error) => {
|
|
2761
|
+
await finalize({ signal: null, exitCode: null, error });
|
|
2762
|
+
throw error;
|
|
2763
|
+
}
|
|
2764
|
+
)
|
|
2765
|
+
};
|
|
2766
|
+
} catch (error) {
|
|
2767
|
+
await cleanup();
|
|
2768
|
+
throw error;
|
|
2769
|
+
}
|
|
2770
|
+
}
|
|
2771
|
+
__name(executeBwrap, "executeBwrap");
|
|
2772
|
+
|
|
2773
|
+
export {
|
|
2774
|
+
loadPty,
|
|
2775
|
+
loadXtermHeadless,
|
|
2776
|
+
normalizePathEnvForWindows,
|
|
2777
|
+
isUnusableScriptEntry,
|
|
2778
|
+
getShellContextEnvVars,
|
|
2779
|
+
noteConPtyHostReleased,
|
|
2780
|
+
disposeConoutWorker,
|
|
2781
|
+
releaseConPtyHost,
|
|
2782
|
+
getShellPagerEnv,
|
|
2783
|
+
getShellAbortReasonKind,
|
|
2784
|
+
isSignalTermination,
|
|
2785
|
+
ShellExecutionService,
|
|
2786
|
+
sandboxAsset,
|
|
2787
|
+
executeBwrap
|
|
2788
|
+
};
|
|
2789
|
+
/**
|
|
2790
|
+
* @license
|
|
2791
|
+
* Copyright 2025 Google LLC
|
|
2792
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
2793
|
+
*/
|
|
2794
|
+
/**
|
|
2795
|
+
* @license
|
|
2796
|
+
* Copyright 2026 Qwen Team
|
|
2797
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
2798
|
+
*/
|
|
2799
|
+
/**
|
|
2800
|
+
* @license
|
|
2801
|
+
* Copyright 2025 Qwen
|
|
2802
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
2803
|
+
*/
|
|
2804
|
+
/**
|
|
2805
|
+
* @license
|
|
2806
|
+
* Copyright 2025 Qwen Team
|
|
2807
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
2808
|
+
*/
|