@oxgeneral/orch 1.0.18 → 1.0.20

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.
@@ -9,7 +9,7 @@ import {b,a as a$2}from'./chunk-3YGXRXS7.js';import {a as a$4}from'./chunk-EWRVH
9
9
  `):[""];j(pe),L(pe.length-1),E(pe[pe.length-1].length);}else if(K.type==="multiselect"){z(0);let ne=I[K.id];pt(ne?new Set(ne.split(",")):new Set);}else {let ne=K.getOptions?.(I)??K.options??[],pe=I[K.id],Q=ne.findIndex(Yt=>Yt.value===pe);z(Q>=0?Q:0);}};if(useInput((R,M)=>{if(_){if(M.escape){y===0?r():an();return}if((M.ctrl||M.meta)&&(R==="v"||R==="i")&&x&&(_.type==="text"||_.type==="textarea")){x();return}if(_.type==="text"){if(De&&Wt.length>0){if(M.upArrow){zt<=0?Ye(false):Ze(k=>k-1);return}if(M.downArrow){Ze(k=>Math.min(Wt.length-1,k+1));return}if(M.return){let k=Wt[zt];k&&b&&b(k.value);return}Ye(false);}if(M.return){let k=S.trim();if(_.required&&!k){Ce(true);return}if(ht!==null){Ce(true),mt(true),Ue.current&&clearTimeout(Ue.current),Ue.current=setTimeout(()=>mt(false),2e3);return}sn(k);return}if(M.downArrow&&_.suggestions&&Wt.length>0){Ye(true),Ze(0);return}if(M.ctrl&&R==="a"){F(0);return}if(M.ctrl&&R==="e"){F(S.length);return}if(M.ctrl&&R==="k"){Ce(true),H(k=>k.slice(0,V));return}if(M.ctrl&&R==="u"){Ce(true),H(k=>k.slice(V)),F(0);return}if(M.ctrl&&R==="w"){Ce(true);let k=Fo(S,V);H(B=>B.slice(0,k)+B.slice(V)),F(k);return}if(M.meta&&(M.leftArrow||R==="b")){F(Fo(S,V));return}if(M.meta&&(M.rightArrow||R==="f")){F(ni(S,V));return}if(M.leftArrow){F(k=>Math.max(0,k-1));return}if(M.rightArrow){F(k=>Math.min(S.length,k+1));return}if(M.backspace||M.delete){if(V===0&&S.length===0&&y>0){an();return}V>0&&(H(k=>k.slice(0,V-1)+k.slice(V)),F(k=>k-1));return}R&&!M.ctrl&&!M.meta&&!M.escape&&(Ce(true),Ye(false),Ze(0),H(k=>k.slice(0,V)+R+k.slice(V)),F(k=>k+R.length));return}if(_.type==="textarea"){if(M.return&&(M.ctrl||M.meta)){let k=P.join(`
10
10
  `).trim();if(_.required&&!k){Ce(true);return}if(ht!==null){Ce(true),mt(true),Ue.current&&clearTimeout(Ue.current),Ue.current=setTimeout(()=>mt(false),2e3);return}sn(k);return}if(M.return){Ce(true),j(k=>{let B=k[O]??"",Z=B.slice(0,N),K=B.slice(N),ye=[...k];return ye.splice(O,1,Z,K),ye}),L(k=>k+1),E(0);return}if(M.ctrl&&R==="a"){E(0);return}if(M.ctrl&&R==="e"){E((P[O]??"").length);return}if(M.ctrl&&R==="k"){Ce(true),j(k=>{let B=[...k];return B[O]=(B[O]??"").slice(0,N),B});return}if(M.ctrl&&R==="u"){Ce(true),j(k=>{let B=[...k];return B[O]=(B[O]??"").slice(N),B}),E(0);return}if(M.ctrl&&R==="w"){Ce(true);let k=O,B=N;j(Z=>{let K=Z[k]??"",ye=Fo(K,B),ne=[...Z];return ne[k]=K.slice(0,ye)+K.slice(B),E(ye),ne});return}if(M.meta&&(M.leftArrow||R==="b")){E(Fo(P[O]??"",N));return}if(M.meta&&(M.rightArrow||R==="f")){E(ni(P[O]??"",N));return}if(M.upArrow){if(Ke>0){let k=Ae[Ke],B=Ae[Ke-1],Z=N-(k?.startCol??0),K=Math.min(B.startCol+Z,B.startCol+B.text.length);L(B.logicalRow),E(K);}return}if(M.downArrow){if(Ke<Ae.length-1){let k=Ae[Ke],B=Ae[Ke+1],Z=N-(k?.startCol??0),K=Math.min(B.startCol+Z,B.startCol+B.text.length);L(B.logicalRow),E(K);}return}if(M.leftArrow){N>0?E(k=>k-1):O>0&&(L(k=>k-1),E((P[O-1]??"").length));return}if(M.rightArrow){let k=(P[O]??"").length;N<k?E(B=>B+1):O<P.length-1&&(L(B=>B+1),E(0));return}if(M.backspace||M.delete){if(N===0&&O===0)return;if(N>0)j(k=>{let B=[...k],Z=B[O]??"";return B[O]=Z.slice(0,N-1)+Z.slice(N),B}),E(k=>k-1);else {let k=(P[O-1]??"").length;j(B=>{let Z=[...B],K=Z[O-1]??"",ye=Z[O]??"";return Z.splice(O-1,2,K+ye),Z}),E(k),L(B=>B-1);}return}if(R&&!M.ctrl&&!M.meta&&!M.escape){Ce(true);let k=R.split(/\r?\n/);if(k.length===1)j(B=>{let Z=[...B],K=Z[O]??"";return Z[O]=K.slice(0,N)+R+K.slice(N),Z}),E(B=>B+R.length);else {let B=O,Z=N;j(K=>{let ye=[...K],ne=ye[B]??"",pe=ne.slice(0,Z),Q=ne.slice(Z),Yt=k[0]??"",ve=k[k.length-1]??"",rr=[pe+Yt,...k.slice(1,-1),ve+Q];return ye.splice(B,1,...rr),ye}),L(B+k.length-1),E((k[k.length-1]??"").length);}}return}if(_.type==="select"||_.type==="multiselect"){if(M.upArrow||R==="k"){z(k=>Math.max(0,k-1));return}if(M.downArrow||R==="j"){z(k=>Math.min(Rt.length-1,k+1));return}if(M.backspace||M.delete){an();return}if(_.type==="select"){if(M.return||M.tab){let k=Rt[Gt];if(k){if(_.validate){let B=_.validate(k.value);if(B!==null){Ce(true),xt(B),mt(true),Ue.current&&clearTimeout(Ue.current),Ue.current=setTimeout(()=>mt(false),2e3);return}}sn(k.value);}return}if(R>="1"&&R<="9"){let k=parseInt(R,10)-1;if(k<Rt.length){let B=Rt[k];B&&sn(B.value);}return}}else {if(R===" "){let k=Rt[Gt];k&&pt(B=>{let Z=new Set(B);return Z.has(k.value)?Z.delete(k.value):Z.add(k.value),Z});return}if(M.return){let k=Array.from(ut).join(",");sn(k);return}}}}}),!_)return null;let nt=rn?ht:null,Wn=Math.max(20,l-6),At=`${y+1}/${le}`,Kt=Math.max(2,f-4),ln=0;Gt>=Kt&&(ln=Gt-Kt+1);let zn=Rt.slice(ln,ln+Kt);return jsxs(Box,{flexDirection:"column",paddingX:2,children:[jsxs(Box,{children:[jsx(Text,{color:e.amber,bold:true,children:t}),jsxs(Text,{color:e.ghost,children:[" ",Ve,Ve," "]}),jsxs(Text,{color:e.dim,children:["step ",At]})]}),jsxs(Box,{children:[jsx(Text,{children:" "}),X.map((R,M)=>jsxs(Text,{color:M===y?e.amber:M<y?e.green:e.ghost,children:[M===y?"\u25CF":M<y?"\u2713":"\u25CB"," "]},R.id))]}),jsxs(Box,{marginTop:0,children:[jsxs(Text,{color:e.white,bold:true,children:[" ",_.label]}),_.required&&jsx(Text,{color:e.red,children:" *"}),!_.required&&jsxs(Text,{color:e.dim,children:[" (optional, ",_.type==="textarea"?`${Er}+Enter`:"Enter"," to skip)"]})]}),_.description&&jsx(Box,{children:jsxs(Text,{color:e.dim,children:[" ",_.description]})}),_.type==="text"&&jsxs(Box,{flexDirection:"column",children:[jsxs(Box,{borderStyle:nt?"round":void 0,borderColor:nt?e.red:void 0,children:[jsxs(Text,{color:e.amber,children:[" ",">"," "]}),S.length>0?jsxs(Fragment,{children:[jsx(Text,{color:e.white,children:S.slice(0,V)}),jsx(Text,{color:e.amber,children:Do}),jsx(Text,{color:e.white,children:S.slice(V)})]}):_.placeholder?jsxs(Fragment,{children:[jsx(Text,{color:e.ghost,children:_.placeholder}),jsx(Text,{color:e.amber,children:Do})]}):jsx(Text,{color:e.amber,children:Do})]}),nt&&jsxs(Text,{color:e.red,dimColor:true,children:[" ",nt]}),qt&&jsx(Text,{color:e.red,children:" Fix the error above"})]}),_.type==="text"&&_.suggestions&&Wt.length>0&&(()=>{let R=Math.max(2,f-6),M=0;De&&zt>=R&&(M=zt-R+1);let k=Wt.slice(M,M+R);return jsxs(Box,{flexDirection:"column",children:[jsxs(Text,{color:e.ghost,children:[" ",Ve,Ve,Ve," or browse templates ",Ve.repeat(Math.max(0,Wn-28))]}),k.map((B,Z)=>{let K=Z+M,ye=De&&K===zt;return jsxs(Box,{children:[jsx(Text,{color:ye?e.amber:e.ghost,children:ye?" \u25B8 ":" "}),jsx(Text,{color:ye?e.white:e.silver,bold:ye,children:B.label}),B.hint&&jsxs(Text,{color:e.dim,wrap:"truncate",children:[" ",Ve," ",B.hint.replace(/\n/g," ")]})]},B.value)})]})})(),_.type==="textarea"&&(()=>{let R=Math.max(3,f-6),M=0;Ke>=R&&(M=Ke-R+1);let k=Ae.slice(M,M+R);return jsxs(Box,{flexDirection:"column",children:[jsxs(Box,{flexDirection:"column",borderStyle:nt?"round":void 0,borderColor:nt?e.red:void 0,children:[k.map((B,Z)=>{let K=Z+M,ye=B.isFirst?String(B.logicalRow+1).padStart(Ft," "):"".padStart(Ft," "),ne=K===Ke,pe=N-B.startCol;return jsxs(Box,{children:[jsxs(Text,{color:e.dim,children:[" ",ye," "]}),jsxs(Text,{color:e.ghost,children:["\u2502"," "]}),ne?jsxs(Fragment,{children:[jsx(Text,{color:e.white,children:B.text.slice(0,pe)}),jsx(Text,{color:e.amber,children:Do}),jsx(Text,{color:e.white,children:B.text.slice(pe)})]}):jsx(Text,{color:e.silver,children:B.text||(B.isFirst?" ":"")})]},`${B.logicalRow}-${B.startCol}`)}),P.length===1&&P[0]===""&&_.placeholder&&jsx(Box,{children:jsxs(Text,{color:e.dim,children:[" ","".padStart(Ft," ")," ",_.placeholder]})})]}),nt&&jsxs(Text,{color:e.red,dimColor:true,children:[" ",nt]}),qt&&jsx(Text,{color:e.red,children:" Fix the error above"})]})})(),_.type==="select"&&jsxs(Box,{flexDirection:"column",children:[zn.map((R,M)=>{let k=M+ln,B=k===Gt,Z=String(k+1).padStart(Rt.length>=10?2:1);return jsxs(Box,{children:[jsx(Text,{color:B?e.amber:e.ghost,children:B?" \u25B8 ":` ${Z} `}),jsx(Text,{color:B?e.white:e.silver,bold:B,children:R.label}),R.hint&&jsxs(Text,{color:e.dim,wrap:"truncate",children:[" ",Ve," ",R.hint.replace(/\n/g," ")]})]},R.value)}),nt&&jsxs(Text,{color:e.red,dimColor:true,children:[" ",nt]}),qt&&jsx(Text,{color:e.red,children:" Fix the error above"})]}),_.type==="multiselect"&&jsxs(Box,{flexDirection:"column",children:[zn.map((R,M)=>{let B=M+ln===Gt,Z=ut.has(R.value);return jsxs(Box,{children:[jsx(Text,{color:B?e.amber:e.ghost,children:B?" \u25B8 ":" "}),jsx(Text,{color:Z?e.green:e.dim,children:Z?"[\u2713]":"[ ]"}),jsxs(Text,{color:B?e.white:e.silver,bold:B,children:[" ",R.label]}),R.hint&&jsxs(Text,{color:e.dim,wrap:"truncate",children:[" ",Ve," ",R.hint.replace(/\n/g," ")]})]},R.value)}),ut.size>0&&jsx(Box,{children:jsxs(Text,{color:e.dim,children:[" ","\u2514"," ",ut.size," selected"]})})]}),jsxs(Box,{marginTop:0,children:[jsxs(Text,{color:e.ghost,children:[" ",_.type==="select"?"\u2191\u2193 select Enter confirm":_.type==="multiselect"?"\u2191\u2193 move Space toggle Enter confirm":_.type==="textarea"?`Enter newline ${Er}+Enter confirm \u2190\u2191\u2192\u2193 navigate`:De?"\u2191\u2193 browse Enter select \u2191 back to input":_.suggestions?"\u2190\u2192 move Enter confirm \u2193 browse templates":"\u2190\u2192 move Enter confirm",x&&(_.type==="text"||_.type==="textarea")?` ${Er}+V paste image`:""," Esc ",y>0?"back":"cancel"]}),T&&jsxs(Text,{color:e.amber,children:[" ",T]})]})]})}var ii=io.memo(function({agents:n,selected:o,msgCounts:r,colorMap:l,maxHeight:f,onConfirm:x,onCancel:T}){let [b,y]=useState(0),[C,I]=useState(()=>new Set(o));useMemo(()=>C.size===0||C.size===n.length,[C.size,n.length]);let S=Math.max(3,f-5),H=useMemo(()=>{if(n.length<=S)return 0;let P=Math.floor(S/2),j=n.length-S;return Math.min(j,Math.max(0,b-P))},[b,n.length,S]),V=n.slice(H,H+S);useInput((P,j)=>{if(j.upArrow){y(O=>O>0?O-1:n.length-1);return}if(j.downArrow){y(O=>O<n.length-1?O+1:0);return}if(P===" "){let O=n[b];if(!O)return;I(L=>{let N=new Set(L);return N.has(O.id)?N.delete(O.id):N.add(O.id),N});return}if(P==="a"||P==="A"){I(O=>new Set);return}if(j.return){x(new Set(C));return}if(j.escape){T();return}});let F=C.size===0?n.length:C.size;return jsxs(Box,{flexDirection:"column",borderStyle:"round",borderColor:e.amber,paddingX:1,children:[jsxs(Box,{gap:1,children:[jsx(Text,{color:e.amber,bold:true,children:" \u25C8 Agent Filter"}),jsxs(Text,{color:e.dim,children:[ge," ",F,"/",n.length," selected"]})]}),jsx(Text,{color:e.ghost,children:Ve.repeat(36)}),V.map((P,j)=>{let L=j+H===b,N=C.size===0||C.has(P.id),E=l.get(P.id)??e.silver,W=r.get(P.id)??0;return jsxs(Box,{gap:0,children:[jsx(Text,{color:L?e.amber:e.ghost,children:L?" \u25B8 ":" "}),jsx(Text,{color:N?e.green:e.ghost,children:N?"[\u2713]":"[ ]"}),jsxs(Text,{color:L?E:N?e.silver:e.dim,bold:L,children:[" ",P.name]}),W>0&&jsxs(Text,{color:e.dim,children:[" ",ge,W]})]},P.id)}),n.length>S&&jsxs(Text,{color:e.ghost,children:[" ",H>0?"\u2191":" "," ",H+S<n.length?"\u2193":" "," ",b+1,"/",n.length]}),jsx(Text,{color:e.ghost,children:Ve.repeat(36)}),jsxs(Text,{color:e.dim,children:[" Space toggle"," ",ge," ","a all"," ",ge," ","Enter confirm"," ",ge," ","Esc cancel"]})]})});var tc={system:"\u2666",lifecycle:"\u25B6",output:"\u2502",tool:"\u2699",result:"\u2190",error:"\u2715",file:"\u270E",info:"\u2502"},nc={system:"System",lifecycle:"Lifecycle",output:"Output",tool:"Tool calls",result:"Results",error:"Errors",file:"Files",info:"Info"},oc={system:e.purple,lifecycle:e.cyan,output:e.white,tool:e.blue,result:e.green,error:e.red,file:e.purple,info:e.silver},wt=["system","lifecycle","output","tool","result","error","file","info"],ci=[{key:"1",label:"all",types:wt},{key:"2",label:"text",types:["output"]},{key:"3",label:"tools",types:["tool","result","file"]},{key:"4",label:"errors",types:["error"]},{key:"5",label:"events",types:["lifecycle","system"]}],di=io.memo(function({selected:n,typeCounts:o,onConfirm:r,onCancel:l}){let[f,x]=useState(0),[T,b]=useState(()=>new Set(n)),y=useMemo(()=>T.size===wt.length||wt.every(I=>T.has(I)),[T]);useInput((I,$)=>{if($.upArrow){x(S=>S>0?S-1:wt.length-1);return}if($.downArrow){x(S=>S<wt.length-1?S+1:0);return}if(I===" "){let S=wt[f];if(!S)return;b(H=>{let V=new Set(H);return V.has(S)?V.delete(S):V.add(S),V});return}if(I==="a"||I==="A"){b(S=>S.size===wt.length?new Set:new Set(wt));return}for(let S of ci)if(I===S.key){b(new Set(S.types));return}if($.return){let S=T.size===0?new Set(wt):new Set(T);r(S);return}if($.escape){l();return}});let C=y?wt.length:T.size;return jsxs(Box,{flexDirection:"column",borderStyle:"round",borderColor:e.amber,paddingX:1,children:[jsxs(Box,{gap:1,children:[jsx(Text,{color:e.amber,bold:true,children:" \u25C8 Type Filter"}),jsxs(Text,{color:e.dim,children:[ge," ",C,"/",wt.length," selected"]})]}),jsx(Text,{color:e.ghost,children:Ve.repeat(36)}),wt.map((I,$)=>{let S=$===f,H=T.has(I),V=o[I]??0,F=oc[I];return jsxs(Box,{gap:0,children:[jsx(Text,{color:S?e.amber:e.ghost,children:S?" \u25B8 ":" "}),jsx(Text,{color:H?e.green:e.ghost,children:H?"[\u2713]":"[ ]"}),jsxs(Text,{color:S?F:e.dim,children:[" ",tc[I]," "]}),jsx(Text,{color:S?F:H?e.silver:e.dim,bold:S,children:nc[I]}),V>0&&jsxs(Text,{color:e.dim,children:[" ",ge,V]})]},I)}),jsx(Text,{color:e.ghost,children:Ve.repeat(36)}),jsxs(Box,{gap:0,children:[jsx(Text,{color:e.dim,children:" "}),ci.map((I,$)=>jsxs(io.Fragment,{children:[$>0&&jsxs(Text,{color:e.ghost,children:[" ",ge," "]}),jsx(Text,{color:e.amberDim,children:I.key}),jsxs(Text,{color:e.dim,children:["=",I.label]})]},I.key))]}),jsxs(Text,{color:e.dim,children:[" Space toggle"," ",ge," ","a all"," ",ge," ","Enter confirm"," ",ge," ","Esc cancel"]})]})});var zo="\u256D",Vo="\u256E",Ho="\u2570",jo="\u256F",Ie="\u2502";function on({children:t,cw:n}){return jsxs(Text,{children:[jsx(Text,{color:e.ghost,children:Ie}),jsxs(Text,{children:[" ",t.padEnd(n)," "]}),jsx(Text,{color:e.ghost,children:Ie})]})}function Wo({cw:t}){return jsx(on,{cw:t,children:""})}function ui({width:t,height:n}){let o=Math.min(t-4,50),r=o-6,l=be(o-2);return jsxs(Box,{flexDirection:"column",paddingX:2,marginTop:1,children:[jsxs(Text,{color:e.ghost,children:[zo,l,Vo]}),jsx(on,{cw:r,children:""}),jsxs(Text,{children:[jsxs(Text,{color:e.ghost,children:[Ie," "]}),jsx(Text,{color:e.amber,children:Ht}),jsx(Text,{color:e.white,bold:true,children:" Welcome to Orch"}),jsx(Text,{children:" ".repeat(Math.max(0,r-15-2))}),jsx(Text,{children:" "}),jsx(Text,{color:e.ghost,children:Ie})]}),jsx(on,{cw:r,children:""}),jsxs(Text,{children:[jsxs(Text,{color:e.ghost,children:[Ie," "]}),jsx(Text,{color:e.silver,children:"Press N to create your first task".padEnd(r)}),jsx(Text,{children:" "}),jsx(Text,{color:e.ghost,children:Ie})]}),jsx(on,{cw:r,children:""}),jsxs(Text,{children:[jsxs(Text,{color:e.ghost,children:[Ie," "]}),jsx(Text,{color:e.amber,children:"N"}),jsx(Text,{color:e.gray,children:" new task"}),jsx(Text,{children:" ".repeat(Math.max(0,r-1-1-8))}),jsx(Text,{children:" "}),jsx(Text,{color:e.ghost,children:Ie})]}),jsx(on,{cw:r,children:""}),jsxs(Text,{color:e.ghost,children:[Ho,l,jo]})]})}function gi({step:t,width:n}){let o=Math.min(n-4,50),r=o-6,l=be(o-2),f,x=null;if(t==="task_created")f="Press R to run task",x={key:"R",label:"run task"};else if(t==="run_started")f="Agent is running your task...";else return null;return jsxs(Box,{flexDirection:"column",paddingX:2,marginTop:1,children:[jsxs(Text,{color:e.ghost,children:[zo,l,Vo]}),jsxs(Text,{children:[jsxs(Text,{color:e.ghost,children:[Ie," "]}),jsx(Text,{color:e.amber,children:Ht}),jsxs(Text,{color:e.silver,children:[" ",f.padEnd(x?r-2-x.key.length-1-x.label.length-2:r-2)]}),x&&jsxs(Fragment,{children:[jsxs(Text,{color:e.amber,children:[" ",x.key]}),jsxs(Text,{color:e.gray,children:[" ",x.label]})]}),jsx(Text,{children:" "}),jsx(Text,{color:e.ghost,children:Ie})]}),jsxs(Text,{color:e.ghost,children:[Ho,l,jo]})]})}function mi({width:t}){let n=Math.min(t-4,50),o=n-6,r=be(n-2);return jsxs(Box,{flexDirection:"column",paddingX:2,marginTop:1,children:[jsxs(Text,{color:e.ghost,children:[zo,r,Vo]}),jsx(on,{cw:o,children:""}),jsxs(Text,{children:[jsxs(Text,{color:e.ghost,children:[Ie," "]}),jsx(Text,{color:e.green,bold:true,children:"First task completed!"}),jsx(Text,{children:" ".repeat(Math.max(0,o-21))}),jsx(Text,{children:" "}),jsx(Text,{color:e.ghost,children:Ie})]}),jsx(on,{cw:o,children:""}),jsxs(Text,{children:[jsxs(Text,{color:e.ghost,children:[Ie," "]}),jsx(Text,{color:e.silver,children:"Type / to see all commands".padEnd(o)}),jsx(Text,{children:" "}),jsx(Text,{color:e.ghost,children:Ie})]}),jsx(on,{cw:o,children:""}),jsxs(Text,{color:e.ghost,children:[Ho,r,jo]})]})}function Uo({count:t,config:n,width:o}){if(t>=3)return null;let r=Math.min((o??44)-4,50),l=r-6,f=be(r-2),x=jsxs(Text,{color:e.ghost,children:[zo,f,Vo]}),T=jsxs(Text,{color:e.ghost,children:[Ho,f,jo]});if(t>0){let y=n.hints[0],C=y?` ${y.key} ${y.label}`:"";return jsxs(Box,{flexDirection:"column",paddingX:2,marginTop:1,children:[x,jsxs(Text,{children:[jsxs(Text,{color:e.ghost,children:[Ie," "]}),jsx(Text,{color:e.amber,children:Ht}),jsxs(Text,{color:e.silver,children:[" ",n.nudge.padEnd(l-2-C.length)]}),y&&jsxs(Fragment,{children:[jsxs(Text,{color:e.amber,children:[" ",y.key]}),jsxs(Text,{color:e.gray,children:[" ",y.label]})]}),jsx(Text,{children:" "}),jsx(Text,{color:e.ghost,children:Ie})]}),T]})}let b=n.hints.reduce((y,C,I)=>y+C.key.length+1+C.label.length+(I>0?3:0),0);return jsxs(Box,{flexDirection:"column",paddingX:2,marginTop:1,children:[x,jsx(Wo,{cw:l}),jsxs(Text,{children:[jsxs(Text,{color:e.ghost,children:[Ie," "]}),jsx(Text,{color:e.amber,children:Ht}),jsxs(Text,{color:e.white,bold:true,children:[" ",n.title]}),jsx(Text,{children:" ".repeat(Math.max(0,l-n.title.length-2))}),jsx(Text,{children:" "}),jsx(Text,{color:e.ghost,children:Ie})]}),jsx(Wo,{cw:l}),n.description.map((y,C)=>jsxs(Text,{children:[jsxs(Text,{color:e.ghost,children:[Ie," "]}),jsx(Text,{color:e.silver,children:y.padEnd(l)}),jsx(Text,{children:" "}),jsx(Text,{color:e.ghost,children:Ie})]},C)),jsx(Wo,{cw:l}),jsxs(Text,{children:[jsxs(Text,{color:e.ghost,children:[Ie," "]}),n.hints.map((y,C)=>jsxs(io.Fragment,{children:[C>0&&jsx(Text,{color:e.ghost,children:" "}),jsx(Text,{color:e.amber,children:y.key}),jsxs(Text,{color:e.gray,children:[" ",y.label]})]},C)),jsx(Text,{children:" ".repeat(Math.max(0,l-b))}),jsx(Text,{children:" "}),jsx(Text,{color:e.ghost,children:Ie})]}),jsx(Wo,{cw:l}),T]})}var sc=2,xi=360,ic={done:4e3,failed:8e3,review:6e3},ac={done:"\u2713",failed:"\u2715",review:Qt},lc={done:e.green,failed:e.red,review:e.blue},cc={done:e.successBg,failed:e.errorBg,review:e.infoBg};function dc(t){let n=t.agentName??"Agent";switch(t.type){case "done":return `Task completed by ${n}`;case "failed":return "Task failed \u2014 press Enter for details";case "review":return "Task ready for review \u2014 press A to approve"}}var uc=io.memo(function({toast:n,onDismiss:o}){let[r,l]=useState(true),[f,x]=useState(false);useEffect(()=>{let S=setTimeout(()=>l(false),xi);return ()=>clearTimeout(S)},[]),useEffect(()=>{let S=ic[n.type],H=setTimeout(()=>x(true),S),V=setTimeout(()=>o(n.id),S+xi);return ()=>{clearTimeout(H),clearTimeout(V);}},[n.id,n.type,o]);let T=r||f,b=ac[n.type],y=lc[n.type],C=cc[n.type],I=dc(n),$=n.title.length>40?n.title.slice(0,39)+"\u2026":n.title;return jsx(Box,{children:jsxs(Text,{backgroundColor:C,children:[jsxs(Text,{color:T?e.dim:y,children:[" ",b," "]}),jsx(Text,{color:T?e.dim:e.white,bold:!T,children:$}),jsxs(Text,{color:T?e.dim:e.silver,children:[" ",I," "]})]})})}),yi=io.memo(function({toasts:n,onDismiss:o}){let r=n.slice(0,sc);return r.length===0?null:jsx(Box,{flexDirection:"column",children:r.map(l=>jsx(uc,{toast:l,onDismiss:o},l.id))})});var fc="\u256D",pc="\u256E",hc="\u2570",xc="\u256F",ct="\u2502",Nr=[{key:"\u2191\u2193/j/k",label:"Navigate"},{key:"Tab/\u2190\u2192",label:"Switch tabs"},{key:"Enter",label:"Detail view"},{key:"G",label:"Goals tab"},{key:"T",label:"Tasks tab"},{key:"A",label:"Agents tab"},{key:"L",label:"Logs tab"}],Dr=[{key:"N",label:"New item"},{key:"E",label:"Edit"},{key:"D",label:"Delete"},{key:"R",label:"Run task"},{key:"S",label:"Show / Stop"},{key:"C",label:"Cancel"},{key:"A",label:"Approve"},{key:"X",label:"Reject"},{key:"U",label:"Autonomous"},{key:"Z",label:"Undo delete"}],Fr=[{key:"/",label:"Command mode"},{key:"/task add",label:"Create task"},{key:"/run",label:"Execute"},{key:"/watch",label:"Auto-dispatch"},{key:"/config",label:"Settings"},{key:"/help",label:"Help"},{key:"/quit",label:"Exit"}],Dn=10,Xt=22;function Gr(t){let n=Math.max(0,Math.floor((Xt-t.length-2)/2)),o=Math.max(0,Xt-n-t.length-2);return be(n)+" "+t+" "+be(o)}var wi=io.memo(function({width:n,height:o}){let r=Xt*3+3+3+2,l=r+2,f=be(l-2),x="KEYBOARD SHORTCUTS",T=Math.max(0,Math.floor((r-x.length)/2)),b=Math.max(0,r-T-x.length),y="Press any key to dismiss",C=Math.max(0,Math.floor((r-y.length)/2)),I=Math.max(0,r-C-y.length),$=Math.max(Nr.length,Dr.length,Fr.length),S=$+10,H=Math.max(0,Math.floor((o-S)/2)),V=[];for(let L=0;L<$;L++){let N=L<Nr.length?Nr[L]:null,E=L<Dr.length?Dr[L]:null,W=L<Fr.length?Fr[L]:null;V.push(jsxs(Text,{children:[jsx(Text,{color:e.amber,children:ct}),jsx(Text,{children:" "}),N?jsxs(Fragment,{children:[jsx(Text,{color:e.amber,bold:true,children:N.key.padEnd(Dn)}),jsx(Text,{color:e.silver,children:N.label.padEnd(Xt-Dn)})]}):jsx(Text,{children:" ".repeat(Xt)}),jsxs(Text,{color:e.dim,children:[" ",ct," "]}),E?jsxs(Fragment,{children:[jsx(Text,{color:e.amber,bold:true,children:E.key.padEnd(Dn)}),jsx(Text,{color:e.silver,children:E.label.padEnd(Xt-Dn)})]}):jsx(Text,{children:" ".repeat(Xt)}),jsxs(Text,{color:e.dim,children:[" ",ct," "]}),W?jsxs(Fragment,{children:[jsx(Text,{color:e.amber,bold:true,children:W.key.padEnd(Dn)}),jsx(Text,{color:e.silver,children:W.label.padEnd(Xt-Dn)})]}):jsx(Text,{children:" ".repeat(Xt)}),jsx(Text,{children:" "}),jsx(Text,{color:e.amber,children:ct})]},`r${L}`));}let F=L=>jsxs(Text,{children:[jsx(Text,{color:e.amber,children:ct}),jsx(Text,{children:" ".repeat(r)}),jsx(Text,{color:e.amber,children:ct})]},L),P=Gr("NAVIGATION"),j=Gr("ACTIONS"),O=Gr("COMMANDS");return jsxs(Box,{flexDirection:"column",paddingX:Math.max(0,Math.floor((n-l)/2)),marginTop:H,children:[jsxs(Text,{color:e.amber,children:[fc,f,pc]}),F("e1"),jsxs(Text,{children:[jsx(Text,{color:e.amber,children:ct}),jsx(Text,{children:" ".repeat(T)}),jsx(Text,{color:e.amber,bold:true,children:x}),jsx(Text,{children:" ".repeat(b)}),jsx(Text,{color:e.amber,children:ct})]}),F("e2"),jsxs(Text,{children:[jsx(Text,{color:e.amber,children:ct}),jsx(Text,{children:" "}),jsx(Text,{color:e.dim,children:P}),jsxs(Text,{color:e.dim,children:[" ",ct," "]}),jsx(Text,{color:e.dim,children:j}),jsxs(Text,{color:e.dim,children:[" ",ct," "]}),jsx(Text,{color:e.dim,children:O}),jsx(Text,{children:" "}),jsx(Text,{color:e.amber,children:ct})]}),F("e3"),V,F("e4"),jsxs(Text,{children:[jsx(Text,{color:e.amber,children:ct}),jsx(Text,{children:" ".repeat(C)}),jsx(Text,{color:e.dim,children:y}),jsx(Text,{children:" ".repeat(I)}),jsx(Text,{color:e.amber,children:ct})]}),F("e5"),jsxs(Text,{color:e.amber,children:[hc,f,xc]})]})});var Ci=[{value:"claude-opus-4-6",label:"Claude Opus 4.6",hint:"most capable"},{value:"claude-sonnet-4-6",label:"Claude Sonnet 4.6",hint:"fast, balanced"},{value:"claude-haiku-4-6",label:"Claude Haiku 4.6",hint:"fastest, cheapest"},{value:"claude-sonnet-4-5-20250929",label:"Claude Sonnet 4.5",hint:"extended thinking"},{value:"claude-haiku-4-5-20251001",label:"Claude Haiku 4.5",hint:"legacy"}],Ii=[{value:"gpt-5.3-codex",label:"GPT-5.3 Codex",hint:"default, balanced"},{value:"gpt-5.4",label:"GPT-5.4",hint:"latest"},{value:"gpt-5",label:"GPT-5",hint:"capable"},{value:"gpt-5.3-codex-spark",label:"GPT-5.3 Codex Spark",hint:"fast"},{value:"o3",label:"o3",hint:"reasoning"},{value:"o4-mini",label:"o4-mini",hint:"fast reasoning"},{value:"gpt-5-mini",label:"GPT-5 Mini",hint:"light"},{value:"gpt-5-nano",label:"GPT-5 Nano",hint:"cheapest"},{value:"codex-mini-latest",label:"Codex Mini",hint:"legacy"}],Mi=[{value:"auto",label:"Auto",hint:"let Cursor decide"},{value:"composer-1.5",label:"Composer 1.5",hint:"latest agent"},{value:"composer-1",label:"Composer 1",hint:"stable agent"},{value:"gpt-5.3-codex",label:"GPT-5.3 Codex",hint:"OpenAI"},{value:"claude-sonnet-4-6",label:"Claude Sonnet 4.6",hint:"Anthropic"}],vi=[{value:"",label:"Default",hint:"use model configured in opencode"},{value:"openrouter/anthropic/claude-sonnet-4.6",label:"Claude Sonnet 4.6",hint:"fast, balanced"},{value:"openrouter/anthropic/claude-opus-4.6",label:"Claude Opus 4.6",hint:"most capable"},{value:"openrouter/google/gemini-2.5-pro",label:"Gemini 2.5 Pro",hint:"Google"},{value:"openrouter/google/gemini-2.5-flash",label:"Gemini 2.5 Flash",hint:"Google, fast"},{value:"openrouter/deepseek/deepseek-v3.2",label:"DeepSeek V3.2",hint:"open-source"},{value:"openrouter/deepseek/deepseek-r1:free",label:"DeepSeek R1",hint:"reasoning, free"},{value:"opencode/big-pickle",label:"Big Pickle",hint:"opencode native"}],_i=[{value:"",label:"Default",hint:"use shell adapter default"}],Ri=[{value:"",label:"Default",hint:"no override \u2014 use model default"},{value:"high",label:"High",hint:"deepest reasoning, best quality, slowest"},{value:"medium",label:"Medium",hint:"balanced speed and quality"},{value:"low",label:"Low",hint:"fastest responses, minimal reasoning"}],Ai=new Set(["claude"]),bc=[{value:"claude",label:"Claude",hint:"Claude Code CLI"},{value:"opencode",label:"OpenCode",hint:"OpenCode \u2014 multi-provider"},{value:"codex",label:"Codex",hint:"OpenAI Codex CLI"},{value:"cursor",label:"Cursor",hint:"Cursor Agent CLI"},{value:"shell",label:"Shell",hint:"custom shell command"}],$i=[{value:"1",label:"P1 Critical",hint:"urgent, do first"},{value:"2",label:"P2 High",hint:"important"},{value:"3",label:"P3 Medium",hint:"default priority"},{value:"4",label:"P4 Low",hint:"nice to have"}],Si=60;function Bi(t){return t.filter(n=>n.status!=="disabled").map(n=>{let o=(n.role??"").split(`
