@testmuai/kane-cli 0.3.0 → 0.3.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.
Files changed (56) hide show
  1. package/dist/{ChromeProfilePicker-U2SEKNEQ.js → ChromeProfilePicker-HGRJNQDM.js} +1 -1
  2. package/dist/{CliFeedbackPrompt-EADRWA76.js → CliFeedbackPrompt-JXEPBJ63.js} +1 -1
  3. package/dist/{CliUploadProgress-DV34KLES.js → CliUploadProgress-L5VJUXUC.js} +1 -1
  4. package/dist/{ConfigView-32U22T7S.js → ConfigView-LOEAT3HQ.js} +1 -1
  5. package/dist/FolderPicker-I6JTRNAU.js +2 -0
  6. package/dist/{HelpView-PUE5XHCB.js → HelpView-UEUKYHFR.js} +1 -1
  7. package/dist/{InfoBox-QNOWEKMD.js → InfoBox-MK7EEGCH.js} +1 -1
  8. package/dist/{LinksBox-UCNEPFJD.js → LinksBox-RSWQWL6G.js} +1 -1
  9. package/dist/{ProfilesView-P6JL2BTH.js → ProfilesView-KCOMTDR5.js} +1 -1
  10. package/dist/ProjectPicker-AX6H5MX3.js +2 -0
  11. package/dist/{SaveSessionPrompt-DIZX3M6X.js → SaveSessionPrompt-RGL3LAEB.js} +1 -1
  12. package/dist/SingleShotApp-YTFAGVZD.js +2 -0
  13. package/dist/{SummaryBox-72NGQYS7.js → SummaryBox-5YPKUIHB.js} +1 -1
  14. package/dist/{TestMdRunView-DD6YI7CY.js → TestMdRunView-QS7IUANM.js} +1 -1
  15. package/dist/{WhoamiView-LSMM65UI.js → WhoamiView-GL3HZQ4Q.js} +1 -1
  16. package/dist/{changelog-P7XOVZ6M.js → changelog-CLQ7HCB3.js} +1 -1
  17. package/dist/{chunk-CFFWCE27.js → chunk-34DK2AUH.js} +1 -1
  18. package/dist/{chunk-JYQO6G7F.js → chunk-3ELBJPHQ.js} +1 -1
  19. package/dist/{chunk-75SVKFKD.js → chunk-3QD3LA72.js} +1 -1
  20. package/dist/{chunk-66CVM7JL.js → chunk-BM4COXQU.js} +1 -1
  21. package/dist/{chunk-OU2XDMNW.js → chunk-BQKDPI6L.js} +1 -1
  22. package/dist/{chunk-Y5RLPELZ.js → chunk-BR2S57O2.js} +1 -1
  23. package/dist/{chunk-7VX5H5MK.js → chunk-DUR6AFYA.js} +1 -1
  24. package/dist/{chunk-YV5KDJLP.js → chunk-F6HEB4PA.js} +1 -1
  25. package/dist/{chunk-BSQVYLV7.js → chunk-HJ3CHMEM.js} +1 -1
  26. package/dist/{chunk-QV2VR72Q.js → chunk-K7MSPKEM.js} +1 -1
  27. package/dist/{chunk-BAKBO5YA.js → chunk-KULEBWMB.js} +1 -1
  28. package/dist/{chunk-FJ6L63SP.js → chunk-KVDOQY2Q.js} +1 -1
  29. package/dist/{chunk-MBQIYYLD.js → chunk-L4GAZTAQ.js} +1 -1
  30. package/dist/{chunk-XW32PCGX.js → chunk-L4OZRHUT.js} +1 -1
  31. package/dist/{chunk-445V6RTR.js → chunk-MEB2KLWF.js} +1 -1
  32. package/dist/{chunk-5KH7U63E.js → chunk-NOH6RERF.js} +1 -1
  33. package/dist/{chunk-PINXGH2T.js → chunk-NZSHFIZX.js} +2 -2
  34. package/dist/{chunk-Q6INY5JA.js → chunk-QO6VFDI4.js} +1 -1
  35. package/dist/{chunk-MH26PIS4.js → chunk-RXMOIIQD.js} +1 -1
  36. package/dist/{chunk-XJ7OYQ7M.js → chunk-THNGNS36.js} +1 -1
  37. package/dist/{chunk-NLYBR5FP.js → chunk-TK7ZJ7YX.js} +1 -1
  38. package/dist/{chunk-OMYNAZW4.js → chunk-VUBZQUP4.js} +1 -1
  39. package/dist/{chunk-MNAVXLW4.js → chunk-WAFO4MT4.js} +1 -1
  40. package/dist/{chunk-JPKW7SRP.js → chunk-XMK4GYI7.js} +1 -1
  41. package/dist/{chunk-I4AD2L5R.js → chunk-XP5SMOND.js} +1 -1
  42. package/dist/{chunk-G7I7EAV6.js → chunk-ZLQ7YLXO.js} +1 -1
  43. package/dist/{chunk-4SNZTVJB.js → chunk-ZX3PMRMO.js} +1 -1
  44. package/dist/index.js +7 -7
  45. package/dist/{logging-NPMKABVV.js → logging-GG23EW5G.js} +1 -1
  46. package/dist/{login-flow-QCYF5347.js → login-flow-ZUZUZIXD.js} +1 -1
  47. package/dist/{persist-recorded-session-53YCJK7U.js → persist-recorded-session-ZXKA4H7E.js} +1 -1
  48. package/dist/{recording-banner-ABFX6FI4.js → recording-banner-IDLY2FM6.js} +1 -1
  49. package/dist/{run-test-md-C63UB65T.js → run-test-md-UPAR3DQY.js} +6 -6
  50. package/dist/{testmd-actions-GPYFEL7F.js → testmd-actions-YYFFNNIH.js} +2 -2
  51. package/dist/{validate-basic-TW5CQAL3.js → validate-basic-27BIMJ2F.js} +1 -1
  52. package/dist/{version-check-6XDFGFCG.js → version-check-6DXFF6IN.js} +1 -1
  53. package/package.json +5 -5
  54. package/dist/FolderPicker-C4ANRIT7.js +0 -2
  55. package/dist/ProjectPicker-XEZIFGJ6.js +0 -2
  56. package/dist/SingleShotApp-RLZN2PVQ.js +0 -2
@@ -1,3 +1,3 @@
1
1
  import { createRequire } from 'module'; const require = createRequire(import.meta.url);
