@testmuai/kane-cli 0.8.8 → 0.8.10
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/dist/{ChatSurface-LS3KF7XY.js → ChatSurface-OWGOCHG3.js} +1 -1
- package/dist/{ChromeProfilePicker-UIJ5ZBLY.js → ChromeProfilePicker-QIMCWPPI.js} +1 -1
- package/dist/{CliFeedbackPrompt-EIQQBWDY.js → CliFeedbackPrompt-34E2AXS4.js} +1 -1
- package/dist/{CliUploadProgress-6U77ZBAX.js → CliUploadProgress-TRKOSED7.js} +1 -1
- package/dist/{ConfigView-MVFLCF5N.js → ConfigView-XVKR7ATN.js} +1 -1
- package/dist/{EvidenceViewOffer-ANVEOXJA.js → EvidenceViewOffer-M2TGMSNE.js} +1 -1
- package/dist/FolderPicker-WZTNQ5IV.js +2 -0
- package/dist/{InfoBox-57MRRSJI.js → InfoBox-QM5YEBMH.js} +1 -1
- package/dist/{LinksBox-RKAEQBFS.js → LinksBox-CSEDEZGU.js} +1 -1
- package/dist/{ProfilesView-RQCQFIXH.js → ProfilesView-CZVPREIS.js} +1 -1
- package/dist/{ProjectPicker-5JEEHLY3.js → ProjectPicker-F6FEWNMY.js} +1 -1
- package/dist/{SaveSessionPrompt-TQROE5JM.js → SaveSessionPrompt-RUSFOLBZ.js} +1 -1
- package/dist/SingleShotApp-WBFVUZFP.js +2 -0
- package/dist/{SummaryBox-C4UY6R65.js → SummaryBox-KOJXTZVZ.js} +1 -1
- package/dist/TestMdRunView-BEXL7TIN.js +2 -0
- package/dist/{TestrunEvidenceTable-LY24PK3T.js → TestrunEvidenceTable-KGVBX76H.js} +1 -1
- package/dist/{WhoamiView-2FIHHS4G.js → WhoamiView-IOTBOCGK.js} +1 -1
- package/dist/{app-download-TO672LBR.js → app-download-7AF6QL2C.js} +1 -1
- package/dist/{auth-EVXJVU72.js → auth-2HTDCT7X.js} +1 -1
- package/dist/{binary-Y4DKNDQH.js → binary-NKX3NEK7.js} +1 -1
- package/dist/{bind-FVCVYYL3.js → bind-IMBQFRKT.js} +2 -2
- package/dist/{bootstrap-4XBQFKWF.js → bootstrap-TNFANHSS.js} +1 -1
- package/dist/bridge-SXYWYZDO.js +2 -0
- package/dist/{changelog-LAQ2VGK6.js → changelog-SQVLSCYO.js} +1 -1
- package/dist/{chunk-UY2ES2Z6.js → chunk-2BIPFAGX.js} +1 -1
- package/dist/{chunk-O4IEPE3T.js → chunk-2ULZVQZV.js} +2 -2
- package/dist/chunk-47OUD76M.js +6 -0
- package/dist/{chunk-ZSFOANLG.js → chunk-5EKTQY2S.js} +1 -1
- package/dist/{chunk-6TVNJDSE.js → chunk-5Q3W3SX7.js} +1 -1
- package/dist/{chunk-VCDXUUJQ.js → chunk-5YBKKWJA.js} +1 -1
- package/dist/{chunk-HK3FFI7Y.js → chunk-6S3Z3WPF.js} +2 -2
- package/dist/chunk-724NYDMU.js +27 -0
- package/dist/{chunk-7CXIOJB3.js → chunk-AWEUKXZQ.js} +1 -1
- package/dist/{chunk-GZLQ2AR6.js → chunk-B4CYIZP5.js} +1 -1
- package/dist/{chunk-ZKRL6HMY.js → chunk-BG2AZQLI.js} +1 -1
- package/dist/{chunk-ZHKBSKCB.js → chunk-BQSLPF5M.js} +1 -1
- package/dist/{chunk-H6YGG3GC.js → chunk-BUM367KV.js} +1 -1
- package/dist/{chunk-K5DL7CZ4.js → chunk-BZCVLCMG.js} +1 -1
- package/dist/{chunk-NAZ36RKI.js → chunk-C33E5XQM.js} +1 -1
- package/dist/{chunk-AZ73FJRK.js → chunk-CKNVMB4E.js} +1 -1
- package/dist/chunk-CPGUTSUD.js +6 -0
- package/dist/{chunk-LI5FMAUO.js → chunk-CSCJLGIY.js} +1 -1
- package/dist/{chunk-HZDNGNO2.js → chunk-CXKWVHZK.js} +1 -1
- package/dist/{chunk-BYOXTXLC.js → chunk-D6566A2X.js} +1 -1
- package/dist/{chunk-WALVOFKR.js → chunk-DF3DUGJS.js} +4 -4
- package/dist/{chunk-BRE426DP.js → chunk-EH3YMGQ7.js} +1 -1
- package/dist/{chunk-PYHWCV2V.js → chunk-EKOL4WCC.js} +1 -1
- package/dist/{chunk-VQVERWC3.js → chunk-ESHDTCSZ.js} +1 -1
- package/dist/{chunk-5LYPSIBC.js → chunk-ETIQJIDI.js} +1 -1
- package/dist/{chunk-RHL7KZNC.js → chunk-FH6EDP77.js} +1 -1
- package/dist/{chunk-V5DYLGAM.js → chunk-FOP6CJAM.js} +1 -1
- package/dist/{chunk-CQCV2RJK.js → chunk-GHL2A273.js} +2 -2
- package/dist/{chunk-JE6OO2Q6.js → chunk-GOF5PQ5T.js} +1 -1
- package/dist/{chunk-SQWVGI3J.js → chunk-HE3ZKFRC.js} +1 -1
- package/dist/{chunk-7RTITBZG.js → chunk-HNNVVK2O.js} +1 -1
- package/dist/{chunk-AO5QH6UU.js → chunk-HXSOZWFL.js} +1 -1
- package/dist/{chunk-XLVH4CIZ.js → chunk-I3OVXNBW.js} +2 -2
- package/dist/{chunk-R4PLEH2A.js → chunk-I5KYZHJ5.js} +49 -49
- package/dist/{chunk-FGRTNRBS.js → chunk-JGZWR3CR.js} +2 -2
- package/dist/{chunk-Q6743UUQ.js → chunk-KUAFVRSR.js} +1 -1
- package/dist/{chunk-N5I2QYFD.js → chunk-LKUWEQ5M.js} +1 -1
- package/dist/{chunk-6T3DWH56.js → chunk-LTNMOEHT.js} +1 -1
- package/dist/{chunk-5M5BG4MT.js → chunk-LUTRUSIV.js} +1 -1
- package/dist/{chunk-2YQ6TW77.js → chunk-M6SFFAAQ.js} +6 -6
- package/dist/{chunk-XJ4TJARR.js → chunk-ML2E3JGK.js} +1 -1
- package/dist/{chunk-7UYSTQMI.js → chunk-NDKHC6KL.js} +1 -1
- package/dist/{chunk-WPSQYEBP.js → chunk-NJQNHD5P.js} +1 -1
- package/dist/{chunk-6LYQ4MJH.js → chunk-NYQOYOBA.js} +1 -1
- package/dist/{chunk-S6M36UIV.js → chunk-NYSFEZUR.js} +1 -1
- package/dist/{chunk-WYOEOJM2.js → chunk-OSRRMY6M.js} +1 -1
- package/dist/{chunk-JPGRUMCS.js → chunk-P3UGM74Z.js} +1 -1
- package/dist/{chunk-OGJR5VIG.js → chunk-PCVTSFIX.js} +1 -1
- package/dist/chunk-PDXZROJM.js +2 -0
- package/dist/{chunk-P67CGWD6.js → chunk-PMOUXVUC.js} +1 -1
- package/dist/{chunk-DHPBVHED.js → chunk-QJNQN6ND.js} +1 -1
- package/dist/{chunk-3GZ4FQ4L.js → chunk-RJ4YFH7K.js} +1 -1
- package/dist/{chunk-5YCOYFZH.js → chunk-RP7FW23G.js} +1 -1
- package/dist/{chunk-BAKOH2BR.js → chunk-RSNG5PBN.js} +1 -1
- package/dist/{chunk-WDOEMLFZ.js → chunk-SAFETUCL.js} +1 -1
- package/dist/{chunk-7YX2HUHY.js → chunk-SAKUG4KE.js} +1 -1
- package/dist/{chunk-UYLNH4SH.js → chunk-SU3QKERU.js} +1 -1
- package/dist/{chunk-QVR2PB6Y.js → chunk-SXUQBPQ6.js} +1 -1
- package/dist/{chunk-XFTF7OOY.js → chunk-SXX7ZE6L.js} +3 -3
- package/dist/{chunk-ZIJLOYXX.js → chunk-TGPI7VDR.js} +7 -7
- package/dist/{chunk-QXLX6LMJ.js → chunk-TI7MR3PB.js} +1 -1
- package/dist/{chunk-AS5UKK27.js → chunk-UEANTGQS.js} +1 -1
- package/dist/{chunk-36ZVMJTJ.js → chunk-USUFF3S6.js} +1 -1
- package/dist/{chunk-HJOGBE23.js → chunk-VIJUT5AR.js} +9 -9
- package/dist/{chunk-4BIJCAR4.js → chunk-W7PBJXLJ.js} +1 -1
- package/dist/{chunk-WRIPTYSN.js → chunk-WAI5UHW3.js} +1 -1
- package/dist/{chunk-OO7LFDET.js → chunk-WAWMIKSI.js} +1 -1
- package/dist/chunk-WEJA3EVI.js +2 -0
- package/dist/{chunk-UDW4ZZAW.js → chunk-WXJQDLXX.js} +1 -1
- package/dist/chunk-XIGTZTFP.js +5 -0
- package/dist/{chunk-2MQP4SSF.js → chunk-XTUSDGAB.js} +1 -1
- package/dist/{chunk-K6JRFRGS.js → chunk-YHL5NA43.js} +1 -1
- package/dist/{chunk-PQYBIWZH.js → chunk-YUA2VDWH.js} +1 -1
- package/dist/{chunk-LMYE3M75.js → chunk-YXPWGIQ2.js} +1 -1
- package/dist/{chunk-FL6TCYA5.js → chunk-ZFZB4CGJ.js} +1 -1
- package/dist/{chunk-ATIX6CVS.js → chunk-ZXTVP4WX.js} +2 -2
- package/dist/{config-5UNFAVY6.js → config-UF635MC4.js} +1 -1
- package/dist/{credentials-64JYS7AQ.js → credentials-3KBLEVJH.js} +1 -1
- package/dist/{deps-bundle-5JPHXHQV.js → deps-bundle-WGF4YYGO.js} +1 -1
- package/dist/{deps-resolve-WFZZ22XH.js → deps-resolve-DVJPU4YX.js} +1 -1
- package/dist/{dispatch-JLMCXOSK.js → dispatch-YTIJKX6C.js} +1 -1
- package/dist/{doctor-KJMR7NRK.js → doctor-2KRK42L2.js} +1 -1
- package/dist/{evidence-OFTY5U4X.js → evidence-CDCFEYS7.js} +1 -1
- package/dist/{evolve-cmd-LU6LPT4F.js → evolve-cmd-L3JIBYP5.js} +1 -1
- package/dist/{extract-bind-YYIOEAYR.js → extract-bind-VFQWACVO.js} +2 -2
- package/dist/{extract-cmd-Q7OG6RY6.js → extract-cmd-2OFQBBJ4.js} +1 -1
- package/dist/{generate-headless-NCVM643E.js → generate-headless-B35UUR5A.js} +2 -2
- package/dist/index.js +26 -26
- package/dist/{ingest-cmd-42VRDSPV.js → ingest-cmd-LAUSXSI3.js} +1 -1
- package/dist/install-ENSOEMSX.js +2 -0
- package/dist/{interactive-bind-ZDJS7PCV.js → interactive-bind-OWASLPBQ.js} +3 -3
- package/dist/{list-commands-3IKFZSGB.js → list-commands-SLQDF6AT.js} +1 -1
- package/dist/login-flow-YKQUXP75.js +2 -0
- package/dist/{mobile-prompts-XPQSRBIW.js → mobile-prompts-6MGOXIKX.js} +1 -1
- package/dist/persist-recorded-session-RKG7HOEW.js +3 -0
- package/dist/pipeline-M25AR7RM.js +2 -0
- package/dist/prepare-target-UGACDQEJ.js +2 -0
- package/dist/{reconcile-cmd-BKIJFVQT.js → reconcile-cmd-MR2MSVZ5.js} +1 -1
- package/dist/{reconcile-deps-Y5G456WD.js → reconcile-deps-RYO67ZXY.js} +2 -2
- package/dist/{reconcile-engine-WDC2MEOY.js → reconcile-engine-PRH6YIAZ.js} +1 -1
- package/dist/{recording-banner-P3RUW62P.js → recording-banner-CH2SZ4IU.js} +1 -1
- package/dist/registry-ARR5ITIQ.js +2 -0
- package/dist/{require-project-folder-ZGQLWZV5.js → require-project-folder-XY77JKAQ.js} +1 -1
- package/dist/{resolve-run-intent-DHZD6A4B.js → resolve-run-intent-JFIGIF72.js} +1 -1
- package/dist/{resolver-W54NOQXY.js → resolver-6VDNZ6KP.js} +1 -1
- package/dist/{run-BGQTRIU4.js → run-GTBYWSLW.js} +1 -1
- package/dist/{run-7TZTUTTU.js → run-UETW72YU.js} +1 -1
- package/dist/{run-test-md-WO2UDYPM.js → run-test-md-OLGWTC4I.js} +2 -2
- package/dist/{skill-installer-UTVUPOTD.js → skill-installer-NT7ZT6O4.js} +1 -1
- package/dist/{spawner-SHCGHLQS.js → spawner-YQSAPZR4.js} +1 -1
- package/dist/tcg-generate-D73BMKOE.js +2 -0
- package/dist/testmd-actions-XPYXS36F.js +2 -0
- package/dist/token-refresh-2XVSIFRM.js +2 -0
- package/dist/{validate-basic-XEPS5I6V.js → validate-basic-OMAFYHME.js} +1 -1
- package/dist/{verdicts-SOX22V6V.js → verdicts-KEBSV2NL.js} +1 -1
- package/dist/{version-check-LWDLMWBJ.js → version-check-FRVZSYNF.js} +1 -1
- package/dist/{walk-session-M3OIWR5K.js → walk-session-LNFOCPJ6.js} +1 -1
- package/dist/{with-telemetry-SF5RHYQE.js → with-telemetry-4ATZC6IR.js} +1 -1
- package/package.json +11 -11
- package/dist/FolderPicker-HVI6KITN.js +0 -2
- package/dist/SingleShotApp-VJVY3F4H.js +0 -2
- package/dist/TestMdRunView-X3CCNYV5.js +0 -2
- package/dist/bridge-6DCBL3GY.js +0 -2
- package/dist/chunk-7UCICMK7.js +0 -5
- package/dist/chunk-HPBI3P6I.js +0 -6
- package/dist/chunk-LPH4TERT.js +0 -2
- package/dist/chunk-OQAN2WYO.js +0 -26
- package/dist/chunk-UPHF2J5E.js +0 -6
- package/dist/install-5NMP6ZV4.js +0 -2
- package/dist/login-flow-UXUQ7GQT.js +0 -2
- package/dist/persist-recorded-session-MFQ7JCLJ.js +0 -3
- package/dist/pipeline-2XITQU5W.js +0 -2
- package/dist/prepare-target-CKRWHYXS.js +0 -2
- package/dist/registry-OEY4IXB6.js +0 -2
- package/dist/tcg-generate-YDNE643C.js +0 -2
- package/dist/testmd-actions-UCJ4ULSX.js +0 -2
- package/dist/token-refresh-ZNV2OSZC.js +0 -2
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createRequire } from 'module'; const require = createRequire(import.meta.url);
|
|
2
|
-
import{d as
|
|
3
|
-
`),await ie.rename(o,i)}async function gr(e){try{let t=await It(e);return t&&Array.isArray(t.executions)?t.executions:[]}catch{return[]}}async function hr(e,t,r=process.cwd()){let n=await me(e,r);if(!n){let o=`evidence: no pack found for "${e}"`;return t.json?console.log(JSON.stringify({valid:!1,error:"not_found",target:e})):console.error(o),2}let i=await B(n,t.profile??"L1");return t.json?console.log(JSON.stringify({valid:i.valid,status:i.status,diagnostics:i.diagnostics})):console.log(`evidence: ${i.valid?"valid":"INVALID"} (${t.profile??"L1"}, status ${i.status})`),i.valid?0:1}function je(e){let t=[];for(let r of e){let n=r.perFlow&&r.perFlow.length?r.perFlow.map(i=>i.resultCode):[r.resultCode];for(let i of n)t.push(D(i))}return
|
|
4
|
-
`;br(Pt(e,"diagnostics.ndjson"),o)}catch{}}import{promises as I}from"fs";import{dirname as Lr,join as O}from"path";import{statSync as kr}from"fs";import{promises as Ve}from"fs";import{basename as Er,join as Sr}from"path";var Ir=1e6,Rr=2e6;function Pr(){return nt.map(e=>it(e))}function $t(e=Pr()){return e.map(t=>{let r=0;try{r=kr(t).size}catch{}return{path:t,offset:r}})}var $r=/\x1b\[[0-9;]*[A-Za-z]/g;async function Ar(e,t,r){let n;try{n=await Ve.open(e,"r");let i=(await n.stat()).size,o=t<=i?t:0,s=i-o;if(s<=0)return null;let a=s>r?i-r:o,u=Buffer.alloc(Math.min(s,r));return await n.read(u,0,u.length,a),u.toString("utf8")}catch{return null}finally{await n?.close().catch(()=>{})}}async function At(e,t){let r=t.caps?.stderr??Ir,n=t.caps?.appium??Rr,i=[];t.runnerStderrPath&&i.push({src:t.runnerStderrPath,from:0,cap:r});for(let o of t.appiumMarks??[])i.push({src:o.path,from:o.offset,cap:n});for(let o of i){let s=await Ar(o.src,o.from,o.cap);if(s===null)continue;let a=s.replace($r,"");if(a!=="")try{await Ve.mkdir(e,{recursive:!0}),await Ve.writeFile(Sr(e,Er(o.src)),a)}catch{}}}async function Fr(e){try{let t=O(e,"tests"),r=await I.readdir(t).catch(()=>[]);for(let n of r){let i=O(t,n,"steps"),o=await I.readdir(i).catch(()=>[]);for(let s of o){let a=await I.readFile(O(i,s,"failure.yaml"),"utf8").catch(()=>null);if(a!=null)try{let u=A(a);if(u&&typeof u=="object"&&u.triage)return!0}catch{}}}}catch{}return!1}async function Lt(e,t,r,n={}){let i=O(e,"tests",t,"logs");if(r)try{await I.mkdir(i,{recursive:!0}),await I.copyFile(r,O(i,"tui.log"))}catch{}await At(i,{runnerStderrPath:r?O(Lr(r),"runner-stderr.log"):void 0,appiumMarks:n.appiumMarks});let o=await Me(i);if(!o.length&&n.requireRealLog)throw new Error(`evidence test ${t} has no real log to declare`);o.length&&await De(e,t,Fe(o))}async function Be(e){let t=e.cwd??process.cwd(),r=e.packDir??w(e.executionId,t);if(!e.saved&&!e.packDir)return await $e(e.executionId,t),{sealed:!1};await Lt(r,e.testId,e.tuiLogPath,{requireRealLog:e.requireRealLog,appiumMarks:e.appiumMarks});let n=O(r,"run.yaml"),i=A(await I.readFile(n,"utf8"));i.environment={...i.environment??{},saved:e.saved,run_kind:e.runKind},await I.writeFile(n,x(i,{lineWidth:-1}));let o=await I.open(n,"r+");try{await o.sync()}finally{await o.close()}let s=await Fr(r);await z(r,new Date().toISOString());let a;try{let d=await B(r,"L1");a=d.valid;let l=(d.diagnostics??[]).filter(c=>String(c?.code??"").includes("failure.status_disagrees"));if(l.length>0)if(e.expectStatusDisagrees||s){let c=e.expectStatusDisagrees?"expected under --bug-detection continue":"self-explained by triaged failure record(s)";console.warn(`evidence: ${l.length} status_disagrees advisory(ies) \u2014 ${c}`)}else console.warn(`evidence: ${l.length} status_disagrees advisory(ies) \u2014 step verdicts disagree with their failure records`,l);if(!d.valid){console.warn(`evidence: sealed pack ${e.executionId} failed L1 validation`,d.diagnostics);let c=String(d.diagnostics?.[0]?.code??"");Ne(Te(r,e.testId),"warn","EVIDENCE_INVALID",{execution_id:e.executionId,first_code:c,surface:e.surface??"testmd"},e.log)}}catch(d){console.warn(`evidence: validation error for ${e.executionId}`,d)}let u;if(e.saved&&e.packDir)try{u=await dt(r,e.executionId,t)}catch(d){console.warn(`evidence: store install failed for ${e.executionId}`,d)}if(e.outputStemDir)try{await Oe(e.outputStemDir,{execution_id:e.executionId,run_kind:e.runKind,status:e.verdict,valid:a,at:new Date().toISOString()})}catch(d){console.warn(`evidence: execution-pointer append failed for ${e.executionId} (pack is sealed)`,d)}return{sealed:!0,valid:a,storePath:u}}import{release as jt}from"os";import{execFileSync as Cr}from"child_process";import{promises as Ft}from"fs";import{join as Ct}from"path";function Dt(e){return e.replace(/\([^)]*\)/g," ").toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")||void 0}async function Ot(e){try{let t=Ct(e,"steps"),r=(await Ft.readdir(t,{withFileTypes:!0})).filter(n=>n.isDirectory()).map(n=>n.name).sort((n,i)=>(parseInt(n,10)||0)-(parseInt(i,10)||0));for(let n of r)try{let i=await Ft.readFile(Ct(t,n,"step.json"),"utf8"),s=JSON.parse(i).basis?.window;if(Array.isArray(s)&&s.length===2&&Number.isFinite(Number(s[0]))&&Number.isFinite(Number(s[1]))&&Number(s[0])>0&&Number(s[1])>0)return`${Math.round(Number(s[0]))}x${Math.round(Number(s[1]))}`}catch{}return}catch{return}}var Mt=!1,oe;function Dr(){if(!Mt)if(Mt=!0,process.platform==="darwin")try{oe=Cr("sw_vers",["-productVersion"],{timeout:2e3}).toString().trim()||void 0}catch{oe=jt()||void 0}else oe=jt()||void 0;return oe}function ze(e){let t={os:le(process.platform)},r=Dr();if(r&&(t.os_version=r),e.cdpBrowser){let i=/^([A-Za-z]+)\/(\d+)/.exec(e.cdpBrowser);i&&(t.browser=i[1].replace(/^Headless/,""),t.browser_version=i[2])}e.resolution&&(t.resolution=e.resolution);let n=st(t,e.runnerEnvironment);if(!n.native_platform)return n;if(e.deviceName&&(n.device=e.deviceName),e.deviceModel){let i=Dt(e.deviceModel);i&&(n.device_slug=i)}return e.pixelResolution&&(n.viewport=n.resolution??Or(e.pixelResolution,n.pixel_ratio)??e.pixelResolution,n.resolution=e.pixelResolution),n}function Or(e,t){if(!t||!Number.isFinite(t)||t<=0)return;let r=/^(\d+)x(\d+)$/.exec(e);if(r)return`${Math.round(Number(r[1])/t)}x${Math.round(Number(r[2])/t)}`}async function Tt(e){if(e)try{let t=await fetch(`${e}/json/version`,{signal:AbortSignal.timeout(2e3)});if(!t.ok)return;let r=await t.json();return typeof r.Browser=="string"?r.Browser:void 0}catch{return}}function jr(e){let t;return()=>(t||(t=Tt(e)),t)}import{promises as R,existsSync as P,readFileSync as Vr}from"fs";import{basename as Br,join as h}from"path";import{readFileSync as Mr}from"fs";import{dirname as Tr,resolve as Nr}from"path";function Nt(e,t){let r=Nr(e),n=Mr(r,"utf8");return L(t?G(n,Z(Tr(r),t)):n)}var H=class e{constructor(t){this.opts=t}executionId;testId;definitionPath=null;definitionContent=null;accumulatedSteps=[];maxOrdinal=0;_attempts=[];_packDirOverride;_attached=!1;appiumMarks=$t();get attached(){return this._attached}static async attach(t){let r=Br(t.packDir).replace(/\.evidence$/,""),n=new e({origin:"testrun",runKind:"author",pid:process.pid,title:t.testId,started:new Date().toISOString(),producerVersion:rt,cwd:t.cwd});n.executionId=r,n.testId=t.testId,n._packDirOverride=t.packDir,n._attached=!0;let i=h(t.packDir,"tests",t.testId);return await R.mkdir(i,{recursive:!0}),t.definition&&(await R.writeFile(h(i,t.definition.path),t.definition.content),n.definitionPath=t.definition.path,n.definitionContent=t.definition.content),n}async start(){if(this._attached)throw new Error("attach-mode session is already started");this.executionId=fe(),this.testId=this.opts.testmdRelPath?Ee(this.opts.testmdRelPath):Se(this.opts.objectiveOrName??"session",this.opts.sessionId??this.executionId);let t=this.opts.definition??null;return await Pe({execution_id:this.executionId,title:this.opts.title,started:this.opts.started,producerVersion:this.opts.producerVersion,surfaces:this.opts.surfaces,run_kind:this.opts.runKind,origin:this.opts.origin,pid:this.opts.pid,...this.opts.credits!==void 0?{credits:this.opts.credits}:{}},this.testId,t,this.opts.cwd,this.opts.packRootDir?this.pack:void 0),t&&(this.definitionPath=t.path,this.definitionContent=t.content),{executionId:this.executionId,testId:this.testId,packTestDir:this.packTestDir}}get pack(){return this._packDirOverride?this._packDirOverride:this.opts.packRootDir?h(this.opts.packRootDir,`${this.executionId}.evidence`):w(this.executionId,this.opts.cwd)}get packTestDir(){return h(this.pack,"tests",this.testId)}async writeDefinition(t,r="test.md"){await R.writeFile(h(this.packTestDir,r),t),this.definitionPath=r,this.definitionContent=t}computeAssuranceId(){try{if(this.opts.testmdRelPath&&this.opts.cwd){let t=h(this.opts.cwd,this.opts.testmdRelPath);if(P(t))return F(Vr(t,"utf8"))?.id}}catch{}}computeDefinitionId(){try{if(this.opts.testmdRelPath&&this.opts.cwd){let t=h(this.opts.cwd,this.opts.testmdRelPath),r=h(this.opts.cwd,".context"),n=P(r)?b(r):void 0;if(P(t))return Nt(t,n)}if(this.definitionContent!=null)return L(this.definitionContent)}catch{}}noteSpawn(t){this.accumulatedSteps.push(...t.steps),this.maxOrdinal=Math.max(this.maxOrdinal,t.maxOrdinal)}nextOrdinalOffset(){return this.maxOrdinal}get steps(){return this.accumulatedSteps}get attempts(){return this._attempts}async archiveAttempt(t,r){let n=this._attempts.length+1,i=h(this.packTestDir,String(n)),o;try{await R.mkdir(i,{recursive:!0});for(let a of["steps","logs","v16-trajectory"]){let u=h(this.packTestDir,a);P(u)&&await R.rename(u,h(i,a))}this.definitionPath&&P(h(this.packTestDir,this.definitionPath))&&await R.copyFile(h(this.packTestDir,this.definitionPath),h(i,this.definitionPath));let s=h(i,"steps");if(P(s)){for(let a of await R.readdir(s))if(P(h(s,a,"failure.yaml"))){o=`${n}/steps/${a}/failure.yaml`;break}}}catch{}return this._attempts.push({n,status:t,steps:this.accumulatedSteps,...r!==void 0?{failedAt:r}:{},...o?{failure:o}:{}}),this.accumulatedSteps=[],this.maxOrdinal=0,n}async writeResult(t){let r=je(t.spawns),n=this._attempts.length?[...this._attempts.map(c=>({status:c.status})),{status:r,...t.durationMs!==void 0?{duration_ms:t.durationMs}:{}}]:void 0,i=n?new Set(n.map(c=>c.status)).size>1:void 0,o=this._attempts.length?{triggered:!0,outcome:r==="passed"?"healed":"exhausted",attempts:this._attempts.map(c=>({n:c.n,status:c.status,failed_at:c.failedAt??-1,...c.failure?{failure:c.failure}:{}}))}:void 0,s=this.pack,a=Ie(t.externalIdInput),u=pe(t.runnerEnv,t.intentEnv),d=this.computeDefinitionId(),p=this.computeAssuranceId();await Ce(s,this.testId,ne({testId:this.testId,status:r,durationMs:t.durationMs,definitionPath:this.definitionPath,definitionId:d,assuranceId:p,externalId:a,environment:u,steps:t.steps,tags:t.tags,attempts:n,flaky:i,adaptiveHeal:o}));for(let c of this._attempts){let f=h(this.packTestDir,String(c.n));P(f)&&await R.writeFile(h(f,"result.yaml"),ne({testId:this.testId,status:c.status,definitionPath:this.definitionPath,definitionId:d,assuranceId:p,externalId:a,environment:u,steps:c.steps,tags:t.tags}))}let l=t.externalIdInput;return t.log&&(l.commit_id||l.test_id||l.testcase_id)&&t.log("info","EVIDENCE_EXTERNAL_ID","Evidence external-id mapping",{execution_id:this.executionId,commit_id:l.commit_id??null,test_id:l.test_id??null,testcase_id:l.testcase_id??null,project_id:l.project_id??null,session_id:l.session_id??null,session_name:l.session_name??null}),r}get id(){return this.executionId}get test(){return this.testId}};async function zr(e,t,r=ge){try{let n=await r(e);if(n.aborted.length>0||n.removed.length>0)try{t?.("info","EVIDENCE_RECOVERY","Startup evidence recovery swept incomplete packs",{aborted:n.aborted,removed:n.removed,origin:"startup"})}catch{}return n}catch(n){return console.warn("evidence: startup recovery failed",n),{aborted:[],removed:[]}}}import{promises as ln}from"fs";import{existsSync as We,mkdirSync as nn,readdirSync as on,readFileSync as sn,rmSync as an,statSync as cn,writeFileSync as dn}from"fs";import{join as T}from"path";import{mkdirSync as Gr,renameSync as Ur,rmSync as qr,writeFileSync as Wr}from"fs";import{join as Vt}from"path";var Yr=5e6;function Bt(e,t,r){let n=Vt(e,"coverage","sources"),i=new Map,o=!1;try{for(let s of r.usecases)for(let a of s.sources){if(i.has(a.id)){a.file=i.get(a.id);continue}if(!a.cid)continue;let u=kt(t,a.cid);if(u===null||u.byteLength>Yr)continue;o||(Gr(n,{recursive:!0}),o=!0);let d=Vt(n,a.id),p=`${d}.tmp-${process.pid}`;Wr(p,u),Ur(p,d);let l=`coverage/sources/${a.id}`;i.set(a.id,l),a.file=l}}catch{for(let s of r.usecases)for(let a of s.sources)delete a.file;if(o)try{qr(n,{recursive:!0,force:!0})}catch{}}}import{appendFileSync as Jt,existsSync as j,readFileSync as $,renameSync as Xt,writeFileSync as Qt}from"fs";import{dirname as Ue,isAbsolute as ae,join as M,resolve as ce}from"path";var Hr=new Set(["inline","testmd","testrun"]),Kr=new Set(["inferred","authored","runtime-derived"]),se=new Set(["passed","failed","broken","skipped"]);function zt(e,t,r){if(r.facts.length===0)return{record:null,errors:[{code:"EMPTY_EXECUTIONS",detail:"a run with no designed units attaches no facts \u2014 skip the call"}]};let n=t;for(let i=0;;i++){let o=te(e);if(n.latestHash!==o){if(i>=3)return{record:null,errors:[{code:"STALE_BASIS",detail:`graph opened at ${String(n.latestHash)} but chain head is ${String(o)} \u2014 retry budget exhausted`}]};n=b(e);continue}let s=Jr(e,n,r);if(s!=="cas")return s;if(i>=3)return{record:null,errors:[{code:"STALE_BASIS",detail:"concurrent appends kept moving the head \u2014 retry budget exhausted"}]};n=b(e)}}function Gt(e,t){return Hr.has(e.mode)?se.has(e.verdict)?Kr.has(e.oracle_mode)?typeof e.drift_flag!="boolean"||typeof e.stale_at_run!="boolean"?[{code:"MISSING_FIELD",detail:`${t}: drift_flag and stale_at_run are required booleans`}]:!e.execution_id||!e.started_at||!e.definition_id_at_run?[{code:"MISSING_FIELD",detail:`${t}: execution_id, started_at and definition_id_at_run are required`}]:[]:[{code:"BAD_ORACLE_MODE",detail:`${t}: oracle_mode '${e.oracle_mode}' not in inferred|authored|runtime-derived`}]:[{code:"BAD_VERDICT",detail:`${t}: verdict '${e.verdict}' not in ${[...se].join("|")}`}]:[{code:"BAD_MODE",detail:`${t}: mode '${e.mode}' not in inline|testmd|testrun`}]}function Ut(e,t,r,n){return{about:t,definition_id_at_run:e.definition_id_at_run,verdict:e.verdict,...r&&r.length?{per_ac:r}:{},drift_flag:e.drift_flag,oracle_mode:e.oracle_mode,stale_at_run:e.stale_at_run,...n.length?{unresolved_acs:n}:{},execution_id:e.execution_id,...e.evidence_id?{evidence_id:e.evidence_id}:{},...e.duration_ms!==void 0?{duration_ms:e.duration_ms}:{},started_at:e.started_at,mode:e.mode,local:e.local,...e.via_parent?{via_parent:e.via_parent}:{}}}function qt(e,t){if(!Array.isArray(t.facts)||t.facts.length===0)return{record:null,errors:[{code:"EMPTY_EXECUTIONS",detail:"parked line carries no facts"}]};for(let r=0;;r++){let n=b(e),i=t.facts.filter(d=>n.appliedEvents.has(d.event_id)).map(d=>d.event_id),o=t.facts.filter(d=>!n.appliedEvents.has(d.event_id));if(o.length===0)return{record:null,errors:null,applied:[],skipped:i,rejected:[]};let s=[],a=[],u=[];for(let d of o){let p=`executions[${d.ref}]`,l=[];if(!d.about_cid||!n.hasNode(d.about_cid))l.push({code:"UNKNOWN_REF",detail:`${p}: about_cid '${String(d.about_cid)}' is not in the graph \u2014 the pinned run-time target is gone`});else if(n.nodeLabel.get(d.about_cid)!==U.TEST)l.push({code:"ILLEGAL_TARGET",detail:`${p}: execution facts attach to tests \u2014 '${d.about_cid}' is a ${n.nodeLabel.get(d.about_cid)}`});else if(!d.event_id)l.push({code:"MISSING_FIELD",detail:`${p}: parked facts require event_id`});else{l.push(...Gt(d,p));for(let m of d.per_ac??[])se.has(m.verdict)||l.push({code:"BAD_VERDICT",detail:`${p}.per_ac['${m.ac_ref}']: verdict '${m.verdict}'`})}if(l.length>0){s.push({event_id:d.event_id??"",errors:l});continue}let c=[],f=[...d.unresolved_acs??[]];for(let m of d.per_ac??[]){let g=n.resolve(m.ac_ref),_=g?n.tipOf(g.cid):null;if(!g||!_||n.superseded.has(_)||n.nodeLabel.get(_)!==U.AC){f.push(m.ac_ref);continue}c.push({ac_ref:n.nameOf.get(_)??_,verdict:m.verdict})}a.push(Ut(d,d.about_cid,c,f)),u.push(d.event_id)}if(a.length===0)return{record:null,errors:null,applied:[],skipped:i,rejected:s};try{let d=q(e,{ts:new Date().toISOString(),proposal_id:null,nodes:[],edges:[],review:[],supersessions:[],executions:a,event_ids:[...u].sort(),source_head_moves:{}},{expectPrev:n.latestHash,busyRetry:{deadlineMs:5e3}}),p;try{W(e)}catch(l){p=`parked facts committed, but the projection refresh failed (${l instanceof Error?l.message:String(l)}) \u2014 read state rebuilds on the next open`}return{record:d.record,errors:null,applied:u,skipped:i,rejected:s,...p?{warnings:[p]}:{}}}catch(d){if(!(d instanceof ve))throw d;if(r>=3)return{record:null,errors:[{code:"STALE_BASIS",detail:"concurrent appends kept moving the head \u2014 parked replay retry budget exhausted (line stays queued)"}]}}}}function Jr(e,t,r){let n=[],i=[];for(let a of r.facts){let u=`executions[${a.ref}]`,d=t.resolve(a.ref),p=d?t.tipOf(d.cid):null;if(!d||!p||t.superseded.has(p)){n.push({code:"UNKNOWN_REF",detail:`${u}: '${a.ref}' is not a live committed node`});continue}if(t.nodeLabel.get(p)!==U.TEST){n.push({code:"ILLEGAL_TARGET",detail:`${u}: execution facts attach to tests \u2014 '${a.ref}' is a ${t.nodeLabel.get(p)}`});continue}let l=Gt(a,u);if(l.length>0){n.push(...l);continue}let c=[];for(let f of a.per_ac??[]){let m=t.resolve(f.ac_ref),g=m?t.tipOf(m.cid):null;if(!m||!g||t.superseded.has(g)||t.nodeLabel.get(g)!==U.AC){n.push({code:"UNKNOWN_REF",detail:`${u}.per_ac: '${f.ac_ref}' is not a live AC`});continue}if(!se.has(f.verdict)){n.push({code:"BAD_VERDICT",detail:`${u}.per_ac['${f.ac_ref}']: verdict '${f.verdict}'`});continue}c.push({ac_ref:t.nameOf.get(g)??g,verdict:f.verdict})}i.push(Ut(a,p,c,a.unresolved_acs??[]))}if(n.length>0)return{record:null,errors:n};let o;try{o=q(e,{ts:new Date().toISOString(),proposal_id:null,nodes:[],edges:[],review:[],supersessions:[],executions:i,...r.eventIds&&r.eventIds.length>0?{event_ids:r.eventIds}:{},source_head_moves:{}},{expectPrev:t.latestHash,busyRetry:{deadlineMs:r.lockDeadlineMs??5e3}})}catch(a){if(a instanceof ve)return"cas";throw a}let s;try{W(e)}catch(a){s=`facts committed, but the projection refresh failed (${a instanceof Error?a.message:String(a)}) \u2014 read state rebuilds on the next open`}return{record:o.record,errors:null,...s?{warnings:[s]}:{}}}function Zt(e){let t={failed:3,broken:2,skipped:1,passed:0},r=new Map;for(let n of e)for(let i of n.verifies??[]){let o=r.get(i);(o===void 0||(t[n.status]??0)>(t[o]??0))&&r.set(i,n.status)}return[...r.entries()].map(([n,i])=>({ref:n,verdict:i}))}function er(e){let t=[],r=re(e.cwd);if(!j(r))return{synced:0,superseded:0,skipped:"no-context",warnings:t};let n=e.by??{kind:"ai",id:"exec-sync"},i=e.lockDeadlineMs;try{Xr(r,t,i)}catch(c){t.push(`sync: parked-facts replay failed (${c instanceof Error?c.message:String(c)}) \u2014 queue intact, retrying next sync`)}let o=b(r),s=[],a=0,u=new Set,d=new Set(e.members.map(c=>ae(c.path)?c.path:ce(e.cwd,c.path))),p=new Map;for(let c of e.members){let f=ae(c.path)?c.path:ce(e.cwd,c.path);if(!j(f)){t.push(`sync: member file missing: ${f} \u2014 skipped, no fact attached`);continue}for(let m of Qr(f,t))if(!u.has(m.path))try{let g=m.path===f,_=!g&&d.has(m.path),v=g?void 0:F($(f,"utf8"))?.id,K=$(m.path,"utf8"),k=F(K);if(!k?.id){u.add(m.path);continue}let ue=o.resolve(k.id),N=ue?o.tipOf(ue.cid):null;if(!ue||!N||o.superseded.has(N)){u.add(m.path),t.push(`sync: ${k.id} does not resolve to a live test \u2014 skipped (foreign store?)`);continue}let J=L(G(K,Z(Ue(m.path),o))),dr=String(o.getNode(N)?.content.test_md_blob??""),X=L(G(dr,mt(o))),V=!1,Q=N;if(J===X)k.base!==X&&Kt(m.path,K,X,t);else if(k.base===X){let y=en(r,o,N,K,J,Ue(m.path),n);y.error?(t.push(`sync: could not supersede ${k.id}: ${y.error}`),V=!0):(a++,Q=y.newCid,V=y.oracleTier,Kt(m.path,$(m.path,"utf8"),J,t),o=b(r))}else V=!0,t.push(k.base?`sync: ${k.id} was edited from an older version \u2014 graph kept; reconcile via a redesign or maintain`:`sync: ${k.id} carries no base pin (hand-copied file?) \u2014 fact attached with drift flag`);if(_){V&&p.set(m.path,!0);continue}u.add(m.path);let Qe=o.getNode(Q)?.content.check,Ze=g?c.acs??[]:[],et=Ze.filter(y=>Yt(o,y.ref)),tt=Ze.filter(y=>!Yt(o,y.ref)).map(y=>y.ref);s.push({ref:k.id,about_cid:Q,definition_id_at_run:J,verdict:c.verdict,...et.length?{per_ac:et.map(y=>({ac_ref:y.ref,verdict:y.verdict}))}:{},drift_flag:V||p.get(m.path)===!0||g&&c.driftFlag===!0,oracle_mode:Qe?.expected_mode??(ut(Qe?.operand)?"runtime-derived":"inferred"),stale_at_run:o.stale(Q)!=="fresh",...tt.length?{unresolved_acs:tt}:{},execution_id:c.executionId,...c.evidenceId?{evidence_id:c.evidenceId}:{},...c.durationMs!==void 0?{duration_ms:c.durationMs}:{},started_at:c.startedAt,mode:c.mode,local:c.local,...v?{via_parent:v}:{}})}catch(g){m.path!==f&&d.has(m.path)||u.add(m.path),t.push(`sync: ${m.path} failed to sync (${g instanceof Error?g.message:String(g)}) \u2014 skipped; other members unaffected`)}}if(s.length===0)return{synced:0,superseded:a,warnings:t};let l;try{l=zt(r,b(r),{facts:s,by:n,lockDeadlineMs:i})}catch(c){return t.push(`sync facts: commit threw: ${c instanceof Error?c.message:String(c)}`),Wt(r,s,n,t,i),{synced:0,superseded:a,warnings:t}}return l.errors?(Wt(r,s,n,t,i),t.push(...l.errors.map(c=>`sync facts: ${c.code}: ${c.detail}`)),{synced:0,superseded:a,warnings:t}):(l.warnings&&t.push(...l.warnings.map(c=>`sync facts: ${c}`)),{synced:s.length,superseded:a,warnings:t})}var qe="pending-facts.ndjson",Ge=".pending-facts.bad";function Wt(e,t,r,n,i){try{let o={by:r,ts:new Date().toISOString(),facts:t.map(a=>({...a,about_cid:a.about_cid??"",event_id:`exec-fact:${a.execution_id}:${a.ref}`}))},s=null;try{s=ee(e,{deadlineMs:i??5e3})}catch{n.push("sync facts: store lock busy \u2014 parking without it (a concurrent queue rewrite may race this line)")}try{Jt(M(e,qe),JSON.stringify(o)+`
|
|
2
|
+
import{d as bt,g as xt}from"./chunk-QQ5MHSSY.js";import{b as ye,c as Y,d as we,e as _e}from"./chunk-HNNVVK2O.js";import{b as w,c as fe,d as dt,f as me,g as ge}from"./chunk-5GUD3CIH.js";import{a as ut,d as lt,h as L,i as pt,j as ft,k as G,l as mt,m as Z,n as gt,o as F,p as ht}from"./chunk-H4WIA4IP.js";import{a as B,b as z,d as ct}from"./chunk-EHN5HTUD.js";import{d as he}from"./chunk-IPEA7ZOF.js";import{d as kt}from"./chunk-NVGBE2DR.js";import{a as re}from"./chunk-CH273NAE.js";import{b as A,c as b}from"./chunk-VZ7KXRXB.js";import{a as le,c as ot,d as st,e as at,f as pe}from"./chunk-P7YZ3PU3.js";import{C as x,e as wt,f as _t}from"./chunk-W3Z7AZNT.js";import{b as W}from"./chunk-6FCPS2VT.js";import{a as yt}from"./chunk-UH2ZTX4E.js";import{b as ve,d as ee,g as te,j as q}from"./chunk-XMTSHHYQ.js";import{d as U,f as vt}from"./chunk-AKX4VRRR.js";import{a as nt,b as it}from"./chunk-HE3ZKFRC.js";import{a as rt}from"./chunk-WEJA3EVI.js";function D(e){if(e===null)return"broken";let t=Math.floor(e/100);return t===1?"passed":t===7?"failed":t===2?"skipped":"broken"}var C={failed:3,broken:2,passed:1,skipped:0};function be(e){let t="skipped";for(let r of e)C[r]>C[t]&&(t=r);return t}import{createHash as ur}from"crypto";import{basename as lr}from"path";function xe(e){let t=e.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"").slice(0,40);return t.length>0?t:"session"}function ke(e){return ur("sha256").update(e).digest("hex").slice(0,8)}function Ee(e){let t=lr(e).replace(/_test\.md$/i,"").replace(/\.md$/i,"");return`${xe(t)}-${ke(e)}`}function Se(e,t){return`${xe(e)}-${ke(t)}`}function Ie(e){let t={};for(let[r,n]of Object.entries(e))typeof n=="string"&&n.length>0&&(t[r]=n);return t}function pr(e,t){return{pack_test_dir:e,ordinal_offset:t}}import{promises as E}from"fs";import{join as S}from"path";function Re(e){let t={evidence:"0.1",run_id:e.execution_id,status:"running",title:e.title,started:e.started,environment:{producer:{name:"kane-cli",version:e.producerVersion},...e.surfaces?{surfaces:e.surfaces}:{},run_kind:e.run_kind,origin:e.origin,pid:e.pid},...e.credits!==void 0?{metrics:{credits:{value:e.credits,type:"count"}}}:{}};return b(t,{lineWidth:-1})}async function Pe(e,t,r,n=process.cwd(),i){let o=i??w(e.execution_id,n),s=S(o,"tests",t);return await E.mkdir(S(o,"coverage"),{recursive:!0}),await E.writeFile(S(o,"coverage",".keep"),""),await E.mkdir(s,{recursive:!0}),await E.writeFile(S(o,"run.yaml"),Re(e)),r&&await E.writeFile(S(s,r.path),r.content),o}async function fr(e,t=process.cwd()){let r=w(e.execution_id,t);await E.mkdir(S(r,"coverage"),{recursive:!0}),await E.writeFile(S(r,"coverage",".keep"),"");let n=A(Re(e));return n.environment&&delete n.environment.run_kind,await E.writeFile(S(r,"run.yaml"),b(n,{lineWidth:-1})),r}async function mr(e,t=process.cwd()){return z(w(e,t),new Date().toISOString())}async function $e(e,t=process.cwd()){await E.rm(w(e,t),{recursive:!0,force:!0})}import{promises as Ae}from"fs";import{join as Le}from"path";function ne(e){let t={evidence:"0.1",test:e.testId,status:e.status,...e.durationMs!==void 0?{duration_ms:e.durationMs}:{},...e.attempts&&e.attempts.length?{attempts:e.attempts}:{},...e.flaky!==void 0?{flaky:e.flaky}:{},...e.adaptiveHeal?{adaptive_heal:e.adaptiveHeal}:{},...e.definitionPath?{definition:{path:e.definitionPath}}:{},...e.definitionId?{definition_id:e.definitionId}:{},...e.assuranceId?{assurance_id:e.assuranceId}:{},...Object.keys(e.externalId).length?{external_id:e.externalId}:{},...e.tags&&e.tags.length?{tags:e.tags}:{},...Object.keys(e.environment).length?{environment:e.environment}:{},steps:e.steps};return b(t,{lineWidth:-1})}function Fe(e){return b({logs:e},{lineWidth:-1})}async function Ce(e,t,r){await Ae.writeFile(Le(e,"tests",t,"result.yaml"),r)}async function De(e,t,r){let n=Le(e,"tests",t,"logs");await Ae.mkdir(n,{recursive:!0}),await Ae.writeFile(Le(n,"meta.yaml"),r)}import{promises as ie}from"fs";import{join as Et}from"path";function St(e){return Et(e,".internal","meta.json")}async function It(e){let t;try{t=await ie.readFile(St(e),"utf8")}catch(n){if(n?.code==="ENOENT")return null;throw n}let r=JSON.parse(t);if(!r||typeof r!="object"||Array.isArray(r))throw new Error("meta.json is not a JSON object");return r}async function Oe(e,t){let r;try{r=await It(e)??{}}catch(s){console.warn(`evidence: meta.json at ${e} unreadable \u2014 skipping execution-pointer append to preserve identity`,s);return}let n=Array.isArray(r.executions)?r.executions:[];n.push(t),r.executions=n,await ie.mkdir(Et(e,".internal"),{recursive:!0});let i=St(e),o=`${i}.tmp-${process.pid}-${Date.now()}`;await ie.writeFile(o,JSON.stringify(r,null,2)+`
|
|
3
|
+
`),await ie.rename(o,i)}async function gr(e){try{let t=await It(e);return t&&Array.isArray(t.executions)?t.executions:[]}catch{return[]}}async function hr(e,t,r=process.cwd()){let n=await me(e,r);if(!n){let o=`evidence: no pack found for "${e}"`;return t.json?console.log(JSON.stringify({valid:!1,error:"not_found",target:e})):console.error(o),2}let i=await B(n,t.profile??"L1");return t.json?console.log(JSON.stringify({valid:i.valid,status:i.status,diagnostics:i.diagnostics})):console.log(`evidence: ${i.valid?"valid":"INVALID"} (${t.profile??"L1"}, status ${i.status})`),i.valid?0:1}function je(e){let t=[];for(let r of e){let n=r.perFlow&&r.perFlow.length?r.perFlow.map(i=>i.resultCode):[r.resultCode];for(let i of n)t.push(D(i))}return be(t)}function vr(e){let t=null;for(let r of e){let n=r.perFlow&&r.perFlow.length?r.perFlow.map(i=>i.resultCode):[r.resultCode];for(let i of n)i!=null&&(t==null||C[D(i)]>C[D(t)]||C[D(i)]===C[D(t)]&&i>t)&&(t=i)}return t}import{promises as yr}from"fs";import{extname as Rt,basename as wr}from"path";var _r={".ndjson":"ndjson",".log":"log",".json":"json",".har":"har"};async function Me(e){let t;try{t=await yr.readdir(e)}catch{return[]}return t.filter(r=>r!=="meta.yaml"&&!r.startsWith(".")).sort().map(r=>({name:wr(r,Rt(r)),file:r,format:_r[Rt(r)]??"txt"}))}import{mkdirSync as br,appendFileSync as xr}from"fs";import{join as Pt}from"path";function Te(e,t){return Pt(e,"tests",t,"logs")}function Ne(e,t,r,n={},i){try{i?.(t,r,r,n)}catch{}if(e)try{br(e,{recursive:!0});let o=JSON.stringify({ts:new Date().toISOString(),level:t,event:r,...n})+`
|
|
4
|
+
`;xr(Pt(e,"diagnostics.ndjson"),o)}catch{}}import{promises as I}from"fs";import{dirname as Lr,join as O}from"path";import{statSync as kr}from"fs";import{promises as Ve}from"fs";import{basename as Er,join as Sr}from"path";var Ir=1e6,Rr=2e6;function Pr(){return nt.map(e=>it(e))}function $t(e=Pr()){return e.map(t=>{let r=0;try{r=kr(t).size}catch{}return{path:t,offset:r}})}var $r=/\x1b\[[0-9;]*[A-Za-z]/g;async function Ar(e,t,r){let n;try{n=await Ve.open(e,"r");let i=(await n.stat()).size,o=t<=i?t:0,s=i-o;if(s<=0)return null;let a=s>r?i-r:o,u=Buffer.alloc(Math.min(s,r));return await n.read(u,0,u.length,a),u.toString("utf8")}catch{return null}finally{await n?.close().catch(()=>{})}}async function At(e,t){let r=t.caps?.stderr??Ir,n=t.caps?.appium??Rr,i=[];t.runnerStderrPath&&i.push({src:t.runnerStderrPath,from:0,cap:r});for(let o of t.appiumMarks??[])i.push({src:o.path,from:o.offset,cap:n});for(let o of i){let s=await Ar(o.src,o.from,o.cap);if(s===null)continue;let a=s.replace($r,"");if(a!=="")try{await Ve.mkdir(e,{recursive:!0}),await Ve.writeFile(Sr(e,Er(o.src)),a)}catch{}}}async function Fr(e){try{let t=O(e,"tests"),r=await I.readdir(t).catch(()=>[]);for(let n of r){let i=O(t,n,"steps"),o=await I.readdir(i).catch(()=>[]);for(let s of o){let a=await I.readFile(O(i,s,"failure.yaml"),"utf8").catch(()=>null);if(a!=null)try{let u=A(a);if(u&&typeof u=="object"&&u.triage)return!0}catch{}}}}catch{}return!1}async function Lt(e,t,r,n={}){let i=O(e,"tests",t,"logs");if(r)try{await I.mkdir(i,{recursive:!0}),await I.copyFile(r,O(i,"tui.log"))}catch{}await At(i,{runnerStderrPath:r?O(Lr(r),"runner-stderr.log"):void 0,appiumMarks:n.appiumMarks});let o=await Me(i);if(!o.length&&n.requireRealLog)throw new Error(`evidence test ${t} has no real log to declare`);o.length&&await De(e,t,Fe(o))}async function Be(e){let t=e.cwd??process.cwd(),r=e.packDir??w(e.executionId,t);if(!e.saved&&!e.packDir)return await $e(e.executionId,t),{sealed:!1};await Lt(r,e.testId,e.tuiLogPath,{requireRealLog:e.requireRealLog,appiumMarks:e.appiumMarks});let n=O(r,"run.yaml"),i=A(await I.readFile(n,"utf8"));i.environment={...i.environment??{},saved:e.saved,run_kind:e.runKind},await I.writeFile(n,b(i,{lineWidth:-1}));let o=await I.open(n,"r+");try{await o.sync()}finally{await o.close()}let s=await Fr(r);await z(r,new Date().toISOString());let a;try{let d=await B(r,"L1");a=d.valid;let l=(d.diagnostics??[]).filter(c=>String(c?.code??"").includes("failure.status_disagrees"));if(l.length>0)if(e.expectStatusDisagrees||s){let c=e.expectStatusDisagrees?"expected under --bug-detection continue":"self-explained by triaged failure record(s)";console.warn(`evidence: ${l.length} status_disagrees advisory(ies) \u2014 ${c}`)}else console.warn(`evidence: ${l.length} status_disagrees advisory(ies) \u2014 step verdicts disagree with their failure records`,l);if(!d.valid){console.warn(`evidence: sealed pack ${e.executionId} failed L1 validation`,d.diagnostics);let c=String(d.diagnostics?.[0]?.code??"");Ne(Te(r,e.testId),"warn","EVIDENCE_INVALID",{execution_id:e.executionId,first_code:c,surface:e.surface??"testmd"},e.log)}}catch(d){console.warn(`evidence: validation error for ${e.executionId}`,d)}let u;if(e.saved&&e.packDir)try{u=await dt(r,e.executionId,t)}catch(d){console.warn(`evidence: store install failed for ${e.executionId}`,d)}if(e.outputStemDir)try{await Oe(e.outputStemDir,{execution_id:e.executionId,run_kind:e.runKind,status:e.verdict,valid:a,at:new Date().toISOString()})}catch(d){console.warn(`evidence: execution-pointer append failed for ${e.executionId} (pack is sealed)`,d)}return{sealed:!0,valid:a,storePath:u}}import{release as jt}from"os";import{execFileSync as Cr}from"child_process";import{promises as Ft}from"fs";import{join as Ct}from"path";function Dt(e){return e.replace(/\([^)]*\)/g," ").toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")||void 0}async function Ot(e){try{let t=Ct(e,"steps"),r=(await Ft.readdir(t,{withFileTypes:!0})).filter(n=>n.isDirectory()).map(n=>n.name).sort((n,i)=>(parseInt(n,10)||0)-(parseInt(i,10)||0));for(let n of r)try{let i=await Ft.readFile(Ct(t,n,"step.json"),"utf8"),s=JSON.parse(i).basis?.window;if(Array.isArray(s)&&s.length===2&&Number.isFinite(Number(s[0]))&&Number.isFinite(Number(s[1]))&&Number(s[0])>0&&Number(s[1])>0)return`${Math.round(Number(s[0]))}x${Math.round(Number(s[1]))}`}catch{}return}catch{return}}var Mt=!1,oe;function Dr(){if(!Mt)if(Mt=!0,process.platform==="darwin")try{oe=Cr("sw_vers",["-productVersion"],{timeout:2e3}).toString().trim()||void 0}catch{oe=jt()||void 0}else oe=jt()||void 0;return oe}function ze(e){let t={os:le(process.platform)},r=Dr();if(r&&(t.os_version=r),e.cdpBrowser){let i=/^([A-Za-z]+)\/(\d+)/.exec(e.cdpBrowser);i&&(t.browser=i[1].replace(/^Headless/,""),t.browser_version=i[2])}e.resolution&&(t.resolution=e.resolution);let n=st(t,e.runnerEnvironment);if(!n.native_platform)return n;if(e.deviceName&&(n.device=e.deviceName),e.deviceModel){let i=Dt(e.deviceModel);i&&(n.device_slug=i)}return e.pixelResolution&&(n.viewport=n.resolution??Or(e.pixelResolution,n.pixel_ratio)??e.pixelResolution,n.resolution=e.pixelResolution),n}function Or(e,t){if(!t||!Number.isFinite(t)||t<=0)return;let r=/^(\d+)x(\d+)$/.exec(e);if(r)return`${Math.round(Number(r[1])/t)}x${Math.round(Number(r[2])/t)}`}async function Tt(e){if(e)try{let t=await fetch(`${e}/json/version`,{signal:AbortSignal.timeout(2e3)});if(!t.ok)return;let r=await t.json();return typeof r.Browser=="string"?r.Browser:void 0}catch{return}}function jr(e){let t;return()=>(t||(t=Tt(e)),t)}import{promises as R,existsSync as P,readFileSync as Vr}from"fs";import{basename as Br,join as h}from"path";import{readFileSync as Mr}from"fs";import{dirname as Tr,resolve as Nr}from"path";function Nt(e,t){let r=Nr(e),n=Mr(r,"utf8");return L(t?G(n,Z(Tr(r),t)):n)}var H=class e{constructor(t){this.opts=t}executionId;testId;definitionPath=null;definitionContent=null;accumulatedSteps=[];maxOrdinal=0;_attempts=[];_packDirOverride;_attached=!1;appiumMarks=$t();get attached(){return this._attached}static async attach(t){let r=Br(t.packDir).replace(/\.evidence$/,""),n=new e({origin:"testrun",runKind:"author",pid:process.pid,title:t.testId,started:new Date().toISOString(),producerVersion:rt,cwd:t.cwd});n.executionId=r,n.testId=t.testId,n._packDirOverride=t.packDir,n._attached=!0;let i=h(t.packDir,"tests",t.testId);return await R.mkdir(i,{recursive:!0}),t.definition&&(await R.writeFile(h(i,t.definition.path),t.definition.content),n.definitionPath=t.definition.path,n.definitionContent=t.definition.content),n}async start(){if(this._attached)throw new Error("attach-mode session is already started");this.executionId=fe(),this.testId=this.opts.testmdRelPath?Ee(this.opts.testmdRelPath):Se(this.opts.objectiveOrName??"session",this.opts.sessionId??this.executionId);let t=this.opts.definition??null;return await Pe({execution_id:this.executionId,title:this.opts.title,started:this.opts.started,producerVersion:this.opts.producerVersion,surfaces:this.opts.surfaces,run_kind:this.opts.runKind,origin:this.opts.origin,pid:this.opts.pid,...this.opts.credits!==void 0?{credits:this.opts.credits}:{}},this.testId,t,this.opts.cwd,this.opts.packRootDir?this.pack:void 0),t&&(this.definitionPath=t.path,this.definitionContent=t.content),{executionId:this.executionId,testId:this.testId,packTestDir:this.packTestDir}}get pack(){return this._packDirOverride?this._packDirOverride:this.opts.packRootDir?h(this.opts.packRootDir,`${this.executionId}.evidence`):w(this.executionId,this.opts.cwd)}get packTestDir(){return h(this.pack,"tests",this.testId)}async writeDefinition(t,r="test.md"){await R.writeFile(h(this.packTestDir,r),t),this.definitionPath=r,this.definitionContent=t}computeAssuranceId(){try{if(this.opts.testmdRelPath&&this.opts.cwd){let t=h(this.opts.cwd,this.opts.testmdRelPath);if(P(t))return F(Vr(t,"utf8"))?.id}}catch{}}computeDefinitionId(){try{if(this.opts.testmdRelPath&&this.opts.cwd){let t=h(this.opts.cwd,this.opts.testmdRelPath),r=h(this.opts.cwd,".context"),n=P(r)?x(r):void 0;if(P(t))return Nt(t,n)}if(this.definitionContent!=null)return L(this.definitionContent)}catch{}}noteSpawn(t){this.accumulatedSteps.push(...t.steps),this.maxOrdinal=Math.max(this.maxOrdinal,t.maxOrdinal)}nextOrdinalOffset(){return this.maxOrdinal}get steps(){return this.accumulatedSteps}get attempts(){return this._attempts}async archiveAttempt(t,r){let n=this._attempts.length+1,i=h(this.packTestDir,String(n)),o;try{await R.mkdir(i,{recursive:!0});for(let a of["steps","logs","v16-trajectory"]){let u=h(this.packTestDir,a);P(u)&&await R.rename(u,h(i,a))}this.definitionPath&&P(h(this.packTestDir,this.definitionPath))&&await R.copyFile(h(this.packTestDir,this.definitionPath),h(i,this.definitionPath));let s=h(i,"steps");if(P(s)){for(let a of await R.readdir(s))if(P(h(s,a,"failure.yaml"))){o=`${n}/steps/${a}/failure.yaml`;break}}}catch{}return this._attempts.push({n,status:t,steps:this.accumulatedSteps,...r!==void 0?{failedAt:r}:{},...o?{failure:o}:{}}),this.accumulatedSteps=[],this.maxOrdinal=0,n}async writeResult(t){let r=je(t.spawns),n=this._attempts.length?[...this._attempts.map(c=>({status:c.status})),{status:r,...t.durationMs!==void 0?{duration_ms:t.durationMs}:{}}]:void 0,i=n?new Set(n.map(c=>c.status)).size>1:void 0,o=this._attempts.length?{triggered:!0,outcome:r==="passed"?"healed":"exhausted",attempts:this._attempts.map(c=>({n:c.n,status:c.status,failed_at:c.failedAt??-1,...c.failure?{failure:c.failure}:{}}))}:void 0,s=this.pack,a=Ie(t.externalIdInput),u=pe(t.runnerEnv,t.intentEnv),d=this.computeDefinitionId(),p=this.computeAssuranceId();await Ce(s,this.testId,ne({testId:this.testId,status:r,durationMs:t.durationMs,definitionPath:this.definitionPath,definitionId:d,assuranceId:p,externalId:a,environment:u,steps:t.steps,tags:t.tags,attempts:n,flaky:i,adaptiveHeal:o}));for(let c of this._attempts){let f=h(this.packTestDir,String(c.n));P(f)&&await R.writeFile(h(f,"result.yaml"),ne({testId:this.testId,status:c.status,definitionPath:this.definitionPath,definitionId:d,assuranceId:p,externalId:a,environment:u,steps:c.steps,tags:t.tags}))}let l=t.externalIdInput;return t.log&&(l.commit_id||l.test_id||l.testcase_id)&&t.log("info","EVIDENCE_EXTERNAL_ID","Evidence external-id mapping",{execution_id:this.executionId,commit_id:l.commit_id??null,test_id:l.test_id??null,testcase_id:l.testcase_id??null,project_id:l.project_id??null,session_id:l.session_id??null,session_name:l.session_name??null}),r}get id(){return this.executionId}get test(){return this.testId}};async function zr(e,t,r=ge){try{let n=await r(e);if(n.aborted.length>0||n.removed.length>0)try{t?.("info","EVIDENCE_RECOVERY","Startup evidence recovery swept incomplete packs",{aborted:n.aborted,removed:n.removed,origin:"startup"})}catch{}return n}catch(n){return console.warn("evidence: startup recovery failed",n),{aborted:[],removed:[]}}}import{promises as ln}from"fs";import{existsSync as We,mkdirSync as nn,readdirSync as on,readFileSync as sn,rmSync as an,statSync as cn,writeFileSync as dn}from"fs";import{join as T}from"path";import{mkdirSync as Gr,renameSync as Ur,rmSync as qr,writeFileSync as Wr}from"fs";import{join as Vt}from"path";var Yr=5e6;function Bt(e,t,r){let n=Vt(e,"coverage","sources"),i=new Map,o=!1;try{for(let s of r.usecases)for(let a of s.sources){if(i.has(a.id)){a.file=i.get(a.id);continue}if(!a.cid)continue;let u=kt(t,a.cid);if(u===null||u.byteLength>Yr)continue;o||(Gr(n,{recursive:!0}),o=!0);let d=Vt(n,a.id),p=`${d}.tmp-${process.pid}`;Wr(p,u),Ur(p,d);let l=`coverage/sources/${a.id}`;i.set(a.id,l),a.file=l}}catch{for(let s of r.usecases)for(let a of s.sources)delete a.file;if(o)try{qr(n,{recursive:!0,force:!0})}catch{}}}import{appendFileSync as Jt,existsSync as j,readFileSync as $,renameSync as Xt,writeFileSync as Qt}from"fs";import{dirname as Ue,isAbsolute as ae,join as M,resolve as ce}from"path";var Hr=new Set(["inline","testmd","testrun"]),Kr=new Set(["inferred","authored","runtime-derived"]),se=new Set(["passed","failed","broken","skipped"]);function zt(e,t,r){if(r.facts.length===0)return{record:null,errors:[{code:"EMPTY_EXECUTIONS",detail:"a run with no designed units attaches no facts \u2014 skip the call"}]};let n=t;for(let i=0;;i++){let o=te(e);if(n.latestHash!==o){if(i>=3)return{record:null,errors:[{code:"STALE_BASIS",detail:`graph opened at ${String(n.latestHash)} but chain head is ${String(o)} \u2014 retry budget exhausted`}]};n=x(e);continue}let s=Jr(e,n,r);if(s!=="cas")return s;if(i>=3)return{record:null,errors:[{code:"STALE_BASIS",detail:"concurrent appends kept moving the head \u2014 retry budget exhausted"}]};n=x(e)}}function Gt(e,t){return Hr.has(e.mode)?se.has(e.verdict)?Kr.has(e.oracle_mode)?typeof e.drift_flag!="boolean"||typeof e.stale_at_run!="boolean"?[{code:"MISSING_FIELD",detail:`${t}: drift_flag and stale_at_run are required booleans`}]:!e.execution_id||!e.started_at||!e.definition_id_at_run?[{code:"MISSING_FIELD",detail:`${t}: execution_id, started_at and definition_id_at_run are required`}]:[]:[{code:"BAD_ORACLE_MODE",detail:`${t}: oracle_mode '${e.oracle_mode}' not in inferred|authored|runtime-derived`}]:[{code:"BAD_VERDICT",detail:`${t}: verdict '${e.verdict}' not in ${[...se].join("|")}`}]:[{code:"BAD_MODE",detail:`${t}: mode '${e.mode}' not in inline|testmd|testrun`}]}function Ut(e,t,r,n){return{about:t,definition_id_at_run:e.definition_id_at_run,verdict:e.verdict,...r&&r.length?{per_ac:r}:{},drift_flag:e.drift_flag,oracle_mode:e.oracle_mode,stale_at_run:e.stale_at_run,...n.length?{unresolved_acs:n}:{},execution_id:e.execution_id,...e.evidence_id?{evidence_id:e.evidence_id}:{},...e.duration_ms!==void 0?{duration_ms:e.duration_ms}:{},started_at:e.started_at,mode:e.mode,local:e.local,...e.via_parent?{via_parent:e.via_parent}:{}}}function qt(e,t){if(!Array.isArray(t.facts)||t.facts.length===0)return{record:null,errors:[{code:"EMPTY_EXECUTIONS",detail:"parked line carries no facts"}]};for(let r=0;;r++){let n=x(e),i=t.facts.filter(d=>n.appliedEvents.has(d.event_id)).map(d=>d.event_id),o=t.facts.filter(d=>!n.appliedEvents.has(d.event_id));if(o.length===0)return{record:null,errors:null,applied:[],skipped:i,rejected:[]};let s=[],a=[],u=[];for(let d of o){let p=`executions[${d.ref}]`,l=[];if(!d.about_cid||!n.hasNode(d.about_cid))l.push({code:"UNKNOWN_REF",detail:`${p}: about_cid '${String(d.about_cid)}' is not in the graph \u2014 the pinned run-time target is gone`});else if(n.nodeLabel.get(d.about_cid)!==U.TEST)l.push({code:"ILLEGAL_TARGET",detail:`${p}: execution facts attach to tests \u2014 '${d.about_cid}' is a ${n.nodeLabel.get(d.about_cid)}`});else if(!d.event_id)l.push({code:"MISSING_FIELD",detail:`${p}: parked facts require event_id`});else{l.push(...Gt(d,p));for(let m of d.per_ac??[])se.has(m.verdict)||l.push({code:"BAD_VERDICT",detail:`${p}.per_ac['${m.ac_ref}']: verdict '${m.verdict}'`})}if(l.length>0){s.push({event_id:d.event_id??"",errors:l});continue}let c=[],f=[...d.unresolved_acs??[]];for(let m of d.per_ac??[]){let g=n.resolve(m.ac_ref),_=g?n.tipOf(g.cid):null;if(!g||!_||n.superseded.has(_)||n.nodeLabel.get(_)!==U.AC){f.push(m.ac_ref);continue}c.push({ac_ref:n.nameOf.get(_)??_,verdict:m.verdict})}a.push(Ut(d,d.about_cid,c,f)),u.push(d.event_id)}if(a.length===0)return{record:null,errors:null,applied:[],skipped:i,rejected:s};try{let d=q(e,{ts:new Date().toISOString(),proposal_id:null,nodes:[],edges:[],review:[],supersessions:[],executions:a,event_ids:[...u].sort(),source_head_moves:{}},{expectPrev:n.latestHash,busyRetry:{deadlineMs:5e3}}),p;try{W(e)}catch(l){p=`parked facts committed, but the projection refresh failed (${l instanceof Error?l.message:String(l)}) \u2014 read state rebuilds on the next open`}return{record:d.record,errors:null,applied:u,skipped:i,rejected:s,...p?{warnings:[p]}:{}}}catch(d){if(!(d instanceof ve))throw d;if(r>=3)return{record:null,errors:[{code:"STALE_BASIS",detail:"concurrent appends kept moving the head \u2014 parked replay retry budget exhausted (line stays queued)"}]}}}}function Jr(e,t,r){let n=[],i=[];for(let a of r.facts){let u=`executions[${a.ref}]`,d=t.resolve(a.ref),p=d?t.tipOf(d.cid):null;if(!d||!p||t.superseded.has(p)){n.push({code:"UNKNOWN_REF",detail:`${u}: '${a.ref}' is not a live committed node`});continue}if(t.nodeLabel.get(p)!==U.TEST){n.push({code:"ILLEGAL_TARGET",detail:`${u}: execution facts attach to tests \u2014 '${a.ref}' is a ${t.nodeLabel.get(p)}`});continue}let l=Gt(a,u);if(l.length>0){n.push(...l);continue}let c=[];for(let f of a.per_ac??[]){let m=t.resolve(f.ac_ref),g=m?t.tipOf(m.cid):null;if(!m||!g||t.superseded.has(g)||t.nodeLabel.get(g)!==U.AC){n.push({code:"UNKNOWN_REF",detail:`${u}.per_ac: '${f.ac_ref}' is not a live AC`});continue}if(!se.has(f.verdict)){n.push({code:"BAD_VERDICT",detail:`${u}.per_ac['${f.ac_ref}']: verdict '${f.verdict}'`});continue}c.push({ac_ref:t.nameOf.get(g)??g,verdict:f.verdict})}i.push(Ut(a,p,c,a.unresolved_acs??[]))}if(n.length>0)return{record:null,errors:n};let o;try{o=q(e,{ts:new Date().toISOString(),proposal_id:null,nodes:[],edges:[],review:[],supersessions:[],executions:i,...r.eventIds&&r.eventIds.length>0?{event_ids:r.eventIds}:{},source_head_moves:{}},{expectPrev:t.latestHash,busyRetry:{deadlineMs:r.lockDeadlineMs??5e3}})}catch(a){if(a instanceof ve)return"cas";throw a}let s;try{W(e)}catch(a){s=`facts committed, but the projection refresh failed (${a instanceof Error?a.message:String(a)}) \u2014 read state rebuilds on the next open`}return{record:o.record,errors:null,...s?{warnings:[s]}:{}}}function Zt(e){let t={failed:3,broken:2,skipped:1,passed:0},r=new Map;for(let n of e)for(let i of n.verifies??[]){let o=r.get(i);(o===void 0||(t[n.status]??0)>(t[o]??0))&&r.set(i,n.status)}return[...r.entries()].map(([n,i])=>({ref:n,verdict:i}))}function er(e){let t=[],r=re(e.cwd);if(!j(r))return{synced:0,superseded:0,skipped:"no-context",warnings:t};let n=e.by??{kind:"ai",id:"exec-sync"},i=e.lockDeadlineMs;try{Xr(r,t,i)}catch(c){t.push(`sync: parked-facts replay failed (${c instanceof Error?c.message:String(c)}) \u2014 queue intact, retrying next sync`)}let o=x(r),s=[],a=0,u=new Set,d=new Set(e.members.map(c=>ae(c.path)?c.path:ce(e.cwd,c.path))),p=new Map;for(let c of e.members){let f=ae(c.path)?c.path:ce(e.cwd,c.path);if(!j(f)){t.push(`sync: member file missing: ${f} \u2014 skipped, no fact attached`);continue}for(let m of Qr(f,t))if(!u.has(m.path))try{let g=m.path===f,_=!g&&d.has(m.path),v=g?void 0:F($(f,"utf8"))?.id,K=$(m.path,"utf8"),k=F(K);if(!k?.id){u.add(m.path);continue}let ue=o.resolve(k.id),N=ue?o.tipOf(ue.cid):null;if(!ue||!N||o.superseded.has(N)){u.add(m.path),t.push(`sync: ${k.id} does not resolve to a live test \u2014 skipped (foreign store?)`);continue}let J=L(G(K,Z(Ue(m.path),o))),dr=String(o.getNode(N)?.content.test_md_blob??""),X=L(G(dr,mt(o))),V=!1,Q=N;if(J===X)k.base!==X&&Kt(m.path,K,X,t);else if(k.base===X){let y=en(r,o,N,K,J,Ue(m.path),n);y.error?(t.push(`sync: could not supersede ${k.id}: ${y.error}`),V=!0):(a++,Q=y.newCid,V=y.oracleTier,Kt(m.path,$(m.path,"utf8"),J,t),o=x(r))}else V=!0,t.push(k.base?`sync: ${k.id} was edited from an older version \u2014 graph kept; reconcile via a redesign or maintain`:`sync: ${k.id} carries no base pin (hand-copied file?) \u2014 fact attached with drift flag`);if(_){V&&p.set(m.path,!0);continue}u.add(m.path);let Qe=o.getNode(Q)?.content.check,Ze=g?c.acs??[]:[],et=Ze.filter(y=>Yt(o,y.ref)),tt=Ze.filter(y=>!Yt(o,y.ref)).map(y=>y.ref);s.push({ref:k.id,about_cid:Q,definition_id_at_run:J,verdict:c.verdict,...et.length?{per_ac:et.map(y=>({ac_ref:y.ref,verdict:y.verdict}))}:{},drift_flag:V||p.get(m.path)===!0||g&&c.driftFlag===!0,oracle_mode:Qe?.expected_mode??(ut(Qe?.operand)?"runtime-derived":"inferred"),stale_at_run:o.stale(Q)!=="fresh",...tt.length?{unresolved_acs:tt}:{},execution_id:c.executionId,...c.evidenceId?{evidence_id:c.evidenceId}:{},...c.durationMs!==void 0?{duration_ms:c.durationMs}:{},started_at:c.startedAt,mode:c.mode,local:c.local,...v?{via_parent:v}:{}})}catch(g){m.path!==f&&d.has(m.path)||u.add(m.path),t.push(`sync: ${m.path} failed to sync (${g instanceof Error?g.message:String(g)}) \u2014 skipped; other members unaffected`)}}if(s.length===0)return{synced:0,superseded:a,warnings:t};let l;try{l=zt(r,x(r),{facts:s,by:n,lockDeadlineMs:i})}catch(c){return t.push(`sync facts: commit threw: ${c instanceof Error?c.message:String(c)}`),Wt(r,s,n,t,i),{synced:0,superseded:a,warnings:t}}return l.errors?(Wt(r,s,n,t,i),t.push(...l.errors.map(c=>`sync facts: ${c.code}: ${c.detail}`)),{synced:0,superseded:a,warnings:t}):(l.warnings&&t.push(...l.warnings.map(c=>`sync facts: ${c}`)),{synced:s.length,superseded:a,warnings:t})}var qe="pending-facts.ndjson",Ge=".pending-facts.bad";function Wt(e,t,r,n,i){try{let o={by:r,ts:new Date().toISOString(),facts:t.map(a=>({...a,about_cid:a.about_cid??"",event_id:`exec-fact:${a.execution_id}:${a.ref}`}))},s=null;try{s=ee(e,{deadlineMs:i??5e3})}catch{n.push("sync facts: store lock busy \u2014 parking without it (a concurrent queue rewrite may race this line)")}try{Jt(M(e,qe),JSON.stringify(o)+`
|
|
5
5
|
`)}finally{s?.()}n.push(`sync facts: commit failed \u2014 ${t.length} fact(s) parked to ${M(e,qe)}; they replay on the next sync`)}catch(o){n.push(`sync facts: could not park the failed batch (${o instanceof Error?o.message:String(o)}) \u2014 this run's facts are LOST`)}}function Xr(e,t,r){let n=M(e,qe);if(!j(n))return;let i;{let d=ee(e,{deadlineMs:r??5e3});try{i=$(n,"utf8")}finally{d()}}let o=i.split(`
|
|
6
6
|
`).filter(d=>d.trim()!=="");if(o.length===0)return;let s=new Set,a=[],u=[];for(let d of o){let p=null;try{let c=JSON.parse(d);c&&Array.isArray(c.facts)&&(p=c)}catch{}if(!p){a.push(d),s.add(d);continue}let l=qt(e,p);if(l.errors){if(l.errors.some(c=>c.code==="STALE_BASIS")){t.push(`sync: parked facts replay deferred (${l.errors[0].detail}) \u2014 retrying next sync`);continue}a.push(d),s.add(d),t.push(`sync: parked facts line quarantined to ${M(e,Ge)} (${l.errors.map(c=>`${c.code}: ${c.detail}`).join("; ")})`);continue}for(let c of l.rejected){let f=p.facts.find(m=>m.event_id===c.event_id);u.push({parent:d,line:JSON.stringify({...f??{event_id:c.event_id},_reason:c.errors})})}l.rejected.length>0&&t.push(`sync: ${l.rejected.length} parked fact(s) quarantined to ${M(e,Ge)} (${l.rejected.map(c=>c.errors.map(f=>`${f.code}: ${f.detail}`).join("; ")).join(" | ")})`),s.add(d),l.warnings&&t.push(...l.warnings.map(c=>`sync: ${c}`)),l.applied.length>0&&t.push(`sync: replayed ${l.applied.length} parked fact(s) from a previous run`)}if(s.size!==0)try{let d=ee(e,{deadlineMs:r??5e3});try{let l=(j(n)?$(n,"utf8"):"").split(`
|
|
7
7
|
`).filter(g=>g.trim()!==""),c=[...a.filter(g=>l.includes(g)),...u.filter(g=>l.includes(g.parent)).map(g=>g.line)];c.length>0&&Jt(M(e,Ge),c.map(g=>g+`
|
|
@@ -14,8 +14,8 @@ import{d as xt,g as bt}from"./chunk-QQ5MHSSY.js";import{b as ye,c as Y,d as we,e
|
|
|
14
14
|
`),n=r.some(o=>/^##\s/.test(o)&&he.test(o)),i=!1;for(let o of r){if(/^##\s/.test(o)){let s=he.exec(o);i=n?s!==null:/\bassert\b/i.test(o),s&&t.push(`v:${s[1].trim()}`);continue}i&&o.trim()!==""&&t.push(o.trim())}return t.join(`
|
|
15
15
|
`)}var rn=0;function Kt(e,t,r,n){try{let i=t.split(`
|
|
16
16
|
`),o=-1;if(i[0]?.trim()==="---"){for(let u=1;u<i.length;u++)if(i[u].trim()==="---"){o=u;break}}if(o<0)return;let s=gt(i,o);if(!s)return;if(s.baseLine!==void 0){let u=i[s.baseLine].endsWith("\r")?"\r":"";i[s.baseLine]=`${s.childIndent}base: ${r}${s.baseComment?` ${s.baseComment}`:""}${u}`}else if(s.strayBase){n.push(`sync: ${e} has a base: line this scanner cannot confidently rewrite (unexpected indentation or key quoting) \u2014 pin refresh skipped (stale pin until the shape is fixed)`);return}else{let d=i[s.idLine??s.start].endsWith("\r")?"\r":"";i.splice((s.idLine??s.start)+1,0,`${s.childIndent??" "}base: ${r}${d}`)}let a=`${e}.tmp-sync.${process.pid}-${rn++}`;Qt(a,i.join(`
|
|
17
|
-
`)),Xt(a,e)}catch(i){n.push(`sync: pin refresh failed for ${e} (${i instanceof Error?i.message:String(i)}) \u2014 next run self-heals`)}}var un={passed:"passed",failed:"failed",broken:"blocked",skipped:"not-run"},tr=(e,t)=>{try{if(!We(t))return{status:"skipped",reason:"no context store at the project root"};let r=T(e,"tests");if(!We(r))return{status:"skipped",reason:"pack has no tests/"};let n=new Map;for(let a of on(r)){let u=T(r,a,"result.yaml");if(!We(u)||!cn(T(r,a)).isDirectory())continue;let d=A(sn(u,"utf8"));if(!d?.definition_id&&!d?.assurance_id)continue;let p=Zt(d.steps??[]),l={testShortId:String(d.test??a),execution:un[String(d.status)]??"not-run",...p.length?{acs:p}:{}};d.assurance_id&&n.set(`id:${d.assurance_id}`,l),d.definition_id&&n.set(`def:${d.definition_id}`,l)}let i=
|
|
18
|
-
`)),i=p=>(n(`error: ${p}`),2);if(t.env!=="prod"&&t.env!=="stage")return i(`invalid --env: ${String(t.env)}`);if(t.port!==void 0&&(!Number.isInteger(t.port)||t.port<1||t.port>65535))return i("invalid --port: expected an integer 1-65535");let o;try{o=Y(t.env,t.viewerUrl),new URL(o)}catch{return i(`invalid --viewer-url: ${t.viewerUrl}`)}if(e.length===0)return i("no pack paths given");let s=new Map;for(let p of e){let l=
|
|
19
|
-
`)),u;try{u=await ye({packs:s,allowedOrigins:[new URL(o).origin],port:t.port,log:a})}catch(p){return i(`could not bind 127.0.0.1${t.port?`:${t.port}`:""} \u2014 ${p.message}`)}n(`serving ${s.size} pack${s.size===1?"":"s"} on http://127.0.0.1:${u.port}`);for(let p of s.keys()){let l=u.urlFor(p);n(p),n(` pack ${l}`),n(` viewer ${we(l,o)}`)}return n("press Ctrl-C to stop"),await(r.hold??kn)(),await u.close(),0}function kn(){return new Promise(e=>{let t=process.listeners("SIGINT");process.removeAllListeners("SIGINT"),process.once("SIGINT",()=>{for(let r of t)process.on("SIGINT",r);e()})})}import{promises as de}from"fs";import{tmpdir as Rn}from"os";import{join as ir,resolve as He}from"path";var En=["error","prefer_first","prefer_latest","discard"],Sn=["external_id.commit_id","external_id.test_id"];function rr(e){let t=e.replace(/-/g,"_");return En.includes(t)?t:null}function nr(e){let t=e==="discard"?{on_collision:"discard"}:{on_collision:"error",identity:{keys:[...Sn],on_same:e??"nest",on_different:e?"error":"split"}};return
|
|
17
|
+
`)),Xt(a,e)}catch(i){n.push(`sync: pin refresh failed for ${e} (${i instanceof Error?i.message:String(i)}) \u2014 next run self-heals`)}}var un={passed:"passed",failed:"failed",broken:"blocked",skipped:"not-run"},tr=(e,t)=>{try{if(!We(t))return{status:"skipped",reason:"no context store at the project root"};let r=T(e,"tests");if(!We(r))return{status:"skipped",reason:"pack has no tests/"};let n=new Map;for(let a of on(r)){let u=T(r,a,"result.yaml");if(!We(u)||!cn(T(r,a)).isDirectory())continue;let d=A(sn(u,"utf8"));if(!d?.definition_id&&!d?.assurance_id)continue;let p=Zt(d.steps??[]),l={testShortId:String(d.test??a),execution:un[String(d.status)]??"not-run",...p.length?{acs:p}:{}};d.assurance_id&&n.set(`id:${d.assurance_id}`,l),d.definition_id&&n.set(`def:${d.definition_id}`,l)}let i=xt(x(t),n,{scope:"run"}),o=bt(i);Bt(e,t,i);let s=b({...i,rollup:o},{lineWidth:-1});return nn(T(e,"coverage"),{recursive:!0}),dn(T(e,"coverage","usecases.yaml"),s),{status:"written"}}catch(r){try{an(T(e,"coverage","sources"),{recursive:!0,force:!0})}catch{}return{status:"skipped",reason:r instanceof Error?r.message:String(r)}}};async function pn(e){try{let t=new H({origin:"inline",runKind:"author",pid:e.pid,title:e.title,started:new Date().toISOString(),producerVersion:e.producerVersion,surfaces:e.surfaces,objectiveOrName:e.objectiveOrName,sessionId:e.sessionId,cwd:e.cwd,packRootDir:e.packRootDir}),r=await t.start();return{session:t,...r,packDir:t.pack,spawns:[],startedAtMs:Date.now(),cwd:e.cwd}}catch(t){return console.warn("evidence: inline pack creation failed",t),null}}function fn(e,t,r){if(!e)return;e.session.noteSpawn(t),t.resolution&&(e.resolution=t.resolution),e.runnerEnvironment=ot(e.runnerEnvironment,t.runnerEnvironment);let n=(r?.per_flow_metadata??[]).map(i=>({resultCode:i?.result_code!=null?Number(i.result_code):null}));e.spawns.push({resultCode:r?.result_code!=null?Number(r.result_code):null,...n.length?{perFlow:n}:{}})}function mn(e){if(e)return{packTestDir:e.packTestDir,ordinalOffset:e.session.nextOrdinalOffset()}}async function gn(e,t){if(!e)return null;if(e.finalized)return e.finalized;let r=(n,i,o)=>t.log?t.log("warn",n,i,o):console.warn(`evidence: ${i}`,o??"");try{if(t.recordedTestPath)try{await e.session.writeDefinition(await ln.readFile(t.recordedTestPath,"utf8"))}catch(s){r("EVIDENCE_DEFINITION_FAILED","could not attach synthesized test.md",{error:String(s)})}let n=t.cdpBrowserCapture?await t.cdpBrowserCapture():void 0,i=await e.session.writeResult({steps:e.session.steps,spawns:e.spawns.length?e.spawns:[{resultCode:null}],externalIdInput:{...t.externalIdInput,execution_id:e.executionId},runnerEnv:ze({cdpBrowser:n,resolution:e.resolution,runnerEnvironment:e.runnerEnvironment,deviceName:t.deviceName,deviceModel:t.deviceModel,pixelResolution:await Ot(e.packTestDir)}),intentEnv:at(t.model,e.runnerEnvironment),durationMs:t.durationMs??Date.now()-e.startedAtMs,log:t.log});try{if(t.recordedTestPath){let s=er({cwd:t.cwd??e.cwd??process.cwd(),members:[{path:t.recordedTestPath,verdict:i,executionId:e.executionId,startedAt:new Date(e.startedAtMs).toISOString(),mode:"inline",local:t.local??!1}]});for(let a of s.warnings)r("EXEC_SYNC",a)}}catch(s){r("EXEC_SYNC","exec-sync failed",{error:String(s)})}try{let s=(t.coverageWriter??tr)(e.packDir,re(t.cwd??e.cwd??process.cwd()));s.status==="skipped"&&r("EVIDENCE_COVERAGE_SKIPPED",`coverage/usecases.yaml not written: ${s.reason}`)}catch(s){r("EVIDENCE_COVERAGE_SKIPPED","coverage writer threw",{error:String(s)})}let o=await Be({executionId:e.executionId,testId:e.testId,saved:t.saved,runKind:"author",verdict:i,cwd:t.cwd??e.cwd,packDir:e.packDir,tuiLogPath:t.tuiLogPath,log:t.log,surface:"inline",requireRealLog:!!e.runnerEnvironment?.native_platform,appiumMarks:e.session.appiumMarks});return e.finalized=o,t.log?.("info","EVIDENCE_SEALED","Inline pack sealed",{execution_id:e.executionId,verdict:i,valid:o.valid,pack:e.packDir,store_copy:o.storePath??null}),o}catch(n){return r("EVIDENCE_SEAL_FAILED","inline pack finalize failed",{error:String(n)}),null}}import{statSync as hn,openSync as vn,readSync as yn,closeSync as wn}from"fs";import{basename as _n,resolve as bn}from"path";async function xn(e,t,r={}){let n=r.out??(p=>process.stdout.write(p+`
|
|
18
|
+
`)),i=p=>(n(`error: ${p}`),2);if(t.env!=="prod"&&t.env!=="stage")return i(`invalid --env: ${String(t.env)}`);if(t.port!==void 0&&(!Number.isInteger(t.port)||t.port<1||t.port>65535))return i("invalid --port: expected an integer 1-65535");let o;try{o=Y(t.env,t.viewerUrl),new URL(o)}catch{return i(`invalid --viewer-url: ${t.viewerUrl}`)}if(e.length===0)return i("no pack paths given");let s=new Map;for(let p of e){let l=bn(p),c;try{c=hn(l)}catch{return i(`${p}: not found`)}if(c.isDirectory())return i(`${p}: is a directory \u2014 packs must be sealed .evidence files (run the execution to completion, or seal it, first)`);if(!c.isFile())return i(`${p}: not a regular file`);let f=Buffer.alloc(2),m=vn(l,"r");try{yn(m,f,0,2,0)}finally{wn(m)}if(f.toString("latin1")!=="PK")return i(`${p}: not a sealed evidence pack (zip magic missing)`);let g=_n(l);if(s.has(g))return i(`duplicate pack basename: ${g} (URL names collide \u2014 rename one)`);s.set(g,l)}let a=r.log??((p,l,c)=>process.stderr.write(`warn: ${l} reason=${c.reason} path=${c.path}
|
|
19
|
+
`)),u;try{u=await ye({packs:s,allowedOrigins:[new URL(o).origin],port:t.port,log:a})}catch(p){return i(`could not bind 127.0.0.1${t.port?`:${t.port}`:""} \u2014 ${p.message}`)}n(`serving ${s.size} pack${s.size===1?"":"s"} on http://127.0.0.1:${u.port}`);for(let p of s.keys()){let l=u.urlFor(p);n(p),n(` pack ${l}`),n(` viewer ${we(l,o)}`)}return n("press Ctrl-C to stop"),await(r.hold??kn)(),await u.close(),0}function kn(){return new Promise(e=>{let t=process.listeners("SIGINT");process.removeAllListeners("SIGINT"),process.once("SIGINT",()=>{for(let r of t)process.on("SIGINT",r);e()})})}import{promises as de}from"fs";import{tmpdir as Rn}from"os";import{join as ir,resolve as He}from"path";var En=["error","prefer_first","prefer_latest","discard"],Sn=["external_id.commit_id","external_id.test_id","environment.os","environment.os_version","environment.browser","environment.browser_version"];function rr(e){let t=e.replace(/-/g,"_");return En.includes(t)?t:null}function nr(e){let t=e==="discard"?{on_collision:"discard"}:{on_collision:"error",identity:{keys:[...Sn],on_same:e??"nest",on_different:e?"error":"split"}};return b({packs:{require_status:"finalized",require_valid:"L1",on_ineligible:"abort"},tests:t,rules:[{file:"run.yaml",key:"run_id",must:"different",on_violation:"skip"},{file:"result.yaml",key:"external_id.project_id",must:"same",on_violation:"error"},{file:"result.yaml",key:"external_id.org_id",must:"same",on_violation:"error"}]},{lineWidth:-1})}async function Ye(e){try{if(!e.isTTY){e.log(_e(e.packPath));return}let t=Y(e.env);await(e.renderPrompt??In)(e.packPath,t)}catch(t){try{e.log(`evidence view failed \u2014 ${t.message}`)}catch{}}}async function In(e,t){let r=await import("./react-QWOAB3TB.js"),{render:n}=await import("./build-JIKYOZUH.js"),{EvidenceViewOffer:i}=await import("./EvidenceViewOffer-M2TGMSNE.js");await new Promise(o=>{let s=n(r.default.createElement(i,{packPath:e,viewerBase:t,onDone:()=>{s.unmount(),o()}}),{stdout:process.stderr,exitOnCtrlC:!1})})}async function Pn(e,t,r=process.cwd(),n={}){let i=n.out??(c=>process.stdout.write(c+`
|
|
20
20
|
`)),o=n.err??(c=>process.stderr.write(c+`
|
|
21
|
-
`)),s=c=>(o(`evidence merge: ${c}`),2);if(!t.runId)return s("--run-id is required (merged identity is the caller's fact)");if(t.rules&&t.onCollision)return s("--rules and --on-collision are mutually exclusive");let a;if(t.onCollision!==void 0){let c=rr(t.onCollision);if(!c)return s(`invalid --on-collision: ${t.onCollision} (expected error | prefer-first | prefer-latest | discard)`);a=c}let u=[];for(let c of e){let f=await $n(c,r);if(!f)return s(`no pack found for "${c}"`);u.push(f)}let d=t.out?He(r,t.out):w(t.runId,r),p=null,l;t.rules?l=He(r,t.rules):(p=await de.mkdtemp(ir(Rn(),"kane-merge-rules-")),l=ir(p,"merge-rules.yaml"),await de.writeFile(l,nr(a)));try{let c=await(n.mergeFn??ct)(u,{runId:t.runId,out:d,rulesPath:l,title:t.title,finalize:t.finalize});return t.json?i(JSON.stringify(c)):An(i,c),c.output.finalized&&!t.json&&await(n.offer??Ye)({packPath:d,env:t.env,isTTY:n.isTTY??(!!process.stdin.isTTY&&!!process.stderr.isTTY),log:o}),0}catch(c){let f=c instanceof Error?c.message:String(c);return c?.code==="ABORT"?(o(`evidence merge: aborted \u2014 ${f}`),1):s(f)}finally{p&&await de.rm(p,{recursive:!0,force:!0}).catch(()=>{})}}async function $n(e,t){let r=He(t,e);if(await or(r))return r;let n=w(e,t);return await or(n)?n:null}async function or(e){try{return await de.stat(e),!0}catch{return!1}}function An(e,t){let{packs:r,tests:n,output:i}=t;e(`evidence: merged ${n.merged} tests from ${r.eligible.length} packs -> ${i.path} (${i.finalized?"sealed":"live"})`);for(let o of r.skipped)e(` skipped ${o.runId}: ${o.rule} \u2014 ${o.reason}`);for(let o of n.collisions){let s;o.action==="nest"?s=`nested into ${o.folder}, latest ${o.winner}`:o.action==="split"?s=`split into ${o.folder}`:s=`winner ${o.winner}`,e(` collision ${o.test}: ${s} (${o.rule})`)}for(let o of n.discarded)e(` discarded ${o}`)}import{copyFileSync as Ln,existsSync as Ke,mkdirSync as Fn}from"fs";import{join as sr}from"path";function Cn(e,t,r){try{let n=sr(e,"auteur","execution.json");if(Ke(n))return!0;for(let i of t)if(!(!i||!Ke(i)))return Fn(sr(e,"auteur"),{recursive:!0}),Ln(i,n),!0}catch(n){try{r?.("debug","EVIDENCE_BLOB_COPY_FAILED","auteur execution blob copy failed",{operation:"ensureAuteurExecution",source:t.find(i=>i&&Ke(i))??null,error:n instanceof Error?n.message:String(n)})}catch{}}return!1}import{readFileSync as Dn}from"fs";import{join as On}from"path";function Xe(e){let t=[],r=!0,n=o=>{if(o===null||typeof o!="object")return;let s=o;if(Array.isArray(s.operations))for(let a of s.operations){let u=a?.operation_id;typeof u=="string"&&u&&t.push(u)}if(Array.isArray(s.children)){s.content_type!=="generative_block"&&(r=!1);for(let a of s.children)n(a)}if(Array.isArray(s.branches)){r=!1;for(let a of s.branches){let u=a?.children;if(Array.isArray(u))for(let d of u)n(d)}}},i=e?.instructions;if(Array.isArray(i))for(let o of i)n(o);return{ids:t,linear:r}}function jn(e){return Xe(e).ids}function Je(e,t){let r=new Set(t.map(a=>a.action_id).filter(Boolean)),n=-1;for(let a of r){let u=e.indexOf(a);u>n&&(n=u)}let i=t.reduce((a,u)=>Math.max(a,u.ordinal),0),o=new Set,s=[];for(let a of e.slice(n+1))r.has(a)||o.has(a)||(o.add(a),s.push({id:a,ordinal:++i,status:"skipped",action_id:a}));return s}function ar(e,t){let r=new Set(t),n=e.filter(o=>o.action_id);if(n.some(o=>r.has(o.action_id))||n.length>t.length)return null;let i=0;return e.map(o=>o.action_id?{...o,action_id:t[i++]}:o)}function Mn(e,t){if(e.length>t.length)return!1;for(let r=0;r<e.length;r++)if(t[r]!==e[r].action_id)return!1;return!0}function Tn(e,t,r,n=!0){if(t.length===0)return{steps:e,tail:[]};let i=(r&&n?ar(e,t):null)??e,o=i.filter(a=>a.action_id),s=new Set(t);return o.length>0&&o.every(a=>s.has(a.action_id))?{steps:i,tail:Je(t,i)}:o.length>0&&!Mn(o,t)?{steps:i,tail:[],unjoined:!0}:{steps:i,tail:Je(t,i)}}function cr(e){try{let t=Dn(On(e,"auteur","execution.json"),"utf8");return Xe(JSON.parse(t))}catch{return{ids:[],linear:!0}}}function Nn(e){return cr(e).ids}export{D as a,
|
|
21
|
+
`)),s=c=>(o(`evidence merge: ${c}`),2);if(!t.runId)return s("--run-id is required (merged identity is the caller's fact)");if(t.rules&&t.onCollision)return s("--rules and --on-collision are mutually exclusive");let a;if(t.onCollision!==void 0){let c=rr(t.onCollision);if(!c)return s(`invalid --on-collision: ${t.onCollision} (expected error | prefer-first | prefer-latest | discard)`);a=c}let u=[];for(let c of e){let f=await $n(c,r);if(!f)return s(`no pack found for "${c}"`);u.push(f)}let d=t.out?He(r,t.out):w(t.runId,r),p=null,l;t.rules?l=He(r,t.rules):(p=await de.mkdtemp(ir(Rn(),"kane-merge-rules-")),l=ir(p,"merge-rules.yaml"),await de.writeFile(l,nr(a)));try{let c=await(n.mergeFn??ct)(u,{runId:t.runId,out:d,rulesPath:l,title:t.title,finalize:t.finalize});return t.json?i(JSON.stringify(c)):An(i,c),c.output.finalized&&!t.json&&await(n.offer??Ye)({packPath:d,env:t.env,isTTY:n.isTTY??(!!process.stdin.isTTY&&!!process.stderr.isTTY),log:o}),0}catch(c){let f=c instanceof Error?c.message:String(c);return c?.code==="ABORT"?(o(`evidence merge: aborted \u2014 ${f}`),1):s(f)}finally{p&&await de.rm(p,{recursive:!0,force:!0}).catch(()=>{})}}async function $n(e,t){let r=He(t,e);if(await or(r))return r;let n=w(e,t);return await or(n)?n:null}async function or(e){try{return await de.stat(e),!0}catch{return!1}}function An(e,t){let{packs:r,tests:n,output:i}=t;e(`evidence: merged ${n.merged} tests from ${r.eligible.length} packs -> ${i.path} (${i.finalized?"sealed":"live"})`);for(let o of r.skipped)e(` skipped ${o.runId}: ${o.rule} \u2014 ${o.reason}`);for(let o of n.collisions){let s;o.action==="nest"?s=`nested into ${o.folder}, latest ${o.winner}`:o.action==="split"?s=`split into ${o.folder}`:s=`winner ${o.winner}`,e(` collision ${o.test}: ${s} (${o.rule})`)}for(let o of n.discarded)e(` discarded ${o}`)}import{copyFileSync as Ln,existsSync as Ke,mkdirSync as Fn}from"fs";import{join as sr}from"path";function Cn(e,t,r){try{let n=sr(e,"auteur","execution.json");if(Ke(n))return!0;for(let i of t)if(!(!i||!Ke(i)))return Fn(sr(e,"auteur"),{recursive:!0}),Ln(i,n),!0}catch(n){try{r?.("debug","EVIDENCE_BLOB_COPY_FAILED","auteur execution blob copy failed",{operation:"ensureAuteurExecution",source:t.find(i=>i&&Ke(i))??null,error:n instanceof Error?n.message:String(n)})}catch{}}return!1}import{readFileSync as Dn}from"fs";import{join as On}from"path";function Xe(e){let t=[],r=!0,n=o=>{if(o===null||typeof o!="object")return;let s=o;if(Array.isArray(s.operations))for(let a of s.operations){let u=a?.operation_id;typeof u=="string"&&u&&t.push(u)}if(Array.isArray(s.children)){s.content_type!=="generative_block"&&(r=!1);for(let a of s.children)n(a)}if(Array.isArray(s.branches)){r=!1;for(let a of s.branches){let u=a?.children;if(Array.isArray(u))for(let d of u)n(d)}}},i=e?.instructions;if(Array.isArray(i))for(let o of i)n(o);return{ids:t,linear:r}}function jn(e){return Xe(e).ids}function Je(e,t){let r=new Set(t.map(a=>a.action_id).filter(Boolean)),n=-1;for(let a of r){let u=e.indexOf(a);u>n&&(n=u)}let i=t.reduce((a,u)=>Math.max(a,u.ordinal),0),o=new Set,s=[];for(let a of e.slice(n+1))r.has(a)||o.has(a)||(o.add(a),s.push({id:a,ordinal:++i,status:"skipped",action_id:a}));return s}function ar(e,t){let r=new Set(t),n=e.filter(o=>o.action_id);if(n.some(o=>r.has(o.action_id))||n.length>t.length)return null;let i=0;return e.map(o=>o.action_id?{...o,action_id:t[i++]}:o)}function Mn(e,t){if(e.length>t.length)return!1;for(let r=0;r<e.length;r++)if(t[r]!==e[r].action_id)return!1;return!0}function Tn(e,t,r,n=!0){if(t.length===0)return{steps:e,tail:[]};let i=(r&&n?ar(e,t):null)??e,o=i.filter(a=>a.action_id),s=new Set(t);return o.length>0&&o.every(a=>s.has(a.action_id))?{steps:i,tail:Je(t,i)}:o.length>0&&!Mn(o,t)?{steps:i,tail:[],unjoined:!0}:{steps:i,tail:Je(t,i)}}function cr(e){try{let t=Dn(On(e,"auteur","execution.json"),"utf8");return Xe(JSON.parse(t))}catch{return{ids:[],linear:!0}}}function Nn(e){return cr(e).ids}export{D as a,be as b,xe as c,ke as d,Ee as e,Se as f,Ie as g,pr as h,Re as i,Pe as j,fr as k,mr as l,$e as m,ne as n,Fe as o,Ce as p,De as q,Oe as r,gr as s,hr as t,je as u,vr as v,Me as w,Te as x,Ne as y,Lt as z,Be as A,Ot as B,ze as C,Tt as D,jr as E,H as F,zr as G,Zt as H,er as I,tr as J,pn as K,fn as L,mn as M,gn as N,xn as O,nr as P,Ye as Q,Pn as R,Cn as S,Xe as T,jn as U,Je as V,ar as W,Tn as X,cr as Y,Nn as Z};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { createRequire } from 'module'; const require = createRequire(import.meta.url);
|
|
2
|
-
import{b as B,c as S,d as T}from"./chunk-
|
|
2
|
+
import{b as B,c as S,d as T}from"./chunk-HNNVVK2O.js";import{c as g}from"./chunk-RFHMDQXZ.js";import{a as E}from"./chunk-LUTRUSIV.js";import{x as n}from"./chunk-WEJA3EVI.js";import{a as h}from"./chunk-HCBYKLMW.js";import{a as i,b as c,c as w,i as x}from"./chunk-C44QQJR4.js";import{a as L}from"./chunk-6YGTRKDT.js";import{e as u}from"./chunk-UR6MHSHU.js";var l=u(L(),1);var r=u(h(),1);function y(e){return new Map(e.map((o,s)=>[`${s}-${o.label}`,o.packPath]))}async function H(e){let o=e.deps?.viewerBase??S(e.env),s=e.deps?.startServer??B,a=e.deps?.openUrl??(m=>g(m).then(()=>{})),t=y(e.rows),d;try{d=await s({packs:t,allowedOrigins:[new URL(o).origin]});let m=d,D=async p=>{let v=[...t.keys()][p];await a(T(m.urlFor(v),o))};if(e.deps?.hold){await e.deps.hold();return}await new Promise(p=>{let v=w(l.default.createElement(P,{rows:e.rows,onOpen:D,onDone:()=>{v.unmount(),p()}}),{stdout:process.stderr,exitOnCtrlC:!1})})}finally{await d?.close()}}function I(e){return e==="passed"?n.green:e==="failed"||e==="broken"||e==="cancelled"?n.red:n.dim}var b=40,R=9,k=20;function f(e,o){return e.length>o?e.slice(0,o-1)+"\u2026":e.padEnd(o)}function O({row:e,selected:o}){let s=e.testId??e.commitId??"";return(0,r.jsxs)(i,{children:[(0,r.jsx)(i,{width:2,flexShrink:0,children:(0,r.jsx)(c,{color:n.orange,children:o?"\u25B8":" "})}),(0,r.jsx)(i,{width:2,flexShrink:0,children:(0,r.jsx)(c,{color:e.kind==="execution"?n.orange:n.muted,children:e.kind==="execution"?"\u25CF":"\u25CB"})}),(0,r.jsx)(i,{width:b,flexShrink:0,children:(0,r.jsx)(c,{color:o?n.orange:void 0,bold:o,wrap:"truncate-end",children:f(e.label,b)})}),(0,r.jsx)(i,{width:R,flexShrink:0,children:(0,r.jsx)(c,{color:I(e.status),bold:o,wrap:"truncate-end",children:f(e.status,R)})}),(0,r.jsx)(i,{width:k,flexShrink:0,children:(0,r.jsx)(c,{color:n.dim,wrap:"truncate-end",children:f(s,k)})})]})}function P(e){let[o,s]=(0,l.useState)(0);return x((a,t)=>{t.upArrow?s(d=>Math.max(0,d-1)):t.downArrow?s(d=>Math.min(e.rows.length-1,d+1)):t.return||a==="o"?e.onOpen(o):(a==="q"||t.escape)&&e.onDone()}),(0,r.jsx)(E,{title:"Evidence",borderColor:n.muted,children:(0,r.jsxs)(i,{flexDirection:"column",children:[e.rows.map((a,t)=>(0,r.jsx)(O,{row:a,selected:t===o},t)),(0,r.jsx)(i,{marginTop:1,children:(0,r.jsx)(c,{color:n.dim,children:"\u2191/\u2193 move \xB7 enter/o open \xB7 q quit"})})]})})}export{y as a,H as b};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createRequire } from 'module'; const require = createRequire(import.meta.url);
|
|
2
|
-
import{b as Bt}from"./chunk-ZMNJBUAO.js";import{f as tr}from"./chunk-W5TTF7GB.js";import{a as Ft}from"./chunk-I7TIGB7K.js";import{a as te,c as Yt,e as Zt,f as qe,g as Qt,h as nr}from"./chunk-
|
|
2
|
+
import{b as Bt}from"./chunk-ZMNJBUAO.js";import{f as tr}from"./chunk-W5TTF7GB.js";import{a as Ft}from"./chunk-I7TIGB7K.js";import{a as te,c as Yt,e as Zt,f as qe,g as Qt,h as nr}from"./chunk-WXJQDLXX.js";import{a as Xt,b as rr,c as sr,d as ir,e as dt,f as or}from"./chunk-5G22NOZK.js";import{a as ke,b as qt,c as Gt,d as Lt,e as Vt}from"./chunk-C33E5XQM.js";import{a as zt}from"./chunk-L2TV4G56.js";import{a as Kt,b as Jt}from"./chunk-BZAGVBCX.js";import{c as Wt}from"./chunk-IVQX3AKL.js";import{e as Ut}from"./chunk-YHL5NA43.js";import{a as Fe}from"./chunk-NJQNHD5P.js";import{b as Nt}from"./chunk-YKTYVJBN.js";import{a as Ht,e as jt}from"./chunk-EV64VI66.js";import{a as er}from"./chunk-GX3FPJUG.js";import{g as Mt}from"./chunk-54JZ6VEW.js";import{a as $e,b as ct}from"./chunk-DNNZ353O.js";import{a as Se}from"./chunk-NVGBE2DR.js";import{b as nt}from"./chunk-IDX3TOPY.js";import{C as ee,m as be,q as Be}from"./chunk-W3Z7AZNT.js";import{g as It}from"./chunk-XMTSHHYQ.js";import{e as at}from"./chunk-DBIBROYW.js";import{d as me}from"./chunk-AKX4VRRR.js";import{b as Ot}from"./chunk-IAHKTEET.js";import{a as At}from"./chunk-5EOX4MEY.js";import{appendFileSync as wr,mkdirSync as ut,rmdirSync as br,writeFileSync as lt}from"fs";import{dirname as mr,extname as Sr,join as ce}from"path";var X=class extends Error{code;constructor(e,a){super(`${e}: ${a}`),this.name="ProposalAdapterError",this.code=e}};function cr(r){return r.version===2}var ar=8;function vr(r){let e=/^extract@(\d+)$/.exec(r??"");return e?Number.parseInt(e[1],10):null}var yr=r=>typeof r=="object"&&r!==null&&"op"in r;function Ge(r,e,a){return{anchor:r.anchor,quote:r.quote,...a||r.source_id!==e?{source_id:r.source_id}:{}}}function dr(r,e,a={}){let m=vr(a.templateVersion),x=m!==null&&m>=5,_=m!==null&&m<5,y=r.archived!=null&&r.archived.length>0&&m!==null&&m<5;if(y&&a.warn?.(`dropped ${r.archived.length} archive op(s): the bound extract template @${m} never described archiving \u2014 nothing was archived; the use-cases still land`),!x&&r.read_basis.length!==1)throw new X("READ_BASIS_COUNT",`read_basis must have exactly 1 element, got ${r.read_basis.length}`);if(r.read_basis.length===0)throw new X("READ_BASIS_COUNT","read_basis must not be empty");let v=r.read_basis[0],h=r.read_basis.length>1,$=r.use_cases.map(i=>{if(_&&i.cite.length!==1)throw new X("CITE_COUNT",`${i.temp_ref}: cite must have exactly 1 element, got ${i.cite.length}`);if(i.cite.length<1||i.cite.length>ar)throw new X("CITE_COUNT",`${i.temp_ref}: 1..${ar} cites allowed, got ${i.cite.length}`);let M=(f,re)=>{if(!x&&f!==v.source_id)throw new X("SOURCE_MISMATCH",`${re}: cite source ${f} != read_basis source ${v.source_id} (single-source)`)};M(i.cite[0].source_id,i.temp_ref);let P=i.cite.map(f=>(M(f.source_id,i.temp_ref),Ge(f,v.source_id,x&&(h||f.source_id!==v.source_id)))),l=(i.updated?.criteria??[]).some(yr);if(!x&&l)throw new X("CRITERIA_OPS_UNSUPPORTED",`${i.temp_ref}: op-union updated.criteria (keep/set/remove) needs an extract@5+ binding \u2014 this session is bound to ${a.templateVersion??"an unversioned template"}`);return{temp_ref:i.temp_ref,title:i.title,...i.description!==void 0?{description:i.description}:{},...i.summary!==void 0?{summary:i.summary}:{},...i.actors!==void 0?{actors:i.actors}:{},...i.value!==void 0?{value:i.value}:{},risk:i.risk,cite:P[0],...P.length>1?{cites:P}:{},...i.criteria!=null&&i.criteria.length>0?{criteria:i.criteria.map((f,re)=>(M(f.cite.source_id,`${i.temp_ref}.criteria[${re}]`),{text:f.text,cite:Ge(f.cite,v.source_id,x&&f.cite.source_id!==v.source_id)}))}:{},depends_on_hint:i.depends_on_hint,matches_existing:i.matches_existing,...i.conflicts_with!=null?{conflicts_with:i.conflicts_with}:{},...i.changed?{changed:!0}:{},...i.updated!=null?{updated:{...i.updated.title!=null?{title:i.updated.title}:{},...i.updated.description!=null?{description:i.updated.description}:{},...i.updated.summary!=null?{summary:i.updated.summary}:{},...i.updated.actors!=null?{actors:i.updated.actors}:{},...i.updated.value!=null?{value:i.updated.value}:{},...i.updated.risk!=null?{risk:i.updated.risk}:{},...i.updated.criteria!=null?{criteria:l?i.updated.criteria.map(f=>f.op==="set"?{op:"set",text:f.text,cite:Ge(f.cite,v.source_id,x&&f.cite.source_id!==v.source_id)}:f.op==="keep"?{op:"keep",ref:f.ref,text:f.text}:{op:"remove",ref:f.ref,text:f.text,reason:f.reason}):i.updated.criteria.map((f,re)=>(M(f.cite.source_id,`${i.temp_ref}.updated.criteria[${re}]`),{text:f.text,cite:Ge(f.cite,v.source_id,x&&f.cite.source_id!==v.source_id)}))}:{}}}:{},...i.change_note!=null?{change_note:i.change_note}:{}}});return{version:1,read_basis:e,source:{source_id:v.source_id,source_cid:v.source_cid},use_cases:$,...h?{sources:r.read_basis.map(i=>({source_id:i.source_id,source_cid:i.source_cid}))}:{},...r.extraction_of!=null&&r.extraction_of.length>0?{extraction_claims:r.extraction_of.map(i=>({source_id:i.source_id,completeness:i.completeness}))}:{},...r.archived!=null&&r.archived.length>0&&!y?{archived:r.archived.map(i=>({target:i.target,reason:i.reason,basis:i.basis}))}:{}}}function ur(r){let{contextDir:e,graph:a}=r,m=r.maxDigestBytes??4096,x={},_=[];for(let[h,$]of a.heads){if(x[h]=$,typeof $!="string")continue;let i=a.mediaOf($),M=a.getNode($)?.content?.blob;if(typeof M=="string")if(i.format==="image")_.push({source_id:h,cid:$,format:"image",blobRef:{path:Se(e,M),cid:M}});else{let P=$e(e,a,$)?.toString("utf8")??"";_.push({source_id:h,cid:$,format:i.format,text:P})}}_.sort((h,$)=>h.source_id<$.source_id?-1:1);let y=[];for(let h of a.byLabel(me.STYLENOTE).sort(($,i)=>$.cid<i.cid?-1:1))a.superseded.has(h.cid)||y.push(`\u2022 ${String(h.content.statement)} [${String(h.content.learned_from_kind)}]`);let v="";for(let h of y){if(Buffer.byteLength(v+h+`
|
|
3
3
|
`,"utf8")>m)break;v+=h+`
|
|
4
4
|
`}return{read_basis:x,sources:_,styleNoteDigest:v}}function lr(r,e){let a=ur({contextDir:r,graph:e}).styleNoteDigest;return a.length>0?a:void 0}function mt(r,e,a,m,x){let _=null,y=()=>_??=x&&Object.keys(x).length>0?Promise.resolve(x):Ut().catch(()=>({}));return{contextDir:r,rootSid:e,locks:at(r,e),probe:m??Ft(r,{resolveAlias:async v=>qt(v,{env:process.env,auth:await y()}),embed:async(v,h)=>Gt(v,h,{env:process.env,auth:await y()}),readVector:(v,h)=>Lt(r,v,h),writeVector:(v,h,$)=>Vt(r,v,h,$)}),...a?.length?{reservedEventIds:a}:{}}}function ht(r,e){let a=[],m=[];for(let x of r.use_cases){let _=x.matches_existing;_?.cid&&e.hasNode(_.cid)?a.push({ref:_.cid,expectedTip:e.tipOf(_.cid)}):m.push({tempRef:x.temp_ref,title:String(x.title??""),probeText:String(x.title??"")})}return{verb:"extract",ucTargets:a,newBuCandidates:m,sourcePins:[{source_id:r.source.source_id,source_cid:r.source.source_cid}],readBasis:r.read_basis??null}}function $r(r,e){let a=(r.images??[]).filter(m=>m.delivery==="selected");if(a.length!==0)return a.map(m=>({ref:m.ref,...m.page!==void 0?{page:m.page}:{},...m.loc!==void 0?{loc:m.loc}:{},media_type:m.media_type,blob_ref:{path:Se(e,m.blob),cid:m.blob}}))}function kr(r){return r.length>8&&r[0]===137&&r[1]===80&&r[2]===78&&r[3]===71?"image/png":r.length>3&&r[0]===255&&r[1]===216&&r[2]===255?"image/jpeg":r.length>12&&r.toString("ascii",0,4)==="RIFF"&&r.toString("ascii",8,12)==="WEBP"?"image/webp":null}function Le(r){return r.toISOString().replace(/[-:]/g,"").slice(0,15)}function hr(r){return r.startsWith("su-conv-")?`conv-${Ot(Buffer.from(r,"utf8")).slice(0,8)}`:r}function pr(r){return r.source_id.startsWith("su-conv-")?"the conversation":r.source_id}function Rr(r,e,a){return`reading ${pr(r)}${a>1?` (source ${e} of ${a})`:""}`}function Re(r){return r.toLowerCase().trim().replace(/\s+/g," ")}function gr(r,e){let a=new Map,m=new Map,x=new Map;for(let{cid:y,content:v}of e.byLabel(me.USECASE)){if(e.superseded.has(y))continue;(e.trust.get(y)==="archived"?x:m).set(Re(String(v.title??"")),y)}let _=y=>e.trust.get(y)==="archived"?{cid:y,archived:!0,reason:e.archivedReason.get(y)}:{cid:y};for(let y of r.use_cases){if(y.matches_existing){let $=y.matches_existing.cid;if(e.superseded.has($)){let i=e.tipOf($);$=e.superseded.has(i)?null:i}if($!==null){a.set(y.temp_ref,_($));continue}}let v=m.get(Re(y.title));if(v){a.set(y.temp_ref,{cid:v});continue}let h=x.get(Re(y.title));h&&a.set(y.temp_ref,_(h))}return a}var fr=/^(\S+)\.criteria\[(\d+)\]/;function Cr(r,e,a){if(e.length===0||!e.every(x=>fr.test(x.detail)))return!1;let m=new Map;for(let x of e){let _=fr.exec(x.detail),y=m.get(_[1])??new Set;y.add(Number(_[2])),m.set(_[1],y)}for(let x of r.use_cases){let _=m.get(x.temp_ref);_?.size&&(x.criteria=(x.criteria??[]).filter((y,v)=>!_.has(v)),a(`${x.temp_ref}: dropped ${_.size} criteria with unverifiable cites \u2014 committed without them (criteria are hints, not oracles)`))}return!0}async function gt(r,e,a,m,x=()=>{},_,y){let v=(h,$)=>x(h,$,r.session_id);return Zt(r,e,a,m,x,{async onProposalEvent(h){let $=h,i=null,M=null;if(cr($))try{i=dr($,r.read_basis,{templateVersion:y?.()??null,warn:P=>{e.out(`warning: ${P}`),v("adapter",{warn:P})}}),v("adapter",{ok:!0,use_cases:i.use_cases.length})}catch(P){M=P instanceof X?P.message:String(P),v("adapter",{ok:!1,error:M})}else i=$;return i&&i.use_cases.length===0&&(e.out("warning: the agent proposed ZERO use-cases for this source"),e.emit?.({type:"warning",code:"ZERO_USE_CASES",message:"the agent proposed ZERO use-cases for this source"})),i&&_&&await _(i),{proposal:i,error:M}}})}var Dr=new Set(["agent","ci","override"]);async function Ss(r,e){let a=`ext-${Le(e.now?.()??new Date)}-lk${Math.random().toString(36).slice(2,8)}`,x=at(e.contextDir,a,e.now?{now:e.now}:void 0).tryAcquire([{kind:"extract"}],{hold:"session",verb:"extract"});if("contended"in x){let _=x.contended.holder,y=`another extraction is running on this context${_?` (pid ${_.pid})`:""} \u2014 retry when it finishes`;return e.out(y),e.emit?.({type:"error",message:y,code:"EXTRACT_LOCKED"}),2}try{return await Er(r,e)}finally{x.release()}}async function Er(r,e){let a=r.mode??"interactive";if(r.posture==="reconcile"){if(r.trust==="hold"){let o="error: --trust hold has no meaning here \u2014 a reconcile IS the review; drop the flag";return e.out(`${o} [TRUST_USAGE]`),e.emit?.({type:"error",message:o,code:"TRUST_USAGE"}),2}if(!r.source||!r.changeContext){let o="reconcile posture needs a pinned source and its change context \u2014 internal wiring fault";return e.out(`error: ${o}`),e.emit?.({type:"error",message:o,code:"POSTURE_USAGE"}),2}if(a==="ci"){let o="reconcile posture is not available under --mode ci \u2014 a held changeset needs a durable session; use --mode agent";return e.out(`error: ${o}`),e.emit?.({type:"error",message:o,code:"POSTURE_USAGE"}),2}}if(r.trust==="hold"&&a==="interactive")return e.out("error: --trust hold only applies to headless runs \u2014 in interactive chat you review items in-session anyway; use --mode agent to hold everything for review"),e.emit?.({type:"error",message:"error: --trust hold only applies to headless runs \u2014 use --mode agent",code:"TRUST_USAGE"}),2;if(a==="interactive"){if(!e.isTTY)return e.out("extract: --mode interactive needs a TTY (use --mode agent|ci|override headless)"),2}else if(!Dr.has(a))return e.out(`extract: unknown mode "${a}" \u2014 interactive | agent | ci | override`),2;if(r.trust!==void 0){if(a==="ci")return e.out("error: --trust is not available under --mode ci (ci is fail-closed \u2014 no trust dials)"),e.emit?.({type:"error",message:"error: --trust is not available under --mode ci",code:"TRUST_UNDER_CI"}),2;if(r.trust!=="auto"&&r.trust!=="hold")return e.out(`error: --trust must be auto | hold, got '${r.trust}'`),e.emit?.({type:"error",message:`error: --trust must be auto | hold, got '${r.trust}'`,code:"TRUST_USAGE"}),2}let m=e.telemetry?.enabled?e.telemetry:void 0,x=Le(e.now?.()??new Date),_=m?At(m.ids.context_instance_id??null,"extract",m.ids.session_id):ce(e.contextDir,"logs",`extract-${x}.log`);ut(mr(_),{recursive:!0});let y=`run-${x}-${Math.random().toString(36).slice(2,8)}`,v=o=>o==="error"||o==="failed_proposal"?"error":o==="repair_respawn"?"warn":"info",h=(o,u,s)=>{try{wr(_,JSON.stringify({ts:new Date().toISOString(),level:v(o),run_id:y,...m?{user_session_id:m.ids.session_id}:{},...s?{session_id:s}:{},kind:o,data:u})+`
|
|
5
5
|
`)}catch{}m?.wireTrace(o,u,s)};{let o=e.out;e.out=u=>{h("transcript",{line:u}),o(u)}}e.chat||e.out(`trace: ${te(_)}`),e.emit?.({type:"run_start",mode:a,trace:_,...m?{session:m.ids.session_id}:{}});let $=Nt();if($&&e.out($),e.preflightTurn){let o=await e.preflightTurn();if(h("preflight",o),!o.ok)return e.out(o.message??"error: turn-endpoint preflight failed"),e.emit?.({type:"error",message:o.message??"error: turn-endpoint preflight failed",code:"PREFLIGHT"}),2}let i=ee(e.contextDir),M=lr(e.contextDir,i),P=r.sources?.length?r.sources:r.source?[r.source]:[];if(P.length>0){if(r.resume){let o="error: --source cannot be combined with --resume (the resumed session already has its scope)";return e.out(o),e.emit?.({type:"error",message:o,code:"SOURCE_WITH_RESUME"}),2}for(let o of P){let u=i.heads.get(o);if(typeof u!="string"){let s=u===null?`error: --source ${o} was ingested but is retired \u2014 re-ingest it to extract again`:`error: --source ${o} is not an ingested source (kane-cli context list shows them)`;return e.out(s),e.emit?.({type:"error",message:s,code:"SOURCE_UNKNOWN"}),2}}}let l=null,f=null;if(r.resume){try{{let c=await or(e.contextDir,r.resume,i,{verb:"extract",deps:{onWarn:C=>e.out(`note: ${C}`)}});{let C=Object.keys(c.handle.state.read_basis??{});if(C.length>1){let B=`error: session ${r.resume} spans ${C.length} sources \u2014 multi-source resume isn't supported yet; committed work is preserved (re-run kane-cli context extract for anything remaining)`;return e.out(B),e.emit?.({type:"error",message:B,code:"MULTI_SOURCE_RESUME"}),c.handle.release(),2}f=c,h("resume_kind",{kind:c.view.pointer===null?"bare-base":c.view.pointer.at==="final"?"pause":"crash"}),l={handle:c.handle,represent:c.represent,questions:c.questions,staleBasis:c.drift.map(B=>B.subject)}}}}catch(c){let C=c instanceof Error?c.message:String(c);return e.out(`error: ${C}`),e.emit?.({type:"error",message:`error: ${C}`,...c instanceof dt?{code:c.code}:{}}),c instanceof dt?2:1}let o=f?null:Xt(l.handle.state.verb,"extract",r.resume);if(o)return e.out(o.message),e.emit?.({type:"error",message:o.message,code:o.code}),l.handle.release(),2;let u=l.handle.state.change_basis;if(u&&(i.heads.get(u.source_id)??null)!==u.new_head){let c=`error: ${u.source_id} moved while this reconcile extraction was paused \u2014 its recorded change context no longer matches; re-run kane-cli maintain reconcile against the current file (session ${r.resume} is defunct and can be ignored)`;return e.out(c),e.emit?.({type:"error",message:c,code:"CHANGE_BASIS_MOVED"}),l.handle.release(),2}if(f&&f.view.pointer!==null&&f.drift.length>0){if(!await e.confirmStale(`changed since the pause: ${f.drift.map(C=>C.subject).join(", ")} \u2014 re-ground and continue against the current versions?`)){let C=`resume aborted: the context moved since the pause (${f.drift.map(B=>B.subject).join(", ")}) \u2014 session ${r.resume} is preserved`;return e.out(C),e.emit?.({type:"error",message:C,code:"RESUME_DRIFT"}),l.handle.release(),2}}else l.staleBasis.length>0&&e.out(`note: changed since the pause: ${l.staleBasis.join(", ")} \u2014 re-presented items may be stale`);let s=[...new Set([...l.handle.state.held_receipts??[],...f?.view.kane?.held_receipts??[]])];if(s.length>0)if(e.chat?.holdReceipt)for(let c of s)e.chat.holdReceipt(c);else e={...e,initialMessage:[s.join(`
|
|
@@ -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-CSCJLGIY.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};
|