11
11
  `)[0].trim(),r=o.length>Si?o.slice(0,Si-1)+"\u2026":o,l=r?`[${n.adapter}] ${r}`:n.adapter;return {value:n.id,label:n.name,hint:l}})}function Ko(t,n="Auto-assign",o="orchestrator picks the best agent"){return [{value:"",label:n,hint:o},...Bi(t)]}var zr=[{value:"",label:"Skip",hint:"no role description"},{value:"Full-stack developer",label:"Full-stack developer",hint:"general purpose"},{value:"Frontend developer",label:"Frontend developer",hint:"React, CSS, UI"},{value:"Backend developer",label:"Backend developer",hint:"APIs, databases, services"},{value:"DevOps engineer",label:"DevOps engineer",hint:"CI/CD, infra, deploys"},{value:"QA / Test engineer",label:"QA / Test engineer",hint:"testing, quality"},{value:"Code reviewer",label:"Code reviewer",hint:"review PRs, find bugs"},{value:"Technical writer",label:"Technical writer",hint:"docs, READMEs"},{value:"__custom__",label:"Custom...",hint:"type your own"}];function Ei(t){return [{value:"",label:"None",hint:"no team"},...(t??[]).filter(n=>n.status==="active").map(n=>({value:n.id,label:n.name,hint:`${n.members.length} members`}))]}function Oi(){return [{id:"shop_template",label:"Agent Shop \u2014 choose a template",type:"select",options:a$2.map(t=>({value:t.key,label:t.name,hint:t.description}))}]}function Vr(t,n,o){let r=a$3(o,n.tier);return t.map(l=>{switch(l.id){case "name":return {...l,defaultValue:n.name};case "adapter":return {...l,defaultValue:o};case "model":return {...l,defaultValue:r};case "role":return {...l,defaultValue:"__custom__"};case "role_custom":return {...l,defaultValue:n.role,skip:void 0};case "skills":{let f=o==="claude"?n.skills:n.skills.filter(x=>!a$4(x));return {...l,defaultValue:f.join(", ")}}case "approval_policy":return {...l,defaultValue:n.approval_policy};default:return l}})}function Yo(t,n){let o=Ei(n);return [{id:"name",label:"Agent name",type:"text",placeholder:"e.g. alpha, frontend-bot, reviewer",required:true,validate:r=>r.trim()?t?.some(l=>l.name===r.trim())?"Agent with this name already exists":null:"Name is required",suggestions:a$2.map(r=>({value:r.key,label:r.name,hint:r.description}))},{id:"adapter",label:"Provider",type:"select",options:bc},{id:"model",label:"Model",type:"select",getOptions:r=>r.adapter==="opencode"?vi:r.adapter==="codex"?Ii:r.adapter==="cursor"?Mi:r.adapter==="shell"?_i:Ci},{id:"effort",label:"Reasoning effort",type:"select",options:Ri,skip:r=>!Ai.has(r.adapter??"")},{id:"role",label:"Role / specialization",type:"select",options:zr},{id:"role_custom",label:"Describe the role",type:"textarea",placeholder:"e.g. Specialist in React and TypeScript",skip:r=>r.role!=="__custom__"},{id:"skills",label:"Skills (comma-separated)",type:"text",placeholder:"e.g. feature-dev:feature-dev, testing-suite:generate-tests"},{id:"approval_policy",label:"Approval policy",type:"text",skip:()=>true},{id:"team",label:"Join team",type:"select",options:o,skip:()=>o.length<=1}]}function Li(t,n="claude"){let o=t.role==="__custom__"?t.role_custom||void 0:t.role||void 0,r=t.skills?t.skills.split(",").map(x=>x.trim()).filter(Boolean):void 0,l=t.approval_policy||"auto",f=t.effort||void 0;return {name:t.name,adapter:t.adapter||n,role:o,model:t.model||void 0,effort:f,approval_policy:l,skills:r,team_id:t.team||void 0}}function Pi(t,n){let o=Bi(t);return [{id:"name",label:"Team name",type:"text",placeholder:"e.g. frontend, backend, qa",required:true,validate:r=>r.trim()?n?.some(l=>l.name===r.trim())?"Team with this name already exists":null:"Name is required"},{id:"lead",label:"Team lead",type:"select",options:o},{id:"members",label:"Team members",type:"multiselect",getOptions:r=>o.filter(l=>l.value!==r.lead),skip:r=>!o.some(l=>l.value!==r.lead)},{id:"description",label:"Description",type:"textarea",placeholder:"Optional team purpose..."}]}function Ni(t){let n=t.members?t.members.split(",").filter(Boolean):[];return {name:t.name,lead_agent_id:t.lead,member_agent_ids:n.length>0?n:void 0,description:t.description||void 0}}function Di(t){let n=Ko(t);return [{id:"title",label:"Task title",type:"text",placeholder:"What needs to be done?",required:true,validate:o=>o.trim()?null:"Title is required"},{id:"priority",label:"Priority",type:"select",options:$i,defaultValue:"3",validate:o=>{let r=Number(o);return !Number.isInteger(r)||r<1||r>4?"Priority must be 1-4":null}},{id:"assignee",label:"Assignee",type:"select",options:n,skip:()=>n.length<=1},{id:"description",label:"Description",type:"textarea",placeholder:"Optional details, context, acceptance criteria..."}]}function Fi(t){return {title:t.title,priority:t.priority?parseInt(t.priority,10):void 0,assignee:t.assignee||void 0,description:t.description||void 0}}function Gi(t,n){let o=Ko(n,"None / Auto","remove assignee");return [{id:"title",label:"Task title",type:"text",defaultValue:t.title,required:true,validate:r=>r.trim()?null:"Title is required"},{id:"priority",label:"Priority",type:"select",options:$i,defaultValue:String(t.priority),validate:r=>{let l=Number(r);return !Number.isInteger(l)||l<1||l>4?"Priority must be 1-4":null}},{id:"assignee",label:"Assignee",type:"select",options:o,defaultValue:t.assignee??"",skip:()=>o.length<=1},{id:"description",label:"Description",type:"textarea",defaultValue:t.description||"",placeholder:"Optional details..."}]}function Wi(t){return {title:t.title,priority:t.priority?parseInt(t.priority,10):void 0,assignee:t.assignee||void 0,description:t.description??""}}function zi(t,n,o){let r=zr.find(b=>b.value===t.role),l=r?t.role:t.role?"__custom__":"",f=t.adapter==="opencode"?vi:t.adapter==="codex"?Ii:t.adapter==="cursor"?Mi:t.adapter==="shell"?_i:Ci,x=Ei(o),T=o?.find(b=>b.members.some(y=>y.agent_id===t.id))?.id;return [{id:"name",label:"Agent name",type:"text",defaultValue:t.name,required:true,validate:b=>b.trim()?n?.some(y=>y.id!==t.id&&y.name===b.trim())?"Agent with this name already exists":null:"Name is required"},{id:"model",label:"Model",type:"select",options:f,defaultValue:t.config.model??""},{id:"effort",label:"Reasoning effort",type:"select",options:Ri,defaultValue:t.config.effort??"",skip:()=>!Ai.has(t.adapter)},{id:"role",label:"Role / specialization",type:"select",options:zr,defaultValue:l},{id:"role_custom",label:"Describe the role",type:"textarea",defaultValue:t.role&&!r?t.role:"",placeholder:"e.g. Specialist in React and TypeScript",skip:b=>b.role!=="__custom__"},{id:"team",label:"Team",type:"select",options:x,defaultValue:T??"",skip:()=>x.length<=1}]}var Tc=[{value:"1",label:"1 agent",hint:"~0.5 GB RAM, 1 subprocess"},{value:"2",label:"2 agents",hint:"~1 GB RAM, 2 subprocesses"},{value:"3",label:"3 agents",hint:"~1.5 GB RAM, 3 subprocesses"},{value:"4",label:"4 agents",hint:"~2 GB RAM, 4 subprocesses"},{value:"6",label:"6 agents",hint:"~3 GB RAM, 6 subprocesses"},{value:"8",label:"8 agents",hint:"~4 GB RAM, 8 subprocesses"},{value:"10",label:"10 agents",hint:"~5 GB RAM, 10 subprocesses"}],yc=[{value:"all",label:"All",hint:"show everything"},{value:"text",label:"Text",hint:"agent output only"},{value:"tools",label:"Tools",hint:"tool calls, results, files"},{value:"errors",label:"Errors",hint:"errors only"},{value:"events",label:"Events",hint:"lifecycle, system events"}],ki=[{value:"true",label:"On"},{value:"false",label:"Off"}];function Vi(t,n,o){let r=o??{toast:true,bell:false};return [{id:"activity_filter",label:"Activity filter preset",type:"select",options:yc,defaultValue:t},{id:"max_concurrent",label:"Max concurrent agents",type:"select",options:Tc,defaultValue:String(n)},{id:"notifications_toast",label:"Toast notifications",type:"select",options:ki,defaultValue:String(r.toast)},{id:"notifications_bell",label:"Bell on completion",type:"select",options:ki,defaultValue:String(r.bell)}]}function Hi(t){let n=t.role==="__custom__"?t.role_custom||void 0:t.role||void 0,o=t.effort||void 0;return {name:t.name,role:n,model:t.model||void 0,effort:o,team_id:t.team||void 0}}function Zo(t){let n=Ko(t,"Any agent","auto-assign to autonomous agents");return [{id:"title",label:"Goal title",type:"text",placeholder:'e.g. "Implement OAuth2 login with Google and GitHub"',description:"Be specific \u2014 agents work better with clear, measurable objectives",required:true,validate:o=>o.trim()?null:"Title is required"},{id:"assignee",label:"Assignee",type:"select",description:"Assigned agent gets autonomous mode \u2014 it will plan and execute without prompts",options:n,skip:()=>n.length<=1},{id:"description",label:"Description",type:"textarea",placeholder:"Success criteria, constraints, technical context...",description:'Context matters \u2014 include tech stack, constraints, and what "done" looks like'}]}function ji(t){return {title:t.title,assignee:t.assignee||void 0,description:t.description||void 0}}function Ui(t,n){let o=Ko(n,"Any agent","auto-assign");return [{id:"title",label:"Goal title",type:"text",defaultValue:t.title,description:"Be specific \u2014 agents work better with clear, measurable objectives",required:true,validate:r=>r.trim()?null:"Title is required"},{id:"assignee",label:"Assignee",type:"select",description:"Assigned agent gets autonomous mode \u2014 it will plan and execute without prompts",options:o,defaultValue:t.assignee??"",skip:()=>o.length<=1},{id:"description",label:"Description",type:"textarea",defaultValue:t.description||"",placeholder:"Success criteria, constraints, technical context...",description:'Context matters \u2014 include tech stack, constraints, and what "done" looks like'}]}function Xi(t){return {title:t.title,assignee:t.assignee||void 0,description:t.description??""}}var qi=10,Ki=500,nr=2048,bn=500,Yi=5,Hr=new Set(["todo","failed","cancelled"]),Cc={title:"Goals",description:["Define what your team should achieve.","The orchestrator breaks goals into tasks","and assigns them to agents automatically."],hints:[{key:"N",label:"new goal"},{key:"/",label:"commands"}],nudge:"Add more goals to keep your team focused."},Ic={title:"Tasks",description:["Units of work dispatched to agents.","Create them manually or let goals","generate them automatically."],hints:[{key:"N",label:"new task"},{key:"W",label:"start orchestrator"}],nudge:"Add more tasks to keep agents busy."},Mc={title:"Agents",description:["AI workers that execute your tasks.","Each agent uses an adapter (claude, codex,","cursor, shell) and has its own role."],hints:[{key:"N",label:"new agent"},{key:"W",label:"start orchestrator"}],nudge:"Add more agents to increase parallelism."},Zi=5e3,Qi=0;function lg(){Qi=0;}var ea=/^\[[\w_]+\]$/;function ta(t){return ea.test(t)?{msgType:"lifecycle",color:e.dim}:t.startsWith("\u2699")?{msgType:"tool",color:e.dim}:t.startsWith("\u2190")?{msgType:"result",color:e.dim}:t.startsWith("\u2713")?{msgType:"lifecycle",color:e.dim}:t.startsWith("\u23F3")?{msgType:"info",color:e.silver}:{msgType:"output",color:e.silver}}var Xr=["#5faf87","#5fafd7","#af87ff","#d7af00","#5fd7d7","#d787af","#afaf5f","#d7875f"],vc=" ".repeat(9),or={system:"\u2666",lifecycle:"\u25B6",output:"\u2502",tool:"\u2699",result:"\u2190",error:"\u2715",file:"\u270E",info:"\u2502"},er=["system","lifecycle","output","tool","result","error","file","info"],Fn=[{label:"all",types:er},{label:"text",types:["output"]},{label:"tools",types:["tool","result","file"]},{label:"errors",types:["error"]},{label:"events",types:["lifecycle","system"]}];function jr(t){let o=(Fn.findIndex(r=>r.types.length===t.size&&r.types.every(l=>t.has(l)))+1)%Fn.length;return Fn[o]}function Ur(t,n){if(t.length!==n.length)return true;for(let o=0;o<t.length;o++)if(t[o].id!==n[o].id||t[o].updated_at!==n[o].updated_at)return true;return false}function cg({projectName:t,tasks:n,agents:o=[],state:r,onRunTask:l,onCreateTask:f,onCancelTask:x,onRetryTask:T,onAssignTask:b$1,onRunAll:y,onDisableAgent:C,onEnableAgent:I,onSubscribeEvents:$,onRefreshTasks:S,onRefreshAgents:H,onRefreshState:V,onLoadHistory:F,onAddAgent:P,onDeleteAgent:j,onApproveTask:O,onRejectTask:L,onDeleteTask:N,onUpdateTask:E,onUpdateAgent:W,onForceStopAgent:z,onCreateTeam:X,onListTeams:_,onJoinTeam:le,onLeaveTeam:Ee,onDisbandTeam:Ft,onSetTeamLead:dt,onStartWatch:Ae,onStopWatch:Ke,onToggleAutonomous:ut,onRefreshGoals:pt,onCreateGoal:De,onUpdateGoal:Ye,onUpdateGoalStatus:gt,onDeleteGoal:Ze,onGetGoalProgress:rn,onCompleteOnboarding:Ce,initialWatchActive:ht,observerMode:xt,watchError:qt,messageBatchMs:mt=process.env.VITEST?0:80,initialActivityFilter:kt="all",onSaveActivityFilter:Ue,initialMaxConcurrent:uo=a.scheduling.max_concurrent_agents,onSaveMaxConcurrent:Gn,initialNotifications:Rt,onSaveNotifications:Gt,version:Wt,latestVersion:zt,onCheckUpdate:sn,onBackgroundInstall:an,defaultAdapter:nt="claude"}){let{exit:Wn}=useApp(),{stdout:At}=useStdout(),[Kt,ln]=useState(zt),zn=useRef(sn);useEffect(()=>{if(zt||!zn.current)return;let i=setTimeout(()=>{zn.current?.().then(p=>{p&&ln(p);}).catch(()=>{});},5e3);return ()=>clearTimeout(i)},[zt]);let[R,M]=useState(false),k=useRef(false);useEffect(()=>{!Kt||!an||k.current||R||(k.current=true,an(Kt).then(i=>{i&&M(true);}).catch(()=>{}));},[Kt,an,R]);let[B,Z]=useState({w:At?.columns??80,h:At?.rows??24});useEffect(()=>{if(!At)return;let i=()=>Z({w:At.columns,h:At.rows});return At.on("resize",i),()=>{At.off("resize",i);}},[At]);let K=B.w,ye=B.h,[ne,pe]=useState(n),[Q,Yt]=useState(o),[ve,rr]=useState(r),[go,sr]=useState(ht??!!r.pid),[Vn,qr]=useState([]),[aa,Kr]=useState(void 0),[Zt,mo]=useState(()=>r.onboardingCompleted||(r.stats?.total_tasks_completed??0)>0?"dismissed":Object.keys(r.running??{}).length>0?"run_started":n.length>0?"task_created":"welcome");useEffect(()=>{if(Zt!=="completed")return;let i=setTimeout(()=>{mo("dismissed"),Ce?.().catch(()=>{});},5e3);return ()=>clearTimeout(i)},[Zt,Ce]);let[A,Tn]=useState("tasks"),[fo,Hn]=useState(0),[ir,Yr]=useState(0),[ar,Zr]=useState(0),[$e,jn]=useState(false),[ze,Jr]=useState([]),[Fe,Oe]=useState("none"),[cn,Ct]=useState(""),[bt,Je]=useState(null),[dn,Un]=useState([]),[$t,lr]=useState(false),[Qr,la]=useState(()=>new Set),[yn,cr]=useState(false),[Xn,dr]=useState(false),[es,ts]=useState(()=>new Set(er)),[qn,ur]=useState(-1),[ca,Kn]=useState(0),[wn,gr]=useState(()=>{let i=Fn.find(p=>p.label===kt);return new Set(i?.types??er)}),po=useMemo(()=>Fn.find(p=>p.types.length===wn.size&&p.types.every(s=>wn.has(s)))?.label??"all",[wn]),mr=useMemo(()=>wn.size>=er.length?ze:ze.filter(i=>wn.has(i.msgType??"info")),[ze,wn]),[ns,da]=useState(uo),[ho,ua]=useState(Rt??{toast:true,bell:false}),[ga,os]=useState([]),ma=useRef(0),[fr,rs]=useState(),ss=useRef(A);ss.current=A;let is=useRef(ne);is.current=ne;let as=useRef(Q);as.current=Q;let xo=useRef(ho);xo.current=ho;let bo=useCallback((i,p)=>{if(!xo.current.toast)return;let s=is.current.find(h=>h.id===p),d=s?.title??p,g=s?.assignee?as.current.find(h=>h.id===s.assignee):void 0;os(h=>{let u=[...h,{id:`toast_${ma.current++}`,type:i,title:d,agentName:g?.name,ts:Date.now()}];return u.length>Yi?u.slice(u.length-Yi):u}),xo.current.bell&&(i==="failed"||i==="review")&&process.stdout.write("\x07");},[]),fa=useCallback(i=>{os(p=>p.filter(s=>s.id!==i));},[]),To=io.useRef(new No).current,[pa,Sn]=useState(0),[ls,cs]=useState(false),[Yn,ha]=useState(false),[xa,pr]=useState(0),[ba,hr]=useState(0),[xr,kn]=useState(0),[yo,br]=useState(false),[Ta,Zn]=useState(0),[wo,Jt]=useState(0),[Vt,ds]=useState([]),[Cn,Tr]=useState([]),In=useRef(Vt);In.current=Vt;let us=useRef(0),Y=useCallback(async i=>{us.current=Date.now();let[p,s,d,g,h]=await Promise.all([S?.()??Promise.resolve(ne),H?.()??Promise.resolve(Q),V?.()??Promise.resolve(ve),i?.includeTeams?_?.()??Promise.resolve(In.current):Promise.resolve(null),pt?.()??Promise.resolve(Vn)]);pe(u=>Ur(u,p)?p:u),Yt(u=>Ur(u,s)?s:u),rr(d),g!==null&&ds(g),qr(u=>Ur(u,h)?h:u),ht&&sr(!!d.pid);},[S,H,V,_,pt,ht]),Mn=useMemo(()=>{let i=new Map;for(let p of Vn)i.set(p.id,p);return i},[Vn]),Le=useMemo(()=>{let i=[...ne].sort((h,u)=>(oo[h.status]??9)-(oo[u.status]??9));if(!Yn)return i;let p=[],s=[],d=[],g=new Map;for(let h of i)h.goalId&&Mn.has(h.goalId)?(g.has(h.goalId)||(d.push(h.goalId),g.set(h.goalId,[])),g.get(h.goalId).push(h)):s.push(h);for(let h of d)p.push(...g.get(h));return [...p,...s]},[ne,Yn,Mn]),Bt=ls?Le:Le.slice(0,qi),vn=Le.length-Bt.length,U=Le[fo],Jn=useMemo(()=>{let i=new Map;for(let p of ne)i.set(p.id,p.title);return i},[ne]),un=useMemo(()=>{let i=new Map;for(let p of Q)i.set(p.id,p.name);return i},[Q]),ya=useMemo(()=>{let i=new Map;for(let p of ne)if(p.goalId){let s=i.get(p.goalId);s||(s=[],i.set(p.goalId,s)),s.push(p);}return i},[ne]),So=useMemo(()=>{let i=new Map;for(let p=0;p<Q.length;p++)i.set(Q[p].id,Xr[p%Xr.length]);return i},[Q]),gs=useMemo(()=>{let i=new Map;for(let p of ze)p.agentId&&i.set(p.agentId,(i.get(p.agentId)??0)+1);return i},[ze]),wa=useMemo(()=>{let i={};for(let p of ze){let s=p.msgType??"info";i[s]=(i[s]??0)+1;}return i},[ze]),{agentTeamMap:_n,activeTeamCount:Qn,teamLeadSet:Sa}=useMemo(()=>{let i=new Map,p=new Set,s=0;for(let d of Vt)if(d.status==="active"){s++,p.add(d.lead_agent_id);for(let g of d.members)i.set(g.agent_id,d.name);}return {agentTeamMap:i,activeTeamCount:s,teamLeadSet:p}},[Vt]),Ge=useMemo(()=>{let i=[...Q];return i.sort((p,s)=>{let d=_n.get(p.id),g=_n.get(s.id);return d&&!g?-1:!d&&g?1:d&&g&&d!==g?d.localeCompare(g):(Rr[p.status]??9)-(Rr[s.status]??9)}),i},[Q,_n]),ee=Ge[ir],ft=useMemo(()=>[...Vn].sort((i,p)=>(c[i.status]??9)-(c[p.status]??9)),[Vn]),re=ft[ar],ka=useMemo(()=>re?ne.filter(i=>i.goalId===re.id):[],[re,ne]),yr=useRef(rn);yr.current=rn,useEffect(()=>{if(!re||!yr.current){Kr(void 0);return}let i=false;return yr.current(re.id).then(p=>{i||Kr(p);}).catch(()=>{}),()=>{i=true;}},[re?.id]);let gn=useRef(new Map),ko=useRef(new Map);useEffect(()=>{for(let[i,p]of Object.entries(ve.running))gn.current.set(p.run_id,p.agent_id),ko.current.set(p.run_id,i);if(gn.current.size>Ki){let i=gn.current.size-Ki,p=0;for(let s of gn.current.keys()){if(p++>=i)break;gn.current.delete(s),ko.current.delete(s);}}},[ve.running]);let mn=useRef([]),eo=useRef(null),wr=useCallback(()=>{if(eo.current=null,mn.current.length===0)return;let i=mn.current;mn.current=[],Jr(p=>{if(i.length>=bn)return i.slice(-bn);let s=bn-i.length;return (p.length>s?p.slice(-s):p).concat(i)});},[]);useEffect(()=>()=>{eo.current&&clearTimeout(eo.current);},[]);let a=useCallback((i,p,s)=>{let d=new Date,g=d.toLocaleTimeString("en-US",{hour12:false,hour:"2-digit",minute:"2-digit",second:"2-digit"}),h=s?.detail&&s.detail.length>nr?s.detail.slice(0,nr)+"\u2026[truncated]":s?.detail;mn.current.push({text:i,color:p,time:g,ts:d.getTime(),...s,detail:h}),mn.current.length>bn&&(mn.current=mn.current.slice(-bn)),mt===0?wr():eo.current||(eo.current=setTimeout(wr,mt));},[wr]);useEffect(()=>{xt?a("Observer mode: watching external orchestrator via disk polling.",e.amber):qt&&a(`Watch mode failed: ${qt}. Tasks will not auto-dispatch.`,e.red);},[]),useEffect(()=>{let i=xt?3e3:5e3,p=setInterval(()=>{Date.now()-us.current>=i&&Y().catch(()=>{});},i);return ()=>clearInterval(p)},[xt,Y]);let Rn=useCallback((i,p,s,d)=>{let g={key:++Qi,entityType:i,entityId:p,entityName:s,expiresAt:Date.now()+Zi,needsForceStop:d?.needsForceStop};Tr(h=>[...h,g]),a(`\u2717 "${s}" will be deleted in ${Math.round(Zi/1e3)}s \u2014 press Z to undo`,e.yellow);},[a]),Ca=useCallback(()=>{Tr(i=>{if(i.length===0)return i;let p=i[i.length-1];return a(`\u21B6 Undo: "${p.entityName}" restored`,e.green),i.slice(0,-1)});},[a]),ms=useCallback(async i=>{try{i.entityType==="task"&&N?await N(i.entityId):i.entityType==="agent"?(i.needsForceStop&&z&&await z(i.entityId),j&&await j(i.entityId)):i.entityType==="goal"&&Ze&&await Ze(i.entityId),a(`\u2713 Deleted "${i.entityName}"`,e.green),Y();}catch(p){a(`Failed to delete "${i.entityName}": ${p instanceof Error?p.message:String(p)}`,e.red);}},[N,j,Ze,z,a,Y]),fs=useRef(ms);fs.current=ms,useEffect(()=>{if(Cn.length===0)return;let i=setInterval(()=>{let p=Date.now(),s=[];Tr(d=>{let g=d.filter(h=>h.expiresAt<=p?(s.push(h),false):true);return s.length>0?g:d});for(let d of s)fs.current(d);},1e3);return ()=>clearInterval(i)},[Cn.length>0]),useEffect(()=>{if(!F)return;let i=p=>{let s=new Date(p.timestamp).toLocaleTimeString("en-US",{hour12:false,hour:"2-digit",minute:"2-digit",second:"2-digit"}),d=typeof p.data=="string"?p.data:JSON.stringify(p.data),g,h=e.silver,u="output";if(p.type==="error")g=typeof p.data=="string"?p.data:JSON.stringify(p.data),g=g.slice(0,200),h=e.red,u="error";else if(p.type==="file_changed")g=String(p.data),h=e.purple,u="file";else if(p.type==="done")g="Completed",h=e.green,u="lifecycle";else if(p.type==="tool_call")g=`\u2699 ${p.data?.name??"tool"}()`,h=e.cyan,u="tool";else {let{summary:w}=ia(d);if(!w)return null;g=w;let J=ta(g);u=J.msgType,h=J.color;}return {text:g,color:h,time:s,ts:new Date(p.timestamp).getTime(),agentId:p.agentId,taskId:p.taskId,msgType:u}};F(p=>{if(p.length===0)return;let s=p.map(i).filter(d=>d!==null);Jr(d=>{let g=[...s,...d];return g.length>bn?g.slice(-bn):g});}).catch(p=>{process.stderr.write(`[TUI] onLoadHistory error: ${p instanceof Error?p.stack??p.message:String(p)}