2
- import{b as Se}from"./chunk-66CVM7JL.js";import{f as ie}from"./chunk-G7VF5SDK.js";import{a as ae}from"./chunk-FJ6L63SP.js";import{b as Te}from"./chunk-G7I7EAV6.js";import{b as be}from"./chunk-75SVKFKD.js";import{a as we}from"./chunk-YCCUBQY4.js";import{a as re,b as oe,d as Ae}from"./chunk-VE3SUJMA.js";import{a as ve,b as ye}from"./chunk-QV2VR72Q.js";import{a as te}from"./chunk-NLYBR5FP.js";import{a as le}from"./chunk-PWGEMRBD.js";import{a as ee}from"./chunk-BSQVYLV7.js";import{a as Y}from"./chunk-HCBYKLMW.js";import{c as xe,t as v}from"./chunk-JYQO6G7F.js";import{a as w,b as g,h as pe,i as z,j as ge,k as he}from"./chunk-C44QQJR4.js";import{a as Z}from"./chunk-6YGTRKDT.js";import{a as fe}from"./chunk-YUUZDFT7.js";import{e as F}from"./chunk-UR6MHSHU.js";var C=F(Z(),1);var q=F(Z(),1);var de=F(Z(),1);var X=F(Y(),1);function Ee({history:c,onSelect:n,onClose:o}){let[d,h]=(0,de.useState)(""),[t,m]=(0,de.useState)(0),e=d?c.search(d).slice(0,8):[];return z((a,x)=>{if(x.escape){o();return}if(x.return){e.length>0&&e[t]?n(e[t]):o();return}if(x.upArrow){m(y=>Math.max(0,y-1));return}if(x.downArrow){m(y=>Math.min(e.length-1,y+1));return}if(x.backspace||x.delete){h(y=>y.slice(0,-1)),m(0);return}a&&!x.ctrl&&!x.meta&&(h(y=>y+a),m(0))}),(0,X.jsxs)(w,{flexDirection:"column",marginLeft:2,borderStyle:"single",paddingX:1,children:[(0,X.jsx)(g,{color:v.muted,bold:!0,children:"reverse search"}),(0,X.jsxs)(w,{gap:1,children:[(0,X.jsx)(g,{color:v.dimmed,children:"search:"}),(0,X.jsx)(g,{children:d}),(0,X.jsx)(g,{color:v.purple,children:"\u2588"})]}),e.length>0&&(0,X.jsx)(g,{children:" "}),e.map((a,x)=>(0,X.jsx)(w,{marginLeft:2,children:(0,X.jsxs)(g,{color:x===t?v.purple:v.dimmed,bold:x===t,children:[x===t?"\u25B8 ":" ",a]})},`${x}-${a}`))]})}var J=F(Y(),1);function Pe({commands:c,selectedIndex:n}){return c.length===0?null:(0,J.jsx)(w,{flexDirection:"column",marginBottom:0,children:c.map((o,d)=>{let h=d===n;return(0,J.jsxs)(w,{children:[(0,J.jsx)(g,{color:h?v.primary:v.dimmed,children:h?"\u276F ":" "}),(0,J.jsxs)(g,{color:h?v.primary:void 0,bold:h,children:["/",o.name]}),o.args&&(0,J.jsxs)(g,{color:v.dimmed,children:[" ",o.args]}),(0,J.jsxs)(g,{color:v.dimmed,children:[" ",o.description]})]},o.name)})})}var ce=F(Z(),1);var Me=27,ke=127,Oe=11;function je(c){return c>=64&&c<=126}function Fe(c,n){c===Oe&&n({killToEnd:!0,ctrl:!0,raw:String.fromCharCode(c)})}function Ke(c,n){c===ke&&n({backspace:!0,meta:!0,raw:"\x1B\x7F"})}function Ue(c,n){let o=c.map(h=>String.fromCharCode(h)).join(""),d=/^\[1;([0-9]+)([A-D])$/.exec(o);if(d){let h=parseInt(d[1],10),t=d[2],m={raw:"\x1B"+o};if(h===2)m.shift=!0;else if(h===3)m.meta=!0;else if(h===5)m.ctrl=!0;else return;t==="A"?m.arrowUp=!0:t==="B"?m.arrowDown=!0:t==="C"?m.arrowRight=!0:t==="D"&&(m.arrowLeft=!0),n(m);return}if(o==="[H"||o==="[1~"||o==="[7~"){n({home:!0,raw:"\x1B"+o});return}if(o==="[F"||o==="[4~"||o==="[8~"){n({end:!0,raw:"\x1B"+o});return}if(o==="[3;5~"){n({delete:!0,ctrl:!0,raw:"\x1B"+o});return}if(o==="[3;3~"){n({delete:!0,meta:!0,raw:"\x1B"+o});return}}function Ne(c,n){c===72?n({home:!0,raw:"\x1BO"+String.fromCharCode(c)}):c===70&&n({end:!0,raw:"\x1BO"+String.fromCharCode(c)})}function $e(){let c="IDLE",n=[];function o(){c="IDLE",n=[]}return{feed(d,h){for(let t of d)c==="IDLE"?t===Me?(c="ESC",n=[]):Fe(t,h):c==="ESC"?t===91?(c="CSI",n=[]):t===79?(c="SS3",n=[]):(Ke(t,h),o()):c==="CSI"?(n.push(t),je(t)&&(Ue([91,...n],h),o())):c==="SS3"&&(Ne(t,h),o())},flushIdle(d){c==="ESC"&&n.length===0&&d({raw:"\x1B"}),o()}}}function Ce(c,n={}){let o=(0,ce.useRef)(c);o.current=c;let{stdin:d}=pe();(0,ce.useEffect)(()=>{if(n.isActive===!1||!d)return;let h=$e(),t=null,m=e=>{t&&(clearTimeout(t),t=null);let a=Buffer.isBuffer(e)?e:Buffer.from(e,"binary");h.feed(a,x=>o.current(x)),t=setTimeout(()=>{h.flushIdle(x=>o.current(x)),t=null},50)};return d.on("data",m),()=>{d.removeListener("data",m),t&&clearTimeout(t)}},[n.isActive,d])}var L=F(Y(),1);function _e({onSubmit:c,onEscape:n,history:o,placeholder:d="Type an objective or /command...",commands:h}){let[t,m]=(0,q.useState)([]),[e,a]=(0,q.useState)(0),[x,y]=(0,q.useState)("none"),[D,E]=(0,q.useState)(-1),_=(0,q.useRef)(""),[I,Q]=(0,q.useState)(!0),{stdout:j}=he(),M=j?.columns??80,[N,$]=(0,q.useState)(0),R=t.join(""),G=(()=>{if(x!=="none"||t.length===0)return"";if(R.startsWith("/")&&h&&R.length>=2){let r=R.slice(1).toLowerCase(),i=h.find(S=>S.name.startsWith(r)&&S.name!==r);return i?`/${i.name}`.slice(R.length):""}if(R.startsWith("/"))return"";let l=o.getAll();for(let r=l.length-1;r>=0;r--)if(l[r].startsWith(R)&&l[r]!==R)return l[r].slice(R.length);return""})(),k=(()=>{if(!h||!R.startsWith("/"))return[];let l=R.length>=2?R.slice(1).toLowerCase():"";return l&&h.some(r=>r.name===l)?[]:h.filter(r=>!l||r.name.startsWith(l))})(),W=k.length>0&&R.startsWith("/");z((l,r)=>{if(I&&l&&Q(!1),r.return){if(W&&k[N]){let i=`/${k[N].name}`;o.push(i),c(i),m([]),a(0),y("none"),E(-1),_.current="",Q(!0),$(0);return}R.trim()&&(o.push(R.trim()),c(R.trim()),m([]),a(0),y("none"),E(-1),_.current="",Q(!0),$(0));return}if(r.escape){x!=="none"?y("none"):t.length>0?(m([]),a(0),E(-1),_.current=""):n?.();return}if(r.tab){if(W&&k[N]){let i=`/${k[N].name}`;m([...i]),a(i.length),$(0);return}if(G){let i=R+G;m([...i]),a(i.length);return}return}if(r.ctrl&&l==="r"){y("search");return}if(r.ctrl&&l==="a"){a(0);return}if(r.ctrl&&l==="e"){a(t.length);return}if(r.ctrl&&l==="w"){if(e===0)return;let i=e-1;for(;i>0&&t[i]===" ";)i--;for(;i>0&&t[i-1]!==" ";)i--;let S=[...t.slice(0,i),...t.slice(e)];m(S),a(i);return}if(r.ctrl&&l==="u"){m([]),a(0),E(-1),y("none");return}if(r.meta&&l==="b"){let i=e-1;for(;i>0&&t[i]===" ";)i--;for(;i>0&&t[i-1]!==" ";)i--;a(Math.max(0,i));return}if(r.meta&&l==="f"){let i=e;for(;i<t.length&&t[i]!==" ";)i++;for(;i<t.length&&t[i]===" ";)i++;a(i);return}if(r.leftArrow){if(r.ctrl||r.shift)return;a(i=>Math.max(0,i-1));return}if(r.rightArrow){if(r.ctrl||r.shift)return;if(e>=t.length&&G){let i=R+G;m([...i]),a(i.length)}else a(i=>Math.min(t.length,i+1));return}if(r.upArrow){if(r.shift)return;if(W){$(i=>Math.max(0,i-1));return}if(x==="none"){let i=o.getAll();if(i.length===0)return;if(D===-1){_.current=R,E(i.length-1);let S=i[i.length-1];m([...S]),a(S.length)}else if(D>0){let S=D-1;E(S);let O=i[S];m([...O]),a(O.length)}}return}if(r.downArrow){if(r.shift)return;if(W){$(i=>Math.min(k.length-1,i+1));return}if(x==="none"){let i=o.getAll();if(D===-1)return;if(D<i.length-1){let S=D+1;E(S);let O=i[S];m([...O]),a(O.length)}else{E(-1);let S=_.current;m([...S]),a(S.length)}}return}if(r.backspace||r.delete){if(r.meta||r.ctrl)return;if(e>0){let i=[...t.slice(0,e-1),...t.slice(e)];m(i),a(e-1),E(-1),$(0)}return}if(l&&!r.ctrl&&!r.meta){let i=[...t.slice(0,e),...l,...t.slice(e)];m(i),a(e+l.length),E(-1),$(0)}},{isActive:x!=="search"}),Ce(l=>{if(l.home){a(0);return}if(l.end){a(t.length);return}if(l.killToEnd){m(t.slice(0,e));return}if(l.arrowLeft&&(l.ctrl||l.meta)){let r=e-1;for(;r>0&&t[r]===" ";)r--;for(;r>0&&t[r-1]!==" ";)r--;a(Math.max(0,r));return}if(l.arrowRight&&(l.ctrl||l.meta)){let r=e;for(;r<t.length&&t[r]!==" ";)r++;for(;r<t.length&&t[r]===" ";)r++;a(r);return}if(l.backspace&&l.meta){if(e===0)return;let r=e-1;for(;r>0&&t[r]===" ";)r--;for(;r>0&&t[r-1]!==" ";)r--;let i=[...t.slice(0,r),...t.slice(e)];m(i),a(r);return}if(l.delete&&(l.ctrl||l.meta)){let r=e;for(;r<t.length&&t[r]===" ";)r++;for(;r<t.length&&t[r]!==" ";)r++;m([...t.slice(0,e),...t.slice(r)]);return}},{isActive:x!=="search"});let ne=l=>{m([...l]),a(l.length),y("none")},U=()=>{y("none")},H=(()=>{if(I&&t.length===0)return null;let l=e>=t.length,r=t.slice(0,e).join(""),i=l?" ":t[e],S=l?"":t.slice(e+1).join(""),O="\u276F "+r+i+S+G,V=2,s=V+r.length,u=s+1,p=u+S.length,f=O.length,T=Math.max(1,Math.ceil(f/M)),P=[];for(let B=0;B<T;B++)P.push({start:B*M,end:Math.min((B+1)*M,f)});return{full:O,p:V,b:s,c:u,a:p,lines:P}})();return(0,L.jsxs)(w,{flexDirection:"column",children:[x==="search"&&(0,L.jsx)(Ee,{history:o,onSelect:ne,onClose:U}),W&&(0,L.jsx)(Pe,{commands:k,selectedIndex:N}),(0,L.jsx)(g,{color:v.muted,children:"\u2500".repeat(M)}),H===null?(0,L.jsxs)(w,{children:[(0,L.jsx)(g,{color:v.purple,children:"\u276F "}),(0,L.jsx)(g,{inverse:!0,children:" "}),(0,L.jsx)(g,{color:v.dimmed,children:d})]}):(0,L.jsx)(w,{flexDirection:"column",children:H.lines.map(({start:l,end:r},i)=>{let{full:S,p:O,b:V,c:s,a:u}=H,p=[];return r>0&&l<O&&p.push((0,L.jsx)(g,{color:v.purple,children:S.slice(Math.max(l,0),Math.min(O,r))},"p")),r>O&&l<V&&p.push((0,L.jsx)(g,{children:S.slice(Math.max(O,l),Math.min(V,r))},"b")),r>V&&l<s&&p.push((0,L.jsx)(g,{color:v.purple,inverse:!0,children:S.slice(Math.max(V,l),Math.min(s,r))},"c")),r>s&&l<u&&p.push((0,L.jsx)(g,{children:S.slice(Math.max(s,l),Math.min(u,r))},"a")),r>u&&p.push((0,L.jsx)(g,{color:v.dimmed,children:S.slice(Math.max(u,l),r)},"g")),(0,L.jsx)(w,{children:p},i)})}),(0,L.jsx)(ee,{bindings:[{keys:"\u2191\u2193",label:"history"},{keys:"\u21B5",label:"submit"},{keys:"tab",label:"complete"},{keys:"ctrl+r",label:"search"}],escBackLabel:"clear"})]})}var K=F(Z(),1);var b=F(Y(),1);function Ge(c){let n=[{id:"method",label:"Auth method",options:[{label:"Basic Auth",value:"basic"},{label:"OAuth (browser)",value:"oauth"}]}];return c&&n.push({id:"env",label:"Environment",options:[{label:"prod",value:"prod"},{label:"stage",value:"stage"}]}),n.push({id:"profile",label:"Profile"}),n.push({id:"credentials",label:"Credentials"}),n}function Re({devMode:c,profiles:n,onBasicLogin:o,onOAuthLogin:d,onComplete:h,onCancel:t}){let m=Ge(c),[e,a]=(0,K.useState)(0),[x,y]=(0,K.useState)(0),[D,E]=(0,K.useState)({}),[_,I]=(0,K.useState)("select"),[Q,j]=(0,K.useState)(""),[M,N]=(0,K.useState)("username"),[$,R]=(0,K.useState)(""),[G,k]=(0,K.useState)(null),[W,ne]=(0,K.useState)(null),U=m[e],H=D.method??"basic",l=D.env??"prod",r=(0,K.useCallback)(()=>{let f=n.filter(T=>T.env===l).map(T=>({label:`${T.profile} [${T.env}]`,value:T.profile}));return f.push({label:"+ Create new",value:"__new__"}),f},[n,l]),i=(0,K.useCallback)(()=>{e===0?t():(a(p=>p-1),y(0),I("select"),j(""),k(null))},[e,t]),S=(0,K.useCallback)(p=>{H==="basic"?(I("text-input"),N("username"),j("")):(I("waiting"),d(p,l).then(()=>{ne(`Logged in via OAuth as ${p} [${l}]`),I("done")}).catch(f=>{k(f.message),I("error")}))},[H,l,d]),O=(0,K.useCallback)(p=>{let f=p.trim();if(f){if(M==="profileName"){let T=f;E(P=>({...P,profile:T})),S(T);return}if(M==="username"){R(f),j(""),N("accessKey"),I("text-input-masked");return}if(M==="accessKey"){let T=D.profile??"default";I("waiting"),(async()=>{try{await o(T,l,$,f),ne(`Logged in as ${T} [${l}] via basic auth`),I("done")}catch{k("Credentials not valid. Please use valid credentials."),R(""),j(""),N("username"),I("text-input")}})()}}},[M,D.profile,l,o,$,S]),V=(0,K.useCallback)(p=>{j(p),G&&k(null)},[G]);z((p,f)=>{if(_==="done"){let P=D.profile??"default";h(P,l);return}if(_==="error"){t();return}if(_==="waiting"){f.escape&&t();return}if(_==="text-input"||_==="text-input-masked")return;if(f.escape){i();return}let T=U?.id==="profile"?r():U?.options??[];if(f.upArrow){y(P=>Math.max(0,P-1));return}if(f.downArrow){y(P=>Math.min(T.length-1,P+1));return}if(f.return&&T[x]){let P=T[x];if(U.id==="profile"){if(P.value==="__new__"){I("text-input"),N("profileName"),j("");return}E(B=>({...B,profile:P.value})),a(B=>B+1),y(0),S(P.value);return}E(B=>({...B,[U.id]:P.value})),a(B=>B+1),y(0)}});let s="Login";if(_==="done")return(0,b.jsxs)(w,{flexDirection:"column",borderStyle:"round",borderColor:v.statusPass,paddingX:2,paddingY:1,children:[(0,b.jsxs)(g,{color:v.statusPass,bold:!0,children:["\u2713 ",W]}),(0,b.jsx)(w,{marginTop:1,children:(0,b.jsx)(g,{color:v.dim,children:"press any key"})})]});if(_==="error")return(0,b.jsxs)(w,{flexDirection:"column",borderStyle:"round",borderColor:v.statusFail,paddingX:2,paddingY:1,children:[(0,b.jsx)(g,{color:v.statusFail,bold:!0,children:"Login failed"}),(0,b.jsx)(w,{marginTop:1,children:(0,b.jsx)(g,{color:v.statusFail,children:G})}),(0,b.jsx)(w,{marginTop:1,children:(0,b.jsx)(g,{color:v.dim,children:"press any key"})})]});if(_==="waiting")return(0,b.jsxs)(w,{flexDirection:"column",borderStyle:"round",borderColor:v.primary,paddingX:2,paddingY:1,children:[(0,b.jsxs)(g,{color:v.primary,bold:!0,children:[s," \u203A OAuth"]}),(0,b.jsx)(w,{marginTop:1,children:(0,b.jsx)(g,{color:v.secondary,children:"Opening browser for login..."})}),(0,b.jsx)(w,{marginTop:1,children:(0,b.jsx)(g,{color:v.primary,children:"Waiting for callback \u27F3"})}),(0,b.jsx)(ee,{bindings:[],escBackLabel:"cancel"})]});if(_==="text-input"||_==="text-input-masked"){let p=M==="username"?"Username":M==="accessKey"?"Access Key":"Profile name",f=M==="username"||M==="accessKey"?`${s} \u203A Basic Auth`:`${s} \u203A New Profile`;return(0,b.jsxs)(w,{flexDirection:"column",borderStyle:"round",borderColor:v.primary,paddingX:2,paddingY:1,children:[G&&(M==="username"||M==="accessKey")&&(0,b.jsx)(w,{marginBottom:1,children:(0,b.jsxs)(g,{color:v.statusFail,children:["\u2717 ",G]})}),(0,b.jsx)(g,{color:v.primary,bold:!0,children:f}),M==="accessKey"&&(0,b.jsxs)(w,{marginTop:1,children:[(0,b.jsx)(g,{color:v.secondary,children:"Username: "}),(0,b.jsx)(g,{children:$})]}),(0,b.jsxs)(w,{marginTop:1,children:[(0,b.jsxs)(g,{color:v.secondary,children:[p,": "]}),(0,b.jsx)(we,{value:Q,onChange:V,onSubmit:O,onCancel:i,masked:_==="text-input-masked"})]}),(0,b.jsx)(ee,{bindings:[{keys:"\u21B5",label:"confirm"}],escBackLabel:"back"})]})}let u=U?.id==="profile"?r():U?.options??[];return(0,b.jsxs)(w,{flexDirection:"column",borderStyle:"round",borderColor:v.primary,paddingX:2,paddingY:1,children:[(0,b.jsx)(g,{color:v.primary,bold:!0,children:s}),(0,b.jsx)(w,{marginTop:1,children:(0,b.jsxs)(g,{color:v.secondary,children:[U?.label,":"]})}),(0,b.jsx)(w,{flexDirection:"column",marginTop:1,children:u.map((p,f)=>{let T=f===x,P=T?"\u276F ":" ",B=p.value==="__new__"?v.statusPass:T?v.primary:void 0;return(0,b.jsxs)(g,{color:B,children:[P,p.label]},p.value)})}),(0,b.jsx)(ee,{bindings:[{keys:"\u2191\u2193",label:"navigate"},{keys:"\u21B5",label:"select"}],escBackLabel:"back"})]})}var Be=F(Z(),1);import{readFileSync as We,writeFileSync as He,mkdirSync as Ve}from"fs";import{dirname as Xe,join as Ye}from"path";var ze=Ye(xe,"command-history.json"),qe=200,me=class{entries;filePath;max;constructor(n=ze,o=qe){this.filePath=n,this.max=o,this.entries=this._load()}push(n){this.entries.length>0&&this.entries[this.entries.length-1]===n||(this.entries.push(n),this.entries.length>this.max&&(this.entries=this.entries.slice(this.entries.length-this.max)),this._save())}getAll(){return[...this.entries]}search(n){let o=n.toLowerCase(),d=[];for(let h=this.entries.length-1;h>=0;h--)this.entries[h].toLowerCase().includes(o)&&d.push(this.entries[h]);return d}_load(){try{let n=We(this.filePath,"utf-8"),o=JSON.parse(n);return Array.isArray(o)?o:[]}catch{return[]}}_save(){try{Ve(Xe(this.filePath),{recursive:!0}),He(this.filePath,JSON.stringify(this.entries)+`
3
- `)}catch{}}};function De(c){let n=(0,Be.useRef)(null);return n.current||(n.current=new me(c)),n.current}async function ue(c,n,o,d){let h=c.loadBasicAuth(n,o),t=c.loadCredentials(n,o);if(!h&&!t)return d("info","STARTUP_GATE_NO_CREDS","Profile has no credentials",{profile:n,env:o}),{status:"needs_login",profile:n,env:o};let m=te(o),e=async()=>c.loadCredentials(n,o)?.access_token??null,a=new le(m.controllerBaseUrl,e,h,d);d("info","STARTUP_GATE_VALIDATE","Validating credentials with controller",{profile:n,env:o,method:h?"basic":"oauth"});let x=await a.resolve(!0);if(x)return d("info","STARTUP_GATE_VALID","Credentials validated",{profile:n,env:o,username:x.username,org_id:x.org_id}),{status:"authenticated",result:{profile:n,env:o,credentials:t,basicAuth:h,tmsCreds:x,resolver:a}};if(!h&&t){let y=t.refresh_token,E=c.loadClient(n,o)?.client_id;if(y&&E){d("info","STARTUP_GATE_REFRESH","Attempting token refresh",{profile:n,env:o});try{let I=await new ye(o).refreshToken(y,E);if(I.access_token){c.saveCredentials(n,o,{...t,...I,expires_at:Date.now()/1e3+(I.expires_in??3600)});let j=await a.resolve(!0);if(j)return d("info","STARTUP_GATE_REFRESH_OK","Token refreshed and validated",{profile:n,env:o,username:j.username}),{status:"authenticated",result:{profile:n,env:o,credentials:{...t,...I},basicAuth:null,tmsCreds:j,resolver:a}}}d("warn","STARTUP_GATE_REFRESH_INVALID","Refreshed token still invalid",{profile:n,env:o})}catch(_){d("warn","STARTUP_GATE_REFRESH_FAILED","Token refresh failed",{profile:n,env:o,error:_ instanceof Error?_.message:String(_)})}}else d("info","STARTUP_GATE_NO_REFRESH","No refresh_token or client_id \u2014 login required",{profile:n,env:o})}return d("info","STARTUP_GATE_INVALID","Credentials invalid \u2014 login required",{profile:n,env:o}),{status:"needs_login",profile:n,env:o}}async function Ie(c,n,o=new ae){let d=c.listProfiles();if(n("info","STARTUP_GATE_START","Auth startup gate",{profile_count:d.length}),d.length===0)return n("info","STARTUP_GATE_NONE","No profiles found \u2014 login required"),{status:"needs_login"};if(d.length>1){let m=c.getActiveProfile(),e=c.getDefaultEnv();if(m&&d.some(x=>x.profile===m&&x.env===e)){n("info","STARTUP_GATE_TRY_ACTIVE","Multiple profiles \u2014 trying active first",{activeProfile:m,activeEnv:e});let x=await ue(c,m,e,n);if(x.status==="authenticated")return x;n("info","STARTUP_GATE_ACTIVE_FAILED","Active profile invalid \u2014 showing picker",{activeProfile:m,activeEnv:e})}return n("info","STARTUP_GATE_MULTI","Multiple profiles \u2014 picker required",{profiles:d.map(a=>`${a.profile}/${a.env}`)}),{status:"needs_pick",profiles:d}}let{profile:h,env:t}=d[0];return c.setActiveProfile(h),c.setDefaultEnv(t),re(c,o,h,t),ue(c,h,t,n)}var A=F(Y(),1);function Vt({resultRef:c,mode:n="singleshot",loginCompleteRef:o}){let{exit:d}=ge(),h=(0,C.useRef)(new ve),t=(0,C.useRef)(new ae),m=(0,C.useRef)(new Se),e=h.current,a=t.current,x=m.current,y=De(),[D,E]=(0,C.useState)(n==="login"?"login":"gate"),[_,I]=(0,C.useState)(null),[Q,j]=(0,C.useState)(null),[M,N]=(0,C.useState)(null),[$,R]=(0,C.useState)(null),[G,k]=(0,C.useState)([]),W=(0,C.useCallback)((s,u,p,f)=>x.log(s,u,p,f),[x]),ne=(0,C.useCallback)((s,u)=>{s?re(e,a,s,u):a.save({project_id:null,project_name:null,folder_id:null,folder_name:null})},[e,a]),U=(0,C.useCallback)(()=>{n==="login"?(o&&(o.current=!0),d()):E("input")},[n,d,o]),H=(0,C.useCallback)((s,u)=>{let p=re(e,a,s,u);if(n==="login"){E("ensure-project");return}Ae(p)?U():p.projectId?E("ensure-folder"):E("ensure-project")},[e,a,U,n]);z((s,u)=>{u.ctrl&&s==="c"&&ie(0,"Ctrl+C exit")});let l=(0,C.useRef)(!1);C.default.useEffect(()=>{l.current||(l.current=!0,n!=="login"&&Ie(e,W).then(s=>{I(s),s.status==="authenticated"?H(s.result.profile,s.result.env):s.status==="needs_pick"?E("pick"):(j(s.profile??null),N(s.env??null),E("login"))}).catch(s=>{R(`Auth check failed: ${s instanceof Error?s.message:String(s)}`)}))},[e,W]);let r=(0,C.useCallback)(s=>{c.current={objective:s},d()},[c,d]),i=(0,C.useCallback)(async(s,u)=>{e.setActiveProfile(s),e.setDefaultEnv(u),(await ue(e,s,u,W)).status==="authenticated"?H(s,u):(j(s),N(u),E("login"))},[e,W,H]),S=(0,C.useCallback)(()=>{let s=e.getActiveProfile(),u=e.getDefaultEnv();if(!s)return null;let p=te(u),f=e.loadBasicAuth(s,u);return new le(p.controllerBaseUrl,async()=>e.loadCredentials(s,u)?.access_token??null,f,W)},[e,W]),O=(0,C.useCallback)(async()=>{let s=S();if(!s)return null;let u=s.cached??await s.resolve();if(!u)return null;let p=te(e.getDefaultEnv()),f=new fe(p.tmsBaseUrl,u.username,u.access_key);try{let P=(await f.listProjects()).find(se=>se.name==="KaneAI Generated");if(P)return{id:P.project_id,name:P.name};let B=await f.createProject("KaneAI Generated");return{id:B.id,name:B.name}}catch{return null}},[S,e]),V=(0,C.useCallback)(async s=>{let u=S();if(!u)return null;let p=u.cached??await u.resolve();if(!p)return null;let f=te(e.getDefaultEnv()),T=new fe(f.tmsBaseUrl,p.username,p.access_key);try{let B=(await T.listFolders(s)).find(Le=>Le.name==="Untitled");if(B)return{id:B.id,name:B.name};let se=await T.createFolder(s,"Untitled");return{id:se.id,name:se.name}}catch{return null}},[S,e]);if(D==="gate")return(0,A.jsx)(w,{paddingX:1,children:(0,A.jsx)(g,{color:"yellow",children:"Checking authentication..."})});if($)return(0,A.jsxs)(w,{flexDirection:"column",paddingX:1,children:[(0,A.jsx)(g,{color:"red",children:$}),(0,A.jsx)(g,{color:"gray",children:"Press Ctrl+C to exit."})]});if(D==="pick"&&_?.status==="needs_pick")return(0,A.jsx)(Je,{profiles:_.profiles,onSelect:i});if(D==="login")return(0,A.jsx)(Re,{devMode:process.env.KANE_DEV_MODE==="1",profiles:e.listProfiles(),onBasicLogin:async(s,u,p,f)=>{let{validateBasicAuth:T}=await import("./validate-basic-TW5CQAL3.js");await T(u,p,f),e.saveBasicAuth(s,u,{username:p,access_key:f}),e.setActiveProfile(s),e.setDefaultEnv(u)},onOAuthLogin:async(s,u)=>{let{LoginFlow:p}=await import("./login-flow-QCYF5347.js");e.setDefaultEnv(u),e.setActiveProfile(s),await new p(s,u,e).login()},onComplete:(s,u)=>{j(s),N(u),e.setActiveProfile(s),e.setDefaultEnv(u),H(s,u)},onCancel:()=>{ie(0,"Login cancelled")}});if(D==="ensure-project"){let s=e.getActiveProfile()??"default",u=e.getDefaultEnv(),p=()=>{if(n==="login"){E("ensure-folder");return}re(e,a,s,u).folderId?U():E("ensure-folder")};return(0,A.jsxs)(w,{flexDirection:"column",children:[(0,A.jsx)(w,{paddingX:1,marginBottom:1,children:(0,A.jsx)(g,{color:"yellow",children:"Project & folder are required to save tests \xB7 Esc to use defaults \xB7 Ctrl+C to exit"})}),(0,A.jsx)(Te,{resolver:S(),currentProjectId:a.load().project_id,env:u,onSelect:(f,T)=>{oe(e,a,s,u,{projectId:f,projectName:T}),k(P=>[...P,`\u2713 Project: ${T} (${f})`]),p()},onCancel:async()=>{let f=await O();f&&(oe(e,a,s,u,{projectId:f.id,projectName:f.name}),k(T=>[...T,`\u2713 Default project: ${f.name} (${f.id})`]),p())}})]})}if(D==="ensure-folder"){let s=e.getActiveProfile()??"default",u=e.getDefaultEnv(),p=e.loadProfileConfig(s,u);return(0,A.jsxs)(w,{flexDirection:"column",children:[(0,A.jsx)(w,{paddingX:1,marginBottom:1,children:(0,A.jsx)(g,{color:"yellow",children:"Project & folder are required to save tests \xB7 Esc to use defaults \xB7 Ctrl+C to exit"})}),(0,A.jsx)(be,{resolver:S(),projectId:p?.project_id??"",currentFolderId:a.load().folder_id,env:u,onSelect:(f,T)=>{oe(e,a,s,u,{folderId:f,folderName:T}),k(P=>[...P,`\u2713 Folder: ${T} (${f})`]),U()},onCancel:async()=>{if(!p?.project_id)return;let f=await V(p.project_id);f&&(oe(e,a,s,u,{folderId:f.id,folderName:f.name}),k(T=>[...T,`\u2713 Default folder: ${f.name} (${f.id})`]),U())}})]})}return D==="input"?(0,A.jsxs)(w,{flexDirection:"column",children:[G.length>0&&(0,A.jsx)(w,{flexDirection:"column",paddingX:1,marginBottom:1,children:G.map((s,u)=>(0,A.jsx)(g,{color:"green",children:s},u))}),(0,A.jsx)(_e,{onSubmit:r,onEscape:()=>ie(0,"User pressed Escape"),history:y,placeholder:"Type an objective..."})]}):(0,A.jsx)(A.Fragment,{})}function Je({profiles:c,onSelect:n}){let[o,d]=(0,C.useState)(0),[h,t]=(0,C.useState)(!1);return z((m,e)=>{if(!h){if(e.escape){ie(0,"Profile picker cancelled");return}if(e.upArrow&&o>0&&d(a=>a-1),e.downArrow&&o<c.length-1&&d(a=>a+1),e.return){t(!0);let a=c[o];n(a.profile,a.env).catch(()=>t(!1))}}}),(0,A.jsxs)(w,{flexDirection:"column",paddingX:1,children:[(0,A.jsx)(g,{color:"#ff9500",bold:!0,children:"Select a profile:"}),(0,A.jsx)(w,{marginTop:1,flexDirection:"column",children:c.map((m,e)=>(0,A.jsxs)(g,{children:[e===o?"\u276F ":" ",(0,A.jsx)(g,{color:e===o?"#ff9500":"white",bold:e===o,children:m.profile}),(0,A.jsxs)(g,{color:"gray",children:[" [",m.env,"]"]})]},`${m.profile}-${m.env}`))}),h&&(0,A.jsx)(w,{marginTop:1,children:(0,A.jsx)(g,{color:"yellow",children:"Validating credentials..."})})]})}export{De as a,_e as b,Re as c,ue as d,Ie as e,Vt as f};
2
+ import{b as Se}from"./chunk-BM4COXQU.js";import{f as ie}from"./chunk-G7VF5SDK.js";import{a as ae}from"./chunk-KVDOQY2Q.js";import{b as Te}from"./chunk-ZLQ7YLXO.js";import{b as be}from"./chunk-3QD3LA72.js";import{a as we}from"./chunk-YCCUBQY4.js";import{a as re,b as oe,d as Ae}from"./chunk-VE3SUJMA.js";import{a as ve,b as ye}from"./chunk-K7MSPKEM.js";import{a as te}from"./chunk-TK7ZJ7YX.js";import{a as le}from"./chunk-PWGEMRBD.js";import{a as ee}from"./chunk-HJ3CHMEM.js";import{a as Y}from"./chunk-HCBYKLMW.js";import{c as xe,t as v}from"./chunk-3ELBJPHQ.js";import{a as w,b as g,h as pe,i as z,j as ge,k as he}from"./chunk-C44QQJR4.js";import{a as Z}from"./chunk-6YGTRKDT.js";import{a as fe}from"./chunk-YUUZDFT7.js";import{e as F}from"./chunk-UR6MHSHU.js";var C=F(Z(),1);var q=F(Z(),1);var de=F(Z(),1);var X=F(Y(),1);function Ee({history:c,onSelect:n,onClose:o}){let[d,h]=(0,de.useState)(""),[t,m]=(0,de.useState)(0),e=d?c.search(d).slice(0,8):[];return z((a,x)=>{if(x.escape){o();return}if(x.return){e.length>0&&e[t]?n(e[t]):o();return}if(x.upArrow){m(y=>Math.max(0,y-1));return}if(x.downArrow){m(y=>Math.min(e.length-1,y+1));return}if(x.backspace||x.delete){h(y=>y.slice(0,-1)),m(0);return}a&&!x.ctrl&&!x.meta&&(h(y=>y+a),m(0))}),(0,X.jsxs)(w,{flexDirection:"column",marginLeft:2,borderStyle:"single",paddingX:1,children:[(0,X.jsx)(g,{color:v.muted,bold:!0,children:"reverse search"}),(0,X.jsxs)(w,{gap:1,children:[(0,X.jsx)(g,{color:v.dimmed,children:"search:"}),(0,X.jsx)(g,{children:d}),(0,X.jsx)(g,{color:v.purple,children:"\u2588"})]}),e.length>0&&(0,X.jsx)(g,{children:" "}),e.map((a,x)=>(0,X.jsx)(w,{marginLeft:2,children:(0,X.jsxs)(g,{color:x===t?v.purple:v.dimmed,bold:x===t,children:[x===t?"\u25B8 ":" ",a]})},`${x}-${a}`))]})}var J=F(Y(),1);function Pe({commands:c,selectedIndex:n}){return c.length===0?null:(0,J.jsx)(w,{flexDirection:"column",marginBottom:0,children:c.map((o,d)=>{let h=d===n;return(0,J.jsxs)(w,{children:[(0,J.jsx)(g,{color:h?v.primary:v.dimmed,children:h?"\u276F ":" "}),(0,J.jsxs)(g,{color:h?v.primary:void 0,bold:h,children:["/",o.name]}),o.args&&(0,J.jsxs)(g,{color:v.dimmed,children:[" ",o.args]}),(0,J.jsxs)(g,{color:v.dimmed,children:[" ",o.description]})]},o.name)})})}var ce=F(Z(),1);var Me=27,ke=127,Oe=11;function je(c){return c>=64&&c<=126}function Fe(c,n){c===Oe&&n({killToEnd:!0,ctrl:!0,raw:String.fromCharCode(c)})}function Ke(c,n){c===ke&&n({backspace:!0,meta:!0,raw:"\x1B\x7F"})}function Ue(c,n){let o=c.map(h=>String.fromCharCode(h)).join(""),d=/^\[1;([0-9]+)([A-D])$/.exec(o);if(d){let h=parseInt(d[1],10),t=d[2],m={raw:"\x1B"+o};if(h===2)m.shift=!0;else if(h===3)m.meta=!0;else if(h===5)m.ctrl=!0;else return;t==="A"?m.arrowUp=!0:t==="B"?m.arrowDown=!0:t==="C"?m.arrowRight=!0:t==="D"&&(m.arrowLeft=!0),n(m);return}if(o==="[H"||o==="[1~"||o==="[7~"){n({home:!0,raw:"\x1B"+o});return}if(o==="[F"||o==="[4~"||o==="[8~"){n({end:!0,raw:"\x1B"+o});return}if(o==="[3;5~"){n({delete:!0,ctrl:!0,raw:"\x1B"+o});return}if(o==="[3;3~"){n({delete:!0,meta:!0,raw:"\x1B"+o});return}}function Ne(c,n){c===72?n({home:!0,raw:"\x1BO"+String.fromCharCode(c)}):c===70&&n({end:!0,raw:"\x1BO"+String.fromCharCode(c)})}function $e(){let c="IDLE",n=[];function o(){c="IDLE",n=[]}return{feed(d,h){for(let t of d)c==="IDLE"?t===Me?(c="ESC",n=[]):Fe(t,h):c==="ESC"?t===91?(c="CSI",n=[]):t===79?(c="SS3",n=[]):(Ke(t,h),o()):c==="CSI"?(n.push(t),je(t)&&(Ue([91,...n],h),o())):c==="SS3"&&(Ne(t,h),o())},flushIdle(d){c==="ESC"&&n.length===0&&d({raw:"\x1B"}),o()}}}function Ce(c,n={}){let o=(0,ce.useRef)(c);o.current=c;let{stdin:d}=pe();(0,ce.useEffect)(()=>{if(n.isActive===!1||!d)return;let h=$e(),t=null,m=e=>{t&&(clearTimeout(t),t=null);let a=Buffer.isBuffer(e)?e:Buffer.from(e,"binary");h.feed(a,x=>o.current(x)),t=setTimeout(()=>{h.flushIdle(x=>o.current(x)),t=null},50)};return d.on("data",m),()=>{d.removeListener("data",m),t&&clearTimeout(t)}},[n.isActive,d])}var L=F(Y(),1);function _e({onSubmit:c,onEscape:n,history:o,placeholder:d="Type an objective or /command...",commands:h}){let[t,m]=(0,q.useState)([]),[e,a]=(0,q.useState)(0),[x,y]=(0,q.useState)("none"),[D,E]=(0,q.useState)(-1),_=(0,q.useRef)(""),[I,Q]=(0,q.useState)(!0),{stdout:j}=he(),M=j?.columns??80,[N,$]=(0,q.useState)(0),R=t.join(""),G=(()=>{if(x!=="none"||t.length===0)return"";if(R.startsWith("/")&&h&&R.length>=2){let r=R.slice(1).toLowerCase(),i=h.find(S=>S.name.startsWith(r)&&S.name!==r);return i?`/${i.name}`.slice(R.length):""}if(R.startsWith("/"))return"";let l=o.getAll();for(let r=l.length-1;r>=0;r--)if(l[r].startsWith(R)&&l[r]!==R)return l[r].slice(R.length);return""})(),k=(()=>{if(!h||!R.startsWith("/"))return[];let l=R.length>=2?R.slice(1).toLowerCase():"";return l&&h.some(r=>r.name===l)?[]:h.filter(r=>!l||r.name.startsWith(l))})(),W=k.length>0&&R.startsWith("/");z((l,r)=>{if(I&&l&&Q(!1),r.return){if(W&&k[N]){let i=`/${k[N].name}`;o.push(i),c(i),m([]),a(0),y("none"),E(-1),_.current="",Q(!0),$(0);return}R.trim()&&(o.push(R.trim()),c(R.trim()),m([]),a(0),y("none"),E(-1),_.current="",Q(!0),$(0));return}if(r.escape){x!=="none"?y("none"):t.length>0?(m([]),a(0),E(-1),_.current=""):n?.();return}if(r.tab){if(W&&k[N]){let i=`/${k[N].name}`;m([...i]),a(i.length),$(0);return}if(G){let i=R+G;m([...i]),a(i.length);return}return}if(r.ctrl&&l==="r"){y("search");return}if(r.ctrl&&l==="a"){a(0);return}if(r.ctrl&&l==="e"){a(t.length);return}if(r.ctrl&&l==="w"){if(e===0)return;let i=e-1;for(;i>0&&t[i]===" ";)i--;for(;i>0&&t[i-1]!==" ";)i--;let S=[...t.slice(0,i),...t.slice(e)];m(S),a(i);return}if(r.ctrl&&l==="u"){m([]),a(0),E(-1),y("none");return}if(r.meta&&l==="b"){let i=e-1;for(;i>0&&t[i]===" ";)i--;for(;i>0&&t[i-1]!==" ";)i--;a(Math.max(0,i));return}if(r.meta&&l==="f"){let i=e;for(;i<t.length&&t[i]!==" ";)i++;for(;i<t.length&&t[i]===" ";)i++;a(i);return}if(r.leftArrow){if(r.ctrl||r.shift)return;a(i=>Math.max(0,i-1));return}if(r.rightArrow){if(r.ctrl||r.shift)return;if(e>=t.length&&G){let i=R+G;m([...i]),a(i.length)}else a(i=>Math.min(t.length,i+1));return}if(r.upArrow){if(r.shift)return;if(W){$(i=>Math.max(0,i-1));return}if(x==="none"){let i=o.getAll();if(i.length===0)return;if(D===-1){_.current=R,E(i.length-1);let S=i[i.length-1];m([...S]),a(S.length)}else if(D>0){let S=D-1;E(S);let O=i[S];m([...O]),a(O.length)}}return}if(r.downArrow){if(r.shift)return;if(W){$(i=>Math.min(k.length-1,i+1));return}if(x==="none"){let i=o.getAll();if(D===-1)return;if(D<i.length-1){let S=D+1;E(S);let O=i[S];m([...O]),a(O.length)}else{E(-1);let S=_.current;m([...S]),a(S.length)}}return}if(r.backspace||r.delete){if(r.meta||r.ctrl)return;if(e>0){let i=[...t.slice(0,e-1),...t.slice(e)];m(i),a(e-1),E(-1),$(0)}return}if(l&&!r.ctrl&&!r.meta){let i=[...t.slice(0,e),...l,...t.slice(e)];m(i),a(e+l.length),E(-1),$(0)}},{isActive:x!=="search"}),Ce(l=>{if(l.home){a(0);return}if(l.end){a(t.length);return}if(l.killToEnd){m(t.slice(0,e));return}if(l.arrowLeft&&(l.ctrl||l.meta)){let r=e-1;for(;r>0&&t[r]===" ";)r--;for(;r>0&&t[r-1]!==" ";)r--;a(Math.max(0,r));return}if(l.arrowRight&&(l.ctrl||l.meta)){let r=e;for(;r<t.length&&t[r]!==" ";)r++;for(;r<t.length&&t[r]===" ";)r++;a(r);return}if(l.backspace&&l.meta){if(e===0)return;let r=e-1;for(;r>0&&t[r]===" ";)r--;for(;r>0&&t[r-1]!==" ";)r--;let i=[...t.slice(0,r),...t.slice(e)];m(i),a(r);return}if(l.delete&&(l.ctrl||l.meta)){let r=e;for(;r<t.length&&t[r]===" ";)r++;for(;r<t.length&&t[r]!==" ";)r++;m([...t.slice(0,e),...t.slice(r)]);return}},{isActive:x!=="search"});let ne=l=>{m([...l]),a(l.length),y("none")},U=()=>{y("none")},H=(()=>{if(I&&t.length===0)return null;let l=e>=t.length,r=t.slice(0,e).join(""),i=l?" ":t[e],S=l?"":t.slice(e+1).join(""),O="\u276F "+r+i+S+G,V=2,s=V+r.length,u=s+1,p=u+S.length,f=O.length,T=Math.max(1,Math.ceil(f/M)),P=[];for(let B=0;B<T;B++)P.push({start:B*M,end:Math.min((B+1)*M,f)});return{full:O,p:V,b:s,c:u,a:p,lines:P}})();return(0,L.jsxs)(w,{flexDirection:"column",children:[x==="search"&&(0,L.jsx)(Ee,{history:o,onSelect:ne,onClose:U}),W&&(0,L.jsx)(Pe,{commands:k,selectedIndex:N}),(0,L.jsx)(g,{color:v.muted,children:"\u2500".repeat(M)}),H===null?(0,L.jsxs)(w,{children:[(0,L.jsx)(g,{color:v.purple,children:"\u276F "}),(0,L.jsx)(g,{inverse:!0,children:" "}),(0,L.jsx)(g,{color:v.dimmed,children:d})]}):(0,L.jsx)(w,{flexDirection:"column",children:H.lines.map(({start:l,end:r},i)=>{let{full:S,p:O,b:V,c:s,a:u}=H,p=[];return r>0&&l<O&&p.push((0,L.jsx)(g,{color:v.purple,children:S.slice(Math.max(l,0),Math.min(O,r))},"p")),r>O&&l<V&&p.push((0,L.jsx)(g,{children:S.slice(Math.max(O,l),Math.min(V,r))},"b")),r>V&&l<s&&p.push((0,L.jsx)(g,{color:v.purple,inverse:!0,children:S.slice(Math.max(V,l),Math.min(s,r))},"c")),r>s&&l<u&&p.push((0,L.jsx)(g,{children:S.slice(Math.max(s,l),Math.min(u,r))},"a")),r>u&&p.push((0,L.jsx)(g,{color:v.dimmed,children:S.slice(Math.max(u,l),r)},"g")),(0,L.jsx)(w,{children:p},i)})}),(0,L.jsx)(ee,{bindings:[{keys:"\u2191\u2193",label:"history"},{keys:"\u21B5",label:"submit"},{keys:"tab",label:"complete"},{keys:"ctrl+r",label:"search"}],escBackLabel:"clear"})]})}var K=F(Z(),1);var b=F(Y(),1);function Ge(c){let n=[{id:"method",label:"Auth method",options:[{label:"Basic Auth",value:"basic"},{label:"OAuth (browser)",value:"oauth"}]}];return c&&n.push({id:"env",label:"Environment",options:[{label:"prod",value:"prod"},{label:"stage",value:"stage"}]}),n.push({id:"profile",label:"Profile"}),n.push({id:"credentials",label:"Credentials"}),n}function Re({devMode:c,profiles:n,onBasicLogin:o,onOAuthLogin:d,onComplete:h,onCancel:t}){let m=Ge(c),[e,a]=(0,K.useState)(0),[x,y]=(0,K.useState)(0),[D,E]=(0,K.useState)({}),[_,I]=(0,K.useState)("select"),[Q,j]=(0,K.useState)(""),[M,N]=(0,K.useState)("username"),[$,R]=(0,K.useState)(""),[G,k]=(0,K.useState)(null),[W,ne]=(0,K.useState)(null),U=m[e],H=D.method??"basic",l=D.env??"prod",r=(0,K.useCallback)(()=>{let f=n.filter(T=>T.env===l).map(T=>({label:`${T.profile} [${T.env}]`,value:T.profile}));return f.push({label:"+ Create new",value:"__new__"}),f},[n,l]),i=(0,K.useCallback)(()=>{e===0?t():(a(p=>p-1),y(0),I("select"),j(""),k(null))},[e,t]),S=(0,K.useCallback)(p=>{H==="basic"?(I("text-input"),N("username"),j("")):(I("waiting"),d(p,l).then(()=>{ne(`Logged in via OAuth as ${p} [${l}]`),I("done")}).catch(f=>{k(f.message),I("error")}))},[H,l,d]),O=(0,K.useCallback)(p=>{let f=p.trim();if(f){if(M==="profileName"){let T=f;E(P=>({...P,profile:T})),S(T);return}if(M==="username"){R(f),j(""),N("accessKey"),I("text-input-masked");return}if(M==="accessKey"){let T=D.profile??"default";I("waiting"),(async()=>{try{await o(T,l,$,f),ne(`Logged in as ${T} [${l}] via basic auth`),I("done")}catch{k("Credentials not valid. Please use valid credentials."),R(""),j(""),N("username"),I("text-input")}})()}}},[M,D.profile,l,o,$,S]),V=(0,K.useCallback)(p=>{j(p),G&&k(null)},[G]);z((p,f)=>{if(_==="done"){let P=D.profile??"default";h(P,l);return}if(_==="error"){t();return}if(_==="waiting"){f.escape&&t();return}if(_==="text-input"||_==="text-input-masked")return;if(f.escape){i();return}let T=U?.id==="profile"?r():U?.options??[];if(f.upArrow){y(P=>Math.max(0,P-1));return}if(f.downArrow){y(P=>Math.min(T.length-1,P+1));return}if(f.return&&T[x]){let P=T[x];if(U.id==="profile"){if(P.value==="__new__"){I("text-input"),N("profileName"),j("");return}E(B=>({...B,profile:P.value})),a(B=>B+1),y(0),S(P.value);return}E(B=>({...B,[U.id]:P.value})),a(B=>B+1),y(0)}});let s="Login";if(_==="done")return(0,b.jsxs)(w,{flexDirection:"column",borderStyle:"round",borderColor:v.statusPass,paddingX:2,paddingY:1,children:[(0,b.jsxs)(g,{color:v.statusPass,bold:!0,children:["\u2713 ",W]}),(0,b.jsx)(w,{marginTop:1,children:(0,b.jsx)(g,{color:v.dim,children:"press any key"})})]});if(_==="error")return(0,b.jsxs)(w,{flexDirection:"column",borderStyle:"round",borderColor:v.statusFail,paddingX:2,paddingY:1,children:[(0,b.jsx)(g,{color:v.statusFail,bold:!0,children:"Login failed"}),(0,b.jsx)(w,{marginTop:1,children:(0,b.jsx)(g,{color:v.statusFail,children:G})}),(0,b.jsx)(w,{marginTop:1,children:(0,b.jsx)(g,{color:v.dim,children:"press any key"})})]});if(_==="waiting")return(0,b.jsxs)(w,{flexDirection:"column",borderStyle:"round",borderColor:v.primary,paddingX:2,paddingY:1,children:[(0,b.jsxs)(g,{color:v.primary,bold:!0,children:[s," \u203A OAuth"]}),(0,b.jsx)(w,{marginTop:1,children:(0,b.jsx)(g,{color:v.secondary,children:"Opening browser for login..."})}),(0,b.jsx)(w,{marginTop:1,children:(0,b.jsx)(g,{color:v.primary,children:"Waiting for callback \u27F3"})}),(0,b.jsx)(ee,{bindings:[],escBackLabel:"cancel"})]});if(_==="text-input"||_==="text-input-masked"){let p=M==="username"?"Username":M==="accessKey"?"Access Key":"Profile name",f=M==="username"||M==="accessKey"?`${s} \u203A Basic Auth`:`${s} \u203A New Profile`;return(0,b.jsxs)(w,{flexDirection:"column",borderStyle:"round",borderColor:v.primary,paddingX:2,paddingY:1,children:[G&&(M==="username"||M==="accessKey")&&(0,b.jsx)(w,{marginBottom:1,children:(0,b.jsxs)(g,{color:v.statusFail,children:["\u2717 ",G]})}),(0,b.jsx)(g,{color:v.primary,bold:!0,children:f}),M==="accessKey"&&(0,b.jsxs)(w,{marginTop:1,children:[(0,b.jsx)(g,{color:v.secondary,children:"Username: "}),(0,b.jsx)(g,{children:$})]}),(0,b.jsxs)(w,{marginTop:1,children:[(0,b.jsxs)(g,{color:v.secondary,children:[p,": "]}),(0,b.jsx)(we,{value:Q,onChange:V,onSubmit:O,onCancel:i,masked:_==="text-input-masked"})]}),(0,b.jsx)(ee,{bindings:[{keys:"\u21B5",label:"confirm"}],escBackLabel:"back"})]})}let u=U?.id==="profile"?r():U?.options??[];return(0,b.jsxs)(w,{flexDirection:"column",borderStyle:"round",borderColor:v.primary,paddingX:2,paddingY:1,children:[(0,b.jsx)(g,{color:v.primary,bold:!0,children:s}),(0,b.jsx)(w,{marginTop:1,children:(0,b.jsxs)(g,{color:v.secondary,children:[U?.label,":"]})}),(0,b.jsx)(w,{flexDirection:"column",marginTop:1,children:u.map((p,f)=>{let T=f===x,P=T?"\u276F ":" ",B=p.value==="__new__"?v.statusPass:T?v.primary:void 0;return(0,b.jsxs)(g,{color:B,children:[P,p.label]},p.value)})}),(0,b.jsx)(ee,{bindings:[{keys:"\u2191\u2193",label:"navigate"},{keys:"\u21B5",label:"select"}],escBackLabel:"back"})]})}var Be=F(Z(),1);import{readFileSync as We,writeFileSync as He,mkdirSync as Ve}from"fs";import{dirname as Xe,join as Ye}from"path";var ze=Ye(xe,"command-history.json"),qe=200,me=class{entries;filePath;max;constructor(n=ze,o=qe){this.filePath=n,this.max=o,this.entries=this._load()}push(n){this.entries.length>0&&this.entries[this.entries.length-1]===n||(this.entries.push(n),this.entries.length>this.max&&(this.entries=this.entries.slice(this.entries.length-this.max)),this._save())}getAll(){return[...this.entries]}search(n){let o=n.toLowerCase(),d=[];for(let h=this.entries.length-1;h>=0;h--)this.entries[h].toLowerCase().includes(o)&&d.push(this.entries[h]);return d}_load(){try{let n=We(this.filePath,"utf-8"),o=JSON.parse(n);return Array.isArray(o)?o:[]}catch{return[]}}_save(){try{Ve(Xe(this.filePath),{recursive:!0}),He(this.filePath,JSON.stringify(this.entries)+`
3
+ `)}catch{}}};function De(c){let n=(0,Be.useRef)(null);return n.current||(n.current=new me(c)),n.current}async function ue(c,n,o,d){let h=c.loadBasicAuth(n,o),t=c.loadCredentials(n,o);if(!h&&!t)return d("info","STARTUP_GATE_NO_CREDS","Profile has no credentials",{profile:n,env:o}),{status:"needs_login",profile:n,env:o};let m=te(o),e=async()=>c.loadCredentials(n,o)?.access_token??null,a=new le(m.controllerBaseUrl,e,h,d);d("info","STARTUP_GATE_VALIDATE","Validating credentials with controller",{profile:n,env:o,method:h?"basic":"oauth"});let x=await a.resolve(!0);if(x)return d("info","STARTUP_GATE_VALID","Credentials validated",{profile:n,env:o,username:x.username,org_id:x.org_id}),{status:"authenticated",result:{profile:n,env:o,credentials:t,basicAuth:h,tmsCreds:x,resolver:a}};if(!h&&t){let y=t.refresh_token,E=c.loadClient(n,o)?.client_id;if(y&&E){d("info","STARTUP_GATE_REFRESH","Attempting token refresh",{profile:n,env:o});try{let I=await new ye(o).refreshToken(y,E);if(I.access_token){c.saveCredentials(n,o,{...t,...I,expires_at:Date.now()/1e3+(I.expires_in??3600)});let j=await a.resolve(!0);if(j)return d("info","STARTUP_GATE_REFRESH_OK","Token refreshed and validated",{profile:n,env:o,username:j.username}),{status:"authenticated",result:{profile:n,env:o,credentials:{...t,...I},basicAuth:null,tmsCreds:j,resolver:a}}}d("warn","STARTUP_GATE_REFRESH_INVALID","Refreshed token still invalid",{profile:n,env:o})}catch(_){d("warn","STARTUP_GATE_REFRESH_FAILED","Token refresh failed",{profile:n,env:o,error:_ instanceof Error?_.message:String(_)})}}else d("info","STARTUP_GATE_NO_REFRESH","No refresh_token or client_id \u2014 login required",{profile:n,env:o})}return d("info","STARTUP_GATE_INVALID","Credentials invalid \u2014 login required",{profile:n,env:o}),{status:"needs_login",profile:n,env:o}}async function Ie(c,n,o=new ae){let d=c.listProfiles();if(n("info","STARTUP_GATE_START","Auth startup gate",{profile_count:d.length}),d.length===0)return n("info","STARTUP_GATE_NONE","No profiles found \u2014 login required"),{status:"needs_login"};if(d.length>1){let m=c.getActiveProfile(),e=c.getDefaultEnv();if(m&&d.some(x=>x.profile===m&&x.env===e)){n("info","STARTUP_GATE_TRY_ACTIVE","Multiple profiles \u2014 trying active first",{activeProfile:m,activeEnv:e});let x=await ue(c,m,e,n);if(x.status==="authenticated")return x;n("info","STARTUP_GATE_ACTIVE_FAILED","Active profile invalid \u2014 showing picker",{activeProfile:m,activeEnv:e})}return n("info","STARTUP_GATE_MULTI","Multiple profiles \u2014 picker required",{profiles:d.map(a=>`${a.profile}/${a.env}`)}),{status:"needs_pick",profiles:d}}let{profile:h,env:t}=d[0];return c.setActiveProfile(h),c.setDefaultEnv(t),re(c,o,h,t),ue(c,h,t,n)}var A=F(Y(),1);function Vt({resultRef:c,mode:n="singleshot",loginCompleteRef:o}){let{exit:d}=ge(),h=(0,C.useRef)(new ve),t=(0,C.useRef)(new ae),m=(0,C.useRef)(new Se),e=h.current,a=t.current,x=m.current,y=De(),[D,E]=(0,C.useState)(n==="login"?"login":"gate"),[_,I]=(0,C.useState)(null),[Q,j]=(0,C.useState)(null),[M,N]=(0,C.useState)(null),[$,R]=(0,C.useState)(null),[G,k]=(0,C.useState)([]),W=(0,C.useCallback)((s,u,p,f)=>x.log(s,u,p,f),[x]),ne=(0,C.useCallback)((s,u)=>{s?re(e,a,s,u):a.save({project_id:null,project_name:null,folder_id:null,folder_name:null})},[e,a]),U=(0,C.useCallback)(()=>{n==="login"?(o&&(o.current=!0),d()):E("input")},[n,d,o]),H=(0,C.useCallback)((s,u)=>{let p=re(e,a,s,u);if(n==="login"){E("ensure-project");return}Ae(p)?U():p.projectId?E("ensure-folder"):E("ensure-project")},[e,a,U,n]);z((s,u)=>{u.ctrl&&s==="c"&&ie(0,"Ctrl+C exit")});let l=(0,C.useRef)(!1);C.default.useEffect(()=>{l.current||(l.current=!0,n!=="login"&&Ie(e,W).then(s=>{I(s),s.status==="authenticated"?H(s.result.profile,s.result.env):s.status==="needs_pick"?E("pick"):(j(s.profile??null),N(s.env??null),E("login"))}).catch(s=>{R(`Auth check failed: ${s instanceof Error?s.message:String(s)}`)}))},[e,W]);let r=(0,C.useCallback)(s=>{c.current={objective:s},d()},[c,d]),i=(0,C.useCallback)(async(s,u)=>{e.setActiveProfile(s),e.setDefaultEnv(u),(await ue(e,s,u,W)).status==="authenticated"?H(s,u):(j(s),N(u),E("login"))},[e,W,H]),S=(0,C.useCallback)(()=>{let s=e.getActiveProfile(),u=e.getDefaultEnv();if(!s)return null;let p=te(u),f=e.loadBasicAuth(s,u);return new le(p.controllerBaseUrl,async()=>e.loadCredentials(s,u)?.access_token??null,f,W)},[e,W]),O=(0,C.useCallback)(async()=>{let s=S();if(!s)return null;let u=s.cached??await s.resolve();if(!u)return null;let p=te(e.getDefaultEnv()),f=new fe(p.tmsBaseUrl,u.username,u.access_key);try{let P=(await f.listProjects()).find(se=>se.name==="KaneAI Generated");if(P)return{id:P.project_id,name:P.name};let B=await f.createProject("KaneAI Generated");return{id:B.id,name:B.name}}catch{return null}},[S,e]),V=(0,C.useCallback)(async s=>{let u=S();if(!u)return null;let p=u.cached??await u.resolve();if(!p)return null;let f=te(e.getDefaultEnv()),T=new fe(f.tmsBaseUrl,p.username,p.access_key);try{let B=(await T.listFolders(s)).find(Le=>Le.name==="Untitled");if(B)return{id:B.id,name:B.name};let se=await T.createFolder(s,"Untitled");return{id:se.id,name:se.name}}catch{return null}},[S,e]);if(D==="gate")return(0,A.jsx)(w,{paddingX:1,children:(0,A.jsx)(g,{color:"yellow",children:"Checking authentication..."})});if($)return(0,A.jsxs)(w,{flexDirection:"column",paddingX:1,children:[(0,A.jsx)(g,{color:"red",children:$}),(0,A.jsx)(g,{color:"gray",children:"Press Ctrl+C to exit."})]});if(D==="pick"&&_?.status==="needs_pick")return(0,A.jsx)(Je,{profiles:_.profiles,onSelect:i});if(D==="login")return(0,A.jsx)(Re,{devMode:process.env.KANE_DEV_MODE==="1",profiles:e.listProfiles(),onBasicLogin:async(s,u,p,f)=>{let{validateBasicAuth:T}=await import("./validate-basic-27BIMJ2F.js");await T(u,p,f),e.saveBasicAuth(s,u,{username:p,access_key:f}),e.setActiveProfile(s),e.setDefaultEnv(u)},onOAuthLogin:async(s,u)=>{let{LoginFlow:p}=await import("./login-flow-ZUZUZIXD.js");e.setDefaultEnv(u),e.setActiveProfile(s),await new p(s,u,e).login()},onComplete:(s,u)=>{j(s),N(u),e.setActiveProfile(s),e.setDefaultEnv(u),H(s,u)},onCancel:()=>{ie(0,"Login cancelled")}});if(D==="ensure-project"){let s=e.getActiveProfile()??"default",u=e.getDefaultEnv(),p=()=>{if(n==="login"){E("ensure-folder");return}re(e,a,s,u).folderId?U():E("ensure-folder")};return(0,A.jsxs)(w,{flexDirection:"column",children:[(0,A.jsx)(w,{paddingX:1,marginBottom:1,children:(0,A.jsx)(g,{color:"yellow",children:"Project & folder are required to save tests \xB7 Esc to use defaults \xB7 Ctrl+C to exit"})}),(0,A.jsx)(Te,{resolver:S(),currentProjectId:a.load().project_id,env:u,onSelect:(f,T)=>{oe(e,a,s,u,{projectId:f,projectName:T}),k(P=>[...P,`\u2713 Project: ${T} (${f})`]),p()},onCancel:async()=>{let f=await O();f&&(oe(e,a,s,u,{projectId:f.id,projectName:f.name}),k(T=>[...T,`\u2713 Default project: ${f.name} (${f.id})`]),p())}})]})}if(D==="ensure-folder"){let s=e.getActiveProfile()??"default",u=e.getDefaultEnv(),p=e.loadProfileConfig(s,u);return(0,A.jsxs)(w,{flexDirection:"column",children:[(0,A.jsx)(w,{paddingX:1,marginBottom:1,children:(0,A.jsx)(g,{color:"yellow",children:"Project & folder are required to save tests \xB7 Esc to use defaults \xB7 Ctrl+C to exit"})}),(0,A.jsx)(be,{resolver:S(),projectId:p?.project_id??"",currentFolderId:a.load().folder_id,env:u,onSelect:(f,T)=>{oe(e,a,s,u,{folderId:f,folderName:T}),k(P=>[...P,`\u2713 Folder: ${T} (${f})`]),U()},onCancel:async()=>{if(!p?.project_id)return;let f=await V(p.project_id);f&&(oe(e,a,s,u,{folderId:f.id,folderName:f.name}),k(T=>[...T,`\u2713 Default folder: ${f.name} (${f.id})`]),U())}})]})}return D==="input"?(0,A.jsxs)(w,{flexDirection:"column",children:[G.length>0&&(0,A.jsx)(w,{flexDirection:"column",paddingX:1,marginBottom:1,children:G.map((s,u)=>(0,A.jsx)(g,{color:"green",children:s},u))}),(0,A.jsx)(_e,{onSubmit:r,onEscape:()=>ie(0,"User pressed Escape"),history:y,placeholder:"Type an objective..."})]}):(0,A.jsx)(A.Fragment,{})}function Je({profiles:c,onSelect:n}){let[o,d]=(0,C.useState)(0),[h,t]=(0,C.useState)(!1);return z((m,e)=>{if(!h){if(e.escape){ie(0,"Profile picker cancelled");return}if(e.upArrow&&o>0&&d(a=>a-1),e.downArrow&&o<c.length-1&&d(a=>a+1),e.return){t(!0);let a=c[o];n(a.profile,a.env).catch(()=>t(!1))}}}),(0,A.jsxs)(w,{flexDirection:"column",paddingX:1,children:[(0,A.jsx)(g,{color:"#ff9500",bold:!0,children:"Select a profile:"}),(0,A.jsx)(w,{marginTop:1,flexDirection:"column",children:c.map((m,e)=>(0,A.jsxs)(g,{children:[e===o?"\u276F ":" ",(0,A.jsx)(g,{color:e===o?"#ff9500":"white",bold:e===o,children:m.profile}),(0,A.jsxs)(g,{color:"gray",children:[" [",m.env,"]"]})]},`${m.profile}-${m.env}`))}),h&&(0,A.jsx)(w,{marginTop:1,children:(0,A.jsx)(g,{color:"yellow",children:"Validating credentials..."})})]})}export{De as a,_e as b,Re as c,ue as d,Ie as e,Vt as f};
@@ -1,2 +1,2 @@
1
1
  import { createRequire } from 'module'; const require = createRequire(import.meta.url);
2
- import{a as h}from"./chunk-BSQVYLV7.js";import{a as A}from"./chunk-HCBYKLMW.js";import{t as a}from"./chunk-JYQO6G7F.js";import{a as c,b as f,i as P}from"./chunk-C44QQJR4.js";import{a as y}from"./chunk-6YGTRKDT.js";import{e as x}from"./chunk-UR6MHSHU.js";var L=x(y(),1);var r=x(A(),1);function B(i,d,l,u,p){let g=l==="basic"&&u?`basic (${u})`:l,n=20,s=`${i} [${d}]`,m="\xB7".repeat(Math.max(2,n-s.length+3));return{label:`${s} ${m} ${g}`,profile:i,env:d,isActive:p}}function I({creds:i,onSwitch:d,onCancel:l}){let u=i.listProfiles(),p=i.getActiveProfile(),g=i.getDefaultEnv(),n=u.map(e=>{let t=i.loadBasicAuth(e.profile,e.env),o=i.loadCredentials(e.profile,e.env)!==null,v=t?"basic":o?"oauth":"none",b=t?t.username:null,w=e.profile===p&&e.env===g;return B(e.profile,e.env,v,b,w)}),[s,m]=(0,L.useState)(()=>{let e=n.findIndex(t=>t.isActive);return e>=0?e:0});return P((e,t)=>{if(t.escape){l();return}if(t.upArrow){m(o=>Math.max(0,o-1));return}if(t.downArrow){m(o=>Math.min(n.length-1,o+1));return}if(t.return&&n[s]){let o=n[s];o.isActive||d(o.profile,o.env),l();return}}),n.length===0?(0,r.jsxs)(c,{flexDirection:"column",borderStyle:"round",borderColor:a.primary,paddingX:2,paddingY:1,children:[(0,r.jsx)(f,{color:a.primary,bold:!0,children:"Profiles"}),(0,r.jsx)(c,{marginTop:1,children:(0,r.jsx)(f,{color:a.dim,children:"No profiles \u2014 use Login to create one"})}),(0,r.jsx)(h,{bindings:[],escBackLabel:"back"})]}):(0,r.jsxs)(c,{flexDirection:"column",borderStyle:"round",borderColor:a.primary,paddingX:2,paddingY:1,children:[(0,r.jsx)(f,{color:a.primary,bold:!0,children:"Profiles"}),(0,r.jsx)(c,{flexDirection:"column",marginTop:1,children:n.map((e,t)=>{let o=t===s,v=o?"\u276F ":" ",b=e.isActive?a.statusPass:o?a.primary:void 0;return(0,r.jsxs)(f,{color:b,children:[v,e.label,e.isActive?" \u25CF active":""]},`${e.profile}-${e.env}`)})}),(0,r.jsx)(h,{bindings:[{keys:"\u2191\u2193",label:"navigate"},{keys:"\u21B5",label:"switch"}],escBackLabel:"back"})]})}export{B as a,I as b};
2
+ import{a as h}from"./chunk-HJ3CHMEM.js";import{a as A}from"./chunk-HCBYKLMW.js";import{t as a}from"./chunk-3ELBJPHQ.js";import{a as c,b as f,i as P}from"./chunk-C44QQJR4.js";import{a as y}from"./chunk-6YGTRKDT.js";import{e as x}from"./chunk-UR6MHSHU.js";var L=x(y(),1);var r=x(A(),1);function B(i,d,l,u,p){let g=l==="basic"&&u?`basic (${u})`:l,n=20,s=`${i} [${d}]`,m="\xB7".repeat(Math.max(2,n-s.length+3));return{label:`${s} ${m} ${g}`,profile:i,env:d,isActive:p}}function I({creds:i,onSwitch:d,onCancel:l}){let u=i.listProfiles(),p=i.getActiveProfile(),g=i.getDefaultEnv(),n=u.map(e=>{let t=i.loadBasicAuth(e.profile,e.env),o=i.loadCredentials(e.profile,e.env)!==null,v=t?"basic":o?"oauth":"none",b=t?t.username:null,w=e.profile===p&&e.env===g;return B(e.profile,e.env,v,b,w)}),[s,m]=(0,L.useState)(()=>{let e=n.findIndex(t=>t.isActive);return e>=0?e:0});return P((e,t)=>{if(t.escape){l();return}if(t.upArrow){m(o=>Math.max(0,o-1));return}if(t.downArrow){m(o=>Math.min(n.length-1,o+1));return}if(t.return&&n[s]){let o=n[s];o.isActive||d(o.profile,o.env),l();return}}),n.length===0?(0,r.jsxs)(c,{flexDirection:"column",borderStyle:"round",borderColor:a.primary,paddingX:2,paddingY:1,children:[(0,r.jsx)(f,{color:a.primary,bold:!0,children:"Profiles"}),(0,r.jsx)(c,{marginTop:1,children:(0,r.jsx)(f,{color:a.dim,children:"No profiles \u2014 use Login to create one"})}),(0,r.jsx)(h,{bindings:[],escBackLabel:"back"})]}):(0,r.jsxs)(c,{flexDirection:"column",borderStyle:"round",borderColor:a.primary,paddingX:2,paddingY:1,children:[(0,r.jsx)(f,{color:a.primary,bold:!0,children:"Profiles"}),(0,r.jsx)(c,{flexDirection:"column",marginTop:1,children:n.map((e,t)=>{let o=t===s,v=o?"\u276F ":" ",b=e.isActive?a.statusPass:o?a.primary:void 0;return(0,r.jsxs)(f,{color:b,children:[v,e.label,e.isActive?" \u25CF active":""]},`${e.profile}-${e.env}`)})}),(0,r.jsx)(h,{bindings:[{keys:"\u2191\u2193",label:"navigate"},{keys:"\u21B5",label:"switch"}],escBackLabel:"back"})]})}export{B as a,I as b};
@@ -1,2 +1,2 @@
1
1
  import { createRequire } from 'module'; const require = createRequire(import.meta.url);
2
- import{a as p}from"./chunk-HCBYKLMW.js";import{t as a}from"./chunk-JYQO6G7F.js";import{b as u}from"./chunk-C44QQJR4.js";import{a as l}from"./chunk-6YGTRKDT.js";import{e as n}from"./chunk-UR6MHSHU.js";var m=n(l(),1);var o=n(l(),1);function c(r,e){let t=(0,o.useRef)(r);t.current=r,(0,o.useEffect)(()=>{if(e===null)return;let i=setInterval(()=>t.current(),e);return()=>clearInterval(i)},[e])}var s=n(p(),1),f=["\u280B","\u2819","\u2839","\u2838","\u283C","\u2834","\u2826","\u2827","\u2807","\u280F"];function I({active:r=!0}){let[e,t]=(0,m.useState)(0);return c(()=>{t(i=>(i+1)%f.length)},r?80:null),(0,s.jsx)(u,{color:a.purple,children:r?f[e]:"\u25CF"})}export{c as a,I as b};
2
+ import{a as p}from"./chunk-HCBYKLMW.js";import{t as a}from"./chunk-3ELBJPHQ.js";import{b as u}from"./chunk-C44QQJR4.js";import{a as l}from"./chunk-6YGTRKDT.js";import{e as n}from"./chunk-UR6MHSHU.js";var m=n(l(),1);var o=n(l(),1);function c(r,e){let t=(0,o.useRef)(r);t.current=r,(0,o.useEffect)(()=>{if(e===null)return;let i=setInterval(()=>t.current(),e);return()=>clearInterval(i)},[e])}var s=n(p(),1),f=["\u280B","\u2819","\u2839","\u2838","\u283C","\u2834","\u2826","\u2827","\u2807","\u280F"];function I({active:r=!0}){let[e,t]=(0,m.useState)(0);return c(()=>{t(i=>(i+1)%f.length)},r?80:null),(0,s.jsx)(u,{color:a.purple,children:r?f[e]:"\u25CF"})}export{c as a,I as b};
@@ -1,2 +1,2 @@
1
1
  import { createRequire } from 'module'; const require = createRequire(import.meta.url);
2
- import{a as R}from"./chunk-BSQVYLV7.js";import{a as X}from"./chunk-HCBYKLMW.js";import{t as n}from"./chunk-JYQO6G7F.js";import{a as c,b as r,i as N}from"./chunk-C44QQJR4.js";import{a as G}from"./chunk-6YGTRKDT.js";import{e as M}from"./chunk-UR6MHSHU.js";var b=M(G(),1);var e=M(X(),1),d=5;function K(i,I){if(!I)return i;let a=I.toLowerCase();return i.filter(v=>v.label.toLowerCase().includes(a))}function Q(i){let{title:I,items:a,loading:v=!1,loadingText:Y,error:h=null,itemNoun:B="items",onSelect:H,onCancel:D,defaultActiveId:y,onTab:L,extraHint:E}=i,[x,s]=(0,b.useState)(0),[p,f]=(0,b.useState)(0),[u,w]=(0,b.useState)(""),[A,S]=(0,b.useState)(null);(0,b.useEffect)(()=>{if(a.length===0)return;if(i.preserveSelectionById&&A!==null){let t=a.findIndex(o=>o.id===A);if(t>=0){f(Math.floor(t/d)),s(t%d);return}}let l=y?a.findIndex(t=>t.id===y):a.findIndex(t=>t.isActive);l>=0?(f(Math.floor(l/d)),s(l%d),i.preserveSelectionById&&S(a[l].id)):i.preserveSelectionById&&(f(0),s(0),S(a[0]?.id??null))},[a,y,i.preserveSelectionById,A]);let g=K(a,u),C=p*d,F=Math.min(C+d,g.length),P=Math.ceil(g.length/d),O=F-C,T=g.slice(C,F);return N((l,t)=>{if(h){t.escape&&D();return}if(t.escape){u?(w(""),s(0),f(0)):D();return}if(t.tab&&L){L();return}if(t.upArrow){if(x>0){let o=x-1;s(o),i.preserveSelectionById&&S(T[o]?.id??null)}else if(p>0){let o=p-1,m=d-1;f(o),s(m),i.preserveSelectionById&&S(g[o*d+m]?.id??null)}return}if(t.downArrow){if(x<O-1){let o=x+1;s(o),i.preserveSelectionById&&S(T[o]?.id??null)}else if(p<P-1){let o=p+1,m=0;f(o),s(m),i.preserveSelectionById&&S(g[o*d+m]?.id??null)}return}if(t.return&&T[x]){H(T[x]);return}if(t.backspace||t.delete){w(o=>o.slice(0,-1)),s(0),f(0);return}l&&!t.ctrl&&!t.meta&&(w(o=>o+l),s(0),f(0))},{isActive:!v}),v?(0,e.jsxs)(c,{flexDirection:"column",borderStyle:"round",borderColor:n.primary,paddingX:2,paddingY:1,children:[(0,e.jsx)(r,{color:n.primary,bold:!0,children:I}),(0,e.jsx)(c,{marginTop:1,children:(0,e.jsx)(r,{color:n.secondary,children:Y??`Loading ${B}\u2026`})})]}):h?(0,e.jsxs)(c,{flexDirection:"column",borderStyle:"round",borderColor:n.statusFail,paddingX:2,paddingY:1,children:[(0,e.jsx)(r,{color:n.statusFail,bold:!0,children:I}),(0,e.jsx)(c,{marginTop:1,children:(0,e.jsx)(r,{color:n.statusFail,children:h})}),(0,e.jsx)(R,{bindings:[]})]}):(0,e.jsxs)(c,{flexDirection:"column",borderStyle:"round",borderColor:n.primary,paddingX:2,paddingY:1,children:[(0,e.jsxs)(c,{children:[(0,e.jsx)(r,{color:n.primary,bold:!0,children:I}),(0,e.jsxs)(r,{color:n.dim,children:[" (",g.length,u?`/${a.length}`:""," ",B,i.loadingMore?" \xB7 loading more":"",")"]})]}),(0,e.jsxs)(c,{marginTop:1,children:[(0,e.jsx)(r,{color:n.secondary,children:u?"filter: ":""}),u?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(r,{children:u}),(0,e.jsx)(r,{inverse:!0,children:" "})]}):(0,e.jsxs)(e.Fragment,{children:[(0,e.jsxs)(r,{color:n.dim,children:["Search ",B,"\u2026"]}),(0,e.jsx)(r,{inverse:!0,children:" "})]})]}),(0,e.jsx)(c,{flexDirection:"column",marginTop:1,children:g.length===0?(0,e.jsxs)(r,{color:n.dim,children:["No ",B,' match "',u,'"']}):T.map((l,t)=>{let o=t===x,m=o?"\u276F ":" ",$=l.isActive?n.statusPass:o?n.primary:void 0;return(0,e.jsxs)(r,{color:$,children:[m,l.label,l.isActive?" \u25CF selected":""]},l.id)})}),P>1&&(0,e.jsx)(c,{marginTop:1,children:(0,e.jsxs)(r,{color:n.dim,children:["Page ",p+1,"/",P]})}),i.footer&&(0,e.jsx)(c,{marginTop:1,flexDirection:"column",children:i.footer}),(0,e.jsx)(R,{bindings:[{keys:"\u2191\u2193",label:"navigate"},{keys:"type",label:"to search"},{keys:"\u21B5",label:"select"},...L&&E?[{keys:"tab",label:E}]:[]],escBackLabel:u?"clear":"back to chat"})]})}export{Q as a};
2
+ import{a as R}from"./chunk-HJ3CHMEM.js";import{a as X}from"./chunk-HCBYKLMW.js";import{t as n}from"./chunk-3ELBJPHQ.js";import{a as c,b as r,i as N}from"./chunk-C44QQJR4.js";import{a as G}from"./chunk-6YGTRKDT.js";import{e as M}from"./chunk-UR6MHSHU.js";var b=M(G(),1);var e=M(X(),1),d=5;function K(i,I){if(!I)return i;let a=I.toLowerCase();return i.filter(v=>v.label.toLowerCase().includes(a))}function Q(i){let{title:I,items:a,loading:v=!1,loadingText:Y,error:h=null,itemNoun:B="items",onSelect:H,onCancel:D,defaultActiveId:y,onTab:L,extraHint:E}=i,[x,s]=(0,b.useState)(0),[p,f]=(0,b.useState)(0),[u,w]=(0,b.useState)(""),[A,S]=(0,b.useState)(null);(0,b.useEffect)(()=>{if(a.length===0)return;if(i.preserveSelectionById&&A!==null){let t=a.findIndex(o=>o.id===A);if(t>=0){f(Math.floor(t/d)),s(t%d);return}}let l=y?a.findIndex(t=>t.id===y):a.findIndex(t=>t.isActive);l>=0?(f(Math.floor(l/d)),s(l%d),i.preserveSelectionById&&S(a[l].id)):i.preserveSelectionById&&(f(0),s(0),S(a[0]?.id??null))},[a,y,i.preserveSelectionById,A]);let g=K(a,u),C=p*d,F=Math.min(C+d,g.length),P=Math.ceil(g.length/d),O=F-C,T=g.slice(C,F);return N((l,t)=>{if(h){t.escape&&D();return}if(t.escape){u?(w(""),s(0),f(0)):D();return}if(t.tab&&L){L();return}if(t.upArrow){if(x>0){let o=x-1;s(o),i.preserveSelectionById&&S(T[o]?.id??null)}else if(p>0){let o=p-1,m=d-1;f(o),s(m),i.preserveSelectionById&&S(g[o*d+m]?.id??null)}return}if(t.downArrow){if(x<O-1){let o=x+1;s(o),i.preserveSelectionById&&S(T[o]?.id??null)}else if(p<P-1){let o=p+1,m=0;f(o),s(m),i.preserveSelectionById&&S(g[o*d+m]?.id??null)}return}if(t.return&&T[x]){H(T[x]);return}if(t.backspace||t.delete){w(o=>o.slice(0,-1)),s(0),f(0);return}l&&!t.ctrl&&!t.meta&&(w(o=>o+l),s(0),f(0))},{isActive:!v}),v?(0,e.jsxs)(c,{flexDirection:"column",borderStyle:"round",borderColor:n.primary,paddingX:2,paddingY:1,children:[(0,e.jsx)(r,{color:n.primary,bold:!0,children:I}),(0,e.jsx)(c,{marginTop:1,children:(0,e.jsx)(r,{color:n.secondary,children:Y??`Loading ${B}\u2026`})})]}):h?(0,e.jsxs)(c,{flexDirection:"column",borderStyle:"round",borderColor:n.statusFail,paddingX:2,paddingY:1,children:[(0,e.jsx)(r,{color:n.statusFail,bold:!0,children:I}),(0,e.jsx)(c,{marginTop:1,children:(0,e.jsx)(r,{color:n.statusFail,children:h})}),(0,e.jsx)(R,{bindings:[]})]}):(0,e.jsxs)(c,{flexDirection:"column",borderStyle:"round",borderColor:n.primary,paddingX:2,paddingY:1,children:[(0,e.jsxs)(c,{children:[(0,e.jsx)(r,{color:n.primary,bold:!0,children:I}),(0,e.jsxs)(r,{color:n.dim,children:[" (",g.length,u?`/${a.length}`:""," ",B,i.loadingMore?" \xB7 loading more":"",")"]})]}),(0,e.jsxs)(c,{marginTop:1,children:[(0,e.jsx)(r,{color:n.secondary,children:u?"filter: ":""}),u?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(r,{children:u}),(0,e.jsx)(r,{inverse:!0,children:" "})]}):(0,e.jsxs)(e.Fragment,{children:[(0,e.jsxs)(r,{color:n.dim,children:["Search ",B,"\u2026"]}),(0,e.jsx)(r,{inverse:!0,children:" "})]})]}),(0,e.jsx)(c,{flexDirection:"column",marginTop:1,children:g.length===0?(0,e.jsxs)(r,{color:n.dim,children:["No ",B,' match "',u,'"']}):T.map((l,t)=>{let o=t===x,m=o?"\u276F ":" ",$=l.isActive?n.statusPass:o?n.primary:void 0;return(0,e.jsxs)(r,{color:$,children:[m,l.label,l.isActive?" \u25CF selected":""]},l.id)})}),P>1&&(0,e.jsx)(c,{marginTop:1,children:(0,e.jsxs)(r,{color:n.dim,children:["Page ",p+1,"/",P]})}),i.footer&&(0,e.jsx)(c,{marginTop:1,flexDirection:"column",children:i.footer}),(0,e.jsx)(R,{bindings:[{keys:"\u2191\u2193",label:"navigate"},{keys:"type",label:"to search"},{keys:"\u21B5",label:"select"},...L&&E?[{keys:"tab",label:E}]:[]],escBackLabel:u?"clear":"back to chat"})]})}export{Q as a};
@@ -1,2 +1,2 @@
1
1
  import { createRequire } from 'module'; const require = createRequire(import.meta.url);
