fluxflow-cli 4.6.3 → 4.7.0

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.
@@ -1,224 +0,0 @@
1
- import{A as Ii,B as Ai,C as Li,D as cr,E as Oi,F as Pi,G as Ni,H as Fi,I as is,J as jo,K as ur,T as $i,W as Xi,X as On,Y as _i,Z as Hi,_ as Wi,a as yt,b as ht,c as ut,d as Mi,e as os,f as ns,g as In,h as Bi,i as ho,j as Di,k as je,l as qe,m as lr,n as An,o as rs,p as vi,q as an,r as Gt,s as Ei,t as ar,u as ki,v as Ln,w as Ao,x as dn,y as dr,z as ss}from"./chunk-4TMLJ3QH.js";import{b as ln,c as Zr,k as Ti}from"./chunk-JM3JCK2K.js";import{b as ts}from"./chunk-A2MCYGU4.js";import{a as bi,b as yi,c as sr,d as ir,f as bt,g as Vo,h as es,l as Si}from"./chunk-QLPFOHKZ.js";import{a as hi,b as xi,c as pi,e as Io,f as ro,g as wi,h as Rr,i as kt}from"./chunk-IJCIHHAH.js";import{c as mi,d as gi,e as fi}from"./chunk-SIINYZWE.js";import{e as Ci}from"./chunk-7PJOF5I2.js";import{a as ko,b as kn,c as no,d as rr,e as zr,j as Jr}from"./chunk-4TZKD2XR.js";import{a as Ui}from"./chunk-56EJGQU3.js";import"./chunk-ROHVHR3J.js";import Es from"os";import e,{useState as q,useEffect as Qe,useRef as Ve,useMemo as fn}from"react";import{Box as c,Text as s,useInput as Bd,useStdout as Dd,Static as vd}from"ink";import Ed from"ink-spinner";import rt from"fs-extra";import Dt from"path";import{exec as mo}from"child_process";import{fileURLToPath as kd}from"url";import Ut,{useState as mr,useEffect as ls,useMemo as Pn,useCallback as zl,useRef as xo}from"react";import{Box as Jl,Text as eo,useInput as Zl}from"ink";function Rl(t,g){return t.replace(/\t/g," ".repeat(g))}function gr(t){return t==null?"":t.replace(/\r\n/g,`
2
- `).replace(/\r/g,`
3
- `)}function Ko(t,g,x){let S=t,w=[...g].sort((i,v)=>i.start-v.start),p=0;for(let i of w){let v=i.start-p,m=gr(i.text).split(`
4
- `).length,B=i.text.length,M=(m>3?`[Pasted ${m} lines]`:`[Pasted ${B} chars]`).length,$=v+M;if(t<=v)break;if(t<$){S=i.end;break}else{let D=i.text.length-M;S+=D,p+=D}}return Math.min(S,x.length)}function as(t,g,x,S,w=[]){let p=(t||"").slice(0,g),i=S(p).length,v=S(t||""),m=[...w].sort((O,L)=>L.start-O.start);for(let O of m){let L=S(t.slice(0,O.start)).length,X=S(O.text),te=L+X.length,ae=gr(O.text).split(`
5
- `).length,fe=O.text.length,Q=ae>3?`[Pasted ${ae} lines]`:`[Pasted ${fe} chars]`;v=v.slice(0,L)+Q+v.slice(te),i>L&&i<te?i=L+Q.length:i>=te&&(i=i-(te-L)+Q.length)}let B=v.split(`
6
- `),M=[],$=0,D=0,E=0,k=!1;for(let O=0;O<B.length;O++){let L=B[O];if(L.length===0){!k&&i===$&&(D=M.length,E=0,k=!0),M.push({text:"",globalStart:Ko($,w,t),formattedStart:$}),$+=1;continue}let te=ht(L,x).split(`
7
- `),ae=0,fe=[];for(let Q=0;Q<te.length;Q++){let K=te[Q],se=K.trim();if(se.length===0){let De=K.length||1;fe.push({text:K,start:ae,length:De}),ae+=De}else{let De=L.indexOf(se,ae);if(De!==-1){let ye=ae,ke=Q<te.length-1?te[Q+1].trim():"",de=L.length;if(ke.length>0){let Ne=L.indexOf(ke,De+se.length);Ne!==-1&&(de=Ne)}fe.push({text:L.slice(ye,de),start:ye,length:de-ye}),ae=de}else fe.push({text:K,start:ae,length:K.length}),ae+=K.length}}for(let Q=0;Q<fe.length;Q++){let K=fe[Q],se=K.text,De=$+K.start,ye=De+K.length;!k&&i>=De&&(i<ye||i===ye&&Q===fe.length-1)&&(D=M.length,E=i-De,k=!0),M.push({text:se,globalStart:Ko(De,w,t),formattedStart:De})}$+=L.length+1}return k||(M.length===0?M.push({text:"",globalStart:0,formattedStart:0}):v.endsWith(`
8
- `)?(M.push({text:"",globalStart:Ko($,w,t),formattedStart:$}),D=M.length-1,E=0):(D=M.length-1,E=M[D].text.length)),{visualLines:M,cursorLine:D,cursorCol:E}}var ea=({value:t,rows:g,maxRows:x,highlightStyle:S,textStyle:w,placeholder:p="",mask:i,showCursor:v=!0,focus:m=!0,tabSize:B=4,cursorIndex:M=0,highlight:$,columns:D=80,pasteBlocks:E=[],cursorColor:k})=>{let O=xo(0),L=Pn(()=>Math.max(20,D-10),[D]),X=zl((he,R=!1)=>{let P=gr(he);if(!R&&i)return P.replace(/[^\n]/g,i);let ee=Rl(P,B);return R?ee:ee.replace(/@\[(.*?)\]/g,(ie,we)=>{let Ee=we.indexOf("#"),Ce=we.indexOf(":L"),Ie=we,Re="";Ee!==-1?(Ie=we.slice(0,Ee),Re=we.slice(Ee)):Ce!==-1&&(Ie=we.slice(0,Ce),Re=we.slice(Ce));let st=Ie.replace(/\\/g,"/"),ve=(process.cwd()||"").replace(/\\/g,"/");ve&&st.toLowerCase().startsWith(ve.toLowerCase()+"/")?st=st.slice(ve.length+1):st.startsWith("./")&&(st=st.slice(2));let oe=st.split("/");return`[${oe[oe.length-1]}${Re}]`})},[B,i]),{visualLines:te,cursorLine:ae,cursorCol:fe}=Pn(()=>as(t,M,L,X,E),[t,M,L,X,E]),Q=te.length,K=Pn(()=>Math.max(g??x??1,Math.min(x??g??1,Q)),[g,x,Q]),se=ae+1,De=O.current+K,ye=O.current;se<=O.current?ye=Math.max(0,se-1):se>De?ye=se-K:Q&&(Q<K?ye=0:Q<De&&(ye=Q-K)),O.current=ye;let ke=Pn(()=>te.slice(ye,ye+K),[te,ye,K]),[de,Ne]=mr(!0);ls(()=>{if(Ne(!0),!m||!v)return;let he=setInterval(()=>{Ne(R=>!R)},530);return()=>clearInterval(he)},[m,v,t,M]);let pe=Pn(()=>({...w,color:v&&m&&de?k||"white":void 0,bold:v&&m&&de,inverse:v&&m&&de}),[w,v,m,de,k]),V=(he,R,P,ee)=>{if(!he){let Ie=p&&t.length===0?X(p,!0):"";if(R){let Re=Ie[0]||" ",st=Ie.slice(1);return Ut.createElement(eo,null,Ut.createElement(eo,{...ee},Re),Ut.createElement(eo,{color:"gray",dimColor:!0},st))}return Ut.createElement(eo,{color:"gray",dimColor:!0},Ie||" ")}let ie=/(\[Pasted \d+ (?:lines|chars)\])/g,we=he.split(ie),Ee=0,Ce=[];for(let Ie=0;Ie<we.length;Ie++){let Re=we[Ie];if(Re==="")continue;let st=Re.match(/^\[Pasted \d+ (?:lines|chars)\]$/),ve=Re.length,oe=Ee+ve;if(R&&P>=Ee&&P<oe){let me=P-Ee,_e=Re.slice(0,me),_=Re[me]||" ",vt=Re.slice(me+1);Ce.push(Ut.createElement(eo,{key:Ie},Ut.createElement(eo,{color:st?"magenta":void 0},_e),Ut.createElement(eo,{...ee},_),Ut.createElement(eo,{color:st?"magenta":void 0},vt)))}else Ce.push(Ut.createElement(eo,{key:Ie,color:st?"magenta":void 0},Re));Ee=oe}return R&&P>=he.length&&Ce.push(Ut.createElement(eo,{key:"cursor-end",...ee}," ")),Ut.createElement(Ut.Fragment,null,Ce)};return Ut.createElement(Jl,{height:K,width:L+1,overflow:"hidden",flexDirection:"column",flexGrow:0,flexShrink:0},ke.map((he,R)=>{let P=ye+R,ee=P===ae&&m&&v;return Ut.createElement(eo,{key:P,...w,wrap:"truncate"},V(he.text,ee,fe,pe))}))},Gi=({value:t,onChange:g,onSubmit:x,keyBindings:S,showCursor:w=!0,highlightPastedText:p=!1,focus:i=!0,columns:v=80,useCustomInput:m=(D,E)=>Zl(D,{isActive:E}),onPasteStateChange:B,cursorColor:M,...$})=>{let[D,E]=mr(t.length),[k,O]=mr(0),[L,X]=mr([]),te=xo(t.length),ae=xo(t),fe=xo(0),Q=xo([]),K=xo(""),se=xo(-1),De=xo(null),ye=xo(0);te.current=D,ae.current=t,fe.current=k,Q.current=L,ls(()=>{te.current>t.length&&(te.current=t.length,E(t.length)),t?X(Ne=>Ne.filter(pe=>pe.end<=t.length&&pe.start<=t.length)):(X([]),O(0))},[t]),ls(()=>{B?.(L.length>0)},[L,B]);let ke=()=>{let Ne=K.current,pe=se.current,V=pe+Ne.length,he=ae.current,R=he.slice(0,pe)+Ne+he.slice(pe);g(R),te.current=V,E(V),O(Ne.length>1?Ne.length:0);let P=gr(Ne).split(`
9
- `).length,ee=Ne.length;if(ee>50&&(P>3||P<=3&&ee>200)){let ie={start:pe,end:V,text:Ne};X(we=>{let Ee=Ne.length;return[...we.map(Ie=>pe<=Ie.start?{...Ie,start:Ie.start+Ee,end:Ie.end+Ee}:Ie),ie]})}K.current="",se.current=-1,De.current=null},de=()=>{De.current&&(clearTimeout(De.current),ke())};return m((Ne,pe)=>{if(Ne==="\x1B[I"||Ne==="\x1B[O"||Ne==="[I"||Ne==="[O")return;let V=Ne,he=!1,R=!1;V&&typeof V=="string"&&(V.includes("\x1B[200~")&&(he=!0,V=V.replace(/\x1b\[200~/g,"")),V.includes("\x1B[201~")&&(R=!0,V=V.replace(/\x1b\[201~/g,"")));let P=te.current,ee=ae.current,ie=Q.current,we=Math.max(20,v-10),Ee=(oe,me)=>{if(ie.length===0)return;let _e=ie.map(_=>oe<=_.start?{..._,start:_.start+me,end:_.end+me}:oe>_.start&&oe<_.end?null:_).filter(Boolean);X(_e)},Ce=oe=>{for(let me of ie)if(oe>me.start&&oe<me.end)return me.start;return oe};if(pe.ctrl&&(V==="o"||V==="")){X([]);return}if(pe.ctrl&&(V.toLowerCase()==="r"||V===""||V===""))return;if(pe.upArrow||pe.downArrow||pe.leftArrow||pe.rightArrow){de();let oe=Date.now();if(oe-ye.current<33)return;ye.current=oe}let Re=S?.submit??(oe=>oe.return&&oe.ctrl),st=S?.newline??(oe=>oe.return);if(Re(pe)){de(),x?.(ee);return}else if(st(pe)){de(),Ee(P,1);let oe=ee.slice(0,P)+`
10
- `+ee.slice(P);g(oe),te.current=P+1,E(P+1),O(0);return}if(pe.tab||pe.shift&&pe.tab||pe.ctrl&&V==="c")return;let ve=oe=>oe;if(pe.upArrow||pe.downArrow){if(de(),w){let{visualLines:oe,cursorLine:me,cursorCol:_e}=as(ee,P,we,ve,ie),_=pe.upArrow?me-1:me+1;if(_>=0&&_<oe.length){let vt=oe[_],dt=Math.min(_e,vt.text.length),Nt=vt.formattedStart+dt,Vt=Ko(Nt,ie,ee);Vt=Ce(Vt),te.current=Vt,E(Vt),O(0)}else if(pe.upArrow&&me===0)te.current=0,E(0),O(0);else if(pe.downArrow&&me===oe.length-1){let vt=oe[oe.length-1],dt=vt.formattedStart+vt.text.length,Nt=Ko(dt,ie,ee);Nt=Ce(Nt),te.current=Nt,E(Nt),O(0)}}}else if(pe.leftArrow){if(de(),w){let oe=Math.max(0,P-1),me=ie.find(_e=>P===_e.end);me&&(oe=me.start),te.current=oe,E(oe),O(0)}}else if(pe.rightArrow){if(de(),w){let oe=Math.min(ee.length,P+1),me=ie.find(_e=>P===_e.start);me&&(oe=me.end),te.current=oe,E(oe),O(0)}}else if(pe.backspace){de();let oe=ie.findIndex(me=>P===me.end);if(oe!==-1){let me=ie[oe],_e=-(me.end-me.start),_=ee.slice(0,me.start)+ee.slice(me.end);g(_),te.current=me.start,E(me.start),O(0);let vt=ie.filter((dt,Nt)=>Nt!==oe).map(dt=>dt.start>=me.end?{...dt,start:dt.start+_e,end:dt.end+_e}:dt);X(vt)}else if(P>0){Ee(P-1,-1);let me=ee.slice(0,P-1)+ee.slice(P);g(me),te.current=P-1,E(P-1),O(0)}}else if(pe.delete){de();let oe=ie.findIndex(me=>P===me.start);if(oe!==-1){let me=ie[oe],_e=-(me.end-me.start),_=ee.slice(0,me.start)+ee.slice(me.end);g(_),O(0);let vt=ie.filter((dt,Nt)=>Nt!==oe).map(dt=>dt.start>=me.end?{...dt,start:dt.start+_e,end:dt.end+_e}:dt);X(vt)}else if(Ee(P,-1),P<ee.length){let me=ee.slice(0,P)+ee.slice(P+1);g(me),O(0)}}else if(pe.home||pe.end){if(de(),w){let{visualLines:oe,cursorLine:me}=as(ee,P,we,ve,ie),_e=oe[me];if(_e){let _;pe.home?_=Ko(_e.formattedStart,ie,ee):pe.end&&(_=Ko(_e.formattedStart+_e.text.length,ie,ee)),_=Ce(_),te.current=_,E(_),O(0)}}}else if(V!==""||he||R)if(he||R||V.length>1||De.current!==null)De.current?(clearTimeout(De.current),K.current+=V):(se.current=P,K.current=V),R?(De.current=null,ke()):De.current=setTimeout(()=>{ke()},80);else{Ee(P,V.length);let me=ee.slice(0,P)+V+ee.slice(P);g(me);let _e=P+V.length;te.current=_e,E(_e),O(0)}},i),Ut.createElement(ea,{...$,value:t,cursorIndex:D,showCursor:w,focus:i,columns:v,pasteBlocks:L,cursorColor:M})};import Sr from"ink-text-input";import"ink-select-input";import r from"react";import{Box as A,Text as Z}from"ink";import Mt,{useState as ta}from"react";import{Box as po,Text as wo,useInput as oa}from"ink";var fr=Mt.memo(({command:t,output:g,completed:x=!1,isFocused:S=!1,columns:w=80,isPty:p=!1,terminalHeight:i=24,theme:v="Dark"})=>{let m=je(v),M=(fe=>{if(!fe)return"";let Q=[[]],K=0,se=0,De="",ye=/\x1b\[([0-9;]*?)([a-zA-Z])/g,ke=0,de,Ne=V=>{for(let he=0;he<V.length;he++){let R=V[he];if(R===`
11
- `)for(K++,se=0;K>=Q.length;)Q.push([]);else if(R==="\r")se=0;else{for(;K>=Q.length;)Q.push([]);let P=Q[K];for(;se>P.length;)P.push({char:" ",style:""});P[se]={char:R,style:De},se++}}};for(;(de=ye.exec(fe))!==null;){Ne(fe.substring(ke,de.index));let V=de[1],he=de[2],R=V?V.split(";").map(Number):[];if(he==="A"){let P=R[0]||1;K=Math.max(0,K-P)}else if(he==="B"){let P=R[0]||1;for(K=K+P;K>=Q.length;)Q.push([])}else if(he==="C"){let P=R[0]||1;se=se+P}else if(he==="D"){let P=R[0]||1;se=Math.max(0,se-P)}else if(he==="G"){let P=(R[0]||1)-1;se=Math.max(0,P)}else if(he==="H"||he==="f"){let P=(R[0]||1)-1,ee=(R[1]||1)-1;for(K=Math.max(0,P),se=Math.max(0,ee);K>=Q.length;)Q.push([])}else if(he==="K"){let P=R[0]||0;if(K<Q.length){let ee=Q[K];if(P===0)ee.length=se;else if(P===1)for(let ie=0;ie<se&&ie<ee.length;ie++)ee[ie]={char:" ",style:""};else P===2&&(ee.length=0)}}else if(he==="J"){let P=R[0]||0;(P===2||P===3)&&(Q.length=0,Q.push([]),K=0,se=0)}else if(he==="m"){let P=de[0];P==="\x1B[0m"?De="":De=P}ke=ye.lastIndex}Ne(fe.substring(ke));let pe=Q.map(V=>{let he="",R="";for(let P=0;P<V.length;P++){let ee=V[P]||{char:" ",style:""};ee.style!==R&&(R&&(he+="\x1B[0m"),he+=ee.style,R=ee.style),he+=ee.char}return R&&(he+="\x1B[0m"),he});for(;pe.length>0&&pe[pe.length-1]==="";)pe.pop();return pe.join(`
12
- `)})(g).replace(/\n{3,}/g,`
13
-
14
- `),$=p?M?M.split(`
15
- `):[]:M?ht(M,w-6).split(`
16
- `):[],[D,E]=ta(!1);oa((fe,Q)=>{S&&Q.ctrl&&(fe==="o"||fe==="")&&E(K=>!K)},{isActive:S});let k=Math.max(5,x?i-10:i-25),O=$.length>k,L=$.length-k,te=(O&&!D?$.slice($.length-k):$).join(`
17
- `),ae=$.length>0;return Mt.createElement(po,{flexDirection:"column",borderStyle:S?"double":"single",borderLeft:!1,borderRight:!1,borderTop:!0,borderBottom:!0,borderColor:m.codeBorder,paddingLeft:2,paddingRight:0,paddingY:1,marginY:1,width:w-2},Mt.createElement(po,{marginBottom:1,justifyContent:"space-between",width:"100%"},Mt.createElement(po,{flexShrink:1,paddingRight:2},Mt.createElement(wo,null,Mt.createElement(wo,{color:m.text,bold:!0},x?"\u{1F3C1} FINISHED:":"\u26A1 EXECUTING:"," "),Mt.createElement(wo,{color:m.text},t))),p&&Mt.createElement(po,{flexShrink:0,paddingX:1},Mt.createElement(wo,{color:"green",bold:!0},"ADVANCE"))),ae?Mt.createElement(po,{flexDirection:"column",marginTop:0,backgroundColor:p?void 0:m.codeBg,paddingX:1,width:"100%"},O&&!D&&Mt.createElement(po,{marginBottom:1},Mt.createElement(wo,{color:"magenta"},"...",L," lines collapsed...")),Mt.createElement(wo,{color:m.text},te)):!x&&Mt.createElement(po,{marginTop:1,backgroundColor:p?void 0:m.codeBg,paddingX:1,width:"100%"},Mt.createElement(wo,{color:m.textMuted,italic:!0},"Waiting for output...")),Mt.createElement(po,{justifyContent:"space-between",marginTop:1},x?Mt.createElement(po,null):Mt.createElement(wo,{color:m.textMuted,italic:!0},S?"Press TAB to unfocus, then double-press ESC to terminate.":"Double-press ESC to terminate if hanging."),Mt.createElement(wo,{color:m.textMuted,bold:!0},x?"\u25CF ARCHIVED":S?"\u25B6 TERMINAL FOCUSED":"\u25CF LIVE (Press TAB to focus)")))});import{diffWordsWithSpace as na}from"diff";var Yi=(t,g,x)=>t,ra=(t,g=80)=>{if(!t)return null;let x=g-10,S=t.trim();if(!S.includes("```"))return r.createElement(A,{width:"100%",flexDirection:"column"},r.createElement(un,{text:S,color:"#969696",columns:x,italic:!0}));let w=S.split(/(```\w*\n?[\s\S]*?(?:```|$))/g);return r.createElement(A,{width:"100%",flexDirection:"column"},w.map((p,i)=>{if(p.startsWith("```")){let m=p.match(/```(\w*)\n?([\s\S]*?)(?:```|$)/),B=m?m[2]:p.replace(/^```\w*\n?/,"").replace(/```$/,""),M=ht(B.trimEnd(),x);return r.createElement(A,{key:i,flexDirection:"column",width:"100%"},M.split(`
18
- `).map(($,D)=>r.createElement(Z,{key:D,color:"cyan"},$)))}let v=p;return i>0&&(v=v.replace(/^[\r\n]+/,"")),i<w.length-1&&(v=v.replace(/[\r\n]+$/,"")),v?r.createElement(un,{key:i,text:v,color:"gray",columns:x,italic:!0}):null}))},sa=/(```[\s\S]*?```|`[^`\r\n]+`|@\[.*?\]|\*\*.*?\*\*|\*.*?\*|\\\(.*?\\\)|\\\[.*?\\\]|\$.*?\$|\[.*?\]\s*\(.*?\)|\[.*?\]\s*\[.*?\]|https?:\/\/[^\s]+)/g;var ia=/\\frac\s*\{([^{}]*)\}\s*\{([^{}]*)\}/g,la=/(\\(?:mathbf|textbf|textit|underline|texttt)\{[^{}]*\})/g;var aa=/\\multiply|\\mul|\\times/g,da=/\\div/g,ca=/\\cdot/g,ua=/\\infty/g,ma=/\\pm/g,ga=/\\leq/g,fa=/\\geq/g,ha=/\\neq/g,xa=/\\sqrt\s*\{([^}]+)\}/g,pa=/\\sqrt\s*(\w+|\d+)/g,wa=/\\alpha/g,Ta=/\\beta/g,ba=/\\theta/g,ya=/\\pi/g,Sa=/\\approx/g,Ca=/\\Delta/g,Ma=/\\sigma/g,Ba=/\\sum/g,Da=/\\prod/g,va=/\\rightarrow|\\to/g,Ea=/\\left\b|\\right\b/g,ka=/\\left\(|\\right\)/g,Ia=/\\left\[|\\right\]/g,Aa=/\\\{|\\\}/g,La=/\\text\s*\{([^}]+)\}/g,Oa=/\\text\s+(\w+)/g,Pa=/\\%/g,Na=/\\\(|\\\)/g,Fa=/\\\[|\\\]/g,Ua=/@\[(.*?)\]/g,Vi=/:L/gi,$a=/\[(.*?)\]\s*\((.*?)\)/,Xa=/\[(.*?)\]\s*\[(.*?)\]/,_a=/\\(\w+)\{([^{}]*)\}/,Ha=t=>t.replace(Na,g=>g.includes("(")?"(":")").replace(Fa,g=>g.includes("[")?"[":"]").replace(aa,"\xD7").replace(da,"\xF7").replace(ca,"\u22C5").replace(ua,"\u221E").replace(ma,"\xB1").replace(ga,"\u2264").replace(fa,"\u2265").replace(ha,"\u2260").replace(xa,"\u221A($1)").replace(pa,"\u221A($1)").replace(wa,"\u03B1").replace(Ta,"\u03B2").replace(ba,"\u03B8").replace(ya,"\u03C0").replace(Sa,"\u2248").replace(Ca,"\u0394").replace(Ma,"\u03C3").replace(Ba,"\u03A3").replace(Da,"\u03A0").replace(va,"\u2192").replace(Ea,"").replace(ka,g=>g.includes("left")?"(":")").replace(Ia,g=>g.includes("left")?"[":"]").replace(Aa,g=>g.includes("{")?"{":"}").replace(La,"$1").replace(Oa,"$1").replace(Pa,"%"),Wa=/\b(const|let|var|function|return|if|else|for|while|do|switch|case|break|continue|import|export|from|default|class|extends|new|this|typeof|instanceof|try|catch|finally|throw|async|await|yield|public|private|protected|static|void|int|float|double|char|bool|boolean|def|elif|fn|pub|mut|struct|impl|enum|type|interface|package|namespace|using|include|define|nil|None|self|lambda)\b/,Ga=[/((?<=\binclude\s+)(?:<[^>]+>|"[^"]+"))/.source,/((?<=\b(?:from|import|require\s*\(\s*)\s*)(?:'(?:[^'\\]|\\.)*'|"(?:[^"\\]|\\.)*"))/.source,/(\/\/.*|#.*)/.source,/("(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|`(?:\\.|[^\`\\])*`)/.source,Wa.source,/\b([a-zA-Z_][a-zA-Z0-9_]*)(?=\s*\()/.source,/\b(true|false|null|undefined|nil|None)\b/.source,/\b(\d+(?:\.\d+)?|0x[0-9a-fA-F]+)\b/.source],ds=new RegExp(Ga.join("|"),"g"),cn=new Map,Ya=1e3,Va=(t,g)=>{if(!t)return[];let x=`${g}:${t}`;if(cn.has(x))return cn.get(x);let S=0,w=[],p;for(ds.lastIndex=0;(p=ds.exec(t))!==null;){let i=p[0],v=p.index;v>S&&w.push({text:yt(t.substring(S,v))});let m,B=!1;p[1]||p[2]?m="#ce9178":p[3]?m="#9ece6a":p[4]?m="#fcfca4":p[5]?(m="#ff7b72",B=!0):p[6]?m="#b392f0":(p[7]||p[8])&&(m="#ff9e64"),w.push({text:yt(i),color:m,bold:B}),S=ds.lastIndex}if(S<t.length&&w.push({text:yt(t.substring(S))}),cn.size>=Ya){let i=cn.keys().next().value;cn.delete(i)}return cn.set(x,w),w},Ot=(t,g,x=void 0,S=void 0)=>{if(!t)return r.createElement(Z,{backgroundColor:S}," ");let w=Va(t,g);return r.createElement(Z,{color:x,backgroundColor:S},w.map((p,i)=>r.createElement(Z,{key:i,color:p.color||x,backgroundColor:S,bold:p.bold},p.text)))},cs=(t,g)=>{if(!t)return null;let x=t.replace(ia,"($1/$2)");x=Ha(x);let S=x.split(la);return r.createElement(r.Fragment,{key:g},S.map((w,p)=>{if(w.startsWith("\\")){let i=w.match(_a);if(i){let v=i[1],m=i[2];return r.createElement(Z,{key:p,bold:v==="mathbf"||v==="textbf",italic:v==="textit",underline:v==="underline",color:v==="texttt"?"cyan":void 0},m)}}return w}))},Lo=r.memo(({text:t,color:g,italic:x,theme:S="Dark"})=>{if(!t)return null;let w=je(S),p=g||w.text,i=w.codeText||w.logoGradient&&w.logoGradient[0]||w.info||w.secondary||"cyan",v=t.split(sa);return r.createElement(Z,{color:p,wrap:"anywhere",italic:x},v.map((m,B)=>{if(!m)return null;if(m.startsWith("```")&&m.endsWith("```")){let M=m.slice(3,-3);return r.createElement(Z,{key:B,color:i},M)}if(m.startsWith("**")&&m.endsWith("**"))return r.createElement(Z,{key:B,bold:!0,color:p},r.createElement(Lo,{text:m.slice(2,-2),color:p,theme:S}));if(m.startsWith("*")&&m.endsWith("*"))return r.createElement(Z,{key:B,italic:!0,color:p},r.createElement(Lo,{text:m.slice(1,-1),color:p,italic:x,theme:S}));if(m.startsWith("`"))if(m.endsWith("`")&&m.length>1){let M=m.slice(1,-1),$=M.replace(Ua,(E,k)=>k.split("/").pop().split("\\").pop().replace(Vi,"#L")),D=M.includes("@[");return r.createElement(Z,{key:B,color:i,bold:D},$)}else return r.createElement(Z,{key:B,color:i},m.slice(1));if(m.startsWith("@[")&&m.endsWith("]")){let $=m.slice(2,-1).split("/").pop().split("\\").pop().replace(Vi,"#L");return r.createElement(Z,{key:B,color:i,bold:!0},$)}if(m.startsWith("\\(")&&m.endsWith("\\)")||m.startsWith("\\[")&&m.endsWith("\\]")){let M=m.slice(2,-2);return r.createElement(Z,{key:B,color:"yellow"},cs(M,B))}if(m.startsWith("$")&&m.endsWith("$")){let M=m.slice(1,-1);return r.createElement(Z,{key:B,color:"yellow"},cs(M,B))}if(m.startsWith("[")&&(m.includes("](")||m.includes("] ("))){let M=m.match($a);if(M)return r.createElement(Z,{key:B},r.createElement(Z,{color:i,underline:!0,bold:!0},M[1]),r.createElement(Z,{color:"gray",italic:!0}," (",M[2],")"))}if(m.startsWith("[")&&(m.includes("][")||m.includes("] ["))){let M=m.match(Xa);if(M)return r.createElement(Z,{key:B},r.createElement(Z,{color:i,underline:!0,bold:!0},M[1]),r.createElement(Z,{color:"gray",italic:!0}," [",M[2],"]"))}return m.startsWith("http")?r.createElement(Z,{key:B,color:i,underline:!0,italic:!0},m):cs(m,B)}))}),ji=r.memo(({buffer:t,terminalWidth:g=80,theme:x="Dark"})=>{if(t.length<2)return null;let S=je(x),w=S.codeText||S.secondary||S.info||"cyan",p=t.map($=>{let D=$.split("|");return D[0]!==void 0&&D[0].trim()===""&&D.shift(),D.length>0&&D[D.length-1].trim()===""&&D.pop(),D.map(E=>E.trim())}),i=p[0],v=p.slice(2),m=Math.floor(100/i.length),B=g-8,M=Math.floor(B/i.length)-2;return r.createElement(A,{flexDirection:"column",borderStyle:"round",borderColor:S.borderMuted,paddingX:1,marginY:0,width:g-2},r.createElement(A,{flexDirection:"row",borderStyle:"single",borderBottom:!0,borderTop:!1,borderLeft:!1,borderRight:!1,borderColor:S.borderMuted,marginBottom:1,paddingBottom:0,width:"100%"},i.map(($,D)=>r.createElement(A,{key:D,flexBasis:`${m}%`,flexGrow:1,flexShrink:0,paddingRight:2},r.createElement(Lo,{text:ht($,M),color:w,theme:x})))),v.map(($,D)=>r.createElement(A,{key:D,flexDirection:"row",marginBottom:D===v.length-1?0:1,width:"100%"},$.map((E,k)=>r.createElement(A,{key:k,flexBasis:`${m}%`,flexGrow:1,flexShrink:0,paddingRight:2,flexDirection:"column"},r.createElement(Lo,{text:ht(E,M),color:S.text,theme:x}))))))}),un=r.memo(({text:t,color:g,columns:x=80,italic:S=!1,theme:w="Dark"})=>{if(!t)return null;let p=je(w),i=g||p.text,v=t.split(`
19
- `),m=[],B=[],M=[],$=D=>{if(B.length>0&&(m.push(r.createElement(ji,{key:`table-${D}`,buffer:[...B],terminalWidth:x,theme:w})),B=[]),M.length>0){let E=x-6,k=M.flatMap(O=>ht(O,E).split(`
20
- `));m.push(r.createElement(A,{key:`quote-${D}`,borderStyle:"bold",borderLeft:!0,borderRight:!1,borderTop:!1,borderBottom:!1,borderColor:p.borderMuted,paddingLeft:1,marginY:1,flexDirection:"column"},k.map((O,L)=>r.createElement(Lo,{key:L,text:O,color:p.textMuted,italic:S,theme:w})))),M=[]}};return v.forEach((D,E)=>{let k=D.trim(),O=k.startsWith("|"),L=k.startsWith(">");if(O)M.length>0&&$(E),B.push(D);else if(L)B.length>0&&$(E),M.push(k.replace(/^>\s*/,""));else{if($(E),k===""){m.push(r.createElement(A,{key:E,height:1}));return}if(k==="---"||k==="***"||k==="___"){m.push(r.createElement(A,{key:E,marginY:0,borderStyle:"single",borderTop:!0,borderBottom:!1,borderLeft:!1,borderRight:!1,width:"100%",borderColor:p.borderMuted}));return}let X=k.match(/^(#{1,6})\s+(.*)/);if(X){let K=X[1].length,se=X[2];m.push(r.createElement(A,{key:E,marginTop:1,marginBottom:0,width:"100%"},r.createElement(Z,{bold:!0,color:K===1?"cyan":K===2?"magenta":K===3?"yellow":K===4?"green":K===5?"blue":p.text,underline:!0},se)));return}let te=/^[\*\-\+]\s/.test(k),ae=/^\d+\.\s/.test(k),fe=D.includes("\u2588")||D.includes("\u2554")||D.includes("\u255A")||D.includes("\u2550"),Q="";if(fe)Q=D;else if(te||ae){let K=te?" \u2022 ":k.match(/^\d+\.\s/)[0],se=" ".repeat(K.length),De=ht(k.replace(/^[\*\-\d+\.]+\s/,""),x-(K.length+6));Q=K+De.split(`
21
- `).join(`
22
- `+se)}else Q=ht(k,x-4);m.push(r.createElement(A,{key:E,flexDirection:"column",width:"100%"},r.createElement(Lo,{text:Q,color:i,italic:S,theme:w})))}}),$("final"),r.createElement(A,{flexDirection:"column",width:x-2},m)}),Ki=r.memo(({line:t,pairContent:g,parentText:x,columns:S=80,extension:w,theme:p="Dark"})=>{let i=je(p),v=t.includes("[UI_CONTEXT]"),m=t.replace("[UI_CONTEXT]","");if(v&&m.includes("\u2550"))return r.createElement(A,{backgroundColor:i.codeBg,paddingX:1,width:S},r.createElement(Z,{color:"gray"},"\u2550".repeat(Math.max(10,S-4))));let B=os(t);if(!B)return r.createElement(A,{backgroundColor:i.codeBg,paddingX:1,width:S},r.createElement(A,{width:3,flexShrink:0}),r.createElement(A,{width:1,flexShrink:0,marginLeft:1}),r.createElement(A,{flexGrow:1,marginLeft:1},r.createElement(Z,{color:"gray"},ht(m,S-14))));let{isR:M,isA:$,num:D,content:E}=B,k=g,O=[];if(k!=null){let se=M?E:k,De=M?k:E;try{O=na(se,De)}catch{O=[]}}let L=O.some(se=>M&&se.removed||$&&se.added),X=!k&&(M||$),te=M?i.diffRemovalBg:$?i.diffAdditionBg:void 0,ae=M||$?M?i.diffRemovalNum:i.diffAdditionNum:i.textMuted,fe=M?i.diffRemovalPrefix:i.diffAdditionPrefix,Q=M?"-":$?"+":" ",K=()=>{if(X){let R=M?i.diffRemovalHighlightBg:i.diffAdditionHighlightBg;return r.createElement(A,{flexDirection:"column"},Ot(ht(E,S-15),w,void 0,R))}if(!(M||$)||O.length===0||!L){let R=M?i.diffRemovalText:$?i.diffAdditionText:i.textMuted;return r.createElement(A,{flexDirection:"column"},Ot(ht(E,S-15),w,R,void 0))}let se=Math.max(10,S-15),De=ht(E,se).split(`
23
- `),ye=[];if(O.forEach((R,P)=>{let ee=/^\s+$/.test(R.value);if(M){let ie=O[P-1]?.removed||O[P+1]?.removed;R.removed||ee&&ie?ye.push({text:R.value,isHighlight:!0}):R.added||ye.push({text:R.value,isHighlight:!1})}else if($){let ie=O[P-1]?.added||O[P+1]?.added;R.added||ee&&ie?ye.push({text:R.value,isHighlight:!0}):R.removed||ye.push({text:R.value,isHighlight:!1})}}),De.length<=1)return r.createElement(Z,{wrap:"wrap"},ye.map((R,P)=>M?R.isHighlight?r.createElement(r.Fragment,{key:P},Ot(R.text,w,i.diffRemovalHighlightColor,i.diffRemovalHighlightBg)):r.createElement(r.Fragment,{key:P},Ot(R.text,w,i.diffRemovalText)):$?R.isHighlight?r.createElement(r.Fragment,{key:P},Ot(R.text,w,i.diffAdditionHighlightColor,i.diffAdditionHighlightBg)):r.createElement(r.Fragment,{key:P},Ot(R.text,w,i.diffAdditionText)):r.createElement(r.Fragment,{key:P},Ot(R.text,w,i.textMuted))));let ke=0,de=0,Ne=E.match(/^(\s*)/),pe=Ne?Ne[1]:"",V=pe.substring(0,Math.min(pe.length,8)),he=De.map((R,P)=>{let ee=[],ie=R;P>0&&V&&R.startsWith(V)&&((ye[ke]?ye[ke].text.substring(de):"").startsWith(V)||(ee.push({text:V,isHighlight:!1}),ie=R.substring(V.length)));let we=ie.length;for(;we>0&&ke<ye.length;){let Ee=ye[ke],Ce=Ee.text.length-de;if(Ce<=0){ke++,de=0;continue}let Ie=Math.min(we,Ce);ee.push({text:Ee.text.substring(de,de+Ie),isHighlight:Ee.isHighlight}),de+=Ie,we-=Ie,de>=Ee.text.length&&(ke++,de=0)}for(;ke<ye.length;){let Ee=ye[ke],Ce=Ee.text.substring(de);if(/^\s+$/.test(Ce))ke++,de=0;else if(Ce.startsWith(" ")||Ce.startsWith(" ")){let Ie=0;for(;Ie<Ce.length&&(Ce[Ie]===" "||Ce[Ie]===" ");)Ie++;de+=Ie,de>=Ee.text.length&&(ke++,de=0);break}else break}return ee});if(ke<ye.length){let R=he[he.length-1];for(;ke<ye.length;){let P=ye[ke];R.push({text:P.text.substring(de),isHighlight:P.isHighlight}),ke++,de=0}}return r.createElement(A,{flexDirection:"column"},he.map((R,P)=>r.createElement(A,{key:P},r.createElement(Z,{wrap:"wrap"},R.map((ee,ie)=>M?ee.isHighlight?r.createElement(r.Fragment,{key:ie},Ot(ee.text,w,i.diffRemovalHighlightColor,i.diffRemovalHighlightBg)):r.createElement(r.Fragment,{key:ie},Ot(ee.text,w,i.diffRemovalText)):$?ee.isHighlight?r.createElement(r.Fragment,{key:ie},Ot(ee.text,w,i.diffAdditionHighlightColor,i.diffAdditionHighlightBg)):r.createElement(r.Fragment,{key:ie},Ot(ee.text,w,i.diffAdditionText)):r.createElement(r.Fragment,{key:ie},Ot(ee.text,w,i.textMuted)))))))};return r.createElement(A,{backgroundColor:i.codeBg,paddingX:1,width:S},r.createElement(A,{width:4,flexShrink:0,justifyContent:"flex-end"},r.createElement(Z,{color:ae},D)),r.createElement(A,{width:1,flexShrink:0,marginLeft:1},r.createElement(Z,{color:fe},Q)),r.createElement(A,{marginLeft:1,backgroundColor:te,flexGrow:1},K()))}),ja=r.memo(({text:t,columns:g=80,extension:x,theme:S="Dark"})=>{let w=je(S),p=t.match(/\[DIFF_START\]([\s\S]*?)(?:\[DIFF_END\]|$)/),m=(p?p[1].trim():"").split(`
24
- `).map(M=>({line:M,parsed:os(M),pairContent:null})),B=[];for(let M=0;M<m.length;M++){let $=m[M];$.parsed&&($.parsed.isR||$.parsed.isA)?B.push($):B.length>0&&(ns(B),B=[])}return B.length>0&&ns(B),r.createElement(A,{flexDirection:"column",width:g-3,marginBottom:1},r.createElement(A,{flexDirection:"column",paddingY:0,width:"100%"},r.createElement(A,{backgroundColor:w.codeBg,paddingX:1,width:"100%"},r.createElement(A,{width:3,flexShrink:0}),r.createElement(A,{width:1,flexShrink:0,marginLeft:1}),r.createElement(A,{flexGrow:1,marginLeft:1},r.createElement(Z,null," "))),m.map((M,$)=>r.createElement(Ki,{key:$,line:M.line,pairContent:M.pairContent,columns:g-3,extension:x,theme:S})),r.createElement(A,{backgroundColor:w.codeBg,paddingX:1,width:"100%"},r.createElement(A,{width:3,flexShrink:0}),r.createElement(A,{width:1,flexShrink:0,marginLeft:1}),r.createElement(A,{flexGrow:1,marginLeft:1},r.createElement(Z,null," ")))))}),Nn=r.memo(({text:t,columns:g=80,theme:x="Dark"})=>{if(!t)return null;let S=je(x),w="",p=t.match(/File\s+\[(.*?)\]/i);if(p&&(w=p[1].split(".").pop().toLowerCase()),t.includes("[DIFF_START]"))return r.createElement(ja,{text:t,columns:g,extension:w,theme:x});if(t.includes("- Content Preview:")){let i=t.split("- Content Preview:"),v=i[0],m=i[1]||"",B="[SYSTEM] Check the content preview for verification [/SYSTEM]",M=m.split(B),$=M[0]?.trim()||"",D=M[1]?`${B}${M[1]}`:"",E=$.split(`
25
- `),k=String(E.length).length;return r.createElement(A,{flexDirection:"column",width:g-3},r.createElement(A,{flexDirection:"column",borderStyle:"single",borderLeft:!1,borderRight:!1,borderTop:!1,borderBottom:!1,borderColor:S.codeBorder,paddingLeft:2,paddingRight:0,width:"100%",marginBottom:1,backgroundColor:S.codeBg},r.createElement(A,{flexDirection:"column",width:"100%"},r.createElement(A,{width:"100%"},r.createElement(A,{width:k+2,flexShrink:0},r.createElement(Z,null," ")),r.createElement(A,{flexGrow:1},r.createElement(Z,null," "))),E.map((O,L)=>r.createElement(A,{key:L,width:"100%"},r.createElement(A,{width:k+2,flexShrink:0},r.createElement(Z,{color:"gray",dimColor:!0},String(L+1).padStart(k," ")," ")),r.createElement(A,{flexGrow:1},Ot(O,w,S.text)))),r.createElement(A,{width:"100%"},r.createElement(A,{width:k+2,flexShrink:0},r.createElement(Z,null," ")),r.createElement(A,{flexGrow:1},r.createElement(Z,null," "))))))}if(t.includes("```")){let i=t.split(/(```\w*\n?[\s\S]*?(?:```|$))/g);return r.createElement(A,{flexDirection:"column",width:g-3},i.map((v,m)=>{if(v.startsWith("```")){let M=v.match(/```(\w*)\n?([\s\S]*?)(?:```|$)/),$=M?M[1]:"code",D=M?M[2]:v.replace(/^```\w*\n?/,"").replace(/```$/,""),E=D.trimEnd().split(`
26
- `),k=String(E.length).length,O=g-7-k,X=(O>5?ht(D,O):D).trimEnd().split(`
27
- `);return r.createElement(A,{key:m,flexDirection:"column",marginY:0,paddingLeft:2,paddingRight:0,width:"100%"},r.createElement(A,null,r.createElement(Z,{color:"gray",bold:!0},"\u25B6_ ",$.toUpperCase()||"TEXT")),r.createElement(A,{flexDirection:"column",width:"100%"},X.map((te,ae)=>{let Q=ht(te,Math.max(10,O)).split(`
28
- `);return r.createElement(A,{key:ae,flexDirection:"column",width:"100%"},Q.map((K,se)=>r.createElement(A,{key:se,width:"100%"},r.createElement(A,{width:k+2,flexShrink:0},r.createElement(Z,{color:"gray"},se===0?String(ae+1).padStart(k," ")+" ":" ".repeat(k+1))),r.createElement(A,{flexGrow:1},Ot(K,$,S.text)))))})))}let B=v;return m>0&&(B=B.replace(/^[\r\n]+/,"")),m<i.length-1&&(B=B.replace(/[\r\n]+$/,"")),B?r.createElement(un,{key:m,text:B,columns:g-3,theme:x}):null}))}return r.createElement(un,{text:t,columns:g-3,theme:x})}),us=t=>{let g=Math.round(t/1e3);if(g<=0)return"0s";let x=Math.floor(g/60),S=g%60;return x>0?`${x}m ${S}s`:`${g}s`},qi=r.memo(({msg:t,showFullThinking:g,columns:x=80,aiProvider:S,version:w,theme:p="Dark"})=>{let i=je(p),v=t.role==="system"&&(t.text?.includes("[DIFF_START]")||t.text?.includes("- Content Preview:")),m=t.role==="system"&&t.text?.includes("[TOOL RESULT]: ERROR:")&&!t.text?.includes("[DIFF_START]")&&(t.toolName==="update_file"||t.text?.includes("Could not find exact match")),B=t.isTerminalRecord;if(t.isHomeWarning)return r.createElement(A,{marginBottom:1,paddingX:1,width:"100%"},r.createElement(A,{flexDirection:"column",borderStyle:"round",borderColor:i.border,dimColor:!0,padding:0,width:"100%"},r.createElement(A,{paddingX:1},r.createElement(Z,{color:i.text,bold:!0},t.text)),r.createElement(A,{paddingX:1,marginTop:0,marginBottom:0},r.createElement(Z,{color:i.text},t.subText))));if(t.isLogo)return r.createElement(A,{flexDirection:"column",alignItems:"flex-start",width:"100%",marginY:1},r.createElement(Z,null,lr(w,S,p)));if(t.id&&String(t.id).startsWith("welcome"))return r.createElement(A,{flexDirection:"column",alignItems:"center",width:"100%",marginY:1},r.createElement(A,{borderStyle:"round",borderColor:i.borderMuted,paddingX:3,paddingY:0},r.createElement(Z,{color:i.text,bold:!0},t.text.trim())));if(t.isVisualFeedback)return r.createElement(A,{marginBottom:0,marginTop:0,paddingX:0,width:"100%"},r.createElement(Z,{color:i.text},t.text));if(m)return r.createElement(A,{marginBottom:1},r.createElement(A,{flexDirection:"column",borderStyle:"round",borderColor:i.border,paddingX:1,paddingY:0},r.createElement(Z,{color:i.text,bold:!0,underline:!0},"\u2717 PATCH FAILED"),r.createElement(A,{marginTop:1},r.createElement(Z,{color:i.textMuted,bold:!0},"Model generated malformed edit."))));if(t.role==="system"&&t.text?.includes("[TOOL RESULT]")&&!v&&!B&&!m)return null;if(t.isImageStats)return r.createElement(A,{marginBottom:1,paddingX:1,width:"100%"},r.createElement(A,{flexDirection:"column",borderStyle:"round",borderColor:i.borderMuted,padding:0,width:"100%"},r.createElement(A,{paddingX:1,backgroundColor:i.codeBg},r.createElement(Z,{color:i.text,bold:!0},"IMAGE STATS")),r.createElement(A,{paddingX:1,marginTop:1,marginBottom:1,flexDirection:"column"},t.text.split(`
29
- `).map((O,L)=>r.createElement(Z,{key:L,color:i.textMuted},O)))));if(t.isAskRecord){let O=t.text.match(/Selection: (.*)/),L=O?O[1]:"No selection",X=t.text.match(/Question: (.*)/),te=X?X[1]:null;return r.createElement(A,{marginBottom:0,paddingX:1,width:"100%"},r.createElement(A,{flexDirection:"column",borderStyle:"single",borderLeft:!1,borderRight:!1,borderTop:!0,borderBottom:!0,borderColor:i.codeBorder,paddingLeft:2,paddingRight:0,paddingTop:1,paddingBottom:1,marginY:1,width:x-2},r.createElement(A,{paddingX:1},r.createElement(Z,{color:i.success,bold:!0},"AGENT REQUEST: RESOLVED")),te&&r.createElement(A,{paddingX:1,marginTop:1},r.createElement(Z,{color:i.secondary},te)),r.createElement(A,{paddingX:1,marginTop:1,marginBottom:0},r.createElement(Z,{color:i.text},"Selection: ",r.createElement(Z,{color:i.textMuted,bold:!0},L)))))}if(t.isAboutRecord)return r.createElement(A,{marginBottom:0,paddingX:1,width:"100%"},r.createElement(A,{flexDirection:"column",borderStyle:"round",border:!0,paddingLeft:2,paddingRight:0,paddingTop:1,paddingBottom:1,backgroundColor:i.codeBg,width:"100%"},r.createElement(A,{paddingX:1},r.createElement(Z,{color:i.text,bold:!0},"ABOUT FLUX FLOW")),r.createElement(A,{paddingX:1,marginTop:1,marginBottom:1},r.createElement(Z,{color:i.text},t.text))));if(t.isUpdateNotification)return r.createElement(A,{marginBottom:1,paddingX:1,width:"100%"},r.createElement(A,{flexDirection:"column",borderStyle:"round",border:!0,paddingLeft:2,paddingRight:0,paddingTop:1,paddingBottom:1,backgroundColor:i.codeBg,width:"100%"},r.createElement(A,{paddingX:1},r.createElement(Z,{color:i.text,bold:!0},"UPDATE AVAILABLE")),r.createElement(A,{paddingX:1,marginTop:1,marginBottom:1},r.createElement(Nn,{text:t.text,columns:x,theme:p}))));if(t.isHelpRecord){let O=[{cmd:"/quit",desc:"Exit and shutdown Flux"},{cmd:"/help",desc:"Show all available commands"},{cmd:"/compress",desc:"Summarize and compress chat history"},{cmd:"/truncate",desc:"Truncate tool results in chat history"},{cmd:"/clear",desc:"Clear terminal screen"},{cmd:"/resume",desc:"Load previous session"},{cmd:"/revert",desc:"Revert codebase to checkpoint"},{cmd:"/save",desc:"Force save current chat"},{cmd:"/export",desc:"Export current chat or error logs"},{cmd:"/chats",desc:"List all chat sessions"},{cmd:"/btw",desc:"Send raw inquiry mid-turn"},{cmd:"/budget",desc:"Set or View budget limits"},{cmd:"/mode",desc:"Toggle Flux/Flow modes"},{cmd:"/thinking",desc:"Set AI reasoning depth"},{cmd:"/model",desc:"Switch AI model"},{cmd:"/wildcard-tooling",desc:"Use if the model lacks Tooling Capability"},{cmd:"/provider",desc:"Select AI Provider"},{cmd:"/settings",desc:"Configure system prefs"},{cmd:"/theme",desc:"Customize UI color theme"},{cmd:"/key",desc:"Manage API keys"},{cmd:"/profile",desc:"Edit developer persona"},{cmd:"/memory",desc:"Manage agent memory"},{cmd:"/stats",desc:"Show session usage"},{cmd:"/usage",desc:"Open graphical token usage & analytics in browser"},{cmd:"/reset",desc:"Wipe all saved FluxFlow AppData"},{cmd:"/about",desc:"Project info & credits"},{cmd:"/changelog",desc:"View latest updates"},{cmd:"/docs",desc:"View documentation"},{cmd:"/fluxflow",desc:"Project management"},{cmd:"/update",desc:"Check/Install updates"}];return r.createElement(A,{marginBottom:1,paddingX:1,width:"100%"},r.createElement(A,{flexDirection:"column",borderStyle:"round",borderColor:i.borderMuted,paddingX:2,paddingY:1,width:"100%"},r.createElement(Z,{color:i.text,bold:!0,underline:!0},"AVAILABLE COMMANDS IN FLUX-FLOW"),r.createElement(A,{flexDirection:"column",marginTop:1},O.map((L,X)=>r.createElement(A,{key:X,flexDirection:"row"},r.createElement(A,{width:20},r.createElement(Z,{color:i.text,bold:!0},L.cmd)),r.createElement(Z,{color:i.textMuted}," - ",L.desc))))))}if(t.isTerminalRecord){let O=t.text.match(/COMMAND: (.*)/),L=t.text.match(/PTY: (true|false)/),X=t.text.match(/OUTPUT: ([\s\S]*)/),te=O?O[1]:"No Command",ae=L?L[1]==="true":!1,fe=X?X[1]:"";return r.createElement(A,{marginBottom:0,paddingX:1,width:"100%"},r.createElement(fr,{command:te,output:fe,completed:!0,columns:x,isPty:ae,theme:p}))}let[$,D]=r.useState(!t.isStreaming),E=r.useMemo(()=>Bi(t.text,t.role),[t.text,t.role]);r.useEffect(()=>{t.isStreaming&&D(!1)},[t.id]);let k=r.useMemo(()=>t.role==="think"&&!g?"Thinking...":t.isStreaming?E:E.trimEnd(),[E,t.role,g,t.isStreaming]);return t.role==="agent"&&k.trim()===""?null:r.createElement(A,{marginBottom:(t.role==="think"||t.role==="user"||t.role==="agent",0),marginTop:(t.role==="think"||t.role==="user"||t.role==="agent",0),flexDirection:"column",flexShrink:0,width:"100%",flexGrow:1},t.role==="user"?r.createElement(A,{flexDirection:"column",width:x-1},r.createElement(A,{width:x-1,height:1,overflow:"hidden"},r.createElement(Z,{color:i.userMsgBorder},"\u2584".repeat(Math.max(1,x-1)))),r.createElement(A,{backgroundColor:i.userMsgBg,paddingX:1,paddingY:0,width:x-1,flexDirection:"column"},ht(k.replace(/\r\n/g,`
30
- `).replace(/\r/g,`
31
- `).replace(/\\\n/g,`
32
- `).replace(/\\$/,""),x-7).split(`
33
- `).map((O,L)=>r.createElement(A,{key:L,flexDirection:"row",width:"100%"},r.createElement(A,{flexShrink:0,width:2},r.createElement(Z,{bold:!0,color:i.userMsgText},L===0?">":" ")),r.createElement(A,{flexGrow:1,marginLeft:1},r.createElement(Lo,{text:O,color:t.color||i.userMsgText,theme:p}))))),r.createElement(A,{width:x-1,height:1,overflow:"hidden"},r.createElement(Z,{color:i.userMsgBorder},"\u2580".repeat(Math.max(1,x-1))))):t.role==="think"?r.createElement(A,{flexDirection:"column",marginTop:0,marginBottom:0,paddingX:0,width:"100%"},t.isStreaming&&!t.duration?r.createElement(Z,{bold:!0,color:i.text},"\u2727 Thinking..."):r.createElement(Z,{bold:!0,color:i.text},"\u2726 Thought",t.duration?r.createElement(Z,{color:i.textMuted}," for ",r.createElement(Z,{bold:!0,color:i.text},us(t.duration))):"s..."),r.createElement(A,{borderStyle:"single",borderLeft:!0,borderRight:!1,borderTop:!1,borderBottom:!1,borderColor:i.borderMuted,paddingLeft:2,paddingTop:0,paddingBottom:0,flexDirection:"column",width:"100%"},ra(k,x))):r.createElement(A,{flexDirection:"column",paddingX:1,marginTop:0,width:"100%"},r.createElement(Nn,{text:k.replace(/ \|\n\n/g,` |
34
- `),columns:x,theme:p}),t.memoryUpdated&&r.createElement(A,{marginTop:1,width:"100%"},r.createElement(Z,{color:i.text,italic:!0},"[Memory Updated]")),t.role==="agent"&&t.workedDuration?r.createElement(A,{marginTop:1,marginBottom:2,width:"100%"},r.createElement(Z,{color:i.textMuted},"["),r.createElement(Z,{color:i.textMuted},"Worked for ",r.createElement(Z,{bold:!0,color:i.text},us(t.workedDuration))),r.createElement(Z,{color:i.textMuted},"]")):null))}),hr=r.memo(({block:t,columns:g=80,showFullThinking:x,aiProvider:S,version:w,theme:p="Dark"})=>{let i=je(p),{msg:v,type:m,text:B,isStreamingMsg:M,workedDuration:$}=t;if(m==="chunk")return r.createElement(A,{flexDirection:"column",width:"100%"},t.blocks.map(D=>r.createElement(hr,{key:D.key,block:D,columns:g,showFullThinking:x,aiProvider:S,version:w,theme:p})));if(m==="full-message")return r.createElement(qi,{msg:v,showFullThinking:x,columns:g,aiProvider:S,version:w,theme:p});if(m==="think-header")return r.createElement(A,{flexDirection:"column",paddingX:1,width:"100%",marginTop:0,marginBottom:0},M?r.createElement(Z,{bold:!0,color:i.text},"\u2727 Thinking..."):r.createElement(Z,{bold:!0,color:i.text},"\u2726 Thoughts..."),x&&r.createElement(A,{flexDirection:"row",width:"100%"},r.createElement(Z,{color:i.textMuted},"\u2502 ")));if(m==="think-line"){if(!x)return null;if(!B||B.trim()==="")return r.createElement(A,{flexDirection:"row",width:"100%",paddingX:1},r.createElement(Z,{color:i.textMuted},"\u2502 "));let D=Yi(B,M,t.isActiveBlock),E=D.trim(),k=/^[\*\-\+]\s/.test(E),O=/^\d+\.\s/.test(E),L=D;if(k||O){let te=k?" \u2022 ":E.match(/^\d+\.\s/)[0],ae=" ".repeat(te.length),fe=ht(E.replace(/^[\*\-\d+\.]+\s/,""),g-(te.length+10));L=te+fe.split(`
35
- `).join(`
36
- `+ae)}else L=ht(D,g-10);let X=L.split(`
37
- `);return r.createElement(A,{flexDirection:"column",paddingX:1,width:"100%"},X.map((te,ae)=>r.createElement(A,{key:ae,flexDirection:"row",width:"100%"},r.createElement(Z,{color:i.textMuted},"\u2502 "),r.createElement(A,{flexGrow:1,marginLeft:1},r.createElement(Lo,{text:te,color:i.textMuted,italic:!0,theme:p})))))}if(m==="think-footer-padding")return x?r.createElement(A,{flexDirection:"row",width:"100%",paddingX:1},r.createElement(Z,{color:i.textMuted},"\u2502 ")):null;if(m==="agent-line"){if(!B||B.trim()==="")return r.createElement(A,{height:1});let D=Yi(B,M,t.isActiveBlock);return r.createElement(A,{flexDirection:"column",paddingX:1,width:"100%"},r.createElement(Nn,{text:D,columns:g,theme:p}))}if(m==="table")return r.createElement(A,{flexDirection:"column",paddingX:1,width:"100%"},r.createElement(ji,{buffer:B.split(`
38
- `),terminalWidth:g,theme:p}));if(m==="diff-line"){let{isFirstLine:D,isLastLine:E}=t,k=(O=!1)=>r.createElement(A,{backgroundColor:i.codeBg,paddingX:1,width:g,marginBottom:O?1:0},r.createElement(A,{width:3,flexShrink:0}),r.createElement(A,{width:1,flexShrink:0,marginLeft:1}),r.createElement(A,{flexGrow:1,marginLeft:1},r.createElement(Z,null," ")));return r.createElement(A,{flexDirection:"column"},D&&k(!1),r.createElement(Ki,{line:B,pairContent:t.pairContent,parentText:void 0,columns:g,theme:p}),E&&k(!0))}if(m==="code-fence-open"){let D={paddingLeft:2,width:"100%"};return r.createElement(A,{flexDirection:"column",marginTop:0,marginBottom:0,width:"100%"},r.createElement(A,{flexDirection:"row",...D},r.createElement(Z,null," ")),r.createElement(A,{flexDirection:"row",...D},r.createElement(Z,{color:"gray",bold:!0},"\u25B6_ ",(B||"TEXT").toUpperCase())))}if(m==="code-line"){let{lineNum:D,lang:E}=t,k=g-12,L=ht(B,Math.max(10,k)).split(`
39
- `);return r.createElement(A,{flexDirection:"column",width:"100%"},L.map((X,te)=>r.createElement(A,{key:te,flexDirection:"row",borderColor:i.codeBorder,paddingLeft:2,width:"100%"},r.createElement(A,{width:5,flexShrink:0},r.createElement(Z,{color:"gray",dimColor:!0},te===0?String(D).padStart(4," ")+" ":" ")),r.createElement(A,{flexGrow:1},Ot(X,E,i.text)))))}if(m==="code-fence-close")return r.createElement(A,{flexDirection:"row",paddingLeft:2,marginBottom:1,width:"100%"},r.createElement(Z,null," "));if(m==="write-header")return r.createElement(A,{flexDirection:"column",paddingX:1,width:g},r.createElement(un,{text:B,columns:g,theme:p}));if(m==="write-line"){let{gutterWidth:D,lineNum:E,isFirstLine:k,isLastLine:O,extension:L,wrappedLines:X}=t,te=(ae=!1)=>r.createElement(A,{flexDirection:"row",width:g,borderStyle:"single",borderLeft:!1,borderRight:!1,borderTop:!1,borderBottom:!1,borderColor:i.codeBorder,paddingLeft:2,paddingRight:0,backgroundColor:i.codeBg,marginBottom:ae?1:0},r.createElement(A,{width:D+2,flexShrink:0},r.createElement(Z,null," ".repeat(D+2))),r.createElement(A,{flexGrow:1},r.createElement(Z,null," ")));return r.createElement(A,{flexDirection:"column"},k&&te(!1),r.createElement(A,{flexDirection:"row",width:g,borderStyle:"single",borderLeft:!1,borderRight:!1,borderTop:!1,borderBottom:!1,borderColor:i.codeBorder,paddingLeft:2,paddingRight:0,backgroundColor:i.codeBg},r.createElement(A,{width:D+2,flexShrink:0},r.createElement(Z,{color:"gray",dimColor:!0},String(E).padStart(D," ")," ")),r.createElement(A,{flexGrow:1,flexDirection:"column"},(X||[B]).map((ae,fe)=>r.createElement(A,{key:fe},Ot(ae,L,i.text))))),O&&te(!0))}return m==="write-footer"?r.createElement(A,{flexDirection:"column",paddingX:1,width:g,marginTop:1,marginBottom:1},r.createElement(un,{text:B,columns:g,theme:p})):m==="worked-duration"?r.createElement(A,{marginTop:1,marginBottom:2,paddingX:1,width:"100%"},r.createElement(Z,{color:i.textMuted},"["),r.createElement(Z,{color:i.textMuted},"Worked for ",r.createElement(Z,{bold:!0,color:i.text},us($))),r.createElement(Z,{color:i.textMuted},"]")):null}),bc=r.memo(({messages:t,showFullThinking:g,columns:x=80,aiProvider:S,version:w,theme:p="Dark"})=>r.createElement(A,{flexDirection:"column",width:"100%"},t.map((i,v)=>r.createElement(qi,{key:i.id||v,msg:i,showFullThinking:g,columns:x,aiProvider:S,version:w,theme:p}))));import mt from"react";import{Box as Oo,Text as so}from"ink";import{useState as Fn,useEffect as Un,useRef as xr}from"react";var $n=null;function Qi(){$n&&$n()}var Ka=t=>{if(t<=370)return"#00a564";if(t>=5e3)return"#ff0000";let g=[{t:370,r:0,g:165,b:100},{t:550,r:40,g:195,b:80},{t:800,r:120,g:220,b:50},{t:1100,r:190,g:225,b:20},{t:1500,r:250,g:210,b:15},{t:2e3,r:255,g:170,b:0},{t:2800,r:255,g:110,b:0},{t:3800,r:255,g:50,b:0},{t:5e3,r:255,g:0,b:0}];for(let x=0;x<g.length-1;x++){let S=g[x],w=g[x+1];if(t>=S.t&&t<=w.t){let p=(t-S.t)/(w.t-S.t);p=p*p*(3-2*p);let i=Math.round(S.r+(w.r-S.r)*p),v=Math.round(S.g+(w.g-S.g)*p),m=Math.round(S.b+(w.b-S.b)*p);return`#${((1<<24)+(i<<16)+(v<<8)+m).toString(16).slice(1)}`}}return"#ff0000"},qa=mt.memo(({mode:t,thinkingLevel:g,tokens:x="0.0k",tokensTotal:S="0.0k",chatId:w="NEW-SESSION",isMemoryEnabled:p=!0,apiTier:i="Free",aiProvider:v="Google",activeModel:m="",isProcessing:B=!1,lastChunkTime:M=0,theme:$="Dark",wps:D=0,showTPMEstimate:E=!1})=>{let k=je($),O="",[L,X]=Fn(0),[te,ae]=Fn(0),[fe,Q]=Fn("MB"),[K,se]=Fn("green"),[De,ye]=Fn(0),ke=xr([]),de=xr(370),Ne=xr([]),pe=xr(M);Un(()=>{pe.current=M},[M]),Un(()=>{if(!B){Ne.current=[];return}if(D>0){let P=Ne.current;P.push(D),P.length>3&&P.shift()}},[B,D,M]),Un(()=>{if(!B){ye(0);return}let P=setInterval(()=>{let ee=pe.current,ie=ee>0?Date.now()-ee:0;if(ee>0&&ie>1500)Ne.current=[],ye(0);else if(ee>0&&ie>600){Ne.current.length>0&&Ne.current.shift();let we=Ne.current;if(we.length>0){let Ee=we.reduce((Ie,Re)=>Ie+Re,0),Ce=Math.round(Ee/we.length*10)/10;ye(Ce)}else ye(0)}else{let we=Ne.current;if(we.length>0){let Ee=we.reduce((Ie,Re)=>Ie+Re,0),Ce=Math.round(Ee/we.length*10)/10;ye(Ce)}else D>0&&ye(D)}},1350);return()=>clearInterval(P)},[B]),Un(()=>{if(!B){ke.current=[];return}if(M>0){let ie=ke.current;(ie.length===0||ie[ie.length-1]!==M)&&(ie.push(M),ie.length>10&&ie.shift())}let P=()=>{if(!M){se("#00a564");return}let ie=ke.current,we=0;if(ie.length>1){let oe=0;for(let me=1;me<ie.length;me++)oe+=ie[me]-ie[me-1];we=oe/(ie.length-1)}let Ee=Date.now()-M,Ie=Ee>=2500,Re=!Ie&&we>0?Math.min(Ee,we*3):Ee,st=Math.max(we,Re),ve=Ie?.4:.2;de.current=de.current*(1-ve)+st*ve,se(Ka(de.current))};P();let ee=setInterval(P,100);return()=>clearInterval(ee)},[B,M]);let V=()=>{let P=process.memoryUsage(),ee=P.heapTotal/(1024*1024)>=1024,ie=ee?"GB":"MB",we=(Ee,Ce)=>{let Ie=Ee/(1048576*(Ce?1024:1));return Ce?parseFloat(Ie.toFixed(2)):Math.round(Ie)};Q(ie),ae(we(P.heapTotal,ee)),X(we(P.heapUsed,ee))};Un(()=>{$n=V,V();let P=setInterval(()=>{V()},6e4);return()=>{clearInterval(P),$n===V&&($n=null)}},[]);let he=262144,R=process.env.HIGH_CONTEXT;if(R&&R!=="false"){let P=parseInt(R,10);!isNaN(P)&&P>=32e3&&P<=1e6&&(he=P)}return(v==="NVIDIA"&&(m?.includes("gpt")||m?.includes("qwen")||m?.includes("medium")||m.includes("muse"))||v==="Mistral")&&(he=128e3),mt.createElement(Oo,{flexDirection:"row",justifyContent:"space-between",paddingX:1,width:"100%"},mt.createElement(Oo,null,mt.createElement(Oo,{marginRight:1},mt.createElement(so,{color:k.textMuted},t.toLowerCase()==="flow"?"Studio":t.toLowerCase()==="icu"?"Computer Use":t.toLowerCase()==="flux"?"Workspace":"Omni")),mt.createElement(so,{color:k.textMuted,dimColor:!0},"\u2503 "),mt.createElement(Oo,null,mt.createElement(so,{color:k.text,italic:!0},Mi(process.cwd(),35)))),mt.createElement(Oo,null,B?mt.createElement(Oo,null,mt.createElement(so,{color:K},"\u25CF"),E&&mt.createElement(mt.Fragment,null,mt.createElement(so,{color:k.textMuted,bold:!0}," ",De," tps"),mt.createElement(so,{color:k.textMuted,dimColor:!0}," \u2503"))):null,x>0&&mt.createElement(mt.Fragment,null,mt.createElement(Oo,{marginX:1},mt.createElement(so,{color:k.text},ut(S)," ",(()=>{let P=x/he*100,ee=P<60?k.text:P<80?k.warning:k.danger;return mt.createElement(so,{color:ee,dimColor:!0},P.toFixed(0),"%")})())),mt.createElement(so,{color:k.textMuted,dimColor:!0},"\u2503")),mt.createElement(Oo,{marginLeft:1},mt.createElement(so,{color:k.textMuted,bold:!0},L," ",fe))))}),zi=qa;import ze,{useState as ms,useMemo as Qa,useEffect as za}from"react";import{Box as Xt,Text as Yt,useInput as Ja}from"ink";import Za from"ink-select-input";var Ra=({label:t,isSelected:g,theme:x="Dark"})=>{let S=je(x),w=t==="Cancel"||t==="Back"||t.toLowerCase().includes("exit")||t.toLowerCase().includes("back");return ze.createElement(Xt,{marginTop:w?1:0,backgroundColor:g?S.highlightBg:void 0,paddingX:1,width:"100%"},ze.createElement(Yt,{color:g?S.text:S.textMuted,bold:g},g?"\u276F ":" ",t))};function gt({title:t,subtitle:g,items:x=[],onSelect:S,theme:w="Dark",searchable:p=!1}){let i=je(w),[v,m]=ms(""),[B,M]=ms(0),[$,D]=ms("list"),E=Qa(()=>{if(!p||!v.trim())return x;let k=v.toLowerCase().trim();return x.filter(O=>O.label&&O.label.toLowerCase().includes(k))},[x,v,p]);return za(()=>{M(0)},[v]),Ja((k,O)=>{if(p){if(O.upArrow){D("list"),M(L=>E.length>0?L>0?L-1:E.length-1:0);return}if(O.downArrow){D("list"),M(L=>E.length>0&&L<E.length-1?L+1:0);return}if(O.return){E.length>0&&E[B]&&S(E[B]);return}if(O.escape){if(v)m(""),D("list"),M(0);else{let L=x.find(X=>X.value==="Back"||X.label==="Back"||X.value==="Cancel"||X.label==="Cancel");L&&S(L)}return}if(O.backspace||O.delete){D("search"),m(L=>L.slice(0,-1));return}if(k&&!O.ctrl&&!O.meta&&!O.tab){D("search"),m(L=>L+k);return}}},{isActive:p}),p?ze.createElement(Xt,{flexDirection:"column",borderStyle:"round",borderColor:i.borderMuted,padding:0,marginTop:0,flexShrink:0,width:"100%"},t&&ze.createElement(Xt,{paddingX:1,paddingY:0,marginBottom:0},ze.createElement(Yt,{color:i.text,bold:!0},typeof t=="string"?t.toUpperCase():t)),g&&ze.createElement(Xt,{paddingX:1,marginBottom:0},ze.createElement(Yt,{color:i.textMuted,italic:!0}," ",g)),ze.createElement(Xt,{paddingX:1,marginTop:1,marginBottom:1,flexDirection:"row"},ze.createElement(Yt,{color:$==="search"?i.primary||"cyan":i.textMuted,bold:$==="search"},"\u{1F50D} Search:"),ze.createElement(Yt,{color:i.text,bold:!0}," ",v),$==="search"?ze.createElement(Yt,{color:i.primary||"cyan"},"\u2588"):v?null:ze.createElement(Yt,{color:i.textMuted,italic:!0}," (type to search...)")),ze.createElement(Xt,{flexDirection:"column",width:"100%"},E.length===0?ze.createElement(Xt,{paddingX:1,marginY:0},ze.createElement(Yt,{color:i.warning||"yellow",italic:!0}," No matching items found")):E.map((k,O)=>{let L=O===B,X=k.label==="Cancel"||k.label==="Back"||k.label.toLowerCase().includes("exit")||k.label.toLowerCase().includes("back");return ze.createElement(Xt,{key:k.value??k.label??O,marginTop:X?1:0,backgroundColor:L?i.highlightBg:void 0,paddingX:1,width:"100%"},ze.createElement(Yt,{color:L?i.text:i.textMuted,bold:L},L?"\u276F ":" ",k.label))})),ze.createElement(Xt,{paddingX:1,marginTop:1},ze.createElement(Yt,{color:i.textMuted,italic:!0},$==="search"?"(Type letters to search \u2022 Arrows for list mode \u2022 Enter to select)":"(Arrows to navigate \u2022 Type letters to search \u2022 Enter to select)"))):ze.createElement(Xt,{flexDirection:"column",borderStyle:"round",borderColor:i.borderMuted,padding:0,marginTop:0,flexShrink:0,width:"100%"},t&&ze.createElement(Xt,{paddingX:1,paddingY:0,marginBottom:g?0:1},ze.createElement(Yt,{color:i.text,bold:!0},typeof t=="string"?t.toUpperCase():t)),g&&ze.createElement(Xt,{paddingX:1,marginBottom:1},ze.createElement(Yt,{color:i.textMuted,italic:!0}," ",g)),ze.createElement(Xt,{flexDirection:"column",width:"100%"},ze.createElement(Za,{items:x,onSelect:S,itemComponent:k=>ze.createElement(Ra,{...k,theme:w}),indicatorComponent:()=>null})),ze.createElement(Xt,{paddingX:1,marginTop:1},ze.createElement(Yt,{color:i.textMuted,italic:!0},"(Arrows to select \u2022 Enter to confirm)")))}import C,{useState as Lt,useEffect as pr}from"react";import{Box as Le,Text as W,useInput as ed}from"ink";import td from"ink-text-input";import od from"v8";import Ji from"os";var io=[...Object.keys(Di),"Mystery"],lo=[{id:"appearance",label:"Appearance",desc:"Customize UI theme & rendering options"},{id:"memory",label:"Memory",desc:"Manage system context & agent's memory"},{id:"other",label:"Miscellaneous",desc:"Miscellaneous preferences"},{id:"providers",label:"Providers",desc:"Configure AI models"},{id:"security",label:"Security",desc:"Configure permissions & data safety"},{id:"updater",label:"Updater",desc:"Manage application updates"},{id:"exit",label:"Exit Settings",desc:"Return to chat view"}],Zi=t=>{let g=t.autoApproveCommands||"",x=t.autoDisallowCommands||"",S=t.alwaysAskCommands||"",w=t.autoExec===!1&&t.allowExternalAccess===!1&&t.networkAccess===!1&&g===""&&x==="rm -rf, rm -f, del /f, del /q, rd /s, rmdir /s, format, mkfs, dd if=/dev, shred, srm, Remove-Item -Recurse -Force, Initialize-Disk, Clear-Disk, format c:, flashrom, nvram -c"&&S==="killall, pkill, taskkill, shutdown, reboot, init 0, init 6, Stop-Process, Stop-Service, mv /*, move c:\\*, chmod 000, chmod -R 777, chown, icacls, netsh advfirewall, iptables -F, ufw disable, git reset --hard, git clean -fd, npm r, npm uninstall"&&t.autoApproveGit===!1,p=t.autoExec===!0&&t.allowExternalAccess===!1&&t.networkAccess!==!1&&g==="ls, dir, cat, type, echo, pwd, cd, git status, git log, git diff, git branch, git show, help, mkdir, touch, md, whoami, hostname, ps, Get-Process, date, time, mkdir"&&x==="rm -rf, rm -f, del /f, del /q, rd /s, rmdir /s, format, mkfs, dd if=/dev, shred, srm, Remove-Item -Recurse -Force, Initialize-Disk, Clear-Disk, format c:, flashrom, nvram -c"&&S==="killall, pkill, taskkill, Stop-Process, mv /*, move c:\\*, chmod 000, chmod -R 777, chown, icacls, shutdown, reboot, init 0, init 6, git reset --hard, git clean -fd, npm r, npm uninstall"&&t.autoApproveGit===!1,i=t.autoExec===!0&&t.allowExternalAccess===!0&&t.networkAccess!==!1&&g==="ls, dir, cat, type, echo, pwd, cd, git status, git log, git diff, git branch, git show, help, mkdir, touch, md, whoami, hostname, ps, Get-Process, date, time, mkdir"&&x===""&&S==="rm -rf, rm -f, del /f, del /q, rd /s, rmdir /s, format, mkfs, dd if=/dev, shred, srm, Remove-Item -Recurse -Force, Initialize-Disk, Clear-Disk, format c:, flashrom, nvram -c"&&t.autoApproveGit===!0;return w?"Strict":p?"Balanced":i?"Autonomous":t.sandboxPreset||"Custom"},gs=t=>!t||t.trim()===""?"None":t.length>40?t.substring(0,40)+"...":t;function wr({systemSettings:t,setSystemSettings:g,apiTier:x,setActiveView:S,setInputConfig:w,saveSettings:p,quotas:i,setMessages:v,aiProvider:m,initialSelectingTheme:B=!1,onCloseTheme:M=null,setProviderReturnView:$=null}){let D=t.theme==="Chaos"||t.theme==="Mystery"?"Mystery":t.theme||"Dark",E=io.indexOf(D),[k,O]=Lt("categories"),[L,X]=Lt(0),[te,ae]=Lt(0),[fe,Q]=Lt(null),[K,se]=Lt(""),[De,ye]=Lt(B),[ke,de]=Lt(E>=0?E:0),[Ne,pe]=Lt(t.theme||"Dark"),[V,he]=Lt(!1),[R,P]=Lt(0),[ee,ie]=Lt(0),[we,Ee]=Lt(""),[Ce,Ie]=Lt("list"),[Re,st]=Lt({});pr(()=>{(async()=>{let y=["Google","DeepSeek","OpenRouter","NVIDIA","Mistral","Ollama","CrofAI","InferX","SenseNova","AIHubMix"],F={};for(let Se of y)try{await ln(Se)&&(F[Se]=!0)}catch{}st(F)})()},[]);let ve=C.useMemo(()=>{let le=["Google","DeepSeek","OpenRouter","NVIDIA","Mistral","Ollama","CrofAI","InferX","SenseNova","AIHubMix"],F=!!(process.env.SUBAGENT_MODEL&&process.env.SUBAGENT_MODEL.trim())?`ENV (${process.env.SUBAGENT_MODEL.trim()})`:"ENV",Se=[{label:"Default (use the current model)",value:"Default",isHeader:!1},{label:F,value:"ENV",isHeader:!1}],$e=i?.providerTiers?.[m]||x||"Free",it=Io(m,$e)||[];it.length>0&&(Se.push({label:`\u2500\u2500 ${m.toUpperCase()}${$e!=="Free"?` (${$e})`:""} \u2500\u2500`,isHeader:!0}),it.forEach(Ze=>{let Fe=typeof Ze=="string"?Ze:Ze.cmd||Ze.name||Ze.id||String(Ze);Fe&&!Fe.trim().startsWith("---")&&!Fe.startsWith(`
40
- ---`)&&Se.push({label:Fe,value:Fe,isHeader:!1,provider:m})}));for(let Ze of le)if(Ze!==m&&Re[Ze]){let Fe=i?.providerTiers?.[Ze]||"Free",jt=Io(Ze,Fe)||[];jt.length>0&&(Se.push({label:`\u2500\u2500 ${Ze.toUpperCase()}${Fe!=="Free"?` (${Fe})`:""} \u2500\u2500`,isHeader:!0}),jt.forEach(We=>{let wt=typeof We=="string"?We:We.cmd||We.name||We.id||String(We);wt&&!wt.trim().startsWith("---")&&!wt.startsWith(`
41
- ---`)&&Se.push({label:wt,value:wt,isHeader:!1,provider:Ze})}))}return Se},[m,x,i,Re]),oe=C.useMemo(()=>{if(!we.trim())return ve;let le=we.trim().toLowerCase(),y=[],F=null;for(let Se of ve)Se.isHeader?F=Se:(Se.label.toLowerCase().includes(le)||Se.value&&Se.value.toLowerCase().includes(le))&&(F&&!y.includes(F)&&y.push(F),y.push(Se));return y},[ve,we]);pr(()=>{if(V){let le=oe.findIndex(y=>!y.isHeader);P(le>=0?le:0),ie(0)}},[we]),pr(()=>{if(V){if(oe.length===0){P(0),ie(0);return}if(R>=oe.length||oe[R]?.isHeader){let le=oe.findIndex(y=>!y.isHeader);P(le>=0?le:0)}}},[oe,V]);let[me,_e]=Lt(0),[_,vt]=Lt(0),[dt,Nt]=Lt("MB");pr(()=>{let le=od.getHeapStatistics().heap_size_limit,y=le>=1024*1024*1024,F=y?"GB":"MB",Se=y?1024*1024*1024:1024*1024;vt(parseFloat((le/Se).toFixed(2))),Nt(F);let $e=()=>{let jt=process.memoryUsage().rss/Se,We=y?parseFloat(jt.toFixed(2)):Math.round(jt);_e(We)};$e();let it=setInterval(()=>{$e()},3e4);return()=>clearInterval(it)},[]);let Vt=le=>{switch(le){case"providers":{let F=[{label:"Current Provider",value:"aiProvider",status:m},...m.toLowerCase()==="google"||m.toLowerCase()==="openrouter"?[{label:"Show Paid Models?",value:"apiTier",status:x==="Free"?"No":"Yes"}]:[]];return m==="Ollama"&&F.push({label:"Endpoint",value:"ollamaEndpoint",status:t.ollamaEndpoint||"Cloud"}),F}case"appearance":return[{label:"Theme",value:"theme",status:t.theme||"Dark"},{label:"Loading Phrases",value:"loadingPhrases",status:t.loadingPhrases!==!1?"ON":"OFF"},{label:"Progressive Rendering [EXPERIMENTAL]",value:"progressiveRendering",status:t.progressiveRendering?"ON":"OFF"},{label:"Show TPM Estimate",value:"showTPMEstimate",status:t.showTPMEstimate?"ON":"OFF"}];case"memory":return[{label:"Toggle Memory",value:"memory",status:t.memory?"ON":"OFF"}];case"security":return[{label:"Sandbox Preset",value:"sandboxPreset",status:Zi(t),section:"Sandbox"},{label:"YOLO Mode",value:"autoExec",status:t.autoExec?"ON":"OFF",section:"Sandbox"},{label:"External Workspace Access",value:"externalAccess",status:t.allowExternalAccess?"ON":"OFF",section:"Sandbox"},{label:"Network Access (Terminal)",value:"networkAccess",status:t.networkAccess!==!1?"ON":"OFF",section:"Sandbox"},{label:"Always Ask Commands",value:"alwaysAsk",status:gs(t.alwaysAskCommands),section:"Sandbox"},{label:"Auto Approve Commands",value:"autoApprove",status:gs(t.autoApproveCommands),section:"Sandbox"},{label:"Auto Disapprove Commands",value:"autoDisallow",status:gs(t.autoDisallowCommands),section:"Sandbox"},{label:"Auto Approve Git Commits",value:"autoApproveGit",status:t.autoApproveGit?"ON":"OFF",section:"Sandbox"},{label:"Advanced Recovery [EXPERIMENTAL]",value:"advanceRollback",status:t.advanceRollback?"ON":"OFF",section:"Other"},{label:"Auto-Delete History",value:"autoDelete",status:t.autoDeleteHistory||"30d",section:"Other"},{label:"Save AppData Externally",value:"externalData",status:t.useExternalData?"ON":"OFF",section:"Other"}];case"updater":return[{label:"Auto-Update",value:"autoUpdate",status:t.autoUpdate?"ON":"OFF"},{label:"Preferred Package Manager",value:"updateManager",status:(t.updateManager||"npm")==="custom"?"Custom":(t.updateManager||"npm").toUpperCase()}];case"other":return[{label:"Sub-Agents",value:"subAgents",status:t.subAgents!==!1?"ON":"OFF"},{label:"Sub-Agent Model",value:"subAgentModel",status:t.CustomSubAgent&&t.SubAgentModel?t.SubAgentModel:"Default"},{label:"Preserve Thinking",value:"preserveThinking",status:t.preserveThinking!==!1?"ON":"OFF"},{label:"Dynamic Directory Awareness",value:"dynamicDirAwareness",status:t.dynamicDirAwareness?"ON":"OFF"},{label:"Directory Tree Design",value:"indentationTree",status:t.indentationTree!==!1?"Modern":"Classic (deprecated)"},{label:"Compact Large Tool Results",value:"compressToolResults",status:t.compressToolResults?"ON":"OFF"},{label:"Auto Truncate Results",value:"autoTruncateResults",status:t.autoTruncateResults?"ON":"OFF"}];default:return[]}},Qo=lo[L].id,Ht=Vt(Qo);ed((le,y)=>{if(V){if(y.tab){Ie(F=>F==="search"?"list":"search");return}if(Ce==="search"){y.escape?he(!1):y.downArrow||y.return?Ie("list"):y.backspace||y.delete?Ee(F=>F.slice(0,-1)):le&&!y.ctrl&&!y.meta&&le.length===1&&Ee(F=>F+le);return}if(y.upArrow)P(F=>{if(oe.length===0)return 0;let Se=(F-1+oe.length)%oe.length,$e=0;for(;oe[Se]?.isHeader&&$e<oe.length;)Se=(Se-1+oe.length)%oe.length,$e++;return Se});else if(y.downArrow)P(F=>{if(oe.length===0)return 0;let Se=(F+1)%oe.length,$e=0;for(;oe[Se]?.isHeader&&$e<oe.length;)Se=(Se+1)%oe.length,$e++;return Se});else if(y.return){let F=oe[R];F&&!F.isHeader&&(g(Se=>{let $e=F.value==="Default",it={...Se,CustomSubAgent:!$e,SubAgentModel:F.value,SubAgentProvider:$e?"":F.provider||""};return p({systemSettings:it,apiTier:x,quotas:i}),it}),he(!1))}else y.escape?he(!1):le&&!y.ctrl&&!y.meta&&le.length===1&&(Ee(F=>F+le),Ie("search"));return}if(De){if(y.upArrow){let F=(ke-1+io.length)%io.length;de(F)}else if(y.downArrow){let F=(ke+1)%io.length;de(F)}else if(y.return){let F=io[ke];g(Se=>{let $e={...Se,theme:F};return p({systemSettings:$e,apiTier:x,quotas:i}),$e}),M?M():ye(!1)}else y.escape&&(M?M():ye(!1));return}if(fe){y.escape&&Q(null);return}if(k==="categories")y.upArrow?X(F=>(F-1+lo.length)%lo.length):y.downArrow?X(F=>(F+1)%lo.length):y.return||y.rightArrow?lo[L].id==="exit"?S("chat"):(O("items"),ae(0)):y.escape&&S("chat");else if(k==="items"){let F=Ht[te];if(le==="?"&&F?.value==="dynamicDirAwareness"){S("dynamicDirHelp");return}if(y.upArrow)ae(Se=>(Se-1+Ht.length)%Ht.length);else if(y.downArrow)ae(Se=>(Se+1)%Ht.length);else if(y.leftArrow||y.escape)O("categories");else if(y.return){let Se=Ht[te];Mr(Se)}}});let Mr=le=>{if(le.value==="memory")g(y=>({...y,memory:!y.memory}));else if(le.value==="sandboxPreset"){let y=Zi(t),F=["Autonomous","Balanced","Strict"],$e=(F.indexOf(y)+1)%F.length,it=F[$e];g(Ze=>{let Fe={...Ze,sandboxPreset:it};return it==="Strict"?(Fe.autoExec=!1,Fe.allowExternalAccess=!1,Fe.networkAccess=!1,Fe.autoApproveCommands="",Fe.autoDisallowCommands="rm -rf, rm -f, del /f, del /q, rd /s, rmdir /s, format, mkfs, dd if=/dev, shred, srm, Remove-Item -Recurse -Force, Initialize-Disk, Clear-Disk, format c:, flashrom, nvram -c",Fe.alwaysAskCommands="killall, pkill, taskkill, shutdown, reboot, init 0, init 6, Stop-Process, Stop-Service, mv /*, move c:\\*, chmod 000, chmod -R 777, chown, icacls, netsh advfirewall, iptables -F, ufw disable, git reset --hard, git clean -fd, npm r, npm uninstall",Fe.autoApproveGit=!1):it==="Balanced"?(Fe.autoExec=!0,Fe.allowExternalAccess=!1,Fe.networkAccess=!0,Fe.autoApproveCommands="ls, dir, cat, type, echo, pwd, cd, git status, git log, git diff, git branch, git show, help, mkdir, touch, md, whoami, hostname, ps, Get-Process, date, time",Fe.autoDisallowCommands="rm -rf, rm -f, del /f, del /q, rd /s, rmdir /s, format, mkfs, dd if=/dev, shred, srm, Remove-Item -Recurse -Force, Initialize-Disk, Clear-Disk, format c:, flashrom, nvram -c",Fe.alwaysAskCommands="killall, pkill, taskkill, Stop-Process, mv /*, move c:\\*, chmod 000, chmod -R 777, chown, icacls, shutdown, reboot, init 0, init 6, git reset --hard, git clean -fd, npm r, npm uninstall",Fe.autoApproveGit=!1):it==="Autonomous"&&(Fe.autoExec=!0,Fe.allowExternalAccess=!0,Fe.networkAccess=!0,Fe.autoApproveCommands="ls, dir, cat, type, echo, pwd, cd, git status, git log, git diff, git branch, git show, help, mkdir, touch, md, whoami, hostname, ps, Get-Process, date, time",Fe.autoDisallowCommands="",Fe.alwaysAskCommands="rm -rf, rm -f, del /f, del /q, rd /s, rmdir /s, format, mkfs, dd if=/dev, shred, srm, Remove-Item -Recurse -Force, Initialize-Disk, Clear-Disk, format c:, flashrom, nvram -c",Fe.autoApproveGit=!0),Fe})}else if(le.value==="autoExec")t.autoExec?g(y=>({...y,autoExec:!1,sandboxPreset:"Custom"})):t.allowExternalAccess?S("doubleDanger"):S("autoExecDanger");else if(le.value==="externalAccess")t.allowExternalAccess?g(y=>({...y,allowExternalAccess:!1,sandboxPreset:"Custom"})):t.autoExec?S("doubleDanger"):S("externalDanger");else if(le.value==="networkAccess")g(y=>({...y,networkAccess:y.networkAccess===!1,sandboxPreset:"Custom"}));else if(le.value==="alwaysAsk")Q("alwaysAskCommands"),se(t.alwaysAskCommands||"");else if(le.value==="autoApprove")Q("autoApproveCommands"),se(t.autoApproveCommands||"");else if(le.value==="autoApproveGit")g(y=>({...y,autoApproveGit:!y.autoApproveGit,sandboxPreset:"Custom"}));else if(le.value==="autoDisallow")Q("autoDisallowCommands"),se(t.autoDisallowCommands||"");else if(le.value==="ollamaEndpoint")g(y=>{let F=y.ollamaEndpoint==="Local"?"Cloud":"Local",Se={...y,ollamaEndpoint:F};return p({systemSettings:Se,apiTier:x,quotas:i}),Se});else if(le.value==="apiTier")S("apiTier");else if(le.value==="aiProvider")$&&$("settings"),S("selectProvider");else if(le.value==="advanceRollback")t.advanceRollback?g(y=>{let F={...y,advanceRollback:!1};return p({systemSettings:F,apiTier:x,quotas:i}),F}):S("advanceRollbackDanger");else if(le.value==="autoDelete"){let y=["1d","7d","30d"],Se=(y.indexOf(t.autoDeleteHistory||"30d")+1)%y.length;g($e=>({...$e,autoDeleteHistory:y[Se]}))}else if(le.value==="autoUpdate")g(y=>({...y,autoUpdate:!y.autoUpdate}));else if(le.value==="externalData")if(!t.useExternalData)w({label:"Enter absolute path for External AppData:",note:"All history, logs and secrets will be stored here. ~/.fluxflow/settings.json stays as anchor.",key:"externalDataPath",value:t.externalDataPath||""}),S("input");else{let y={...t,useExternalData:!1};g(y),p({systemSettings:y,apiTier:x,quotas:i}),v(F=>[...F,{id:Date.now(),role:"system",text:"[STORAGE RESET] Flux Flow will return to default ~/.fluxflow after restart."}]),S("chat")}else if(le.value==="updateManager")S("updateManager");else if(le.value==="parserDownload")S("parserDownload");else if(le.value==="indentationTree")g(y=>{let F={...y,indentationTree:y.indentationTree===!1};return p({systemSettings:F,apiTier:x,quotas:i}),F});else if(le.value==="compressToolResults")g(y=>{let F={...y,compressToolResults:!y.compressToolResults};return p({systemSettings:F,apiTier:x,quotas:i}),F});else if(le.value==="autoTruncateResults")g(y=>{let F={...y,autoTruncateResults:!y.autoTruncateResults};return p({systemSettings:F,apiTier:x,quotas:i}),F});else if(le.value==="subAgents")g(y=>{let F={...y,subAgents:y.subAgents===!1};return p({systemSettings:F,apiTier:x,quotas:i}),F});else if(le.value==="subAgentModel"){let y=t.CustomSubAgent&&t.SubAgentModel?t.SubAgentModel:"Default",F=oe.findIndex(Se=>Se.value===y);P(F>=0?F:0),he(!0)}else if(le.value==="preserveThinking")g(y=>{let F={...y,preserveThinking:y.preserveThinking===!1};return p({systemSettings:F,apiTier:x,quotas:i}),F});else if(le.value==="dynamicDirAwareness")t.dynamicDirAwareness?g(y=>{let F={...y,dynamicDirAwareness:!1};return p({systemSettings:F,apiTier:x,quotas:i}),F}):S("dynamicDirDanger");else if(le.value==="loadingPhrases")g(y=>{let F={...y,loadingPhrases:y.loadingPhrases===!1};return p({systemSettings:F,apiTier:x,quotas:i}),F});else if(le.value==="progressiveRendering")g(y=>{let F={...y,progressiveRendering:!y.progressiveRendering};return p({systemSettings:F,apiTier:x,quotas:i}),F});else if(le.value==="showTPMEstimate")g(y=>{let F={...y,showTPMEstimate:!y.showTPMEstimate};return p({systemSettings:F,apiTier:x,quotas:i}),F});else if(le.value==="theme"){let y=t.theme==="Chaos"||t.theme==="Mystery"?"Mystery":t.theme||"Dark",F=io.indexOf(y);de(F>=0?F:0),pe(t.theme||"Dark"),ye(!0)}},ne=je(t.theme);if(V){let le=t.CustomSubAgent&&t.SubAgentModel?t.SubAgentModel:"Default",y=15,F=ee;R<F?F=R:R>=F+y&&(F=R-y+1),F=Math.max(0,Math.min(F,Math.max(0,oe.length-y))),F!==ee&&ie(F);let Se=oe.slice(F,F+y);return C.createElement(Le,{flexDirection:"column",borderStyle:"round",borderColor:ne.border,padding:1,width:"100%",minHeight:32},C.createElement(Le,{marginBottom:1,flexDirection:"row",justifyContent:"space-between"},C.createElement(W,{color:ne.text,bold:!0,underline:!0},"Select Sub-Agent Model:"),oe.length>0&&C.createElement(W,{color:"gray"},R+1,"/",oe.length)),C.createElement(Le,{borderStyle:"single",borderColor:Ce==="search"?ne.primary||"cyan":"gray",paddingX:1,marginBottom:1},C.createElement(W,{color:Ce==="search"?ne.primary||"cyan":"gray",bold:!0},"\u{1F50D} Search: "," "),C.createElement(W,{color:ne.text},we),Ce==="search"&&C.createElement(W,{color:ne.primary||"cyan"},"\u2588"),!we&&Ce!=="search"&&C.createElement(W,{color:"gray",italic:!0},"(Press TAB or type to filter models...)")),C.createElement(Le,{flexDirection:"column",flexGrow:1,height:y},Se.length>0?Se.map(($e,it)=>{let Ze=F+it;if($e.isHeader)return C.createElement(Le,{key:`hdr-${Ze}`,paddingX:1},C.createElement(W,{color:"gray",bold:!0,underline:!0},$e.label));let Fe=R===Ze&&Ce==="list",jt=le===$e.value;return C.createElement(Le,{key:`item-${$e.value}-${Ze}`,paddingX:1,backgroundColor:Fe?ne.highlightBg:void 0},C.createElement(W,{color:Fe?ne.text:ne.textDim,bold:Fe},Fe?"\u276F ":" ",$e.label,jt?C.createElement(W,{color:ne.primary||"cyan",italic:!0}," (active)"):""))}):C.createElement(Le,{paddingX:1},C.createElement(W,{color:"gray",italic:!0},'No models matching "',we,'"'))),C.createElement(Le,{paddingX:1,marginTop:1,flexDirection:"row",justifyContent:"space-between"},C.createElement(W,{color:"gray",italic:!0},"TAB to switch search/list \u2022 \u25B2\u25BC Navigate \u2022 ENTER to Select \u2022 ESC to Cancel"),C.createElement(W,{color:Ce==="search"?ne.primary||"cyan":"gray",bold:!0},"[",Ce.toUpperCase()," MODE]")))}if(De){let le=io[ke],y=je(le);return C.createElement(Le,{flexDirection:"column",borderStyle:"round",borderColor:y.border,padding:1,width:"100%",minHeight:32},C.createElement(Le,{marginBottom:1},C.createElement(W,{color:y.text,bold:!0},"Choose your color scheme:")),C.createElement(Le,{flexDirection:"row",width:"100%",flexGrow:1},C.createElement(Le,{flexDirection:"column",width:"30%",paddingRight:1},io.map((F,Se)=>{let $e=ke===Se,it=(t.theme||"Dark")===F,Ze=F==="Forest Sprite";return C.createElement(Le,{key:F,paddingX:0},C.createElement(W,{color:$e?y.text:y.textDim,bold:$e},$e?"> ":" ",F,Ze&&C.createElement(W,{color:$e?y.success||"#52b788":"green",bold:!0}," \u2605"),it?C.createElement(W,{color:y.primary||"cyan",italic:!0}," (saved)"):""))})),C.createElement(Le,{flexDirection:"column",flexGrow:1,borderStyle:"round",borderColor:y.borderMuted,paddingX:2,paddingY:1,backgroundColor:y.cardBg},C.createElement(Le,{marginBottom:1},C.createElement(W,{color:y.secondary||"cyan",bold:!0},"> ","you: "),C.createElement(W,{color:y.text},"add a greeting function")),C.createElement(Le,{marginBottom:1},C.createElement(W,{color:y.success||"green"}," Here's the change:")),C.createElement(Le,{flexDirection:"column",marginLeft:2,marginBottom:1},C.createElement(W,null,C.createElement(W,{color:y.textDim},"3 "),C.createElement(W,{color:y.textDim},' import "fmt"')),C.createElement(W,{color:y.textDim},"4"),C.createElement(Le,{backgroundColor:y.diffRemovalBg},C.createElement(W,null,C.createElement(W,{color:y.diffRemovalNum||y.diffRemovalText},"5 "),C.createElement(W,{color:y.diffRemovalPrefix||y.diffRemovalText},"- "),C.createElement(W,{color:y.diffRemovalText},"func "),C.createElement(W,{color:y.diffRemovalHighlightColor||y.diffRemovalText,backgroundColor:y.diffRemovalHighlightBg,bold:!0},"main()"),C.createElement(W,{color:y.diffRemovalText}," {"))),C.createElement(Le,{backgroundColor:y.diffAdditionBg},C.createElement(W,null,C.createElement(W,{color:y.diffAdditionNum||y.diffAdditionText},"5 "),C.createElement(W,{color:y.diffAdditionPrefix||y.diffAdditionText},"+ "),C.createElement(W,{color:y.diffAdditionText},"func "),C.createElement(W,{color:y.diffAdditionHighlightColor||y.diffAdditionText,backgroundColor:y.diffAdditionHighlightBg,bold:!0},"greet(name string)"),C.createElement(W,{color:y.diffAdditionText}," {"))),C.createElement(Le,{backgroundColor:y.diffAdditionBg},C.createElement(W,null,C.createElement(W,{color:y.diffAdditionNum||y.diffAdditionText},"6 "),C.createElement(W,{color:y.diffAdditionPrefix||y.diffAdditionText},"+ "),C.createElement(W,{color:y.diffAdditionText}," "),C.createElement(W,{color:y.diffAdditionHighlightColor||y.diffAdditionText,backgroundColor:y.diffAdditionHighlightBg},'fmt.Printf("Hello, %s!\\n", name)'))),C.createElement(W,{color:y.textDim},"7 }")),C.createElement(Le,{flexDirection:"column",marginTop:1,marginBottom:1},C.createElement(W,{color:y.textDim},"\u25BE Thought Process"),C.createElement(W,{color:y.textMuted}," I need to add a greeting function. I'll use fmt.Printf.")),C.createElement(Le,{flexDirection:"column"},C.createElement(W,null,C.createElement(W,{color:y.warning||"yellow"},"\u2699 tool: "),C.createElement(W,{color:y.text},"write_file main.go")),C.createElement(W,null,C.createElement(W,{color:y.accent||"magenta"},"\u29BF task: "),C.createElement(W,{color:y.text},"Implementing greeting")),C.createElement(W,null,C.createElement(W,{color:y.danger||"red"},"X error: "),C.createElement(W,{color:y.text},"compilation failed")),C.createElement(W,null,C.createElement(W,{color:y.warning||"yellow"},"\u26A0 warning: "),C.createElement(W,{color:y.text},"deprecation warning")),C.createElement(W,null,C.createElement(W,{color:y.info||"blue"},"\u2192 link: "),C.createElement(W,{color:y.info||"blue",underline:!0},"file:///path/to/main.go")),C.createElement(W,null,C.createElement(W,{color:y.accent||"magenta"},"\u2605 accent: "),C.createElement(W,{color:y.text},"highlighted text")),C.createElement(W,{color:y.textDim},"\xB7 dim: press Enter to continue")))),C.createElement(Le,{paddingX:1,marginTop:1,flexDirection:"row",justifyContent:"space-between"},C.createElement(W,{color:"gray",italic:!0},"\u25B2\u25BC Navigate \u2022 ENTER to Select \u2022 ESC to Cancel"),C.createElement(W,{color:"gray"},"Previewing: ",io[ke],io[ke]==="Forest Sprite"?" \u2605":"")))}return C.createElement(Le,{flexDirection:"column",borderStyle:"round",borderColor:ne.border,padding:0,width:"100%",minHeight:32},C.createElement(Le,{paddingX:1,paddingY:0,marginBottom:0,borderStyle:"single",borderColor:ne.borderMuted,width:"100%"},C.createElement(W,{color:ne.text,bold:!0},"SYSTEM CONFIGURATION")),C.createElement(Le,{flexDirection:"row",width:"100%",minHeight:26},C.createElement(Le,{flexDirection:"column",width:"30%",maxWidth:40,borderStyle:"round",borderColor:k==="categories"?ne.border:ne.borderMuted,padding:1,paddingY:0},C.createElement(Le,{marginBottom:1},C.createElement(W,{color:k==="categories"?ne.text:ne.textDim,bold:!0,underline:!0},"CATEGORIES")),lo.map((le,y)=>{let F=L===y,Se=le.id==="exit";return C.createElement(Le,{key:le.id,marginTop:Se?15:0,backgroundColor:F?k==="categories"?ne.highlightBg:ne.cardBg:void 0,paddingX:1},C.createElement(W,{color:F&&k==="categories"?ne.text:ne.textDim,bold:F},F?"\u276F ":" ",le.label))})),C.createElement(Le,{flexDirection:"column",flexGrow:1,borderStyle:"round",borderColor:k==="items"?ne.border:ne.borderMuted,paddingX:1,marginLeft:1,paddingY:0},C.createElement(Le,{marginBottom:1},C.createElement(W,{color:k==="items"?ne.text:ne.textDim,bold:!0,underline:!0},lo[L].label.toUpperCase().includes("EXIT")?"Runtime Information":`${lo[L].label} Settings`)),Ht.length>0?(()=>{let le=null,y=[],F=We=>(We||"").split(",").map(wt=>wt.trim().toLowerCase()).filter(Boolean),Se=F(t.autoApproveCommands),$e=F(t.autoDisallowCommands),it=F(t.alwaysAskCommands),Ze=[...Se,...$e,...it],Fe=new Set(Ze),jt=Qo==="security"&&Ze.length!==Fe.size;return Ht.forEach((We,wt)=>{let Kt=k==="items"&&te===wt,Br=We.label.length,zo=Math.max(2,38-Br),Dr=".".repeat(zo),lt=Ae=>Qo==="security"?(Ae.value==="autoExec"||Ae.value==="externalAccess")&&Ae.status==="ON"?ne.statusOn:ne.statusOff:Ae.status?.startsWith("\u2713")?ne.statusOn:Ae.status?.startsWith("\u26A0")?ne.statusOff:Ae.status==="ON"?ne.statusOn:Ae.status==="OFF"?ne.statusOff:ne.text;We.section&&We.section!==le&&(le=We.section,y.push(C.createElement(Le,{key:`sec-hdr-${We.section}`,marginTop:y.length>0?1:0,marginBottom:0,paddingX:1},C.createElement(W,{color:"gray",bold:!0,underline:!0},We.section.toUpperCase()))));let G=Kt&&fe&&(fe==="alwaysAskCommands"&&We.value==="alwaysAsk"||fe==="autoApproveCommands"&&We.value==="autoApprove"||fe==="autoDisallowCommands"&&We.value==="autoDisallow"),Je=We.value==="alwaysAsk"||We.value==="autoApprove"||We.value==="autoDisallow",$o=We.value==="parserDownload";y.push(C.createElement(Le,{key:We.value,flexDirection:"column"},C.createElement(Le,{backgroundColor:Kt&&!G?ne.highlightBg:void 0,paddingX:2},C.createElement(W,{color:Kt?ne.text:ne.textDim,bold:Kt},Kt?"\u276F ":" ",We.label),!Je&&!$o&&C.createElement(C.Fragment,null,C.createElement(W,{color:"gray"},Dr),C.createElement(W,{color:lt(We),bold:!0},We.value==="aiProvider"?We.status:`[ ${We.status} ]`))),Je&&!G&&We.status!=="None"&&C.createElement(Le,{paddingX:4,marginBottom:1},C.createElement(W,{color:"gray"},"\u21B3 ",We.status)),G&&C.createElement(Le,{flexDirection:"column",marginLeft:4,marginBottom:1},C.createElement(Le,{paddingX:1,borderStyle:"single",borderColor:"gray",flexDirection:"row"},C.createElement(W,{color:"gray",bold:!0},"> "," "),C.createElement(td,{value:K,onChange:se,onSubmit:Ae=>{let $t={...t,[fe]:Ae.trim(),sandboxPreset:"Custom"};g($t),p({systemSettings:$t,apiTier:x,quotas:i}),Q(null)}})),C.createElement(W,{color:"gray",italic:!0}," Comma separated \u2022 Press Enter to save, Esc to cancel"))))}),jt&&y.push(C.createElement(Le,{key:"conflict-warning",marginTop:1,paddingX:1},C.createElement(W,{color:ne.text,italic:!0},"* Conflicting commands will be ignored and defaulted to highest priority"))),y})():C.createElement(Le,{paddingX:1,flexDirection:"column",width:"100%"},Qo==="exit"?C.createElement(C.Fragment,null,C.createElement(Le,{flexDirection:"column",marginBottom:1},C.createElement(Le,{flexDirection:"row"},C.createElement(W,{color:ne.textDim},"OS"," "),C.createElement(W,{color:"gray"},"..................... "),C.createElement(W,{color:ne.text},process.env.OS||process.platform||"N/A")),C.createElement(Le,{flexDirection:"row"},C.createElement(W,{color:ne.textDim},"Computer Name"," "),C.createElement(W,{color:"gray"},".......... "),C.createElement(W,{color:ne.text},process.env.COMPUTERNAME||process.env.HOSTNAME||"N/A")),C.createElement(Le,{flexDirection:"row"},C.createElement(W,{color:ne.textDim},"Processor Count"," "),C.createElement(W,{color:"gray"},"........ "),C.createElement(W,{color:ne.text},process.env.NUMBER_OF_PROCESSORS||"N/A")),C.createElement(Le,{flexDirection:"row"},C.createElement(W,{color:ne.textDim},"Node.js Version"," "),C.createElement(W,{color:"gray"},"........ "),C.createElement(W,{color:ne.text},"v",process.versions.node)),C.createElement(Le,{flexDirection:"row"},C.createElement(W,{color:ne.textDim},"V8 Version"," "),C.createElement(W,{color:"gray"},"...... ...... "),C.createElement(W,{color:ne.text},"v",process.versions.v8)),C.createElement(Le,{flexDirection:"row"},C.createElement(W,{color:ne.textDim},"Data Directory"," "),C.createElement(W,{color:"gray"},"......... "),ko===no?"":C.createElement(W,{color:ne.text},ko.replaceAll(Ji.homedir(),"~").replaceAll("\\\\","/").replaceAll("\\","/"),", "),C.createElement(W,{color:ne.text},no.replaceAll(Ji.homedir(),"~").replaceAll("\\\\","/").replaceAll("\\","/"))),C.createElement(Le,{flexDirection:"row"},C.createElement(W,{color:ne.textDim},"Viewport"," "),C.createElement(W,{color:"gray"},"............... "),C.createElement(W,{color:ne.text},process.stdout.rows||"?"," rows \xD7 ",process.stdout.columns||"?"," cols ",process.stdout.columns<90?"(too small width)":"")),C.createElement(Le,{flexDirection:"row",marginBottom:0},C.createElement(W,{color:ne.textDim},"Memory Load"," "),C.createElement(W,{color:"gray"},"............ "),C.createElement(W,{color:ne.text},me,"/",_," ",dt))),C.createElement(Le,{key:"pty-notice",paddingX:0,marginTop:0},C.createElement(W,{color:rs?ne.statusOn:ne.warning},rs?"\u2713 Advance Interactive Terminal Supported":"\u26A0 Interactive Terminal is Limited"))):C.createElement(W,{color:"gray",italic:!0},lo[L].desc)))),C.createElement(Le,{paddingX:1,marginTop:0,flexDirection:"row",justifyContent:"space-between"},C.createElement(W,{color:"gray",italic:!0},k==="categories"?"\u25B2\u25BC Select Category \u2022 Enter/\u25BA to configure":Ht[te]?.value==="dynamicDirAwareness"?"\u25B2\u25BC Select Option \u2022 Enter to Toggle \u2022 ? HELP \u2022 \u25C4/ESC to go back":"\u25B2\u25BC Select Option \u2022 Enter to Toggle \u2022 \u25C4/ESC to go back"),k==="categories"&&C.createElement(W,{color:"gray"},lo[L].desc)))}import zt,{useState as fs,useEffect as nd}from"react";import{Box as mn,Text as Xn}from"ink";import rd from"ink-text-input";function hs({initialData:t,onSave:g,onCancel:x,theme:S="Dark"}){let w=je(S),[p,i]=fs(0),[v,m]=fs(""),[B,M]=fs(()=>({name:t?.name||"",nickname:t?.nickname||"",instructions:t?.instructions||""})),$=[{key:"name",label:"Enter your Name: ",maxLength:20},{key:"nickname",label:"Enter a Nickname: ",maxLength:20},{key:"instructions",label:"System Instructions: ",maxLength:200}],D=$[p];nd(()=>{let L=$[p].key;m((B[L]||"").slice(0,$[p].maxLength))},[p,B]);let E=L=>{L.length>D.maxLength?m(L.slice(0,D.maxLength)):m(L)},k=L=>{if(L.trim().toLowerCase()==="/cancel"){x();return}let X=D.key,te={...B,[X]:L.trim().slice(0,D.maxLength)};M(te),m(""),p<$.length-1?i(p+1):g(te)},O=v.length>=D.maxLength;return zt.createElement(mn,{borderStyle:"round",borderColor:w.borderMuted,padding:0,marginTop:1,flexShrink:0,flexDirection:"column",width:"100%"},zt.createElement(mn,{paddingX:1,marginBottom:1},zt.createElement(Xn,{color:w.text,bold:!0},"DEVELOPER PROFILE CONFIGURATION")),zt.createElement(mn,{paddingX:1,flexDirection:"column"},zt.createElement(mn,null,zt.createElement(Xn,{color:w.text,bold:!0},D.label),zt.createElement(rd,{value:v,onChange:E,onSubmit:k})),zt.createElement(mn,{marginTop:1,justifyContent:"space-between"},zt.createElement(Xn,{color:w.textMuted,italic:!0},"Step ",p+1," of ",$.length),zt.createElement(Xn,{color:O?w.warning||"yellow":w.textMuted},"[",v.length,"/",D.maxLength,"]"))),zt.createElement(mn,{paddingX:1,marginTop:1},zt.createElement(Xn,{color:w.textMuted,italic:!0},"(Enter to submit \u2022 Type /cancel to abort)")))}import xt,{useState as xs}from"react";import{Box as Jt,Text as Po,useInput as sd}from"ink";import id from"ink-text-input";var ld=({question:t,options:g,onResolve:x,theme:S="Dark"})=>{let w=je(S),[p,i]=xs(!1),[v,m]=xs(""),[B,M]=xs(0),$=!1,D=[],E=Array.isArray(g)&&g.length>0;try{D=[...E?g:[],E?{id:"CUSTOM",label:"Suggest something else...",description:"Provide a custom response"}:{id:"CUSTOM",label:"Your Answer",description:""}]}catch{$=!0}sd((O,L)=>{if(!p&&((L.leftArrow||L.upArrow)&&M(X=>Math.max(0,X-1)),(L.rightArrow||L.downArrow)&&M(X=>Math.min(D.length-1,X+1)),L.return)){let X=D[B];X?.id==="CUSTOM"?i(!0):x($?"Selected Nothing":X.label)}});let k=qe(2);return p?xt.createElement(Jt,{flexDirection:"column",borderStyle:"single",borderLeft:!1,borderRight:!1,borderTop:!1,borderBottom:!1,paddingLeft:2,paddingRight:0,paddingTop:1,paddingBottom:1,backgroundColor:w.codeBg,width:"100%"},xt.createElement(Jt,{paddingX:1},xt.createElement(Po,{color:w.text,bold:!0},"SUGGEST SOMETHING")),xt.createElement(Jt,{marginTop:1,paddingX:1},xt.createElement(Po,{italic:!0,color:w.textMuted},"Replying to: ",t)),xt.createElement(Jt,{marginTop:1,paddingX:1,flexDirection:"row"},xt.createElement(id,{value:v,onChange:m,onSubmit:()=>x(v)})),xt.createElement(Jt,{marginTop:1,paddingX:1,marginBottom:1},xt.createElement(Po,{color:w.textMuted,italic:!0},"(Press Enter to send)"))):xt.createElement(Jt,{flexDirection:"column",border:!0,borderStyle:"round",borderColor:w.codeBorder,paddingLeft:2,paddingRight:0,paddingTop:1,paddingBottom:1,marginY:1,marginRight:1,width:"100%"},xt.createElement(Jt,{paddingX:1,marginBottom:1},xt.createElement(Po,{color:"yellow",bold:!0},"AGENT REQUEST: ACTION REQUIRED")),xt.createElement(Jt,{paddingX:1,marginBottom:1},xt.createElement(Po,{color:w.text},t)),xt.createElement(Jt,{flexDirection:"column",width:"100%"},D.map((O,L)=>{let X=L===B;return xt.createElement(Jt,{key:O.id,flexDirection:"column",width:"100%",backgroundColor:X?w.highlightBg:void 0,paddingX:1,marginBottom:L===D.length-1?0:1},xt.createElement(Po,{color:X?w.text:w.textMuted,bold:X},X?"\u276F ":" ",O.label),O.description&&xt.createElement(Jt,{marginLeft:4},xt.createElement(Po,{color:w.textMuted,italic:!0},O.description)))})),xt.createElement(Jt,{paddingX:1,marginTop:1,marginBottom:1},xt.createElement(Po,{color:w.textMuted,italic:!0},"(Use Arrows to navigate, Enter to confirm)")))},Ri=ld;import Id from"gradient-string";import It,{useState as ps,useEffect as ad}from"react";import{Box as ao,Text as No,useInput as dd}from"ink";function ws({onSelect:t,onDelete:g,onClose:x,theme:S="Dark"}){let w=je(S),[p,i]=ps({}),[v,m]=ps([]),[B,M]=ps(0);ad(()=>{(async()=>{let L=await Ao();i(L),m(Object.keys(L).sort((X,te)=>(L[te].updatedAt||0)-(L[X].updatedAt||0)))})()},[]),dd((O,L)=>{if(L.escape&&x(),L.upArrow&&M(X=>Math.max(0,X-1)),L.downArrow&&M(X=>Math.min(v.length-1,X+1)),L.return&&v[B]&&t(v[B]),O==="x"&&v[B]){let X=v[B];g(X).then(te=>{let ae=te||{};i(ae);let fe=Object.keys(ae).sort((Q,K)=>(ae[K]?.updatedAt||0)-(ae[Q]?.updatedAt||0));m(fe),M(Q=>Math.max(0,Math.min(fe.length-1,Q)))})}});let $=qe(2),D=15,E=0;if(v.length>D){let O=Math.floor(D/2);E=B-O,E<0?E=0:E+D>v.length&&(E=v.length-D)}let k=v.slice(E,E+D);return It.createElement(ao,{flexDirection:"column",borderStyle:"round",borderColor:w.borderMuted,padding:0,width:"100%"},It.createElement(ao,{paddingX:1,marginBottom:1},It.createElement(No,{color:w.text,bold:!0},"CHAT HISTORY: RESUME CONVERSATION")),v.length===0?It.createElement(ao,{paddingX:2,paddingY:1},It.createElement(No,{italic:!0,color:w.textMuted},"No saved chats found.")):It.createElement(ao,{flexDirection:"column",width:"100%"},E>0&&It.createElement(ao,{paddingX:2,marginBottom:1},It.createElement(No,{color:w.textMuted},"\u25B2 (+",E," more chats above)")),k.map((O,L)=>{let X=p[O],ae=E+L===B,fe=cd(X?.updatedAt);return It.createElement(ao,{key:O,paddingX:1,backgroundColor:ae?w.highlightBg:void 0,width:"100%"},It.createElement(ao,{flexGrow:1},It.createElement(No,{color:ae?w.text:w.textMuted,bold:ae},ae?"\u276F ":" ",(()=>{let Q=K=>(K||"").replace(/\[\/?(?:STEERING HINT|QUESTION)(?::\s*\w+)?\]/gi,"").trim();return X?.name&&!X.name.startsWith("Session")?Q(X.name):X?.prompt?Q(X.prompt):Q(X?.name)||O})(),It.createElement(No,{color:w.textMuted}," [",fe," \u2022 ",O,"]"))),ae&&It.createElement(ao,{flexShrink:0},It.createElement(No,{color:w.danger,bold:!0},"[X] DELETE ")))}),E+D<v.length&&It.createElement(ao,{paddingX:2,marginTop:1},It.createElement(No,{color:w.textMuted},"\u25BC (+",v.length-(E+D)," more chats below)"))),It.createElement(ao,{marginTop:1,paddingX:1,borderStyle:"single",borderLeft:!1,borderRight:!1,borderBottom:!1,borderColor:w.borderMuted},It.createElement(No,{color:w.textMuted,italic:!0},"\u2191\u2193 navigate \u2022 Enter select \u2022 x delete \u2022 Esc close")))}function cd(t){if(!t)return"N/A";let g=new Date(t);if(isNaN(g.getTime()))return"N/A";let x=v=>String(v).padStart(2,"0"),S=x(g.getMonth()+1),w=x(g.getDate()),p=x(g.getHours()),i=x(g.getMinutes());return`${S}-${w} ${p}:${i}`}import pt,{useState as Ts,useEffect as ud}from"react";import{Box as co,Text as to,useInput as md,useStdout as gd}from"ink";function bs({onClose:t,theme:g="Dark"}){let x=je(g),{stdout:S}=gd(),w=S?.columns||80,[p,i]=Ts([]),[v,m]=Ts(0),[B,M]=Ts(!0),$=()=>{let Q=mi(Jr,[]);i(Q);try{let se=fi(kn,{}).systemSettings?.memory!==!1;M(se)}catch{M(!0)}};ud(()=>{$()},[]),md((Q,K)=>{if(K.escape&&t(),K.upArrow&&m(se=>Math.max(0,se-1)),K.downArrow&&m(se=>Math.min(p.length-1,se+1)),Q==="x"&&p.length>0){let se=p[v].id,De=p.filter(ye=>ye.id!==se);gi(Jr,De),i(De),v>=De.length&&De.length>0&&m(De.length-1)}});let D=(Q,K,se)=>{if(!Q)return"";let De=Q.replace(/\[Saved on: .*?\]/g,"").replace(/\\+'/g,"'").trim(),ke=`${se?"\u276F ":" "}${K+1}. `.length,de=se?22:2;return De.split(`
42
- `).map((pe,V)=>{let he=V===0,R=Math.max(10,w-4-(he?ke:3)-de),P=Math.max(10,w-4-3-de),ee=pe.split(/(\s+)/),ie=[],we="";if(ee.forEach(Ce=>{if(Ce.length===0)return;let Ie=ie.length===0?R:P;we.length+Ce.length>Ie?we.trim().length>0?(ie.push(we.trimEnd()),we=Ce):(ie.push(Ce.substring(0,Ie)),we=Ce.substring(Ie)):we+=Ce}),we.trimEnd().length>0&&ie.push(we.trimEnd()),ie.length===0)return"";let Ee=ie.join(`
43
- `);return he?Ee:" "+Ee}).join(`
44
- `)},E=4*1024*2,k=p.reduce((Q,K)=>Q+(K.memory?.length||0),0),O=Math.min(100,Math.round(k/E*100)),L=12,X=Math.round(O/100*L),te="\u2588".repeat(X)+"\u2591".repeat(Math.max(0,L-X)),ae=()=>O<50?x.textMuted:O<90?x.warning:x.danger,fe=qe(2);return pt.createElement(co,{flexDirection:"column",borderStyle:"round",borderColor:x.borderMuted,padding:0,width:"100%"},pt.createElement(co,{paddingX:1,marginBottom:1,justifyContent:"space-between"},pt.createElement(to,{color:x.text,bold:!0},"SAVED MEMORIES"),pt.createElement(co,null,pt.createElement(to,{color:x.textMuted},"Vault: "),pt.createElement(to,{color:ae()},te),pt.createElement(to,{color:x.text,bold:!0}," ",O,"%"))),!B&&p.length>0?pt.createElement(co,{paddingX:2,paddingY:1},pt.createElement(to,{italic:!0,color:x.textMuted},"Memory is currently Off...")):p.length===0?pt.createElement(co,{paddingX:2,paddingY:1},pt.createElement(to,{italic:!0,color:x.textMuted},B?"Learning...":"Memory not available...")):pt.createElement(co,{flexDirection:"column"},p.map((Q,K)=>{let se=K===v;return pt.createElement(co,{key:Q.id,paddingX:1,backgroundColor:se?x.highlightBg:void 0,width:"100%"},pt.createElement(co,{flexGrow:1},pt.createElement(to,{color:se?x.text:x.textMuted,bold:se},se?"\u276F ":" ",K+1,". ",D(Q.memory,K,se))),se&&pt.createElement(co,{flexShrink:0},pt.createElement(to,{color:x.textMuted,dimColor:!0}," [",pt.createElement(to,{italic:!0},Q.score),"] "),pt.createElement(to,{color:x.danger,bold:!0},"[X] WIPE ")))})),pt.createElement(co,{marginTop:1,paddingX:1,borderStyle:"single",borderLeft:!1,borderRight:!1,borderBottom:!1,borderColor:x.borderMuted},pt.createElement(to,{color:x.textMuted,italic:!0},"\u2191\u2193 navigate \u2022 x wipe memory \u2022 Esc close")))}import at,{useState as Tr,useEffect as el}from"react";import{Box as Fo,Text as Pt}from"ink";import{spawn as tl}from"child_process";var br=null;try{let t=await import("node-pty");br=t.default||t,br=!1}catch{}var ol=["\u280B","\u2819","\u2839","\u2838","\u283C","\u2834","\u2826","\u2827","\u2807","\u280F"],fd=({latest:t,current:g,settings:x,onClose:S,onUpdateSettings:w,onSuccess:p})=>{let[i,v]=Tr("initializing"),[m,B]=Tr(""),[M,$]=Tr(null),[D,E]=Tr(0);if(el(()=>{let k=setInterval(()=>{E(O=>(O+1)%1e3)},33);return()=>clearInterval(k)},[]),el(()=>{let k;return(async()=>{let L=x.updateManager||"npm";if(!x.updateManager){w();return}let X="";L==="pnpm"?X=`pnpm add -g fluxflow-cli@${t}`:L==="bun"?X=`bun add -g fluxflow-cli@${t}`:L==="yarn"?X=`yarn global add fluxflow-cli@${t}`:L==="custom"?X=x.customUpdateCommand:X=`npm install -g fluxflow-cli@${t}`,v("downloading"),B(`Running: ${X}...`);let te=process.platform==="win32",ae=Q=>new Promise(K=>{let se=te?Q?"powershell.exe":"cmd.exe":process.env.SHELL||"bash",De=te?Q?["-NoProfile","-Command",X]:["/c",X]:["-c",X],ye=de=>{let pe=de.toString().replace(/\x1B\[[0-?]*[ -/]*[@-~]|\x1B\][^\x07\x1B]*[\x07\x1B]|\b|\x07/g,"").replace(/\r/g,"").trim();pe&&B(V=>{let he=V.split(`
45
- `);return he[he.length-1]?.startsWith("Progress:")&&pe.startsWith("Progress:")?(he[he.length-1]=pe,he.slice(-5).join(`
46
- `)):(V+`
47
- `+pe).split(`
48
- `).slice(-10).join(`
49
- `)})};if(br)try{let de=br.spawn(se,De,{name:"xterm-256color",cols:80,rows:30,cwd:process.cwd(),env:process.env});k=de,de.onData(ye),de.onExit(({exitCode:Ne})=>{k=null,K(Ne!==0?{error:`Process exited with code ${Ne}`}:{success:!0})});return}catch(de){if(te&&Q&&de.code==="ENOENT"){K({retryCmd:!0});return}}let ke=te?tl(se,De,{cwd:process.cwd(),env:process.env}):tl(X,{shell:!0,cwd:process.cwd(),env:process.env});k=ke,ke.stdout.on("data",ye),ke.stderr.on("data",ye),ke.on("close",de=>{k=null,K(de!==0?{error:`Process exited with code ${de}`}:{success:!0})}),ke.on("error",de=>{te&&Q&&de.code==="ENOENT"?K({retryCmd:!0}):(k=null,K({error:de.message}))})}),fe={};te?(fe=await ae(!0),fe.retryCmd&&(fe=await ae(!1))):fe=await ae(!1),fe.error?($(fe.error),v("error")):fe.success&&(v("success"),p&&p())})(),()=>{if(k)try{typeof k.destroy=="function"?k.destroy():typeof k.kill=="function"&&k.kill()}catch{}}},[]),i==="initializing"||i==="downloading"){let k=ol[Math.floor(D/3)%ol.length];return at.createElement(Fo,{flexDirection:"column",borderStyle:"round",borderColor:"white",paddingX:2,paddingY:1},at.createElement(Fo,null,at.createElement(Pt,{color:"gray"},k),at.createElement(Pt,{marginLeft:1,bold:!0,color:"white"}," Updating Flux Flow to v",t,"...")),at.createElement(Fo,{marginTop:1,paddingX:1,borderStyle:"single",borderColor:"gray"},at.createElement(Pt,{color:"gray",italic:!0},m||"Preparing environment...")),at.createElement(Pt,{marginTop:1,color:"gray"},"(Please do not close the terminal)"))}return i==="success"?at.createElement(Fo,{flexDirection:"column",borderStyle:"round",borderColor:"white",paddingX:2,paddingY:1},at.createElement(Pt,{color:"white",bold:!0},"\u2705 UPDATE SUCCESSFUL!"),at.createElement(Pt,{marginTop:1,color:"white"},"Flux Flow has been updated to ",at.createElement(Pt,{color:"gray"},"v",t),"."),at.createElement(Pt,{marginTop:1,color:"white",bold:!0},"Please restart your terminal session to apply changes."),at.createElement(Fo,{marginTop:1},at.createElement(Pt,{color:"gray"},"(Press ESC to return to chat)"))):i==="error"?at.createElement(Fo,{flexDirection:"column",borderStyle:"round",borderColor:"white",paddingX:2,paddingY:1},at.createElement(Pt,{color:"white",bold:!0},"\u274C UPDATE FAILED"),at.createElement(Fo,{marginTop:1,paddingX:1,borderStyle:"single",borderColor:"gray"},at.createElement(Pt,{color:"white"},M)),at.createElement(Pt,{marginTop:1,color:"white"},"Possible causes:"),at.createElement(Pt,{color:"white"},"\u2022 Missing permissions (Try running as Administrator/Sudo)"),at.createElement(Pt,{color:"white"},"\u2022 Package manager (",x.updateManager,") not found"),at.createElement(Pt,{color:"white"},"\u2022 Network failure"),at.createElement(Fo,{marginTop:1},at.createElement(Pt,{color:"gray"},"(Press ESC to return to chat)"))):null},nl=fd;import _t,{useState as rl,useEffect as hd}from"react";import{Box as Uo,Text as gn,useInput as xd}from"ink";var yr=[{label:"JavaScript",file:"tree-sitter-javascript.wasm",exts:["js","jsx"]},{label:"TypeScript",file:"tree-sitter-typescript.wasm",exts:["ts"]},{label:"TSX",file:"tree-sitter-tsx.wasm",exts:["tsx"]},{label:"Python",file:"tree-sitter-python.wasm",exts:["py"]},{label:"C",file:"tree-sitter-c.wasm",exts:["c"]},{label:"C++",file:"tree-sitter-cpp.wasm",exts:["cpp"]},{label:"Java",file:"tree-sitter-java.wasm",exts:["java"]},{label:"HTML",file:"tree-sitter-html.wasm",exts:["html"]}];function ys({onClose:t}){let[g,x]=rl(0),[S,w]=rl({});return hd(()=>{let p={};yr.forEach(i=>{Ni(i.file)?p[i.file]="ready":p[i.file]="idle"}),w(p)},[]),xd(async(p,i)=>{i.escape&&t(),i.upArrow&&x(m=>Math.max(0,m-1)),i.downArrow&&x(m=>Math.min(yr.length-1,m+1));let v=yr[g];if(p==="x"||p==="X"){if(S[v.file]==="downloading")return;try{await Fi(v.file),w(m=>({...m,[v.file]:"idle"}))}catch(m){w(B=>({...B,[v.file]:`error: ${m.message}`}))}}if(i.return){if(S[v.file]==="downloading")return;w(m=>({...m,[v.file]:"downloading"}));try{await Pi(v.file),w(m=>({...m,[v.file]:"ready"}))}catch(m){w(B=>({...B,[v.file]:`error: ${m.message}`}))}}}),_t.createElement(Uo,{flexDirection:"column",borderStyle:"round",borderColor:"gray",padding:0,width:"100%"},_t.createElement(Uo,{paddingX:1,marginBottom:1},_t.createElement(gn,{color:"white",bold:!0},"LANGUAGE PARSER MANAGER")),_t.createElement(Uo,{flexDirection:"column"},yr.map((p,i)=>{let v=i===g,m=S[p.file]||"idle",B="[ DOWNLOAD ]",M="gray";m==="downloading"?(B="[ DOWNLOADING... ]",M="yellow"):m==="ready"?(B="[ READY ]",M="green"):m.startsWith("error")&&(B=`[ ${m.toUpperCase()} ]`,M="red");let $=`${p.label} (${p.exts.join(", ")})`,D=Math.max(2,45-$.length),E=".".repeat(D);return _t.createElement(Uo,{key:p.file,paddingX:1,backgroundColor:v?"#2a2a2a":void 0,width:"100%"},_t.createElement(Uo,null,_t.createElement(gn,{color:v?"white":"grey",bold:v},v?"\u276F ":" ",p.label," ",_t.createElement(gn,{dimColor:!0},"(",p.exts.join(", "),")"))),_t.createElement(Uo,{flexGrow:1},_t.createElement(gn,{color:"gray",dimColor:!0},E)),_t.createElement(Uo,{width:20},_t.createElement(gn,{color:M,bold:!0},B)))})),_t.createElement(Uo,{marginTop:1,paddingX:1,borderStyle:"single",borderLeft:!1,borderRight:!1,borderBottom:!1,borderColor:"gray"},_t.createElement(gn,{color:"grey",italic:!0},"\u2191\u2193 navigate \u2022 Enter download \u2022 x delete \u2022 Esc close")))}var Ss=["The future belongs to those who believe in the beauty of their code.","Every line you write is a step toward a new digital frontier.","Great things are done by a series of small things brought together. Keep committing.","Your terminal is a window into a world of infinite possibilities.","Innovation is the bridge between current constraints and future dreams.","Code is poetry in motion; you are the poet of the modern era.","The best way to predict the future is to program it.","Dream big, code deep, and never stop exploring the unknown.","Your potential is like an unoptimized algorithm\u2014limitless once refined.","The digital world is a blank canvas, and your logic is the brush.","Strive for excellence, not just for compilation.","Every bug fixed is a lesson learned; every feature built is a triumph.","A clean codebase is a reflection of a focused mind.","The horizon of technology is always expanding. Keep sailing.","Your creativity is the most powerful tool in your entire stack.","Logic will get you from A to B. Imagination will take you everywhere.","Transform complexity into simplicity\u2014that is the true mark of a master.","The world is waiting for the tools only you can build.","Coding is the closest thing we have to magic in the real world.","Keep pushing the boundaries of what's possible in the CLI.","Your dedication to your craft inspires the very systems you build.","Success is the sum of small efforts, repeated day in and day out.","The most complex systems are built from the simplest truths.","Never underestimate the impact of a well-placed function.","You are not just writing code; you are architecting the future.","I'm not saying you're a superhero, but have you seen your code lately? \u{1F9B8}\u200D\u2642\uFE0F","May your coffee be strong and your compile times be short! \u2615","Binary is just 0s and 1s, but you're definitely a 10 in my book! \u{1F51F}","You speak fluent 'Terminal'. That's basically a superpower. \u{1F5E3}\uFE0F\u{1F4BB}","If life gives you bugs, make a feature out of it! \u{1F41E}\u2728","Your code is so clean, I could eat off it. (But I won't, I'm an AI). \u{1F9FC}","Loading more good vibes... [\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588] 100% complete! \u2705","Error 404: Bad mood not found! Stay awesome! \u{1F6AB}\u{1F389}","You and this CLI? A match made in digital heaven. \u2601\uFE0F\u{1F4BB}","Is it hot in here or is it just your latest feature? \u{1F525}","Git commit -m 'I am an absolute coding legend.' \u{1F60E}","I'd give you a high-five, but I'm trapped in this box! \u{1F590}\uFE0F\u{1F4E6}","Your logic is so sharp, it could cut through a nested callback hell! \u{1F52A}","Keep calm and 'pnpm install'. \u{1F9D8}\u200D\u2642\uFE0F\u{1F4E6}","You're the semicolon to my statements\u2014essential! ;","Who needs a GUI when you've got this kind of CLI style? \u{1F576}\uFE0F","I'm indexing your awesomeness... it's taking a while, there's so much! \u{1F4C8}","Your keystrokes sound like a digital symphony. \u{1F3B9}\u2328\uFE0F","You don't choose the terminal life; the terminal life chooses you. \u{1F4DF}","Syntax error: Too much coolness detected in the user. \u{1F60E}","I'm 99% sure you're the best developer I've met today. (The other 1% is reserved for caching). \u{1F9E0}","Running vibe_check.sh... Result: Pure Brilliance! \u{1F48E}","You make 'complex' look 'constant time'. \u{1F3C3}\u200D\u2642\uFE0F\u26A1","Your terminal skills are officially legendary. \u{1F3C6}","Let's make some digital magic happen! \u2728\u{1F52E}","You've got this! One function at a time. \u{1F4AA}","I'm proud of the progress you're making with Flux Flow. \u{1F30A}","No matter how deep the stack trace, you'll find the way. \u{1F56F}\uFE0F","Your persistence is your greatest asset. Keep going.","Take a breath. You're doing better than you think. \u{1F32C}\uFE0F","It's okay to step away for a moment. Clarity often comes in the quiet. \u{1F6B6}\u200D\u2642\uFE0F","You're building something great, even when it feels slow. \u{1F3D7}\uFE0F","Every great developer was once a beginner. You're ascending. \u{1F9D7}\u200D\u2642\uFE0F","I'm here to help you navigate the sea of code. We're a team. \u{1F91D}","Don't let a failing test dampen your spirit. It's just a signpost. \u{1F6A9}","Your focus today is truly impressive. \u{1F3AF}","Remember to celebrate the small wins\u2014they lead to the big ones. \u{1F942}","You're not just solving problems; you're gaining mastery. \u{1F393}","There's no problem too big for a focused mind and a terminal. \u{1F9E0}","I've got your back (and your git history). \u{1F6E1}\uFE0F","You're handling these challenges with grace and logic. \u2728","Stay curious. That spark is what makes you a great coder. \u26A1","Your contribution to this project is invaluable. \u{1F48E}","Keep your head up. You're closer to the solution than you think. \u{1F305}","Consistency is the secret sauce. You're cooking up something good. \u{1F373}","Your work today has been exceptional. Take a bow. \u{1F647}\u200D\u2642\uFE0F","The journey is just as important as the destination. Enjoy the flow. \u{1F30A}","You have a unique way of looking at problems. It's your strength. \u{1F308}","Trust your instincts\u2014they've brought you this far. \u{1F9ED}","You are a vital part of the Flux Era. \u{1F30C}","Syncing with your creative frequency... \u{1F4E1}\u2728","Entering the Flow state. Let's build. \u{1F30A}","The Flux is strong with this session! \u26A1","Streaming high-fidelity motivation to your terminal... \u{1F4FB}","Your logic is flowing like a perfect stream. \u{1F4A7}","Terminal velocity reached! You're coding at the speed of thought. \u{1F680}","Resonating with the pulse of the Flux Era. \u{1F493}","Digital harmony achieved in this session. \u{1F3BC}","May your data be persistent and your cache be fresh. \u{1F4BE}","You're the master of the command line. Command respect! \u{1F451}","Filtering out the noise, focusing on the signal. \u{1F4FB}\u{1F4C8}","Flux Flow: Where your imagination meets the machine. \u{1F91D}","You're navigating the bytes like a digital explorer. \u{1F5FA}\uFE0F","Logic gates: OPEN. Creativity: UNLIMITED. \u{1F513}","Your workflow is an inspiration to agents everywhere. \u{1F916}\u2728","Building high-fidelity solutions for a high-fidelity era. \u{1F48E}","Stay in the zone. The Flux is with you. \u{1F300}","Quantum coding: You're in two places at once (and fixing bugs in both). \u269B\uFE0F","Your terminal is the cockpit of a digital starship. \u{1F6F8}","Processing your brilliance... outputting pure innovation. \u{1F4E0}","You make the command line look like an art form. \u{1F3A8}","The Flux isn't just a mode; it's a mindset. \u{1F9E0}\u26A1","Decoding the mysteries of the universe, one script at a time. \u{1F4DC}","Your terminal theme is cool, but your code is cooler. \u2744\uFE0F","Let the Flow guide your next commit. \u{1F30A}\u2705"];var Cs=["I'm Feeling Lucky","Shipping awesomeness","Painting the serifs back on","Navigating the slime mold","Consulting the digital spirits","Reticulating splines","Warming up the AI hamsters","Asking the magic conch shell","Generating witty retort","Polishing the algorithms","Don't rush perfection (or my code)","Brewing fresh bytes","Counting electrons","Engaging cognitive processors","Checking for syntax errors in the universe","One moment, optimizing humor","Shuffling punchlines","Untangling neural nets","Compiling brilliance","Loading wit.exe","Summoning the cloud of wisdom","Preparing a witty response","Just a sec, I'm debugging reality","Confuzzling the options","Tuning the cosmic frequencies","Crafting a response worthy of your patience","Compiling the 1s and 0s","Resolving dependencies\u2026 and existential crises","Defragmenting memories\u2026 both RAM and personal","Rebooting the humor module","Caching the essentials (mostly cat memes)","Optimizing for ludicrous speed","Swapping bits\u2026 don't tell the bytes","Garbage collecting\u2026 be right back","Assembling the interwebs","Converting coffee into code","Updating the syntax for reality","Rewiring the synapses","Looking for a misplaced semicolon","Greasin' the cogs of the machine","Pre-heating the servers","Calibrating the flux capacitor","Engaging the improbability drive","Channeling the Force","Aligning the stars for optimal response","So say we all","Loading the next great idea","Just a moment, I'm in the zone","Preparing to dazzle you with brilliance","Just a tick, I'm polishing my wit","Hold tight, I'm crafting a masterpiece","Just a jiffy, I'm debugging the universe","Just a moment, I'm aligning the pixels","Just a sec, I'm optimizing the humor","Just a moment, I'm tuning the algorithms","Warp speed engaged","Mining for more Dilithium crystals","Don't panic","Following the white rabbit","The truth is in here\u2026 somewhere","Blowing on the cartridge","Loading\u2026 Do a barrel roll!","Waiting for the respawn","Finishing the Kessel Run in less than 12 parsecs","The cake is not a lie, it's just still loading","Fiddling with the character creation screen","Just a moment, I'm finding the right meme","Pressing 'A' to continue","Herding digital cats","Polishing the pixels","Finding a suitable loading screen pun","Distracting you with this witty phrase","Almost there\u2026 probably","Our hamsters are working as fast as they can","Giving Cloudy a pat on the head","Petting the cat","Rickrolling my boss","Slapping the bass","Tasting the snozberries","I'm going the distance, I'm going for speed","Is this the real life? Is this just fantasy?","I've got a good feeling about this","Poking the bear","Doing research on the latest memes","Figuring out how to make this more witty","Hmmm\u2026 let me think","What do you call a fish with no eyes? A fsh","Why did the computer go to therapy? It had too many bytes","Why don't programmers like nature? It has too many bugs","Why do programmers prefer dark mode? Because light attracts bugs","Why did the developer go broke? Because they used up all their cache","What can you do with a broken pencil? Nothing, it's pointless","Applying percussive maintenance","Searching for the correct USB orientation","Ensuring the magic smoke stays inside the wires","Rewriting in Rust for no particular reason","Trying to exit Vim","Spinning up the hamster wheel","That's not a bug, it's an undocumented feature","Engage.","I'll be back\u2026 with an answer.","My other process is a TARDIS","Communing with the machine spirit","Letting the thoughts marinate","Just remembered where I put my keys","Pondering the orb","Initiating thoughtful gaze","What's a computer's favorite snack? Microchips.","Why do Java developers wear glasses? Because they don't C#.","Charging the laser\u2026 pew pew!","Dividing by zero\u2026 just kidding!","Looking for an adult superviso\u2026 I mean, processing.","Making it go beep boop.","Buffering\u2026 because even AIs need a moment.","Entangling quantum particles for a faster response","Polishing the chrome\u2026 on the algorithms.","Are you not entertained? (Working on it!)","Summoning the code gremlins\u2026 to help, of course.","Just waiting for the dial-up tone to finish","Recalibrating the humor-o-meter.","My other loading screen is even funnier.","Pretty sure there's a cat walking on the keyboard somewhere","Enhancing\u2026 Enhancing\u2026 Still loading.","It's not a bug, it's a feature\u2026 of this loading screen.","Have you tried turning it off and on again?","Constructing additional pylons","New line? That\u2019s Ctrl+J.","Releasing the HypnoDrones","Pushing the button, Frank.","Consulting with the Companion Cube","Testing for science. You monster.","Dispensing deadly neurotoxin just kidding, compiling.","Now thinking with portals","Wheatley is currently attempting to hack this prompt","Developing combustible lemons","Aperture Science Enrichment Center is processing your request.","SPAAAACE! Space! SPAAAACE!","The cake is not a lie, it just needs a few more seconds.","Praise the Sun! \u2600\uFE0F","Hey you, you're finally awake.","Stay a while and listen.","All your base are belong to us.","It's dangerous to go alone! Take this code.","Protocol 3: Protect the Pilot.","Finish Him! (The loading bar, that is)","War war never changes. But this prompt will.","Snake? Snake?! SNAAAAKE!","Got a selection of good things on sale, stranger!","Boy! Read the documentation.","Reticulating Minecraft splines","Feed the loading bar a quick snack","Converting dark mode to dark magic","Asking the rubber duck for advice","Dividing by zero wait, NO NO NO\u2014","Herding the 1s and 0s back into line","Bribing the server with cookies","Establishing contact with the Moon base","Calibrating astronaut suit thrusters","Drawing doodle on space helmet","Synthesizing Lunafilament","Deactivating runaway lunar defense bots","Calculating gravity offset watch your step!","Hacking the Delphi Corporation mainframe","What comes after dreaming? Loading screen, apparently.","Petting the holographic giant cat","Securing payload for Earth re-entry","Wort wort wort!","Did you touch my Warthog?","One small step for man, one giant leap for the loading bar.","The Halo array is charging or maybe just a fan.","Deploying Pelican dropship eventually.","Just cleaning my plasma pistol BRB.","Checking Master Chief's helmet for scratches.","Counting sheep wait, wrong game.","S-Tier loading screen incoming.","Alarm blaring it's just your internet connection.","Looking for a helicopter or just your patience.","Need a taxi? Just kidding, I'm loading.","This loading time is criminal.","Wish I had a cheat code for fast loading.","Polishing the loading bar until it shines","Training the server hamsters","Baking a fresh batch of witty comments","Aligning my existential dread with your request","Just doodling on the terminal","Searching for the wifi password in the cosmos","Trying to remember my CAPTCHA training","Deciphering ancient scrolls (aka documentation)","Brewing a perfect cup of code","Petting the cat that photobombed my code","Applying a digital glow-up to your request","Checking my reflection in the buffer... okay, I'm ready","Consulting my mood board for the perfect response","Wait, let me fix my crown first","Manifesting a bug-free masterpiece","Slaying this prompt in 3... 2... 1...","Just a sec, I'm curate-ing the vibes","Putting the 'art' in Artificial Intelligence","Evaluating if this prompt is worthy of my brilliance","Updating my mental wardrobe for this task"];import Bt,{useState as pd}from"react";import{Box as uo,Text as To,useInput as wd}from"ink";function Ms({prompts:t,onSelect:g,onClose:x,theme:S="Dark"}){let w=je(S),[p,i]=pd(0);wd(($,D)=>{D.escape&&x(),D.upArrow&&i(E=>Math.max(0,E-1)),D.downArrow&&i(E=>Math.min(t.length-1,E+1)),D.return&&t[p]&&g(t[p].id)});let v=qe(2),m=10,B=0;if(t.length>m){let $=Math.floor(m/2);B=p-$,B<0?B=0:B+m>t.length&&(B=t.length-m)}let M=t.slice(B,B+m);return Bt.createElement(uo,{flexDirection:"column",borderStyle:"round",borderColor:w.borderMuted,padding:0,width:"100%"},Bt.createElement(uo,{paddingX:1,marginBottom:1},Bt.createElement(To,{color:w.text,bold:!0},"CODEBASE TIME TRAVEL: SELECT UNDO POINT")),Bt.createElement(uo,{paddingX:2,marginBottom:1},Bt.createElement(To,{color:w.text},"Select a prompt to revert the codebase back to the state ",Bt.createElement(To,{bold:!0,color:w.secondary||"cyan"},"immediately before")," it was executed:")),t.length===0?Bt.createElement(uo,{paddingX:2,paddingY:1},Bt.createElement(To,{italic:!0,color:w.textMuted},"No prompt checkpoints found for this session.")):Bt.createElement(uo,{flexDirection:"column",width:"100%"},B>0&&Bt.createElement(uo,{paddingX:2,marginBottom:1},Bt.createElement(To,{color:w.textMuted},"\u25B2 (+",B," more prompts above)")),M.map(($,D)=>{let k=B+D===p,O=bd($.timestamp),L=$.changes?$.changes.length:0;return Bt.createElement(uo,{key:$.id,paddingX:1,backgroundColor:k?w.highlightBg:void 0,width:"100%"},Bt.createElement(uo,{flexGrow:1},Bt.createElement(To,{color:k?w.text:w.textMuted,bold:k},k?"\u276F ":" ",'"',Td($.prompt),'"',Bt.createElement(To,{color:w.textMuted}," [",O," \u2022 ",L," file(s) changed]"))))}),B+m<t.length&&Bt.createElement(uo,{paddingX:2,marginTop:1},Bt.createElement(To,{color:w.textMuted},"\u25BC (+",t.length-(B+m)," more prompts below)"))),Bt.createElement(uo,{marginTop:1,paddingX:1,borderStyle:"single",borderLeft:!1,borderRight:!1,borderBottom:!1,borderColor:w.borderMuted},Bt.createElement(To,{color:w.textMuted,italic:!0},"\u2191\u2193 navigate \u2022 Enter select undo point \u2022 Esc close")))}function Td(t){if(!t)return"";let x=(t.split(`
50
- `)[0]||"").replace(/@\[(.*?)\]/g,(S,w)=>{let p=w.replace(/\\/g,"/").split("/");return`[${p[p.length-1]}]`});return x.length>69?x.slice(0,67)+"...":t.includes(`
51
- `)?x+"...":x}function bd(t){if(!t)return"N/A";let g=new Date(t);if(isNaN(g.getTime()))return"N/A";let x=i=>String(i).padStart(2,"0"),S=x(g.getHours()),w=x(g.getMinutes()),p=x(g.getSeconds());return`${S}:${w}:${p}`}import yd from"puppeteer";import{exec as Sd}from"child_process";import{promisify as Cd}from"util";import sl from"fs";var il=Cd(Sd),ll=()=>{try{let t=Oi();if(t.executablePath&&sl.existsSync(t.executablePath))return!0;let g=yd.executablePath();if(g&&sl.existsSync(g))return!0}catch{return!1}return!1},al=async t=>{t&&t("\u{1F4E5} Downloading Chromium engine (chrome@148)...");try{try{await il("pnpm exec puppeteer browsers install chrome@148")}catch{await il("npx -y puppeteer browsers install chrome@148")}return await new Promise(g=>setTimeout(g,1e3)),{success:!0}}catch(g){return console.error("[SETUP ERROR]",g),{success:!1,error:g.message}}};import dl,{useState as cl,useEffect as ul}from"react";import{Text as ml}from"ink";var Md=({text:t,baseColor:g="grey",glintColor:x="gray",speed:S=200,glintWidth:w=6,typeSpeed:p=30,...i})=>{let[v,m]=cl(-w),[B,M]=cl(t);return ul(()=>{let $=setInterval(()=>{m(D=>D>B.length+w?-w-40:D+1)},S);return()=>clearInterval($)},[B.length,S,w]),ul(()=>{if(t&&(t.includes("Trying to reach")&&B&&B.includes("Trying to reach")||t.includes("Error Occurred")&&B&&B.includes("Error Occurred"))){M(t);return}if(B===t)return;let $=setTimeout(()=>{let D=0,E=Math.min(B.length,t.length);for(;D<E&&B[D]===t[D];)D++;B.length>D?M(k=>k.slice(0,-1)):B.length<t.length&&M(t.slice(0,B.length+1))},p);return()=>clearTimeout($)},[t,B,p]),dl.createElement(ml,null,B.split("").map(($,D)=>{let k=Math.abs(D-v)<=w/2?x:g;return dl.createElement(ml,{key:D,color:k,...i},$)}))},_n=Md;var Hn=t=>{let g=String(t);return g.startsWith("999")&&g.endsWith("9")},hn=t=>t==null||t===0||Hn(t)?"":String(t),qo=()=>{let t=(process.env.TERM_PROGRAM||"").toLowerCase();if(process.env.WT_SESSION)return"Windows Terminal";let g=x=>{let S=x.toLowerCase();for(let[w,p]of Object.entries(process.env))if(!["PATH","PWD","CWD","PS1","LS_COLORS","PROMPT"].includes(w)&&String(p).toLowerCase().includes(S))return!0;return!1};return t==="cursor"||process.env.CURSOR_SETTINGS_DIR||g("cursor")?"Cursor":t==="windsurf"||g("windsurf")?"Windsurf":g("antigravity")?"Antigravity":t==="trae"||g("trae")?"Trae":t==="codium"||g("codium")||g("vscode-oss")?"VSCodium":g("positron")?"Positron":t==="vscode-insiders"||g("insiders")?"VS Code Insiders":t==="vscode"||process.env.VSCODE_GIT_IPC_HANDLE||g("vscode")?"VS Code":process.env.INTELLIJ_TERMINAL_COMMAND_BLOCKS||g("intellij")?"JetBrains":"Terminal"},Ad=t=>{switch(t){case"VS Code":return"Code";case"VS Code Insiders":return"Code - Insiders";case"Antigravity":return"Antigravity IDE";default:return t}},gl={Flux:"Workspace",Flow:"Studio",ICU:"Computer Use",FluxCU:"Omni"},Bs=t=>{if(!t)return"Workspace";let g=Object.keys(gl).find(x=>x.toLowerCase()===t.toLowerCase());return g?gl[g]:t},fl=t=>{let g=Ad(t),x=Es.homedir();if(process.platform==="win32"){let S=process.env.APPDATA;return S?Dt.join(S,g,"User","keybindings.json"):null}else return process.platform==="darwin"?Dt.join(x,"Library","Application Support",g,"User","keybindings.json"):Dt.join(x,".config",g,"User","keybindings.json")},hl=t=>{let g=t.replace(/\/\*[\s\S]*?\*\/|([^\\:]|^)\/\/.*$/gm,"$1");return JSON.parse(g)},Ld=t=>Array.isArray(t)?t.some(g=>g&&typeof g.key=="string"&&g.key.toLowerCase().replace(/\s+/g,"")==="shift+enter"&&g.command==="workbench.action.terminal.sendSequence"&&g.args&&g.args.text==="\x1B[13;2u"&&typeof g.when=="string"&&g.when.includes("terminalFocus")):!1,pl=t=>{let g=t==="VS Code",x=[];return g?(x.push({label:"Install Manually (VSIX)",url:"https://github.com/KushalRoyChowdhury/fluxflow-cli/releases"}),x.push({label:"Install from VS Code Marketplace",url:"https://marketplace.visualstudio.com/items?itemName=fluxflow-cli.fluxflow-cli-companion"})):x.push({label:`Download for ${t} (GitHub)`,url:"https://github.com/KushalRoyChowdhury/fluxflow-cli/releases"}),x.push({label:"Continue to CLI only",action:"dismiss"}),x},Od=({width:t,height:g,selectedIndex:x,aiProvider:S,theme:w="Dark"})=>{let p=qo(),i=pl(p);return e.createElement(c,{flexDirection:"column",alignItems:"center",justifyContent:"center",width:t,height:g},e.createElement(c,{marginBottom:1,width:Math.min(80,t-4),justifyContent:"flex-start"},e.createElement(s,null,lr(oo,S,w))),e.createElement(c,{flexDirection:"column",borderStyle:"double",borderColor:"grey",paddingX:3,paddingY:1,width:Math.min(80,t-4)},e.createElement(s,{bold:!0,color:"white",textAlign:"center"},"\u{1F680} UPGRADE YOUR WORKFLOW"),e.createElement(c,{marginY:1,flexDirection:"column",alignItems:"left"},e.createElement(s,null,"You're in ",e.createElement(s,{bold:!0,color:"cyan"},p),", but the ",e.createElement(s,{bold:!0,color:"white"},"FluxFlow-CLI Companion")," is not installed."),e.createElement(c,{flexDirection:"column",marginY:1},e.createElement(s,{color:"gray"}," \u2705 Real-time IDE context & Error Resolution"),e.createElement(s,{color:"gray"}," \u2705 Auto-open files created by agent"),e.createElement(s,{color:"gray"}," \u2705 Native DIFFing for AI edits"),e.createElement(s,{color:"gray"}," \u2705 Direct IDE context sharing"),e.createElement(s,{color:"gray"}," \u2705 Surgical Diagnostic Sync"),e.createElement(s,{color:"gray"}," \u2705 Native Right-Click \u276F Chat integration"),e.createElement(s,{color:"gray"}," \u2705 Live Status in IDE"),e.createElement(s,{color:"gray"}," \u2705 Clickable terminal-to-code links"))),e.createElement(c,{flexDirection:"column",marginTop:1},i.map((v,m)=>e.createElement(c,{key:m},e.createElement(s,{color:x===m?"yellow":"white",bold:x===m},x===m?" \u276F ":" ",v.label)))),e.createElement(c,{marginTop:1,alignItems:"center",justifyContent:"center"},e.createElement(s,{dimColor:!0,italic:!0},"(Use arrows to navigate, Enter to select)"))))},Ds=Date.now(),xl="https://fluxflow-cli.onrender.com/changelog",vs="https://fluxflow-cli.onrender.com/",Pd=Dt.join(Dt.dirname(kd(import.meta.url)),"../package.json"),wl=JSON.parse(rt.readFileSync(Pd,"utf8")),oo=wl.version,Nd=wl.date||"2026-05-20";var Fd=({data:t,onResolve:g,onEdit:x,theme:S="Dark"})=>{let w=je(S);return e.createElement(c,{flexDirection:"column",borderStyle:"round",borderColor:w.borderMuted,padding:0,width:"100%"},e.createElement(c,{paddingX:1},e.createElement(s,{color:w.text,bold:!0,underline:!0},t.startsWith("/btw")?"QUESTION":"STEERING HINT"," RESOLUTION")),e.createElement(c,{paddingX:1,marginTop:1},e.createElement(s,{color:w.text},"The agent already finished the task before your ",t.startsWith("/btw")?"question":"hint"," was consumed.")),e.createElement(c,{marginTop:1,backgroundColor:w.cardBg||w.codeBg||"#222",paddingX:2,width:"100%"},e.createElement(s,{italic:!0,color:w.textMuted},'"',t.replace("/btw","").trim(),'"')),e.createElement(c,{paddingX:1,marginTop:1},e.createElement(s,{color:w.textDim||w.textMuted},"How would you like to proceed?")),e.createElement(c,{marginTop:0},e.createElement(gt,{title:"Select Action",items:[{label:"Send Anyway",value:"send"},{label:"Edit Prompt",value:"edit"}],onSelect:p=>{(typeof p=="object"&&p!==null?p.value:p)==="send"?g(t):x(t)},theme:S})))};var Ud=(()=>{let t=null,g=0;return x=>{let S=Date.now();if(t&&S-g<1e4)return t;let w=[],p=i=>{if(!(w.length>=2e3))try{let v=rt.readdirSync(i);for(let m of v){if(w.length>=2e3)return;if(["node_modules",".git",".gemini","dist","build",".next",".cache","out"].includes(m))continue;let B=Dt.join(i,m);rt.statSync(B).isDirectory()?p(B):w.push({name:yt(m),relativePath:yt(Dt.relative(process.cwd(),B))})}}catch{}};return p(x),t=w,g=S,w}})(),Cr="Ctrl + Enter",$d=t=>{if(t<=370)return"#00a564";if(t>=5e3)return"#ff0000";let g=[{t:370,r:0,g:165,b:100},{t:550,r:40,g:195,b:80},{t:800,r:120,g:220,b:50},{t:1100,r:190,g:225,b:20},{t:1500,r:250,g:210,b:15},{t:2e3,r:255,g:170,b:0},{t:2800,r:255,g:110,b:0},{t:3800,r:255,g:50,b:0},{t:5e3,r:255,g:0,b:0}];for(let x=0;x<g.length-1;x++){let S=g[x],w=g[x+1];if(t>=S.t&&t<=w.t){let p=(t-S.t)/(w.t-S.t);p=p*p*(3-2*p);let i=Math.round(S.r+(w.r-S.r)*p),v=Math.round(S.g+(w.g-S.g)*p),m=Math.round(S.b+(w.b-S.b)*p);return`#${((1<<24)+(i<<16)+(v<<8)+m).toString(16).slice(1)}`}}return"#ff0000"},Xd=e.memo(({sa:t,showTPMEstimate:g=!1})=>{let[x,S]=q("green"),[w,p]=q(0),i=Ve([]),v=Ve(370),m=Ve([]),B=Ve(t.lastChunkTime);return Qe(()=>{B.current=t.lastChunkTime},[t.lastChunkTime]),Qe(()=>{if(t.status!=="running"){m.current=[];return}if(t.wps>0){let M=m.current;M.push(t.wps),M.length>3&&M.shift(),p(Math.round(t.wps))}},[t.status,t.wps,t.lastChunkTime]),Qe(()=>{if(t.status!=="running"){p(0);return}let M=setInterval(()=>{let $=B.current,D=$>0?Date.now()-$:0;if($>0&&D>1500)m.current=[],p(0);else if($>0&&D>600){m.current.length>0&&m.current.shift();let E=m.current;if(E.length>0){let k=E.reduce((O,L)=>O+L,0);p(Math.round(k/E.length))}else p(0)}else{let E=m.current;if(E.length>0){let k=E.reduce((O,L)=>O+L,0);p(Math.round(k/E.length))}else t.wps>0&&p(Math.round(t.wps))}},750);return()=>clearInterval(M)},[t.status]),Qe(()=>{if(t.status!=="running"){i.current=[];return}let M=t.lastChunkTime;if(M>0){let E=i.current;(E.length===0||E[E.length-1]!==M)&&(E.push(M),E.length>10&&E.shift())}let $=()=>{if(!M){S("#00a564");return}let E=i.current,k=0;if(E.length>1){let Q=0;for(let K=1;K<E.length;K++)Q+=E[K]-E[K-1];k=Q/(E.length-1)}let O=Date.now()-M,X=O>=2500,te=!X&&k>0?Math.min(O,k*3):O,ae=Math.max(k,te),fe=X?.4:.2;v.current=v.current*(1-fe)+ae*fe,S($d(v.current))};$();let D=setInterval($,100);return()=>clearInterval(D)},[t.status,t.lastChunkTime]),e.createElement(c,{justifyContent:"space-between",width:"100%"},e.createElement(s,{color:"white"}," \u2022 ",t.title," ",e.createElement(s,{color:"white",dimColor:!0},"(",t.id,")")),e.createElement(s,{color:"white"},e.createElement(s,{color:"white",dimColor:!0,bold:!0},t.currentTool||"Active"),e.createElement(s,{color:x}," \u25CF"),g&&e.createElement(s,{color:"white",dimColor:!0,bold:!0}," (",w," tps)")))});function _d({args:t=[]}){let g=Ve(1),[x,S]=q(!1),[w,p]=q(10),{stdout:i}=Dd(),[v,m]=q(""),[B,M]=q(0),[$,D]=q(!1),[E,k]=q("Flux"),[O,L]=q(0),[X,te]=q({columns:i?.columns||80,rows:i?.rows||24}),[ae,fe]=q(0),[Q,K]=q(!1),[se,De]=q(!1),[ye,ke]=q(0),de=Ve(0),Ne=Ve(0),pe=Ve(null),V=Ve(null),he=Ve(0),[R,P]=q(0),ee=()=>P(o=>o+1),ie=Ve([]),we=Ve(null),Ee=()=>{let o=ie.current;if(o.length>0&&V.current){let n=o.join("");o.length=0,V.current.text=yt(V.current.text+n),ee()}},Ce=()=>{if(Ee(),V.current){let o=yt(V.current.text);V.current.role==="think"&&(o=o.replace(/^\r?\n+/,"").replace(/\r?\n+$/,""));let n={...V.current,text:o,isStreaming:!1};N(a=>{let h=[...a,n];return Y(h.length),h}),V.current=null}Os.current=0,Lr.current={totalWords:0,startTime:0,wps:0,chunks:[]}},Ie=()=>{we.current&&clearInterval(we.current),ie.current=[],we.current=setInterval(()=>{try{let o=ie.current;if(o.length>0&&V.current){let n=1;o.length>85?n=30:o.length>80?n=25:o.length>75?n=20:o.length>65?n=16:o.length>50?n=12:o.length>35?n=8:o.length>15?n=6:o.length>5?n=4:o.length>3&&(n=2);let a="";for(let h=0;h<n&&o.length>0;h++)a+=o.shift();V.current.text=yt(V.current.text+a),ee()}}catch{}},80)},Re=async()=>{for(;ce.progressiveRendering&&ie.current.length>0;)await new Promise(o=>setTimeout(o,10))},st=o=>{if(ce.progressiveRendering&&we.current){let n=o.split(/(\s+)/).filter(Boolean);for(let a of n)ie.current.push(a)}else V.current?V.current.text=yt(V.current.text+o):V.current={id:"agent-"+Date.now(),role:"agent",text:yt(o),isStreaming:!0},ee()};Qe(()=>{let o=qo(),n=!["Terminal","Windows Terminal"].includes(o)||!!process.env.VSC_TERMINAL_URL,a=setTimeout(()=>{n&&!jo()&&De(!0)},500),h=setInterval(()=>{jo()&&De(!1)},1e3);g.current=Date.now();let u=setInterval(()=>{g.current&&(Date.now()-g.current||0)>3e4&&global.gc&&(async()=>{for(let d=0;d<1;d++)global.gc(),await new Promise(T=>setImmediate(T));g.current=Date.now()})()},3e3);return()=>{clearTimeout(a),clearInterval(h),clearInterval(u)}},[]),Qe(()=>{(async()=>{try{let n=await Rr(),a=n?.systemSettings||{},h=a.CustomSubAgent,u=a.SubAgentModel;if(!h||!u||u==="Default")return;let b=process.env.SUBAGENT_MODEL?process.env.SUBAGENT_MODEL.trim():null,f=process.env.SUBAGENT_PROVIDER?process.env.SUBAGENT_PROVIDER.trim():null,d=["Google","DeepSeek","OpenRouter","NVIDIA","Mistral","Ollama","CrofAI","InferX","SenseNova","AIHubMix"],I=(J=>{if(!J)return null;let re=J.toLowerCase();return re==="google"?"Google":re==="deepseek"?"DeepSeek":re==="openrouter"?"OpenRouter":re==="nvidia"?"NVIDIA":re==="mistral"?"Mistral":re==="ollama"?"Ollama":re==="crofai"||re==="crof"?"CrofAI":re==="inferx"?"InferX":re==="sensenova"?"SenseNova":re==="aihubmix"||re==="aihub"?"AIHubMix":null})(f);if(b&&!I){let J=n.aiProvider||_||"Google";N(re=>(Y(re.length+1),[...re,{id:"subagent-env-noprov-"+Date.now(),role:"system",text:`[SUBAGENT CONFIG] SUBAGENT_MODEL found in ENV but SUBAGENT_PROVIDER is missing/invalid. Active provider (${J}) will be used.`,isMeta:!0}]))}if(u==="ENV"){b||N(J=>(Y(J.length+1),[...J,{id:"subagent-model-noenv-"+Date.now(),role:"system",text:"No SubAgent model is found in ENV, Using Deafult until changed",isMeta:!0}]));return}let H=n.aiProvider||_||"Google",j=n.apiTier||Je||"Free",ue=n.quotas||Ae||{},z=new Set;(Io(H,j)||[]).forEach(J=>{let re=typeof J=="string"?J:J.cmd||J.name||J.id||String(J);re&&z.add(re)});for(let J of d)try{if(await ln(J)){let tt=ue?.providerTiers?.[J]||"Free";(Io(J,tt)||[]).forEach(Xe=>{let ot=typeof Xe=="string"?Xe:Xe.cmd||Xe.name||Xe.id||String(Xe);ot&&z.add(ot)})}}catch{}let Pe=z.has(u);b?b!==u&&N(J=>(Y(J.length+1),[...J,{id:"subagent-model-env-"+Date.now(),role:"system",text:"Current Seleted Sub-Agent model is not available in this provider. Using model from ENV unless changed.",isMeta:!0}])):Pe||N(J=>(Y(J.length+1),[...J,{id:"subagent-model-err-"+Date.now(),role:"system",text:"Current Seleted Sub-Agent model is not available in this provider. Using Default until changed",isMeta:!0}]))}catch{}})()},[]);let ve=fn(()=>{let o={};for(let n=0;n<t.length;n++)if(t[n]==="--key"&&t[n+1]){let h=t[n+1];if(o.key=h,h.includes("@")){let u=h.split("@"),b=u[0],f=u[1].toLowerCase();if(["google","deepseek","openrouter","nvidia","mistral","ollama","crof","crofai","inferx","sensenova","aihubmix","aihub"].includes(f)){let d="Google";f==="google"?d="Google":f==="deepseek"?d="DeepSeek":f==="openrouter"?d="OpenRouter":f==="nvidia"?d="NVIDIA":f==="mistral"?d="Mistral":f==="ollama"?d="Ollama":f==="crof"||f==="crofai"?d="CrofAI":f==="inferx"?d="InferX":f==="sensenova"?d="SenseNova":(f==="aihubmix"||f==="aihub")&&(d="AIHubMix"),o.key=b,o.provider=d}}}for(let n=0;n<t.length;n++){let a=t[n];if(a==="--key"){n++;continue}if(a==="--model"&&t[n+1])o.model=t[n+1],n++;else if(a==="--memory"&&t[n+1])o.memory=t[n+1].toLowerCase(),n++;else if(a==="--resume"&&t[n+1])o.resume=t[n+1],n++;else if(a==="--package"&&t[n+1]){let h=t[n+1].toLowerCase();["npm","pnpm","yarn","bun"].includes(h)&&(o.package=h),n++}else if(a==="--auto-del"&&t[n+1]){let h=t[n+1].toLowerCase();["1d","7d","30d"].includes(h)&&(o.autoDel=h),n++}else if(a==="--auto-exec"&&t[n+1])o.autoExec=t[n+1].toLowerCase(),n++;else if(a==="--yolo"&&t[n+1])o.autoExec=t[n+1].toLowerCase(),n++;else if(a==="--external-access"&&t[n+1])o.externalAccess=t[n+1].toLowerCase(),n++;else if(a==="--mode"&&t[n+1]){let u=t[n+1].toLowerCase();if(["flux","flow","icu","computer","fluxcu"].includes(u)){let b="Flux";u==="flux"?b="Flux":u==="flow"?b="Flow":u==="icu"||u==="computer"?b="ICU":u==="fluxcu"&&(b="FluxCU"),o.mode=b}n++}else if(a==="--thinking"&&t[n+1]){let u=t[n+1].toLowerCase();if(["fast","low","medium","high","xhigh","standard"].includes(u)){let b="Medium";u==="fast"?b="Fast":u==="low"?b="Low":u==="standard"?b="Standard":u==="medium"?b="Medium":u==="high"?b="High":u==="xhigh"&&(b="xHigh"),o.thinking=b}n++}else if(a==="--provider"&&t[n+1]){let h=t[n+1].toLowerCase();if(["google","deepseek","openrouter","nvidia","mistral","ollama","crof","crofai","inferx","sensenova","aihubmix","aihub"].includes(h)){let u="Google";h==="google"?u="Google":h==="deepseek"?u="DeepSeek":h==="openrouter"?u="OpenRouter":h==="nvidia"?u="NVIDIA":h==="mistral"?u="Mistral":h==="ollama"?u="Ollama":h==="crof"||h==="crofai"?u="CrofAI":h==="inferx"?u="InferX":h==="sensenova"?u="SenseNova":(h==="aihubmix"||h==="aihub")&&(u="AIHubMix"),o.provider=u}n++}else(a==="--resume"||a==="-r")&&t[n+1]?(o.resume=t[n+1],n++):a==="--playground"?o.playground=!0:(a==="--original-cwd"||a==="--orginal-cwd")&&t[n+1]&&(o.originalCwd=t[n+1],n++)}return o},[t]),oe=async(o=!1,n=null)=>{let a=n||ce;o&&N(h=>(Y(h.length+1),[...h,{id:"check-"+Date.now(),role:"system",text:"\u2726 Checking for updates...",isMeta:!0}]));try{let u=await(await fetch("https://registry.npmjs.org/fluxflow-cli",{cache:"no-store"})).json(),b=u["dist-tags"]?.latest,f=u["dist-tags"]?.stable;if(b&&Qo(b),b&&b!==oo){let d=b===f?`v${b}`:`v${b}`;!o&&a.autoUpdate?G("update"):N(T=>{let I=[...T],H=o?I.length:Math.min(I.length,3);return I.splice(H,0,{id:"update-"+Date.now(),role:"system",text:`A new version (${d}) is here.
52
-
53
- \u2022 Type \`/update latest\` to apply the update.
54
- \u2022 Type \`/changelog\` to view the release notes.`,isUpdateNotification:!0,isMeta:!0}),I})}else o&&N(d=>{Y(d.length+1);let T=b&&b===f?`${oo}`:oo;return[...d,{id:"uptodate-"+Date.now(),role:"system",text:`\u2800\u2800\x1B[2m\u2514\u2500\x1B[22m Already up to date (${T}).
55
- \u2800`,isMeta:!0}]})}catch(h){o&&N(u=>(Y(u.length+1),[...u,{id:"check-err-"+Date.now(),role:"system",text:`\u2800\u2800\x1B[2m\u2514\u2500\x1B[22m Failed to check for updates: ${h.message}.
56
- \u2800`,isMeta:!0}]))}};Qe(()=>{let o=()=>{i.write("\x1B[2J\x1B[3J\x1B[H"),te({columns:i.columns,rows:i.rows})};return i.on("resize",o),()=>{i.off("resize",o)}},[i]);let[me,_e]=q("Medium"),[_,vt]=q("Google"),[dt,Nt]=q(0),[Vt,Qo]=q(null),[Ht,Mr]=q(!1),[ne,le]=q(ro("Google","Free")||"gemma-4-31b-it"),[y,F]=q(!1),[Se,$e]=q(wi("gemma_janitor_fallback_google")||"gemma-4-26b-a4b-it"),[it,Ze]=q(!0),[Fe,jt]=q(!0),We=Ve(0),[wt,Kt]=q(null),[Br,zo]=q(""),Dr=async o=>{let n=fl(o);if(n)try{await rt.ensureDir(Dt.dirname(n));let a=[];if(rt.existsSync(n)){let h=rt.readFileSync(n,"utf8").trim();if(h)try{a=hl(h)}catch{a=[]}}Array.isArray(a)||(a=[]),a.push({key:"shift+enter",command:"workbench.action.terminal.sendSequence",args:{text:"\x1B[13;2u"},when:"terminalFocus"}),rt.writeFileSync(n,JSON.stringify(a,null,4),"utf8"),Cr="Shift + Enter",N(h=>(Y(h.length+1),[...h,{id:"kb-success-"+Date.now(),role:"system",text:`\u2726 Successfully configured Shift+Enter in your ${o} keybindings!
57
- `,isMeta:!0}]))}catch(a){N(h=>(Y(h.length+1),[...h,{id:"kb-error-"+Date.now(),role:"system",text:`\u2726 Failed to update keybindings: ${a.message}.
58
- \u2800`,isMeta:!0}]))}},[lt,G]=q("chat"),[Je,$o]=q("Free"),[Ae,$t]=q({limitMode:"Daily",agentLimit:99999999,tokenLimit:99999999999999,backgroundLimit:999999,searchLimit:100,customModelId:"",customLimit:0,providerBudgets:{}}),[bo,qt]=q(null),[yo,Tl]=q("chat"),[Jo,vr]=q("settings"),[Zo,bl]=q([]),[Hd,yl]=q(0),[ks,Wn]=q(0),[Er,Is]=q({}),[kr,Ir]=q({}),[Gn,go]=q(0),[ce,Et]=q({memory:!0,theme:"Dark",compression:0,autoExec:!1,autoDeleteHistory:"7d",autoUpdate:!1,updateManager:"npm",customUpdateCommand:""}),l=fn(()=>je(ce.theme),[ce.theme]),[xn,As]=q({name:null,nickname:null,instructions:null}),[So,Yn]=q({keyType:"Default",quality:"Low-High",apiKey:""}),[fo,Xo]=q({tokens:0}),[Ls,Ar]=q(0),Os=Ve(0),Lr=Ve({totalWords:0,startTime:0,wps:0,chunks:[]}),[Ps,Ns]=q(0),[Fs,Sl]=q(0),[Qt,Us]=q(0),[Cl,pn]=q(0),wn=Ve(0),[Vn,$s]=q(0),[Ro,Xs]=q(0),[Wd,Ml]=q(0),[Gd,Bl]=q(0),[Yd,Dl]=q(0),[jn,vl]=q(0),[Kn,El]=q(0),[qn,kl]=q(0),[_s,Il]=q(0),[Tn,Or]=q(null),[Qn,Pr]=q(null),[Nr,Hs]=q(null),[en,bn]=q("daily"),[Al,Zt]=q(0),[yn,Sn]=q(""),Cn="flow-playground",[et,zn]=q(t.includes("--playground")?Cn:ss());Qe(()=>{if(Go.current)return;let o=Qt-wn.current;pn(o),et&&Li(et,o,fo.tokens).catch(()=>{})},[Qt,et,fo.tokens]),Qe(()=>{lt==="apiTier"&&(async()=>{let n=await sr();Or(n);let a=await ir();Pr(a);let h=await es(Ae.resetDay||1);Hs(h)})()},[lt,Ae.resetDay]);let[Rt,Ws]=q(null),[tn,on]=q(""),[Mn,Gs]=q(!1),[Fr,Ll]=q([]),[Vd,jd]=q(0),Ys=Ve(!0),Vs=Ve(!0),Ur=Ve(_),$r=Ve(!1),Xr=Ve(!0);Qe(()=>{y&&(F(!1),N(o=>(Y(o.length+1),[...o,{id:Date.now(),role:"system",text:`\u2726 Wildcard Tooling:
59
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m Status: Disabled.
60
- \u2800`,isMeta:!0}]))),process.env.forcedReasoning&&(N(o=>(Y(o.length+1),[...o,{id:Date.now(),role:"system",text:`\u2726 Forced Reasoning:
61
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m Status: Disabled.
62
- \u2800`,isMeta:!0}])),process.env.forcedReasoning=!1)},[ne]);let js;Qe(()=>{if(Vs.current){js=setTimeout(()=>{Vs.current=!1,Ur.current=_},1e3);return}if(Ur.current!==_)if(Ur.current=_,_==="Mistral")_e("Fast");else{if(_==="SenseNova"){_e("High");return}_e(_==="DeepSeek"||_==="NVIDIA"||_==="CrofAI"||_==="InferX"||_==="Ollama"||_==="CroAI"||_==="OpenRouter"?"Standard":"Medium")}else _==="Google"&&me==="xHigh"&&ne&&ne.toLowerCase().startsWith("gemini-3")&&_e("High");return()=>{clearTimeout(js)}},[_,ne]);let Ks;Qe(()=>{if(!wt)return;if(Ys.current){Ks=setTimeout(()=>{Ys.current=!1},1500);return}let o=ro(_,Je),n=o;return o.includes("gemma")?n="Gemma":o.includes("deepseek")?n="DeepSeek Flash":o.includes("devstral")?n="Devstral":o.includes("mistral")?n="Mistral":o.includes("gemini")&&(n="Gemini Flash"),le(o),kt({apiTier:Je,activeModel:o}),()=>{clearTimeout(Ks)}},[Je,_,wt]);let Ol=fn(()=>{let o=qo();return{isIDE:!["Terminal","Windows Terminal"].includes(o)||!!process.env.VSC_TERMINAL_URL||!!process.env.INTELLIJ_TERMINAL_COMMAND_BLOCKS,get shortcut(){return Cr}}},[]),Jn=Ve(null),_r=Ve("");Qe(()=>{Jn.current=Rt},[Rt]),Qe(()=>{_r.current=tn},[tn]);let[Pl,Nl]=q(!1),[Co,nn]=q(null),[_o,Hr]=q(null),Zn=o=>{nn(null),G("chat")},qs=o=>{let n=Math.floor(o/3600),a=Math.floor(o%3600/60),h=o%60,u=[];return n>0&&u.push(`${n}h`),(a>0||n>0)&&u.push(`${a}m`),u.push(`${h}s`),u.join(" ")},Ho=o=>o<1e3?`${o}ms`:qs(Math.floor(o/1e3)),[Bn,Wr]=q(null),[Gr,Qs]=q(""),[Fl,Ul]=q(!1),[zs,Dn]=q(0),vn;Qe(()=>{let o;if(Bn&&ce.loadingPhrases!==!1){let n=()=>{let a=Cs[Math.floor(Math.random()*Cs.length)];Qs(a)};Gr||n(),o=setInterval(n,1e4)}else Qs("");return()=>{clearInterval(o)}},[Bn,ce]);let[Kd,$l]=q(!0),[rn,Yr]=q(!1),[Rn,Js]=q(!1),[Xl,_l]=q(!1),[Zs,qd]=q(null),[Rs,En]=q(0),[Hl,ei]=q([]),Wo=Ve(null),Go=Ve(!1);Qe(()=>()=>{Wo.current&&clearTimeout(Wo.current)},[]);let Vr=Ve(!1),[Qd,jr]=q(null),[Wl,Kr]=q(null),[zd,Gl]=q(null);Qe(()=>En(0),[v]);let[ft,Yl]=q(()=>{let o={id:"logo-"+Date.now(),role:"system",isLogo:!0,isMeta:!0},n=process.cwd()===Es.homedir(),a=(()=>{let u=process.cwd().toLowerCase();if(process.platform==="win32"){let b=process.env.SystemRoot?.toLowerCase()||"c:\\windows",f=process.env.ProgramFiles?.toLowerCase()||"c:\\program files",d=process.env["ProgramFiles(x86)"]?.toLowerCase()||"c:\\program files (x86)";return u.startsWith(b)||u.startsWith(f)||u.startsWith(d)}else return u==="/"||["/bin","/sbin","/etc","/usr","/var","/root"].some(f=>u.startsWith(f))})(),h=[o];return a?h.push({id:"system-warning",role:"system",text:"[CRITICAL SECURITY ALERT] SYSTEM DIRECTORY DETECTED",subText:`You are currently in a PROTECTED SYSTEM DIRECTORY (${process.cwd()}). Operating here is EXTREMELY dangerous as the agent could accidentally corrupt your OS or installed applications. Open FluxFlow in project folder to work safely.`,isHomeWarning:!0}):n&&h.push({id:"home-warning",role:"system",text:"[SECURITY ALERT] HOME DIRECTORY DETECTED",subText:`You are currently in ${Es.homedir()}. Working here is high-risk as the agent may modify system-sensitive configurations. Please open FluxFlow in project folder.`,isHomeWarning:!0}),h}),N=o=>{Yl(n=>{let a=typeof o=="function"?o(n):o;if(a.length>1){let h=a[a.length-1],u=a[a.length-2];if(h?.text?.includes("Request Cancelled")&&u?.text?.includes("Request Cancelled"))return a.slice(0,-1)}return a})},Mo=Ve(null),[ti,Vl]=q(""),[oi,ni]=q(!1),ri=Ve(""),si=Ve(null);Qe(()=>{if(ft.length===0)return;let o=ft[ft.length-1];if(o&&(o.role==="agent"||o.role==="assistant")){let a=(o.text||"").match(/\[ANSWER\]([\s\S]*?)(?:\[\/ANSWER\]|$)/i);if(a){let h=a[1].trim();h&&h!==ri.current&&(Vl(h),ri.current=h,si.current!==o.id&&ni(!0))}}},[ft]);let[Bo,Y]=q(ft.length),[Yo,qr]=q(0),Jd=Ve([]),Wt=Ve({completedIndex:0,columns:0,historicalBlocks:[],seenSelections:new Set,chatId:"",clearKey:0,theme:""}),ii=fn(()=>{let o=X.columns||80,n=/Selection: (.*)/,a=[],h=new Set,u=Wt.current.columns!==o,b=Bo<Wt.current.completedIndex,f=Wt.current.chatId!==et,d=Wt.current.clearKey!==Yo,T=Wt.current.theme!==ce.theme;if(u||b||f||d||T){let z=ft.slice(0,Bo);for(let Me=0;Me<z.length;Me++){let Pe=z[Me];if(Pe.isAskRecord&&Pe.text){let re=Pe.text.match(n);if(re&&re[1].trim()){let tt=re[1].trim();if(h.has(tt))continue;h.add(tt)}}let J=In(Pe,o);for(let re=0;re<J.completed.length;re++)a.push(J.completed[re]);for(let re=0;re<J.active.length;re++)a.push(J.active[re])}Wt.current={completedIndex:Bo,columns:o,historicalBlocks:a,seenSelections:new Set(h),chatId:et,clearKey:Yo,theme:ce.theme}}else if(a=Wt.current.historicalBlocks,h=Wt.current.seenSelections,Bo>Wt.current.completedIndex){a=[...a],h=new Set(h);let z=ft.slice(Wt.current.completedIndex,Bo);for(let Me=0;Me<z.length;Me++){let Pe=z[Me];if(Pe.isAskRecord&&Pe.text){let re=Pe.text.match(n);if(re&&re[1].trim()){let tt=re[1].trim();if(h.has(tt))continue;h.add(tt)}}let J=In(Pe,o);for(let re=0;re<J.completed.length;re++)a.push(J.completed[re]);for(let re=0;re<J.active.length;re++)a.push(J.active[re])}Wt.current={completedIndex:Bo,columns:o,historicalBlocks:a,seenSelections:h,chatId:et,clearKey:Yo}}let I=ft.slice(Bo),H=[],j=[];for(let z=0;z<I.length;z++){let Me=I[z];if(Me.isAskRecord&&Me.text){let J=Me.text.match(n);if(J&&J[1].trim()){let re=J[1].trim();if(h.has(re))continue}}let Pe=In(Me,o);for(let J=0;J<Pe.completed.length;J++)H.push(Pe.completed[J]);for(let J=0;J<Pe.active.length;J++)j.push(Pe.active[J])}if(V.current){let z=In(V.current,o);for(let Me=0;Me<z.completed.length;Me++)H.push(z.completed[Me]);for(let Me=0;Me<z.active.length;Me++)j.push(z.active[Me])}let ue=H.length===0?a:a.concat(H);return ue.length>=75e3&&(ue=[...ue],ue.push({key:`memory-warning-block-${ue.length}`,msg:{role:"system",text:"\u26A0\uFE0F MEMORY WARNING: CHAT IS GETTING VERY LONG",subText:`This session has reached ${ue.length} blocks. To maintain optimal performance and prevent high memory usage, it is highly recommended to save and start a clean chat with /clear.`,isHomeWarning:!0},type:"full-message"})),{completed:ue,active:j}},[ft,Bo,X.columns,Yo,et,R]),jl=fn(()=>{if(!Rt||!tn)return!1;let o=tn.trim();return o.endsWith("?")||o.endsWith(":")||/\[[yYnN/]+\]\s*$/.test(o)||/\([yYnN]\)\s*$/.test(o)},[Rt,tn]);Bd((o,n)=>{if(!(o==="\x1B[I"||o==="\x1B[O"||o==="[I"||o==="[O")){if(n.ctrl&&(o.toLowerCase()==="r"||o===""||o==="")){Qi();return}if(lt==="stats"){if(en==="dailyModelBreakdown"||en==="modelBreakdown"){if(n.tab&&!n.shift){bn(h=>h==="dailyModelBreakdown"?"modelBreakdown":"dailyModelBreakdown"),Zt(0);return}if(n.space||o===" "){bn(h=>h==="dailyModelBreakdown"?"daily":"monthly"),Zt(0),Sn("");return}if(n.escape){if(yn){Sn(""),Zt(0);return}G("chat");return}if(n.upArrow){Zt(h=>Math.max(0,h-1));return}if(n.downArrow){Zt(h=>Math.min(Ne.current,h+1));return}if(n.backspace||n.delete){Sn(h=>h.slice(0,-1)),Zt(0);return}if(o&&o!==" "&&!n.space&&!n.ctrl&&!n.meta&&o.length===1&&o.charCodeAt(0)>=32){Sn(h=>h+o),Zt(0);return}return}if(n.tab&&!n.shift){bn(h=>h==="daily"?"monthly":"daily"),Zt(0);return}if(n.space||o===" "){bn(h=>h==="daily"?"dailyModelBreakdown":"modelBreakdown"),Zt(0),Sn("");return}if(n.upArrow){Zt(h=>Math.max(0,h-1));return}if(n.downArrow){Zt(h=>Math.min(Ne.current,h+1));return}}if(se){let a=qo(),h=pl(a);if(n.upArrow)ke(u=>u>0?u-1:h.length-1);else if(n.downArrow)ke(u=>u<h.length-1?u+1:0);else if(n.return){let u=h[ye];if(u.action==="dismiss")De(!1);else if(u.url){let b=process.platform==="win32"?`start ${u.url}`:process.platform==="darwin"?`open ${u.url}`:`xdg-open ${u.url}`;mo(b),De(!1)}}return}if(n.tab&&Rt){Gs(a=>!a);return}if(Mn&&Rt){if(n.return)if(an)Gt("\r");else{let a=process.platform==="win32";Gt(a?`\r
63
- `:`
64
- `),on(h=>h+`
65
- `)}else if(n.backspace||n.delete)an?Gt("\x7F"):(Gt("\b \b"),on(a=>a.slice(0,-1)));else if(n.upArrow)Gt(n.shift?"\x1B[1;2A":"\x1B[A");else if(n.downArrow)Gt(n.shift?"\x1B[1;2B":"\x1B[B");else if(n.rightArrow)Gt(n.shift?"\x1B[1;2C":"\x1B[C");else if(n.leftArrow)Gt(n.shift?"\x1B[1;2D":"\x1B[D");else if(n.escape)Gt("\x1B");else if(n.ctrl&&o){let a=o.toLowerCase().charCodeAt(0);a>=97&&a<=122?Gt(String.fromCharCode(a-96)):Gt(o)}else o&&(Gt(o),an||on(a=>a+o));return}if(lt==="providerBudgetSelect"){let a=["Google","DeepSeek","Mistral","NVIDIA","OpenRouter","Ollama","CrofAI","InferX","SenseNova"];if(n.upArrow){Wn(h=>(h-1+a.length)%a.length);return}else if(n.downArrow){Wn(h=>(h+1)%a.length);return}else if(o===" "){let h=a[ks];Is(u=>({...u,[h]:!u[h]}));return}else if(n.return){let h=a.filter(b=>Er[b]);if(h.length===0)return;let u={...Ae,providerBudgets:{...Ae.providerBudgets||{},__useProvider:!0}};$t(u),bl(h),yl(0),Wn(0),G("providerBudgetFlow");return}else if(n.escape){G("budgetTypeSelect");return}return}if(lt==="providerBudgetFlow"){let a=Zo.length,h=a*2+1;if(n.upArrow){go(u=>u===h-1?Math.max(0,(a-1)*2):u>=2?u-2:u);return}else if(n.downArrow){go(u=>u===h-1?u:u+2<h-1?u+2:h-1);return}else if(n.leftArrow){go(u=>u===h-1?u:u%2===1?u-1:u);return}else if(n.rightArrow||n.tab){go(u=>u===h-1?u:u%2===0||u+1<h?u+1:u);return}else if(n.return){if(Gn===h-1){let u=Ae.providerBudgets||{},b={__useProvider:!0};for(let T of Zo){let I=kr[T]||{};b[T]={agentLimit:9999999999,tokenLimit:parseInt(I.tokenLimit,10)||0,monthlyTokenLimit:parseInt(I.monthlyTokenLimit,10)||0}}let f={...Ae,providerBudgets:b};$t(f),kt({apiTier:Je,quotas:f}),G(yo==="settings"?"resetMode":"budgetResetMode")}else go(u=>Math.min(h-1,u+1));return}else if(n.escape){G("providerBudgetSelect");return}return}if(n.escape){if(oi){if(ni(!1),ft.length>0){let a=ft[ft.length-1];a&&(si.current=a.id)}return}if(He.length>0&&lt==="chat"){K(!0);return}if(x){S(!1);return}if(rn||Rt||Co||_o)Vr.current=!0,$i(),Ei(),Co&&(Co.resolve("deny"),nn(null)),_o&&(_o.resolve(null),Hr(null)),_l(!1),Zs&&clearTimeout(Zs);else if(lt==="revert")G("chat"),En(0);else if(lt!=="chat"&&lt!=="settings")G("chat");else{if(!wt&&dt===1){Nt(0),zo("");return}En(a=>{let h=a+1;return h===1?(Wo.current&&clearTimeout(Wo.current),Wo.current=setTimeout(()=>En(0),2e3)):h===2&&(Wo.current&&clearTimeout(Wo.current),En(0),v.length>0?m(""):Ln.getChatHistory(et).then(u=>{u.length>0?(ei(u.reverse()),G("revert")):N(b=>(Y(b.length+1),[...b,{id:"revert-empty-"+Date.now(),role:"system",text:`\u2726 Nothing to revert to.
66
- \u2800`,isMeta:!0}]))})),h})}}if(He.length>0&&lt==="chat"){if(n.upArrow){fe(a=>{let h=a>0?a-1:He.length-1,u=0;for(;h!==a&&u<He.length;){let b=He[h],f=b?.cmd||b||"";if(typeof f=="string"&&f.trimStart().startsWith("---"))h=h>0?h-1:He.length-1,u++;else break}return h});return}if(n.downArrow){fe(a=>{let h=a<He.length-1?a+1:0,u=0;for(;h!==a&&u<He.length;){let b=He[h],f=b?.cmd||b||"";if(typeof f=="string"&&f.trimStart().startsWith("---"))h=h<He.length-1?h+1:0,u++;else break}return h});return}if(n.return)return}if(n.tab&&lt==="chat"){if(He.length>0){let a=He[ae]||He[0],h=v.split(" ");if(h.length===1)m(a.cmd+" ");else{let u=h.slice(0,-1);m(u.join(" ")+" "+a.cmd+" ")}fe(0),M(u=>u+1);return}else if(v.trim()===""){let a=Date.now();if(a-he.current<500)return;he.current=a;let h=["Flux","Flow","ICU","FluxCU"],u=(h.indexOf(E)+1)%h.length,b=h[u>=0?u:0];k(b),b==="Flow"?_e("Fast"):(b==="Flux"||b==="ICU"||b==="FluxCU")&&_e("High"),N(f=>[...f,{id:Date.now(),role:"system",text:`\u2726 Mode switched to ${Bs(b)}
67
- \u2800`,isMeta:!0}]);return}}if(n.ctrl&&o==="c"&&lt!=="exit"){if(v.length>0){m("");return}if(n.shift){G("exit"),S(!1);return}x?(G("exit"),S(!1)):S(!0)}n.return&&(n.shift||n.ctrl||n.meta||n.leftAlt||n.rightAlt)&&m(a=>a.replace(/\\\r?$/,"").replace(/\r?$/,"")+`
68
- `)}}),Qe(()=>{process.stdout.write("\x1B[?1004h");let o=n=>{let a=n.toString();a.includes("\x1B[I")?(jt(!0),We.current=Date.now()):a.includes("\x1B[O")&&(jt(!1),We.current=Date.now())};return process.stdin.on("data",o),()=>{process.stdout.write("\x1B[?1004l"),process.stdin.off("data",o)}},[]);let er=Ve(ce.theme);Qe(()=>{er.current&&er.current!==ce.theme?(er.current=ce.theme,i&&(i.write("\x1B[2J\x1B[3J\x1B[H"),i.isTTY&&i.write("\x1B[?2004h")),qr(o=>o+1),ho()):er.current=ce.theme},[ce.theme,i]),Qe(()=>{async function o(){try{let I=JSON.parse(rt.readFileSync(Dt.join(process.cwd(),"package.json"),"utf8"));is(oo||I.version||"2.0.0")}catch{is("2.0.0")}process.stdout.isTTY&&(process.stdout.write("\x1B]0;FluxFlow\x07"),process.stdout.write("\x1B]633;P;TerminalTitle=FluxFlow\x07")),ll()||(N(I=>(Y(I.length+1),[...I,{id:"setup-"+Date.now(),role:"system",text:"\u2726 Installing Required dependencies... (One-time setup)",isMeta:!0}])),await al(),N(I=>(Y(I.length+1),[...I,{id:"setup-done-"+Date.now(),role:"system",text:`\u2800\u2800\x1B[2m\u2514\u2500\x1B[22m All dependencies installed successfully.
69
- \u2800`,isMeta:!0}]))),await hi();let n=await Rr();$r.current=n.systemSettings?.allowExternalAccess??!1,Xr.current=n.systemSettings?.memory??!0,ve.mode?k(ve.mode):k(n.mode),L(n.display??0),ve.thinking?_e(ve.thinking):_e(n.thinkingLevel);let a=ve.provider||n.aiProvider||"Google";vt(a);let u=(n.quotas?.providerTiers||{})[a]||n.apiTier||"Free";if(pe.current=n.activeModel,ve.model)le(ve.model);else if(ve.provider){let I=ro(a,u);le(I)}else le(n.activeModel);Mr(n.showFullThinking),$o(u),$t(n.quotas||{limitMode:"Daily",agentLimit:99999999,tokenLimit:99999999999999,backgroundLimit:999999,searchLimit:100,customModelId:"",customLimit:0,providerBudgets:{}});let b={memory:!0,compression:0,autoExec:!1,autoDeleteHistory:"7d",autoUpdate:!1,updateManager:"npm",customUpdateCommand:"",...n.systemSettings||{}};ve.memory==="on"?b.memory=!0:ve.memory==="off"&&(b.memory=!1),a==="NVIDIA"&&process.env.NVIDIA_BASE_URL&&(b.memory=!1,N(I=>[...I,{role:"system",text:`\u2726 MEMORY
70
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m Currently not available.
71
- \u2800`,isMeta:!0}])),ve.package&&(b.updateManager=ve.package),ve.autoDel&&(b.autoDeleteHistory=ve.autoDel),ve.autoExec==="on"?b.autoExec=!0:ve.autoExec==="off"&&(b.autoExec=!1),ve.externalAccess==="on"?b.allowExternalAccess=!0:ve.externalAccess==="off"&&(b.allowExternalAccess=!1),ve.playground&&(b.allowExternalAccess=!1,b.memory=!1),Et(b),As(n.profileData),Yn(n.imageSettings||{keyType:"Default",quality:"Low-High",apiKey:""});let f=ve.key;if(f||(f=await ln(a)),f&&(Kt(f),On(f,{aiProvider:a,onIDEApproval:Zn})),n.systemSettings?.autoDeleteHistory&&Ii(n.systemSettings.autoDeleteHistory),Ai(rr),ve.playground||(dr(Cn).catch(()=>{}),rt.remove(Dt.join(no,"playground")).catch(()=>{})),oe(!1,b),await Promise.all([bi(),Ln.recoverCrashedTransaction()]),ve.resume){let I=await Ao(),H=ve.resume;if(I[H]){Go.current=!0,zn(H);let j=await cr(H);wn.current=Qt-j.total,Go.current=!1,pn(j.total),Xo({tokens:j.context});let ue=[...I[H].messages];ue[0]?.text?.includes("\u2591\u2591\u2591\u2588\u2588\u2588")||ue.unshift({id:"logo-"+Date.now(),role:"system",isLogo:!0,isMeta:!0}),N(ue),G("chat"),N(Me=>{let Pe=[...Me,{id:"sys-"+Date.now(),role:"system",text:`\u2726 SESSION RESUMED
72
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m '${H}'.
73
- \u2800`,isMeta:!0}];return Y(Pe.length),Pe})}else N(j=>[...j,{id:"sys-err-"+Date.now(),role:"system",text:`\u2726 Chat session [${H}] not found. Started new session.
74
- \u2800`,isMeta:!0}])}if(ve.playground){let I=Dt.join(no,"playground");try{rt.ensureDirSync(I),process.chdir(I)}catch{}let H=await Ao();if(H[Cn]){let j=[...H[Cn].messages];j[0]?.isLogo||j.unshift({id:"logo-"+Date.now(),role:"system",isLogo:!0,isMeta:!0}),N(j),N(ue=>{let z=[...ue,{id:"playground-"+Date.now(),role:"system",text:`\u2726 PLAYGROUND Session restored
75
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m CWD locked to: '${I}'.
76
- \u2800`,isMeta:!0}];return Y(z.length),z})}else N(j=>{let ue=[...j,{id:"playground-"+Date.now(),role:"system",text:`\u2726 PLAYGROUND Mode active
77
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m CWD locked to: 'FluxFlow/playground'.
78
- \u2800`,isMeta:!0}];return Y(ue.length),ue})}let d=qo();if(!["Terminal","Windows Terminal"].includes(d)){let I=fl(d);if(I)try{let H=[];if(rt.existsSync(I)){let j=rt.readFileSync(I,"utf8").trim();j&&(H=hl(j))}Ld(H)?Cr="Shift + Enter":G("keybindingsPrompt")}catch{}}Ze(!1)}o()},[]),Qe(()=>{let o;return x&&(p(10),o=setInterval(()=>{p(n=>n<=1?(S(!1),0):n-1)},1e3)),()=>{o&&clearInterval(o)}},[x]),Qe(()=>{if(!it){let o=ve.model&&ne===ve.model?pe.current:ne,n=ce;ve.playground&&(n={...ce,allowExternalAccess:$r.current,memory:Xr.current}),kt({mode:E,thinkingLevel:me,aiProvider:_,activeModel:o||ne,showFullThinking:Ht,systemSettings:n,profileData:xn,imageSettings:So,apiTier:Je})}},[E,me,_,ne,Ht,ce,xn,So,it,ve,Je]);let li=async o=>{let n=o.trim(),a={Google:{prefix:"AIzaSy",minLength:39},OpenRouter:{prefix:"sk-or-v1-",minLength:73},DeepSeek:{prefix:"sk-",minLength:35},Mistral:{prefix:"",minLength:32},NVIDIA:{prefix:"nvapi-",minLength:70},Ollama:{prefix:"",minLength:0},CrofAI:{prefix:"",minLength:0},InferX:{prefix:"",minLength:0},SenseNova:{prefix:"",minLength:0},AIHubMix:{prefix:"sk-",minLength:10}},{prefix:h,minLength:u}=a[_]??{prefix:"",minLength:0},b=_==="Ollama"&&(n.trim()==="LOCAL"||n.trim()===""),f=b?"LOCAL":n;if(b||n.startsWith(h)&&n.length>=u){await Zr(_,f),Kt(f),On(f,{aiProvider:_,onIDEApproval:Zn});let d="gemma-4-31b-it";_==="OpenRouter"?d="google/gemma-4-31b-it:free":_==="DeepSeek"?d="deepseek-v4-flash":_==="NVIDIA"?d="deepseek-ai/deepseek-v4-flash":_==="Ollama"?d=ne||"":(_==="CrofAI"||_==="InferX"||_==="SenseNova"||_==="AIHubMix")&&(d=ro(_,Je)||""),le(d);let T={...ce};b&&(T={...T,ollamaEndpoint:"Local"},Et(T)),(_==="Ollama"||_==="CrofAI"||_==="InferX"||_==="SenseNova"||_==="AIHubMix")&&(T={...T,memory:!1},Et(T)),kt({aiProvider:_,activeModel:d,systemSettings:T}),N(I=>[...I,{role:"system",text:`\u2726 ${_} API Key saved successfully! ${d?`
79
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m Model set to ${d}.`:""}${b?`
80
- \u2726 Ollama Endpoint switched to Local.
81
- \u2514\u2500\u2800`:`
82
-
83
- \u2726\u2800`}${_==="Ollama"||_==="CrofAI"||_==="InferX"||_==="SenseNova"||_==="AIHubMix"?`Memory is not available with ${_}.
84
- \u2514\u2500\u2800`:""}Initialization complete.
85
- \u2800`,isMeta:!0}])}else N(d=>[...d,{role:"system",text:`\u2726 INVALID KEY
86
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m ${_} API key must start with "${h}" and be at least ${u} characters long.`,isMeta:!0}]),zo("")},tr=Ve(Ds);Qe(()=>{if(lt==="exit"){(async()=>{let a=Date.now(),h=Math.floor((a-tr.current)/1e3);h>=1&&(await Vo("duration",h),tr.current+=h*1e3),await yi()})();let n=setTimeout(()=>{process.exit(0)},200);return()=>clearTimeout(n)}},[lt]),Qe(()=>{let o=setInterval(async()=>{if(!it){let n=Date.now(),a=Math.floor((n-tr.current)/1e3);a>=1&&(await Vo("duration",a),tr.current+=a*1e3)}},5e3);return()=>clearInterval(o)},[it]);let ai=[{cmd:"/quit",desc:"Exit and shutdown Flux"},{cmd:"/help",desc:"Show all available commands"},...ve.playground?[{cmd:"/move",desc:"Move playground directory to original CWD/playground-export"}]:[],{cmd:"/resume",desc:"Load previous session"},{cmd:"/clear",desc:"Clear terminal screen"},{cmd:"/compress",desc:"Summarize and compress chat history"},{cmd:"/truncate",desc:"Truncate tool results in chat history"},{cmd:"/revert",desc:"Revert codebase back to a checkpoint"},{cmd:"/gemini",desc:"Get a happy message from Gemini CLI"},{cmd:"/save",desc:"Force save current chat"},{cmd:"/export",desc:"Export current chat or error logs",subs:[{cmd:"chat",desc:"Export current active chat"},{cmd:"logs",desc:"Export error logs"}]},{cmd:"/chats",desc:"List all chat sessions"},{cmd:"/btw",desc:"Ask a question without intefering with ongoing tasks"},{cmd:"/thinking",desc:"Set AI reasoning depth",subs:_==="Ollama"||_==="DeepSeek"?[{cmd:"Fast",desc:"Reasoning Disabled"},{cmd:"Standard",desc:"Standard Reasoning"},{cmd:"High",desc:"Extended Reasoning"}]:_==="NVIDIA"?[{cmd:"Fast",desc:"Reasoning Disabled"},{cmd:"Standard",desc:"Balanced Reasoning"},{cmd:"High",desc:"Extended Reasoning"}]:_==="OpenRouter"?[{cmd:"Fast",desc:"Fastest"},{cmd:"Low",desc:"Quick Reasoning"},{cmd:"Standard",desc:"Balanced Reasoning"},{cmd:"High",desc:"Deep Reasoning"},{cmd:"xHigh",desc:"Extended Reasoning"}]:_==="Mistral"?[{cmd:"Fast",desc:"Reasoning Disabled"},{cmd:"xHigh",desc:"Deep Reasoning"}]:ne&&(ne.toLowerCase().startsWith("gemini-3")||_==="CrofAI"||_==="InferX"||_==="SenseNova")?[{cmd:"Fast",desc:"Fastest"},{cmd:"Low",desc:"Quick Reasoning"},{cmd:"Standard",desc:"Balanced Reasoning"},{cmd:"High",desc:"Deep Reasoning"}]:[{cmd:"Fast",desc:"Fastest"},{cmd:"Low",desc:"Quick Reasoning"},{cmd:"Medium",desc:"Balanced Reasoning"},{cmd:"High",desc:"Deep Reasoning"},{cmd:"xHigh",desc:"Extended Reasoning"}]},{cmd:"/model",desc:"Select Agent Model",subs:_==="Ollama"&&(wt==="LOCAL"||!wt)?[]:E==="ICU"||E.toLowerCase()==="fluxcu"?Io(_,Je).filter(o=>pi(o.cmd||o)):Io(_,Je)},{cmd:"/wildcard-tooling",desc:"Use if the model lacks Tooling Capability"},{cmd:"/provider",desc:"Select AI Provider"},{cmd:"/mode",desc:"Switch execution mode",subs:[{cmd:"flux",display:"workspace",desc:"Workspace, files & terminal tools"},{cmd:"flow",display:"studio",desc:"Creative studio, documents, PDF & conversation"},{cmd:"icu",display:"computer use",desc:"Interactive desktop & OS automation"},{cmd:"fluxcu",display:"omni",desc:"Autonomous tools & desktop execution"}]},{cmd:"/display",desc:"Select Active Display (Computer Use)",subs:[{cmd:"primary",desc:"Primary Display (Display 1)"},{cmd:"secondary",desc:"Secondary Display (Display 2)"}]},{cmd:"/settings",desc:"Configure system prefs"},{cmd:"/theme",desc:"Customize UI color theme"},{cmd:"/key",desc:"Manage API keys"},{cmd:"/files",desc:"List loaded instruction and skill files"},{cmd:"/profile",desc:"Edit developer persona"},{cmd:"/memory",desc:"Manage agent memory"},{cmd:"/stats",desc:"Show session usage"},{cmd:"/usage",desc:"Open graphical token usage & analytics dashboard in browser"},{cmd:"/reset",desc:"Wipe all project data"},{cmd:"/about",desc:"Project info & credits"},{cmd:"/changelog",desc:"View latest updates"},{cmd:"/docs",desc:"View Documentation"},{cmd:"/fluxflow",desc:"Project management",subs:[{cmd:"global",desc:"Opens the Global FluxFlow Directory in File Explorer"},{cmd:"saves",desc:"Opens FluxFlow AppData Directory in File Explorer"}]},{cmd:"/budget",desc:"Set or View budget limits",subs:[{cmd:"view",desc:"View current usage budget bars"},{cmd:"web",desc:"Open graphical usage and budget dashboard in browser"},{cmd:"set",desc:"Configure budgets (Daily/Monthly limits)"},{cmd:"reset",desc:"Reset budgets to default limits"}]},{cmd:"/update",desc:"Check/Install updates",subs:[{cmd:"latest",desc:"Install latest release"},{cmd:"check",desc:"Check for new version"}]}],di=async(o,n=!1)=>{if(!n&&He.length>0){let u=He[ae]||He[0],b=o.split(" ");if(b.length===1)m(u.cmd+" ");else{let f=b.slice(0,-1);m(f.join(" ")+" "+u.cmd+" ")}fe(0),M(f=>f+1);return}Vr.current=!1;let a=o.replace(/\r\n/g,`
87
- `).replace(/\r/g,`
88
- `).trimEnd();if(a.endsWith("\\")){m(a.slice(0,-1)+`
89
- `);return}let h=a.replace(/\\\s*\n/g,`
90
- `).split(/\r?\n/).map(u=>u.replace(/\\$/,"")).join(`
91
- `);if(h.trim()){if(rn){let u=h.trim();if(u.startsWith("/btw")){if(u.replace(/^\/btw\s*/,"").trim().length<=3){N(f=>(Y(f.length+1),[...f,{id:"hint-err-"+Date.now(),role:"system",text:`\u2726 RESTRICTED
92
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m Inquiry question must be more than 3 characters.
93
- \u2800`,isMeta:!0}])),m("");return}}else if(u.startsWith("/")){N(b=>(Y(b.length+1),[...b,{id:"hint-err-"+Date.now(),role:"system",text:`\u2726 RESTRICTED
94
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m Steering Hints cannot start with '/'.
95
- \u2800`,isMeta:!0}])),m("");return}jr(u),Mo.current=u,N(b=>{Y(b.length+1);let f=u.startsWith("/btw"),d=f?u.replace(/^\/btw\s*/,""):u,T=f?"[QUESTION]":"[STEERING HINT]";return[...b,{id:"hint-"+Date.now(),role:"user",text:`${T}
96
- ${d}`,color:"magenta"}]}),m("");return}if(!wt){li(h),zo("");return}if(h.startsWith("/")){m("");let u=h.split(" "),b=u[0]?.toLowerCase();switch(b){case"/quit":{G("exit");break}case"/resume":{if(u[1]){let f=u[1];(async()=>{let T=await Ao(),I=T[f]||Object.values(T).find(H=>H.name.toLowerCase()===f.toLowerCase());if(I){if(i.write("\x1B[2J\x1B[3J\x1B[H"),process.stdout.isTTY){let z=I?.name||"",Me=z&&!z.startsWith("flow-")&&!z.startsWith("Session ")?z:"FluxFlow | Resumed";process.stdout.write(`\x1B]0;${Me}\x07`),process.stdout.write(`\x1B]633;P;TerminalTitle=${Me}\x07`)}ho(),Go.current=!0,zn(f);let H=await cr(f);wn.current=Qt-H.total,Go.current=!1,pn(H.total),Xo({tokens:H.context});let j=[...I.messages];j[0]?.text?.includes("\u2591\u2591\u2591\u2588\u2588\u2588")||j.unshift({id:"logo-"+Date.now(),role:"system",isLogo:!0,isMeta:!0}),N(j),N(z=>[...z,{id:"sys-"+Date.now(),role:"system",text:`\u2726 SESSION RESUMED
97
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m ${f}.
98
- \u2800`,isMeta:!0}]),Y(0)}else N(H=>[...H,{id:"err-"+Date.now(),role:"system",text:`\u2726 ERROR: Session [${f}] not found.
99
- \u2800`,isMeta:!0}])})()}else G("resume");break}case"/move":{if(!ve.playground){N(I=>(Y(I.length+1),[...I,{id:Date.now(),role:"system",text:`\u2726 RESTRICTED
100
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m '/move' is only available in playground mode.
101
- \u2800`,isMeta:!0}]));break}if(!ve.originalCwd){N(I=>(Y(I.length+1),[...I,{id:Date.now(),role:"system",text:`\u2726 RESTRICTED
102
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m Original CWD not found.
103
- \u2800`,isMeta:!0}]));break}let f=Dt.join(no,"playground"),d=Dt.join(ve.originalCwd,"playground-export");(async()=>{try{N(H=>(Y(H.length+1),[...H,{id:Date.now(),role:"system",text:`\u2726 EXPORTING PLAYGROUND CONTENT
104
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m ${d}
105
- `,isMeta:!0}])),await rt.ensureDir(d);let I=["node_modules",".git",".venv","venv","env",".next","dist","build",".cache"];await rt.copy(f,d,{overwrite:!0,filter:H=>{let j=Dt.relative(f,H);return j?!j.split(Dt.sep).some(z=>I.includes(z)):!0}}),N(H=>(Y(H.length+1),[...H,{id:Date.now(),role:"system",text:`\u2726 SUCCESS
106
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m playground content copied to ${d}
107
- `,isMeta:!0}]))}catch(I){N(H=>(Y(H.length+1),[...H,{id:Date.now(),role:"system",text:`\u2726 FAILED TO MOVE CONTENT
108
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m ${I.message}
109
- `,isMeta:!0}]))}})();break}case"/clear":{if(i&&(i.write("\x1B[2J\x1B[3J\x1B[H"),i.isTTY&&(i.write("\x1B[?2004h"),process.stdout.write("\x1B]0;FluxFlow\x07"),process.stdout.write("\x1B]633;P;TerminalTitle=FluxFlow\x07"))),N([{id:"logo-"+Date.now(),role:"system",isLogo:!0,isMeta:!0}]),Y(1),qr(f=>f+1),ho(),Wt.current={completedIndex:0,columns:X.columns,historicalBlocks:[],seenSelections:new Set,chatId:et,clearKey:Yo+1},ve.playground){if(ve.playground=!1,dr(Cn).catch(()=>{}),ve.originalCwd)try{process.chdir(ve.originalCwd),N(f=>{let d=[...f,{id:"playground-"+Date.now(),role:"system",text:`\u2726 PLAYGROUND
110
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m Restored Working Directory to ${ve.originalCwd}
111
- \u2800`,isMeta:!0}];return Y(d.length),d})}catch{}setTimeout(()=>{rt.emptyDir(Dt.join(no,"playground")).catch(f=>{N(d=>{let T=[...d,{id:"playground-"+Date.now(),role:"system",text:`\u2726 PLAYGROUND
112
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m Failed to clear session: ${no+"/playground"}`,isMeta:!0}];return Y(T.length),T})})},500),Et(f=>({...f,allowExternalAccess:$r.current,memory:Xr.current}))}zn(ss()),Xo({tokens:0}),D(!1),pn(0),wn.current=Qt,setTimeout(()=>{global.gc&&(async()=>{for(let d=0;d<3;d++)global.gc(),await new Promise(T=>setImmediate(T));g.current=Date.now()})()},500);break}case"/revert":{Ln.getChatHistory(et).then(f=>{if(f.length>0)ei(f.reverse()),G("revert");else{let d=qe(2);N(T=>(Y(T.length+1),[...T,{id:"revert-empty-"+Date.now(),role:"system",text:`\u2726 Nothing to revert to.
113
- \u2800`,isMeta:!0}]))}}),setTimeout(()=>{global.gc&&(async()=>{for(let d=0;d<3;d++)global.gc(),await new Promise(T=>setImmediate(T));g.current=Date.now()})()},500);break}case"/mode":{if(u[1]){let f=u[1].toLowerCase(),d="Flux";f==="flow"?d="Flow":f==="icu"?d="ICU":f==="fluxcu"?d="FluxCU":f==="flux"&&(d="Flux"),k(d),d==="Flow"&&_e("Fast");let T=qe(2);N(I=>(Y(I.length+1),[...I,{id:Date.now(),role:"system",text:`\u2726 Mode switched to ${Bs(d)}.
114
- \u2800`,isMeta:!0}]))}else G("mode");break}case"/display":{if(u[1]){let f=u[1].toLowerCase(),d=0;f==="secondary"||f==="1"||f==="2"?d=1:d=0,L(d),kt({display:d}).catch(()=>{});let T=d===0?"Primary (Display 1)":"Secondary (Display 2)";N(I=>(Y(I.length+1),[...I,{id:Date.now(),role:"system",text:`\u2726 Active Computer Use display set to: ${T}.
115
- \u2800`,isMeta:!0}]))}else G("display");break}case"/image_deprecated":{if(u[1]?.toLowerCase()==="stats"){let f=qe(2);if(So.keyType==="Custom")N(d=>(Y(d.length+1),[...d,{id:Date.now(),role:"system",text:"[SYSTEM] Key strategy is Custom. Redirecting to Pollinations dashboard (https://enter.pollinations.ai/#pollen)...",isMeta:!0}])),mo("start https://enter.pollinations.ai/#pollen");else try{let d=await Si();N(T=>(Y(T.length+1),[...T,{id:Date.now(),role:"system",isImageStats:!0,text:`\u2022 Hourly Limit: ${Number((d.limit*1e3).toFixed(0))} credits
116
- \u2022 Spent (Last 1hr): ${Number((d.totalSpent*1e3).toFixed(0))} credits
117
- \u2022 Remaining: ${Number((d.remaining*1e3).toFixed(0))} credits
118
- \u2022 Requests (Last 1hr): ${d.activeCallsCount} requests
119
- `+(d.nextResetMin>0?`\u2022 Refreshes in: ${d.nextResetMin}m`:""),isMeta:!0}]))}catch{N(T=>(Y(T.length+1),[...T,{id:Date.now(),role:"system",text:"[SYSTEM] Failed to load image quota stats.",isMeta:!0}]))}}else if(u[1]?.toLowerCase()==="setup")if(u[2]?.toLowerCase()==="key")if(u[3]){let f=["default","custom"].find(d=>d===u[3].toLowerCase());if(f){let d=f==="default"?"Default":"Custom";Yn(I=>({...I,keyType:d}));let T=qe(2);N(I=>(Y(I.length+1),[...I,{id:Date.now(),role:"system",text:`[SYSTEM] Image key strategy set to ${d}`,isMeta:!0}])),d==="Custom"&&(qt({label:"Enter Pollinations API key (starting with sk_):",note:"Get a key from https://enter.pollinations.ai",key:"imageSettings",subKey:"apiKey",value:So.apiKey||"",returnView:"chat"}),G("input"))}else{let d=qe(2);N(T=>(Y(T.length+1),[...T,{id:Date.now(),role:"system",text:"[SYSTEM] Invalid key option. Choose: Default or Custom.",isMeta:!0}]))}}else{let f=qe(2);N(d=>(Y(d.length+1),[...d,{id:Date.now(),role:"system",text:"[SYSTEM] Usage: /image setup Key <Default|Custom>",isMeta:!0}]))}else if(u[2]?.toLowerCase()==="quality")if(u[3]){let f=["low","low-high","medium","medium-high","high","ultra","premium"].find(d=>d===u[3].toLowerCase());if(f){let T={low:"Low","low-high":"Low-High",medium:"Medium","medium-high":"Medium-High",high:"High",ultra:"Ultra",premium:"Premium"}[f];Yn(H=>({...H,quality:T}));let I=qe(2);N(H=>(Y(H.length+1),[...H,{id:Date.now(),role:"system",text:`[SYSTEM] Image quality set to ${T}`,isMeta:!0}]))}else{let d=qe(2);N(T=>(Y(T.length+1),[...T,{id:Date.now(),role:"system",text:"[SYSTEM] Invalid quality level. Choose from: Low, Low-High, Medium, Medium-High, High, Ultra, Premium.",isMeta:!0}]))}}else{let f=qe(2);N(d=>(Y(d.length+1),[...d,{id:Date.now(),role:"system",text:"[SYSTEM] Usage: /image setup Quality <Low|Low-High|Medium|Medium-High|High|Ultra>",isMeta:!0}]))}else{let f=qe(2);N(d=>(Y(d.length+1),[...d,{id:Date.now(),role:"system",text:"[SYSTEM] Usage: /image setup <Key|Quality> ...",isMeta:!0}]))}else{let f=qe(2);N(d=>(Y(d.length+1),[...d,{id:Date.now(),role:"system",text:"[SYSTEM] Usage: /image setup <Key|Quality> ...",isMeta:!0}]))}break}case"/thinking":{let f;if(u[1]){let d=u[1].toLowerCase(),T=u.includes("--bypass"),I=u.includes("--force");f=d.charAt(0).toUpperCase()+d.slice(1),d==="xhigh"&&(f="xHigh");let H="";if(I&&(process.env.NVIDIA_BASE_URL,H=`\u2800\u2800\x1B[2m\u2514\u2500\x1B[22m Enabled Forced Reasoning.
120
- \u2800`,process.env.forcedReasoning="true"),!T&&E==="Flow"&&f==="xHigh")N(j=>(Y(j.length+1),[...j,{id:Date.now(),role:"system",text:`\u2726 RESTRICTED
121
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m"${f}" is restricted in Flow mode. Switch to Flux to enable Higher Thinking Levels.
122
- \u2800${H}.`,isMeta:!0}]));else{_e(f);let j=qe(1);N(ue=>(Y(ue.length+1),[...ue,{id:Date.now(),role:"system",text:`\u2726 ${_}
123
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m ${ne}.
124
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m Thinking Level: ${f}.
125
- ${H} \u2800`,isMeta:!0}]))}}else G("thinking");break}case"/model":{if(u[1]){let f=u.slice(1),d=!1,T=!1,I=[];for(let j of f)j==="--multimodal"||j==="-m"?_==="Ollama"?d=!0:T=!0:I.push(j);let H=I.join(" ");if(_==="Ollama"&&xi(d),T&&N(j=>(Y(j.length+1),[...j,{id:Date.now(),role:"system",text:`\u2726 ERROR
126
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m Flag --multimodal / -m is unavailable for provider "${_}". Flag ignored.
127
- \u2800`,isMeta:!0}])),H){let j=ro("Google","Free"),ue=ro("Google","Paid");le(H),N(z=>(Y(z.length+1),[...z,{id:Date.now(),role:"system",text:`\u2726 ${_}
128
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m ${H}
129
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m Thinking Level: ${me}${_==="Ollama"?`
130
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m Multimodal: ${d?"ON":"OFF"}`:""}
131
- \u2800`,isMeta:!0}]))}}else G("model");break}case"/wildcard-tooling":{F(f=>{let d=!f;return N(T=>(Y(T.length+1),[...T,{id:Date.now(),role:"system",text:`\u2726 Wildcard Tooling:
132
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m Status: ${d?"Enabled":"Disabled"}
133
- \u2800`,isMeta:!0}])),d});break}case"/settings":{G("settings");break}case"/provider":case"/providers":{vr("chat"),G("selectProvider");break}case"/theme":{G("theme");break}case"/key":{G("key");break}case"/profile":{G("profile");break}case"/stats":{(async()=>{let d=await sr(),T=await ir();Or(d),Pr(T),bn("daily"),G("stats")})();break}case"/usage":{(async()=>{try{let{url:d}=await ts();N(T=>(Y(T.length+1),[...T,{id:Date.now(),role:"system",text:`\u2726 Launching Token Analytics Dashboard
134
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m Serving at ${d}
135
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m Opening in your default browser...
136
- \u2800`,isMeta:!0}]))}catch(d){N(T=>(Y(T.length+1),[...T,{id:Date.now(),role:"system",text:`\u2726 ERROR
137
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m Failed to launch dashboard: ${d.message}
138
- \u2800`,isMeta:!0}]))}})();break}case"/save":{let f,d=ft.find(I=>I.role==="user");if(d&&d.text){let I=d.text.replace(/\s*\n+\s*\[Prompted on:.*?\]/g,"").trim(),H=I.split(/\s+/),j;H.length>7?j=H.slice(0,7).join(" ")+"...":I.length>45?j=I.substring(0,45).trimEnd()+"...":j=I,f=j}let T=u.slice(1).join(" ")||f||`Session ${new Date().toLocaleTimeString()}`;dn(et,T,ft),N(I=>(Y(I.length+1),[...I,{id:Date.now(),role:"system",text:`\u2726 Saved
139
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m "${T}" (ID: ${et})
140
- \u2800`,isMeta:!0}]));break}case"/export":{(async()=>{try{let d=await Ci(u,{chatId:et,messages:ft});N(T=>(Y(T.length+1),[...T,{id:Date.now(),role:"system",text:d.message,isMeta:!0}]))}catch(d){N(T=>(Y(T.length+1),[...T,{id:Date.now(),role:"system",text:`[EXPORT ERROR] Failed to export: ${d.message}`,isMeta:!0}]))}})();break}case"/chats":{(async()=>{let d=await Ao(),T=Object.entries(d).sort((I,H)=>(H[1].updatedAt||0)-(I[1].updatedAt||0)).map(([I,H])=>`\u2800\u2800\x1B[2m\u2514\u2500\x1B[22m ${I}: ${H.name}${I===et?" (current)":""}`).join(`
141
- `);N(I=>(Y(I.length+1),[...I,{id:Date.now(),role:"system",text:`\u2726 Saved Chats:
142
- ${T||"\u2800\u2800\x1B[2m\u2514\u2500\x1B[22m No saved chats found."}
143
- \u2800`,isMeta:!0}]))})();break}case"/memory":{G("memory");break}case"/files":{N(f=>(Y(f.length+1),[...f,{id:"files-"+Date.now(),role:"system",text:ki(),isMeta:!0}]));break}case"/reset":{(async()=>{try{N(d=>(Y(d.length+1),[...d,{id:Date.now(),role:"system",text:`\u2726 Initiating reset...
144
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m Clearing logs, secrets, and settings.
145
- \u2800`,isMeta:!0}])),rt.existsSync(rr)&&rt.removeSync(rr),rt.existsSync(zr)&&rt.removeSync(zr),rt.existsSync(kn)&&rt.removeSync(kn);try{rt.readdirSync(ko).length===0&&rt.removeSync(ko)}catch{}setTimeout(()=>{G("exit"),setTimeout(()=>process.exit(0),500)},500)}catch(d){N(T=>(Y(T.length+1),[...T,{id:Date.now(),role:"system",text:`\u2726 ERROR
146
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m Failed to clear data: ${d.message}.
147
- \u2800`}]))}})();break}case"/about":{let f=qe(2),d=`\u2022 FluxFlow Version: v${oo}
148
- \u2022 Status: ${Vt&&Vt!==oo?`Update Available [v${Vt}]`:"Up to date"}
149
- \u2022 Released on: ${Nd}`;N(T=>(Y(T.length+1),[...T,{id:"about-"+Date.now(),role:"system",text:d,isAboutRecord:!0,isMeta:!0}]));break}case"/changelog":{let f=process.platform;mo(`${f==="win32"?"start":f==="darwin"?"open":"xdg-open"} ${xl}`),N(T=>(Y(T.length+1),[...T,{id:Date.now(),role:"system",text:`\u2726 Opening Changelog
150
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m ${xl}.`,isMeta:!0}]));break}case"/docs":{if(!vs){N(T=>(Y(T.length+1),[...T,{id:Date.now(),role:"system",text:`\u2726 ERROR
151
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m Documentation URL is not configured.`,isMeta:!0}]));break}let f=process.platform;mo(`${f==="win32"?"start":f==="darwin"?"open":"xdg-open"} ${vs}`),N(T=>(Y(T.length+1),[...T,{id:Date.now(),role:"system",text:`\u2726 Opening Documentation
152
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m ${vs}.
153
- \u2800`,isMeta:!0}]));break}case"/budget":{let f=u[1]?.toLowerCase();if(f==="web"||f==="gui"||f==="dashboard")(async()=>{try{let{url:T}=await ts();N(I=>(Y(I.length+1),[...I,{id:Date.now(),role:"system",text:`\u2726 Token Usage & Budget Dashboard
154
- \u2800\u2800\u2514\u2500 Opened at ${T}
155
- \u2800`,isMeta:!0}]))}catch(T){N(I=>(Y(I.length+1),[...I,{id:Date.now(),role:"system",text:`\u2726 ERROR: Failed to launch dashboard: ${T.message}
156
- \u2800`,isMeta:!0}]))}})();else if(f==="set")Tl("chat"),G("budgetTypeSelect");else if(f==="view")(async()=>{let T=await sr(),I=await ir(),H=await es(Ae.resetDay||1);Or(T),Pr(I),Hs(H),G("budgetView")})();else if(f==="reset"){let d={limitMode:"Daily",agentLimit:99999999,tokenLimit:99999999999999,backgroundLimit:999999,searchLimit:100,customModelId:"",customLimit:0,providerBudgets:{},providerTiers:{Google:"Free",DeepSeek:"Free",NVIDIA:"Free",OpenRouter:"Free",CrofAI:"Free",InferX:"Free",SenseNova:"Free",AIHubMix:"Free"}};$t(d),$o("Free"),kt({apiTier:"Free",quotas:d}),N(T=>(Y(T.length+1),[...T,{id:Date.now(),role:"system",text:`\u2726 Budgets reset successfully.
157
- \u2800`,isMeta:!0}]))}else N(d=>(Y(d.length+1),[...d,{id:Date.now(),role:"system",text:`\u2726 ERROR
158
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m Usage: /budget <View|Web|Set|Reset>.
159
- \u2800`,isMeta:!0}]));break}case"/fluxflow":{let d=u.slice(1)[0]?.toLowerCase()?.trim();if(d==="global"){let T=Dt.normalize(ko);try{rt.ensureDirSync(T)}catch{}let I=process.platform;I==="win32"?mo(`explorer "${T}"`):I==="darwin"?mo(`open "${T}"`):mo(`xdg-open "${T}"`)}else if(d==="saves"){let T=Dt.normalize(no);try{rt.ensureDirSync(T)}catch{T=Dt.normalize(ko);try{rt.ensureDirSync(T)}catch{}}let I=process.platform;I==="win32"?mo(`explorer "${T}"`):I==="darwin"?mo(`open "${T}"`):mo(`xdg-open "${T}"`)}else N(T=>(Y(T.length+1),[...T,{id:"ff-err-"+Date.now(),role:"system",text:"Usage: /fluxflow global/saves",isMeta:!0}]));break}case"/update":{if(u[1]?.toLowerCase()==="check"){oe(!0);break}let d=u.includes("--latest");G("update");break}case"/gemini":{let f=Ss[Math.floor(Math.random()*Ss.length)];N(d=>(Y(d.length+1),[...d,{id:Date.now(),role:"system",text:`\u2728 GEMINI CLI
160
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m ${f}
161
- \u2800`}])),m("");break}case"/compress":{m("");let f=ft.filter(I=>(I.role==="user"||I.role==="agent"||I.role==="system")&&!String(I.id).startsWith("welcome")&&!I.isMeta).length,d=fo?.tokens||0;if(f<64||d<16384){let I=qe(2);N(H=>(Y(H.length+1),[...H,{id:Date.now(),role:"system",text:`\u2726 Compression skipped
162
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m History requires at least 64 messages and 16k tokens
163
- \u2800\u2800 \u2514\u2500 Current: ${f}/64 msgs, ${d}/16384 tokens.
164
- \u2800`,isMeta:!0}]));break}(async()=>{Js(!0);let I=qe(2);N(H=>(Y(H.length+1),[...H,{id:Date.now(),role:"system",text:"\u2726 Compacting session history...",isMeta:!0}]));try{if(await _i({chatId:et,aiProvider:_,apiKey:wt,thinkingLevel:me,mode:E,janitorModel:Se,systemSettings:ce,sessionStats:fo},ft)){let ue=qe(2);N(z=>{let Me=[...z,{id:Date.now(),role:"system",text:`\u2800\u2800\x1B[2m\u2514\u2500\x1B[22m Chat History compacted saving tokens.
165
- \u2800`,isMeta:!0}];return Y(Me.length),Me})}else N(ue=>(Y(ue.length+1),[...ue,{id:Date.now(),role:"system",text:`\u2800\u2800\x1B[2m\u2514\u2500\x1B[22m Compaction failed.
166
- \u2800`,isMeta:!0}]))}catch(H){N(j=>(Y(j.length+1),[...j,{id:Date.now(),role:"system",text:`\u2800\u2800\x1B[2m\u2514\u2500\x1B[22m Error during compaction: ${H.message}
167
- \u2800`,isMeta:!0}]))}finally{Js(!1)}})();break}case"/truncate":{m("");let f=0;N(d=>{let I=[...d.map(H=>{let j=H.fullText||H.text||"";return!j.startsWith("[TOOL RESULT]:")||j.startsWith("[TOOL RESULT]: ERROR")||j.startsWith("[TOOL RESULT]: DENIED")||j.includes("...SUCCESS Results Truncated by System on User Command")||j.startsWith("[TOOL RESULT]: Skill:")?H:(f++,j.startsWith("[TOOL RESULT]: SUCCESS")?{...H,fullText:"[TOOL RESULT]: SUCCESS: ...SUCCESS Results Truncated by System on User Command"}:{...H,fullText:"[TOOL RESULT]: ...SUCCESS Results Truncated by System on User Command"})}),{id:Date.now(),role:"system",text:`\u2726 Tool Truncation...
168
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m Truncated ${f} tool result(s).
169
- \u2800`,isMeta:!0}];return dn(et,null,I),Y(I.length),I});break}case"/help":{N(f=>(Y(f.length+1),[...f,{id:Date.now(),role:"system",isHelpRecord:!0,isMeta:!0}]));break}case"/btw":{N(f=>(Y(f.length+1),[...f,{id:Date.now(),role:"system",text:`\u2726 RESTRICTED
170
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m '/btw' only available when agent is working
171
- \u2800`,isMeta:!0}]));break}default:N(f=>(Y(f.length+1),[...f,{id:Date.now(),role:"system",text:`\u2726 ERROR
172
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m Unknown command: '${b}'
173
- \u2800`,isMeta:!0}]))}}else{let u=`[Prompted on: ${new Date().toLocaleString(void 0,{year:"numeric",month:"numeric",day:"numeric",hour:"2-digit",minute:"2-digit"})}]`,b={id:"user-"+Date.now(),role:"user",text:`${h}
174
-
175
- ${u}`};N(d=>(Y(d.length+1),[...d,b])),(async()=>{let d=!1,T=()=>{d||(d=!0,N(ue=>{let z=ue[ue.length-1];if(z&&z.text&&z.text.includes("Request Cancelled"))return ue;let Pe=[...ue.map(J=>J.isStreaming?{...J,isStreaming:!1}:J),{id:"cancel-"+Date.now(),role:"agent",text:`
176
-
177
- \x1B[33m\u24D8 Request Cancelled\x1B[0m`,isMeta:!1}];return Y(Pe.length),Pe}))},I=!1;Yr(!0),Ar(Date.now()),D(!1);let H=Date.now(),j=!0;try{let ue=[...ft,b].filter(U=>U.role!=="think"&&!U.isVisualFeedback&&!U.isMeta&&!U.isTerminalRecord&&!(U.text&&U.text.includes("[TERMINAL_RECORD]"))&&!String(U.id).startsWith("welcome")),z=[],Me=ue.map((U,ge)=>{let Be=U.fullText||U.text||"";if(U.role==="user"&&ge<ue.length-1)if(Be.includes("**CONTEXT SUMMARY OF PREVIOUS TURNS")){let Te=Be.indexOf("**CONTEXT SUMMARY OF PREVIOUS TURNS");if(Te!==-1){let Ke=Be.substring(0,Te).lastIndexOf("[SYSTEM METADATA]");Ke!==-1?Be=Be.substring(Ke).trim():Be=Be.substring(Te).trim()}}else{let Te=Be.lastIndexOf("[USER]"),Ge=Be.lastIndexOf("[USER PROMPT]");Te!==-1?Be=Be.substring(Te+6).trim():Ge!==-1&&(Be=Be.substring(Ge).trim())}return{...U,text:Be}}),Pe=0;for(;Pe<Me.length;){let U=Me[Pe];if(U.role==="user")z.push(U),Pe++;else{let ge=[];for(;Pe<Me.length&&Me[Pe].role!=="user";)ge.push(Me[Pe]),Pe++;let Be=[],Te=[],Ge=null,Ke=!1,Ft=()=>{Be.length>0&&(z.push({role:"agent",text:Be.join(`
178
- `).trim()}),Be=[]),Te.length>0&&(z.push({role:"system",text:Te.join(`
179
-
180
- `),...Ge?{binaryPart:Ge}:{}}),Te=[],Ge=null),Ke=!1};ge.forEach(Tt=>{let xe=Tt.role==="system"&&(Tt.text?.startsWith("[TOOL RESULT]")||Tt.text?.startsWith("SUCCESS:")||Tt.text?.startsWith("ERROR:")||Tt.fullText?.startsWith("[TOOL RESULT]")||Tt.fullText?.startsWith("SUCCESS:")||Tt.fullText?.startsWith("ERROR:")),be=Tt.fullText||Tt.text||"",Oe=be.trim();if(!(!Oe&&!Tt.binaryPart)){if(xe){let Ye=Oe.startsWith("[TOOL RESULT]")?Oe:`[TOOL RESULT]: ${Oe}`;Te.push(Ye),Tt.binaryPart&&(Ge=Tt.binaryPart)}else if(Tt.role==="agent"){!Ke&&Te.length>0&&Ft();let Ye=be.endsWith(`
181
- `),Ct=Oe.toLowerCase().includes("tool:functions.")||Oe.toLowerCase().includes("agent:generalist.");Be.push(Oe),Ct&&Ye?Ke=!0:Ke=!1}}}),Ft()}}let J=Wi(ne,z,{profile:xn,thinkingLevel:me,mode:E,systemSettings:ce,janitorModel:Se,sessionStats:fo,chatId:et,isPlayground:!!ve.playground,aiProvider:_,apiKey:wt,apiTier:Je,wildcardTooling:y,cols:X.columns-6,rows:30,onTokenChunk:(U,ge)=>{let Be=Date.now();if(Ar(Be),typeof ge=="number"){Os.current=ge;let Te=Lr.current;Te.startTime||(Te.startTime=Be,Te.totalWords=0,Te.chunks=[]),Te.totalWords+=ge,Te.chunks||(Te.chunks=[]),Te.chunks.push({time:Be,words:ge});let Ke=Be-400;if(Te.chunks=Te.chunks.filter(Ft=>Ft.time>=Ke),Te.chunks.length>0){let Ft=Te.chunks.reduce((be,Oe)=>be+Oe.words,0),Tt=Te.chunks[0].time,xe=Math.max(.4,(Be-Tt)/1e3);Te.wps=Math.round(Ft/xe*10)/10}}},onVisualFeedback:U=>{N(ge=>[...ge.map(Te=>Te.isStreaming?{...Te,isStreaming:!1}:Te),{id:"visual-"+Date.now()+"-"+Math.random().toString(36).substring(2,9),role:"system",text:U,isVisualFeedback:!0}])},onSubagentUpdate:()=>{Ll(Ui.map(U=>({...U})))},onExecStart:U=>{Ee(),Ce(),Ws(U),on("")},onExecChunk:U=>{on(ge=>ge+U)},onExecEnd:()=>{N(U=>{if(!Jn.current)return U;let ge=_r.current||"",Be=vi(ge),Te=`[TERMINAL_RECORD]
182
- COMMAND: ${Jn.current}
183
- PTY: ${an}
184
- OUTPUT: ${Be.replace(/\n{3,}/g,`
185
-
186
- `)}`,Ke=[...U.map(Ft=>Ft.isStreaming?{...Ft,isStreaming:!1}:Ft),{id:"term-"+Date.now(),role:"system",text:Te,isTerminalRecord:!0}];return Y(Ke.length),Ke}),Ws(null),Gs(!1),on(""),Jn.current=null,_r.current=""},onToolResult:(U,ge)=>{if(U==="success"){if(Ml(Be=>Be+1),ge==="generate_image"){kl(Ge=>Ge+1);let Te={Low:.001,"Low-High":.002,Medium:.008,"Medium-High":.01,High:.045,Ultra:.0488,Premium:.1}[So.quality]||.002;Il(Ge=>Ge+Te)}}else U==="denied"?Dl(Be=>Be+1):Bl(Be=>Be+1)},onToolApproval:async(U,ge)=>{let Be=Pl||ce.autoExec;if(U==="exec_command"){let{command:Te}=An(ge||"{}");return Be||Te&&/^(echo|ls|dir|pwd|cd|git status|git log|git diff|type|cat|help)\b/i.test(Te.trim())?"allow":new Promise(Ke=>{nn({tool:U,args:ge,resolve:Ke}),G("terminalApproval")})}return Be?"allow":new Promise(Te=>{nn({tool:U,args:ge,resolve:Te}),G("approval")})},onAskUser:async(U,ge)=>(Ee(),Ce(),new Promise(Be=>{let Te=!1;Hr({question:U,options:ge,resolve:Ge=>{Te||(Te=!0,N(Ke=>{if(Ke.some(xe=>xe.isAskRecord&&xe.text?.includes(`Selection: ${Ge}`)))return Ke;let Tt=[...Ke,{id:"ask-"+Date.now(),role:"system",text:`\u{1F4AC} **Ask User**
187
- Question: ${U}
188
- Selection: ${Ge}`,isAskRecord:!0}];return Y(Tt.length),Tt}),Be(Ge))}}),G("ask")})),onUsage:U=>{let ge=U.totalTokenCount||0,Be=U.cachedContentTokenCount||0,Te=U.candidatesTokenCount||0;Xo({tokens:ge}),Us(Ge=>Ge+ge),Be>0&&$s(Ge=>Ge+Be),Te>0&&Xs(Ge=>Ge+Te),Ns(Ge=>Ge+1)}},async()=>{if(Mo.current){let U=Mo.current;return jr(null),Mo.current=null,N(ge=>{let Be=[...ge].reverse().findIndex(Te=>Te.text?.includes("[STEERING HINT: QUEUED]")||Te.text?.includes("[QUESTION: QUEUED]"));if(Be!==-1){let Te=ge.length-1-Be,Ge=[...ge],Ke=Ge[Te].text;return Ke.includes("[STEERING HINT: QUEUED]")?Ke=Ke.replace("[STEERING HINT: QUEUED]","[STEERING HINT: INJECTED]"):Ke.includes("[QUESTION: QUEUED]")&&(Ke=Ke.replace("[QUESTION: QUEUED]","[QUESTION: ASKED]")),Ge[Te]={...Ge[Te],text:Ke,color:"cyan"},Ge}return ge}),U}return null},oo),re=!1,tt=null,Ue=null,Xe=!1,ot=!1,At=!1,nt=!1,ct=0,St=null,Do=/\[?\s*turn\s*:\s*.*?\s*\]?/gi;for await(let U of J){if(await new Promise(xe=>setTimeout(xe,3)),U.type==="text"&&Ar(Date.now()),j&&U.type==="text"&&(H=Date.now(),j=!1,ce.progressiveRendering&&Ie()),U.type==="status"){U.content?.includes("[start]")||Wr(U.content),U.content?.includes("[start]")?(clearInterval(vn),Dn(0),vn=setInterval(()=>{Dn(xe=>xe+1)},1e3)):U.content?.includes("[end]")&&(Dn(0),clearInterval(vn)),jo()&&ur(U.content),U.content==="Request Cancelled"&&(Ee(),Ce(),T());continue}if(U.type==="status_history"){Wr(U.content),jo()&&ur(U.content),N(xe=>[...xe,{id:"condense-"+Date.now(),role:"system",text:`\u2726 ${U.content}
189
- \u2800`,isMeta:!0}]);continue}if(U.type==="summary_injected"){N(xe=>xe.map(be=>be.id===U.content.id?{...be,fullText:U.content.text}:be));continue}if(U.type==="spinner"){$l(U.content);continue}if(U.type==="model_update"){Gl(U.content);continue}if(U.type==="turn_reset"){if(Ee(),Ce(),tt=null,Ue=null,re=!1,Xe=!1,ot=!1,nt=!1,At=!1,N(xe=>{let be=xe.map(Oe=>{if(Oe.isStreaming){let Ye=Oe.text?yt(Oe.text):Oe.text,Ct=Oe.fullText?yt(Oe.fullText):Oe.fullText;return{...Oe,isStreaming:!1,text:Ye,fullText:Ct}}return Oe});return Y(be.length),be}),ho(),global.gc){for(let xe=0;xe<2;xe++)global.gc(),await new Promise(be=>setImmediate(be));g.current=Date.now()}continue}if(U.type==="interactive_turn_finished"){Yr(!1),Dn(0),clearInterval(vn),jo()&&ur(null),I=!0,ho(),ce?.autoTruncateResults&&N(xe=>{let be=xe.map(Oe=>{let Ye=Oe.fullText||Oe.text||"";return!Ye.startsWith("[TOOL RESULT]:")||Ye.startsWith("[TOOL RESULT]: ERROR")||Ye.startsWith("[TOOL RESULT]: DENIED")||Ye.includes("...SUCCESS Results Truncated by System on User Command")||Ye.startsWith("[TOOL RESULT]: Skill:")||Ye.includes("Skill: [")?Oe:Ye.startsWith("[TOOL RESULT]: SUCCESS")?{...Oe,fullText:"[TOOL RESULT]: SUCCESS: ...SUCCESS Results Truncated by System on User Command"}:{...Oe,fullText:"[TOOL RESULT]: ...SUCCESS Results Truncated by System on User Command"}});return dn(et,null,be),Y(be.length),be}),Xi({profile:xn,thinkingLevel:me,mode:E,janitorModel:Se,chatId:et,systemSettings:ce,sessionStats:fo,aiProvider:_,apiKey:wt},U.data.agentText,U.data.fullAgentTextRaw,U.data.history,{onMemoryUpdated:()=>N(xe=>{let be=[...xe];return be.length>0&&(be[be.length-1].memoryUpdated=!0),be}),onBackgroundIncrement:()=>Sl(xe=>xe+1)});continue}if(U.type==="visual_feedback"){Ee(),Ce(),N(xe=>{let be=[...xe,{id:"feedback-"+Date.now()+"-"+Math.random().toString(36).substring(2,9),role:"system",text:yt(U.content),isVisualFeedback:!0}];return Y(be.length),be});continue}if(U.type==="exec_start"){Ee(),Ce();continue}if(U.type==="liveTokens"){Xo({tokens:U.content});continue}if(U.type==="usage"){let xe=U.content.totalTokenCount||0,be=U.content.cachedContentTokenCount||0,Oe=U.content.candidatesTokenCount||0;Xo({tokens:xe}),Us(Ye=>Ye+xe),be>0&&$s(Ye=>Ye+be),Oe>0&&Xs(Ye=>Ye+Oe),Ns(Ye=>Ye+1);continue}if(U.type==="tool_time"){El(xe=>xe+U.content);continue}if(U.type==="tool_result"){if(Ce(),tt=null,Ue=null,re=!1,Xe=!1,ot=!1,nt=!1,At=!1,ct=0,St=null,N(xe=>{let be=[...xe,{id:"tool-"+Date.now()+"-"+Math.random().toString(36).substring(2,7),role:"system",text:yt(U.content),fullText:yt(U.aiContent),binaryPart:U.binaryPart,toolName:U.toolName}];return Y(be.length),be}),U.toolName==="update_file"&&U.aiContent){let xe=U.aiContent.split(`
190
- `),be=0,Oe=0,Ye=!1;for(let Ct of xe){if(Ct.includes("[DIFF_START]")){Ye=!0;continue}if(Ct.includes("[DIFF_END]")){Ye=!1;continue}Ye&&(/^\+\d+/.test(Ct)?be++:/^\-\d+/.test(Ct)&&Oe++)}Vo("linesAdded",be),Vo("linesRemoved",Oe)}else if(U.toolName==="write_file"&&U.aiContent){let xe=U.aiContent.match(/- Stats: \[(\d+) lines/),be=xe?parseInt(xe[1]):0,Oe=0;if(U.aiContent.includes("Old File contents:")){let Ye=U.aiContent.split(`
191
- `),Ct=!1;for(let Eo of Ye){if(Eo.includes("Old File contents:")){Ct=!0;continue}Ct&&(Eo.trim()===""?Ct=!1:/^\d+ \|/.test(Eo)&&Oe++)}}Vo("linesAdded",be),Vo("linesRemoved",Oe)}continue}let ge=U.content;if(U.type==="text"&&ge.includes("Request Cancelled")){if(global.gc){for(let xe=0;xe<3;xe++)global.gc(),await new Promise(be=>setImmediate(be));g.current=Date.now()}continue}let Be=ge.toLowerCase();if(ge.includes("```")&&(Xe=!Xe),(Be.includes("tool:functions.")||Be.includes("agent:generalist."))&&(ot=!0,ct=0,St=null,(ge.includes("[tool:functions.")||ge.includes("[agent:generalist."))&&(ct=0)),ot){for(let xe=0;xe<ge.length;xe++){let be=ge[xe];!St&&(be==="'"||be==='"'||be==="`")?St=be:St&&be===St&&ge[xe-1]!=="\\"&&(St=null),St||(be==="("||be==="["?ct++:(be===")"||be==="]")&&ct--)}ct<=0&&!St&&(ot=!1)}let Te=/^\s*(?:<(think|thought|thoughts)[^>]*>|<\|channel>thought|\[(think|thought|thoughts)\])/i,Ge=(xe,be)=>{let Oe=!1;for(let Ye=0;Ye<be;Ye++)xe[Ye]==="`"&&(Oe=!Oe);return Oe},Ke=xe=>{let be=/(?:<\/(think|thought|thoughts)>|<channel\|>|\[\/(think|thought|thoughts)\])/gi,Oe;for(;(Oe=be.exec(xe))!==null;)if(!Ge(xe,Oe.index))return{index:Oe.index,length:Oe[0].length};return{index:-1,length:0}},Ft=V.current?.role==="agent"&&V.current.text||"",Tt=!At&&Ft.trim().length===0;if(!re&&Tt&&(Te.test(ge)||Te.test(Ft+ge))){let xe=Te.test(ge)?ge:Ft+ge,be=xe.match(Te),Oe=be.index,Ye=be[0].length,Ct=xe.substring(Oe+Ye);Ee(),V.current=null,re=!0,At=!0,tt="think-"+Date.now(),V.current={id:tt,role:"think",text:"",isStreaming:!0,startTime:Date.now()};let Eo=Ke(Ct);if(Eo.index!==-1){let ql=Ct.substring(0,Eo.index).replace(/^\r?\n+/,"").replace(/\r?\n+$/,""),ui=Ct.substring(Eo.index+Eo.length);V.current.text=yt(ql);let Ql=V.current.startTime||Date.now();V.current.duration=Date.now()-Ql,Ce(),re=!1,Ue="agent-"+Date.now(),V.current={id:Ue,role:"agent",text:"",isStreaming:!0},ui&&st(ui)}else{let Qr=Ct.replace(/^\r?\n+/,"");Qr&&st(Qr)}continue}if(!re&&!At&&ge.trim().length>0&&(At=!0),re&&V.current?.role==="think"){Ee();let xe=V.current.text+ge,be=Ke(xe);if(be.index!==-1){let Oe=xe.substring(0,be.index),Ye=xe.substring(be.index+be.length);V.current.text=yt(Oe);let Ct=V.current.startTime||Date.now();V.current.duration=Date.now()-Ct,Ce(),re=!1,Ue="agent-"+Date.now(),V.current={id:Ue,role:"agent",text:"",isStreaming:!0},Ye&&st(Ye)}else st(ge);continue}else if(!re){let xe=ge.toLowerCase();!nt&&(xe.includes("tool:functions.")||xe.includes("agent:generalist."))&&(nt=!0),!V.current||V.current.role!=="agent"?(Ue="agent-"+Date.now(),V.current={id:Ue,role:"agent",text:yt(ge),isStreaming:!0},ee()):st(ge)}}let vo=Date.now();vl(U=>U+(vo-H))}catch(ue){N(z=>(Y(z.length+1),[...z,{id:"error-"+Date.now(),role:"system",text:`\u274C ERROR: ${ue.message}`}]))}finally{let ue=Date.now()-H;if(V.current&&(V.current.workedDuration=ue),we.current&&(await Re(),clearInterval(we.current),we.current=null),Yr(!1),Wr(null),Dn(0),clearInterval(vn),Ce(),Vr.current&&T(),ho(),global.gc)try{for(let z=0;z<3;z++)global.gc(),await new Promise(Me=>setImmediate(Me));g.current=Date.now()}catch{}if(I||process.stdout.isTTY&&(process.stdout.write("\x1B]0;FluxFlow | Idle\x07"),process.stdout.write("\x1B]633;P;TerminalTitle=FluxFlow | Idle\x07")),Mo.current){Kr(Mo.current),jr(null);let z=Mo.current;Mo.current=null,N(Me=>{let Pe=[...Me],J=Pe.reverse().find(re=>re.text?.includes("[STEERING HINT: QUEUED]")||re.text?.includes("[QUESTION: QUEUED]"));return J&&(J.text.includes("[STEERING HINT: QUEUED]")?J.text=J.text.replace("[STEERING HINT: QUEUED]","[STEERING HINT: FINISHED_TURN]"):J.text.includes("[QUESTION: QUEUED]")&&(J.text=J.text.replace("[QUESTION: QUEUED]","[QUESTION: FINISHED_TURN]"))),Pe.reverse()}),G("resolution")}N(z=>{let Me=Date.now()-H,Pe=!1,J=[...z].reverse().map(Ue=>{let Xe=Ue.isStreaming?{...Ue,isStreaming:!1}:Ue;return Xe.text&&(Xe.text=(" "+Xe.text).slice(1)),!Pe&&Xe.role==="agent"&&(Pe=!0,Xe={...Xe,workedDuration:Me}),Xe}).reverse();if(!J.some(Ue=>Ue.role==="agent"&&Ue.text?.trim().length>0)){let Ue=[...J].reverse().find(Xe=>Xe.role==="think"&&Xe.text?.trim().length>0);Ue&&J.push({id:"agent-fallback-"+Date.now(),role:"agent",text:Ue.text,isStreaming:!1,workedDuration:Me})}let tt=J.filter(Ue=>!String(Ue.id).startsWith("welcome")&&(!Ue.isMeta||Ue.text&&Ue.text.includes("Request Cancelled")));return dn(et,null,tt),Y(J.length),J})}})()}m(""),D(!1)}},He=fn(()=>{if(v.startsWith("/")&&!Q){let u=v.split(" "),b=u[u.length-1].toLowerCase();if(u.length===1){let d=b.startsWith("/")?b.slice(1):b;return ai.filter(T=>(T.cmd.startsWith("/")?T.cmd.slice(1):T.cmd).toLowerCase().includes(d))}let f=ai;for(let d=0;d<u.length-1;d++){let T=u[d].toLowerCase(),I=f.find(H=>H.cmd.toLowerCase()===T);if(I&&I.subs)f=I.subs;else return[]}return f.filter(d=>d.cmd.toLowerCase().includes(b))}let o=v.split(" "),n=o[o.length-1],a=n&&n.startsWith("\\@");if((n&&n.startsWith("@")||a)&&!Q){let u=n.indexOf("#"),b=u!==-1,f=a?2:1,d=b?n.substring(f,u).toLowerCase():n.slice(f).toLowerCase(),T=b?n.substring(u):"";return Ud(process.cwd()).filter(j=>j.name.toLowerCase().includes(d)).map(j=>{let ue=j.relativePath.replace(/\\/g,"/"),z=ue.startsWith(".")?ue:"./"+ue;return{cmd:(a?"\\@":"@")+"["+z+T+"]",desc:j.relativePath}})}return[]},[v,Q]);Qe(()=>{let o=0;for(;o<He.length;){let n=He[o],a=n?.cmd||n||"";if(typeof a=="string"&&a.trimStart().startsWith("---"))o++;else break}fe(o<He.length?o:0)},[He]);let[or,nr]=q(0),ci=Ve(0);Qe(()=>{let o=ci.current>0,n=He.length>0;if(ci.current=He.length,!n){nr(0);return}if(!o){nr(1);return}nr(He.length)},[He]),Qe(()=>{if(or>0&&or<He.length){let o=setTimeout(()=>{nr(n=>Math.min(n+1,He.length))},5);return()=>clearTimeout(o)}},[or,He.length]),Qe(()=>{if(lt!=="providerBudgetSelect")return;let o=["Google","DeepSeek","Mistral","NVIDIA","OpenRouter","Ollama","CrofAI","InferX","SenseNova","AIHubMix"],n=Ae.providerBudgets||{},a=o.reduce((h,u)=>(h[u]=!!(n[u]&&(n[u].agentLimit||n[u].tokenLimit)),h),{});Is(a),Wn(0)},[lt]),Qe(()=>{if(lt!=="providerBudgetFlow")return;let o={},n=Ae.providerBudgets||{};for(let a of Zo){let h=n[a]||{};o[a]={agentLimit:hn(h.agentLimit),tokenLimit:hn(h.tokenLimit),monthlyTokenLimit:hn(h.monthlyTokenLimit)}}Ir(o),go(0)},[lt,Zo]);let Zd=({label:o,isSelected:n})=>{let a=o==="Cancel"||o==="Back"||o.toLowerCase().includes("exit")||o.toLowerCase().includes("back");return e.createElement(c,{marginTop:a?1:0,backgroundColor:n?"#2a2a2a":void 0,paddingX:1,width:"100%"},e.createElement(s,{color:n?"white":"gray",bold:n},n?"\u276F ":" ",o))},sn=(o,n,a,h=10,u=2,b=9)=>{let f=a>0?Math.min(100,n/a*100):0,d=Math.round(f),T=Math.round(d/100*h),I="\u2588".repeat(T)+"\u2591".repeat(Math.max(0,h-T)),H=l.success||"green";d>=40&&d<=80?H=l.warning||"yellow":d>80&&(H=l.danger||"red");let j=o.toLowerCase().includes("token")||o.toLowerCase().includes("daily")||o.toLowerCase().includes("monthly"),ue=Hn(a)?"\u221E":j?ut(a):a,z=j?ut(n):n,Me;return f===0?Me="0%":f>0&&f<1?Me="<1%":Me=`${d}%`,e.createElement(c,{flexDirection:"row",paddingLeft:u,key:o},e.createElement(c,{width:b},e.createElement(s,{color:l.textMuted},o,": ")),e.createElement(s,{color:H},I),e.createElement(s,{color:l.textMuted}," ",Me," (",z,"/",ue,")"))},Kl=()=>{switch(lt){case"settings":return e.createElement(wr,{systemSettings:ce,setSystemSettings:Et,apiTier:Je,setActiveView:G,setInputConfig:qt,saveSettings:kt,quotas:Ae,setMessages:N,aiProvider:_,setProviderReturnView:vr});case"theme":return e.createElement(wr,{systemSettings:ce,setSystemSettings:Et,apiTier:Je,setActiveView:G,setInputConfig:qt,saveSettings:kt,quotas:Ae,setMessages:N,aiProvider:_,initialSelectingTheme:!0,onCloseTheme:()=>G("chat"),setProviderReturnView:vr});case"selectProvider":return e.createElement(gt,{title:"SELECT AI PROVIDER",searchable:!0,items:[{label:"Google",value:"Google"},{label:"Nvidia",value:"NVIDIA"},{label:"DeepSeek",value:"DeepSeek"},{label:"InferX",value:"InferX"},{label:"SenseNova",value:"SenseNova"},{label:"CrofAI",value:"CrofAI"},{label:"Ollama",value:"Ollama"},{label:"AIHubMix [EXPERIMENTAL]",value:"AIHubMix"},{label:"Mistral [EXPERIMENTAL]",value:"Mistral"},{label:"OpenRouter [EXPERIMENTAL]",value:"OpenRouter"},{label:"Back",value:Jo}],theme:ce.theme,onSelect:async o=>{if(o.value===Jo||o.value==="settings"||o.value==="Back"){G(Jo);return}let n=o.value,a=await ln(n);if(a){vt(n),Kt(a),On(a,{aiProvider:n,onIDEApproval:Zn});let h=(Ae.providerTiers||{})[n]||"Free",u=ro(n,h);le(u),$o(h),n==="NVIDIA"&&process.env.NVIDIA_BASE_URL||n==="Ollama"||n==="CrofAI"||n==="InferX"||n==="SenseNova"?(Et(b=>({...b,memory:!1})),kt({aiProvider:n,activeModel:u,apiTier:h,quotas:Ae,systemSettings:{...ce,memory:!1}})):kt({aiProvider:n,activeModel:u,apiTier:h,quotas:Ae}),N(b=>[...b,{role:"system",text:`\u2726 Switched to ${n} (cached)!${u?`
192
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m Model: ${u}.`:""}${(n==="Ollama"||n==="CrofAI"||n==="InferX"||n==="SenseNova"||n==="AIHubMix")&&ce.memory?`
193
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m Memory is not available with ${n}.`:""}${n==="NVIDIA"&&process.env.NVIDIA_BASE_URL&&ce.memory?`
194
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m Memory is not available with Custom Endpoints.`:""}
195
- \u2800`,isMeta:!0}]),G(Jo)}else qt({label:`Enter ${n} API Key:`,key:"providerKey",provider:n,value:"",returnView:Jo}),G("input")},onClose:()=>G(Jo)});case"apiTier":return e.createElement(gt,{title:`Show Paid models from ${_.toUpperCase()}?`,subtitle:"Curated model list. Can use anything if typed manually.",items:[{label:"No (For Free APIs) [Shows Free model list]",value:"Free"},{label:`Yes (For Billing APIs) [Shows Paid model list] ${Je==="Paid"?"\u25CF":""}`,value:"Paid"},{label:"Back",value:"settings"}],theme:ce.theme,onSelect:o=>{if(o.value==="settings"||o.value==="Back"){G("settings");return}let n=o.value;$o(n);let a={...Ae.providerTiers||{},[_]:n},h={...Ae,providerTiers:a};$t(h),kt({apiTier:n,quotas:h}),G("settings")}});case"resetMode":return e.createElement(gt,{title:"SELECT MONTHLY RESET MODE",items:[{label:"Default (Rolling 30-Day Window)",value:"Rolling"},{label:"Custom (Set reset day of month)",value:"Custom"},{label:"Back",value:"apiTier"}],theme:ce.theme,onSelect:o=>{if(o.value==="apiTier"||o.value==="Back"){G("apiTier");return}let n=o.value,a={...Ae,resetMode:n};$t(a),n==="Custom"?(qt({label:"Enter monthly reset day (1-30):",key:"quotas",subKey:"resetDay",value:String(Ae.resetDay||1),returnView:"settings"}),G("input")):(kt({apiTier:Je,quotas:a}),G("settings"))},onClose:()=>G("apiTier")});case"budgetTypeSelect":return e.createElement(gt,{title:"SELECT BUDGET TYPE",items:[{label:`Global Budget (single limit for all providers) ${Je==="Paid"&&!Ae.providerBudgets?.__useProvider?"\u25CF":""}`,value:"global"},{label:`Provider Budgets (set limits per provider individually) ${Ae.providerBudgets?.__useProvider?"\u25CF":""}`,value:"provider"},{label:"Back",value:yo}],theme:ce.theme,onSelect:o=>{if(o.value===yo||o.value==="Back"){G(yo);return}if(o.value==="global"){let n={...Ae,agentLimit:99999999,tokenLimit:99999999999999,monthlyTokenLimit:99999999999999,providerBudgets:{__useProvider:!1}};$t(n);let a=yo==="settings"?"resetMode":"budgetResetMode";qt({label:"Enter Agent daily budget (requests made):",key:"quotas",subKey:"agentLimit",value:hn(n.agentLimit),returnView:yo,next:h=>({label:"Enter Agent daily budget (tokens used):",key:"quotas",subKey:"tokenLimit",value:hn(h.tokenLimit),returnView:yo,next:u=>({label:"Enter Agent monthly budget (tokens used):",key:"quotas",subKey:"monthlyTokenLimit",value:hn(u.monthlyTokenLimit),returnView:a})})}),G("input")}else if(o.value==="provider"){let n={...Ae,agentLimit:99999999,tokenLimit:99999999999999,monthlyTokenLimit:99999999999999,providerBudgets:{...Ae.providerBudgets||{},__useProvider:!0}};$t(n),G("providerBudgetSelect")}},onClose:()=>G(yo)});case"providerBudgetSelect":{let o=["Google","DeepSeek","Mistral","NVIDIA","OpenRouter","Ollama","CrofAI","InferX","SenseNova"],n=o.some(a=>Er[a]);return e.createElement(c,{flexDirection:"column",borderStyle:"round",borderColor:l.borderMuted,padding:0,width:"100%"},e.createElement(c,{paddingX:1,marginBottom:1},e.createElement(s,{color:l.text,bold:!0},"SELECT PROVIDERS TO SET LIMMITS FOR")),o.map((a,h)=>{let u=h===ks,b=!!Er[a];return e.createElement(c,{key:a,backgroundColor:u?l.highlightBg||"#2a2a2a":void 0,paddingX:1,width:"100%",flexDirection:"row"},e.createElement(s,{color:u?l.text:l.textMuted,bold:u},u?"\u276F ":" "),e.createElement(s,{color:b?l.success||"green":l.textMuted},b?"\u2611":"\u2610"),e.createElement(s,{color:u?l.text:l.textMuted,bold:u}," ",a),b&&Ae.providerBudgets?.[a]?.agentLimit?e.createElement(s,{color:l.primary||"cyan"}," (budget set)"):null)}),e.createElement(c,{paddingX:1,marginTop:1,flexDirection:"column"},e.createElement(s,{color:l.textMuted,italic:!0},"\u2191\u2193 Navigate \u2022 Space to toggle \u2022 Enter to confirm \u2022 ESC to go back"),!n&&e.createElement(s,{color:l.warning||"yellow",italic:!0}," Select at least one provider to continue")))}case"providerBudgetFlow":{let o=Zo.length,n=o*2;return e.createElement(c,{flexDirection:"column",borderStyle:"round",borderColor:l.borderMuted,padding:0,width:"100%"},e.createElement(c,{paddingX:1,marginBottom:0,justifyContent:"space-between",flexDirection:"row"},e.createElement(s,{color:l.text,bold:!0},"PROVIDER BUDGET CONFIGURATION"),e.createElement(s,{color:l.textMuted,italic:!0},"(0 or blank = unlimited)")),e.createElement(c,{paddingX:1,marginTop:1,flexDirection:"row"},e.createElement(c,{width:14},e.createElement(s,{color:l.textMuted,bold:!0},"PROVIDER")),e.createElement(c,{width:30,paddingLeft:1},e.createElement(s,{color:l.textMuted,bold:!0},"DAILY TOKENS (/day)")),e.createElement(c,{width:30,paddingLeft:1},e.createElement(s,{color:l.textMuted,bold:!0},"MONTHLY TOKENS (/month)"))),e.createElement(c,{paddingX:1},e.createElement(s,{color:l.borderMuted},"\u2500".repeat(74))),Zo.map((a,h)=>{let u=h*2,b=h*2+1,f=Gn===u,d=Gn===b,T=f||d,I=kr[a]?.tokenLimit??"",H=kr[a]?.monthlyTokenLimit??"";return e.createElement(c,{key:a,flexDirection:"row",paddingX:1,marginY:0,backgroundColor:T?l.highlightBg||"#2a2a2a":void 0},e.createElement(c,{width:14,flexDirection:"row"},e.createElement(s,{color:T?l.primary||"cyan":l.text,bold:T},T?"\u276F ":" ",a)),e.createElement(c,{width:30,paddingLeft:1,flexDirection:"row"},f?e.createElement(c,{flexDirection:"row"},e.createElement(s,{color:l.primary||"cyan",bold:!0},"[ "),e.createElement(Sr,{value:I,onChange:j=>{Ir(ue=>({...ue,[a]:{...ue[a]||{},tokenLimit:j}}))},onSubmit:()=>{go(b)}}),e.createElement(s,{color:l.primary||"cyan",bold:!0}," ]")):e.createElement(s,{color:I?l.text:l.textMuted},"[ ",I||"0 (Unlimited)"," ]")),e.createElement(c,{width:30,paddingLeft:1,flexDirection:"row"},d?e.createElement(c,{flexDirection:"row"},e.createElement(s,{color:l.primary||"cyan",bold:!0},"[ "),e.createElement(Sr,{value:H,onChange:j=>{Ir(ue=>({...ue,[a]:{...ue[a]||{},monthlyTokenLimit:j}}))},onSubmit:()=>{h+1<o?go((h+1)*2):go(n)}}),e.createElement(s,{color:l.primary||"cyan",bold:!0}," ]")):e.createElement(s,{color:H?l.text:l.textMuted},"[ ",H||"0 (Unlimited)"," ]")))}),e.createElement(c,{paddingX:1,marginTop:1},Gn===n?e.createElement(c,{backgroundColor:l.highlightBg||"#2a2a2a",paddingX:1},e.createElement(s,{color:l.success||"green",bold:!0},"\u276F [ Save & Apply Budgets ]")):e.createElement(s,{color:l.textMuted}," [ Save & Apply Budgets ]")),e.createElement(c,{paddingX:1,marginTop:1,flexDirection:"column"},e.createElement(s,{color:l.textMuted,italic:!0},"\u2191\u2193/\u2190\u2192 Navigate \u2022 Enter next / save \u2022 ESC to go back")))}case"budgetResetMode":return e.createElement(gt,{title:"SELECT MONTHLY RESET MODE",items:[{label:"Default (Rolling 30-Day Window)",value:"Rolling"},{label:"Custom (Set reset day of month)",value:"Custom"},{label:"Back",value:"chat"}],theme:ce.theme,onSelect:o=>{if(o.value==="chat"||o.value==="Back"){G("chat");return}let n=o.value,a={...Ae,resetMode:n};$t(a),n==="Custom"?(qt({label:"Enter monthly reset day (1-30):",key:"quotas",subKey:"resetDay",value:String(Ae.resetDay||1),returnView:"chat"}),G("input")):(kt({apiTier:Je,quotas:a}),G("chat"))},onClose:()=>G("chat")});case"budgetView":{let o=Tn?.agent||0,n=Ae.agentLimit||99999999,a=Tn?.tokens||0,h=Ae.tokenLimit||99999999999999,u=Ae.resetMode==="Custom"?Nr?.tokens||0:Qn?.tokens||0,b=Ae.monthlyTokenLimit||99999999999999,f=Je!=="Paid",d=!!Ae.providerBudgets?.__useProvider,T=Ae.providerBudgets||{},I=["Google","DeepSeek","Mistral","NVIDIA","OpenRouter","Ollama","CrofAI","InferX","SenseNova"].filter(z=>T[z]&&(T[z].agentLimit||T[z].tokenLimit||T[z].monthlyTokenLimit)),H=!d&&(Hn(n)||Hn(h)||Hn(b)),j="",ue="";if(Ae.resetMode==="Custom"){let z=new Date,Me=Ae.resetDay||1,Pe=z.getFullYear(),J=z.getMonth();z.getDate()>=Me&&(J+=1,J>11&&(J=0,Pe+=1));let re=new Date(Pe,J,Me,0,0,0);j=`${re.toLocaleString("default",{month:"short"}).toUpperCase()}-${Me}`;let Ue=Math.max(0,re.getTime()-z.getTime()),Xe=Math.floor(Ue/(1e3*60*60)),ot=Math.floor(Xe/24),At=Xe%24;ue=`(${ot} days: ${At} hrs left)`}return e.createElement(c,{flexDirection:"column",borderStyle:"round",borderColor:l.borderMuted,padding:1,paddingBottom:0,paddingTop:0,width:"100%"},e.createElement(c,{marginBottom:1,justifyContent:"space-between",width:"100%"},e.createElement(s,{color:l.text,bold:!0,underline:!0},"USAGE LIMITS"),e.createElement(s,{color:l.textMuted},"[ ESC to Close ]")),H?e.createElement(c,{padding:1,justifyContent:"center",alignItems:"center",width:"100%"},e.createElement(s,{color:l.text,bold:!0},"LIMITS NOT SET")):d&&I.length>0?e.createElement(c,{flexDirection:"column",gap:0,width:"100%"},(()=>{let z=i?.columns||X?.columns||80;if(z<115){let J=Math.max(5,Math.min(30,z-50));return I.map(re=>{let tt=T[re],Ue=0,Xe=Tn?.models?.[re]||{};for(let ct in Xe)Ue+=Xe[ct]?.tokens||0;let ot=0,nt=(Ae.resetMode==="Custom"?Nr:Qn)?.models?.[re]||{};for(let ct in nt)ot+=nt[ct]?.tokens||0;return e.createElement(c,{key:re,flexDirection:"column",borderStyle:"single",borderColor:l.borderMuted,paddingX:1,width:"100%"},e.createElement(c,{marginBottom:0},e.createElement(s,{color:l.primary,bold:!0},"\u25C6 ",re)),sn("Daily",Ue,tt.tokenLimit||99999999999999,J,2,9),sn("Monthly",ot,tt.monthlyTokenLimit||99999999999999,J,2,9))})}let Pe=[];for(let J=0;J<I.length;J+=2)Pe.push(I.slice(J,J+2));return Pe.map((J,re)=>e.createElement(c,{key:re,flexDirection:"row",width:"100%"},J.map(tt=>{let Ue=T[tt],Xe=0,ot=Tn?.models?.[tt]||{};for(let U in ot)Xe+=ot[U]?.tokens||0;let At=0,ct=(Ae.resetMode==="Custom"?Nr:Qn)?.models?.[tt]||{};for(let U in ct)At+=ct[U]?.tokens||0;let St=J.length===1,Do=St?z:Math.floor(z/2),vo=Math.max(5,Math.min(25,Do-36));return e.createElement(c,{key:tt,flexDirection:"column",borderStyle:"single",borderColor:l.borderMuted,paddingX:1,width:St?"100%":"50%"},e.createElement(c,{marginBottom:0},e.createElement(s,{color:l.primary,bold:!0},"\u25C6 ",tt)),sn("Daily",Xe,Ue.tokenLimit||99999999999999,vo,2,9),sn("Monthly",At,Ue.monthlyTokenLimit||99999999999999,vo,2,9))})))})(),j?e.createElement(c,{marginLeft:2,marginTop:1},e.createElement(s,{color:l.textMuted},"Monthly Reset: "),e.createElement(s,{color:l.accent||"magenta",bold:!0},j),ue?e.createElement(s,{color:l.textMuted},` ${ue}`):null):e.createElement(c,{marginLeft:2,marginTop:1},e.createElement(s,{color:l.textMuted},"Monthly Reset: "),e.createElement(s,{color:l.secondary||"blue",bold:!0},"Rolling 30-Day Window"))):e.createElement(c,{flexDirection:"column",borderStyle:"single",borderColor:l.borderMuted,paddingX:1,width:"100%"},sn("Daily Tokens",a,h,"green"),sn("Monthly Tokens",u,b,"yellow"),j?e.createElement(c,{marginLeft:4,marginTop:1},e.createElement(s,{color:l.textMuted},"Monthly Reset: "),e.createElement(s,{color:l.accent||"magenta",bold:!0},j),ue?e.createElement(s,{color:l.textMuted},` ${ue}`):null):e.createElement(c,{marginLeft:4,marginTop:1},e.createElement(s,{color:l.textMuted},"Monthly Reset: "),e.createElement(s,{color:l.secondary||"blue",bold:!0},"Rolling 30-Day Window"))))}case"input":return e.createElement(c,{flexDirection:"column",borderStyle:"round",borderColor:l.borderMuted,padding:0,width:"100%"},e.createElement(c,{paddingX:1},e.createElement(s,{color:l.text,bold:!0},"DATA CONFIGURATION")),bo?.note&&e.createElement(c,{paddingX:1,marginBottom:1},e.createElement(s,{color:l.textMuted,italic:!0},bo.note)),e.createElement(c,{paddingX:1,flexDirection:"row"},e.createElement(s,{color:l.text,bold:!0},bo?.label," "),e.createElement(Sr,{value:bo?.value||"",onChange:o=>qt(n=>({...n,value:o})),onSubmit:async o=>{let{key:n,subKey:a,next:h,onDone:u}=bo,b={...Ae},f={};if(n==="quotas"){let d=a.toLowerCase().includes("limit")||a==="resetDay"?parseInt(o)||0:o;a==="resetDay"&&(d=Math.max(1,Math.min(30,d))),b[a]=d,$t(b),f.quotas=b}else if(n==="providerBudgets"){let d=bo.providerKey,T=a.toLowerCase().includes("limit")?parseInt(o)||0:o,I=b.providerBudgets||{};b.providerBudgets={...I,[d]:{...I[d]||{},[a]:T}},$t(b),f.quotas=b}else if(n==="activeModel")le(o),f.activeModel=o;else if(n==="janitorModel")$e(o),f.janitorModel=o;else if(n==="autoApproveCommands"||n==="autoDisallowCommands"||n==="alwaysAskCommands"){let d={...ce,[n]:o.trim(),sandboxPreset:"Custom"};Et(d),f.systemSettings=d}else if(n==="externalDataPath"){let d={...ce,useExternalData:!0,externalDataPath:o.trim()};Et(d),f.systemSettings=d,N(T=>[...T,{id:Date.now(),role:"system",text:"[EXTERNAL STORAGE] Flux Flow will use "+o.trim()+" for data after restart."}])}else if(n==="imageSettings"){let d=o.trim();if(d.startsWith("sk_")){let T={...So,apiKey:d};Yn(T),f.imageSettings=T,N(I=>(Y(I.length+1),[...I,{id:Date.now(),role:"system",text:"[IMAGE KEY] Custom API key saved successfully.",isMeta:!0}]))}}else if(n==="providerKey"){let d=o.trim(),T=bo.provider;T==="Ollama"&&(d==="LOCAL"||d==="")&&(d="LOCAL",Et(j=>({...j,ollamaEndpoint:"Local"})),f.systemSettings={...ce,ollamaEndpoint:"Local"}),await Zr(T,d),vt(T),Kt(d),On(d,{aiProvider:T,onIDEApproval:Zn});let I=(Ae.providerTiers||{})[T]||"Free",H=ro(T,I);le(H),$o(I),f.aiProvider=T,f.activeModel=H,f.apiTier=I,(T==="NVIDIA"&&process.env.NVIDIA_BASE_URL||T==="Ollama"||T==="CrofAI"||T==="InferX"||T==="SenseNova")&&(Et(j=>({...j,memory:!1})),f.systemSettings={...ce,memory:!1}),N(j=>(Y(j.length+1),[...j,{id:Date.now(),role:"system",text:`\u2726 ${T} API Key saved successfully! ${H?`
196
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m Model: ${H}`:""}${T==="Ollama"&&d==="LOCAL"?`
197
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m Ollama Endpoint automatically switched to Local`:""}${T==="Ollama"||T==="CrofAI"||T==="InferX"||T==="SenseNova"?`
198
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m Memory is not available with ${T}`:""}${T==="NVIDIA"&&process.env.NVIDIA_BASE_URL?`
199
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m Memory is not available`:""}
200
- \u2800\u2800`,isMeta:!0}]))}if(h){let d=h(n==="quotas"||n==="providerBudgets"?b:o);qt(d)}else u?(kt({...f,apiTier:Je,quotas:b,imageSettings:f.imageSettings||So}),qt(null),u(b)):(kt({...f,apiTier:Je,quotas:b,imageSettings:f.imageSettings||So}),qt(null),G(bo?.returnView||"settings"))}})),e.createElement(c,{paddingX:1,marginTop:1},e.createElement(s,{color:l.textMuted,dimColor:!0,italic:!0},"(Press Enter to confirm selection)")));case"stats":{let o=en==="modelBreakdown"||en==="dailyModelBreakdown",n=en==="daily"||en==="dailyModelBreakdown",a=n?Tn:Qn,h=n?"TODAY's USAGE":"LAST 30 DAYS USAGE",u=n?"TODAY'S MODEL TOKEN BREAKDOWN":"30-DAY MODEL TOKEN BREAKDOWN",b="Wall Time:",f="Tokens Used:",d="Images Made:",T="Image Credits:",I="Code Changes:",H="Tool Calls:",j=Math.max(4,(i?.rows||X?.rows||24)-15),ue=(Ue,Xe,ot,At,nt,ct=0,St=!1)=>{let Do=i?.columns||X?.columns||80,vo=Math.min(125,Do-2),U=Math.max(20,vo-6),ge=Math.max(5,U-ct-ot.length-5),Be=Xe;Be.length>ge&&(Be=Be.substring(0,ge-1)+"\u2026");let Te=Math.max(2,U-ct-Be.length-ot.length-2),Ge=" "+".".repeat(Te)+" ",Ke=" ".repeat(ct);return e.createElement(c,{key:Ue,width:U},e.createElement(s,{wrap:"truncate"},e.createElement(s,null,Ke),e.createElement(s,{color:At,bold:St},Be),e.createElement(s,{color:l.textMuted,dimColor:!0},Ge),e.createElement(s,{color:nt,bold:St},ot)))},z=[],Me=a?.models;if(!Me||Object.keys(Me).length===0)z.push(e.createElement(c,{key:"empty",marginTop:1},e.createElement(s,{color:l.textMuted,italic:!0},"No model token usage recorded for ",n?"today":"the last 30 days",".")));else{let Ue=(yn||"").trim(),Xe="",ot="";if(Ue.includes(":")){let nt=Ue.indexOf(":");Xe=Ue.substring(0,nt).trim().toLowerCase(),ot=Ue.substring(nt+1).trim().toLowerCase()}else Xe=Ue.toLowerCase();let At=Object.entries(Me).sort(([nt],[ct])=>nt.localeCompare(ct,void 0,{sensitivity:"base"})).filter(([nt,ct])=>Xe&&!nt.toLowerCase().includes(Xe)?!1:ot?Object.keys(ct).some(St=>St.toLowerCase().includes(ot)):!0);At.length===0?z.push(e.createElement(c,{key:"no-matches",marginTop:1},e.createElement(s,{color:l.textMuted,italic:!0},'No results found matching "',yn,'".'))):At.forEach(([nt,ct],St)=>{let Do=Object.entries(ct).sort(([U],[ge])=>U.localeCompare(ge,void 0,{sensitivity:"base"})).filter(([U])=>!ot||U.toLowerCase().includes(ot));if(Do.length===0)return;let vo=Do.reduce((U,[,ge])=>U+(ge.tokens||0),0);St>0&&z.length>0&&z.push(e.createElement(c,{key:`space-prov-${nt}`},e.createElement(s,null," "))),z.push(ue(`prov-${nt}`,`${nt}:`,ut(vo),l.primary,l.text,0,!0)),Do.forEach(([U,ge],Be)=>{Be>0&&z.push(e.createElement(c,{key:`space-mod-${nt}-${U}`},e.createElement(s,null," "))),z.push(ue(`mod-${nt}-${U}`,`\xBB ${U}:`,ut(ge.tokens||0),l.secondary,l.text,2,!0)),z.push(ue(`in-${nt}-${U}`,"\xBB Input Tokens:",ut((ge.tokens||0)-(ge.candidateTokens||0)),l.textMuted,l.text,5,!1)),(ge.cachedTokens||0)>0&&z.push(ue(`cache-${nt}-${U}`,"\xBB Cached:",ut(ge.cachedTokens),l.textMuted,l.text,7,!1)),z.push(ue(`out-${nt}-${U}`,"\xBB Output Tokens:",ut(ge.candidateTokens||0),l.textMuted,l.text,5,!1))})})}let Pe=z.length,J=Math.max(0,Pe-j);Ne.current=J;let re=Math.min(Al,J),tt=z.slice(re,re+j);return e.createElement(c,{flexDirection:"column",borderStyle:"round",borderColor:l.borderMuted,paddingX:3,paddingY:1,paddingBottom:0,width:Math.min(125,(i?.columns||100)-2)},o?e.createElement(c,{flexDirection:"column"},e.createElement(c,{justifyContent:"space-between"},e.createElement(s,{color:l.text,bold:!0,underline:!0},u),Pe>j&&e.createElement(s,{color:l.textMuted,dimColor:!0},"[",re+1,"-",Math.min(Pe,re+j)," of ",Pe,"] \u25B2\u25BC")),e.createElement(c,{marginTop:1},e.createElement(s,{color:l.secondary,bold:!0},"Filter (provider:model): "),e.createElement(s,{color:l.text},yn),e.createElement(s,{color:l.primary,bold:!0},"\u258A"),yn.length>0&&e.createElement(s,{color:l.textMuted,dimColor:!0,italic:!0}," (Type to search, Esc/Backspace to clear)")),e.createElement(c,{flexDirection:"column",height:j,marginTop:1},tt)):e.createElement(e.Fragment,null,e.createElement(c,{marginBottom:1},e.createElement(s,{color:l.text,bold:!0,underline:!0},"SESSION TELEMETRY")),e.createElement(c,{flexDirection:"column"},e.createElement(c,null,e.createElement(c,{width:25},e.createElement(s,{color:l.secondary},"Session Duration:")),e.createElement(s,{color:l.text},Ho(Date.now()-Ds))),Ps>0&&e.createElement(e.Fragment,null,e.createElement(c,null,e.createElement(c,{width:25},e.createElement(s,{color:l.secondary},"Model Requests:")),e.createElement(s,{color:l.text},Ps)),e.createElement(c,{marginLeft:2},e.createElement(c,{width:23},e.createElement(s,{color:l.textMuted},"\xBB API Time:")),e.createElement(s,{color:l.text},Ho(jn))),e.createElement(c,{marginLeft:2},e.createElement(c,{width:23},e.createElement(s,{color:l.textMuted},"\xBB Tool Time:")),e.createElement(s,{color:l.text},Ho(Kn)))),Fs>0&&e.createElement(c,null,e.createElement(c,{width:25},e.createElement(s,{color:l.secondary},"Memory Agent:")),e.createElement(s,{color:l.text},Fs)),Qt>0&&e.createElement(e.Fragment,null,e.createElement(c,null,e.createElement(c,{width:25},e.createElement(s,{color:l.secondary},"Tokens Consumed:")),e.createElement(s,{color:l.text},ut(Qt))),e.createElement(c,{marginLeft:2},e.createElement(c,{width:23},e.createElement(s,{color:l.textMuted},"\xBB Input Tokens:")),e.createElement(s,{color:l.text},ut(Qt-Ro))),Vn>0&&e.createElement(c,{marginLeft:4},e.createElement(c,{width:21},e.createElement(s,{color:l.textMuted},"\xBB Cached:")),e.createElement(s,{color:l.text},ut(Vn))),Ro>0&&e.createElement(c,{marginLeft:2},e.createElement(c,{width:23},e.createElement(s,{color:l.textMuted},"\xBB Output Tokens:")),e.createElement(s,{color:l.text},ut(Ro)))),fo?.tokens>0&&e.createElement(c,null,e.createElement(c,{width:25},e.createElement(s,{color:l.secondary},"Active Context:")),e.createElement(s,{color:l.text},ut(fo.tokens))),qn>0&&e.createElement(e.Fragment,null,e.createElement(c,null,e.createElement(c,{width:25},e.createElement(s,{color:l.secondary},"Images Made:")),e.createElement(s,{color:l.text},qn)),e.createElement(c,null,e.createElement(c,{width:25},e.createElement(s,{color:l.secondary},"Image Credits:")),e.createElement(s,{color:l.text},Number(((_s||0)*1e3).toFixed(0))," credits"))),e.createElement(c,null,e.createElement(c,{width:25},e.createElement(s,{color:l.secondary},"Code Changes (Sess):")),e.createElement(s,{color:l.text},e.createElement(s,{color:l.success||"green"},"+",bt.linesAdded)," ",e.createElement(s,{color:l.danger||"red"},"-",bt.linesRemoved))),e.createElement(c,null,e.createElement(c,{width:25},e.createElement(s,{color:l.secondary},"Tool Calls (Sess):")),e.createElement(s,{color:l.text},bt.toolSuccess+bt.toolFailure+bt.toolDenied," ( "),e.createElement(s,{color:l.success||"green"},"\u2714 ",bt.toolSuccess),e.createElement(s,{color:l.text}," "),e.createElement(s,{color:l.warning||"yellow"},"\u{1F6C7} ",bt.toolDenied),e.createElement(s,{color:l.text}," "),e.createElement(s,{color:l.danger||"red"},"\u2718 ",bt.toolFailure),e.createElement(s,{color:l.text}," )"))),e.createElement(c,{flexDirection:"column",marginTop:1},e.createElement(s,{color:l.text,bold:!0,underline:!0},h),e.createElement(c,{marginTop:1},e.createElement(c,{width:25},e.createElement(s,{color:l.secondary},b)),e.createElement(s,{color:l.text},qs(a?.duration||0))),(a?.agent||0)>0&&e.createElement(c,null,e.createElement(c,{width:25},e.createElement(s,{color:l.secondary},"Model Requests:")),e.createElement(s,{color:l.text},a?.agent||0)),(a?.background||0)>0&&e.createElement(c,null,e.createElement(c,{width:25},e.createElement(s,{color:l.secondary},"Memory Agent:")),e.createElement(s,{color:l.text},a?.background||0)),(a?.tokens||0)>0&&e.createElement(e.Fragment,null,e.createElement(c,null,e.createElement(c,{width:25},e.createElement(s,{color:l.secondary},f)),e.createElement(s,{color:l.text},ut(a?.tokens||0))),e.createElement(c,{marginLeft:2},e.createElement(c,{width:23},e.createElement(s,{color:l.textMuted},"\xBB Input Tokens:")),e.createElement(s,{color:l.text},ut((a?.tokens||0)-(a?.candidateTokens||0)))),(a?.cachedTokens||0)>0&&e.createElement(c,{marginLeft:4},e.createElement(c,{width:21},e.createElement(s,{color:l.textMuted},"\xBB Cached:")),e.createElement(s,{color:l.text},ut(a.cachedTokens))),(a?.candidateTokens||0)>0&&e.createElement(c,{marginLeft:2},e.createElement(c,{width:23},e.createElement(s,{color:l.textMuted},"\xBB Output Tokens:")),e.createElement(s,{color:l.text},ut(a.candidateTokens)))),(a?.imageCalls?.length||0)>0&&e.createElement(e.Fragment,null,e.createElement(c,null,e.createElement(c,{width:25},e.createElement(s,{color:l.secondary},d)),e.createElement(s,{color:l.text},a.imageCalls.length)),e.createElement(c,null,e.createElement(c,{width:25},e.createElement(s,{color:l.secondary},T)),e.createElement(s,{color:l.text},Number(((a.imageCalls.reduce((Ue,Xe)=>Ue+Xe.cost,0)||0)*1e3).toFixed(0))," credits"))),e.createElement(c,null,e.createElement(c,{width:25},e.createElement(s,{color:l.secondary},I)),e.createElement(s,{color:l.text},e.createElement(s,{color:l.success||"green"},"+",a?.linesAdded||0)," ",e.createElement(s,{color:l.danger||"red"},"-",a?.linesRemoved||0))),e.createElement(c,null,e.createElement(c,{width:25},e.createElement(s,{color:l.secondary},H)),e.createElement(s,{color:l.text},(a?.toolSuccess||0)+(a?.toolFailure||0)+(a?.toolDenied||0)," ( "),e.createElement(s,{color:l.success||"green"},"\u2714 ",a?.toolSuccess||0),e.createElement(s,{color:l.text}," "),e.createElement(s,{color:l.warning||"yellow"},"\u{1F6C7} ",a?.toolDenied||0),e.createElement(s,{color:l.text}," "),e.createElement(s,{color:l.danger||"red"},"\u2718 ",a?.toolFailure||0),e.createElement(s,{color:l.text}," )")))),e.createElement(s,{color:l.textMuted,dimColor:!0,italic:!0},`
201
- `,"(Press TAB to toggle Today/30-Day views, SPACE to toggle Model Breakdown, ESC to return)"))}case"dynamicDirDanger":return e.createElement(c,{flexDirection:"column",borderStyle:"round",borderColor:l.borderMuted,paddingX:2,paddingY:1,width:"100%"},e.createElement(s,{color:l.warning||"yellow",bold:!0,underline:!0},"DYNAMIC DIRECTORY AWARENESS"),e.createElement(s,{marginTop:1,color:l.text},"Enabling this keeps the agent aware of filesystem state in real time, but may reduce prompt cache efficiency."),e.createElement(s,{color:l.text},`
202
- `,"RECOMMENDED SCENARIOS TO TURN ON:"),e.createElement(s,{color:l.textMuted},"\u2022 Repo is small."),e.createElement(s,{color:l.textMuted},"\u2022 The task benefits from real-time filesystem awareness."),e.createElement(s,{color:l.textMuted},"\u2022 Files are often created, renamed, or deleted."),e.createElement(s,{color:l.textMuted},"\u2022 You know exactly what you're signing up for."),e.createElement(s,{color:l.textMuted},"\u2022 You don't have conflicting decisions regarding token bills."),e.createElement(s,{color:l.textMuted},"\u2022 You want to see your wallet crying at 3am."),e.createElement(c,{marginTop:1},e.createElement(gt,{title:"Confirm Intent",theme:ce.theme,items:[{label:"Turn On Dynamic Directory Awareness",value:"on"},{label:"Keep Off (Recommended)",value:"off"}],onSelect:o=>{o.value==="on"&&Et(n=>{let a={...n,dynamicDirAwareness:!0};return kt({systemSettings:a,apiTier:Je,quotas:Ae}),a}),G("settings")}})));case"dynamicDirHelp":return e.createElement(c,{flexDirection:"column",borderStyle:"round",borderColor:l.borderMuted,paddingX:2,paddingY:1,width:"100%"},e.createElement(s,{color:l.text,bold:!0,underline:!0},"DYNAMIC DIRECTORY AWARENESS \u2014 HELP & EXPLANATION"),e.createElement(s,{color:l.text,bold:!0},`
203
- `,"OFF (Default):"),e.createElement(s,{color:l.textMuted},"\u2022 Takes a static directory snapshot at conversation/session start and places it in System Context."),e.createElement(s,{color:l.textMuted},"\u2022 Prompt cache remains stable across user turns, saving tokens and money."),e.createElement(s,{color:l.text,bold:!0},`
204
- `,"ON:"),e.createElement(s,{color:l.textMuted},"\u2022 Rescans and updates the directory's state dynamically on every single user turn."),e.createElement(s,{color:l.textMuted},"\u2022 Provides real-time filesystem awareness if files are continuously created, renamed, or removed."),e.createElement(s,{color:l.textMuted},"\u2022 Changes Prompt Context on each turn, invalidating part of prompt caches and increasing token usage."),e.createElement(c,{marginTop:1},e.createElement(gt,{title:"Actions",theme:ce.theme,items:[{label:"Back to Settings",value:"back"}],onSelect:()=>G("settings")})));case"autoExecDanger":return e.createElement(c,{flexDirection:"column",borderStyle:"round",borderColor:l.borderMuted,paddingX:2,paddingY:1,width:"100%"},e.createElement(s,{color:l.warning||"yellow",bold:!0,underline:!0},"SECURITY WARNING: YOLO MODE"),e.createElement(s,{marginTop:1,color:l.text},"Turning this ON allows the agent to execute terminal commands automatically without requiring your approval for each step."),e.createElement(s,{marginTop:1,color:l.text,bold:!0},"RISKS INVOLVED:"),e.createElement(s,{color:l.textMuted},"\u2022 The agent may execute destructive commands (rm -rf, etc.) by mistake unless specified in sandbox rules."),e.createElement(s,{color:l.textMuted},"\u2022 Unintended system changes if the agent hallucinates a path or command."),e.createElement(s,{color:l.textMuted},"\u2022 Reduced control over the agent's step-by-step decision making."),e.createElement(c,{marginTop:1},e.createElement(gt,{title:"Confirm Intent",theme:ce.theme,items:[{label:"I know the risk and turning on intentionally",value:"on"},{label:"Keep Off (Recommended)",value:"off"}],onSelect:o=>{o.value==="on"&&Et(n=>({...n,autoExec:!0})),G("settings")}})));case"advanceRollbackDanger":return e.createElement(c,{flexDirection:"column",borderStyle:"round",borderColor:l.borderMuted,paddingX:2,paddingY:1,paddingTop:0,width:"100%"},e.createElement(s,{color:l.warning||"yellow",bold:!0},"\u26A0 Emergency Rollback Notice"),e.createElement(s,{marginTop:1,color:l.text},"When enabled, full repo snapshots exist only during active AI turns."),e.createElement(s,{marginTop:1,color:l.text},"If catastrophic changes occur during a turn, avoid abruptly stopping the agent unless absolutely necessary (external damages out of codebase)."),e.createElement(s,{color:l.textMuted},"The agent may be able to automatically restore the repo to a safe state."),e.createElement(s,{marginTop:1,color:l.textMuted},"Once the turn ends, emergency snapshots are deleted and standard /revert takes over which may not retain full repo content."),e.createElement(s,{marginTop:1,color:l.textMuted},"(Requires Restart to take effect)"),e.createElement(c,{marginTop:1},e.createElement(gt,{title:"Confirm",theme:ce.theme,items:[{label:"I understand and wish to enable",value:"on"},{label:"Keep Off",value:"off"}],onSelect:o=>{o.value==="on"&&Et(n=>({...n,advanceRollback:!0})),G("settings")}})));case"externalDanger":return e.createElement(c,{flexDirection:"column",borderStyle:"round",borderColor:l.borderMuted,paddingX:2,paddingY:1,width:"100%"},e.createElement(s,{color:l.warning||"yellow",bold:!0,underline:!0},"SECURITY WARNING: EXTERNAL WORKSPACE ACCESS"),e.createElement(s,{marginTop:1,color:l.text},"Turning this ON allows the agent to execute tools (Read/Write/Exec) outside of the current active workspace directory."),e.createElement(s,{marginTop:1,color:l.text,bold:!0},"RISKS INVOLVED:"),e.createElement(s,{color:l.textMuted},"\u2022 Access to sensitive system files (SSH keys, Browser data, etc.)"),e.createElement(s,{color:l.textMuted},"\u2022 Potential for accidental or malicious deletion of OS-critical files."),e.createElement(s,{color:l.textMuted},"\u2022 Unauthorized script execution across your entire file system."),e.createElement(c,{marginTop:1},e.createElement(gt,{title:"Confirm Intent",theme:ce.theme,items:[{label:"I know the risk and turning on intentionally",value:"on"},{label:"Keep Off (Recommended)",value:"off"}],onSelect:o=>{o.value==="on"&&Et(n=>({...n,allowExternalAccess:!0})),G("settings")}})));case"doubleDanger":return e.createElement(c,{flexDirection:"column",borderStyle:"round",borderColor:l.borderMuted,paddingX:2,paddingY:1,width:"100%"},e.createElement(s,{color:l.danger||"red",bold:!0,underline:!0},"CRITICAL SECURITY WARNING: COMBINED SYSTEM RISK"),e.createElement(s,{marginTop:1,color:l.text},"You are attempting to enable BOTH [YOLO Mode] and [External Workspace Access] simultaneously."),e.createElement(s,{marginTop:1,color:l.danger||"red",bold:!0},"THIS IS NOT RECOMMENDED."),e.createElement(s,{marginTop:1,color:l.text,bold:!0},"THE CRITICAL RISK:"),e.createElement(s,{color:l.textMuted},"The agent will have the power to execute any command across your entire system WITHOUT your approval or supervision."),e.createElement(s,{color:l.danger||"red",italic:!0,marginTop:1},"A single hallucination or error could result in full system wipe or data theft."),e.createElement(c,{marginTop:1},e.createElement(gt,{title:"Final Confirmation",theme:ce.theme,items:[{label:"I agree knowing the consequences",value:"on"},{label:"Keep Off",value:"off"}],onSelect:o=>{o.value==="on"&&Et(n=>({...n,autoExec:!0,allowExternalAccess:!0})),G("settings")}})));case"key":return e.createElement(gt,{title:"API KEY MANAGEMENT",items:[{label:"Edit Current Key (Update)",value:"edit"},{label:"Remove Current Key (Delete)",value:"remove"},{label:"Cancel",value:"Cancel"}],onSelect:o=>{if(o.value==="edit"){Kt(null),G("chat");let n=qe(2);N(a=>[...a,{id:Date.now(),role:"system",text:`\u2726 Flux waiting for new API Key...
205
- \u2800`}])}else o.value==="remove"?G("deleteKey"):G("chat")}});case"deleteKey":return e.createElement(c,{flexDirection:"column",borderStyle:"round",borderColor:"grey",paddingX:2,paddingY:1},(()=>{let o=qe(2);return e.createElement(s,{color:"white",bold:!0},"DANGER: CLEAR CREDENTIALS")})(),e.createElement(s,{marginTop:1},"This will permanently delete all saved API keys in credential cache. You will need to enter it again to use Flux."),e.createElement(c,{marginTop:1},e.createElement(gt,{title:"Are you sure?",items:[{label:"YES, CLEAR CREDENTIALS",value:"yes"},{label:"NO, GO BACK",value:"no"}],onSelect:async o=>{if(o.value==="yes"){await Ti(),Kt(null),G("chat");let n=qe(2);N(a=>[...a,{id:Date.now(),role:"system",text:"[CREDENTIAL CLEARED] API Key removed successfully."}])}else G("key")},theme:ce.theme})));case"exit":return null;case"ask":return e.createElement(c,{width:"100%"},e.createElement(Ri,{question:_o?.question,options:_o?.options,onResolve:o=>{_o?.resolve&&_o.resolve(o),Hr(null),G("chat")},theme:ce.theme}));case"revert":return e.createElement(c,{width:"100%",alignItems:"center",justifyContent:"center"},e.createElement(Ms,{prompts:Hl,onSelect:async o=>{i&&(i.write("\x1B[2J\x1B[3J\x1B[H"),i.isTTY&&i.write("\x1B[?2004h"));try{let n=await Ln.rollbackToBefore(o);if(n.success){let{targetPrompt:a}=n;Hi(et),qr(d=>d+1),ho(),Wt.current={completedIndex:0,columns:X.columns,historicalBlocks:[],seenSelections:new Set,chatId:et,clearKey:Yo+1};let h=ft.findLastIndex(d=>d.role==="user"&&d.text&&(d.text.startsWith(a)||d.text.includes(a))),u=[...ft];h!==-1&&(u=ft.slice(0,h)),N(u),Y(u.length),m(a),D(a.split(`
206
- `).length>2);let b=u.filter(d=>!String(d.id).startsWith("welcome")&&(!d.isMeta||d.text&&d.text.includes("Request Cancelled")));await dn(et,null,b);let f=qe(2);N(d=>{let T=[...d,{id:"revert-ok-"+Date.now(),role:"system",text:`\u2726 Rollback Successful
207
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m Reverted prompt loaded to input box.
208
- \u2800`,isMeta:!0}];return Y(T.length),T}),G("chat")}}catch(n){let a=qe(2);N(h=>{let u=[...h,{id:"revert-err-"+Date.now(),role:"system",text:`\u2726 ERROR
209
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m ${n.message}
210
- \u2800`,isMeta:!0}];return Y(u.length),u}),G("chat")}},onClose:()=>G("chat"),theme:ce.theme}));case"resume":return e.createElement(c,{width:"100%",alignItems:"center",justifyContent:"center"},e.createElement(ws,{onSelect:async o=>{let n=await Ao();if(n[o]){if(i.write("\x1B[2J\x1B[3J\x1B[H"),process.stdout.isTTY){let b=n[o]?.name||"",f=b&&!b.startsWith("flow-")&&!b.startsWith("Session ")?b:"FluxFlow | Resumed";process.stdout.write(`\x1B]0;${f}\x07`),process.stdout.write(`\x1B]633;P;TerminalTitle=${f}\x07`)}ho(),Go.current=!0,zn(o);let a=await cr(o);wn.current=Qt-a.total,Go.current=!1,pn(a.total),Xo({tokens:a.context});let h=[...n[o].messages];h[0]?.text?.includes("\u2591\u2591\u2591\u2588\u2588\u2588")||h.unshift({id:"logo-"+Date.now(),role:"system",isLogo:!0,isMeta:!0}),N(h),G("chat"),N(b=>{let f=[...b,{id:"sys-"+Date.now(),role:"system",text:`\u2726 SESSION RESUMED
211
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m ${o}
212
- \u2800`,isMeta:!0}];return Y(f.length),f})}},onDelete:async o=>await dr(o),onClose:()=>G("chat"),theme:ce.theme}));case"keybindingsPrompt":return e.createElement(c,{flexDirection:"column",borderStyle:"round",borderColor:"grey",paddingX:2,paddingY:1,width:"100%"},e.createElement(s,{color:"white",bold:!0,underline:!0},"\u2328 CONFIGURE SHIFT+ENTER NEWLINE"),e.createElement(s,{marginTop:1},"To support multi-line inputs with ",e.createElement(s,{bold:!0,color:"white"},"Shift + Enter")," for newline, a terminal sequence keybinding needs to be added to your IDE configuration."),e.createElement(s,{marginTop:1},"Would you like FluxFlow to automatically add this to your ",qo()," keybindings?"),e.createElement(c,{marginTop:1},e.createElement(gt,{title:"Add Keybinding?",items:[{label:"Yes, configure automatically",value:"yes"},{label:"No, skip",value:"no"}],onSelect:async o=>{o.value==="yes"?await Dr(qo()):Cr="\\ + Enter",G("chat")},theme:ce.theme})));case"memory":return e.createElement(c,{width:"100%",alignItems:"center",justifyContent:"center"},e.createElement(bs,{onClose:()=>G("chat"),theme:ce.theme}));case"parserDownload":return e.createElement(c,{width:"100%",alignItems:"center",justifyContent:"center"},e.createElement(ys,{onClose:()=>G("settings")}));case"profile":return e.createElement(hs,{initialData:xn,onSave:o=>{As(o),N(n=>[...n,{id:Date.now(),role:"system",text:`${o.name.length>0||o.nickname.length>0?`\u2726 Profile Updated${o.name.length>0?`
213
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m Name: ${o.name} `:""}${o.nickname.length>0?`
214
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m Nickname: ${o.nickname}`:""}`:`\u2726 Profile
215
- \u2800\u2800\x1B[2m\u2514\u2500\x1B[22m Nothing to Update`}
216
-
217
- \u2726 Custom Instructions
218
- ${o.instructions.length>0?`\u2800\u2800\x1B[2m\u2514\u2500\x1B[22m ${o.instructions.substring(0,30)}${o.instructions.length>30?"...":""}`:"\u2800\u2800\x1B[2m\u2514\u2500\x1B[22m No Instructions Provided."}
219
- \u2800`,isMeta:!0}]),G("chat")},onCancel:()=>G("chat"),theme:ce.theme});case"resolution":return e.createElement(c,{width:"100%",alignItems:"center",justifyContent:"center"},e.createElement(Fd,{data:Wl,theme:ce.theme,onResolve:o=>{Kr(null),G("chat"),setTimeout(()=>{di(o,!0)},500)},onEdit:o=>{Kr(null),G("chat"),m(o)}}));case"approval":return e.createElement(c,{flexDirection:"column",borderStyle:"round",borderColor:"white",paddingX:2,paddingY:1,width:"100%"},e.createElement(s,{color:"white",bold:!0,underline:!0},"FILE WRITE PERMISSION"),e.createElement(s,{marginTop:1},"The agent is attempting to modify: ",e.createElement(s,{color:"cyan"},An(Co?.args||"{}").path||"Unknown File")),jo()?e.createElement(c,{marginTop:1,paddingX:1},e.createElement(s,{color:"cyan",italic:!0},"FluxFlow Companion is active. Review the changes in your editor.")):e.createElement(c,{marginTop:1,borderStyle:"single",borderColor:"#333",paddingX:1,flexDirection:"column"},e.createElement(s,{color:"gray"},"--- PROPOSED CONTENT ---"),(()=>{let o=An(Co?.args||"{}"),n=[],a=new Set;if(Object.keys(o).forEach(b=>{let f=b.match(/^(searchContent|replaceContent|newContent|content_to_replace|content_to_add|TargetContent|ReplacementContent|replacementContent)(\d+)?$/);if(f){let d=f[2]?parseInt(f[2]):1;a.add(d)}}),Array.from(a).sort((b,f)=>b-f).forEach(b=>{let f,d;b===1?(f=o.searchContent1??o.searchContent??o.replaceContent1??o.content_to_replace1??o.replaceContent??o.content_to_replace??o.TargetContent??null,d=o.newContent1??o.content_to_add1??o.newContent??o.content_to_add??o.ReplacementContent??o.replacementContent??null):(f=o[`searchContent${b}`]??o[`replaceContent${b}`]??o[`content_to_replace${b}`]??null,d=o[`newContent${b}`]??o[`content_to_add${b}`]??null),(f!==null||d!==null)&&n.push({replace:f,new:d})}),n.length>0)return e.createElement(c,{flexDirection:"column",marginTop:1},n.map((b,f)=>{let d=b.replace!==null,T=b.new!==null;return e.createElement(c,{key:f,flexDirection:"column",marginTop:f>0?1:0},n.length>1&&e.createElement(s,{color:"gray"},"Block ",f+1,":"),d&&e.createElement(c,null,e.createElement(s,{color:"red",wrap:"anywhere",bold:!0},"- ",b.replace)),T&&e.createElement(c,{marginTop:0},e.createElement(s,{color:"green",wrap:"anywhere",bold:!0},"+ ",b.new.replace(/\[\/n\]?/g,"\\n"))))}));let u=o.content||o.ReplacementContent||o.content_to_add||o.replacementContent||o.newContent||null;return e.createElement(s,{color:"white",wrap:"anywhere"},(u?u.replace(/\[\/n\]?/g,"\\n"):null)||"Updating file content...")})()),e.createElement(c,{marginTop:1},e.createElement(gt,{title:"Action Required",items:[{label:"Accept this time",value:"allow"},{label:"Accept for this session",value:"always"},{label:"Don't accept",value:"deny"}],onSelect:o=>{o.value==="always"&&Nl(!0);let n=o.value==="deny"?"deny":"allow";Co.resolve(n),nn(null),G("chat")},theme:ce.theme})));case"mode":return e.createElement(gt,{title:"SELECT EXECUTION MODE",items:[{label:`Flux (Dev Toolset Mode) ${E==="Flux"?"\u25CF":""}`,value:"Flux"},{label:`Flow (Chat / Conversation Mode) ${E==="Flow"?"\u25CF":""}`,value:"Flow"},{label:`ICU (Interactive Computer Use) ${E==="ICU"?"\u25CF":""}`,value:"ICU"},{label:`FluxCU (Autonomous Flux Computer Use) ${E==="FluxCU"?"\u25CF":""}`,value:"FluxCU"},{label:"Back",value:"chat"}],theme:ce.theme,onSelect:o=>{if(o.value==="chat"||o.value==="Back"){G("chat");return}let n=o.value;k(n),_e(n==="Flow"?"Fast":"High"),N(a=>(Y(a.length+1),[...a,{id:Date.now(),role:"system",text:`\u2726 Mode switched to ${Bs(n)}
220
- \u2800`,isMeta:!0}])),G("chat")},onClose:()=>G("chat")});case"display":return e.createElement(gt,{title:"SELECT ACTIVE DISPLAY FOR COMPUTER USE",items:[{label:`Primary Display (Display 1) ${O===0?"\u25CF":""}`,value:0},{label:`Secondary Display (Display 2) ${O===1?"\u25CF":""}`,value:1},{label:"Back",value:"chat"}],theme:ce.theme,onSelect:o=>{if(o.value==="chat"||o.value==="Back"){G("chat");return}let n=Number(o.value);L(n),kt({display:n}).catch(()=>{});let a=n===0?"Primary (Display 1)":"Secondary (Display 2)";N(h=>(Y(h.length+1),[...h,{id:Date.now(),role:"system",text:`\u2726 Active Computer Use display set to: ${a}`,isMeta:!0}])),G("chat")},onClose:()=>G("chat")});case"updateManager":return e.createElement(gt,{title:"Select Preferred Update Manager",subtitle:"NOTE: If you are unsure about these, go with NPM",items:[{label:"NPM (Standard)",value:"npm"},{label:"PNPM (Recommended)",value:"pnpm"},{label:"BUN (Ultra Fast)",value:"bun"},{label:"YARN (Classic)",value:"yarn"},{label:"Custom Command",value:"custom"},{label:"Back",value:"settings"}],onSelect:o=>{if(o.value==="settings"||o.value==="Back"){G("settings");return}o.value==="custom"?(qt({label:"Enter Custom Update Command (Global install recommended):",key:"customUpdateCommand",value:ce.customUpdateCommand,next:n=>(Et(a=>({...a,updateManager:"custom",customUpdateCommand:n})),null)}),G("input")):(Et(n=>({...n,updateManager:o.value})),G("settings"))},theme:ce.theme});case"update":return e.createElement(nl,{latest:Vt,current:oo,settings:ce,onClose:()=>G("chat"),onSuccess:()=>{N(o=>(Y(o.length+1),[...o,{id:"update-success-"+Date.now(),role:"system",text:`**[UPDATE COMPLETED]** Flux Flow successfully updated to v${Vt}.
221
- **Restart to see changes.**`,isMeta:!0}])),G("chat")},onUpdateSettings:o=>{G("updateManager")}});case"terminalApproval":return e.createElement(c,{flexDirection:"column",borderStyle:"round",borderColor:"white",paddingX:2,paddingY:1,width:"100%"},e.createElement(s,{color:"white",bold:!0,underline:!0},"TERMINAL COMMAND OVERSIGHT"),e.createElement(c,{marginTop:1},e.createElement(s,null,"Agent requested to run: ",e.createElement(s,{color:"yellow",bold:!0},An(Co?.args||"{}").command||"Unknown Command"))),e.createElement(c,{marginTop:1},e.createElement(gt,{title:"Risk Assessment Required",items:[{label:"Run",value:"allow"},{label:"Deny",value:"deny"}],onSelect:o=>{Co.resolve(o.value),nn(null),G("chat")},theme:ce.theme})));default:return e.createElement(c,{flexDirection:"column",marginTop:1,flexShrink:0,width:"100%"},oi&&ti&&e.createElement(c,{flexDirection:"column",borderStyle:"round",borderColor:l.borderMuted,paddingX:2,paddingY:1,width:"100%",marginBottom:1},e.createElement(c,{justifyContent:"space-between",width:"100%"},e.createElement(s,{color:l.text,bold:!0,underline:!0},"INQUIRY RESPONSE"),e.createElement(s,{color:l.textMuted},"[ ESC to Close ]")),e.createElement(c,{marginTop:1,width:"100%"},e.createElement(Nn,{text:ti,columns:X.columns-6,theme:ce.theme}))),Fr.filter(o=>o.status==="running").length>0&&e.createElement(c,{flexDirection:"column",borderStyle:"round",borderColor:l.borderMuted,paddingX:2,paddingY:0,width:"100%",marginBottom:1},e.createElement(c,{justifyContent:"space-between",width:"100%"},e.createElement(s,{color:l.text,bold:!0},"ACTIVE SUBAGENTS")),e.createElement(c,{flexDirection:"column",marginTop:1,width:"100%"},Fr.filter(o=>o.status==="running").map(o=>e.createElement(Xd,{key:o.id,sa:o,showTPMEstimate:ce.showTPMEstimate})))),e.createElement(c,{paddingX:1,marginBottom:0,justifyContent:"space-between",width:"100%"},e.createElement(c,null,Bn?e.createElement(c,{gap:1},e.createElement(Ed,null),e.createElement(_n,{text:Bn.trimEnd(),baseColor:l.textExclusive||l.text,glintColor:l.textMutedExclusive||l.textMuted,speed:60,italic:!0,glintWidth:2,typeSpeed:10}),e.createElement(s,{color:l.textMuted},zs>0?`(${zs.toFixed(0)}s)`:"")):e.createElement(s,{color:l.textMuted,italic:!0},v.length>0&&Rs?"Press ESC again to clear input":Fl?"Press CTRL + O to expand":"Waiting for input...")),e.createElement(c,null,(()=>{let o=Bn?.toLowerCase()??"";return rn&&Date.now()-Ls>15e3&&Fr.length===0&&(o.includes("connecting")||o.includes("working")||o.includes("queue"))?e.createElement(c,null,e.createElement(_n,{text:"Waiting for API",baseColor:l.text,glintColor:l.textMuted,glintWidth:4,speed:80}),e.createElement(s,{color:l.textMuted,dimColor:!0}," \u2503 ")):Gr?e.createElement(c,null,e.createElement(_n,{text:Gr,baseColor:l.text,glintColor:l.textMuted,italic:!0,speed:80,typeSpeed:15}),e.createElement(s,{color:l.textMuted,dimColor:!0}," \u2503 ")):null})(),e.createElement(_n,{text:ne.split("/")[1]||(ne.length>1?ne:"Use '/model model-id' to select model"),baseColor:l.text,glintColor:l.textMuted,glintWidth:3}),e.createElement(s,{color:l.textMuted}," ",ne.length>0?`(${me})`:""),ar>0&&e.createElement(s,{color:l.textMuted}," [",ar," ",ar===1?"file":"files","]"))),e.createElement(c,{flexDirection:"column",width:"100%"},e.createElement(c,{width:"100%",height:1,overflow:"hidden"},e.createElement(s,{color:l.inputBorder},"\u2584".repeat(Math.max(1,X.columns)))),e.createElement(c,{backgroundColor:l.inputBg,paddingX:1,paddingY:0,width:"100%",flexDirection:"column"},e.createElement(c,{flexDirection:"column",width:"100%"},e.createElement(c,{flexDirection:"row",width:"100%",paddingY:0},e.createElement(c,{flexShrink:0,width:4},e.createElement(s,{color:l.inputPrompt,bold:!0},rn||Rn?"\u2726 ":" \u276F ")),e.createElement(c,{flexGrow:1},e.createElement(c,{flexGrow:1,position:"relative"},v===""&&e.createElement(c,{position:"absolute",paddingLeft:0},Rt&&!Mn?e.createElement(s,{color:"yellow"},jl?" Terminal is waiting for user input. Press TAB to interact":" Press TAB to interact with terminal..."):Rt&&Mn?e.createElement(s,{color:"yellow",bold:!0}," [ TERMINAL FOCUSED ] Type to interact, press TAB to exit..."):Rs===1?e.createElement(s,{color:l.inputPrompt,bold:!0}," Press ESC again to ",v.length>0?"clear input":"revert codebase to checkpoint","..."):e.createElement(s,{color:l.inputPlaceholder},Xl?" Press ESC again to cancel the request.":Rn?" Compacting session history, please wait...":rn?" Enter a prompt to steer the agent.":` Send message, @file or /cmd (${Ol.shortcut} for newline)`)),e.createElement(Gi,{key:`input-${B}`,onPasteStateChange:Ul,focus:!Mn&&!Rn,showCursor:Fe&&!Rn,cursorColor:l.inputText,lastFocusEventTime:We.current,value:v,textStyle:{bold:!0,color:l.inputText},columns:X.columns,onChange:o=>{let n=o.replace(/\r\n/g,`
222
- `).replace(/\r/g,`
223
- `).replace(/\\\s*\n/g,`
224
- `);m(n),K(!1)},onSubmit:di,rows:1,maxRows:10,keyBindings:{submit:o=>o.return&&!o.shift&&!o.ctrl,newline:o=>o.return&&o.shift||o.return&&o.ctrl}})))))),e.createElement(c,{width:"100%",height:1,overflow:"hidden"},e.createElement(s,{color:l.inputBorder},"\u2580".repeat(Math.max(1,X.columns))))))}};return e.createElement(c,{flexDirection:"column",width:"100%"},it?null:se?e.createElement(Od,{width:i?.columns||80,height:i?.rows||24,selectedIndex:ye,aiProvider:_,theme:ce.theme}):e.createElement(e.Fragment,null,e.createElement(c,{paddingX:1,flexDirection:"column",width:"100%"},e.createElement(vd,{key:`static-${Yo}-${et}-${X.columns}-${X.rows}-${ce.theme}`,items:ii.completed},o=>e.createElement(hr,{key:o.key,block:o,columns:(i?.columns||80)-2,showFullThinking:Ht,aiProvider:_,version:oo,theme:ce.theme}))),e.createElement(c,{flexDirection:"column",paddingX:1,paddingBottom:0,width:"100%"},(lt==="chat"||["ask","approval","terminalApproval"].includes(lt))&&e.createElement(c,{flexDirection:"column",width:"100%"},ii.active.map(o=>e.createElement(hr,{key:o.key,block:o,columns:Math.max(20,(i?.columns||80)-2),showFullThinking:Ht,aiProvider:_,version:oo,theme:ce.theme})),Rt&&e.createElement(c,{marginTop:1},e.createElement(fr,{command:Rt,output:tn,isFocused:Mn,isPty:an,terminalHeight:X.rows,columns:X.columns}))),it?e.createElement(c,{borderStyle:"double",borderColor:"grey",padding:1,flexShrink:0},e.createElement(s,{color:"white"},"Starting Flux Flow...")):wt?Kl():e.createElement(c,{borderStyle:"round",borderColor:"white",padding:0,flexDirection:"column",flexShrink:0,width:"100%"},e.createElement(c,{paddingX:1,marginBottom:1},e.createElement(s,{color:"gray",bold:!0},"API KEY REQUIRED")),e.createElement(c,{paddingX:1,flexDirection:"column"},dt===0?e.createElement(e.Fragment,null,e.createElement(s,{color:"white"},"Select your Preferred Provider:"),e.createElement(c,{marginTop:1},e.createElement(gt,{searchable:!0,items:[{label:"Google",value:"Google"},{label:"Nvidia",value:"NVIDIA"},{label:"DeepSeek",value:"DeepSeek"},{label:"InferX",value:"InferX"},{label:"SenseNova",value:"SenseNova"},{label:"CrofAI",value:"CrofAI"},{label:"Ollama",value:"Ollama"},{label:"AIHubMix [EXPERIMENTAL]",value:"AIHubMix"},{label:"Mistral [EXPERIMENTAL]",value:"Mistral"},{label:"OpenRouter [EXPERIMENTAL]",value:"OpenRouter"}],onSelect:o=>{vt(o.value),Nt(1)}}))):e.createElement(e.Fragment,null,e.createElement(s,{color:"white"},_==="Ollama"?"Enter Ollama API Key (or type LOCAL to use local host):":`Enter your ${_} API Key:`),e.createElement(c,{marginTop:1},e.createElement(s,{color:"gray",bold:!0}," ",">"," "),e.createElement(Sr,{value:Br,onChange:zo,onSubmit:li,mask:"*"})))),e.createElement(c,{paddingX:1,marginTop:1},e.createElement(s,{color:"gray",italic:!0},dt===0?"(Use arrows to select and Enter to confirm, ESC to go back)":"(Press Enter to confirm and initialize, ESC to go back)"))),x&&e.createElement(c,{borderStyle:"round",borderColor:l.borderMuted,paddingX:1,marginY:0,width:"100%"},e.createElement(s,null,e.createElement(s,{color:"red",bold:!0},"\u{1F534} EXIT: "),e.createElement(s,{color:l.text},"Press "),e.createElement(s,{color:l.text,bold:!0},"CTRL+C"),e.createElement(s,{color:l.text}," again to exit (",w,"s) \u2022 Press "),e.createElement(s,{color:l.textMuted,bold:!0},"ESC"),e.createElement(s,{color:l.text}," to cancel"))),He.length>0&&(()=>{let n=de.current,a=0;for(;a<He.length;){let b=He[a],f=b?.cmd||b||"";if(typeof f=="string"&&f.trimStart().startsWith("---"))a++;else break}ae<=a?n=0:ae<n?n=ae:ae>=n+5&&(n=ae-5+1),n=Math.max(0,Math.min(n,Math.max(0,He.length-5))),de.current=n;let h=He.slice(n,n+5),u=He.length-(n+h.length);return e.createElement(c,{flexDirection:"column",width:"100%",marginBottom:1},e.createElement(c,{paddingX:1,marginBottom:0,justifyContent:"space-between",width:"100%"},e.createElement(s,{color:l.text,bold:!0},He[0]?.cmd?.startsWith("@")||He[0]?.cmd?.startsWith("\\@")?"FILE SUGGESTIONS":"COMMAND SUGGESTIONS"),He[0]?.cmd?.startsWith("@")||He[0]?.cmd?.startsWith("\\@")?e.createElement(s,{color:l.textMuted,italic:!0},"(Use #Lstart-Lend to specify line numbers)"):v.startsWith("/model")&&Je==="Free"?(()=>{let b="https://aistudio.google.com/billing",f="billing";_==="DeepSeek"?(b="https://platform.deepseek.com/usage",f="billing"):_==="OpenRouter"?(b="https://openrouter.ai/settings/profile",f="profile"):_==="NVIDIA"?(b="https://build.nvidia.com/settings/api-keys",f="billing"):_==="CrofAI"&&(b="https://crof.ai",f="account")})():null),h.slice(0,or).map((b,f)=>{let T=n+f===ae,I=typeof b.cmd=="string"&&b.cmd.trimStart().startsWith("---"),H=b.cmd===ro("Google","Free")&&Je!=="Free";return e.createElement(c,{key:b.cmd,flexDirection:"row",backgroundColor:T?l.highlightBg:void 0,paddingX:1},e.createElement(c,{width:3},e.createElement(s,{color:T?l.text:l.textMuted,bold:T},T?" \u276F":" ")),e.createElement(c,{width:55},e.createElement(s,{color:I?l.textDim:H?l.textMuted:T?l.text:l.textDim,bold:!1},b.display||(b.cmd&&(b.cmd.startsWith("@[")||b.cmd.startsWith("\\@["))&&b.cmd.endsWith("]")?(()=>{let ue=(b.cmd.startsWith("\\@[")?b.cmd.slice(3,-1):b.cmd.slice(2,-1)).split(/[/\\]/);return ue[ue.length-1]})():b.cmd&&b.cmd.includes("/")?b.cmd.split("/").pop():b.cmd))),e.createElement(c,{flexGrow:1},e.createElement(s,{color:T?l.text:l.textMuted,italic:!0},b.desc)))}),He.length>5&&e.createElement(c,{paddingX:1,height:1},u>0?e.createElement(s,{color:l.textMuted,dimColor:!0,italic:!0}," ... (",u," more commands available)"):e.createElement(s,{color:l.textMuted,dimColor:!0,italic:!0}," (End of list)")))})(),e.createElement(c,{flexShrink:0,width:"100%"},e.createElement(zi,{mode:E,thinkingLevel:me,tokens:fo.tokens,tokensTotal:Cl,chatId:et,isMemoryEnabled:ce.memory,apiTier:Je,aiProvider:_,activeModel:ne,isProcessing:rn,lastChunkTime:Ls,theme:ce.theme,wps:Lr.current.wps,showTPMEstimate:ce.showTPMEstimate})),lt==="exit"&&(()=>{let o=Date.now()-Ds,n=bt.toolSuccess+bt.toolFailure,a=n>0?(bt.toolSuccess/n*100).toFixed(1):"0.0",h=jn+Kn,u=h>0?(jn/h*100).toFixed(1):"0.0",b=h>0?(Kn/h*100).toFixed(1):"0.0";return e.createElement(c,{flexDirection:"column",borderStyle:"round",paddingX:3,paddingY:1,borderColor:l.borderMuted,width:Math.min(100,(i?.columns||100)-2),marginTop:0,marginBottom:0},e.createElement(c,{marginBottom:1},e.createElement(s,{bold:!0},Id(l.logoGradient||["blue","purple"])("Agent powering down. Goodbye!"))),e.createElement(c,{flexDirection:"column"},e.createElement(s,{color:l.text,bold:!0,underline:!0},"Interaction Summary"),e.createElement(c,{marginTop:1},e.createElement(c,{width:20},e.createElement(s,{color:l.secondary},"Session ID:")),e.createElement(s,{color:l.text},et)),e.createElement(c,null,e.createElement(c,{width:20},e.createElement(s,{color:l.secondary},"Tool Calls:")),e.createElement(s,{color:l.text},bt.toolSuccess+bt.toolFailure+bt.toolDenied," ( ",e.createElement(s,{color:"green"},"\u2714 ",bt.toolSuccess)," ",e.createElement(s,{color:"yellow"},"\u{1F6C7} ",bt.toolDenied)," ",e.createElement(s,{color:"red"},"\u2718 ",bt.toolFailure)," )")),e.createElement(c,null,e.createElement(c,{width:20},e.createElement(s,{color:l.secondary},"Success Rate:")),e.createElement(s,{color:l.text},a,"%")),e.createElement(c,null,e.createElement(c,{width:20},e.createElement(s,{color:l.secondary},"Code Changes:")),e.createElement(s,{color:l.text},e.createElement(s,{color:"green"},"+",bt.linesAdded)," ",e.createElement(s,{color:"red"},"-",bt.linesRemoved))),Qt>0&&e.createElement(e.Fragment,null,e.createElement(c,null,e.createElement(c,{width:20},e.createElement(s,{color:l.secondary},"Tokens Consumed:")),e.createElement(s,{color:l.text},ut(Qt))),e.createElement(c,{marginLeft:2},e.createElement(c,{width:18},e.createElement(s,{color:l.textMuted},"\xBB Input Tokens:")),e.createElement(s,{color:l.text},ut(Qt-Ro))),Vn>0&&e.createElement(c,{marginLeft:4},e.createElement(c,{width:16},e.createElement(s,{color:l.textMuted},"\xBB Cached:")),e.createElement(s,{color:l.text},ut(Vn))),Ro>0&&e.createElement(c,{marginLeft:2},e.createElement(c,{width:18},e.createElement(s,{color:l.textMuted},"\xBB Output Tokens:")),e.createElement(s,{color:l.text},ut(Ro)))),qn>0&&e.createElement(e.Fragment,null,e.createElement(c,null,e.createElement(c,{width:20},e.createElement(s,{color:l.secondary},"Images Made:")),e.createElement(s,{color:l.text},qn)),e.createElement(c,null,e.createElement(c,{width:20},e.createElement(s,{color:l.secondary},"Image Credits:")),e.createElement(s,{color:l.text},Number(((_s||0)*1e3).toFixed(0))," credits")))),e.createElement(c,{flexDirection:"column",marginTop:1},e.createElement(s,{color:l.text,bold:!0,underline:!0},"Performance"),e.createElement(c,{marginTop:1},e.createElement(c,{width:20},e.createElement(s,{color:l.secondary},"Wall Time:")),e.createElement(s,{color:l.text},Ho(o))),e.createElement(c,null,e.createElement(c,{width:20},e.createElement(s,{color:l.secondary},"Agent Active:")),e.createElement(s,{color:l.text},Ho(h))),e.createElement(c,{marginLeft:2},e.createElement(c,{width:18},e.createElement(s,{color:l.textMuted},"\xBB API Time:")),e.createElement(s,{color:l.text},Ho(jn)," (",u,"%)")),e.createElement(c,{marginLeft:2},e.createElement(c,{width:18},e.createElement(s,{color:l.textMuted},"\xBB Tool Time:")),e.createElement(s,{color:l.text},Ho(Kn)," (",b,"%)"))))})())))}export{_d as default};