12
- `);});},[]),useEffect(()=>{_?.().then(ds).catch(()=>{}),pt?.().then(qr).catch(()=>{});},[]);let Co=useCallback(()=>{Je({title:"NEW AGENT",steps:Yo(Q,In.current),kind:"agent"}),Oe("wizard");},[Q]),ps=useCallback(()=>{Je({title:"AGENT SHOP",steps:Oi(),kind:"agent_shop"}),Oe("wizard");},[]),Io=useCallback(()=>{Un([]),Je({title:"NEW TASK",steps:Di(Q),kind:"task"}),Oe("wizard");},[Q]),Ia=useCallback(async()=>{try{let{detectClipboardType:i,getClipboardImage:p}=await import('./clipboard-service-AJTJG2DJ.js'),s=await i();if(s!=="image")return a(s==="text"?"Clipboard has text, not image":"Clipboard is empty",e.dim),s;let d=await p();if(!d)return a("Failed to read clipboard image",e.red),"empty";let{mkdtemp:g,writeFile:h}=await import('fs/promises'),{tmpdir:u}=await import('os'),{join:w}=await import('path'),J=await g(w(u(),"orch-paste-")),Ot=w(J,`clipboard-${Date.now()}.${d.ext}`);return await h(Ot,d.data),Un(fn=>[...fn,Ot]),a(`\u{1F4CE} Image attached (${Math.round(d.data.length/1024)}KB)`,e.green),"image"}catch{return a("Clipboard paste failed",e.red),"empty"}},[a]),Ma=useCallback(i=>{Je({title:"EDIT TASK",steps:Gi(i,Q),kind:"edit_task",targetId:i.id}),Oe("wizard");},[Q]),hs=useCallback(()=>{Je({title:"NEW TEAM",steps:Pi(Q,Vt),kind:"team"}),Oe("wizard");},[Q]),va=useCallback(i=>{Je({title:"EDIT AGENT",steps:zi(i,Q,Vt),kind:"edit_agent",targetId:i.id}),Oe("wizard");},[Vt]),xs=useCallback(()=>{Je({title:"SETTINGS",steps:Vi(po,ns,ho),kind:"config"}),Oe("wizard");},[po,ns]),_a=useCallback(i=>{Oe("none");let p=bt?.kind,s=bt?.targetId;if(Je(null),p==="agent_shop"){let d=i.shop_template,g=d?b(d):void 0;if(g){let h=Yo(Q,In.current),u=Vr(h,g,nt);Je({title:`NEW AGENT \u2014 ${g.name}`,steps:u,kind:"agent_from_shop"}),Oe("wizard");}else a("No template selected",e.yellow);return}if((p==="agent"||p==="agent_from_shop")&&P){let d=Li(i,nt);a(`Creating agent "${d.name}"...`,e.amber),P(d.name,d.adapter,{model:d.model,effort:d.effort,role:d.role,approval_policy:d.approval_policy,skills:d.skills}).then(g=>{a(`\u2713 Created agent "${g.name}" (${g.id}, ${g.adapter})`,e.green),d.team_id&&le?le(d.team_id,g.id).then(h=>{a(`\u2713 Joined team "${h.name}"`,e.green),Y({includeTeams:true});},h=>a(`Failed to join team: ${h instanceof Error?h.message:String(h)}`,e.red)):Y();},g=>a(`Failed: ${g instanceof Error?g.message:String(g)}`,e.red));}else if(p==="team"&&X){let d=Ni(i);a(`Creating team "${d.name}"...`,e.amber),X(d).then(g=>{a(`\u2713 Created team "${g.name}" (${g.id}, ${g.members.length} members)`,e.green),Y({includeTeams:true});},g=>a(`Failed: ${g instanceof Error?g.message:String(g)}`,e.red));}else if(p==="task"&&f){let d=Fi(i),g=dn.length>0?[...dn]:void 0;Un([]),a(`Creating "${d.title}"...`,e.amber),f(d.title,{priority:d.priority,description:d.description,attachments:g}).then(h=>{a(`\u2713 Created "${h.title}" (${h.id})${g?` \u{1F4CE}${g.length}`:""}`,e.green),d.assignee&&b$1&&b$1(h.id,d.assignee).catch(()=>{}),Y();},h=>a(`Failed: ${h instanceof Error?h.message:String(h)}`,e.red));}else if(p==="edit_task"&&s&&E){let d=Wi(i),g=dn.length>0?[...dn]:void 0;Un([]),a("Updating task...",e.amber),E(s,{...d,attachments:g}).then(h=>{a(`\u2713 Updated "${h.title}"${g?` \u{1F4CE}${g.length}`:""}`,e.green),d.assignee&&b$1&&b$1(s,d.assignee).catch(()=>{}),Y();},h=>a(`Failed: ${h instanceof Error?h.message:String(h)}`,e.red));}else if(p==="edit_agent"&&s&&W){let d=Hi(i),g=d.team_id??"",h=Vt.find(u=>u.members.some(w=>w.agent_id===s))?.id??"";a("Updating agent...",e.amber),W(s,{name:d.name,role:d.role,model:d.model,effort:d.effort}).then(u=>{a(`\u2713 Updated agent "${u.name}"`,e.green);let w=[];h&&h!==g&&Ee&&w.push(Ee(h,s).then(J=>a(`\u2713 Left team "${J.name}"`,e.green),J=>a(`Failed to leave team: ${J instanceof Error?J.message:String(J)}`,e.red))),g&&g!==h&&le&&w.push(le(g,s).then(J=>a(`\u2713 Joined team "${J.name}"`,e.green),J=>a(`Failed to join team: ${J instanceof Error?J.message:String(J)}`,e.red))),Promise.all(w).then(()=>Y({includeTeams:w.length>0}));},u=>a(`Failed: ${u instanceof Error?u.message:String(u)}`,e.red));}else if(p==="config"){if(i.activity_filter){let u=Fn.find(w=>w.label===i.activity_filter);u&&(gr(new Set(u.types)),Ue?.(u.label));}if(i.max_concurrent){let u=parseInt(i.max_concurrent,10);u>0&&(da(u),Gn?.(u));}let d=i.notifications_toast==="true",g=i.notifications_bell==="true",h={toast:d,bell:g};ua(h),Gt?.(h),a("Settings saved",e.green);}else if(p==="goal"&&De){let d=ji(i);a(`Creating goal "${d.title}"...`,e.amber),De(d).then(g=>{a(`\u2713 Created goal "${g.title}" (${g.id})`,e.green),Y();},g=>a(`Failed: ${g instanceof Error?g.message:String(g)}`,e.red));}else if(p==="edit_goal"&&s&&Ye){let d=Xi(i);a("Updating goal...",e.amber),Ye(s,d).then(g=>{a(`\u2713 Updated goal "${g.title}"`,e.green),Y();},g=>a(`Failed: ${g instanceof Error?g.message:String(g)}`,e.red));}},[bt,P,f,X,le,Ee,b$1,E,W,ut,De,Ye,a,Y,Ue,Gn,ho,Gt,Vt,dn]),Ra=useCallback(()=>{Oe("none"),Je(null),Un([]);},[]),Aa=useCallback(i=>{let p=b(i);if(!p)return;let s=Yo(Q,In.current),d=Vr(s,p,nt);Je({title:`NEW AGENT \u2014 ${p.name}`,steps:d,kind:"agent_from_shop"}),Oe("wizard");},[]);useEffect(()=>{if(!$)return;let i=null,p=()=>{i||(i=setTimeout(()=>{i=null,Y().catch(()=>{});},150));},s=$(d=>{if(d.type==="agent:started"&&(gn.current.set(d.runId,d.agentId),ko.current.set(d.runId,d.taskId)),Uc(d,a,gn.current,ko.current),d.type==="task:created"?mo(g=>g==="welcome"?"task_created":g):d.type==="agent:started"?mo(g=>g==="task_created"?"run_started":g):d.type==="task:status_changed"&&d.to==="done"&&mo(g=>g==="run_started"?"completed":g),d.type==="task:status_changed"&&(d.to==="done"?bo("done",d.taskId):d.to==="failed"?bo("failed",d.taskId):d.to==="review"&&bo("review",d.taskId),xo.current.toast&&ss.current!=="tasks")){let g=d.to==="done"?e.green:d.to==="failed"?e.red:d.to==="review"?e.blue:void 0;g&&rs({tab:"tasks",color:g});}(d.type==="task:status_changed"||d.type==="task:created"||d.type==="task:assigned"||d.type==="agent:started"||d.type==="agent:completed"||d.type==="run:retry"||d.type==="goal:created"||d.type==="goal:status_changed"||d.type==="goal:updated"||d.type==="goal:deleted")&&p();});return ()=>{s(),i&&clearTimeout(i);}},[$,a,Y,bo]);let Sr=xt?"observing":go?"watching":"idle",$a=ve.started_at?g(ve.started_at):void 0,bs=ve.stats.total_tokens.total,Ts=useMemo(()=>{let i={running:0,retrying:0,review:0,todo:0,done:0,failed:0,cancelled:0};for(let p of ne)p.status==="in_progress"?i.running++:p.status==="retrying"?i.retrying++:p.status==="review"?i.review++:p.status==="todo"?i.todo++:p.status==="done"?i.done++:p.status==="failed"?i.failed++:p.status==="cancelled"&&i.cancelled++;return {...i,teams:Qn}},[ne,Qn]);Ts.running;let Ba=useMemo(()=>({input:ve.stats.total_tokens.input??0,output:ve.stats.total_tokens.output??0,reasoning:ve.stats.total_tokens.reasoning??0,total:bs,cache_read:ve.stats.total_tokens.cache_read??0,cache_write:ve.stats.total_tokens.cache_write??0}),[ve.stats.total_tokens,bs]),It=Math.max(4,ye-9),Ea=_n.size,Oa=Q.length>Ea,La=Qn>0?Qn+(Oa?1:0):0,Pa=useMemo(()=>{if(!Yn||Mn.size===0)return 0;let i=0,p=new Set,s=false;for(let d of Bt)d.goalId&&Mn.has(d.goalId)?p.has(d.goalId)||(p.add(d.goalId),i++):s=true;return s&&i++,i},[Yn,Mn,Bt]),Na=A==="goals"?ft.length+1:A==="tasks"?Bt.length+1+(vn>0?1:0)+Pa:A==="agents"?Q.length+1+La:0,Da=Math.min(Na+1,Math.ceil(It*.5)),Fa=A==="logs"?It:Math.max(2,Math.min(Da,It-4)),Se,Et;if(A==="logs")Se=It,Et=0;else if(yo)Se=0,Et=Math.max(1,It);else {let i=Math.max(3,Math.min(Fa+xr,It-4));Se=i,Et=Math.max(1,It-i);}let _e=Math.max(10,K-2),Mt=useMemo(()=>Fe==="command"?Js(cn):[],[Fe,cn]),An=It-4-3;useEffect(()=>{xr>An&&kn(An),xr<-An&&kn(-An);},[It]),useEffect(()=>{Sn(i=>Math.min(i,Math.max(0,Bt.length-Se)));},[Bt.length,Se]),useEffect(()=>{pr(i=>Math.min(i,Math.max(0,Ge.length-Se)));},[Ge.length,Se]),useEffect(()=>{hr(i=>Math.min(i,Math.max(0,ft.length-Se)));},[ft.length,Se]);let Ga=useCallback(i=>{let s=i.trim().replace(/^\//,"").split(/\s+/),d=s[0]?.toLowerCase();if(!d)return;let g=h=>h instanceof Error?h.message:String(h);switch(d){case "cancel":{if(!U){a("No task selected",e.yellow);return}if(!x)return;a(`Cancelling "${U.title}"...`,e.amber),x(U.id).then(()=>{a(`\u2713 Cancelled "${U.title}"`,e.green),Y();},h=>a(`Failed: ${g(h)}`,e.red));return}case "retry":{if(!U){a("No task selected",e.yellow);return}if(!T)return;a(`Retrying "${U.title}"...`,e.amber),T(U.id).then(()=>{a(`\u2713 Retried "${U.title}"`,e.green),Y();},h=>a(`Failed: ${g(h)}`,e.red));return}case "assign":{if(!U){a("No task selected",e.yellow);return}if(!b$1||!s[1]){a("Usage: assign <agent>",e.yellow);return}a(`Assigning "${U.title}" to ${s[1]}...`,e.amber),b$1(U.id,s[1]).then(()=>{a(`\u2713 Assigned "${U.title}" to ${s[1]}`,e.green),Y();},h=>a(`Failed: ${g(h)}`,e.red));return}case "task":{let h=s[1]?.toLowerCase();if(h==="add"){let u=s.slice(2).join(" ");if(!u){Io();return}if(!f){a("Create not available",e.yellow);return}a(`Creating "${u}"...`,e.amber),f(u).then(w=>{a(`\u2713 Created "${w.title}" (${w.id})`,e.green),Y();},w=>a(`Failed: ${g(w)}`,e.red));}else if(h==="list"){let u=Le.map(w=>` ${w.id} ${w.status.padEnd(11)} ${w.title}`);if(u.length===0)a("No tasks",e.dim);else for(let w of u)a(w,e.cyan);}else if(h==="show"){let u=s[2]?Le.find(w=>w.id===s[2]):U;if(!u){a("No task selected or id given",e.yellow);return}a(`${u.id} ${u.status} P${u.priority} "${u.title}"`,e.cyan),u.assignee&&a(` agent: ${u.assignee}`,e.dim),u.description&&a(` ${u.description.slice(0,100)}`,e.dim);}else if(h==="cancel"){let u=s[2]?Le.find(w=>w.id===s[2]):U;if(!u){a("No task selected or id given",e.yellow);return}if(!x)return;a(`Cancelling "${u.title}"...`,e.amber),x(u.id).then(()=>{a(`\u2713 Cancelled "${u.title}"`,e.green),Y();},w=>a(`Failed: ${g(w)}`,e.red));}else if(h==="retry"){let u=s[2]?Le.find(w=>w.id===s[2]):U;if(!u){a("No task selected or id given",e.yellow);return}if(!T)return;a(`Retrying "${u.title}"...`,e.amber),T(u.id).then(()=>{a(`\u2713 Retried "${u.title}"`,e.green),Y();},w=>a(`Failed: ${g(w)}`,e.red));}else if(h==="assign"){let u=s[2]?Le.find(Ot=>Ot.id===s[2]):void 0,w=u??U,J=u?s[3]:s[2];if(!w){a("No task selected or id given",e.yellow);return}if(!J){a("Usage: /task assign [id] <agent>",e.yellow);return}if(!b$1)return;a(`Assigning "${w.title}" to ${J}...`,e.amber),b$1(w.id,J).then(()=>{a(`\u2713 Assigned "${w.title}" to ${J}`,e.green),Y();},Ot=>a(`Failed: ${g(Ot)}`,e.red));}else if(h==="approve"){let u=s[2]?Le.find(w=>w.id===s[2]):U;if(!u){a("No task selected or id given",e.yellow);return}if(u.status!=="review"){a(`Cannot approve \u2014 status is ${u.status}`,e.yellow);return}if(!O)return;a(`Approving "${u.title}"...`,e.amber),O(u.id).then(()=>{a(`\u2713 Approved "${u.title}"`,e.green),Y();},w=>a(`Failed: ${g(w)}`,e.red));}else if(h==="reject"){let u=s[2]?Le.find(J=>J.id===s[2]):U;if(!u){a("No task selected or id given",e.yellow);return}if(u.status!=="review"){a(`Cannot reject \u2014 status is ${u.status}`,e.yellow);return}if(!L)return;let w=s.slice(s[2]&&Le.find(J=>J.id===s[2])?3:2).join(" ").trim()||void 0;a(`Rejecting "${u.title}"${w?" with feedback":""}...`,e.amber),L(u.id,w).then(()=>{a(`\u2713 Rejected "${u.title}" \u2192 todo`,e.green),Y();},J=>a(`Failed: ${g(J)}`,e.red));}else if(h==="delete"){let u=s[2]?Le.find(w=>w.id===s[2]):U;if(!u){a("No task selected or id given",e.yellow);return}if(u.status==="in_progress"){a("Cannot delete \u2014 task is running",e.yellow);return}if(!N)return;Rn("task",u.id,u.title);}else a("Usage: /task add|list|show|cancel|retry|assign|approve|reject|delete",e.yellow);return}case "agent":{let h=s[1]?.toLowerCase();if(h==="add"){let u=s[2];if(!u){Co();return}if(!P){a("Agent creation not available",e.yellow);return}let w=s[3];a(`Creating agent "${u}"...`,e.amber),P(u,w).then(J=>{a(`\u2713 Created agent "${J.name}" (${J.id}, ${J.adapter})`,e.green),Y();},J=>a(`Failed: ${g(J)}`,e.red));}else if(h==="list"){let u=Ge.map(w=>` ${w.id} ${w.status.padEnd(8)} ${w.name} (${w.adapter})`);if(u.length===0)a("No agents",e.dim);else for(let w of u)a(w,e.cyan);}else if(h==="disable"){let u=s[2]?Ge.find(w=>w.id===s[2]||w.name===s[2]):ee;if(!u){a("No agent selected or id given",e.yellow);return}if(!C)return;a(`Disabling ${u.name}...`,e.amber),C(u.id).then(()=>{a(`\u2713 Disabled ${u.name}`,e.green),Y();},w=>a(`Failed: ${g(w)}`,e.red));}else if(h==="enable"){let u=s[2]?Ge.find(w=>w.id===s[2]||w.name===s[2]):ee;if(!u){a("No agent selected or id given",e.yellow);return}if(!I)return;a(`Enabling ${u.name}...`,e.amber),I(u.id).then(()=>{a(`\u2713 Enabled ${u.name}`,e.green),Y();},w=>a(`Failed: ${g(w)}`,e.red));}else if(h==="delete"||h==="remove"){let u=s[2]?Ge.find(w=>w.id===s[2]||w.name===s[2]):ee;if(!u){a("No agent selected or id given",e.yellow);return}if(u.status==="running"){a("Cannot delete \u2014 agent is running",e.yellow);return}if(!j){a("Agent deletion not available",e.yellow);return}Rn("agent",u.id,u.name);}else if(h==="autonomous"||h==="auto"){let u=s[2]?Ge.find(w=>w.id===s[2]||w.name===s[2]):ee;if(!u){a("No agent selected or id given",e.yellow);return}if(!ut){a("Autonomous toggle not available",e.yellow);return}u.autonomous?(a(`Disabling autonomous mode for "${u.name}"...`,e.amber),ut(u.id,false).then(()=>{a(`${pn} ${u.name} autonomous OFF`,e.cyan),Y();},w=>a(`Failed: ${g(w)}`,e.red))):(a(`Enabling autonomous mode for "${u.name}"...`,e.amber),ut(u.id,true).then(()=>{a(`${pn} ${u.name} autonomous ON`,e.cyan),Y();},w=>a(`Failed: ${g(w)}`,e.red)));}else h==="shop"?ps():a("Usage: /agent add|list|disable|enable|delete|autonomous|shop",e.yellow);return}case "team":{let h=s[1]?.toLowerCase();if(h==="create"||h==="add")hs();else if(h==="list"){let u=In.current;if(u.length===0)a("No teams",e.dim);else for(let w of u)a(` ${w.id} ${w.status.padEnd(8)} ${w.name} (${w.members.length} members)`,e.cyan);}else if(h==="join"){if(!le){a("Join not available",e.yellow);return}let u=s[2],w=s[3]??ee?.id;if(!u||!w){a("Usage: /team join <teamId> [agentId]",e.yellow);return}a(`Joining team ${u}...`,e.amber),le(u,w).then(J=>{a(`\u2713 Agent joined team "${J.name}"`,e.green),Y({includeTeams:true});},J=>a(`Failed: ${g(J)}`,e.red));}else if(h==="leave"){if(!Ee){a("Leave not available",e.yellow);return}let u=s[2],w=s[3]??ee?.id;if(!u||!w){a("Usage: /team leave <teamId> [agentId]",e.yellow);return}a(`Leaving team ${u}...`,e.amber),Ee(u,w).then(J=>{a(`\u2713 Agent left team "${J.name}"`,e.green),Y({includeTeams:true});},J=>a(`Failed: ${g(J)}`,e.red));}else if(h==="disband"){if(!Ft){a("Disband not available",e.yellow);return}let u=s[2];if(!u){a("Usage: /team disband <teamId>",e.yellow);return}a(`Disbanding team ${u}...`,e.amber),Ft(u).then(()=>{a("\u2713 Team disbanded",e.green),Y({includeTeams:true});},w=>a(`Failed: ${g(w)}`,e.red));}else if(h==="set-lead"){if(!dt){a("Set-lead not available",e.yellow);return}let u=s[2],w=s[3];if(!u||!w){a("Usage: /team set-lead <teamId> <agentId>",e.yellow);return}a(`Setting lead for team ${u}...`,e.amber),dt(u,w).then(J=>{a(`\u2713 New lead for team "${J.name}"`,e.green),Y({includeTeams:true});},J=>a(`Failed: ${g(J)}`,e.red));}else a("Usage: /team create|list|join|leave|disband|set-lead",e.yellow);return}case "goal":{let h=s[1]?.toLowerCase();if(h==="add"||h==="create"){let u=s.slice(2).join(" ").trim();if(!u){let w=Zo(Q);Je({title:"New Goal",steps:w,kind:"goal"}),Oe("wizard");return}if(!De){a("Goal creation not available",e.yellow);return}a(`Creating goal "${u}"...`,e.amber),De({title:u}).then(w=>{a(`\u2713 Created goal "${w.title}" (${w.id})`,e.green),Y();},w=>a(`Failed: ${g(w)}`,e.red));}else if(h==="list"){let u=ft.map(w=>` ${w.id} ${w.status.padEnd(8)} ${w.title}`);if(u.length===0)a("No goals",e.dim);else for(let w of u)a(w,e.cyan);}else if(h==="show"){let u=s[2]?ft.find(w=>w.id===s[2]):re;if(!u){a("No goal selected or id given",e.yellow);return}a(`${u.id} ${u.status} "${u.title}"`,e.cyan),u.description&&a(` ${u.description.slice(0,100)}`,e.dim);}else if(h==="status"){let u=s[2]?ft.find(fn=>fn.id===s[2]):void 0,w=u??re;if(!w){a("No goal selected or id given",e.yellow);return}let J=s[u?3:2];if(!J||!a$1.includes(J)){a("Usage: /goal status [id] <active|paused|achieved|abandoned>",e.yellow);return}let Ot=J;if(!gt){a("Status update not available",e.yellow);return}a(`Updating goal status to ${Ot}...`,e.amber),gt(w.id,Ot).then(fn=>{a(`\u2713 Goal "${fn.title}" \u2192 ${Ot}`,e.green),Y();},fn=>a(`Failed: ${g(fn)}`,e.red));}else if(h==="delete"){let u=s[2]?ft.find(w=>w.id===s[2]):re;if(!u){a("No goal selected or id given",e.yellow);return}if(!Ze){a("Goal deletion not available",e.yellow);return}Rn("goal",u.id,u.title);}else a("Usage: /goal add|list|show|status|delete",e.yellow);return}case "run":{let h=s[1]??U?.id;if(!h){a("No task selected or id given",e.yellow);return}if(!l){a("Run not available",e.yellow);return}let u=Le.find(w=>w.id===h);if(u&&!Hr.has(u.status)){a(`Cannot run \u2014 status is ${u.status}`,e.yellow);return}a(`Running ${h}...`,e.amber),l(h).then(()=>{a(`\u2713 Dispatched ${h}`,e.green),Y();},w=>a(`Failed: ${g(w)}`,e.red));return}case "run-all":{if(!y){a("Run-all not available",e.yellow);return}a("Running all todo tasks...",e.amber),y().then(()=>{a("\u2713 Dispatched all todo tasks",e.green),Y();},h=>a(`Failed: ${g(h)}`,e.red));return}case "watch":{if(go){a("Watch mode already active",e.yellow);return}if(!Ae){a("Watch not available",e.yellow);return}a("Starting watch mode...",e.amber),Ae().then(()=>{sr(true),a("\u2713 Watch mode started",e.green);},h=>a(`Failed: ${g(h)}`,e.red));return}case "pause":{if(!go){a("Watch mode not active",e.yellow);return}if(!Ke){a("Pause not available",e.yellow);return}a("Pausing watch mode...",e.amber),Ke().then(()=>{sr(false),a("\u2713 Watch mode paused",e.green);},h=>a(`Failed: ${g(h)}`,e.red));return}case "config":{s[1]?.toLowerCase()==="activity-filter"?gr(u=>{let w=jr(u);return Ue?.(w.label),a(`Activity filter: ${w.label}`,e.amber),new Set(w.types)}):xs();return}case "status":{let h=ne.filter(u=>u.status==="in_progress").length;a(`${Sr} ${h} running ${ne.length} tasks ${Ge.length} agents`,e.cyan);return}case "help":{for(let[h,u]of Object.entries(hn)){let w=u.sub?" "+u.sub.join("|"):u.args?" "+u.args:"";a(` /${h}${w} \u2014 ${u.help}`,e.silver);}return}case "quit":{Wn();return}case "disable":{if(!ee){a("No agent selected",e.yellow);return}if(!C)return;a(`Disabling ${ee.name}...`,e.amber),C(ee.id).then(()=>{a(`\u2713 Disabled ${ee.name}`,e.green),Y();},h=>a(`Failed: ${g(h)}`,e.red));return}case "enable":{if(!ee){a("No agent selected",e.yellow);return}if(!I)return;a(`Enabling ${ee.name}...`,e.amber),I(ee.id).then(()=>{a(`\u2713 Enabled ${ee.name}`,e.green),Y();},h=>a(`Failed: ${g(h)}`,e.red));return}default:a(`Unknown: ${d}. Type /help for commands`,e.yellow);}},[U,ee,Le,Ge,ne,Sr,go,x,T,b$1,y,l,f,C,I,P,O,L,N,le,Ee,Ft,dt,Ae,Ke,a,Wn,Y,Io,Co,hs,xs]);useInput((i,p)=>{if(!($t&&(lr(false),i==="?"||p.escape||i==="\x1BOP"))&&!yn){if((p.ctrl||p.meta)&&i==="s"&&Fe==="wizard"&&bt?.kind==="agent"){ps();return}if(Fe!=="none"){if(p.escape){Oe("none"),Ct(""),To.reset();return}if(p.return){let s=cn.trim();if(!s)return;if(Fe==="new_task"){if(!f)return;Oe("none"),Ct(""),a(`Creating "${s}"...`,e.amber),f(s).then(d=>{a(`\u2713 Created "${d.title}" (${d.id})`,e.green),Y();},d=>a(`Failed to create: ${d instanceof Error?d.message:String(d)}`,e.red));}else if(Fe==="command"){let d=s;if(Mt.length>0&&Mt[wo]){let g=Mt[wo],h=g.cmd.replace(/\s+\[.*\]$/,"");if((h.startsWith(s)||s==="/")&&(d=h),g.subs&&!h.includes(" ")){Ct(h+" "),Jt(0);return}}Oe("none"),Ct(""),Jt(0),To.push(d),Ga(d);}return}if(p.tab&&Fe==="command"){if(Mt.length>0){let s=Mt[wo];if(s){let d=s.cmd.replace(/\s+\[.*\]$/,"");Ct(d+(s.subs?" ":"")),Jt(0);}}else {let s=$r(cn);s&&Ct(d=>d+s);}return}if(p.upArrow&&Fe==="command"){if(Mt.length>0)Jt(s=>Math.max(0,s-1));else {let s=To.prev();s!==null&&Ct(s);}return}if(p.downArrow&&Fe==="command"){if(Mt.length>0)Jt(s=>Math.min(Mt.length-1,s+1));else {let s=To.next();Ct(s??"");}return}if(p.backspace||p.delete){Ct(s=>s.slice(0,-1)),Jt(0);return}i&&!p.ctrl&&!p.meta&&(Ct(s=>s+i),Jt(0));return}if(i.toLowerCase()==="q"){Wn();return}if(p.escape){if($e){jn(false),Zn(0);return}if(A==="logs"&&qn>=0){ur(-1),Kn(0);return}return}if((i==="+"||i==="=")&&A!=="logs"){yo?(br(false),kn(-Math.floor(It/2))):kn(s=>Math.max(-An,s-3));return}if(i==="-"&&A!=="logs"){yo?(br(false),kn(Math.floor(It/2))):kn(s=>Math.min(An,s+3));return}if(i==="M"&&A!=="logs"){br(s=>!s);return}if(i==="?"){lr(true);return}if(i==="\x1BOP"){lr(true);return}if(i==="/"&&!$e){Oe("command"),Ct("/"),Jt(0);return}if((i==="a"||i==="A")&&A==="logs"&&!$e&&!yn&&!Xn){cr(true);return}if(i==="f"&&A==="logs"&&!$e&&!yn&&!Xn){dr(true);return}if(i==="F"&&A==="logs"&&!$e&&!yn&&!Xn){ts(s=>new Set(jr(s).types));return}if((i==="z"||i==="Z")&&Cn.length>0){Ca();return}if((i==="f"||i==="F")&&(A==="tasks"||A==="agents"||A==="goals")&&!$e){gr(s=>{let d=jr(s);return Ue?.(d.label),new Set(d.types)});return}if((i==="n"||i==="N")&&A==="tasks"&&!$e&&f){Io();return}if((i==="n"||i==="N")&&A==="agents"&&!$e&&P){Co();return}if((i==="n"||i==="N")&&A==="goals"&&!$e&&De){let s=Zo(Q);Je({title:"New Goal",steps:s,kind:"goal"}),Oe("wizard");return}if((i==="e"||i==="E")&&A==="goals"&&re&&Ye){let s=Ui(re,Q);Je({title:`Edit Goal: ${re.title}`,steps:s,kind:"edit_goal",targetId:re.id}),Oe("wizard");return}if((i==="d"||i==="D")&&A==="goals"&&re&&Ze){Rn("goal",re.id,re.title);return}if((i==="c"||i==="C")&&A==="goals"&&re&&gt){(re.status==="active"||re.status==="paused")&&(a(`Marking goal "${re.title}" as achieved...`,e.amber),gt(re.id,"achieved").then(()=>{a(`\u2713 Goal "${re.title}" achieved`,e.green),Y();},s=>a(`Failed: ${s instanceof Error?s.message:String(s)}`,e.red)));return}if((i==="x"||i==="X")&&A==="goals"&&re&&gt){(re.status==="active"||re.status==="paused")&&(a(`Abandoning goal "${re.title}"...`,e.amber),gt(re.id,"abandoned").then(()=>{a(`\u2713 Goal "${re.title}" abandoned`,e.dim),Y();},s=>a(`Failed: ${s instanceof Error?s.message:String(s)}`,e.red)));return}if((i==="p"||i==="P")&&A==="goals"&&re&&gt){let s=re.status==="paused"?"active":"paused";(re.status==="active"||re.status==="paused")&&gt(re.id,s).then(()=>{a(`Goal "${re.title}" ${s}`,e.cyan),Y();},d=>a(`Failed: ${d instanceof Error?d.message:String(d)}`,e.red));return}if((i==="a"||i==="A")&&A==="tasks"&&U?.status==="review"&&O){a(`Approving "${U.title}"...`,e.amber),O(U.id).then(()=>{a(`\u2713 Approved "${U.title}"`,e.green),Y();},s=>a(`Failed: ${s instanceof Error?s.message:String(s)}`,e.red));return}if((i==="x"||i==="X")&&A==="tasks"&&U?.status==="review"&&L){a(`Rejecting "${U.title}"...`,e.amber),L(U.id).then(()=>{a(`\u2713 Rejected "${U.title}" \u2192 todo`,e.green),Y();},s=>a(`Failed: ${s instanceof Error?s.message:String(s)}`,e.red));return}if((i==="c"||i==="C")&&A==="tasks"&&U&&x){if(U.status==="done"||U.status==="failed"||U.status==="cancelled"){a(`Cannot cancel \u2014 status is ${U.status}`,e.yellow);return}a(`Cancelling "${U.title}"...`,e.amber),x(U.id).then(()=>{a(`\u2713 Cancelled "${U.title}"`,e.green),Y();},s=>a(`Failed: ${s instanceof Error?s.message:String(s)}`,e.red));return}if((i==="e"||i==="E")&&A==="tasks"&&U&&E){Ma(U);return}if((i==="e"||i==="E")&&A==="agents"&&ee&&W){va(ee);return}if((i==="s"||i==="S")&&A==="tasks"){cs(s=>!s),Hn(0),Sn(0);return}if((i==="g"||i==="G")&&A==="tasks"&&!$e){ha(s=>!s),Hn(0),Sn(0);return}if((i==="s"||i==="S")&&A==="agents"&&ee&&z){if(!Object.values(ve.running).some(d=>d.agent_id===ee.id)&&ee.status!=="running"){a(`Agent "${ee.name}" is not running`,e.yellow);return}a(`Force-stopping agent "${ee.name}"...`,e.amber),z(ee.id).then(()=>{a(`\u2713 Stopped agent "${ee.name}"`,e.green),Y();},d=>a(`Failed: ${d instanceof Error?d.message:String(d)}`,e.red));return}if((i==="d"||i==="D")&&A==="tasks"&&U&&U.status!=="in_progress"&&N){Rn("task",U.id,U.title);return}if((i==="d"||i==="D")&&A==="agents"&&ee&&j){let s=Object.values(ve.running).some(d=>d.agent_id===ee.id);if(s&&!z){a(`Cannot delete \u2014 agent "${ee.name}" is running. Press S to stop first.`,e.yellow);return}Rn("agent",ee.id,ee.name,{needsForceStop:s});return}if((i==="u"||i==="U")&&A==="agents"&&ee&&ut){let s=!ee.autonomous;a(`${s?"Enabling":"Disabling"} autonomous mode for "${ee.name}"...`,e.amber),ut(ee.id,s).then(()=>{a(`${pn} ${ee.name} autonomous ${s?"ON":"OFF"}`,e.cyan),Y();},d=>a(`Failed: ${d instanceof Error?d.message:String(d)}`,e.red));return}if(!$e){if(i==="g"||i==="G"){Tn("goals");return}if(i==="t"||i==="T"){Tn("tasks");return}if(i==="a"||i==="A"){Tn("agents");return}if(i==="l"||i==="L"){Tn("logs");return}}if(!$e){let s=Oo.map(g=>g.id),d=s.indexOf(A);if(p.tab||p.rightArrow){Tn(s[(d+1)%s.length]);return}if(p.leftArrow){Tn(s[(d+s.length-1)%s.length]);return}}if(p.return){let s=vn>0?Bt.length:-1;if(A==="tasks"&&fo===s){cs(g=>!g),Hn(0),Sn(0);return}let d=Bt.length+(vn>0?1:0);if(A==="tasks"&&fo===d&&f){Io();return}if(A==="goals"&&ar===ft.length&&De){let g=Zo(Q);Je({title:"New Goal",steps:g,kind:"goal"}),Oe("wizard");return}if(A==="agents"&&ir===Ge.length&&P){Co();return}if(A==="goals"&&re){jn(g=>!g),Zn(0);return}if(A==="tasks"&&U){jn(g=>!g);return}if(A==="agents"&&ee){jn(g=>!g);return}if(A==="logs"&&qn>=0){jn(g=>!g);return}}if((i==="r"||i==="R")&&A==="tasks"&&U&&l){if(!Hr.has(U.status)){a(`Cannot run "${U.title}" \u2014 status is ${U.status}`,e.yellow);return}a(`Running "${U.title}"...`,e.green),l(U.id).then(()=>{a(`Dispatched "${U.title}"`,e.green),Y();},s=>a(`Failed to run: ${s instanceof Error?s.message:String(s)}`,e.red));return}if(p.upArrow||i==="k"){if(A==="goals"&&$e){Zn(s=>Math.max(0,s-1));return}A==="goals"?Zr(s=>{let d=Math.max(0,s-1);return hr(g=>d<g?d:g),d}):A==="tasks"?Hn(s=>{let d=Math.max(0,s-1);return Sn(g=>d<g?d:g),d}):A==="agents"?Yr(s=>{let d=Math.max(0,s-1);return pr(g=>d<g?d:g),d}):A==="logs"&&ur(s=>{if(s===-1){let g=ze.length-1;return Kn(Math.max(0,g-Se+2)),Math.max(0,g)}let d=Math.max(0,s-1);return Kn(g=>d<g?d:g),d});}if(p.downArrow||i==="j"){if(A==="goals"&&$e){Zn(s=>s+1);return}if(A==="goals"){let s=ft.length+(De?1:0)-1;Zr(d=>{let g=Math.min(Math.max(0,s),d+1);return hr(h=>g>=h+Se?g-Se+1:h),g});}else if(A==="tasks"){let s=Bt.length+(f?1:0)+(vn>0?1:0)-1;Hn(d=>{let g=Math.min(Math.max(0,s),d+1);return Sn(h=>g>=h+Se?g-Se+1:h),g});}else if(A==="agents"){let s=Ge.length+(P?1:0)-1;Yr(d=>{let g=Math.min(Math.max(0,s),d+1);return pr(h=>g>=h+Se?g-Se+1:h),g});}else A==="logs"&&ur(s=>{if(s===-1)return -1;let d=ze.length-1;if(s>=d)return Kn(0),-1;let g=s+1;return Kn(h=>g>=h+Se-1?g-Se+2:h),g});}}});let ot=Fe!=="none",ys=qn>=0?ze[qn]:void 0,Mo=yo?"+/- exit max":"+/- resize \u2502 M max",ws=!ot&&$e&&A==="tasks"&&U,Ss=!ot&&$e&&A==="agents"&&ee,ks=!ot&&$e&&A==="goals"&&re,Wa=!ot&&$e&&A==="logs"&&ys,kr=U?.id,za=useMemo(()=>kr?ze.filter(i=>i.taskId===kr):[],[ze,kr]),Va=!ot&&A==="tasks"&&U&&Hr.has(U.status)&&!!l,Ha=!ot&&!$e&&(A==="goals"&&!!De||A==="tasks"&&!!f||A==="agents"&&!!P),ja=!ot&&A==="tasks"&&U?.status==="review"&&!!O,Ua=!ot&&A==="tasks"&&U?.status==="review"&&!!L,Xa=ee?Object.values(ve.running).some(i=>i.agent_id===ee.id):false,qa=!ot&&(A==="goals"&&re&&!!Ze||A==="tasks"&&U&&U.status!=="in_progress"&&!!N||A==="agents"&&ee&&!!j),Ka=!ot&&!$e&&(A==="goals"&&!!re&&!!Ye||A==="tasks"&&!!U&&!!E||A==="agents"&&!!ee&&!!W),Ya=!ot&&A==="agents"&&ee&&(Xa||ee.status==="running")&&!!z,Za=!ot&&A==="agents"&&!!ee&&!!ut,Ja=!ot&&A==="goals"&&!!re&&(re.status==="active"||re.status==="paused")&&!!gt,Qa=!ot&&Cn.length>0,Cs=Fe==="command"&&Mt.length>0,Is=bt?.kind==="task"||bt?.kind==="edit_task";return jsxs(Box,{flexDirection:"column",width:K,height:ye,children:[jsx(Zs,{projectName:t,activeView:A,mode:Sr,stats:Ts,tokens:Ba,uptime:$a,width:K,version:Wt,latestVersion:Kt,updateInstalled:R,taskBadge:vn>0?Le.length:void 0,flashTab:fr?.tab,flashColor:fr?.color,onFlashComplete:fr?()=>rs(void 0):void 0}),jsx(Box,{height:1}),$t&&jsx(wi,{width:K,height:ye-7}),!$t&&Zt==="welcome"&&A==="tasks"&&jsx(ui,{width:K,height:ye}),!$t&&A==="goals"&&jsx(Ac,{goals:ft,selectedIndex:ar,scrollOffset:ba,height:Se,width:_e,showAddRow:!!De,agentNameMap:un,tasksByGoalMap:ya}),!$t&&Zt!=="welcome"&&A==="tasks"&&jsx(Bc,{tasks:Bt,selectedIndex:fo,scrollOffset:pa,height:Se,width:_e,showAddRow:!!f,agentNameMap:un,hiddenCount:vn,goalMap:Mn,groupByGoal:Yn}),!$t&&A==="tasks"&&(Zt==="task_created"||Zt==="run_started")&&jsx(gi,{step:Zt,width:K}),!$t&&A==="tasks"&&Zt==="completed"&&jsx(mi,{width:K}),!$t&&A==="agents"&&jsx(Ec,{agents:Ge,selectedIndex:ir,scrollOffset:xa,height:Se,width:_e,state:ve,taskTitleMap:Jn,showAddRow:!!P,agentTeamMap:_n,teamLeadSet:Sa,activeTeamCount:Qn}),!$t&&A==="logs"&&jsxs(Fragment,{children:[jsx(Lc,{messages:ze,height:yn||Xn?Math.max(3,Se-16):Se,agents:Ge,logAgentFilter:Qr,logTypeFilter:es,selectedIndex:qn,scrollOffset:ca,agentNameMap:un,agentColorMap:So,agentMsgCounts:gs,taskTitleMap:Jn,width:_e}),yn&&jsx(Box,{paddingX:2,children:jsx(ii,{agents:Ge,selected:Qr,msgCounts:gs,colorMap:So,maxHeight:Math.min(Se-4,18),onConfirm:i=>{la(i),cr(false);},onCancel:()=>cr(false)})}),Xn&&jsx(Box,{paddingX:2,children:jsx(di,{selected:es,typeCounts:wa,onConfirm:i=>{ts(i),dr(false);},onCancel:()=>dr(false)})})]}),jsx(Box,{height:1}),$t?null:Fe==="wizard"&&bt?jsx(oi,{title:bt.title,steps:bt.steps,onComplete:_a,onCancel:Ra,width:_e,height:Et,onPasteImage:Is?Ia:void 0,onSuggestionSelected:bt.kind==="agent"?Aa:void 0,footerExtra:dn.length>0&&Is?`\u{1F4CE}${dn.length}`:void 0},`${bt.kind}-${bt.title}`):Cs?jsxs(Fragment,{children:[jsx(Jo,{label:"COMMANDS",width:_e}),jsx(Rc,{suggestions:Mt,selectedIndex:wo,height:Math.min(Mt.length,Et),width:_e})]}):Fe==="new_task"?jsxs(Fragment,{children:[jsx(Vc,{mode:Fe,width:_e}),jsx(Hc,{mode:Fe,value:cn,width:_e})]}):ws?jsxs(Fragment,{children:[jsx(Dc,{task:U,width:_e,resizeHint:Mo}),jsx(qs,{task:U,height:Et,width:_e,taskLogs:za,agentNameMap:un,taskTitleMap:Jn})]}):ks?jsxs(Fragment,{children:[jsx(Jo,{label:`GOAL: ${re.title}`,width:_e,suffixLen:Mo.length+2,suffix:jsxs(Text,{color:e.dim,children:[" ",Mo," "]})}),jsx($c,{goal:re,height:Et,width:_e,agentNameMap:un,tasks:ka,progressReport:aa,scrollOffset:Ta,onClampScroll:Zn})]}):Ss?jsxs(Fragment,{children:[jsx(Fc,{agent:ee,width:_e,resizeHint:Mo}),jsx(Gc,{agent:ee,height:Et,state:ve,taskTitleMap:Jn,teamName:_n.get(ee.id)})]}):Wa?jsxs(Fragment,{children:[jsx(Jo,{label:"LOG",width:_e}),jsx(Nc,{message:ys,height:Et,width:_e,agents:Ge,agentNameMap:un,agentColorMap:So,taskTitleMap:Jn})]}):ze.length>0&&A!=="logs"?jsxs(Fragment,{children:[(()=>{let i=` F:${po.toUpperCase()} \u2502 ${mr.length}/${ze.length}`;return jsx(Jo,{label:"ACTIVITY",width:_e,suffixLen:i.length,suffix:jsxs(Fragment,{children:[jsx(Text,{color:e.dim,children:" F:"}),jsx(Text,{color:e.amber,children:po.toUpperCase()}),jsxs(Text,{color:e.ghost,children:[" ","\u2502"," ",mr.length,"/",ze.length]})]})})})(),jsx(Pc,{messages:mr,height:Math.max(1,Et-1),width:_e,agents:Ge,agentNameMap:un,agentColorMap:So})]}):A==="goals"?jsx(Uo,{count:ft.length,config:Cc,width:_e}):A==="tasks"?jsx(Uo,{count:Le.length,config:Ic,width:_e}):A==="agents"?jsx(Uo,{count:Ge.length,config:Mc,width:_e}):null,jsx(Box,{flexGrow:1}),jsx(yi,{toasts:ga,onDismiss:fa}),Cn.length>0&&jsx(_c,{deletions:Cn,width:K}),jsx(Qs,{mode:Fe==="command"?"command":"navigate",value:Fe==="command"?cn:"",completion:Fe==="command"?$r(cn):null,activeView:A,canRun:!!Va,canNew:!!Ha,canApprove:!!ja,canReject:!!Ua,canCancel:A==="tasks"&&!!U&&U.status==="in_progress"&&!!x,canDelete:!!qa,canUndo:!!Qa,canEdit:!!Ka,canForceStop:!!Ya,canToggleAuto:!!Za,autoActive:ee?.autonomous,canPause:!!Ja,isPaused:re?.status==="paused",canToggleShowAll:A==="tasks"&&Le.length>qi,showAllActive:ls,hasDetail:!!(ws||Ss||ks),itemCount:A==="goals"?ft.length:A==="tasks"?Le.length:A==="agents"?Q.length:ze.length,itemLabel:A==="goals"?"goals":A==="tasks"?"tasks":A==="agents"?"agents":"events",width:K,hasSuggestions:Cs,onboardingCompleted:r.onboardingCompleted})]})}var _c=io.memo(function({deletions:n,width:o}){let[,r]=useState(0);useEffect(()=>{let f=setInterval(()=>r(x=>x+1),1e3);return ()=>clearInterval(f)},[]);let l=Date.now();return jsx(Box,{flexDirection:"column",width:o,children:n.map(f=>{let x=Math.max(0,Math.ceil((f.expiresAt-l)/1e3)),T=Math.max(0,o-4),b=f.entityType==="task"?"Task":f.entityType==="agent"?"Agent":"Goal",y=Math.max(10,T-b.length-30),C=f.entityName.length>y?f.entityName.slice(0,y-1)+"\u2026":f.entityName;return jsx(Box,{paddingX:2,children:jsxs(Text,{color:e.yellow,children:["\u2717 ",jsx(Text,{bold:true,children:b}),` "${C}" \u2014 `,jsxs(Text,{color:e.amber,bold:true,children:[x,"s"]}),jsx(Text,{color:e.dim,children:" \u2502 "}),jsx(Text,{color:e.gray,bold:true,children:"Z"}),jsx(Text,{color:e.dim,children:" undo"})]})},f.key)})})});function Rc({suggestions:t,selectedIndex:n,height:o,width:r}){let l=o,f=0;n>=l&&(f=n-l+1);let x=t.slice(f,f+l);return jsx(Box,{flexDirection:"column",paddingX:2,children:x.map((T,b)=>{let y=b+f,C=y===n,I=C?"\u25B6":" ",$=Math.min(20,Math.max(14,...t.map(P=>P.cmd.length+1))),S=T.cmd.padEnd($),H=T.subs?` ${T.subs}`:"",V=Math.max(4,r-$-H.length-8),F=T.desc.length>V?T.desc.slice(0,V-1)+"\u2026":T.desc;return jsxs(Text,{wrap:"truncate",children:[jsx(Text,{color:C?e.amber:e.ghost,children:` ${I} `}),jsx(Text,{color:C?e.white:e.silver,bold:C,children:S}),jsx(Text,{color:e.dim,children:F}),H&&jsx(Text,{color:e.ghost,children:H})]},y)})})}function Ac({goals:t,selectedIndex:n,scrollOffset:o=0,height:r,width:l,showAddRow:f,agentNameMap:x,tasksByGoalMap:T}){let b=t.length,y=t.slice(o,o+r),C=f&&b>=o&&b<o+r;return jsxs(Box,{flexDirection:"column",height:r,children:[y.map((I,$)=>jsx(Box,{paddingX:2,children:jsx(Xs,{goal:I,selected:$+o===n,width:l-2,agentNameMap:x,tasksByGoal:T?.get(I.id)})},I.id)),C&&jsx(Box,{paddingX:2,children:jsxs(Text,{color:n===b?e.amber:e.ghost,children:[n===b?" \u25B8 ":" ",jsx(Text,{color:n===b?e.amber:e.dim,children:"+ add goal..."})]})},"__add__")]})}function $c({goal:t,height:n,width:o,agentNameMap:r,tasks:l,progressReport:f,scrollOffset:x=0,onClampScroll:T}){let y=io.useMemo(()=>{let V=l??[],F=t.assignee?r?.get(t.assignee)??t.assignee:"\u2014",P=Math.max(20,o-6),j=(z,X)=>{if(z.length<=X)return [z];let _=[];for(let le=0;le<z.length;le+=X)_.push(z.slice(le,le+X));return _},O=_r(f)?.split(`
12
+ `);});},[]),useEffect(()=>{_?.().then(ds).catch(()=>{}),pt?.().then(qr).catch(()=>{});},[]);let Co=useCallback(()=>{Je({title:"NEW AGENT",steps:Yo(Q,In.current),kind:"agent"}),Oe("wizard");},[Q]),ps=useCallback(()=>{Je({title:"AGENT SHOP",steps:Oi(),kind:"agent_shop"}),Oe("wizard");},[]),Io=useCallback(()=>{Un([]),Je({title:"NEW TASK",steps:Di(Q),kind:"task"}),Oe("wizard");},[Q]),Ia=useCallback(async()=>{try{let{detectClipboardType:i,getClipboardImage:p}=await import('./clipboard-service-AJTJG2DJ.js'),s=await i();if(s!=="image")return a(s==="text"?"Clipboard has text, not image":"Clipboard is empty",e.dim),s;let d=await p();if(!d)return a("Failed to read clipboard image",e.red),"empty";let{mkdtemp:g,writeFile:h}=await import('fs/promises'),{tmpdir:u}=await import('os'),{join:w}=await import('path'),J=await g(w(u(),"orch-paste-")),Ot=w(J,`clipboard-${Date.now()}.${d.ext}`);return await h(Ot,d.data),Un(fn=>[...fn,Ot]),a(`\u{1F4CE} Image attached (${Math.round(d.data.length/1024)}KB)`,e.green),"image"}catch{return a("Clipboard paste failed",e.red),"empty"}},[a]),Ma=useCallback(i=>{Je({title:"EDIT TASK",steps:Gi(i,Q),kind:"edit_task",targetId:i.id}),Oe("wizard");},[Q]),hs=useCallback(()=>{Je({title:"NEW TEAM",steps:Pi(Q,Vt),kind:"team"}),Oe("wizard");},[Q]),va=useCallback(i=>{Je({title:"EDIT AGENT",steps:zi(i,Q,Vt),kind:"edit_agent",targetId:i.id}),Oe("wizard");},[Vt]),xs=useCallback(()=>{Je({title:"SETTINGS",steps:Vi(po,ns,ho),kind:"config"}),Oe("wizard");},[po,ns]),_a=useCallback(i=>{Oe("none");let p=bt?.kind,s=bt?.targetId;if(Je(null),p==="agent_shop"){let d=i.shop_template,g=d?b(d):void 0;if(g){let h=Yo(Q,In.current),u=Vr(h,g,nt);Je({title:`NEW AGENT \u2014 ${g.name}`,steps:u,kind:"agent_from_shop"}),Oe("wizard");}else a("No template selected",e.yellow);return}if((p==="agent"||p==="agent_from_shop")&&P){let d=Li(i,nt);a(`Creating agent "${d.name}"...`,e.amber),P(d.name,d.adapter,{model:d.model,effort:d.effort,role:d.role,approval_policy:d.approval_policy,skills:d.skills}).then(g=>{a(`\u2713 Created agent "${g.name}" (${g.id}, ${g.adapter})`,e.green),d.team_id&&le?le(d.team_id,g.id).then(h=>{a(`\u2713 Joined team "${h.name}"`,e.green),Y({includeTeams:true});},h=>a(`Failed to join team: ${h instanceof Error?h.message:String(h)}`,e.red)):Y();},g=>a(`Failed: ${g instanceof Error?g.message:String(g)}`,e.red));}else if(p==="team"&&X){let d=Ni(i);a(`Creating team "${d.name}"...`,e.amber),X(d).then(g=>{a(`\u2713 Created team "${g.name}" (${g.id}, ${g.members.length} members)`,e.green),Y({includeTeams:true});},g=>a(`Failed: ${g instanceof Error?g.message:String(g)}`,e.red));}else if(p==="task"&&f){let d=Fi(i),g=dn.length>0?[...dn]:void 0;Un([]),a(`Creating "${d.title}"...`,e.amber),f(d.title,{priority:d.priority,description:d.description,attachments:g}).then(h=>{a(`\u2713 Created "${h.title}" (${h.id})${g?` \u{1F4CE}${g.length}`:""}`,e.green),d.assignee&&b$1&&b$1(h.id,d.assignee).catch(()=>{}),Y();},h=>a(`Failed: ${h instanceof Error?h.message:String(h)}`,e.red));}else if(p==="edit_task"&&s&&E){let d=Wi(i),g=dn.length>0?[...dn]:void 0;Un([]),a("Updating task...",e.amber),E(s,{...d,attachments:g}).then(h=>{a(`\u2713 Updated "${h.title}"${g?` \u{1F4CE}${g.length}`:""}`,e.green),d.assignee&&b$1&&b$1(s,d.assignee).catch(()=>{}),Y();},h=>a(`Failed: ${h instanceof Error?h.message:String(h)}`,e.red));}else if(p==="edit_agent"&&s&&W){let d=Hi(i),g=d.team_id??"",h=Vt.find(u=>u.members.some(w=>w.agent_id===s))?.id??"";a("Updating agent...",e.amber),W(s,{name:d.name,role:d.role,model:d.model,effort:d.effort}).then(u=>{a(`\u2713 Updated agent "${u.name}"`,e.green);let w=[];h&&h!==g&&Ee&&w.push(Ee(h,s).then(J=>a(`\u2713 Left team "${J.name}"`,e.green),J=>a(`Failed to leave team: ${J instanceof Error?J.message:String(J)}`,e.red))),g&&g!==h&&le&&w.push(le(g,s).then(J=>a(`\u2713 Joined team "${J.name}"`,e.green),J=>a(`Failed to join team: ${J instanceof Error?J.message:String(J)}`,e.red))),Promise.all(w).then(()=>Y({includeTeams:w.length>0}));},u=>a(`Failed: ${u instanceof Error?u.message:String(u)}`,e.red));}else if(p==="config"){if(i.activity_filter){let u=Fn.find(w=>w.label===i.activity_filter);u&&(gr(new Set(u.types)),Ue?.(u.label));}if(i.max_concurrent){let u=parseInt(i.max_concurrent,10);u>0&&(da(u),Gn?.(u));}let d=i.notifications_toast==="true",g=i.notifications_bell==="true",h={toast:d,bell:g};ua(h),Gt?.(h),a("Settings saved",e.green);}else if(p==="goal"&&De){let d=ji(i);a(`Creating goal "${d.title}"...`,e.amber),De(d).then(g=>{a(`\u2713 Created goal "${g.title}" (${g.id})`,e.green),Y();},g=>a(`Failed: ${g instanceof Error?g.message:String(g)}`,e.red));}else if(p==="edit_goal"&&s&&Ye){let d=Xi(i);a("Updating goal...",e.amber),Ye(s,d).then(g=>{a(`\u2713 Updated goal "${g.title}"`,e.green),Y();},g=>a(`Failed: ${g instanceof Error?g.message:String(g)}`,e.red));}},[bt,P,f,X,le,Ee,b$1,E,W,ut,De,Ye,a,Y,Ue,Gn,ho,Gt,Vt,dn]),Ra=useCallback(()=>{Oe("none"),Je(null),Un([]);},[]),Aa=useCallback(i=>{let p=b(i);if(!p)return;let s=Yo(Q,In.current),d=Vr(s,p,nt);Je({title:`NEW AGENT \u2014 ${p.name}`,steps:d,kind:"agent_from_shop"}),Oe("wizard");},[]);useEffect(()=>{if(!$)return;let i=null,p=()=>{i||(i=setTimeout(()=>{i=null,Y().catch(()=>{});},150));},s=$(d=>{if(d.type==="agent:started"&&(gn.current.set(d.runId,d.agentId),ko.current.set(d.runId,d.taskId)),Uc(d,a,gn.current,ko.current),d.type==="task:created"?mo(g=>g==="welcome"?"task_created":g):d.type==="agent:started"?mo(g=>g==="task_created"?"run_started":g):d.type==="task:status_changed"&&d.to==="done"&&mo(g=>g==="run_started"?"completed":g),d.type==="task:status_changed"&&(d.to==="done"?bo("done",d.taskId):d.to==="failed"?bo("failed",d.taskId):d.to==="review"&&bo("review",d.taskId),xo.current.toast&&ss.current!=="tasks")){let g=d.to==="done"?e.green:d.to==="failed"?e.red:d.to==="review"?e.blue:void 0;g&&rs({tab:"tasks",color:g});}(d.type==="task:status_changed"||d.type==="task:created"||d.type==="task:assigned"||d.type==="agent:started"||d.type==="agent:completed"||d.type==="run:retry"||d.type==="goal:created"||d.type==="goal:status_changed"||d.type==="goal:updated"||d.type==="goal:deleted")&&p();});return ()=>{s(),i&&clearTimeout(i);}},[$,a,Y,bo]);let Sr=xt?"observing":go?"watching":"idle",$a=ve.started_at?g(ve.started_at):void 0,bs=ve.stats.total_tokens.total,Ts=useMemo(()=>{let i={running:0,retrying:0,review:0,todo:0,done:0,failed:0,cancelled:0};for(let p of ne)p.status==="in_progress"?i.running++:p.status==="retrying"?i.retrying++:p.status==="review"?i.review++:p.status==="todo"?i.todo++:p.status==="done"?i.done++:p.status==="failed"?i.failed++:p.status==="cancelled"&&i.cancelled++;return {...i,teams:Qn}},[ne,Qn]);Ts.running;let Ba=useMemo(()=>({input:ve.stats.total_tokens.input??0,output:ve.stats.total_tokens.output??0,reasoning:ve.stats.total_tokens.reasoning??0,total:bs,cache_read:ve.stats.total_tokens.cache_read??0,cache_write:ve.stats.total_tokens.cache_write??0}),[ve.stats.total_tokens,bs]),It=Math.max(4,ye-9),Ea=_n.size,Oa=Q.length>Ea,La=Qn>0?Qn+(Oa?1:0):0,Pa=useMemo(()=>{if(!Yn||Mn.size===0)return 0;let i=0,p=new Set,s=false;for(let d of Bt)d.goalId&&Mn.has(d.goalId)?p.has(d.goalId)||(p.add(d.goalId),i++):s=true;return s&&i++,i},[Yn,Mn,Bt]),Na=A==="goals"?ft.length+1:A==="tasks"?Bt.length+1+(vn>0?1:0)+Pa:A==="agents"?Q.length+1+La:0,Da=Math.min(Na+1,Math.ceil(It*.5)),Fa=A==="logs"?It:Math.max(2,Math.min(Da,It-4)),Se,Et;if(A==="logs")Se=It,Et=0;else if(yo)Se=0,Et=Math.max(1,It);else {let i=Math.max(3,Math.min(Fa+xr,It-4));Se=i,Et=Math.max(1,It-i);}let _e=Math.max(10,K-2),Mt=useMemo(()=>Fe==="command"?Js(cn):[],[Fe,cn]),An=It-4-3;useEffect(()=>{xr>An&&kn(An),xr<-An&&kn(-An);},[It]),useEffect(()=>{Sn(i=>Math.min(i,Math.max(0,Bt.length-Se)));},[Bt.length,Se]),useEffect(()=>{pr(i=>Math.min(i,Math.max(0,Ge.length-Se)));},[Ge.length,Se]),useEffect(()=>{hr(i=>Math.min(i,Math.max(0,ft.length-Se)));},[ft.length,Se]);let Ga=useCallback(i=>{let s=i.trim().replace(/^\//,"").split(/\s+/),d=s[0]?.toLowerCase();if(!d)return;let g=h=>h instanceof Error?h.message:String(h);switch(d){case "cancel":{if(!U){a("No task selected",e.yellow);return}if(!x)return;a(`Cancelling "${U.title}"...`,e.amber),x(U.id).then(()=>{a(`\u2713 Cancelled "${U.title}"`,e.green),Y();},h=>a(`Failed: ${g(h)}`,e.red));return}case "retry":{if(!U){a("No task selected",e.yellow);return}if(!T)return;a(`Retrying "${U.title}"...`,e.amber),T(U.id).then(()=>{a(`\u2713 Retried "${U.title}"`,e.green),Y();},h=>a(`Failed: ${g(h)}`,e.red));return}case "assign":{if(!U){a("No task selected",e.yellow);return}if(!b$1||!s[1]){a("Usage: assign <agent>",e.yellow);return}a(`Assigning "${U.title}" to ${s[1]}...`,e.amber),b$1(U.id,s[1]).then(()=>{a(`\u2713 Assigned "${U.title}" to ${s[1]}`,e.green),Y();},h=>a(`Failed: ${g(h)}`,e.red));return}case "task":{let h=s[1]?.toLowerCase();if(h==="add"){let u=s.slice(2).join(" ");if(!u){Io();return}if(!f){a("Create not available",e.yellow);return}a(`Creating "${u}"...`,e.amber),f(u).then(w=>{a(`\u2713 Created "${w.title}" (${w.id})`,e.green),Y();},w=>a(`Failed: ${g(w)}`,e.red));}else if(h==="list"){let u=Le.map(w=>` ${w.id} ${w.status.padEnd(11)} ${w.title}`);if(u.length===0)a("No tasks",e.dim);else for(let w of u)a(w,e.cyan);}else if(h==="show"){let u=s[2]?Le.find(w=>w.id===s[2]):U;if(!u){a("No task selected or id given",e.yellow);return}a(`${u.id} ${u.status} P${u.priority} "${u.title}"`,e.cyan),u.assignee&&a(` agent: ${u.assignee}`,e.dim),u.description&&a(` ${u.description.slice(0,100)}`,e.dim);}else if(h==="cancel"){let u=s[2]?Le.find(w=>w.id===s[2]):U;if(!u){a("No task selected or id given",e.yellow);return}if(!x)return;a(`Cancelling "${u.title}"...`,e.amber),x(u.id).then(()=>{a(`\u2713 Cancelled "${u.title}"`,e.green),Y();},w=>a(`Failed: ${g(w)}`,e.red));}else if(h==="retry"){let u=s[2]?Le.find(w=>w.id===s[2]):U;if(!u){a("No task selected or id given",e.yellow);return}if(!T)return;a(`Retrying "${u.title}"...`,e.amber),T(u.id).then(()=>{a(`\u2713 Retried "${u.title}"`,e.green),Y();},w=>a(`Failed: ${g(w)}`,e.red));}else if(h==="assign"){let u=s[2]?Le.find(Ot=>Ot.id===s[2]):void 0,w=u??U,J=u?s[3]:s[2];if(!w){a("No task selected or id given",e.yellow);return}if(!J){a("Usage: /task assign [id] <agent>",e.yellow);return}if(!b$1)return;a(`Assigning "${w.title}" to ${J}...`,e.amber),b$1(w.id,J).then(()=>{a(`\u2713 Assigned "${w.title}" to ${J}`,e.green),Y();},Ot=>a(`Failed: ${g(Ot)}`,e.red));}else if(h==="approve"){let u=s[2]?Le.find(w=>w.id===s[2]):U;if(!u){a("No task selected or id given",e.yellow);return}if(u.status!=="review"){a(`Cannot approve \u2014 status is ${u.status}`,e.yellow);return}if(!O)return;a(`Approving "${u.title}"...`,e.amber),O(u.id).then(()=>{a(`\u2713 Approved "${u.title}"`,e.green),Y();},w=>a(`Failed: ${g(w)}`,e.red));}else if(h==="reject"){let u=s[2]?Le.find(J=>J.id===s[2]):U;if(!u){a("No task selected or id given",e.yellow);return}if(u.status!=="review"){a(`Cannot reject \u2014 status is ${u.status}`,e.yellow);return}if(!L)return;let w=s.slice(s[2]&&Le.find(J=>J.id===s[2])?3:2).join(" ").trim()||void 0;a(`Rejecting "${u.title}"${w?" with feedback":""}...`,e.amber),L(u.id,w).then(()=>{a(`\u2713 Rejected "${u.title}" \u2192 todo`,e.green),Y();},J=>a(`Failed: ${g(J)}`,e.red));}else if(h==="delete"){let u=s[2]?Le.find(w=>w.id===s[2]):U;if(!u){a("No task selected or id given",e.yellow);return}if(u.status==="in_progress"){a("Cannot delete \u2014 task is running",e.yellow);return}if(!N)return;Rn("task",u.id,u.title);}else a("Usage: /task add|list|show|cancel|retry|assign|approve|reject|delete",e.yellow);return}case "agent":{let h=s[1]?.toLowerCase();if(h==="add"){let u=s[2];if(!u){Co();return}if(!P){a("Agent creation not available",e.yellow);return}let w=s[3];a(`Creating agent "${u}"...`,e.amber),P(u,w).then(J=>{a(`\u2713 Created agent "${J.name}" (${J.id}, ${J.adapter})`,e.green),Y();},J=>a(`Failed: ${g(J)}`,e.red));}else if(h==="list"){let u=Ge.map(w=>` ${w.id} ${w.status.padEnd(8)} ${w.name} (${w.adapter})`);if(u.length===0)a("No agents",e.dim);else for(let w of u)a(w,e.cyan);}else if(h==="disable"){let u=s[2]?Ge.find(w=>w.id===s[2]||w.name===s[2]):ee;if(!u){a("No agent selected or id given",e.yellow);return}if(!C)return;a(`Disabling ${u.name}...`,e.amber),C(u.id).then(()=>{a(`\u2713 Disabled ${u.name}`,e.green),Y();},w=>a(`Failed: ${g(w)}`,e.red));}else if(h==="enable"){let u=s[2]?Ge.find(w=>w.id===s[2]||w.name===s[2]):ee;if(!u){a("No agent selected or id given",e.yellow);return}if(!I)return;a(`Enabling ${u.name}...`,e.amber),I(u.id).then(()=>{a(`\u2713 Enabled ${u.name}`,e.green),Y();},w=>a(`Failed: ${g(w)}`,e.red));}else if(h==="delete"||h==="remove"){let u=s[2]?Ge.find(w=>w.id===s[2]||w.name===s[2]):ee;if(!u){a("No agent selected or id given",e.yellow);return}if(u.status==="running"){a("Cannot delete \u2014 agent is running",e.yellow);return}if(!j){a("Agent deletion not available",e.yellow);return}Rn("agent",u.id,u.name);}else if(h==="autonomous"||h==="auto"){let u=s[2]?Ge.find(w=>w.id===s[2]||w.name===s[2]):ee;if(!u){a("No agent selected or id given",e.yellow);return}if(!ut){a("Autonomous toggle not available",e.yellow);return}u.autonomous?(a(`Disabling autonomous mode for "${u.name}"...`,e.amber),ut(u.id,false).then(()=>{a(`${pn} ${u.name} autonomous OFF`,e.cyan),Y();},w=>a(`Failed: ${g(w)}`,e.red))):(a(`Enabling autonomous mode for "${u.name}"...`,e.amber),ut(u.id,true).then(()=>{a(`${pn} ${u.name} autonomous ON`,e.cyan),Y();},w=>a(`Failed: ${g(w)}`,e.red)));}else h==="shop"?ps():a("Usage: /agent add|list|disable|enable|delete|autonomous|shop",e.yellow);return}case "team":{let h=s[1]?.toLowerCase();if(h==="create"||h==="add")hs();else if(h==="list"){let u=In.current;if(u.length===0)a("No teams",e.dim);else for(let w of u)a(` ${w.id} ${w.status.padEnd(8)} ${w.name} (${w.members.length} members)`,e.cyan);}else if(h==="join"){if(!le){a("Join not available",e.yellow);return}let u=s[2],w=s[3]??ee?.id;if(!u||!w){a("Usage: /team join <teamId> [agentId]",e.yellow);return}a(`Joining team ${u}...`,e.amber),le(u,w).then(J=>{a(`\u2713 Agent joined team "${J.name}"`,e.green),Y({includeTeams:true});},J=>a(`Failed: ${g(J)}`,e.red));}else if(h==="leave"){if(!Ee){a("Leave not available",e.yellow);return}let u=s[2],w=s[3]??ee?.id;if(!u||!w){a("Usage: /team leave <teamId> [agentId]",e.yellow);return}a(`Leaving team ${u}...`,e.amber),Ee(u,w).then(J=>{a(`\u2713 Agent left team "${J.name}"`,e.green),Y({includeTeams:true});},J=>a(`Failed: ${g(J)}`,e.red));}else if(h==="disband"){if(!Ft){a("Disband not available",e.yellow);return}let u=s[2];if(!u){a("Usage: /team disband <teamId>",e.yellow);return}a(`Disbanding team ${u}...`,e.amber),Ft(u).then(()=>{a("\u2713 Team disbanded",e.green),Y({includeTeams:true});},w=>a(`Failed: ${g(w)}`,e.red));}else if(h==="set-lead"){if(!dt){a("Set-lead not available",e.yellow);return}let u=s[2],w=s[3];if(!u||!w){a("Usage: /team set-lead <teamId> <agentId>",e.yellow);return}a(`Setting lead for team ${u}...`,e.amber),dt(u,w).then(J=>{a(`\u2713 New lead for team "${J.name}"`,e.green),Y({includeTeams:true});},J=>a(`Failed: ${g(J)}`,e.red));}else a("Usage: /team create|list|join|leave|disband|set-lead",e.yellow);return}case "goal":{let h=s[1]?.toLowerCase();if(h==="add"||h==="create"){let u=s.slice(2).join(" ").trim();if(!u){let w=Zo(Q);Je({title:"New Goal",steps:w,kind:"goal"}),Oe("wizard");return}if(!De){a("Goal creation not available",e.yellow);return}a(`Creating goal "${u}"...`,e.amber),De({title:u}).then(w=>{a(`\u2713 Created goal "${w.title}" (${w.id})`,e.green),Y();},w=>a(`Failed: ${g(w)}`,e.red));}else if(h==="list"){let u=ft.map(w=>` ${w.id} ${w.status.padEnd(8)} ${w.title}`);if(u.length===0)a("No goals",e.dim);else for(let w of u)a(w,e.cyan);}else if(h==="show"){let u=s[2]?ft.find(w=>w.id===s[2]):re;if(!u){a("No goal selected or id given",e.yellow);return}a(`${u.id} ${u.status} "${u.title}"`,e.cyan),u.description&&a(` ${u.description.slice(0,100)}`,e.dim);}else if(h==="status"){let u=s[2]?ft.find(fn=>fn.id===s[2]):void 0,w=u??re;if(!w){a("No goal selected or id given",e.yellow);return}let J=s[u?3:2];if(!J||!a$1.includes(J)){a("Usage: /goal status [id] <active|paused|achieved|abandoned>",e.yellow);return}let Ot=J;if(!gt){a("Status update not available",e.yellow);return}a(`Updating goal status to ${Ot}...`,e.amber),gt(w.id,Ot).then(fn=>{a(`\u2713 Goal "${fn.title}" \u2192 ${Ot}`,e.green),Y();},fn=>a(`Failed: ${g(fn)}`,e.red));}else if(h==="delete"){let u=s[2]?ft.find(w=>w.id===s[2]):re;if(!u){a("No goal selected or id given",e.yellow);return}if(!Ze){a("Goal deletion not available",e.yellow);return}Rn("goal",u.id,u.title);}else a("Usage: /goal add|list|show|status|delete",e.yellow);return}case "run":{let h=s[1]??U?.id;if(!h){a("No task selected or id given",e.yellow);return}if(!l){a("Run not available",e.yellow);return}let u=Le.find(w=>w.id===h);if(u&&!Hr.has(u.status)){a(`Cannot run \u2014 status is ${u.status}`,e.yellow);return}a(`Running ${h}...`,e.amber),l(h).then(()=>{a(`\u2713 Dispatched ${h}`,e.green),Y();},w=>a(`Failed: ${g(w)}`,e.red));return}case "run-all":{if(!y){a("Run-all not available",e.yellow);return}a("Running all todo tasks...",e.amber),y().then(()=>{a("\u2713 Dispatched all todo tasks",e.green),Y();},h=>a(`Failed: ${g(h)}`,e.red));return}case "watch":{if(go){a("Watch mode already active",e.yellow);return}if(!Ae){a("Watch not available",e.yellow);return}a("Starting watch mode...",e.amber),Ae().then(()=>{sr(true),a("\u2713 Watch mode started",e.green);},h=>a(`Failed: ${g(h)}`,e.red));return}case "pause":{if(!go){a("Watch mode not active",e.yellow);return}if(!Ke){a("Pause not available",e.yellow);return}a("Pausing watch mode...",e.amber),Ke().then(()=>{sr(false),a("\u2713 Watch mode paused",e.green);},h=>a(`Failed: ${g(h)}`,e.red));return}case "config":{s[1]?.toLowerCase()==="activity-filter"?gr(u=>{let w=jr(u);return Ue?.(w.label),a(`Activity filter: ${w.label}`,e.amber),new Set(w.types)}):xs();return}case "status":{let h=ne.filter(u=>u.status==="in_progress").length;a(`${Sr} ${h} running ${ne.length} tasks ${Ge.length} agents`,e.cyan);return}case "help":{for(let[h,u]of Object.entries(hn)){let w=u.sub?" "+u.sub.join("|"):u.args?" "+u.args:"";a(` /${h}${w} \u2014 ${u.help}`,e.silver);}return}case "quit":{Wn();return}case "disable":{if(!ee){a("No agent selected",e.yellow);return}if(!C)return;a(`Disabling ${ee.name}...`,e.amber),C(ee.id).then(()=>{a(`\u2713 Disabled ${ee.name}`,e.green),Y();},h=>a(`Failed: ${g(h)}`,e.red));return}case "enable":{if(!ee){a("No agent selected",e.yellow);return}if(!I)return;a(`Enabling ${ee.name}...`,e.amber),I(ee.id).then(()=>{a(`\u2713 Enabled ${ee.name}`,e.green),Y();},h=>a(`Failed: ${g(h)}`,e.red));return}default:a(`Unknown: ${d}. Type /help for commands`,e.yellow);}},[U,ee,Le,Ge,ne,Sr,go,x,T,b$1,y,l,f,C,I,P,O,L,N,le,Ee,Ft,dt,Ae,Ke,a,Wn,Y,Io,Co,hs,xs]);useInput((i,p)=>{if(!($t&&(lr(false),i==="?"||p.escape||i==="\x1BOP"))&&!yn){if((p.ctrl||p.meta)&&i==="s"&&Fe==="wizard"&&bt?.kind==="agent"){ps();return}if(Fe!=="none"){if(p.escape){Oe("none"),Ct(""),To.reset();return}if(p.return){let s=cn.trim();if(!s)return;if(Fe==="new_task"){if(!f)return;Oe("none"),Ct(""),a(`Creating "${s}"...`,e.amber),f(s).then(d=>{a(`\u2713 Created "${d.title}" (${d.id})`,e.green),Y();},d=>a(`Failed to create: ${d instanceof Error?d.message:String(d)}`,e.red));}else if(Fe==="command"){let d=s;if(Mt.length>0&&Mt[wo]){let g=Mt[wo],h=g.cmd.replace(/\s+\[.*\]$/,"");if((h.startsWith(s)||s==="/")&&(d=h),g.subs&&!h.includes(" ")){Ct(h+" "),Jt(0);return}}Oe("none"),Ct(""),Jt(0),To.push(d),Ga(d);}return}if(p.tab&&Fe==="command"){if(Mt.length>0){let s=Mt[wo];if(s){let d=s.cmd.replace(/\s+\[.*\]$/,"");Ct(d+(s.subs?" ":"")),Jt(0);}}else {let s=$r(cn);s&&Ct(d=>d+s);}return}if(p.upArrow&&Fe==="command"){if(Mt.length>0)Jt(s=>Math.max(0,s-1));else {let s=To.prev();s!==null&&Ct(s);}return}if(p.downArrow&&Fe==="command"){if(Mt.length>0)Jt(s=>Math.min(Mt.length-1,s+1));else {let s=To.next();Ct(s??"");}return}if(p.backspace||p.delete){Ct(s=>s.slice(0,-1)),Jt(0);return}i&&!p.ctrl&&!p.meta&&(Ct(s=>s+i),Jt(0));return}if(i.toLowerCase()==="q"){Wn();return}if(p.escape){if($e){jn(false),Zn(0);return}if(A==="logs"&&qn>=0){ur(-1),Kn(0);return}return}if((i==="+"||i==="=")&&A!=="logs"){yo?(br(false),kn(-Math.floor(It/2))):kn(s=>Math.max(-An,s-3));return}if(i==="-"&&A!=="logs"){yo?(br(false),kn(Math.floor(It/2))):kn(s=>Math.min(An,s+3));return}if(i==="M"&&A!=="logs"){br(s=>!s);return}if(i==="?"){lr(true);return}if(i==="\x1BOP"){lr(true);return}if(i==="/"&&!$e){Oe("command"),Ct("/"),Jt(0);return}if((i==="a"||i==="A")&&A==="logs"&&!$e&&!yn&&!Xn){cr(true);return}if(i==="f"&&A==="logs"&&!$e&&!yn&&!Xn){dr(true);return}if(i==="F"&&A==="logs"&&!$e&&!yn&&!Xn){ts(s=>new Set(jr(s).types));return}if((i==="z"||i==="Z")&&Cn.length>0){Ca();return}if((i==="f"||i==="F")&&(A==="tasks"||A==="agents"||A==="goals")&&!$e){gr(s=>{let d=jr(s);return Ue?.(d.label),new Set(d.types)});return}if((i==="n"||i==="N")&&A==="tasks"&&!$e&&f){Io();return}if((i==="n"||i==="N")&&A==="agents"&&!$e&&P){Co();return}if((i==="n"||i==="N")&&A==="goals"&&!$e&&De){let s=Zo(Q);Je({title:"New Goal",steps:s,kind:"goal"}),Oe("wizard");return}if((i==="e"||i==="E")&&A==="goals"&&re&&Ye){let s=Ui(re,Q);Je({title:`Edit Goal: ${re.title}`,steps:s,kind:"edit_goal",targetId:re.id}),Oe("wizard");return}if((i==="d"||i==="D")&&A==="goals"&&re&&Ze){Rn("goal",re.id,re.title);return}if((i==="c"||i==="C")&&A==="goals"&&re&&gt){(re.status==="active"||re.status==="paused")&&(a(`Marking goal "${re.title}" as achieved (pending tasks will be cancelled)...`,e.amber),gt(re.id,"achieved",{force:true}).then(()=>{a(`\u2713 Goal "${re.title}" achieved`,e.green),Y();},s=>a(`Failed: ${s instanceof Error?s.message:String(s)}`,e.red)));return}if((i==="x"||i==="X")&&A==="goals"&&re&&gt){(re.status==="active"||re.status==="paused")&&(a(`Abandoning goal "${re.title}"...`,e.amber),gt(re.id,"abandoned").then(()=>{a(`\u2713 Goal "${re.title}" abandoned`,e.dim),Y();},s=>a(`Failed: ${s instanceof Error?s.message:String(s)}`,e.red)));return}if((i==="p"||i==="P")&&A==="goals"&&re&&gt){let s=re.status==="paused"?"active":"paused";(re.status==="active"||re.status==="paused")&&gt(re.id,s).then(()=>{a(`Goal "${re.title}" ${s}`,e.cyan),Y();},d=>a(`Failed: ${d instanceof Error?d.message:String(d)}`,e.red));return}if((i==="a"||i==="A")&&A==="tasks"&&U?.status==="review"&&O){a(`Approving "${U.title}"...`,e.amber),O(U.id).then(()=>{a(`\u2713 Approved "${U.title}"`,e.green),Y();},s=>a(`Failed: ${s instanceof Error?s.message:String(s)}`,e.red));return}if((i==="x"||i==="X")&&A==="tasks"&&U?.status==="review"&&L){a(`Rejecting "${U.title}"...`,e.amber),L(U.id).then(()=>{a(`\u2713 Rejected "${U.title}" \u2192 todo`,e.green),Y();},s=>a(`Failed: ${s instanceof Error?s.message:String(s)}`,e.red));return}if((i==="c"||i==="C")&&A==="tasks"&&U&&x){if(U.status==="done"||U.status==="failed"||U.status==="cancelled"){a(`Cannot cancel \u2014 status is ${U.status}`,e.yellow);return}a(`Cancelling "${U.title}"...`,e.amber),x(U.id).then(()=>{a(`\u2713 Cancelled "${U.title}"`,e.green),Y();},s=>a(`Failed: ${s instanceof Error?s.message:String(s)}`,e.red));return}if((i==="e"||i==="E")&&A==="tasks"&&U&&E){Ma(U);return}if((i==="e"||i==="E")&&A==="agents"&&ee&&W){va(ee);return}if((i==="s"||i==="S")&&A==="tasks"){cs(s=>!s),Hn(0),Sn(0);return}if((i==="g"||i==="G")&&A==="tasks"&&!$e){ha(s=>!s),Hn(0),Sn(0);return}if((i==="s"||i==="S")&&A==="agents"&&ee&&z){if(!Object.values(ve.running).some(d=>d.agent_id===ee.id)&&ee.status!=="running"){a(`Agent "${ee.name}" is not running`,e.yellow);return}a(`Force-stopping agent "${ee.name}"...`,e.amber),z(ee.id).then(()=>{a(`\u2713 Stopped agent "${ee.name}"`,e.green),Y();},d=>a(`Failed: ${d instanceof Error?d.message:String(d)}`,e.red));return}if((i==="d"||i==="D")&&A==="tasks"&&U&&U.status!=="in_progress"&&N){Rn("task",U.id,U.title);return}if((i==="d"||i==="D")&&A==="agents"&&ee&&j){let s=Object.values(ve.running).some(d=>d.agent_id===ee.id);if(s&&!z){a(`Cannot delete \u2014 agent "${ee.name}" is running. Press S to stop first.`,e.yellow);return}Rn("agent",ee.id,ee.name,{needsForceStop:s});return}if((i==="u"||i==="U")&&A==="agents"&&ee&&ut){let s=!ee.autonomous;a(`${s?"Enabling":"Disabling"} autonomous mode for "${ee.name}"...`,e.amber),ut(ee.id,s).then(()=>{a(`${pn} ${ee.name} autonomous ${s?"ON":"OFF"}`,e.cyan),Y();},d=>a(`Failed: ${d instanceof Error?d.message:String(d)}`,e.red));return}if(!$e){if(i==="g"||i==="G"){Tn("goals");return}if(i==="t"||i==="T"){Tn("tasks");return}if(i==="a"||i==="A"){Tn("agents");return}if(i==="l"||i==="L"){Tn("logs");return}}if(!$e){let s=Oo.map(g=>g.id),d=s.indexOf(A);if(p.tab||p.rightArrow){Tn(s[(d+1)%s.length]);return}if(p.leftArrow){Tn(s[(d+s.length-1)%s.length]);return}}if(p.return){let s=vn>0?Bt.length:-1;if(A==="tasks"&&fo===s){cs(g=>!g),Hn(0),Sn(0);return}let d=Bt.length+(vn>0?1:0);if(A==="tasks"&&fo===d&&f){Io();return}if(A==="goals"&&ar===ft.length&&De){let g=Zo(Q);Je({title:"New Goal",steps:g,kind:"goal"}),Oe("wizard");return}if(A==="agents"&&ir===Ge.length&&P){Co();return}if(A==="goals"&&re){jn(g=>!g),Zn(0);return}if(A==="tasks"&&U){jn(g=>!g);return}if(A==="agents"&&ee){jn(g=>!g);return}if(A==="logs"&&qn>=0){jn(g=>!g);return}}if((i==="r"||i==="R")&&A==="tasks"&&U&&l){if(!Hr.has(U.status)){a(`Cannot run "${U.title}" \u2014 status is ${U.status}`,e.yellow);return}a(`Running "${U.title}"...`,e.green),l(U.id).then(()=>{a(`Dispatched "${U.title}"`,e.green),Y();},s=>a(`Failed to run: ${s instanceof Error?s.message:String(s)}`,e.red));return}if(p.upArrow||i==="k"){if(A==="goals"&&$e){Zn(s=>Math.max(0,s-1));return}A==="goals"?Zr(s=>{let d=Math.max(0,s-1);return hr(g=>d<g?d:g),d}):A==="tasks"?Hn(s=>{let d=Math.max(0,s-1);return Sn(g=>d<g?d:g),d}):A==="agents"?Yr(s=>{let d=Math.max(0,s-1);return pr(g=>d<g?d:g),d}):A==="logs"&&ur(s=>{if(s===-1){let g=ze.length-1;return Kn(Math.max(0,g-Se+2)),Math.max(0,g)}let d=Math.max(0,s-1);return Kn(g=>d<g?d:g),d});}if(p.downArrow||i==="j"){if(A==="goals"&&$e){Zn(s=>s+1);return}if(A==="goals"){let s=ft.length+(De?1:0)-1;Zr(d=>{let g=Math.min(Math.max(0,s),d+1);return hr(h=>g>=h+Se?g-Se+1:h),g});}else if(A==="tasks"){let s=Bt.length+(f?1:0)+(vn>0?1:0)-1;Hn(d=>{let g=Math.min(Math.max(0,s),d+1);return Sn(h=>g>=h+Se?g-Se+1:h),g});}else if(A==="agents"){let s=Ge.length+(P?1:0)-1;Yr(d=>{let g=Math.min(Math.max(0,s),d+1);return pr(h=>g>=h+Se?g-Se+1:h),g});}else A==="logs"&&ur(s=>{if(s===-1)return -1;let d=ze.length-1;if(s>=d)return Kn(0),-1;let g=s+1;return Kn(h=>g>=h+Se-1?g-Se+2:h),g});}}});let ot=Fe!=="none",ys=qn>=0?ze[qn]:void 0,Mo=yo?"+/- exit max":"+/- resize \u2502 M max",ws=!ot&&$e&&A==="tasks"&&U,Ss=!ot&&$e&&A==="agents"&&ee,ks=!ot&&$e&&A==="goals"&&re,Wa=!ot&&$e&&A==="logs"&&ys,kr=U?.id,za=useMemo(()=>kr?ze.filter(i=>i.taskId===kr):[],[ze,kr]),Va=!ot&&A==="tasks"&&U&&Hr.has(U.status)&&!!l,Ha=!ot&&!$e&&(A==="goals"&&!!De||A==="tasks"&&!!f||A==="agents"&&!!P),ja=!ot&&A==="tasks"&&U?.status==="review"&&!!O,Ua=!ot&&A==="tasks"&&U?.status==="review"&&!!L,Xa=ee?Object.values(ve.running).some(i=>i.agent_id===ee.id):false,qa=!ot&&(A==="goals"&&re&&!!Ze||A==="tasks"&&U&&U.status!=="in_progress"&&!!N||A==="agents"&&ee&&!!j),Ka=!ot&&!$e&&(A==="goals"&&!!re&&!!Ye||A==="tasks"&&!!U&&!!E||A==="agents"&&!!ee&&!!W),Ya=!ot&&A==="agents"&&ee&&(Xa||ee.status==="running")&&!!z,Za=!ot&&A==="agents"&&!!ee&&!!ut,Ja=!ot&&A==="goals"&&!!re&&(re.status==="active"||re.status==="paused")&&!!gt,Qa=!ot&&Cn.length>0,Cs=Fe==="command"&&Mt.length>0,Is=bt?.kind==="task"||bt?.kind==="edit_task";return jsxs(Box,{flexDirection:"column",width:K,height:ye,children:[jsx(Zs,{projectName:t,activeView:A,mode:Sr,stats:Ts,tokens:Ba,uptime:$a,width:K,version:Wt,latestVersion:Kt,updateInstalled:R,taskBadge:vn>0?Le.length:void 0,flashTab:fr?.tab,flashColor:fr?.color,onFlashComplete:fr?()=>rs(void 0):void 0}),jsx(Box,{height:1}),$t&&jsx(wi,{width:K,height:ye-7}),!$t&&Zt==="welcome"&&A==="tasks"&&jsx(ui,{width:K,height:ye}),!$t&&A==="goals"&&jsx(Ac,{goals:ft,selectedIndex:ar,scrollOffset:ba,height:Se,width:_e,showAddRow:!!De,agentNameMap:un,tasksByGoalMap:ya}),!$t&&Zt!=="welcome"&&A==="tasks"&&jsx(Bc,{tasks:Bt,selectedIndex:fo,scrollOffset:pa,height:Se,width:_e,showAddRow:!!f,agentNameMap:un,hiddenCount:vn,goalMap:Mn,groupByGoal:Yn}),!$t&&A==="tasks"&&(Zt==="task_created"||Zt==="run_started")&&jsx(gi,{step:Zt,width:K}),!$t&&A==="tasks"&&Zt==="completed"&&jsx(mi,{width:K}),!$t&&A==="agents"&&jsx(Ec,{agents:Ge,selectedIndex:ir,scrollOffset:xa,height:Se,width:_e,state:ve,taskTitleMap:Jn,showAddRow:!!P,agentTeamMap:_n,teamLeadSet:Sa,activeTeamCount:Qn}),!$t&&A==="logs"&&jsxs(Fragment,{children:[jsx(Lc,{messages:ze,height:yn||Xn?Math.max(3,Se-16):Se,agents:Ge,logAgentFilter:Qr,logTypeFilter:es,selectedIndex:qn,scrollOffset:ca,agentNameMap:un,agentColorMap:So,agentMsgCounts:gs,taskTitleMap:Jn,width:_e}),yn&&jsx(Box,{paddingX:2,children:jsx(ii,{agents:Ge,selected:Qr,msgCounts:gs,colorMap:So,maxHeight:Math.min(Se-4,18),onConfirm:i=>{la(i),cr(false);},onCancel:()=>cr(false)})}),Xn&&jsx(Box,{paddingX:2,children:jsx(di,{selected:es,typeCounts:wa,onConfirm:i=>{ts(i),dr(false);},onCancel:()=>dr(false)})})]}),jsx(Box,{height:1}),$t?null:Fe==="wizard"&&bt?jsx(oi,{title:bt.title,steps:bt.steps,onComplete:_a,onCancel:Ra,width:_e,height:Et,onPasteImage:Is?Ia:void 0,onSuggestionSelected:bt.kind==="agent"?Aa:void 0,footerExtra:dn.length>0&&Is?`\u{1F4CE}${dn.length}`:void 0},`${bt.kind}-${bt.title}`):Cs?jsxs(Fragment,{children:[jsx(Jo,{label:"COMMANDS",width:_e}),jsx(Rc,{suggestions:Mt,selectedIndex:wo,height:Math.min(Mt.length,Et),width:_e})]}):Fe==="new_task"?jsxs(Fragment,{children:[jsx(Vc,{mode:Fe,width:_e}),jsx(Hc,{mode:Fe,value:cn,width:_e})]}):ws?jsxs(Fragment,{children:[jsx(Dc,{task:U,width:_e,resizeHint:Mo}),jsx(qs,{task:U,height:Et,width:_e,taskLogs:za,agentNameMap:un,taskTitleMap:Jn})]}):ks?jsxs(Fragment,{children:[jsx(Jo,{label:`GOAL: ${re.title}`,width:_e,suffixLen:Mo.length+2,suffix:jsxs(Text,{color:e.dim,children:[" ",Mo," "]})}),jsx($c,{goal:re,height:Et,width:_e,agentNameMap:un,tasks:ka,progressReport:aa,scrollOffset:Ta,onClampScroll:Zn})]}):Ss?jsxs(Fragment,{children:[jsx(Fc,{agent:ee,width:_e,resizeHint:Mo}),jsx(Gc,{agent:ee,height:Et,state:ve,taskTitleMap:Jn,teamName:_n.get(ee.id)})]}):Wa?jsxs(Fragment,{children:[jsx(Jo,{label:"LOG",width:_e}),jsx(Nc,{message:ys,height:Et,width:_e,agents:Ge,agentNameMap:un,agentColorMap:So,taskTitleMap:Jn})]}):ze.length>0&&A!=="logs"?jsxs(Fragment,{children:[(()=>{let i=` F:${po.toUpperCase()} \u2502 ${mr.length}/${ze.length}`;return jsx(Jo,{label:"ACTIVITY",width:_e,suffixLen:i.length,suffix:jsxs(Fragment,{children:[jsx(Text,{color:e.dim,children:" F:"}),jsx(Text,{color:e.amber,children:po.toUpperCase()}),jsxs(Text,{color:e.ghost,children:[" ","\u2502"," ",mr.length,"/",ze.length]})]})})})(),jsx(Pc,{messages:mr,height:Math.max(1,Et-1),width:_e,agents:Ge,agentNameMap:un,agentColorMap:So})]}):A==="goals"?jsx(Uo,{count:ft.length,config:Cc,width:_e}):A==="tasks"?jsx(Uo,{count:Le.length,config:Ic,width:_e}):A==="agents"?jsx(Uo,{count:Ge.length,config:Mc,width:_e}):null,jsx(Box,{flexGrow:1}),jsx(yi,{toasts:ga,onDismiss:fa}),Cn.length>0&&jsx(_c,{deletions:Cn,width:K}),jsx(Qs,{mode:Fe==="command"?"command":"navigate",value:Fe==="command"?cn:"",completion:Fe==="command"?$r(cn):null,activeView:A,canRun:!!Va,canNew:!!Ha,canApprove:!!ja,canReject:!!Ua,canCancel:A==="tasks"&&!!U&&U.status==="in_progress"&&!!x,canDelete:!!qa,canUndo:!!Qa,canEdit:!!Ka,canForceStop:!!Ya,canToggleAuto:!!Za,autoActive:ee?.autonomous,canPause:!!Ja,isPaused:re?.status==="paused",canToggleShowAll:A==="tasks"&&Le.length>qi,showAllActive:ls,hasDetail:!!(ws||Ss||ks),itemCount:A==="goals"?ft.length:A==="tasks"?Le.length:A==="agents"?Q.length:ze.length,itemLabel:A==="goals"?"goals":A==="tasks"?"tasks":A==="agents"?"agents":"events",width:K,hasSuggestions:Cs,onboardingCompleted:r.onboardingCompleted})]})}var _c=io.memo(function({deletions:n,width:o}){let[,r]=useState(0);useEffect(()=>{let f=setInterval(()=>r(x=>x+1),1e3);return ()=>clearInterval(f)},[]);let l=Date.now();return jsx(Box,{flexDirection:"column",width:o,children:n.map(f=>{let x=Math.max(0,Math.ceil((f.expiresAt-l)/1e3)),T=Math.max(0,o-4),b=f.entityType==="task"?"Task":f.entityType==="agent"?"Agent":"Goal",y=Math.max(10,T-b.length-30),C=f.entityName.length>y?f.entityName.slice(0,y-1)+"\u2026":f.entityName;return jsx(Box,{paddingX:2,children:jsxs(Text,{color:e.yellow,children:["\u2717 ",jsx(Text,{bold:true,children:b}),` "${C}" \u2014 `,jsxs(Text,{color:e.amber,bold:true,children:[x,"s"]}),jsx(Text,{color:e.dim,children:" \u2502 "}),jsx(Text,{color:e.gray,bold:true,children:"Z"}),jsx(Text,{color:e.dim,children:" undo"})]})},f.key)})})});function Rc({suggestions:t,selectedIndex:n,height:o,width:r}){let l=o,f=0;n>=l&&(f=n-l+1);let x=t.slice(f,f+l);return jsx(Box,{flexDirection:"column",paddingX:2,children:x.map((T,b)=>{let y=b+f,C=y===n,I=C?"\u25B6":" ",$=Math.min(20,Math.max(14,...t.map(P=>P.cmd.length+1))),S=T.cmd.padEnd($),H=T.subs?` ${T.subs}`:"",V=Math.max(4,r-$-H.length-8),F=T.desc.length>V?T.desc.slice(0,V-1)+"\u2026":T.desc;return jsxs(Text,{wrap:"truncate",children:[jsx(Text,{color:C?e.amber:e.ghost,children:` ${I} `}),jsx(Text,{color:C?e.white:e.silver,bold:C,children:S}),jsx(Text,{color:e.dim,children:F}),H&&jsx(Text,{color:e.ghost,children:H})]},y)})})}function Ac({goals:t,selectedIndex:n,scrollOffset:o=0,height:r,width:l,showAddRow:f,agentNameMap:x,tasksByGoalMap:T}){let b=t.length,y=t.slice(o,o+r),C=f&&b>=o&&b<o+r;return jsxs(Box,{flexDirection:"column",height:r,children:[y.map((I,$)=>jsx(Box,{paddingX:2,children:jsx(Xs,{goal:I,selected:$+o===n,width:l-2,agentNameMap:x,tasksByGoal:T?.get(I.id)})},I.id)),C&&jsx(Box,{paddingX:2,children:jsxs(Text,{color:n===b?e.amber:e.ghost,children:[n===b?" \u25B8 ":" ",jsx(Text,{color:n===b?e.amber:e.dim,children:"+ add goal..."})]})},"__add__")]})}function $c({goal:t,height:n,width:o,agentNameMap:r,tasks:l,progressReport:f,scrollOffset:x=0,onClampScroll:T}){let y=io.useMemo(()=>{let V=l??[],F=t.assignee?r?.get(t.assignee)??t.assignee:"\u2014",P=Math.max(20,o-6),j=(z,X)=>{if(z.length<=X)return [z];let _=[];for(let le=0;le<z.length;le+=X)_.push(z.slice(le,le+X));return _},O=_r(f)?.split(`
13
13
  `).flatMap(z=>j(z,P))??[],L=_r(t.description)?.split(`
