@qwen-code/qwen-code 0.21.1 → 0.21.2
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/bundled/qc-helper/docs/configuration/settings.md +1 -0
- package/bundled/qc-helper/docs/features/channels/_meta.ts +1 -0
- package/bundled/qc-helper/docs/features/channels/github.md +42 -10
- package/bundled/qc-helper/docs/features/channels/gitlab.md +171 -0
- package/bundled/qc-helper/docs/features/code-review.md +20 -0
- package/bundled/qc-helper/docs/features/hooks.md +20 -0
- package/bundled/qc-helper/docs/features/sub-agents.md +22 -8
- package/bundled/qc-helper/docs/qwen-serve.md +7 -5
- package/bundled/review/SKILL.md +1 -1
- package/chunks/{MaxSizedBox-VI3ROJJA.js → MaxSizedBox-TQBQ247P.js} +42 -38
- package/chunks/{StandaloneSessionPicker-LYXKD2EV.js → StandaloneSessionPicker-2HPTKCLX.js} +58 -54
- package/chunks/{acp-startup-profiler-DFVPFQ6C.js → acp-startup-profiler-2C4A5ZTJ.js} +2 -2
- package/chunks/{acpAgent-WN5SRDQO.js → acpAgent-PS6EDGH3.js} +431 -168
- package/chunks/{agent-K6ECSM64.js → agent-VDOUB35F.js} +38 -34
- package/chunks/{agent-headless-NO4Y2HOE.js → agent-headless-EO53EFS2.js} +38 -34
- package/chunks/{anthropicContentGenerator-V2QOGVYD.js → anthropicContentGenerator-OFHSZJBF.js} +6 -6
- package/chunks/{artifact-tool-6K6U7XYJ.js → artifact-tool-RDN2W7ND.js} +2 -2
- package/chunks/{askUserQuestion-GD2IJJ7I.js → askUserQuestion-OZERWH5R.js} +2 -2
- package/chunks/{bridge-3KJEWDNE.js → bridge-W7AZSRZQ.js} +42 -38
- package/chunks/{build-S6DO7LMM.js → build-GDBLPA24.js} +1 -1
- package/chunks/{channel-management-service-XR7GZSWF.js → channel-management-service-5S7YCWX5.js} +20 -5
- package/chunks/{channel-settings-store-HW4FXXUA.js → channel-settings-store-JFVRSNER.js} +44 -40
- package/chunks/{channel-worker-group-XDPTDWTX.js → channel-worker-group-OVWGYMZS.js} +5 -5
- package/chunks/{channel-worker-manager-YYEHVRRE.js → channel-worker-manager-H55GKOQA.js} +5 -5
- package/chunks/{channel-worker-supervisor-74HTWA2G.js → channel-worker-supervisor-CABBXYHK.js} +3 -3
- package/chunks/{chunk-UWMLWVCA.js → chunk-2IIJTXYF.js} +26 -10
- package/chunks/{chunk-VYOXCEPJ.js → chunk-2KKCCLPT.js} +1 -1
- package/chunks/{chunk-T4TXDL7G.js → chunk-2LEOZTBT.js} +36 -24
- package/chunks/{chunk-XWWKIXVD.js → chunk-3APUUXRF.js} +1 -1
- package/chunks/{chunk-TCIFAA7K.js → chunk-3F2WDAV6.js} +2 -2
- package/chunks/{chunk-SGFT55XI.js → chunk-3I6DUGQD.js} +1 -1
- package/chunks/{chunk-ZURDMIDR.js → chunk-44F4LBWZ.js} +228 -71
- package/chunks/{chunk-GKX7E4CO.js → chunk-45IOTAUS.js} +1 -1
- package/chunks/{chunk-6QIGFD5W.js → chunk-4KP2F2TE.js} +1 -1
- package/chunks/{chunk-X5WNMMIA.js → chunk-54YCNSK5.js} +4241 -1636
- package/chunks/{chunk-P4WOAOJW.js → chunk-56Z7QEAQ.js} +67 -21
- package/chunks/{chunk-UPUG4GXM.js → chunk-5NNHICSA.js} +3 -3
- package/chunks/{chunk-LGAOC3ZS.js → chunk-675H6PLP.js} +1 -1
- package/chunks/{chunk-5KTQXHPY.js → chunk-6CQWRWUC.js} +3 -3
- package/chunks/chunk-6FMJLI5M.js +1591 -0
- package/chunks/{chunk-GZ3RCT54.js → chunk-6MPDY6ZG.js} +1 -1
- package/chunks/{chunk-RCUQIPTN.js → chunk-6PQPKTXP.js} +1 -1
- package/chunks/{chunk-KCO4FLFJ.js → chunk-6TAASXWL.js} +3 -3
- package/chunks/{chunk-JHNRZMHI.js → chunk-77V3VIKL.js} +9 -9
- package/chunks/{chunk-CAPPWD3X.js → chunk-7KAXXBER.js} +3 -3
- package/chunks/{chunk-A4COXFB3.js → chunk-7SJN2IWT.js} +5 -5
- package/chunks/{chunk-Y4IHBGBP.js → chunk-7ULQIS27.js} +1 -1
- package/chunks/{chunk-5MKRTI4T.js → chunk-A7Y5H4TX.js} +4 -4
- package/chunks/{chunk-CVHIL5IG.js → chunk-AOHY3QJ3.js} +13 -6
- package/chunks/chunk-AQ37AY7B.js +93 -0
- package/chunks/{chunk-OCESJA77.js → chunk-AUOULH6Q.js} +45 -45
- package/chunks/{chunk-UBEPNVDI.js → chunk-BBIQAX4V.js} +3 -3
- package/chunks/{chunk-JSD33JG6.js → chunk-CBBP4BMC.js} +23 -9
- package/chunks/{chunk-ZHBO7WVX.js → chunk-CNTR4GR6.js} +1 -1
- package/chunks/{chunk-PB3MBFKG.js → chunk-CO2U743O.js} +4 -4
- package/chunks/{chunk-XZC5VLBZ.js → chunk-CPZAH673.js} +4 -0
- package/chunks/{chunk-T3O2B4XO.js → chunk-CU47KXB5.js} +3 -3
- package/chunks/{chunk-2LKVPASC.js → chunk-D4HTUMGX.js} +3 -3
- package/chunks/{chunk-BNWB5CYE.js → chunk-D6MDRSZ6.js} +7 -7
- package/chunks/{chunk-7BAU433D.js → chunk-DEEABGH2.js} +867 -91
- package/chunks/{chunk-52ZSWYEG.js → chunk-DQ2O5QOJ.js} +1 -1
- package/chunks/{chunk-WBSMNTSV.js → chunk-DSFHVTWD.js} +2 -2
- package/chunks/{chunk-PT722TDT.js → chunk-DUNI4EBW.js} +701 -86
- package/chunks/{chunk-UHUSJ6X7.js → chunk-E2BHWIDT.js} +19 -4
- package/chunks/{chunk-T2QMKU3R.js → chunk-E2FN6SM7.js} +17 -5
- package/chunks/{chunk-W4MIWP6M.js → chunk-E6CJ2SMM.js} +2 -2
- package/chunks/{chunk-5ZF5XXTS.js → chunk-EQNUDTL6.js} +2 -2
- package/chunks/{chunk-2N7CODY5.js → chunk-EU5TBFJI.js} +2 -2
- package/chunks/{chunk-TFRMVU6R.js → chunk-FANRZEAJ.js} +1 -1
- package/chunks/{chunk-WBL3FJEU.js → chunk-FC4KQFCS.js} +1 -1
- package/chunks/{chunk-GNR2RNMP.js → chunk-FCYYAB4S.js} +2 -2
- package/chunks/{chunk-FNMZK765.js → chunk-FJ5WUMUQ.js} +1 -1
- package/chunks/{chunk-J7OACQDE.js → chunk-FNDXMN7I.js} +71 -49
- package/chunks/{chunk-U3E3UQAA.js → chunk-FS674JW4.js} +3 -3
- package/chunks/{chunk-S7W2GKIO.js → chunk-G7XXKQYS.js} +2 -0
- package/chunks/{chunk-VWOOBLTY.js → chunk-GJ2GBPBD.js} +2 -2
- package/chunks/{chunk-TBBV36Y4.js → chunk-GL4JOZXU.js} +4 -4
- package/chunks/{chunk-FTD6DP4T.js → chunk-GURGAJTX.js} +2 -1
- package/chunks/{chunk-65PQENQP.js → chunk-H6I4PGRV.js} +5 -5
- package/chunks/{chunk-7XATOOE7.js → chunk-HC45LTEN.js} +1 -1
- package/chunks/{chunk-VCPIZRYH.js → chunk-HIVKI6O6.js} +7 -7
- package/chunks/{chunk-HMRM2A3U.js → chunk-HX6RLYUO.js} +3 -3
- package/chunks/{chunk-GZXCZHCT.js → chunk-I3G5JWBV.js} +1 -1
- package/chunks/{chunk-2XSLTRFZ.js → chunk-I5BT7ADR.js} +2 -2
- package/chunks/{chunk-GATT5TKW.js → chunk-IGTHU3T4.js} +1 -1
- package/chunks/{chunk-4G2BISNC.js → chunk-IIUGIWWY.js} +1 -1
- package/chunks/{chunk-7I5GTCT4.js → chunk-JCJ7LKNA.js} +5104 -4817
- package/chunks/{chunk-657BH7VM.js → chunk-JE2CEOBO.js} +2 -2
- package/chunks/{chunk-S3TWXGKA.js → chunk-JE7KQ2UP.js} +4 -2
- package/chunks/{chunk-BPZKP57P.js → chunk-JJPKFJBT.js} +3 -3
- package/chunks/{chunk-6PE7N3A4.js → chunk-JLZ3RBQG.js} +7 -5
- package/chunks/{chunk-2LQTH543.js → chunk-JXVC2PL3.js} +2 -2
- package/chunks/{chunk-JCW2R7WC.js → chunk-K623ENWT.js} +3 -79
- package/chunks/{chunk-T2NCM2ET.js → chunk-K6KS3LTN.js} +2 -749
- package/chunks/{chunk-6RPMI2AB.js → chunk-KR32NIAN.js} +6 -6
- package/chunks/{chunk-XBYYDKAZ.js → chunk-KWHKHSIS.js} +8 -7
- package/chunks/{chunk-EVKE2FZL.js → chunk-KXDONCPU.js} +4 -4
- package/chunks/{chunk-5TBMQLGG.js → chunk-L2E5GFAG.js} +2 -2
- package/chunks/{chunk-MHAIJPTD.js → chunk-L32VV3ZJ.js} +12 -12
- package/chunks/{chunk-OKF7JF3R.js → chunk-LHKCY7DY.js} +3 -3
- package/chunks/{chunk-LW3RFMG7.js → chunk-LOY7RWQG.js} +3 -3
- package/chunks/{chunk-AQIDMUGU.js → chunk-LYI2PZDK.js} +1 -1
- package/chunks/{chunk-YGF33UXG.js → chunk-MB32MS4U.js} +12 -3
- package/chunks/{chunk-Y6AXW2OG.js → chunk-MM7TH7ZM.js} +1 -1
- package/chunks/{chunk-2DN4J57Y.js → chunk-N4ACHWNH.js} +1 -1
- package/chunks/{chunk-M7OONWYU.js → chunk-NBD76HUW.js} +4 -2
- package/chunks/{chunk-A2D5BAVP.js → chunk-NHFEMWAZ.js} +1 -1
- package/chunks/{chunk-3EFXSQCM.js → chunk-NTDH4IML.js} +7 -7
- package/chunks/chunk-O6GEWCJA.js +21 -0
- package/chunks/{chunk-7DXQIJID.js → chunk-OFZKFPYG.js} +3 -3
- package/chunks/{chunk-JTV5K7NH.js → chunk-P5VC5USY.js} +1 -1
- package/chunks/{chunk-Q43KPN7X.js → chunk-P755N4CS.js} +3 -3
- package/chunks/{chunk-XFZYFU3I.js → chunk-PCK4B6LR.js} +1 -1
- package/chunks/{chunk-EJGJIBRS.js → chunk-PJOHNFIY.js} +3 -3
- package/chunks/{chunk-WUZ7H6DP.js → chunk-PVNQRENX.js} +1 -1
- package/chunks/{chunk-LO4ROVP4.js → chunk-PZEXDV3H.js} +106 -8
- package/chunks/{chunk-WZRWHXFE.js → chunk-Q3T5KA2V.js} +1 -1
- package/chunks/{chunk-QIZKCVM3.js → chunk-Q5WZTTWE.js} +4 -4
- package/chunks/{chunk-BGTQCTQW.js → chunk-QARJNL2V.js} +3 -3
- package/chunks/{chunk-GXIJHV66.js → chunk-QCXGC7QB.js} +3 -3
- package/chunks/{chunk-DZLYR4U3.js → chunk-QDK4F2N5.js} +1 -1
- package/chunks/{chunk-NOKIVHOL.js → chunk-QTHQ6Z5X.js} +1 -1
- package/chunks/{chunk-A3NDJ5SB.js → chunk-R2XWGR75.js} +2 -2
- package/chunks/{chunk-JX27F6QS.js → chunk-RDJOB6S3.js} +1 -1
- package/chunks/{chunk-TV64SXKD.js → chunk-RG64CDT2.js} +4 -4
- package/chunks/{chunk-JFMA7Y5M.js → chunk-RSVPYAGK.js} +5 -5
- package/chunks/{chunk-64LQLPL7.js → chunk-SHN4KHDK.js} +3 -3
- package/chunks/chunk-T3CHYWJZ.js +758 -0
- package/chunks/{chunk-PONHVBRT.js → chunk-TEGJSJDF.js} +2 -2
- package/chunks/{chunk-75GFAX4R.js → chunk-THVU3RNH.js} +1 -1
- package/chunks/{record-artifact-XAMSFSW4.js → chunk-TIRRPCFS.js} +22 -7
- package/chunks/{chunk-HV26XH34.js → chunk-TTJZAIFP.js} +3 -3
- package/chunks/{chunk-JMONIXMJ.js → chunk-TZTAV5RH.js} +1 -1
- package/chunks/{chunk-7AEJDLRA.js → chunk-UV6KF7T3.js} +2 -2
- package/chunks/{chunk-PLDQBIO6.js → chunk-V25K5ID7.js} +1 -1
- package/chunks/{chunk-S4WJVPZW.js → chunk-V4XNUDPE.js} +3 -3
- package/chunks/{chunk-2FAK6PNM.js → chunk-VEMNQMHA.js} +2 -2
- package/chunks/{chunk-CQL64ESB.js → chunk-VMX5RZQH.js} +12 -10
- package/chunks/{chunk-EIF3FXTB.js → chunk-W3UKBMSI.js} +63 -18
- package/chunks/{chunk-TDL6LB4K.js → chunk-WWCMSZII.js} +21 -9
- package/chunks/{chunk-5YKDXHUY.js → chunk-XP4L6KS3.js} +2 -2
- package/chunks/{chunk-RPLGZJV2.js → chunk-XQK4XXTN.js} +1 -1
- package/chunks/{chunk-KAMYKP7E.js → chunk-XUGZYLDH.js} +1 -1
- package/chunks/{chunk-MR5EAQ5M.js → chunk-YANIWTRZ.js} +1 -1
- package/chunks/{chunk-3L2SPEBH.js → chunk-YGE3IXJP.js} +1 -1
- package/chunks/{chunk-BCZFQXWK.js → chunk-YUFIEIWC.js} +1 -1
- package/chunks/{chunk-75MIQ3LV.js → chunk-Z3S5EMOW.js} +4 -4
- package/chunks/{chunk-BMFALVGQ.js → chunk-ZMOJ7ISP.js} +1 -1
- package/chunks/{chunk-GEBV2JGB.js → chunk-ZPZ7ZJEE.js} +1 -1
- package/chunks/{computer-use-ZTIDHMMA.js → computer-use-5QWCFNKD.js} +38 -34
- package/chunks/{config-utils-NYSXDMEQ.js → config-utils-WADIDWGG.js} +4 -4
- package/chunks/{contextCommand-2PIEU37Z.js → contextCommand-4Z7T7TUM.js} +40 -36
- package/chunks/{core-runtime-3XEYLQFK.js → core-runtime-6N4EFC2Q.js} +38 -34
- package/chunks/{create-sub-session-SBYUMSSS.js → create-sub-session-62YZWVAY.js} +2 -2
- package/chunks/{create-sub-session-R76FVXCI.js → create-sub-session-AEREHZBQ.js} +38 -34
- package/chunks/{cron-create-2QK6TCEC.js → cron-create-6E7GIQTG.js} +4 -4
- package/chunks/{cron-delete-FDCDFYMG.js → cron-delete-JD26XY3W.js} +4 -4
- package/chunks/{cron-list-XN3WVBTP.js → cron-list-CUWFB44G.js} +4 -4
- package/chunks/{daemon-Q2AB5Z23.js → daemon-PCNCI5YU.js} +72 -3
- package/chunks/{daemon-status-provider-3XJI6CAL.js → daemon-status-provider-DDF7C5M7.js} +46 -42
- package/chunks/{daemon-trust-policy-ILUDTLHD.js → daemon-trust-policy-Q4KSOJTR.js} +43 -39
- package/chunks/{daemon-trust-policy-monitor-HS3PKKRO.js → daemon-trust-policy-monitor-V6FTE3IY.js} +43 -39
- package/chunks/{deferred-core-runtime-X4QV662U.js → deferred-core-runtime-GHJ5GQHK.js} +38 -34
- package/chunks/{dist-BSTVRPMT.js → dist-26BIMQT6.js} +276 -16
- package/chunks/{dist-SV7Q3AWJ.js → dist-2PERFI23.js} +12 -9
- package/chunks/{dist-DOLYHMXE.js → dist-OAOC5OV4.js} +2 -2
- package/chunks/{dist-YGBBMK3Z.js → dist-PVEAFLHY.js} +5 -4
- package/chunks/{dist-HVRQ2CFL.js → dist-SL2LUMML.js} +1180 -5
- package/chunks/dist-ULIG4M5H.js +13415 -0
- package/chunks/{dist-IXQEQWRG.js → dist-WGMNT3JQ.js} +1 -1
- package/chunks/{dist-SSU66DM4.js → dist-ZHXOBXDN.js} +1 -1
- package/chunks/{earlyInputCapture-XKLZT7ZD.js → earlyInputCapture-TQXLLISD.js} +39 -35
- package/chunks/{edit-HHGIOTQ2.js → edit-FJEUV6KZ.js} +38 -34
- package/chunks/{enter-worktree-ZN7PUQ46.js → enter-worktree-7GE3TZ4P.js} +38 -34
- package/chunks/{enterPlanMode-EIFIDSIV.js → enterPlanMode-KR5TMPCJ.js} +38 -34
- package/chunks/{environment-XXQ75D2Q.js → environment-SWL3CMB3.js} +40 -36
- package/chunks/{errors-4GMVU7CK.js → errors-XQE7BGZV.js} +40 -36
- package/chunks/{exit-worktree-GXMI4ATY.js → exit-worktree-CHKTYNCV.js} +38 -34
- package/chunks/{exitPlanMode-34UVY7M6.js → exitPlanMode-QYAG6LWX.js} +38 -34
- package/chunks/{fast-path-VPIVA7L6.js → fast-path-Z2K7W6DC.js} +2 -2
- package/chunks/{gemini-4BWIK4WD.js → gemini-YU4XKEDG.js} +91 -87
- package/chunks/{geminiContentGenerator-3XVV5MSS.js → geminiContentGenerator-ZZX6NBO4.js} +6 -6
- package/chunks/{glob-TZ2ABCJG.js → glob-VYF5CXSX.js} +38 -34
- package/chunks/goal-tools-HGO6VXPB.js +335 -0
- package/chunks/{grep-BEF463NA.js → grep-5DP5ZUTW.js} +38 -34
- package/chunks/{handleAutoUpdate-L6ERF36Y.js → handleAutoUpdate-UVBJ56DL.js} +42 -38
- package/chunks/{i18n-FMM5FDXR.js → i18n-UQNYHEUD.js} +39 -35
- package/chunks/{image-gen-HHVLF7HS.js → image-gen-WHPIZNWF.js} +9 -9
- package/chunks/{initializer-625TIAIO.js → initializer-GMIICF4W.js} +44 -40
- package/chunks/{installationInfo-6AM4I2Y3.js → installationInfo-4MGG4WVI.js} +39 -35
- package/chunks/{keychain-token-storage-72IYCAZV.js → keychain-token-storage-IKO4G53C.js} +2 -2
- package/chunks/list-CPN2W334.js +92 -0
- package/chunks/{list-agents-R6KDXQR3.js → list-agents-PXJ7ZUFB.js} +2 -2
- package/chunks/{loadedSettingsAdapter-SPUTNKAV.js → loadedSettingsAdapter-ZQAV5NDO.js} +43 -39
- package/chunks/{loggingContentGenerator-LKOF7XI7.js → loggingContentGenerator-5E7W4IEP.js} +18 -18
- package/chunks/{loop-wakeup-3IQKCYAH.js → loop-wakeup-Y26NQZ5I.js} +13 -6
- package/chunks/{ls-DKZ37A7N.js → ls-ONQTTMQR.js} +4 -4
- package/chunks/{lsp-QNWN7KN3.js → lsp-YGHHRGMD.js} +2 -2
- package/chunks/{managed-npm-update-ACQGGIN5.js → managed-npm-update-MKKAXYXA.js} +39 -35
- package/chunks/{mcp-SZLHKFJW.js → mcp-V5NTJF6X.js} +43 -39
- package/chunks/{monitor-DF52UVHI.js → monitor-CO3ASY6E.js} +38 -34
- package/chunks/nonInteractiveCli-ZJYEOO7U.js +148 -0
- package/chunks/{notebook-edit-FCWS4XVN.js → notebook-edit-Z7AEE6FM.js} +38 -34
- package/chunks/{openaiContentGenerator-7LDK3DCJ.js → openaiContentGenerator-CA3MQOP3.js} +19 -19
- package/chunks/{pidfile-6ERW3DF4.js → pidfile-NL7MKDRU.js} +39 -35
- package/chunks/{processUtils-COKZAMUP.js → processUtils-PB5K2DYH.js} +2 -2
- package/chunks/{qwenContentGenerator-TKWUMR7N.js → qwenContentGenerator-JYFNDCOS.js} +44 -40
- package/chunks/{qwenOAuth2-7HMU47SF.js → qwenOAuth2-W2ALKQDD.js} +8 -8
- package/chunks/{read-file-X6DRC574.js → read-file-IEOR5H5W.js} +11 -11
- package/chunks/{read-mcp-resource-GFTWYXMK.js → read-mcp-resource-U2IJN5HM.js} +2 -2
- package/chunks/record-artifact-MGPJ7EG4.js +21 -0
- package/chunks/{resumeHistoryUtils-PFPM2GWM.js → resumeHistoryUtils-BNBTP5AS.js} +44 -40
- package/chunks/{ripGrep-OWV2IVJC.js → ripGrep-UMQODKEB.js} +38 -34
- package/chunks/{run-qwen-serve-TSTCO4XE.js → run-qwen-serve-RN2R6QQW.js} +116 -65
- package/chunks/{runtime-DAUPSUKI.js → runtime-QFJ2MJF5.js} +48 -44
- package/chunks/{scheduler-KMADMT26.js → scheduler-AMYUFOZI.js} +38 -34
- package/chunks/{sdk-exporters-http-WO556XNU.js → sdk-exporters-http-4BQANSJ6.js} +3 -3
- package/chunks/{sdk-impl-LPAVACSF.js → sdk-impl-Z4VXWVFX.js} +3 -3
- package/chunks/{send-message-SAWK4DZX.js → send-message-PMP4ATVM.js} +6 -11
- package/chunks/{serve-NNRWS6F4.js → serve-EIIYJVX3.js} +43 -39
- package/chunks/{server-WEH7DVCH.js → server-EP2LLAPD.js} +1768 -712
- package/chunks/{session-WXC56V2I.js → session-GMPZBLOW.js} +83 -79
- package/chunks/{settings-DJDXFDZ3.js → settings-LN7RNKBS.js} +47 -43
- package/chunks/{shell-JN5VRQXD.js → shell-EM2OWU5X.js} +38 -34
- package/chunks/{skill-SGXPKJCS.js → skill-T5VPSK73.js} +17 -16
- package/chunks/{skill-settings-VJ5PDMZI.js → skill-settings-GMR3GMNY.js} +42 -38
- package/chunks/{spawnChannel-ETMJW7YX.js → spawnChannel-YPCU62DI.js} +40 -36
- package/chunks/{standalone-update-MK3Z7KBI.js → standalone-update-JAKIM2NF.js} +40 -36
- package/chunks/{startInteractiveUI-ZCGIXPGT.js → startInteractiveUI-YETQWGYF.js} +774 -779
- package/chunks/{syntheticOutput-355CB6CJ.js → syntheticOutput-D7E6ZFKR.js} +3 -3
- package/chunks/{task-create-INGWNUG4.js → task-create-NFCYD43L.js} +10 -9
- package/chunks/{task-list-5XNNGTF4.js → task-list-TAVMGEVD.js} +5 -5
- package/chunks/{task-stop-4ROAOBXH.js → task-stop-ZDF2UJRM.js} +2 -2
- package/chunks/{task-update-CRK5VWWZ.js → task-update-6L7LHGEX.js} +10 -9
- package/chunks/{team-create-QQGAJG7P.js → team-create-LFJ6HGNY.js} +38 -34
- package/chunks/{team-delete-S2RCXA4P.js → team-delete-DPGGRQBU.js} +5 -5
- package/chunks/{team-plan-approval-RT7Q5R6O.js → team-plan-approval-C2KLSDGO.js} +38 -34
- package/chunks/{theme-manager-EEWIQJ7J.js → theme-manager-JQ3ZGBP5.js} +39 -35
- package/chunks/{todoWrite-7WM3VDMY.js → todoWrite-2UO5G6G6.js} +32 -4
- package/chunks/{tool-search-Z3Z4AYKP.js → tool-search-FAZBFRJZ.js} +15 -14
- package/chunks/{total-session-admission-44JKRWQD.js → total-session-admission-5CALIVYO.js} +42 -38
- package/chunks/{trustedFolders-X2JEIO57.js → trustedFolders-KOPSP44S.js} +39 -35
- package/chunks/{update-relaunch-VWNPYDIP.js → update-relaunch-6QL2TICS.js} +5 -5
- package/chunks/{updateCheck-KAQH67DV.js → updateCheck-4Q6RIKFW.js} +41 -37
- package/chunks/{useAutoAcceptIndicator-JH6BCF7S.js → useAutoAcceptIndicator-Q5BMKZV3.js} +47 -43
- package/chunks/{validateNonInterActiveAuth-GIUJ2UFS.js → validateNonInterActiveAuth-GKOC5F6Z.js} +79 -75
- package/chunks/{version-BGLYIJUY.js → version-VSATY2LD.js} +1 -1
- package/chunks/{web-fetch-OTDU4VQF.js → web-fetch-JCLKL6NL.js} +14 -14
- package/chunks/{web-search-FP6SIHPR.js → web-search-DSQTFUBX.js} +8 -8
- package/chunks/{workflow-YCIVBYSB.js → workflow-M6QAVKVJ.js} +41 -37
- package/chunks/workspace-providers-status-YKLTLMJA.js +89 -0
- package/chunks/{workspace-registration-store-OTMS3H4C.js → workspace-registration-store-5DMGKU64.js} +1 -1
- package/chunks/{workspace-registry-O63R6IZ4.js → workspace-registry-PTYUSYXX.js} +42 -38
- package/chunks/{workspace-service-M6LLHKJ5.js → workspace-service-25ML3T47.js} +48 -44
- package/chunks/{workspace-skills-status-C2V7BAIS.js → workspace-skills-status-YKZWOYRX.js} +44 -40
- package/chunks/{workspace-trust-reconciler-IBUPOUJN.js → workspace-trust-reconciler-5FI2S3OS.js} +47 -43
- package/chunks/write-file-AY7VLP5X.js +78 -0
- package/chunks/zoom-image-S4LJZMD5.js +224 -0
- package/cli.js +50 -16
- package/package.json +3 -3
- package/web-shell/assets/{arc-75-Wdeo3.js → arc-xjArKHU2.js} +1 -1
- package/web-shell/assets/{architectureDiagram-3BPJPVTR-FKeXQbyP.js → architectureDiagram-3BPJPVTR-BgrQDNYG.js} +1 -1
- package/web-shell/assets/{blockDiagram-GPEHLZMM-CY0vc-A3.js → blockDiagram-GPEHLZMM-CXxWC-1_.js} +1 -1
- package/web-shell/assets/{c4Diagram-AAUBKEIU-CNP-A-8u.js → c4Diagram-AAUBKEIU-Dx1tLm3v.js} +1 -1
- package/web-shell/assets/channel-B1cyk94G.js +1 -0
- package/web-shell/assets/{chunk-2J33WTMH-GybS4Gii.js → chunk-2J33WTMH-CBxjogVR.js} +1 -1
- package/web-shell/assets/{chunk-4BX2VUAB-02H91V8v.js → chunk-4BX2VUAB-izb-rY5W.js} +1 -1
- package/web-shell/assets/{chunk-55IACEB6-D3M-2VT6.js → chunk-55IACEB6-NzLyvSb8.js} +1 -1
- package/web-shell/assets/{chunk-727SXJPM-CCu29u4H.js → chunk-727SXJPM-DVyKb0dl.js} +1 -1
- package/web-shell/assets/{chunk-AQP2D5EJ-CaFKWgrn.js → chunk-AQP2D5EJ-BtqL7NzB.js} +1 -1
- package/web-shell/assets/{chunk-FMBD7UC4-ZZpPqIwQ.js → chunk-FMBD7UC4-iNpdKIO0.js} +1 -1
- package/web-shell/assets/{chunk-ND2GUHAM-D22DqGs8.js → chunk-ND2GUHAM-DI7cbFmX.js} +1 -1
- package/web-shell/assets/{chunk-QZHKN3VN-Bu85S0fw.js → chunk-QZHKN3VN-3Y_-xFYs.js} +1 -1
- package/web-shell/assets/classDiagram-4FO5ZUOK-BpBYZoRE.js +1 -0
- package/web-shell/assets/classDiagram-v2-Q7XG4LA2-BpBYZoRE.js +1 -0
- package/web-shell/assets/{cose-bilkent-S5V4N54A-f1CK1Gwe.js → cose-bilkent-S5V4N54A--raRatZn.js} +1 -1
- package/web-shell/assets/{dagre-BM42HDAG-D0Ow8F_n.js → dagre-BM42HDAG-B8SU70mO.js} +1 -1
- package/web-shell/assets/{diagram-2AECGRRQ-BPrmTWp8.js → diagram-2AECGRRQ-ewgoakXo.js} +1 -1
- package/web-shell/assets/{diagram-5GNKFQAL-HccuFAzy.js → diagram-5GNKFQAL-Bm_JLTnS.js} +1 -1
- package/web-shell/assets/{diagram-KO2AKTUF-BrS76mbA.js → diagram-KO2AKTUF-DEIUjUy9.js} +1 -1
- package/web-shell/assets/{diagram-LMA3HP47-V7T9lU-5.js → diagram-LMA3HP47-C2Wmrpj-.js} +1 -1
- package/web-shell/assets/{diagram-OG6HWLK6-DKidyJMR.js → diagram-OG6HWLK6-CtYe6bFx.js} +1 -1
- package/web-shell/assets/{erDiagram-TEJ5UH35-DBadZIkp.js → erDiagram-TEJ5UH35-DfpHcWLV.js} +1 -1
- package/web-shell/assets/{flowDiagram-I6XJVG4X-BymfqdNJ.js → flowDiagram-I6XJVG4X-CAiUhio5.js} +1 -1
- package/web-shell/assets/{ganttDiagram-6RSMTGT7-DOw340jf.js → ganttDiagram-6RSMTGT7-CYc7ezr4.js} +1 -1
- package/web-shell/assets/{gitGraphDiagram-PVQCEYII-_8EiD8sl.js → gitGraphDiagram-PVQCEYII-70lbkcRS.js} +1 -1
- package/web-shell/assets/index-C1k3PDuU.css +5 -0
- package/web-shell/assets/index-C2GE3DAF.js +74 -0
- package/web-shell/assets/index-DZLIXILO.js +1750 -0
- package/web-shell/assets/{index-CKIadvET.js → index-Ww86nT9f.js} +1 -1
- package/web-shell/assets/{infoDiagram-5YYISTIA-D61KYQBu.js → infoDiagram-5YYISTIA-C7e8DWPa.js} +1 -1
- package/web-shell/assets/{ishikawaDiagram-YF4QCWOH-CsiXSpNx.js → ishikawaDiagram-YF4QCWOH-BYLr2op-.js} +1 -1
- package/web-shell/assets/{journeyDiagram-JHISSGLW-Sdfionyh.js → journeyDiagram-JHISSGLW-hEibAHKX.js} +1 -1
- package/web-shell/assets/{kanban-definition-UN3LZRKU-C3WI3Cnl.js → kanban-definition-UN3LZRKU-F2rt8Uhp.js} +1 -1
- package/web-shell/assets/{linear-Dpigcc62.js → linear-DPhyNezd.js} +1 -1
- package/web-shell/assets/{mermaid.core-Ct97pqgW.js → mermaid.core-ZUtnug0n.js} +5 -5
- package/web-shell/assets/{mindmap-definition-RKZ34NQL-BzeaN0rB.js → mindmap-definition-RKZ34NQL-DDWcMoi8.js} +1 -1
- package/web-shell/assets/{pieDiagram-4H26LBE5-CvjgcbVD.js → pieDiagram-4H26LBE5-CTRKzw1_.js} +1 -1
- package/web-shell/assets/{quadrantDiagram-W4KKPZXB-BUzgTNdH.js → quadrantDiagram-W4KKPZXB-CAEwYG_z.js} +1 -1
- package/web-shell/assets/{requirementDiagram-4Y6WPE33-B7zKlgUQ.js → requirementDiagram-4Y6WPE33-CRjnH9D9.js} +1 -1
- package/web-shell/assets/{sankeyDiagram-5OEKKPKP-Bb9CQgrT.js → sankeyDiagram-5OEKKPKP-LPQT_sOd.js} +1 -1
- package/web-shell/assets/{sequenceDiagram-3UESZ5HK-DJ6V7itG.js → sequenceDiagram-3UESZ5HK-Ht2Iqvb0.js} +1 -1
- package/web-shell/assets/{stateDiagram-AJRCARHV-IImflERY.js → stateDiagram-AJRCARHV-CIUdqOXu.js} +1 -1
- package/web-shell/assets/stateDiagram-v2-BHNVJYJU-BmqqQZ6w.js +1 -0
- package/web-shell/assets/{timeline-definition-PNZ67QCA-6Q_uWHKh.js → timeline-definition-PNZ67QCA-BcilneZF.js} +1 -1
- package/web-shell/assets/{vennDiagram-CIIHVFJN-TmyKyjwv.js → vennDiagram-CIIHVFJN-BljwiiH1.js} +1 -1
- package/web-shell/assets/{wardley-L42UT6IY-CRh9uiPv.js → wardley-L42UT6IY-DeKjkYjq.js} +1 -1
- package/web-shell/assets/{wardleyDiagram-YWT4CUSO-59TKAW8w.js → wardleyDiagram-YWT4CUSO-L3U1H7KG.js} +1 -1
- package/web-shell/assets/{xychartDiagram-2RQKCTM6-GCSUIK2L.js → xychartDiagram-2RQKCTM6-IJnWsgMT.js} +1 -1
- package/web-shell/index.html +2 -2
- package/chunks/list-L2GA674Y.js +0 -88
- package/chunks/nonInteractiveCli-5T7KYKLK.js +0 -144
- package/chunks/workspace-providers-status-S35YAIUS.js +0 -85
- package/chunks/write-file-3BZC3EAE.js +0 -72
- package/chunks/zoom-image-TZ6S2O57.js +0 -351
- package/web-shell/assets/channel-DPYMT76A.js +0 -1
- package/web-shell/assets/classDiagram-4FO5ZUOK--JstsIgL.js +0 -1
- package/web-shell/assets/classDiagram-v2-Q7XG4LA2--JstsIgL.js +0 -1
- package/web-shell/assets/index-D1eXNRHe.js +0 -1389
- package/web-shell/assets/index-DVLD4CQq.css +0 -5
- package/web-shell/assets/stateDiagram-v2-BHNVJYJU-CYI_YoNR.js +0 -1
|
@@ -0,0 +1,1591 @@
|
|
|
1
|
+
// Force strict mode and setup for ESM
|
|
2
|
+
"use strict";
|
|
3
|
+
import {
|
|
4
|
+
init_esbuild_shims
|
|
5
|
+
} from "./chunk-5O2XNYP6.js";
|
|
6
|
+
import {
|
|
7
|
+
__name
|
|
8
|
+
} from "./chunk-J2S4EL5Y.js";
|
|
9
|
+
|
|
10
|
+
// packages/core/src/goals/goal-protocol.ts
|
|
11
|
+
init_esbuild_shims();
|
|
12
|
+
var GOAL_STATE_VERSION = 2;
|
|
13
|
+
var GOAL_PROPOSAL_REASON_MAX_CHARACTERS = 8e3;
|
|
14
|
+
var GOAL_PROPOSAL_REASON_MAX_BYTES = 16e3;
|
|
15
|
+
var PAUSED_GOAL_SYSTEM_REMINDER = "<system-reminder>\nThe Goal is paused. Do not continue its objective unless the user resumes it. Treat this message as ordinary conversation.\n</system-reminder>";
|
|
16
|
+
function goalRequiresExactPermit(snapshot) {
|
|
17
|
+
return snapshot.goal !== null && (snapshot.goal.status === "active" || snapshot.activity === "running");
|
|
18
|
+
}
|
|
19
|
+
__name(goalRequiresExactPermit, "goalRequiresExactPermit");
|
|
20
|
+
function validateGoalProposalReason(reason) {
|
|
21
|
+
if (!reason.trim()) return "Goal proposal reason must not be empty";
|
|
22
|
+
if ([...reason].length > GOAL_PROPOSAL_REASON_MAX_CHARACTERS) {
|
|
23
|
+
return `Goal proposal reason exceeds ${GOAL_PROPOSAL_REASON_MAX_CHARACTERS} characters`;
|
|
24
|
+
}
|
|
25
|
+
if (new TextEncoder().encode(reason).byteLength > GOAL_PROPOSAL_REASON_MAX_BYTES) {
|
|
26
|
+
return `Goal proposal reason exceeds ${GOAL_PROPOSAL_REASON_MAX_BYTES} UTF-8 bytes`;
|
|
27
|
+
}
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
__name(validateGoalProposalReason, "validateGoalProposalReason");
|
|
31
|
+
|
|
32
|
+
// packages/core/src/goals/goal-evidence.ts
|
|
33
|
+
init_esbuild_shims();
|
|
34
|
+
var CATALOG_PREVIEW_LIMIT = 240;
|
|
35
|
+
var CATALOG_ENTRY_LIMIT = 100;
|
|
36
|
+
var CATALOG_BYTE_LIMIT = 24e3;
|
|
37
|
+
var CATALOG_LINEAGE_LIMIT = 16;
|
|
38
|
+
var GOAL_EVIDENCE_REFERENCE_LIMIT = CATALOG_ENTRY_LIMIT;
|
|
39
|
+
var VERIFIER_EVIDENCE_BYTE_LIMIT = 256e3;
|
|
40
|
+
var EvidenceSourceUnavailableError = class extends Error {
|
|
41
|
+
constructor(code, message) {
|
|
42
|
+
super(message);
|
|
43
|
+
this.code = code;
|
|
44
|
+
this.name = "EvidenceSourceUnavailableError";
|
|
45
|
+
}
|
|
46
|
+
static {
|
|
47
|
+
__name(this, "EvidenceSourceUnavailableError");
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
var InvalidGoalEvidenceReferenceError = class extends Error {
|
|
51
|
+
constructor(code, message, reference) {
|
|
52
|
+
super(message);
|
|
53
|
+
this.code = code;
|
|
54
|
+
this.reference = reference;
|
|
55
|
+
this.name = "InvalidGoalEvidenceReferenceError";
|
|
56
|
+
}
|
|
57
|
+
static {
|
|
58
|
+
__name(this, "InvalidGoalEvidenceReferenceError");
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
function buildGoalEvidenceCatalog(input) {
|
|
62
|
+
const analysis = analyzeEvidence(input);
|
|
63
|
+
return {
|
|
64
|
+
entries: analysis.catalog.map((entry) => ({ ...entry })),
|
|
65
|
+
lineageTurnIds: analysis.lineageTurnIds.slice(-CATALOG_LINEAGE_LIMIT),
|
|
66
|
+
truncated: analysis.catalogTruncated
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
__name(buildGoalEvidenceCatalog, "buildGoalEvidenceCatalog");
|
|
70
|
+
function validateGoalEvidenceReferences(input) {
|
|
71
|
+
const references = input.proposal.evidenceRefs;
|
|
72
|
+
if (references.length === 0) {
|
|
73
|
+
throw new InvalidGoalEvidenceReferenceError(
|
|
74
|
+
"no_evidence_references",
|
|
75
|
+
"A terminal Goal proposal must cite at least one evidence record."
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
if (references.length > GOAL_EVIDENCE_REFERENCE_LIMIT) {
|
|
79
|
+
throw new InvalidGoalEvidenceReferenceError(
|
|
80
|
+
"too_many_evidence_references",
|
|
81
|
+
`A terminal Goal proposal may cite at most ${GOAL_EVIDENCE_REFERENCE_LIMIT} evidence records.`
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
if (new Set(references).size !== references.length) {
|
|
85
|
+
throw new InvalidGoalEvidenceReferenceError(
|
|
86
|
+
"duplicate_evidence_reference",
|
|
87
|
+
"A terminal Goal proposal must not cite the same evidence record more than once."
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
const analysis = analyzeEvidence(input);
|
|
91
|
+
const citedRecords = references.map(
|
|
92
|
+
(reference) => validateReference(reference, input, analysis)
|
|
93
|
+
);
|
|
94
|
+
if (input.proposal.status === "complete" && analysis.catalogTruncated) {
|
|
95
|
+
throw new InvalidGoalEvidenceReferenceError(
|
|
96
|
+
"catalog_truncated",
|
|
97
|
+
"A complete Goal proposal requires an exhaustive bounded evidence catalog."
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
const evidenceBytes = citedRecords.reduce(
|
|
101
|
+
(total, record) => total + Buffer.byteLength(record.content, "utf8"),
|
|
102
|
+
0
|
|
103
|
+
);
|
|
104
|
+
if (evidenceBytes > VERIFIER_EVIDENCE_BYTE_LIMIT) {
|
|
105
|
+
throw new InvalidGoalEvidenceReferenceError(
|
|
106
|
+
"evidence_payload_too_large",
|
|
107
|
+
`Cited Goal evidence exceeds the ${VERIFIER_EVIDENCE_BYTE_LIMIT}-byte verifier limit.`
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
validateBlockerCoverage(input.proposal, citedRecords, analysis);
|
|
111
|
+
return {
|
|
112
|
+
citedRecords: citedRecords.map((entry) => ({ ...entry }))
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
__name(validateGoalEvidenceReferences, "validateGoalEvidenceReferences");
|
|
116
|
+
function analyzeEvidence(input) {
|
|
117
|
+
if (input.permit.goalId !== input.goal.goalId || input.permit.revision !== input.goal.revision || !isNonEmptyString(input.permit.turnId)) {
|
|
118
|
+
throw new EvidenceSourceUnavailableError(
|
|
119
|
+
"permit_goal_mismatch",
|
|
120
|
+
"The current Goal permit does not match the Goal evidence revision."
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
const cursorId = input.goal.evidenceCursor.recordId;
|
|
124
|
+
if (cursorId === null) {
|
|
125
|
+
throw new EvidenceSourceUnavailableError(
|
|
126
|
+
"cursor_unset",
|
|
127
|
+
"The Goal evidence cursor is not available."
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
const indexByUuid = /* @__PURE__ */ new Map();
|
|
131
|
+
for (let index = 0; index < input.records.length; index += 1) {
|
|
132
|
+
const uuid = input.records[index].uuid;
|
|
133
|
+
if (indexByUuid.has(uuid)) {
|
|
134
|
+
throw new EvidenceSourceUnavailableError(
|
|
135
|
+
"duplicate_record_uuid",
|
|
136
|
+
`The active transcript chain contains duplicate record UUID ${uuid}.`
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
indexByUuid.set(uuid, index);
|
|
140
|
+
}
|
|
141
|
+
const cursorIndex = indexByUuid.get(cursorId);
|
|
142
|
+
if (cursorIndex === void 0) {
|
|
143
|
+
throw new EvidenceSourceUnavailableError(
|
|
144
|
+
"cursor_not_found",
|
|
145
|
+
`The Goal evidence cursor ${cursorId} is not in the active transcript chain.`
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
const lineageTurnIds = collectLineageTurnIds(input, cursorIndex);
|
|
149
|
+
if (lineageTurnIds.at(-1) !== input.permit.turnId) {
|
|
150
|
+
throw new EvidenceSourceUnavailableError(
|
|
151
|
+
"current_turn_not_tail",
|
|
152
|
+
"The current Goal permit is not the tail of the active transcript lineage."
|
|
153
|
+
);
|
|
154
|
+
}
|
|
155
|
+
const selectedEvidence = [];
|
|
156
|
+
let catalogBytes = 0;
|
|
157
|
+
let catalogTruncated = false;
|
|
158
|
+
for (let index = input.records.length - 1; index > cursorIndex; index -= 1) {
|
|
159
|
+
if (selectedEvidence.length >= CATALOG_ENTRY_LIMIT) {
|
|
160
|
+
catalogTruncated = true;
|
|
161
|
+
break;
|
|
162
|
+
}
|
|
163
|
+
const evidence = catalogEvidence(input.records[index], input);
|
|
164
|
+
if (!evidence) continue;
|
|
165
|
+
const entryBytes = Buffer.byteLength(JSON.stringify(evidence), "utf8");
|
|
166
|
+
if (catalogBytes + entryBytes > CATALOG_BYTE_LIMIT) {
|
|
167
|
+
catalogTruncated = true;
|
|
168
|
+
break;
|
|
169
|
+
}
|
|
170
|
+
selectedEvidence.push(evidence);
|
|
171
|
+
catalogBytes += entryBytes;
|
|
172
|
+
}
|
|
173
|
+
selectedEvidence.reverse();
|
|
174
|
+
const eligibleByUuid = new Map(
|
|
175
|
+
selectedEvidence.map((entry) => [entry.uuid, entry])
|
|
176
|
+
);
|
|
177
|
+
return {
|
|
178
|
+
cursorIndex,
|
|
179
|
+
catalog: selectedEvidence,
|
|
180
|
+
eligibleByUuid,
|
|
181
|
+
indexByUuid,
|
|
182
|
+
lineageTurnIds,
|
|
183
|
+
catalogTruncated
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
__name(analyzeEvidence, "analyzeEvidence");
|
|
187
|
+
function collectLineageTurnIds(input, cursorIndex) {
|
|
188
|
+
const lineageTurnIds = [];
|
|
189
|
+
const seenTurnIds = /* @__PURE__ */ new Set();
|
|
190
|
+
let currentTurnId;
|
|
191
|
+
for (let index = cursorIndex + 1; index < input.records.length; index += 1) {
|
|
192
|
+
const record = input.records[index];
|
|
193
|
+
const context = parseGoalContext(record.goalContext);
|
|
194
|
+
if (!context) {
|
|
195
|
+
if (claimsGoalRevision(record.goalContext, input.goal)) {
|
|
196
|
+
throw new EvidenceSourceUnavailableError(
|
|
197
|
+
"malformed_turn_context",
|
|
198
|
+
`Goal-owned transcript record ${record.uuid} has malformed turn context.`
|
|
199
|
+
);
|
|
200
|
+
}
|
|
201
|
+
continue;
|
|
202
|
+
}
|
|
203
|
+
if (context.goalId !== input.goal.goalId || context.revision !== input.goal.revision) {
|
|
204
|
+
continue;
|
|
205
|
+
}
|
|
206
|
+
if (context.turnId === currentTurnId) continue;
|
|
207
|
+
if (seenTurnIds.has(context.turnId)) {
|
|
208
|
+
throw new EvidenceSourceUnavailableError(
|
|
209
|
+
"turn_reentry",
|
|
210
|
+
`Goal turn ${context.turnId} re-enters the active transcript lineage.`
|
|
211
|
+
);
|
|
212
|
+
}
|
|
213
|
+
seenTurnIds.add(context.turnId);
|
|
214
|
+
lineageTurnIds.push(context.turnId);
|
|
215
|
+
currentTurnId = context.turnId;
|
|
216
|
+
}
|
|
217
|
+
return lineageTurnIds;
|
|
218
|
+
}
|
|
219
|
+
__name(collectLineageTurnIds, "collectLineageTurnIds");
|
|
220
|
+
function validateReference(reference, input, analysis) {
|
|
221
|
+
const recordIndex = analysis.indexByUuid.get(reference);
|
|
222
|
+
if (recordIndex === void 0) {
|
|
223
|
+
throw new InvalidGoalEvidenceReferenceError(
|
|
224
|
+
"missing_reference",
|
|
225
|
+
`Evidence reference ${reference} is not in the active transcript chain.`,
|
|
226
|
+
reference
|
|
227
|
+
);
|
|
228
|
+
}
|
|
229
|
+
if (recordIndex <= analysis.cursorIndex) {
|
|
230
|
+
throw new InvalidGoalEvidenceReferenceError(
|
|
231
|
+
"pre_cursor_reference",
|
|
232
|
+
`Evidence reference ${reference} is not after the Goal evidence cursor.`,
|
|
233
|
+
reference
|
|
234
|
+
);
|
|
235
|
+
}
|
|
236
|
+
const record = input.records[recordIndex];
|
|
237
|
+
if (!coherentEvidenceProvenance(record)) {
|
|
238
|
+
throw new InvalidGoalEvidenceReferenceError(
|
|
239
|
+
"ineligible_reference",
|
|
240
|
+
`Transcript record ${reference} is not an eligible evidence source.`,
|
|
241
|
+
reference
|
|
242
|
+
);
|
|
243
|
+
}
|
|
244
|
+
const context = parseGoalContext(record.goalContext);
|
|
245
|
+
if (!context) {
|
|
246
|
+
throw new InvalidGoalEvidenceReferenceError(
|
|
247
|
+
"missing_goal_context",
|
|
248
|
+
`Evidence reference ${reference} has no valid Goal turn context.`,
|
|
249
|
+
reference
|
|
250
|
+
);
|
|
251
|
+
}
|
|
252
|
+
if (context.goalId !== input.goal.goalId) {
|
|
253
|
+
throw new InvalidGoalEvidenceReferenceError(
|
|
254
|
+
"wrong_goal_id",
|
|
255
|
+
`Evidence reference ${reference} belongs to a different Goal.`,
|
|
256
|
+
reference
|
|
257
|
+
);
|
|
258
|
+
}
|
|
259
|
+
if (context.revision !== input.goal.revision) {
|
|
260
|
+
throw new InvalidGoalEvidenceReferenceError(
|
|
261
|
+
"wrong_revision",
|
|
262
|
+
`Evidence reference ${reference} belongs to a different Goal revision.`,
|
|
263
|
+
reference
|
|
264
|
+
);
|
|
265
|
+
}
|
|
266
|
+
if (!analysis.lineageTurnIds.includes(context.turnId)) {
|
|
267
|
+
throw new InvalidGoalEvidenceReferenceError(
|
|
268
|
+
"wrong_turn_lineage",
|
|
269
|
+
`Evidence reference ${reference} is not in the active Goal turn lineage.`,
|
|
270
|
+
reference
|
|
271
|
+
);
|
|
272
|
+
}
|
|
273
|
+
const catalogEntry = analysis.eligibleByUuid.get(reference);
|
|
274
|
+
if (!catalogEntry) {
|
|
275
|
+
throw new InvalidGoalEvidenceReferenceError(
|
|
276
|
+
"reference_not_catalogued",
|
|
277
|
+
`Evidence reference ${reference} is outside the bounded Goal evidence catalog.`,
|
|
278
|
+
reference
|
|
279
|
+
);
|
|
280
|
+
}
|
|
281
|
+
const content = evidenceContent(record, catalogEntry.provenance);
|
|
282
|
+
if (!content) {
|
|
283
|
+
throw new InvalidGoalEvidenceReferenceError(
|
|
284
|
+
"ineligible_reference",
|
|
285
|
+
`Transcript record ${reference} has no eligible evidence content.`,
|
|
286
|
+
reference
|
|
287
|
+
);
|
|
288
|
+
}
|
|
289
|
+
return { ...catalogEntry, content };
|
|
290
|
+
}
|
|
291
|
+
__name(validateReference, "validateReference");
|
|
292
|
+
function validateBlockerCoverage(proposal, citedRecords, analysis) {
|
|
293
|
+
if (proposal.status !== "blocked") return;
|
|
294
|
+
if (proposal.blockerKind === "authority" || proposal.blockerKind === "external") {
|
|
295
|
+
if (!citedRecords.some(
|
|
296
|
+
({ provenance }) => provenance === "real_user" || provenance === "tool_result"
|
|
297
|
+
)) {
|
|
298
|
+
throw new InvalidGoalEvidenceReferenceError(
|
|
299
|
+
"immediate_blocker_external_evidence_required",
|
|
300
|
+
"An immediate blocker requires cited user input or external tool evidence."
|
|
301
|
+
);
|
|
302
|
+
}
|
|
303
|
+
const citedIds = new Set(citedRecords.map(({ uuid }) => uuid));
|
|
304
|
+
const oldestBlockerIndex = Math.min(
|
|
305
|
+
...citedRecords.filter(
|
|
306
|
+
({ provenance }) => provenance === "real_user" || provenance === "tool_result"
|
|
307
|
+
).map(
|
|
308
|
+
({ uuid }) => analysis.catalog.findIndex((entry) => entry.uuid === uuid)
|
|
309
|
+
)
|
|
310
|
+
);
|
|
311
|
+
const uncitedNewerEvidence = analysis.catalog.slice(oldestBlockerIndex + 1).filter(({ uuid }) => !citedIds.has(uuid));
|
|
312
|
+
if (uncitedNewerEvidence.length > 0) {
|
|
313
|
+
throw new InvalidGoalEvidenceReferenceError(
|
|
314
|
+
"immediate_blocker_newer_evidence_required",
|
|
315
|
+
"An immediate blocker must cite every newer bounded evidence record so contradictory evidence cannot be omitted."
|
|
316
|
+
);
|
|
317
|
+
}
|
|
318
|
+
return;
|
|
319
|
+
}
|
|
320
|
+
const requiredTurnIds = analysis.lineageTurnIds.slice(-3);
|
|
321
|
+
const currentTurnId = requiredTurnIds.at(-1);
|
|
322
|
+
const citedTurnIds = new Set(
|
|
323
|
+
citedRecords.filter(
|
|
324
|
+
(record) => record.provenance !== "assistant_output" || record.turnId === currentTurnId
|
|
325
|
+
).map(({ turnId }) => turnId)
|
|
326
|
+
);
|
|
327
|
+
if (requiredTurnIds.length !== 3 || !requiredTurnIds.every((turnId) => citedTurnIds.has(turnId))) {
|
|
328
|
+
throw new InvalidGoalEvidenceReferenceError(
|
|
329
|
+
"repeated_blocker_turn_coverage",
|
|
330
|
+
"A repeated blocker requires evidence from the current and two immediately preceding Goal turns."
|
|
331
|
+
);
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
__name(validateBlockerCoverage, "validateBlockerCoverage");
|
|
335
|
+
function catalogEvidence(record, input) {
|
|
336
|
+
const provenance = coherentEvidenceProvenance(record);
|
|
337
|
+
if (!provenance) return void 0;
|
|
338
|
+
const context = parseGoalContext(record.goalContext);
|
|
339
|
+
if (!context || context.goalId !== input.goal.goalId || context.revision !== input.goal.revision) {
|
|
340
|
+
return void 0;
|
|
341
|
+
}
|
|
342
|
+
const preview = evidencePreview(record, provenance);
|
|
343
|
+
if (!preview) return void 0;
|
|
344
|
+
return {
|
|
345
|
+
uuid: record.uuid,
|
|
346
|
+
provenance,
|
|
347
|
+
turnId: context.turnId,
|
|
348
|
+
preview,
|
|
349
|
+
proofKind: proofKindOf(provenance)
|
|
350
|
+
};
|
|
351
|
+
}
|
|
352
|
+
__name(catalogEvidence, "catalogEvidence");
|
|
353
|
+
function coherentEvidenceProvenance(record) {
|
|
354
|
+
if (record.type === "system") return void 0;
|
|
355
|
+
const provenance = record.provenance ?? legacySafeProvenance(record);
|
|
356
|
+
if (provenance === "real_user") {
|
|
357
|
+
return record.type === "user" && (record.subtype === void 0 || record.subtype === "mid_turn_user_message") ? provenance : void 0;
|
|
358
|
+
}
|
|
359
|
+
if (provenance === "assistant_output") {
|
|
360
|
+
return record.type === "assistant" && record.subtype === void 0 ? provenance : void 0;
|
|
361
|
+
}
|
|
362
|
+
if (provenance === "tool_result") {
|
|
363
|
+
return record.type === "tool_result" && record.subtype === void 0 ? provenance : void 0;
|
|
364
|
+
}
|
|
365
|
+
return void 0;
|
|
366
|
+
}
|
|
367
|
+
__name(coherentEvidenceProvenance, "coherentEvidenceProvenance");
|
|
368
|
+
function legacySafeProvenance(record) {
|
|
369
|
+
if (record.type === "user" && (record.subtype === void 0 || record.subtype === "mid_turn_user_message")) {
|
|
370
|
+
return "real_user";
|
|
371
|
+
}
|
|
372
|
+
if (record.type === "assistant" && record.subtype === void 0) {
|
|
373
|
+
return "assistant_output";
|
|
374
|
+
}
|
|
375
|
+
if (record.type === "tool_result" && record.subtype === void 0) {
|
|
376
|
+
return "tool_result";
|
|
377
|
+
}
|
|
378
|
+
return void 0;
|
|
379
|
+
}
|
|
380
|
+
__name(legacySafeProvenance, "legacySafeProvenance");
|
|
381
|
+
function evidenceContent(record, provenance) {
|
|
382
|
+
const content = [];
|
|
383
|
+
for (const part of record.message?.parts ?? []) {
|
|
384
|
+
if (part.thought !== true && typeof part.text === "string") {
|
|
385
|
+
content.push(part.text);
|
|
386
|
+
}
|
|
387
|
+
if (provenance === "tool_result" && part.functionResponse) {
|
|
388
|
+
const rendered = renderToolResponse(part.functionResponse);
|
|
389
|
+
if (rendered) content.push(rendered);
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
return content.join("\n").trim();
|
|
393
|
+
}
|
|
394
|
+
__name(evidenceContent, "evidenceContent");
|
|
395
|
+
function evidencePreview(record, provenance) {
|
|
396
|
+
let preview = "";
|
|
397
|
+
const append = /* @__PURE__ */ __name((value) => {
|
|
398
|
+
if (!value || preview.length >= CATALOG_PREVIEW_LIMIT) return;
|
|
399
|
+
const separator = preview ? "\n" : "";
|
|
400
|
+
const remaining = CATALOG_PREVIEW_LIMIT - preview.length;
|
|
401
|
+
preview += `${separator}${value}`.slice(0, remaining);
|
|
402
|
+
}, "append");
|
|
403
|
+
for (const part of record.message?.parts ?? []) {
|
|
404
|
+
if (part.thought !== true && typeof part.text === "string") {
|
|
405
|
+
append(part.text);
|
|
406
|
+
}
|
|
407
|
+
if (provenance === "tool_result" && part.functionResponse) {
|
|
408
|
+
append(renderToolResponsePreview(part.functionResponse));
|
|
409
|
+
}
|
|
410
|
+
if (preview.length >= CATALOG_PREVIEW_LIMIT) break;
|
|
411
|
+
}
|
|
412
|
+
return preview.trim();
|
|
413
|
+
}
|
|
414
|
+
__name(evidencePreview, "evidencePreview");
|
|
415
|
+
function renderToolResponse(functionResponse) {
|
|
416
|
+
if (functionResponse.response === void 0) return "";
|
|
417
|
+
try {
|
|
418
|
+
return JSON.stringify({
|
|
419
|
+
...functionResponse.name === void 0 ? {} : { name: functionResponse.name },
|
|
420
|
+
response: functionResponse.response
|
|
421
|
+
});
|
|
422
|
+
} catch {
|
|
423
|
+
return "";
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
__name(renderToolResponse, "renderToolResponse");
|
|
427
|
+
function renderToolResponsePreview(functionResponse) {
|
|
428
|
+
if (functionResponse.response === void 0) return "";
|
|
429
|
+
try {
|
|
430
|
+
return JSON.stringify({
|
|
431
|
+
...functionResponse.name === void 0 ? {} : { name: functionResponse.name },
|
|
432
|
+
response: summarizeJsonValue(
|
|
433
|
+
functionResponse.response,
|
|
434
|
+
0,
|
|
435
|
+
/* @__PURE__ */ new WeakSet()
|
|
436
|
+
)
|
|
437
|
+
}).slice(0, CATALOG_PREVIEW_LIMIT);
|
|
438
|
+
} catch {
|
|
439
|
+
return "";
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
__name(renderToolResponsePreview, "renderToolResponsePreview");
|
|
443
|
+
function summarizeJsonValue(value, depth, seen) {
|
|
444
|
+
if (typeof value === "string") {
|
|
445
|
+
return value.slice(0, CATALOG_PREVIEW_LIMIT);
|
|
446
|
+
}
|
|
447
|
+
if (value === null || typeof value === "number" || typeof value === "boolean") {
|
|
448
|
+
return value;
|
|
449
|
+
}
|
|
450
|
+
if (typeof value !== "object") return String(value);
|
|
451
|
+
if (seen.has(value)) return "[Circular]";
|
|
452
|
+
if (depth >= 2) return "[Nested value]";
|
|
453
|
+
seen.add(value);
|
|
454
|
+
if (Array.isArray(value)) {
|
|
455
|
+
return value.slice(0, 6).map((entry) => summarizeJsonValue(entry, depth + 1, seen));
|
|
456
|
+
}
|
|
457
|
+
return Object.fromEntries(
|
|
458
|
+
Object.entries(value).slice(0, 6).map(([key, entry]) => [key, summarizeJsonValue(entry, depth + 1, seen)])
|
|
459
|
+
);
|
|
460
|
+
}
|
|
461
|
+
__name(summarizeJsonValue, "summarizeJsonValue");
|
|
462
|
+
function proofKindOf(provenance) {
|
|
463
|
+
if (provenance === "real_user") return "user_input";
|
|
464
|
+
if (provenance === "assistant_output") return "delivered_output";
|
|
465
|
+
return "external_fact";
|
|
466
|
+
}
|
|
467
|
+
__name(proofKindOf, "proofKindOf");
|
|
468
|
+
function parseGoalContext(value) {
|
|
469
|
+
if (!isRecord(value)) return void 0;
|
|
470
|
+
if (!hasOnlyKeys(value, ["goalId", "revision", "turnId"]) || !isNonEmptyString(value["goalId"]) || typeof value["revision"] !== "number" || !Number.isInteger(value["revision"]) || value["revision"] < 1 || !isNonEmptyString(value["turnId"])) {
|
|
471
|
+
return void 0;
|
|
472
|
+
}
|
|
473
|
+
return {
|
|
474
|
+
goalId: value["goalId"],
|
|
475
|
+
revision: value["revision"],
|
|
476
|
+
turnId: value["turnId"]
|
|
477
|
+
};
|
|
478
|
+
}
|
|
479
|
+
__name(parseGoalContext, "parseGoalContext");
|
|
480
|
+
function claimsGoalRevision(value, goal) {
|
|
481
|
+
if (!isRecord(value)) return false;
|
|
482
|
+
return value["goalId"] === goal.goalId && value["revision"] === goal.revision;
|
|
483
|
+
}
|
|
484
|
+
__name(claimsGoalRevision, "claimsGoalRevision");
|
|
485
|
+
function isRecord(value) {
|
|
486
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
487
|
+
}
|
|
488
|
+
__name(isRecord, "isRecord");
|
|
489
|
+
function hasOnlyKeys(value, keys) {
|
|
490
|
+
return Object.keys(value).every((key) => keys.includes(key));
|
|
491
|
+
}
|
|
492
|
+
__name(hasOnlyKeys, "hasOnlyKeys");
|
|
493
|
+
function isNonEmptyString(value) {
|
|
494
|
+
return typeof value === "string" && value.trim().length > 0;
|
|
495
|
+
}
|
|
496
|
+
__name(isNonEmptyString, "isNonEmptyString");
|
|
497
|
+
|
|
498
|
+
// packages/core/src/goals/goal-runtime.ts
|
|
499
|
+
init_esbuild_shims();
|
|
500
|
+
import { randomUUID } from "node:crypto";
|
|
501
|
+
|
|
502
|
+
// packages/core/src/goals/goal-reducer.ts
|
|
503
|
+
init_esbuild_shims();
|
|
504
|
+
var MAX_BLOCKED_AUDIT_COUNT = 3;
|
|
505
|
+
var GoalConflictError = class extends Error {
|
|
506
|
+
constructor(current) {
|
|
507
|
+
super("Goal version does not match the current session Goal");
|
|
508
|
+
this.current = current;
|
|
509
|
+
this.name = "GoalConflictError";
|
|
510
|
+
}
|
|
511
|
+
static {
|
|
512
|
+
__name(this, "GoalConflictError");
|
|
513
|
+
}
|
|
514
|
+
};
|
|
515
|
+
var GoalInvalidTransitionError = class extends Error {
|
|
516
|
+
constructor(message, current) {
|
|
517
|
+
super(message);
|
|
518
|
+
this.current = current;
|
|
519
|
+
this.name = "GoalInvalidTransitionError";
|
|
520
|
+
}
|
|
521
|
+
static {
|
|
522
|
+
__name(this, "GoalInvalidTransitionError");
|
|
523
|
+
}
|
|
524
|
+
};
|
|
525
|
+
function elapsedActiveTime(goal, now) {
|
|
526
|
+
return goal.activeTimeMs + (goal.status === "active" ? Math.max(0, now - goal.updatedAt) : 0);
|
|
527
|
+
}
|
|
528
|
+
__name(elapsedActiveTime, "elapsedActiveTime");
|
|
529
|
+
function reduceGoalControl(current, transition) {
|
|
530
|
+
const { request } = transition;
|
|
531
|
+
if (request.action === "create") {
|
|
532
|
+
if (current) throw new GoalConflictError(snapshotOf(current));
|
|
533
|
+
return createGoal(
|
|
534
|
+
transition.nextGoalId,
|
|
535
|
+
normalizeObjective(request.objective, snapshotOf(null)),
|
|
536
|
+
transition.now,
|
|
537
|
+
transition.cursor
|
|
538
|
+
);
|
|
539
|
+
}
|
|
540
|
+
assertExpectedVersion(
|
|
541
|
+
current,
|
|
542
|
+
request.expectedGoalId,
|
|
543
|
+
request.expectedRevision
|
|
544
|
+
);
|
|
545
|
+
if (request.action === "clear") return null;
|
|
546
|
+
if (request.action === "replace") {
|
|
547
|
+
return createGoal(
|
|
548
|
+
transition.nextGoalId,
|
|
549
|
+
normalizeObjective(request.objective, snapshotOf(current)),
|
|
550
|
+
transition.now,
|
|
551
|
+
transition.cursor
|
|
552
|
+
);
|
|
553
|
+
}
|
|
554
|
+
if (request.action === "edit") {
|
|
555
|
+
if (current.status === "complete") {
|
|
556
|
+
throw new GoalInvalidTransitionError(
|
|
557
|
+
"A completed Goal cannot be edited",
|
|
558
|
+
snapshotOf(current)
|
|
559
|
+
);
|
|
560
|
+
}
|
|
561
|
+
return transitionGoal(current, transition.now, {
|
|
562
|
+
revision: current.revision + 1,
|
|
563
|
+
objective: normalizeObjective(request.objective, snapshotOf(current)),
|
|
564
|
+
evidenceCursor: copyCursor(transition.cursor)
|
|
565
|
+
});
|
|
566
|
+
}
|
|
567
|
+
if (request.action === "pause") {
|
|
568
|
+
if (current.status !== "active") {
|
|
569
|
+
throw new GoalInvalidTransitionError(
|
|
570
|
+
"Only an active Goal can be paused",
|
|
571
|
+
snapshotOf(current)
|
|
572
|
+
);
|
|
573
|
+
}
|
|
574
|
+
return transitionGoal(current, transition.now, { status: "paused" });
|
|
575
|
+
}
|
|
576
|
+
if (current.status === "complete") {
|
|
577
|
+
throw new GoalInvalidTransitionError(
|
|
578
|
+
"A completed Goal cannot be resumed",
|
|
579
|
+
snapshotOf(current)
|
|
580
|
+
);
|
|
581
|
+
}
|
|
582
|
+
if (current.status === "active") {
|
|
583
|
+
throw new GoalInvalidTransitionError(
|
|
584
|
+
"An active Goal cannot be resumed",
|
|
585
|
+
snapshotOf(current)
|
|
586
|
+
);
|
|
587
|
+
}
|
|
588
|
+
if (request.action !== "resume") {
|
|
589
|
+
return assertNever(request, snapshotOf(current));
|
|
590
|
+
}
|
|
591
|
+
return transitionGoal(current, transition.now, { status: "active" });
|
|
592
|
+
}
|
|
593
|
+
__name(reduceGoalControl, "reduceGoalControl");
|
|
594
|
+
function reduceGoalTurnFinished(current, transition) {
|
|
595
|
+
if (current.status !== "active" && current.status !== "paused") {
|
|
596
|
+
throw new GoalInvalidTransitionError(
|
|
597
|
+
"Only an active or paused Goal can finish a turn",
|
|
598
|
+
snapshotOf(current)
|
|
599
|
+
);
|
|
600
|
+
}
|
|
601
|
+
return transitionGoal(current, transition.now, {
|
|
602
|
+
turnCount: current.turnCount + 1,
|
|
603
|
+
...transition.lastReason === void 0 ? {} : { lastReason: transition.lastReason }
|
|
604
|
+
});
|
|
605
|
+
}
|
|
606
|
+
__name(reduceGoalTurnFinished, "reduceGoalTurnFinished");
|
|
607
|
+
function parseGoalStateRecordPayloadV2(value) {
|
|
608
|
+
if (!isRecord2(value) || !hasOnlyKeys2(value, ["v", "cause", "snapshot", "blockedAudit"]) || value["v"] !== GOAL_STATE_VERSION || !isGoalStateCause(value["cause"]) || !isBlockedAudit(value["blockedAudit"])) {
|
|
609
|
+
return void 0;
|
|
610
|
+
}
|
|
611
|
+
const parsedSnapshot = parseGoalSnapshotV2(value["snapshot"]);
|
|
612
|
+
return parsedSnapshot?.activity === "idle" ? {
|
|
613
|
+
v: GOAL_STATE_VERSION,
|
|
614
|
+
cause: value["cause"],
|
|
615
|
+
snapshot: parsedSnapshot,
|
|
616
|
+
...value["blockedAudit"] ? { blockedAudit: structuredClone(value["blockedAudit"]) } : {}
|
|
617
|
+
} : void 0;
|
|
618
|
+
}
|
|
619
|
+
__name(parseGoalStateRecordPayloadV2, "parseGoalStateRecordPayloadV2");
|
|
620
|
+
function parseGoalSnapshotV2(value) {
|
|
621
|
+
if (!isRecord2(value) || !hasOnlyKeys2(value, ["v", "goal", "activity"]) || value["v"] !== GOAL_STATE_VERSION || !isGoalActivity(value["activity"])) {
|
|
622
|
+
return void 0;
|
|
623
|
+
}
|
|
624
|
+
if (value["goal"] === null) {
|
|
625
|
+
return {
|
|
626
|
+
v: GOAL_STATE_VERSION,
|
|
627
|
+
goal: null,
|
|
628
|
+
activity: value["activity"]
|
|
629
|
+
};
|
|
630
|
+
}
|
|
631
|
+
const goal = parseGoalRecord(value["goal"]);
|
|
632
|
+
return goal ? { v: GOAL_STATE_VERSION, goal, activity: value["activity"] } : void 0;
|
|
633
|
+
}
|
|
634
|
+
__name(parseGoalSnapshotV2, "parseGoalSnapshotV2");
|
|
635
|
+
function createGoal(goalId, objective, now, cursor) {
|
|
636
|
+
return {
|
|
637
|
+
goalId,
|
|
638
|
+
revision: 1,
|
|
639
|
+
objective,
|
|
640
|
+
status: "active",
|
|
641
|
+
evidenceCursor: copyCursor(cursor),
|
|
642
|
+
turnCount: 0,
|
|
643
|
+
activeTimeMs: 0,
|
|
644
|
+
createdAt: now,
|
|
645
|
+
updatedAt: now
|
|
646
|
+
};
|
|
647
|
+
}
|
|
648
|
+
__name(createGoal, "createGoal");
|
|
649
|
+
function assertExpectedVersion(current, expectedGoalId, expectedRevision) {
|
|
650
|
+
if (!current || current.goalId !== expectedGoalId || current.revision !== expectedRevision) {
|
|
651
|
+
throw new GoalConflictError(snapshotOf(current));
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
__name(assertExpectedVersion, "assertExpectedVersion");
|
|
655
|
+
function normalizeObjective(objective, current) {
|
|
656
|
+
const normalized = objective.trim();
|
|
657
|
+
if (!normalized) {
|
|
658
|
+
throw new GoalInvalidTransitionError(
|
|
659
|
+
"Goal objective must not be empty",
|
|
660
|
+
current
|
|
661
|
+
);
|
|
662
|
+
}
|
|
663
|
+
return normalized;
|
|
664
|
+
}
|
|
665
|
+
__name(normalizeObjective, "normalizeObjective");
|
|
666
|
+
function transitionGoal(goal, now, changes) {
|
|
667
|
+
return {
|
|
668
|
+
...goal,
|
|
669
|
+
...changes,
|
|
670
|
+
activeTimeMs: elapsedActiveTime(goal, now),
|
|
671
|
+
updatedAt: now
|
|
672
|
+
};
|
|
673
|
+
}
|
|
674
|
+
__name(transitionGoal, "transitionGoal");
|
|
675
|
+
function snapshotOf(goal) {
|
|
676
|
+
return { v: GOAL_STATE_VERSION, goal, activity: "idle" };
|
|
677
|
+
}
|
|
678
|
+
__name(snapshotOf, "snapshotOf");
|
|
679
|
+
function copyCursor(cursor) {
|
|
680
|
+
return { recordId: cursor.recordId };
|
|
681
|
+
}
|
|
682
|
+
__name(copyCursor, "copyCursor");
|
|
683
|
+
function parseGoalRecord(value) {
|
|
684
|
+
if (!isRecord2(value) || !hasOnlyKeys2(value, [
|
|
685
|
+
"goalId",
|
|
686
|
+
"revision",
|
|
687
|
+
"objective",
|
|
688
|
+
"status",
|
|
689
|
+
"evidenceCursor",
|
|
690
|
+
"turnCount",
|
|
691
|
+
"activeTimeMs",
|
|
692
|
+
"createdAt",
|
|
693
|
+
"updatedAt",
|
|
694
|
+
"lastReason"
|
|
695
|
+
]) || typeof value["goalId"] !== "string" || !value["goalId"] || !isNonNegativeInteger(value["revision"]) || value["revision"] === 0 || typeof value["objective"] !== "string" || !value["objective"].trim() || !isGoalStatus(value["status"]) || !isTranscriptCursor(value["evidenceCursor"]) || !isNonNegativeInteger(value["turnCount"]) || !isNonNegativeNumber(value["activeTimeMs"]) || !isFiniteNumber(value["createdAt"]) || !isFiniteNumber(value["updatedAt"]) || value["lastReason"] !== void 0 && typeof value["lastReason"] !== "string") {
|
|
696
|
+
return void 0;
|
|
697
|
+
}
|
|
698
|
+
return {
|
|
699
|
+
goalId: value["goalId"],
|
|
700
|
+
revision: value["revision"],
|
|
701
|
+
objective: value["objective"],
|
|
702
|
+
status: value["status"],
|
|
703
|
+
evidenceCursor: copyCursor(value["evidenceCursor"]),
|
|
704
|
+
turnCount: value["turnCount"],
|
|
705
|
+
activeTimeMs: value["activeTimeMs"],
|
|
706
|
+
createdAt: value["createdAt"],
|
|
707
|
+
updatedAt: value["updatedAt"],
|
|
708
|
+
...value["lastReason"] === void 0 ? {} : { lastReason: value["lastReason"] }
|
|
709
|
+
};
|
|
710
|
+
}
|
|
711
|
+
__name(parseGoalRecord, "parseGoalRecord");
|
|
712
|
+
function isTranscriptCursor(value) {
|
|
713
|
+
return isRecord2(value) && hasOnlyKeys2(value, ["recordId"]) && (typeof value["recordId"] === "string" || value["recordId"] === null);
|
|
714
|
+
}
|
|
715
|
+
__name(isTranscriptCursor, "isTranscriptCursor");
|
|
716
|
+
function isGoalStatus(value) {
|
|
717
|
+
return value === "active" || value === "paused" || value === "blocked" || value === "usage_limited" || value === "complete";
|
|
718
|
+
}
|
|
719
|
+
__name(isGoalStatus, "isGoalStatus");
|
|
720
|
+
function isGoalActivity(value) {
|
|
721
|
+
return value === "idle" || value === "running" || value === "verifying";
|
|
722
|
+
}
|
|
723
|
+
__name(isGoalActivity, "isGoalActivity");
|
|
724
|
+
function isGoalStateCause(value) {
|
|
725
|
+
return value === "create" || value === "replace" || value === "edit" || value === "pause" || value === "resume" || value === "turn_finished" || value === "verifier_accept" || value === "verifier_reject" || value === "complete" || value === "blocked" || value === "usage_limited" || value === "clear" || value === "migrated";
|
|
726
|
+
}
|
|
727
|
+
__name(isGoalStateCause, "isGoalStateCause");
|
|
728
|
+
function isBlockedAudit(value) {
|
|
729
|
+
return value === void 0 || isRecord2(value) && hasOnlyKeys2(value, ["fingerprint", "count", "turnIds"]) && typeof value["fingerprint"] === "string" && value["fingerprint"].length > 0 && isNonNegativeInteger(value["count"]) && value["count"] > 0 && value["count"] <= MAX_BLOCKED_AUDIT_COUNT && Array.isArray(value["turnIds"]) && value["turnIds"].length === value["count"] && value["turnIds"].every(
|
|
730
|
+
(turnId) => typeof turnId === "string" && turnId.length > 0
|
|
731
|
+
);
|
|
732
|
+
}
|
|
733
|
+
__name(isBlockedAudit, "isBlockedAudit");
|
|
734
|
+
function isRecord2(value) {
|
|
735
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
736
|
+
}
|
|
737
|
+
__name(isRecord2, "isRecord");
|
|
738
|
+
function hasOnlyKeys2(value, keys) {
|
|
739
|
+
return Object.keys(value).every((key) => keys.includes(key));
|
|
740
|
+
}
|
|
741
|
+
__name(hasOnlyKeys2, "hasOnlyKeys");
|
|
742
|
+
function isNonNegativeInteger(value) {
|
|
743
|
+
return typeof value === "number" && Number.isInteger(value) && value >= 0;
|
|
744
|
+
}
|
|
745
|
+
__name(isNonNegativeInteger, "isNonNegativeInteger");
|
|
746
|
+
function isNonNegativeNumber(value) {
|
|
747
|
+
return typeof value === "number" && Number.isFinite(value) && value >= 0;
|
|
748
|
+
}
|
|
749
|
+
__name(isNonNegativeNumber, "isNonNegativeNumber");
|
|
750
|
+
function isFiniteNumber(value) {
|
|
751
|
+
return typeof value === "number" && Number.isFinite(value);
|
|
752
|
+
}
|
|
753
|
+
__name(isFiniteNumber, "isFiniteNumber");
|
|
754
|
+
function assertNever(value, snapshot) {
|
|
755
|
+
throw new GoalInvalidTransitionError(
|
|
756
|
+
`Unsupported Goal control action: ${String(value)}`,
|
|
757
|
+
snapshot
|
|
758
|
+
);
|
|
759
|
+
}
|
|
760
|
+
__name(assertNever, "assertNever");
|
|
761
|
+
|
|
762
|
+
// packages/core/src/goals/goal-persistence.ts
|
|
763
|
+
init_esbuild_shims();
|
|
764
|
+
var LEGACY_ACTIVE_KINDS = /* @__PURE__ */ new Set(["set", "checking"]);
|
|
765
|
+
var LEGACY_STOPPED_KINDS = /* @__PURE__ */ new Set([
|
|
766
|
+
"achieved",
|
|
767
|
+
"cleared",
|
|
768
|
+
"failed",
|
|
769
|
+
"aborted",
|
|
770
|
+
"paused"
|
|
771
|
+
]);
|
|
772
|
+
function recoverGoalFromRecords(records) {
|
|
773
|
+
let unsupported;
|
|
774
|
+
for (let index = records.length - 1; index >= 0; index -= 1) {
|
|
775
|
+
const record = records[index];
|
|
776
|
+
if (record?.subtype !== "goal_state") continue;
|
|
777
|
+
const payload = record.type === "system" ? parseGoalStateRecordPayloadV2(record.systemPayload) : void 0;
|
|
778
|
+
if (payload) return { kind: "v2", payload };
|
|
779
|
+
unsupported ??= {
|
|
780
|
+
kind: "unsupported",
|
|
781
|
+
reason: `Goal lifecycle record ${record.uuid} is malformed or uses an unsupported version`
|
|
782
|
+
};
|
|
783
|
+
}
|
|
784
|
+
return unsupported ?? recoverLegacyGoal(records);
|
|
785
|
+
}
|
|
786
|
+
__name(recoverGoalFromRecords, "recoverGoalFromRecords");
|
|
787
|
+
function recoverLegacyGoal(records) {
|
|
788
|
+
for (let recordIndex = records.length - 1; recordIndex >= 0; recordIndex -= 1) {
|
|
789
|
+
const record = records[recordIndex];
|
|
790
|
+
if (record?.type !== "system" || record.subtype !== "slash_command") {
|
|
791
|
+
continue;
|
|
792
|
+
}
|
|
793
|
+
const payload = record.systemPayload;
|
|
794
|
+
if (payload?.phase !== "result" || !Array.isArray(payload.outputHistoryItems)) {
|
|
795
|
+
continue;
|
|
796
|
+
}
|
|
797
|
+
for (let itemIndex = payload.outputHistoryItems.length - 1; itemIndex >= 0; itemIndex -= 1) {
|
|
798
|
+
const value = payload.outputHistoryItems[itemIndex];
|
|
799
|
+
if (!isObjectRecord(value) || value["type"] !== "goal_status") continue;
|
|
800
|
+
const kind = value["kind"];
|
|
801
|
+
const condition = value["condition"];
|
|
802
|
+
if (typeof kind !== "string" || typeof condition !== "string") {
|
|
803
|
+
return unsupportedLegacy(record.uuid);
|
|
804
|
+
}
|
|
805
|
+
if (LEGACY_STOPPED_KINDS.has(kind)) return { kind: "none" };
|
|
806
|
+
if (!LEGACY_ACTIVE_KINDS.has(kind) || condition.trim().length === 0) {
|
|
807
|
+
return unsupportedLegacy(record.uuid);
|
|
808
|
+
}
|
|
809
|
+
return { kind: "legacy", objective: condition.trim() };
|
|
810
|
+
}
|
|
811
|
+
}
|
|
812
|
+
return { kind: "none" };
|
|
813
|
+
}
|
|
814
|
+
__name(recoverLegacyGoal, "recoverLegacyGoal");
|
|
815
|
+
function unsupportedLegacy(recordUuid) {
|
|
816
|
+
return {
|
|
817
|
+
kind: "unsupported",
|
|
818
|
+
reason: `Legacy Goal record ${recordUuid} cannot be recovered safely`
|
|
819
|
+
};
|
|
820
|
+
}
|
|
821
|
+
__name(unsupportedLegacy, "unsupportedLegacy");
|
|
822
|
+
function isObjectRecord(value) {
|
|
823
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
824
|
+
}
|
|
825
|
+
__name(isObjectRecord, "isObjectRecord");
|
|
826
|
+
function createMigratedGoalState(input) {
|
|
827
|
+
const objective = input.objective.trim();
|
|
828
|
+
if (!objective) {
|
|
829
|
+
throw new Error("Migrated Goal objective must not be empty");
|
|
830
|
+
}
|
|
831
|
+
return {
|
|
832
|
+
v: GOAL_STATE_VERSION,
|
|
833
|
+
cause: "migrated",
|
|
834
|
+
snapshot: {
|
|
835
|
+
v: GOAL_STATE_VERSION,
|
|
836
|
+
activity: "idle",
|
|
837
|
+
goal: {
|
|
838
|
+
goalId: input.goalId,
|
|
839
|
+
revision: 1,
|
|
840
|
+
objective,
|
|
841
|
+
status: "paused",
|
|
842
|
+
evidenceCursor: { recordId: input.recordUuid },
|
|
843
|
+
turnCount: 0,
|
|
844
|
+
activeTimeMs: 0,
|
|
845
|
+
createdAt: input.now,
|
|
846
|
+
updatedAt: input.now
|
|
847
|
+
}
|
|
848
|
+
}
|
|
849
|
+
};
|
|
850
|
+
}
|
|
851
|
+
__name(createMigratedGoalState, "createMigratedGoalState");
|
|
852
|
+
|
|
853
|
+
// packages/core/src/goals/goal-runtime.ts
|
|
854
|
+
var GOAL_RUNTIME_DISPOSED_MESSAGE = "Goal runtime has been disposed";
|
|
855
|
+
var STALE_GOAL_TURN_MESSAGE = "Goal turn permit is no longer valid";
|
|
856
|
+
var GoalPersistenceUnavailableError = class extends Error {
|
|
857
|
+
static {
|
|
858
|
+
__name(this, "GoalPersistenceUnavailableError");
|
|
859
|
+
}
|
|
860
|
+
constructor(message = "Goal persistence is unavailable for this session", options) {
|
|
861
|
+
super(message, options);
|
|
862
|
+
this.name = "GoalPersistenceUnavailableError";
|
|
863
|
+
}
|
|
864
|
+
};
|
|
865
|
+
function normalizeRecoveredBlockedAudit(audit) {
|
|
866
|
+
return {
|
|
867
|
+
...structuredClone(audit),
|
|
868
|
+
fingerprint: audit.fingerprint.startsWith("\n") ? `repeated${audit.fingerprint}` : audit.fingerprint
|
|
869
|
+
};
|
|
870
|
+
}
|
|
871
|
+
__name(normalizeRecoveredBlockedAudit, "normalizeRecoveredBlockedAudit");
|
|
872
|
+
function createGoalRuntime(options) {
|
|
873
|
+
if (Boolean(options.evidenceSource) !== Boolean(options.verifier)) {
|
|
874
|
+
throw new Error(
|
|
875
|
+
"Goal evidence source and verifier must be configured together"
|
|
876
|
+
);
|
|
877
|
+
}
|
|
878
|
+
let snapshot = {
|
|
879
|
+
v: GOAL_STATE_VERSION,
|
|
880
|
+
goal: null,
|
|
881
|
+
activity: "idle"
|
|
882
|
+
};
|
|
883
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
884
|
+
let dispatchTail = Promise.resolve();
|
|
885
|
+
let host;
|
|
886
|
+
let currentPermit;
|
|
887
|
+
let currentPermitHost;
|
|
888
|
+
let currentTurnKey;
|
|
889
|
+
let queuedTurnKey;
|
|
890
|
+
let continuationQueued = false;
|
|
891
|
+
let currentProposal;
|
|
892
|
+
let pendingProposal;
|
|
893
|
+
let verificationAttempt;
|
|
894
|
+
let blockedAudit;
|
|
895
|
+
let nextVerifierFeedback;
|
|
896
|
+
let currentTurnFeedback;
|
|
897
|
+
let restored = false;
|
|
898
|
+
let disposed = false;
|
|
899
|
+
let recoveryError;
|
|
900
|
+
const assertAvailable = /* @__PURE__ */ __name(() => {
|
|
901
|
+
if (disposed) throw new Error(GOAL_RUNTIME_DISPOSED_MESSAGE);
|
|
902
|
+
}, "assertAvailable");
|
|
903
|
+
const assertOperational = /* @__PURE__ */ __name(() => {
|
|
904
|
+
assertAvailable();
|
|
905
|
+
if (recoveryError) throw recoveryError;
|
|
906
|
+
}, "assertOperational");
|
|
907
|
+
const getSnapshot = /* @__PURE__ */ __name(() => structuredClone(snapshot), "getSnapshot");
|
|
908
|
+
const broadcast = /* @__PURE__ */ __name((cause) => {
|
|
909
|
+
for (const listener of listeners) {
|
|
910
|
+
try {
|
|
911
|
+
listener(getSnapshot(), cause);
|
|
912
|
+
} catch {
|
|
913
|
+
}
|
|
914
|
+
}
|
|
915
|
+
}, "broadcast");
|
|
916
|
+
const preemptHost = /* @__PURE__ */ __name((reason, target = host) => {
|
|
917
|
+
try {
|
|
918
|
+
target?.preemptGoalTurn(reason);
|
|
919
|
+
} catch {
|
|
920
|
+
}
|
|
921
|
+
}, "preemptHost");
|
|
922
|
+
const flushContinuation = /* @__PURE__ */ __name((cause) => {
|
|
923
|
+
if (!continuationQueued || !host || currentPermit || pendingProposal || verificationAttempt || snapshot.activity !== "idle" || snapshot.goal?.status !== "active") {
|
|
924
|
+
return;
|
|
925
|
+
}
|
|
926
|
+
continuationQueued = false;
|
|
927
|
+
const scheduledHost = host;
|
|
928
|
+
const continuationContext = snapshot.goal.objective;
|
|
929
|
+
const verifierFeedback = nextVerifierFeedback;
|
|
930
|
+
nextVerifierFeedback = void 0;
|
|
931
|
+
currentTurnFeedback = verifierFeedback;
|
|
932
|
+
currentPermit = {
|
|
933
|
+
goalId: snapshot.goal.goalId,
|
|
934
|
+
revision: snapshot.goal.revision,
|
|
935
|
+
turnId: randomUUID()
|
|
936
|
+
};
|
|
937
|
+
currentPermitHost = scheduledHost;
|
|
938
|
+
currentTurnKey = `goal-runtime:${currentPermit.turnId}`;
|
|
939
|
+
const startedPermit = structuredClone(currentPermit);
|
|
940
|
+
snapshot = { ...snapshot, activity: "running" };
|
|
941
|
+
broadcast(cause);
|
|
942
|
+
const handleStartFailure = /* @__PURE__ */ __name(() => {
|
|
943
|
+
void enqueue(async () => {
|
|
944
|
+
if (isCurrentPermit(startedPermit)) {
|
|
945
|
+
const nextTurnKey = queuedTurnKey;
|
|
946
|
+
currentPermit = void 0;
|
|
947
|
+
currentPermitHost = void 0;
|
|
948
|
+
currentTurnKey = void 0;
|
|
949
|
+
currentProposal = void 0;
|
|
950
|
+
if (currentTurnFeedback !== void 0) {
|
|
951
|
+
nextVerifierFeedback ??= currentTurnFeedback;
|
|
952
|
+
}
|
|
953
|
+
currentTurnFeedback = void 0;
|
|
954
|
+
if (host === scheduledHost) host = void 0;
|
|
955
|
+
if (nextTurnKey && snapshot.goal?.status === "active") {
|
|
956
|
+
currentPermit = {
|
|
957
|
+
goalId: snapshot.goal.goalId,
|
|
958
|
+
revision: snapshot.goal.revision,
|
|
959
|
+
turnId: randomUUID()
|
|
960
|
+
};
|
|
961
|
+
currentPermitHost = host;
|
|
962
|
+
currentTurnKey = nextTurnKey;
|
|
963
|
+
currentTurnFeedback = nextVerifierFeedback;
|
|
964
|
+
nextVerifierFeedback = void 0;
|
|
965
|
+
queuedTurnKey = void 0;
|
|
966
|
+
continuationQueued = false;
|
|
967
|
+
snapshot = { ...snapshot, activity: "running" };
|
|
968
|
+
} else {
|
|
969
|
+
snapshot = { ...snapshot, activity: "idle" };
|
|
970
|
+
}
|
|
971
|
+
broadcast();
|
|
972
|
+
if (!currentPermit) queueContinuation();
|
|
973
|
+
}
|
|
974
|
+
}).catch(() => void 0);
|
|
975
|
+
}, "handleStartFailure");
|
|
976
|
+
let started;
|
|
977
|
+
try {
|
|
978
|
+
started = scheduledHost.startGoalTurn({
|
|
979
|
+
permit: startedPermit,
|
|
980
|
+
continuationContext,
|
|
981
|
+
...verifierFeedback ? { verifierFeedback } : {}
|
|
982
|
+
});
|
|
983
|
+
} catch {
|
|
984
|
+
handleStartFailure();
|
|
985
|
+
return;
|
|
986
|
+
}
|
|
987
|
+
void started.catch(handleStartFailure);
|
|
988
|
+
}, "flushContinuation");
|
|
989
|
+
const queueContinuation = /* @__PURE__ */ __name((cause) => {
|
|
990
|
+
if (snapshot.goal?.status !== "active" || currentPermit || pendingProposal || verificationAttempt) {
|
|
991
|
+
return;
|
|
992
|
+
}
|
|
993
|
+
continuationQueued = true;
|
|
994
|
+
flushContinuation(cause);
|
|
995
|
+
}, "queueContinuation");
|
|
996
|
+
const enqueue = /* @__PURE__ */ __name((operation) => {
|
|
997
|
+
const result = dispatchTail.then(operation, operation);
|
|
998
|
+
dispatchTail = result.then(
|
|
999
|
+
() => void 0,
|
|
1000
|
+
() => void 0
|
|
1001
|
+
);
|
|
1002
|
+
return result;
|
|
1003
|
+
}, "enqueue");
|
|
1004
|
+
const isCurrentPermit = /* @__PURE__ */ __name((permit) => snapshot.goal?.goalId === permit.goalId && snapshot.goal.revision === permit.revision && currentPermit?.goalId === permit.goalId && currentPermit.revision === permit.revision && currentPermit.turnId === permit.turnId, "isCurrentPermit");
|
|
1005
|
+
const getSnapshotForPermit = /* @__PURE__ */ __name((permit) => {
|
|
1006
|
+
assertOperational();
|
|
1007
|
+
if (!isCurrentPermit(permit) || !snapshot.goal) {
|
|
1008
|
+
throw new Error(STALE_GOAL_TURN_MESSAGE);
|
|
1009
|
+
}
|
|
1010
|
+
return getSnapshot();
|
|
1011
|
+
}, "getSnapshotForPermit");
|
|
1012
|
+
const isCurrentVerificationAttempt = /* @__PURE__ */ __name((attempt) => verificationAttempt === attempt && snapshot.goal?.goalId === attempt.permit.goalId && snapshot.goal.revision === attempt.permit.revision && snapshot.goal.status === "active" && snapshot.activity === "verifying", "isCurrentVerificationAttempt");
|
|
1013
|
+
const invalidateVerification = /* @__PURE__ */ __name((reason) => {
|
|
1014
|
+
const attempt = verificationAttempt;
|
|
1015
|
+
verificationAttempt = void 0;
|
|
1016
|
+
pendingProposal = void 0;
|
|
1017
|
+
if (attempt && !attempt.controller.signal.aborted) {
|
|
1018
|
+
attempt.controller.abort(new Error(reason));
|
|
1019
|
+
}
|
|
1020
|
+
}, "invalidateVerification");
|
|
1021
|
+
const verifierInput = /* @__PURE__ */ __name((attempt, evidence) => {
|
|
1022
|
+
const currentDeliveredOutput = evidence.citedRecords.filter(
|
|
1023
|
+
(record) => record.proofKind === "delivered_output" && record.turnId === attempt.permit.turnId
|
|
1024
|
+
).map((record) => record.content);
|
|
1025
|
+
const base = {
|
|
1026
|
+
goal: {
|
|
1027
|
+
goalId: attempt.goal.goalId,
|
|
1028
|
+
revision: attempt.goal.revision,
|
|
1029
|
+
objective: attempt.goal.objective
|
|
1030
|
+
},
|
|
1031
|
+
currentTurnId: attempt.permit.turnId,
|
|
1032
|
+
evidence: evidence.citedRecords,
|
|
1033
|
+
...currentDeliveredOutput.length > 0 ? { currentDeliveredOutput } : {}
|
|
1034
|
+
};
|
|
1035
|
+
if (attempt.proposal.status === "complete") {
|
|
1036
|
+
return {
|
|
1037
|
+
...base,
|
|
1038
|
+
proposal: { ...attempt.proposal, status: "complete" }
|
|
1039
|
+
};
|
|
1040
|
+
}
|
|
1041
|
+
return {
|
|
1042
|
+
...base,
|
|
1043
|
+
proposal: { ...attempt.proposal, status: "blocked" },
|
|
1044
|
+
blockedPolicy: "A blocked Goal is resumable. It may be accepted immediately only when the evidence shows that new user authority or a material user choice is required, or that an external state change is required, and no meaningful in-scope work remains. An ordinary technical blocker requires evidence of the same cause from the current and two immediately preceding Goal turns. Difficulty, uncertainty, incomplete work, or a preference for clarification do not by themselves justify blocked."
|
|
1045
|
+
};
|
|
1046
|
+
}, "verifierInput");
|
|
1047
|
+
const promoteQueuedUserTurn = /* @__PURE__ */ __name(() => {
|
|
1048
|
+
const nextTurnKey = queuedTurnKey;
|
|
1049
|
+
if (!nextTurnKey || currentPermit || snapshot.goal?.status !== "active") {
|
|
1050
|
+
return false;
|
|
1051
|
+
}
|
|
1052
|
+
queuedTurnKey = void 0;
|
|
1053
|
+
continuationQueued = false;
|
|
1054
|
+
currentPermit = {
|
|
1055
|
+
goalId: snapshot.goal.goalId,
|
|
1056
|
+
revision: snapshot.goal.revision,
|
|
1057
|
+
turnId: randomUUID()
|
|
1058
|
+
};
|
|
1059
|
+
currentPermitHost = host;
|
|
1060
|
+
currentTurnKey = nextTurnKey;
|
|
1061
|
+
currentTurnFeedback = nextVerifierFeedback;
|
|
1062
|
+
nextVerifierFeedback = void 0;
|
|
1063
|
+
snapshot = { ...snapshot, activity: "running" };
|
|
1064
|
+
return true;
|
|
1065
|
+
}, "promoteQueuedUserTurn");
|
|
1066
|
+
const admitAfterRejection = /* @__PURE__ */ __name(() => {
|
|
1067
|
+
continuationQueued = false;
|
|
1068
|
+
if (promoteQueuedUserTurn()) return false;
|
|
1069
|
+
const activityBefore = snapshot.activity;
|
|
1070
|
+
queueContinuation("verifier_reject");
|
|
1071
|
+
return activityBefore !== snapshot.activity;
|
|
1072
|
+
}, "admitAfterRejection");
|
|
1073
|
+
const recordVerificationOutcome = /* @__PURE__ */ __name(async (attempt, outcome) => {
|
|
1074
|
+
await enqueue(async () => {
|
|
1075
|
+
if (!isCurrentVerificationAttempt(attempt) || !snapshot.goal) return;
|
|
1076
|
+
const now = Date.now();
|
|
1077
|
+
if (outcome.kind === "decision" && outcome.result.decision === "accept") {
|
|
1078
|
+
const acceptedGoal = {
|
|
1079
|
+
...snapshot.goal,
|
|
1080
|
+
activeTimeMs: elapsedActiveTime(snapshot.goal, now),
|
|
1081
|
+
updatedAt: now,
|
|
1082
|
+
lastReason: outcome.result.reason
|
|
1083
|
+
};
|
|
1084
|
+
const acceptedSnapshot = {
|
|
1085
|
+
v: GOAL_STATE_VERSION,
|
|
1086
|
+
goal: acceptedGoal,
|
|
1087
|
+
activity: "idle"
|
|
1088
|
+
};
|
|
1089
|
+
const terminalSnapshot = {
|
|
1090
|
+
v: GOAL_STATE_VERSION,
|
|
1091
|
+
goal: {
|
|
1092
|
+
...acceptedGoal,
|
|
1093
|
+
status: attempt.proposal.status
|
|
1094
|
+
},
|
|
1095
|
+
activity: "idle"
|
|
1096
|
+
};
|
|
1097
|
+
await options.journal.recordGoalState(randomUUID(), {
|
|
1098
|
+
v: GOAL_STATE_VERSION,
|
|
1099
|
+
cause: "verifier_accept",
|
|
1100
|
+
snapshot: acceptedSnapshot
|
|
1101
|
+
});
|
|
1102
|
+
if (!isCurrentVerificationAttempt(attempt) || !snapshot.goal) return;
|
|
1103
|
+
await options.journal.recordGoalState(randomUUID(), {
|
|
1104
|
+
v: GOAL_STATE_VERSION,
|
|
1105
|
+
cause: attempt.proposal.status,
|
|
1106
|
+
snapshot: terminalSnapshot
|
|
1107
|
+
});
|
|
1108
|
+
if (!isCurrentVerificationAttempt(attempt) || !snapshot.goal) return;
|
|
1109
|
+
verificationAttempt = void 0;
|
|
1110
|
+
pendingProposal = void 0;
|
|
1111
|
+
if (attempt.proposal.status === "complete") queuedTurnKey = void 0;
|
|
1112
|
+
continuationQueued = false;
|
|
1113
|
+
nextVerifierFeedback = void 0;
|
|
1114
|
+
currentTurnFeedback = void 0;
|
|
1115
|
+
snapshot = structuredClone(terminalSnapshot);
|
|
1116
|
+
broadcast(attempt.proposal.status);
|
|
1117
|
+
return;
|
|
1118
|
+
}
|
|
1119
|
+
if (outcome.kind === "usage_limited") {
|
|
1120
|
+
const limitedSnapshot = {
|
|
1121
|
+
v: GOAL_STATE_VERSION,
|
|
1122
|
+
goal: {
|
|
1123
|
+
...snapshot.goal,
|
|
1124
|
+
status: "usage_limited",
|
|
1125
|
+
activeTimeMs: elapsedActiveTime(snapshot.goal, now),
|
|
1126
|
+
updatedAt: now,
|
|
1127
|
+
lastReason: outcome.reason
|
|
1128
|
+
},
|
|
1129
|
+
activity: "idle"
|
|
1130
|
+
};
|
|
1131
|
+
await options.journal.recordGoalState(randomUUID(), {
|
|
1132
|
+
v: GOAL_STATE_VERSION,
|
|
1133
|
+
cause: "usage_limited",
|
|
1134
|
+
snapshot: limitedSnapshot
|
|
1135
|
+
});
|
|
1136
|
+
if (!isCurrentVerificationAttempt(attempt) || !snapshot.goal) return;
|
|
1137
|
+
verificationAttempt = void 0;
|
|
1138
|
+
pendingProposal = void 0;
|
|
1139
|
+
continuationQueued = false;
|
|
1140
|
+
nextVerifierFeedback = void 0;
|
|
1141
|
+
currentTurnFeedback = void 0;
|
|
1142
|
+
snapshot = structuredClone(limitedSnapshot);
|
|
1143
|
+
broadcast("usage_limited");
|
|
1144
|
+
return;
|
|
1145
|
+
}
|
|
1146
|
+
const rejectedSnapshot = {
|
|
1147
|
+
v: GOAL_STATE_VERSION,
|
|
1148
|
+
goal: {
|
|
1149
|
+
...snapshot.goal,
|
|
1150
|
+
activeTimeMs: elapsedActiveTime(snapshot.goal, now),
|
|
1151
|
+
updatedAt: now,
|
|
1152
|
+
lastReason: outcome.result.reason
|
|
1153
|
+
},
|
|
1154
|
+
activity: "idle"
|
|
1155
|
+
};
|
|
1156
|
+
await options.journal.recordGoalState(randomUUID(), {
|
|
1157
|
+
v: GOAL_STATE_VERSION,
|
|
1158
|
+
cause: "verifier_reject",
|
|
1159
|
+
snapshot: rejectedSnapshot,
|
|
1160
|
+
...blockedAudit ? { blockedAudit: structuredClone(blockedAudit) } : {}
|
|
1161
|
+
});
|
|
1162
|
+
if (!isCurrentVerificationAttempt(attempt) || !snapshot.goal) return;
|
|
1163
|
+
verificationAttempt = void 0;
|
|
1164
|
+
pendingProposal = void 0;
|
|
1165
|
+
snapshot = structuredClone(rejectedSnapshot);
|
|
1166
|
+
nextVerifierFeedback = outcome.result.reason;
|
|
1167
|
+
const continuationBroadcast = admitAfterRejection();
|
|
1168
|
+
if (!continuationBroadcast) broadcast("verifier_reject");
|
|
1169
|
+
});
|
|
1170
|
+
}, "recordVerificationOutcome");
|
|
1171
|
+
const runVerification = /* @__PURE__ */ __name(async (attempt) => {
|
|
1172
|
+
const evidenceSource = options.evidenceSource;
|
|
1173
|
+
const verifier = options.verifier;
|
|
1174
|
+
if (!evidenceSource || !verifier) return;
|
|
1175
|
+
let outcome;
|
|
1176
|
+
try {
|
|
1177
|
+
await evidenceSource.flush();
|
|
1178
|
+
if (attempt.controller.signal.aborted) return;
|
|
1179
|
+
const records = await evidenceSource.readActiveTranscriptChain();
|
|
1180
|
+
if (attempt.controller.signal.aborted) return;
|
|
1181
|
+
const evidence = validateGoalEvidenceReferences({
|
|
1182
|
+
records,
|
|
1183
|
+
goal: attempt.goal,
|
|
1184
|
+
permit: attempt.permit,
|
|
1185
|
+
proposal: attempt.proposal
|
|
1186
|
+
});
|
|
1187
|
+
const result = await verifier(
|
|
1188
|
+
verifierInput(attempt, evidence),
|
|
1189
|
+
attempt.controller.signal
|
|
1190
|
+
);
|
|
1191
|
+
if (attempt.controller.signal.aborted) return;
|
|
1192
|
+
outcome = { kind: "decision", result };
|
|
1193
|
+
} catch (error) {
|
|
1194
|
+
if (attempt.controller.signal.aborted) return;
|
|
1195
|
+
if (error instanceof InvalidGoalEvidenceReferenceError) {
|
|
1196
|
+
outcome = {
|
|
1197
|
+
kind: "decision",
|
|
1198
|
+
result: { decision: "reject", reason: error.message }
|
|
1199
|
+
};
|
|
1200
|
+
} else {
|
|
1201
|
+
const reason = error instanceof EvidenceSourceUnavailableError ? error.message : error instanceof Error ? error.message : String(error);
|
|
1202
|
+
outcome = { kind: "usage_limited", reason };
|
|
1203
|
+
}
|
|
1204
|
+
}
|
|
1205
|
+
await recordVerificationOutcome(attempt, outcome);
|
|
1206
|
+
}, "runVerification");
|
|
1207
|
+
return {
|
|
1208
|
+
getSnapshot,
|
|
1209
|
+
getSnapshotForPermit,
|
|
1210
|
+
subscribe(listener) {
|
|
1211
|
+
listeners.add(listener);
|
|
1212
|
+
return () => listeners.delete(listener);
|
|
1213
|
+
},
|
|
1214
|
+
restore(records) {
|
|
1215
|
+
return enqueue(async () => {
|
|
1216
|
+
assertAvailable();
|
|
1217
|
+
if (restored) return;
|
|
1218
|
+
const recovery = recoverGoalFromRecords(records);
|
|
1219
|
+
if (recovery.kind === "unsupported") {
|
|
1220
|
+
recoveryError = new GoalPersistenceUnavailableError(recovery.reason);
|
|
1221
|
+
throw recoveryError;
|
|
1222
|
+
}
|
|
1223
|
+
try {
|
|
1224
|
+
let recoveredSnapshot;
|
|
1225
|
+
let recoveredCause;
|
|
1226
|
+
if (recovery.kind === "v2") {
|
|
1227
|
+
recoveredSnapshot = {
|
|
1228
|
+
...structuredClone(recovery.payload.snapshot),
|
|
1229
|
+
activity: "idle"
|
|
1230
|
+
};
|
|
1231
|
+
blockedAudit = recovery.payload.blockedAudit ? normalizeRecoveredBlockedAudit(recovery.payload.blockedAudit) : void 0;
|
|
1232
|
+
recoveredCause = recovery.payload.cause;
|
|
1233
|
+
} else if (recovery.kind === "legacy") {
|
|
1234
|
+
const recordUuid = randomUUID();
|
|
1235
|
+
const payload = createMigratedGoalState({
|
|
1236
|
+
objective: recovery.objective,
|
|
1237
|
+
goalId: randomUUID(),
|
|
1238
|
+
recordUuid,
|
|
1239
|
+
now: Date.now()
|
|
1240
|
+
});
|
|
1241
|
+
try {
|
|
1242
|
+
await options.journal.recordGoalState(recordUuid, payload);
|
|
1243
|
+
} catch (error) {
|
|
1244
|
+
throw new GoalPersistenceUnavailableError(
|
|
1245
|
+
error instanceof Error ? error.message : String(error),
|
|
1246
|
+
{ cause: error }
|
|
1247
|
+
);
|
|
1248
|
+
}
|
|
1249
|
+
assertAvailable();
|
|
1250
|
+
recoveredSnapshot = structuredClone(payload.snapshot);
|
|
1251
|
+
recoveredCause = payload.cause;
|
|
1252
|
+
}
|
|
1253
|
+
if (recoveredSnapshot) snapshot = recoveredSnapshot;
|
|
1254
|
+
recoveryError = void 0;
|
|
1255
|
+
restored = true;
|
|
1256
|
+
if (recoveredSnapshot) broadcast(recoveredCause);
|
|
1257
|
+
queueContinuation();
|
|
1258
|
+
} catch (error) {
|
|
1259
|
+
if (!disposed) {
|
|
1260
|
+
recoveryError = error instanceof Error ? error : new Error(String(error));
|
|
1261
|
+
}
|
|
1262
|
+
throw error;
|
|
1263
|
+
}
|
|
1264
|
+
});
|
|
1265
|
+
},
|
|
1266
|
+
bindHost(nextHost) {
|
|
1267
|
+
assertOperational();
|
|
1268
|
+
host = nextHost;
|
|
1269
|
+
queueContinuation();
|
|
1270
|
+
return () => {
|
|
1271
|
+
if (host === nextHost) host = void 0;
|
|
1272
|
+
};
|
|
1273
|
+
},
|
|
1274
|
+
beginTurn(turnKey) {
|
|
1275
|
+
assertOperational();
|
|
1276
|
+
if (snapshot.goal?.status !== "active") return void 0;
|
|
1277
|
+
if (snapshot.activity === "verifying" || pendingProposal || verificationAttempt) {
|
|
1278
|
+
queuedTurnKey ??= turnKey;
|
|
1279
|
+
continuationQueued = false;
|
|
1280
|
+
return void 0;
|
|
1281
|
+
}
|
|
1282
|
+
if (currentPermit) {
|
|
1283
|
+
if (currentTurnKey === turnKey) return structuredClone(currentPermit);
|
|
1284
|
+
queuedTurnKey ??= turnKey;
|
|
1285
|
+
continuationQueued = false;
|
|
1286
|
+
return void 0;
|
|
1287
|
+
}
|
|
1288
|
+
continuationQueued = false;
|
|
1289
|
+
currentPermit = {
|
|
1290
|
+
goalId: snapshot.goal.goalId,
|
|
1291
|
+
revision: snapshot.goal.revision,
|
|
1292
|
+
turnId: randomUUID()
|
|
1293
|
+
};
|
|
1294
|
+
currentPermitHost = host;
|
|
1295
|
+
currentTurnKey = turnKey;
|
|
1296
|
+
currentTurnFeedback = nextVerifierFeedback;
|
|
1297
|
+
nextVerifierFeedback = void 0;
|
|
1298
|
+
snapshot = { ...snapshot, activity: "running" };
|
|
1299
|
+
broadcast();
|
|
1300
|
+
return structuredClone(currentPermit);
|
|
1301
|
+
},
|
|
1302
|
+
releaseTurn(turnKey) {
|
|
1303
|
+
return enqueue(async () => {
|
|
1304
|
+
assertOperational();
|
|
1305
|
+
let released = false;
|
|
1306
|
+
if (queuedTurnKey === turnKey) {
|
|
1307
|
+
queuedTurnKey = void 0;
|
|
1308
|
+
released = true;
|
|
1309
|
+
}
|
|
1310
|
+
if (currentPermit && currentTurnKey === turnKey) {
|
|
1311
|
+
if (currentTurnFeedback !== void 0) {
|
|
1312
|
+
nextVerifierFeedback ??= currentTurnFeedback;
|
|
1313
|
+
}
|
|
1314
|
+
currentPermit = void 0;
|
|
1315
|
+
currentPermitHost = void 0;
|
|
1316
|
+
currentTurnKey = void 0;
|
|
1317
|
+
currentTurnFeedback = void 0;
|
|
1318
|
+
currentProposal = void 0;
|
|
1319
|
+
snapshot = { ...snapshot, activity: "idle" };
|
|
1320
|
+
broadcast();
|
|
1321
|
+
released = true;
|
|
1322
|
+
}
|
|
1323
|
+
if (released) queueContinuation();
|
|
1324
|
+
return released;
|
|
1325
|
+
});
|
|
1326
|
+
},
|
|
1327
|
+
permitForTurn(turnKey) {
|
|
1328
|
+
assertOperational();
|
|
1329
|
+
return currentPermit && currentTurnKey === turnKey ? structuredClone(currentPermit) : void 0;
|
|
1330
|
+
},
|
|
1331
|
+
getVerifierFeedback(permit) {
|
|
1332
|
+
assertOperational();
|
|
1333
|
+
if (!isCurrentPermit(permit)) {
|
|
1334
|
+
throw new Error(STALE_GOAL_TURN_MESSAGE);
|
|
1335
|
+
}
|
|
1336
|
+
return currentTurnFeedback;
|
|
1337
|
+
},
|
|
1338
|
+
finishTurn(permit) {
|
|
1339
|
+
const finish = enqueue(
|
|
1340
|
+
async () => {
|
|
1341
|
+
assertOperational();
|
|
1342
|
+
if (!isCurrentPermit(permit) || !snapshot.goal) {
|
|
1343
|
+
throw new Error(STALE_GOAL_TURN_MESSAGE);
|
|
1344
|
+
}
|
|
1345
|
+
const recordUuid = randomUUID();
|
|
1346
|
+
const nextGoal = reduceGoalTurnFinished(snapshot.goal, {
|
|
1347
|
+
now: Date.now()
|
|
1348
|
+
});
|
|
1349
|
+
const persistedSnapshot = {
|
|
1350
|
+
v: GOAL_STATE_VERSION,
|
|
1351
|
+
goal: nextGoal,
|
|
1352
|
+
activity: "idle"
|
|
1353
|
+
};
|
|
1354
|
+
const persistedBlockedAudit = currentProposal?.blockedAuditCandidate;
|
|
1355
|
+
await options.journal.recordGoalState(recordUuid, {
|
|
1356
|
+
v: GOAL_STATE_VERSION,
|
|
1357
|
+
cause: "turn_finished",
|
|
1358
|
+
snapshot: persistedSnapshot,
|
|
1359
|
+
...persistedBlockedAudit ? { blockedAudit: structuredClone(persistedBlockedAudit) } : {}
|
|
1360
|
+
});
|
|
1361
|
+
assertAvailable();
|
|
1362
|
+
const nextTurnKey = queuedTurnKey;
|
|
1363
|
+
const proposal = currentProposal;
|
|
1364
|
+
const activeProposal = proposal && persistedSnapshot.goal?.status === "active" ? proposal : void 0;
|
|
1365
|
+
if (activeProposal?.blockedAuditCandidate) {
|
|
1366
|
+
blockedAudit = activeProposal.blockedAuditCandidate;
|
|
1367
|
+
} else if (persistedSnapshot.goal?.status === "active") {
|
|
1368
|
+
blockedAudit = void 0;
|
|
1369
|
+
}
|
|
1370
|
+
pendingProposal = activeProposal?.readyForVerification && !options.verifier ? {
|
|
1371
|
+
permit: structuredClone(permit),
|
|
1372
|
+
proposal: structuredClone(activeProposal.proposal)
|
|
1373
|
+
} : void 0;
|
|
1374
|
+
verificationAttempt = activeProposal?.readyForVerification && options.verifier ? {
|
|
1375
|
+
permit: structuredClone(permit),
|
|
1376
|
+
proposal: structuredClone(activeProposal.proposal),
|
|
1377
|
+
goal: structuredClone(nextGoal),
|
|
1378
|
+
controller: new AbortController()
|
|
1379
|
+
} : void 0;
|
|
1380
|
+
const verifying = Boolean(pendingProposal || verificationAttempt);
|
|
1381
|
+
snapshot = {
|
|
1382
|
+
...structuredClone(persistedSnapshot),
|
|
1383
|
+
activity: verifying ? "verifying" : "idle"
|
|
1384
|
+
};
|
|
1385
|
+
currentPermit = void 0;
|
|
1386
|
+
currentPermitHost = void 0;
|
|
1387
|
+
currentTurnKey = void 0;
|
|
1388
|
+
currentTurnFeedback = void 0;
|
|
1389
|
+
queuedTurnKey = verifying ? nextTurnKey : void 0;
|
|
1390
|
+
continuationQueued = false;
|
|
1391
|
+
currentProposal = void 0;
|
|
1392
|
+
if (!verifying && nextTurnKey && snapshot.goal?.status === "active") {
|
|
1393
|
+
currentPermit = {
|
|
1394
|
+
goalId: snapshot.goal.goalId,
|
|
1395
|
+
revision: snapshot.goal.revision,
|
|
1396
|
+
turnId: randomUUID()
|
|
1397
|
+
};
|
|
1398
|
+
currentPermitHost = host;
|
|
1399
|
+
currentTurnKey = nextTurnKey;
|
|
1400
|
+
currentTurnFeedback = nextVerifierFeedback;
|
|
1401
|
+
nextVerifierFeedback = void 0;
|
|
1402
|
+
snapshot = { ...snapshot, activity: "running" };
|
|
1403
|
+
}
|
|
1404
|
+
broadcast("turn_finished");
|
|
1405
|
+
if (!verifying && !currentPermit) {
|
|
1406
|
+
queueContinuation();
|
|
1407
|
+
}
|
|
1408
|
+
return verificationAttempt;
|
|
1409
|
+
}
|
|
1410
|
+
);
|
|
1411
|
+
return finish.then(async (attempt) => {
|
|
1412
|
+
if (attempt) await runVerification(attempt);
|
|
1413
|
+
});
|
|
1414
|
+
},
|
|
1415
|
+
async getGoalForWorker(permit) {
|
|
1416
|
+
assertOperational();
|
|
1417
|
+
if (!isCurrentPermit(permit) || !snapshot.goal) {
|
|
1418
|
+
throw new Error(STALE_GOAL_TURN_MESSAGE);
|
|
1419
|
+
}
|
|
1420
|
+
const goal = structuredClone(snapshot.goal);
|
|
1421
|
+
const verifierFeedback = currentTurnFeedback;
|
|
1422
|
+
const evidenceSource = options.evidenceSource;
|
|
1423
|
+
if (!evidenceSource) {
|
|
1424
|
+
return {
|
|
1425
|
+
goalId: goal.goalId,
|
|
1426
|
+
revision: goal.revision,
|
|
1427
|
+
objective: goal.objective,
|
|
1428
|
+
evidenceCursor: structuredClone(goal.evidenceCursor),
|
|
1429
|
+
...verifierFeedback ? { verifierFeedback } : {}
|
|
1430
|
+
};
|
|
1431
|
+
}
|
|
1432
|
+
await evidenceSource.flush();
|
|
1433
|
+
const records = await evidenceSource.readActiveTranscriptChain();
|
|
1434
|
+
const evidenceCatalog = buildGoalEvidenceCatalog({
|
|
1435
|
+
records,
|
|
1436
|
+
goal,
|
|
1437
|
+
permit
|
|
1438
|
+
});
|
|
1439
|
+
if (!isCurrentPermit(permit) || !snapshot.goal) {
|
|
1440
|
+
throw new Error(STALE_GOAL_TURN_MESSAGE);
|
|
1441
|
+
}
|
|
1442
|
+
return {
|
|
1443
|
+
goalId: goal.goalId,
|
|
1444
|
+
revision: goal.revision,
|
|
1445
|
+
objective: goal.objective,
|
|
1446
|
+
evidenceCursor: structuredClone(goal.evidenceCursor),
|
|
1447
|
+
evidenceCatalog,
|
|
1448
|
+
...verifierFeedback ? { verifierFeedback } : {}
|
|
1449
|
+
};
|
|
1450
|
+
},
|
|
1451
|
+
recordTerminalProposal(permit, proposal) {
|
|
1452
|
+
assertOperational();
|
|
1453
|
+
if (!isCurrentPermit(permit)) {
|
|
1454
|
+
throw new Error(STALE_GOAL_TURN_MESSAGE);
|
|
1455
|
+
}
|
|
1456
|
+
const reasonError = validateGoalProposalReason(proposal.reason);
|
|
1457
|
+
if (reasonError) throw new Error(reasonError);
|
|
1458
|
+
if (currentProposal) {
|
|
1459
|
+
return {
|
|
1460
|
+
recorded: false,
|
|
1461
|
+
readyForVerification: currentProposal.readyForVerification
|
|
1462
|
+
};
|
|
1463
|
+
}
|
|
1464
|
+
let readyForVerification = true;
|
|
1465
|
+
let blockedAuditCandidate;
|
|
1466
|
+
if (proposal.status === "blocked" && proposal.blockerKind !== "authority" && proposal.blockerKind !== "external") {
|
|
1467
|
+
const fingerprint = `${proposal.blockerKind ?? "repeated"}
|
|
1468
|
+
${proposal.reason}`;
|
|
1469
|
+
blockedAuditCandidate = {
|
|
1470
|
+
fingerprint,
|
|
1471
|
+
count: blockedAudit?.fingerprint === fingerprint ? Math.min(blockedAudit.count + 1, 3) : 1,
|
|
1472
|
+
turnIds: blockedAudit?.fingerprint === fingerprint ? [...blockedAudit.turnIds, permit.turnId].slice(-3) : [permit.turnId]
|
|
1473
|
+
};
|
|
1474
|
+
readyForVerification = blockedAuditCandidate.count >= 3;
|
|
1475
|
+
}
|
|
1476
|
+
currentProposal = {
|
|
1477
|
+
proposal: structuredClone(proposal),
|
|
1478
|
+
readyForVerification,
|
|
1479
|
+
...blockedAuditCandidate ? { blockedAuditCandidate } : {}
|
|
1480
|
+
};
|
|
1481
|
+
return { recorded: true, readyForVerification };
|
|
1482
|
+
},
|
|
1483
|
+
takePendingTerminalProposal() {
|
|
1484
|
+
assertOperational();
|
|
1485
|
+
const proposal = pendingProposal;
|
|
1486
|
+
pendingProposal = void 0;
|
|
1487
|
+
return proposal ? structuredClone(proposal) : void 0;
|
|
1488
|
+
},
|
|
1489
|
+
dispatch(request) {
|
|
1490
|
+
const execute = /* @__PURE__ */ __name(async () => {
|
|
1491
|
+
assertOperational();
|
|
1492
|
+
const recordUuid = randomUUID();
|
|
1493
|
+
const nextGoal = reduceGoalControl(snapshot.goal, {
|
|
1494
|
+
request,
|
|
1495
|
+
now: Date.now(),
|
|
1496
|
+
nextGoalId: randomUUID(),
|
|
1497
|
+
cursor: request.action === "create" || request.action === "replace" || request.action === "edit" ? { recordId: recordUuid } : options.journal.getTranscriptCursor()
|
|
1498
|
+
});
|
|
1499
|
+
const nextSnapshot = {
|
|
1500
|
+
v: GOAL_STATE_VERSION,
|
|
1501
|
+
goal: nextGoal,
|
|
1502
|
+
activity: "idle"
|
|
1503
|
+
};
|
|
1504
|
+
await options.journal.recordGoalState(recordUuid, {
|
|
1505
|
+
v: GOAL_STATE_VERSION,
|
|
1506
|
+
cause: request.action,
|
|
1507
|
+
snapshot: nextSnapshot
|
|
1508
|
+
});
|
|
1509
|
+
assertAvailable();
|
|
1510
|
+
const invalidatesPermit = request.action === "create" || request.action === "replace" || request.action === "edit" || request.action === "pause" || request.action === "clear";
|
|
1511
|
+
const invalidatedHost = currentPermitHost ?? host;
|
|
1512
|
+
if (invalidatesPermit) {
|
|
1513
|
+
invalidateVerification(`Goal ${request.action}`);
|
|
1514
|
+
}
|
|
1515
|
+
if (invalidatesPermit) {
|
|
1516
|
+
currentPermit = void 0;
|
|
1517
|
+
currentPermitHost = void 0;
|
|
1518
|
+
currentTurnKey = void 0;
|
|
1519
|
+
queuedTurnKey = void 0;
|
|
1520
|
+
currentProposal = void 0;
|
|
1521
|
+
pendingProposal = void 0;
|
|
1522
|
+
blockedAudit = void 0;
|
|
1523
|
+
nextVerifierFeedback = void 0;
|
|
1524
|
+
currentTurnFeedback = void 0;
|
|
1525
|
+
continuationQueued = false;
|
|
1526
|
+
} else if (request.action === "resume") {
|
|
1527
|
+
blockedAudit = void 0;
|
|
1528
|
+
}
|
|
1529
|
+
snapshot = {
|
|
1530
|
+
...structuredClone(nextSnapshot),
|
|
1531
|
+
activity: currentPermit && request.action === "resume" ? "running" : "idle"
|
|
1532
|
+
};
|
|
1533
|
+
if (request.action === "resume") promoteQueuedUserTurn();
|
|
1534
|
+
broadcast(request.action);
|
|
1535
|
+
if (invalidatesPermit) {
|
|
1536
|
+
preemptHost(`Goal ${request.action}`, invalidatedHost);
|
|
1537
|
+
}
|
|
1538
|
+
if (request.action === "resume" || request.action !== "clear" && snapshot.goal?.status === "active") {
|
|
1539
|
+
queueContinuation();
|
|
1540
|
+
}
|
|
1541
|
+
return { snapshot: getSnapshot() };
|
|
1542
|
+
}, "execute");
|
|
1543
|
+
return enqueue(execute);
|
|
1544
|
+
},
|
|
1545
|
+
dispose() {
|
|
1546
|
+
if (disposed) return;
|
|
1547
|
+
disposed = true;
|
|
1548
|
+
const invalidatedHost = currentPermitHost ?? host;
|
|
1549
|
+
currentPermit = void 0;
|
|
1550
|
+
currentPermitHost = void 0;
|
|
1551
|
+
currentTurnKey = void 0;
|
|
1552
|
+
queuedTurnKey = void 0;
|
|
1553
|
+
continuationQueued = false;
|
|
1554
|
+
currentProposal = void 0;
|
|
1555
|
+
pendingProposal = void 0;
|
|
1556
|
+
invalidateVerification("Goal runtime disposed");
|
|
1557
|
+
blockedAudit = void 0;
|
|
1558
|
+
nextVerifierFeedback = void 0;
|
|
1559
|
+
currentTurnFeedback = void 0;
|
|
1560
|
+
preemptHost("Goal runtime disposed", invalidatedHost);
|
|
1561
|
+
host = void 0;
|
|
1562
|
+
listeners.clear();
|
|
1563
|
+
}
|
|
1564
|
+
};
|
|
1565
|
+
}
|
|
1566
|
+
__name(createGoalRuntime, "createGoalRuntime");
|
|
1567
|
+
|
|
1568
|
+
// packages/core/src/goals/goal-turn-context.ts
|
|
1569
|
+
init_esbuild_shims();
|
|
1570
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
1571
|
+
var goalTurnContext = new AsyncLocalStorage();
|
|
1572
|
+
|
|
1573
|
+
export {
|
|
1574
|
+
GOAL_PROPOSAL_REASON_MAX_CHARACTERS,
|
|
1575
|
+
PAUSED_GOAL_SYSTEM_REMINDER,
|
|
1576
|
+
goalRequiresExactPermit,
|
|
1577
|
+
validateGoalProposalReason,
|
|
1578
|
+
GOAL_EVIDENCE_REFERENCE_LIMIT,
|
|
1579
|
+
parseGoalStateRecordPayloadV2,
|
|
1580
|
+
parseGoalSnapshotV2,
|
|
1581
|
+
GOAL_RUNTIME_DISPOSED_MESSAGE,
|
|
1582
|
+
STALE_GOAL_TURN_MESSAGE,
|
|
1583
|
+
GoalPersistenceUnavailableError,
|
|
1584
|
+
createGoalRuntime,
|
|
1585
|
+
goalTurnContext
|
|
1586
|
+
};
|
|
1587
|
+
/**
|
|
1588
|
+
* @license
|
|
1589
|
+
* Copyright 2026 Qwen Team
|
|
1590
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
1591
|
+
*/
|