2
- import{s}from"./chunk-JYQO6G7F.js";function n(r="prod"){let e=s[r];return r!=="stage"?e:{authBaseUrl:process.env.KANE_STAGE_AUTH_URL??e.authBaseUrl,consentUrl:process.env.KANE_STAGE_CONSENT_URL??e.consentUrl,controllerBaseUrl:process.env.TESTMUAI_BASE_URL??e.controllerBaseUrl,tmsBaseUrl:process.env.KANE_STAGE_TMS_URL??e.tmsBaseUrl,secretsBaseUrl:process.env.KANE_STAGE_SECRETS_URL??e.secretsBaseUrl,testManagerUiUrl:process.env.KANE_STAGE_TEST_MANAGER_UI_URL??e.testManagerUiUrl,shareApiBaseUrl:process.env.KANE_STAGE_SHARE_API_URL??e.shareApiBaseUrl,v16ServerHost:process.env.KANE_STAGE_V16_SERVER_HOST??e.v16ServerHost}}export{n as a};
2
+ import{s}from"./chunk-3ELBJPHQ.js";function n(r="prod"){let e=s[r];return r!=="stage"?e:{authBaseUrl:process.env.KANE_STAGE_AUTH_URL??e.authBaseUrl,consentUrl:process.env.KANE_STAGE_CONSENT_URL??e.consentUrl,controllerBaseUrl:process.env.TESTMUAI_BASE_URL??e.controllerBaseUrl,tmsBaseUrl:process.env.KANE_STAGE_TMS_URL??e.tmsBaseUrl,secretsBaseUrl:process.env.KANE_STAGE_SECRETS_URL??e.secretsBaseUrl,testManagerUiUrl:process.env.KANE_STAGE_TEST_MANAGER_UI_URL??e.testManagerUiUrl,shareApiBaseUrl:process.env.KANE_STAGE_SHARE_API_URL??e.shareApiBaseUrl,v16ServerHost:process.env.KANE_STAGE_V16_SERVER_HOST??e.v16ServerHost}}export{n as a};
@@ -1,2 +1,2 @@
1
1
  import { createRequire } from 'module'; const require = createRequire(import.meta.url);