14
14
  `).flatMap(z=>j(z,P))??[],N=Bs[t.status]??e.dim,E=new Map;for(let z of V)E.set(z.status,(E.get(z.status)??0)+1);let W=[];if(W.push({key:"row-status",node:jsxs(Box,{children:[jsxs(Box,{width:24,children:[jsx(Text,{color:e.dim,children:" status "}),jsx(Text,{color:N,bold:true,children:t.status})]}),jsxs(Box,{children:[jsx(Text,{color:e.dim,children:" assignee "}),jsx(Text,{color:t.assignee?e.green:e.dim,children:F})]})]})}),W.push({key:"row-id",node:jsxs(Box,{children:[jsxs(Box,{width:24,children:[jsx(Text,{color:e.dim,children:" id "}),jsx(Text,{color:e.dim,children:t.id})]}),jsxs(Box,{children:[jsx(Text,{color:e.dim,children:" created "}),jsx(Text,{children:t.created_at.slice(0,10)})]})]})}),t.updated_at&&t.updated_at!==t.created_at&&W.push({key:"row-updated",node:jsxs(Box,{children:[jsx(Box,{width:24,children:jsxs(Text,{color:e.dim,children:[" "," "]})}),jsxs(Box,{children:[jsx(Text,{color:e.dim,children:" Updated "}),jsx(Text,{children:t.updated_at.slice(0,10)})]})]})}),V.length>0){let z=[];for(let[X,_]of E)z.push(`${_} ${X}`);W.push({key:"row-tasks-summary",node:jsxs(Box,{children:[jsxs(Box,{width:24,children:[jsx(Text,{color:e.dim,children:" tasks "}),jsx(Text,{color:e.cyan,children:V.length})]}),jsxs(Box,{children:[jsx(Text,{color:e.dim,children:" "}),jsx(Text,{color:e.dim,children:z.join(" \xB7 ")})]})]})});}if(L.length>0){W.push({key:"desc-gap",node:jsx(Text,{children:" "})});for(let z=0;z<L.length;z++)W.push({key:`desc-${z}`,node:jsxs(Text,{color:e.silver,wrap:"truncate",children:[" ",L[z]]})});}else W.push({key:"desc-gap",node:jsx(Text,{children:" "})}),W.push({key:"desc-empty",node:jsx(Text,{color:e.dim,children:" No description."})});if(O.length>0){W.push({key:"prog-gap",node:jsx(Text,{children:" "})}),W.push({key:"prog-div",node:jsx(Pn,{label:"progress",width:o})});for(let z=0;z<O.length;z++)W.push({key:`prog-${z}`,node:jsxs(Text,{color:e.white,wrap:"truncate",children:[" ",O[z]]})});}if(V.length>0){W.push({key:"tasks-gap",node:jsx(Text,{children:" "})}),W.push({key:"tasks-div",node:jsx(Pn,{label:`tasks (${V.length})`,width:o})});for(let z of V){let X=Ao[z.status]??e.dim;W.push({key:`task-${z.id}`,node:jsxs(Text,{color:e.silver,wrap:"truncate",children:[" ",jsx(Text,{color:X,children:z.status.padEnd(12)}),z.title.slice(0,Math.max(10,o-22))]})});}}return W},[t,l,f,o,r]),C=Math.max(0,y.length-n),I=Math.min(x,C);io.useEffect(()=>{T&&I!==x&&T(I);},[I,x,T]);let $=y.length>n&&I<C,S=$?n-1:n,H=y.slice(I,I+S);return jsxs(Box,{flexDirection:"column",height:n,paddingX:2,children:[H.map(V=>jsx(Box,{children:V.node},V.key)),$&&jsxs(Text,{color:e.ghost,children:[" ","\u2193"," ",y.length-I-S," more ","\u2014"," ","\u2191","\u2193"," to scroll"]})]})}function Bc({tasks:t,selectedIndex:n,scrollOffset:o=0,height:r,width:l,showAddRow:f,agentNameMap:x,hiddenCount:T=0,goalMap:b,groupByGoal:y=false}){let C=T>0,I=C?t.length:-1,$=t.length+(C?1:0),S=t.slice(o,o+r),H=C&&I>=o&&I<o+r,V=f&&$>=o&&$<o+r,F=useMemo(()=>{if(!y||!b||b.size===0)return null;let N=new Map;for(let E of t)if(E.goalId&&b.has(E.goalId)){let W=N.get(E.goalId)??{total:0,done:0};W.total++,E.status==="done"&&W.done++,N.set(E.goalId,W);}return N},[t,y,b]),P=y&&b?t.filter(N=>!N.goalId||!b.has(N.goalId)).length:0,j=y&&b&&b.size>0&&F&&F.size>0,O=[],L=o>0?t[o-1]?.goalId??null:void 0;for(let N=0;N<S.length&&O.length<r;N++){let E=S[N],W=E.goalId&&b?.has(E.goalId)?E.goalId:null;if(j){if(W&&W!==L){let z=b.get(W),X=F.get(W)??{total:0,done:0};if(O.push(jsx(Ds,{goalTitle:z.title,taskCount:X.total,doneCount:X.done,width:l},`gh_${W}`)),O.length>=r)break}if(!W&&L!==null&&L!==void 0&&(O.push(jsx(Fs,{taskCount:P,width:l},"__ungrouped__")),O.length>=r))break}L=W,O.push(jsx(Box,{paddingX:2,children:jsx(Eo,{task:E,selected:N+o===n,width:l-2,agentNameMap:x,goalMap:b})},E.id));}return H&&O.length<r&&O.push(jsx(Box,{paddingX:2,children:jsxs(Text,{color:n===I?e.amber:e.ghost,children:[n===I?" \u25B8 ":" ",jsxs(Text,{color:n===I?e.amber:e.dim,children:["\u25BC"," Show all (",T," more) \u2014 press ",jsx(Text,{bold:true,color:e.gray,children:"S"})]})]})},"__show_all__")),V&&O.length<r&&O.push(jsx(Box,{paddingX:2,children:jsxs(Text,{color:n===$?e.amber:e.ghost,children:[n===$?" \u25B8 ":" ",jsx(Text,{color:n===$?e.amber:e.dim,children:"+ add task..."})]})},"__add__")),jsx(Box,{flexDirection:"column",height:r,children:O})}function Ec({agents:t,selectedIndex:n,scrollOffset:o=0,height:r,width:l,state:f,taskTitleMap:x,showAddRow:T,agentTeamMap:b,teamLeadSet:y,activeTeamCount:C}){let I=new Map;for(let E of Object.values(f.running))I.set(E.agent_id,E);let $=new Map;if(C&&C>0)for(let E of t){let W=b?.get(E.id);W&&$.set(W,($.get(W)??0)+1);}let S=t.length,H=t.slice(o,o+r),V=T&&S>=o&&S<o+r,F=C!=null&&C>0,P=new Map;if(F&&y&&b){for(let E of t)if(y.has(E.id)){let W=b.get(E.id);W&&P.set(W,E.name);}}let j=0;for(let E of $.values())j+=E;let O=t.length-j,L=[],N=o>0?b?.get(t[o-1]?.id??""):void 0;for(let E=0;E<H.length&&L.length<r;E++){let W=H[E],z=b?.get(W.id);if(F&&z&&z!==N&&(L.push(jsx(Vs,{teamName:z,memberCount:$.get(z)??0,leadName:P.get(z),width:l},`ts-${z}`)),L.length>=r)||F&&!z&&N&&(L.push(jsx(Hs,{memberCount:O,width:l},"ts-unassigned")),L.length>=r))break;N=z,L.push(jsx(Box,{paddingX:2,children:jsx(zs,{agent:W,selected:E+o===n,width:l-2,runningEntry:I.get(W.id),currentTaskTitle:W.current_task?x.get(W.current_task):void 0,teamName:z,isLead:y?.has(W.id)})},W.id));}return V&&L.length<r&&L.push(jsx(Box,{paddingX:2,children:jsxs(Text,{color:n===S?e.amber:e.ghost,children:[n===S?" \u25B8 ":" ",jsx(Text,{color:n===S?e.amber:e.dim,children:"+ add agent..."})]})},"__add__")),jsx(Box,{flexDirection:"column",height:r,children:L})}function na(t=5e3){let[n,o]=useState(Date.now());return useEffect(()=>{let r=setInterval(()=>o(Date.now()),t);return ()=>clearInterval(r)},[t]),n}function oa(t,n){let o=Math.max(0,n-t);return o<3e3?"now":o<6e4?`${Math.floor(o/1e3)}s`:o<36e5?`${Math.floor(o/6e4)}m`:`${Math.floor(o/36e5)}h`}function Oc(t){if(t==="error")return e.errorBg}function ra(t,n){switch(t){case "output":return e.white;case "tool":return e.dim;case "result":return e.dim;case "file":return e.gray;case "error":return e.red;case "lifecycle":return e.dim;case "system":return e.dim;default:return n}}function Lc({messages:t,height:n,agents:o,logAgentFilter:r,logTypeFilter:l,selectedIndex:f,scrollOffset:x,agentNameMap:T,agentColorMap:b,agentMsgCounts:y,taskTitleMap:C,width:I}){let $=na(),S=useMemo(()=>t.filter(X=>{if(r.size>0&&X.agentId&&!r.has(X.agentId))return false;let _=X.msgType??"info";return l.has(_)}),[t,r,l]);useMemo(()=>{let X={};for(let _ of t){let le=_.msgType??"info";X[le]=(X[le]??0)+1;}return X},[t]);let V=l.size>=8?"all":l.size===1&&l.has("output")?"text":l.size===1&&l.has("error")?"errors":l.has("tool")&&!l.has("output")?"tools":l.has("lifecycle")&&!l.has("output")?"events":`${l.size} types`,F=r.size>0,P=n-2,j=f===-1?S.slice(-P):S.slice(x,x+P),O=f===-1?-1:f-x,L=Math.min(10,Math.max(6,...o.map(X=>X.name.length))),N=11+L,E=X=>{if(X===0)return true;let _=j[X],le=j[X-1];return _.agentId!==le.agentId?true:_.agentId?_.ts-le.ts>3e4:false},W=Math.max(4,Math.floor((I-20)/Math.max(1,o.length))-1),z=Math.min(W,10);return jsxs(Box,{flexDirection:"column",paddingX:1,children:[jsxs(Box,{gap:0,justifyContent:"space-between",width:I,children:[jsxs(Box,{gap:0,children:[f===-1?jsxs(Box,{gap:0,children:[jsx(Text,{backgroundColor:e.successBg,color:e.green,children:" "}),jsx(Text,{backgroundColor:e.successBg,color:e.green,children:jsx(jt,{color:e.green})}),jsx(Text,{backgroundColor:e.successBg,color:e.green,children:" LIVE "})]}):jsxs(Text,{backgroundColor:e.warnBg,color:e.amber,children:[" \u2191\u2193 ",f+1,"/",S.length," "]}),jsxs(Text,{color:e.dim,children:[" ",S.length," events"]}),V!=="all"&&jsxs(Text,{color:e.amber,children:[" f:",V]}),F&&jsxs(Text,{color:e.cyan,children:[" ",r.size,"/",o.length," agents"]})]}),jsxs(Box,{gap:0,children:[jsx(Text,{color:e.amber,bold:true,children:"a"}),jsx(Text,{color:e.dim,children:" filter "}),jsx(Text,{color:e.amber,bold:true,children:"f"}),jsx(Text,{color:e.dim,children:" type "}),jsx(Text,{color:e.amber,bold:true,children:"F"}),jsx(Text,{color:e.dim,children:" cycle"})]})]}),jsx(Box,{gap:0,children:o.map(X=>{let _=b.get(X.id)??Xr[0],le=r.size===0||r.has(X.id),Ee=X.name.length>z?X.name.slice(0,z-1)+"\u2026":X.name;return jsxs(Text,{color:le?_:e.ghost,bold:le,children:[" ",Ee]},X.id)})}),j.length===0?jsxs(Box,{flexDirection:"column",paddingX:2,paddingTop:1,children:[jsx(Text,{color:e.dim,children:t.length===0?" \u256D\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u256E":"No events for current filter."}),t.length===0&&jsxs(Fragment,{children:[jsx(Text,{color:e.dim,children:" \u2502 \u2502"}),jsxs(Text,{color:e.dim,children:[" \u2502 ",jsx(Text,{color:e.ghost,children:"\u25C7"}),jsx(Text,{color:e.gray,children:" Waiting for activity "}),"\u2502"]}),jsxs(Text,{color:e.dim,children:[" \u2502 ",jsx(Text,{color:e.ghost,children:"\u2502"}),jsx(Text,{color:e.dim,children:" Run tasks or start "}),"\u2502"]}),jsxs(Text,{color:e.dim,children:[" \u2502 ",jsx(Text,{color:e.ghost,children:"\u2502"}),jsx(Text,{color:e.dim,children:" the orchestrator "}),"\u2502"]}),jsxs(Text,{color:e.dim,children:[" \u2502 ",jsx(Text,{color:e.ghost,children:"\u25C7"}),jsx(Text,{color:e.dim,children:" "}),"\u2502"]}),jsx(Text,{color:e.dim,children:" \u2570\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u256F"})]})]}):j.map((X,_)=>{let le=_===O,Ee=X.msgType??"info",Ft=or[Ee]??"\u2502",dt=X.agentId?T.get(X.agentId)??X.agentId.slice(0,8):void 0,Ae=X.agentId?b.get(X.agentId):void 0,Ke=E(_),pt=(_>0?j[_-1]:void 0)?.agentId===X.agentId&&!!X.agentId,De=!pt&&!!dt,Ye=pt&&!!dt,gt=ra(Ee,X.color),Ze=le?e.infoBg:Ee==="error"?e.errorBg:void 0,rn=X.taskId?C.get(X.taskId):void 0,Ce=oa(X.ts,$),ht=rn&&I>80?`#${rn.slice(0,20)}`:"",xt=ht?ht.length+3:0,qt=Math.max(10,I-2-N-xt),mt=rt(X.text,qt);return jsxs(Box,{backgroundColor:Ze,children:[jsx(Text,{color:Ae??e.ghost,children:Ke&&De?"\u250C":Ye?"\u2502":" "}),jsx(Text,{color:le?e.amber:void 0,children:le?"\u25B8":" "}),jsx(Box,{width:5,children:jsx(Text,{color:Ce==="now"?e.green:le?e.silver:e.ghost,children:Ce.padStart(4)})}),jsx(Box,{width:L+1,children:De?jsxs(Text,{color:Ae,bold:true,children:[" ",dt.slice(0,L).padEnd(L)]}):Ye?jsxs(Text,{color:Ae??e.ghost,children:[" ","\xB7".padEnd(L)]}):jsxs(Text,{color:e.ghost,children:[" "," ".padEnd(L)]})}),jsxs(Text,{color:Ee==="error"?e.red:Ae??e.dim,children:[" ",Ft," "]}),jsx(Text,{color:le?e.white:gt,bold:le||Ee==="lifecycle",children:mt}),ht&&jsxs(Text,{color:e.ghost,children:[" ",jsx(Text,{color:e.dim,backgroundColor:e.void,children:` ${ht} `})]})]},_)})]})}function Pc({messages:t,height:n,width:o,agents:r,agentNameMap:l,agentColorMap:f}){let x=na(),T=t.slice(-n),b=Math.max(10,o-2-17),y=Math.max(0,n-T.length),C=0,I=[];for(let $=0;$<T.length;$++)$>0&&T[$].agentId!==T[$-1].agentId&&C++,I.push(C);return jsxs(Box,{flexDirection:"column",paddingX:1,children:[y>0&&jsx(Box,{height:y}),T.map(($,S)=>{let H=$.agentId?l.get($.agentId)??$.agentId.slice(0,8):void 0,V=$.agentId?f.get($.agentId):void 0,F=$.msgType??"info",P=or[F]??"\u2502",j=ra(F,$.color),L=(S>0?T[S-1]:void 0)?.agentId===$.agentId&&!!$.agentId,N=(I[S]&1)===1,E=Oc(F)??(N?"#1a1a1a":void 0),W=oa($.ts,x),z=rt($.text,b);return jsxs(Box,{backgroundColor:E,children:[jsx(Text,{color:V??e.ghost,children:!L&&H?"\u258D":L?"\u258F":" "}),jsx(Box,{width:5,children:jsx(Text,{color:L?e.ghost:W==="now"?e.green:e.dim,children:L?" ":W.padStart(4)})}),jsx(Box,{width:9,children:H&&!L?jsxs(Text,{color:V,bold:true,children:[" ",H.slice(0,8)]}):jsx(Text,{color:e.ghost,children:vc})}),jsxs(Text,{color:F==="error"?e.red:L?e.ghost:V??e.dim,children:[P," "]}),jsx(Text,{color:j,children:z})]},S)})]})}function Nc({message:t,height:n,width:o,agents:r,agentNameMap:l,agentColorMap:f,taskTitleMap:x}){let T=t.detail??t.text,b=t.msgType??"info",y=t.agentId?l.get(t.agentId)??t.agentId.slice(0,8):void 0,C=t.agentId?f.get(t.agentId):e.dim,I=t.taskId?x.get(t.taskId):void 0,$,S=false;try{let P=JSON.parse(T);$=JSON.stringify(P,null,2),S=!0;}catch{$=T;}let H=Math.max(4,o-6),V=Math.max(1,n-4),F=$.split(`
