@testmuai/kane-cli 0.3.7 → 0.4.1
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/{ChromeProfilePicker-CBF6SP67.js → ChromeProfilePicker-63JS7QX6.js} +1 -1
- package/dist/{CliFeedbackPrompt-P2FJBV3S.js → CliFeedbackPrompt-3SDJ5GZP.js} +1 -1
- package/dist/{CliUploadProgress-B4CVWX62.js → CliUploadProgress-ZSZ7TGCN.js} +1 -1
- package/dist/ConfigView-OOQYCHWM.js +2 -0
- package/dist/FolderPicker-FILMS64I.js +2 -0
- package/dist/HelpView-KBFE4EMP.js +2 -0
- package/dist/{InfoBox-SYT7CVM4.js → InfoBox-QECFIGGW.js} +1 -1
- package/dist/{LinksBox-R3VLKMYS.js → LinksBox-2L2UX4LB.js} +1 -1
- package/dist/{ProfilesView-XKUXSFMQ.js → ProfilesView-72UTQ5PX.js} +1 -1
- package/dist/ProjectPicker-NLEAW232.js +2 -0
- package/dist/{SaveSessionPrompt-WAVXAYCK.js → SaveSessionPrompt-VNJDLJTF.js} +1 -1
- package/dist/SingleShotApp-V2UTGNZO.js +2 -0
- package/dist/SummaryBox-O772FRGO.js +2 -0
- package/dist/TestMdRunView-OVHCLNI7.js +2 -0
- package/dist/WhoamiView-LR2EFCTK.js +2 -0
- package/dist/{changelog-M5VP33UN.js → changelog-VCAUV47V.js} +1 -1
- package/dist/chunk-45VTQLJS.js +6 -0
- package/dist/chunk-4QO6JYHX.js +2 -0
- package/dist/chunk-77SZF4ZU.js +2 -0
- package/dist/chunk-7I2SQ2KP.js +2 -0
- package/dist/chunk-7NDFOI6Z.js +2 -0
- package/dist/chunk-7U4NY37W.js +22 -0
- package/dist/chunk-AGS57DSG.js +17 -0
- package/dist/chunk-C6S4IEBC.js +2 -0
- package/dist/chunk-CMRNCZGV.js +6 -0
- package/dist/chunk-DAVPOA2L.js +2 -0
- package/dist/{chunk-VUIXILBR.js → chunk-EEF6OT52.js} +8 -8
- package/dist/chunk-FGC74Z76.js +2 -0
- package/dist/chunk-FPFOW6BS.js +2 -0
- package/dist/chunk-G6AXOEED.js +2 -0
- package/dist/{chunk-74MJWDIW.js → chunk-H4XK55B3.js} +1 -1
- package/dist/chunk-HN7DVSVI.js +11 -0
- package/dist/chunk-HUOC7DUT.js +2 -0
- package/dist/chunk-IBDWHXNE.js +2 -0
- package/dist/{chunk-QKM3RHSQ.js → chunk-J2KTLZAW.js} +1 -1
- package/dist/{chunk-PQGNWC33.js → chunk-JGXJDTMO.js} +1 -1
- package/dist/chunk-JJERCR2W.js +5 -0
- package/dist/{chunk-L256AYYL.js → chunk-KJEJ7VW5.js} +1 -1
- package/dist/chunk-LAR7I5SR.js +2 -0
- package/dist/chunk-LEXQLAWB.js +60 -0
- package/dist/chunk-LOIRZFV3.js +10 -0
- package/dist/chunk-LPUQ4HWQ.js +2 -0
- package/dist/{chunk-X5CCG35O.js → chunk-OFEPMULV.js} +1 -1
- package/dist/chunk-OIPVMEM7.js +2 -0
- package/dist/chunk-P7ZUISQG.js +2 -0
- package/dist/chunk-RHUD7MK4.js +20 -0
- package/dist/chunk-RJNGCQCL.js +2 -0
- package/dist/chunk-T46Z27UL.js +5 -0
- package/dist/chunk-TCLKNUAL.js +17 -0
- package/dist/chunk-UHFCCGVX.js +2 -0
- package/dist/chunk-UYHNJUPY.js +2 -0
- package/dist/chunk-V3FSESZ4.js +2 -0
- package/dist/chunk-VKG45YIL.js +2 -0
- package/dist/chunk-YAVIOVVP.js +2 -0
- package/dist/chunk-YSSBAIJI.js +8 -0
- package/dist/chunk-Z7AXAKPX.js +9 -0
- package/dist/chunk-ZUIWBVGF.js +14 -0
- package/dist/exit-manager-V2NW7A7U.js +2 -0
- package/dist/generate-headless-XWVVEFQR.js +18 -0
- package/dist/index.js +39 -38
- package/dist/list-commands-Y6A3XR4L.js +2 -0
- package/dist/login-flow-MKAYO6IS.js +2 -0
- package/dist/persist-recorded-session-WBPLUA55.js +3 -0
- package/dist/{pipeline-L3VM7QEX.js → pipeline-L5TDZMLS.js} +1 -1
- package/dist/{recording-banner-Q66Y2UIC.js → recording-banner-Q36WARSF.js} +1 -1
- package/dist/require-project-folder-DBXAG7FB.js +2 -0
- package/dist/resolver-IDCGRPFJ.js +2 -0
- package/dist/run-test-md-H2X6CUIX.js +14 -0
- package/dist/scrollback-6GINSTL2.js +2 -0
- package/dist/tcg-generate-WURS7TXW.js +2 -0
- package/dist/testmd-actions-MQ3N7IS4.js +2 -0
- package/dist/{tms-client-R5ZIAOBH.js → tms-client-NNYXLXZK.js} +1 -1
- package/dist/token-refresh-HHNMHTYX.js +2 -0
- package/dist/validate-basic-VFJZKHOE.js +2 -0
- package/dist/{version-check-WWOS4OEZ.js → version-check-5NUDIYG4.js} +1 -1
- package/package.json +5 -5
- package/dist/ConfigView-PCX3TZNC.js +0 -2
- package/dist/FolderPicker-UTY6XQHP.js +0 -2
- package/dist/HelpView-CDK7II5Q.js +0 -2
- package/dist/ProjectPicker-TWTR6SWR.js +0 -2
- package/dist/SingleShotApp-JH6A65TZ.js +0 -2
- package/dist/SummaryBox-FDNFQYSC.js +0 -2
- package/dist/TestMdRunView-E4UDWIGT.js +0 -2
- package/dist/WhoamiView-YG6SSQTV.js +0 -2
- package/dist/chunk-2SXNPFGD.js +0 -2
- package/dist/chunk-5XTLIGWL.js +0 -2
- package/dist/chunk-7CLUJYMW.js +0 -2
- package/dist/chunk-BDC7IOXP.js +0 -17
- package/dist/chunk-BPF7TDRU.js +0 -2
- package/dist/chunk-EIZXV3UH.js +0 -2
- package/dist/chunk-G7VF5SDK.js +0 -10
- package/dist/chunk-HROFBRMS.js +0 -5
- package/dist/chunk-JHNEE2MB.js +0 -2
- package/dist/chunk-KMTNMUVS.js +0 -8
- package/dist/chunk-KX7K3Y7R.js +0 -5
- package/dist/chunk-LYSEA5FB.js +0 -6
- package/dist/chunk-MJQ2EHSC.js +0 -2
- package/dist/chunk-OQZG3V6B.js +0 -2
- package/dist/chunk-PJMTAAZ7.js +0 -2
- package/dist/chunk-PYU2JPAY.js +0 -2
- package/dist/chunk-QCNKJUPT.js +0 -2
- package/dist/chunk-R7JZMKC7.js +0 -9
- package/dist/chunk-TP6KYKPD.js +0 -2
- package/dist/chunk-U4XV5KUD.js +0 -2
- package/dist/chunk-VS5FTXRZ.js +0 -13
- package/dist/chunk-WZCGEQ6M.js +0 -2
- package/dist/chunk-X7VI7KK3.js +0 -11
- package/dist/chunk-YX3YFXT5.js +0 -2
- package/dist/chunk-ZAUHYR76.js +0 -2
- package/dist/chunk-ZY4BZQHD.js +0 -2
- package/dist/login-flow-3YFO62HA.js +0 -2
- package/dist/persist-recorded-session-LVQLORT4.js +0 -3
- package/dist/resolver-OA35IO7J.js +0 -2
- package/dist/run-test-md-5TNUTTEA.js +0 -64
- package/dist/testmd-actions-O4NTH2OR.js +0 -20
- package/dist/validate-basic-JJOEAFLT.js +0 -2
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { createRequire } from 'module'; const require = createRequire(import.meta.url);
|
|
2
|
+
import{a as L,b as et}from"./chunk-CMRNCZGV.js";import{a as U,b as X}from"./chunk-77SZF4ZU.js";import{a as Z,b as tt}from"./chunk-MDBXYXSC.js";import{a as C,b as J,e as P,f as Q}from"./chunk-AH4AXJML.js";import{a as W}from"./chunk-YSSBAIJI.js";import{a as z}from"./chunk-UHFCCGVX.js";import{a as N}from"./chunk-T46Z27UL.js";import{a as G}from"./chunk-LAR7I5SR.js";import{a as I}from"./chunk-RZ4F3BHX.js";import{t as h}from"./chunk-IBDWHXNE.js";import{a as $}from"./chunk-HCBYKLMW.js";import{a as k,b as g,i as K}from"./chunk-C44QQJR4.js";import{a as B}from"./chunk-6YGTRKDT.js";import{e as R}from"./chunk-UR6MHSHU.js";var M=R(B(),1);import{existsSync as D,readFileSync as jt,rmSync as dt,unlinkSync as Bt}from"fs";import{resolve as Y}from"path";import{promises as rt,realpathSync as _t}from"fs";import{homedir as xt}from"os";import{join as H,parse as wt,relative as nt,resolve as ot}from"path";var it=new Set(["node_modules",".git","dist","build",".next",".venv","venv","target","__pycache__"]),v=class extends Error{constructor(i){super(`refusing to scan '${i}'. Run from your project root, or pass --root <dir>.`);this.cwd=i;this.name="HomeRefusedError"}};function st(t){try{return _t(ot(t))}catch{return ot(t)}}function yt(t){let r=st(t),i=st(xt()),n=wt(r).root;if(process.platform==="win32"){let o=e=>e.toLowerCase();return o(r)===o(i)||o(r)===o(n)}return r===i||r===n}async function A(t){if(yt(t.root))throw new v(t.root);let r=t.maxEntries??5e4,i=t.maxResults??5e3,n=new Set(t.ignore??[]),o=[],e=0,s=0,c=!1,d,l=[t.root];for(;l.length>0&&!c;){let a=l.shift(),m;try{m=await rt.readdir(a,{withFileTypes:!0})}catch{continue}s++;for(let E of m){if(e++,e>r){c=!0,d="max_entries";break}let x=E.name,T=H(a,x);if(E.isDirectory()){if(it.has(x)||x.startsWith(".")||x.startsWith("output-")||n.has(x))continue;l.push(T)}else if(E.isFile()&&x.endsWith("_test.md")&&(o.push({path:T,relPath:nt(t.root,T),source:"cwd"}),o.length>=i)){c=!0,d="max_results";break}}t.onProgress?.(s,o.length)}if(!c){let m=[{dir:H(t.root,".testmuai","tests"),depth:0}];for(;m.length>0&&!c;){let{dir:E,depth:x}=m.shift(),T;try{T=await rt.readdir(E,{withFileTypes:!0})}catch{continue}s++;for(let f of T){if(e++,e>r){c=!0,d="max_entries";break}let w=f.name,y=H(E,w);if(f.isDirectory()){if(x>=20||w.startsWith(".")||w.startsWith("output-")||it.has(w))continue;m.push({dir:y,depth:x+1})}else if(f.isFile()&&w.endsWith("_test.md")&&(o.push({path:y,relPath:nt(t.root,y),source:"tests-dir"}),o.length>=i)){c=!0,d="max_results";break}}}}return{results:o,aborted:c,abortReason:d,dirsScanned:s}}import{mkdirSync as kt,writeFileSync as Et}from"fs";import{join as bt}from"path";function at(t,r){return`Basic ${Buffer.from(`${t}:${r}`).toString("base64")}`}async function Tt(t){let r=Z({tmsBaseUrl:t.tmsBaseUrl,testcaseId:t.testcaseId,codeExport:{enabled:!0,language:t.language,skipValidation:t.skipValidation}}),i=await I(r.url,{method:"POST",headers:{"content-type":"application/json",authorization:at(t.auth.username,t.auth.access_key)},body:JSON.stringify(r.body)});if(!i.ok)throw new Error(`code-export trigger failed: ${i.status} ${await i.text()}`);t.log("info","CODE_EXPORT_TRIGGERED","Code export triggered",{testcase_id:t.testcaseId})}async function St(t){let r=tt({tmsBaseUrl:t.tmsBaseUrl,testcaseId:t.testcaseId}),i=t.pollIntervalMs??5e3,n=t.timeoutMs??3e5,o=Date.now()+n;for(;Date.now()<o;){let e=await I(r,{headers:{authorization:at(t.auth.username,t.auth.access_key),accept:"application/json"}});if(!e.ok){await new Promise(l=>setTimeout(l,i));continue}let c=(await e.json()).data?.find(l=>l.code_name==="kane-cli-trigger");if(!c){await new Promise(l=>setTimeout(l,i));continue}let d=(c.status??"").toLowerCase();if(d==="in progress"||d==="in_progress"||d==="pending"){await new Promise(l=>setTimeout(l,i));continue}if(!c.url||c.url.length===0)throw new Error(`code-export status=${c.status} but no files returned`);kt(t.outDir,{recursive:!0});for(let l of c.url){let a=bt(t.outDir,l.file_name),m=await I(l.file_url);if(!m.ok){t.log("warn","CODE_EXPORT_FILE_FAILED","Failed to download file",{file_name:l.file_name,status:m.status});continue}let E=await m.text();Et(a,E,"utf-8")}return t.log("info","CODE_EXPORT_DOWNLOADED","Code export saved",{out_dir:t.outDir,file_count:c.url.length}),t.outDir}throw new Error("code-export polling timed out")}async function ct(t){return await Tt(t),await St(t)}var b=R(B(),1);import{existsSync as Rt,readFileSync as vt}from"fs";var p=R($(),1);function Pt(t){L(t);let r=P(t);if(!Rt(r))return null;try{return JSON.parse(vt(r,"utf8"))}catch{return{}}}function Mt(t){return t===null?"never_run":t.testcase_id?"synced":"local_only"}function Dt(t){return t==="synced"?"\u2601":t==="local_only"?"\u25A3":"\u25CB"}function Ct(t){return t==="tests-dir"?"\u2726":" "}function Ot(t,r){return r==="all"?!0:r==="synced"?t.status==="synced":r==="local"?t.status==="local_only":r==="never_run"?t.status==="never_run":r==="cli"?t.source==="tests-dir":r==="hand"?t.source==="cwd":!0}var V=["all","synced","local","never_run","cli","hand"];function Ft(t){let r=V.indexOf(t);return V[(r+1)%V.length]}function lt({root:t,currentOrgId:r,onSelect:i,onCancel:n}){let[o,e]=(0,b.useState)([]),[s,c]=(0,b.useState)(null),[d,l]=(0,b.useState)(!0),[a,m]=(0,b.useState)("all");(0,b.useEffect)(()=>{(async()=>{try{let f=await A({root:t}),w=[];for(let y of f.results){let j=Pt(y.path);j?.org_id!==void 0&&j.org_id!==r||w.push({path:y.path,relPath:y.relPath,name:C(y.path),status:Mt(j),source:y.source})}e(w),l(!1)}catch(f){f instanceof v,c(f.message),l(!1)}})()},[t,r]);let E=(0,b.useMemo)(()=>o.filter(f=>Ot(f,a)).map(f=>({id:f.path,label:`${Dt(f.status)} ${Ct(f.source)} ${f.relPath}`})),[o,a]),x=(0,b.useMemo)(()=>It(a,o),[a,o]);if(s)return(0,p.jsxs)(k,{flexDirection:"column",borderStyle:"round",borderColor:h.red,paddingX:2,paddingY:1,children:[(0,p.jsx)(g,{color:h.red,bold:!0,children:"testmd"}),(0,p.jsx)(k,{marginTop:1,children:(0,p.jsx)(g,{color:h.red,children:s})})]});let T=a==="all"?"all":$t(a);return(0,p.jsx)(z,{title:`testmd \xB7 filter: ${T}`,items:E,loading:d,itemNoun:"tests",onSelect:f=>{let w=o.find(y=>y.path===f.id);w&&i(w)},onCancel:n,onTab:()=>m(f=>Ft(f)),extraHint:"cycle filter",footer:x})}function $t(t){return t==="synced"?"synced (\u2601)":t==="local"?"local (\u25A3)":t==="never_run"?"never run (\u25CB)":t==="cli"?"cli-generated (\u2726)":t==="hand"?"hand-written":"all"}function It(t,r){let i={synced:r.filter(o=>o.status==="synced").length,local:r.filter(o=>o.status==="local_only").length,never:r.filter(o=>o.status==="never_run").length,cli:r.filter(o=>o.source==="tests-dir").length,hand:r.filter(o=>o.source==="cwd").length},n=o=>o?h.orange:h.dim;return(0,p.jsxs)(k,{flexDirection:"column",children:[(0,p.jsx)(g,{color:h.dim,children:"legend:"}),(0,p.jsxs)(k,{children:[(0,p.jsx)(g,{color:n(t==="synced"),children:` \u2601 synced (${i.synced}) `}),(0,p.jsx)(g,{color:n(t==="local"),children:`\u25A3 local (${i.local}) `}),(0,p.jsx)(g,{color:n(t==="never_run"),children:`\u25CB never run (${i.never})`})]}),(0,p.jsxs)(k,{children:[(0,p.jsx)(g,{color:n(t==="cli"),children:` \u2726 cli-generated (${i.cli}) `}),(0,p.jsx)(g,{color:n(t==="hand"),children:` hand-written (${i.hand})`})]})]})}var O=R(B(),1);import{existsSync as Lt,readFileSync as At}from"fs";var u=R($(),1);function ut({path:t,relPath:r,onAction:i,onBack:n,onView:o}){let[e,s]=(0,O.useState)(null),[c,d]=(0,O.useState)(!1);(0,O.useEffect)(()=>{let a=P(t);if(Lt(a))try{s(JSON.parse(At(a,"utf8")))}catch{s(null)}},[t]),K((a,m)=>{if(m.escape){if(c){d(!1);return}n();return}if(c){a==="y"||a==="Y"?(d(!1),i("delete")):(a==="n"||a==="N")&&d(!1);return}a==="r"&&i("run"),a==="e"&&e?.testcase_id&&i("export"),a==="d"&&d(!0),a==="v"&&o&&o()});let l=({k:a,v:m})=>m?(0,u.jsxs)(g,{children:[(0,u.jsx)(g,{color:h.dim,children:a.padEnd(14)}),m]}):null;return(0,u.jsxs)(k,{flexDirection:"column",borderStyle:"round",borderColor:h.orange,paddingX:2,paddingY:1,children:[(0,u.jsx)(g,{color:h.orange,bold:!0,children:r}),(0,u.jsx)(k,{marginTop:1,flexDirection:"column",children:e?(0,u.jsxs)(u.Fragment,{children:[(0,u.jsx)(l,{k:"test_id",v:e.test_id}),(0,u.jsx)(l,{k:"testcase_id",v:e.testcase_id}),(0,u.jsx)(l,{k:"project_id",v:e.project_id}),(0,u.jsx)(l,{k:"folder_id",v:e.folder_id}),(0,u.jsx)(l,{k:"org_id",v:e.org_id}),(0,u.jsx)(l,{k:"session_name",v:e.session_name}),(0,u.jsx)(l,{k:"commit_id",v:e.commit_id})]}):(0,u.jsx)(g,{color:h.dim,children:"(never run \u2014 no meta.json)"})}),c?(0,u.jsx)(k,{marginTop:1,children:(0,u.jsxs)(g,{color:h.red,bold:!0,children:["Delete ",r," and its output dir? [y/n]"]})}):(0,u.jsx)(k,{marginTop:1,children:(0,u.jsxs)(g,{color:h.dim,children:["[r] run [e] export",e?.testcase_id?"":" (need testcase_id)"," [d] delete",o?" [v] view":""," [Esc] back"]})})]})}function F(t){L(t);let r=P(t);if(!D(r))return null;try{return JSON.parse(jt(r,"utf8"))}catch{return null}}function ft(t,r){return!t||t.org_id===void 0?!0:t.org_id===r}function q(t,r){return ft(t,r)?null:(process.stderr.write(`error: this test belongs to org ${t.org_id}; you are logged in as org ${r}.
|
|
3
|
+
Switch profiles with \`kane-cli profiles switch\` to act on it.
|
|
4
|
+
`),2)}async function Me(t={}){let r=!!process.stdin.isTTY&&!t.json,i=new N,n=new W;await et({isInteractive:r,creds:i,config:n});let o=i.getDefaultEnv()??"prod";try{let e=await X({creds:i,env:o,log:()=>{}});return e.resolvedCreds?.org_id===void 0?(process.stderr.write("error: TMS did not return an org_id. Run `kane-cli login` again.\n"),{ok:!1,code:2}):{ok:!0,orgId:String(e.resolvedCreds.org_id)}}catch(e){if(e instanceof U)return process.stderr.write("error: not authenticated. Run `kane-cli login` first.\n"),{ok:!1,code:2};throw e}}async function De(t,r){if(process.stdin.isTTY&&!t.json)return await Jt(r,t.root);let i=t.root??process.cwd(),n;try{n=await A({root:i,ignore:t.ignore})}catch(o){if(o instanceof v)return process.stderr.write(`error: ${o.message}
|
|
5
|
+
`),2;throw o}for(let o of n.results){let e=F(o.path);if(!ft(e,r))continue;let s={path:o.relPath.startsWith(".")?o.relPath:`./${o.relPath}`,name:C(o.path),has_meta:e!==null,source:o.source,synced:!!e?.testcase_id};e&&(e.test_id&&(s.test_id=e.test_id),e.testcase_id&&(s.testcase_id=e.testcase_id),e.org_id&&(s.org_id=e.org_id),e.project_id&&(s.project_id=e.project_id),e.folder_id&&(s.folder_id=e.folder_id)),process.stdout.write(JSON.stringify(s)+`
|
|
6
|
+
`)}return n.aborted&&process.stderr.write(`warn: walk aborted (${n.abortReason}). Pass --root or --ignore to narrow.
|
|
7
|
+
`),0}var mt=-1001,gt=-1002,pt=-1003,_={action:null,path:null};function Nt(t,r){return _.action=t,_.path=r,t==="run"?mt:t==="export"?gt:pt}function Wt({root:t,currentOrgId:r,onComplete:i}){let[n,o]=M.default.useState({kind:"list"});return M.default.useEffect(()=>{n.kind==="exiting"&&i(n.code)},[n,i]),n.kind==="list"?M.default.createElement(lt,{root:t,currentOrgId:r,onSelect:e=>o({kind:"inspect",path:e.path,relPath:e.relPath}),onCancel:()=>o({kind:"exiting",code:0})}):n.kind==="inspect"?M.default.createElement(ut,{path:n.path,relPath:n.relPath,onAction:async e=>{o({kind:"exiting",code:Nt(e,n.path)})},onBack:()=>o({kind:"list"})}):null}async function Jt(t,r){let i=r??process.cwd(),{render:n}=await import("./build-JIKYOZUH.js"),o=await new Promise(e=>{let{unmount:s,waitUntilExit:c}=n(M.default.createElement(Wt,{root:i,currentOrgId:t,onComplete:d=>{s(),e(d)}}),{stdout:process.stderr,exitOnCtrlC:!0});c().then(()=>e(0)).catch(()=>e(0))});if(o===mt&&_.path){let{runTestMdFile:e}=await import("./run-test-md-H2X6CUIX.js"),s=await e(_.path,{});return _.action=null,_.path=null,s}if(o===gt&&_.path){let e=await Xt(_.path,{},t);return _.action=null,_.path=null,e}if(o===pt&&_.path){let e=await Ut(_.path,!0,t);return _.action=null,_.path=null,e}return o}async function Ce(t,r){let i=Y(t);if(!D(i))return process.stderr.write(`error: file not found: ${i}
|
|
8
|
+
`),2;let n=F(i),o=q(n,r);if(o!==null)return o;let e={path:i,name:C(i),has_meta:n!==null};return n&&(n.commit_id&&(e.commit_id=n.commit_id),n.test_id&&(e.test_id=n.test_id),n.testcase_id&&(e.testcase_id=n.testcase_id),n.project_id&&(e.project_id=n.project_id),n.folder_id&&(e.folder_id=n.folder_id),n.org_id&&(e.org_id=n.org_id),n.session_name&&(e.session_name=n.session_name)),process.stdout.write(JSON.stringify(e)+`
|
|
9
|
+
`),0}async function Ut(t,r,i){let n=Y(t);if(!D(n))return process.stderr.write(`error: file not found: ${n}
|
|
10
|
+
`),2;let o=F(n),e=q(o,i);if(e!==null)return e;if(!r)return process.stderr.write(`error: refusing to delete without --yes.
|
|
11
|
+
This will remove '${n}' and '${J(n)}/'.
|
|
12
|
+
`),2;let s=J(n);if(D(s))try{dt(s,{recursive:!0,force:!0})}catch(c){return process.stderr.write(`error: failed to remove ${s}: ${c.message}
|
|
13
|
+
`),2}try{Bt(n)}catch(c){return process.stderr.write(`error: failed to remove ${n}: ${c.message}
|
|
14
|
+
`),2}return process.stderr.write(`removed ${n} and ${s}/
|
|
15
|
+
`),0}var S=class extends Error{kind;constructor(r,i){super(i),this.name="ExportError",this.kind=r}};async function Oe(t,r){let{codeDir:i}=await ht(t,r);return{codeDir:i}}async function ht(t,r){let i=F(t);if(!i?.testcase_id)throw new S("not-synced","this test has not been synced to TMS \u2014 run `kane-cli testmd run` first.");let n=new W().load(),o=r.language??n.code_export?.language;if(!o)throw new S("no-language","--language not provided and no default in tui-config.");let e=r.output??Q(t,"playwright",o),s=D(e);if(s&&!r.force){let a=!1;try{let{readdirSync:m}=await import("fs");a=m(e).length>0}catch{}if(a)return{kind:"reused",codeDir:e}}s&&r.force&&dt(e,{recursive:!0,force:!0});let c=new N,d=r.env??c.getDefaultEnv()??"prod",l;try{l=await X({creds:c,env:d,log:()=>{}})}catch(a){throw a instanceof U?new S("auth-fail","not authenticated. Run `kane-cli login` first."):a}if(!l.basicAuth)throw new S("auth-incomplete","TMS basic auth could not be resolved. Run `kane-cli login` again.");try{let a=G(d);await ct({tmsBaseUrl:a.tmsBaseUrl,testcaseId:i.testcase_id,auth:l.basicAuth,language:o,framework:"playwright",skipValidation:n.code_export?.skip_validation??!0,outDir:e,log:()=>{}})}catch(a){throw new S("export-fail",`code export failed: ${a.message}`)}return{kind:"exported",codeDir:e}}async function Xt(t,r,i){let n=Y(t);if(!D(n))return process.stderr.write(`error: file not found: ${n}
|
|
16
|
+
`),2;let o=F(n),e=q(o,i);if(e!==null)return e;try{let s=await ht(n,r);return s.kind==="reused"?process.stderr.write(`reusing existing export at ${s.codeDir}
|
|
17
|
+
`):process.stderr.write(`exported to ${s.codeDir}
|
|
18
|
+
`),0}catch(s){if(s instanceof S)return s.kind==="not-synced"?(process.stderr.write("error: this test has not been synced to TMS \u2014 run `kane-cli testmd run` first.\n"),2):s.kind==="no-language"?(process.stderr.write(`error: --language not provided and no default in tui-config.
|
|
19
|
+
`),2):s.kind==="auth-fail"?(process.stderr.write("error: not authenticated. Run `kane-cli login` first.\n"),2):s.kind==="auth-incomplete"?(process.stderr.write("error: TMS basic auth could not be resolved. Run `kane-cli login` again.\n"),2):(process.stderr.write(`error: ${s.message}
|
|
20
|
+
`),2);throw s}}export{lt as a,ut as b,F as c,ft as d,q as e,Me as f,De as g,Jt as h,Ce as i,Ut as j,S as k,Oe as l,Xt as m};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { createRequire } from 'module'; const require = createRequire(import.meta.url);
|
|
2
|
+
import{b as B}from"./chunk-S3DAAAE5.js";import{a as g}from"./chunk-UYHNJUPY.js";import{t as s}from"./chunk-IBDWHXNE.js";import{a as w}from"./chunk-HCBYKLMW.js";import{a as x,b as t,c as h,i as P,j as S}from"./chunk-C44QQJR4.js";import{a as C}from"./chunk-6YGTRKDT.js";import{e as T}from"./chunk-UR6MHSHU.js";var o=T(C(),1);var e=T(w(),1);function D({defaultName:i,onSubmit:c}){let[d,p]=(0,o.useState)("confirm"),[f,a]=(0,o.useState)(""),[m,u]=(0,o.useState)(null),l=(0,o.useMemo)(()=>f.trim()||i,[f,i]);return P((n,r)=>{if(d==="confirm"){if(n==="y"||n==="Y"){a(i),p("name");return}if(n==="n"||n==="N"||r.escape||r.ctrl&&n==="c"){c(null);return}if(r.return){c(i);return}return}if(r.return){if(!B(l)){u(`name "${l}" is invalid; allowed: letters, digits, underscore, hyphen`);return}c(l);return}if(r.escape||r.ctrl&&n==="c"){c(null);return}if(r.backspace||r.delete){a(v=>v.slice(0,-1)),u(null);return}n&&!r.ctrl&&!r.meta&&(a(v=>v+n),u(null))}),d==="confirm"?(0,e.jsx)(g,{title:"Save session?",titleColor:"#ff9500",rows:[{label:"name",value:(0,e.jsx)(t,{color:s.orange,children:i})}],footer:(0,e.jsxs)(x,{flexDirection:"column",children:[(0,e.jsx)(t,{color:s.dim,children:"enter \u2014 save with this name"}),(0,e.jsx)(t,{color:s.dim,children:"Y \u2014 edit name"}),(0,e.jsx)(t,{color:s.dim,children:"N/esc \u2014 discard session"})]})}):(0,e.jsx)(g,{title:"Save session?",titleColor:"#ff9500",rows:[{label:"name",value:(0,e.jsxs)(x,{children:[(0,e.jsx)(t,{color:s.orange,children:f}),(0,e.jsx)(t,{inverse:!0,children:" "})]})}],footer:(0,e.jsxs)(x,{flexDirection:"column",children:[m&&(0,e.jsx)(t,{color:s.red,children:m}),(0,e.jsx)(t,{color:s.dim,children:"enter \u2014 save \xB7 esc \u2014 discard"})]})})}function V(){return new Date().toISOString().slice(0,19).replace(/:/g,"-")}async function Y(i){return new Promise(c=>{function d(){let{exit:a}=S(),[m,u]=(0,o.useState)(!1);return(0,o.useEffect)(()=>{if(m){let l=setTimeout(()=>a(),50);return()=>clearTimeout(l)}},[m,a]),(0,e.jsx)(D,{defaultName:i,onSubmit:l=>{c(l),u(!0)}})}let{waitUntilExit:p,unmount:f}=h((0,e.jsx)(d,{}),{stdout:process.stderr,exitOnCtrlC:!1});p().then(()=>{try{f()}catch{}})})}export{D as a,V as b,Y as c};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { createRequire } from 'module'; const require = createRequire(import.meta.url);
|
|
2
|
+
import{c as g}from"./chunk-IBDWHXNE.js";import{readFileSync as o,writeFileSync as h,mkdirSync as u,readdirSync as a,unlinkSync as s,existsSync as l,chmodSync as f}from"fs";import{join as n,dirname as P}from"path";var d=class{baseDir;profilesDir;configFile;constructor(t=g){this.baseDir=t,this.profilesDir=n(t,"profiles"),this.configFile=n(t,"config.json")}readConfig(){try{return JSON.parse(o(this.configFile,"utf-8"))}catch{return{}}}writeConfig(t){u(this.baseDir,{recursive:!0,mode:448}),h(this.configFile,JSON.stringify(t,null,2)+`
|
|
3
|
+
`),f(this.configFile,384)}getActiveProfile(){return this.readConfig().active_profile??null}setActiveProfile(t){let i=this.readConfig();i.active_profile=t,this.writeConfig(i)}getDefaultEnv(){return this.readConfig().default_env??"prod"}setDefaultEnv(t){let i=this.readConfig();i.default_env=t,this.writeConfig(i)}credentialsPath(t,i){return n(this.profilesDir,t,i,"credentials")}clientPath(t,i){return n(this.profilesDir,t,i,"client.json")}basicAuthPath(t,i){return n(this.profilesDir,t,i,"basic-auth")}profileConfigPath(t,i){return n(this.profilesDir,t,i,"profile-config.json")}saveProfileConfig(t,i,r){let e=this.loadProfileConfig(t,i)??{};this.writeSecure(this.profileConfigPath(t,i),{...e,...r})}loadProfileConfig(t,i){try{return JSON.parse(o(this.profileConfigPath(t,i),"utf-8"))}catch{return null}}writeSecure(t,i){try{u(P(t),{recursive:!0,mode:448}),h(t,JSON.stringify(i,null,2)+`
|
|
4
|
+
`),f(t,384)}catch(r){let e=r instanceof Error?r.message:String(r);process.stderr.write(`[auth] Failed to save credentials: ${e}
|
|
5
|
+
`)}}saveCredentials(t,i,r){this.writeSecure(this.credentialsPath(t,i),r)}loadCredentials(t,i){try{return JSON.parse(o(this.credentialsPath(t,i),"utf-8"))}catch{return null}}saveClient(t,i,r){this.writeSecure(this.clientPath(t,i),r)}loadClient(t,i){try{return JSON.parse(o(this.clientPath(t,i),"utf-8"))}catch{return null}}getActiveCredentials(){let t=this.getActiveProfile();if(!t)return{credentials:null,profile:null,env:null};let i=this.getDefaultEnv();return{credentials:this.loadCredentials(t,i),profile:t,env:i}}saveBasicAuth(t,i,r){this.writeSecure(this.basicAuthPath(t,i),r)}loadBasicAuth(t,i){try{return JSON.parse(o(this.basicAuthPath(t,i),"utf-8"))}catch{return null}}deleteBasicAuth(t,i){try{s(this.basicAuthPath(t,i))}catch{}}resolveAuth(){let t=this.getActiveProfile();if(!t)return null;let i=this.getDefaultEnv(),r=this.loadBasicAuth(t,i);return r?{method:"basic",...r,profile:t,env:i}:this.loadCredentials(t,i)?{method:"oauth",profile:t,env:i}:null}listProfiles(){let t=[];try{for(let i of a(this.profilesDir)){let r=n(this.profilesDir,i);try{for(let e of a(r)){let c=n(r,e),v=l(n(c,"credentials")),p=l(n(c,"client.json")),y=l(n(c,"basic-auth"));(v||p||y)&&t.push({profile:i,env:e})}}catch{}}}catch{}return t}deleteProfile(t,i){try{s(this.credentialsPath(t,i))}catch{}if(this.getActiveProfile()===t){let r=this.readConfig();delete r.active_profile,this.writeConfig(r)}}deleteProfileFull(t,i){if(i){try{s(this.credentialsPath(t,i))}catch{}try{s(this.clientPath(t,i))}catch{}try{s(this.basicAuthPath(t,i))}catch{}try{s(this.profileConfigPath(t,i))}catch{}}else try{let r=n(this.profilesDir,t);for(let e of a(r)){try{s(n(r,e,"credentials"))}catch{}try{s(n(r,e,"client.json"))}catch{}try{s(n(r,e,"basic-auth"))}catch{}try{s(n(r,e,"profile-config.json"))}catch{}}}catch{}}};export{d as a};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { createRequire } from 'module'; const require = createRequire(import.meta.url);
|
|
2
|
+
import{a as m}from"./chunk-LPUQ4HWQ.js";import{b as f,c as j}from"./chunk-VE3SUJMA.js";import{a as g}from"./chunk-LAR7I5SR.js";var _="KaneAI Generated",E="Untitled";async function p(e){let r=e.config.load(),d=new m(g(e.env).tmsBaseUrl,e.tmsCreds.username,e.tmsCreds.access_key),l=e.projectName??_,o=e.folderName??E,t=r.project_id??null,s=r.project_name??null;if(!t){let a=(await d.listProjects()).find(n=>n.name===l);if(a)t=a.project_id,s=a.name,e.log("info","ENSURE_PROJECT_FOUND","Found default project",{project_id:t,name:s});else{let n=await d.createProject(l);t=n.id,s=n.name,e.log("info","ENSURE_PROJECT_CREATED","Created default project",{project_id:t,name:s})}f(e.creds,e.config,e.profile,e.env,{projectId:t,projectName:s})}let c=r.folder_id??null,i=r.folder_name??null,u=!r.project_id;if(!c||u){let a=(await d.listFolders(t)).find(n=>n.name===o);if(a)c=a.id,i=a.name,e.log("info","ENSURE_FOLDER_FOUND","Found default folder",{folder_id:c,name:i});else{let n=await d.createFolder(t,o);c=n.id,i=n.name,e.log("info","ENSURE_FOLDER_CREATED","Created default folder",{folder_id:c,name:i})}f(e.creds,e.config,e.profile,e.env,{folderId:c,folderName:i})}return{projectId:t,projectName:s??l,folderId:c,folderName:i??o}}function N(e,r,d){let l=e.loadProfileConfig(r,d)??{};return{projectId:l.project_id??null,folderId:l.folder_id??null}}function A(e,r){return e.projectId===null||e.folderId===null||r===null?"needs-picker":r.project==="ok"&&r.folder==="ok"?"ok":r.project==="error"&&r.folder==="error"?"ok-tms-degraded":"needs-picker"}var k=(e,r)=>`error: profile "${e}" (${r}) has no project/folder configured AND no TMS credentials were available to auto-configure one.
|
|
3
|
+
|
|
4
|
+
discover IDs:
|
|
5
|
+
kane-cli projects list --search "<keyword>" --limit 10
|
|
6
|
+
kane-cli folders list --project <project-id> --search "<keyword>" --limit 10
|
|
7
|
+
|
|
8
|
+
create one:
|
|
9
|
+
kane-cli projects create "<project-name>"
|
|
10
|
+
kane-cli folders create "<folder-name>" --project <project-id>
|
|
11
|
+
|
|
12
|
+
set them:
|
|
13
|
+
kane-cli config project <project-id>
|
|
14
|
+
kane-cli config folder <folder-id>
|
|
15
|
+
`;function C(e,r){return k(e,r)}function D(e){return`info: auto-configured project "${e.projectName}" (${e.projectId}) and folder "${e.folderName}" (${e.folderId}). Change with: kane-cli config project <id> / kane-cli config folder <id>.`}function L(e){return`${JSON.stringify({type:"project_folder_auto_defaulted",project_id:e.projectId,project_name:e.projectName,folder_id:e.folderId,folder_name:e.folderName})}
|
|
16
|
+
`}async function S(e){if(e.isLocal)return e.log("info","GATE_SKIP_LOCAL","Gate skipped (--local)",{}),{status:"skip",reason:"local"};j(e.creds,e.config,e.profile,e.env,e.log);let r=N(e.creds,e.profile,e.env),d=null;if(r.projectId!==null){let o=g(e.env);d=await new m(o.tmsBaseUrl,e.tmsCreds.username,e.tmsCreds.access_key).validateProjectFolder(r.projectId,r.folderId??""),e.log("info","GATE_VALIDATE","TMS project/folder validation",{project:d.project,folder:d.folder,folder_was_cached:r.folderId!==null})}else r.folderId!==null&&(f(e.creds,e.config,e.profile,e.env,{folderId:null,folderName:null}),e.log("warn","GATE_CLEARED_ORPHAN_FOLDER","Cleared orphan folder (no project cached)",{folder_id:r.folderId}),r.folderId=null);let l=A(r,d);if(l==="ok")return{status:"ok",projectId:r.projectId,folderId:r.folderId};if(l==="ok-tms-degraded")return e.log("warn","GATE_TMS_DEGRADED","TMS validation failed; using cached IDs",{project_id:r.projectId,folder_id:r.folderId}),{status:"ok",projectId:r.projectId,folderId:r.folderId};if(d){let o={};d.project==="missing"?(o.projectId=null,o.projectName=null,o.folderId=null,o.folderName=null):d.folder==="missing"&&(o.folderId=null,o.folderName=null),Object.keys(o).length>0&&(f(e.creds,e.config,e.profile,e.env,o),e.log("info","GATE_CLEARED_STALE","Cleared stale cached IDs before re-resolve",{project_cleared:d.project==="missing",folder_cleared:d.folder==="missing"||d.project==="missing"}))}try{let o=await p({creds:e.creds,config:e.config,profile:e.profile,env:e.env,tmsCreds:e.tmsCreds,log:e.log}),t={projectId:o.projectId,projectName:o.projectName,folderId:o.folderId,folderName:o.folderName};return e.log("info","GATE_AUTO_DEFAULTED","Auto-configured project/folder",{project_id:t.projectId,project_name:t.projectName,folder_id:t.folderId,folder_name:t.folderName}),e.onAnnounce?e.onAnnounce(t):process.stderr.write(`${D(t)}
|
|
17
|
+
`),{status:"ok",projectId:t.projectId,folderId:t.folderId,autoDefaulted:t}}catch(o){let t=C(e.profile,e.env);if(e.log("error","GATE_FATAL","Auto-default failed",{profile:e.profile,env:e.env,cached_project_id:r.projectId,cached_folder_id:r.folderId,validation:d,error:o instanceof Error?o.message:String(o)}),e.onFatalExit)e.onFatalExit(t);else{process.stderr.write(t);let{shutdown:s}=await import("./exit-manager-V2NW7A7U.js");s(2,"Project/folder gate failed")}return{status:"cancelled"}}}export{p as a,N as b,A as c,C as d,D as e,L as f,S as g};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { createRequire } from 'module'; const require = createRequire(import.meta.url);
|
|
2
|
+
import{a as R}from"./chunk-JGXJDTMO.js";import{t as r}from"./chunk-IBDWHXNE.js";import{a as Y}from"./chunk-HCBYKLMW.js";import{a,b as i,i as X}from"./chunk-C44QQJR4.js";import{a as G}from"./chunk-6YGTRKDT.js";import{e as P}from"./chunk-UR6MHSHU.js";var u=P(G(),1);var e=P(Y(),1),f=5;function K(t,I){if(!I)return t;let c=I.toLowerCase();return t.filter(B=>B.label.toLowerCase().includes(c))}function J(t){let{title:I,items:c,loading:B=!1,loadingText:F,error:L=null,itemNoun:T="items",onSelect:H,onCancel:E,defaultActiveId:w,onTab:y,extraHint:N}=t,[x,d]=(0,u.useState)(0),[S,g]=(0,u.useState)(0),[s,A]=(0,u.useState)(""),[C,h]=(0,u.useState)(null);(0,u.useEffect)(()=>{if(c.length===0)return;if(t.preserveSelectionById&&C!==null){let n=c.findIndex(o=>o.id===C);if(n>=0){g(Math.floor(n/f)),d(n%f);return}}let l=w?c.findIndex(n=>n.id===w):c.findIndex(n=>n.isActive);l>=0?(g(Math.floor(l/f)),d(l%f),t.preserveSelectionById&&h(c[l].id)):t.preserveSelectionById&&(g(0),d(0),h(c[0]?.id??null))},[c,w,t.preserveSelectionById,C]),(0,u.useEffect)(()=>{if(!t.onSearch)return;let l=setTimeout(()=>t.onSearch(s),t.searchDebounceMs??250);return()=>clearTimeout(l)},[s,t.onSearch,t.searchDebounceMs]);let m=t.onSearch?c:K(c,s),M=S*f,p=Math.min(M+f,m.length),D=Math.ceil(m.length/f),O=p-M,v=m.slice(M,p);return X((l,n)=>{if(L){n.escape&&E();return}if(n.escape){s?(A(""),d(0),g(0)):E();return}if(n.tab&&y){y();return}if(n.upArrow){if(x>0){let o=x-1;d(o),t.preserveSelectionById&&h(v[o]?.id??null)}else if(S>0){let o=S-1,b=f-1;g(o),d(b),t.preserveSelectionById&&h(m[o*f+b]?.id??null)}return}if(n.downArrow){if(x<O-1){let o=x+1;d(o),t.preserveSelectionById&&h(v[o]?.id??null)}else if(S<D-1){let o=S+1,b=0;g(o),d(b),t.preserveSelectionById&&h(m[o*f+b]?.id??null)}return}if(n.return&&v[x]){H(v[x]);return}if(n.backspace||n.delete){A(o=>o.slice(0,-1)),d(0),g(0);return}l&&!n.ctrl&&!n.meta&&(A(o=>o+l),d(0),g(0))},{isActive:!B}),B?(0,e.jsxs)(a,{flexDirection:"column",borderStyle:"round",borderColor:r.orange,paddingX:2,paddingY:1,children:[(0,e.jsx)(i,{color:r.orange,bold:!0,children:I}),(0,e.jsx)(a,{marginTop:1,children:(0,e.jsx)(i,{color:r.secondary,children:F??`Loading ${T}\u2026`})})]}):L?(0,e.jsxs)(a,{flexDirection:"column",borderStyle:"round",borderColor:r.red,paddingX:2,paddingY:1,children:[(0,e.jsx)(i,{color:r.red,bold:!0,children:I}),(0,e.jsx)(a,{marginTop:1,children:(0,e.jsx)(i,{color:r.red,children:L})}),(0,e.jsx)(R,{bindings:[]})]}):(0,e.jsxs)(a,{flexDirection:"column",borderStyle:"round",borderColor:r.orange,paddingX:2,paddingY:1,children:[(0,e.jsxs)(a,{children:[(0,e.jsx)(i,{color:r.orange,bold:!0,children:I}),(0,e.jsxs)(i,{color:r.dim,children:[" (",m.length,!t.onSearch&&s?`/${c.length}`:""," ",T,t.loadingMore?" \xB7 loading more":"",")"]})]}),(0,e.jsxs)(a,{marginTop:1,children:[(0,e.jsx)(i,{color:r.secondary,children:s?"filter: ":""}),s?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(i,{children:s}),(0,e.jsx)(i,{inverse:!0,children:" "})]}):(0,e.jsxs)(e.Fragment,{children:[(0,e.jsxs)(i,{color:r.dim,children:["Search ",T,"\u2026"]}),(0,e.jsx)(i,{inverse:!0,children:" "})]})]}),(0,e.jsx)(a,{flexDirection:"column",marginTop:1,children:t.searching?(0,e.jsxs)(i,{color:r.secondary,children:["Searching ",T,"\u2026"]}):m.length===0?(0,e.jsxs)(i,{color:r.dim,children:["No ",T,' match "',s,'"']}):v.map((l,n)=>{let o=n===x,b=o?"\u276F ":" ",$=l.isActive?r.green:o?r.orange:void 0;return(0,e.jsxs)(i,{color:$,children:[b,l.label,l.isActive?" \u25CF selected":""]},l.id)})}),!t.searching&&D>1&&(0,e.jsx)(a,{marginTop:1,children:(0,e.jsxs)(i,{color:r.dim,children:["Page ",S+1,"/",D]})}),t.footer&&(0,e.jsx)(a,{marginTop:1,flexDirection:"column",children:t.footer}),(0,e.jsx)(R,{bindings:[{keys:"\u2191\u2193",label:"navigate"},{keys:"type",label:"to search"},{keys:"\u21B5",label:"select"},...y&&N?[{keys:"tab",label:N}]:[]],escBackLabel:s?"clear":"back to chat"})]})}export{J as a};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { createRequire } from 'module'; const require = createRequire(import.meta.url);
|
|
2
|
+
import{a as u,b as x}from"./chunk-HUOC7DUT.js";import{t as m}from"./chunk-IBDWHXNE.js";import{a as f}from"./chunk-HCBYKLMW.js";import{a as r,b as i}from"./chunk-C44QQJR4.js";import{e as n}from"./chunk-UR6MHSHU.js";var e=n(f(),1);function C({title:B,titleColor:c,borderColor:d,variant:p,rows:s,footer:t,labelWidth:l=14,marginBottom:b=1}){return(0,e.jsxs)(u,{title:B,titleColor:c,borderColor:d,variant:p,marginBottom:b,children:[s.map((o,a)=>typeof o.value=="string"?(0,e.jsx)(x,{label:o.label,value:o.value,valueColor:o.valueColor,labelWidth:l},`${o.label}-${a}`):(0,e.jsxs)(r,{children:[(0,e.jsx)(r,{width:l,children:(0,e.jsx)(i,{color:m.dim,children:o.label})}),o.value]},`${o.label}-${a}`)),t&&(0,e.jsx)(r,{marginTop:1,children:t})]})}export{C as a};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { createRequire } from 'module'; const require = createRequire(import.meta.url);
|
|
2
|
+
import{a as S}from"./chunk-UYHNJUPY.js";import{t as o}from"./chunk-IBDWHXNE.js";import{a as R}from"./chunk-HCBYKLMW.js";import{a as x,b as c,j as y}from"./chunk-C44QQJR4.js";import{a as w}from"./chunk-6YGTRKDT.js";import{e as b}from"./chunk-UR6MHSHU.js";var T=b(w(),1);var i=b(R(),1);function L(e){let t=e.decisions.filter(l=>l.kind==="replay").length,r=e.decisions.filter(l=>l.kind==="author").length,d=e.outcomes.filter(l=>l.status==="passed").length,p=e.outcomes.filter(l=>l.status==="failed").length,f=e.outcomes.filter(l=>l.status==="skipped").length,a=o.green,n;e.cancelled||e.overallStatus==="interrupted"?(a=o.orange,n="CANCELLED"):e.overallStatus==="failed"?(a=o.red,n="FAILED"):n="PASSED";let s=`${n} \xB7 ${e.durationS}s \xB7 ${e.outcomes.length} steps (${d} passed, ${p} failed, ${f} skipped)`,k=`${t} replay \xB7 ${r} author`,C=e.retryTriggered,_="yes \u2014 run recovered after a replay miss",u,g=o.dim;if(e.cancelled)u="\u2013 not committed (cancellation)";else if(e.overallStatus==="failed")u="\u2013 not committed (run failed)",g=o.red;else if(!e.shouldCommit)e.isFirstRun?u="\u2013 not committed (first run skipped commit)":e.lockHeld?u="\u2013 not committed":u="\u2013 not committed (readonly fallback / no lock)";else{let l=e.uploadResult?.testcaseId;u=l?`\u2713 pushed (testcase=${l})`:"\u2713 pushed",g=o.green}let v=e.shouldReplaceLocalOutput?"output dir replaced":e.anyAuthorStepRan?"untouched (cancellation or no replace)":"untouched (replay-only)",m,h=o.dim;return e.shouldUploadArtifacts?e.uploadResult?.success?(m="\u2713 TMS",h=o.green):e.uploadResult?(m=`\u2717 failed${e.uploadResult.error?`: ${e.uploadResult.error}`:""}`,h=o.red):m="\u2013 not run":m="\u2013 skipped (--local or no auth)",{resultLine:{color:a,text:s},breakdown:k,showRetries:C,retriesText:_,commitText:u,commitColor:g,artifactsText:v,uploadText:m,uploadColor:h}}function O(e){let t=e.decisions.filter(s=>s.kind==="replay").length,r=e.decisions.filter(s=>s.kind==="author").length,d=e.outcomes.filter(s=>s.status==="passed").length,p=e.outcomes.filter(s=>s.status==="failed").length,f=e.outcomes.filter(s=>s.status==="skipped").length,a,n=!1;return e.cancelled?a="cancellation":e.overallStatus==="failed"?a="run_failed":e.shouldCommit&&e.uploadResult?.testcaseId?(a="ok",n=!0):!e.shouldCommit&&!e.lockHeld&&!e.isFirstRun?a="readonly_fallback":a="not_committed",{type:"test_md_summary",overall_status:e.overallStatus,duration_s:e.durationS,steps:{total:e.outcomes.length,passed:d,failed:p,skipped:f,replay_decisions:t,author_decisions:r},retries:{triggered:e.retryTriggered},commit:{committed:n,reason:a,...e.uploadResult?.testcaseId?{testcase_id:e.uploadResult.testcaseId}:{}},artifacts:{replaced:e.shouldReplaceLocalOutput},upload:{performed:e.shouldUploadArtifacts,...e.uploadResult?{succeeded:!!e.uploadResult.success}:{}},...e.shareUrl?{share_url:e.shareUrl}:{},cancelled:e.cancelled}}function A({data:e}){let t=L(e),r=[{label:"result",value:(0,i.jsx)(c,{color:t.resultLine.color,bold:!0,children:t.resultLine.text})},{label:"breakdown",value:(0,i.jsx)(c,{color:o.dim,children:t.breakdown})}];return t.showRetries&&r.push({label:"retries",value:(0,i.jsx)(c,{color:o.orange,children:t.retriesText})}),r.push({label:"commit",value:(0,i.jsx)(c,{color:t.commitColor,children:t.commitText})}),r.push({label:"artifacts",value:(0,i.jsx)(c,{color:o.dim,children:t.artifactsText})}),r.push({label:"upload",value:(0,i.jsx)(c,{color:t.uploadColor,children:t.uploadText})}),(0,i.jsx)(S,{title:"Run summary",titleColor:"#ff9500",rows:r})}function I({data:e}){let{exit:t}=y();return(0,T.useEffect)(()=>{let r=setTimeout(()=>t(),50);return()=>clearTimeout(r)},[t]),(0,i.jsx)(x,{flexDirection:"column",children:(0,i.jsx)(A,{data:e})})}export{L as a,O as b,A as c,I as d};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { createRequire } from 'module'; const require = createRequire(import.meta.url);
|
|
2
|
+
import{a as b}from"./chunk-JGXJDTMO.js";import{k as d,t as o}from"./chunk-IBDWHXNE.js";import{a as L}from"./chunk-HCBYKLMW.js";import{a as u,b as c,i as A}from"./chunk-C44QQJR4.js";import{a as D}from"./chunk-6YGTRKDT.js";import{e as h}from"./chunk-UR6MHSHU.js";var x=h(D(),1);import{readdirSync as N,mkdirSync as B,statSync as k}from"fs";import{join as P}from"path";var r=h(L(),1);function O(n){try{return N(n).filter(l=>{try{return k(P(n,l)).isDirectory()}catch{return!1}})}catch{return[]}}function E(n,l,f,v){return{name:n,path:l,label:n,isActive:v}}function H({currentPath:n,onSelect:l,onCancel:f}){let s=O(d).map(i=>{let e=P(d,i);return E(i,e,n,e===n)}),p=!n,R=s.length+2,[a,C]=(0,x.useState)(()=>{if(p)return 0;let i=s.findIndex(e=>e.isActive);return i>=0?i+1:0}),[T,I]=(0,x.useState)(!1),[S,g]=(0,x.useState)("");return A((i,e)=>{if(T){if(e.escape){I(!1),g("");return}if(e.return){let t=S.trim();if(t){let m=P(d,t);B(m,{recursive:!0}),l(m),f()}return}if(e.backspace||e.delete){g(t=>t.slice(0,-1));return}i&&!e.ctrl&&!e.meta&&g(t=>t+i);return}if(e.escape){f();return}if(e.upArrow){C(t=>Math.max(0,t-1));return}if(e.downArrow){C(t=>Math.min(R-1,t+1));return}if(e.return){if(a===0){p||l(""),f();return}if(a===s.length+1){B(d,{recursive:!0}),I(!0),g("");return}let t=s[a-1];t&&!t.isActive&&l(t.path),f();return}}),T?(0,r.jsxs)(u,{flexDirection:"column",borderStyle:"round",borderColor:o.orange,paddingX:2,paddingY:1,children:[(0,r.jsx)(c,{color:o.orange,bold:!0,children:"Chrome Profile \u203A New"}),(0,r.jsxs)(u,{marginTop:1,children:[(0,r.jsx)(c,{color:o.secondary,children:"Name: "}),(0,r.jsx)(c,{children:S}),(0,r.jsx)(c,{color:o.dim,children:"\u2588"})]}),(0,r.jsx)(b,{bindings:[{keys:"\u21B5",label:"create"}],escBackLabel:"back"})]}):(0,r.jsxs)(u,{flexDirection:"column",borderStyle:"round",borderColor:o.orange,paddingX:2,paddingY:1,children:[(0,r.jsx)(c,{color:o.orange,bold:!0,children:"Chrome Profile"}),(0,r.jsxs)(u,{flexDirection:"column",marginTop:1,children:[(0,r.jsxs)(c,{color:p?o.green:a===0?o.orange:o.dim,children:[a===0?"\u276F ":" ","Use temporary (no profile)",p?" \u25CF active":""]}),s.map((i,e)=>{let m=e+1===a,w=m?"\u276F ":" ",y=i.isActive?o.green:m?o.orange:void 0;return(0,r.jsxs)(c,{color:y,children:[w,i.label,i.isActive?" \u25CF active":""]},i.name)}),(0,r.jsxs)(c,{color:a===s.length+1?o.orange:o.dim,children:[a===s.length+1?"\u276F ":" ","+ Create new"]})]}),(0,r.jsx)(b,{bindings:[{keys:"\u2191\u2193",label:"navigate"},{keys:"\u21B5",label:"select"}],escBackLabel:"back"})]})}export{O as a,E as b,H as c};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { createRequire } from 'module'; const require = createRequire(import.meta.url);
|
|
2
|
+
import{a as t}from"./chunk-OIPVMEM7.js";async function l(e){let o=e.credentials.expires_at,i=e.thresholdSeconds??300;if(o-Date.now()/1e3>=i)return null;let r=e.creds.loadClient(e.profile,e.env);if(!r)return null;let n=await new t(e.env).refreshToken(e.credentials.refresh_token,r.client_id),s=Math.floor(Date.now()/1e3)+n.expires_in;return e.creds.saveCredentials(e.profile,e.env,{access_token:n.access_token,refresh_token:n.refresh_token,expires_at:s,scope:n.scope}),{accessToken:n.access_token,refreshToken:n.refresh_token,expiresAt:s,scope:n.scope}}export{l as a};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { createRequire } from 'module'; const require = createRequire(import.meta.url);
|
|
2
|
+
import{d as s,h as l}from"./chunk-IBDWHXNE.js";import{readFileSync as d,writeFileSync as i,mkdirSync as o,existsSync as p}from"fs";import{dirname as a}from"path";var n={window_size:{width:1920,height:1080},chrome_profile_path:"",default_url:l,model:"v16-alpha",project_id:null,project_name:null,folder_id:null,folder_name:null,mode:"testing",code_export:{enabled:!0,language:"python",skip_validation:!0},generate:{scenario_limit:2,per_scenario_limit:3,memory_enabled:!1},last_seen_version:""},c=class{constructor(t=s){this.path=t}exists(){return p(this.path)}load(){try{let t=d(this.path,"utf-8"),e=JSON.parse(t);return{...n,...e,code_export:{...n.code_export,...e.code_export??{}},generate:{...n.generate,...e.generate??{}}}}catch{return{...n,code_export:{...n.code_export},generate:{...n.generate}}}}set(t,e){try{let r=this.load();r[t]=e,o(a(this.path),{recursive:!0}),i(this.path,JSON.stringify(r,null,2)+`
|
|
3
|
+
`)}catch(r){let g=r instanceof Error?r.message:String(r);process.stderr.write(`[config] Failed to save config: ${g}
|
|
4
|
+
`)}}save(t){try{let r={...this.load(),...t};o(a(this.path),{recursive:!0}),i(this.path,JSON.stringify(r,null,2)+`
|
|
5
|
+
`)}catch(e){let r=e instanceof Error?e.message:String(e);process.stderr.write(`[config] Failed to save config: ${r}
|
|
6
|
+
`)}}writeRaw(t){try{o(a(this.path),{recursive:!0}),i(this.path,JSON.stringify(t,null,2)+`
|
|
7
|
+
`)}catch(e){let r=e instanceof Error?e.message:String(e);process.stderr.write(`[config] Failed to save config: ${r}
|
|
8
|
+
`)}}};export{c as a};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { createRequire } from 'module'; const require = createRequire(import.meta.url);
|
|
2
|
+
import{a as Ae}from"./chunk-YSSBAIJI.js";import{a as _e}from"./chunk-FPFOW6BS.js";import{a as Se}from"./chunk-YCCUBQY4.js";import{a as ye}from"./chunk-VE3SUJMA.js";import{a as Ce}from"./chunk-OIPVMEM7.js";import{a as Ee}from"./chunk-LAR7I5SR.js";import{a as oe}from"./chunk-JGXJDTMO.js";import{c as ve,t as f}from"./chunk-IBDWHXNE.js";import{a as Z}from"./chunk-HCBYKLMW.js";import{a as T,b as d,h as Te,i as ce,k as we}from"./chunk-C44QQJR4.js";import{a as ue}from"./chunk-6YGTRKDT.js";import{e as M}from"./chunk-UR6MHSHU.js";var Re=M(ue(),1);import{readFileSync as Me,writeFileSync as Oe,mkdirSync as ke}from"fs";import{dirname as Ke,join as Ue}from"path";var Ne=Ue(ve,"command-history.json"),Fe=200,ge=class{entries;filePath;max;constructor(t=Ne,n=Fe){this.filePath=t,this.max=n,this.entries=this._load()}push(t){this.entries.length>0&&this.entries[this.entries.length-1]===t||(this.entries.push(t),this.entries.length>this.max&&(this.entries=this.entries.slice(this.entries.length-this.max)),this._save())}getAll(){return[...this.entries]}search(t){let n=t.toLowerCase(),o=[];for(let s=this.entries.length-1;s>=0;s--)this.entries[s].toLowerCase().includes(n)&&o.push(this.entries[s]);return o}_load(){try{let t=Me(this.filePath,"utf-8"),n=JSON.parse(t);return Array.isArray(n)?n:[]}catch{return[]}}_save(){try{ke(Ke(this.filePath),{recursive:!0}),Oe(this.filePath,JSON.stringify(this.entries)+`
|
|
3
|
+
`)}catch{}}};function nt(i){let t=(0,Re.useRef)(null);return t.current||(t.current=new ge(i)),t.current}var K=M(ue(),1);var pe=M(ue(),1);var H=M(Z(),1);function Pe({history:i,onSelect:t,onClose:n}){let[o,s]=(0,pe.useState)(""),[l,x]=(0,pe.useState)(0),S=o?i.search(o).slice(0,8):[];return ce((w,g)=>{if(g.escape){n();return}if(g.return){S.length>0&&S[l]?t(S[l]):n();return}if(g.upArrow){x(A=>Math.max(0,A-1));return}if(g.downArrow){x(A=>Math.min(S.length-1,A+1));return}if(g.backspace||g.delete){s(A=>A.slice(0,-1)),x(0);return}w&&!g.ctrl&&!g.meta&&(s(A=>A+w),x(0))}),(0,H.jsxs)(T,{flexDirection:"column",marginLeft:2,borderStyle:"single",paddingX:1,children:[(0,H.jsx)(d,{color:f.muted,bold:!0,children:"reverse search"}),(0,H.jsxs)(T,{gap:1,children:[(0,H.jsx)(d,{color:f.dim,children:"search:"}),(0,H.jsx)(d,{children:o}),(0,H.jsx)(d,{color:f.orange,children:"\u2588"})]}),S.length>0&&(0,H.jsx)(d,{children:" "}),S.map((w,g)=>(0,H.jsx)(T,{marginLeft:2,children:(0,H.jsxs)(d,{color:g===l?f.orange:f.dim,bold:g===l,children:[g===l?"\u25B8 ":" ",w]})},`${g}-${w}`))]})}var ee=M(Z(),1);function Ie({commands:i,selectedIndex:t}){return i.length===0?null:(0,ee.jsx)(T,{flexDirection:"column",marginBottom:0,children:i.map((n,o)=>{let s=o===t;return(0,ee.jsxs)(T,{children:[(0,ee.jsx)(d,{color:s?f.orange:f.dim,children:s?"\u276F ":" "}),(0,ee.jsxs)(d,{color:s?f.orange:void 0,bold:s,children:["/",n.name]}),n.args&&(0,ee.jsxs)(d,{color:f.dim,children:[" ",n.args]}),(0,ee.jsxs)(d,{color:f.dim,children:[" ",n.description]})]},n.name)})})}var de=M(ue(),1);var We=27,He=127,Ge=11;function $e(i){return i>=64&&i<=126}function Ve(i,t){i===Ge&&t({killToEnd:!0,ctrl:!0,raw:String.fromCharCode(i)})}function Ye(i,t){i===He&&t({backspace:!0,meta:!0,raw:"\x1B\x7F"})}function ze(i,t){let n=i.map(s=>String.fromCharCode(s)).join(""),o=/^\[1;([0-9]+)([A-D])$/.exec(n);if(o){let s=parseInt(o[1],10),l=o[2],x={raw:"\x1B"+n};if(s===2)x.shift=!0;else if(s===3)x.meta=!0;else if(s===5)x.ctrl=!0;else return;l==="A"?x.arrowUp=!0:l==="B"?x.arrowDown=!0:l==="C"?x.arrowRight=!0:l==="D"&&(x.arrowLeft=!0),t(x);return}if(n==="[H"||n==="[1~"||n==="[7~"){t({home:!0,raw:"\x1B"+n});return}if(n==="[F"||n==="[4~"||n==="[8~"){t({end:!0,raw:"\x1B"+n});return}if(n==="[3;5~"){t({delete:!0,ctrl:!0,raw:"\x1B"+n});return}if(n==="[3;3~"){t({delete:!0,meta:!0,raw:"\x1B"+n});return}}function Xe(i,t){i===72?t({home:!0,raw:"\x1BO"+String.fromCharCode(i)}):i===70&&t({end:!0,raw:"\x1BO"+String.fromCharCode(i)})}function je(){let i="IDLE",t=[];function n(){i="IDLE",t=[]}return{feed(o,s){for(let l of o)i==="IDLE"?l===We?(i="ESC",t=[]):Ve(l,s):i==="ESC"?l===91?(i="CSI",t=[]):l===79?(i="SS3",t=[]):(Ye(l,s),n()):i==="CSI"?(t.push(l),$e(l)&&(ze([91,...t],s),n())):i==="SS3"&&(Xe(l,s),n())},flushIdle(o){i==="ESC"&&t.length===0&&o({raw:"\x1B"}),n()}}}function Be(i,t={}){let n=(0,de.useRef)(i);n.current=i;let{stdin:o}=Te();(0,de.useEffect)(()=>{if(t.isActive===!1||!o)return;let s=je(),l=null,x=S=>{l&&(clearTimeout(l),l=null);let w=Buffer.isBuffer(S)?S:Buffer.from(S,"binary");s.feed(w,g=>n.current(g)),l=setTimeout(()=>{s.flushIdle(g=>n.current(g)),l=null},50)};return o.on("data",x),()=>{o.removeListener("data",x),l&&clearTimeout(l)}},[t.isActive,o])}var E=M(Z(),1),xe=10;function qe(i){return i.replace(/\x1b?\[200~/g,"").replace(/\x1b?\[201~/g,"").replace(/\r\n/g,`
|
|
4
|
+
`).replace(/\r/g,`
|
|
5
|
+
`).replace(/[\x00-\x08\x0b-\x1f\x7f]/g,"")}function Je(i,t){let n=[],o=0;for(;o<=i.length;){let s=o;for(;s<i.length&&i[s]!==`
|
|
6
|
+
`;)s++;if(o===s)n.push({start:o,end:o});else{let l=o;for(;l<s;){let x=Math.min(l+t,s);n.push({start:l,end:x}),l=x}}if(s>=i.length)break;o=s+1}return n}function Qe(i,t,n){if(i.length===0)return 0;if(t>=n.length)return i.length-1;if(n[t]===`
|
|
7
|
+
`){for(let o=i.length-1;o>=0;o--)if(i[o].end===t)return o;return i.length-1}for(let o=0;o<i.length;o++){let s=i[o];if(s.start<=t&&t<s.end)return o}return i.length-1}function Le(i,t,n,o){let s=Je(i,n);if(s.length===0)return null;let l=Qe(s,t,i),x=l+o;if(x<0||x>=s.length)return null;let S=t-s[l].start,w=s[x],g=w.end-w.start;return w.start+Math.min(S,g)}function vt({onSubmit:i,onEscape:t,history:n,placeholder:o="Type an objective or /command...",commands:s,clearSeq:l,submitVerb:x,footerBindings:S,inert:w=!1,clearOnSubmit:g=!0,noHistory:A=!1,accent:G=f.orange}){let[c,p]=(0,K.useState)([]),[u,b]=(0,K.useState)(0),[R,C]=(0,K.useState)("none"),[U,B]=(0,K.useState)(-1),V=(0,K.useRef)(""),[X,Y]=(0,K.useState)(!0),{stdout:he}=we(),j=he?.columns??80,[D,N]=(0,K.useState)(0),O=(0,K.useRef)(!1);(0,K.useEffect)(()=>{if(l!==void 0){if(!O.current){O.current=!0;return}p([]),b(0),B(-1),V.current="",Y(!0),C("none"),N(0)}},[l]);let y=c.join(""),q=(()=>{if(R!=="none"||c.length===0)return"";if(y.startsWith("/")&&s&&y.length>=2){let e=y.slice(1).toLowerCase(),r=s.find(h=>h.name.startsWith(e)&&h.name!==e);return r?`/${r.name}`.slice(y.length):""}if(y.startsWith("/")||A)return"";let a=n.getAll();for(let e=a.length-1;e>=0;e--)if(a[e].startsWith(y)&&a[e]!==y)return a[e].slice(y.length);return""})(),F=(()=>{if(!s||!y.startsWith("/"))return[];let a=y.length>=2?y.slice(1).toLowerCase():"";return a&&s.some(e=>e.name===a)?[]:s.filter(e=>!a||e.name.startsWith(a))})(),te=F.length>0&&y.startsWith("/");if(ce((a,e)=>{if(X&&a&&Y(!1),e.return){if(te&&F[D]){let r=`/${F[D].name}`;A||n.push(r),i(r),p([]),b(0),C("none"),B(-1),V.current="",Y(!0),N(0);return}y.trim()&&(A||n.push(y.trim()),i(y.trim()),g&&(p([]),b(0),C("none"),B(-1),V.current="",Y(!0),N(0)));return}if(e.escape){R!=="none"?C("none"):c.length>0?(p([]),b(0),B(-1),V.current=""):t?.();return}if(e.tab&&!e.shift){if(te&&F[D]){let r=`/${F[D].name}`;p([...r]),b(r.length),N(0);return}if(q){let r=y+q;p([...r]),b(r.length);return}return}if(e.ctrl&&a==="r"){if(A)return;C("search");return}if(e.ctrl&&a==="a"){b(0);return}if(e.ctrl&&a==="e"){b(c.length);return}if(e.ctrl&&a==="w"){if(u===0)return;let r=u-1;for(;r>0&&c[r]===" ";)r--;for(;r>0&&c[r-1]!==" ";)r--;let h=[...c.slice(0,r),...c.slice(u)];p(h),b(r);return}if(e.ctrl&&a==="u"){p([]),b(0),B(-1),C("none");return}if(e.meta&&a==="b"){let r=u-1;for(;r>0&&c[r]===" ";)r--;for(;r>0&&c[r-1]!==" ";)r--;b(Math.max(0,r));return}if(e.meta&&a==="f"){let r=u;for(;r<c.length&&c[r]!==" ";)r++;for(;r<c.length&&c[r]===" ";)r++;b(r);return}if(e.leftArrow){if(e.ctrl||e.shift)return;b(r=>Math.max(0,r-1));return}if(e.rightArrow){if(e.ctrl||e.shift)return;if(u>=c.length&&q){let r=y+q;p([...r]),b(r.length)}else b(r=>Math.min(c.length,r+1));return}if(e.upArrow){if(e.shift)return;if(te){N(r=>Math.max(0,r-1));return}if(R==="none"){let r=Math.max(1,j-2),h=Le(c,u,r,-1);if(h!==null){b(h);return}if(A)return;let v=n.getAll();if(v.length===0)return;if(U===-1){V.current=y,B(v.length-1);let _=v[v.length-1];p([..._]),b(_.length)}else if(U>0){let _=U-1;B(_);let k=v[_];p([...k]),b(k.length)}}return}if(e.downArrow){if(e.shift)return;if(te){N(r=>Math.min(F.length-1,r+1));return}if(R==="none"){let r=Math.max(1,j-2),h=Le(c,u,r,1);if(h!==null){b(h);return}if(A)return;let v=n.getAll();if(U===-1)return;if(U<v.length-1){let _=U+1;B(_);let k=v[_];p([...k]),b(k.length)}else{B(-1);let _=V.current;p([..._]),b(_.length)}}return}if(e.backspace||e.delete){if(e.meta||e.ctrl)return;if(u>0){let r=[...c.slice(0,u-1),...c.slice(u)];p(r),b(u-1),B(-1),N(0)}return}if(a&&!e.ctrl&&!e.meta){let r=qe(a);if(!r)return;let h=[...c.slice(0,u),...r,...c.slice(u)];p(h),b(u+r.length),B(-1),N(0)}},{isActive:!w&&R!=="search"}),Be(a=>{if(a.home){b(0);return}if(a.end){b(c.length);return}if(a.killToEnd){p(c.slice(0,u));return}if(a.arrowLeft&&(a.ctrl||a.meta)){let e=u-1;for(;e>0&&c[e]===" ";)e--;for(;e>0&&c[e-1]!==" ";)e--;b(Math.max(0,e));return}if(a.arrowRight&&(a.ctrl||a.meta)){let e=u;for(;e<c.length&&c[e]!==" ";)e++;for(;e<c.length&&c[e]===" ";)e++;b(e);return}if(a.backspace&&a.meta){if(u===0)return;let e=u-1;for(;e>0&&c[e]===" ";)e--;for(;e>0&&c[e-1]!==" ";)e--;let r=[...c.slice(0,e),...c.slice(u)];p(r),b(e);return}if(a.delete&&(a.ctrl||a.meta)){let e=u;for(;e<c.length&&c[e]===" ";)e++;for(;e<c.length&&c[e]!==" ";)e++;p([...c.slice(0,u),...c.slice(e)]);return}},{isActive:!w&&R!=="search"}),w)return(0,E.jsxs)(T,{flexDirection:"column",children:[(0,E.jsx)(d,{color:f.muted,children:"\u2500".repeat(j)}),(0,E.jsxs)(T,{children:[(0,E.jsx)(d,{color:f.muted,children:"\u276F "}),(0,E.jsx)(d,{color:f.dim,children:o})]}),(0,E.jsx)(oe,{bindings:S??[{keys:"ctrl+c",label:"cancel"},{keys:"/cancel",label:"stop turn"},{keys:"ctrl+t",label:"thinking"}],suppressEscBack:!0})]});let me=a=>{p([...a]),b(a.length),C("none")},se=()=>{C("none")},ae=(()=>{if(X&&c.length===0)return null;let a=u>=c.length,e=c.slice(0,u).join(""),r,h;a?(r=" ",h=""):c[u]===`
|
|
8
|
+
`?(r=" ",h=c.slice(u).join("")):(r=c[u],h=c.slice(u+1).join(""));let v=e+r+h+q,_=e.length,k=_+1,re=k+h.length,fe=Math.max(1,j-2),P=[],z=0;for(;z<=v.length;){let L=v.indexOf(`
|
|
9
|
+
`,z);if(L===-1&&(L=v.length),z===L)P.push({type:"content",start:z,end:z});else{let W=z;for(;W<L;){let J=Math.min(W+fe,L);P.push({type:"content",start:W,end:J}),W=J}}if(L>=v.length)break;z=L+1}let $=Math.max(0,P.findIndex(L=>L.start<=_&&_<=L.end)),ie;if(P.length<=xe)ie=P;else{let W=xe-1-4;if($<4||$>=P.length-W)ie=[...P.slice(0,4),{type:"ellipsis",hidden:P.length-4-W},...P.slice(P.length-W)];else{let J=xe-2,be=Math.floor(J/2),Q=$-be,le=$+(J-be)-1;Q<1&&(le+=1-Q,Q=1),le>P.length-2&&(Q-=le-(P.length-2),le=P.length-2),Q=Math.max(1,Q),ie=[{type:"ellipsis",hidden:Q},...P.slice(Q,le+1),{type:"ellipsis",hidden:P.length-le-1}]}}return{full:v,b:_,c:k,a:re,rows:ie}})();return(0,E.jsxs)(T,{flexDirection:"column",children:[R==="search"&&(0,E.jsx)(Pe,{history:n,onSelect:me,onClose:se}),te&&(0,E.jsx)(Ie,{commands:F,selectedIndex:D}),(0,E.jsx)(d,{color:f.muted,children:"\u2500".repeat(j)}),ae===null?(0,E.jsxs)(T,{children:[(0,E.jsx)(d,{color:G,children:"\u276F "}),(0,E.jsx)(d,{inverse:!0,children:" "}),(0,E.jsx)(d,{color:f.dim,children:o})]}):(()=>{let a=ae.rows.findIndex(e=>e.type==="content");return(0,E.jsx)(T,{flexDirection:"column",children:ae.rows.map((e,r)=>{if(e.type==="ellipsis")return(0,E.jsx)(T,{children:(0,E.jsxs)(d,{color:f.dim,children:[" \u22EF ","(",e.hidden," more line",e.hidden===1?"":"s",")"]})},r);let{full:h,b:v,c:_,a:k}=ae,re=e.start,ne=e.end,fe=r===a,P=fe?"\u276F ":" ",z=fe?G:f.muted,$=[(0,E.jsx)(d,{color:z,children:P},"p")];re<Math.min(v,ne)&&$.push((0,E.jsx)(d,{children:h.slice(re,Math.min(v,ne))},"b"));let ie=Math.max(v,re),L=Math.min(_,ne);ie<L&&$.push((0,E.jsx)(d,{color:G,inverse:!0,children:h.slice(ie,L)},"c"));let W=Math.max(_,re),J=Math.min(k,ne);return W<J&&$.push((0,E.jsx)(d,{children:h.slice(W,J)},"a")),ne>k&&$.push((0,E.jsx)(d,{color:f.dim,children:h.slice(Math.max(k,re),ne)},"g")),(0,E.jsx)(T,{children:$},r)})})})(),(0,E.jsx)(oe,{bindings:S??[{keys:"\u2191\u2193",label:"history"},{keys:"\u21B5",label:x??"submit"},{keys:"tab",label:"complete"},{keys:"ctrl+r",label:"search"}],escBackLabel:"clear"})]})}var I=M(ue(),1);var m=M(Z(),1);function Ze(i){let t=[{id:"method",label:"Auth method",options:[{label:"Basic Auth",value:"basic"},{label:"OAuth (browser)",value:"oauth"}]}];return i&&t.push({id:"env",label:"Environment",options:[{label:"prod",value:"prod"},{label:"stage",value:"stage"}]}),t.push({id:"profile",label:"Profile"}),t.push({id:"credentials",label:"Credentials"}),t}function Rt({devMode:i,profiles:t,onBasicLogin:n,onOAuthLogin:o,onComplete:s,onCancel:l}){let x=Ze(i),[S,w]=(0,I.useState)(0),[g,A]=(0,I.useState)(0),[G,c]=(0,I.useState)({}),[p,u]=(0,I.useState)("select"),[b,R]=(0,I.useState)(""),[C,U]=(0,I.useState)("username"),[B,V]=(0,I.useState)(""),[X,Y]=(0,I.useState)(null),[he,j]=(0,I.useState)(null),D=x[S],N=G.method??"basic",O=G.env??"prod",y=(0,I.useCallback)(()=>{let e=t.filter(r=>r.env===O).map(r=>({label:`${r.profile} [${r.env}]`,value:r.profile}));return e.push({label:"+ Create new",value:"__new__"}),e},[t,O]),q=(0,I.useCallback)(()=>{S===0?l():(w(a=>a-1),A(0),u("select"),R(""),Y(null))},[S,l]),F=(0,I.useCallback)(a=>{N==="basic"?(u("text-input"),U("username"),R("")):(u("waiting"),o(a,O).then(()=>{j(`Logged in via OAuth as ${a} [${O}]`),u("done")}).catch(e=>{Y(e.message),u("error")}))},[N,O,o]),te=(0,I.useCallback)(a=>{let e=a.trim();if(e){if(C==="profileName"){let r=e;c(h=>({...h,profile:r})),F(r);return}if(C==="username"){V(e),R(""),U("accessKey"),u("text-input-masked");return}if(C==="accessKey"){let r=G.profile??"default";u("waiting"),(async()=>{try{await n(r,O,B,e),j(`Logged in as ${r} [${O}] via basic auth`),u("done")}catch{Y("Credentials not valid. Please use valid credentials."),V(""),R(""),U("username"),u("text-input")}})()}}},[C,G.profile,O,n,B,F]),me=(0,I.useCallback)(a=>{R(a),X&&Y(null)},[X]);ce((a,e)=>{if(p==="done"){let h=G.profile??"default";s(h,O);return}if(p==="error"){l();return}if(p==="waiting"){e.escape&&l();return}if(p==="text-input"||p==="text-input-masked")return;if(e.escape){q();return}let r=D?.id==="profile"?y():D?.options??[];if(e.upArrow){A(h=>Math.max(0,h-1));return}if(e.downArrow){A(h=>Math.min(r.length-1,h+1));return}if(e.return&&r[g]){let h=r[g];if(D.id==="profile"){if(h.value==="__new__"){u("text-input"),U("profileName"),R("");return}c(v=>({...v,profile:h.value})),w(v=>v+1),A(0),F(h.value);return}c(v=>({...v,[D.id]:h.value})),w(v=>v+1),A(0)}});let se="Login";if(p==="done")return(0,m.jsxs)(T,{flexDirection:"column",borderStyle:"round",borderColor:f.green,paddingX:2,paddingY:1,children:[(0,m.jsxs)(d,{color:f.green,bold:!0,children:["\u2713 ",he]}),(0,m.jsx)(T,{marginTop:1,children:(0,m.jsx)(d,{color:f.dim,children:"press any key"})})]});if(p==="error")return(0,m.jsxs)(T,{flexDirection:"column",borderStyle:"round",borderColor:f.red,paddingX:2,paddingY:1,children:[(0,m.jsx)(d,{color:f.red,bold:!0,children:"Login failed"}),(0,m.jsx)(T,{marginTop:1,children:(0,m.jsx)(d,{color:f.red,children:X})}),(0,m.jsx)(T,{marginTop:1,children:(0,m.jsx)(d,{color:f.dim,children:"press any key"})})]});if(p==="waiting")return(0,m.jsxs)(T,{flexDirection:"column",borderStyle:"round",borderColor:f.orange,paddingX:2,paddingY:1,children:[(0,m.jsxs)(d,{color:f.orange,bold:!0,children:[se," \u203A OAuth"]}),(0,m.jsx)(T,{marginTop:1,children:(0,m.jsx)(d,{color:f.secondary,children:"Opening browser for login..."})}),(0,m.jsx)(T,{marginTop:1,children:(0,m.jsx)(d,{color:f.orange,children:"Waiting for callback \u27F3"})}),(0,m.jsx)(oe,{bindings:[],escBackLabel:"cancel"})]});if(p==="text-input"||p==="text-input-masked"){let a=C==="username"?"Username":C==="accessKey"?"Access Key":"Profile name",e=C==="username"||C==="accessKey"?`${se} \u203A Basic Auth`:`${se} \u203A New Profile`;return(0,m.jsxs)(T,{flexDirection:"column",borderStyle:"round",borderColor:f.orange,paddingX:2,paddingY:1,children:[X&&(C==="username"||C==="accessKey")&&(0,m.jsx)(T,{marginBottom:1,children:(0,m.jsxs)(d,{color:f.red,children:["\u2717 ",X]})}),(0,m.jsx)(d,{color:f.orange,bold:!0,children:e}),C==="accessKey"&&(0,m.jsxs)(T,{marginTop:1,children:[(0,m.jsx)(d,{color:f.secondary,children:"Username: "}),(0,m.jsx)(d,{children:B})]}),(0,m.jsxs)(T,{marginTop:1,children:[(0,m.jsxs)(d,{color:f.secondary,children:[a,": "]}),(0,m.jsx)(Se,{value:b,onChange:me,onSubmit:te,onCancel:q,masked:p==="text-input-masked"})]}),(0,m.jsx)(oe,{bindings:[{keys:"\u21B5",label:"confirm"}],escBackLabel:"back"})]})}let ae=D?.id==="profile"?y():D?.options??[];return(0,m.jsxs)(T,{flexDirection:"column",borderStyle:"round",borderColor:f.orange,paddingX:2,paddingY:1,children:[(0,m.jsx)(d,{color:f.orange,bold:!0,children:se}),(0,m.jsx)(T,{marginTop:1,children:(0,m.jsxs)(d,{color:f.secondary,children:[D?.label,":"]})}),(0,m.jsx)(T,{flexDirection:"column",marginTop:1,children:ae.map((a,e)=>{let r=e===g,h=r?"\u276F ":" ",v=a.value==="__new__"?f.green:r?f.orange:void 0;return(0,m.jsxs)(d,{color:v,children:[h,a.label]},a.value)})}),(0,m.jsx)(oe,{bindings:[{keys:"\u2191\u2193",label:"navigate"},{keys:"\u21B5",label:"select"}],escBackLabel:"back"})]})}async function De(i,t,n,o){let s=i.loadBasicAuth(t,n),l=i.loadCredentials(t,n);if(!s&&!l)return o("info","STARTUP_GATE_NO_CREDS","Profile has no credentials",{profile:t,env:n}),{status:"needs_login",profile:t,env:n};let x=Ee(n),S=async()=>i.loadCredentials(t,n)?.access_token??null,w=new _e(x.controllerBaseUrl,S,s,o);o("info","STARTUP_GATE_VALIDATE","Validating credentials with controller",{profile:t,env:n,method:s?"basic":"oauth"});let g=await w.resolve(!0);if(g)return o("info","STARTUP_GATE_VALID","Credentials validated",{profile:t,env:n,username:g.username,org_id:g.org_id}),{status:"authenticated",result:{profile:t,env:n,credentials:l,basicAuth:s,tmsCreds:g,resolver:w}};if(!s&&l){let A=l.refresh_token,c=i.loadClient(t,n)?.client_id;if(A&&c){o("info","STARTUP_GATE_REFRESH","Attempting token refresh",{profile:t,env:n});try{let u=await new Ce(n).refreshToken(A,c);if(u.access_token){i.saveCredentials(t,n,{...l,...u,expires_at:Date.now()/1e3+(u.expires_in??3600)});let R=await w.resolve(!0);if(R)return o("info","STARTUP_GATE_REFRESH_OK","Token refreshed and validated",{profile:t,env:n,username:R.username}),{status:"authenticated",result:{profile:t,env:n,credentials:{...l,...u},basicAuth:null,tmsCreds:R,resolver:w}}}o("warn","STARTUP_GATE_REFRESH_INVALID","Refreshed token still invalid",{profile:t,env:n})}catch(p){o("warn","STARTUP_GATE_REFRESH_FAILED","Token refresh failed",{profile:t,env:n,error:p instanceof Error?p.message:String(p)})}}else o("info","STARTUP_GATE_NO_REFRESH","No refresh_token or client_id \u2014 login required",{profile:t,env:n})}return o("info","STARTUP_GATE_INVALID","Credentials invalid \u2014 login required",{profile:t,env:n}),{status:"needs_login",profile:t,env:n}}async function Ot(i,t,n=new Ae){let o=i.listProfiles();if(t("info","STARTUP_GATE_START","Auth startup gate",{profile_count:o.length}),o.length===0)return t("info","STARTUP_GATE_NONE","No profiles found \u2014 login required"),{status:"needs_login"};if(o.length>1){let x=i.getActiveProfile(),S=i.getDefaultEnv();if(x&&o.some(g=>g.profile===x&&g.env===S)){t("info","STARTUP_GATE_TRY_ACTIVE","Multiple profiles \u2014 trying active first",{activeProfile:x,activeEnv:S});let g=await De(i,x,S,t);if(g.status==="authenticated")return g;t("info","STARTUP_GATE_ACTIVE_FAILED","Active profile invalid \u2014 showing picker",{activeProfile:x,activeEnv:S})}return t("info","STARTUP_GATE_MULTI","Multiple profiles \u2014 picker required",{profiles:o.map(w=>`${w.profile}/${w.env}`)}),{status:"needs_pick",profiles:o}}let{profile:s,env:l}=o[0];return i.setActiveProfile(s),i.setDefaultEnv(l),ye(i,n,s,l),De(i,s,l,t)}export{nt as a,vt as b,Rt as c,De as d,Ot as e};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { createRequire } from 'module'; const require = createRequire(import.meta.url);
|
|
2
|
+
import{a as yr,b as xo}from"./chunk-3MSXQU2C.js";import{a as gi}from"./chunk-FGC74Z76.js";import{a as oi,b as Br,c as On,d as ii,e as $n,f as si,h as ai,i as ci,j as li,k as ui,l as di,m as rt,n as mi,o as fi,p as pi}from"./chunk-45VTQLJS.js";import{a as wo,b as Ro,d as Po,e as Do,f as Lo,g as zo,h as Cr,i as Ir,k as Xo,l as Ko,m as Yo,n as Jo,o as Er,p as Qo,q as Zo,r as ei,t as nt,u as ni}from"./chunk-LEXQLAWB.js";import{a as ti}from"./chunk-EEF6OT52.js";import{a as No,b as Uo,l as ri}from"./chunk-RHUD7MK4.js";import{a as hi,b as _r}from"./chunk-RJNGCQCL.js";import{a as Go}from"./chunk-HN7DVSVI.js";import{b as Fo}from"./chunk-AH4AXJML.js";import{a as vo,b as Tt,c as Ln,d as Vo,e as Oo}from"./chunk-Z7AXAKPX.js";import{c as jn}from"./chunk-AGS57DSG.js";import{a as Nt}from"./chunk-YSSBAIJI.js";import{a as Ao}from"./chunk-FPFOW6BS.js";import{a as yo,b as To,c as So,d as jo,e as Mo,f as $o,h as qo}from"./chunk-JJERCR2W.js";import{a as Mn,b as Ho,c as kr}from"./chunk-G6AXOEED.js";import{a as Tr}from"./chunk-7NDFOI6Z.js";import{c as Wo}from"./chunk-V3FSESZ4.js";import{a as Vn}from"./chunk-DAVPOA2L.js";import{b as $t}from"./chunk-KJEJ7VW5.js";import{b as Ft}from"./chunk-P7ZUISQG.js";import{a as Co,d as tt,e as an,f as St,g as Ut}from"./chunk-LOIRZFV3.js";import{g as Io}from"./chunk-TCLKNUAL.js";import{a as sn}from"./chunk-LPUQ4HWQ.js";import{a as Ge,b as Xe,c as ko}from"./chunk-VE3SUJMA.js";import{a as Bo}from"./chunk-YAVIOVVP.js";import{a as _o}from"./chunk-J2KTLZAW.js";import{a as Dn}from"./chunk-T46Z27UL.js";import{a as Eo}from"./chunk-OIPVMEM7.js";import{a as Ve}from"./chunk-LAR7I5SR.js";import{a as Sr}from"./chunk-UYHNJUPY.js";import{a as mt}from"./chunk-HUOC7DUT.js";import{b as bo}from"./chunk-C6S4IEBC.js";import{b as wr}from"./chunk-4QO6JYHX.js";import{c as Rr}from"./chunk-VKG45YIL.js";import{a as Ot}from"./chunk-JGXJDTMO.js";import{a as rn,c as Me,h as on,t as r}from"./chunk-IBDWHXNE.js";import{a as L}from"./chunk-HCBYKLMW.js";import{a as f,b as t,i as Re,j as go,k as ho}from"./chunk-C44QQJR4.js";import{a as he}from"./chunk-6YGTRKDT.js";import{e as C}from"./chunk-UR6MHSHU.js";var T=C(he(),1);var xi=C(he(),1);var Gt=C(L(),1);function vi({path:e}){return e.length===0?null:(0,Gt.jsx)(f,{children:e.map((n,o)=>(0,Gt.jsxs)(xi.default.Fragment,{children:[o>0&&(0,Gt.jsx)(t,{color:r.muted,children:" \u203A "}),(0,Gt.jsx)(t,{color:r.dim,children:n})]},o))})}var G=C(L(),1);function bi({profile:e,environment:n,tokenValid:o,runCount:i,sessionId:p,viewMode:d,breadcrumb:x,chatMode:h,tcgRequestId:v,tcgStreamStatus:w}){let{stdout:j}=ho(),R=j?.columns??80,B=h??"run",c=n==="stage",u=n==="prod",D=B==="generate"?r.generateAccent:r.orange,F=w==="completed"?r.green:w==="failed"?r.red:r.generateAccent;return(0,G.jsxs)(f,{flexDirection:"column",children:[(0,G.jsx)(t,{color:r.muted,children:"\u2500".repeat(R)}),x&&x.length>0&&(0,G.jsx)(f,{paddingX:1,children:(0,G.jsx)(vi,{path:x})}),(0,G.jsxs)(f,{paddingX:1,gap:1,children:[(0,G.jsx)(t,{color:r.dim,children:"Mode:"}),(0,G.jsx)(t,{color:D,bold:!0,children:B==="generate"?"Generate":"Run"}),(0,G.jsx)(t,{color:r.muted,children:"|"}),B==="generate"?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(t,{color:r.dim,children:"req"}),(0,G.jsx)(t,{color:r.dim,children:v??"\u2014"}),w&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(t,{color:r.muted,children:"\xB7"}),(0,G.jsx)(t,{color:F,children:w})]})]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(t,{color:r.dim,children:"Session:"}),(0,G.jsx)(t,{color:r.dim,children:p})]}),(0,G.jsx)(t,{color:r.muted,children:"|"}),(0,G.jsx)(t,{color:o?r.green:r.red,children:"\u25CF"}),(0,G.jsx)(t,{color:r.dim,children:o?"authenticated":"not logged in"}),!u&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(t,{color:r.muted,children:"|"}),c?(0,G.jsx)(t,{color:r.orange,bold:!0,children:"\u26A0 stage"}):(0,G.jsx)(t,{color:r.green,children:n})]})]}),(0,G.jsxs)(f,{paddingX:1,gap:1,children:[(0,G.jsx)(t,{color:r.dim,children:e??"no profile"}),B==="run"&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(t,{color:r.muted,children:"|"}),(0,G.jsxs)(t,{color:r.dim,children:["runs: ",i]})]}),(0,G.jsx)(t,{color:r.muted,children:"|"}),(0,G.jsx)(t,{dimColor:!0,children:xo()})]}),(0,G.jsx)(f,{paddingX:1,children:(0,G.jsx)(t,{dimColor:!0,children:d==="chat"?"ctrl+c cancel/exit":"\u2191\u2193 navigate \u21B5 select esc back"})})]})}var At=C(he(),1);var cn=[[[" "],[" "],[" "],[" "],["\u2584","#af87d7"],["\u2588","#af87d7"],["\u2588","#af87d7"],["\u2588","#af87d7"],[" "],[" "],[" "],[" "],[" "],["\u2588","#af87d7"],["\u2588","#af87d7"],["\u2588","#af87d7"],["\u2584","#af87d7"],[" "],[" "],[" "],[" "]],[[" "],[" "],["\u2584","#875faf"],["\u2584","#af87d7","#875faf"],["\u2588","#af87d7"],["\u2588","#af87d7"],["\u2588","#af87d7"],["\u2588","#af87d7"],["\u2588","#af87d7"],["\u2588","#af87d7"],["\u2588","#af87d7"],["\u2588","#af87d7"],["\u2588","#af87d7"],["\u2588","#af87d7"],["\u2588","#af87d7"],["\u2588","#af87d7"],["\u2588","#af87d7"],["\u2584","#af87d7","#875faf"],["\u2584","#875faf"],[" "],[" "]],[[" "],[" "],["\u2588","#875faf"],["\u2588","#af87d7"],["\u2584","#000000","#af87d7"],["\u2584","#000000","#303030"],["\u2584","#000000","#303030"],["\u2584","#000000","#303030"],["\u2584","#000000","#303030"],["\u2584","#000000","#303030"],["\u2584","#000000","#303030"],["\u2584","#000000","#303030"],["\u2584","#000000","#303030"],["\u2584","#000000","#303030"],["\u2584","#000000","#303030"],["\u2584","#000000","#303030"],["\u2584","#000000","#af87d7"],["\u2588","#af87d7"],["\u2588","#875faf"],[" "],[" "]],[[" "],["\u2588","#875faf"],["\u2588","#875faf"],["\u2588","#af87d7"],["\u2588","#000000"],["\u2584","#585858","#000000"],["\u2588","#000000"],["\u2588","#000000"],["\u2588","#000000"],["\u2588","#000000"],["\u2588","#000000"],["\u2588","#000000"],["\u2588","#000000"],["\u2588","#000000"],["\u2588","#000000"],["\u2588","#000000"],["\u2588","#000000"],["\u2588","#af87d7"],["\u2588","#875faf"],["\u2588","#875faf"],[" "]],[[" "],["\u2588","#875faf"],["\u2588","#875faf"],["\u2588","#af87d7"],["\u2588","#000000"],["\u2588","#585858"],["\u2588","#000000"],["\u2588","#000000"],["\u2588","#000000"],["\u2588","#000000"],["\u2588","#000000"],["\u2588","#000000"],["\u2588","#000000"],["\u2588","#000000"],["\u2588","#000000"],["\u2588","#000000"],["\u2588","#000000"],["\u2588","#af87d7"],["\u2588","#875faf"],["\u2588","#875faf"],[" "]],[[" "],[" "],["\u2588","#875faf"],["\u2588","#af87d7"],["\u2588","#000000"],["\u2584","#000000","#585858"],["\u2588","#000000"],["\u2588","#000000"],["\u2584","#af87d7","#000000"],["\u2584","#af87d7","#000000"],["\u2584","#af87d7","#000000"],["\u2584","#af87d7","#000000"],["\u2584","#af87d7","#000000"],["\u2588","#000000"],["\u2588","#000000"],["\u2588","#000000"],["\u2588","#000000"],["\u2588","#af87d7"],["\u2588","#875faf"],[" "],[" "]],[[" "],[" "],["\u2580","#875faf"],["\u2580","#af87d7"],["\u2580","#af87d7"],["\u2588","#af87d7"],["\u2588","#af87d7"],["\u2588","#af87d7"],["\u2588","#af87d7"],["\u2588","#af87d7"],["\u2588","#af87d7"],["\u2588","#af87d7"],["\u2588","#af87d7"],["\u2588","#af87d7"],["\u2588","#af87d7"],["\u2588","#af87d7"],["\u2580","#af87d7"],["\u2580","#af87d7"],["\u2580","#875faf"],[" "],[" "]],[[" "],[" "],[" "],[" "],[" "],["\u2580","#af87d7"],["\u2580","#af87d7"],["\u2588","#af87d7"],["\u2588","#af87d7"],["\u2588","#af87d7"],["\u2588","#af87d7"],["\u2588","#af87d7"],["\u2588","#af87d7"],["\u2588","#af87d7"],["\u2580","#af87d7"],["\u2580","#af87d7"],[" "],[" "],[" "],[" "],[" "]]];var X=C(L(),1),Fn="#af87d7",Ar="#875faf",yi="#5b3a7a",Xs="#ff9500",Ks="#ea580c";var Pr="#666666",Ys="#555555",_t=[[Fn,"\u2588\u2588\u2588 \u2588\u2588\u2588 \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588 \u2588\u2588\u2588\u2588 \u2588\u2588\u2588 \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588 \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588 \u2588\u2588\u2588 \u2588\u2588\u2588"],[Fn,"\u2588\u2588\u2588 \u2588\u2588\u2588 \u2588\u2588\u2588 \u2588\u2588\u2588 \u2588\u2588\u2588\u2588\u2588 \u2588\u2588\u2588 \u2588\u2588\u2588 \u2588\u2588\u2588 \u2588\u2588\u2588 \u2588\u2588\u2588"],[Fn,"\u2588\u2588\u2588 \u2588\u2588\u2588 \u2588\u2588\u2588 \u2588\u2588\u2588 \u2588\u2588\u2588\u2588\u2588\u2588 \u2588\u2588\u2588 \u2588\u2588\u2588 \u2588\u2588\u2588 \u2588\u2588\u2588 \u2588\u2588\u2588"],[Fn,"\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588 \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588 \u2588\u2588\u2588 \u2588\u2588\u2588 \u2588\u2588\u2588 \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588 \u2588\u2588\u2588 \u2588\u2588\u2588 \u2588\u2588\u2588"],[Ar,"\u2588\u2588\u2588 \u2588\u2588\u2588 \u2588\u2588\u2588 \u2588\u2588\u2588 \u2588\u2588\u2588 \u2588\u2588\u2588\u2588\u2588\u2588 \u2588\u2588\u2588 \u2588\u2588\u2588 \u2588\u2588\u2588 \u2588\u2588\u2588"],[Ar,"\u2588\u2588\u2588 \u2588\u2588\u2588 \u2588\u2588\u2588 \u2588\u2588\u2588 \u2588\u2588\u2588 \u2588\u2588\u2588\u2588\u2588 \u2588\u2588\u2588 \u2588\u2588\u2588 \u2588\u2588\u2588 \u2588\u2588\u2588"],[Ar,"\u2588\u2588\u2588 \u2588\u2588\u2588 \u2588\u2588\u2588 \u2588\u2588\u2588 \u2588\u2588\u2588 \u2588\u2588\u2588\u2588 \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588 \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588 \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588 \u2588\u2588\u2588"]],Dr=_t.map(([,e])=>[...e]);function Ti({visibleRows:e=_t.length}){let n=Math.min(e,_t.length);return(0,X.jsxs)(f,{flexDirection:"column",children:[_t.slice(0,n).map(([o,i],p)=>{let d=Dr[p];return(0,X.jsx)(t,{children:d.map((x,h)=>{if(x==="\u2588")return(0,X.jsx)(t,{color:o,children:"\u2588"},h);let v=h>0&&d[h-1]==="\u2588",w=p>0&&h>0&&Dr[p-1][h-1]==="\u2588";return v||w?(0,X.jsx)(t,{color:yi,children:"\u2592"},h):(0,X.jsx)(t,{children:" "},h)})},p)}),n>=_t.length&&(0,X.jsxs)(t,{children:[" ",Dr[_t.length-1].map((o,i)=>o==="\u2588"?(0,X.jsx)(t,{color:yi,children:"\u2580"},i):(0,X.jsx)(t,{children:" "},i))]})]})}function Js({visibleRows:e=cn.length}){let n=Math.min(e,cn.length);return(0,X.jsx)(f,{flexDirection:"column",children:cn.slice(0,n).map((o,i)=>(0,X.jsx)(t,{children:o.map((p,d)=>{let x=p[0],h=p[1],v=p[2];return h?(0,X.jsx)(t,{color:h,backgroundColor:v,children:x},d):(0,X.jsx)(t,{children:x},d)})},i))})}function Nn({size:e="compact",helmetVisibleRows:n=cn.length,textVisibleRows:o=_t.length,showMeta:i=!1,user:p=null,authenticated:d=!1,version:x=""}){return e==="compact"?(0,X.jsx)(Ti,{}):(0,X.jsxs)(f,{flexDirection:"column",paddingX:1,paddingY:1,children:[(0,X.jsx)(t,{color:Xs,italic:!0,children:" Welcome to"}),(0,X.jsx)(t,{children:" "}),(0,X.jsxs)(f,{gap:2,children:[(0,X.jsx)(Js,{visibleRows:n}),(0,X.jsxs)(f,{flexDirection:"column",children:[(0,X.jsx)(Ti,{visibleRows:o}),(0,X.jsx)(f,{justifyContent:"flex-end",width:73,children:(0,X.jsx)(t,{color:Ks,italic:!0,children:"Command-line interface"})})]})]}),i&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(t,{children:" "}),(0,X.jsxs)(t,{children:[(0,X.jsx)(t,{color:Pr,children:" Browser automation powered by AI. "}),(0,X.jsx)(t,{color:Ys,children:`v${x}`})]}),(0,X.jsx)(t,{children:" "}),(0,X.jsx)(t,{children:(0,X.jsx)(t,{color:Pr,children:" KaneCLI can navigate websites, fill forms, test web UI, and extract"})}),(0,X.jsx)(t,{children:(0,X.jsx)(t,{color:Pr,children:" data \u2014 right from your terminal."})}),(0,X.jsx)(t,{children:" "})]})]})}var Mr=C(L(),1),Lr=8,jr=7;function Si({onComplete:e}){let[n,o]=(0,At.useState)(0),[i,p]=(0,At.useState)(0),[d,x]=(0,At.useState)(!1),[h]=(0,At.useState)(()=>{let v=new Dn,w=v.getActiveProfile(),j=v.getDefaultEnv(),R=w?v.loadCredentials(w,j):null,B=w?v.loadBasicAuth(w,j):null;return{authenticated:!!(R||B),user:B?.username??w??null}});return Tr(()=>{o(v=>Math.min(Lr,v+1))},n<Lr?60:null),Tr(()=>{p(v=>Math.min(jr,v+1))},i<jr?80:null),(0,At.useEffect)(()=>{n>=Lr&&i>=jr&&!d&&(x(!0),e?.())},[n,i,d,e]),(0,Mr.jsx)(f,{flexDirection:"column",children:(0,Mr.jsx)(Nn,{size:"full",helmetVisibleRows:n,textVisibleRows:i,showMeta:d,user:h.user,authenticated:h.authenticated,version:rn})})}var ft=C(L(),1);function wi({entry:e}){return e.type==="input"?(0,ft.jsxs)(f,{children:[(0,ft.jsx)(t,{color:r.orange,children:"\u276F "}),(0,ft.jsx)(t,{children:e.text})]}):e.type==="error"?(0,ft.jsx)(f,{marginLeft:2,children:(0,ft.jsx)(t,{color:r.red,children:e.text})}):(0,ft.jsx)(f,{marginLeft:2,children:(0,ft.jsx)(t,{color:e.type==="info"?r.dim:void 0,children:e.text})})}var ot=C(he(),1);var Ee=C(L(),1);function Qs(e,n){let o=[],p=Math.max(n-4,30);o.push({type:"title",text:e.title});for(let d=0;d<e.sections.length;d++){let x=e.sections[d];d>0&&o.push({type:"divider",text:"\u2500".repeat(p)}),x.label&&o.push({type:"header",text:x.label});let h=x.entries.length>0?Math.max(...x.entries.map(v=>v.key.length)):0;for(let v of x.entries){let w="\xB7".repeat(Math.max(2,h-v.key.length+3)),j=`${v.key} ${w} ${v.value}`;o.push({type:"entry",text:j,color:v.color})}}return o.push({type:"footer",text:"esc back"}),o}function Ri({data:e,width:n=60}){let o=Qs(e,n);return(0,Ee.jsx)(f,{flexDirection:"column",borderStyle:"round",borderColor:r.orange,paddingX:2,paddingY:1,children:o.map((i,p)=>{if(i.type==="title")return(0,Ee.jsx)(t,{color:r.orange,bold:!0,children:i.text},p);if(i.type==="header")return(0,Ee.jsx)(f,{marginTop:1,children:(0,Ee.jsx)(t,{color:r.dim,children:i.text})},p);if(i.type==="divider")return(0,Ee.jsx)(f,{marginTop:1,marginBottom:0,children:(0,Ee.jsx)(t,{color:r.muted,children:i.text})},p);if(i.type==="footer")return(0,Ee.jsx)(f,{marginTop:1,children:(0,Ee.jsx)(t,{color:r.dim,children:i.text})},p);let d=i.text.match(/^(.+?) (·+) (.+)$/);return d?(0,Ee.jsxs)(t,{children:[(0,Ee.jsxs)(t,{color:r.secondary,children:[d[1]," "]}),(0,Ee.jsxs)(t,{color:r.muted,children:[d[2]," "]}),(0,Ee.jsx)(t,{color:i.color,children:d[3]})]},p):(0,Ee.jsx)(t,{color:i.color,children:i.text},p)})})}var be=C(L(),1);function Vr(e,n){let o=[];function i(p,d){for(let x of p)o.push({item:x,depth:d}),x.type==="submenu"&&x.children&&n.length>d&&n[d]===x.id&&i(x.children,d+1)}return i(e,0),o}function Or({items:e,onRunSelected:n,initialExpandedPath:o,onDismiss:i,renderLoginWizard:p,renderProfilesView:d,renderChromeProfilePicker:x,renderProjectPicker:h,renderFolderPicker:v,renderWindowSizePicker:w,onActiveViewChange:j}){let[R,B]=(0,ot.useState)(()=>{let O=o??[],U=Vr(e,O),E=0;if(O.length>0){let M=U.findIndex(Y=>Y.item.id===O[0]);M>=0&&M+1<U.length&&(E=M+1)}return{expandedPath:O,selectedIndex:E,inputValue:"",isEditing:!1,isSelecting:!1,feedback:null,activeView:null,infoData:null}}),c=Vr(e,R.expandedPath),u=c[R.selectedIndex]?.item,D=(0,ot.useRef)(null),F=(0,ot.useCallback)(O=>{B(U=>({...U,feedback:O})),D.current&&clearTimeout(D.current),D.current=setTimeout(()=>{B(U=>({...U,feedback:null})),D.current=null},4e3)},[]);(0,ot.useEffect)(()=>()=>{D.current&&clearTimeout(D.current)},[]),(0,ot.useEffect)(()=>{j?.(R.activeView)},[R.activeView,j]);let V=(0,ot.useCallback)(()=>{B(O=>({...O,activeView:null,infoData:null}))},[]);return Re((O,U)=>{if(R.activeView==="infoView"){U.escape&&V();return}if(!(R.activeView==="loginWizard"||R.activeView==="profilesView"||R.activeView==="chromeProfilePicker"||R.activeView==="projectPicker"||R.activeView==="folderPicker"||R.activeView==="windowSizePicker")){if(R.isEditing){if(U.escape){B(E=>({...E,isEditing:!1,inputValue:""}));return}if(U.return){let E=R.inputValue.trim();if(u?.onValue&&E){let M=u.currentValue;u.onValue(E),F(M?`${u.label}: ${M} \u2192 ${E}`:`${u.label}: ${E}`)}B(M=>({...M,isEditing:!1,inputValue:""}));return}if(U.backspace||U.delete){B(E=>({...E,inputValue:E.inputValue.slice(0,-1)}));return}O&&!U.ctrl&&!U.meta&&B(E=>({...E,inputValue:E.inputValue+O}));return}if(R.isSelecting&&u?.options){let E=u.options;if(U.escape){B(M=>({...M,isSelecting:!1}));return}if(U.upArrow){B(M=>({...M,inputValue:String(Math.max(0,Number(M.inputValue||"0")-1))}));return}if(U.downArrow){B(M=>({...M,inputValue:String(Math.min(E.length-1,Number(M.inputValue||"0")+1))}));return}if(U.return){let M=Number(R.inputValue||"0"),Y=E[M];if(Y&&u.onValue){let K=u.currentValue;u.onValue(Y.value),F(K?`${u.label}: ${K} \u2192 ${Y.label}`:`${u.label}: ${Y.label}`)}B(K=>({...K,isSelecting:!1,inputValue:""}));return}return}if(U.upArrow){B(E=>({...E,selectedIndex:Math.max(0,E.selectedIndex-1)}));return}if(U.downArrow){B(E=>({...E,selectedIndex:Math.min(c.length-1,E.selectedIndex+1)}));return}if(U.escape){if(R.expandedPath.length===0){i?.();return}B(E=>{let M=E.expandedPath.slice(0,-1),Y=Vr(e,M),K=E.expandedPath[E.expandedPath.length-1],we=Y.findIndex(q=>q.item.id===K);return{...E,expandedPath:M,selectedIndex:we>=0?we:0}});return}if(U.return&&u){if(u.id==="run-start"){n();return}if(u.type==="submenu"){let E=c[R.selectedIndex]?.depth??0;B(M=>({...M,expandedPath:[...M.expandedPath.slice(0,E),u.id],selectedIndex:M.selectedIndex+1}));return}if(u.onInfo){let E=u.onInfo();B(M=>({...M,activeView:"infoView",infoData:E}));return}if(u.onLoginWizard){u.onLoginWizard(),B(E=>({...E,activeView:"loginWizard"}));return}if(u.onProfilesView){u.onProfilesView(),B(E=>({...E,activeView:"profilesView"}));return}if(u.onChromeProfilePicker){u.onChromeProfilePicker(),B(E=>({...E,activeView:"chromeProfilePicker"}));return}if(u.onProjectPicker){u.onProjectPicker(),B(E=>({...E,activeView:"projectPicker"}));return}if(u.onFolderPicker){u.onFolderPicker(),B(E=>({...E,activeView:"folderPicker"}));return}if(u.onWindowSizePicker){u.onWindowSizePicker(),B(E=>({...E,activeView:"windowSizePicker"}));return}if(u.type==="action"){u.onAction?.(),u.suppressFeedback||F(`${u.label} done`);return}if(u.type==="select"&&u.options){let E=u.options.findIndex(M=>M.value===u.currentValue);B(M=>({...M,isSelecting:!0,inputValue:String(Math.max(0,E))}));return}if(u.type==="text-input"){B(E=>({...E,isEditing:!0,inputValue:u.currentValue??""}));return}}}}),(0,be.jsx)(f,{flexDirection:"column",paddingX:1,children:R.activeView==="infoView"&&R.infoData?(0,be.jsx)(Ri,{data:R.infoData}):R.activeView==="loginWizard"&&p?p(V):R.activeView==="profilesView"&&d?d(V):R.activeView==="chromeProfilePicker"&&x?x(V):R.activeView==="projectPicker"&&h?h(V):R.activeView==="folderPicker"&&v?v(V):R.activeView==="windowSizePicker"&&w?w(V):(0,be.jsxs)(be.Fragment,{children:[c.map(({item:O,depth:U},E)=>{let M=E===R.selectedIndex,Y=" ".repeat(U),K=M?"\u276F ":" ",we=O.type==="submenu"?R.expandedPath.includes(O.id)?"\u25BC ":"\u25B6 ":" ",q=O.currentValue!=null?` [${O.currentValue}]`:"";if(M&&R.isSelecting&&O.options){let ue=Number(R.inputValue||"0");return(0,be.jsxs)(f,{flexDirection:"column",children:[(0,be.jsxs)(t,{color:r.orange,children:[Y,K,we,O.label]}),O.options.map((se,Ye)=>(0,be.jsxs)(t,{color:Ye===ue?r.orange:void 0,children:[Y," ",Ye===ue?"\u276F ":" ",se.label]},se.value))]},O.id)}return M&&R.isEditing?(0,be.jsxs)(t,{color:r.orange,children:[Y,K,we,O.label,": ",R.inputValue,(0,be.jsx)(t,{color:r.dim,children:"\u2588"})]},O.id):(0,be.jsxs)(t,{color:M?r.orange:void 0,dimColor:!M&&U>0,children:[Y,K,we,O.label,(0,be.jsx)(t,{dimColor:!0,children:q})]},O.id)}),R.feedback&&(0,be.jsx)(f,{marginTop:1,children:(0,be.jsxs)(t,{color:r.green,children:["\u2713 ",R.feedback]})}),(0,be.jsx)(Ot,{bindings:[{keys:"\u2191\u2193",label:"navigate"},{keys:"\u21B5",label:"select"}],escBackLabel:"back"})]})})}var ln=C(he(),1);var ke=C(L(),1),$r=800,Fr=3840,Nr=600,Ur=2160;function ki(e,n){if(!n)return"Enter a value";let o=Number(n);if(!Number.isInteger(o))return"Must be a whole number";if(e==="width"){if(o<$r)return`Min ${$r}`;if(o>Fr)return`Max ${Fr}`}else{if(o<Nr)return`Min ${Nr}`;if(o>Ur)return`Max ${Ur}`}return null}function Gr({currentWidth:e,currentHeight:n,onSelect:o,onCancel:i}){let[p,d]=(0,ln.useState)("width"),[x,h]=(0,ln.useState)(String(e)),[v,w]=(0,ln.useState)(String(n)),[j,R]=(0,ln.useState)(null);Re((c,u)=>{if(u.escape){i();return}if(u.tab||u.rightArrow||u.leftArrow){d(D=>D==="width"?"height":"width"),R(null);return}if(u.return){let D=ki("width",x);if(D){d("width"),R(`Width: ${D}`);return}let F=ki("height",v);if(F){d("height"),R(`Height: ${F}`);return}o(Number(x),Number(v));return}if(u.backspace||u.delete){p==="width"?h(D=>D.slice(0,-1)):w(D=>D.slice(0,-1)),R(null);return}c&&/^\d$/.test(c)&&(p==="width"?h(D=>D+c):w(D=>D+c),R(null))});let B=(c,u,D)=>{let F=p===D,V=F?r.orange:r.secondary;return(0,ke.jsxs)(f,{flexDirection:"column",children:[(0,ke.jsxs)(t,{color:r.dim,children:[" ",c]}),(0,ke.jsx)(f,{borderStyle:"round",borderColor:V,paddingX:1,width:10,children:(0,ke.jsxs)(t,{color:F?void 0:r.dim,children:[u||" ",F?(0,ke.jsx)(t,{color:r.dim,children:"\u2588"}):""]})}),(0,ke.jsxs)(t,{color:r.dim,dimColor:!0,children:[" ",D==="width"?`${$r}\u2013${Fr}`:`${Nr}\u2013${Ur}`]})]})};return(0,ke.jsxs)(f,{flexDirection:"column",paddingX:1,children:[(0,ke.jsx)(t,{color:r.orange,bold:!0,children:"Window Size"}),(0,ke.jsxs)(f,{marginTop:1,gap:1,children:[B("Width",x,"width"),(0,ke.jsx)(f,{alignItems:"center",marginTop:1,children:(0,ke.jsx)(t,{color:r.dim,children:"x"})}),B("Height",v,"height")]}),j&&(0,ke.jsx)(f,{marginTop:1,children:(0,ke.jsx)(t,{color:r.red,children:j})}),(0,ke.jsx)(Ot,{bindings:[{keys:"tab/\u2190\u2192",label:"switch field"},{keys:"\u21B5",label:"save"}],escBackLabel:"cancel"})]})}var Ce=C(he(),1);async function Ci(e,n,o){let i=e.loadCredentials(n,o),p=e.loadClient(n,o);if(i&&p){let x=new Eo(o);await Promise.allSettled([x.revokeToken(i.access_token,p.client_id,"access_token"),x.revokeToken(i.refresh_token,p.client_id,"refresh_token")])}e.deleteProfileFull(n,o);let d=e.listProfiles();return d.length>0&&(e.setActiveProfile(d[0].profile),e.setDefaultEnv(d[0].env)),{profile:n,env:o,switchedTo:d.length>0?d[0]:void 0}}function Ii(){let[e]=(0,Ce.useState)(()=>new Dn),[n,o]=(0,Ce.useState)(()=>{let u=e.resolveAuth();if(!u)return!1;if(u.method==="basic")return!0;let{credentials:D}=e.getActiveCredentials();return D?D.expires_at>Date.now()/1e3:!1}),i=(0,Ce.useRef)(null),p=(0,Ce.useRef)(null),d=(0,Ce.useCallback)(()=>{let u=e.resolveAuth();return u?{method:u.method,profile:u.profile,env:u.env}:null},[e]),x=(0,Ce.useCallback)(async()=>{let{credentials:u,profile:D,env:F}=e.getActiveCredentials();if(!u||!D||!F)return null;let V=u.expires_at,O=Date.now()/1e3;if(V-O<300){if(p.current)return p.current;let U=(async()=>{try{let E=await Bo({creds:e,profile:D,env:F,credentials:u});return E?(o(!0),E.accessToken):null}catch{return o(!1),null}finally{p.current=null}})();return p.current=U,U}return o(!0),u.access_token},[e]),h=(0,Ce.useCallback)(()=>{let u=e.resolveAuth();return!u||u.method!=="basic"?null:{username:u.username,access_key:u.access_key}},[e]),v=(0,Ce.useCallback)((u,D)=>{i.current?.revoke();let F=Ve(u),V=h(),O=new Ao(F.controllerBaseUrl,x,V,D);return i.current=O,O},[h,x]),w=(0,Ce.useCallback)(()=>i.current,[]),j=(0,Ce.useCallback)(()=>{let u=h();if(u)return u;let D=i.current?.cached;return D?{username:D.username,access_key:D.access_key}:null},[h]),R=(0,Ce.useCallback)(async()=>{let u=i.current;return u?u.resolve():null},[]),B=(0,Ce.useCallback)(async(u="default")=>{let D=e.getDefaultEnv();await new _o(u,D,e).login(),e.setActiveProfile(u);try{let V=new Nt;Ge(e,V,u,D)}catch{}o(!0)},[e]),c=(0,Ce.useCallback)(async()=>{let u=e.getActiveProfile();if(!u)return null;let D=e.getDefaultEnv(),F=await Ci(e,u,D);return o(!1),{profile:F.profile,env:F.env}},[e]);return{creds:e,tokenValid:n,setTokenValid:o,getToken:x,getBasicAuth:h,getAuthInfo:d,login:B,logout:c,initResolver:v,getResolver:w,getResolvedBasicAuth:j,resolveBasicAuth:R}}var pt=C(he(),1);import{mkdtempSync as Zs,rmSync as ea}from"fs";import{join as ta}from"path";import{tmpdir as na}from"os";function Ei(){let[e]=(0,pt.useState)(()=>new Nt),n=(0,pt.useRef)(null),o=(0,pt.useRef)(null),i=(0,pt.useRef)(null),p=(0,pt.useCallback)(async x=>{if(n.current)return n.current;if(i.current)return i.current;let h=(async()=>{let v=e.load(),w;if(v.chrome_profile_path)w=v.chrome_profile_path.replace("~",process.env.HOME??"~");else{o.current&&(St("tempDir","Previous temp dir removed before retry"),o.current=null);let R=Zs(ta(na(),"kane-clean-"));o.current=R,w=R,tt("tempDir",()=>{try{ea(R,{recursive:!0,force:!0})}catch{}})}let j=await Do({userDataDir:w,width:v.window_size.width,height:v.window_size.height,startUrl:x??v.default_url??void 0});return n.current=j,tt("chrome",()=>{j.kill()}),j})();i.current=h;try{return await h}finally{i.current=null}},[e]),d=(0,pt.useCallback)(()=>{St("chrome","Chrome killed"),St("tempDir","Temp dir removed"),n.current=null,o.current=null},[]);return{ensureChrome:p,killChrome:d}}var Un=[{name:"run",description:"Execute a test run",args:'"objective"'},{name:"login",description:"OAuth login",args:"[--profile name]"},{name:"logout",description:"Logout & revoke tokens",args:"[--profile name]"},{name:"whoami",description:"Show profile info",args:"[--profile name]"},{name:"balance",description:"Show credit balance"},{name:"profiles",description:"Manage profiles",args:"list|switch|delete"},{name:"config",description:"Manage configuration",args:"show|set-window|set-mode|chrome-profile|project|folder"},{name:"new",description:"Start a fresh session (uploads current first)"},{name:"name",description:"Set the current session's name (used at /exit save)",args:"<new-name>"},{name:"summary",description:"View detailed run summaries",args:"[index]"},{name:"cancel",description:"Abort current run"},{name:"help",description:"Show command reference"},{name:"clear",description:"Clear chat history"},{name:"exit",description:"Quit kane-cli"}];function Gn(e){let n=e.trim();if(!n.startsWith("/"))return null;let i=n.slice(1).match(/(?:[^\s"]+|"[^"]*")+/g)??[];if(i.length===0)return null;let p=i[0],d={},x=1;for(;x<i.length;){let h=i[x];if(h.startsWith("--")){let v=h.slice(2),w=i[x+1];w&&!w.startsWith("--")?(d[v]=w.replace(/^"|"$/g,""),x+=2):(d[v]=void 0,x++)}else{let v=h.replace(/^"|"$/g,"");p==="run"?d.objective=v:p==="config"?d.action?d.value=v:d.action=v:p==="profiles"?d.action=v:p==="summary"&&(d.index=v),x++}}return{command:p,args:d,raw:n}}var Fc=[{name:"Testing",commands:Un.filter(e=>["run","cancel"].includes(e.name))},{name:"Auth",commands:Un.filter(e=>["login","logout","whoami","balance","profiles"].includes(e.name))},{name:"Settings",commands:Un.filter(e=>["config"].includes(e.name))},{name:"Session",commands:Un.filter(e=>["new","name","summary","help","clear","exit"].includes(e.name))}];var Bi=[{name:"testmd",description:"Browse & run saved tests under cwd"},{name:"auth",description:"Login, logout, profiles"},{name:"config",description:"View/change settings"},{name:"help",description:"Command reference"},{name:"new",description:"Start a fresh session"},{name:"name",description:"Set the session name",args:"<new-name>"},{name:"exit",description:"Quit kane-cli"}],ra={name:"cancel",description:"Abort current run"},oa={name:"cancel",description:"Cancel current generation"},qt=[{name:"generate",description:"Switch to Generate mode (test case generator)"},{name:"summary",description:"View run summaries",args:"[index]"},ra,...Bi],un=[{name:"run",description:"Switch back to Run mode"},{name:"save",description:"Save the current test cases"},{name:"view",description:"Open the scenario browser",args:"[S<n>]"},oa,...Bi],_i=qt;function qn(e,n="run"){let o=n==="generate"?un:qt,i=e.startsWith("/")?e.slice(1):e;return i?o.filter(p=>p.name.startsWith(i)):o}var ia=new Set([...qt,...un].map(e=>e.name));function Ai(e,n){let o=n==="generate"?un:qt;return ia.has(e)?o.some(i=>i.name===e):!0}function Pi(e,n){let o=n?.trim();return o?e==="generate"?{kind:"reject"}:{kind:"run",objective:o}:e==="generate"?{kind:"toggle"}:{kind:"already"}}var wt=C(L(),1);function qr({flows:e,filterIndex:n}){let o=n!==void 0?e.filter(i=>i.index===n):e;return o.length===0?null:(0,wt.jsx)(f,{flexDirection:"column",children:o.map(i=>(0,wt.jsxs)(f,{flexDirection:"column",marginTop:1,children:[(0,wt.jsxs)(f,{marginLeft:1,children:[(0,wt.jsx)(t,{color:r.purple,bold:!0,children:"Flow "+i.index+": "}),(0,wt.jsx)(t,{color:r.purple,children:i.objective})]}),(0,wt.jsx)($o,{status:i.status==="error"?"failed":i.status,summary:i.summary,duration:i.duration,steps:i.steps,stepsPassed:i.stepsPassed,stepsFailed:i.stepsFailed,reason:i.reason,creditsConsumed:i.creditsConsumed})]},i.index))})}var Rt=C(L(),1),sa={ok:"\u2713",error:"\u2717",cancelled:"\u2298"},aa={ok:r.green,error:r.red,cancelled:r.dim};function Di({status:e,command:n,message:o,details:i,accentColor:p}){let d=n.startsWith("/")?n.slice(1):n,x=p??aa[e];return(0,Rt.jsxs)(f,{flexDirection:"column",marginLeft:2,marginTop:1,children:[(0,Rt.jsx)(f,{marginLeft:1,children:(0,Rt.jsxs)(t,{color:x,bold:!0,children:[sa[e]," ",d]})}),(0,Rt.jsxs)(f,{borderStyle:"round",borderColor:x,paddingX:2,flexDirection:"column",width:70,children:[(0,Rt.jsx)(t,{children:o}),i&&(0,Rt.jsx)(t,{color:r.dim,children:i})]})]})}var pn=C(he(),1);import{join as mn}from"path";var dn=C(L(),1);function Li({tabs:e,activeIndex:n}){return(0,dn.jsx)(f,{children:e.map((o,i)=>(0,dn.jsx)(f,{marginRight:1,children:i===n?(0,dn.jsx)(t,{color:r.orange,bold:!0,children:`[ ${o} ]`}):(0,dn.jsx)(t,{color:r.dim,children:` ${o} `})},o))})}var S=C(L(),1),fn=["Commands","Shortcuts","Tests","Setup","About"],Hn=18,ca="https://www.testmuai.com/support/docs/kane-cli-introduction",la="https://github.com/LambdaTest/kane-cli/issues";function ji({onClose:e,version:n,environment:o,sessionId:i,runUrl:p,mode:d="run"}){let[x,h]=(0,pn.useState)(0),[v,w]=(0,pn.useState)(0);(0,pn.useEffect)(()=>{w(0)},[x]);let j=fn[x],R=j==="Commands"?ua(d):j==="Shortcuts"?da():j==="Tests"?ma():j==="Setup"?fa():pa({version:n,environment:o,sessionId:i,runUrl:p}),B=R.length,c=v>0,u=v+Hn<B,D=R.slice(v,v+Hn);Re((V,O)=>{if(O.escape){e();return}if(O.rightArrow||O.tab){h(U=>(U+1)%fn.length);return}if(O.leftArrow){h(U=>(U-1+fn.length)%fn.length);return}if(O.upArrow){w(U=>Math.max(0,U-1));return}if(O.downArrow){w(U=>Math.min(Math.max(0,B-Hn),U+1));return}});let F=[{keys:"\u2190\u2192/tab",label:"switch tabs"}];return B>Hn&&F.push({keys:"\u2191\u2193",label:"scroll"}),(0,S.jsxs)(f,{flexDirection:"column",borderStyle:"round",borderColor:r.orange,paddingX:2,paddingY:1,children:[(0,S.jsx)(Li,{tabs:[...fn],activeIndex:x,onChange:h}),c&&(0,S.jsx)(f,{marginTop:1,children:(0,S.jsx)(t,{color:r.dim,children:"\u25B2 more above"})}),(0,S.jsx)(f,{marginTop:c?0:1,flexDirection:"column",children:D}),u&&(0,S.jsx)(f,{children:(0,S.jsx)(t,{color:r.dim,children:"\u25BC more below"})}),(0,S.jsx)(Ot,{bindings:F,escBackLabel:"back to chat"})]})}function ua(e){let n=e==="generate"?un:qt;return[(0,S.jsx)(t,{color:r.dim,children:"Type a natural-language objective and press \u21B5 to run, e.g."},"intro"),(0,S.jsx)(f,{marginLeft:2,children:(0,S.jsx)(t,{color:r.orange,children:'"search amazon for laptop"'})},"ex"),(0,S.jsx)(f,{marginBottom:1},"sp"),(0,S.jsx)(t,{color:r.dim,bold:!0,children:"Slash commands"},"cmd-h"),...n.map(o=>(0,S.jsxs)(f,{marginLeft:2,children:[(0,S.jsx)(f,{width:14,children:(0,S.jsxs)(t,{color:r.orange,children:["/",o.name]})}),o.args&&(0,S.jsx)(f,{width:14,children:(0,S.jsx)(t,{color:r.dim,children:o.args})}),(0,S.jsx)(t,{color:r.dim,children:o.description})]},o.name)),(0,S.jsx)(f,{marginBottom:1},"sp2"),(0,S.jsx)(f,{marginLeft:2,children:(0,S.jsx)(t,{color:r.dim,children:"/auth submenu: login \xB7 logout \xB7 whoami \xB7 profiles \xB7 balance"})},"auth-sub"),(0,S.jsx)(f,{marginLeft:2,children:(0,S.jsx)(t,{color:r.dim,children:"/config submenu: show \xB7 set-mode \xB7 set-window \xB7 chrome-profile \xB7 project \xB7 folder"})},"config-sub")]}function Wn(e,n){return[(0,S.jsx)(t,{color:r.dim,bold:!0,children:e},`h-${e}`),...n.map(([o,i],p)=>(0,S.jsxs)(f,{marginLeft:2,children:[(0,S.jsx)(f,{width:26,children:(0,S.jsx)(t,{color:r.orange,children:o})}),(0,S.jsx)(t,{color:r.dim,children:i})]},`r-${e}-${p}`)),(0,S.jsx)(f,{marginBottom:1},`s-${e}`)]}function da(){return[...Wn("Cursor & word edit",[["\u2190 \u2192","Cursor by char"],["Ctrl+A Ctrl+E","Start / end of line"],["Home End","Start / end (Linux/Win; rare on Mac laptops)"],["Backspace","Delete char before cursor"],["Ctrl+W","Delete word back"],["Ctrl+U","Clear input"],["Ctrl+K","Kill from cursor to end"],["Ctrl+\u2190 Ctrl+\u2192","Word jump (Linux/Win, iTerm2)"],["Option+\u2190 Option+\u2192","Word jump (Mac native)"],["Option+B Option+F","Word jump (Mac, Emacs-style)"],["Alt+Backspace","Delete word back (Option+Delete on Mac)"],["Ctrl+Delete Option+Fn+Del","Delete word forward"]]),...Wn("History & completion",[["\u2191 \u2193","Previous / next history"],["Tab","Accept ghost / fill highlighted command"],["Ctrl+R","Reverse-search history"],["\u21B5","Submit"],["Esc","Close overlay / clear / back"]]),...Wn("Lists & menus",[["\u2191 \u2193","Navigate"],["type any char","Filter"],["\u21B5","Select"],["Tab","Create-new (in pickers)"],["Esc","Clear filter, then back"]]),...Wn("Global",[["Ctrl+C","Cancel run \xB7 twice exits"]]),(0,S.jsx)(t,{color:r.dim,bold:!0,children:"Platform caveats"},"cv-h"),(0,S.jsx)(t,{color:r.dim,children:'\u2022 Mac Terminal.app: enable "Use Option as Meta key" (Profile \u2192 Keyboard)'},"cv-1"),(0,S.jsx)(t,{color:r.dim,children:"\u2022 Mac iTerm2: works by default (Esc+ mode)"},"cv-2"),(0,S.jsx)(t,{color:r.dim,children:"\u2022 Mac Mission Control may intercept Ctrl+arrow \u2014 use Option+arrow instead"},"cv-3"),(0,S.jsx)(t,{color:r.dim,children:"\u2022 Bare Forward Delete acts as Backspace (Ink can't disambiguate)"},"cv-4"),(0,S.jsx)(t,{color:r.dim,children:"\u2022 Shift+arrow is parsed but unbound (selection model is future)"},"cv-5"),(0,S.jsx)(t,{color:r.dim,children:"\u2022 Thousands of terminals exist \u2014 if a shortcut fails, run `cat` to see bytes"},"cv-6")]}function ma(){return[(0,S.jsxs)(t,{color:r.dim,children:["Sessions you run here are saved as ",(0,S.jsx)(t,{color:r.orange,children:"*_test.md"})," files you can replay later."]},"t-intro"),(0,S.jsx)(f,{marginBottom:1},"t-sp1"),(0,S.jsx)(t,{color:r.dim,bold:!0,children:"Auto-save"},"t-save-h"),(0,S.jsxs)(t,{color:r.dim,children:[" In ",(0,S.jsx)(t,{color:r.orange,children:"testing"})," mode, /exit prompts to save the session under a name (default: timestamp)."]},"t-save-1"),(0,S.jsxs)(t,{color:r.dim,children:[" In ",(0,S.jsx)(t,{color:r.orange,children:"action"})," mode, sessions are ephemeral unless launched with --name or set via /name."]},"t-save-2"),(0,S.jsxs)(t,{color:r.dim,children:[" Output: ",(0,S.jsx)(t,{color:r.orange,children:"<cwd>/.testmuai/tests/<name>_test.md"})," + sibling ",(0,S.jsx)(t,{color:r.orange,children:"output-<name>/"})," (Result.md + .internal/meta.json)."]},"t-save-3"),(0,S.jsx)(f,{marginBottom:1},"t-sp2"),(0,S.jsx)(t,{color:r.dim,bold:!0,children:"Replay from a shell"},"t-run-h"),(0,S.jsxs)(t,{color:r.dim,children:[" ",(0,S.jsx)(t,{color:r.orange,children:"kane-cli testmd run path/to/foo_test.md"})," \xB7 ",(0,S.jsx)(t,{color:r.orange,children:"kane-cli testmd list"})," \xB7 bare ",(0,S.jsx)(t,{color:r.orange,children:"kane-cli testmd"})," opens a TTY picker."]},"t-run-1"),(0,S.jsx)(t,{color:r.dim,children:" The .md file carries its own config (mode, max_steps, variables, \u2026) so the replay is reproducible."},"t-run-2"),(0,S.jsx)(f,{marginBottom:1},"t-sp3"),(0,S.jsx)(t,{color:r.dim,bold:!0,children:"Naming a session mid-run"},"t-name-h"),(0,S.jsxs)(t,{color:r.dim,children:[" Type ",(0,S.jsxs)(t,{color:r.orange,children:["/name ","<new-name>"]})," any time before /exit. Name allowed chars: letters, digits, _, -."]},"t-name-1"),(0,S.jsxs)(t,{color:r.dim,children:[" Discarding at the save prompt: press ",(0,S.jsx)(t,{color:r.orange,children:"N"})," (only key that discards \u2014 every other key saves with default)."]},"t-name-2")]}function fa(){return[(0,S.jsx)(t,{color:r.dim,bold:!0,children:"1. Login"},"s1-h"),(0,S.jsx)(t,{color:r.dim,children:" /auth \u2192 login. OAuth opens browser; basic uses LambdaTest username + access key."},"s1-b"),(0,S.jsx)(t,{color:r.dim,bold:!0,children:"2. Project & folder"},"s2-h"),(0,S.jsx)(t,{color:r.dim,children:" /config project / /config folder. Esc auto-picks KaneAI Generated / Untitled."},"s2-b"),(0,S.jsx)(t,{color:r.dim,bold:!0,children:"3. Mode"},"s3-h"),(0,S.jsx)(t,{color:r.dim,children:" testing (saves to TMS) | action (local report). /config set-mode"},"s3-b"),(0,S.jsx)(f,{marginBottom:1},"spacer-1"),(0,S.jsx)(t,{color:r.dim,bold:!0,children:"Variables (later wins)"},"v-h"),(0,S.jsxs)(t,{color:r.dim,children:[" ",`${mn(Me,"variables")}/*.json`," (global)"]},"v-1"),(0,S.jsxs)(t,{color:r.dim,children:[" ","{cwd}/.testmuai/variables/*.json"," (local) \xB7 --variables-file \xB7 --variables ","'{...}'"]},"v-2"),(0,S.jsx)(t,{color:r.dim,children:' Format: { "key": { "value": "...", "secret": false } } \xB7 ref via {{key}}'},"v-3"),(0,S.jsx)(f,{marginBottom:1},"spacer-2"),(0,S.jsx)(t,{color:r.dim,bold:!0,children:"Context files"},"c-h"),(0,S.jsxs)(t,{color:r.dim,children:[" Global: ",mn(Me,"global-memory.md")]},"c-1"),(0,S.jsxs)(t,{color:r.dim,children:[" Local: ","{cwd}/.testmuai/context.md"," \xB7 CLI: --global-context, --local-context"]},"c-2"),(0,S.jsx)(f,{marginBottom:1},"spacer-3"),(0,S.jsx)(t,{color:r.dim,bold:!0,children:"Paths"},"p-h"),(0,S.jsxs)(t,{color:r.dim,children:[" Config: ",mn(Me,"tui-config.json")," \xB7 Auth: ",mn(Me,"config.json")]},"p-1"),(0,S.jsxs)(t,{color:r.dim,children:[" Sessions: ",mn(Me,"sessions"),"/"]},"p-2")]}function pa({version:e,environment:n,sessionId:o,runUrl:i}){return[(0,S.jsxs)(f,{children:[(0,S.jsx)(t,{color:r.orange,bold:!0,children:"kane-cli "}),(0,S.jsxs)(t,{color:r.muted,children:["v",e]})]},"title"),(0,S.jsx)(f,{marginBottom:1},"sp"),(0,S.jsxs)(f,{children:[(0,S.jsx)(f,{width:14,children:(0,S.jsx)(t,{color:r.dim,children:"Environment"})}),(0,S.jsx)(t,{children:n})]},"env"),(0,S.jsxs)(f,{children:[(0,S.jsx)(f,{width:14,children:(0,S.jsx)(t,{color:r.dim,children:"Session"})}),(0,S.jsx)(t,{children:o})]},"sess"),(0,S.jsxs)(f,{children:[(0,S.jsx)(f,{width:14,children:(0,S.jsx)(t,{color:r.dim,children:"Default URL"})}),(0,S.jsx)(t,{color:r.orange,children:i})]},"url"),(0,S.jsx)(f,{marginBottom:1},"sp2"),(0,S.jsxs)(f,{children:[(0,S.jsx)(f,{width:14,children:(0,S.jsx)(t,{color:r.dim,children:"Docs"})}),(0,S.jsx)(t,{color:r.orange,underline:!0,children:ca})]},"docs"),(0,S.jsxs)(f,{children:[(0,S.jsx)(f,{width:14,children:(0,S.jsx)(t,{color:r.dim,children:"Bugs"})}),(0,S.jsx)(t,{color:r.orange,underline:!0,children:la})]},"bugs")]}var zn=C(he(),1);import{existsSync as Mi,readFileSync as ll,rmSync as ga,unlinkSync as ha}from"fs";function Vi(e){let n=Fo(e);Mi(n)&&ga(n,{recursive:!0,force:!0}),Mi(e)&&ha(e)}var Hr=C(L(),1);function Oi({cwd:e,currentOrgId:n,onClose:o,onRun:i,onExport:p}){let[d,x]=(0,zn.useState)("list"),[h,v]=(0,zn.useState)(null),[w,j]=(0,zn.useState)(0);return d==="inspect"&&h?(0,Hr.jsx)(Uo,{path:h.path,relPath:h.relPath,onBack:()=>x("list"),onAction:R=>{if(R==="run")i(h);else if(R==="export")p(h);else{try{Vi(h.path)}catch{}v(null),x("list"),j(B=>B+1)}}}):(0,Hr.jsx)(No,{root:e,currentOrgId:n,onSelect:R=>{v(R),x("inspect")},onCancel:o},w)}var Ie=C(he(),1);function $i(e){let[n,o]=(0,Ie.useState)(null),[i,p]=(0,Ie.useState)(!1),[d,x]=(0,Ie.useState)(null),[h,v]=(0,Ie.useState)(null),[w,j]=(0,Ie.useState)(null),R=(0,Ie.useRef)(0),B=(0,Ie.useRef)([]),c=(0,Ie.useRef)(!1),u=(0,Ie.useRef)(null),D=(0,Ie.useRef)(e);D.current=e;let F=(0,Ie.useCallback)(async U=>{if(c.current)return null;c.current=!0;let E=++R.current,M=[];B.current=M;let Y=q=>`testmd-run-${E}-${q}`,K={register:(q,ue)=>{let se=Y(q);M.push(se),tt(se,ue)},deregister:q=>an(Y(q)),cleanup:(q,ue)=>St(Y(q),ue),remoteLogger:D.current.remoteLogger},we={runSteps:q=>new Promise(ue=>{let se=()=>{u.current=null,ue()};u.current=se,o({...q,exitOnComplete:!1,onAllComplete:()=>{q.onAllComplete?.(),se()}})}),onLockState:q=>{},onRetryAttempt:q=>{},onSummary:async q=>{x(q)},onLinks:async q=>{v(q)},runUpload:q=>q.execute(),onAgentEvent:q=>{}};p(!0),x(null),v(null),j(null);try{let q=await D.current.buildInput(U),ue=await ni(q,we,K);return j(ue),ue}finally{c.current=!1,u.current=null,p(!1),o(null);for(let q of M)St(q,"run-finished");M.length=0}},[]),V=(0,Ie.useCallback)(()=>{for(let E of B.current)St(E,"cancelled");B.current=[];let U=u.current;u.current=null,U?.()},[]),O=(0,Ie.useCallback)(()=>{x(null),v(null),j(null)},[]);return{start:F,cancel:V,clearResult:O,running:i,runViewProps:n,summary:d,links:h,runSummary:w}}var ye=C(he(),1);function Fi(e={}){let[n,o]=(0,ye.useState)(()=>On({requestId:"",objective:""})),[i,p]=(0,ye.useState)(!1),[d,x]=(0,ye.useState)(null),h=(0,ye.useRef)(null),v=(0,ye.useRef)(!1),w=(0,ye.useRef)(null),j=(0,ye.useCallback)(async(F,V,O)=>{v.current=!1;let U=0,E=0,M=0;for await(let Y of F){if(v.current)break;switch(o(K=>si(K,Y)),Y.type){case"thinking_done":O?.("tcg_thinking",{tookMs:Y.tookMs});break;case"progress":{let K=Math.min(100,Math.floor(Y.pct/25)*25);K>M&&(M=K,O?.("tcg_progress",{pct:K}));break}case"snapshot":U=Y.data.scenarios.length,E=Y.data.scenarios.reduce((K,we)=>K+(we.test_cases?.length??0),0),O?.("tcg_snapshot",{scenarioCount:U,caseCount:E});break;case"clarification":O?.("tcg_clarification",{});break;case"done":O?.("tcg_request_done",{status:Y.status,scenarioCount:U,caseCount:E,durationMs:Date.now()-V});break;case"error":O?.("tcg_request_error",{errorCode:"tcg_request_failed",durationMs:Date.now()-V});break}}},[]),R=(0,ye.useCallback)(async(F,V)=>{if(h.current)throw new Error("useTcgSession: a session is already active; call reset() or end() first");let O=e.makeClient??ai;h.current=O(F),w.current=new AbortController;let U=On({requestId:"",objective:V.prompt});o($n(U));let E;try{E=await h.current.start(V,w.current.signal)}catch(Y){throw h.current=null,w.current=null,o(K=>({...K,turnActive:!1})),Y}x(E.requestId),o($n({...E.state,requestId:E.requestId,objective:V.prompt}));let M=Date.now();e.log?.("tcg_request_start",{request_id:E.requestId,objectiveChars:V.prompt.length,scenarioLimit:V.scenarioLimit,perScenarioLimit:V.perScenarioLimit,memoryEnhancement:V.memoryEnhancement}),await j(E.events,M,e.log)},[j,e.makeClient,e.log]),B=(0,ye.useCallback)(async F=>{if(!h.current||!d)throw new Error("useTcgSession: chat() with no active request");o(V=>$n(ii(V))),await h.current.chat(d,F)},[d]),c=(0,ye.useCallback)(async()=>{if(!(!d||!h.current)){v.current=!0,w.current&&w.current.abort();try{await h.current.cancel(d)}catch{}h.current=null,x(null),o(F=>({...F,turnActive:!1}))}},[d]),u=(0,ye.useCallback)(async()=>{if(!(!d||!h.current)){v.current=!0,w.current&&w.current.abort();try{await h.current.end(d)}catch{}h.current=null,x(null),o(F=>({...F,turnActive:!1}))}},[d]),D=(0,ye.useCallback)(()=>{v.current=!0,w.current&&w.current.abort(),w.current=null,o(On({requestId:"",objective:""})),x(null),p(!1),h.current=null},[]);return(0,ye.useEffect)(()=>()=>{v.current=!0,w.current&&w.current.abort()},[]),{state:n,isStreaming:n.turnActive,isTerminal:oi(n.status),isReconnecting:i,turnActive:n.turnActive,inReview:n.scenarios.length>0&&!n.turnActive&&!Br(n.status),isSessionClosed:Br(n.status),requestId:d,startWith:R,chat:B,cancel:c,end:u,reset:D}}var Z=C(he(),1);import{join as Ht,resolve as Ta}from"path";import{mkdirSync as zr,writeFileSync as Xi,appendFileSync as Sa}from"fs";function Ni(e){let n=Ve(e.env);return!n||!n.testGeneratorBaseUrl?{ok:!1,error:`Unknown environment "${e.env}" \u2014 fix default_env via /config`}:{ok:!0,conn:{baseUrl:`${n.testGeneratorBaseUrl}/test-generator/api/v2`,authResolver:e.resolver,projectId:e.projectId,folderId:e.folderId,log:e.log}}}function Ui(e){return e.turnActive?!0:e.requestId!=null&&!e.isSessionClosed&&!e.saved}function Gi(e){return e.isRunning||e.hasLiveResults}function qi(e){let n=(e??"").trim().match(/^[sS](\d+)$/);if(!n)return{level:"scenarios"};let o=parseInt(n[1],10);return o<1?{level:"scenarios"}:{level:"cases",scenarioIdx:o-1}}function Oe(e,n){return`S${e+1}.C${n+1}`}function Hi(e,n){return e.reduce((o,i,p)=>o+(i.test_cases??[]).filter((d,x)=>!n.has(Oe(p,x))).length,0)}function Wi(e,n){return e.map((o,i)=>({...o,test_cases:(o.test_cases??[]).filter((p,d)=>!n.has(Oe(i,d)))})).filter(o=>(o.test_cases??[]).length>0)}var gn=C(he(),1);import{createHash as xa}from"crypto";function va(e){return xa("sha1").update(JSON.stringify({t:e.title,p:e.preconditions,m:e.manual_steps})).digest("hex")}var Xn=class{constructor(n){this.deps=n;this.max=n.maxConcurrent??3}cache=new Map;caseById=new Map;queue=[];active=0;max;onSnapshot(n){n.forEach((o,i)=>{(o.test_cases??[]).forEach((p,d)=>{if(!rt(p)||p.manual_steps==null)return;let x=va(p),h=this.cache.get(p.id);h&&h.hash===x||(h?.controller?.abort(),this.caseById.set(p.id,p),this.cache.set(p.id,{hash:x,ref:Oe(i,d),status:"pending"}),this.queue.includes(p.id)||this.queue.push(p.id))})}),this.pump()}pump(){for(;this.active<this.max&&this.queue.length>0;){let n=this.queue.shift(),o=this.cache.get(n),i=this.caseById.get(n);!o||!i||o.status!=="pending"||(this.active++,this.runOne(n,i,o))}}async runOne(n,o,i){let p=`bifurcation-${n}`,d=new AbortController;i.controller=d;let x=this.deps.run??this.defaultRun.bind(this);tt(p,()=>d.abort());let h=Date.now();try{this.safeLog("tcg_bif_start",{caseId:n,ref:i.ref});let v=await x(mi(o),d.signal);if(!d.signal.aborted&&this.cache.get(n)===i){i.status="done",i.result=v;try{this.deps.persist?.(n,v,i.ref)}catch{}this.safeLog("tcg_bif_done",{caseId:n,ref:i.ref,total_flows:v.total_flows,is_single_flow:v.is_single_flow,estimated_steps_total:(v.sub_objectives??[]).reduce((w,j)=>w+(j.estimated_steps??0),0),credits_consumed:v.credits_consumed,durationMs:Date.now()-h})}}catch(v){!d.signal.aborted&&this.cache.get(n)===i&&(i.status="error",i.error=v.message,this.safeLog("tcg_bif_error",{caseId:n,ref:i.ref,errorCode:"bifurcation_failed",durationMs:Date.now()-h}))}finally{an(p),this.active--,this.pump()}}safeLog(n,o){try{this.deps.log?.(n,o)}catch{}}async defaultRun(n,o){let i=await this.deps.resolveAuth(),p=fi({objective:n,model:this.deps.model,sessionId:this.deps.sessionId,auth:i});return pi(p,this.deps.spawnOpts,o)}getStatus(n){return this.cache.get(n)?.status}getResult(n){return this.cache.get(n)?.result}dispose(){for(let[n,o]of this.cache)o.controller?.abort(),an(`bifurcation-${n}`);this.cache.clear(),this.caseById.clear(),this.queue=[],this.active=0}};function zi(e){let n=(0,gn.useRef)(null);return(0,gn.useEffect)(()=>{if(!e.enabled)return;let o=e.log,i=o?(p,d,x,h)=>o(d,h??{}):void 0;return n.current=new Xn({model:e.model,sessionId:e.sessionId,resolveAuth:e.resolveAuth,spawnOpts:{environment:e.environment,log:i},log:o,persist:e.persist}),()=>{n.current?.dispose(),n.current=null}},[e.enabled,e.sessionId,e.model,e.environment]),(0,gn.useEffect)(()=>{n.current&&n.current.onSnapshot(e.scenarios)},[e.scenarios]),{getStatus:o=>n.current?.getStatus(o),getResult:o=>n.current?.getResult(o),manager:n}}var ba=["request_id","session_id","caseId","ref","total_flows","is_single_flow","estimated_steps_total","credits_consumed","durationMs","pct","tookMs","scenarioCount","caseCount","savedCount","fellBack","turnIndex","status","errorCode","objectiveChars","scenarioLimit","perScenarioLimit","memoryEnhancement"],ya=new Set(ba);function Wr(e){let n={};for(let o of Object.keys(e))ya.has(o)&&e[o]!==void 0&&(n[o]=e[o]);return n}var qe=C(L(),1);async function wa(e){let n=e?.getResolvedBasicAuth?.();if(n)return{username:n.username,access_key:n.access_key};let o=await e?.getToken?.();return typeof o=="string"&&o.length>0?{auth:{type:"bearer",token:o}}:{}}function Ki(e){let{tcg:n,initialChatMode:o,tuiConfig:i,auth:p,session:d,appendStatic:x,handleInput:h,freezeTcgArtifact:v,rearmArtifactFreeze:w,initialGenerateLimits:j}=e,[R,B]=(0,Z.useState)(o??"run"),[c,u]=(0,Z.useState)(null),[D,F]=(0,Z.useState)(null),[V,O]=(0,Z.useState)(null),[U,E]=(0,Z.useState)(0),[M,Y]=(0,Z.useState)(!1),K=(0,Z.useRef)(null),we=(0,Z.useRef)(()=>{}),q=(0,Z.useCallback)(()=>wa(p),[p]),ue=(0,Z.useRef)(null);ue.current=n.requestId;let se=(0,Z.useCallback)((H,ee)=>{let de=H.endsWith("_error")?"warn":"info",J=Wr({request_id:ue.current??void 0,...ee});d.log(de,H,JSON.stringify(J),J);try{let Be=typeof J.request_id=="string"&&J.request_id||ue.current||"unknown",pe=Ht(Me,"tcg",Be);zr(pe,{recursive:!0}),Sa(Ht(pe,"tcg_tui.log"),`[${new Date().toISOString()}] ${H} ${JSON.stringify(J)}
|
|
3
|
+
`)}catch{}},[d]),Ye=(0,Z.useRef)(0),xt=(0,Z.useCallback)((H,ee,de)=>{try{let J=Ht(Me,"tcg",ue.current??"unknown","bifurcation");zr(J,{recursive:!0}),Xi(Ht(J,`${H}.json`),JSON.stringify({request_id:ue.current,ref:de,...ee},null,2))}catch{}},[]),Je=zi({scenarios:n.state?.scenarios??[],model:i.model,sessionId:d.sessionId,resolveAuth:q,environment:p?.creds?.getDefaultEnv?.(),enabled:!!n.requestId&&!n.isSessionClosed,log:se,persist:xt}),kt=(0,Z.useRef)(null);(0,Z.useEffect)(()=>{let H=n.requestId;if(!H||!n.isSessionClosed&&!n.isTerminal)return;let ee=n.state?.scenarios??[];if(ee.length!==0&&kt.current!==H){kt.current=H;try{let de=Ht(Me,"tcg",H);zr(de,{recursive:!0}),Xi(Ht(de,"request.json"),JSON.stringify({request_id:H,objective:n.state?.objective,headline:n.state?.headline,scenarios:ee,status:n.state?.status},null,2))}catch{}}},[n.requestId,n.isTerminal,n.isSessionClosed,n.state?.scenarios,n.state?.status,n.state?.objective,n.state?.headline]);let De=(0,Z.useCallback)((H,ee=1500)=>{O(H),K.current&&clearTimeout(K.current),K.current=setTimeout(()=>{O(null),K.current=null},ee)},[]);(0,Z.useEffect)(()=>()=>{K.current&&clearTimeout(K.current)},[]);let Pt=(0,Z.useCallback)(async H=>{u(null),F(null),Y(!1);let ee=H.trim();if(!ee)return;if(ee.startsWith("/")){we.current(ee),E(pe=>pe+1);return}if(!i.project_id||!i.folder_id){F("Set a project and folder first \u2014 use /config");return}let de=p.getResolver();if(!de){u("Not logged in \u2014 use /login");return}let J=Ni({env:p.creds.getDefaultEnv(),resolver:de,projectId:i.project_id,folderId:i.folder_id,log:(pe,Qe,Kt,vt)=>d.log(pe,Qe,"",Wr(vt??{}))});if(!J.ok){u(J.error);return}let Be=J.conn;v(),n.reset(),w();try{let pe=j??{};x((0,qe.jsx)(f,{marginTop:1,children:(0,qe.jsx)(t,{color:r.generateAccent,bold:!0,children:`\u276F ${ee}`})})),await n.startWith(Be,{prompt:ee,scenarioLimit:pe.scenarioLimit??i.generate.scenario_limit,perScenarioLimit:pe.perScenarioLimit??i.generate.per_scenario_limit,memoryEnhancement:i.generate.memory_enabled})}catch(pe){let Qe=pe instanceof Error?pe.message:String(pe);u(Qe||"Generation failed")}},[i,n,p,d,j,x,v,w]),hn=(0,Z.useCallback)(()=>u(null),[]),Xt=(0,Z.useCallback)(H=>{x((0,qe.jsx)(t,{color:r.generateAccent,bold:!0,children:`\u276F ${H}`})),Ye.current+=1,se("tcg_refine",{turnIndex:Ye.current}),n.chat(H).catch(ee=>u(ee?.message??"chat failed"))},[x,n,se]),Fe=(0,Z.useCallback)(H=>{x((0,qe.jsx)(t,{color:r.generateAccent,bold:!0,children:`\u276F ${H}`})),n.chat(H).catch(ee=>u(ee?.message??"chat failed"))},[x,n]),Ct=(0,Z.useCallback)(H=>{let ee=Gn(H);if(ee?.command==="view"){let de=H.trim().split(/\s+/).slice(1)[0];if(n.state.scenarios.length===0){e.emitFeedback("ok","/view","(no generation yet)");return}let J=qi(de);if(J.level==="cases"&&J.scenarioIdx>=n.state.scenarios.length){e.emitFeedback("error","/view",`No scenario S${J.scenarioIdx+1}`);return}e.openBrowse(J);return}if(ee?.command==="save"){let de=n.state.scenarios;if(de.length===0){e.emitFeedback("error","/save","Nothing to save yet.");return}let J=Wi(de,e.excluded),Be=J.reduce((vt,at)=>vt+(at.test_cases??[]).filter(rt).length,0);if(Be===0){e.emitFeedback("error","/save",Hi(de,e.excluded)===0?"All cases removed \u2014 nothing to save.":"No functional test cases to save.");return}let pe={...n.state,scenarios:J},Qe=H.trim().split(/\s+/).slice(1)[0],Kt=Qe?Ta(process.cwd(),Qe):process.cwd();Y(!0),e.freezeTcgArtifact(),(async()=>{let vt=J.flatMap(ce=>(ce.test_cases??[]).filter(rt)),at=Date.now()+3e4;for(;Date.now()<at&&vt.some(ce=>Je.getStatus(ce.id)==="pending");)await new Promise(ce=>setTimeout(ce,250));let vn=new Map;for(let ce of vt)vn.set(ce.id,Je.getStatus(ce.id)==="done"?Je.getResult(ce.id):void 0);n.end();let _e=0,It=ce=>{let Dt=vn.get(ce.id);return Dt?li(Dt,ce):(_e++,ui(ce))};try{let ce=await di(pe,Kt,{},It);se("tcg_save",{savedCount:ce.paths.length,fellBack:_e})}catch(ce){e.emitFeedback("error","/save",`Save failed: ${ce.message}`);return}let bn=`test case${Be===1?"":"s"}`;e.emitFeedback("ok","/save",_e>0?`Saved ${Be} ${bn} \xB7 ${_e} fell back to raw steps.`:`Saved ${Be} ${bn}.`)})();return}ee?.command==="new"&&Y(!1),h(H)},[h,e,n,Je,se]);we.current=Ct;let Le=(0,Z.useCallback)(H=>{B(H),E(ee=>ee+1)},[]),xn=(0,Z.useCallback)(H=>{let ee=R==="generate"&&H==="run",de=R==="run"&&H==="generate",J=Ui({requestId:n.requestId,isSessionClosed:n.isSessionClosed,turnActive:n.turnActive,saved:M}),Be=Gi({isRunning:e.runner.isRunning,hasLiveResults:e.runner.lastRunEnd!=null});return ee&&J?(e.openSwitchConfirm("run"),!1):de&&Be?(e.openSwitchConfirm("generate"),!1):(Le(H),!0)},[R,n.requestId,n.isSessionClosed,n.turnActive,M,e,Le]),or=(0,Z.useCallback)(async H=>{R==="generate"?(e.freezeTcgArtifact(),await n.end().catch(()=>{}),n.reset(),Y(!1),e.appendStatic((0,qe.jsxs)(f,{marginBottom:1,children:[(0,qe.jsx)(t,{color:r.red,children:"\u2717 "}),(0,qe.jsx)(t,{color:r.dim,children:"Discarded generation"})]}))):(e.runner.isRunning&&e.runner.cancelRun(),e.runner.clearLastRun(),e.appendStatic((0,qe.jsxs)(f,{marginBottom:1,children:[(0,qe.jsx)(t,{color:r.red,children:"\u2717 "}),(0,qe.jsx)(t,{color:r.dim,children:"Discarded run"})]}))),Le(H),H==="generate"?e.emitFeedback("ok","/generate","Switched to Generate mode.",void 0,r.generateAccent):e.emitFeedback("ok","/run","Switched to Run mode.",void 0,r.orange)},[R,n,e,Le]);return{chatMode:R,tcgError:c,tcgValidationError:D,composeIdleHint:V,inputClearSeq:U,handleGenerateSubmit:Pt,onRefine:Xt,onClarificationAnswer:Fe,onSlash:Ct,onClearError:hn,flashComposeHint:De,setInputClearSeq:E,setChatMode:B,setTcgError:u,setTcgValidationError:F,generateSaved:M,requestSwitch:xn,confirmSwitch:or,bifurcation:Je,tcgLog:se}}var it=C(he(),1);function Kn(e){return e.level==="cases"?{level:"cases",scenarioIdx:e.scenarioIdx,caseIdx:0,cursor:0,scroll:0}:{level:"scenarios",scenarioIdx:0,caseIdx:0,cursor:0,scroll:0}}var Yi=(e,n)=>Math.max(0,Math.min(n,e));function Xr(e,n,o){switch(n.type){case"open":return Kn(n.target);case"move":{let i=e.level==="scenarios"?o.length-1:e.level==="cases"?(o[e.scenarioIdx]??1)-1:0;return{...e,cursor:Yi(e.cursor+n.delta,Math.max(0,i))}}case"enter":return e.level==="scenarios"?{...e,level:"cases",scenarioIdx:e.cursor,caseIdx:0,cursor:0,scroll:0}:e.level==="cases"?{...e,level:"detail",caseIdx:e.cursor,scroll:0}:e;case"back":return e.level==="detail"?{...e,level:"cases",cursor:e.caseIdx,scroll:0}:e.level==="cases"?{...e,level:"scenarios",cursor:e.scenarioIdx}:e;case"sibling":{if(e.level==="scenarios")return e;let i=Yi(e.scenarioIdx+n.delta,Math.max(0,o.length-1));return{...e,scenarioIdx:i,caseIdx:0,cursor:0,scroll:0}}case"scroll":return{...e,scroll:Math.max(0,e.scroll+n.delta)};default:return e}}function Ji(e){let[n,o]=(0,it.useState)(null),[i,p]=(0,it.useReducer)((R,B)=>Xr(R,B,e),Kn({level:"scenarios"})),[d,x]=(0,it.useState)(new Set),h=(0,it.useCallback)(R=>{o(R),p({type:"open",target:R})},[]),v=(0,it.useCallback)(()=>o(null),[]),w=(0,it.useCallback)((R,B)=>{let c=Oe(R,B);x(u=>{let D=new Set(u);return D.has(c)?D.delete(c):D.add(c),D})},[]),j=(0,it.useCallback)((R,B)=>{x(c=>{let u=new Set(c),D=Array.from({length:B},(V,O)=>Oe(R,O)),F=D.every(V=>u.has(V));return D.forEach(V=>F?u.delete(V):u.add(V)),u})},[]);return{target:n,open:h,close:v,isOpen:n!=null,state:i,excluded:d,toggleCase:w,toggleScenario:j}}var Qn=C(he(),1);function Qi(){return{committedChat:0,committedThinking:0,prevTurnActive:!1}}function Zi(e,n,o){let i=[],p={...e};if(e.prevTurnActive&&!o&&n.thinkingLog.length>e.committedThinking){let x=n.thinkingLog.slice(e.committedThinking).reduce((v,w)=>v+(w.tookMs??0),0),h=Math.round(x/1e3);i.push({kind:"thinking-summary",text:` thought for ${h}s`}),p.committedThinking=n.thinkingLog.length}p.prevTurnActive=o;for(let d=e.committedChat;d<n.chatLog.length;d++)i.push({kind:"chat",text:n.chatLog[d].text});return p.committedChat=n.chatLog.length,{items:i,next:p}}function es(e){let n=e;return n=n.replace(/@TS\{([^}]+)\}/g,"@S{$1}"),n=n.replace(/@TS-(\d+)/g,(o,i)=>`@S${parseInt(i,10)}.C1`),n=n.replace(/@TS(\d+)/g,(o,i)=>`@S${parseInt(i,10)}`),n=n.replace(/\\n/g,`
|
|
4
|
+
`),n}var $e=C(L(),1),ts=e=>e!==void 0&&/[A-Za-z0-9]/.test(e);function Yn(e){let n=[],o="",i=()=>{o&&(n.push({text:o}),o="")},p=(x,h,v)=>(x===0||!ts(e[x-1]))&&(h+v>=e.length||!ts(e[h+v])),d=0;for(;d<e.length;){let x=e.slice(d,d+2),h=e[d];if(x==="**"||x==="__"){let v=e.indexOf(x,d+2);if(v!==-1&&v>d+2&&(x==="**"||p(d,v,2))){i(),n.push({text:e.slice(d+2,v),bold:!0}),d=v+2;continue}}if(h==="`"){let v=e.indexOf("`",d+1);if(v!==-1&&v>d+1){i(),n.push({text:e.slice(d+1,v),code:!0}),d=v+1;continue}}if(h==="*"||h==="_"){let v=e.indexOf(h,d+1);if(v!==-1&&v>d+1&&(h==="*"||p(d,v,1))){i(),n.push({text:e.slice(d+1,v),italic:!0}),d=v+1;continue}}o+=h,d+=1}return i(),n.length===0&&n.push({text:""}),n}function Jn(e){return e.map((n,o)=>(0,$e.jsx)(t,{bold:n.bold,italic:n.italic,color:n.code?r.dim:void 0,children:n.text},o))}function Ra(e){return e.split(`
|
|
5
|
+
`).map(n=>{if(n.trim()==="")return{kind:"blank"};let o=n.match(/^\s*[-*+]\s+(.*)$/);if(o)return{kind:"bullet",segs:Yn(o[1])};let i=n.match(/^\s*(\d+)\.\s+(.*)$/);if(i)return{kind:"numbered",n:i[1],segs:Yn(i[2])};let p=n.match(/^#{1,6}\s+(.*)$/);return p?{kind:"heading",segs:Yn(p[1])}:{kind:"para",segs:Yn(n)}})}function ka(e,n,o=""){switch(e.kind){case"blank":return(0,$e.jsx)(t,{children:o||" "},n);case"heading":return(0,$e.jsxs)(t,{bold:!0,children:[o,Jn(e.segs)]},n);case"bullet":return(0,$e.jsx)(f,{marginLeft:1,children:(0,$e.jsxs)(t,{children:[o,"\u2022 ",Jn(e.segs)]})},n);case"numbered":return(0,$e.jsx)(f,{marginLeft:1,children:(0,$e.jsxs)(t,{children:[o,`${e.n}. `,Jn(e.segs)]})},n);default:return(0,$e.jsxs)(t,{children:[o,Jn(e.segs)]},n)}}function ns({text:e}){let n=Ra(es(e));return(0,$e.jsxs)(f,{marginBottom:1,children:[(0,$e.jsx)(t,{color:r.generateAccent,children:"\u2503 "}),(0,$e.jsx)(f,{flexDirection:"column",children:n.map((o,i)=>ka(o,i))})]})}var Kr=C(L(),1);function Ca(e){return e.kind==="thinking-summary"?(0,Kr.jsx)(t,{color:r.dim,children:e.text}):(0,Kr.jsx)(ns,{text:e.text})}function rs(e,n,o){let i=(0,Qn.useRef)(Qi());(0,Qn.useEffect)(()=>{let{items:p,next:d}=Zi(i.current,e,n);i.current=d;for(let x of p)o(Ca(x))})}var xe=C(L(),1);function os({projectId:e,folderId:n,onSubmit:o,history:i,error:p,validationError:d,composeIdleHint:x,clearSeq:h,closedNotice:v}){return(0,xe.jsxs)(f,{flexDirection:"column",children:[(0,xe.jsx)(f,{marginLeft:2,marginTop:1,children:!(!!e&&!!n)&&(0,xe.jsxs)(t,{color:r.orange,children:["\u2691 ",(0,xe.jsx)(t,{color:r.muted,children:"project / folder not set \u2014 use "}),(0,xe.jsx)(t,{bold:!0,children:"/config"})]})}),d&&(0,xe.jsx)(f,{marginLeft:2,marginTop:1,children:(0,xe.jsx)(mt,{variant:"error",paddingY:0,children:(0,xe.jsx)(t,{color:r.red,children:d})})}),p&&(0,xe.jsx)(f,{marginLeft:2,marginTop:1,children:(0,xe.jsx)(mt,{variant:"error",paddingY:0,children:(0,xe.jsx)(t,{color:r.red,children:p})})}),v&&(0,xe.jsx)(f,{paddingX:1,children:(0,xe.jsx)(t,{color:r.dim,children:v})}),x&&(0,xe.jsx)(f,{marginLeft:2,marginTop:1,children:(0,xe.jsx)(t,{color:r.dim,children:x})}),(0,xe.jsx)(Tt,{onSubmit:o,history:i,noHistory:!0,accent:r.generateAccent,commands:qn("","generate"),clearSeq:h,clearOnSubmit:!1,placeholder:"Describe what to generate... (/ = commands)",footerBindings:[{keys:"\u21B5",label:"generate"},{keys:"tab",label:"complete"},{keys:"/run",label:"Run mode"},{keys:"ctrl+t",label:"thinking"}]})]})}var us=C(he(),1);var Te=C(L(),1);function Ia(e){return e?`[${e[0].toUpperCase()}]`:""}var Ea=8;function Zn({scenarios:e,headline:n,activeSid:o}){let i=e.slice(0,Ea),p=e.length-i.length;return(0,Te.jsxs)(f,{flexDirection:"column",marginBottom:1,marginLeft:2,children:[n&&(0,Te.jsx)(f,{paddingX:1,children:(0,Te.jsx)(t,{color:r.generateAccent,bold:!0,children:n})}),(0,Te.jsxs)(mt,{title:`Scenarios (${e.length})`,titleColor:r.generateAccent,borderColor:r.generateAccent,paddingX:1,children:[i.map(d=>{let x=!!o&&d.sid===o,h=x?"\u2237":"\u2713",v=x?r.generateAccent:r.green,w=d.test_cases?.length??0;return(0,Te.jsxs)(f,{gap:1,children:[(0,Te.jsx)(t,{color:v,children:h}),(0,Te.jsx)(t,{color:r.dim,children:d.sid??`#${d.id}`}),(0,Te.jsx)(t,{children:d.title??"(untitled)"}),(0,Te.jsx)(t,{color:r.muted,children:Ia(d.priority)}),(0,Te.jsxs)(t,{color:r.dim,children:[w," case",w===1?"":"s"]})]},d.id)}),p>0&&(0,Te.jsx)(t,{color:r.muted,children:`\u22EE +${p} more`}),(0,Te.jsx)(f,{marginTop:1,children:(0,Te.jsxs)(t,{color:r.dim,children:[(0,Te.jsx)(t,{color:r.generateAccent,children:"/view"})," inspect \xB7 ",(0,Te.jsx)(t,{color:r.generateAccent,children:"/save"})," save as runnable tests"]})})]})]})}var gt=C(L(),1),Ba=5;function is({thinking:e,expanded:n,thinkingDone:o,maxLines:i=Ba}){if(!n)return(0,gt.jsxs)(f,{paddingX:1,children:[(0,gt.jsx)(t,{color:r.dim,children:o?"\u2237 thinking complete ":"\u2237 thinking\u2026 "}),(0,gt.jsx)(t,{color:r.muted,children:o?"(ctrl+t to view)":"(ctrl+t to show)"})]});let p=e.split(`
|
|
6
|
+
`),d=Math.max(0,p.length-i),x=d>0?p.slice(-i).join(`
|
|
7
|
+
`):e;return(0,gt.jsxs)(mt,{variant:"default",paddingX:1,children:[d>0&&(0,gt.jsxs)(t,{color:r.muted,children:["\u22EE (",d," earlier line",d===1?"":"s"," hidden)"]}),(0,gt.jsx)(t,{color:r.dim,children:x}),o&&(0,gt.jsx)(t,{color:r.muted,children:"\u2014 thinking complete"})]})}var Wt=C(L(),1),ss=24;function _a(e){let n=Math.max(0,Math.min(100,e)),o=Math.round(n/100*ss);return{filled:"\u2588".repeat(o),empty:"\u2591".repeat(ss-o)}}function as({pct:e}){let n=_a(e);return(0,Wt.jsxs)(f,{paddingX:1,children:[(0,Wt.jsx)(t,{color:r.generateAccent,children:n.filled}),(0,Wt.jsx)(t,{color:r.muted,children:n.empty}),(0,Wt.jsx)(t,{color:r.dim,children:` ${e}%`})]})}var ht=C(L(),1);function cs(e,n){let o=e.trim();return o.startsWith("/")?{kind:"slash",text:o}:o?n?{kind:"ignore",text:o}:{kind:"refine",text:o}:{kind:"ignore",text:""}}function ls({state:e,history:n,turnActive:o,onClarificationAnswer:i,onClearError:p,onRefine:d,onSlash:x}){let h=i?v=>{p?.(),i(v)}:void 0;return(0,ht.jsxs)(ht.Fragment,{children:[e.pendingClarification&&h&&(0,ht.jsx)(f,{paddingX:1,marginTop:1,flexDirection:"column",children:(0,ht.jsx)(Tt,{onSubmit:h,history:n,noHistory:!0,accent:r.generateAccent,placeholder:"Type your answer\u2026",submitVerb:"answer",footerBindings:[{keys:"\u21B5",label:"answer"}]})}),!(e.pendingClarification&&h)&&(o?(0,ht.jsx)(Tt,{inert:!0,onSubmit:()=>{},history:n,placeholder:"(generating\u2026 input inert \u2014 Ctrl+C to cancel)"}):(0,ht.jsx)(Tt,{onSubmit:v=>{let w=cs(v,o);w.kind==="slash"?x?.(w.text):w.kind==="refine"&&d?.(w.text)},history:n,noHistory:!0,accent:r.generateAccent,commands:qn("","generate"),placeholder:"Refine, or /save \xB7 /view \xB7 /run",submitVerb:"refine",footerBindings:[{keys:"\u21B5",label:"refine"},{keys:"tab",label:"complete"},{keys:"/run",label:"Run mode"},{keys:"ctrl+t",label:"thinking"}]}))]})}var He=C(L(),1);function ds({state:e,requestId:n,history:o,onClarificationAnswer:i,error:p,onClearError:d,turnActive:x,onRefine:h,onSlash:v}){let[w,j]=(0,us.useState)(!1),R=e.thinking.length===0&&e.thinkingLog.length>0,B=[...e.thinkingLog.map(c=>c.text),e.thinking].filter(c=>c.length>0).join(`
|
|
8
|
+
|
|
9
|
+
`);return Re((c,u)=>{u.ctrl&&c==="t"&&j(D=>!D)}),(0,He.jsxs)(f,{flexDirection:"column",children:[(0,He.jsx)(f,{marginBottom:1,marginLeft:2,children:(0,He.jsx)(is,{thinking:B,expanded:w,thinkingDone:R})}),x&&(0,He.jsx)(f,{marginLeft:2,children:(0,He.jsx)(as,{pct:e.progress})}),p&&(0,He.jsx)(f,{marginLeft:2,marginTop:1,children:(0,He.jsx)(mt,{variant:"error",paddingY:0,children:(0,He.jsx)(t,{color:r.red,children:p})})}),e.scenarios.length>0&&(0,He.jsx)(Zn,{scenarios:e.scenarios,headline:e.headline,activeSid:null}),(0,He.jsx)(ls,{state:e,history:o,turnActive:x,onClarificationAnswer:i,onClearError:d,onRefine:h,onSlash:v})]})}var hs=C(he(),1);var Se=C(L(),1);function Aa(e,n,o){let i=(e.test_cases??[]).length;return Array.from({length:i},(p,d)=>Oe(n,d)).some(p=>!o.has(p))}function ms({scenarios:e,cursor:n,excluded:o}){let i=e.reduce((p,d)=>p+(d.test_cases??[]).length,0);return(0,Se.jsxs)(f,{flexDirection:"column",paddingX:1,children:[(0,Se.jsxs)(t,{children:[(0,Se.jsx)(t,{color:r.dim,children:"Generate \u203A "}),(0,Se.jsx)(t,{color:r.generateAccent,children:"Scenarios"}),(0,Se.jsx)(t,{color:r.dim,children:` ${e.length} scenarios \xB7 ${i} cases`})]}),(0,Se.jsx)(t,{color:r.muted,children:"\u2500".repeat(60)}),(0,Se.jsx)(f,{flexDirection:"column",marginY:1,children:e.map((p,d)=>{let x=d===n,h=Aa(p,d,o);return(0,Se.jsxs)(t,{children:[(0,Se.jsx)(t,{color:r.generateAccent,children:x?"\u276F ":" "}),(0,Se.jsx)(t,{color:r.generateAccent,children:`S${d+1}`}),(0,Se.jsx)(t,{children:` ${p.title??"(untitled)"}`}),(0,Se.jsx)(t,{color:r.dim,children:` [${p.priority??"-"}] ${(p.test_cases??[]).length} cases `}),(0,Se.jsx)(t,{color:h?r.green:r.red,children:h?"\u2713":"\u2717"})]},p.id)})}),(0,Se.jsx)(t,{color:r.muted,children:"\u2500".repeat(60)}),(0,Se.jsx)(t,{color:r.dim,children:"\u2191\u2193 move \u21B5 open x remove esc back to chat"})]})}var ve=C(L(),1);function fs({scenario:e,scenarioIdx:n,cursor:o,excluded:i}){let p=e.test_cases??[],d=p.some(x=>!rt(x));return(0,ve.jsxs)(f,{flexDirection:"column",paddingX:1,children:[(0,ve.jsxs)(t,{children:[(0,ve.jsx)(t,{color:r.dim,children:"Generate \u203A Scenarios \u203A "}),(0,ve.jsx)(t,{color:r.generateAccent,children:`S${n+1} ${e.title??"(untitled)"}`}),(0,ve.jsx)(t,{color:r.dim,children:` ${p.length} cases`})]}),(0,ve.jsx)(t,{color:r.muted,children:"\u2500".repeat(60)}),(0,ve.jsx)(f,{flexDirection:"column",marginY:1,children:p.map((x,h)=>{let v=h===o,w=i.has(Oe(n,h));return(0,ve.jsxs)(t,{children:[(0,ve.jsx)(t,{color:r.generateAccent,children:v?"\u276F ":" "}),(0,ve.jsx)(t,{color:r.generateAccent,children:`C${h+1}`}),(0,ve.jsx)(t,{children:` ${x.title??"(untitled)"} `}),rt(x)?(0,ve.jsx)(t,{color:w?r.red:r.green,children:w?"\u2717 removed":"\u2713 included"}):(0,ve.jsx)(t,{color:r.dim,children:"\u2713"})]},x.id)})}),(0,ve.jsx)(t,{color:r.muted,children:"\u2500".repeat(60)}),d&&(0,ve.jsx)(t,{color:r.dim,children:"gray \u2713 = non-functional \xB7 won't be saved by /save"}),(0,ve.jsx)(t,{color:r.dim,children:"\u2191\u2193 move \u21B5 view detail x remove case \u25C2 \u25B8 sibling \u2190 scenarios esc chat"})]})}var Ke=C(L(),1);function Yr({label:e,value:n}){return n?(0,Ke.jsxs)(f,{flexDirection:"column",marginBottom:1,children:[(0,Ke.jsx)(t,{color:r.dim,children:e}),(0,Ke.jsx)(f,{marginLeft:1,children:(0,Ke.jsx)(t,{children:n})})]}):null}function ps({n:e,step:n,expected:o}){return(0,Ke.jsxs)(f,{flexDirection:"column",marginBottom:1,children:[(0,Ke.jsxs)(t,{children:[(0,Ke.jsx)(t,{color:r.generateAccent,children:`${e}. `}),n]}),o?(0,Ke.jsx)(f,{marginLeft:3,children:(0,Ke.jsx)(t,{color:r.dim,children:`\u2192 ${o}`})}):null]})}var ie=C(L(),1);function gs({scenario:e,scenarioIdx:n,caseIdx:o,scroll:i,excluded:p,getStatus:d,getResult:x}){let h=(e.test_cases??[])[o],v=Oe(n,o),w=p.has(v),j=h?rt(h):!0,R=h&&d?d(h.id):void 0,B=R==="done"?(0,ie.jsx)(t,{color:r.generateAccent,children:"ready"}):R==="error"?(0,ie.jsx)(t,{color:r.red,children:"failed \u2192 raw steps"}):R==="pending"?(0,ie.jsx)(t,{color:r.dim,children:"bifurcating\u2026"}):null,c=R==="done"&&h&&x?x(h.id):void 0,u=c?c.sub_objectives.map(F=>({step:F.objective,expected:""})):ci(h?.manual_steps),D=[h?.priority&&`Priority ${h.priority}`,h?.polarity&&`Polarity ${h.polarity}`,h?.tags&&`Tags ${h.tags}`].filter(Boolean).join(" \xB7 ");return(0,ie.jsxs)(f,{flexDirection:"column",paddingX:1,children:[(0,ie.jsxs)(t,{children:[(0,ie.jsx)(t,{color:r.dim,children:`Generate \u203A S${n+1} \u203A `}),(0,ie.jsx)(t,{color:r.generateAccent,children:`C${o+1} ${h?.title??"(untitled)"}`}),B?(0,ie.jsx)(t,{children:" "}):null,B]}),j?(0,ie.jsx)(t,{color:w?r.red:r.green,children:w?"\u2717 removed":"\u2713 included"}):(0,ie.jsx)(t,{color:r.dim,children:"\u2713 non-functional \xB7 not saved by /save"}),(0,ie.jsx)(t,{color:r.muted,children:"\u2500".repeat(60)}),(0,ie.jsxs)(f,{flexDirection:"column",marginTop:1,children:[D?(0,ie.jsx)(f,{marginBottom:1,children:(0,ie.jsx)(t,{color:r.dim,children:D})}):null,(0,ie.jsx)(Yr,{label:"Description",value:h?.description}),(0,ie.jsx)(Yr,{label:"Preconditions",value:h?.preconditions}),u.length>0&&(0,ie.jsxs)(f,{flexDirection:"column",children:[(0,ie.jsx)(t,{color:r.dim,children:"Steps"}),(0,ie.jsx)(f,{flexDirection:"column",marginLeft:1,marginTop:0,children:u.slice(i).map((F,V)=>(0,ie.jsx)(ps,{n:i+V+1,step:F.step,expected:F.expected},V))})]})]}),(0,ie.jsx)(t,{color:r.muted,children:"\u2500".repeat(60)}),(0,ie.jsx)(t,{color:r.dim,children:"\u2191\u2193 scroll \u2190 back \u25C2 \u25B8 prev/next case x remove esc chat"})]})}var er=C(L(),1);function xs({scenarios:e,target:n,onClose:o,excluded:i,onToggleCase:p,onToggleScenario:d,getStatus:x,getResult:h}){let v=e.map(B=>(B.test_cases??[]).length),[w,j]=(0,hs.useReducer)((B,c)=>Xr(B,c,v),Kn(n));Re((B,c)=>{if(c.escape){o();return}if(c.upArrow){j(w.level==="detail"?{type:"scroll",delta:-1}:{type:"move",delta:-1});return}if(c.downArrow){j(w.level==="detail"?{type:"scroll",delta:1}:{type:"move",delta:1});return}if(c.return){j({type:"enter"});return}if(c.leftArrow){if(w.level==="scenarios"){o();return}j({type:"back"});return}if(B==="["){j({type:"sibling",delta:-1});return}if(B==="]"){j({type:"sibling",delta:1});return}if(B==="x"){w.level==="scenarios"?d(w.cursor,v[w.cursor]??0):p(w.scenarioIdx,w.level==="cases"?w.cursor:w.caseIdx);return}});let R=e[w.scenarioIdx];if(w.level==="scenarios"||R===void 0){let B=w.level==="scenarios"?w.cursor:0;return(0,er.jsx)(ms,{scenarios:e,cursor:B,excluded:i})}return w.level==="cases"?(0,er.jsx)(fs,{scenario:R,scenarioIdx:w.scenarioIdx,cursor:w.cursor,excluded:i}):(0,er.jsx)(gs,{scenario:R,scenarioIdx:w.scenarioIdx,caseIdx:w.caseIdx,scroll:w.scroll,excluded:i,getStatus:x,getResult:h})}var tr=C(L(),1);function vs({tcg:e,gm:n,history:o,tuiConfig:i,browse:p}){return p?(0,tr.jsx)(xs,{scenarios:e.state.scenarios,target:p.target,onClose:p.onClose,excluded:p.excluded,onToggleCase:p.onToggleCase,onToggleScenario:p.onToggleScenario,getStatus:p.getStatus,getResult:p.getResult}):!e.requestId||e.isSessionClosed?(0,tr.jsx)(os,{projectId:i.project_id,folderId:i.folder_id,onSubmit:n.handleGenerateSubmit,history:o,error:n.tcgError,validationError:n.tcgValidationError,composeIdleHint:n.composeIdleHint,clearSeq:n.inputClearSeq,closedNotice:e.isSessionClosed?`Generation ${e.state.status}. Type a new objective or /run.`:void 0}):(0,tr.jsx)(ds,{state:e.state,requestId:e.requestId,history:o,turnActive:e.turnActive,error:n.tcgError??e.state.error,onClearError:()=>n.onClearError?.(),onClarificationAnswer:d=>n.onClarificationAnswer?.(d),onRefine:n.onRefine,onSlash:n.onSlash})}var bs=C(he(),1);var st=C(L(),1);function Pa({message:e,confirmLabel:n,choice:o}){return(0,st.jsxs)(f,{flexDirection:"column",borderStyle:"round",borderColor:r.dim,paddingX:1,children:[(0,st.jsx)(t,{bold:!0,children:e}),(0,st.jsxs)(f,{marginTop:1,children:[(0,st.jsx)(t,{color:o==="yes"?r.red:r.dim,children:`\u276F ${n}`}),(0,st.jsx)(t,{children:" "}),(0,st.jsx)(t,{color:o==="no"?r.green:r.dim,children:"\u276F No"})]}),(0,st.jsx)(t,{color:r.dim,children:"\u2190 \u2192 choose \xB7 \u21B5 confirm \xB7 esc cancel"})]})}function ys({message:e,onConfirm:n,onCancel:o,confirmLabel:i="Yes, end"}){let[p,d]=(0,bs.useState)("no");return Re((x,h)=>{(h.leftArrow||h.rightArrow)&&d(v=>v==="yes"?"no":"yes"),h.return&&(p==="yes"?n:o)(),h.escape&&o()}),(0,st.jsx)(Pa,{message:e,confirmLabel:i,choice:p})}var Da=null;function Ts(e){Da=e}import{join as zt,resolve as La}from"path";var nr=C(L(),1);function Ss({status:e,steps:n,duration:o,creditsConsumed:i,reason:p}){let d=e==="passed",x=d?r.green:r.red,h=d?"\u2713":"\u2717",v=d?"Passed":"Failed",w=o<60?`${o.toFixed(1)}s`:`${Math.floor(o/60)}m ${Math.round(o%60)}s`,j=typeof i=="number"&&i>0?` \xB7 ${i.toFixed(4)} credits`:"",R=!d&&p?` \xB7 ${p}`:"";return(0,nr.jsxs)(f,{children:[(0,nr.jsxs)(t,{bold:!0,color:x,children:[h," ",v]}),(0,nr.jsxs)(t,{color:r.dim,children:[" ","\xB7 ",n," steps \xB7 ",w,j,R]})]})}var Rs=C(L(),1);function ws(){return(0,Rs.jsx)(t,{color:r.dim,children:"Continue below \xB7 /new fresh session \xB7 /summary view details \xB7 Ctrl+C exit"})}var rr=e=>({kind:"login",env:e}),Jr=e=>({kind:"switch",env:e}),ks=(e,n)=>e?{kind:"switch",env:n}:{kind:"logout"};async function Cs(e){await new sn(e.tmsBaseUrl,e.username,e.accessKey).submitFeedback({instruction_id:"",test_id:e.testId,feedback_type:e.feedbackType,mode:e.mode??"human",...e.details?{details:e.details}:{}}),e.log("info","FEEDBACK_SUBMITTED","Feedback submitted",{type:e.feedbackType})}var b=C(L(),1);function ef({localMode:e=!1,codeExport:n,codeLanguage:o,skipCodeValidation:i,updatePromise:p,migrationResult:d,sessionName:x,initialChatMode:h,initialObjective:v,initialGenerateLimits:w}={}){go();let j=(0,T.useRef)(new jn),[R,B]=(0,T.useState)(0),c=j.current,[u]=(0,T.useState)(()=>new Nt),D=(0,T.useRef)(0),F=(0,T.useCallback)(()=>`msg-${++D.current}`,[]),[V,O]=(0,T.useState)(!1),[U,E]=(0,T.useState)(null),[M,Y]=(0,T.useState)(!1),[K,we]=(0,T.useState)(0),[q,ue]=(0,T.useState)(!1),[se,Ye]=(0,T.useState)(null),[xt,Je]=(0,T.useState)(null),kt=(0,T.useRef)(null),[De,Pt]=(0,T.useState)(null),[hn,Xt]=(0,T.useState)(Mn()),[Fe,Ct]=(0,T.useState)(null),[Le,xn]=(0,T.useState)([]),[or,H]=(0,T.useState)(!1),[ee,de]=(0,T.useState)(!1),[J,Be]=(0,T.useState)(null),[pe,Qe]=(0,T.useState)(null),[Kt,vt]=(0,T.useState)(null),at=(0,T.useRef)(null),vn=(0,T.useRef)(null),_e=(0,T.useRef)(0),It=(0,T.useRef)(""),bn=(0,T.useRef)(null),ce=(0,T.useRef)(null),Dt=(0,T.useRef)({}),yn=(0,T.useRef)(null),{append:Qr}=bo(),re=(0,T.useCallback)(a=>Qr((0,b.jsx)(f,{paddingX:1,children:a})),[Qr]),[Yt,Ze]=(0,T.useState)("booting"),[Is,Es]=(0,T.useState)([]),[Bs,ir]=(0,T.useState)(!1),[Zr,_s]=(0,T.useState)(!1),[Tn,As]=(0,T.useState)("chat"),[et,Jt]=(0,T.useState)(null),[Sn,eo]=(0,T.useState)(null),[Qt,to]=(0,T.useState)(!1),[Zt,wn]=(0,T.useState)(!1),no=(0,T.useRef)(()=>{}),Ps=(0,T.useCallback)((a,m)=>no.current(a,m),[]),z=Fi({log:Ps});rs(z.state,z.turnActive,re);let sr=(0,T.useRef)(!1),ct=(0,T.useCallback)(()=>{sr.current||z.state.scenarios.length!==0&&(sr.current=!0,re((0,b.jsx)(Zn,{scenarios:z.state.scenarios,activeSid:null})))},[z.state.scenarios,re]);(0,T.useEffect)(()=>{z.isSessionClosed&&ct()},[z.isSessionClosed,ct]);let[Rn,en]=(0,T.useState)(null),[te,tn]=(0,T.useState)({headless:!1,maxSteps:50,timeout:0,cdpEndpoint:"",wsEndpoint:"",useCft:!1}),ro=vo(),g=Ii(),kn=Ei(),Ne=(0,T.useMemo)(()=>({auth:{initResolver:a=>g.initResolver(a,(m,s,l,y)=>j.current.log(m,s,l,y)),getResolver:()=>g.getResolver(),getBasicAuth:()=>g.getBasicAuth(),getToken:()=>g.getToken()},getSession:()=>j.current,log:(a,m,s,l)=>j.current.log(a,m,s,l),state:{getTmsCredsCache:()=>Fe,setTmsCredsCache:Ct,identityServicesRef:vn,screenshotQueueRef:at},exit:{registerCleanup:tt,setExitRemoteLogger:Co},options:{skipScreenshotQueue:e}}),[g.initResolver,g.getResolver,g.getBasicAuth,g.getToken,Fe,e]),Ds=(0,T.useCallback)((a,m,s)=>{let l=at.current;if(!l)return;let y=_e.current+m;zo(c.sessionDir,y,a,l,(P,$,N,W)=>c.log(P,$,N,W),s)},[c]),Ls=(0,T.useCallback)((a,m,s)=>{c.logStep(a,m,s)},[c]),js=(0,T.useCallback)(a=>yn.current?.setStepText(a),[]),Ms=(0,T.useCallback)(()=>yn.current?.setStepComplete(),[]),_=jo(Ds,Ls,js,Ms),[k,ge]=(0,T.useState)(()=>u.load()),[,Vs]=(0,T.useState)(0),Ae=(0,T.useCallback)(()=>Vs(a=>a+1),[]),[I,me]=(0,T.useState)(null),Lt=g.creds.getActiveProfile(),oe=g.creds.getDefaultEnv(),We=(0,T.useCallback)((a,m)=>{let s=a?g.creds.loadProfileConfig(a,m):null;u.save({project_id:s?.project_id??null,project_name:s?.project_name??null,folder_id:s?.folder_id??null,folder_name:s?.folder_name??null}),ge(u.load())},[g.creds,u]),ar=(0,T.useCallback)(async(a,m)=>{let s=g.getResolver();if(!s)return null;let l=s.cached??await s.resolve();if(!l)return null;let y=Ve(m),P=new sn(y.tmsBaseUrl,l.username,l.access_key);try{let N=(await P.listProjects()).find(Q=>Q.name==="KaneAI Generated");if(N)return{id:N.project_id,name:N.name};let W=await P.createProject("KaneAI Generated");return{id:W.id,name:W.name}}catch{return null}},[g]),cr=(0,T.useCallback)(async(a,m)=>{let s=g.getResolver();if(!s)return null;let l=s.cached??await s.resolve();if(!l)return null;let y=Ve(a),P=new sn(y.tmsBaseUrl,l.username,l.access_key);try{let N=(await P.listFolders(m)).find(Q=>Q.name==="Untitled");if(N)return{id:N.id,name:N.name};let W=await P.createFolder(m,"Untitled");return{id:W.id,name:W.name}}catch{return null}},[g]);(0,T.useEffect)(()=>{M||(c.start({model:k.model,environment:oe,profile:Lt}),x&&c.setSessionName(x),Y(!0))},[c,M,k.model,oe,Lt,x]);let oo=(0,T.useRef)(!1);(0,T.useEffect)(()=>{if(!M||oo.current)return;oo.current=!0;let a=x?[{label:"session",value:x},{label:"test",value:yr(zt(process.cwd(),".testmuai","tests",`${x}_test.md`))},{label:"output",value:yr(zt(process.cwd(),".testmuai","tests",`output-${x}`))}]:[{label:"session",value:"ephemeral"},{label:"note",value:"use /name <name> to persist this session"}];re((0,b.jsx)(Sr,{title:"Recording",titleColor:"#ff9500",rows:a}))},[M,x,re]);let io=(0,T.useRef)(!1);(0,T.useEffect)(()=>{if(!V||io.current||!M)return;io.current=!0;let a=Ne.state.getTmsCredsCache();if(!a){c.log("warn","BOOT_RESOLVE_FAILED","Boot done but tmsCredsCache empty \u2014 non-controller APIs may fail");return}nt({kind:"boot",tmsCreds:a,env:oe},Ne).then(m=>{m&&(a.org_id!==void 0&&c.setOrgId(String(a.org_id)),c.setPlan(a.plan??null),c.log("info","BOOT_RESOLVE_OK","Boot identity attached",{username:a.username,org_id:a.org_id,plan:a.plan??null}))}).catch(m=>{c.log("error","BOOT_RESOLVE_ERROR","Boot identity attach error",{error:m instanceof Error?m.message:String(m)})})},[V,M,Ne,oe,c]);let Et=(0,T.useCallback)(async()=>{if(Fe)return c.log("info","TMS_CREDS_CACHED","Using cached TMS credentials",{username:Fe.username,org_id:Fe.org_id}),Fe;let a=await g.resolveBasicAuth();return a?(c.log("info","TMS_CREDS_OK","TMS credentials resolved",{username:a.username,org_id:a.org_id,user_id:a.user_id}),Ct(a)):c.log("warn","TMS_CREDS_FAILED","No TMS credentials resolved"),a},[g,Fe,c]),Cn=(0,T.useCallback)(a=>{re((0,b.jsx)(Sr,{title:"\u24D8 Auto-configured",titleColor:r.orange,rows:[{label:"project",value:`${a.projectName} (${a.projectId})`},{label:"folder",value:`${a.folderName} (${a.folderId})`},{label:"change with",value:(0,b.jsxs)(f,{flexDirection:"column",children:[(0,b.jsx)(t,{color:r.dim,children:"kane-cli config project <id>"}),(0,b.jsx)(t,{color:r.dim,children:"kane-cli config folder <id>"})]})}]}))},[re]),so=(0,T.useCallback)(async()=>{let a=await Et();if(!a)return c.log("warn","PROJECT_FAILED","No TMS credentials for project/folder gate"),null;let m=g.creds.getActiveProfile()??"default",s=g.creds.getDefaultEnv(),l=await Io({creds:g.creds,config:u,profile:m,env:s,tmsCreds:{username:a.username,access_key:a.access_key},isLocal:e,log:(y,P,$,N)=>c.log(y,P,$,N),onAnnounce:Cn});return l.status==="ok"?{projectId:l.projectId,folderId:l.folderId}:null},[Et,u,c,g.creds,e,Cn]),ae=(0,T.useCallback)(a=>{let m=F(),s={...a,id:m};re((0,b.jsx)(wi,{entry:s}))},[F,re]),A=(0,T.useCallback)((a,m,s,l,y)=>{re((0,b.jsx)(Di,{status:a,command:m,message:s,details:l,accentColor:y})),m==="/save"&&a==="ok"&&re((0,b.jsx)(f,{marginLeft:2,children:(0,b.jsxs)(t,{color:r.dim,children:["\u2192 Run ",(0,b.jsx)(t,{color:r.generateAccent,children:"/testmd"})," to list your saved tests."]})}))},[re]),ao=(0,T.useRef)(()=>{}),bt=Ji(z.state.scenarios.map(a=>(a.test_cases??[]).length)),lt=Ki({tcg:z,initialChatMode:h,tuiConfig:k,auth:g,session:c,runner:_,appendStatic:re,handleInput:a=>ao.current(a),freezeTcgArtifact:ct,rearmArtifactFreeze:()=>{sr.current=!1},openSwitchConfirm:a=>en({reason:"switch",to:a}),emitFeedback:A,excluded:bt.excluded,openBrowse:bt.open,initialGenerateLimits:w});no.current=lt.tcgLog;let{chatMode:fe,tcgError:Ma,tcgValidationError:Va,composeIdleHint:Oa,inputClearSeq:Os,handleGenerateSubmit:$s,flashComposeHint:In,setTcgError:$a}=lt,lr=(0,T.useCallback)(async(a,m)=>{let s=Yo({objective:a,globalDir:zt(Me,"variables"),localDir:zt(process.cwd(),".testmuai","variables")}),l=c.nextRunIndex();_e.current=l,It.current=s.auteurObjective,c.logRunStart(l,s.auteurObjective,m??""),c.setFirstRun(s.auteurObjective,m??"");let y=g.getResolvedBasicAuth(),P=y,$=null;if(!P&&($=await g.getToken(),!$)){ae({type:"error",text:"Not authenticated. Run /login first."});return}let N={basicAuth:y??null,token:$,resolver:g.getResolver(),resolvedCreds:null};bn.current=N;let W=g.creds.getActiveProfile()??"default",Q=g.creds.getDefaultEnv();ko(g.creds,u,W,Q,(le,je,dt,ze)=>c.log(le,je,dt,ze));let Pe=u.load();if(ge(Pe),l===0&&!e){c.log("info","ATM_CREATE_START","Creating test via ATM endpoint",{run_index:0});let le=await so(),je=u.load();ge(je);let dt=Ve(oe),ze=P?{username:P.username,access_key:P.access_key}:await Et();if(ze){let yt=await ei({tmsBaseUrl:dt.tmsBaseUrl,auth:{username:ze.username,access_key:ze.access_key},objective:s.auteurObjective,url:m??k.default_url??"",projectId:le?.projectId??je.project_id??"",folderId:le?.folderId??je.folder_id??"",hasCustomProfile:!!k.chrome_profile_path,log:(br,Hs,Ws,zs)=>c.log(br,Hs,Ws,zs)});yt&&(c.setTestId(yt),le?.projectId&&c.setProjectId(le.projectId))}}let Ue=null;if(te.useCft)ae({type:"info",text:"CfT mode: Playwright will manage browser"});else if(te.wsEndpoint)ae({type:"info",text:`WS endpoint: ${te.wsEndpoint.slice(0,60)}...`});else if(te.cdpEndpoint)ae({type:"info",text:`CDP endpoint: ${te.cdpEndpoint}`});else{ae({type:"info",text:"Starting Chrome..."});try{Ue=await kn.ensureChrome(m)}catch(je){ae({type:"error",text:Po(je)});return}c.logChromeLaunch(Ue.port,Ue.cdpEndpoint),ae({type:"info",text:`Chrome ready (port ${Ue.port})`});let le=Lo({headless:te.headless,cdpEndpoint:Ue.cdpEndpoint,chromePid:Ue.process.pid});le&&(yn.current=le,tt("marker-overlay",()=>le.kill()))}c.setAuteurVariables(s.auteur),ce.current=s;let jt=P&&!e?await Jo({variables:s,auth:P,orgId:String((await Et())?.org_id??""),env:oe,localMode:e,log:(le,je,dt,ze)=>c.log(le,je,dt,ze)}):{};Dt.current=jt;let ut=Er(zt(Me,"global-memory.md")),Mt=Er(zt(process.cwd(),".testmuai","context.md")),nn=Ue?{cdpEndpoint:Ue.cdpEndpoint,instance:Ue,tempDir:null}:te.wsEndpoint?{wsEndpoint:te.wsEndpoint,instance:null,tempDir:null}:te.cdpEndpoint?{cdpEndpoint:te.cdpEndpoint,instance:null,tempDir:null}:{instance:null,tempDir:null};if(l===0){let le={mode:k.mode,max_steps:te.maxSteps,timeout:te.timeout>0?te.timeout:void 0,target:Ue?"chrome":te.cdpEndpoint?"cdp":te.wsEndpoint?"ws":void 0,chrome_profile:k.chrome_profile_path||void 0,cdp_endpoint:te.cdpEndpoint||void 0,ws_endpoint:te.wsEndpoint||void 0,headless:te.headless,global_context:ut??void 0,local_context:Mt??void 0,variables:Object.keys(s.auteur).length>0?s.auteur:void 0};c.setResolvedGlobal(le)}let Vt=Ko(s.auteur,s.auteurObjective),Pn=Xo({objective:s.auteurObjective,url:m,model:k.model,chrome:nn,auth:N,sessionId:c.sessionId,runIndex:l,windowSize:k.window_size,maxSteps:te.maxSteps,headless:te.headless,variables:Object.keys(Vt).length>0?Vt:void 0,globalContext:ut??void 0,localContext:Mt??void 0,sessionContext:c.getContext()});m&&E(m),Ye(null),_.startRun(Pn,{environment:oe,mode:k.mode,log:(le,je,dt,ze)=>c.log(le,je,dt,ze)}),we(le=>le+1)},[g,kn,u,k,c,oe,_,ae,te,so,Et]),Fs=(0,T.useCallback)(async a=>{let m=La(a),s=Go(m),l=new jn,y=g.getResolvedBasicAuth(),P=null;y||(P=await g.getToken());let $={basicAuth:y??null,token:P,resolver:g.getResolver(),resolvedCreds:null},N=oe,W=Ve(N),Q=g.creds.getActiveProfile()??"default";return{path:m,cwd:process.cwd(),opts:{},isAgent:!1,resolved:s,resolvedAuth:$,cliOverrides:{},environment:N,envConfig:W,profile:Q,model:"v16-alpha",creds:g.creds,configStore:u,session:l,skipGlobalRemoteLogger:!0,onAnnounce:Cn}},[g,u,oe,Cn]),ne=$i({buildInput:Fs,remoteLogger:null}),ur=(0,T.useRef)(null);(0,T.useEffect)(()=>{if(_.bifurcationInfo&&_.bifurcationInfo!==ur.current){ur.current=_.bifurcationInfo;let{flows:a,isSingleFlow:m}=_.bifurcationInfo;if(m&&a.length===1&&a[0])c.log("info","OBJECTIVE_REWRITTEN","Objective rewritten",{objective:a[0]}),ae({type:"info",text:`Objective: ${a[0]}`});else if(!m&&a.length>1){let s=[`Bifurcated into ${a.length} flows:`];a.forEach((l,y)=>s.push(` ${y+1}. ${l}`)),c.log("info","BIFURCATION","Objective bifurcated into flows",{flow_count:a.length}),ae({type:"info",text:s.join(`
|
|
10
|
+
`)})}}},[_.bifurcationInfo,c,ae]);let dr=T.default.useRef(null),mr=T.default.useRef(0),fr=T.default.useRef(0);(0,T.useEffect)(()=>{if(_.lastRunEnd&&_.lastRunEnd!==dr.current){dr.current=_.lastRunEnd;let{status:a,duration:m,summary:s,reason:l,context:y}=_.lastRunEnd,{passed:P,failed:$,total:N}=Mo(_.steps);mr.current+=N,fr.current+=m??0,Ye({status:a,duration:m??0,summary:s??"",stepsPassed:P,stepsFailed:$,stepsTotal:N,reason:l,finalState:_.lastRunEnd?.final_state,creditsConsumed:_.lastRunEnd?.credits_consumed}),c.logRunEnd(_e.current,a,m,s);let W=_.bifurcationInfo,Q=W&&!W.isSingleFlow?W.flows:null,Pe=wo(_.lastRunEnd,_e.current,Q),Ue=Ro(_.lastRunEnd,It.current,_e.current,Pe);c.addRunResult(Ue,_.lastRunEnd?.total_runs);let jt=_.lastRunEnd?.per_flow_metadata;if(W&&!W.isSingleFlow&&jt&&jt.length>1)for(let ut=0;ut<jt.length;ut++){let Mt=jt[ut],nn=_.steps[ut],Vt=nn?.children??[],Pn=Vt.filter(yt=>yt.status==="passed").length,le=Vt.filter(yt=>yt.status==="failed").length,je=Vt.reduce((yt,br)=>yt+(br.duration??0),0),dt=nn?.status==="failed"?"failed":"passed",ze=W.flows[ut]??nn?.objective??It.current;c.addFlow({runIndex:_e.current,flowId:W.flows[ut],objective:ze,status:dt,summary:Mt.summary??"",duration:je,steps:Pn+le,stepsPassed:Pn,stepsFailed:le,reason:Mt.error_message??void 0,creditsConsumed:Mt.credits_consumed??void 0})}else c.addFlow({runIndex:_e.current,objective:It.current,status:a,summary:s??"",duration:m??0,steps:N,stepsPassed:P,stepsFailed:$,reason:l,creditsConsumed:_.lastRunEnd?.credits_consumed})}},[_.lastRunEnd,c,ae]);let pr=(0,T.useRef)(null);(0,T.useEffect)(()=>{_.askingUser&&(pr.current=_.askingUser)},[_.askingUser]);let gr=(0,T.useRef)(null);(0,T.useEffect)(()=>{if(se&&!_.isRunning&&_.lastRunEnd){if(gr.current===_.lastRunEnd)return;gr.current=_.lastRunEnd,re((0,b.jsxs)(f,{flexDirection:"column",children:[(0,b.jsx)(Ss,{status:se.status,steps:se.stepsTotal,duration:se.duration,creditsConsumed:se.creditsConsumed,reason:se.reason}),(0,b.jsx)(ws,{})]})),Ye(null)}},[se,_.isRunning,_.lastRunEnd,re]);let co=(0,T.useRef)(null);(0,T.useEffect)(()=>{if(ne.runSummary&&!ne.running){if(co.current===ne.runSummary)return;co.current=ne.runSummary,(ne.summary||ne.links)&&re((0,b.jsxs)(f,{flexDirection:"column",children:[ne.summary&&(0,b.jsx)(Wo,{data:ne.summary}),ne.links&&(0,b.jsx)(Vn,{...ne.links,autoExit:!1})]}))}},[ne.runSummary,ne.running,ne.summary,ne.links,re]),(0,T.useEffect)(()=>{yn.current?.setRunActive(_.isRunning)},[_.isRunning]),(0,T.useEffect)(()=>{if(_.runError&&!_.isRunning){let a=_.runError.trim();c.log("error","RUNNER_ERROR","Runner error occurred",{error:a}),c.escalateRun(c.nextRunIndex()-1);let s=a.split(`
|
|
11
|
+
`).slice(-8).join(`
|
|
12
|
+
`);ae({type:"error",text:`Runner error:
|
|
13
|
+
${s}`})}},[_.runError,_.isRunning,ae,c]);let En=(0,T.useCallback)(async()=>{c.log("info","EXIT_UPLOAD_START","Starting exit upload pipeline"),Xt(Mn()),Pt({status:"uploading"});let a=g.getResolvedBasicAuth(),m=null;if(!a&&(m=await g.getToken(),!m))return c.log("warn","EXIT_UPLOAD_ABORTED","Exit upload aborted \u2014 no auth available"),null;let s=Fe??await Et();if(!s)return c.log("warn","EXIT_UPLOAD_ABORTED","Exit upload aborted \u2014 no TMS credentials"),c.setUploadStatus("failed","Could not get TMS credentials"),null;c.log("info","EXIT_UPLOAD_CONFIG","Exit upload configuration",{test_id:c.testId,commit_id:c.sessionId,project_id:k.project_id,session_dir:c.sessionDir,run_dirs:c.getRunDirs()});let l={basicAuth:a??null,token:m,resolver:g.getResolver(),resolvedCreds:s};at.current&&(c.log("info","SCREENSHOT_UPLOAD_DRAIN","Draining screenshot queue before pipeline"),await at.current.drain(),c.log("info","SCREENSHOT_UPLOAD_DRAINED","Screenshot queue drained"));let y=Qo({session:c,env:oe,auth:l,variables:ce.current??{raw:{},auteur:{},auteurObjective:"",secretEntries:[],nonSecretEntries:[]},variableIds:Dt.current,projectId:k.project_id,folderId:k.folder_id,totalSteps:mr.current,totalDuration:fr.current,screenshotExtMap:at.current?.getExtMap(),codeExport:Zo({codeExport:n,codeLanguage:o,skipCodeValidation:i},k.code_export),onProgress:(N,W,Q)=>{c.log("info","EXIT_PROGRESS","Upload progress",{step:N,status:W,detail:Q}),Xt(Pe=>Ho(Pe,N,W,Q))},log:(N,W,Q,Pe)=>c.log(N,W,Q,Pe),shouldUploadArtifacts:!0,shouldReplaceLocalOutput:!1,shouldCommit:!1,isFirstRun:!0}),$=await new ti(y).execute();if($.success){c.log("info","EXIT_UPLOAD_OK","Exit upload succeeded",{test_id:$.testId,testcase_id:$.testcaseId??null,share_id:$.shareId??null}),c.setUploadStatus("uploaded"),$.testId&&c.setTestId($.testId),$.testcaseId&&c.setTestcaseId($.testcaseId);let N=Ve(oe),W=k.project_id,Q=$.testcaseId&&$.shareId&&W?Cr(N.testManagerUiUrl,W,$.testcaseId,$.shareId):void 0,Pe=$.testcaseId&&W?Ir(N.testManagerUiUrl,W,$.testcaseId):void 0;Pt({status:"success",testUrl:Q,testCaseLink:Pe,codeExportDir:$.codeExportDir}),Ts({shareableLink:Q,testCaseLink:Pe,codeExportDir:$.codeExportDir})}else c.log("error","EXIT_UPLOAD_FAILED","Exit upload failed",{error:$.error}),c.setUploadStatus("failed",$.error),Pt({status:"failed",error:$.error});return $},[g,oe,c,k,Fe,Et]),Bn=(0,T.useCallback)(async()=>{c.log("info","SESSION_RESET_START","Starting session reset via /new"),H(!0);let a=c.getFlows();a.length>0&&re((0,b.jsx)(qr,{flows:a}));let m=null;if(!e)try{m=await En()??null}catch(y){c.log("error","SESSION_RESET_UPLOAD_FAILED","Upload failed during /new",{error:String(y)}),ae({type:"error",text:"Upload failed \u2014 session data saved locally."})}let s=null;try{let{persistRecordedSession:y}=await import("./persist-recorded-session-WBPLUA55.js");s=y(c,{testcaseId:c.testcaseId??void 0,projectId:k.project_id??void 0,folderId:k.folder_id??void 0,codeExportDir:m?.codeExportDir})}catch(y){c.log("error","SESSION_RESET_PERSIST_FAILED","Persist failed during /new",{error:String(y)})}if(m?.success&&m.testcaseId||s){let y=Ve(oe),P=k.project_id,$=m?.testcaseId;re((0,b.jsx)(Vn,{recordedTestPath:s?.recordedTestPath,outputDir:s?.outputDir,shareableLink:$&&m?.shareId&&P?Cr(y.testManagerUiUrl,P,$,m.shareId):void 0,testCaseLink:$&&P?Ir(y.testManagerUiUrl,P,$):void 0,codeExportDir:m?.codeExportDir,autoExit:!1}))}c.testId&&xn(y=>[...y,{testId:c.testId,runCount:K}]),kn.killChrome(),await c.finish("complete");let l=new jn;l.start({model:k.model,environment:oe,profile:Lt??null}),j.current=l,B(y=>y+1),c.log("info","SESSION_RESET_COMPLETE","Session reset complete",{new_session_id:l.sessionId}),await nt({kind:"resessionize",env:oe},Ne),we(0),mr.current=0,fr.current=0,_e.current=0,It.current="",ce.current=null,Dt.current={},An.current=0,xr.current=0,pr.current=null,gr.current=null,dr.current=null,ur.current=null,Ye(null),E(null),Pt(null),Xt(Mn()),H(!1),re((0,b.jsxs)(f,{flexDirection:"column",marginY:1,children:[(0,b.jsx)(t,{color:r.dim,children:"\u2500".repeat(44)}),(0,b.jsx)(t,{color:r.green,bold:!0,children:"New session started"})]}))},[c,ae,re,e,En,kn,K,k,oe,Lt,Ne]),lo=(0,T.useCallback)(async()=>{if(!(c.nextRunIndex()>0)){ae({type:"info",text:"No runs in current session."});return}if(_.isRunning){ae({type:"error",text:"Cannot reset while a run is in progress. Cancel the run first."});return}if(k.mode==="testing"&&!c.sessionName){Qe("new"),Be(_r());return}await Bn()},[c,_,ae,k.mode,Bn]),uo=(0,T.useCallback)(async()=>{await c.finish("complete"),Ut(0,"Session complete")},[c]),Ns=(0,T.useCallback)(async a=>{de(!1);let m=c.testId??(Le.length>0?Le[Le.length-1].testId:null);if(a&&m){c.log("info","EXIT_FEEDBACK_SUBMIT","Submitting session feedback",{choice:a});try{let s=Ve(oe),l=g.getResolvedBasicAuth();l&&await Cs({tmsBaseUrl:s.tmsBaseUrl,username:l.username,accessKey:l.access_key,testId:m,feedbackType:a,log:(y,P,$,N)=>c.log(y,P,$,N)})}catch(s){c.log("error","EXIT_FEEDBACK_FAILED","Feedback submission failed",{error:String(s)})}}else c.log("info","EXIT_FEEDBACK_SKIPPED","Feedback skipped");uo()},[oe,g,c,uo,Le]),_n=(0,T.useCallback)(async()=>{let a=c.nextRunIndex()>0,m=null;if(a&&!e){c.log("info","EXIT_WITH_ACTIVE_SESSION","Exit with active session \u2014 uploading first"),ue(!0);try{m=await En()??null}catch(l){c.log("error","EXIT_UPLOAD_FAILED","Exit upload failed",{error:String(l)})}c.testId&&xn(l=>[...l,{testId:c.testId,runCount:K}])}try{let{persistRecordedSession:l}=await import("./persist-recorded-session-WBPLUA55.js"),y=l(c,{testcaseId:c.testcaseId??void 0,projectId:k.project_id??void 0,folderId:k.folder_id??void 0,codeExportDir:m?.codeExportDir});y&&vt(y)}catch(l){c.log("error","EXIT_PERSIST_FAILED","Persist failed during /exit",{error:String(l)})}if(a&&!e&&await c.finish("complete"),!(c.testId??(Le.length>0?Le[Le.length-1].testId:null))||e){await c.finish("complete"),Ut(0,"No test ID \u2014 quick exit");return}ue(!0),de(!0)},[c,e,En,K,Le,k]),Bt=(0,T.useCallback)(async()=>{if(q)return;c.log("info","EXIT_START","TUI exit initiated");let a=k.mode==="testing",m=c.nextRunIndex()>0;if(a&&m&&!c.sessionName){Qe("exit"),Be(_r());return}await _n()},[q,c,k.mode,_n]),Us=(0,T.useCallback)(a=>{a&&c.setSessionName(a);let m=pe;Be(null),Qe(null),m==="new"?Bn():_n()},[c,pe,_n,Bn]);(0,T.useEffect)(()=>{if(!q)return;let a=300*1e3,m=setTimeout(async()=>{c.setUploadStatus("failed","Upload timed out after 5m"),await c.finish("complete"),Ut(0,"Upload timed out after 5m")},a);return()=>clearTimeout(m)},[q,c]);let An=T.default.useRef(0),hr=T.default.useRef(null),xr=T.default.useRef(0);Re((a,m)=>{if(m.ctrl&&a==="c"){if(fe==="generate"&&z.isStreaming){ct(),z.cancel();return}if(!ne.running){if(q){xr.current+=1,xr.current>=2&&(c.setUploadStatus("pending","Force exit by user"),c.finish("complete"),Ut(0,"Force exit by user"));return}if(_.isRunning){_.cancelRun(),ae({type:"info",text:"Run cancelled."}),An.current++,hr.current&&clearTimeout(hr.current),hr.current=setTimeout(()=>{An.current=0},2e3),An.current>=2&&Bt();return}Bt()}}}),Re((a,m)=>{if(m.ctrl&&a==="t"&&fe==="generate"&&!z.isStreaming){In("no thinking yet");return}});let mo=T.default.useMemo(()=>{let a=g.creds.getActiveProfile()??"none",m=g.creds.getDefaultEnv();return[{id:"run",label:"Run",type:"submenu",children:[{id:"run-start",label:"Start Run",type:"action"},{id:"run-config",label:"Run Config",type:"submenu",children:[{id:"run-headless",label:"Headless",type:"select",currentValue:te.headless?"on":"off",options:[{label:"off",value:"off"},{label:"on",value:"on"}],onValue:s=>{tn(l=>({...l,headless:s==="on"}))}},{id:"run-max-steps",label:"Max Steps",type:"text-input",currentValue:String(te.maxSteps),onValue:s=>{let l=parseInt(s,10);l>0&&tn(y=>({...y,maxSteps:l}))}},{id:"run-timeout",label:"Timeout (sec)",type:"text-input",currentValue:te.timeout?String(te.timeout):"",placeholder:"0 = no timeout",onValue:s=>{let l=parseInt(s,10);tn(y=>({...y,timeout:isNaN(l)?0:l}))}},{id:"run-cdp",label:"CDP Endpoint",type:"text-input",currentValue:te.cdpEndpoint,placeholder:"http://127.0.0.1:9222",onValue:s=>{tn(l=>({...l,cdpEndpoint:s}))}},{id:"run-ws",label:"WS Endpoint",type:"text-input",currentValue:te.wsEndpoint,placeholder:"wss://...",onValue:s=>{tn(l=>({...l,wsEndpoint:s}))}}]}]},{id:"auth",label:"Auth",type:"submenu",children:[{id:"login",label:"Login",type:"action",onLoginWizard:()=>{}},{id:"logout",label:"Logout",type:"action",onAction:()=>{g.logout().then(s=>{Ae();let l=g.creds.getActiveProfile(),y=g.creds.getDefaultEnv();We(l,y);let P=ks(l,y);nt(P,Ne).catch(()=>{}),s?A("ok","/logout",`Logged out: ${s.profile} [${s.env}]`):A("ok","/logout","No active profile")}).catch(()=>{A("error","/logout","Logout failed")})}},{id:"whoami",label:"Who Am I",type:"action",onInfo:()=>{let s=g.creds.getActiveProfile()??"none",l=g.creds.getDefaultEnv(),y=g.creds.loadBasicAuth(s,l),P=y?"basic":g.creds.loadCredentials(s,l)?"oauth":"not configured";return{title:"Who Am I",sections:[{label:"Identity",entries:[{key:"Profile",value:s},{key:"Environment",value:l}]},{label:"Authentication",entries:[{key:"Method",value:P},...y?[{key:"Username",value:y.username}]:[]]},{label:"Token",entries:[{key:"Status",value:g.tokenValid?"valid":"not logged in",color:g.tokenValid?r.green:r.red}]}]}}},{id:"balance",label:"Credit Balance",type:"action",suppressFeedback:!0,onAction:()=>{(async()=>{let s=g.creds.getActiveProfile()??"default",l=g.creds.getDefaultEnv(),y=Ve(l);try{let P=g.getBasicAuth(),$=P?null:await g.getToken();if(!P&&!$){Je({text:"Not authenticated. Run /login first.",color:r.red});return}let{ControllerClient:N}=await import("./controller-client-RD2YEMAH.js"),Q=await(P?new N(y.controllerBaseUrl,{username:P.username,accessKey:P.access_key}):new N(y.controllerBaseUrl,$)).getCreditBalance();Je({text:`Credits \u2014 available: ${Q.available_credits}, total: ${Q.total_credits} (${s} / ${l})`,color:r.green})}catch(P){Je({text:`Balance check failed: ${P instanceof Error?P.message:String(P)}`,color:r.red})}kt.current&&clearTimeout(kt.current),kt.current=setTimeout(()=>{Je(null),kt.current=null},5e3)})()}},{id:"profiles",label:"Profiles",type:"action",onProfilesView:()=>{}}]},{id:"config",label:"Config",type:"submenu",children:[{id:"config-show",label:"Show",type:"action",onInfo:()=>({title:"Show Config",sections:[{label:"General",entries:[{key:"Model",value:"v16-alpha"},{key:"Mode",value:k.mode}]},{label:"Browser",entries:[{key:"Window",value:`${k.window_size.width}x${k.window_size.height}`},{key:"Chrome Profile",value:k.chrome_profile_path?k.chrome_profile_path.split("/").pop()??k.chrome_profile_path:"(temporary)"}]},{label:"Project",entries:[{key:"Project",value:k.project_name?`${k.project_name} (${k.project_id})`:k.project_id??"(none)"},{key:"Folder",value:k.folder_name?`${k.folder_name} (${k.folder_id})`:k.folder_id??"(none)"},{key:"Default URL",value:on}]},{label:"Code Export",entries:[{key:"Enabled",value:k.code_export.enabled?"yes":"no"},{key:"Language",value:k.code_export.language},{key:"Skip Validation",value:k.code_export.skip_validation?"yes":"no"}]}]})},{id:"config-chrome",label:"Chrome Profile",type:"action",onChromeProfilePicker:()=>{}},{id:"config-project",label:"Project",type:"action",onProjectPicker:()=>{}},{id:"config-folder",label:"Folder",type:"action",...k.project_id?{onFolderPicker:()=>{}}:{onInfo:()=>({title:"Folder",sections:[{entries:[{key:"Status",value:"Select a project first",color:r.dim}]}]})}},{id:"config-window",label:"Window Size",type:"action",currentValue:`${k.window_size.width}x${k.window_size.height}`,onWindowSizePicker:()=>{}},{id:"config-mode",label:"Mode",type:"select",currentValue:k.mode,options:[{label:"testing",value:"testing"},{label:"action",value:"action"}],onValue:s=>{(s==="action"||s==="testing")&&(u.set("mode",s),ge(u.load()),A("ok","/config set-mode",s))}},{id:"config-generate",label:"Generate",type:"submenu",currentValue:`${k.generate.scenario_limit}x${k.generate.per_scenario_limit}`,children:[{id:"config-generate-scenario-limit",label:"Scenario limit",type:"text-input",currentValue:String(k.generate.scenario_limit),placeholder:"5",onValue:s=>{let l=parseInt(s,10);if(!Number.isFinite(l)||l<1||l>20){A("error","/config",`Scenario limit must be 1-20 (got ${s})`);return}u.set("generate",{...k.generate,scenario_limit:l}),ge(u.load()),A("ok","/config",`Scenario limit: ${l}`)}},{id:"config-generate-per-scenario-limit",label:"Per-scenario limit",type:"text-input",currentValue:String(k.generate.per_scenario_limit),placeholder:"4",onValue:s=>{let l=parseInt(s,10);if(!Number.isFinite(l)||l<1||l>20){A("error","/config",`Per-scenario limit must be 1-20 (got ${s})`);return}u.set("generate",{...k.generate,per_scenario_limit:l}),ge(u.load()),A("ok","/config",`Per-scenario limit: ${l}`)}},{id:"config-generate-memory",label:"Memory",type:"select",currentValue:k.generate.memory_enabled?"on":"off",options:[{label:"on",value:"on"},{label:"off",value:"off"}],onValue:s=>{let l=s==="on";u.set("generate",{...k.generate,memory_enabled:l}),ge(u.load()),A("ok","/config",`Memory: ${l?"on":"off"}`)}}]},{id:"config-code-export",label:"Code Export",type:"submenu",currentValue:k.code_export.enabled?"enabled":"disabled",children:[{id:"config-code-export-enabled",label:"Enabled",type:"select",currentValue:k.code_export.enabled?"on":"off",options:[{label:"off",value:"off"},{label:"on",value:"on"}],onValue:s=>{u.set("code_export",{...k.code_export,enabled:s==="on"}),ge(u.load()),A("ok","/config code-export enabled",s)}},{id:"config-code-export-language",label:"Language",type:"select",currentValue:k.code_export.language,options:[{label:"python",value:"python"},{label:"javascript",value:"javascript"}],onValue:s=>{s!=="python"&&s!=="javascript"||(u.set("code_export",{...k.code_export,language:s}),ge(u.load()),A("ok","/config code-export language",s))}},{id:"config-code-export-skip-validation",label:"Skip Validation",type:"select",currentValue:k.code_export.skip_validation?"on":"off",options:[{label:"off",value:"off"},{label:"on",value:"on"}],onValue:s=>{u.set("code_export",{...k.code_export,skip_validation:s==="on"}),ge(u.load()),A("ok","/config code-export skip-validation",s)}}]}]},{id:"exit",label:"Exit",type:"action",onAction:()=>{Bt()}}]},[g,u,k,ae,Bt,te,Ae,A]),vr=(0,T.useCallback)(a=>{if(_.askingUser){let s=_.askingUser;re((0,b.jsxs)(f,{flexDirection:"column",marginLeft:2,paddingLeft:1,marginTop:1,children:[(0,b.jsx)(f,{marginLeft:1,children:(0,b.jsx)(t,{color:r.orange,bold:!0,children:"Agent Question"})}),(0,b.jsxs)(f,{borderStyle:"round",borderColor:r.orange,flexDirection:"column",paddingX:2,paddingY:1,width:70,children:[(0,b.jsxs)(f,{children:[(0,b.jsx)(f,{width:3,children:(0,b.jsx)(t,{color:r.orange,bold:!0,children:"?"})}),(0,b.jsx)(f,{flexShrink:1,children:(0,b.jsx)(t,{wrap:"wrap",children:s})})]}),(0,b.jsxs)(f,{marginTop:1,children:[(0,b.jsx)(f,{width:3,children:(0,b.jsx)(t,{color:r.dim,bold:!0,children:"\u2192"})}),(0,b.jsx)(f,{flexShrink:1,children:(0,b.jsx)(t,{wrap:"wrap",children:a})})]})]})]})),pr.current=null,_.sendAnswer(a);return}if(c.logCommand(a),_.isRunning){ae({type:"error",text:"Run in progress. Ctrl+C to cancel."});return}let m=Gn(a);if(m){if(!Ai(m.command,fe)){A("error",`/${m.command}`,`/${m.command} isn't available in ${fe==="run"?"Run":"Generate"} mode.`);return}switch(m.command){case"profiles":if(fe==="generate"&&z.requestId&&m.args.action==="switch"){en({reason:"profile",pendingArgs:m.args});return}Jt("auth");return;case"login":case"logout":case"whoami":case"balance":case"auth":Jt("auth");return;case"config":Jt("config");return;case"help":to(!0);return;case"testmd":if(_.isRunning||z.isStreaming||ne.running){A("error","/testmd","Finish or cancel the current run/generation first.");return}ne.clearResult(),wn(!0);return;case"generate":if(ne.running){A("error","/generate","Finish or cancel the running test first.");return}fe==="run"?lt.requestSwitch("generate")&&A("ok","/generate","Switched to Generate mode.",void 0,r.generateAccent):A("ok","/generate","Already in Generate mode.",void 0,r.generateAccent);return;case"run":{let s=Pi(fe,m.args.objective);switch(s.kind){case"run":lr(s.objective,on);return;case"reject":A("error","/run",'Switch to Run mode first (bare /run), then /run "objective".');return;case"already":A("ok","/run","Already in Run mode.",void 0,r.orange);return;case"toggle":lt.requestSwitch("run")&&A("ok","/run","Switched to Run mode.",void 0,r.orange);return}return}case"update":{(async()=>{let{getUpdateCommand:s}=await import("./version-check-5NUDIYG4.js");A("ok","/update",`To update kane-cli, run: ${s()}`)})();return}case"summary":{if(fe==="generate"&&!z.requestId){In("no generation yet"),A("ok","/summary","(no generation yet)");return}let s=c.getFlows();if(s.length===0){A("ok","/summary","No runs yet in this session.");return}let l=m.args.index?parseInt(m.args.index,10):void 0;if(l!==void 0&&!c.getFlow(l)){A("error","/summary",`No flow at index ${l}`,`${s.length} flow${s.length===1?"":"s"} available. Use /summary to see all.`);return}re((0,b.jsx)(qr,{flows:s,filterIndex:l})),A("ok","/summary",l!==void 0?`Flow ${l}`:`${s.length} flow${s.length===1?"":"s"}`);return}case"new":fe==="generate"&&z.requestId&&(ct(),z.end().catch(s=>{A("error","/new",`Could not end generation cleanly: ${s.message}`)}),z.reset()),lo(),A("ok","/new","Session reset");return;case"name":{let s=m.raw.replace(/^\/name\s*/,"").trim();if(!s){A("error","/name","Usage: /name <new-name>");return}(async()=>{let{validateNameOrThrow:l}=await import("./name-validator-5YGJXLZ7.js");try{l(s),c.setSessionName(s),A("ok","/name",`Session name set: ${s}`)}catch(y){A("error","/name",y.message)}})();return}case"cancel":if(fe==="generate"&&z.isStreaming){ct(),z.cancel(),A("ok","/cancel","Cancelled");return}if(fe==="generate"&&!z.requestId){In("no generation yet"),A("ok","/cancel","(no generation yet)");return}if(ne.running){ne.cancel(),A("ok","/cancel","Run cancelled");return}_.cancelRun(),A("ok","/cancel","Run cancelled");return;case"clear":A("ok","/clear","Chat cleared");return;case"exit":fe==="generate"&&z.requestId&&(ct(),z.end()),Bt();return;default:A("error",`/${m.command}`,"Unknown command");return}}if(a.trim().toLowerCase()==="exit"){Bt();return}re((0,b.jsxs)(f,{children:[(0,b.jsx)(t,{color:r.orange,children:"\u276F "}),(0,b.jsx)(t,{children:a})]})),lr(a,on)},[_,ae,A,re,c,lr,Bt,lo,fe,z.isStreaming,z.requestId,z,In,ct,ne]);ao.current=vr;let fo=(0,T.useRef)(!1);(0,T.useEffect)(()=>{if(!fo.current&&V&&h==="generate"&&v){fo.current=!0;let a=setTimeout(()=>{$s(v)},50);return()=>clearTimeout(a)}},[V,h,v]);let po=g.getAuthInfo(),Gs=po?po.method==="basic"?"basic auth":"oauth":"not logged in",qs=(()=>{if(Qt)return["help"];if(Zt)return["testmd"];if(I)return I.phase==="wizard"?["auth","login"]:I.phase==="project"?["auth","login","project"]:I.phase==="folder"?["auth","login","folder"]:["auth","login"];let a={infoView:"info",loginWizard:"login",profilesView:"profiles",chromeProfilePicker:"chrome-profile",projectPicker:"project",folderPicker:"folder",windowSizePicker:"set-window"};return et==="auth"?Sn?["auth",a[Sn]]:["auth"]:et==="config"?Sn?["config",a[Sn]]:["config"]:et==="help"?["help"]:_.askingUser?["agent question"]:[]})();return(0,b.jsxs)(f,{flexDirection:"column",children:[!V&&!Zr&&(0,b.jsx)(Si,{onComplete:()=>{let a=g.creds.getActiveProfile(),m=g.creds.getDefaultEnv(),s=a?g.creds.loadCredentials(a,m):null,l=a?g.creds.loadBasicAuth(a,m):null,y=!!(s||l),P=l?.username??a??null;re((0,b.jsx)(Nn,{size:"full",helmetVisibleRows:8,textVisibleRows:7,showMeta:!0,version:rn,authenticated:y,user:P})),_s(!0);let $=(N,W,Q,Pe)=>{c.log(N,W,Q,Pe)};if(Oo(g.creds,$).then(N=>{if(N.status==="authenticated"){let{profile:W,env:Q,tmsCreds:Pe}=N.result;g.creds.setActiveProfile(W),g.creds.setDefaultEnv(Q),Ae(),Ct(Pe),Ze("ready"),O(!0)}else N.status==="needs_pick"?(Es(N.profiles),Ze("pick")):Ze("login")}).catch(N=>{c.log("error","STARTUP_GATE_ERROR","Auth gate failed",{error:String(N)}),Ze("login")}),p&&p.then(async N=>{if(N){let{getUpdateCommand:W}=await import("./version-check-5NUDIYG4.js");A("ok","update available",`${N.current} \u2192 ${N.latest}`,`Run: ${W()}`)}}).catch(()=>{}),d&&d.changes.length>0){let N=`kane-cli updated to ${d.toVersion}. Default settings changed:`,W=[...d.changes.map(Q=>`\u2022 ${Q.description} (${Q.field}: ${JSON.stringify(Q.from)} \u2192 ${JSON.stringify(Q.to)})`),"","Use /config to review or revert any of these."].join(`
|
|
14
|
+
`);A("ok","defaults updated",N,W)}}}),!V&&Yt==="booting"&&Zr&&(0,b.jsx)(f,{paddingX:1,children:(0,b.jsx)(t,{color:"yellow",children:"Checking authentication..."})}),!V&&Yt==="pick"&&(0,b.jsx)(ja,{profiles:Is,onCancel:()=>Ze("login"),onSelect:async(a,m)=>{g.creds.setActiveProfile(a),g.creds.setDefaultEnv(m),Ae(),ir(!0);let s=(l,y,P,$)=>{c.log(l,y,P,$)};try{let l=await Vo(g.creds,a,m,s);ir(!1),l.status==="authenticated"?(We(a,m),Ct(l.result.tmsCreds),Ze("ready"),O(!0)):Ze("login")}catch{ir(!1),Ze("login")}},validating:Bs}),!V&&Yt==="login"&&!I&&(0,b.jsx)(Ln,{devMode:process.env.KANE_DEV_MODE==="1",profiles:g.creds.listProfiles(),onBasicLogin:async(a,m,s,l)=>{let{validateBasicAuth:y}=await import("./validate-basic-VFJZKHOE.js");await y(m,s,l),g.creds.saveBasicAuth(a,m,{username:s,access_key:l}),g.creds.setActiveProfile(a),g.creds.setDefaultEnv(m),Ge(g.creds,u,a,m),g.setTokenValid(!0),Ae()},onOAuthLogin:async(a,m)=>{g.creds.setDefaultEnv(m),await g.login(a),Ge(g.creds,u,a,m),Ae()},onComplete:(a,m)=>{nt(rr(m),Ne).then(()=>{Ae(),me({phase:"project",profile:a,env:m})}).catch(()=>{me({phase:"project",profile:a,env:m})})},onCancel:()=>{Ut(0,"Login cancelled at startup")}}),!V&&Yt==="login"&&I?.phase==="project"&&(0,b.jsx)($t,{resolver:g.getResolver(),currentProjectId:null,env:I.env,onSelect:(a,m)=>{g.creds.saveProfileConfig(I.profile,I.env,{project_id:a,project_name:m}),A("ok","/config project",m,`id: ${a}`),me({...I,phase:"folder"})},onCancel:async()=>{let a=await ar(I.profile,I.env);a&&(Xe(g.creds,u,I.profile,I.env,{projectId:a.id,projectName:a.name}),A("ok","/config project",a.name,`id: ${a.id}`),me({...I,phase:"folder"}))}}),!V&&Yt==="login"&&I?.phase==="folder"&&(0,b.jsx)(Ft,{resolver:g.getResolver(),projectId:g.creds.loadProfileConfig(I.profile,I.env)?.project_id??"",currentFolderId:null,env:I.env,onSelect:(a,m)=>{g.creds.saveProfileConfig(I.profile,I.env,{folder_id:a,folder_name:m}),A("ok","/config folder",m,`id: ${a}`),We(I.profile,I.env),me(null),Ze("ready"),O(!0)},onCancel:async()=>{let a=g.creds.loadProfileConfig(I.profile,I.env);if(!a?.project_id)return;let m=await cr(I.env,a.project_id);m&&(Xe(g.creds,u,I.profile,I.env,{folderId:m.id,folderName:m.name}),A("ok","/config folder",m.name,`id: ${m.id}`),We(I.profile,I.env),me(null),Ze("ready"),O(!0))}}),V&&Tn==="menu"&&!q&&(0,b.jsx)(f,{marginBottom:1,children:(0,b.jsxs)(f,{borderStyle:"round",borderColor:"#dc4e08",paddingX:2,children:[(0,b.jsx)(t,{color:"#ff9500",bold:!0,children:"KaneAI CLI"}),(0,b.jsx)(t,{color:r.dim,children:" \u2502 "}),(0,b.jsx)(t,{color:"#ff9500",children:k.model}),(0,b.jsx)(t,{color:r.dim,children:" \u2502 "}),(0,b.jsx)(t,{color:r.dim,children:Gs}),(0,b.jsx)(t,{color:r.dim,children:" \u2502 "}),(0,b.jsxs)(t,{color:r.dim,children:[Lt??"no profile","/",oe]})]})}),V&&!q&&(0,b.jsxs)(f,{flexDirection:"column",flexGrow:1,children:[Tn==="menu"&&(0,b.jsxs)(b.Fragment,{children:[(0,b.jsx)(Or,{items:mo,onRunSelected:()=>As("chat"),onActiveViewChange:eo,renderLoginWizard:a=>{let m=I?.phase??"wizard";if(m==="project")return(0,b.jsx)($t,{resolver:g.getResolver(),currentProjectId:null,env:I.env,onSelect:(s,l)=>{g.creds.saveProfileConfig(I.profile,I.env,{project_id:s,project_name:l}),A("ok","/config project",l,`id: ${s}`),me(y=>y?{...y,phase:"folder"}:null)},onCancel:async()=>{if(!I)return;let s=await ar(I.profile,I.env);s&&(Xe(g.creds,u,I.profile,I.env,{projectId:s.id,projectName:s.name}),A("ok","/config project",s.name,`id: ${s.id}`),me(l=>l?{...l,phase:"folder"}:null))}});if(m==="folder"){let s=g.creds.loadProfileConfig(I.profile,I.env);return(0,b.jsx)(Ft,{resolver:g.getResolver(),projectId:s?.project_id??"",currentFolderId:null,env:I.env,onSelect:(l,y)=>{g.creds.saveProfileConfig(I.profile,I.env,{folder_id:l,folder_name:y}),A("ok","/config folder",y,`id: ${l}`),We(I.profile,I.env),me(null),a()},onCancel:async()=>{if(!I)return;let l=g.creds.loadProfileConfig(I.profile,I.env);if(!l?.project_id)return;let y=await cr(I.env,l.project_id);y&&(Xe(g.creds,u,I.profile,I.env,{folderId:y.id,folderName:y.name}),A("ok","/config folder",y.name,`id: ${y.id}`),We(I.profile,I.env),me(null),a())}})}return(0,b.jsx)(Ln,{devMode:process.env.KANE_DEV_MODE==="1",profiles:g.creds.listProfiles(),onBasicLogin:async(s,l,y,P)=>{let{validateBasicAuth:$}=await import("./validate-basic-VFJZKHOE.js");await $(l,y,P),g.creds.saveBasicAuth(s,l,{username:y,access_key:P}),g.creds.setActiveProfile(s),g.creds.setDefaultEnv(l),Ge(g.creds,u,s,l),g.setTokenValid(!0),Ae()},onOAuthLogin:async(s,l)=>{g.creds.setDefaultEnv(l),await g.login(s),Ge(g.creds,u,s,l),Ae()},onComplete:(s,l)=>{nt(rr(l),Ne).then(()=>{me({phase:"project",profile:s,env:l})}).catch(()=>{me({phase:"project",profile:s,env:l})})},onCancel:()=>{me(null),a()}})},renderProfilesView:a=>(0,b.jsx)(wr,{creds:g.creds,onSwitch:(m,s)=>{let l=g.creds.getActiveProfile()??"(none)";g.creds.setActiveProfile(m),g.creds.setDefaultEnv(s),Ge(g.creds,u,m,s),We(m,s),Ae(),nt(Jr(s),Ne).catch(()=>{}),A("ok","/profiles switch",`${l} \u2192 ${m} [${s}]`)},onCancel:a}),renderChromeProfilePicker:a=>(0,b.jsx)(Rr,{currentPath:k.chrome_profile_path,onSelect:m=>{u.set("chrome_profile_path",m),ge(u.load()),A("ok","/config chrome-profile",m),a()},onCancel:a}),renderProjectPicker:a=>(0,b.jsx)($t,{resolver:g.getResolver(),currentProjectId:k.project_id,env:oe,onSelect:(m,s)=>{Xe(g.creds,u,g.creds.getActiveProfile()??"default",g.creds.getDefaultEnv(),{projectId:m,projectName:s}),A("ok","/config project",s,`id: ${m}`),ge(u.load()),a()},onCancel:a}),renderFolderPicker:a=>(0,b.jsx)(Ft,{resolver:g.getResolver(),projectId:k.project_id??"",currentFolderId:k.folder_id,env:oe,onSelect:(m,s)=>{Xe(g.creds,u,g.creds.getActiveProfile()??"default",g.creds.getDefaultEnv(),{folderId:m,folderName:s}),A("ok","/config folder",s,`id: ${m}`),ge(u.load()),a()},onCancel:a}),renderWindowSizePicker:a=>(0,b.jsx)(Gr,{currentWidth:k.window_size.width,currentHeight:k.window_size.height,onSelect:(m,s)=>{u.set("window_size",{width:m,height:s}),ge(u.load()),A("ok","/config set-window",`${m} \xD7 ${s}`),a()},onCancel:a})}),xt&&(0,b.jsx)(f,{paddingX:1,marginTop:1,children:(0,b.jsx)(t,{color:xt.color,children:xt.text})})]}),Tn==="chat"&&(0,b.jsxs)(b.Fragment,{children:[(()=>{let a=So({isRunning:_.isRunning,bifurcationInfo:_.bifurcationInfo,steps:_.steps,cmInitCounts:_.cmInitCounts,replayInfo:_.replayInfo});return a?(0,b.jsx)(To,{label:a.label,hasBifurcation:a.hasBifurcation}):null})(),_.isRunning&&_.steps.length>0&&(0,b.jsx)(yo,{steps:_.steps,bifurcated:!!_.bifurcationInfo&&!_.bifurcationInfo.isSingleFlow,flows:_.bifurcationInfo?.flows,cmInitCounts:_.cmInitCounts,onStepCommit:re},`run-${_e.current}`),ne.runViewProps&&(0,b.jsx)(qo,{...ne.runViewProps,onCancel:()=>{ne.runViewProps?.onCancel?.(),ne.cancel()}}),Qt&&(0,b.jsx)(ji,{onClose:()=>to(!1),version:rn,environment:g.creds.getDefaultEnv(),sessionId:c.sessionId,runUrl:k.default_url??on,mode:fe}),Zt&&(0,b.jsx)(Oi,{cwd:process.cwd(),currentOrgId:String(Fe?.org_id??""),onClose:()=>wn(!1),onRun:a=>{if(_.isRunning||z.isStreaming||ne.running){setTimeout(()=>A("error","/testmd","Finish or cancel the current run first."),0);return}wn(!1),!(fe==="generate"&&!lt.requestSwitch("run"))&&(fe==="generate"&&setTimeout(()=>A("ok","/testmd",`Switched to Run mode to run ${a.relPath}`,void 0,r.orange),0),ne.start(a.path).catch(m=>setTimeout(()=>A("error","/testmd",`Run failed: ${m.message}`),0)))},onExport:a=>{wn(!1),ri(a.path,{language:k.code_export.language??"python",env:oe}).then(m=>setTimeout(()=>A("ok","/testmd",`Exported code \u2192 ${m.codeDir}`),0)).catch(m=>setTimeout(()=>A("error","/testmd",`Export failed: ${m.message}`),0))}}),et&&!_.isRunning&&(()=>{let a=mo.find(m=>m.id===et);return a?.children?(0,b.jsx)(Or,{items:a.children,onRunSelected:()=>Jt(null),onDismiss:()=>Jt(null),onActiveViewChange:eo,renderLoginWizard:m=>{let s=I?.phase??"wizard";if(s==="project")return(0,b.jsx)($t,{resolver:g.getResolver(),currentProjectId:null,env:I.env,onSelect:(l,y)=>{g.creds.saveProfileConfig(I.profile,I.env,{project_id:l,project_name:y}),A("ok","/config project",y,`id: ${l}`),me(P=>P?{...P,phase:"folder"}:null)},onCancel:async()=>{if(!I)return;let l=await ar(I.profile,I.env);l&&(Xe(g.creds,u,I.profile,I.env,{projectId:l.id,projectName:l.name}),A("ok","/config project",l.name,`id: ${l.id}`),me(y=>y?{...y,phase:"folder"}:null))}});if(s==="folder"){let l=g.creds.loadProfileConfig(I.profile,I.env);return(0,b.jsx)(Ft,{resolver:g.getResolver(),projectId:l?.project_id??"",currentFolderId:null,env:I.env,onSelect:(y,P)=>{g.creds.saveProfileConfig(I.profile,I.env,{folder_id:y,folder_name:P}),A("ok","/config folder",P,`id: ${y}`),We(I.profile,I.env),me(null),m()},onCancel:async()=>{if(!I)return;let y=g.creds.loadProfileConfig(I.profile,I.env);if(!y?.project_id)return;let P=await cr(I.env,y.project_id);P&&(Xe(g.creds,u,I.profile,I.env,{folderId:P.id,folderName:P.name}),A("ok","/config folder",P.name,`id: ${P.id}`),We(I.profile,I.env),me(null),m())}})}return(0,b.jsx)(Ln,{devMode:process.env.KANE_DEV_MODE==="1",profiles:g.creds.listProfiles(),onBasicLogin:async(l,y,P,$)=>{let{validateBasicAuth:N}=await import("./validate-basic-VFJZKHOE.js");await N(y,P,$),g.creds.saveBasicAuth(l,y,{username:P,access_key:$}),g.creds.setActiveProfile(l),g.creds.setDefaultEnv(y),Ge(g.creds,u,l,y),g.setTokenValid(!0),Ae()},onOAuthLogin:async(l,y)=>{g.creds.setDefaultEnv(y),await g.login(l),Ge(g.creds,u,l,y),Ae()},onComplete:(l,y)=>{nt(rr(y),Ne).then(()=>{me({phase:"project",profile:l,env:y})}).catch(()=>{me({phase:"project",profile:l,env:y})})},onCancel:()=>{me(null),m()}})},renderProfilesView:m=>(0,b.jsx)(wr,{creds:g.creds,onSwitch:(s,l)=>{let y=g.creds.getActiveProfile()??"(none)";g.creds.setActiveProfile(s),g.creds.setDefaultEnv(l),Ge(g.creds,u,s,l),We(s,l),Ae(),nt(Jr(l),Ne).catch(()=>{}),A("ok","/profiles switch",`${y} \u2192 ${s} [${l}]`),m()},onCancel:m}),renderChromeProfilePicker:m=>(0,b.jsx)(Rr,{currentPath:k.chrome_profile_path,onSelect:s=>{u.save({chrome_profile_path:s}),ge(u.load()),A("ok","/config chrome-profile",s),m()},onCancel:m}),renderProjectPicker:m=>(0,b.jsx)($t,{resolver:g.getResolver(),currentProjectId:k.project_id,env:oe,onSelect:(s,l)=>{Xe(g.creds,u,g.creds.getActiveProfile()??"default",g.creds.getDefaultEnv(),{projectId:s,projectName:l}),ge(u.load()),A("ok","/config project",l,`id: ${s}`),m()},onCancel:m}),renderFolderPicker:m=>(0,b.jsx)(Ft,{resolver:g.getResolver(),projectId:k.project_id??"",currentFolderId:k.folder_id,env:oe,onSelect:(s,l)=>{Xe(g.creds,u,g.creds.getActiveProfile()??"default",g.creds.getDefaultEnv(),{folderId:s,folderName:l}),ge(u.load()),A("ok","/config folder",l,`id: ${s}`),m()},onCancel:m}),renderWindowSizePicker:m=>(0,b.jsx)(Gr,{currentWidth:k.window_size.width,currentHeight:k.window_size.height,onSelect:(s,l)=>{u.set("window_size",{width:s,height:l}),ge(u.load()),A("ok","/config set-window",`${s} \xD7 ${l}`),m()},onCancel:m})},et):null})(),et&&xt&&(0,b.jsx)(f,{paddingX:1,marginTop:1,children:(0,b.jsx)(t,{color:xt.color,children:xt.text})}),fe==="run"&&!et&&!Qt&&!Zt&&!J&&_.askingUser&&(0,b.jsxs)(f,{flexDirection:"column",marginLeft:2,paddingLeft:1,marginTop:1,children:[(0,b.jsx)(f,{marginLeft:1,children:(0,b.jsx)(t,{color:r.orange,bold:!0,children:"Agent Question"})}),(0,b.jsx)(f,{borderStyle:"round",borderColor:r.orange,flexDirection:"column",paddingX:2,paddingY:1,width:70,children:(0,b.jsxs)(f,{children:[(0,b.jsx)(f,{width:3,children:(0,b.jsx)(t,{color:r.orange,bold:!0,children:"?"})}),(0,b.jsx)(f,{flexShrink:1,children:(0,b.jsx)(t,{wrap:"wrap",children:_.askingUser})})]})})]}),Rn&&(()=>{let a=Rn,m=a.reason==="switch"?a.to==="run"?"Discard the current generation and switch to Run?":"Stop the current run / discard its results and switch to Generate?":"Switching profile will end this generation. Continue?",s=a.reason==="switch"?"Discard & switch":"Yes, end";return(0,b.jsx)(ys,{message:m,confirmLabel:s,onConfirm:async()=>{if(a.reason==="switch"){let y=a.to;en(null),lt.confirmSwitch(y);return}ct();let l=a.pendingArgs;if(en(null),await z.end(),z.reset(),l.profile){let y=g.creds.getDefaultEnv(),P=g.creds.getActiveProfile()??"(none)";g.creds.setActiveProfile(l.profile),g.creds.setDefaultEnv(y),Ge(g.creds,u,l.profile,y),We(l.profile,y),Ae(),nt({kind:"switch",env:y},Ne).catch(()=>{}),A("ok","/profiles switch",`${P} \u2192 ${l.profile} [${y}]`)}else vr("/profiles switch")},onCancel:()=>en(null)})})(),fe==="run"&&!et&&!Qt&&!Zt&&!J&&!Rn&&!ne.running&&(0,b.jsx)(Tt,{onSubmit:vr,onEscape:void 0,history:ro,commands:_i,clearSeq:Os,placeholder:_.askingUser?"Type your answer...":_.isRunning?"Run in progress... Ctrl+C to cancel":"Type an objective... (/ = commands)",footerBindings:[{keys:"\u2191\u2193",label:"history"},{keys:"\u21B5",label:"submit"},{keys:"tab",label:"complete"},{keys:"ctrl+r",label:"search"},{keys:"/generate",label:"test cases"}]}),fe==="generate"&&!et&&!Qt&&!Zt&&!J&&!Rn&&(0,b.jsx)(vs,{tcg:z,gm:lt,history:ro,tuiConfig:k,browse:bt.isOpen?{target:bt.target,onClose:bt.close,excluded:bt.excluded,onToggleCase:bt.toggleCase,onToggleScenario:bt.toggleScenario,getStatus:lt.bifurcation.getStatus,getResult:lt.bifurcation.getResult}:null})]})]}),V&&q&&De&&(0,b.jsxs)(b.Fragment,{children:[(0,b.jsx)(kr,{steps:hn,status:De.status,testUrl:De.testUrl,error:De.error}),De.status==="success"&&(0,b.jsx)(Vn,{recordedTestPath:Kt?.recordedTestPath,outputDir:Kt?.outputDir,shareableLink:De.testUrl,testCaseLink:De.testCaseLink,codeExportDir:De.codeExportDir,autoExit:!1})]}),J&&(0,b.jsx)(hi,{defaultName:J,onSubmit:Us}),ee&&(0,b.jsx)(gi,{onSubmit:Ns}),or&&De&&(0,b.jsx)(kr,{steps:hn,status:De.status,error:De.error}),V&&!q&&(0,b.jsx)(bi,{profile:Lt,environment:oe,tokenValid:g.tokenValid,runCount:K,sessionId:c.sessionId,viewMode:Tn,breadcrumb:qs,chatMode:fe,tcgRequestId:z.requestId,tcgStreamStatus:z.isStreaming?"streaming":z.isReconnecting?"reconnecting":z.isTerminal&&z.state.status.toLowerCase()==="completed"?"completed":z.isTerminal&&z.state.status.toLowerCase()==="failed"?"failed":null})]})}function ja({profiles:e,onSelect:n,onCancel:o,validating:i}){let[p,d]=(0,T.useState)(0);return Re((x,h)=>{if(!i){if(h.escape){o();return}if(h.upArrow&&p>0&&d(v=>v-1),h.downArrow&&p<e.length-1&&d(v=>v+1),h.return){let v=e[p];n(v.profile,v.env)}}}),(0,b.jsxs)(f,{flexDirection:"column",paddingX:1,children:[(0,b.jsx)(t,{color:"#ff9500",bold:!0,children:"Select a profile:"}),(0,b.jsx)(f,{marginTop:1,flexDirection:"column",children:e.map((x,h)=>(0,b.jsxs)(t,{children:[h===p?"\u276F ":" ",(0,b.jsx)(t,{color:h===p?"#ff9500":"white",bold:h===p,children:x.profile}),(0,b.jsxs)(t,{color:"gray",children:[" [",x.env,"]"]})]},`${x.profile}-${x.env}`))}),i&&(0,b.jsx)(f,{marginTop:1,children:(0,b.jsx)(t,{color:"yellow",children:"Validating credentials..."})}),!i&&(0,b.jsx)(f,{marginTop:1,children:(0,b.jsx)(t,{color:"gray",children:"Esc = new login"})})]})}export{Ci as a,Cs as b,ef as c};
|