@testmuai/kane-cli 0.8.7 → 0.8.9
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/bin/kane-cli.cjs +5 -1
- package/dist/{ChatSurface-3PEXML4X.js → ChatSurface-HXCRGPSE.js} +1 -1
- package/dist/{ChromeProfilePicker-E3CZ52RH.js → ChromeProfilePicker-PJS4NGEC.js} +1 -1
- package/dist/{CliFeedbackPrompt-BEVZRLQA.js → CliFeedbackPrompt-Q56VKWKM.js} +1 -1
- package/dist/{CliUploadProgress-V2FLLVR6.js → CliUploadProgress-TMVTKNOT.js} +1 -1
- package/dist/{ConfigView-ZOGKVFQT.js → ConfigView-Y7ZVYT2C.js} +1 -1
- package/dist/EvidenceViewOffer-XV3WF2EC.js +2 -0
- package/dist/FolderPicker-UGHFCPUL.js +2 -0
- package/dist/{InfoBox-4TNE7QMG.js → InfoBox-IDJYGPXF.js} +1 -1
- package/dist/{LinksBox-TXO5X5UD.js → LinksBox-5XNJ3UJJ.js} +1 -1
- package/dist/{ProfilesView-S4YPEZEF.js → ProfilesView-U73QBC5W.js} +1 -1
- package/dist/{ProjectPicker-LWFX2QT2.js → ProjectPicker-KCE2VZCO.js} +1 -1
- package/dist/{SaveSessionPrompt-MJTCIQIZ.js → SaveSessionPrompt-3FHLIRLS.js} +1 -1
- package/dist/SingleShotApp-ECA24PKW.js +2 -0
- package/dist/{SummaryBox-UIVK3QDR.js → SummaryBox-GKHU4C4H.js} +1 -1
- package/dist/TestMdRunView-KLMMXQCN.js +2 -0
- package/dist/{TestrunEvidenceTable-GYGVNCYW.js → TestrunEvidenceTable-INNZCGTM.js} +1 -1
- package/dist/{WhoamiView-NRGMMLL4.js → WhoamiView-PSL7PUVT.js} +1 -1
- package/dist/{app-download-HTQOD3YF.js → app-download-MBUJGT3R.js} +1 -1
- package/dist/{auth-5URO2XJU.js → auth-TYG473Z4.js} +1 -1
- package/dist/{binary-2U4YTTFS.js → binary-QQXWA35Q.js} +1 -1
- package/dist/{bind-NO4TMSHJ.js → bind-WJ5UEMMZ.js} +3 -3
- package/dist/{bootstrap-UOEW3VZM.js → bootstrap-MYG4TJVF.js} +1 -1
- package/dist/bridge-S3WZ4TH2.js +2 -0
- package/dist/{changelog-7BPYLUDK.js → changelog-N4L5ZUGF.js} +1 -1
- package/dist/{chat-committer-GUK6IBCL.js → chat-committer-K3NOTLOU.js} +1 -1
- package/dist/chat-controller-YJCNU76T.js +2 -0
- package/dist/{chunk-DJC6MLO4.js → chunk-22HCCSL7.js} +1 -1
- package/dist/{chunk-Z7HUW3L4.js → chunk-27P7PJAL.js} +1 -1
- package/dist/{chunk-K7VX6YIT.js → chunk-2DKJZPIH.js} +1 -1
- package/dist/{chunk-IQBKCLLR.js → chunk-34VSIQNO.js} +1 -1
- package/dist/{chunk-VMRP44MN.js → chunk-367NASYK.js} +1 -1
- package/dist/chunk-4PMZ5FCD.js +2 -0
- package/dist/{chunk-C4OVX65Q.js → chunk-54JZ6VEW.js} +1 -1
- package/dist/{chunk-GAO6ZMCT.js → chunk-5G22NOZK.js} +1 -1
- package/dist/{chunk-ILKSL4PI.js → chunk-6FCPS2VT.js} +1 -1
- package/dist/{chunk-76ILJPZF.js → chunk-6MJGCETZ.js} +1 -1
- package/dist/{chunk-T4LAHU57.js → chunk-6S426ODE.js} +3 -3
- package/dist/{chunk-LRZXVDPY.js → chunk-6UNXON3J.js} +1 -1
- package/dist/{chunk-7VAE7WXF.js → chunk-6ZNRPDLP.js} +2 -2
- package/dist/{chunk-YDEK2FJQ.js → chunk-7RAIRUXO.js} +1 -1
- package/dist/{chunk-YKYZKBMH.js → chunk-AARF24Z3.js} +17 -17
- package/dist/chunk-AKX4VRRR.js +2 -0
- package/dist/{chunk-VHA7UNDW.js → chunk-AOB2ZX45.js} +1 -1
- package/dist/{chunk-GJ6RJVXH.js → chunk-AROBXG66.js} +1 -1
- package/dist/{chunk-3BY7MX3D.js → chunk-BOZODWIZ.js} +1 -1
- package/dist/{chunk-GYTZLUFV.js → chunk-BVON52QL.js} +1 -1
- package/dist/{chunk-3IM5QGVV.js → chunk-CCEXSCTN.js} +1 -1
- package/dist/{chunk-E5C3HUIY.js → chunk-CJD3EEPT.js} +1 -1
- package/dist/{chunk-IJABR5SX.js → chunk-COJGXGKZ.js} +1 -1
- package/dist/chunk-D5MK4WTK.js +26 -0
- package/dist/{chunk-72J4V3DA.js → chunk-DGNVKMGN.js} +1 -1
- package/dist/{chunk-QQ67Z4IW.js → chunk-DKUD2D5Y.js} +1 -1
- package/dist/{chunk-HHQ67JCU.js → chunk-DUEROGOF.js} +1 -1
- package/dist/{chunk-N2N5T5JN.js → chunk-DWHXXPDX.js} +1 -1
- package/dist/{chunk-HEWWWMUN.js → chunk-EEFZXZTZ.js} +1 -1
- package/dist/{chunk-F43KOMVB.js → chunk-EV64VI66.js} +1 -1
- package/dist/{chunk-TKQSIKMR.js → chunk-F5BI3ALG.js} +1 -1
- package/dist/{chunk-BISBPWN3.js → chunk-FC6DEFUP.js} +1 -1
- package/dist/{chunk-E6AF53HZ.js → chunk-FT23VFSR.js} +48 -47
- package/dist/{chunk-7CU5EBC6.js → chunk-GWSGTZMK.js} +1 -1
- package/dist/{chunk-IMR64OCZ.js → chunk-GX3FPJUG.js} +1 -1
- package/dist/chunk-H4WIA4IP.js +26 -0
- package/dist/{chunk-ZFRWVWUR.js → chunk-H5TNYYZW.js} +1 -1
- package/dist/{chunk-HAGJA7KG.js → chunk-H6KL3FSB.js} +1 -1
- package/dist/{chunk-QZB7CBRO.js → chunk-HKCZ67AT.js} +1 -1
- package/dist/{chunk-NM6PEYED.js → chunk-HPBI3P6I.js} +3 -3
- package/dist/{chunk-UOLERTKE.js → chunk-IANCFSSL.js} +1 -1
- package/dist/{chunk-C5ZIKKIB.js → chunk-IBPF5IM5.js} +1 -1
- package/dist/{chunk-SZTUZZEA.js → chunk-IDQBMC3B.js} +1 -1
- package/dist/{chunk-46HYKID6.js → chunk-IJYV3KKD.js} +2 -2
- package/dist/chunk-IPEA7ZOF.js +8 -0
- package/dist/{chunk-R2JRQD4I.js → chunk-IPZFZUJX.js} +1 -1
- package/dist/{chunk-WNHLKDOT.js → chunk-IVQX3AKL.js} +1 -1
- package/dist/{chunk-5ZV64NAG.js → chunk-IWVA37B6.js} +1 -1
- package/dist/{chunk-P4JUY54O.js → chunk-JPZHCB4Z.js} +1 -1
- package/dist/{chunk-B2KXIFZD.js → chunk-JQW2QFSX.js} +1 -1
- package/dist/{chunk-JZ26R6UL.js → chunk-JUJ4SAGH.js} +1 -1
- package/dist/chunk-KAZGHWGK.js +5 -0
- package/dist/{chunk-Q4CTSXDM.js → chunk-KGKJU27A.js} +1 -1
- package/dist/{chunk-OADHU5HL.js → chunk-KKBID6TD.js} +1 -1
- package/dist/{chunk-LOMPRMG3.js → chunk-LRHSWJDR.js} +1 -1
- package/dist/{chunk-UFYIQ4E3.js → chunk-M7D7EHNN.js} +1 -1
- package/dist/{chunk-2RO2BWCZ.js → chunk-ME3DGP7G.js} +2 -2
- package/dist/{chunk-EU5ZH334.js → chunk-MJHLQKQC.js} +1 -1
- package/dist/chunk-N7Z7BQYO.js +3 -0
- package/dist/{chunk-X7R2JWOJ.js → chunk-NTEI2O3O.js} +1 -1
- package/dist/{chunk-U35Y7SGB.js → chunk-NVNPXOOC.js} +1 -1
- package/dist/{chunk-DSNB7EI6.js → chunk-O3RRCPIU.js} +1 -1
- package/dist/{chunk-SWXEBLKX.js → chunk-O5U6EAL3.js} +1 -1
- package/dist/{chunk-HL4UXOHV.js → chunk-OEH4LU5L.js} +1 -1
- package/dist/{chunk-XAQ3Y63J.js → chunk-OLKHUNSQ.js} +18 -18
- package/dist/{chunk-TMFFHGCT.js → chunk-OME5EJ5X.js} +4 -4
- package/dist/{chunk-ZH2ROVHE.js → chunk-OR6M5HCV.js} +2 -2
- package/dist/{chunk-BPHQNTUD.js → chunk-P2VERPOP.js} +1 -1
- package/dist/{chunk-DMOZM22N.js → chunk-PH4RABYU.js} +1 -1
- package/dist/{chunk-A66ZGHO2.js → chunk-QDE2BBAK.js} +1 -1
- package/dist/chunk-QHUNFH5P.js +363 -0
- package/dist/{chunk-5DBK6QNS.js → chunk-QQ5MHSSY.js} +1 -1
- package/dist/{chunk-VOXDZS4N.js → chunk-QS3DXKZN.js} +2 -2
- package/dist/{chunk-YGVY63PE.js → chunk-R5PIIYN2.js} +1 -1
- package/dist/{chunk-6AUSG5SB.js → chunk-R7GMVPAF.js} +1 -1
- package/dist/chunk-RSSOJ3L2.js +21 -0
- package/dist/{chunk-T3DVIDBA.js → chunk-SJBIXLL3.js} +1 -1
- package/dist/{chunk-F7RR24BL.js → chunk-SV5ZTCQA.js} +1 -1
- package/dist/{chunk-IRPAWAK7.js → chunk-TJLGHGUO.js} +3 -3
- package/dist/{chunk-AUERMBX5.js → chunk-TJR4R45C.js} +1 -1
- package/dist/{chunk-MROHDW4W.js → chunk-TN4SXGAP.js} +1 -1
- package/dist/{chunk-YYSWJU6H.js → chunk-UEIQTXB6.js} +1 -1
- package/dist/{chunk-CUM23TLF.js → chunk-UH2ZTX4E.js} +1 -1
- package/dist/{chunk-3YKNJIVB.js → chunk-VDKGMVXZ.js} +1 -1
- package/dist/{chunk-6YVVTYVO.js → chunk-VQFJM7VP.js} +7 -7
- package/dist/{chunk-4EFDEDTL.js → chunk-VSEWQEM5.js} +1 -1
- package/dist/{chunk-AJXOJF2X.js → chunk-W3Z7AZNT.js} +1 -1
- package/dist/{chunk-C765HUXU.js → chunk-W5BTYVZD.js} +1 -1
- package/dist/{chunk-YC6HYBLN.js → chunk-WH5RVDD6.js} +2 -2
- package/dist/chunk-WHEWZR2C.js +15 -0
- package/dist/{chunk-DTBKKC2R.js → chunk-WHMMOMUY.js} +1 -1
- package/dist/{chunk-Z3EEMIVV.js → chunk-WIAZN7G4.js} +1 -1
- package/dist/{chunk-HLXOYLZV.js → chunk-XMTSHHYQ.js} +1 -1
- package/dist/{chunk-OHD4CZXT.js → chunk-XPFFH2PC.js} +1 -1
- package/dist/{chunk-XWKUZJCP.js → chunk-YMLC55J4.js} +1 -1
- package/dist/{chunk-NQFAZM2D.js → chunk-Z2DT2QMX.js} +1 -1
- package/dist/{chunk-HO3T5LJH.js → chunk-ZAKX5BN6.js} +1 -1
- package/dist/{chunk-B27X3C2E.js → chunk-ZBJAYCPS.js} +1 -1
- package/dist/chunk-ZDAO5D6D.js +16 -0
- package/dist/{chunk-44PZPNXJ.js → chunk-ZHB7V3NY.js} +1 -1
- package/dist/{committer-JC6BIBNR.js → committer-C6UCDYMC.js} +1 -1
- package/dist/{config-XNDP425N.js → config-ZDGCZZT3.js} +1 -1
- package/dist/{cover-cmd-HREOYWWD.js → cover-cmd-5LPHIOSI.js} +1 -1
- package/dist/{credentials-ZTBWB3LK.js → credentials-YEWA7HXA.js} +1 -1
- package/dist/{deps-bundle-OHCYH5KL.js → deps-bundle-JQUW73W5.js} +1 -1
- package/dist/{deps-resolve-K2NX2W3K.js → deps-resolve-RXF3JWAP.js} +1 -1
- package/dist/descriptor-PWUUNYV7.js +2 -0
- package/dist/design-committer-UPC6NZUF.js +2 -0
- package/dist/dispatch-TRYJZWJE.js +2 -0
- package/dist/{doctor-XXOGVMAI.js → doctor-F7R4WUSI.js} +1 -1
- package/dist/{dossier-2M62K2PA.js → dossier-Y6TJWFZU.js} +1 -1
- package/dist/evidence-F3CQJQIB.js +2 -0
- package/dist/{evolve-cmd-WQB7E2B5.js → evolve-cmd-ICTXNYU4.js} +1 -1
- package/dist/exit-manager-ZLDO54S4.js +2 -0
- package/dist/{explain-AOZNHWMB.js → explain-3HAZY7Q6.js} +1 -1
- package/dist/{explain-cmd-7VTWRROR.js → explain-cmd-RMJPXD4U.js} +1 -1
- package/dist/{explain-cmd-2SCD5T6U.js → explain-cmd-XCRO4AS6.js} +1 -1
- package/dist/{extract-bind-3YXY7ZU2.js → extract-bind-PH3VB7PY.js} +3 -3
- package/dist/{extract-cmd-WGXEJ54C.js → extract-cmd-HSESPCTL.js} +2 -2
- package/dist/{feeder-GVZSWX6Q.js → feeder-IOR3XRNF.js} +1 -1
- package/dist/gaps-cmd-JIUM5YDY.js +3 -0
- package/dist/{gate-54BRAE7N.js → gate-E3BLIUEA.js} +1 -1
- package/dist/{generate-headless-PCNAJ2LS.js → generate-headless-Z5YF7UHX.js} +2 -2
- package/dist/index.js +91 -91
- package/dist/ingest-TTUQ7UDK.js +2 -0
- package/dist/ingest-cmd-SNPNVPIO.js +2 -0
- package/dist/install-VBUDO2YW.js +2 -0
- package/dist/{interactive-bind-ZFMG2JIX.js → interactive-bind-HZG2KCTX.js} +4 -4
- package/dist/{lifecycle-cmd-5FRGYY3M.js → lifecycle-cmd-KSMETBPP.js} +1 -1
- package/dist/{list-cmd-DD4WYJSH.js → list-cmd-V3HJ5K4O.js} +1 -1
- package/dist/{list-commands-64THS67Y.js → list-commands-BHQHPHOH.js} +1 -1
- package/dist/{logical-ids-U2OUMYCP.js → logical-ids-MLXAH45L.js} +1 -1
- package/dist/login-flow-TWGSFMWW.js +2 -0
- package/dist/{maintenance-cmd-7V44VGL4.js → maintenance-cmd-VFYGKY3X.js} +1 -1
- package/dist/{mobile-prompts-RITBS32L.js → mobile-prompts-ELBW35KK.js} +1 -1
- package/dist/persist-recorded-session-DXUJXHC5.js +3 -0
- package/dist/{phase-seed-ATH337WF.js → phase-seed-BMOSAA74.js} +1 -1
- package/dist/pipeline-ULKJX3FG.js +2 -0
- package/dist/prepare-target-M656XQLU.js +2 -0
- package/dist/readmodel-TDRFVDVI.js +2 -0
- package/dist/reconcile-cmd-DBOUGUEB.js +2 -0
- package/dist/{reconcile-deps-XEUZHUQX.js → reconcile-deps-RX66LB4B.js} +2 -2
- package/dist/reconcile-engine-OEDO57U7.js +2 -0
- package/dist/{recording-banner-NLS7K2RV.js → recording-banner-COX2HBLL.js} +1 -1
- package/dist/{records-XWF6KDQH.js → records-JLS63SDI.js} +1 -1
- package/dist/registry-PAVGNBIB.js +2 -0
- package/dist/{require-project-folder-V4F74R4A.js → require-project-folder-XFUJYJEA.js} +1 -1
- package/dist/resolve-run-intent-24D3BV2J.js +2 -0
- package/dist/{resolver-7EAM4A6O.js → resolver-ITA6TGPJ.js} +1 -1
- package/dist/{revert-2UCOMQ4J.js → revert-PRR3D4XM.js} +1 -1
- package/dist/{review-cmd-VN6VGUWJ.js → review-cmd-SAGIKWEW.js} +1 -1
- package/dist/run-IHELHWA2.js +2 -0
- package/dist/run-OTSAYPBQ.js +2 -0
- package/dist/{run-test-md-CPGKD3DD.js → run-test-md-U5PSCPZU.js} +2 -2
- package/dist/{sessions-cmd-ME7NM6ES.js → sessions-cmd-VDQGRBEM.js} +1 -1
- package/dist/{skill-installer-WEV2M32J.js → skill-installer-STKFBIY4.js} +1 -1
- package/dist/{spawner-GG6YQB4A.js → spawner-R76ROCR2.js} +1 -1
- package/dist/{structured-answers-2WOTULBQ.js → structured-answers-YAVW65G4.js} +1 -1
- package/dist/tcg-generate-VJARWDD4.js +2 -0
- package/dist/testmd-actions-PXGLZV5L.js +2 -0
- package/dist/token-refresh-ZFT457VI.js +2 -0
- package/dist/{validate-basic-QJL4DCKY.js → validate-basic-BPJVV64Y.js} +1 -1
- package/dist/verdicts-56ZZN3E4.js +2 -0
- package/dist/{version-check-KONSQ4M3.js → version-check-PWHLDMPD.js} +1 -1
- package/dist/{view-cmd-ZSMU4I4J.js → view-cmd-SXXNDZIC.js} +1 -1
- package/dist/{walk-session-X2N4XHLU.js → walk-session-OMUB7DPJ.js} +1 -1
- package/dist/with-telemetry-WI5FZFEK.js +2 -0
- package/package.json +11 -14
- package/dist/EvidenceViewOffer-KWX27WNZ.js +0 -2
- package/dist/FolderPicker-EIKQSSF6.js +0 -2
- package/dist/SingleShotApp-5LCIH6DQ.js +0 -2
- package/dist/TestMdRunView-RE5GX5QX.js +0 -2
- package/dist/bridge-P2EBLXPY.js +0 -2
- package/dist/chat-controller-6GUUMUVP.js +0 -2
- package/dist/chunk-56PAQAX5.js +0 -19
- package/dist/chunk-7EFG27IZ.js +0 -355
- package/dist/chunk-E5Q5CDOX.js +0 -2
- package/dist/chunk-FVKLNQ4T.js +0 -26
- package/dist/chunk-GDB2V6QA.js +0 -21
- package/dist/chunk-LWZ7EIXX.js +0 -2
- package/dist/chunk-Q3S5EKX5.js +0 -21
- package/dist/chunk-UASEGQ7B.js +0 -11
- package/dist/chunk-WXHQYYD5.js +0 -2
- package/dist/chunk-YC2TFACE.js +0 -5
- package/dist/descriptor-OEUZZCOK.js +0 -2
- package/dist/design-committer-IIHKNEYF.js +0 -2
- package/dist/dispatch-JZWIFKRB.js +0 -2
- package/dist/evidence-FN2SQB6Z.js +0 -2
- package/dist/exit-manager-3FVBTNYR.js +0 -2
- package/dist/gaps-cmd-MFZ52DC7.js +0 -3
- package/dist/ingest-TTSDUMH5.js +0 -2
- package/dist/ingest-cmd-D2MD6EAK.js +0 -2
- package/dist/install-RHINEFR5.js +0 -2
- package/dist/login-flow-B5J6JXQN.js +0 -2
- package/dist/persist-recorded-session-Z5SCYWXR.js +0 -3
- package/dist/pipeline-HMFLLUZJ.js +0 -2
- package/dist/prepare-target-HOEFIKXN.js +0 -2
- package/dist/readmodel-UZETCXV6.js +0 -2
- package/dist/reconcile-cmd-Q7CBNPRX.js +0 -2
- package/dist/reconcile-engine-ES2INERY.js +0 -2
- package/dist/registry-E5RSXYQJ.js +0 -2
- package/dist/resolve-run-intent-WSOCGJUN.js +0 -2
- package/dist/run-45ODACZR.js +0 -2
- package/dist/run-ZYARNPAS.js +0 -2
- package/dist/tcg-generate-DASCY23M.js +0 -2
- package/dist/testmd-actions-X6HEL5NH.js +0 -2
- package/dist/token-refresh-ZTQFC3Q3.js +0 -2
- package/dist/verdicts-CRNN765C.js +0 -2
- package/dist/with-telemetry-Y6MVROKX.js +0 -2
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createRequire } from 'module'; const require = createRequire(import.meta.url);
|
|
2
|
-
import{c as k}from"./chunk-RFHMDQXZ.js";import{a as b}from"./chunk-
|
|
2
|
+
import{c as k}from"./chunk-RFHMDQXZ.js";import{a as b}from"./chunk-IPZFZUJX.js";import{a as C}from"./chunk-6MJGCETZ.js";import{p as m,q as u,r as f,s as x,t as y}from"./chunk-DWHXXPDX.js";import{createServer as S}from"http";import{randomBytes as A}from"crypto";import{URL as L}from"url";var P=class{profile;environment;creds;oauth;constructor(r="default",o="prod",e){this.profile=r,this.environment=o,this.creds=e??new C,this.oauth=new b(o)}async login(){let{server:r,port:o}=await this.startCallbackServer(),e=y(o);try{let t=this.creds.loadClient(this.profile,this.environment),i=t?.redirect_uris;(!t||!i?.includes(e))&&(t=await this.oauth.registerClient(e),this.creds.saveClient(this.profile,this.environment,t));let c=t.client_id,[h,d]=b.generatePkce(),a=A(32).toString("hex"),n=this.oauth.buildAuthorizationUrl(c,d,a,e),l=await this.waitForCallback(r,o,n,a);if(!l)throw new Error("Login cancelled or timed out");let p=await this.oauth.exchangeCode(l,c,h,e),g={access_token:p.access_token,refresh_token:p.refresh_token,expires_at:Math.floor(Date.now()/1e3)+p.expires_in,scope:p.scope??"*"};return this.creds.saveCredentials(this.profile,this.environment,g),this.creds.setActiveProfile(this.profile),g}catch(t){throw r.close(),t}}startCallbackServer(){return new Promise((r,o)=>{let e=u,t=()=>{let i=S();i.on("error",c=>{c.code==="EADDRINUSE"&&e<f?(e++,t()):o(new Error(`Failed to start callback server: ${c.message}. Ports ${u}-${f} are all in use.`))}),i.listen(e,m,()=>{r({server:i,port:e})})};t()})}waitForCallback(r,o,e,t){return new Promise(i=>{let c=!1,h=setTimeout(()=>d(null),12e4),d=a=>{c||(c=!0,clearTimeout(h),r.close(),i(a))};r.on("request",(a,n)=>{let l=new L(a.url??"/",`http://${m}:${o}`);if(l.pathname!==x){n.writeHead(404),n.end();return}let p=l.searchParams.get("state"),g=l.searchParams.get("code");if(l.searchParams.get("error")){n.writeHead(200,{"Content-Type":"text/html; charset=utf-8"}),n.end(v({state:"error",title:"Login failed",message:"We couldn't complete the sign-in. You can close this tab and try again from your terminal."})),d(null);return}if(p!==t){n.writeHead(400,{"Content-Type":"text/html; charset=utf-8"}),n.end(v({state:"error",title:"Invalid state",message:"The sign-in response didn't match this session. Please return to your terminal and try again."})),d(null);return}n.writeHead(200,{"Content-Type":"text/html; charset=utf-8"}),n.end(v({state:"success",title:"You're signed in",message:"Head back to your terminal \u2014 KaneAI is ready when you are.",autoClose:!0})),d(g)}),k(e).catch(a=>{let n=a instanceof Error?a.message:String(a);process.stderr.write(`[auth] Could not open browser: ${n}
|
|
3
3
|
Please open this URL manually: ${e}
|
|
4
4
|
`)})})}};function v(s){let r=s.state==="success",o=r?"#22c55e":"#ef4444",e=r?"rgba(34, 197, 94, 0.12)":"rgba(239, 68, 68, 0.12)",t=r?'<svg viewBox="0 0 24 24" width="36" height="36" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M5 12.5l4.5 4.5L19 7"/></svg>':'<svg viewBox="0 0 24 24" width="36" height="36" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M6 6l12 12M18 6L6 18"/></svg>',i=s.autoClose?"<script>setTimeout(function(){try{window.close();}catch(e){}}, 1500);</script>":"";return`<!doctype html>
|
|
5
5
|
<html lang="en">
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createRequire } from 'module'; const require = createRequire(import.meta.url);
|
|
2
|
-
import{b as p,c as
|
|
3
|
-
`)}let i=
|
|
2
|
+
import{b as p,c as j,d as M,e as y,f as C,g as A,i as D,l as F,o as T,q as $,r as O}from"./chunk-WHEWZR2C.js";import{c as H,d as z}from"./chunk-2YQ6TW77.js";import{a as E}from"./chunk-IPEA7ZOF.js";import{a as k}from"./chunk-NTEI2O3O.js";import{r as B,s as R}from"./chunk-RSSOJ3L2.js";import{a as P}from"./chunk-DWHXXPDX.js";import{e as q}from"./chunk-UR6MHSHU.js";import{existsSync as f,mkdirSync as V,readFileSync as Z,renameSync as N,writeFileSync as K}from"fs";import{join as Q}from"path";function fe(e){F(p(e));let t=p(e);if(!f(t))return;let n=Q(t,"meta.json"),r=y(e);if(f(n)&&!f(r))try{V(M(e),{recursive:!0}),N(n,r)}catch(o){process.stderr.write(`warn: meta.json migration failed: ${o.message}
|
|
3
|
+
`)}let i=A(e);if(f(i)){let o="python";try{let c=new k().load();c.code_export?.language&&(o=c.code_export.language)}catch{}let a=C(e,"playwright",o);if(!f(a))try{N(i,a)}catch(c){process.stderr.write(`warn: generated-code migration failed: ${c.message}
|
|
4
4
|
`)}}if(f(r))try{let o=JSON.parse(Z(r,"utf8"));"md5sum"in o&&(delete o.md5sum,K(r,JSON.stringify(o,null,2)+`
|
|
5
5
|
`,"utf8"))}catch(o){process.stderr.write(`warn: meta.json md5sum strip failed: ${o.message}
|
|
6
|
-
`)}}async function ye(e){if(!e.isInteractive)return{recovered:!1};if(W(e.creds))return{recovered:!1};let{SingleShotApp:t}=await import("./SingleShotApp-
|
|
6
|
+
`)}}async function ye(e){if(!e.isInteractive)return{recovered:!1};if(W(e.creds))return{recovered:!1};let{SingleShotApp:t}=await import("./SingleShotApp-ECA24PKW.js"),{ScrollbackProvider:n}=await import("./scrollback-JLPJR25X.js"),{render:r}=await import("./build-JIKYOZUH.js"),i=await import("./react-QWOAB3TB.js"),o={current:null},a={current:!1},{waitUntilExit:c,unmount:l}=r(i.default.createElement(n,null,i.default.createElement(t,{resultRef:o,mode:"login",loginCompleteRef:a})),{exitOnCtrlC:!1});R(()=>l()),await c();try{process.stdin.setRawMode?.(!1)}catch{}return process.stdout.write("\x1B[?25h"),a.current?{recovered:!0}:(B(0,"Startup gate cancelled"),{recovered:!1})}function W(e){let t=e.getActiveProfile(),n=e.getDefaultEnv();if(!t||!!!(e.loadBasicAuth(t,n)||e.loadCredentials(t,n)))return!1;let i=e.loadProfileConfig(t,n)??{};return!!i.project_id&&!!i.folder_id}var J=q(H(),1);import{existsSync as v,readFileSync as U,readdirSync as X,statSync as Y}from"fs";import{dirname as ee,isAbsolute as te,join as g,relative as x,resolve as re,sep as h}from"path";import{createHash as ne}from"crypto";var S="testmd-bundle.json",d=class extends Error{constructor(t){super(t),this.name="BundleUsageError"}},_=e=>e.split(h).join("/");function I(e){if(!v(e))return[];let t=[];for(let n of X(e).sort()){let r=g(e,n);Y(r).isDirectory()?t.push(...I(r)):t.push(r)}return t}function se(e){let t=e.map(r=>ee(r).split(h)),n=t[0];for(let r of t.slice(1)){let i=0;for(;i<n.length&&i<r.length&&n[i]===r[i];)i++;n=n.slice(0,i)}return n.join(h)||h}function ie(e){for(let t of e){let n=E(t,U(t,"utf8"));for(let r of n.steps)if(r.body.kind==="import_ref"&&te(r.body.path))throw new d(`bundle sync: absolute @import is not portable after unzip: ${t} step ${r.index} (@import ${r.body.path})`)}}function G(e){let t=re(e),n=T(t);if(!n?.commit_id||!n?.test_id)throw new d(`bundle sync: ${t} is not authored \u2014 run \`kane-cli testmd run\` first (output-<stem>/.internal/meta.json needs commit_id + test_id)`);let r;try{r=O(t)}catch(s){throw s instanceof $?new d(`bundle sync: ${s.message}`):s}let i=[t];for(let s of r.steps)for(let u of s.trace.slice(1))i.includes(u.file)||i.push(u.file);ie(i);let o=[];for(let s of r.unitFiles){if(s.file===t)continue;let u=p(s.file);o.includes(u)||o.push(u)}let a=[...i],c=s=>{v(s)&&a.push(s)};c(j(t)),a.push(y(t)),c(g(p(t),".internal","execution.json")),a.push(...I(D(t)));for(let s of o)c(g(s,"Result.md")),a.push(...I(g(s,".internal","steps")));let l=se(a);if(v(g(l,S)))throw new d(`bundle sync: a real file named ${S} exists at the zip root (${l}) \u2014 it would collide with the generated manifest`);let b=a.map(s=>{let u=U(s);return{abs:s,rel:_(x(l,s)),sha256:ne("sha256").update(u).digest("hex"),bytes:u.length}}).sort((s,u)=>s.rel<u.rel?-1:1),m=_(x(l,t)),L={schema_version:2,entry:m,commit_id:n.commit_id,test_id:n.test_id,testcase_id:n.testcase_id??null,project_id:n.project_id??null,folder_id:n.folder_id??null,org_id:n.org_id??null,created_at:new Date().toISOString(),producer:{name:"kane-cli",version:P},files:b.map(s=>({path:s.rel,sha256:s.sha256,bytes:s.bytes})),units:r.unitFiles.filter(s=>s.file!==t).map(s=>({path:_(x(l,s.file)),kind:s.kind}))};return{zipRoot:l,entry:m,files:b,manifest:L}}var w=e=>e instanceof Error?e.message:String(e);function oe(e){return new Promise((t,n)=>{let r=(0,J.default)("zip",{zlib:{level:6}}),i=[];r.on("data",o=>i.push(o)),r.on("error",n),r.on("end",()=>t(Buffer.concat(i))),r.append(JSON.stringify(e.manifest,null,2)+`
|
|
7
7
|
`,{name:S});for(let o of e.files)r.file(o.abs,{name:o.rel});r.finalize()})}async function ae(e){let{plan:t,controller:n,testId:r,sessionId:i,commitId:o}=e,a;try{a=await oe(t)}catch(l){return{ok:!1,stage:"zip",error:w(l)}}let c;try{let l={key:"testmd",content_type:"application/zip",filename:`${o}-testmd.zip`},m=(await n.getPresignedUrls(r,i,[l])).urls?.testmd?.upload_url;if(!m)return{ok:!1,stage:"presign",error:"presign response missing testmd upload_url"};c=m}catch(l){return{ok:!1,stage:"presign",error:w(l)}}try{await z(c,a,"application/zip")}catch(l){return{ok:!1,stage:"upload",error:w(l)}}return{ok:!0,bytes:a.length}}async function Ee(e){let t;try{t=G(e.sourcePath)}catch(n){return n instanceof d?{ok:!1,stage:"collect",error:n.message}:{ok:!1,stage:"collect",error:w(n)}}return ae({...e,plan:t})}function je(e){return e.shouldUploadPipeline&&e.uploadSucceeded&&!!e.metaCommitId&&!!e.metaTestId}export{fe as a,ye as b,G as c,Ee as d,je as e};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { createRequire } from 'module'; const require = createRequire(import.meta.url);
|
|
2
|
-
import{a as $}from"./chunk-YCCUBQY4.js";import{a as U}from"./chunk-
|
|
2
|
+
import{a as $}from"./chunk-YCCUBQY4.js";import{a as U}from"./chunk-CJD3EEPT.js";import{a as k}from"./chunk-BPMSNGXQ.js";import{a as _}from"./chunk-7RAIRUXO.js";import{a as T}from"./chunk-H6KL3FSB.js";import{x as i}from"./chunk-DWHXXPDX.js";import{a as O}from"./chunk-HCBYKLMW.js";import{a as u,b as s}from"./chunk-C44QQJR4.js";import{a as K}from"./chunk-6YGTRKDT.js";import{e as S}from"./chunk-UR6MHSHU.js";var e=S(K(),1);var r=S(O(),1);function V(n,x,c){return{id:n,label:`${x} (${n})`,isActive:n===c}}function se({resolver:n,currentProjectId:x,env:c,onSelect:w,onCancel:C}){let[q,B]=(0,e.useState)([]),[D,l]=(0,e.useState)(!0),[H,m]=(0,e.useState)(!1),[J,g]=(0,e.useState)(!1),[Q,P]=(0,e.useState)(null),[d,p]=(0,e.useState)("list"),[v,R]=(0,e.useState)(""),[E,h]=(0,e.useState)(null),[I,X]=(0,e.useState)(""),b=(0,e.useRef)(!1),A=(0,e.useRef)(!0);(0,e.useEffect)(()=>{if(!n){P("Login first to browse projects"),l(!1);return}let o=new AbortController,a=I.trim();return A.current?l(!0):a&&g(!0),m(!0),P(null),(async()=>{try{let t=n.cached??await n.resolve();if(!t){P("Login first to browse projects"),l(!1),m(!1),g(!1);return}let L=T(c),F=new k(L.tmsBaseUrl,t.username,t.access_key),f=!0,N=0,G=a?{signal:o.signal,name:a,perPage:10}:{signal:o.signal,perPage:10};for await(let y of F.listProjectsStream(G)){if(f&&(l(!1),g(!1),A.current=!1,f=!1),y.totalLoaded===0&&y.done&&N===0&&!a){b.current=!0,p("naming"),m(!1);return}let M=y.projects.map(j=>V(j.project_id,j.name,x));B(N===0?M:j=>[...j,...M]),N+=y.projects.length,y.done&&m(!1)}f&&(l(!1),m(!1),g(!1))}catch(t){if(t?.name==="AbortError")return;P(t instanceof Error?t.message:String(t)),l(!1),m(!1),g(!1)}})(),()=>o.abort()},[n,x,c,I]);let Y=(0,e.useCallback)(o=>{let a=o.trim();if(!a){h("Name cannot be empty");return}h(null),p("creating"),(async()=>{try{if(!n)throw new Error("Not authenticated");let t=n.cached??await n.resolve();if(!t)throw new Error("Not authenticated");let L=T(c),f=await new k(L.tmsBaseUrl,t.username,t.access_key).createProject(a);w(f.id,f.name)}catch(t){h(t instanceof Error?t.message:String(t)),p("naming")}})()},[n,c,w]),z=(0,e.useCallback)(()=>{R(""),h(null),b.current?C():p("list")},[C]);return d==="naming"||d==="creating"?(0,r.jsxs)(u,{flexDirection:"column",borderStyle:"round",borderColor:i.orange,paddingX:2,paddingY:1,children:[(0,r.jsx)(s,{color:i.orange,bold:!0,children:"Create new project"}),b.current&&(0,r.jsx)(u,{marginTop:1,children:(0,r.jsx)(s,{color:i.dim,children:"No projects yet \u2014 let's create one."})}),(0,r.jsxs)(u,{marginTop:1,children:[(0,r.jsx)(s,{color:i.dim,children:"Name: "}),d==="naming"?(0,r.jsx)($,{value:v,onChange:o=>{R(o),E&&h(null)},onSubmit:Y,onCancel:z}):(0,r.jsx)(s,{children:v})]}),E&&(0,r.jsx)(u,{marginTop:1,children:(0,r.jsx)(s,{color:i.red,children:E})}),d==="creating"&&(0,r.jsx)(u,{marginTop:1,children:(0,r.jsx)(s,{color:i.dim,children:"Creating..."})}),d==="naming"&&(0,r.jsx)(_,{bindings:[{keys:"\u21B5",label:"create"}],escBackLabel:b.current?"cancel":"back"})]}):(0,r.jsx)(U,{title:"Projects",items:q,loading:D,loadingMore:H,searching:J,preserveSelectionById:!0,onSearch:X,error:Q,itemNoun:"projects",onTab:()=>{b.current=!1,p("naming")},extraHint:"tab to create new",onSelect:o=>{let a=o.label.replace(` (${o.id})`,"");w(o.id,a)},onCancel:C})}export{V as a,se as b};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { createRequire } from 'module'; const require = createRequire(import.meta.url);
|
|
2
|
-
import{b as t}from"./chunk-
|
|
2
|
+
import{b as t}from"./chunk-DWHXXPDX.js";import{join as i}from"path";function e(n=t){return i(n,"plugins")}function g(n,r=t){return i(e(r),n)}function c(n,r,o=t){return i(g(n,o),r)}function f(n,r=t){return i(g(n,r),"current")}function x(n,r=t){return i(g(n,r),"config.json")}function l(n,r=t){return i(g(n,r),".jobs")}function s(n=t){return i(n,"bin")}function h(n=t){return i(s(n),"hyperexecute")}export{e as a,g as b,c,f as d,x as e,l as f,s as g,h};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { createRequire } from 'module'; const require = createRequire(import.meta.url);
|
|
2
|
-
import{x as m}from"./chunk-
|
|
2
|
+
import{x as m}from"./chunk-DWHXXPDX.js";import{a as x}from"./chunk-HCBYKLMW.js";import{a as u,b as a,j as g}from"./chunk-C44QQJR4.js";import{a as b}from"./chunk-6YGTRKDT.js";import{e as f}from"./chunk-UR6MHSHU.js";var T=f(b(),1);function k(i,n){if(!n)return i;let l=i.trim()||n;return`\x1B]8;;${n}\x07${l}\x1B]8;;\x07`}var r=f(x(),1);function $({shareableLink:i,testCaseLink:n,codeExportDir:l,recordedTestPath:s,outputDir:o,autoExit:p=!0}){let{exit:c}=g();(0,T.useEffect)(()=>{if(!p)return;let t=setTimeout(()=>c(),100);return()=>clearTimeout(t)},[c,p]);let e=[];return s&&e.push({label:"Test",url:s,linkUrl:`file://${s}`}),o&&e.push({label:"Output",url:o,linkUrl:`file://${o}`}),i&&e.push({label:"ShareLink",url:i}),n&&e.push({label:"TestCase",url:n}),l&&!o&&e.push({label:"CodeExport",url:l,linkUrl:`file://${l}`}),e.length===0?(0,r.jsx)(r.Fragment,{}):(0,r.jsx)(u,{flexDirection:"column",marginTop:1,marginLeft:1,children:e.map(t=>(0,r.jsxs)(u,{flexDirection:"column",marginBottom:1,children:[(0,r.jsxs)(a,{color:m.orange,children:[t.label,":"]}),(0,r.jsx)(a,{color:m.dim,children:k(t.url,t.linkUrl??t.url)})]},t.label))})}export{$ as a};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { createRequire } from 'module'; const require = createRequire(import.meta.url);
|
|
2
|
-
import{i as s,j as e}from"./chunk-
|
|
2
|
+
import{i as s,j as e}from"./chunk-AKX4VRRR.js";import{a as t,b as i}from"./chunk-IAHKTEET.js";function a(r,n){return"sha256:"+i(Buffer.from("assurance."+r+"\0"+t(s(r,n)),"utf8"))}function f(r,n,o,u){return"sha256:"+i(Buffer.from("assurance.edge\0"+t({type:r,src:n,dst:o,props:e(r,u)}),"utf8"))}function d(r,n){return{source_id:r,blob:n}}function p(r){return{...r,derived:!0}}export{a,f as b,d as c,p as d};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { createRequire } from 'module'; const require = createRequire(import.meta.url);
|
|
2
|
-
import{a as h}from"./chunk-
|
|
2
|
+
import{a as h}from"./chunk-IBPF5IM5.js";import{a as f}from"./chunk-6UNXON3J.js";import{a as m}from"./chunk-H6KL3FSB.js";var o=class extends Error{constructor(a,l){super(a);this.code=l;this.name="AuthError"}};async function k(c){let{creds:i,env:a,usernameFlag:l,accessKeyFlag:g,log:t}=c,e=null,u=null;if(l&&g)e={username:l,access_key:g},t("info","AUTH_RESOLVE_FLAGS","Auth resolved via CLI flags",{username:l});else{let r=i.resolveAuth();r?.method==="basic"&&(e={username:r.username,access_key:r.access_key},t("info","AUTH_RESOLVE_CONFIG","Auth resolved via config",{username:r.username}))}if(!e){let{credentials:r,profile:E}=i.getActiveCredentials();if(!r)throw new o("Not authenticated \u2014 no credentials found","not_authenticated");if(u=r.access_token,r.expires_at-Date.now()/1e3<300)try{let n=await f({creds:i,profile:E,env:a,credentials:r});n&&(u=n.accessToken,t("info","AUTH_TOKEN_REFRESHED","OAuth token refreshed"))}catch(n){let d=n instanceof Error?n.message:String(n);throw t("error","TOKEN_REFRESH_FAILED","Token refresh failed",{error:d}),new o(`Token refresh failed: ${d}`,"refresh_failed")}}let v=m(a),b=async()=>u,y=e?{username:e.username,access_key:e.access_key}:null,p=new h(v.controllerBaseUrl,b,y,t),s=await p.resolve();return s&&!e&&(e={username:s.username,access_key:s.access_key},t("info","AUTH_RESOLVE_CONTROLLER","Auth resolved via controller",{username:s.username})),{basicAuth:e,token:u,resolver:p,resolvedCreds:s}}export{o as a,k as b};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { createRequire } from 'module'; const require = createRequire(import.meta.url);
|
|
2
|
-
import{a as ke}from"./chunk-
|
|
3
|
-
`).length)}let l=t.extractionCompleteness.get(f);c.push({source_id:f,kind:h,lines:E,head_cid:u,extracted:_,last_extract_at:l?.at??null,extractor_version:l?.extractor_version??null})}let{rows:s,truncated:d,next_cursor:m}=
|
|
2
|
+
import{a as ke}from"./chunk-ME3DGP7G.js";import{b as he,c as _e,d as J,e as Z}from"./chunk-KKBID6TD.js";import{d as ye,e as we}from"./chunk-AXTPNZPX.js";import{d as V}from"./chunk-BZAGVBCX.js";import{a as pe}from"./chunk-WH5RVDD6.js";import{a as O}from"./chunk-DNNZ353O.js";import{B as me,C as N}from"./chunk-W3Z7AZNT.js";import{b as ge}from"./chunk-6FCPS2VT.js";import{a as ue}from"./chunk-UH2ZTX4E.js";import{e as de,j as fe}from"./chunk-XMTSHHYQ.js";import{d as ae,f as le}from"./chunk-AKX4VRRR.js";function bt(t){let e=process.env.HOME??"";return e&&t.startsWith(e)?`~${t.slice(e.length)}`:t}import{randomBytes as mt}from"crypto";function ee(t,e){let n=Math.min(t.length,e.length),o=0,r=0,c=0;for(let s=0;s<n;s++)o+=t[s]*e[s],r+=t[s]*t[s],c+=e[s]*e[s];return r===0||c===0?0:o/(Math.sqrt(r)*Math.sqrt(c))}function te(t,e,n){return n*t+(1-n)*e}var ne=.7;var ze=["get_node","get_edges","find_by_provenance","match_by_type","stale_nodes","search_similar","search_similar_batch","history"],Qe=["source_read","source_grep","source_list"],Ke=[...ze,...Qe],Se=50,Ee=200,re=10,Re=50,be=20,We=200,Xe=50;function H(t,e,n){let o=typeof t=="number"&&Number.isFinite(t)?Math.floor(t):e;return Math.max(1,Math.min(o,n))}function C(t,e){let n=t[e];if(typeof n!="string"||n.length===0)throw new b(`param "${e}" must be a non-empty string`);return n}function M(t,e){let n=t[e];if(n==null)return null;if(typeof n!="string")throw new b(`param "${e}" must be a string when present`);return n}var b=class extends Error{},xe=24,qe=10,Ye=10;function Je(t){let e=t.cursor;if(e==null)return 0;if(typeof e=="string"&&/^\d+$/.test(e))return Number.parseInt(e,10);throw new b(`BAD_CURSOR: cursor ${JSON.stringify(e)} is not a cursor this store minted`)}function Ae(t,e){let n=e.fields;if(!Array.isArray(n)||n.length===0)return t;let o=new Set(n.filter(r=>typeof r=="string"));return t.map(r=>Object.fromEntries(Object.entries(r).filter(([c])=>o.has(c))))}function se(t,e,n=Se,o=Ee){let r=Je(e),c=H(e.limit,n,o),s=t.slice(r,r+c),d=r+s.length<t.length;return{rows:Ae(s,e),truncated:d,next_cursor:d?String(r+s.length):null}}var Ze=t=>t.cursor!=null||t.fields!=null;function U(t,e,n=Se){let o=se(t,e,n);return Ze(e)||o.truncated?{rows:o.rows,truncated:o.truncated,next_cursor:o.next_cursor}:o.rows}function oe(t,e){let n=t.getNode(e);return n?{cid:e,label:n.label,content:n.content,trust:t.trust.get(e)??null,freshness:t.stale(e)}:null}function ve(t){return new Set(t.toLowerCase().replace(/[^\p{L}\p{N}]+/gu," ").split(" ").filter(Boolean))}function z(t,...e){let n=ve(t);if(n.size===0)return 0;let o=t.trim().toLowerCase(),r=0;for(let c of e){let s=ve(c);if(s.size===0)continue;let d=0;for(let u of n)s.has(u)&&d++;let m=n.size+s.size-d,f=m===0?0:d/m;o&&c.toLowerCase().includes(o)&&(f=Math.max(f,.9)),r=Math.max(r,f)}return r}function et(t,e){let n=C(e,"cid"),o=M(e,"type"),r=M(e,"direction")??"both";if(!["out","in","both"].includes(r))throw new b('param "direction" must be out|in|both');let c=[];(r==="out"||r==="both")&&c.push(...t.edgesFrom(n)),(r==="in"||r==="both")&&c.push(...t.edgesInto(n));let s=c.filter(d=>o==null||d.type===o);return U(s,e)}function tt(t,e){let n=C(e,"source_id"),o=t.heads.get(n)??null,r=[];for(let c of t.nodeLabel.keys()){let s=t.derivesInto(c).filter(m=>m.props.source_id===n).map(m=>({source_cid:m.props.source_cid,anchor:m.props.anchor??null}));if(s.length===0)continue;let d=oe(t,c);d&&r.push({...d,pins:s,pinned_to_head:o!=null&&s.some(m=>m.source_cid===o)})}return U(r,e,Ee)}function nt(t,e){let n=C(e,"label"),o=M(e,"trust"),r=M(e,"freshness"),c=[];for(let{cid:s}of t.byLabel(n)){let d=oe(t,s);d&&(o!=null&&d.trust!==o||r!=null&&d.freshness!==r||c.push(d))}return U(c,e)}function rt(t,e={}){let n=M(e,"label"),o=t.staleList().map(({cid:r,state:c})=>{let s=t.getNode(r);return{cid:r,state:c,label:s?.label??null,title:s?.content.title??null}}).filter(r=>n==null||r.label===n);return U(o,e)}function st(t,e,n){let o=e.extracted,r=M(e,"kind"),c=[];for(let f of[...t.heads.keys()].sort()){let u=t.heads.get(f);if(typeof u!="string")continue;let h=t.mediaOf(u).format;if(r!=null&&h!==r)continue;let _=t.extractedSourceCids.has(u);if(typeof o=="boolean"&&_!==o)continue;let E=0;if(h!=="image"){let y=O(n,t,u);y&&(E=y.toString("utf8").replace(/\n$/,"").split(`
|
|
3
|
+
`).length)}let l=t.extractionCompleteness.get(f);c.push({source_id:f,kind:h,lines:E,head_cid:u,extracted:_,last_extract_at:l?.at??null,extractor_version:l?.extractor_version??null})}let{rows:s,truncated:d,next_cursor:m}=se(c,e);return{sources:s,truncated:d,next_cursor:m}}function ot(t,e,n){let o=C(e,"ref"),r=t.resolve(o);if(!r)throw new b(`UNKNOWN_REF: ${o} names nothing in the graph`);let c=r.tip,s=new Map;for(let[p,k]of t.superseded)typeof k=="string"&&k!==p&&s.set(k,[...s.get(k)??[],p]);let d=[],m=[c],f=new Set;for(;m.length>0;){let p=m.pop();f.has(p)||(f.add(p),d.push(p),m.push(...s.get(p)??[]))}let{records:u}=de(n),g=new Map,h=new Map;for(let p of u){for(let k of p.nodes)g.has(k.cid)||g.set(k.cid,p.ts);for(let k of p.supersessions)k.kind==="node"&&h.set(k.old,{by_cid:k.new,reason:k.reason})}let _=d.map(p=>({cid:p,minted_at:g.get(p)??null,superseded_by:h.get(p)?.by_cid??null,reason:h.get(p)?.reason??null,change_note:null})),{rows:E,truncated:l,next_cursor:y}=se(_,e,Ye);return{root_logical_id:t.displayNameOf(c),live_tip:t.superseded.has(c)?null:c,truncated:l,next_cursor:y,chain:E}}function $e(t){let e=t.queries;if(!Array.isArray(e)||e.length<1||e.length>xe)throw new b(`param "queries" must be 1..${xe} entries`);return e.map((n,o)=>{if(typeof n!="object"||n===null)throw new b(`queries[${o}] must be an object`);let r=n;if(typeof r.qid!="string"||r.qid.length===0)throw new b(`queries[${o}].qid must be a non-empty string`);if(typeof r.text!="string"||r.text.length===0)throw new b(`queries[${o}].text must be a non-empty string`);return{qid:r.qid,text:r.text,topK:H(r.top_k,re,qe)}})}function De(t){let e=[];for(let{cid:n,content:o}of t.byLabel("usecase"))t.superseded.has(n)||e.push({cid:n,title:String(o.title??""),summary:String(o.summary??""),description:String(o.description??"")});return e}function Me(t,e,n){let o=De(t);return e.map(r=>{let c=[];for(let s of o){let d=n(r,s);d<=0||c.push({cid:s.cid,logical_id:t.displayNameOf(s.cid),title:s.title,score:Math.round(d*1e3)/1e3,trust:t.trust.get(s.cid)??null,superseded:!1})}return c.sort((s,d)=>d.score-s.score||s.cid.localeCompare(d.cid)),{qid:r.qid,truncated:c.length>r.topK,matches:c.slice(0,r.topK)}})}function Ce(t,e){let n=$e(e);return{results:Me(t,n,(o,r)=>z(o.text,r.title,r.summary,r.description)),scorer:"lexical_fallback"}}function it(t,e){let n=C(e,"text"),o=M(e,"label")??"usecase",r=H(e.k,re,Re),c=[];for(let{cid:s,content:d}of t.byLabel(o)){let m=String(d.title??""),f=String(d.summary??""),u=z(n,m,f);u<=0||c.push({cid:s,title:m,summary:f,score:Math.round(u*1e3)/1e3,trust:t.trust.get(s)??null,freshness:t.stale(s)})}return c.sort((s,d)=>d.score-s.score||s.cid.localeCompare(d.cid)),c.slice(0,r)}function Te(t,e,n){let o=t.heads.get(n);if(typeof o!="string"){let c=[...t.heads.keys()].sort().join(", ");throw new b(`unknown source_id "${n}" \u2014 known: ${c||"(none)"}`)}if(t.mediaOf(o).format==="image")throw new b(`source "${n}" is an image \u2014 no line window (cite img#whole)`);let r=O(e,t,o);if(r==null)throw new b(`source "${n}" blob is missing from the store`);return{head:o,lines:r.toString("utf8").replace(/\n$/,"").split(`
|
|
4
4
|
`)}}function ct(t,e,n){return t.slice(e-1,n).map((o,r)=>`${String(e+r).padStart(4,"0")}| ${o}`).join(`
|
|
5
|
-
`)}function at(t,e,n){let o=
|
|
6
|
-
`)}async function ft(t,e,n){let o=
|
|
7
|
-
`)))}let{vectors:h}=await n.embed(H,[...o.map(l=>l.text),...g]),_=o.map((l,y)=>Float32Array.from(h[y]));for(let l=0;l<u.length;l++){let y=Float32Array.from(h[o.length+l]);f.set(u[l],y),s(n.contextDir,m,u[l],y)}let E=new Map(o.map((l,y)=>[l.qid,y]));return{results:Me(t,o,(l,y)=>{let p=f.get(y.cid),k=p?te(_[E.get(l.qid)],p):0;return ne(k,Q(l.text,y.title,y.summary,y.description),d)}),scorer:"embedding"}}catch{return n.onDegraded?.(),Ce(t,e)}}async function Ie(t,e,n,o){if((e==="search_similar"||e==="search_similar_batch")&&o)try{return{ok:!0,result:e==="search_similar"?await ft(t,n,o):await gt(t,n,o)}}catch(r){return r instanceof b?{ok:!1,error:`${e}: ${r.message}`}:{ok:!1,error:`${e}: graph read failed: ${r instanceof Error?r.message:String(r)}`}}return ut(t,e,n,o?.contextDir)}var pt=2,Ne=10,ht=2;function Ge(t,e,n){return t.map(o=>{let r=e.find(c=>c.id===o.id);if(r&&r.selected_index!=null&&r.selected_index>=0&&r.selected_index<o.options.length){let s=(o.allow_free_text||o.options[r.selected_index]?.input===!0)&&r.free_text!=null?r.free_text:null;return{id:o.id,resolution:"answered",selected_index:r.selected_index,free_text:s}}return r&&r.free_text!=null&&o.allow_free_text?{id:o.id,resolution:"answered",selected_index:-1,free_text:r.free_text}:n.explicitAcceptDefaults?{id:o.id,resolution:"assumed-default",selected_index:o.recommended_index,flagged:!0}:{id:o.id,resolution:"deferred",selected_index:null}})}async function Nt(t,e,n,o,r=()=>{},c){let s=(i,a)=>r(i,a,t.session_id),d=(process.env.ASSURANCE_LOG_LEVEL??"info").toLowerCase()==="debug",m={contextDir:e.contextDir,resolveAlias:i=>he(i,{env:process.env,auth:e.auth}),embed:(i,a)=>_e(i,a,{env:process.env,auth:e.auth}),...e.onEmbedDegraded?{onDegraded:e.onEmbedDegraded}:{}},f=0,u=e.agent(t,{auth:e.auth,onWarn:i=>{s("warn",i),e.out(i)},onStderr:i=>s("agent_stderr",i)}),g=null,h=null,_,E,l=u.send.bind(u),y=new Set(["user_response","user_message","session_complete"]),p=null,k=!1,$=[],v=i=>{if(i.type==="session_complete"&&(k=!0),p!==null&&y.has(i.type)){$.push(i),s("belt_withheld",{type:i.type,unacked_seq:p});return}l(i)};if(t.checkpoints&&!e.checkpoint)throw u.kill(),new Error("run_config.checkpoints is on but DriverDeps.checkpoint sink is absent (programming error)");let C=!1,W=e.pendingDeferral??null,O=!1,je=e.chat?.attachSender?.(i=>v(i));e.initialMessage&&(v({type:"user_message",message_id:`msg-${t.session_id}-${mt(3).toString("hex")}`,text:e.initialMessage}),s("user_message_sent",{chars:e.initialMessage.length,...d?{text:e.initialMessage}:{}}),e.emit?.({type:"message_sent",sid:t.session_id,chars:e.initialMessage.length}),e.chat?.note("\u21B3 delivered to the agent"));let X,F=0,q=0,B=0,Y,R=ye(),N=e.progress??e.out;try{for await(let i of u.events){try{e.chat?.onAgentEvent(i)}catch(a){s("chat_mirror_error",{event_type:i.type,message:a instanceof Error?a.message:String(a)})}if(i.type==="reasoning_delta"?(f+=i.text.length,process.env.KANE_TRACE_REASONING&&s("reasoning_delta",i.text)):i.type==="state_checkpoint"&&!process.env.KANE_TRACE_REASONING?s("state_checkpoint",{seq:i.seq,items:i.delta_items.length,bytes:JSON.stringify(i.delta_items).length}):s(i.type,i),i.type==="reasoning_done"&&s("reasoning_chars",f),i.type==="progress")N(`\u2026 ${i.stage}${i.n?` #${i.n}`:""}`),e.emit?.({type:"agent_activity",kind:"progress",label:`${i.stage}${i.n?` #${i.n}`:""}`});else if(i.type==="reasoning_delta"||i.type==="reasoning_done"||i.type==="tool_activity"||i.type==="decision_activity"){e.onStreamEvent?.(i);let a=R;if(R=we(R,i),R===a)continue;i.type==="reasoning_delta"?R.liveThinking===i.text&&N("\u2237 thinking\u2026"):i.type==="reasoning_done"?i.present&&(N(`thought for ${(i.took_ms/1e3).toFixed(1)}s`),e.emit?.({type:"agent_activity",kind:"thinking_done",label:`thought for ${(i.took_ms/1e3).toFixed(1)}s`})):i.type==="tool_activity"?i.status!=="done"&&(N(R.activity[R.activity.length-1].label),e.emit?.({type:"agent_activity",kind:"tool",label:R.activity[R.activity.length-1].label})):(N(`\xB7 ${R.activity[R.activity.length-1].label}`),e.emit?.({type:"agent_activity",kind:"decision",label:R.activity[R.activity.length-1].label}))}else if(i.type==="usage"){Y=i.total_credits;let a=S=>Math.round(S*100)/100;e.emit?.({type:"usage",credits:a(i.credits),total_credits:a(i.total_credits)})}else if(i.type==="graph_query"){let a=await Ie(e.graphSlot?.current??o,i.method,i.params??{},m),S=a.ok?{type:"graph_result",id:i.id,ok:!0,result:a.result}:{type:"graph_result",id:i.id,ok:!1,error:a.error};s("graph_result",d?{id:i.id,method:i.method,ok:a.ok,result:a.ok?a.result:a.error}:{id:i.id,method:i.method,ok:a.ok}),v(S)}else if(i.type==="ingest_request")if(e.ingest){let a;try{a=await e.ingest({id:i.id,ref:i.ref,purpose:i.purpose??null})}catch(T){s("ingest_executor_threw",{id:i.id,error:T instanceof Error?T.message:String(T)}),a={ok:!1,error:{code:"INGEST_FAILED",message:"the landing failed \u2014 see the trace for detail"}}}let S=a.ok?{type:"ingest_result",id:i.id,ok:!0,result:a.result}:{type:"ingest_result",id:i.id,ok:!1,error:a.error};s("ingest_result",a.ok?{id:i.id,ok:!0,source_id:a.result.source_id}:{id:i.id,ok:!1,code:a.error.code}),v(S)}else{let a={type:"ingest_result",id:i.id,ok:!1,error:{code:"INGEST_UNAVAILABLE",message:"this session has no ingest executor"}};s("ingest_result",{id:i.id,ok:!1,code:a.error.code}),v(a)}else if(i.type==="state_checkpoint"){if(!e.checkpoint)throw new Error("state_checkpoint arrived with no checkpoint sink (programming error)");p=i.seq;try{for(e.checkpoint.persist(i),p=null,l({type:"checkpoint_ack",seq:i.seq}),s("checkpoint_acked",{seq:i.seq,at:i.at});$.length>0&&p===null;)v($.shift())}catch(a){let S=a instanceof Error?a.message:String(a);C||(C=!0,e.out("warning: couldn't save the session checkpoint \u2014 pausing so no work is lost")),s("checkpoint_persist_failed",{seq:i.seq,message:S}),l({type:"pause"})}}else if(i.type==="session_paused")O=!0,E=i;else if(i.type==="done")O=!0;else if(i.type==="ask_user"){i.text&&(e.chat?e.chat.ledger({kind:"agent",text:i.text}):e.out(i.text),e.emit?.({type:"agent_message",text:i.text}));let a=t.mode;if(W){let w=W;W=null,e.emit?.({type:"ask_deferred",source_id:w.ingested.source_id,cid:w.ingested.cid,questions:i.questions.length}),s("ask_deferred",{source_id:w.ingested.source_id,questions:i.questions.length}),v({type:"user_response",answers:[],deferral:{deferred:!0,ingested:w.ingested}});continue}if(a!=="interactive"){let w=i.questions.filter(x=>x.risk==="high");if(a==="ci"&&w.length>0){X=w,u.kill();break}if(a==="agent"&&w.length>0){s("pause_requested",{high:w.map(x=>x.id)}),v({type:"pause"});continue}let A=Ge(i.questions,[],{explicitAcceptDefaults:!0});F+=A.length;for(let x of A)s("assumed_default",{id:x.id,resolution:x.resolution}),e.emit?.({type:"assumed_default",id:x.id,selected_index:x.selected_index,risk:i.questions.find(V=>V.id===x.id)?.risk});let j={type:"user_response",answers:A.map(x=>({id:x.id,selected_index:x.resolution==="deferred"?null:x.selected_index,free_text:null}))};v(j);continue}let S=await e.ask(i.questions);if(!Array.isArray(S)){v({type:"user_response",answers:[],deferral:S});continue}let T=S,Pe=Ge(i.questions,T,{explicitAcceptDefaults:!1}),He={type:"user_response",answers:i.questions.map(w=>{let A=T.find(x=>x.id===w.id);if(A?.free_text!=null){let x=A.selected_index!=null&&A.selected_index>=0&&A.selected_index<w.options.length?A.selected_index:null;if(x!=null){let G=w.allow_free_text||w.options[x]?.input===!0;return G&&A.free_text!=null&&n.set(w.id,(n.get(w.id)??0)+1),{id:w.id,selected_index:x,free_text:G?A.free_text:null}}let V=n.get(w.id)??0;if(!w.allow_free_text||V>=pt){let G=w.options[w.recommended_index]?.label??"recommended option";if(F+=1,e.emit?.({type:"assumed_default",id:w.id,selected_index:w.recommended_index,risk:w.risk}),e.chat?.noteCoercion)e.chat.noteCoercion(w,G);else{let J=w.text.replace(/\?+\s*$/,""),Ue=J.length<=36?J:`${J.slice(0,33)}\u2026`;e.out(`note: couldn't use a typed answer for "${Ue}" \u2014 kept the recommended option (${G})`)}return{id:w.id,selected_index:w.recommended_index,free_text:null}}return n.set(w.id,V+1),{id:w.id,selected_index:null,free_text:A.free_text}}let j=Pe.find(x=>x.id===w.id);return j.resolution==="deferred"?{id:w.id,selected_index:null,free_text:null}:{id:w.id,selected_index:j.selected_index,free_text:null}})};v(He)}else if(i.type==="chat_ops"&&!e.chat){let a=i.chat_ops??i,S=Array.isArray(a.ops)?a.ops.length:0;if(S===0)a.text&&(e.out(a.text),e.emit?.({type:"agent_message",text:a.text})),v({type:"session_complete"}),s("headless_zero_op_chat_turn_complete",{chars:a.text?.length??0});else if(B<ht)B+=1,v({type:"user_message",message_id:`nochat-${t.session_id}-${B}`,text:"[auto-repair] chat ops are unavailable in this mode \u2014 commit through finalize_design, or finish if nothing remains."}),s("headless_chat_ops_nudge",{n:B,ops:S});else{h="the agent kept trying to hold a conversation in a non-interactive run",e.out("error: the agent kept trying to hold a conversation in a non-interactive run \u2014 session closed; re-run interactively, or retry"),s("headless_chat_ops_terminal",{ops:S}),u.kill();break}}else if(i.type===(c.terminalEventType??"proposal")){let a=await c.onProposalEvent(i[i.type]);if(g=a.proposal,a.error&&(h=a.error),a.receipt)e.emit?.(a.receipt.event),t.mode!=="interactive"?(q+=1,a.sessionComplete||q>=Ne?(a.sessionComplete||(e.out(`warning: ${Ne} commits without completion \u2014 closing the session (runaway guard)`),s("receipt_runaway_cap",{commits:q})),v({type:"session_complete"}),s("session_complete_sent",{commit_n:a.receipt.event.commit_n,runaway:!a.sessionComplete})):(v({type:"user_message",message_id:`receipt-${t.session_id}-${String(a.receipt.event.commit_n??0)}`,text:a.receipt.text}),s("receipt_sent",{commit_n:a.receipt.event.commit_n,chars:a.receipt.text.length}))):e.chat?.holdReceipt&&(e.chat.holdReceipt(a.receipt.text),s("receipt_held",{commit_n:a.receipt.event.commit_n}));else if(a.error&&t.mode!=="interactive"){e.out("error: saving the agent's work failed and can't be retried in this mode \u2014 session closed; re-run to retry"),e.emit?.({type:"warning",code:"SAVE_FAILED",message:"saving the agent's work failed and can't be retried in this mode \u2014 session closed; re-run to retry"}),s("headless_commit_error_terminal",{error:a.error}),u.kill();break}}else if(i.type==="error"){O=!0;let a=i;if(a.code==="PAIR_MISMATCH")throw new pe(a.expected??"",a.actual??"");h=i.message,typeof a.code=="string"&&(_=a.code);let S=i.failed_proposal;S&&s("failed_proposal",S)}}}finally{u.kill(),je?.()}let Ve=t.chat===!0&&t.mode==="interactive",ce=!!e.checkpoint&&!O&&!k&&!E&&!X&&h===null&&g===null&&!Ve;return{proposal:g,error:h,..._!==void 0?{errorCode:_}:{},paused:E,highRisk:X,...F>0?{assumedDefaults:F}:{},...Y!==void 0?{creditsTotal:Y}:{},...ce?{crashed:ce}:{}}}function Le(t,e){let n=e.trim(),o=null;for(let r of t??[])if(r.ref===n){if(!r.consumed)return{kind:"unconsumed"};o={kind:"consumed",identity:r.consumed}}return o??{kind:"unauthorized"}}function Lt(t,e,n){let o=e.trim(),r=[...t??[]];return r.find(s=>s.ref===o&&!s.consumed)||r.push({ref:o,entered_at:n.toISOString()}),r}function Oe(t,e,n){let o=e.trim(),r=[...t??[]],c=r.findIndex(s=>s.ref===o&&!s.consumed);return c<0||(r[c]={...r[c],consumed:n}),r}import{basename as K}from"path";function Fe(t,e,n,o,r){let c=e.mediaOf(o),s=0;if(c.format!=="image"){let d=L(t,e,o);d&&(s=d.toString("utf8").replace(/\n$/,"").split(`
|
|
8
|
-
`).length)}return{source_id:n,cid:o,total_lines:s,media_type:c.format,status:r}}function Ht(t){return async e=>{let n=Le(t.handle.state.ingest_registry,e.ref);if(n.kind==="unauthorized")return{ok:!1,error:{code:"INGEST_UNAUTHORIZED_REF",message:"that ref was not provided by the owner this session \u2014 only owner-provided refs may land"}};if(n.kind==="consumed"){let _=t.graphSlot?.current??
|
|
9
|
-
`)){try{let n=
|
|
5
|
+
`)}function at(t,e,n){let o=C(e,"source_id"),r=M(e,"anchor"),c=e.line_range;if(r!=null&&c!=null)throw new b("give anchor OR line_range, not both");let{head:s,lines:d}=Te(t,n,o),m=d.length,f,u;if(r!=null){let g=/^L(\d+)-L(\d+)$/.exec(r);if(!g)throw new b(`anchor "${r}" is not L<a>-L<b>`);let h=Number(g[1]),_=Number(g[2]);if(h<1||_<h||_>m)throw new b(`anchor "${r}" does not resolve (source has ${m} lines)`);f=Math.max(1,h-be),u=Math.min(m,_+be)}else if(c!=null){if(!Array.isArray(c)||c.length!==2||!c.every(_=>Number.isInteger(_)))throw new b('param "line_range" must be [from_line, to_line]');let[g,h]=c;if(g<1||h<g)throw new b('param "line_range" must be 1-based with from \u2264 to');if(g>m)throw new b(`line_range starts past the end (source has ${m} lines)`);f=g,u=Math.min(h,m)}else f=1,u=m;return u=Math.min(u,f+We-1),{window:ct(d,f,u),from_line:f,to_line:u,source_cid:s,total_lines:m}}function lt(t,e,n){let o=C(e,"pattern"),r=M(e,"source_id"),c;try{c=new RegExp(o,"u")}catch(f){throw new b(`invalid pattern: ${f instanceof Error?f.message:String(f)}`)}let s=r!=null?[r]:[...t.heads.keys()].sort(),d=[],m=!1;e:for(let f of s){if(r==null){let g=t.heads.get(f);if(typeof g!="string"||t.mediaOf(g).format==="image")continue}let{lines:u}=Te(t,n,f);for(let g=0;g<u.length;g++)if(c.test(u[g])){if(d.length>=Xe){m=!0;break e}d.push({source_id:f,line:g+1,text:u[g]})}}return{matches:d,truncated:m}}function ut(t,e,n,o){try{switch(e){case"get_node":{let r=oe(t,C(n,"cid"));return r==null?{ok:!0,result:null}:{ok:!0,result:Ae([r],n)[0]}}case"get_edges":return{ok:!0,result:et(t,n)};case"find_by_provenance":return{ok:!0,result:tt(t,n)};case"match_by_type":return{ok:!0,result:nt(t,n)};case"stale_nodes":return{ok:!0,result:rt(t,n)};case"search_similar":return{ok:!0,result:it(t,n)};case"search_similar_batch":return{ok:!0,result:Ce(t,n)};case"history":{if(o==null)throw new b("history unavailable (no context store)");return{ok:!0,result:ot(t,n,o)}}case"source_list":{if(o==null)throw new b("source roster unavailable (no context store)");return{ok:!0,result:st(t,n,o)}}case"source_read":case"source_grep":{if(o==null)throw new b("source text unavailable (no context store)");return{ok:!0,result:(e==="source_read"?at:lt)(t,n,o)}}default:return{ok:!1,error:`unknown method: ${e} \u2014 available: ${Ke.join(", ")}`}}}catch(r){return r instanceof b?{ok:!1,error:`${e}: ${r.message}`}:{ok:!1,error:`${e}: graph read failed: ${r instanceof Error?r.message:String(r)}`}}}var P="assurance.sim";function dt(t){return[t.title,t.summary,t.description].filter(Boolean).join(`
|
|
6
|
+
`)}async function ft(t,e,n){let o=C(e,"text"),r=M(e,"label")??"usecase",c=H(e.k,re,Re),s=[];for(let{cid:m,content:f}of t.byLabel(r)){if(t.superseded.has(m))continue;let u=String(f.title??""),g=String(f.summary??""),h=String(f.description??"");s.push({cid:m,title:u,summary:g,description:h,lex:z(o,u,g,h)})}let d=m=>{let f=[];for(let u of s){let g=m(u);g.score<=0||f.push({cid:u.cid,title:u.title,summary:u.summary,score:Math.round(g.score*1e3)/1e3,trust:t.trust.get(u.cid)??null,freshness:t.stale(u.cid),...g.dense!==void 0?{dense_score:Math.round(g.dense*1e3)/1e3,lexical_score:Math.round(u.lex*1e3)/1e3}:{}})}return f.sort((u,g)=>g.score-u.score||u.cid.localeCompare(g.cid)),f.slice(0,c)};try{let m=n.readVector??J,f=n.writeVector??Z,u=n.alpha??ne,{alias:g}=await n.resolveAlias(P),h=new Map,_=[],E=[];for(let p of s){let k=m(n.contextDir,g,p.cid);k?h.set(p.cid,k):(_.push(p.cid),E.push(dt(p)))}let{vectors:l}=await n.embed(P,[o,...E]),y=Float32Array.from(l[0]);for(let p=0;p<_.length;p++){let k=Float32Array.from(l[p+1]);h.set(_[p],k),f(n.contextDir,g,_[p],k)}return d(p=>{let k=h.get(p.cid),$=k?ee(y,k):0;return{score:te($,p.lex,u),dense:$}})}catch{return n.onDegraded?.(),d(m=>({score:m.lex}))}}async function gt(t,e,n){let o=$e(e),r=De(t);try{let c=n.readVector??J,s=n.writeVector??Z,d=n.alpha??ne,{alias:m}=await n.resolveAlias(P),f=new Map,u=[],g=[];for(let l of r){let y=c(n.contextDir,m,l.cid);y?f.set(l.cid,y):(u.push(l.cid),g.push([l.title,l.summary,l.description].filter(Boolean).join(`
|
|
7
|
+
`)))}let{vectors:h}=await n.embed(P,[...o.map(l=>l.text),...g]),_=o.map((l,y)=>Float32Array.from(h[y]));for(let l=0;l<u.length;l++){let y=Float32Array.from(h[o.length+l]);f.set(u[l],y),s(n.contextDir,m,u[l],y)}let E=new Map(o.map((l,y)=>[l.qid,y]));return{results:Me(t,o,(l,y)=>{let p=f.get(y.cid),k=p?ee(_[E.get(l.qid)],p):0;return te(k,z(l.text,y.title,y.summary,y.description),d)}),scorer:"embedding"}}catch{return n.onDegraded?.(),Ce(t,e)}}async function Ie(t,e,n,o){if((e==="search_similar"||e==="search_similar_batch")&&o)try{return{ok:!0,result:e==="search_similar"?await ft(t,n,o):await gt(t,n,o)}}catch(r){return r instanceof b?{ok:!1,error:`${e}: ${r.message}`}:{ok:!1,error:`${e}: graph read failed: ${r instanceof Error?r.message:String(r)}`}}return ut(t,e,n,o?.contextDir)}var pt=2,Ne=10,ht=2;function Ge(t,e,n){return t.map(o=>{let r=e.find(c=>c.id===o.id);if(r&&r.selected_index!=null&&r.selected_index>=0&&r.selected_index<o.options.length){let s=(o.allow_free_text||o.options[r.selected_index]?.input===!0)&&r.free_text!=null?r.free_text:null;return{id:o.id,resolution:"answered",selected_index:r.selected_index,free_text:s}}return r&&r.free_text!=null&&o.allow_free_text?{id:o.id,resolution:"answered",selected_index:-1,free_text:r.free_text}:n.explicitAcceptDefaults?{id:o.id,resolution:"assumed-default",selected_index:o.recommended_index,flagged:!0}:{id:o.id,resolution:"deferred",selected_index:null}})}async function Nt(t,e,n,o,r=()=>{},c){let s=(i,a)=>r(i,a,t.session_id),d=(process.env.ASSURANCE_LOG_LEVEL??"info").toLowerCase()==="debug",m={contextDir:e.contextDir,resolveAlias:i=>he(i,{env:process.env,auth:e.auth}),embed:(i,a)=>_e(i,a,{env:process.env,auth:e.auth}),...e.onEmbedDegraded?{onDegraded:e.onEmbedDegraded}:{}},f=0,u=e.agent(t,{auth:e.auth,onWarn:i=>{s("warn",i),e.out(i)},onStderr:i=>s("agent_stderr",i)}),g=null,h=null,_,E,l=u.send.bind(u),y=new Set(["user_response","user_message","session_complete"]),p=null,k=!1,$=[],x=i=>{if(i.type==="session_complete"&&(k=!0),p!==null&&y.has(i.type)){$.push(i),s("belt_withheld",{type:i.type,unacked_seq:p});return}l(i)};if(t.checkpoints&&!e.checkpoint)throw u.kill(),new Error("run_config.checkpoints is on but DriverDeps.checkpoint sink is absent (programming error)");let T=!1,K=e.pendingDeferral??null,F=!1,je=e.chat?.attachSender?.(i=>x(i));e.initialMessage&&(x({type:"user_message",message_id:`msg-${t.session_id}-${mt(3).toString("hex")}`,text:e.initialMessage}),s("user_message_sent",{chars:e.initialMessage.length,...d?{text:e.initialMessage}:{}}),e.emit?.({type:"message_sent",sid:t.session_id,chars:e.initialMessage.length}),e.chat?.note("\u21B3 delivered to the agent"));let W,B=0,X=0,j=0,q,R=ye(),G=e.progress??e.out;try{for await(let i of u.events){try{e.chat?.onAgentEvent(i)}catch(a){s("chat_mirror_error",{event_type:i.type,message:a instanceof Error?a.message:String(a)})}if(i.type==="reasoning_delta"?(f+=i.text.length,process.env.KANE_TRACE_REASONING&&s("reasoning_delta",i.text)):i.type==="state_checkpoint"&&!process.env.KANE_TRACE_REASONING?s("state_checkpoint",{seq:i.seq,items:i.delta_items.length,bytes:JSON.stringify(i.delta_items).length}):s(i.type,i),i.type==="reasoning_done"&&s("reasoning_chars",f),i.type==="progress")G(`\u2026 ${i.stage}${i.n?` #${i.n}`:""}`),e.emit?.({type:"agent_activity",kind:"progress",label:`${i.stage}${i.n?` #${i.n}`:""}`});else if(i.type==="reasoning_delta"||i.type==="reasoning_done"||i.type==="tool_activity"||i.type==="decision_activity"){e.onStreamEvent?.(i);let a=R;if(R=we(R,i),R===a)continue;i.type==="reasoning_delta"?R.liveThinking===i.text&&G("\u2237 thinking\u2026"):i.type==="reasoning_done"?i.present&&(G(`thought for ${(i.took_ms/1e3).toFixed(1)}s`),e.emit?.({type:"agent_activity",kind:"thinking_done",label:`thought for ${(i.took_ms/1e3).toFixed(1)}s`})):i.type==="tool_activity"?i.status!=="done"&&(G(R.activity[R.activity.length-1].label),e.emit?.({type:"agent_activity",kind:"tool",label:R.activity[R.activity.length-1].label})):(G(`\xB7 ${R.activity[R.activity.length-1].label}`),e.emit?.({type:"agent_activity",kind:"decision",label:R.activity[R.activity.length-1].label}))}else if(i.type==="usage"){q=i.total_credits;let a=v=>Math.round(v*100)/100;e.emit?.({type:"usage",credits:a(i.credits),total_credits:a(i.total_credits)})}else if(i.type==="graph_query"){let a=await Ie(e.graphSlot?.current??o,i.method,i.params??{},m),v=a.ok?{type:"graph_result",id:i.id,ok:!0,result:a.result}:{type:"graph_result",id:i.id,ok:!1,error:a.error};s("graph_result",d?{id:i.id,method:i.method,ok:a.ok,result:a.ok?a.result:a.error}:{id:i.id,method:i.method,ok:a.ok}),x(v)}else if(i.type==="ingest_request")if(e.ingest){let a;try{a=await e.ingest({id:i.id,ref:i.ref,purpose:i.purpose??null})}catch(I){s("ingest_executor_threw",{id:i.id,error:I instanceof Error?I.message:String(I)}),a={ok:!1,error:{code:"INGEST_FAILED",message:"the landing failed \u2014 see the trace for detail"}}}let v=a.ok?{type:"ingest_result",id:i.id,ok:!0,result:a.result}:{type:"ingest_result",id:i.id,ok:!1,error:a.error};s("ingest_result",a.ok?{id:i.id,ok:!0,source_id:a.result.source_id}:{id:i.id,ok:!1,code:a.error.code}),x(v)}else{let a={type:"ingest_result",id:i.id,ok:!1,error:{code:"INGEST_UNAVAILABLE",message:"this session has no ingest executor"}};s("ingest_result",{id:i.id,ok:!1,code:a.error.code}),x(a)}else if(i.type==="state_checkpoint"){if(!e.checkpoint)throw new Error("state_checkpoint arrived with no checkpoint sink (programming error)");p=i.seq;try{for(e.checkpoint.persist(i),p=null,l({type:"checkpoint_ack",seq:i.seq}),s("checkpoint_acked",{seq:i.seq,at:i.at});$.length>0&&p===null;)x($.shift())}catch(a){let v=a instanceof Error?a.message:String(a);T||(T=!0,e.out("warning: couldn't save the session checkpoint \u2014 pausing so no work is lost")),s("checkpoint_persist_failed",{seq:i.seq,message:v}),l({type:"pause"})}}else if(i.type==="session_paused")F=!0,E=i;else if(i.type==="done")F=!0;else if(i.type==="ask_user"){i.text&&(e.chat?e.chat.ledger({kind:"agent",text:i.text}):e.out(i.text),e.emit?.({type:"agent_message",text:i.text}));let a=t.mode;if(K){let w=K;K=null,e.emit?.({type:"ask_deferred",source_id:w.ingested.source_id,cid:w.ingested.cid,questions:i.questions.length}),s("ask_deferred",{source_id:w.ingested.source_id,questions:i.questions.length}),x({type:"user_response",answers:[],deferral:{deferred:!0,ingested:w.ingested}});continue}if(a!=="interactive"){if(a==="agent"){s("pause_requested",{questions:i.questions.map(S=>S.id)}),x({type:"pause"});continue}if(a==="ci"){let S=i.questions.filter(A=>A.risk==="high");if(S.length>0){W=S,u.kill();break}}let w=Ge(i.questions,[],{explicitAcceptDefaults:!0});B+=w.length;for(let S of w)s("assumed_default",{id:S.id,resolution:S.resolution}),e.emit?.({type:"assumed_default",id:S.id,selected_index:S.selected_index,risk:i.questions.find(A=>A.id===S.id)?.risk});let D={type:"user_response",answers:w.map(S=>({id:S.id,selected_index:S.resolution==="deferred"?null:S.selected_index,free_text:null}))};x(D);continue}let v=await e.ask(i.questions);if(!Array.isArray(v)){x({type:"user_response",answers:[],deferral:v});continue}let I=v,Pe=Ge(i.questions,I,{explicitAcceptDefaults:!1}),He={type:"user_response",answers:i.questions.map(w=>{let D=I.find(A=>A.id===w.id);if(D?.free_text!=null){let A=D.selected_index!=null&&D.selected_index>=0&&D.selected_index<w.options.length?D.selected_index:null;if(A!=null){let L=w.allow_free_text||w.options[A]?.input===!0;return L&&D.free_text!=null&&n.set(w.id,(n.get(w.id)??0)+1),{id:w.id,selected_index:A,free_text:L?D.free_text:null}}let ce=n.get(w.id)??0;if(!w.allow_free_text||ce>=pt){let L=w.options[w.recommended_index]?.label??"recommended option";if(B+=1,e.emit?.({type:"assumed_default",id:w.id,selected_index:w.recommended_index,risk:w.risk}),e.chat?.noteCoercion)e.chat.noteCoercion(w,L);else{let Y=w.text.replace(/\?+\s*$/,""),Ue=Y.length<=36?Y:`${Y.slice(0,33)}\u2026`;e.out(`note: couldn't use a typed answer for "${Ue}" \u2014 kept the recommended option (${L})`)}return{id:w.id,selected_index:w.recommended_index,free_text:null}}return n.set(w.id,ce+1),{id:w.id,selected_index:null,free_text:D.free_text}}let S=Pe.find(A=>A.id===w.id);return S.resolution==="deferred"?{id:w.id,selected_index:null,free_text:null}:{id:w.id,selected_index:S.selected_index,free_text:null}})};x(He)}else if(i.type==="chat_ops"&&!e.chat){let a=i.chat_ops??i,v=Array.isArray(a.ops)?a.ops.length:0;if(v===0)a.text&&(e.out(a.text),e.emit?.({type:"agent_message",text:a.text})),x({type:"session_complete"}),s("headless_zero_op_chat_turn_complete",{chars:a.text?.length??0});else if(j<ht)j+=1,x({type:"user_message",message_id:`nochat-${t.session_id}-${j}`,text:"[auto-repair] chat ops are unavailable in this mode \u2014 commit through finalize_design, or finish if nothing remains."}),s("headless_chat_ops_nudge",{n:j,ops:v});else{h="the agent kept trying to hold a conversation in a non-interactive run",e.out("error: the agent kept trying to hold a conversation in a non-interactive run \u2014 session closed; re-run interactively, or retry"),s("headless_chat_ops_terminal",{ops:v}),u.kill();break}}else if(i.type===(c.terminalEventType??"proposal")){let a=await c.onProposalEvent(i[i.type]);if(g=a.proposal,a.error&&(h=a.error),a.receipt)e.emit?.(a.receipt.event),t.mode!=="interactive"?(X+=1,a.sessionComplete||X>=Ne?(a.sessionComplete||(e.out(`warning: ${Ne} commits without completion \u2014 closing the session (runaway guard)`),s("receipt_runaway_cap",{commits:X})),x({type:"session_complete"}),s("session_complete_sent",{commit_n:a.receipt.event.commit_n,runaway:!a.sessionComplete})):(x({type:"user_message",message_id:`receipt-${t.session_id}-${String(a.receipt.event.commit_n??0)}`,text:a.receipt.text}),s("receipt_sent",{commit_n:a.receipt.event.commit_n,chars:a.receipt.text.length}))):e.chat?.holdReceipt&&(e.chat.holdReceipt(a.receipt.text),s("receipt_held",{commit_n:a.receipt.event.commit_n}));else if(a.error&&t.mode!=="interactive"){e.out("error: saving the agent's work failed and can't be retried in this mode \u2014 session closed; re-run to retry"),e.emit?.({type:"warning",code:"SAVE_FAILED",message:"saving the agent's work failed and can't be retried in this mode \u2014 session closed; re-run to retry"}),s("headless_commit_error_terminal",{error:a.error}),u.kill();break}}else if(i.type==="error"){F=!0;let a=i;if(a.code==="PAIR_MISMATCH")throw new pe(a.expected??"",a.actual??"");h=i.message,typeof a.code=="string"&&(_=a.code);let v=i.failed_proposal;v&&s("failed_proposal",v)}}}finally{u.kill(),je?.()}let Ve=t.chat===!0&&t.mode==="interactive",ie=!!e.checkpoint&&!F&&!k&&!E&&!W&&h===null&&g===null&&!Ve;return{proposal:g,error:h,..._!==void 0?{errorCode:_}:{},paused:E,highRisk:W,...B>0?{assumedDefaults:B}:{},...q!==void 0?{creditsTotal:q}:{},...ie?{crashed:ie}:{}}}function Le(t,e){let n=e.trim(),o=null;for(let r of t??[])if(r.ref===n){if(!r.consumed)return{kind:"unconsumed"};o={kind:"consumed",identity:r.consumed}}return o??{kind:"unauthorized"}}function Lt(t,e,n){let o=e.trim(),r=[...t??[]];return r.find(s=>s.ref===o&&!s.consumed)||r.push({ref:o,entered_at:n.toISOString()}),r}function Oe(t,e,n){let o=e.trim(),r=[...t??[]],c=r.findIndex(s=>s.ref===o&&!s.consumed);return c<0||(r[c]={...r[c],consumed:n}),r}import{basename as Q}from"path";function Fe(t,e,n,o,r){let c=e.mediaOf(o),s=0;if(c.format!=="image"){let d=O(t,e,o);d&&(s=d.toString("utf8").replace(/\n$/,"").split(`
|
|
8
|
+
`).length)}return{source_id:n,cid:o,total_lines:s,media_type:c.format,status:r}}function Ht(t){return async e=>{let n=Le(t.handle.state.ingest_registry,e.ref);if(n.kind==="unauthorized")return{ok:!1,error:{code:"INGEST_UNAUTHORIZED_REF",message:"that ref was not provided by the owner this session \u2014 only owner-provided refs may land"}};if(n.kind==="consumed"){let _=t.graphSlot?.current??N(t.contextDir);return{ok:!0,result:Fe(t.contextDir,_,n.identity.source_id,n.identity.cid,"unchanged")}}let o=[],r={out:_=>o.push(_),err:_=>o.push(_),confirm:async()=>!1,isTTY:!1},c;try{c=await ke([e.ref],{},r,t.cwd,t.remoteDeps)}catch(_){return{ok:!1,error:{code:"INGEST_FAILED",message:_ instanceof Error?_.message:String(_)}}}if(c.code!==0||c.results.length===0)return{ok:!1,error:{code:"INGEST_FAILED",message:o.find(E=>E.startsWith("error:"))??o.at(-1)??"the landing failed"}};let s=c.results[0],d={source_id:s.source_id,cid:s.source_cid},m=Oe(t.handle.state.ingest_registry,e.ref,d),f=s.status==="versioned"&&t.schedule,u=t.schedule?[...t.handle.state.ingest_schedule??[],f?{source_id:s.source_id,cid:s.source_cid,status:"skipped",note:"new version of a known source \u2014 its changes await your review (reconcile), never a blind re-extraction"}:{source_id:s.source_id,cid:s.source_cid,status:"pending"}]:void 0;t.handle.save({ingest_registry:m,...u!==void 0?{ingest_schedule:u}:{}}),t.graphSlot&&(t.graphSlot.current=N(t.contextDir));let g=t.graphSlot?.current??N(t.contextDir),h=Fe(t.contextDir,g,s.source_id,s.source_cid,s.status==="unchanged"?"unchanged":"landed");return t.note(f?`landed ${s.source_id} (${Q(e.ref)}) \u2014 ${h.total_lines} lines; a NEW VERSION of a known source \u2014 its changes await your review (the check-in offers it), not a blind re-extraction`:t.schedule?`landed ${s.source_id} (${Q(e.ref)}) \u2014 ${h.total_lines} lines; scheduled for extraction in this run`:t.scheduleRefused?`landed ${s.source_id} (${Q(e.ref)}) \u2014 ${h.total_lines} lines; ${t.scheduleRefused}`:`landed ${s.source_id} (${Q(e.ref)}) \u2014 ${h.total_lines} lines; it guides this design only (not extracted \u2014 its own extraction pass adds its use-cases)`),{ok:!0,result:h}}}var _t=3,yt={edit:"edit",reject:"mistake",dedup_dropped:"mistake",approve:"usage",enhance:"directed-edit",add:"directed-edit",default_accepted:"usage",default_overridden:"edit",gap_resolution:"usage",dedup_kept:"usage"};function Be(t){let{contextDir:e,graph:n,watermark:o,by:r}=t,{signals:c}=V(e,o),s=c.filter(l=>l.event_id===void 0||n.appliedEvents.has(l.event_id)),d=new Map;for(let l of s){let y=l.event_id??`${l.ts}|${l.id}|${l.verdict}|${l.polarity}`;d.has(`${y}|${l.polarity}|${l.verdict}`)||d.set(`${y}|${l.polarity}|${l.verdict}`,l)}let m=[...d.values()].sort((l,y)=>(l.event_id??l.ts)<(y.event_id??y.ts)?-1:1),f=new Map;for(let l of m){let y=`${l.verdict}|${l.tag??""}`,p=f.get(y)??{verdict:l.verdict,tag:l.tag,events:new Set};p.events.add(l.event_id??l.ts),f.set(y,p)}let u=[],g=[],h=new Set,_=0;for(let[,l]of[...f.entries()].sort(([y],[p])=>y<p?-1:1)){if(l.events.size<_t)continue;let p={derived:!0,statement:`${l.verdict}${l.tag?`/${l.tag}`:""} recurs (${l.events.size} distinct events) \u2014 bias future proposals ${l.verdict==="approve"?"toward":"away from"} this pattern`,learned_from_kind:yt[l.verdict]??"usage",learned_from:[...l.events].sort()},k=le("stylenote",p);if(k.length>0)return{record:null,errors:k.map(T=>({code:T.code,detail:T.detail})),minted:0};let $=ue("stylenote",p);if(n.hasNode($))continue;u.push({cid:$,label:ae.STYLENOTE,content:p});let x=me("stylenote",T=>h.has(T),n.names.keys());x!==null&&(h.add(x),g.push({cid:$,slug:x,by:r})),_+=1}return u.length===0?{record:null,errors:null,minted:0}:{record:fe(e,{ts:new Date().toISOString(),proposal_id:null,nodes:u,edges:[],review:[],supersessions:[],source_head_moves:{},...g.length>0?{names:g}:{}},{expectPrev:n.latestHash}).record,errors:null,minted:_}}var wt={kind:"system",id:"distiller"};function tn(t,e=n=>process.stderr.write(n+`
|
|
9
|
+
`)){try{let n=N(t),{watermark:o}=V(t),r=Be({contextDir:t,graph:n,watermark:o,by:wt});if(r.errors){let c=r.errors.map(s=>`${s.code}: ${s.detail}`).join("; ");return e(`warning: style-note distill skipped \u2014 ${c}`),{minted:0,error:c}}if(r.minted>0)try{ge(t)}catch{}return{minted:r.minted,error:null}}catch(n){let o=n instanceof Error?n.message:String(n);return e(`warning: style-note distill skipped \u2014 ${o}`),{minted:0,error:o}}}export{bt as a,Ie as b,pt as c,Ge as d,Nt as e,Lt as f,Ht as g,tn as h};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { createRequire } from 'module'; const require = createRequire(import.meta.url);
|
|
2
|
-
import{a as w,b as O}from"./chunk-
|
|
2
|
+
import{a as w,b as O}from"./chunk-4PMZ5FCD.js";import{a as I}from"./chunk-KBM3XHAM.js";import{e as L}from"./chunk-IDX3TOPY.js";import{a as N,b as k}from"./chunk-BKM2LWU2.js";import{a as R,b as y,c as T,d as m,e as A,g as b,h as r}from"./chunk-RSSOJ3L2.js";import{b as x}from"./chunk-5EOX4MEY.js";import{a as E}from"./chunk-RZ4F3BHX.js";import{a as g,i as v}from"./chunk-DWHXXPDX.js";import{platform as X,arch as Y}from"os";import P from"fs";import M from"fs";import D from"path";var V=1e3,d=0,j=new Set([130,3]),a=class t{ids;logger;opts;ended=!1;createdAt=Date.now();errorState;constructor(e,n={emitted:!1}){this.ids=e.envelope,this.logger=e.logger,this.opts=e,this.errorState=n}get enabled(){return this.logger!==null}event(e,n={}){if(!this.logger)return;e==="ASR_ERROR"&&(this.errorState.emitted=!0);let i=m(this.ids,e,n);this.logger.log(R[e],e,e,C(i))}error(e,n={}){this.logger&&(this.logger.escalate(d),this.event("ASR_ERROR",{...n,error_code:e}))}child(e,n){return new t({...this.opts,envelope:{...this.ids,operation_id:n,parent_operation_id:this.ids.operation_id,verb:"design"}},this.errorState)}async lateBindContext(e){if(!(!this.logger||this.ids.context_instance_id))try{let{ensureStoreIds:n}=await import("./store-id-EOSGEKVK.js"),{ids:i,cloned:s}=n(e);this.ids.context_lineage_id=i.context_lineage_id,this.ids.context_instance_id=i.context_instance_id,s&&this.event("ASR_CONTEXT_CLONED")}catch{}}agentSession(e){this.ids.agent_session_id=e}spawnEnv(){if(!this.opts.telemetryEnabled)return{};let e={TESTMUAI_USER_SESSION_ID:this.ids.session_id,TESTMUAI_OPERATION_ID:this.ids.operation_id,TESTMUAI_CLIENT_VERSION:this.opts.clientVersion,TESTMUAI_TELEMETRY_PROXY_URL:this.opts.proxyUrl};return this.ids.context_instance_id&&(e.TESTMUAI_CONTEXT_INSTANCE_ID=this.ids.context_instance_id),e}traceTee(){return e=>{if(!this.logger)return;let n=typeof e.kind=="string"?e.kind.slice(0,64):"trace",i={...C(m(this.ids,"ASR_CMD_START",{})),trace_kind:n};typeof e.code=="string"&&(i.trace_code=e.code.slice(0,64)),delete i.event,this.logger.logStep(d,`trace_${n}`,n,i)}}wireTrace(e,n,i){if(!this.logger)return;i&&this.agentSession(i);let s=n&&typeof n=="object"?n:{};switch(e){case"spawn":this.event("ASR_AGENT_SPAWN",{tier:s.tier});break;case"session_paused":this.event("ASR_SESSION_PAUSED",s);break;case"commit":this.event("ASR_COMMIT",s);break;default:this.traceTee()({kind:e,code:typeof s.code=="string"?s.code:void 0})}}banner(){return`session: ${this.ids.session_id}`}supportFooter(){return`if this keeps failing, share this id with support: ${this.ids.session_id}`}async end(e){if(!this.ended){if(this.ended=!0,e.duration_ms===void 0&&(e={...e,duration_ms:Date.now()-this.createdAt}),this.logger)if(e.exit_code===0?this.logger.discardSteps(d):this.logger.escalate(d),e.exit_code>0&&!j.has(e.exit_code)&&!this.errorState.emitted&&this.event("ASR_ERROR",{error_code:e.exit_code===2?"usage_exit_unattributed":`exit_${e.exit_code}_unattributed`,exit_code:e.exit_code}),this.event("ASR_CMD_END",e),this.opts.longSession)await this.logger.shutdown();else{let n=await this.logger.flushOnce(V);(n==="failed"||n==="timeout")&&A(this.logger.drainBuffer())}this.logger&&this.writeManifestLine(e.exit_code),r(null)}}writeManifestLine(e){try{let n=x(this.ids.context_instance_id??null);M.mkdirSync(D.dirname(n),{recursive:!0});let i={ts:new Date().toISOString(),session_id:this.ids.session_id,operation_id:this.ids.operation_id,agent_session_id:this.ids.agent_session_id,verb:this.ids.verb,mode:this.ids.mode,exit_code:e};M.appendFileSync(n,JSON.stringify(i)+`
|
|
3
3
|
`,{flag:"a",mode:384})}catch{}}};function C(t){let e={event:t.event,session_id:t.session_id,operation_id:t.operation_id,verb:t.verb,mode:t.mode,component:t.component,seq:t.seq,context_lineage_id:t.context_lineage_id,context_instance_id:t.context_instance_id};t.parent_operation_id&&(e.parent_operation_id=t.parent_operation_id),t.agent_session_id&&(e.agent_session_id=t.agent_session_id);for(let[n,i]of Object.entries(t.context))e[n]=i;return e}var u=process.env.KANE_TELEMETRY_URL||v;function B(){return process.env.TESTMUAI_BASE_URL?"custom":process.env.TESTMUAI_ENV==="stage"?"stage":"prod"}function _e(t){let e=process.env.KANE_TELEMETRY!=="0"&&(!process.env.VITEST||process.env.KANE_TELEMETRY==="1"),n=t.env??B(),i=null;if(t.resumeSid&&t.contextRoot)try{let o=L(t.contextRoot,t.resumeSid);o?.user_session_id&&(i=o.user_session_id)}catch{}if(!i&&t.applyPlanPath)try{let o=JSON.parse(P.readFileSync(t.applyPlanPath,"utf8"));o.telemetry?.user_session_id&&(i=o.telemetry.user_session_id)}catch{}let s=i!==null;i||(i=y());let l=null,c=null,f=!1;if(t.contextRoot&&P.existsSync(t.contextRoot))if(t.write&&e){let o=k(t.contextRoot);l=o.ids.context_lineage_id,c=o.ids.context_instance_id,f=o.cloned}else{let o=N(t.contextRoot);l=o?.context_lineage_id??null,c=o?.context_instance_id??null}let h={session_id:i,operation_id:T(),context_lineage_id:l,context_instance_id:c,verb:t.verb,mode:t.mode,component:"kane-cli"},_=null;if(e){let o=I(n),S={org_id:o.org_id??"",user_id:o.user_id??"",machine_id:o.machine_id,email:null,email_domain:"",user_type:o.user_type??"unknown",env:o.env,plan:o.plan??"unknown"},U=t.mode==="interactive"||t.mode==="cli"?"cli":"agent";_=new w({proxyUrl:u,sessionId:i,identity:S,device:{cli_version:g,platform:X(),arch:Y(),host_agent:O(),invocation_mode:U},getToken:async()=>null}),t.longSession&&_.start()}let p=new a({envelope:h,logger:_,longSession:!!t.longSession,proxyUrl:u,clientVersion:`kane-cli/${g}`,telemetryEnabled:e});return e&&(r(h),p.event("ASR_CMD_START",{resumed:s,applied_plan:!!t.applyPlanPath}),f&&p.event("ASR_CONTEXT_CLONED"),b(async o=>{try{return(await E(u,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(o)})).ok}catch{return!1}}).catch(()=>{})),p}export{B as a,_e as b};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { createRequire } from 'module'; const require = createRequire(import.meta.url);
|
|
2
|
-
import{a as be}from"./chunk-
|
|
2
|
+
import{a as be}from"./chunk-JQW2QFSX.js";import{a as xe,b as Re}from"./chunk-6FCPS2VT.js";import{a as se,b as q,d as ue}from"./chunk-UH2ZTX4E.js";import{a as Ne,b as Ee,g as le,j as ee}from"./chunk-XMTSHHYQ.js";import{d as te,e as w,f as re,g as oe,h as de}from"./chunk-AKX4VRRR.js";function Me(r,s){let t=r.toLowerCase().trim().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"");if(t.length>60){let o=t.lastIndexOf("-",60);t=(o>0?t.slice(0,o):t.slice(0,60)).replace(/-+$/g,"")}if(!ae.test(t))return null;let e=t;for(let o=2;s(e);o++)e=`${t}-${o}`;return ae.test(e)?e:null}var Ve={source:"src",usecase:"uc",scenario:"sc",ac:"ac",test:"t",gap:"gap",stylenote:"sty"};function ze(r,s,t){let e=Ve[r];return Me(e?`${e} ${s}`:s,t)}var Pe={usecase:"uc",scenario:"sc",ac:"ac",test:"t",gap:"gap",stylenote:"sty"},Oe=/^(uc|sc|ac|t|gap|sty)-\d+$/i;function we(r,s,t){let e=Pe[r];if(!e)return null;let o=new RegExp(`^${e}-(\\d+)$`),d=0;for(let p of t){let l=o.exec(p);if(!l)continue;let n=Number(l[1]);Number.isSafeInteger(n)&&n>d&&(d=n)}let c=d+1;for(;s(`${e}-${c}`);)c+=1;return`${e}-${c}`}var Le=/^L([1-9]\d*)-L([1-9]\d*)$/,Ge=/^img#(p[1-9]\d*-[1-9]\d*|i[1-9]\d*)$/;function pe(r){if(r==="img#whole")return{kind:"img-whole"};let s=Ge.exec(r);if(s)return{kind:"img-part",ref:s[1]};let t=Le.exec(r);return t?{kind:"lines",a:parseInt(t[1],10),b:parseInt(t[2],10)}:null}function Ue(r,s){let t=/^L(\d+)-L(\d+)$/.exec(s);if(!t)return null;let e=parseInt(t[1],10),o=parseInt(t[2],10),d=r.split(`
|
|
3
3
|
`);return e<1||o<e||o>d.length?null:d.slice(e-1,o).map(c=>c.replace(/^\d+\| /,"")).join(`
|
|
4
4
|
`)}function Te(r,s,t){let e=pe(s.anchor);if(r.format==="image")return e?.kind==="img-whole"?[]:[{code:"CITE_ANCHOR_INVALID",detail:`image cites are anchor-only (img#whole), got ${s.anchor}`}];if(e?.kind==="img-part")return new Set((r.images??[]).map(c=>c.ref)).has(e.ref)?[]:[{code:"CITE_ANCHOR_INVALID",detail:`anchor ${s.anchor} names no embedded image of this source version`}];if(!s.anchor||s.quote===void 0||s.quote==="")return[{code:"MISSING_CITE",detail:"text-kind cites need anchor+quote"}];let o=t!==null?Ue(t,s.anchor):null;return o===null?[{code:"BAD_ANCHOR",detail:`anchor ${s.anchor} does not resolve in the source`}]:o.includes(s.quote)?[]:[{code:"QUOTE_MISMATCH",detail:`quote is not verbatim within ${s.anchor}`}]}import{existsSync as Fe,readFileSync as He}from"fs";function dt(r){let s=Re(r),t=new Map(Object.entries(s.heads)),e=new Map(Object.entries(s.trust)),o=new Map(Object.entries(s.nodeLabel)),d=new Map(Object.entries(s.superseded)),c=new Map(Object.entries(s.names)),p=new Map(Object.entries(s.archivedReason)),l=new Set(s.appliedEvents),n=new Map(Object.entries(s.conv)),m=g=>s.media[g]??{format:"text",media_type:"text/plain",anchors_supported:["L-L"]},f=new Map;for(let[g,_]of c)f.set(_,g);let a=new Map,S=g=>{if(a.has(g))return a.get(g);if(!o.has(g))return a.set(g,null),null;let _=xe(r,g);if(!Fe(_))throw new Ne(`derived node file missing for ${g} \u2014 run kane-cli context rebuild`);let I=JSON.parse(He(_,"utf8"));return a.set(g,I),I},v=g=>{let _=g,I=new Set;for(;d.has(_)&&!I.has(_);){I.add(_);let O=d.get(_);if(typeof O!="string")break;_=O}return _},N=null,y=g=>{let _=f.get(g);if(_!==void 0)return _;if(N===null){N=new Map;for(let[G,D]of d)typeof D=="string"&&N.set(D,G)}let I=new Set,O=g;for(;!I.has(O);){I.add(O);let G=N.get(O);if(G===void 0)return null;let D=f.get(G);if(D!==void 0)return D;O=G}return null},b=g=>{Oe.test(g)&&(g=g.toLowerCase());let _=t.get(g),I=o.has(g)?g:c.get(g)??(typeof _=="string"?_:void 0);if(I===void 0||!o.has(I))return null;let O=v(I);return{cid:I,tip:O,superseded:d.has(I)||d.has(O)}},V=new Map;for(let g of Object.values(s.forward))for(let _ of g){let I=V.get(_.dst);I?I.push(_):V.set(_.dst,[_])}let A=g=>(g??[]).filter(_=>!d.has(_.ecid)),K=g=>A(V.get(g)),P=g=>K(g).filter(_=>_.type===w.DERIVES),J=g=>A(s.forward[g]).some(_=>oe(_.type)?.pin?.comparesTo==="dst_tip"&&d.has(_.dst)),ie=g=>{if(d.has(g))return"superseded";let _=P(g);if(_.length===0)return J(g)?"stale":"fresh";let I=new Map;for(let D of _)I.set(D.props.source_id,D);let O=!1,G=!1;for(let[D,k]of I){let U=t.get(D);if(U!=null&&(O=!0,U!==k.props.source_cid)){let i=n.get(D)?.chain;(!i||!i.includes(k.props.source_cid))&&(G=!0)}}return O?G||J(g)?"stale":"fresh":"orphaned"};return{heads:t,trust:e,nodeLabel:o,superseded:d,names:c,nameOf:f,archivedReason:p,appliedEvents:l,convChains:n,mediaOf:m,extractedSourceCids:new Set(s.extracted),extractionCompleteness:new Map(Object.entries(s.completeness??{}).map(([g,{seq:_,...I}])=>[g,I])),designOf:new Map(Object.entries(s.design_of??{})),designGenerationOf:new Map(Object.entries(s.design_generation??{})),latestHash:s.applied.hash,lastSeq:s.applied.seq,hasNode:g=>o.has(g),getNode:S,byLabel:g=>[...o.entries()].filter(([,_])=>_===g).map(([_])=>({cid:_,content:S(_)?.content??{}})),edgesFrom:g=>A(s.forward[g]),edgesInto:K,derivesInto:P,resolve:b,tipOf:v,displayNameOf:y,stale:ie,staleList:()=>[...o.keys()].map(g=>({cid:g,state:ie(g)})).filter(g=>g.state!=="fresh"),execHistory:g=>{let _=b(g);if(!_)return[];let I=v(_.cid),O=new Set([I]),G=!0;for(;G;){G=!1;for(let[k,U]of d)U!==null&&O.has(U)&&!O.has(k)&&(O.add(k),G=!0)}let D=[];for(let k of Object.entries(s.exec??{}))O.has(k[0])&&D.push(...k[1]);return D.sort((k,U)=>k.started_at<U.started_at?-1:1)},retractedEdgesTouching:g=>{let _=new Set([v(g),g]),I=!0;for(;I;){I=!1;for(let[k,U]of d)typeof U=="string"&&_.has(U)&&!_.has(k)&&(_.add(k),I=!0)}let O=s.edgeRetractions??{},G=[],D=new Set;for(let k of _)for(let U of[...s.forward[k]??[],...V.get(k)??[]]){let i=O[U.ecid];!i||D.has(U.ecid)||(D.add(U.ecid),G.push({...U,retraction:i}))}return G}}}function at(r,s){if(r.stale(s)!=="stale")return!1;let t=new Map;for(let e of r.derivesInto(s))t.set(e.props.source_id,e);for(let[e,o]of t){let d=r.heads.get(e);if(d==null||d===o.props.source_cid)continue;let c=r.convChains.get(e)?.chain;if(!c||!c.includes(o.props.source_cid))return!0}for(let e of r.edgesFrom(s)){if(oe(e.type)?.pin?.comparesTo!=="dst_tip"||!r.superseded.has(e.dst))continue;let o=r.tipOf(e.dst);if(r.superseded.has(o)||r.nodeLabel.get(o)==="usecase")return!0}return!1}function fe(r,s){let t=new Map;for(let[c,p]of r.superseded)typeof p=="string"&&p!==c&&t.set(p,[...t.get(p)??[],c]);let e=[],o=[s],d=new Set;for(;o.length>0;){let c=o.pop();d.has(c)||(d.add(c),e.push(c),o.push(...t.get(c)??[]))}return e}function je(r,s){return(r.extraction_claims??[]).some(t=>t.source_id===s&&t.completeness==="complete")}function qe(r,s){let t=new Set;for(let e of fe(r,s))for(let o of r.derivesInto(e))t.add(o.props?.source_id??"conversation");return t}function ve(r,s){let t=[],e=[],o=r.archived??[];if(o.length===0)return{valid:t,errors:e};let d=new Set([...r.source?[r.source.source_id]:[],...(r.sources??[]).map(p=>p.source_id)]),c=new Set;for(let p of r.use_cases){if(!p.matches_existing)continue;let l=s.resolve(p.matches_existing.cid);l&&c.add(s.tipOf(l.cid))}for(let p of o){let l=`archived[${p.target}]`,n=s.resolve(p.target),m=n?s.tipOf(n.cid):null;if(!m||(s.trust.get(m)??null)==="archived"){e.push({code:"ARCHIVE_TARGET_UNKNOWN",detail:`${l}: target does not resolve to an existing, live item`});continue}let f=qe(s,m);if(!f.has(p.basis)){e.push({code:"ARCHIVE_FOREIGN_PROVENANCE",detail:`${l}: its provenance does not include ${p.basis} \u2014 an archive claim must come from a source that evidences the item`});continue}if(!d.has(p.basis)){e.push({code:"ARCHIVE_WITHOUT_COMPLETE_CLAIM",detail:`${l}: ${p.basis} was not read by this extraction \u2014 a completeness claim only counts for a source this run actually read`});continue}if(!je(r,p.basis)){e.push({code:"ARCHIVE_WITHOUT_COMPLETE_CLAIM",detail:`${l}: archiving needs an EXPLICIT complete extraction claim for ${p.basis} (the omitted-claims default does not count) \u2014 add extraction_claims`});continue}if(c.has(m)){e.push({code:"ARCHIVE_TARGET_MATCHED",detail:`${l}: this proposal also matches the target via matches_existing \u2014 a matched item cannot be archived by the same extraction; propose the change as an update instead`});continue}let a=[...f].filter(S=>S!==p.basis);if(a.length>0){e.push({code:"ARCHIVE_OTHER_LIVE_EVIDENCE",detail:`${l}: still evidenced by ${a.join(", ")} \u2014 an item another live source evidences is never archived from here`});continue}t.push({op:p,cid:m})}return{valid:t,errors:e}}function Se(r,s,t){return r.superseded.has(t)}function ke(r){let{graph:s,oldTip:t,newCid:e,newLabel:o,by:d}=r,c=[],p=[],l=[],n=[],m=new Set;for(let f of s.edgesFrom(t)){if(f.type===w.DERIVES||r.skipEcids?.has(f.ecid))continue;p.push({kind:"edge",ecid:f.ecid,reason:r.reason,by:d}),m.add(f.ecid);let a=r.dstRedirect?.get(f.dst)??f.dst,S=s.nodeLabel.get(f.dst)??"(unknown)",v=de(f.type,o,S,f.props);if(v.length>0){l.push(`rebless ${f.type} \u2192 ${f.dst}: ${v.map(b=>b.detail).join("; ")}`);continue}let N=be(s,{type:f.type,src:e,dst:a},{pending:n,retracted:m},`rebless ${f.type}`);if(N){l.push(N.detail);continue}let y=q(f.type,e,a,f.props);if(s.superseded.has(y)){l.push(`rebless ${f.type} \u2192 ${a}: the re-derived edge (${y}) was retracted \u2014 retraction is terminal, the successor cannot revive it`);continue}c.push({ecid:y,type:f.type,src:e,dst:a,props:f.props}),n.push({src:e,dst:a,type:f.type})}return{edges:c,supersessions:p,errors:l}}var ae=/^[a-z0-9][a-z0-9-]{1,63}$/;function De(r,s,t,e){if(!s)return{error:{code:"SUPERSEDE_TARGET_MISSING",detail:"supersede verdict needs a target (slug or cid)"}};let o=r.resolve(s);return o?o.superseded||e.has(o.cid)?{error:{code:"ALREADY_SUPERSEDED",detail:`${s} is already superseded (tip: ${o.tip})`}}:o.cid===t?{error:{code:"SELF_SUPERSEDE",detail:"a node cannot supersede itself"}}:{targetCid:o.cid}:{error:{code:"UNKNOWN_SUPERSEDE_TARGET",detail:`${s} names nothing in the graph`}}}function Ke(r,s,t,e,o=[]){if(!oe(s)?.acyclic)return null;if(t===e)return{code:"EDGE_CYCLE",detail:`${s} ${t} \u2192 itself`};let c=n=>[...r.edgesFrom(n).filter(m=>m.type===s).map(m=>m.dst),...o.filter(m=>m.type===s&&m.src===n).map(m=>m.dst)],p=new Set,l=[e];for(;l.length>0;){let n=l.pop();if(n===t)return{code:"EDGE_CYCLE",detail:`${s} ${t} \u2192 ${e} closes a cycle`};p.has(n)||(p.add(n),l.push(...c(n)))}return null}function Rt(r,s,t,e){let d=oe(s)?.cardinality;if(d!=="one-live-per-src"&&d!=="one-live-per-src-and-dst")return null;let c=r.edgesFrom(t).filter(p=>p.type===s&&!r.superseded.has(p.dst));if(c.length>0)return{code:"CARDINALITY_VIOLATION",detail:`${s} from ${t} already has a live edge (${c[0].ecid}) \u2014 supersede it first`};if(d==="one-live-per-src-and-dst"&&e!==void 0){let p=r.edgesInto(e).filter(l=>l.type===s&&!r.superseded.has(l.src));if(p.length>0)return{code:"CARDINALITY_VIOLATION",detail:`${s} onto ${e} already has a live edge (${p[0].ecid}) \u2014 strict 1:1, supersede it first`}}return null}var Ie=new Set(["high","med","low"]),ge=r=>r.cites&&r.cites.length>0?r.cites:[r.cite];function he(r){let s=0;for(let t of r)typeof t=="object"&&t!==null&&"op"in t&&s++;return s===0?"flat":s===r.length?"ops":"mixed"}var We=/^c[1-9][0-9]*$/;function Ae(r,s,t,e){let o=new Map,d=[],c=[];for(let[l,n]of s.entries()){let m=`${r}.updated.criteria[${l}]`;if(n.op==="keep"||n.op==="remove"){if(!We.test(n.ref??"")){e.push({code:"CRITERIA_REF_UNKNOWN",detail:`${m}: ref ${JSON.stringify(n.ref)} is not a c<N> criterion index`});continue}if(o.has(n.ref)){e.push({code:"CRITERIA_REF_DUPLICATE",detail:`${m}: ${n.ref} is already named by another op \u2014 every prior criterion appears in exactly one keep or remove`});continue}o.set(n.ref,n);let f=Number.parseInt(n.ref.slice(1),10);if(f>t.length){e.push({code:"CRITERIA_REF_UNKNOWN",detail:`${m}: ${n.ref} \u2014 the live target has ${t.length} criteria`});continue}if(t[f-1]!==n.text){e.push({code:"CRITERIA_REF_MISMATCH",detail:`${m}: ${n.ref} echo mismatch \u2014 the live target's criterion ${f} reads ${JSON.stringify(t[f-1])}, the op echoed ${JSON.stringify(n.text)} \u2014 re-read the node and re-emit`});continue}n.op==="remove"&&(d.push(n.text),(!n.reason||!n.reason.trim())&&e.push({code:"EMPTY_REASON",detail:`${m}: a remove op carries its reason`}))}else!n.text||!n.text.trim()?e.push({code:"EMPTY_CRITERION",detail:`${m}: set text is empty`}):c.push(n.text)}let p=[];for(let l=1;l<=t.length;l++)o.has(`c${l}`)||p.push(`c${l}`);p.length>0&&e.push({code:"CRITERIA_PARTITION_INCOMPLETE",detail:`${r}: prior criteria ${p.join(", ")} named by no keep/remove op \u2014 every prior criterion must be kept or removed (with a reason)`});for(let l of d)c.includes(l)&&e.push({code:"CRITERIA_OP_CONFLICT",detail:`${r}: ${JSON.stringify(l)} is removed AND re-set in the same update \u2014 drop one of the two ops`})}function bt(r,s,t){let e=[],o=r.sources??[r.source],d=new Map(o.map(n=>[n.source_id,n.source_cid])),c=new Map;if(typeof s=="string")c.set(r.source.source_id,{media:t.mediaOf(r.source.source_cid),numberedText:s});else for(let[n,m]of s)c.set(n,m);for(let n of o)t.hasNode(n.source_cid)||e.push({code:"MISSING_SOURCE_NODE",detail:`source ${n.source_id} (${n.source_cid}) is not a committed node \u2014 ingest it first`});let p=(n,m)=>{let f=m.source_id??r.source.source_id;if(!d.has(f)){e.push({code:"CITE_SOURCE_UNKNOWN",detail:`${n}: cite source ${JSON.stringify(f)} is not in read_basis`});return}let a=c.get(f);if(!a){e.push({code:"MISSING_SOURCE_NODE",detail:`${n}: no citable text available for source ${f}`});return}for(let S of Te(a.media,m,a.numberedText))e.push({code:S.code,detail:`${n}: ${S.detail}`})},l=new Set;for(let n of r.use_cases){if(l.has(n.temp_ref)&&e.push({code:"DUP_TEMP_REF",detail:`duplicate temp_ref ${n.temp_ref}`}),l.add(n.temp_ref),(!n.title||!n.title.trim())&&e.push({code:"EMPTY_TITLE",detail:`${n.temp_ref}: title is empty`}),Ie.has(n.risk)||e.push({code:"BAD_RISK",detail:`${n.temp_ref}: risk ${JSON.stringify(n.risk)} not in high|med|low`}),!n.cite||!n.cite.anchor)e.push({code:"MISSING_CITE",detail:`${n.temp_ref}: every derived use-case must carry a cite`});else for(let f of ge(n))p(n.temp_ref,f);n.matches_existing&&!t.hasNode(n.matches_existing.cid)&&e.push({code:"UNKNOWN_MATCH",detail:`${n.temp_ref}: matches_existing ${n.matches_existing.cid} is not in the graph`});for(let[f,a]of(n.criteria??[]).entries())(!a.text||!a.text.trim())&&e.push({code:"EMPTY_CRITERION",detail:`${n.temp_ref}.criteria[${f}]: text is empty`}),!a.cite||!a.cite.anchor?e.push({code:"MISSING_CITE",detail:`${n.temp_ref}.criteria[${f}]: every criterion carries its own cite`}):p(`${n.temp_ref}.criteria[${f}]`,a.cite);let m=n.updated?.criteria??[];if(m.length>0){let f=he(m);if(f==="mixed")e.push({code:"CRITERIA_SHAPE_MIXED",detail:`${n.temp_ref}.updated.criteria mixes op-shaped (keep/set/remove) and {text, cite} entries \u2014 emit ONE shape for the whole array`});else if(f==="ops"){let a=m,S=n.matches_existing?Ye(t,n.matches_existing.cid):null;if(!S)e.push({code:"CRITERIA_REF_UNKNOWN",detail:`${n.temp_ref}: op-union criteria address a prior version \u2014 they need a resolvable matches_existing target`});else{let v=t.getNode(S.cid)?.content.criteria??[];Ae(n.temp_ref,a,v,e)}for(let[v,N]of a.entries())N.op==="set"&&(!N.cite||!N.cite.anchor?e.push({code:"MISSING_CITE",detail:`${n.temp_ref}.updated.criteria[${v}]: a set op carries the proposing source's cite`}):p(`${n.temp_ref}.updated.criteria[${v}]`,N.cite))}else for(let[a,S]of m.entries())(!S.text||!S.text.trim())&&e.push({code:"EMPTY_CRITERION",detail:`${n.temp_ref}.updated.criteria[${a}]: text is empty`}),!S.cite||!S.cite.anchor?e.push({code:"MISSING_CITE",detail:`${n.temp_ref}.updated.criteria[${a}]: every updated criterion carries its own cite`}):p(`${n.temp_ref}.updated.criteria[${a}]`,S.cite)}}return e.push(...ve(r,t).errors),e}function Be(r,s,t){return`${r}:${s}:${t}`}function Je(r,s,t,e){let o=`${s}:${t}:`,d=0;for(let c of r.appliedEvents){if(!c.startsWith(o))continue;let p=c.slice(o.length);if(!/^\d+$/.test(p))continue;let l=Number.parseInt(p,10);l>d&&(d=l)}return Array.from({length:e},(c,p)=>Be(s,t,d+1+p))}function Ye(r,s){let t=r.resolve(s);if(t===null)return null;let e=t.cid;if(r.superseded.has(e)){let o=r.tipOf(e);return r.superseded.has(o)?null:{cid:o,redirected:!0}}return{cid:e,redirected:!1}}function Ot(r){let{contextDir:s,graph:t,proposal:e,proposalId:o,verdicts:d,by:c,allowStaleBasis:p,extractorVersion:l,autoName:n}=r,m=le(s);if(!p&&e.read_basis!==m)return{record:null,errors:[{code:"STALE_BASIS",detail:`proposal read_basis ${String(e.read_basis)} != latest ${String(m)}`}]};for(let i of e.sources??[e.source])if(!t.hasNode(i.source_cid))return{record:null,errors:[{code:"MISSING_SOURCE_NODE",detail:`source ${i.source_id} (${i.source_cid}) is not a committed node \u2014 ingest it first`}]};let f=new Map((e.sources??[e.source]).map(i=>[i.source_id,i.source_cid])),a=[],S=[],v=new Map,N=[],y=t.mediaOf(e.source.source_cid),b=new Set,V=[],A=[],K=[],P=[];for(let i of ve(e,t).valid)P.push({id:i.cid,kind:"pending_archive",resolution:"pending",edit:null,reason:i.op.reason,by:c});let J=[],ie=[],g=new Set,_=new Set,I=(i,h,F)=>{let Y=De(t,h.supersedeTarget,F,g);if("error"in Y){a.push({code:Y.error.code,detail:`${i}: ${Y.error.detail}`});return}g.add(Y.targetCid),J.push({kind:"node",old:Y.targetCid,new:F,reason:h.reason??`superseded via review by ${c.id}`,by:c})};for(let i of e.use_cases){let h=d.get(i.temp_ref)??{resolution:"skipped"};b.has(i.temp_ref)&&a.push({code:"DUP_TEMP_REF",detail:`duplicate temp_ref ${i.temp_ref}`}),b.add(i.temp_ref),(!i.title||!i.title.trim())&&a.push({code:"EMPTY_TITLE",detail:`${i.temp_ref}: title is empty`}),Ie.has(i.risk)||a.push({code:"BAD_RISK",detail:`${i.temp_ref}: risk ${JSON.stringify(i.risk)} not in high|med|low`});let F=pe(i.cite?.anchor??""),Y=i.cite?.source_id!==void 0&&f.has(i.cite.source_id)?t.mediaOf(f.get(i.cite.source_id)):y;if(Y.format==="image"){if(F?.kind!=="img-whole"){a.push({code:i.cite?.anchor?"CITE_ANCHOR_INVALID":"MISSING_CITE",detail:`${i.temp_ref}: image cites are anchor-only (img#whole)`});continue}}else if(F?.kind==="img-part"){if(!(Y.images??[]).some(E=>E.ref===F.ref)){a.push({code:"CITE_ANCHOR_INVALID",detail:`${i.temp_ref}: anchor ${i.cite?.anchor} names no embedded image of this source version`});continue}}else if(!i.cite||!i.cite.anchor||!i.cite.quote){a.push({code:"MISSING_CITE",detail:`${i.temp_ref}: every derived use-case must cite anchor+quote`});continue}h.resolution==="edited"&&h.edit&&(h.edit.title!==void 0&&!h.edit.title.trim()&&a.push({code:"EMPTY_TITLE",detail:`${i.temp_ref}: edited title is empty`}),h.edit.risk!==void 0&&!Ie.has(h.edit.risk)&&a.push({code:"BAD_RISK",detail:`${i.temp_ref}: edited risk ${JSON.stringify(h.edit.risk)} invalid`}));let me=ue({title:h.edit?.title??i.title,description:i.description,summary:h.edit?.summary??i.summary,actors:i.actors,value:i.value,risk:h.edit?.risk??i.risk,...i.criteria&&i.criteria.length>0?{criteria:i.criteria.map(u=>u.text)}:{}}),x=se("usecase",me),_e=i.cite.source_id??e.source.source_id,Ce=f.get(_e);if(i.cite.source_id!==void 0&&Ce===void 0){a.push({code:"CITE_SOURCE_UNKNOWN",detail:`${i.temp_ref}: cite source ${JSON.stringify(_e)} is not in read_basis`});continue}let Z={source_id:_e,source_cid:Ce??e.source.source_cid,anchor:i.cite.anchor,...i.cite.quote?{quote:i.cite.quote}:{}};if(i.matches_existing&&!t.hasNode(i.matches_existing.cid)){a.push({code:"UNKNOWN_MATCH",detail:`${i.temp_ref}: matches_existing ${i.matches_existing.cid} is not in the graph`});continue}let R=i.matches_existing?.cid??(t.hasNode(x)?x:null);if(R&&t.superseded.has(R)){let u=t.tipOf(R);R=t.superseded.has(u)?null:u}if(R&&i.matches_existing&&(t.trust.get(R)??null)==="derived"){let u=i.updated?.criteria??[];if(i.changed&&u.length>0&&he(u)==="ops"&&(h.resolution==="approved"||h.resolution==="edited")){a.push({code:"UC_UNREVIEWED",detail:`${i.temp_ref}: merge target ${R.slice(0,19)} is unreviewed (derived) \u2014 bless it first (kane-cli context review) and re-propose the merge`});continue}let E=(r.probeHits??[]).find(C=>C.tempRef===i.temp_ref&&C.candidateCid===R);N.push({tempRef:i.temp_ref,candidate_cid:R,score:E?.score??1,scorer:E?.scorer??"lexical_fallback"}),R=null}if(R){if(i.changed&&(h.resolution==="approved"||h.resolution==="edited")){let u=i.updated;if(!u||Object.keys(u).length===0){a.push({code:"CHANGED_NEEDS_PAYLOAD",detail:`${i.temp_ref}: changed:true needs an updated{...} payload naming the moved fields`});continue}let E=t.getNode(R)?.content??{},C=u.criteria??[],M=C.length>0?he(C):"flat";if(M==="mixed"){a.push({code:"CRITERIA_SHAPE_MIXED",detail:`${i.temp_ref}.updated.criteria mixes op-shaped (keep/set/remove) and {text, cite} entries \u2014 emit ONE shape for the whole array`});continue}if(M==="ops"){let L=C,H=E.criteria??[],j=a.length;Ae(i.temp_ref,L,H,a);for(let[ne,ce]of L.entries())ce.op==="set"&&(!ce.cite||!ce.cite.anchor)&&a.push({code:"MISSING_CITE",detail:`${i.temp_ref}.updated.criteria[${ne}]: a set op carries the proposing source's cite`});if(a.length>j)continue;let T=L.filter(ne=>ne.op!=="remove").map(ne=>ne.text),B=ue({title:h.edit?.title??u.title??String(E.title??i.title),...u.description??E.description?{description:u.description??E.description}:{},...h.edit?.summary??u.summary??E.summary?{summary:h.edit?.summary??u.summary??E.summary}:{},...u.actors??E.actors?{actors:u.actors??E.actors}:{},...u.value??E.value?{value:u.value??E.value}:{},risk:h.edit?.risk??u.risk??String(E.risk??i.risk),...T.length>0?{criteria:T}:{}}),Q=se("usecase",B);if(Q!==R){for(let $ of re("usecase",B))a.push({code:$.code,detail:`${i.temp_ref}: ${$.detail}`});V.push({cid:Q,label:te.USECASE,content:B});for(let $ of ge(i)){let X=$.source_id??e.source.source_id,W=f.get(X);if(!W){a.push({code:"CITE_SOURCE_UNKNOWN",detail:`${i.temp_ref}: cite source ${JSON.stringify(X)} is not in read_basis`});continue}let z={source_id:X,source_cid:W,anchor:$.anchor,...$.quote?{quote:$.quote}:{}};A.push({ecid:q("DERIVES",W,Q,z),type:w.DERIVES,src:W,dst:Q,props:z})}let ce=fe(t,R).flatMap($=>t.edgesInto($)).filter($=>$.type===w.DERIVES&&typeof $.props.claim=="string");for(let $ of L){if($.op!=="keep")continue;let X=new Set;for(let W of ce){let z=W.props;if(z.claim!==$.text)continue;let $e=`${z.source_id}|${z.source_cid}|${z.anchor}`;if(X.has($e))continue;X.add($e);let ye={...W.props};A.push({ecid:q("DERIVES",W.src,Q,ye),type:w.DERIVES,src:W.src,dst:Q,props:ye})}}for(let $ of L){if($.op!=="set")continue;let X=$.cite.source_id??e.source.source_id,W=f.get(X);if(!W){a.push({code:"CITE_SOURCE_UNKNOWN",detail:`${i.temp_ref}: set cite source ${JSON.stringify(X)} is not in read_basis`});continue}let z={source_id:X,source_cid:W,anchor:$.cite.anchor,...$.cite.quote?{quote:$.cite.quote}:{},claim:$.text};A.push({ecid:q("DERIVES",W,Q,z),type:w.DERIVES,src:W,dst:Q,props:z})}for(let $ of L)$.op==="remove"&&S.push({about:R,ref:$.ref,text:$.text,reason:$.reason});I(i.temp_ref,{resolution:"supersede",supersedeTarget:R,reason:h.reason??`criteria merge: ${e.source.source_id} (${L.filter($=>$.op==="keep").length} kept, ${L.filter($=>$.op==="set").length} set, ${L.filter($=>$.op==="remove").length} removed)`},Q),P.push({id:Q,kind:"review-item",resolution:h.resolution,edit:h.resolution==="edited"?{...h.edit}:null,reason:null,by:c});continue}}else{let L=C.map(T=>typeof T=="string"?{text:T,cite:void 0}:T),H=ue({title:h.edit?.title??u.title??String(E.title??i.title),...u.description??E.description?{description:u.description??E.description}:{},...h.edit?.summary??u.summary??E.summary?{summary:h.edit?.summary??u.summary??E.summary}:{},...u.actors??E.actors?{actors:u.actors??E.actors}:{},...u.value??E.value?{value:u.value??E.value}:{},risk:h.edit?.risk??u.risk??String(E.risk??i.risk),...u.criteria?L.length>0?{criteria:L.map(T=>T.text)}:{}:E.criteria?{criteria:E.criteria}:{}}),j=se("usecase",H);if(j!==R){for(let T of re("usecase",H))a.push({code:T.code,detail:`${i.temp_ref}: ${T.detail}`});V.push({cid:j,label:te.USECASE,content:H}),A.push({ecid:q("DERIVES",Z.source_cid,j,Z),type:w.DERIVES,src:Z.source_cid,dst:j,props:Z});for(let T of L){if(!T.cite)continue;let B={source_id:e.source.source_id,source_cid:e.source.source_cid,anchor:T.cite.anchor,...T.cite.quote?{quote:T.cite.quote}:{},claim:T.text};A.push({ecid:q("DERIVES",B.source_cid,j,B),type:w.DERIVES,src:B.source_cid,dst:j,props:B})}I(i.temp_ref,{resolution:"supersede",supersedeTarget:R,reason:h.reason??`matches-but-changed: ${e.source.source_id} moved (${Object.keys(u).join(", ")})`},j),P.push({id:j,kind:"review-item",resolution:h.resolution,edit:h.resolution==="edited"?{...h.edit}:null,reason:null,by:c});continue}for(let T of L){if(!T.cite)continue;let B={source_id:e.source.source_id,source_cid:e.source.source_cid,anchor:T.cite.anchor,...T.cite.quote?{quote:T.cite.quote}:{},claim:T.text};A.push({ecid:q("DERIVES",B.source_cid,R,B),type:w.DERIVES,src:B.source_cid,dst:R,props:B})}}}if(i.changed&&h.resolution==="skipped"){let u=i.updated?.criteria??[];u.length>0&&he(u)==="ops"&&P.push({id:R,kind:"pending_update",resolution:"pending",edit:{temp_ref:i.temp_ref,source_id:e.source.source_id,updated:i.updated},reason:i.change_note??null,by:c})}if(h.resolution!=="rejected"){for(let u of ge(i)){let E=u.source_id??e.source.source_id,C=f.get(E);if(!C){a.push({code:"CITE_SOURCE_UNKNOWN",detail:`${i.temp_ref}: cite source ${JSON.stringify(E)} is not in read_basis`});continue}let M={source_id:E,source_cid:C,anchor:u.anchor,...u.quote?{quote:u.quote}:{}};A.push({ecid:q("DERIVES",C,R,M),type:w.DERIVES,src:C,dst:R,props:M})}(h.resolution==="approved"||h.resolution==="edited"||h.resolution==="supersede")&&P.push({id:R,kind:"review-item",resolution:"approved",edit:null,reason:null,by:c}),h.resolution==="supersede"&&I(i.temp_ref,h,R)}continue}for(let u of re("usecase",me))a.push({code:u.code,detail:`${i.temp_ref}: ${u.detail}`});for(let u of de(w.DERIVES,"source","usecase",Z))a.push({code:u.code,detail:`${i.temp_ref}: ${u.detail}`});V.push({cid:x,label:te.USECASE,content:me}),v.set(i.temp_ref,x),A.push({ecid:q("DERIVES",Z.source_cid,x,Z),type:w.DERIVES,src:Z.source_cid,dst:x,props:Z});for(let u of ge(i).slice(1)){let E=u.source_id??e.source.source_id,C=f.get(E);if(!C){a.push({code:"CITE_SOURCE_UNKNOWN",detail:`${i.temp_ref}: cite source ${JSON.stringify(E)} is not in read_basis`});continue}let M={source_id:E,source_cid:C,anchor:u.anchor,...u.quote?{quote:u.quote}:{}};for(let L of de(w.DERIVES,"source","usecase",M))a.push({code:L.code,detail:`${i.temp_ref}: ${L.detail}`});A.push({ecid:q("DERIVES",C,x,M),type:w.DERIVES,src:C,dst:x,props:M})}for(let u of i.criteria??[]){let E=u.cite.source_id??e.source.source_id,C=f.get(E);if(!C){a.push({code:"CITE_SOURCE_UNKNOWN",detail:`${i.temp_ref}: criterion cite source ${JSON.stringify(E)} is not in read_basis`});continue}let M={source_id:E,source_cid:C,anchor:u.cite.anchor,...u.cite.quote?{quote:u.cite.quote}:{},claim:u.text};A.push({ecid:q("DERIVES",M.source_cid,x,M),type:w.DERIVES,src:M.source_cid,dst:x,props:M})}for(let u of i.depends_on_hint??[]){let E=H=>H.toLowerCase().trim().replace(/\s+/g," "),C=null,M=t.resolve(u);if(M&&!M.superseded&&t.nodeLabel.get(M.cid)===te.USECASE&&(C=M.cid),!C){for(let{cid:H,content:j}of t.byLabel(te.USECASE))if(!t.superseded.has(H)&&E(String(j.title??""))===E(u)){C=H;break}}if(!C){let H=V.find(j=>j.label===te.USECASE&&E(String(j.content.title??""))===E(u));H&&(C=H.cid)}!C||C===x||Ke(t,w.DEPENDS_ON,x,C,K)||K.some(H=>H.src===x&&H.dst===C)||(A.push({ecid:q(w.DEPENDS_ON,x,C,{reason:"extract hint"}),type:w.DEPENDS_ON,src:x,dst:C,props:{reason:"extract hint"}}),K.push({src:x,dst:C,type:w.DEPENDS_ON}))}if((h.resolution==="approved"||h.resolution==="edited"||h.resolution==="supersede")&&t.superseded.get(x)===null&&!g.has(x)&&J.push({kind:"node",old:x,new:x,reason:`re-minted after tombstone via review by ${c.id}`,by:c}),n){let u=we("usecase",E=>_.has(E),t.names.keys());u!==null&&!t.nameOf.has(x)&&(_.add(u),ie.push({cid:x,slug:u,by:c}))}h.resolution==="approved"?P.push({id:x,kind:"review-item",resolution:"approved",edit:null,reason:null,by:c}):h.resolution==="edited"?P.push({id:x,kind:"review-item",resolution:"edited",edit:{...h.edit},reason:null,by:c}):h.resolution==="rejected"?P.push({id:x,kind:"review-item",resolution:"rejected",edit:null,reason:h.reason??null,by:c}):h.resolution==="supersede"&&(P.push({id:x,kind:"review-item",resolution:"approved",edit:null,reason:h.reason??null,by:c}),I(i.temp_ref,h,x))}if(a.length)return{record:null,errors:a};let O=new Date().toISOString(),G=(e.sources?.length??0)>1||(e.extraction_claims?.length??0)>0,D;if(G){let i=[];if(e.extraction_claims==null)i.push({source_id:e.source.source_id,source_cid:e.source.source_cid,completeness:"complete",...l?{extractor_version:l}:{},at:O});else{let h=new Map(e.extraction_claims.map(F=>[F.source_id,F.completeness]));for(let F of e.sources??[e.source]){let Y=h.get(F.source_id)??null;Y!==null&&i.push({source_id:F.source_id,source_cid:F.source_cid,completeness:Y,...l?{extractor_version:l}:{},at:O})}}D=i}else D=e.source.source_cid;let k=[];for(let i of r.probeHits??[])k.push({...v.has(i.tempRef)?{new_cid:v.get(i.tempRef)}:{},candidate_cid:i.candidateCid,score:i.score,scorer:i.scorer,probe_basis:null});for(let i of N){let h=v.get(i.tempRef);k.some(F=>F.new_cid===h&&F.candidate_cid===i.candidate_cid)||k.push({...h!==void 0?{new_cid:h}:{},candidate_cid:i.candidate_cid,score:i.score,scorer:i.scorer,probe_basis:null})}return{record:ee(s,{ts:O,proposal_id:o,...o!=null?{extraction_of:D}:{},...o!=null&&l?{extractor_version:l}:{},...S.length>0?{criteria_removed:S}:{},...k.length>0?{dedup_hits:k}:{},nodes:V,edges:A,review:P,supersessions:J,...ie.length>0?{names:ie}:{},...r.judgements&&r.judgements.length>0?{judgements:r.judgements}:{},...r.eventIds&&r.eventIds.length>0?{event_ids:r.eventIds}:r.sid?{event_ids:Je(t,r.sid,"extract",1)}:{},...r.sid?{sid:r.sid}:{},source_head_moves:{}},{expectPrev:m}).record,errors:null}}function wt(r){let{contextDir:s,graph:t,verdicts:e,by:o}=r,d=[],c=[],p=[],l=[],n=[],m=new Set,f=new Map;for(let[S,v]of e){if(v.resolution!=="edited")continue;let N=t.resolve(S);if(!N||N.superseded)continue;let y=t.getNode(N.cid);if(!y)continue;let b={...y.content,...v.edit?.title!==void 0?{title:v.edit.title}:{},...v.edit?.summary!==void 0?{summary:v.edit.summary}:{},...v.edit?.risk!==void 0?{risk:v.edit.risk}:{}};if(re(y.label,b).length>0)continue;let V=se(y.label,b);V===N.cid||Se(t,N.cid,V)||f.set(N.cid,V)}for(let[S,v]of e){if(v.resolution==="skipped")continue;let N=t.resolve(S);if(!N){d.push({code:"UNKNOWN_NODE",detail:`${S} names nothing in the graph`});continue}if(N.superseded){d.push({code:"SUPERSEDED_TARGET",detail:`${S} is superseded \u2014 review the tip (${N.tip})`});continue}let y=N.cid;if(v.resolution==="approved")l.push({id:y,kind:"review-item",resolution:"approved",edit:null,reason:null,by:o});else if(v.resolution==="rejected")r.holdArchives?l.push({id:y,kind:"pending_archive",resolution:"pending",edit:null,reason:v.reason??null,by:o}):l.push({id:y,kind:"review-item",resolution:"rejected",edit:null,reason:v.reason??null,by:o});else if(v.resolution==="edited"){if(m.has(y)){d.push({code:"DUPLICATE_TARGET",detail:`${S}: this node was already superseded by another verdict in this batch \u2014 one verdict per node`});continue}let b=t.getNode(y);if(!b){d.push({code:"UNKNOWN_NODE",detail:`${S}: node file unreadable`});continue}let V={...b.content,...v.edit?.title!==void 0?{title:v.edit.title}:{},...v.edit?.summary!==void 0?{summary:v.edit.summary}:{},...v.edit?.risk!==void 0?{risk:v.edit.risk}:{}},A=re(b.label,V);if(A.length>0){for(let J of A)d.push({code:J.code,detail:`${S}: ${J.detail}`});continue}let K=se(b.label,V);if(K===y){l.push({id:y,kind:"review-item",resolution:"approved",edit:null,reason:null,by:o});continue}if(Se(t,y,K)){d.push({code:"SUPERSEDE_CYCLE",detail:`${S}: edit reproduces an already-superseded version (supersession cycle guard) \u2014 re-edit forward or redesign`});continue}let P=ke({graph:t,oldTip:y,newCid:K,newLabel:b.label,by:o,reason:`re-blessed onto ${K} (edited in review)`,dstRedirect:f});if(P.errors.length>0){for(let J of P.errors)d.push({code:"REBLESS_REFUSED",detail:`${S}: ${J}`});continue}c.push({cid:K,label:b.label,content:V}),p.push(...P.edges),m.add(y),n.push({kind:"node",old:y,new:K,reason:v.reason??"edited in review",by:o}),n.push(...P.supersessions),l.push({id:K,kind:"review-item",resolution:"edited",edit:{...v.edit},reason:null,by:o})}else if(v.resolution==="supersede"){let b=De(t,v.supersedeTarget,y,m);if("error"in b){d.push({code:b.error.code,detail:`${S}: ${b.error.detail}`});continue}m.add(b.targetCid),r.holdArchives?l.push({id:b.targetCid,kind:"pending_archive",resolution:"pending",edit:null,reason:`supersede by ${y}${v.reason?` \u2014 ${v.reason}`:""}`,by:o}):(n.push({kind:"node",old:b.targetCid,new:y,reason:v.reason??`superseded via review by ${o.id}`,by:o}),l.push({id:y,kind:"review-item",resolution:"approved",edit:null,reason:v.reason??null,by:o}))}}return d.length?{record:null,errors:d}:l.length===0&&n.length===0?{record:null,errors:[{code:"NO_VERDICTS",detail:"every item was skipped \u2014 nothing to commit"}]}:{record:ee(s,{ts:new Date().toISOString(),proposal_id:null,nodes:c,edges:p,review:l,supersessions:n,source_head_moves:{}},{expectPrev:t.latestHash}).record,errors:null}}function Tt(r){let{contextDir:s,graph:t,survivor:e,merged:o,reason:d,by:c}=r,p=t.resolve(e),l=t.resolve(o);return p?l?p.superseded||l.superseded?{record:null,errors:[{code:"ALREADY_SUPERSEDED",detail:"a side of the pair is already superseded \u2014 the pair is drained"}]}:p.cid===l.cid?{record:null,errors:[{code:"SELF_SUPERSEDE",detail:"a pair cannot merge a node into itself"}]}:{record:ee(s,{ts:new Date().toISOString(),proposal_id:null,nodes:[],edges:[],review:[],supersessions:[{kind:"node",old:l.cid,new:p.cid,reason:d??`pair merge: duplicate of ${e}`,by:c}],source_head_moves:{}},{expectPrev:t.latestHash}).record,errors:null}:{record:null,errors:[{code:"UNKNOWN_NODE",detail:`${o} names nothing in the graph`}]}:{record:null,errors:[{code:"UNKNOWN_NODE",detail:`${e} names nothing in the graph`}]}}function kt(r){let{contextDir:s,graph:t,assignments:e,by:o}=r,d=[],c=[],p=new Set;for(let{ref:n,slug:m}of e){if(!ae.test(m)){d.push({code:"BAD_SLUG",detail:`${JSON.stringify(m)} \u2014 slugs are kebab-case ${String(ae)}`});continue}let f=t.resolve(n);if(!f){d.push({code:"UNKNOWN_REF",detail:`${n} names nothing in the graph`});continue}if(f.superseded){d.push({code:"SUPERSEDED_TARGET",detail:`${n} is superseded \u2014 name the tip instead (${f.tip})`});continue}let a=t.names.get(m);if(a!==void 0&&!t.superseded.has(a)&&a!==f.cid||p.has(m)){d.push({code:"SLUG_TAKEN",detail:`${m} already names ${a??"another node in this record"}`});continue}p.add(m),c.push({cid:f.cid,slug:m,by:o})}return d.length?{record:null,errors:d}:c.length===0?{record:null,errors:[{code:"NO_ASSIGNMENTS",detail:"nothing to name"}]}:{record:ee(s,{ts:new Date().toISOString(),proposal_id:null,nodes:[],edges:[],review:[],supersessions:[],names:c,source_head_moves:{}},{expectPrev:t.latestHash}).record,errors:null}}function Dt(r){let{contextDir:s,graph:t,sourceId:e,reason:o,by:d}=r,c=t.heads.get(e);return c===void 0?{record:null,errors:[{code:"UNKNOWN_SOURCE",detail:`no source ${e} in the graph`}]}:c===null?{record:null,errors:[{code:"ALREADY_RETIRED",detail:`source ${e} is already retired`}]}:{record:ee(s,{ts:new Date().toISOString(),proposal_id:null,nodes:[],edges:[],review:[],supersessions:[{kind:"node",old:c,new:null,reason:o??`retired source ${e}`,by:d}],source_head_moves:{[e]:null},names:[]},{expectPrev:t.latestHash}).record,errors:null}}function At(r){let s=re("gap",r.content);if(s.length>0)return{ok:!1,refusal:`defer gap failed schema validation: ${s.map(d=>d.detail).join("; ")}`};let t=se("gap",r.content),e={reason:"reconcile change deferred"},o=r.annotates?[{ecid:q(w.ANNOTATES,t,r.annotates,e),type:w.ANNOTATES,src:t,dst:r.annotates,props:e}]:[];for(let d=0;;d++)try{return ee(r.contextDir,{ts:new Date().toISOString(),proposal_id:null,nodes:[{cid:t,label:"gap",content:r.content}],edges:o,review:[],supersessions:[],source_head_moves:{}},{expectPrev:le(r.contextDir)}),{ok:!0,cid:t}}catch(c){if(c instanceof Ee){if(d<3)continue;return{ok:!1,refusal:"concurrent activity kept moving the store \u2014 try the card again"}}throw c}}function Mt(r){let s=r.graph.byLabel("gap").filter(t=>t.content.kind==="reconcile_deferred"&&typeof t.content.uc=="string"&&r.graph.tipOf(t.content.uc)===r.targetTip&&(r.sourceId===void 0||t.content.basis?.source_id===void 0||t.content.basis.source_id===r.sourceId)&&!r.graph.superseded.has(t.cid)&&r.graph.trust.get(t.cid)!=="archived");if(s.length===0)return{resolved:0};for(let t=0;;t++)try{return ee(r.contextDir,{ts:new Date().toISOString(),proposal_id:null,nodes:[],edges:[],review:[],supersessions:s.map(e=>({kind:"node",old:e.cid,new:r.resolvedBy,reason:"reconcile change resolved by a later verdict",by:r.by})),source_head_moves:{}},{expectPrev:le(r.contextDir)}),{resolved:s.length}}catch(e){if(e instanceof Ee){if(t<3)continue;return{resolved:0}}throw e}}export{pe as a,Ue as b,Te as c,ve as d,Se as e,ke as f,ae as g,Ke as h,Rt as i,ge as j,he as k,Ae as l,bt as m,Be as n,Je as o,Ye as p,Ot as q,wt as r,Tt as s,kt as t,Dt as u,At as v,Mt as w,Me as x,Ve as y,ze as z,Oe as A,we as B,dt as C,at as D,fe as E};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { createRequire } from 'module'; const require = createRequire(import.meta.url);
|
|
2
|
-
import{a as S}from"./chunk-
|
|
2
|
+
import{a as S}from"./chunk-HKCZ67AT.js";import{x as o}from"./chunk-DWHXXPDX.js";import{a as R}from"./chunk-HCBYKLMW.js";import{a as y,b as c,j as x}from"./chunk-C44QQJR4.js";import{a as w}from"./chunk-6YGTRKDT.js";import{e as b}from"./chunk-UR6MHSHU.js";var k=b(w(),1);var i=b(R(),1);function A(e){let t=e.decisions.filter(l=>l.kind==="replay").length,r=e.decisions.filter(l=>l.kind==="author").length,p=e.outcomes.filter(l=>l.status==="passed").length,d=e.outcomes.filter(l=>l.status==="failed").length,f=e.outcomes.filter(l=>l.status==="skipped").length,a=o.green,n;e.cancelled||e.overallStatus==="interrupted"?(a=o.orange,n="CANCELLED"):e.overallStatus==="failed"?(a=o.red,n="FAILED"):n="PASSED";let s=`${n} \xB7 ${e.durationS}s \xB7 ${e.outcomes.length} steps (${p} passed, ${d} failed, ${f} skipped)`,T=`${t} replay \xB7 ${r} author`,C=e.retryTriggered,_="yes \u2014 healed after a replay miss",u,h=o.dim;if(e.cancelled)u="\u2013 not committed (cancellation)";else if(e.overallStatus==="failed")u="\u2013 not committed (run failed)",h=o.red;else if(!e.shouldCommit)e.isFirstRun?u="\u2013 not committed (first run skipped commit)":e.lockHeld?u="\u2013 not committed":u="\u2013 not committed (readonly fallback / no lock)";else{let l=e.uploadResult?.testcaseId;u=l?`\u2713 pushed (testcase=${l})`:"\u2713 pushed",h=o.green}let v=e.shouldReplaceLocalOutput?"output dir replaced":e.anyAuthorStepRan?"untouched (cancellation or no replace)":"untouched (replay-only)",m,g=o.dim;return e.shouldUploadArtifacts?e.uploadResult?.success?(m="\u2713 TMS",g=o.green):e.uploadResult?(m=`\u2717 failed${e.uploadResult.error?`: ${e.uploadResult.error}`:""}`,g=o.red):m="\u2013 not run":m="\u2013 skipped (--local or no auth)",{resultLine:{color:a,text:s},breakdown:T,showRetries:C,retriesText:_,commitText:u,commitColor:h,artifactsText:v,uploadText:m,uploadColor:g}}function O(e){let t=e.decisions.filter(s=>s.kind==="replay").length,r=e.decisions.filter(s=>s.kind==="author").length,p=e.outcomes.filter(s=>s.status==="passed").length,d=e.outcomes.filter(s=>s.status==="failed").length,f=e.outcomes.filter(s=>s.status==="skipped").length,a,n=!1;return e.cancelled?a="cancellation":e.overallStatus==="failed"?a="run_failed":e.shouldCommit&&e.uploadResult?.testcaseId?(a="ok",n=!0):!e.shouldCommit&&!e.lockHeld&&!e.isFirstRun?a="readonly_fallback":a="not_committed",{type:"test_md_summary",overall_status:e.overallStatus,duration_s:e.durationS,steps:{total:e.outcomes.length,passed:p,failed:d,skipped:f,replay_decisions:t,author_decisions:r},adaptive_heal:{triggered:e.retryTriggered},commit:{committed:n,reason:a,...e.uploadResult?.testcaseId?{testcase_id:e.uploadResult.testcaseId}:{}},artifacts:{replaced:e.shouldReplaceLocalOutput},upload:{performed:e.shouldUploadArtifacts,...e.uploadResult?{succeeded:!!e.uploadResult.success}:{}},...e.shareUrl?{share_url:e.shareUrl}:{},cancelled:e.cancelled,...e.imports&&e.imports.length>0?{imports:e.imports}:{}}}function D({data:e}){let t=A(e),r=[{label:"result",value:(0,i.jsx)(c,{color:t.resultLine.color,bold:!0,children:t.resultLine.text})},{label:"breakdown",value:(0,i.jsx)(c,{color:o.dim,children:t.breakdown})}];return t.showRetries&&r.push({label:"adaptive heal",value:(0,i.jsx)(c,{color:o.orange,children:t.retriesText})}),r.push({label:"commit",value:(0,i.jsx)(c,{color:t.commitColor,children:t.commitText})}),r.push({label:"artifacts",value:(0,i.jsx)(c,{color:o.dim,children:t.artifactsText})}),r.push({label:"upload",value:(0,i.jsx)(c,{color:t.uploadColor,children:t.uploadText})}),(0,i.jsx)(S,{title:"Run summary",titleColor:"#ff9500",rows:r})}function I({data:e}){let{exit:t}=x();return(0,k.useEffect)(()=>{let r=setTimeout(()=>t(),50);return()=>clearTimeout(r)},[t]),(0,i.jsx)(y,{flexDirection:"column",children:(0,i.jsx)(D,{data:e})})}export{A as a,O as b,D as c,I as d};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { createRequire } from 'module'; const require = createRequire(import.meta.url);
|
|
2
|
-
import{a as n}from"./chunk-
|
|
2
|
+
import{a as n}from"./chunk-DWHXXPDX.js";import{createHash as _}from"crypto";import{existsSync as m,readFileSync as u}from"fs";import{dirname as T,join as f,resolve as o}from"path";import{fileURLToPath as E}from"url";var s=T(E(import.meta.url)),l=2;function p(e,r){let t=_("sha256");return t.update(`kane-assurance-contract
|
|
3
3
|
`),t.update(e),t.update(`
|
|
4
|
-
agent_state_schema=${r}`),"sha256:"+t.digest("hex")}function d(){return[o(s,".."),o(s,"../../..")]}function i(){return"sha256:
|
|
4
|
+
agent_state_schema=${r}`),"sha256:"+t.digest("hex")}function d(){return[o(s,".."),o(s,"../../..")]}function i(){return"sha256:da159529b51d00a7c5455d7773dc5143fa670ec0af9646aa5346f22faeb367db"}var a=class extends Error{constructor(t,c){super(`agent/cli contract mismatch (cli ${t||"<unset>"}, agent ${c||"<unset>"}) \u2014 rebuild or reinstall the stale half`);this.expected=t;this.actual=c;this.name="PairMismatchError"}};function I(){return{TESTMUAI_CONTRACT_DIGEST:i(),TESTMUAI_CLIENT_VERSION:process.env.KANE_DEV_FORCE_CLIENT_RELEASE??`kane-cli/${n}`}}export{a,I as b};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { createRequire } from 'module'; const require = createRequire(import.meta.url);
|
|
2
|
+
import{a as k,c as j}from"./chunk-IPEA7ZOF.js";import{dirname as J,basename as L,join as c}from"path";function W(t){let e=L(t);return e.endsWith("_test.md")?e.slice(0,-8):e.endsWith(".md")?e.slice(0,-3):e}function h(t){return c(J(t),`output-${W(t)}`)}function ot(t){return c(h(t),"Result.md")}function O(t){return c(h(t),".internal")}function R(t){return c(O(t),"meta.json")}function st(t,e,n){return c(h(t),`${e}-${n}-code`)}function dt(t){return c(h(t),"generated-code")}function ct(t){return h(t)+".staging"}function H(t){return c(O(t),"steps")}function at(t,e,n){return c(H(t),`${e}-${n}`)}import{existsSync as s,renameSync as b,rmSync as g}from"fs";function ft(t){let e=`${t}.staging`,n=`${t}.bak`;if(!s(e))throw new Error(`atomicReplaceDir: staging missing: ${e}`);if(process.platform==="win32"){s(t)&&g(t,{recursive:!0,force:!0}),b(e,t);return}s(t)&&(s(n)&&g(n,{recursive:!0,force:!0}),b(t,n)),b(e,t),s(n)&&g(n,{recursive:!0,force:!0})}function gt(t){let e=`${t}.staging`,n=`${t}.bak`;if(process.platform==="win32"){s(e)&&(s(t)?g(e,{recursive:!0,force:!0}):b(e,t));return}if(s(n)&&!s(t)){b(n,t),s(e)&&g(e,{recursive:!0,force:!0});return}s(n)&&s(t)&&g(n,{recursive:!0,force:!0}),s(e)&&s(t)&&g(e,{recursive:!0,force:!0})}import{readFileSync as Q,existsSync as X}from"fs";import{basename as E,dirname as Z,isAbsolute as B,resolve as F}from"path";import{createHash as I}from"crypto";function y(t){if(t==null)return null;if(Array.isArray(t))return t.map(y);if(typeof t=="object"){let e={};for(let n of Object.keys(t).sort()){let r=t[n];r!==void 0&&(e[n]=y(r))}return e}return t}function U(t){if(t.body.kind!=="objective")throw new Error("stepMd5: only objective steps have an md5; @import rows do not");let e={...t.config??{},optional:t.optional??!1},n=JSON.stringify(y(e));return I("md5").update(t.body.text).update(`
|
|
3
|
+
`).update(n).digest("hex")}function C(t){let e={};for(let[r,o]of Object.entries(t.bindings??{}))e[r]={value:o.value,...o.secret===!0?{secret:!0}:{},...o.syntax?{syntax:o.syntax}:{}};let n=JSON.stringify(y({bindings:e,optional:t.optional}));return I("md5").update(t.path).update(`
|
|
4
|
+
`).update(n).digest("hex")}function ht(t){return U({index:t.trace[t.trace.length-1].stepIndex,heading:t.trace[t.trace.length-1].heading,verifies:[],body:{kind:"objective",text:t.objective},config:t.parsedConfig,headingLine:1,optional:t.optional})}import{writeFileSync as Y,mkdirSync as z,readFileSync as q}from"fs";import{dirname as $}from"path";function T(t){try{return JSON.parse(q(R(t),"utf8"))}catch{return null}}function xt(t){let e=R(t.sourcePath);try{z($(e),{recursive:!0})}catch(r){return process.stderr.write(`
|
|
5
|
+
\u26A0 Failed to create output directory.
|
|
6
|
+
${r.message}
|
|
7
|
+
Path: ${$(e)}
|
|
8
|
+
|
|
9
|
+
`),e}let n={commit_id:t.commitId};t.testId!==void 0&&(n.test_id=t.testId),t.testcaseId!==void 0&&(n.testcase_id=t.testcaseId),t.projectId!==void 0&&(n.project_id=t.projectId),t.folderId!==void 0&&(n.folder_id=t.folderId),t.orgId!==void 0&&(n.org_id=t.orgId),t.sessionName!==void 0&&(n.session_name=t.sessionName),t.plan!==void 0&&(n.plan=t.plan);try{Y(e,JSON.stringify(n,null,2)+`
|
|
10
|
+
`,"utf8")}catch(r){process.stderr.write(`
|
|
11
|
+
\u26A0 Failed to write meta.json.
|
|
12
|
+
${r.message}
|
|
13
|
+
Path: ${e}
|
|
14
|
+
|
|
15
|
+
`)}return e}var D=["target","chrome_profile","cdp_endpoint","ws_endpoint","headless"],tt=["app","no_reset","os_version","device_name"],et=["mode","on_lock_conflict","tags","target","chrome_profile","cdp_endpoint","ws_endpoint","headless","app","no_reset","os_version","device_name"],l=class extends Error{constructor(e){super(e),this.name="TestMdResolveError"}};function S(t){return E(t).endsWith("_test.md")?"test":"helper"}function Ot(t){let e=F(t),n=V(e),r=nt(n.global),o=[],a=[],d=[{file:e,kind:S(e)}],p=[];return P(n,a,o,[],e,{},d,p,{}),o.forEach((m,_)=>m.flatIndex=_+1),{rootPath:e,rootTitle:n.title,rootGlobal:n.global,rootSteps:n.steps,chrome:r,steps:o,unitFiles:d,warnings:p}}function It(t){let e=[];for(let n of t.unitFiles){if(n.kind!=="test")continue;let r=T(n.file);r&&e.push({file:n.file,...r.project_id?{project_id:String(r.project_id)}:{},...r.org_id?{org_id:String(r.org_id)}:{}})}return e}function V(t){if(!X(t))throw new l(`@import path not found: ${t}`);let e=Q(t,"utf8");return k(t,e)}function P(t,e,n,r,o,a,d,p,u){if(e.includes(t.path)){let i=[...e,t.path].map(f=>E(f)).join(" \u2192 ");throw new l(`cyclic reference: ${i}`)}e.push(t.path);let m=r.length===0,_=t.global.variables??{};for(let i of Object.keys(a))if(Object.hasOwn(_,i))throw new l(`callsite binding '${i}' collides with a declared variable in ${t.path} (frontmatter variables are pinned; parameters are its undeclared names)`);let w=t.global;if(!m){let i={...t.global};for(let f of et)i[f]!==void 0&&(p.push(`${t.path}: '${f}' is root-governed on imported units \u2014 ignored`),delete i[f]);i.url!==void 0&&(u.pending=String(i.url),delete i.url),w=i}for(let i of t.steps){let f=i.body.kind!=="objective";if(i.optional&&f&&!m)throw new l(`intermediate-ref 'optional' is not supported in v1: ${t.path}:${i.headingLine}`);if(i.body.kind==="objective"){let x={file:t.path,stepIndex:i.index,heading:i.heading,optional:i.optional??!1},G=it(w,i.config,a),M={flatIndex:0,objective:i.body.text,sourceFile:t.path,trace:[...r,x],config:G,parsedConfig:i.config,optional:i.optional??!1,verifies:i.verifies,owningFile:t.path,unitKind:S(t.path)};u.pending&&(M.unitEntryUrl=u.pending,u.pending=void 0),n.push(M);continue}let A={file:t.path,stepIndex:i.index,heading:i.heading,optional:i.optional??!1,rowMd5:C({path:i.body.path,bindings:i.body.bindings,optional:i.optional??!1})},K=Z(t.path),v=B(i.body.path)?i.body.path:F(K,i.body.path),N=V(v);d.some(x=>x.file===v)||d.push({file:v,kind:S(v)}),P(N,e,n,[...r,A],o,i.body.bindings??{},d,p,u)}m||(u.pending=void 0),e.pop()}function nt(t){let e={};for(let n of D){if(n==="target"){let r=j(t);r!==void 0&&(e.target=r);continue}t[n]!==void 0&&(e[n]=t[n])}return e}function it(t,e,n){let r={};for(let[d,p]of Object.entries(t))D.includes(d)||tt.includes(d)||(r[d]=p);let o={...r,...e??{}},a={...n,...t.variables??{},...e?.variables??{}};return Object.keys(a).length>0?o.variables=a:delete o.variables,o}export{W as a,h as b,ot as c,O as d,R as e,st as f,dt as g,ct as h,H as i,at as j,ft as k,gt as l,C as m,ht as n,T as o,xt as p,l as q,Ot as r,It as s};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createRequire } from 'module'; const require = createRequire(import.meta.url);
|
|
2
|
-
import{c as m,d as g,e as f}from"./chunk-
|
|
2
|
+
import{c as m,d as g,e as f}from"./chunk-TN4SXGAP.js";import{b as d}from"./chunk-DWHXXPDX.js";import{mkdirSync as M,writeFileSync as o,existsSync as c,readFileSync as O}from"fs";import{join as a}from"path";var p={name:"remote-execution",version:"0.3.0",backendId:"hyper",kaneCompat:">=0.4.0",defaults:{runson:"mac",concurrency:1}},E={runson:"mac",concurrency:1,timeoutMinutes:120},y=`version: "0.1"
|
|
3
3
|
runson: {{runson}}
|
|
4
4
|
autosplit: true
|
|
5
5
|
concurrency: {{concurrency}}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { createRequire } from 'module'; const require = createRequire(import.meta.url);
|
|
2
|
-
import{g as h}from"./chunk-
|
|
2
|
+
import{g as h}from"./chunk-EV64VI66.js";import{e as l}from"./chunk-XMTSHHYQ.js";import{b as u}from"./chunk-DBIBROYW.js";import{d as f}from"./chunk-AKX4VRRR.js";import{existsSync as w,readFileSync as _,readdirSync as R}from"fs";import{join as p}from"path";function g(i,r){let{records:t}=l(i),o=new Set;for(let e of t)for(let n of e.review)n.resolution!=="pending"&&o.add(n.id);let s=[],d=new Set;for(let e=t.length-1;e>=0;e--)for(let n of t[e].dedup_hits??[]){if(n.new_cid===void 0)continue;let c=`${n.new_cid}|${n.candidate_cid}`;d.has(c)||(d.add(c),!o.has(n.new_cid)&&(r.superseded.has(n.new_cid)||r.superseded.has(n.candidate_cid)||r.trust.get(n.new_cid)==="derived"&&s.push({new_cid:n.new_cid,candidate_cid:n.candidate_cid,score:n.score,scorer:n.scorer})))}return s}var a=(i,r)=>i.displayNameOf(r)??r.slice(0,19);function m(i,r){return{design_children:i.edgesInto(r).filter(o=>(o.type==="belongs_to"||o.type==="scoped_to")&&!i.superseded.has(o.src)).length}}function v(i,r){let{records:t}=l(i),o=new Set,s=new Map;for(let e of t)for(let n of e.review)n.kind==="pending_archive"?s.set(n.id,n.reason):n.resolution!=="pending"&&o.add(n.id);let d=new Map;for(let[e,n]of s)r.superseded.has(e)||r.trust.get(e)!=="derived"||o.has(e)||d.set(e,n);return{all:s,live:d}}function y(i,r){let t=[],o=new Set;for(let e of g(i.contextDir,r)){o.add(e.new_cid);let n=e.scorer==="lexical_fallback"?" (lexical fallback \u2014 the probe ran degraded)":"";t.push({kind:"PAIR",ref:a(r,e.new_cid),title:String(r.getNode(e.new_cid)?.content.title??e.new_cid.slice(0,12)),why:`possible duplicate of ${a(r,e.candidate_cid)} \u2014 score ${e.score}${n}`,pair:{candidate_cid:e.candidate_cid,candidate_ref:a(r,e.candidate_cid),score:e.score,scorer:e.scorer}})}let{all:s,live:d}=v(i.contextDir,r);for(let[e,n]of d)t.push({kind:"REVIEW",ref:a(r,e),title:String(r.getNode(e)?.content.title??e.slice(0,12)),why:`archive held for interactive confirmation${n?` \u2014 ${n}`:""}`,held:!0,impact:m(r,e)});for(let e of k(i.contextDir))t.push({kind:"MODIFY_HELD",ref:`${e.sid}:${e.tempRef}`,title:String(e.content.title??e.tempRef),why:`${e.rationale} \u2014 held by paused/dead session ${e.sid}`,heldPayload:e});for(let{cid:e,content:n}of r.byLabel(f.USECASE))r.superseded.has(e)||r.trust.get(e)!=="derived"||o.has(e)||s.has(e)||t.push({kind:"REVIEW",ref:a(r,e),title:String(n.title??e.slice(0,12)),why:"unreviewed \u2014 approve, archive, or defer",impact:m(r,e)});return t}function F(i,r){let t={REVIEW:0,PAIR:0,MODIFY_HELD:0};for(let o of y(i,r))t[o.kind]++;return t}function b(i,r){try{let t=JSON.parse(_(p(i,"sessions",r,".lock"),"utf8"));return typeof t.pid=="number"&&u(t.pid)}catch{return!1}}function k(i){let r=[],t=p(i,"sessions");if(!w(t))return r;let o=[];try{o=R(t)}catch{return r}for(let s of o){if(!w(p(t,s,"state.json"))||b(i,s))continue;let d=[],e=!1;try{let c=h(i,s).kane;c?.pending?.proposals?.length&&(d=c.pending.proposals,e=!0)}catch{e=!1}if(!e)try{d=JSON.parse(_(p(t,s,"state.json"),"utf8")).pending?.proposals??[]}catch{continue}for(let n of d)r.push({sid:s,tempRef:String(n.tempRef??n.temp_ref??"held"),...typeof n.event_id=="string"?{event_id:n.event_id}:{},label:String(n.label??"usecase"),content:n.content??{},rationale:String(n.rationale??"held payload")})}return r}export{m as a,v as b,y as c,F as d};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { createRequire } from 'module'; const require = createRequire(import.meta.url);
|
|
2
|
-
import{b as O}from"./chunk-DBIBROYW.js";import{a as $}from"./chunk-
|
|
2
|
+
import{b as O}from"./chunk-DBIBROYW.js";import{a as $}from"./chunk-AKX4VRRR.js";import{a as E,b as N}from"./chunk-IAHKTEET.js";import{closeSync as S,existsSync as F,fsyncSync as k,mkdirSync as P,openSync as q,readFileSync as p,readdirSync as T,renameSync as R,rmSync as v,writeFileSync as A}from"fs";import{join as u}from"path";var i=class extends Error{};function x(e,t){if(e.schema_version!==void 0&&e.schema_version!==$)throw new i(`record ${t} is stamped ${e.schema_version}, this build reads ${$} \u2014 migrate explicitly`);if(e.parents!==void 0&&!(e.prev_hash===null?e.parents.length===0:e.parents.length===1&&e.parents[0]===e.prev_hash))throw new i(`record ${t}: parents does not mirror prev_hash \u2014 multi-parent records need a DAG-aware reader`)}var C=class extends i{},b=class extends i{code="CONTEXT_APPEND_BUSY"};function I(e,t){P(e,{recursive:!0});let r=u(e,".lock"),c=Date.now()+(t?t.deadlineMs:2e3);for(;;)try{let o=q(r,"wx");return A(o,`${process.pid}
|
|
3
3
|
`),S(o),()=>{try{v(r)}catch{}}}catch(o){if(o.code!=="EEXIST")throw o;if(t){let n=null,a=null;try{a=p(r,"utf8");let h=Number.parseInt(a.trim(),10);n=Number.isInteger(h)?h:null}catch{a=null}if(a!==null&&(n===null||!O(n))){let h=`${r}.break-${process.pid}-${Date.now()}`;try{R(r,h);let s=null;try{s=p(h,"utf8")}catch{s=null}if(s===null||s===a)v(h,{force:!0});else try{R(h,r)}catch{v(h,{force:!0})}}catch(s){if(s.code!=="ENOENT")throw s}continue}if(Date.now()>c)throw new b(`.context append is busy: ${r} held by live pid ${String(n)} past the deadline`);Atomics.wait(new Int32Array(new SharedArrayBuffer(4)),0,0,25+Math.floor(Math.random()*50));continue}if(Date.now()>c)throw new i(`.context is locked by another process \u2014 remove ${r} if that process is gone`);Atomics.wait(new Int32Array(new SharedArrayBuffer(4)),0,0,25)}}var j=/^\d{6}-[0-9a-f]{12}\.json$/,f=e=>u(e,"commits");function w(e){return"sha256:"+N(Buffer.from(E(e),"utf8"))}function y(e){let t=f(e);return F(t)?T(t).filter(r=>j.test(r)).sort():[]}function H(e){let t=y(e),r=[],c=[],o=null;return t.forEach((n,a)=>{let h=p(u(f(e),n),"utf8"),s;try{s=JSON.parse(h)}catch(d){throw new i(`corrupt commit record ${n}: ${String(d)}`)}if(s.seq!==a+1)throw new i(`sequence gap: expected seq ${a+1}, ${n} has ${s.seq}`);if(s.prev_hash!==o)throw new i(`broken chain at ${n}: prev_hash ${String(s.prev_hash)} != ${String(o)}`);x(s,n);let m=w(s),l=n.slice(7,19);if(!m.slice(7).startsWith(l))throw new i(`tampered record ${n}: content hash ${m} does not match filename`);r.push(s),c.push(m),o=m}),{records:r,hashes:c}}function J(e){let t=y(e);if(t.length===0)return null;let r=t[t.length-1],c=p(u(f(e),r),"utf8"),o;try{o=JSON.parse(c)}catch(a){throw new i(`corrupt tail record ${r}: ${String(a)}`)}x(o,r);let n=w(o);if(!n.slice(7).startsWith(r.slice(7,19)))throw new i(`tampered tail record ${r}: content hash ${n} does not match filename`);if(o.seq!==t.length)throw new i(`sequence gap at tail: ${t.length} record files but tail seq is ${o.seq}`);return{seq:o.seq,hash:n}}function U(e){return J(e)?.hash??null}function B(e,t,r){let c=y(e);if(c.length<t)throw new i(`derived state is ahead of the record log (applied seq ${t}, ${c.length} records) \u2014 run kane-cli context rebuild`);let o=[],n=[],a=r;for(let h=t;h<c.length;h++){let s=c[h],m=p(u(f(e),s),"utf8"),l;try{l=JSON.parse(m)}catch(g){throw new i(`corrupt commit record ${s}: ${String(g)}`)}if(l.seq!==h+1)throw new i(`sequence gap: expected seq ${h+1}, ${s} has ${l.seq}`);if(l.prev_hash!==a)throw new i(`broken chain at ${s}: prev_hash ${String(l.prev_hash)} != ${String(a)}`);x(l,s);let d=w(l);if(!d.slice(7).startsWith(s.slice(7,19)))throw new i(`tampered record ${s}: content hash ${d} does not match filename`);o.push(l),n.push(d),a=d}return{records:o,hashes:n}}function V(e,t){if(t.seq===0){if(t.hash!==null)throw new i("watermark not in chain: seq 0 cannot carry a hash");return H(e)}let r=y(e);if(r.length<t.seq)throw new i(`watermark not in chain: seq ${t.seq} is beyond the ${r.length}-record chain`);let c=r[t.seq-1],o;try{o=JSON.parse(p(u(f(e),c),"utf8"))}catch(a){throw new i(`watermark record ${c} unreadable: ${String(a)}`)}let n=w(o);if(n!==t.hash)throw new i(`watermark not in chain: seq ${t.seq} hashes ${n}, watermark claims ${String(t.hash)}`);return B(e,t.seq,t.hash)}function Y(e,t,r){let c=I(e,r.busyRetry);try{return M(e,t,r)}finally{c()}}function K(e,t){let r=I(e);try{return M(e,t,{})}finally{r()}}function M(e,t,r){let c=J(e),o=(c?.seq??0)+1,n=c?.hash??null;if(r.expectPrev!==void 0&&r.expectPrev!==n)throw new C(`concurrent append detected: validated against ${String(r.expectPrev)} but the chain head is ${String(n)} \u2014 re-open and retry`);let a={seq:o,prev_hash:n,...t,schema_version:$,parents:n===null?[]:[n]},h=w(a),s=f(e);P(s,{recursive:!0});let m=`${String(o).padStart(6,"0")}-${h.slice(7,19)}.json`,l=u(s,m),d=l+".tmp",g=q(d,"w");try{A(g,JSON.stringify(a)+`
|
|
4
4
|
`),k(g)}finally{S(g)}R(d,l);try{let _=q(s,"r");k(_),S(_)}catch{}return{seq:o,hash:h,file:l,record:a}}export{i as a,C as b,b as c,I as d,H as e,J as f,U as g,B as h,V as i,Y as j,K as k};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { createRequire } from 'module'; const require = createRequire(import.meta.url);
|
|
2
|
-
import{a as o,b as i}from"./chunk-
|
|
2
|
+
import{a as o,b as i}from"./chunk-VSEWQEM5.js";import{resolve as n}from"path";async function w(c,s,r={}){let e=i({verb:c,mode:"cli",contextRoot:n(process.cwd(),".context"),env:o(),write:r.write});try{let t=await s(e);return r.write&&t===0&&await e.lateBindContext(n(process.cwd(),".context")),t===1&&process.stderr.write(e.supportFooter()+`
|
|
3
3
|
`),await e.end({exit_code:t}),t}catch(t){throw e.error("cli_crash"),process.stderr.write(e.supportFooter()+`
|
|
4
4
|
`),await e.end({exit_code:1}),t}}export{w as a};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { createRequire } from 'module'; const require = createRequire(import.meta.url);
|
|
2
|
-
import{d,e as f}from"./chunk-
|
|
2
|
+
import{d,e as f}from"./chunk-AKX4VRRR.js";var G={high:3,med:2,low:1},R={create:0,evolve:1,"reuse-candidate":2},_=.75;function a(e,n){return!e.superseded.has(n)&&e.trust.get(n)!=="archived"}function E(e,n){return e.edgesInto(n).some(t=>t.type===f.VERIFIES&&a(e,t.src))}function m(e,n="med"){let t=e.risk;return t==="high"||t==="med"||t==="low"?t:n}function u(e,n){return e.displayNameOf(n)??n}function y(e,n){return`kane-cli design tests --use-case ${u(e,n)}`}function b(e,n){let t=e.edgesFrom(n).find(i=>i.type===f.SCOPED_TO&&a(e,i.dst));if(!t)return null;let s=e.nodeLabel.get(t.dst);if(s===d.USECASE)return t.dst;if(s===d.SCENARIO){let i=e.edgesFrom(t.dst).find(r=>r.type===f.BELONGS_TO&&a(e,r.dst));return i?i.dst:null}return null}function v(e,n){let t=b(e,n);return t?y(e,t):w(e,n)}function w(e,n){return`kane-cli design explain ${u(e,n)}`}function h(e,n){let t=e.edgesFrom(n).find(i=>i.type===f.AUTOMATES&&a(e,i.dst));if(!t)return null;let s=e.edgesFrom(t.dst).find(i=>i.type===f.BELONGS_TO&&a(e,i.dst));return s?s.dst:null}function x(e){let n=[];for(let{cid:t,content:s}of e.byLabel(d.AC))a(e,t)&&(E(e,t)||n.push({ref:u(e,t),kind:"no-verifies",why:"no live test verifies this acceptance criterion",risk:m(s),stage:"design",tag:"create",ready_command:v(e,t)}));return n}function S(e){let n=[];for(let{cid:t,content:s}of e.byLabel(d.USECASE)){if(!a(e,t))continue;let i=e.edgesInto(t).filter(o=>o.type===f.BELONGS_TO&&a(e,o.src));if(i.length===0){n.push({ref:u(e,t),kind:"zero-scenario",why:"use-case has no scenarios",risk:m(s),stage:"design",tag:"create",ready_command:y(e,t)});continue}i.every(o=>e.getNode(o.src)?.content.case_type==="happy")&&n.push({ref:u(e,t),kind:"happy-only",why:"use-case is exercised by happy-path scenarios only",risk:m(s),stage:"design",tag:"create",ready_command:y(e,t)})}return n}function L(e){let n=[];for(let{cid:t,content:s}of e.byLabel(d.GAP)){if(!a(e,t))continue;let i=s.ref,r=typeof i=="string"?e.resolve(i):null,o=r&&a(e,r.tip)?r.tip:null,l=o?e.nodeLabel.get(o):null,p=s.kind==="reconcile_deferred"?"kane-cli maintain reconcile":l===d.USECASE?y(e,o):l===d.AC?v(e,o):w(e,t),c=s.question&&typeof s.question=="object"?s.question:void 0,g=typeof s.text=="string"&&s.text||(c&&typeof c.header=="string"?c.header:"")||"design gap";n.push({ref:u(e,t),kind:String(s.kind),why:g,risk:m(s),stage:"design",tag:"create",ready_command:p,...typeof s.risk_rationale=="string"?{risk_rationale:s.risk_rationale}:{},...c?{question:c}:{}})}return n}function C(e){let n=[];for(let{cid:t,content:s}of e.byLabel(d.AC)){if(!a(e,t))continue;let i=e.stale(t);i==="fresh"||i==="superseded"||n.push({ref:u(e,t),kind:"stale-ac",why:`acceptance criterion is ${i} \u2014 its source moved since this was authored \xB7 why: kane-cli design explain ${u(e,t)}`,risk:m(s),stage:"design",tag:"evolve",ready_command:"kane-cli maintain reconcile"})}for(let{cid:t,content:s}of e.byLabel(d.TEST)){if(!a(e,t))continue;let i=e.stale(t);if(i==="fresh"||i==="superseded")continue;let r=e.edgesFrom(t).filter(k=>k.type===f.VERIFIES&&a(e,k.dst)),o=r.map(k=>m(e.getNode(k.dst)?.content??{})),l=o.includes("high")?"high":o.includes("med")?"med":o.includes("low")?"low":"med",p=r[0]?.dst??null,c=p?null:h(e,t),g=p?v(e,p):c?y(e,c):w(e,t);n.push({ref:u(e,t),kind:"stale-test",why:`test is ${i} \u2014 its source moved since this was authored`,risk:l,stage:"design",tag:"evolve",ready_command:g})}return n}async function O(e,n,t){for(let s of e)if(s.tag==="create"){if(!t){s.meta={embed_arm:"skipped"};continue}try{let i=n.resolve(s.ref),r=i?n.getNode(i.tip):null,o=r&&(String(r.content.title??"")||String(r.content.text??""))||s.why,l=r?.label===d.USECASE?"scenario":"test",c=(await t.searchSimilar(o,{label:l,k:1}))[0];c&&c.score>=_?(s.tag="reuse-candidate",s.meta={embed_arm:"used",near_hit:{ref:u(n,c.cid),score:c.score}}):s.meta={embed_arm:"used",near_hit:null}}catch{s.meta={embed_arm:"skipped"}}}}function A(e,n){let t=G[n.risk]-G[e.risk];if(t!==0)return t;let s=R[e.tag]-R[n.tag];return s!==0?s:e.ref<n.ref?-1:e.ref>n.ref?1:0}function T(e,n){let t=[],s=r=>{let o=e.resolve(r);return o&&!o.superseded?m(e.getNode(o.tip)?.content??{}):"med"},i=r=>{let o=e.resolve(r),l=o&&!o.superseded?b(e,o.tip):null;return l?u(e,l):r};for(let r of n.usecases??[])for(let o of r.acceptance_criteria??[])(o.covered_by??[]).length>0&&(o.execution==="failed"?t.push({ref:o.id,kind:"execution-failed",stage:"cover",tag:"evolve",risk:s(o.id),why:`covering test failed against this AC (tests: ${(o.covered_by??[]).join(", ")})`,ready_command:`kane-cli maintain evolve ${i(o.id)}`}):o.execution==="blocked"?t.push({ref:o.id,kind:"execution-blocked",stage:"cover",tag:"reuse-candidate",risk:s(o.id),why:"the oracle could not run (infrastructure) \u2014 the covering test exists and is reusable",ready_command:"kane-cli testrun run"}):o.execution==="not-run"&&t.push({ref:o.id,kind:"covered-not-run",stage:"cover",tag:"reuse-candidate",risk:s(o.id),why:"a covering test exists but never joined this pack \u2014 run it",ready_command:"kane-cli testrun run"}));return t}async function N(e,n,t,s){if(n!=="design"&&!s)throw new Error(`gaps-engine: stage "${n}" requires a pack's usecases doc`);let i=[];return(n==="design"||n==="all")&&i.push(...x(e),...S(e),...L(e),...C(e)),(n==="cover"||n==="all")&&i.push(...T(e,s)),await O(i,e,t),i.sort(A),i}export{a,E as b,b as c,N as d};
|