15
15
  `).slice(0,V);return jsxs(Box,{flexDirection:"column",paddingX:1,children:[jsx(Box,{children:jsxs(Text,{color:e.ghost,children:["\u256D",be(H+2),"\u256E"]})}),jsxs(Box,{children:[jsx(Text,{color:e.ghost,children:"\u2502 "}),jsx(Text,{color:e.dim,children:t.time}),jsx(Text,{color:e.ghost,children:" \u2502 "}),y&&jsx(Text,{color:C,bold:true,children:y}),y&&jsx(Text,{color:e.ghost,children:" \u2502 "}),jsxs(Text,{color:or[b]?b==="error"?e.red:e.dim:e.dim,children:[or[b]??"\u2502"," ",b]}),I&&jsxs(Fragment,{children:[jsx(Text,{color:e.ghost,children:" \u2502 "}),jsxs(Text,{color:e.dim,children:["#",I.slice(0,30)]})]})]}),jsxs(Box,{children:[jsx(Text,{color:e.ghost,children:"\u2502 "}),jsx(Text,{color:t.color,bold:true,wrap:"truncate",children:t.text.slice(0,H)})]}),jsx(Box,{children:jsxs(Text,{color:e.ghost,children:["\u251C",be(H+2),"\u2524"]})}),F.map((P,j)=>jsxs(Box,{children:[jsx(Text,{color:e.ghost,children:"\u2502 "}),S&&jsxs(Text,{color:e.ghost,children:[String(j+1).padStart(3)," "]}),jsx(Text,{wrap:"truncate",color:S&&P.includes('"')?e.cyan:S&&/^\s*[}\]]/.test(P)?e.ghost:P.startsWith("error")||P.startsWith("Error")?e.red:e.silver,children:P.slice(0,S?H-4:H)})]},j)),jsx(Box,{children:jsxs(Text,{color:e.ghost,children:["\u2570",be(H+2),"\u256F"]})})]})}function Jo({label:t,width:n,suffix:o,suffixLen:r=0}){let l=` ${t} `,f=3,x=f+l.length+2;if(!o){let y=Math.max(0,n-x);return jsxs(Box,{paddingX:1,children:[jsx(Text,{color:e.ghost,children:He(f)}),jsx(Text,{backgroundColor:"#1a1a22",color:e.dim,bold:true,children:l}),jsx(Text,{color:e.ghost,children:He(y)})]})}let T=2,b=Math.max(0,n-x-T-r);return jsxs(Box,{paddingX:1,children:[jsx(Text,{color:e.ghost,children:He(f)}),jsx(Text,{backgroundColor:"#1a1a22",color:e.dim,bold:true,children:l}),jsx(Text,{color:e.ghost,children:He(T)}),o,jsx(Text,{color:e.ghost,children:He(b)})]})}function Dc({task:t,width:n,resizeHint:o}){let r=" DETAIL ",l=o?` ${o} `:"",f=n-r.length-l.length-10,x=t.title.length>f?t.title.slice(0,f-3)+"...":t.title,T=Math.max(0,n-3-r.length-x.length-l.length-4);return jsxs(Box,{paddingX:1,children:[jsx(Text,{color:e.ghost,children:He(3)}),jsx(Text,{backgroundColor:"#2d1f0a",color:e.amber,bold:true,children:r}),jsxs(Text,{color:e.ghost,children:[Ro," "]}),jsx(Text,{color:e.white,bold:true,children:x}),jsxs(Text,{color:e.ghost,children:[" ",He(Math.max(0,T))]}),l?jsx(Text,{color:e.dim,children:l}):null]})}function Fc({agent:t,width:n,resizeHint:o}){let r=" AGENT ",l=o?` ${o} `:"",f=n-r.length-l.length-10,x=t.name.length>f?t.name.slice(0,f-3)+"...":t.name,T=Math.max(0,n-3-r.length-x.length-l.length-4);return jsxs(Box,{paddingX:1,children:[jsx(Text,{color:e.ghost,children:He(3)}),jsx(Text,{backgroundColor:"#0f2d1f",color:e.green,bold:true,children:r}),jsxs(Text,{color:e.ghost,children:[Ro," "]}),jsx(Text,{color:e.green,bold:true,children:x}),jsxs(Text,{color:e.ghost,children:[" ",He(Math.max(0,T))]}),l?jsx(Text,{color:e.dim,children:l}):null]})}function Gc({agent:t,height:n$1,state:o,taskTitleMap:r,teamName:l}){let f=Wc[t.status]??e.dim;Object.values(o.running).find(y=>y.agent_id===t.id);let T=t.current_task?r.get(t.current_task):void 0,b=24;return jsxs(Box,{flexDirection:"column",paddingX:2,children:[jsxs(Box,{children:[jsxs(Box,{width:b,children:[jsx(Text,{color:e.dim,children:" status "}),jsx(Text,{color:f,children:t.status})]}),jsxs(Box,{children:[jsx(Text,{color:e.dim,children:" adapter "}),jsx(Text,{color:e.cyan,children:t.adapter})]})]}),jsxs(Box,{children:[jsxs(Box,{width:b,children:[jsx(Text,{color:e.dim,children:" model "}),jsx(Text,{children:t.config.model??"\u2014"})]}),jsxs(Box,{children:[jsx(Text,{color:e.dim,children:" task "}),jsx(Text,{color:T?e.white:e.dim,children:T??"\u2014"})]})]}),jsxs(Box,{children:[jsxs(Box,{width:b,children:[jsx(Text,{color:e.dim,children:" runs "}),jsx(Text,{children:t.stats.total_runs}),jsx(Text,{color:e.dim,children:" ("}),jsx(Text,{color:e.green,children:t.stats.tasks_completed}),jsx(Text,{color:e.dim,children:"/"}),jsx(Text,{color:t.stats.tasks_failed>0?e.red:e.dim,children:t.stats.tasks_failed}),jsx(Text,{color:e.dim,children:")"})]}),jsxs(Box,{children:[jsx(Text,{color:e.dim,children:" team "}),jsx(Text,{color:l?e.amber:e.dim,children:l??"\u2014"})]})]}),t.autonomous&&jsx(Box,{children:jsxs(Box,{width:b,children:[jsx(Text,{color:e.dim,children:" auto "}),jsxs(Text,{color:e.cyan,children:[pn," ON"]})]})}),t.config.skills&&t.config.skills.length>0&&jsxs(Box,{children:[jsx(Text,{color:e.dim,children:" skills "}),jsx(Text,{color:e.cyan,wrap:"truncate",children:rt(t.config.skills.join(", "),500)})]}),t.last_error&&(()=>{let y=t.last_error.kind,C=n[y],I=!C||y==="unknown",$=t.last_error.timestamp,S=$?g($)+" ago":"";return jsxs(Fragment,{children:[jsx(Text,{children:" "}),jsxs(Box,{flexDirection:"column",borderStyle:"single",borderColor:e.red,paddingX:1,children:[jsxs(Text,{color:e.red,bold:true,children:["\u26A0"," \u041E\u0448\u0438\u0431\u043A\u0430"]}),C&&jsx(Text,{color:e.white,children:C.message}),C&&jsx(Text,{color:e.cyan,children:C.fix}),C?.doctorHint&&jsx(Text,{color:e.yellow,children:"\u0414\u0438\u0430\u0433\u043D\u043E\u0441\u0442\u0438\u043A\u0430: orch doctor"}),I&&t.last_error.message&&jsx(Text,{color:e.dim,children:rt(t.last_error.message,120)}),S&&jsx(Text,{color:e.dim,children:S})]})]})})(),jsx(Text,{children:" "}),t.role?t.role.split(`