2
- import{b as f}from"./chunk-MH26PIS4.js";import{a as x}from"./chunk-HCBYKLMW.js";import{t}from"./chunk-JYQO6G7F.js";import{a as r,b as n}from"./chunk-C44QQJR4.js";import{a as B}from"./chunk-6YGTRKDT.js";import{e as c}from"./chunk-UR6MHSHU.js";var p=c(B(),1);var e=c(x(),1);function v(){return[{name:"convert",label:"Converting session data",status:"pending"},{name:"zip",label:"Compressing artifacts",status:"pending"},{name:"presign",label:"Requesting upload URLs",status:"pending"},{name:"upload",label:"Uploading to KaneAI",status:"pending"},{name:"atomic_replace",label:"Replacing local output",status:"pending"},{name:"commit_lock",label:"Committing to TMS",status:"pending"},{name:"finalize",label:"Finalizing test case",status:"pending"},{name:"code_export",label:"Downloading test code",status:"pending"}]}function U(s,o,d,a){return s.map(l=>l.name===o?{...l,status:d,detail:a}:l)}function R(s){let o=s/1e3;if(o<60)return`${o.toFixed(1)}s`;let d=Math.floor(o/60),a=Math.round(o%60);return`${d}m ${a}s`}function D(s){let[o,d]=(0,p.useState)(0),a=p.default.useRef(Date.now());return(0,p.useEffect)(()=>{if(!s)return;a.current=Date.now();let l=setInterval(()=>{d(Date.now()-a.current)},100);return()=>clearInterval(l)},[s]),o}function h({steps:s,status:o,testUrl:d,error:a}){let l=D(o==="uploading");return o==="uploading"?(0,e.jsxs)(r,{flexDirection:"column",paddingX:1,paddingY:1,children:[(0,e.jsxs)(r,{children:[(0,e.jsx)(n,{color:t.primary,children:"\u2601 "}),(0,e.jsx)(n,{color:t.primary,bold:!0,children:"Saving to KaneAI"}),(0,e.jsxs)(n,{color:t.dimmed,children:[" ",R(l)]})]}),(0,e.jsx)(r,{flexDirection:"column",marginTop:1,children:s.filter(i=>i.status!=="skipped").map((i,S,T)=>{let b=S===T.length-1?"\u2514\u2500":"\u251C\u2500",m=i.status==="done",u=i.status==="running",g=i.status==="failed";return(0,e.jsxs)(r,{children:[(0,e.jsxs)(n,{color:t.dimmed,children:[" ",b," "]}),(0,e.jsx)(r,{width:3,children:u?(0,e.jsx)(f,{}):m?(0,e.jsx)(n,{color:t.green,children:"\u2713"}):g?(0,e.jsx)(n,{color:t.red,children:"\u2717"}):(0,e.jsx)(n,{color:t.muted,children:"\u25CB"})}),(0,e.jsx)(n,{color:m?t.dim:u?t.base:g?t.red:t.muted,children:i.label}),i.detail&&(0,e.jsxs)(n,{color:t.dimmed,children:[" ",i.detail]})]},i.name)})}),(0,e.jsx)(r,{marginTop:1,children:(0,e.jsx)(n,{color:t.muted,children:" press Ctrl+C twice to force exit"})})]}):o==="success"?(0,e.jsx)(e.Fragment,{}):(0,e.jsxs)(r,{flexDirection:"column",paddingX:1,paddingY:1,children:[(0,e.jsxs)(r,{children:[(0,e.jsx)(n,{color:t.red,children:"\u2601 "}),(0,e.jsx)(n,{color:t.red,bold:!0,children:"Save failed"})]}),a&&(0,e.jsxs)(r,{marginTop:0,children:[(0,e.jsx)(n,{color:t.dimmed,children:" "}),(0,e.jsx)(n,{color:t.dim,children:a})]})]})}export{v as a,U as b,h as c};
2
+ import{b as f}from"./chunk-RXMOIIQD.js";import{a as x}from"./chunk-HCBYKLMW.js";import{t}from"./chunk-3ELBJPHQ.js";import{a as r,b as n}from"./chunk-C44QQJR4.js";import{a as B}from"./chunk-6YGTRKDT.js";import{e as c}from"./chunk-UR6MHSHU.js";var p=c(B(),1);var e=c(x(),1);function v(){return[{name:"convert",label:"Converting session data",status:"pending"},{name:"zip",label:"Compressing artifacts",status:"pending"},{name:"presign",label:"Requesting upload URLs",status:"pending"},{name:"upload",label:"Uploading to KaneAI",status:"pending"},{name:"atomic_replace",label:"Replacing local output",status:"pending"},{name:"commit_lock",label:"Committing to TMS",status:"pending"},{name:"finalize",label:"Finalizing test case",status:"pending"},{name:"code_export",label:"Downloading test code",status:"pending"}]}function U(s,o,d,a){return s.map(l=>l.name===o?{...l,status:d,detail:a}:l)}function R(s){let o=s/1e3;if(o<60)return`${o.toFixed(1)}s`;let d=Math.floor(o/60),a=Math.round(o%60);return`${d}m ${a}s`}function D(s){let[o,d]=(0,p.useState)(0),a=p.default.useRef(Date.now());return(0,p.useEffect)(()=>{if(!s)return;a.current=Date.now();let l=setInterval(()=>{d(Date.now()-a.current)},100);return()=>clearInterval(l)},[s]),o}function h({steps:s,status:o,testUrl:d,error:a}){let l=D(o==="uploading");return o==="uploading"?(0,e.jsxs)(r,{flexDirection:"column",paddingX:1,paddingY:1,children:[(0,e.jsxs)(r,{children:[(0,e.jsx)(n,{color:t.primary,children:"\u2601 "}),(0,e.jsx)(n,{color:t.primary,bold:!0,children:"Saving to KaneAI"}),(0,e.jsxs)(n,{color:t.dimmed,children:[" ",R(l)]})]}),(0,e.jsx)(r,{flexDirection:"column",marginTop:1,children:s.filter(i=>i.status!=="skipped").map((i,S,T)=>{let b=S===T.length-1?"\u2514\u2500":"\u251C\u2500",m=i.status==="done",u=i.status==="running",g=i.status==="failed";return(0,e.jsxs)(r,{children:[(0,e.jsxs)(n,{color:t.dimmed,children:[" ",b," "]}),(0,e.jsx)(r,{width:3,children:u?(0,e.jsx)(f,{}):m?(0,e.jsx)(n,{color:t.green,children:"\u2713"}):g?(0,e.jsx)(n,{color:t.red,children:"\u2717"}):(0,e.jsx)(n,{color:t.muted,children:"\u25CB"})}),(0,e.jsx)(n,{color:m?t.dim:u?t.base:g?t.red:t.muted,children:i.label}),i.detail&&(0,e.jsxs)(n,{color:t.dimmed,children:[" ",i.detail]})]},i.name)})}),(0,e.jsx)(r,{marginTop:1,children:(0,e.jsx)(n,{color:t.muted,children:" press Ctrl+C twice to force exit"})})]}):o==="success"?(0,e.jsx)(e.Fragment,{}):(0,e.jsxs)(r,{flexDirection:"column",paddingX:1,paddingY:1,children:[(0,e.jsxs)(r,{children:[(0,e.jsx)(n,{color:t.red,children:"\u2601 "}),(0,e.jsx)(n,{color:t.red,bold:!0,children:"Save failed"})]}),a&&(0,e.jsxs)(r,{marginTop:0,children:[(0,e.jsx)(n,{color:t.dimmed,children:" "}),(0,e.jsx)(n,{color:t.dim,children:a})]})]})}export{v as a,U as b,h as c};
@@ -1,5 +1,5 @@
1
1
  import { createRequire } from 'module'; const require = createRequire(import.meta.url);
2
- import{a as oe}from"./chunk-7VX5H5MK.js";import{b as q}from"./chunk-YV5KDJLP.js";import{a as L,c as ae}from"./chunk-FFO5XXKV.js";import{b as ne,e as J,h as ie}from"./chunk-SLA75N5B.js";import{a as K}from"./chunk-66CVM7JL.js";import{b as re,d as se}from"./chunk-G7VF5SDK.js";import{b as G}from"./chunk-VE3SUJMA.js";import{a as k}from"./chunk-NLYBR5FP.js";import{a as ee}from"./chunk-E47GFYXA.js";import{i as B,j as H}from"./chunk-JYQO6G7F.js";import{a as D}from"./chunk-YUUZDFT7.js";import{a as O,b as te}from"./chunk-DXKKUGFG.js";import{dirname as Be,join as He}from"path";function Kt(e,t,r){let s=e.total_runs??1,o=e.run_dir,n,i;if(s>1&&o){let a=Be(o);n=Array.from({length:s},(c,l)=>He(a,String(t+l))),r&&r.length===s&&(i=r)}return{allRunDirs:n,flowObjectives:i}}function Gt(e,t,r,s){return{index:r,objective:t,summary:e.summary,oneLiner:e.one_liner,status:e.status,resultCode:e.result_code,reasonCode:e.reason_code,perFlowMetadata:e.per_flow_metadata,context:e.context??{memory:{},variables:{},pointer:""},run_dir:e.run_dir,run_dirs:s.allRunDirs,flow_objectives:s.flowObjectives}}import{spawn as Ke}from"child_process";async function ce(e,t,r=100){let s=`${e.replace(/\/+$/,"")}/json/version`,o=await fetch(s);if(!o.ok)throw new Error(`CDP /json/version returned ${o.status}`);let n=await o.json();if(!n.webSocketDebuggerUrl)throw new Error("CDP /json/version missing webSocketDebuggerUrl");let i=new ee(n.webSocketDebuggerUrl);await new Promise((S,h)=>{i.once("open",S),i.once("error",h)});let a=1,c=new Map;i.on("message",S=>{let h;try{h=JSON.parse(S.toString())}catch{return}if(h.id==null)return;let _=c.get(h.id);_&&(c.delete(h.id),h.error?_.reject(new Error(h.error.message)):_.resolve(h.result))});function l(S,h){let _=a++;return new Promise((Fe,Me)=>{c.set(_,{resolve:Ve=>Fe(Ve),reject:Me});let Z={id:_,method:S};h&&(Z.params=h),i.send(JSON.stringify(Z))})}let u=(await l("Target.getTargets")).targetInfos.find(S=>S.type==="page");if(!u)throw i.close(),new Error("CDP: no page target found");let m=(await l("Browser.getWindowForTarget",{targetId:u.targetId})).windowId,p="",g=!1,w=null,I=!1;i.on("close",()=>{I=!0}),i.on("error",()=>{I=!0});async function T(){if(!g){if(I){g=!0;return}try{let h=(await l("Browser.getWindowBounds",{windowId:m})).bounds,_=`${h.left}:${h.top}:${h.width}:${h.height}`;_!==p&&(p=_,t({left:h.left,top:h.top,width:h.width,height:h.height}))}catch{}g||(w=setTimeout(T,r))}}return T(),{stop(){if(!g){g=!0,w&&clearTimeout(w);try{i.close()}catch{}}}}}var Ge=new Set(["1","true","yes"]);function Xt(e){if(e?.headless)return null;let t=process.env.KANE_CLI_DISABLE_MARKER;if(t!=null&&Ge.has(t.toLowerCase()))return null;let r=oe();if(!r)return null;let s=[...r.args,"overlay"];e?.text&&s.push(e.text);let o;try{o=Ke(r.cmd,s,{cwd:r.cwd,stdio:["pipe","ignore","ignore"],detached:!1,windowsHide:!0})}catch{return null}function n(c){if(!(!o.stdin||o.stdin.destroyed))try{o.stdin.write(JSON.stringify(c)+`
2
+ import{a as oe}from"./chunk-DUR6AFYA.js";import{b as q}from"./chunk-F6HEB4PA.js";import{a as L,c as ae}from"./chunk-FFO5XXKV.js";import{b as ne,e as J,h as ie}from"./chunk-SLA75N5B.js";import{a as K}from"./chunk-BM4COXQU.js";import{b as re,d as se}from"./chunk-G7VF5SDK.js";import{b as G}from"./chunk-VE3SUJMA.js";import{a as k}from"./chunk-TK7ZJ7YX.js";import{a as ee}from"./chunk-E47GFYXA.js";import{i as B,j as H}from"./chunk-3ELBJPHQ.js";import{a as D}from"./chunk-YUUZDFT7.js";import{a as O,b as te}from"./chunk-DXKKUGFG.js";import{dirname as Be,join as He}from"path";function Kt(e,t,r){let s=e.total_runs??1,o=e.run_dir,n,i;if(s>1&&o){let a=Be(o);n=Array.from({length:s},(c,l)=>He(a,String(t+l))),r&&r.length===s&&(i=r)}return{allRunDirs:n,flowObjectives:i}}function Gt(e,t,r,s){return{index:r,objective:t,summary:e.summary,oneLiner:e.one_liner,status:e.status,resultCode:e.result_code,reasonCode:e.reason_code,perFlowMetadata:e.per_flow_metadata,context:e.context??{memory:{},variables:{},pointer:""},run_dir:e.run_dir,run_dirs:s.allRunDirs,flow_objectives:s.flowObjectives}}import{spawn as Ke}from"child_process";async function ce(e,t,r=100){let s=`${e.replace(/\/+$/,"")}/json/version`,o=await fetch(s);if(!o.ok)throw new Error(`CDP /json/version returned ${o.status}`);let n=await o.json();if(!n.webSocketDebuggerUrl)throw new Error("CDP /json/version missing webSocketDebuggerUrl");let i=new ee(n.webSocketDebuggerUrl);await new Promise((S,h)=>{i.once("open",S),i.once("error",h)});let a=1,c=new Map;i.on("message",S=>{let h;try{h=JSON.parse(S.toString())}catch{return}if(h.id==null)return;let _=c.get(h.id);_&&(c.delete(h.id),h.error?_.reject(new Error(h.error.message)):_.resolve(h.result))});function l(S,h){let _=a++;return new Promise((Fe,Me)=>{c.set(_,{resolve:Ve=>Fe(Ve),reject:Me});let Z={id:_,method:S};h&&(Z.params=h),i.send(JSON.stringify(Z))})}let u=(await l("Target.getTargets")).targetInfos.find(S=>S.type==="page");if(!u)throw i.close(),new Error("CDP: no page target found");let m=(await l("Browser.getWindowForTarget",{targetId:u.targetId})).windowId,p="",g=!1,w=null,I=!1;i.on("close",()=>{I=!0}),i.on("error",()=>{I=!0});async function T(){if(!g){if(I){g=!0;return}try{let h=(await l("Browser.getWindowBounds",{windowId:m})).bounds,_=`${h.left}:${h.top}:${h.width}:${h.height}`;_!==p&&(p=_,t({left:h.left,top:h.top,width:h.width,height:h.height}))}catch{}g||(w=setTimeout(T,r))}}return T(),{stop(){if(!g){g=!0,w&&clearTimeout(w);try{i.close()}catch{}}}}}var Ge=new Set(["1","true","yes"]);function Xt(e){if(e?.headless)return null;let t=process.env.KANE_CLI_DISABLE_MARKER;if(t!=null&&Ge.has(t.toLowerCase()))return null;let r=oe();if(!r)return null;let s=[...r.args,"overlay"];e?.text&&s.push(e.text);let o;try{o=Ke(r.cmd,s,{cwd:r.cwd,stdio:["pipe","ignore","ignore"],detached:!1,windowsHide:!0})}catch{return null}function n(c){if(!(!o.stdin||o.stdin.destroyed))try{o.stdin.write(JSON.stringify(c)+`
3
3
  `)}catch{}}e?.chromePid&&e.chromePid>0&&n({type:"chrome_pid",pid:e.chromePid});let i=null;e?.cdpEndpoint&&ce(e.cdpEndpoint,c=>n({type:"bounds",...c})).then(c=>{i=c.stop}).catch(()=>{});let a=!1;return{setRunActive(c){a||n({type:"run_active",active:c})},setStepText(c){if(a)return;let l=c.trim();l&&n({type:"step_text",text:l})},setStepComplete(){a||n({type:"step_complete"})},kill(){if(!a){a=!0,i?.();try{o.stdin?.end()}catch{}try{o.kill("SIGTERM")}catch{}}}}}import{readFileSync as Je,existsSync as qe}from"fs";function tr(e){if(!qe(e))return null;try{return Je(e,"utf-8").trim()||null}catch{return null}}function le(e,t,r){return`${e}/projects/${t}/test-cases/${r}`}function sr(e,t,r,s){return`${le(e,t,r)}/dashboard/share/${s}?type=summary&agentView=true&fqdn=summary-page`}function or(e,t,r){return`${le(e,t,r)}/dashboard?type=summary&agentView=true&fqdn=summary-page`}import{readFileSync as de,readdirSync as ue,existsSync as R}from"fs";import{join as v}from"path";function cr(e,t,r,s,o,n){try{let i=v(e,"runs",String(t),"run-test");if(!R(i)){o("warn","SCREENSHOT_SKIP","Runs dir not found",{step_index:r,reason:"runsDir_not_found",path:i});return}let a=i;if(n){let g=v(i,`child-${n}`);if(!R(g)){o("warn","SCREENSHOT_SKIP","Child dir not found",{step_index:r,child_id:n,reason:"child_dir_not_found",path:g});return}let w=ue(g).filter(I=>R(v(g,I,"screenshots")));if(w.length===0){o("warn","SCREENSHOT_SKIP","No screenshots dir under child",{step_index:r,child_id:n,reason:"no_child_screenshots_dir"});return}a=v(g,w[0])}else if(!R(v(i,"screenshots"))){let g=ue(i).filter(w=>R(v(i,w,"screenshots")));if(g.length===0){o("warn","SCREENSHOT_SKIP","No screenshots dir found",{step_index:r,reason:"no_screenshots_dir"});return}a=v(i,g[0])}let c=v(a,"screenshots",`step_${String(r).padStart(3,"0")}.png`);if(!R(c)){o("warn","SCREENSHOT_SKIP","Screenshot not found",{step_index:r,child_id:n,reason:"screenshot_not_found",path:c});return}let l=v(i,"actions.ndjson");if(!R(l)){o("warn","SCREENSHOT_SKIP","NDJSON not found",{step_index:r,reason:"ndjson_not_found"});return}let d=de(l,"utf-8").trim().split(`
4
4
  `),u=d[d.length-1];if(!u){o("warn","SCREENSHOT_SKIP","NDJSON empty",{step_index:r,reason:"ndjson_empty"});return}let m=JSON.parse(u).action_id;if(!m){o("warn","SCREENSHOT_SKIP","No action_id in NDJSON",{step_index:r,reason:"no_action_id"});return}let p=de(c);s.enqueue(m,p),o("info","SCREENSHOT_ENQUEUED","Screenshot enqueued",{step_index:r,child_id:n,action_id:m,size:p.length})}catch(i){o("error","SCREENSHOT_DISPATCH_ERROR","Screenshot dispatch error",{step_index:r,error:i instanceof Error?i.message:String(i)})}}import We from"sharp";var me=class{maxWorkers;maxRetries=2;queue=[];activeCount=0;drainResolvers=[];sas;log;constructor(t,r=3,s){this.sas=t,this.maxWorkers=r,this.log=s}updateSas(t){this.sas=t}enqueue(t,r){this.queue.push({operationId:t,buffer:r}),this.pump()}async drain(t=3e4){if(!(this.queue.length===0&&this.activeCount===0))return new Promise(r=>{this.drainResolvers.push(r),setTimeout(()=>{r()},t)})}pump(){for(;this.activeCount<this.maxWorkers&&this.queue.length>0;){let t=this.queue.shift();this.activeCount++,this.processJob(t).finally(()=>{if(this.activeCount--,this.pump(),this.queue.length===0&&this.activeCount===0){for(let r of this.drainResolvers)r();this.drainResolvers=[]}})}}async processJob(t){let r,s="image/webp";try{let a=await We(t.buffer).webp({quality:80}).toBuffer();r=new Uint8Array(a)}catch(a){r=new Uint8Array(t.buffer),s="image/png",this.log?.("warn","SCREENSHOT_CONVERT_FAILED","WebP conversion failed, using PNG",{operation_id:t.operationId,error:a instanceof Error?a.message:String(a)})}let o=s==="image/webp"?"webp":"png",n=`test_screenshots/untagged_screenshot/${t.operationId}.${o}`,i=`${this.sas.base_url}/${this.sas.container}/${n}?${this.sas.sas_token}`;for(let a=0;a<=this.maxRetries;a++)try{let c=await fetch(i,{method:"PUT",headers:{"Content-Type":s,"x-ms-blob-type":"BlockBlob"},body:r});if(c.ok)return;if(a<this.maxRetries){await this.backoff(a);continue}this.log?.("warn","SCREENSHOT_UPLOAD_FAILED","Screenshot upload failed after retries",{operation_id:t.operationId,status:c.status,attempts:this.maxRetries+1})}catch{if(a<this.maxRetries){await this.backoff(a);continue}this.log?.("warn","SCREENSHOT_UPLOAD_FAILED","Screenshot upload failed (network error)",{operation_id:t.operationId,error:"network",attempts:this.maxRetries+1})}}backoff(t){let r=t===0?1e3:3e3;return new Promise(s=>setTimeout(s,r))}isNearExpiry(){if(!this.sas.expiry)return!1;let t=new Date(this.sas.expiry).getTime();return Date.now()>t-5*6e4}};function fe(e,t){let r={},s={},o=t;for(let[n,i]of Object.entries(e))if(i.secret){let a=`secrets.user.${n}`;r[a]={value:i.value,secret:!0,syntax:`{{secrets.user.${n}}}`,type:"secret"},s[n]=a,o=o.replaceAll(`{{${n}}}`,`{{secrets.user.${n}}}`)}else{let a=`global.${n}`;r[a]={value:i.value,secret:!1,syntax:`{{global.${n}}}`,type:"global"},s[n]=a,o=o.replaceAll(`{{${n}}}`,`{{global.${n}}}`)}return{variables:r,objective:o,keyMap:s}}var $=class{constructor(t){this.baseUrl=t}async pushSecret(t){let r=O(t.username,t.accessKey),s=await fetch(`${this.baseUrl}/logistics/v1.0/secrets/create`,{method:"PUT",headers:{Authorization:r,"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({secretKey:t.secretKey,secretValue:t.secretValue,orgId:t.orgId,username:t.username,scope:"user",type:"user",accessKey:t.accessKey})});if(!s.ok)throw new Error(`Push secret failed: ${s.status} ${await s.text()}`)}static extractVariableKeys(t){let r=t.matchAll(/\{\{([a-zA-Z_][a-zA-Z0-9_]*)\}\}/g),s=new Set;for(let o of r)s.add(o[1]);return[...s]}};var N=class extends te{constructor(t,r,s){super(t,{username:r,accessKey:s})}async upsertVariable(t){let r=t.environmentId??0,s=await fetch(`${this.baseUrl}/v1/variables`,{method:"POST",headers:this.headers(),body:JSON.stringify({name:t.name,value:String(t.value),type:"variable",value_type:"string",is_persist:t.isPersist??!1,environment_id:r})});if(s.ok)return{id:(await s.json()).id??0};if(s.status!==409&&s.status!==422)return{id:0};if(!(await fetch(`${this.baseUrl}/v1/variables/name/${encodeURIComponent(t.name)}`,{method:"PUT",headers:this.headers(),body:JSON.stringify({value:String(t.value),value_type:"string",type:"variable",environment_id:r})})).ok)return{id:0};let n=await fetch(`${this.baseUrl}/v1/variables/${encodeURIComponent(t.name)}?environment_id=${r}`,{method:"GET",headers:this.headers()});return n.ok?{id:(await n.json()).data?.id??0}:{id:0}}};import{readdirSync as ze,readFileSync as ge,existsSync as he}from"fs";import{join as Ye}from"path";function pe(e,t){if(!he(e))return{};let r={},s;try{s=ze(e).filter(o=>o.endsWith(".json")).sort()}catch{return{}}for(let o of s)try{let n=ge(Ye(e,o),"utf-8"),i=JSON.parse(n);if(i&&typeof i=="object"){for(let[a,c]of Object.entries(i))if(c&&typeof c=="object"&&"value"in c){let l=c;r[a]={value:l.value,secret:l.secret??!1,syntax:l.syntax??`{{${a}}}`}}}}catch{t?t("warn","VARIABLE_PARSE_FAILED","Skipping invalid variables file",{file:o}):process.stderr.write(`[variables] Warning: skipping invalid variables file: ${o}
5
5
  `)}return r}function be(e){if(!he(e))throw new Error(`Variables file not found: ${e}`);let t=ge(e,"utf-8"),r=JSON.parse(t),s={};if(r&&typeof r=="object"){for(let[o,n]of Object.entries(r))if(n&&typeof n=="object"&&"value"in n){let i=n;s[o]={value:i.value,secret:i.secret??!1,syntax:i.syntax??`{{${o}}}`}}}return s}function ye(e){let t;try{t=JSON.parse(e)}catch{throw new Error("Invalid --variables JSON")}let r={};if(t&&typeof t=="object"){for(let[s,o]of Object.entries(t))if(o&&typeof o=="object"&&"value"in o){let n=o;r[s]={value:n.value,secret:n.secret??!1,syntax:n.syntax??`{{${s}}}`}}}return r}function we(e,t,r){let s=pe(e,r),o=pe(t,r);return{...s,...o}}function Cr(e,t){if(Object.keys(e).length===0)return{};let r={};for(let[s,o]of Object.entries(e)){let n=o.syntax??`{{${s}}}`;t.includes(n)&&(r[s]=o)}return r}function xr(e){let t=we(e.globalDir,e.localDir,e.onLoadError),r=e.file?be(e.file):{},s=e.inline?ye(e.inline):{},o={...t,...r,...s},n=Object.keys(o).length>0,{variables:i,objective:a}=n?fe(o,e.objective):{variables:{},objective:e.objective},c=Object.entries(o).filter(([,d])=>d.secret),l=Object.entries(o).filter(([,d])=>!d.secret);return{raw:o,auteur:i,auteurObjective:a,secretEntries:c,nonSecretEntries:l}}async function kr(e){if(e.localMode)return{};let t=k(e.env);if(e.variables.secretEntries.length>0){let s=new $(t.secretsBaseUrl);for(let[o,n]of e.variables.secretEntries)s.pushSecret({secretKey:o,secretValue:n.value,username:e.auth.username,accessKey:e.auth.access_key,orgId:e.orgId}).then(()=>e.log("info","SECRET_PUSH_OK","Secret pushed",{key:o})).catch(i=>e.log("error","SECRET_PUSH_FAILED","Secret push failed",{key:o,error:String(i)}))}let r={};if(e.variables.nonSecretEntries.length>0){let s=new N(t.tmsBaseUrl,e.auth.username,e.auth.access_key);for(let[o,n]of e.variables.nonSecretEntries)try{let i=await s.upsertVariable({name:o,value:n.value});r[o]=i.id,e.log("info","VAR_PUSH_OK","Variable pushed",{name:o,id:i.id})}catch(i){e.log("error","VAR_PUSH_FAILED","Variable push failed",{name:o,error:String(i)})}}return r}function Pr(e){let t={objective:e.objective,model:e.model,width:e.windowSize.width,height:e.windowSize.height,session_id:e.sessionId,run_index:e.runIndex,stream:!0,max_steps:e.maxSteps??30,headless:e.headless??!1};return e.url&&(t.url=e.url),e.chrome.wsEndpoint?t.ws_endpoint=e.chrome.wsEndpoint:e.chrome.cdpEndpoint&&(t.cdp_endpoint=e.chrome.cdpEndpoint),e.auth.basicAuth?(t.username=e.auth.basicAuth.username,t.access_key=e.auth.basicAuth.access_key):e.auth.token&&(t.auth={type:"bearer",token:e.auth.token}),e.disableAskUser&&(t.disable_ask_user=!0),e.enableTaskSkills&&(t.enable_task_skills=!0),e.variables&&Object.keys(e.variables).length>0&&(t.variables=e.variables),e.globalContext&&(t.global_context=e.globalContext),e.localContext&&(t.local_context=e.localContext),e.sessionContext&&(t.session_context=e.sessionContext),t}var Qe=15e3,W=3,Se=[500,1e3];async function Tr(e){if(process.env.KANE_LOCK_CONFLICT_SIMULATE==="1")return{ok:!1,reason:"concurrent",httpStatus:409,message:"simulated contention (KANE_LOCK_CONFLICT_SIMULATE=1)"};let t=`${e.baseUrl}/test/${encodeURIComponent(e.testId)}/playground`,r=await U(t,{from_commit_id:e.fromCommitId,new_commit_id:e.newCommitId},e.auth);return r.ok?{ok:!0,sessionExpiresAt:y(r.body,"session_expires_at")??""}:{ok:!1,...Xe(r)}}function Xe(e){let t=y(e.body,"error")??y(e.body,"code")??"",r=y(e.body,"message")??y(e.body,"detail")??e.text??`HTTP ${e.status}`,s;return e.status===0?s="network":e.status===401||e.status===403?s="auth":e.status===409&&t==="PlaygroundBaseCommitMismatch"?s="base_mismatch":e.status===409?s="concurrent":e.status===422?s="disabled":e.status===400&&/no committed/i.test(r)?s="no_commits":e.status===400?s="missing_field":e.status>=500||e.status===408||e.status===429?s="network":s="other",{reason:s,httpStatus:e.status,message:r}}async function Or(e){let t=`${e.baseUrl}/test/${encodeURIComponent(e.testId)}/playground/reserve`,r=await U(t,void 0,e.auth);return r.ok?{ok:!0,sessionExpiresAt:y(r.body,"session_expires_at")??""}:{ok:!1,expired:r.status===404,httpStatus:r.status,message:y(r.body,"message")??y(r.body,"detail")??r.text??`HTTP ${r.status}`}}async function ve(e){let t=`${e.baseUrl}/test/${encodeURIComponent(e.testId)}/commit`,r={commit_id:e.body.commitId,from_commit_id:e.body.fromCommitId,commit_message:e.body.commitMessage,total_steps:e.body.totalSteps};e.body.timeTaken!==void 0&&(r.time_taken=e.body.timeTaken),e.body.objectives!==void 0&&(r.objectives=e.body.objectives);let s=await U(t,r,e.auth);return s.ok?{ok:!0,testId:y(s.body,"test_id")??e.testId,testcaseId:y(s.body,"testcase_id")??"",projectId:y(s.body,"project_id"),isTestCaseDeleted:typeof s.body?.is_test_case_deleted=="boolean"?s.body.is_test_case_deleted:void 0}:{ok:!1,...Ze(s)}}function Ze(e){let t=y(e.body,"error")??y(e.body,"code")??"",r=y(e.body,"message")??y(e.body,"detail")??e.text??`HTTP ${e.status}`,s;return e.status===0?s="network":e.status===401||e.status===403?s="auth":e.status===409&&t==="PlaygroundBaseCommitMismatch"?s="base_mismatch":e.status===409&&t==="PlaygroundCommitLockMismatch"?s="lock_mismatch":e.status===409?s="expired":e.status===422?s="not_found":e.status>=500||e.status===408||e.status===429?s="network":s="other",{reason:s,httpStatus:e.status,message:r}}async function Dr(e){let t=`${e.baseUrl}/test/${encodeURIComponent(e.testId)}/commit`,r={discard:!0,commit_id:e.body.commitId,from_commit_id:e.body.fromCommitId,commit_message:"(discarded)",total_steps:1},s=await U(t,r,e.auth);return s.ok?{ok:!0}:{ok:!1,reason:y(s.body,"error")??"other",httpStatus:s.status,message:y(s.body,"message")??y(s.body,"detail")??s.text??`HTTP ${s.status}`}}async function U(e,t,r){let s=null;for(let o=1;o<=W;o++){let n=new AbortController,i=setTimeout(()=>n.abort(),Qe);try{let a=await fetch(e,{method:"POST",headers:{Authorization:O(r.username,r.accessKey),"Content-Type":"application/json",Accept:"application/json"},...t!==void 0?{body:JSON.stringify(t)}:{},signal:n.signal});clearTimeout(i);let c=await a.text(),l=null;if(c)try{l=JSON.parse(c)}catch{}let d=a.status>=500||a.status===408||a.status===429;if(a.ok||!d)return{ok:a.ok,status:a.status,body:l,text:c};if(o<W){await _e(Se[o-1]??1e3);continue}return{ok:!1,status:a.status,body:l,text:c}}catch(a){if(clearTimeout(i),s=a,o<W){await _e(Se[o-1]??1e3);continue}}}return{ok:!1,status:0,body:null,text:s?.message??"exhausted retries"}}function _e(e){return new Promise(t=>setTimeout(t,e))}function y(e,t){if(typeof e!="object"||e===null)return;let r=e[t];return typeof r=="string"?r:void 0}import{readFileSync as Oe,writeFileSync as De,existsSync as Le}from"fs";import{mkdirSync as Q,writeFileSync as _t}from"fs";import{join as x}from"path";import{createHash as et}from"crypto";function z(e){if(e==null)return null;if(Array.isArray(e))return e.map(z);if(typeof e=="object"){let t={};for(let r of Object.keys(e).sort()){let s=e[r];s!==void 0&&(t[r]=z(s))}return t}return e}function tt(e){if(e.body.kind!=="objective")throw new Error("stepMd5: only objective steps have an md5; @import rows do not");let t={...e.config??{},optional:e.optional??!1},r=JSON.stringify(z(t));return et("md5").update(e.body.text).update(`
@@ -1,2 +1,2 @@
1
1
  import { createRequire } from 'module'; const require = createRequire(import.meta.url);
2
- import{b as B}from"./chunk-S3DAAAE5.js";import{a as h}from"./chunk-4SNZTVJB.js";import{a as w}from"./chunk-HCBYKLMW.js";import{t as s}from"./chunk-JYQO6G7F.js";import{a as x,b as t,c as g,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"),[m,a]=(0,o.useState)(""),[f,u]=(0,o.useState)(null),l=(0,o.useMemo)(()=>m.trim()||i,[m,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)(h,{title:"Save session?",titleColor:"#ff9500",rows:[{label:"name",value:(0,e.jsx)(t,{color:s.cyan,children:i})}],footer:(0,e.jsxs)(x,{flexDirection:"column",children:[(0,e.jsx)(t,{color:s.dimmed,children:"enter \u2014 save with this name"}),(0,e.jsx)(t,{color:s.dimmed,children:"Y \u2014 edit name"}),(0,e.jsx)(t,{color:s.dimmed,children:"N/esc \u2014 discard session"})]})}):(0,e.jsx)(h,{title:"Save session?",titleColor:"#ff9500",rows:[{label:"name",value:(0,e.jsxs)(x,{children:[(0,e.jsx)(t,{color:s.cyan,children:m}),(0,e.jsx)(t,{inverse:!0,children:" "})]})}],footer:(0,e.jsxs)(x,{flexDirection:"column",children:[f&&(0,e.jsx)(t,{color:s.red,children:f}),(0,e.jsx)(t,{color:s.dimmed,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(),[f,u]=(0,o.useState)(!1);return(0,o.useEffect)(()=>{if(f){let l=setTimeout(()=>a(),50);return()=>clearTimeout(l)}},[f,a]),(0,e.jsx)(D,{defaultName:i,onSubmit:l=>{c(l),u(!0)}})}let{waitUntilExit:p,unmount:m}=g((0,e.jsx)(d,{}),{stdout:process.stderr,exitOnCtrlC:!1});p().then(()=>{try{m()}catch{}})})}export{D as a,V as b,Y as c};
2
+ import{b as B}from"./chunk-S3DAAAE5.js";import{a as h}from"./chunk-ZX3PMRMO.js";import{a as w}from"./chunk-HCBYKLMW.js";import{t as s}from"./chunk-3ELBJPHQ.js";import{a as x,b as t,c as g,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"),[m,a]=(0,o.useState)(""),[f,u]=(0,o.useState)(null),l=(0,o.useMemo)(()=>m.trim()||i,[m,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)(h,{title:"Save session?",titleColor:"#ff9500",rows:[{label:"name",value:(0,e.jsx)(t,{color:s.cyan,children:i})}],footer:(0,e.jsxs)(x,{flexDirection:"column",children:[(0,e.jsx)(t,{color:s.dimmed,children:"enter \u2014 save with this name"}),(0,e.jsx)(t,{color:s.dimmed,children:"Y \u2014 edit name"}),(0,e.jsx)(t,{color:s.dimmed,children:"N/esc \u2014 discard session"})]})}):(0,e.jsx)(h,{title:"Save session?",titleColor:"#ff9500",rows:[{label:"name",value:(0,e.jsxs)(x,{children:[(0,e.jsx)(t,{color:s.cyan,children:m}),(0,e.jsx)(t,{inverse:!0,children:" "})]})}],footer:(0,e.jsxs)(x,{flexDirection:"column",children:[f&&(0,e.jsx)(t,{color:s.red,children:f}),(0,e.jsx)(t,{color:s.dimmed,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(),[f,u]=(0,o.useState)(!1);return(0,o.useEffect)(()=>{if(f){let l=setTimeout(()=>a(),50);return()=>clearTimeout(l)}},[f,a]),(0,e.jsx)(D,{defaultName:i,onSubmit:l=>{c(l),u(!0)}})}let{waitUntilExit:p,unmount:m}=g((0,e.jsx)(d,{}),{stdout:process.stderr,exitOnCtrlC:!1});p().then(()=>{try{m()}catch{}})})}export{D as a,V as b,Y as c};
@@ -1,2 +1,2 @@
1
1
  import { createRequire } from 'module'; const require = createRequire(import.meta.url);
2
- import{a as x}from"./chunk-HCBYKLMW.js";import{t as m}from"./chunk-JYQO6G7F.js";import{a as u,b as a,j as g}from"./chunk-C44QQJR4.js";import{a as b}from"./chunk-6YGTRKDT.js";import{e as f}from"./chunk-UR6MHSHU.js";var T=f(b(),1);function k(n,t){if(!t)return n;let l=n.trim()||t;return`\x1B]8;;${t}\x07${l}\x1B]8;;\x07`}var r=f(x(),1);function $({shareableLink:n,testCaseLink:t,codeExportDir:l,recordedTestPath:s,outputDir:o,autoExit:p=!0}){let{exit:c}=g();(0,T.useEffect)(()=>{if(!p)return;let i=setTimeout(()=>c(),100);return()=>clearTimeout(i)},[c,p]);let e=[];return s&&e.push({label:"Test",url:s,linkUrl:`file://${s}`}),o&&e.push({label:"Output",url:o,linkUrl:`file://${o}`}),n&&e.push({label:"ShareLink",url:n}),t&&e.push({label:"TestCase",url:t}),l&&!o&&e.push({label:"CodeExport",url:l,linkUrl:`file://${l}`}),e.length===0?(0,r.jsx)(r.Fragment,{}):(0,r.jsx)(u,{flexDirection:"column",marginTop:1,marginLeft:1,children:e.map(i=>(0,r.jsxs)(u,{flexDirection:"column",marginBottom:1,children:[(0,r.jsxs)(a,{color:m.primary,children:[i.label,":"]}),(0,r.jsx)(a,{color:m.dim,children:k(i.url,i.linkUrl??i.url)})]},i.label))})}export{$ as a};
2
+ import{a as x}from"./chunk-HCBYKLMW.js";import{t as m}from"./chunk-3ELBJPHQ.js";import{a as u,b as a,j as g}from"./chunk-C44QQJR4.js";import{a as b}from"./chunk-6YGTRKDT.js";import{e as f}from"./chunk-UR6MHSHU.js";var T=f(b(),1);function k(n,t){if(!t)return n;let l=n.trim()||t;return`\x1B]8;;${t}\x07${l}\x1B]8;;\x07`}var r=f(x(),1);function $({shareableLink:n,testCaseLink:t,codeExportDir:l,recordedTestPath:s,outputDir:o,autoExit:p=!0}){let{exit:c}=g();(0,T.useEffect)(()=>{if(!p)return;let i=setTimeout(()=>c(),100);return()=>clearTimeout(i)},[c,p]);let e=[];return s&&e.push({label:"Test",url:s,linkUrl:`file://${s}`}),o&&e.push({label:"Output",url:o,linkUrl:`file://${o}`}),n&&e.push({label:"ShareLink",url:n}),t&&e.push({label:"TestCase",url:t}),l&&!o&&e.push({label:"CodeExport",url:l,linkUrl:`file://${l}`}),e.length===0?(0,r.jsx)(r.Fragment,{}):(0,r.jsx)(u,{flexDirection:"column",marginTop:1,marginLeft:1,children:e.map(i=>(0,r.jsxs)(u,{flexDirection:"column",marginBottom:1,children:[(0,r.jsxs)(a,{color:m.primary,children:[i.label,":"]}),(0,r.jsx)(a,{color:m.dim,children:k(i.url,i.linkUrl??i.url)})]},i.label))})}export{$ as a};
@@ -1,2 +1,2 @@
1
1
  import { createRequire } from 'module'; const require = createRequire(import.meta.url);
2
- import{a as I}from"./chunk-YCCUBQY4.js";import{a as A}from"./chunk-XJ7OYQ7M.js";import{a as L}from"./chunk-NLYBR5FP.js";import{a as R}from"./chunk-BSQVYLV7.js";import{a as v}from"./chunk-HCBYKLMW.js";import{t as s}from"./chunk-JYQO6G7F.js";import{a as u,b as i}from"./chunk-C44QQJR4.js";import{a as J}from"./chunk-6YGTRKDT.js";import{a as T}from"./chunk-YUUZDFT7.js";import{e as N}from"./chunk-UR6MHSHU.js";var t=N(J(),1);var e=N(v(),1);function X(n,y,c){return{id:n,label:`${y} (${n})`,isActive:n===c}}function Z({resolver:n,currentProjectId:y,env:c,onSelect:x,onCancel:w}){let[F,M]=(0,t.useState)([]),[_,l]=(0,t.useState)(!0),[$,m]=(0,t.useState)(!1),[O,P]=(0,t.useState)(null),[g,d]=(0,t.useState)("list"),[S,k]=(0,t.useState)(""),[C,p]=(0,t.useState)(null),h=(0,t.useRef)(!1);(0,t.useEffect)(()=>{if(!n){P("Login first to browse projects"),l(!1);return}let o=new AbortController;return l(!0),m(!0),(async()=>{try{let r=n.cached??await n.resolve();if(!r){P("Login first to browse projects"),l(!1),m(!1);return}let a=L(c),E=new T(a.tmsBaseUrl,r.username,r.access_key),j=!0,b=0;for await(let f of E.listProjectsStream({signal:o.signal})){if(j&&(l(!1),j=!1),f.totalLoaded===0&&f.done&&b===0){h.current=!0,d("naming"),m(!1);return}f.projects.length>0&&(M(H=>[...H,...f.projects.map(B=>X(B.project_id,B.name,y))]),b+=f.projects.length),f.done&&m(!1)}j&&(l(!1),m(!1))}catch(r){if(r?.name==="AbortError")return;P(r instanceof Error?r.message:String(r)),l(!1),m(!1)}})(),()=>o.abort()},[n,y,c]);let U=(0,t.useCallback)(o=>{let r=o.trim();if(!r){p("Name cannot be empty");return}p(null),d("creating"),(async()=>{try{if(!n)throw new Error("Not authenticated");let a=n.cached??await n.resolve();if(!a)throw new Error("Not authenticated");let E=L(c),b=await new T(E.tmsBaseUrl,a.username,a.access_key).createProject(r);x(b.id,b.name)}catch(a){p(a instanceof Error?a.message:String(a)),d("naming")}})()},[n,c,x]),D=(0,t.useCallback)(()=>{k(""),p(null),h.current?w():d("list")},[w]);return g==="naming"||g==="creating"?(0,e.jsxs)(u,{flexDirection:"column",borderStyle:"round",borderColor:s.primary,paddingX:2,paddingY:1,children:[(0,e.jsx)(i,{color:s.primary,bold:!0,children:"Create new project"}),h.current&&(0,e.jsx)(u,{marginTop:1,children:(0,e.jsx)(i,{color:s.dim,children:"No projects yet \u2014 let's create one."})}),(0,e.jsxs)(u,{marginTop:1,children:[(0,e.jsx)(i,{color:s.dim,children:"Name: "}),g==="naming"?(0,e.jsx)(I,{value:S,onChange:o=>{k(o),C&&p(null)},onSubmit:U,onCancel:D}):(0,e.jsx)(i,{children:S})]}),C&&(0,e.jsx)(u,{marginTop:1,children:(0,e.jsx)(i,{color:s.red,children:C})}),g==="creating"&&(0,e.jsx)(u,{marginTop:1,children:(0,e.jsx)(i,{color:s.dim,children:"Creating..."})}),g==="naming"&&(0,e.jsx)(R,{bindings:[{keys:"\u21B5",label:"create"}],escBackLabel:h.current?"cancel":"back"})]}):(0,e.jsx)(A,{title:"Projects",items:F,loading:_,loadingMore:$,preserveSelectionById:!0,error:O,itemNoun:"projects",onTab:()=>{h.current=!1,d("naming")},extraHint:"tab to create new",onSelect:o=>{let r=o.label.replace(` (${o.id})`,"");x(o.id,r)},onCancel:w})}export{X as a,Z as b};
2
+ import{a as I}from"./chunk-YCCUBQY4.js";import{a as A}from"./chunk-THNGNS36.js";import{a as L}from"./chunk-TK7ZJ7YX.js";import{a as R}from"./chunk-HJ3CHMEM.js";import{a as v}from"./chunk-HCBYKLMW.js";import{t as s}from"./chunk-3ELBJPHQ.js";import{a as u,b as i}from"./chunk-C44QQJR4.js";import{a as J}from"./chunk-6YGTRKDT.js";import{a as T}from"./chunk-YUUZDFT7.js";import{e as N}from"./chunk-UR6MHSHU.js";var t=N(J(),1);var e=N(v(),1);function X(n,y,c){return{id:n,label:`${y} (${n})`,isActive:n===c}}function Z({resolver:n,currentProjectId:y,env:c,onSelect:x,onCancel:w}){let[F,M]=(0,t.useState)([]),[_,l]=(0,t.useState)(!0),[$,m]=(0,t.useState)(!1),[O,P]=(0,t.useState)(null),[g,d]=(0,t.useState)("list"),[S,k]=(0,t.useState)(""),[C,p]=(0,t.useState)(null),h=(0,t.useRef)(!1);(0,t.useEffect)(()=>{if(!n){P("Login first to browse projects"),l(!1);return}let o=new AbortController;return l(!0),m(!0),(async()=>{try{let r=n.cached??await n.resolve();if(!r){P("Login first to browse projects"),l(!1),m(!1);return}let a=L(c),E=new T(a.tmsBaseUrl,r.username,r.access_key),j=!0,b=0;for await(let f of E.listProjectsStream({signal:o.signal})){if(j&&(l(!1),j=!1),f.totalLoaded===0&&f.done&&b===0){h.current=!0,d("naming"),m(!1);return}f.projects.length>0&&(M(H=>[...H,...f.projects.map(B=>X(B.project_id,B.name,y))]),b+=f.projects.length),f.done&&m(!1)}j&&(l(!1),m(!1))}catch(r){if(r?.name==="AbortError")return;P(r instanceof Error?r.message:String(r)),l(!1),m(!1)}})(),()=>o.abort()},[n,y,c]);let U=(0,t.useCallback)(o=>{let r=o.trim();if(!r){p("Name cannot be empty");return}p(null),d("creating"),(async()=>{try{if(!n)throw new Error("Not authenticated");let a=n.cached??await n.resolve();if(!a)throw new Error("Not authenticated");let E=L(c),b=await new T(E.tmsBaseUrl,a.username,a.access_key).createProject(r);x(b.id,b.name)}catch(a){p(a instanceof Error?a.message:String(a)),d("naming")}})()},[n,c,x]),D=(0,t.useCallback)(()=>{k(""),p(null),h.current?w():d("list")},[w]);return g==="naming"||g==="creating"?(0,e.jsxs)(u,{flexDirection:"column",borderStyle:"round",borderColor:s.primary,paddingX:2,paddingY:1,children:[(0,e.jsx)(i,{color:s.primary,bold:!0,children:"Create new project"}),h.current&&(0,e.jsx)(u,{marginTop:1,children:(0,e.jsx)(i,{color:s.dim,children:"No projects yet \u2014 let's create one."})}),(0,e.jsxs)(u,{marginTop:1,children:[(0,e.jsx)(i,{color:s.dim,children:"Name: "}),g==="naming"?(0,e.jsx)(I,{value:S,onChange:o=>{k(o),C&&p(null)},onSubmit:U,onCancel:D}):(0,e.jsx)(i,{children:S})]}),C&&(0,e.jsx)(u,{marginTop:1,children:(0,e.jsx)(i,{color:s.red,children:C})}),g==="creating"&&(0,e.jsx)(u,{marginTop:1,children:(0,e.jsx)(i,{color:s.dim,children:"Creating..."})}),g==="naming"&&(0,e.jsx)(R,{bindings:[{keys:"\u21B5",label:"create"}],escBackLabel:h.current?"cancel":"back"})]}):(0,e.jsx)(A,{title:"Projects",items:F,loading:_,loadingMore:$,preserveSelectionById:!0,error:O,itemNoun:"projects",onTab:()=>{h.current=!1,d("naming")},extraHint:"tab to create new",onSelect:o=>{let r=o.label.replace(` (${o.id})`,"");x(o.id,r)},onCancel:w})}export{X as a,Z as b};
@@ -1,2 +1,2 @@
1
1
  import { createRequire } from 'module'; const require = createRequire(import.meta.url);
2
- import{a as u,b as x}from"./chunk-CFFWCE27.js";import{a as f}from"./chunk-HCBYKLMW.js";import{t as m}from"./chunk-JYQO6G7F.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:d,borderColor:c,variant:p,rows:s,footer:t,labelWidth:l=14,marginBottom:b=1}){return(0,e.jsxs)(u,{title:B,titleColor:d,borderColor:c,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.dimmed,children:o.label})}),o.value]},`${o.label}-${a}`)),t&&(0,e.jsx)(r,{marginTop:1,children:t})]})}export{C as a};
2
+ import{a as u,b as x}from"./chunk-34DK2AUH.js";import{a as f}from"./chunk-HCBYKLMW.js";import{t as m}from"./chunk-3ELBJPHQ.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:d,borderColor:c,variant:p,rows:s,footer:t,labelWidth:l=14,marginBottom:b=1}){return(0,e.jsxs)(u,{title:B,titleColor:d,borderColor:c,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.dimmed,children:o.label})}),o.value]},`${o.label}-${a}`)),t&&(0,e.jsx)(r,{marginTop:1,children:t})]})}export{C as a};