@@ -856,7 +856,9 @@ var Orchestrator = class _Orchestrator {
856
856
  return true;
857
857
  });
858
858
  for (const taskId of dueRetries) {
859
- await this.dispatchTask(taskId);
859
+ const retryTask = await this.deps.taskStore.get(taskId);
860
+ if (!retryTask || !isDispatchable(retryTask.status)) continue;
861
+ await this.dispatchTask(taskId, retryTask);
860
862
  }
861
863
  await this.saveState();
862
864
  }
@@ -1071,13 +1073,16 @@ Agent role: ${role}` : `Autonomous work cycle. Agent role: ${role}`;
1071
1073
  /**
1072
1074
  * Dispatch a single task: claim → assign → execute.
1073
1075
  */
1074
- async dispatchTask(taskId) {
1076
+ async dispatchTask(taskId, prefetched) {
1075
1077
  const state = this.state;
1076
1078
  if (state.running[taskId]) {
1077
1079
  const entry = state.running[taskId];
1078
1080
  throw new TaskAlreadyRunningError(taskId, entry.run_id, entry.agent_id);
1079
1081
  }
1080
- const task = await this.deps.taskService.get(taskId);
1082
+ const task = prefetched ?? await this.deps.taskService.get(taskId);
1083
+ if (!isDispatchable(task.status)) {
1084
+ return;
1085
+ }
1081
1086
  state.claimed.add(taskId);
1082
1087
  await this.saveState();
1083
1088
  try {
@@ -1487,6 +1492,7 @@ Agent role: ${role}` : `Autonomous work cycle. Agent role: ${role}`;
1487
1492
  await this.flushStateLazy();
1488
1493
  this.abortControllers.delete(taskId);
1489
1494
  const state = this.state;
1495
+ if (!state.running[taskId]) return;
1490
1496
  const task = await this.deps.taskStore.get(taskId);
1491
1497
  if (!task) return;
1492
1498
  await this.deps.runService.finish(entry.run_id, "failed", void 0, error);
@@ -1787,5 +1793,5 @@ function serializeEventData(data, maxLen) {
1787
1793
  }
1788
1794
 
1789
1795
  export { Orchestrator, canTransition, isBlocked, isDispatchable, isTerminal, resolveFailureStatus };
1790
- //# sourceMappingURL=chunk-NNF3VEVJ.js.map
1791
- //# sourceMappingURL=chunk-NNF3VEVJ.js.map
1796
+ //# sourceMappingURL=chunk-WM64PSY4.js.map
1797
+ //# sourceMappingURL=chunk-WM64PSY4.js.map