@oxgeneral/orch 1.0.10 → 1.0.13

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.
@@ -0,0 +1,22 @@
1
+ #!/usr/bin/env node
2
+ import {b,a as a$2}from'./chunk-HWEMBO36.js';import {a}from'./chunk-N4OXN2HW.js';import {c,a as a$1}from'./chunk-HXOMNULD.js';import {f,h,g}from'./chunk-64WUDYEM.js';import {m}from'./chunk-IKNBPOQL.js';import ao,{useState,useMemo,useEffect,useRef,useCallback}from'react';import {Box,Text,useInput,useApp,useStdout}from'ink';import {jsxs,jsx,Fragment}from'react/jsx-runtime';var e={amber:"#ffaf00",amberDim:"#af8700",green:"#5faf87",red:"#d75f5f",blue:"#5fafd7",yellow:"#d7af00",cyan:"#5fd7d7",purple:"#af87ff",white:"#eeeeee",silver:"#bcbcbc",gray:"#808080",dim:"#585858",ghost:"#3a3a3a",void:"#262626",errorBg:"#3d1515",warnBg:"#3d2e0a",successBg:"#0f2d1f",infoBg:"#1a1a22",toolBg:"#0f1f2d"},Ro="\u2501",Ve="\u2500",fe="\xB7",Zt="\u25C8",Ir="\u2605",gn="\u27F3",Ht="\u25C6",Ao={in_progress:e.green,retrying:e.yellow,review:e.blue,todo:e.dim,done:e.green,failed:e.red,cancelled:e.dim},Ms=new Map,vs=new Map;function He(t){if(t<=0)return "";let n=Ms.get(t);return n||(n=Ro.repeat(t),Ms.set(t,n)),n}function Te(t){if(t<=0)return "";let n=vs.get(t);return n||(n=Ve.repeat(t),vs.set(t,n)),n}function rt(t,n){return t.length>n?t.slice(0,n-1)+"\u2026":t}var Ya=1e4;function Mr(t,n=Ya){if(t)return t.length>n?t.slice(0,n)+`
3
+ \u2026[truncated]`:t}var _s={active:e.green,paused:e.dim,achieved:e.amber,abandoned:e.ghost};var Qa=120,vr=0,oo=null,$o=new Set;function el(){oo||(oo=setInterval(()=>{vr++;for(let t of $o)t(vr);},Qa));}function tl(){oo&&$o.size===0&&(clearInterval(oo),oo=null);}function mn(){let[t,n]=useState(vr);return useEffect(()=>{let o=r=>n(r);return $o.add(o),el(),()=>{$o.delete(o),tl();}},[]),t}var Rs=["\u280B","\u2819","\u2839","\u2838","\u283C","\u2834","\u2826","\u2827","\u2807","\u280F"];function En({color:t}){let n=mn();return jsx(Text,{color:t,children:Rs[n%Rs.length]})}var ro={in_progress:0,retrying:1,review:2,todo:3,done:4,failed:5,cancelled:6};var sl="\u25CB",$s="\u2713",Bs="\u2715",il="\u21BB",al="\u2500",ll="\u25B6",Pt={green:"#0f2d1f",blue:"#0f1f2d",yellow:"#2d2a0f",red:"#2d0f0f",neutral:"#1a1a22",amber:"#2d1f0a"},cl={in_progress:{icon:ll,label:"RUN",fg:e.green,bg:Pt.green,bold:true,spinner:true},retrying:{icon:il,label:"RETRY",fg:e.yellow,bg:Pt.yellow,spinner:true},review:{icon:Zt,label:"REVIEW",fg:e.blue,bg:Pt.blue},todo:{icon:sl,label:"TODO",fg:e.dim,bg:Pt.neutral},done:{icon:$s,label:"DONE",fg:e.green,bg:Pt.green},failed:{icon:Bs,label:"FAIL",fg:e.red,bg:Pt.red,bold:true},cancelled:{icon:al,label:"OFF",fg:e.dim,bg:Pt.neutral}},dl={1:{color:e.red,label:"!!!"},2:{color:e.yellow,label:"!!"},3:{color:e.dim,label:"!"},4:{color:e.ghost,label:fe}};var gl=18,ml="#2d1f0a",Bo=ao.memo(function({task:n,selected:o,width:r,agentNameMap:l,goalMap:p}){let b=cl[n.status],T=n.status==="in_progress"||n.status==="retrying",x=dl[n.priority]??{color:e.ghost,label:fe},y,C;if(n.status==="done")y=$s,C=e.green;else if(n.status==="failed")y=Bs,C=e.red;else if(T){let E=Date.now()-new Date(n.updated_at).getTime();y=f(E),C=e.cyan;}else y="\u2014",C=void 0;let M=o?"\u25B8":" ",A=n.goalId?p?.get(n.goalId):void 0,S=!!A,H=10,V=4,F=14,P=S?gl:0,j=7,L=2+H+V+F+P+j,O=r?Math.max(10,r-L):40,N=n.assignee?l?.get(n.assignee)??n.assignee:void 0;return jsxs(Box,{children:[jsxs(Text,{color:o?e.amber:void 0,children:[M," "]}),jsx(Box,{width:H,children:jsx(Text,{backgroundColor:b.bg,color:b.fg,bold:b.bold,children:b.spinner?jsxs(Fragment,{children:[" ",jsx(En,{color:b.fg})," ",b.label," "]}):jsxs(Fragment,{children:[" ",b.icon," ",b.label," "]})})}),jsx(Box,{width:V,children:jsx(Text,{color:x.color,bold:n.priority<=2,children:x.label})}),jsxs(Box,{width:O,children:[jsx(Text,{wrap:"truncate",bold:o||T,color:o?e.white:T?e.silver:void 0,children:n.title.length>O?n.title.slice(0,O-1)+"\u2026":n.title}),(n.attachments?.length??0)>0&&jsxs(Text,{color:e.dim,children:[" ","\u{1F4CE}",n.attachments.length]})]}),S&&jsx(Box,{width:P,children:jsxs(Text,{backgroundColor:ml,color:e.amberDim,wrap:"truncate",children:[" \u2295 ",rt(A.title,13)," "]})}),jsx(Box,{width:F,children:N?jsxs(Text,{backgroundColor:Pt.green,color:e.green,wrap:"truncate",children:[" ",N.length>F-2?N.slice(0,F-3)+"\u2026":N," "]}):jsx(Text,{color:e.ghost,children:"\u2014"})}),jsx(Box,{width:j,justifyContent:"flex-end",children:jsx(Text,{color:C,dimColor:!C,children:y})})]})});var Es="\u2295";function Ls({goalTitle:t,taskCount:n,doneCount:o,width:r}){let l=n>0?Math.round(o/n*100):0,p=` ${Es} ${t.toUpperCase()} ${fe} ${n} task${n!==1?"s":""} ${fe} ${l}% done `,b=3,T=Math.max(0,r-b-p.length-4);return jsxs(Box,{paddingX:2,children:[jsx(Text,{color:e.ghost,children:Te(b)}),jsx(Text,{backgroundColor:Pt.amber,color:e.amber,bold:true,children:p}),jsx(Text,{color:e.ghost,children:Te(T)})]})}function Os({taskCount:t,width:n}){let o=` ${Es} UNGROUPED ${fe} ${t} task${t!==1?"s":""} `,r=3,l=Math.max(0,n-r-o.length-4);return jsxs(Box,{paddingX:2,children:[jsx(Text,{color:e.ghost,children:Te(r)}),jsx(Text,{backgroundColor:Pt.neutral,color:e.dim,children:o}),jsx(Text,{color:e.ghost,children:Te(l)})]})}var pl="\u2715",Ps="\u25CB",hl="\u25B6",xl="\u2713",Ln={green:"#0f2d1f",red:"#2d0f0f",neutral:"#1a1a22",amber:"#2d1f0a"},bl={running:{icon:hl,label:"ACTIVE",fg:e.green,bg:Ln.green,bold:true,spinner:true},idle:{icon:Ps,label:"IDLE",fg:e.dim,bg:Ln.neutral},error:{icon:pl,label:"ERROR",fg:e.red,bg:Ln.red,bold:true},disabled:{icon:Ps,label:"OFF",fg:e.ghost,bg:Ln.neutral}},_r={running:0,idle:1,error:2,disabled:3},Ds=ao.memo(function({agent:n,selected:o,width:r,runningEntry:l,currentTaskTitle:p,teamName:b,isLead:T}){let x=bl[n.status],y=n.status==="running",C,M;if(y&&l){let N=Date.now()-new Date(l.started_at).getTime();C=f(N),M=e.cyan;}else n.stats.total_runs>0?(C=`${n.stats.tasks_completed}/${n.stats.total_runs}`,M=n.stats.tasks_completed>0?e.green:e.dim):(C="\u2014",M=void 0);let A=o?"\u25B8":" ",S=11,H=8,V=b?Math.min(b.length+2,12):0,F=10,P=2+S+H+V+F,j=r?Math.max(8,r-P):20,L=n.stats.total_runs>0,O=L?Math.round(n.stats.tasks_completed/n.stats.total_runs*100):0;return jsxs(Box,{children:[jsxs(Text,{color:o?e.amber:void 0,children:[A," "]}),jsx(Box,{width:S,children:jsx(Text,{backgroundColor:x.bg,color:x.fg,bold:x.bold,children:x.spinner?jsxs(Fragment,{children:[" ",jsx(En,{color:x.fg})," ",x.label," "]}):jsxs(Fragment,{children:[" ",x.icon," ",x.label," "]})})}),jsx(Box,{width:j,children:jsxs(Text,{wrap:"truncate",bold:o||y,color:o?e.white:y?e.green:e.silver,children:[n.autonomous&&jsxs(Text,{color:e.cyan,children:[gn," "]}),T&&jsxs(Text,{color:e.amber,children:[Ir," "]}),n.name,y&&p&&jsxs(Text,{color:e.dim,children:[" ",fe," ",p]}),n.status==="error"&&n.last_error&&jsxs(Text,{color:e.red,children:[" ",fe," ",rt(m[n.last_error.kind]?.message??n.last_error.message,30)]})]})}),jsx(Box,{width:H,children:jsx(Text,{color:e.dim,children:n.adapter})}),b&&jsx(Box,{width:V,children:jsx(Text,{color:e.amber,wrap:"truncate",children:b})}),jsx(Box,{width:F,justifyContent:"flex-end",children:L&&!y?jsxs(Text,{color:O>=80?e.green:O>=50?e.yellow:e.red,children:[C," ",xl]}):jsx(Text,{color:M,dimColor:!M,children:C})})]})});function Fs({teamName:t,memberCount:n,leadName:o,width:r}){let l=`${n} agent${n!==1?"s":""}`,p=o?` ${fe} ${Ir} ${o}`:"",b=` ${Zt} ${t.toUpperCase()} ${fe} ${l}${p} `,T=3,x=Math.max(0,r-T-b.length-4);return jsxs(Box,{paddingX:2,children:[jsx(Text,{color:e.ghost,children:Te(T)}),jsx(Text,{backgroundColor:Ln.amber,color:e.amber,bold:true,children:b}),jsx(Text,{color:e.ghost,children:Te(x)})]})}var Tl="\u25C7";function Gs({memberCount:t,width:n}){let o=`${t} agent${t!==1?"s":""}`,r=` ${Tl} UNASSIGNED ${fe} ${o} `,l=3,p=Math.max(0,n-l-r.length-4);return jsxs(Box,{paddingX:2,children:[jsx(Text,{color:e.ghost,children:Te(l)}),jsx(Text,{backgroundColor:Ln.neutral,color:e.dim,children:r}),jsx(Text,{color:e.ghost,children:Te(p)})]})}var Ws="\u2713",zs="\u2715",wl="\u2016",Sl="\u25C9",io={green:"#0f2d1f",amber:"#2d1f0a",neutral:"#1a1a22"},kl={active:{icon:Sl,label:"ACTIVE",fg:e.green,bg:io.green,bold:true},paused:{icon:wl,label:"PAUSED",fg:e.dim,bg:io.neutral},achieved:{icon:Ws,label:"DONE",fg:e.amber,bg:io.amber,bold:true},abandoned:{icon:zs,label:"DROP",fg:e.ghost,bg:io.neutral}},Cl="\u2588",Il="\u2591",Ml=14,Vs=ao.memo(function({goal:n,selected:o,width:r,agentNameMap:l,tasksByGoal:p}){let b=kl[n.status],T=o?"\u25B8":" ",x=p?.length??0,y=p?.filter(O=>O.status==="done").length??0,C=x>0,M=11,A=C?Ml:0,S=14,H=7,V=2+M+A+S+H,F=r?Math.max(10,r-V):40,P=n.assignee?l?.get(n.assignee)??n.assignee:void 0,j,L;if(n.status==="achieved")j=Ws,L=e.amber;else if(n.status==="abandoned")j=zs,L=e.ghost;else {let O=Date.now()-new Date(n.created_at).getTime(),N=Math.floor(O/864e5);j=N>0?`${N}d`:"<1d",L=e.dim;}return jsxs(Box,{children:[jsxs(Text,{color:o?e.amber:void 0,children:[T," "]}),jsx(Box,{width:M,children:jsxs(Text,{backgroundColor:b.bg,color:b.fg,bold:b.bold,children:[" ",b.icon," ",b.label," "]})}),jsx(Box,{width:F,children:jsx(Text,{wrap:"truncate",bold:o||n.status==="active",color:o?e.white:n.status==="active"?e.silver:void 0,children:n.title.length>F?n.title.slice(0,F-1)+"\u2026":n.title})}),C&&(()=>{let N=x>0?Math.round(y/x*6):0,E=6-N;return jsxs(Box,{width:A,children:[jsx(Text,{color:e.green,children:Cl.repeat(N)}),jsx(Text,{color:e.ghost,children:Il.repeat(E)}),jsx(Text,{color:e.dim,children:` ${y}/${x}`})]})})(),jsx(Box,{width:S,children:P?jsxs(Text,{backgroundColor:io.green,color:e.green,wrap:"truncate",children:[" ",P.length>S-2?P.slice(0,S-3)+"\u2026":P," "]}):jsx(Text,{color:e.ghost,children:"\u2014"})}),jsx(Box,{width:H,justifyContent:"flex-end",children:jsx(Text,{color:L,dimColor:!L,children:j})})]})});var vl={system:"\u2666",lifecycle:"\u25B6",output:"\u2502",tool:"\u2699",result:"\u2190",error:"\u2715",file:"\u270E",info:"\u2502"};function Nn({label:t,width:n,color:o}){let r=n-4,l=` ${t} `,p=3,b=Math.max(0,r-p-l.length);return jsxs(Text,{color:o??e.ghost,children:[" ",Te(p),l,Te(b)]})}function Hs({task:t,height:n,width:o,taskLogs:r,agentNameMap:l,taskTitleMap:p}){let b=Ao[t.status]??e.dim,T=t.priority<=2?t.priority===1?e.red:e.yellow:void 0,x=24,y=!!t.description?.trim(),C=!!t.proof?.agent_summary,M=(t.proof?.files_changed?.length??0)>0,A=(r?.length??0)>0,S=(t.attachments?.length??0)>0,H=y?t.description.split(`
4
+ `):[],V=C?t.proof.agent_summary.split(`
5
+ `):[],F=3;S&&(F+=2+t.attachments.length),y?(F+=1,F+=Math.min(H.length,Math.max(1,Math.ceil((n-10)*.3)))):C||(F+=2),C&&(F+=2),M&&(F+=1),A&&(F+=2);let P=Math.max(0,n-F),j=0,L=0;C&&A?(j=Math.max(1,Math.floor(P*.4)),L=Math.max(1,P-j)):C?j=P:A&&(L=P);let O=y?H.slice(0,Math.max(1,Math.ceil((n-10)*.3))):[],N=V.slice(0,j);return jsxs(Box,{flexDirection:"column",paddingX:2,children:[jsxs(Box,{children:[jsxs(Box,{width:x,children:[jsx(Text,{color:e.dim,children:" status "}),jsx(Text,{color:b,children:t.status})]}),jsxs(Box,{children:[jsx(Text,{color:e.dim,children:" assignee "}),jsx(Text,{color:t.assignee?e.green:e.dim,children:t.assignee?l?.get(t.assignee)??t.assignee:"\u2014"})]})]}),jsxs(Box,{children:[jsxs(Box,{width:x,children:[jsx(Text,{color:e.dim,children:" priority "}),jsxs(Text,{color:T,bold:t.priority<=2,children:["P",t.priority]})]}),jsxs(Box,{children:[jsx(Text,{color:e.dim,children:" attempts "}),jsxs(Text,{children:[t.attempts,"/",t.max_attempts]})]})]}),jsxs(Box,{children:[jsxs(Box,{width:x,children:[jsx(Text,{color:e.dim,children:" labels "}),jsx(Text,{color:e.purple,children:t.labels.length>0?t.labels.join(", "):"\u2014"})]}),jsxs(Box,{children:[jsx(Text,{color:e.dim,children:" depends "}),jsx(Text,{dimColor:true,children:t.depends_on.length>0?t.depends_on.map(E=>p?.get(E)??E).join(", "):"\u2014"})]})]}),S&&jsxs(Fragment,{children:[jsx(Text,{children:" "}),jsx(Nn,{label:`attachments (${t.attachments.length})`,width:o,color:e.dim}),t.attachments.map((E,W)=>jsxs(Text,{color:e.cyan,wrap:"truncate",children:[" ",E]},`a${W}`))]}),y&&jsxs(Fragment,{children:[jsx(Text,{children:" "}),O.map((E,W)=>jsxs(Text,{color:e.silver,wrap:"truncate",children:[" ",rt(E,o-8)]},`d${W}`))]}),!y&&!C&&jsxs(Fragment,{children:[jsx(Text,{children:" "}),jsx(Text,{color:e.dim,children:" No description."})]}),C&&jsxs(Fragment,{children:[jsx(Text,{children:" "}),jsx(Nn,{label:"result",width:o,color:e.dim}),N.map((E,W)=>jsxs(Text,{color:e.white,wrap:"truncate",children:[" ",rt(E,o-8)]},`r${W}`))]}),M&&jsxs(Box,{children:[jsx(Text,{color:e.dim,children:" files "}),jsx(Text,{color:e.cyan,children:t.proof.files_changed.length}),jsx(Text,{color:e.dim,children:" changed"}),t.proof.branch&&jsxs(Fragment,{children:[jsxs(Text,{color:e.dim,children:[" ","\xB7"," "]}),jsx(Text,{color:e.cyan,children:t.proof.branch})]})]}),A&&jsxs(Fragment,{children:[jsx(Text,{children:" "}),jsx(Nn,{label:"activity",width:o,color:e.dim}),r.slice(-L).map((E,W)=>{let z=E.msgType??"info",X=vl[z]??"\u2502",_=E.color;z==="tool"?_=e.cyan:z==="file"?_=e.purple:z==="error"?_=e.red:z==="lifecycle"?_=e.green:z==="system"&&(_=e.dim);let ae=Math.max(10,o-12),Ee=rt(E.text,ae);return jsxs(Box,{children:[jsxs(Text,{color:e.ghost,children:[" ",E.time," "]}),jsxs(Text,{color:z==="error"?e.red:e.dim,children:[X," "]}),jsx(Text,{color:_,bold:z==="lifecycle",children:Ee})]},W)})]})]})}var Eo=[{key:"G",id:"goals",label:"GOALS"},{key:"T",id:"tasks",label:"TASKS"},{key:"A",id:"agents",label:"AGENTS"},{key:"L",id:"logs",label:"ACTIONS"}];var js="\u25CF",Xs="\u25CB",_l="\u2713",Rl="\u2715",Al="\u2191",$l="\u2193",Bl="\u03A3",El="\u25B6",Ll="\u21BB",Ol="\u{1F9E0}",Us=["\u280B","\u2819","\u2839","\u2838","\u283C","\u2834","\u2826","\u2827","\u2807","\u280F"],Rr=[" ","\u2581","\u2582","\u2583","\u2584","\u2585","\u2586","\u2587","\u2588"],Qe={green:"#0f2d1f",blue:"#0f1f2d",yellow:"#2d2a0f",red:"#2d0f0f",neutral:"#1a1a22",amber:"#2d1f0a"};function qs({color:t}){let n=mn();return jsx(Text,{color:t,children:Us[n%Us.length]})}function Pl(){let t=mn(),n=Math.floor(t/10)%2===0;return jsx(Text,{color:n?e.amber:e.amberDim,bold:true,children:Ht})}function Nl({width:t,active:n}){let o=Math.max(4,Math.floor(t*.08)),r=2,l=mn(),p=Math.ceil((t+o)/r),b=n?l%(p*2):0;if(!n)return jsx(Box,{paddingX:1,children:jsx(Text,{color:e.ghost,children:He(t)})});let T=b<p?b*r:(p*2-b)*r,x=Math.max(0,T-o),y=Math.min(t,T),C=x,M=Math.max(0,y-x),A=Math.max(0,t-y);return jsxs(Box,{paddingX:1,children:[jsx(Text,{color:e.ghost,children:He(C)}),jsx(Text,{color:e.amber,children:He(M)}),jsx(Text,{color:e.ghost,children:He(A)})]})}function Dl({data:t,width:n,color:o}){if(t.length===0)return null;let r=t.slice(-n),l=Math.max(...r,1),p=r.map(b=>{let T=Math.round(b/l*(Rr.length-1));return Rr[T]??Rr[0]}).join("");return jsx(Text,{color:o,children:p})}function Fl({tab:t,flashColor:n,onComplete:o,badge:r}){let l=mn(),p=ao.useRef(l),b=ao.useRef(false),T=l-p.current,x=2,y=6*x;return ao.useEffect(()=>{T>=y&&!b.current&&(b.current=true,o());},[T,o]),Math.floor(T/x)%2===0&&T<y?jsxs(Text,{backgroundColor:n,color:"#0a0a0c",bold:true,children:[" ",t.key," ",t.label,r," "]}):jsxs(Box,{gap:0,children:[jsx(Text,{color:e.ghost,children:t.key}),jsxs(Text,{color:e.dim,children:[" ",t.label.toLowerCase(),r]})]})}function Gl({projectName:t,activeView:n,mode:o,stats:r,uptime:l,width:p,version:b,latestVersion:T,updateInstalled:x,taskBadge:y,flashTab:C,flashColor:M,onFlashComplete:A}){return jsxs(Box,{paddingX:1,justifyContent:"space-between",width:p,children:[jsxs(Box,{gap:0,children:[jsx(Pl,{}),jsx(Text,{color:e.amber,bold:true,children:" ORCH"}),b&&jsxs(Text,{color:e.ghost,children:[" ",b]}),T&&T!==b&&(x?jsxs(Text,{backgroundColor:Qe.green,color:e.green,bold:true,children:[" v",T," INSTALLED \u2014 RESTART TO APPLY "]}):jsxs(Text,{backgroundColor:Qe.green,color:e.green,bold:true,children:[" UPDATE ",T," "]})),jsxs(Text,{color:e.ghost,children:[" ",fe," "]}),jsx(Text,{color:e.silver,children:t})]}),jsx(Box,{gap:0,children:Eo.map((S,H)=>{let V=n===S.id,F=S.id==="tasks"&&y!=null&&y>0?` (${y})`:"",P=!V&&C===S.id&&M&&A;return jsxs(ao.Fragment,{children:[H>0&&jsx(Text,{children:" "}),V?jsxs(Text,{backgroundColor:e.amber,color:"#0a0a0c",bold:true,children:[" ",S.key," ",S.label,F," "]}):P?jsx(Fl,{tab:S,flashColor:M,onComplete:A,badge:F}):jsxs(Box,{gap:0,children:[jsx(Text,{color:e.ghost,children:S.key}),jsxs(Text,{color:e.dim,children:[" ",S.label.toLowerCase(),F]})]})]},S.id)})}),jsxs(Box,{gap:0,children:[o==="watching"?jsxs(Text,{backgroundColor:Qe.green,color:e.green,bold:true,children:[" ",js," WATCHING"," "]}):o==="observing"?jsxs(Text,{backgroundColor:Qe.amber,color:e.amber,bold:true,children:[" ",js," OBSERVING"," "]}):jsxs(Text,{backgroundColor:Qe.neutral,color:e.dim,children:[" ",Xs," IDLE"," "]}),r.running>0&&jsxs(Fragment,{children:[jsx(Text,{children:" "}),jsxs(Text,{backgroundColor:Qe.green,color:e.green,children:[" ",jsx(qs,{color:e.green})," ",r.running," active"," "]})]}),l&&jsxs(Text,{color:e.ghost,children:[" ",l]})]})]})}function Wl({stats:t,tokens:n,width:o,sparklineData:r}){let p=[{icon:El,label:"RUN",count:t.running,fg:e.green,bg:Qe.green,bold:true,spinner:true,show:t.running>0},{icon:Ll,label:"RETRY",count:t.retrying,fg:e.yellow,bg:Qe.yellow,show:t.retrying>0},{icon:Zt,label:"REVIEW",count:t.review,fg:e.blue,bg:Qe.blue,show:t.review>0},{icon:Xs,label:"TODO",count:t.todo,fg:e.dim,bg:Qe.neutral,show:t.todo>0},{icon:_l,label:"DONE",count:t.done,fg:e.green,bg:Qe.green,show:t.done>0},{icon:Rl,label:"FAIL",count:t.failed,fg:e.red,bg:Qe.red,bold:true,show:t.failed>0},{icon:Ht,label:"TEAMS",count:t.teams,fg:e.amber,bg:Qe.amber,show:t.teams>0}].filter(x=>x.show),b=n.total>0,T=r&&r.length>0?Math.min(16,r.length):0;return jsxs(Box,{paddingX:1,justifyContent:"space-between",width:o,children:[jsxs(Box,{gap:1,children:[p.map(x=>jsx(Text,{backgroundColor:x.bg,color:x.fg,bold:x.bold,children:x.spinner?jsxs(Fragment,{children:[" ",jsx(qs,{color:x.fg})," ",x.count," ",x.label," "]}):jsxs(Fragment,{children:[" ",x.icon," ",x.count," ",x.label," "]})},x.label)),p.length===0&&jsxs(Text,{backgroundColor:Qe.neutral,color:e.dim,children:[" ","NO TASKS"," "]})]}),jsxs(Box,{gap:0,children:[T>0&&r&&jsxs(Fragment,{children:[jsx(Dl,{data:r,width:T,color:e.amberDim}),jsx(Text,{children:" "})]}),b&&jsxs(Text,{backgroundColor:Qe.amber,color:e.cyan,children:[" ",Al,h(n.input)," ",$l,h(n.output),n.reasoning>0?` ${Ol}${h(n.reasoning)}`:""," ",fe," ",Bl,h(n.total)," "]})]})]})}var Ks=ao.memo(function(n){let o=Math.max(10,n.width-2),r=n.stats.running>0;return jsxs(Box,{flexDirection:"column",children:[jsx(Box,{height:1}),jsx(Gl,{projectName:n.projectName,activeView:n.activeView,mode:n.mode,stats:n.stats,uptime:n.uptime,width:n.width,version:n.version,latestVersion:n.latestVersion,updateInstalled:n.updateInstalled,taskBadge:n.taskBadge,flashTab:n.flashTab,flashColor:n.flashColor,onFlashComplete:n.onFlashComplete}),jsx(Box,{height:1}),jsx(Wl,{stats:n.stats,tokens:n.tokens,width:n.width,sparklineData:n.sparklineData}),jsx(Nl,{width:o,active:r})]})});var lo="\u0423\u041F\u0420\u0410\u0412\u041B\u0415\u041D\u0418\u0415",Dn="\u041C\u041E\u041D\u0418\u0422\u041E\u0420\u0418\u041D\u0413",Oo="\u041D\u0410\u0421\u0422\u0420\u041E\u0419\u041A\u0418",fn={task:{sub:["add","list","show","cancel","retry","assign","approve","reject","delete"],help:"Manage tasks",category:lo},agent:{sub:["add","list","disable","enable","delete","autonomous","shop"],help:"Manage agents",category:lo},team:{sub:["create","list","join","leave","disband","set-lead"],help:"Manage teams",category:lo},goal:{sub:["add","list","show","status","delete"],help:"Manage goals",category:lo},run:{args:"[id]",help:"Run task (or selected)",category:Dn},"run-all":{help:"Run all todo tasks",category:Dn},watch:{help:"Start watch mode (auto-dispatch)",category:Dn},pause:{help:"Pause watch mode",category:Dn},status:{help:"Show orchestrator status",category:Dn},config:{sub:["activity-filter","max-concurrent"],help:"TUI settings",category:Oo},help:{help:"List all commands",category:Oo},quit:{help:"Exit the TUI",category:Oo}};function Ar(t){if(!t.startsWith("/"))return null;let n=t.slice(1),o=n.indexOf(" ");if(o===-1){let T=n;if(!T)return null;let x=Object.keys(fn).find(y=>y.startsWith(T)&&y!==T);return x?x.slice(T.length):null}let r=n.slice(0,o),l=fn[r];if(!l?.sub)return null;let p=n.slice(o+1);if(!p)return null;let b=l.sub.find(T=>T.startsWith(p)&&T!==p);return b?b.slice(p.length):null}function Ys(t){if(!t.startsWith("/"))return [];let n=t.slice(1),o=n.indexOf(" ");if(o===-1){let T=n.toLowerCase(),x=[];if(!T){let y=[lo,Dn,Oo];for(let C of y){x.push({cmd:"",desc:`\u2500\u2500 ${C} \u2500\u2500`});for(let[M,A]of Object.entries(fn))if(A.category===C){let S=A.args?` ${A.args}`:"";x.push({cmd:`/${M}${S}`,desc:A.help,subs:A.sub?.join(" \xB7 ")});}}return x}for(let[y,C]of Object.entries(fn))if(y.startsWith(T)){let M=C.args?` ${C.args}`:"";if(x.push({cmd:`/${y}${M}`,desc:C.help,subs:C.sub?.join(" \xB7 ")}),y===T&&C.sub)for(let A of C.sub)x.push({cmd:`/${y} ${A}`,desc:`${C.help}: ${A}`});}return x}let r=n.slice(0,o),l=fn[r];if(!l?.sub)return [];let p=n.slice(o+1).toLowerCase(),b=[];for(let T of l.sub)(!p||T.startsWith(p))&&b.push({cmd:`/${r} ${T}`,desc:`${l.help}: ${T}`});return b}var Po=class{entries=[];cursor=0;push(n){n&&(this.entries[this.entries.length-1]!==n&&(this.entries.push(n),this.entries.length>100&&this.entries.shift()),this.cursor=this.entries.length);}prev(){return this.entries.length===0?null:(this.cursor>0&&this.cursor--,this.entries[this.cursor]??null)}next(){return this.cursor<this.entries.length-1?(this.cursor++,this.entries[this.cursor]??null):(this.cursor=this.entries.length,null)}reset(){this.cursor=this.entries.length;}};var Vl="\u2588",Zs=ao.memo(function({mode:n,value:o,completion:r,activeView:l,canRun:p,canNew:b,canApprove:T,canReject:x,canCancel:y,canDelete:C,canUndo:M,canEdit:A,canForceStop:S,canToggleAuto:H,autoActive:V,canPause:F,isPaused:P,canToggleShowAll:j,showAllActive:L,hasDetail:O,itemCount:N,itemLabel:E,width:W,hasSuggestions:z,onboardingCompleted:X}){if(n==="command"){let _=z?" \u2191\u2193 select Tab fill Esc \u2715":" Enter exec \u2191\u2193 history Tab complete Esc \u2715",ae=Math.max(4,W-6-_.length-(r?.length??0)-1),Ee=o.length>ae?"\u2026"+o.slice(-(ae-1)):o;return jsx(Box,{paddingX:2,justifyContent:"space-between",width:W,children:jsxs(Box,{children:[jsx(Text,{color:e.amber,children:"/ "}),jsx(Text,{color:e.white,children:Ee}),r&&jsx(Text,{color:e.ghost,children:r}),jsx(Text,{color:e.amber,children:Vl}),jsx(Text,{color:e.dim,children:_})]})})}return jsxs(Box,{paddingX:2,justifyContent:"space-between",width:W,children:[jsxs(Text,{color:e.dim,children:[jsx(Text,{bold:true,color:e.gray,children:"\u2191\u2193"})," ",jsx(Text,{bold:true,color:e.gray,children:"Tab"}),"/",jsx(Text,{bold:true,color:e.gray,children:"\u2190\u2192"})," ",jsx(Text,{bold:true,color:e.gray,children:"/"})," cmd",b&&jsxs(Fragment,{children:[" ",jsx(Text,{bold:true,color:e.gray,children:"N"})," new"]}),p&&jsxs(Fragment,{children:[" ",jsx(Text,{bold:true,color:e.gray,children:"R"})," run"]}),y&&jsxs(Fragment,{children:[" ",jsx(Text,{bold:true,color:e.amber,children:"C"})," cancel"]}),T&&jsxs(Fragment,{children:[" ",jsx(Text,{bold:true,color:e.green,children:"A"})," approve"]}),x&&jsxs(Fragment,{children:[" ",jsx(Text,{bold:true,color:e.red,children:"X"})," reject"]}),A&&jsxs(Fragment,{children:[" ",jsx(Text,{bold:true,color:e.cyan,children:"E"})," edit"]}),S&&jsxs(Fragment,{children:[" ",jsx(Text,{bold:true,color:e.red,children:"S"})," stop"]}),F&&jsxs(Fragment,{children:[" ",jsx(Text,{bold:true,color:e.amber,children:"P"}),P?" resume":" pause"]}),H&&jsxs(Fragment,{children:[" ",jsx(Text,{bold:true,color:e.cyan,children:"U"}),V?" auto off":" auto on"]}),j&&jsxs(Fragment,{children:[" ",jsx(Text,{bold:true,color:e.gray,children:"S"}),L?" collapse":" show all"]}),C&&!T&&jsxs(Fragment,{children:[" ",jsx(Text,{bold:true,color:e.gray,children:"D"})," delete"]}),M&&jsxs(Fragment,{children:[" ",jsx(Text,{bold:true,color:e.yellow,children:"Z"})," undo"]}),O&&jsxs(Fragment,{children:[" ",jsx(Text,{bold:true,color:e.gray,children:"Esc"})," close"]}),!O&&(l==="tasks"||l==="agents"||l==="goals")&&jsxs(Fragment,{children:[" ",jsx(Text,{bold:true,color:e.gray,children:"Enter"})," detail"]})," ",jsx(Text,{bold:true,color:e.gray,children:"Q"})," quit"," ",jsx(Text,{bold:true,color:X===false?e.amber:e.gray,children:"?"}),jsx(Text,{color:X===false?e.amber:void 0,children:" help"})]}),N>0&&jsxs(Text,{color:e.dim,children:[N," ",E]})]})});var No="\u2588",Br=process.platform==="darwin"?"\u2318":"Ctrl";function Ul(t,n){if(n<=0||t.length<=n)return [t];let o=[];for(let r=0;r<t.length;r+=n)o.push(t.slice(r,r+n));return o}function Do(t,n){if(n<=0)return 0;let o=n-1;for(;o>0&&t[o-1]===" ";)o--;for(;o>0&&t[o-1]!==" ";)o--;return o}function ei(t,n){if(n>=t.length)return t.length;let o=n;for(;o<t.length&&t[o]!==" ";)o++;for(;o<t.length&&t[o]===" ";)o++;return o}function ti({title:t,steps:n,onComplete:o,onCancel:r,width:l,height:p,onPasteImage:b,footerExtra:T,onSuggestionSelected:x}){let [y,C]=useState(0),[M,A]=useState({}),[S,H]=useState(()=>{let $=n.find(I=>!I.skip?.({}));return $?.type==="text"&&$.defaultValue?$.defaultValue:""}),[V,F]=useState(()=>{let $=n.find(I=>!I.skip?.({}));return $?.type==="text"&&$.defaultValue?$.defaultValue.length:0}),[P,j]=useState(()=>{let $=n.find(I=>!I.skip?.({}));return $?.type==="textarea"&&$.defaultValue?$.defaultValue.split(`
6
+ `):[""]}),[L,O]=useState(0),[N,E]=useState(0),[W,z]=useState(()=>{let $=n.find(I=>!I.skip?.({}));if($?.type==="select"&&$.defaultValue){let k=($.getOptions?.({})??$.options??[]).findIndex(B=>B.value===$.defaultValue);return k>=0?k:0}return 0}),X=useMemo(()=>n.filter($=>!$.skip?.(M)),[n,M]),_=X[y],ae=X.length,{taLineNumWidth:Ft,taContentWidth:dt}=useMemo(()=>{let $=String(P.length).length;return {taLineNumWidth:$,taContentWidth:Math.max(1,l-$-4)}},[P.length,l]),Re=useMemo(()=>{if(!_||_.type!=="textarea")return [];let $=[];for(let I=0;I<P.length;I++){let k=Ul(P[I]??"",dt);for(let B=0;B<k.length;B++)$.push({logicalRow:I,startCol:B*dt,text:k[B],isFirst:B===0});}return $},[_?.id,_?.type,P,dt]),Ke=useMemo(()=>{for(let $=0;$<Re.length;$++){let I=Re[$];if(I.logicalRow===L&&(N>=I.startCol&&N<I.startCol+dt||N>=I.startCol&&($+1>=Re.length||Re[$+1].logicalRow!==L)))return $}return 0},[Re,L,N,dt]),[ut,pt]=useState(new Set),[De,Ye]=useState(false),[gt,Ze]=useState(0),[nn,Ce]=useState(false),[ht,xt]=useState(null),[Xt,mt]=useState(false),kt=useRef(null),Ue=useRef(null),go=useMemo(()=>_?_.type==="text"?S:_.type==="textarea"?P.join(`
7
+ `):"":"",[_,S,P]),Wn=useCallback(($,I)=>{if(kt.current&&clearTimeout(kt.current),!I){xt(null);return}kt.current=setTimeout(()=>{xt(I($));},300);},[]);useEffect(()=>(_&&_.validate&&(_.type==="text"||_.type==="textarea")&&Wn(go,_.validate),()=>{kt.current&&clearTimeout(kt.current);}),[go,_,Wn]),useEffect(()=>()=>{Ue.current&&clearTimeout(Ue.current);},[]);let Rt=useMemo(()=>!_||_.type!=="select"&&_.type!=="multiselect"?[]:_.getOptions?.(M)??_.options??[],[_,M]),Gt=Math.min(W,Math.max(0,Rt.length-1)),Wt=useMemo(()=>{if(!_?.suggestions)return [];if(!S.trim())return _.suggestions;let $=S.toLowerCase();return _.suggestions.filter(I=>I.label.toLowerCase().includes($)||(I.hint??"").toLowerCase().includes($))},[_?.suggestions,S]),zt=Math.min(gt,Math.max(0,Wt.length-1)),on=$=>{let I={...M,[_.id]:$};A(I),H(""),F(0),j([""]),O(0),E(0),z(0),pt(new Set),Ye(false),Ze(0),Ce(false),xt(null),mt(false),kt.current&&clearTimeout(kt.current);let k=_.id,q=n.findIndex(te=>te.id===k)+1;for(;q<n.length;){let te=n[q];if(te&&!te.skip?.(I))break;q++;}if(q>=n.length)o(I);else {let te=n[q].id,de=n.filter(Ae=>!Ae.skip?.(I)).findIndex(Ae=>Ae.id===te);C(de>=0?de:0);let K=n[q];if(K.type==="text"){let Ae=K.defaultValue??"";H(Ae),F(Ae.length);}else if(K.type==="textarea"){let Ae=K.defaultValue?K.defaultValue.split(`
8
+ `):[""];j(Ae),O(Ae.length-1),E(Ae[Ae.length-1].length);}else if(K.type==="select"){let Ae=K.getOptions?.(I)??K.options??[];if(K.defaultValue){let we=Ae.findIndex(Vn=>Vn.value===K.defaultValue);z(we>=0?we:0);}else z(0);}else K.type==="multiselect"&&(z(0),K.defaultValue?pt(new Set(K.defaultValue.split(","))):pt(new Set));}},rn=()=>{if(y===0){r();return}let $=_.id,k=n.findIndex(de=>de.id===$)-1;for(;k>=0;){let de=n[k];if(de&&!de.skip?.(M))break;k--;}if(k<0){r();return}let B=n[k].id,q=X.findIndex(de=>de.id===B);C(q>=0?q:0),Ye(false),Ze(0),Ce(false),xt(null),mt(false),kt.current&&clearTimeout(kt.current);let te=n[k];if(M[te.id]&&Ce(true),te.type==="text"){let de=M[te.id]??te.defaultValue??"";H(de),F(de.length);}else if(te.type==="textarea"){let de=M[te.id]??te.defaultValue??"",K=de?de.split(`
9
+ `):[""];j(K),O(K.length-1),E(K[K.length-1].length);}else if(te.type==="multiselect"){z(0);let de=M[te.id];pt(de?new Set(de.split(",")):new Set);}else {let de=te.getOptions?.(M)??te.options??[],K=M[te.id],Ae=de.findIndex(we=>we.value===K);z(Ae>=0?Ae:0);}};if(useInput(($,I)=>{if(_){if(I.escape){y===0?r():rn();return}if((I.ctrl||I.meta)&&($==="v"||$==="i")&&b&&(_.type==="text"||_.type==="textarea")){b();return}if(_.type==="text"){if(De&&Wt.length>0){if(I.upArrow){zt<=0?Ye(false):Ze(k=>k-1);return}if(I.downArrow){Ze(k=>Math.min(Wt.length-1,k+1));return}if(I.return){let k=Wt[zt];k&&x&&x(k.value);return}Ye(false);}if(I.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}on(k);return}if(I.downArrow&&_.suggestions&&Wt.length>0){Ye(true),Ze(0);return}if(I.ctrl&&$==="a"){F(0);return}if(I.ctrl&&$==="e"){F(S.length);return}if(I.ctrl&&$==="k"){Ce(true),H(k=>k.slice(0,V));return}if(I.ctrl&&$==="u"){Ce(true),H(k=>k.slice(V)),F(0);return}if(I.ctrl&&$==="w"){Ce(true);let k=Do(S,V);H(B=>B.slice(0,k)+B.slice(V)),F(k);return}if(I.meta&&(I.leftArrow||$==="b")){F(Do(S,V));return}if(I.meta&&(I.rightArrow||$==="f")){F(ei(S,V));return}if(I.leftArrow){F(k=>Math.max(0,k-1));return}if(I.rightArrow){F(k=>Math.min(S.length,k+1));return}if(I.backspace||I.delete){if(V===0&&S.length===0&&y>0){rn();return}V>0&&(H(k=>k.slice(0,V-1)+k.slice(V)),F(k=>k-1));return}$&&!I.ctrl&&!I.meta&&!I.escape&&(Ce(true),Ye(false),Ze(0),H(k=>k.slice(0,V)+$+k.slice(V)),F(k=>k+$.length));return}if(_.type==="textarea"){if(I.return&&(I.ctrl||I.meta)){let k=P.join(`
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}on(k);return}if(I.return){Ce(true),j(k=>{let B=k[L]??"",q=B.slice(0,N),te=B.slice(N),le=[...k];return le.splice(L,1,q,te),le}),O(k=>k+1),E(0);return}if(I.ctrl&&$==="a"){E(0);return}if(I.ctrl&&$==="e"){E((P[L]??"").length);return}if(I.ctrl&&$==="k"){Ce(true),j(k=>{let B=[...k];return B[L]=(B[L]??"").slice(0,N),B});return}if(I.ctrl&&$==="u"){Ce(true),j(k=>{let B=[...k];return B[L]=(B[L]??"").slice(N),B}),E(0);return}if(I.ctrl&&$==="w"){Ce(true);let k=L,B=N;j(q=>{let te=q[k]??"",le=Do(te,B),de=[...q];return de[k]=te.slice(0,le)+te.slice(B),E(le),de});return}if(I.meta&&(I.leftArrow||$==="b")){E(Do(P[L]??"",N));return}if(I.meta&&(I.rightArrow||$==="f")){E(ei(P[L]??"",N));return}if(I.upArrow){if(Ke>0){let k=Re[Ke],B=Re[Ke-1],q=N-(k?.startCol??0),te=Math.min(B.startCol+q,B.startCol+B.text.length);O(B.logicalRow),E(te);}return}if(I.downArrow){if(Ke<Re.length-1){let k=Re[Ke],B=Re[Ke+1],q=N-(k?.startCol??0),te=Math.min(B.startCol+q,B.startCol+B.text.length);O(B.logicalRow),E(te);}return}if(I.leftArrow){N>0?E(k=>k-1):L>0&&(O(k=>k-1),E((P[L-1]??"").length));return}if(I.rightArrow){let k=(P[L]??"").length;N<k?E(B=>B+1):L<P.length-1&&(O(B=>B+1),E(0));return}if(I.backspace||I.delete){if(N===0&&L===0)return;if(N>0)j(k=>{let B=[...k],q=B[L]??"";return B[L]=q.slice(0,N-1)+q.slice(N),B}),E(k=>k-1);else {let k=(P[L-1]??"").length;j(B=>{let q=[...B],te=q[L-1]??"",le=q[L]??"";return q.splice(L-1,2,te+le),q}),E(k),O(B=>B-1);}return}if($&&!I.ctrl&&!I.meta&&!I.escape){Ce(true);let k=$.split(/\r?\n/);if(k.length===1)j(B=>{let q=[...B],te=q[L]??"";return q[L]=te.slice(0,N)+$+te.slice(N),q}),E(B=>B+$.length);else {let B=L,q=N;j(te=>{let le=[...te],de=le[B]??"",K=de.slice(0,q),Ae=de.slice(q),we=k[0]??"",Vn=k[k.length-1]??"",Tn=[K+we,...k.slice(1,-1),Vn+Ae];return le.splice(B,1,...Tn),le}),O(B+k.length-1),E((k[k.length-1]??"").length);}}return}if(_.type==="select"||_.type==="multiselect"){if(I.upArrow||$==="k"){z(k=>Math.max(0,k-1));return}if(I.downArrow||$==="j"){z(k=>Math.min(Rt.length-1,k+1));return}if(I.backspace||I.delete){rn();return}if(_.type==="select"){if(I.return||I.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}}on(k.value);}return}if($>="1"&&$<="9"){let k=parseInt($,10)-1;if(k<Rt.length){let B=Rt[k];B&&on(B.value);}return}}else {if($===" "){let k=Rt[Gt];k&&pt(B=>{let q=new Set(B);return q.has(k.value)?q.delete(k.value):q.add(k.value),q});return}if(I.return){let k=Array.from(ut).join(",");on(k);return}}}}}),!_)return null;let nt=nn?ht:null,At=Math.max(20,l-6),xn=`${y+1}/${ae}`,zn=Math.max(2,p-4),qt=0;Gt>=zn&&(qt=Gt-zn+1);let bn=Rt.slice(qt,qt+zn);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 ",xn]})]}),jsxs(Box,{children:[jsx(Text,{children:" "}),X.map(($,I)=>jsxs(Text,{color:I===y?e.amber:I<y?e.green:e.ghost,children:[I===y?"\u25CF":I<y?"\u2713":"\u25CB"," "]},$.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"?`${Br}+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:No}),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:No})]}):jsx(Text,{color:e.amber,children:No})]}),nt&&jsxs(Text,{color:e.red,dimColor:true,children:[" ",nt]}),Xt&&jsx(Text,{color:e.red,children:" Fix the error above"})]}),_.type==="text"&&_.suggestions&&Wt.length>0&&(()=>{let $=Math.max(2,p-6),I=0;De&&zt>=$&&(I=zt-$+1);let k=Wt.slice(I,I+$);return jsxs(Box,{flexDirection:"column",children:[jsxs(Text,{color:e.ghost,children:[" ",Ve,Ve,Ve," or browse templates ",Ve.repeat(Math.max(0,At-28))]}),k.map((B,q)=>{let te=q+I,le=De&&te===zt;return jsxs(Box,{children:[jsx(Text,{color:le?e.amber:e.ghost,children:le?" \u25B8 ":" "}),jsx(Text,{color:le?e.white:e.silver,bold:le,children:B.label}),B.hint&&jsxs(Text,{color:e.dim,wrap:"truncate",children:[" ",Ve," ",B.hint.replace(/\n/g," ")]})]},B.value)})]})})(),_.type==="textarea"&&(()=>{let $=Math.max(3,p-6),I=0;Ke>=$&&(I=Ke-$+1);let k=Re.slice(I,I+$);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,q)=>{let te=q+I,le=B.isFirst?String(B.logicalRow+1).padStart(Ft," "):"".padStart(Ft," "),de=te===Ke,K=N-B.startCol;return jsxs(Box,{children:[jsxs(Text,{color:e.dim,children:[" ",le," "]}),jsxs(Text,{color:e.ghost,children:["\u2502"," "]}),de?jsxs(Fragment,{children:[jsx(Text,{color:e.white,children:B.text.slice(0,K)}),jsx(Text,{color:e.amber,children:No}),jsx(Text,{color:e.white,children:B.text.slice(K)})]}):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]}),Xt&&jsx(Text,{color:e.red,children:" Fix the error above"})]})})(),_.type==="select"&&jsxs(Box,{flexDirection:"column",children:[bn.map(($,I)=>{let k=I+qt,B=k===Gt,q=String(k+1).padStart(Rt.length>=10?2:1);return jsxs(Box,{children:[jsx(Text,{color:B?e.amber:e.ghost,children:B?" \u25B8 ":` ${q} `}),jsx(Text,{color:B?e.white:e.silver,bold:B,children:$.label}),$.hint&&jsxs(Text,{color:e.dim,wrap:"truncate",children:[" ",Ve," ",$.hint.replace(/\n/g," ")]})]},$.value)}),nt&&jsxs(Text,{color:e.red,dimColor:true,children:[" ",nt]}),Xt&&jsx(Text,{color:e.red,children:" Fix the error above"})]}),_.type==="multiselect"&&jsxs(Box,{flexDirection:"column",children:[bn.map(($,I)=>{let B=I+qt===Gt,q=ut.has($.value);return jsxs(Box,{children:[jsx(Text,{color:B?e.amber:e.ghost,children:B?" \u25B8 ":" "}),jsx(Text,{color:q?e.green:e.dim,children:q?"[\u2713]":"[ ]"}),jsxs(Text,{color:B?e.white:e.silver,bold:B,children:[" ",$.label]}),$.hint&&jsxs(Text,{color:e.dim,wrap:"truncate",children:[" ",Ve," ",$.hint.replace(/\n/g," ")]})]},$.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 ${Br}+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",b&&(_.type==="text"||_.type==="textarea")?` ${Br}+V paste image`:""," Esc ",y>0?"back":"cancel"]}),T&&jsxs(Text,{color:e.amber,children:[" ",T]})]})]})}var ri=ao.memo(function({agents:n,selected:o,msgCounts:r,colorMap:l,maxHeight:p,onConfirm:b,onCancel:T}){let [x,y]=useState(0),[C,M]=useState(()=>new Set(o));useMemo(()=>C.size===0||C.size===n.length,[C.size,n.length]);let S=Math.max(3,p-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,x-P))},[x,n.length,S]),V=n.slice(H,H+S);useInput((P,j)=>{if(j.upArrow){y(L=>L>0?L-1:n.length-1);return}if(j.downArrow){y(L=>L<n.length-1?L+1:0);return}if(P===" "){let L=n[x];if(!L)return;M(O=>{let N=new Set(O);return N.has(L.id)?N.delete(L.id):N.add(L.id),N});return}if(P==="a"||P==="A"){M(L=>new Set);return}if(j.return){b(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:[fe," ",F,"/",n.length," selected"]})]}),jsx(Text,{color:e.ghost,children:Ve.repeat(36)}),V.map((P,j)=>{let O=j+H===x,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:O?e.amber:e.ghost,children:O?" \u25B8 ":" "}),jsx(Text,{color:N?e.green:e.ghost,children:N?"[\u2713]":"[ ]"}),jsxs(Text,{color:O?E:N?e.silver:e.dim,bold:O,children:[" ",P.name]}),W>0&&jsxs(Text,{color:e.dim,children:[" ",fe,W]})]},P.id)}),n.length>S&&jsxs(Text,{color:e.ghost,children:[" ",H>0?"\u2191":" "," ",H+S<n.length?"\u2193":" "," ",x+1,"/",n.length]}),jsx(Text,{color:e.ghost,children:Ve.repeat(36)}),jsxs(Text,{color:e.dim,children:[" Space toggle"," ",fe," ","a all"," ",fe," ","Enter confirm"," ",fe," ","Esc cancel"]})]})});var Zl={system:"\u2666",lifecycle:"\u25B6",output:"\u2502",tool:"\u2699",result:"\u2190",error:"\u2715",file:"\u270E",info:"\u2502"},Jl={system:"System",lifecycle:"Lifecycle",output:"Output",tool:"Tool calls",result:"Results",error:"Errors",file:"Files",info:"Info"},Ql={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"],ai=[{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"]}],li=ao.memo(function({selected:n,typeCounts:o,onConfirm:r,onCancel:l}){let[p,b]=useState(0),[T,x]=useState(()=>new Set(n)),y=useMemo(()=>T.size===wt.length||wt.every(M=>T.has(M)),[T]);useInput((M,A)=>{if(A.upArrow){b(S=>S>0?S-1:wt.length-1);return}if(A.downArrow){b(S=>S<wt.length-1?S+1:0);return}if(M===" "){let S=wt[p];if(!S)return;x(H=>{let V=new Set(H);return V.has(S)?V.delete(S):V.add(S),V});return}if(M==="a"||M==="A"){x(S=>S.size===wt.length?new Set:new Set(wt));return}for(let S of ai)if(M===S.key){x(new Set(S.types));return}if(A.return){let S=T.size===0?new Set(wt):new Set(T);r(S);return}if(A.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:[fe," ",C,"/",wt.length," selected"]})]}),jsx(Text,{color:e.ghost,children:Ve.repeat(36)}),wt.map((M,A)=>{let S=A===p,H=T.has(M),V=o[M]??0,F=Ql[M];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:[" ",Zl[M]," "]}),jsx(Text,{color:S?F:H?e.silver:e.dim,bold:S,children:Jl[M]}),V>0&&jsxs(Text,{color:e.dim,children:[" ",fe,V]})]},M)}),jsx(Text,{color:e.ghost,children:Ve.repeat(36)}),jsxs(Box,{gap:0,children:[jsx(Text,{color:e.dim,children:" "}),ai.map((M,A)=>jsxs(ao.Fragment,{children:[A>0&&jsxs(Text,{color:e.ghost,children:[" ",fe," "]}),jsx(Text,{color:e.amberDim,children:M.key}),jsxs(Text,{color:e.dim,children:["=",M.label]})]},M.key))]}),jsxs(Text,{color:e.dim,children:[" Space toggle"," ",fe," ","a all"," ",fe," ","Enter confirm"," ",fe," ","Esc cancel"]})]})});var Wo="\u256D",zo="\u256E",Vo="\u2570",Ho="\u256F",Ie="\u2502";function tn({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 Go({cw:t}){return jsx(tn,{cw:t,children:""})}function ci({width:t,height:n}){let o=Math.min(t-4,50),r=o-6,l=Te(o-2);return jsxs(Box,{flexDirection:"column",paddingX:2,marginTop:1,children:[jsxs(Text,{color:e.ghost,children:[Wo,l,zo]}),jsx(tn,{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(tn,{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(tn,{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(tn,{cw:r,children:""}),jsxs(Text,{color:e.ghost,children:[Vo,l,Ho]})]})}function di({step:t,width:n}){let o=Math.min(n-4,50),r=o-6,l=Te(o-2),p,b=null;if(t==="task_created")p="Press R to run task",b={key:"R",label:"run task"};else if(t==="run_started")p="Agent is running your task...";else return null;return jsxs(Box,{flexDirection:"column",paddingX:2,marginTop:1,children:[jsxs(Text,{color:e.ghost,children:[Wo,l,zo]}),jsxs(Text,{children:[jsxs(Text,{color:e.ghost,children:[Ie," "]}),jsx(Text,{color:e.amber,children:Ht}),jsxs(Text,{color:e.silver,children:[" ",p.padEnd(b?r-2-b.key.length-1-b.label.length-2:r-2)]}),b&&jsxs(Fragment,{children:[jsxs(Text,{color:e.amber,children:[" ",b.key]}),jsxs(Text,{color:e.gray,children:[" ",b.label]})]}),jsx(Text,{children:" "}),jsx(Text,{color:e.ghost,children:Ie})]}),jsxs(Text,{color:e.ghost,children:[Vo,l,Ho]})]})}function ui({width:t}){let n=Math.min(t-4,50),o=n-6,r=Te(n-2);return jsxs(Box,{flexDirection:"column",paddingX:2,marginTop:1,children:[jsxs(Text,{color:e.ghost,children:[Wo,r,zo]}),jsx(tn,{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(tn,{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(tn,{cw:o,children:""}),jsxs(Text,{color:e.ghost,children:[Vo,r,Ho]})]})}function jo({count:t,config:n,width:o}){if(t>=3)return null;let r=Math.min((o??44)-4,50),l=r-6,p=Te(r-2),b=jsxs(Text,{color:e.ghost,children:[Wo,p,zo]}),T=jsxs(Text,{color:e.ghost,children:[Vo,p,Ho]});if(t>0){let y=n.hints[0],C=y?` ${y.key} ${y.label}`:"";return jsxs(Box,{flexDirection:"column",paddingX:2,marginTop:1,children:[b,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 x=n.hints.reduce((y,C,M)=>y+C.key.length+1+C.label.length+(M>0?3:0),0);return jsxs(Box,{flexDirection:"column",paddingX:2,marginTop:1,children:[b,jsx(Go,{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(Go,{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(Go,{cw:l}),jsxs(Text,{children:[jsxs(Text,{color:e.ghost,children:[Ie," "]}),n.hints.map((y,C)=>jsxs(ao.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-x))}),jsx(Text,{children:" "}),jsx(Text,{color:e.ghost,children:Ie})]}),jsx(Go,{cw:l}),T]})}var tc=2,pi=360,nc={done:4e3,failed:8e3,review:6e3},oc={done:"\u2713",failed:"\u2715",review:Zt},rc={done:e.green,failed:e.red,review:e.blue},sc={done:e.successBg,failed:e.errorBg,review:e.infoBg};function ic(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 ac=ao.memo(function({toast:n,onDismiss:o}){let[r,l]=useState(true),[p,b]=useState(false);useEffect(()=>{let S=setTimeout(()=>l(false),pi);return ()=>clearTimeout(S)},[]),useEffect(()=>{let S=nc[n.type],H=setTimeout(()=>b(true),S),V=setTimeout(()=>o(n.id),S+pi);return ()=>{clearTimeout(H),clearTimeout(V);}},[n.id,n.type,o]);let T=r||p,x=oc[n.type],y=rc[n.type],C=sc[n.type],M=ic(n),A=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:[" ",x," "]}),jsx(Text,{color:T?e.dim:e.white,bold:!T,children:A}),jsxs(Text,{color:T?e.dim:e.silver,children:[" ",M," "]})]})})}),bi=ao.memo(function({toasts:n,onDismiss:o}){let r=n.slice(0,tc);return r.length===0?null:jsx(Box,{flexDirection:"column",children:r.map(l=>jsx(ac,{toast:l,onDismiss:o},l.id))})});var dc="\u256D",uc="\u256E",gc="\u2570",mc="\u256F",ct="\u2502",Pr=[{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"}],Nr=[{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"}],Dr=[{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"}],Fn=10,Ut=22;function Fr(t){let n=Math.max(0,Math.floor((Ut-t.length-2)/2)),o=Math.max(0,Ut-n-t.length-2);return Te(n)+" "+t+" "+Te(o)}var Ti=ao.memo(function({width:n,height:o}){let r=Ut*3+3+3+2,l=r+2,p=Te(l-2),b="KEYBOARD SHORTCUTS",T=Math.max(0,Math.floor((r-b.length)/2)),x=Math.max(0,r-T-b.length),y="Press any key to dismiss",C=Math.max(0,Math.floor((r-y.length)/2)),M=Math.max(0,r-C-y.length),A=Math.max(Pr.length,Nr.length,Dr.length),S=A+10,H=Math.max(0,Math.floor((o-S)/2)),V=[];for(let O=0;O<A;O++){let N=O<Pr.length?Pr[O]:null,E=O<Nr.length?Nr[O]:null,W=O<Dr.length?Dr[O]: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(Fn)}),jsx(Text,{color:e.silver,children:N.label.padEnd(Ut-Fn)})]}):jsx(Text,{children:" ".repeat(Ut)}),jsxs(Text,{color:e.dim,children:[" ",ct," "]}),E?jsxs(Fragment,{children:[jsx(Text,{color:e.amber,bold:true,children:E.key.padEnd(Fn)}),jsx(Text,{color:e.silver,children:E.label.padEnd(Ut-Fn)})]}):jsx(Text,{children:" ".repeat(Ut)}),jsxs(Text,{color:e.dim,children:[" ",ct," "]}),W?jsxs(Fragment,{children:[jsx(Text,{color:e.amber,bold:true,children:W.key.padEnd(Fn)}),jsx(Text,{color:e.silver,children:W.label.padEnd(Ut-Fn)})]}):jsx(Text,{children:" ".repeat(Ut)}),jsx(Text,{children:" "}),jsx(Text,{color:e.amber,children:ct})]},`r${O}`));}let F=O=>jsxs(Text,{children:[jsx(Text,{color:e.amber,children:ct}),jsx(Text,{children:" ".repeat(r)}),jsx(Text,{color:e.amber,children:ct})]},O),P=Fr("NAVIGATION"),j=Fr("ACTIONS"),L=Fr("COMMANDS");return jsxs(Box,{flexDirection:"column",paddingX:Math.max(0,Math.floor((n-l)/2)),marginTop:H,children:[jsxs(Text,{color:e.amber,children:[dc,p,uc]}),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:b}),jsx(Text,{children:" ".repeat(x)}),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:L}),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(M)}),jsx(Text,{color:e.amber,children:ct})]}),F("e5"),jsxs(Text,{color:e.amber,children:[gc,p,mc]})]})});var Si=[{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"}],ki=[{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"}],Ci=[{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"}],Ii=[{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"}],Mi=[{value:"",label:"Default",hint:"use shell adapter default"}],fc=[{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"}],vi=[{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"}],yi=60;function _i(t){return t.filter(n=>n.status!=="disabled").map(n=>{let o=(n.role??"").split(`
11
+ `)[0].trim(),r=o.length>yi?o.slice(0,yi-1)+"\u2026":o,l=r?`[${n.adapter}] ${r}`:n.adapter;return {value:n.id,label:n.name,hint:l}})}function qo(t,n="Auto-assign",o="orchestrator picks the best agent"){return [{value:"",label:n,hint:o},..._i(t)]}var Wr=[{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 Ri(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 Ai(){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 zr(t,n){return t.map(o=>{switch(o.id){case "name":return {...o,defaultValue:n.name};case "adapter":return {...o,defaultValue:n.adapter};case "model":return {...o,defaultValue:n.model};case "role":return {...o,defaultValue:"__custom__"};case "role_custom":return {...o,defaultValue:n.role,skip:void 0};case "skills":return {...o,defaultValue:n.skills.join(", ")};case "approval_policy":return {...o,defaultValue:n.approval_policy};default:return o}})}function Ko(t,n){let o=Ri(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:fc},{id:"model",label:"Model",type:"select",getOptions:r=>r.adapter==="opencode"?Ii:r.adapter==="codex"?ki:r.adapter==="cursor"?Ci:r.adapter==="shell"?Mi:Si},{id:"role",label:"Role / specialization",type:"select",options:Wr},{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 $i(t){let n=t.role==="__custom__"?t.role_custom||void 0:t.role||void 0,o=t.skills?t.skills.split(",").map(l=>l.trim()).filter(Boolean):void 0,r=t.approval_policy||"auto";return {name:t.name,adapter:t.adapter||"claude",role:n,model:t.model||void 0,approval_policy:r,skills:o,team_id:t.team||void 0}}function Bi(t,n){let o=_i(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 Ei(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 Li(t){let n=qo(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:vi,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 Oi(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 Pi(t,n){let o=qo(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:vi,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 Ni(t){return {title:t.title,priority:t.priority?parseInt(t.priority,10):void 0,assignee:t.assignee||void 0,description:t.description??""}}function Di(t,n,o){let r=Wr.find(x=>x.value===t.role),l=r?t.role:t.role?"__custom__":"",p=t.adapter==="opencode"?Ii:t.adapter==="codex"?ki:t.adapter==="cursor"?Ci:t.adapter==="shell"?Mi:Si,b=Ri(o),T=o?.find(x=>x.members.some(y=>y.agent_id===t.id))?.id;return [{id:"name",label:"Agent name",type:"text",defaultValue:t.name,required:true,validate:x=>x.trim()?n?.some(y=>y.id!==t.id&&y.name===x.trim())?"Agent with this name already exists":null:"Name is required"},{id:"model",label:"Model",type:"select",options:p,defaultValue:t.config.model??""},{id:"role",label:"Role / specialization",type:"select",options:Wr,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:x=>x.role!=="__custom__"},{id:"team",label:"Team",type:"select",options:b,defaultValue:T??"",skip:()=>b.length<=1}]}var pc=[{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"}],hc=[{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"}],wi=[{value:"true",label:"On"},{value:"false",label:"Off"}];function Fi(t,n,o){let r=o??{toast:true,bell:false};return [{id:"activity_filter",label:"Activity filter preset",type:"select",options:hc,defaultValue:t},{id:"max_concurrent",label:"Max concurrent agents",type:"select",options:pc,defaultValue:String(n)},{id:"notifications_toast",label:"Toast notifications",type:"select",options:wi,defaultValue:String(r.toast)},{id:"notifications_bell",label:"Bell on completion",type:"select",options:wi,defaultValue:String(r.bell)}]}function Gi(t){let n=t.role==="__custom__"?t.role_custom||void 0:t.role||void 0;return {name:t.name,role:n,model:t.model||void 0,team_id:t.team||void 0}}function Yo(t){let n=qo(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 Wi(t){return {title:t.title,assignee:t.assignee||void 0,description:t.description||void 0}}function zi(t,n){let o=qo(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 Vi(t){return {title:t.title,assignee:t.assignee||void 0,description:t.description??""}}var Hi=10,ji=500,tr=2048,hn=500,Ui=5,Vr=new Set(["todo","failed","cancelled"]),yc={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."},wc={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."},Sc={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."},Xi=5e3,Ki=0;function tg(){Ki=0;}var Yi=/^\[[\w_]+\]$/;function Zi(t){return Yi.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 jr=["#5faf87","#5fafd7","#af87ff","#d7af00","#5fd7d7","#d787af","#afaf5f","#d7875f"],kc=" ".repeat(9),nr={system:"\u2666",lifecycle:"\u25B6",output:"\u2502",tool:"\u2699",result:"\u2190",error:"\u2715",file:"\u270E",info:"\u2502"},Qo=["system","lifecycle","output","tool","result","error","file","info"],Gn=[{label:"all",types:Qo},{label:"text",types:["output"]},{label:"tools",types:["tool","result","file"]},{label:"errors",types:["error"]},{label:"events",types:["lifecycle","system"]}];function Hr(t){let o=(Gn.findIndex(r=>r.types.length===t.size&&r.types.every(l=>t.has(l)))+1)%Gn.length;return Gn[o]}function ng({projectName:t,tasks:n,agents:o=[],state:r,onRunTask:l,onCreateTask:p,onCancelTask:b$1,onRetryTask:T,onAssignTask:x,onRunAll:y,onDisableAgent:C,onEnableAgent:M,onSubscribeEvents:A,onRefreshTasks:S,onRefreshAgents:H,onRefreshState:V,onLoadHistory:F,onAddAgent:P,onDeleteAgent:j,onApproveTask:L,onRejectTask:O,onDeleteTask:N,onUpdateTask:E,onUpdateAgent:W,onForceStopAgent:z,onCreateTeam:X,onListTeams:_,onJoinTeam:ae,onLeaveTeam:Ee,onDisbandTeam:Ft,onSetTeamLead:dt,onStartWatch:Re,onStopWatch:Ke,onToggleAutonomous:ut,onRefreshGoals:pt,onCreateGoal:De,onUpdateGoal:Ye,onUpdateGoalStatus:gt,onDeleteGoal:Ze,onGetGoalProgress:nn,onCompleteOnboarding:Ce,initialWatchActive:ht,observerMode:xt,watchError:Xt,messageBatchMs:mt=process.env.VITEST?0:80,initialActivityFilter:kt="all",onSaveActivityFilter:Ue,initialMaxConcurrent:go=a.scheduling.max_concurrent_agents,onSaveMaxConcurrent:Wn,initialNotifications:Rt,onSaveNotifications:Gt,version:Wt,latestVersion:zt,onCheckUpdate:on,onBackgroundInstall:rn}){let{exit:nt}=useApp(),{stdout:At}=useStdout(),[xn,zn]=useState(zt),qt=useRef(on);useEffect(()=>{if(zt||!qt.current)return;let i=setTimeout(()=>{qt.current?.().then(f=>{f&&zn(f);}).catch(()=>{});},5e3);return ()=>clearTimeout(i)},[zt]);let[bn,$]=useState(false),I=useRef(false);useEffect(()=>{!xn||!rn||I.current||bn||(I.current=true,rn(xn).then(i=>{i&&$(true);}).catch(()=>{}));},[xn,rn,bn]);let[k,B]=useState({w:At?.columns??80,h:At?.rows??24});useEffect(()=>{if(!At)return;let i=()=>B({w:At.columns,h:At.rows});return At.on("resize",i),()=>{At.off("resize",i);}},[At]);let q=k.w,te=k.h,[le,de]=useState(n),[K,Ae]=useState(o),[we,Vn]=useState(r),[Tn,or]=useState(ht??!!r.pid),[Hn,Ur]=useState([]),[oa,Xr]=useState(void 0),[Kt,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(Kt!=="completed")return;let i=setTimeout(()=>{mo("dismissed"),Ce?.().catch(()=>{});},5e3);return ()=>clearTimeout(i)},[Kt,Ce]);let[R,yn]=useState("tasks"),[fo,jn]=useState(0),[rr,qr]=useState(0),[sr,Kr]=useState(0),[$e,Un]=useState(false),[ze,Yr]=useState([]),[Fe,Le]=useState("none"),[sn,Ct]=useState(""),[bt,Je]=useState(null),[an,Xn]=useState([]),[$t,ir]=useState(false),[Zr,ra]=useState(()=>new Set),[wn,ar]=useState(false),[qn,lr]=useState(false),[Jr,Qr]=useState(()=>new Set(Qo)),[Kn,cr]=useState(-1),[sa,Yn]=useState(0),[Sn,dr]=useState(()=>{let i=Gn.find(f=>f.label===kt);return new Set(i?.types??Qo)}),po=useMemo(()=>Gn.find(f=>f.types.length===Sn.size&&f.types.every(s=>Sn.has(s)))?.label??"all",[Sn]),ur=useMemo(()=>Sn.size>=Qo.length?ze:ze.filter(i=>Sn.has(i.msgType??"info")),[ze,Sn]),[es,ia]=useState(go),[ho,aa]=useState(Rt??{toast:true,bell:false}),[la,ts]=useState([]),ca=useRef(0),[gr,ns]=useState(),os=useRef(R);os.current=R;let rs=useRef(le);rs.current=le;let ss=useRef(K);ss.current=K;let xo=useRef(ho);xo.current=ho;let bo=useCallback((i,f)=>{if(!xo.current.toast)return;let s=rs.current.find(h=>h.id===f),d=s?.title??f,u=s?.assignee?ss.current.find(h=>h.id===s.assignee):void 0;ts(h=>{let g=[...h,{id:`toast_${ca.current++}`,type:i,title:d,agentName:u?.name,ts:Date.now()}];return g.length>Ui?g.slice(g.length-Ui):g}),xo.current.bell&&(i==="failed"||i==="review")&&process.stdout.write("\x07");},[]),da=useCallback(i=>{ts(f=>f.filter(s=>s.id!==i));},[]),To=ao.useRef(new Po).current,[ua,kn]=useState(0),[is,as]=useState(false),[Zn,ga]=useState(false),[ma,mr]=useState(0),[fa,fr]=useState(0),[pr,Cn]=useState(0),[yo,hr]=useState(false),[pa,Jn]=useState(0),[wo,Yt]=useState(0),[Vt,ls]=useState([]),[In,xr]=useState([]),Mn=useRef(Vt);Mn.current=Vt;let cs=useRef(0),Z=useCallback(async i=>{cs.current=Date.now();let[f,s,d,u,h]=await Promise.all([S?.()??Promise.resolve(le),H?.()??Promise.resolve(K),V?.()??Promise.resolve(we),i?.includeTeams?_?.()??Promise.resolve(Mn.current):Promise.resolve(null),pt?.()??Promise.resolve(Hn)]);de(f),Ae(s),Vn(d),u!==null&&ls(u),Ur(h),ht&&or(!!d.pid);},[S,H,V,_,pt,ht]),vn=useMemo(()=>{let i=new Map;for(let f of Hn)i.set(f.id,f);return i},[Hn]),Oe=useMemo(()=>{let i=[...le].sort((h,g)=>(ro[h.status]??9)-(ro[g.status]??9));if(!Zn)return i;let f=[],s=[],d=[],u=new Map;for(let h of i)h.goalId&&vn.has(h.goalId)?(u.has(h.goalId)||(d.push(h.goalId),u.set(h.goalId,[])),u.get(h.goalId).push(h)):s.push(h);for(let h of d)f.push(...u.get(h));return [...f,...s]},[le,Zn,vn]),Bt=is?Oe:Oe.slice(0,Hi),_n=Oe.length-Bt.length,U=Oe[fo],Qn=useMemo(()=>{let i=new Map;for(let f of le)i.set(f.id,f.title);return i},[le]),ln=useMemo(()=>{let i=new Map;for(let f of K)i.set(f.id,f.name);return i},[K]),ha=useMemo(()=>{let i=new Map;for(let f of le)if(f.goalId){let s=i.get(f.goalId);s||(s=[],i.set(f.goalId,s)),s.push(f);}return i},[le]),So=useMemo(()=>{let i=new Map;for(let f=0;f<K.length;f++)i.set(K[f].id,jr[f%jr.length]);return i},[K]),ds=useMemo(()=>{let i=new Map;for(let f of ze)f.agentId&&i.set(f.agentId,(i.get(f.agentId)??0)+1);return i},[ze]),xa=useMemo(()=>{let i={};for(let f of ze){let s=f.msgType??"info";i[s]=(i[s]??0)+1;}return i},[ze]),{agentTeamMap:Rn,activeTeamCount:eo,teamLeadSet:ba}=useMemo(()=>{let i=new Map,f=new Set,s=0;for(let d of Vt)if(d.status==="active"){s++,f.add(d.lead_agent_id);for(let u of d.members)i.set(u.agent_id,d.name);}return {agentTeamMap:i,activeTeamCount:s,teamLeadSet:f}},[Vt]),Ge=useMemo(()=>{let i=[...K];return i.sort((f,s)=>{let d=Rn.get(f.id),u=Rn.get(s.id);return d&&!u?-1:!d&&u?1:d&&u&&d!==u?d.localeCompare(u):(_r[f.status]??9)-(_r[s.status]??9)}),i},[K,Rn]),Q=Ge[rr],ft=useMemo(()=>[...Hn].sort((i,f)=>(c[i.status]??9)-(c[f.status]??9)),[Hn]),oe=ft[sr],Ta=useMemo(()=>oe?le.filter(i=>i.goalId===oe.id):[],[oe,le]),br=useRef(nn);br.current=nn,useEffect(()=>{if(!oe||!br.current){Xr(void 0);return}let i=false;return br.current(oe.id).then(f=>{i||Xr(f);}).catch(()=>{}),()=>{i=true;}},[oe?.id]);let cn=useRef(new Map),ko=useRef(new Map);useEffect(()=>{for(let[i,f]of Object.entries(we.running))cn.current.set(f.run_id,f.agent_id),ko.current.set(f.run_id,i);if(cn.current.size>ji){let i=cn.current.size-ji,f=0;for(let s of cn.current.keys()){if(f++>=i)break;cn.current.delete(s),ko.current.delete(s);}}},[we.running]);let dn=useRef([]),to=useRef(null),Tr=useCallback(()=>{if(to.current=null,dn.current.length===0)return;let i=dn.current;dn.current=[],Yr(f=>{if(i.length>=hn)return i.slice(-hn);let s=hn-i.length;return (f.length>s?f.slice(-s):f).concat(i)});},[]);useEffect(()=>()=>{to.current&&clearTimeout(to.current);},[]);let a=useCallback((i,f,s)=>{let d=new Date,u=d.toLocaleTimeString("en-US",{hour12:false,hour:"2-digit",minute:"2-digit",second:"2-digit"}),h=s?.detail&&s.detail.length>tr?s.detail.slice(0,tr)+"\u2026[truncated]":s?.detail;dn.current.push({text:i,color:f,time:u,ts:d.getTime(),...s,detail:h}),dn.current.length>hn&&(dn.current=dn.current.slice(-hn)),mt===0?Tr():to.current||(to.current=setTimeout(Tr,mt));},[Tr]);useEffect(()=>{xt?a("Observer mode: watching external orchestrator via disk polling.",e.amber):Xt&&a(`Watch mode failed: ${Xt}. Tasks will not auto-dispatch.`,e.red);},[]),useEffect(()=>{if(!xt)return;let i=3e3,f=setInterval(()=>{Date.now()-cs.current>=i&&Z().catch(()=>{});},i);return ()=>clearInterval(f)},[xt,Z]);let An=useCallback((i,f,s,d)=>{let u={key:++Ki,entityType:i,entityId:f,entityName:s,expiresAt:Date.now()+Xi,needsForceStop:d?.needsForceStop};xr(h=>[...h,u]),a(`\u2717 "${s}" will be deleted in ${Math.round(Xi/1e3)}s \u2014 press Z to undo`,e.yellow);},[a]),ya=useCallback(()=>{xr(i=>{if(i.length===0)return i;let f=i[i.length-1];return a(`\u21B6 Undo: "${f.entityName}" restored`,e.green),i.slice(0,-1)});},[a]),us=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),Z();}catch(f){a(`Failed to delete "${i.entityName}": ${f instanceof Error?f.message:String(f)}`,e.red);}},[N,j,Ze,z,a,Z]),gs=useRef(us);gs.current=us,useEffect(()=>{if(In.length===0)return;let i=setInterval(()=>{let f=Date.now(),s=[];xr(d=>{let u=d.filter(h=>h.expiresAt<=f?(s.push(h),false):true);return s.length>0?u:d});for(let d of s)gs.current(d);},1e3);return ()=>clearInterval(i)},[In.length>0]),useEffect(()=>{if(!F)return;let i=f=>{let s=new Date(f.timestamp).toLocaleTimeString("en-US",{hour12:false,hour:"2-digit",minute:"2-digit",second:"2-digit"}),d=typeof f.data=="string"?f.data:JSON.stringify(f.data),u,h=e.silver,g="output";if(f.type==="error")u=typeof f.data=="string"?f.data:JSON.stringify(f.data),u=u.slice(0,200),h=e.red,g="error";else if(f.type==="file_changed")u=String(f.data),h=e.purple,g="file";else if(f.type==="done")u="Completed",h=e.green,g="lifecycle";else if(f.type==="tool_call")u=`\u2699 ${f.data?.name??"tool"}()`,h=e.cyan,g="tool";else {let{summary:w}=na(d);if(!w)return null;u=w;let J=Zi(u);g=J.msgType,h=J.color;}return {text:u,color:h,time:s,ts:new Date(f.timestamp).getTime(),agentId:f.agentId,taskId:f.taskId,msgType:g}};F(f=>{if(f.length===0)return;let s=f.map(i).filter(d=>d!==null);Yr(d=>{let u=[...s,...d];return u.length>hn?u.slice(-hn):u});}).catch(f=>{process.stderr.write(`[TUI] onLoadHistory error: ${f instanceof Error?f.stack??f.message:String(f)}
12
+ `);});},[]),useEffect(()=>{_?.().then(ls).catch(()=>{}),pt?.().then(Ur).catch(()=>{});},[]);let Co=useCallback(()=>{Je({title:"NEW AGENT",steps:Ko(K,Mn.current),kind:"agent"}),Le("wizard");},[K]),ms=useCallback(()=>{Je({title:"AGENT SHOP",steps:Ai(),kind:"agent_shop"}),Le("wizard");},[]),Io=useCallback(()=>{Xn([]),Je({title:"NEW TASK",steps:Li(K),kind:"task"}),Le("wizard");},[K]),wa=useCallback(async()=>{try{let{detectClipboardType:i,getClipboardImage:f}=await import('./clipboard-service-WVON5ZN4.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 f();if(!d)return a("Failed to read clipboard image",e.red),"empty";let{mkdtemp:u,writeFile:h}=await import('fs/promises'),{tmpdir:g}=await import('os'),{join:w}=await import('path'),J=await u(w(g(),"orch-paste-")),Lt=w(J,`clipboard-${Date.now()}.${d.ext}`);return await h(Lt,d.data),Xn(un=>[...un,Lt]),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]),Sa=useCallback(i=>{Je({title:"EDIT TASK",steps:Pi(i,K),kind:"edit_task",targetId:i.id}),Le("wizard");},[K]),fs=useCallback(()=>{Je({title:"NEW TEAM",steps:Bi(K,Vt),kind:"team"}),Le("wizard");},[K]),ka=useCallback(i=>{Je({title:"EDIT AGENT",steps:Di(i,K,Vt),kind:"edit_agent",targetId:i.id}),Le("wizard");},[Vt]),ps=useCallback(()=>{Je({title:"SETTINGS",steps:Fi(po,es,ho),kind:"config"}),Le("wizard");},[po,es]),Ca=useCallback(i=>{Le("none");let f=bt?.kind,s=bt?.targetId;if(Je(null),f==="agent_shop"){let d=i.shop_template,u=d?b(d):void 0;if(u){let h=Ko(K,Mn.current),g=zr(h,u);Je({title:`NEW AGENT \u2014 ${u.name}`,steps:g,kind:"agent_from_shop"}),Le("wizard");}else a("No template selected",e.yellow);return}if((f==="agent"||f==="agent_from_shop")&&P){let d=$i(i);a(`Creating agent "${d.name}"...`,e.amber),P(d.name,d.adapter,{model:d.model,role:d.role,approval_policy:d.approval_policy,skills:d.skills}).then(u=>{a(`\u2713 Created agent "${u.name}" (${u.id}, ${u.adapter})`,e.green),d.team_id&&ae?ae(d.team_id,u.id).then(h=>{a(`\u2713 Joined team "${h.name}"`,e.green),Z({includeTeams:true});},h=>a(`Failed to join team: ${h instanceof Error?h.message:String(h)}`,e.red)):Z();},u=>a(`Failed: ${u instanceof Error?u.message:String(u)}`,e.red));}else if(f==="team"&&X){let d=Ei(i);a(`Creating team "${d.name}"...`,e.amber),X(d).then(u=>{a(`\u2713 Created team "${u.name}" (${u.id}, ${u.members.length} members)`,e.green),Z({includeTeams:true});},u=>a(`Failed: ${u instanceof Error?u.message:String(u)}`,e.red));}else if(f==="task"&&p){let d=Oi(i),u=an.length>0?[...an]:void 0;Xn([]),a(`Creating "${d.title}"...`,e.amber),p(d.title,{priority:d.priority,description:d.description,attachments:u}).then(h=>{a(`\u2713 Created "${h.title}" (${h.id})${u?` \u{1F4CE}${u.length}`:""}`,e.green),d.assignee&&x&&x(h.id,d.assignee).catch(()=>{}),Z();},h=>a(`Failed: ${h instanceof Error?h.message:String(h)}`,e.red));}else if(f==="edit_task"&&s&&E){let d=Ni(i),u=an.length>0?[...an]:void 0;Xn([]),a("Updating task...",e.amber),E(s,{...d,attachments:u}).then(h=>{a(`\u2713 Updated "${h.title}"${u?` \u{1F4CE}${u.length}`:""}`,e.green),d.assignee&&x&&x(s,d.assignee).catch(()=>{}),Z();},h=>a(`Failed: ${h instanceof Error?h.message:String(h)}`,e.red));}else if(f==="edit_agent"&&s&&W){let d=Gi(i),u=d.team_id??"",h=Vt.find(g=>g.members.some(w=>w.agent_id===s))?.id??"";a("Updating agent...",e.amber),W(s,{name:d.name,role:d.role,model:d.model}).then(g=>{a(`\u2713 Updated agent "${g.name}"`,e.green);let w=[];h&&h!==u&&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))),u&&u!==h&&ae&&w.push(ae(u,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(()=>Z({includeTeams:w.length>0}));},g=>a(`Failed: ${g instanceof Error?g.message:String(g)}`,e.red));}else if(f==="config"){if(i.activity_filter){let g=Gn.find(w=>w.label===i.activity_filter);g&&(dr(new Set(g.types)),Ue?.(g.label));}if(i.max_concurrent){let g=parseInt(i.max_concurrent,10);g>0&&(ia(g),Wn?.(g));}let d=i.notifications_toast==="true",u=i.notifications_bell==="true",h={toast:d,bell:u};aa(h),Gt?.(h),a("Settings saved",e.green);}else if(f==="goal"&&De){let d=Wi(i);a(`Creating goal "${d.title}"...`,e.amber),De(d).then(u=>{a(`\u2713 Created goal "${u.title}" (${u.id})`,e.green),Z();},u=>a(`Failed: ${u instanceof Error?u.message:String(u)}`,e.red));}else if(f==="edit_goal"&&s&&Ye){let d=Vi(i);a("Updating goal...",e.amber),Ye(s,d).then(u=>{a(`\u2713 Updated goal "${u.title}"`,e.green),Z();},u=>a(`Failed: ${u instanceof Error?u.message:String(u)}`,e.red));}},[bt,P,p,X,ae,Ee,x,E,W,ut,De,Ye,a,Z,Ue,Wn,ho,Gt,Vt,an]),Ia=useCallback(()=>{Le("none"),Je(null),Xn([]);},[]),Ma=useCallback(i=>{let f=b(i);if(!f)return;let s=Ko(K,Mn.current),d=zr(s,f);Je({title:`NEW AGENT \u2014 ${f.name}`,steps:d,kind:"agent_from_shop"}),Le("wizard");},[]);useEffect(()=>{if(!A)return;let i=null,f=()=>{i||(i=setTimeout(()=>{i=null,Z().catch(()=>{});},150));},s=A(d=>{if(d.type==="agent:started"&&(cn.current.set(d.runId,d.agentId),ko.current.set(d.runId,d.taskId)),zc(d,a,cn.current,ko.current),d.type==="task:created"?mo(u=>u==="welcome"?"task_created":u):d.type==="agent:started"?mo(u=>u==="task_created"?"run_started":u):d.type==="task:status_changed"&&d.to==="done"&&mo(u=>u==="run_started"?"completed":u),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&&os.current!=="tasks")){let u=d.to==="done"?e.green:d.to==="failed"?e.red:d.to==="review"?e.blue:void 0;u&&ns({tab:"tasks",color:u});}(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")&&f();});return ()=>{s(),i&&clearTimeout(i);}},[A,a,Z,bo]);let yr=xt?"observing":Tn?"watching":"idle",va=we.started_at?g(we.started_at):void 0,hs=we.stats.total_tokens.total,xs=useMemo(()=>{let i={running:0,retrying:0,review:0,todo:0,done:0,failed:0,cancelled:0};for(let f of le)f.status==="in_progress"?i.running++:f.status==="retrying"?i.retrying++:f.status==="review"?i.review++:f.status==="todo"?i.todo++:f.status==="done"?i.done++:f.status==="failed"?i.failed++:f.status==="cancelled"&&i.cancelled++;return {...i,teams:eo}},[le,eo]);xs.running;let _a=useMemo(()=>({input:we.stats.total_tokens.input??0,output:we.stats.total_tokens.output??0,reasoning:we.stats.total_tokens.reasoning??0,total:hs,cache_read:we.stats.total_tokens.cache_read??0,cache_write:we.stats.total_tokens.cache_write??0}),[we.stats.total_tokens,hs]),It=Math.max(4,te-9),Ra=Rn.size,Aa=K.length>Ra,$a=eo>0?eo+(Aa?1:0):0,Ba=useMemo(()=>{if(!Zn||vn.size===0)return 0;let i=0,f=new Set,s=false;for(let d of Bt)d.goalId&&vn.has(d.goalId)?f.has(d.goalId)||(f.add(d.goalId),i++):s=true;return s&&i++,i},[Zn,vn,Bt]),Ea=R==="goals"?ft.length+1:R==="tasks"?Bt.length+1+(_n>0?1:0)+Ba:R==="agents"?K.length+1+$a:0,La=Math.min(Ea+1,Math.ceil(It*.5)),Oa=R==="logs"?It:Math.max(2,Math.min(La,It-4)),Se,Et;if(R==="logs")Se=It,Et=0;else if(yo)Se=0,Et=Math.max(1,It);else {let i=Math.max(3,Math.min(Oa+pr,It-4));Se=i,Et=Math.max(1,It-i);}let ve=Math.max(10,q-2),Mt=useMemo(()=>Fe==="command"?Ys(sn):[],[Fe,sn]),$n=It-4-3;useEffect(()=>{pr>$n&&Cn($n),pr<-$n&&Cn(-$n);},[It]),useEffect(()=>{kn(i=>Math.min(i,Math.max(0,Bt.length-Se)));},[Bt.length,Se]),useEffect(()=>{mr(i=>Math.min(i,Math.max(0,Ge.length-Se)));},[Ge.length,Se]),useEffect(()=>{fr(i=>Math.min(i,Math.max(0,ft.length-Se)));},[ft.length,Se]);let Pa=useCallback(i=>{let s=i.trim().replace(/^\//,"").split(/\s+/),d=s[0]?.toLowerCase();if(!d)return;let u=h=>h instanceof Error?h.message:String(h);switch(d){case "cancel":{if(!U){a("No task selected",e.yellow);return}if(!b$1)return;a(`Cancelling "${U.title}"...`,e.amber),b$1(U.id).then(()=>{a(`\u2713 Cancelled "${U.title}"`,e.green),Z();},h=>a(`Failed: ${u(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),Z();},h=>a(`Failed: ${u(h)}`,e.red));return}case "assign":{if(!U){a("No task selected",e.yellow);return}if(!x||!s[1]){a("Usage: assign <agent>",e.yellow);return}a(`Assigning "${U.title}" to ${s[1]}...`,e.amber),x(U.id,s[1]).then(()=>{a(`\u2713 Assigned "${U.title}" to ${s[1]}`,e.green),Z();},h=>a(`Failed: ${u(h)}`,e.red));return}case "task":{let h=s[1]?.toLowerCase();if(h==="add"){let g=s.slice(2).join(" ");if(!g){Io();return}if(!p){a("Create not available",e.yellow);return}a(`Creating "${g}"...`,e.amber),p(g).then(w=>{a(`\u2713 Created "${w.title}" (${w.id})`,e.green),Z();},w=>a(`Failed: ${u(w)}`,e.red));}else if(h==="list"){let g=Oe.map(w=>` ${w.id} ${w.status.padEnd(11)} ${w.title}`);if(g.length===0)a("No tasks",e.dim);else for(let w of g)a(w,e.cyan);}else if(h==="show"){let g=s[2]?Oe.find(w=>w.id===s[2]):U;if(!g){a("No task selected or id given",e.yellow);return}a(`${g.id} ${g.status} P${g.priority} "${g.title}"`,e.cyan),g.assignee&&a(` agent: ${g.assignee}`,e.dim),g.description&&a(` ${g.description.slice(0,100)}`,e.dim);}else if(h==="cancel"){let g=s[2]?Oe.find(w=>w.id===s[2]):U;if(!g){a("No task selected or id given",e.yellow);return}if(!b$1)return;a(`Cancelling "${g.title}"...`,e.amber),b$1(g.id).then(()=>{a(`\u2713 Cancelled "${g.title}"`,e.green),Z();},w=>a(`Failed: ${u(w)}`,e.red));}else if(h==="retry"){let g=s[2]?Oe.find(w=>w.id===s[2]):U;if(!g){a("No task selected or id given",e.yellow);return}if(!T)return;a(`Retrying "${g.title}"...`,e.amber),T(g.id).then(()=>{a(`\u2713 Retried "${g.title}"`,e.green),Z();},w=>a(`Failed: ${u(w)}`,e.red));}else if(h==="assign"){let g=s[2]?Oe.find(Lt=>Lt.id===s[2]):void 0,w=g??U,J=g?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(!x)return;a(`Assigning "${w.title}" to ${J}...`,e.amber),x(w.id,J).then(()=>{a(`\u2713 Assigned "${w.title}" to ${J}`,e.green),Z();},Lt=>a(`Failed: ${u(Lt)}`,e.red));}else if(h==="approve"){let g=s[2]?Oe.find(w=>w.id===s[2]):U;if(!g){a("No task selected or id given",e.yellow);return}if(g.status!=="review"){a(`Cannot approve \u2014 status is ${g.status}`,e.yellow);return}if(!L)return;a(`Approving "${g.title}"...`,e.amber),L(g.id).then(()=>{a(`\u2713 Approved "${g.title}"`,e.green),Z();},w=>a(`Failed: ${u(w)}`,e.red));}else if(h==="reject"){let g=s[2]?Oe.find(J=>J.id===s[2]):U;if(!g){a("No task selected or id given",e.yellow);return}if(g.status!=="review"){a(`Cannot reject \u2014 status is ${g.status}`,e.yellow);return}if(!O)return;let w=s.slice(s[2]&&Oe.find(J=>J.id===s[2])?3:2).join(" ").trim()||void 0;a(`Rejecting "${g.title}"${w?" with feedback":""}...`,e.amber),O(g.id,w).then(()=>{a(`\u2713 Rejected "${g.title}" \u2192 todo`,e.green),Z();},J=>a(`Failed: ${u(J)}`,e.red));}else if(h==="delete"){let g=s[2]?Oe.find(w=>w.id===s[2]):U;if(!g){a("No task selected or id given",e.yellow);return}if(g.status==="in_progress"){a("Cannot delete \u2014 task is running",e.yellow);return}if(!N)return;An("task",g.id,g.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 g=s[2];if(!g){Co();return}if(!P){a("Agent creation not available",e.yellow);return}let w=s[3];a(`Creating agent "${g}"...`,e.amber),P(g,w).then(J=>{a(`\u2713 Created agent "${J.name}" (${J.id}, ${J.adapter})`,e.green),Z();},J=>a(`Failed: ${u(J)}`,e.red));}else if(h==="list"){let g=Ge.map(w=>` ${w.id} ${w.status.padEnd(8)} ${w.name} (${w.adapter})`);if(g.length===0)a("No agents",e.dim);else for(let w of g)a(w,e.cyan);}else if(h==="disable"){let g=s[2]?Ge.find(w=>w.id===s[2]||w.name===s[2]):Q;if(!g){a("No agent selected or id given",e.yellow);return}if(!C)return;a(`Disabling ${g.name}...`,e.amber),C(g.id).then(()=>{a(`\u2713 Disabled ${g.name}`,e.green),Z();},w=>a(`Failed: ${u(w)}`,e.red));}else if(h==="enable"){let g=s[2]?Ge.find(w=>w.id===s[2]||w.name===s[2]):Q;if(!g){a("No agent selected or id given",e.yellow);return}if(!M)return;a(`Enabling ${g.name}...`,e.amber),M(g.id).then(()=>{a(`\u2713 Enabled ${g.name}`,e.green),Z();},w=>a(`Failed: ${u(w)}`,e.red));}else if(h==="delete"||h==="remove"){let g=s[2]?Ge.find(w=>w.id===s[2]||w.name===s[2]):Q;if(!g){a("No agent selected or id given",e.yellow);return}if(g.status==="running"){a("Cannot delete \u2014 agent is running",e.yellow);return}if(!j){a("Agent deletion not available",e.yellow);return}An("agent",g.id,g.name);}else if(h==="autonomous"||h==="auto"){let g=s[2]?Ge.find(w=>w.id===s[2]||w.name===s[2]):Q;if(!g){a("No agent selected or id given",e.yellow);return}if(!ut){a("Autonomous toggle not available",e.yellow);return}g.autonomous?(a(`Disabling autonomous mode for "${g.name}"...`,e.amber),ut(g.id,false).then(()=>{a(`${gn} ${g.name} autonomous OFF`,e.cyan),Z();},w=>a(`Failed: ${u(w)}`,e.red))):(a(`Enabling autonomous mode for "${g.name}"...`,e.amber),ut(g.id,true).then(()=>{a(`${gn} ${g.name} autonomous ON`,e.cyan),Z();},w=>a(`Failed: ${u(w)}`,e.red)));}else h==="shop"?ms():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")fs();else if(h==="list"){let g=Mn.current;if(g.length===0)a("No teams",e.dim);else for(let w of g)a(` ${w.id} ${w.status.padEnd(8)} ${w.name} (${w.members.length} members)`,e.cyan);}else if(h==="join"){if(!ae){a("Join not available",e.yellow);return}let g=s[2],w=s[3]??Q?.id;if(!g||!w){a("Usage: /team join <teamId> [agentId]",e.yellow);return}a(`Joining team ${g}...`,e.amber),ae(g,w).then(J=>{a(`\u2713 Agent joined team "${J.name}"`,e.green),Z({includeTeams:true});},J=>a(`Failed: ${u(J)}`,e.red));}else if(h==="leave"){if(!Ee){a("Leave not available",e.yellow);return}let g=s[2],w=s[3]??Q?.id;if(!g||!w){a("Usage: /team leave <teamId> [agentId]",e.yellow);return}a(`Leaving team ${g}...`,e.amber),Ee(g,w).then(J=>{a(`\u2713 Agent left team "${J.name}"`,e.green),Z({includeTeams:true});},J=>a(`Failed: ${u(J)}`,e.red));}else if(h==="disband"){if(!Ft){a("Disband not available",e.yellow);return}let g=s[2];if(!g){a("Usage: /team disband <teamId>",e.yellow);return}a(`Disbanding team ${g}...`,e.amber),Ft(g).then(()=>{a("\u2713 Team disbanded",e.green),Z({includeTeams:true});},w=>a(`Failed: ${u(w)}`,e.red));}else if(h==="set-lead"){if(!dt){a("Set-lead not available",e.yellow);return}let g=s[2],w=s[3];if(!g||!w){a("Usage: /team set-lead <teamId> <agentId>",e.yellow);return}a(`Setting lead for team ${g}...`,e.amber),dt(g,w).then(J=>{a(`\u2713 New lead for team "${J.name}"`,e.green),Z({includeTeams:true});},J=>a(`Failed: ${u(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 g=s.slice(2).join(" ").trim();if(!g){let w=Yo(K);Je({title:"New Goal",steps:w,kind:"goal"}),Le("wizard");return}if(!De){a("Goal creation not available",e.yellow);return}a(`Creating goal "${g}"...`,e.amber),De({title:g}).then(w=>{a(`\u2713 Created goal "${w.title}" (${w.id})`,e.green),Z();},w=>a(`Failed: ${u(w)}`,e.red));}else if(h==="list"){let g=ft.map(w=>` ${w.id} ${w.status.padEnd(8)} ${w.title}`);if(g.length===0)a("No goals",e.dim);else for(let w of g)a(w,e.cyan);}else if(h==="show"){let g=s[2]?ft.find(w=>w.id===s[2]):oe;if(!g){a("No goal selected or id given",e.yellow);return}a(`${g.id} ${g.status} "${g.title}"`,e.cyan),g.description&&a(` ${g.description.slice(0,100)}`,e.dim);}else if(h==="status"){let g=s[2]?ft.find(un=>un.id===s[2]):void 0,w=g??oe;if(!w){a("No goal selected or id given",e.yellow);return}let J=s[g?3:2];if(!J||!a$1.includes(J)){a("Usage: /goal status [id] <active|paused|achieved|abandoned>",e.yellow);return}let Lt=J;if(!gt){a("Status update not available",e.yellow);return}a(`Updating goal status to ${Lt}...`,e.amber),gt(w.id,Lt).then(un=>{a(`\u2713 Goal "${un.title}" \u2192 ${Lt}`,e.green),Z();},un=>a(`Failed: ${u(un)}`,e.red));}else if(h==="delete"){let g=s[2]?ft.find(w=>w.id===s[2]):oe;if(!g){a("No goal selected or id given",e.yellow);return}if(!Ze){a("Goal deletion not available",e.yellow);return}An("goal",g.id,g.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 g=Oe.find(w=>w.id===h);if(g&&!Vr.has(g.status)){a(`Cannot run \u2014 status is ${g.status}`,e.yellow);return}a(`Running ${h}...`,e.amber),l(h).then(()=>{a(`\u2713 Dispatched ${h}`,e.green),Z();},w=>a(`Failed: ${u(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),Z();},h=>a(`Failed: ${u(h)}`,e.red));return}case "watch":{if(Tn){a("Watch mode already active",e.yellow);return}if(!Re){a("Watch not available",e.yellow);return}a("Starting watch mode...",e.amber),Re().then(()=>{or(true),a("\u2713 Watch mode started",e.green);},h=>a(`Failed: ${u(h)}`,e.red));return}case "pause":{if(!Tn){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(()=>{or(false),a("\u2713 Watch mode paused",e.green);},h=>a(`Failed: ${u(h)}`,e.red));return}case "config":{s[1]?.toLowerCase()==="activity-filter"?dr(g=>{let w=Hr(g);return Ue?.(w.label),a(`Activity filter: ${w.label}`,e.amber),new Set(w.types)}):ps();return}case "status":{let h=le.filter(g=>g.status==="in_progress").length;a(`${yr} ${h} running ${le.length} tasks ${Ge.length} agents`,e.cyan);return}case "help":{for(let[h,g]of Object.entries(fn)){let w=g.sub?" "+g.sub.join("|"):g.args?" "+g.args:"";a(` /${h}${w} \u2014 ${g.help}`,e.silver);}return}case "quit":{nt();return}case "disable":{if(!Q){a("No agent selected",e.yellow);return}if(!C)return;a(`Disabling ${Q.name}...`,e.amber),C(Q.id).then(()=>{a(`\u2713 Disabled ${Q.name}`,e.green),Z();},h=>a(`Failed: ${u(h)}`,e.red));return}case "enable":{if(!Q){a("No agent selected",e.yellow);return}if(!M)return;a(`Enabling ${Q.name}...`,e.amber),M(Q.id).then(()=>{a(`\u2713 Enabled ${Q.name}`,e.green),Z();},h=>a(`Failed: ${u(h)}`,e.red));return}default:a(`Unknown: ${d}. Type /help for commands`,e.yellow);}},[U,Q,Oe,Ge,le,yr,Tn,b$1,T,x,y,l,p,C,M,P,L,O,N,ae,Ee,Ft,dt,Re,Ke,a,nt,Z,Io,Co,fs,ps]);useInput((i,f)=>{if(!($t&&(ir(false),i==="?"||f.escape||i==="\x1BOP"))&&!wn){if((f.ctrl||f.meta)&&i==="s"&&Fe==="wizard"&&bt?.kind==="agent"){ms();return}if(Fe!=="none"){if(f.escape){Le("none"),Ct(""),To.reset();return}if(f.return){let s=sn.trim();if(!s)return;if(Fe==="new_task"){if(!p)return;Le("none"),Ct(""),a(`Creating "${s}"...`,e.amber),p(s).then(d=>{a(`\u2713 Created "${d.title}" (${d.id})`,e.green),Z();},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 u=Mt[wo],h=u.cmd.replace(/\s+\[.*\]$/,"");if((h.startsWith(s)||s==="/")&&(d=h),u.subs&&!h.includes(" ")){Ct(h+" "),Yt(0);return}}Le("none"),Ct(""),Yt(0),To.push(d),Pa(d);}return}if(f.tab&&Fe==="command"){if(Mt.length>0){let s=Mt[wo];if(s){let d=s.cmd.replace(/\s+\[.*\]$/,"");Ct(d+(s.subs?" ":"")),Yt(0);}}else {let s=Ar(sn);s&&Ct(d=>d+s);}return}if(f.upArrow&&Fe==="command"){if(Mt.length>0)Yt(s=>Math.max(0,s-1));else {let s=To.prev();s!==null&&Ct(s);}return}if(f.downArrow&&Fe==="command"){if(Mt.length>0)Yt(s=>Math.min(Mt.length-1,s+1));else {let s=To.next();Ct(s??"");}return}if(f.backspace||f.delete){Ct(s=>s.slice(0,-1)),Yt(0);return}i&&!f.ctrl&&!f.meta&&(Ct(s=>s+i),Yt(0));return}if(i.toLowerCase()==="q"){nt();return}if(f.escape){if($e){Un(false),Jn(0);return}if(R==="logs"&&Kn>=0){cr(-1),Yn(0);return}return}if((i==="+"||i==="=")&&R!=="logs"){yo?(hr(false),Cn(-Math.floor(It/2))):Cn(s=>Math.max(-$n,s-3));return}if(i==="-"&&R!=="logs"){yo?(hr(false),Cn(Math.floor(It/2))):Cn(s=>Math.min($n,s+3));return}if(i==="M"&&R!=="logs"){hr(s=>!s);return}if(i==="?"){ir(true);return}if(i==="\x1BOP"){ir(true);return}if(i==="/"&&!$e){Le("command"),Ct("/"),Yt(0);return}if((i==="a"||i==="A")&&R==="logs"&&!$e&&!wn&&!qn){ar(true);return}if(i==="f"&&R==="logs"&&!$e&&!wn&&!qn){lr(true);return}if(i==="F"&&R==="logs"&&!$e&&!wn&&!qn){Qr(s=>new Set(Hr(s).types));return}if((i==="z"||i==="Z")&&In.length>0){ya();return}if((i==="f"||i==="F")&&(R==="tasks"||R==="agents"||R==="goals")&&!$e){dr(s=>{let d=Hr(s);return Ue?.(d.label),new Set(d.types)});return}if((i==="n"||i==="N")&&R==="tasks"&&!$e&&p){Io();return}if((i==="n"||i==="N")&&R==="agents"&&!$e&&P){Co();return}if((i==="n"||i==="N")&&R==="goals"&&!$e&&De){let s=Yo(K);Je({title:"New Goal",steps:s,kind:"goal"}),Le("wizard");return}if((i==="e"||i==="E")&&R==="goals"&&oe&&Ye){let s=zi(oe,K);Je({title:`Edit Goal: ${oe.title}`,steps:s,kind:"edit_goal",targetId:oe.id}),Le("wizard");return}if((i==="d"||i==="D")&&R==="goals"&&oe&&Ze){An("goal",oe.id,oe.title);return}if((i==="c"||i==="C")&&R==="goals"&&oe&&gt){(oe.status==="active"||oe.status==="paused")&&(a(`Marking goal "${oe.title}" as achieved...`,e.amber),gt(oe.id,"achieved").then(()=>{a(`\u2713 Goal "${oe.title}" achieved`,e.green),Z();},s=>a(`Failed: ${s instanceof Error?s.message:String(s)}`,e.red)));return}if((i==="x"||i==="X")&&R==="goals"&&oe&&gt){(oe.status==="active"||oe.status==="paused")&&(a(`Abandoning goal "${oe.title}"...`,e.amber),gt(oe.id,"abandoned").then(()=>{a(`\u2713 Goal "${oe.title}" abandoned`,e.dim),Z();},s=>a(`Failed: ${s instanceof Error?s.message:String(s)}`,e.red)));return}if((i==="p"||i==="P")&&R==="goals"&&oe&&gt){let s=oe.status==="paused"?"active":"paused";(oe.status==="active"||oe.status==="paused")&&gt(oe.id,s).then(()=>{a(`Goal "${oe.title}" ${s}`,e.cyan),Z();},d=>a(`Failed: ${d instanceof Error?d.message:String(d)}`,e.red));return}if((i==="a"||i==="A")&&R==="tasks"&&U?.status==="review"&&L){a(`Approving "${U.title}"...`,e.amber),L(U.id).then(()=>{a(`\u2713 Approved "${U.title}"`,e.green),Z();},s=>a(`Failed: ${s instanceof Error?s.message:String(s)}`,e.red));return}if((i==="x"||i==="X")&&R==="tasks"&&U?.status==="review"&&O){a(`Rejecting "${U.title}"...`,e.amber),O(U.id).then(()=>{a(`\u2713 Rejected "${U.title}" \u2192 todo`,e.green),Z();},s=>a(`Failed: ${s instanceof Error?s.message:String(s)}`,e.red));return}if((i==="c"||i==="C")&&R==="tasks"&&U&&b$1){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),b$1(U.id).then(()=>{a(`\u2713 Cancelled "${U.title}"`,e.green),Z();},s=>a(`Failed: ${s instanceof Error?s.message:String(s)}`,e.red));return}if((i==="e"||i==="E")&&R==="tasks"&&U&&E){Sa(U);return}if((i==="e"||i==="E")&&R==="agents"&&Q&&W){ka(Q);return}if((i==="s"||i==="S")&&R==="tasks"){as(s=>!s),jn(0),kn(0);return}if((i==="g"||i==="G")&&R==="tasks"&&!$e){ga(s=>!s),jn(0),kn(0);return}if((i==="s"||i==="S")&&R==="agents"&&Q&&z){if(!Object.values(we.running).some(d=>d.agent_id===Q.id)&&Q.status!=="running"){a(`Agent "${Q.name}" is not running`,e.yellow);return}a(`Force-stopping agent "${Q.name}"...`,e.amber),z(Q.id).then(()=>{a(`\u2713 Stopped agent "${Q.name}"`,e.green),Z();},d=>a(`Failed: ${d instanceof Error?d.message:String(d)}`,e.red));return}if((i==="d"||i==="D")&&R==="tasks"&&U&&U.status!=="in_progress"&&N){An("task",U.id,U.title);return}if((i==="d"||i==="D")&&R==="agents"&&Q&&j){let s=Object.values(we.running).some(d=>d.agent_id===Q.id);if(s&&!z){a(`Cannot delete \u2014 agent "${Q.name}" is running. Press S to stop first.`,e.yellow);return}An("agent",Q.id,Q.name,{needsForceStop:s});return}if((i==="u"||i==="U")&&R==="agents"&&Q&&ut){let s=!Q.autonomous;a(`${s?"Enabling":"Disabling"} autonomous mode for "${Q.name}"...`,e.amber),ut(Q.id,s).then(()=>{a(`${gn} ${Q.name} autonomous ${s?"ON":"OFF"}`,e.cyan),Z();},d=>a(`Failed: ${d instanceof Error?d.message:String(d)}`,e.red));return}if(!$e){if(i==="g"||i==="G"){yn("goals");return}if(i==="t"||i==="T"){yn("tasks");return}if(i==="a"||i==="A"){yn("agents");return}if(i==="l"||i==="L"){yn("logs");return}}if(!$e){let s=Eo.map(u=>u.id),d=s.indexOf(R);if(f.tab||f.rightArrow){yn(s[(d+1)%s.length]);return}if(f.leftArrow){yn(s[(d+s.length-1)%s.length]);return}}if(f.return){let s=_n>0?Bt.length:-1;if(R==="tasks"&&fo===s){as(u=>!u),jn(0),kn(0);return}let d=Bt.length+(_n>0?1:0);if(R==="tasks"&&fo===d&&p){Io();return}if(R==="goals"&&sr===ft.length&&De){let u=Yo(K);Je({title:"New Goal",steps:u,kind:"goal"}),Le("wizard");return}if(R==="agents"&&rr===Ge.length&&P){Co();return}if(R==="goals"&&oe){Un(u=>!u),Jn(0);return}if(R==="tasks"&&U){Un(u=>!u);return}if(R==="agents"&&Q){Un(u=>!u);return}if(R==="logs"&&Kn>=0){Un(u=>!u);return}}if((i==="r"||i==="R")&&R==="tasks"&&U&&l){if(!Vr.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),Z();},s=>a(`Failed to run: ${s instanceof Error?s.message:String(s)}`,e.red));return}if(f.upArrow||i==="k"){if(R==="goals"&&$e){Jn(s=>Math.max(0,s-1));return}R==="goals"?Kr(s=>{let d=Math.max(0,s-1);return fr(u=>d<u?d:u),d}):R==="tasks"?jn(s=>{let d=Math.max(0,s-1);return kn(u=>d<u?d:u),d}):R==="agents"?qr(s=>{let d=Math.max(0,s-1);return mr(u=>d<u?d:u),d}):R==="logs"&&cr(s=>{if(s===-1){let u=ze.length-1;return Yn(Math.max(0,u-Se+2)),Math.max(0,u)}let d=Math.max(0,s-1);return Yn(u=>d<u?d:u),d});}if(f.downArrow||i==="j"){if(R==="goals"&&$e){Jn(s=>s+1);return}if(R==="goals"){let s=ft.length+(De?1:0)-1;Kr(d=>{let u=Math.min(Math.max(0,s),d+1);return fr(h=>u>=h+Se?u-Se+1:h),u});}else if(R==="tasks"){let s=Bt.length+(p?1:0)+(_n>0?1:0)-1;jn(d=>{let u=Math.min(Math.max(0,s),d+1);return kn(h=>u>=h+Se?u-Se+1:h),u});}else if(R==="agents"){let s=Ge.length+(P?1:0)-1;qr(d=>{let u=Math.min(Math.max(0,s),d+1);return mr(h=>u>=h+Se?u-Se+1:h),u});}else R==="logs"&&cr(s=>{if(s===-1)return -1;let d=ze.length-1;if(s>=d)return Yn(0),-1;let u=s+1;return Yn(h=>u>=h+Se-1?u-Se+2:h),u});}}});let ot=Fe!=="none",bs=Kn>=0?ze[Kn]:void 0,Mo=yo?"+/- exit max":"+/- resize \u2502 M max",Ts=!ot&&$e&&R==="tasks"&&U,ys=!ot&&$e&&R==="agents"&&Q,ws=!ot&&$e&&R==="goals"&&oe,Na=!ot&&$e&&R==="logs"&&bs,wr=U?.id,Da=useMemo(()=>wr?ze.filter(i=>i.taskId===wr):[],[ze,wr]),Fa=!ot&&R==="tasks"&&U&&Vr.has(U.status)&&!!l,Ga=!ot&&!$e&&(R==="goals"&&!!De||R==="tasks"&&!!p||R==="agents"&&!!P),Wa=!ot&&R==="tasks"&&U?.status==="review"&&!!L,za=!ot&&R==="tasks"&&U?.status==="review"&&!!O,Va=Q?Object.values(we.running).some(i=>i.agent_id===Q.id):false,Ha=!ot&&(R==="goals"&&oe&&!!Ze||R==="tasks"&&U&&U.status!=="in_progress"&&!!N||R==="agents"&&Q&&!!j),ja=!ot&&!$e&&(R==="goals"&&!!oe&&!!Ye||R==="tasks"&&!!U&&!!E||R==="agents"&&!!Q&&!!W),Ua=!ot&&R==="agents"&&Q&&(Va||Q.status==="running")&&!!z,Xa=!ot&&R==="agents"&&!!Q&&!!ut,qa=!ot&&R==="goals"&&!!oe&&(oe.status==="active"||oe.status==="paused")&&!!gt,Ka=!ot&&In.length>0,Ss=Fe==="command"&&Mt.length>0,ks=bt?.kind==="task"||bt?.kind==="edit_task";return jsxs(Box,{flexDirection:"column",width:q,height:te,children:[jsx(Ks,{projectName:t,activeView:R,mode:yr,stats:xs,tokens:_a,uptime:va,width:q,version:Wt,latestVersion:xn,updateInstalled:bn,taskBadge:_n>0?Oe.length:void 0,flashTab:gr?.tab,flashColor:gr?.color,onFlashComplete:gr?()=>ns(void 0):void 0}),jsx(Box,{height:1}),$t&&jsx(Ti,{width:q,height:te-7}),!$t&&Kt==="welcome"&&R==="tasks"&&jsx(ci,{width:q,height:te}),!$t&&R==="goals"&&jsx(Mc,{goals:ft,selectedIndex:sr,scrollOffset:fa,height:Se,width:ve,showAddRow:!!De,agentNameMap:ln,tasksByGoalMap:ha}),!$t&&Kt!=="welcome"&&R==="tasks"&&jsx(_c,{tasks:Bt,selectedIndex:fo,scrollOffset:ua,height:Se,width:ve,showAddRow:!!p,agentNameMap:ln,hiddenCount:_n,goalMap:vn,groupByGoal:Zn}),!$t&&R==="tasks"&&(Kt==="task_created"||Kt==="run_started")&&jsx(di,{step:Kt,width:q}),!$t&&R==="tasks"&&Kt==="completed"&&jsx(ui,{width:q}),!$t&&R==="agents"&&jsx(Rc,{agents:Ge,selectedIndex:rr,scrollOffset:ma,height:Se,width:ve,state:we,taskTitleMap:Qn,showAddRow:!!P,agentTeamMap:Rn,teamLeadSet:ba,activeTeamCount:eo}),!$t&&R==="logs"&&jsxs(Fragment,{children:[jsx($c,{messages:ze,height:wn||qn?Math.max(3,Se-16):Se,agents:Ge,logAgentFilter:Zr,logTypeFilter:Jr,selectedIndex:Kn,scrollOffset:sa,agentNameMap:ln,agentColorMap:So,agentMsgCounts:ds,taskTitleMap:Qn,width:ve}),wn&&jsx(Box,{paddingX:2,children:jsx(ri,{agents:Ge,selected:Zr,msgCounts:ds,colorMap:So,maxHeight:Math.min(Se-4,18),onConfirm:i=>{ra(i),ar(false);},onCancel:()=>ar(false)})}),qn&&jsx(Box,{paddingX:2,children:jsx(li,{selected:Jr,typeCounts:xa,onConfirm:i=>{Qr(i),lr(false);},onCancel:()=>lr(false)})})]}),jsx(Box,{height:1}),$t?null:Fe==="wizard"&&bt?jsx(ti,{title:bt.title,steps:bt.steps,onComplete:Ca,onCancel:Ia,width:ve,height:Et,onPasteImage:ks?wa:void 0,onSuggestionSelected:bt.kind==="agent"?Ma:void 0,footerExtra:an.length>0&&ks?`\u{1F4CE}${an.length}`:void 0},`${bt.kind}-${bt.title}`):Ss?jsxs(Fragment,{children:[jsx(Zo,{label:"COMMANDS",width:ve}),jsx(Ic,{suggestions:Mt,selectedIndex:wo,height:Math.min(Mt.length,Et),width:ve})]}):Fe==="new_task"?jsxs(Fragment,{children:[jsx(Fc,{mode:Fe,width:ve}),jsx(Gc,{mode:Fe,value:sn,width:ve})]}):Ts?jsxs(Fragment,{children:[jsx(Lc,{task:U,width:ve,resizeHint:Mo}),jsx(Hs,{task:U,height:Et,width:ve,taskLogs:Da,agentNameMap:ln,taskTitleMap:Qn})]}):ws?jsxs(Fragment,{children:[jsx(Zo,{label:`GOAL: ${oe.title}`,width:ve,suffixLen:Mo.length+2,suffix:jsxs(Text,{color:e.dim,children:[" ",Mo," "]})}),jsx(vc,{goal:oe,height:Et,width:ve,agentNameMap:ln,tasks:Ta,progressReport:oa,scrollOffset:pa,onClampScroll:Jn})]}):ys?jsxs(Fragment,{children:[jsx(Oc,{agent:Q,width:ve,resizeHint:Mo}),jsx(Pc,{agent:Q,height:Et,state:we,taskTitleMap:Qn,teamName:Rn.get(Q.id)})]}):Na?jsxs(Fragment,{children:[jsx(Zo,{label:"LOG",width:ve}),jsx(Ec,{message:bs,height:Et,width:ve,agents:Ge,agentNameMap:ln,agentColorMap:So,taskTitleMap:Qn})]}):ze.length>0&&R!=="logs"?jsxs(Fragment,{children:[(()=>{let i=` F:${po.toUpperCase()} \u2502 ${ur.length}/${ze.length}`;return jsx(Zo,{label:"ACTIVITY",width:ve,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"," ",ur.length,"/",ze.length]})]})})})(),jsx(Bc,{messages:ur,height:Math.max(1,Et-1),width:ve,agents:Ge,agentNameMap:ln,agentColorMap:So})]}):R==="goals"?jsx(jo,{count:ft.length,config:yc,width:ve}):R==="tasks"?jsx(jo,{count:Oe.length,config:wc,width:ve}):R==="agents"?jsx(jo,{count:Ge.length,config:Sc,width:ve}):null,jsx(Box,{flexGrow:1}),jsx(bi,{toasts:la,onDismiss:da}),In.length>0&&jsx(Cc,{deletions:In,width:q}),jsx(Zs,{mode:Fe==="command"?"command":"navigate",value:Fe==="command"?sn:"",completion:Fe==="command"?Ar(sn):null,activeView:R,canRun:!!Fa,canNew:!!Ga,canApprove:!!Wa,canReject:!!za,canCancel:R==="tasks"&&!!U&&U.status==="in_progress"&&!!b$1,canDelete:!!Ha,canUndo:!!Ka,canEdit:!!ja,canForceStop:!!Ua,canToggleAuto:!!Xa,autoActive:Q?.autonomous,canPause:!!qa,isPaused:oe?.status==="paused",canToggleShowAll:R==="tasks"&&Oe.length>Hi,showAllActive:is,hasDetail:!!(Ts||ys||ws),itemCount:R==="goals"?ft.length:R==="tasks"?Oe.length:R==="agents"?K.length:ze.length,itemLabel:R==="goals"?"goals":R==="tasks"?"tasks":R==="agents"?"agents":"events",width:q,hasSuggestions:Ss,onboardingCompleted:r.onboardingCompleted})]})}var Cc=ao.memo(function({deletions:n,width:o}){let[,r]=useState(0);useEffect(()=>{let p=setInterval(()=>r(b=>b+1),1e3);return ()=>clearInterval(p)},[]);let l=Date.now();return jsx(Box,{flexDirection:"column",width:o,children:n.map(p=>{let b=Math.max(0,Math.ceil((p.expiresAt-l)/1e3)),T=Math.max(0,o-4),x=p.entityType==="task"?"Task":p.entityType==="agent"?"Agent":"Goal",y=Math.max(10,T-x.length-30),C=p.entityName.length>y?p.entityName.slice(0,y-1)+"\u2026":p.entityName;return jsx(Box,{paddingX:2,children:jsxs(Text,{color:e.yellow,children:["\u2717 ",jsx(Text,{bold:true,children:x}),` "${C}" \u2014 `,jsxs(Text,{color:e.amber,bold:true,children:[b,"s"]}),jsx(Text,{color:e.dim,children:" \u2502 "}),jsx(Text,{color:e.gray,bold:true,children:"Z"}),jsx(Text,{color:e.dim,children:" undo"})]})},p.key)})})});function Ic({suggestions:t,selectedIndex:n,height:o,width:r}){let l=o,p=0;n>=l&&(p=n-l+1);let b=t.slice(p,p+l);return jsx(Box,{flexDirection:"column",paddingX:2,children:b.map((T,x)=>{let y=x+p,C=y===n,M=C?"\u25B6":" ",A=Math.min(20,Math.max(14,...t.map(P=>P.cmd.length+1))),S=T.cmd.padEnd(A),H=T.subs?` ${T.subs}`:"",V=Math.max(4,r-A-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:` ${M} `}),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 Mc({goals:t,selectedIndex:n,scrollOffset:o=0,height:r,width:l,showAddRow:p,agentNameMap:b,tasksByGoalMap:T}){let x=t.length,y=t.slice(o,o+r),C=p&&x>=o&&x<o+r;return jsxs(Box,{flexDirection:"column",height:r,children:[y.map((M,A)=>jsx(Box,{paddingX:2,children:jsx(Vs,{goal:M,selected:A+o===n,width:l-2,agentNameMap:b,tasksByGoal:T?.get(M.id)})},M.id)),C&&jsx(Box,{paddingX:2,children:jsxs(Text,{color:n===x?e.amber:e.ghost,children:[n===x?" \u25B8 ":" ",jsx(Text,{color:n===x?e.amber:e.dim,children:"+ add goal..."})]})},"__add__")]})}function vc({goal:t,height:n,width:o,agentNameMap:r,tasks:l,progressReport:p,scrollOffset:b=0,onClampScroll:T}){let y=ao.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 ae=0;ae<z.length;ae+=X)_.push(z.slice(ae,ae+X));return _},L=Mr(p)?.split(`
13
+ `).flatMap(z=>j(z,P))??[],O=Mr(t.description)?.split(`
14
+ `).flatMap(z=>j(z,P))??[],N=_s[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(O.length>0){W.push({key:"desc-gap",node:jsx(Text,{children:" "})});for(let z=0;z<O.length;z++)W.push({key:`desc-${z}`,node:jsxs(Text,{color:e.silver,wrap:"truncate",children:[" ",O[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(L.length>0){W.push({key:"prog-gap",node:jsx(Text,{children:" "})}),W.push({key:"prog-div",node:jsx(Nn,{label:"progress",width:o})});for(let z=0;z<L.length;z++)W.push({key:`prog-${z}`,node:jsxs(Text,{color:e.white,wrap:"truncate",children:[" ",L[z]]})});}if(V.length>0){W.push({key:"tasks-gap",node:jsx(Text,{children:" "})}),W.push({key:"tasks-div",node:jsx(Nn,{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,p,o,r]),C=Math.max(0,y.length-n),M=Math.min(b,C);ao.useEffect(()=>{T&&M!==b&&T(M);},[M,b,T]);let A=y.length>n&&M<C,S=A?n-1:n,H=y.slice(M,M+S);return jsxs(Box,{flexDirection:"column",height:n,paddingX:2,children:[H.map(V=>jsx(Box,{children:V.node},V.key)),A&&jsxs(Text,{color:e.ghost,children:[" ","\u2193"," ",y.length-M-S," more ","\u2014"," ","\u2191","\u2193"," to scroll"]})]})}function _c({tasks:t,selectedIndex:n,scrollOffset:o=0,height:r,width:l,showAddRow:p,agentNameMap:b,hiddenCount:T=0,goalMap:x,groupByGoal:y=false}){let C=T>0,M=C?t.length:-1,A=t.length+(C?1:0),S=t.slice(o,o+r),H=C&&M>=o&&M<o+r,V=p&&A>=o&&A<o+r,F=useMemo(()=>{if(!y||!x||x.size===0)return null;let N=new Map;for(let E of t)if(E.goalId&&x.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,x]),P=y&&x?t.filter(N=>!N.goalId||!x.has(N.goalId)).length:0,j=y&&x&&x.size>0&&F&&F.size>0,L=[],O=o>0?t[o-1]?.goalId??null:void 0;for(let N=0;N<S.length&&L.length<r;N++){let E=S[N],W=E.goalId&&x?.has(E.goalId)?E.goalId:null;if(j){if(W&&W!==O){let z=x.get(W),X=F.get(W)??{total:0,done:0};if(L.push(jsx(Ls,{goalTitle:z.title,taskCount:X.total,doneCount:X.done,width:l},`gh_${W}`)),L.length>=r)break}if(!W&&O!==null&&O!==void 0&&(L.push(jsx(Os,{taskCount:P,width:l},"__ungrouped__")),L.length>=r))break}O=W,L.push(jsx(Box,{paddingX:2,children:jsx(Bo,{task:E,selected:N+o===n,width:l-2,agentNameMap:b,goalMap:x})},E.id));}return H&&L.length<r&&L.push(jsx(Box,{paddingX:2,children:jsxs(Text,{color:n===M?e.amber:e.ghost,children:[n===M?" \u25B8 ":" ",jsxs(Text,{color:n===M?e.amber:e.dim,children:["\u25BC"," Show all (",T," more) \u2014 press ",jsx(Text,{bold:true,color:e.gray,children:"S"})]})]})},"__show_all__")),V&&L.length<r&&L.push(jsx(Box,{paddingX:2,children:jsxs(Text,{color:n===A?e.amber:e.ghost,children:[n===A?" \u25B8 ":" ",jsx(Text,{color:n===A?e.amber:e.dim,children:"+ add task..."})]})},"__add__")),jsx(Box,{flexDirection:"column",height:r,children:L})}function Rc({agents:t,selectedIndex:n,scrollOffset:o=0,height:r,width:l,state:p,taskTitleMap:b,showAddRow:T,agentTeamMap:x,teamLeadSet:y,activeTeamCount:C}){let M=new Map;for(let E of Object.values(p.running))M.set(E.agent_id,E);let A=new Map;if(C&&C>0)for(let E of t){let W=x?.get(E.id);W&&A.set(W,(A.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&&x){for(let E of t)if(y.has(E.id)){let W=x.get(E.id);W&&P.set(W,E.name);}}let j=0;for(let E of A.values())j+=E;let L=t.length-j,O=[],N=o>0?x?.get(t[o-1]?.id??""):void 0;for(let E=0;E<H.length&&O.length<r;E++){let W=H[E],z=x?.get(W.id);if(F&&z&&z!==N&&(O.push(jsx(Fs,{teamName:z,memberCount:A.get(z)??0,leadName:P.get(z),width:l},`ts-${z}`)),O.length>=r)||F&&!z&&N&&(O.push(jsx(Gs,{memberCount:L,width:l},"ts-unassigned")),O.length>=r))break;N=z,O.push(jsx(Box,{paddingX:2,children:jsx(Ds,{agent:W,selected:E+o===n,width:l-2,runningEntry:M.get(W.id),currentTaskTitle:W.current_task?b.get(W.current_task):void 0,teamName:z,isLead:y?.has(W.id)})},W.id));}return V&&O.length<r&&O.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:O})}function Ji(t=5e3){let[n,o]=useState(Date.now());return useEffect(()=>{let r=setInterval(()=>o(Date.now()),t);return ()=>clearInterval(r)},[t]),n}function Qi(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 Ac(t){if(t==="error")return e.errorBg}function ea(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 $c({messages:t,height:n,agents:o,logAgentFilter:r,logTypeFilter:l,selectedIndex:p,scrollOffset:b,agentNameMap:T,agentColorMap:x,agentMsgCounts:y,taskTitleMap:C,width:M}){let A=Ji(),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 ae=_.msgType??"info";X[ae]=(X[ae]??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=p===-1?S.slice(-P):S.slice(b,b+P),L=p===-1?-1:p-b,O=Math.min(10,Math.max(6,...o.map(X=>X.name.length))),N=11+O,E=X=>{if(X===0)return true;let _=j[X],ae=j[X-1];return _.agentId!==ae.agentId?true:_.agentId?_.ts-ae.ts>3e4:false},W=Math.max(4,Math.floor((M-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:M,children:[jsxs(Box,{gap:0,children:[p===-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(En,{color:e.green})}),jsx(Text,{backgroundColor:e.successBg,color:e.green,children:" LIVE "})]}):jsxs(Text,{backgroundColor:e.warnBg,color:e.amber,children:[" \u2191\u2193 ",p+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 _=x.get(X.id)??jr[0],ae=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:ae?_:e.ghost,bold:ae,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 ae=_===L,Ee=X.msgType??"info",Ft=nr[Ee]??"\u2502",dt=X.agentId?T.get(X.agentId)??X.agentId.slice(0,8):void 0,Re=X.agentId?x.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=ea(Ee,X.color),Ze=ae?e.infoBg:Ee==="error"?e.errorBg:void 0,nn=X.taskId?C.get(X.taskId):void 0,Ce=Qi(X.ts,A),ht=nn&&M>80?`#${nn.slice(0,20)}`:"",xt=ht?ht.length+3:0,Xt=Math.max(10,M-2-N-xt),mt=rt(X.text,Xt);return jsxs(Box,{backgroundColor:Ze,children:[jsx(Text,{color:Re??e.ghost,children:Ke&&De?"\u250C":Ye?"\u2502":" "}),jsx(Text,{color:ae?e.amber:void 0,children:ae?"\u25B8":" "}),jsx(Box,{width:5,children:jsx(Text,{color:Ce==="now"?e.green:ae?e.silver:e.ghost,children:Ce.padStart(4)})}),jsx(Box,{width:O+1,children:De?jsxs(Text,{color:Re,bold:true,children:[" ",dt.slice(0,O).padEnd(O)]}):Ye?jsxs(Text,{color:Re??e.ghost,children:[" ","\xB7".padEnd(O)]}):jsxs(Text,{color:e.ghost,children:[" "," ".padEnd(O)]})}),jsxs(Text,{color:Ee==="error"?e.red:Re??e.dim,children:[" ",Ft," "]}),jsx(Text,{color:ae?e.white:gt,bold:ae||Ee==="lifecycle",children:mt}),ht&&jsxs(Text,{color:e.ghost,children:[" ",jsx(Text,{color:e.dim,backgroundColor:e.void,children:` ${ht} `})]})]},_)})]})}function Bc({messages:t,height:n,width:o,agents:r,agentNameMap:l,agentColorMap:p}){let b=Ji(),T=t.slice(-n),x=Math.max(10,o-2-17),y=Math.max(0,n-T.length),C=0,M=[];for(let A=0;A<T.length;A++)A>0&&T[A].agentId!==T[A-1].agentId&&C++,M.push(C);return jsxs(Box,{flexDirection:"column",paddingX:1,children:[y>0&&jsx(Box,{height:y}),T.map((A,S)=>{let H=A.agentId?l.get(A.agentId)??A.agentId.slice(0,8):void 0,V=A.agentId?p.get(A.agentId):void 0,F=A.msgType??"info",P=nr[F]??"\u2502",j=ea(F,A.color),O=(S>0?T[S-1]:void 0)?.agentId===A.agentId&&!!A.agentId,N=(M[S]&1)===1,E=Ac(F)??(N?"#1a1a1a":void 0),W=Qi(A.ts,b),z=rt(A.text,x);return jsxs(Box,{backgroundColor:E,children:[jsx(Text,{color:V??e.ghost,children:!O&&H?"\u258D":O?"\u258F":" "}),jsx(Box,{width:5,children:jsx(Text,{color:O?e.ghost:W==="now"?e.green:e.dim,children:O?" ":W.padStart(4)})}),jsx(Box,{width:9,children:H&&!O?jsxs(Text,{color:V,bold:true,children:[" ",H.slice(0,8)]}):jsx(Text,{color:e.ghost,children:kc})}),jsxs(Text,{color:F==="error"?e.red:O?e.ghost:V??e.dim,children:[P," "]}),jsx(Text,{color:j,children:z})]},S)})]})}function Ec({message:t,height:n,width:o,agents:r,agentNameMap:l,agentColorMap:p,taskTitleMap:b}){let T=t.detail??t.text,x=t.msgType??"info",y=t.agentId?l.get(t.agentId)??t.agentId.slice(0,8):void 0,C=t.agentId?p.get(t.agentId):e.dim,M=t.taskId?b.get(t.taskId):void 0,A,S=false;try{let P=JSON.parse(T);A=JSON.stringify(P,null,2),S=!0;}catch{A=T;}let H=Math.max(4,o-6),V=Math.max(1,n-4),F=A.split(`
15
+ `).slice(0,V);return jsxs(Box,{flexDirection:"column",paddingX:1,children:[jsx(Box,{children:jsxs(Text,{color:e.ghost,children:["\u256D",Te(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:nr[x]?x==="error"?e.red:e.dim:e.dim,children:[nr[x]??"\u2502"," ",x]}),M&&jsxs(Fragment,{children:[jsx(Text,{color:e.ghost,children:" \u2502 "}),jsxs(Text,{color:e.dim,children:["#",M.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",Te(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",Te(H+2),"\u256F"]})})]})}function Zo({label:t,width:n,suffix:o,suffixLen:r=0}){let l=` ${t} `,p=3,b=p+l.length+2;if(!o){let y=Math.max(0,n-b);return jsxs(Box,{paddingX:1,children:[jsx(Text,{color:e.ghost,children:He(p)}),jsx(Text,{backgroundColor:"#1a1a22",color:e.dim,bold:true,children:l}),jsx(Text,{color:e.ghost,children:He(y)})]})}let T=2,x=Math.max(0,n-b-T-r);return jsxs(Box,{paddingX:1,children:[jsx(Text,{color:e.ghost,children:He(p)}),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(x)})]})}function Lc({task:t,width:n,resizeHint:o}){let r=" DETAIL ",l=o?` ${o} `:"",p=n-r.length-l.length-10,b=t.title.length>p?t.title.slice(0,p-3)+"...":t.title,T=Math.max(0,n-3-r.length-b.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:b}),jsxs(Text,{color:e.ghost,children:[" ",He(Math.max(0,T))]}),l?jsx(Text,{color:e.dim,children:l}):null]})}function Oc({agent:t,width:n,resizeHint:o}){let r=" AGENT ",l=o?` ${o} `:"",p=n-r.length-l.length-10,b=t.name.length>p?t.name.slice(0,p-3)+"...":t.name,T=Math.max(0,n-3-r.length-b.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:b}),jsxs(Text,{color:e.ghost,children:[" ",He(Math.max(0,T))]}),l?jsx(Text,{color:e.dim,children:l}):null]})}function Pc({agent:t,height:n,state:o,taskTitleMap:r,teamName:l}){let p=Nc[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,x=24;return jsxs(Box,{flexDirection:"column",paddingX:2,children:[jsxs(Box,{children:[jsxs(Box,{width:x,children:[jsx(Text,{color:e.dim,children:" status "}),jsx(Text,{color:p,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:x,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:x,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:x,children:[jsx(Text,{color:e.dim,children:" auto "}),jsxs(Text,{color:e.cyan,children:[gn," 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=m[y],M=!C||y==="unknown",A=t.last_error.timestamp,S=A?g(A)+" 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"}),M&&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(`
16
+ `).slice(0,Math.max(1,n-(t.last_error?10:4))).map((y,C)=>jsxs(Text,{color:e.silver,wrap:"truncate",children:[" ",rt(y,500)]},C)):jsx(Text,{color:e.dim,children:" No role description."})]})}var Nc={idle:e.dim,running:e.green,error:e.red,disabled:e.ghost},Dc="\u2588";function Fc({mode:t,width:n}){let r=` ${t==="command"?"COMMAND":"NEW TASK"} `,l=Math.max(0,n-3-r.length-2);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}),jsx(Text,{color:e.ghost,children:He(l)})]})}function Gc({mode:t,value:n,width:o}){let r=t==="command"?"/":"\u25B8",l=Math.max(10,o-8),p=n.length>l?n.slice(-l):n;return jsxs(Box,{paddingX:2,children:[jsxs(Text,{color:e.amber,children:[r," "]}),jsx(Text,{color:e.white,children:p}),jsx(Text,{color:e.amber,children:Dc})]})}function ta(t,n){if(!n||typeof n!="object")return "";let o=n;if(o.file_path&&typeof o.file_path=="string")return o.file_path.split("/").slice(-2).join("/");if(o.command&&typeof o.command=="string")return o.command.slice(0,60);if(o.pattern&&typeof o.pattern=="string")return `"${o.pattern.slice(0,40)}"`;if(o.glob&&typeof o.glob=="string")return o.glob.slice(0,40);let r=JSON.stringify(o);return r.length>80?r.slice(0,77)+"...":r}function Jo(t,n=200){if(typeof t=="string")return t.slice(0,n);if(!Array.isArray(t))return null;let o=[],r=0;for(let l of t){if(r>=n)break;if(l?.type==="text"&&typeof l.text=="string"){let p=l.text.split(`
17
+ `).find(b=>b.trim().length>0)??"";o.push(p.slice(0,n-r)),r+=p.length;}else if(l?.type==="tool_use"){let p=ta(l.name??"tool",l.input),b=`\u2699 ${l.name??"tool"}(${p})`;o.push(b),r+=b.length;}else if(l?.type==="tool_result")o.push("\u2190 (result)"),r+=10;else if(l?.type==="thinking"&&typeof l.thinking=="string"){let p=l.thinking.slice(0,60).split(`
18
+ `)[0]??"";o.push(`\u{1F4AD} ${p}`),r+=p.length+3;}}return o.length>0?o.join(" "):null}function qi(t){if(typeof t=="string"){let o=t.split(`
19
+ `).length,r=t.split(`
20
+ `).find(l=>l.trim().length>0)??"";return o>3?`${r.slice(0,80)}... (${o} lines)`:r.slice(0,120)}if(!Array.isArray(t))return "(result)";let n=[];for(let o of t)if(o?.type==="tool_result"){o.tool_use_id?o.tool_use_id.slice(0,8):"";let l=o.is_error,p=typeof o.content=="string"?o.content:"",b=p.split(`
21
+ `).length;l?n.push(`\u2715 error: ${p.slice(0,60)}`):b>3?n.push(`\u2713 ${b} lines`):n.push(`\u2713 ${p.slice(0,80)}`);}else o?.type==="text"&&typeof o.text=="string"&&n.push(o.text.split(`
22
+ `)[0]?.slice(0,80)??"");return n.join(" ")||"(result)"}function na(t){let n=()=>t.length>tr?t.slice(0,tr)+"\u2026":t;if(Yi.test(t.trim()))return {summary:t.trim(),detail:n()};try{let o=JSON.parse(t);if(o.type==="message"&&o.role==="assistant"){let r=Jo(o.content);return r?{summary:r.slice(0,200),detail:n()}:{summary:null,detail:""}}if(o.type==="assistant"||o.role==="assistant"){let r=o.message?.content??o.content,l=Jo(r);return l?{summary:l.slice(0,200),detail:n()}:{summary:null,detail:""}}if(o.type==="user"||o.role==="user"){let r=o.message?.content??o.content;return {summary:`\u2190 ${qi(r).slice(0,180)}`,detail:n()}}if(o.type==="tool_use"||typeof o.name=="string"&&"input"in o){let r=o.name??"tool",l=ta(r,o.input);return {summary:`\u2699 ${r}(${l})`,detail:n()}}if(o.type==="tool_result")return {summary:`\u2190 ${qi(o.content).slice(0,180)}`,detail:n()};if(o.type==="result"){let r=typeof o.result=="string"?o.result:null;return {summary:r?`\u2713 ${r.slice(0,180)}`:"\u2713 Agent finished",detail:n()}}if(o.type==="rate_limit_event")return {summary:`\u23F3 Rate limited (${o.rate_limit_info?.rateLimitType??"unknown"})`,detail:n()};if(o.subtype){if(o.message){let r=o.message.content??o.message,l=Jo(r);if(l)return {summary:l.slice(0,200),detail:n()}}return {summary:`[${o.subtype}]`,detail:n()}}if(o.content){let r=Jo(o.content);if(r)return {summary:r.slice(0,200),detail:n()}}return o.type?{summary:`[${o.type}]`,detail:n()}:{summary:t.slice(0,150),detail:n()}}catch{return {summary:Wc(t),detail:n()}}}function Wc(t){let n=t.match(/"subtype"\s*:\s*"([^"]+)"/);if(n)return `[${n[1]}]`;let o=t.match(/"type"\s*:\s*"([^"]+)"/),r=t.match(/"role"\s*:\s*"([^"]+)"/),l=o?.[1],p=r?.[1];if(!l&&!p)return t.slice(0,200);if(l==="assistant"||l==="message"||p==="assistant"){let b=t.match(/"text"\s*:\s*"((?:[^"\\]|\\.)*)"/);if(b)try{return JSON.parse(`"${b[1]}"`).slice(0,200)}catch{}return "\u{1F4AC} (assistant)"}if(l==="user"||l==="tool_result"||p==="user")return "\u2190 (tool result)";if(l==="tool_use")return `\u2699 ${t.match(/"name"\s*:\s*"([^"]+)"/)?.[1]??"tool"}()`;if(l==="result"){let b=t.match(/"result"\s*:\s*"((?:[^"\\]|\\.)*)"/);if(b)try{return `\u2713 ${JSON.parse(`"${b[1]}"`).slice(0,180)}`}catch{}return "\u2713 Agent finished"}return l==="rate_limit_event"?"\u23F3 Rate limited":`[${l??p}]`}function zc(t,n,o,r){let l=p=>r?.get(p);switch(t.type){case "agent:started":n("Started task",e.green,{agentId:t.agentId,taskId:t.taskId,msgType:"lifecycle"});break;case "agent:output":{let{summary:p,detail:b}=na(t.data);if(p){let T=Zi(p);n(p,T.color,{agentId:t.agentId,taskId:l(t.runId),detail:b,msgType:T.msgType});}break}case "agent:file_changed":n(`${t.path}`,e.purple,{agentId:t.agentId,taskId:l(t.runId),msgType:"file"});break;case "agent:completed":n(t.success?"Completed successfully":"Failed",t.success?e.green:e.red,{agentId:t.agentId,taskId:l(t.runId),msgType:"lifecycle"});break;case "agent:error":n(`${t.error.slice(0,150)}`,e.red,{agentId:t.agentId,taskId:l(t.runId),detail:t.error,msgType:"error"});break;case "task:status_changed":n(`${t.from} \u2192 ${t.to}`,e.cyan,{taskId:t.taskId,msgType:"system"});break;case "task:assigned":n(`Assigned \u2192 ${t.agentId}`,e.cyan,{taskId:t.taskId,msgType:"system"});break;case "task:created":n(`Created: ${t.task.title}`,e.amber,{taskId:t.task.id,msgType:"system"});break;case "run:retry":n(`Retry #${t.attempt} (${Math.round(t.delay_ms/1e3)}s delay)`,e.yellow,{agentId:o?.get(t.runId),taskId:l(t.runId),msgType:"lifecycle"});break;case "orchestrator:tick":(t.running>0||t.queued>0)&&n(`${t.running} running \xB7 ${t.queued} queued`,e.ghost,{msgType:"system"});break;case "orchestrator:stall_detected":n("Stall detected",e.yellow,{agentId:o?.get(t.runId),taskId:l(t.runId),msgType:"error"});break;case "task:cascade_failed":n(`Cascade failed (dep: ${t.failedDependencyId})`,e.red,{taskId:t.taskId,detail:t.reason,msgType:"error"});break}}export{ng as App,tg as _resetPendingDeletionSeq};
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env node
2
+ import i from'fs/promises';import {readFileSync,mkdirSync,writeFileSync}from'fs';import u from'path';import y from'os';import {execFile}from'child_process';var p="@oxgeneral/orch",o=u.join(y.homedir(),".orchestry"),s=u.join(o,"update-check.json"),c=14400*1e3,b=c*.75;function A(t,e){let r=t.split(".").map(Number),n=e.split(".").map(Number);for(let a=0;a<3;a++){let d=(r[a]??0)-(n[a]??0);if(d!==0)return d>0?1:-1}return 0}async function N(){try{let t=await i.readFile(s,"utf-8"),e=JSON.parse(t);if(Date.now()-e.checked_at<c)return e}catch{}return null}async function S(t){await i.mkdir(o,{recursive:true});let e={latest:t,checked_at:Date.now()},r=`${s}.tmp.${process.pid}`;await i.writeFile(r,JSON.stringify(e),"utf-8"),await i.rename(r,s);}function U(){return new Promise(t=>{execFile("npm",["view",p,"version","--json"],{timeout:5e3},(r,n)=>{if(r)return t(null);try{t(JSON.parse(n.trim()));}catch{t(null);}}).unref();})}function g(t,e){return {current:t,latest:e,updateAvailable:A(e,t)>0}}async function f(t){let e=await U();return e?(await S(e).catch(()=>{}),g(t,e)):null}async function P(t){try{let e=await N();return e?(Date.now()-e.checked_at>=b&&f(t).catch(()=>{}),g(t,e.latest)):f(t).catch(()=>null)}catch{return null}}function R(t){if(!t.updateAvailable)return;let e=`
3
+ Update available: ${t.current} \u2192 ${t.latest}
4
+ Run: npm install -g ${p}
5
+ `;process.stderr.write(e);}var l=u.join(o,"update-installed.json");function v(t){return new Promise(e=>{try{let n=JSON.parse(readFileSync(l,"utf-8"));if(n.version===t&&Date.now()-n.installed_at<c){e(!1);return}}catch{}execFile("npm",["install","-g",`${p}@${t}`],{timeout:6e4},n=>{n||(mkdirSync(o,{recursive:true}),writeFileSync(l,JSON.stringify({version:t,installed_at:Date.now()}))),e(!n);});})}function x(t){try{let e=JSON.parse(readFileSync(l,"utf-8"));return e.version!==t&&Date.now()-e.installed_at<c}catch{return false}}export{f as a,P as b,R as c,v as d,x as e};
package/dist/cli.js CHANGED
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- import {a as a$3,e}from'./chunk-3AXNSYCM.js';import {k as k$1}from'./chunk-ZMLF5HI5.js';import {a as a$1,b,i}from'./chunk-64WUDYEM.js';import {a as a$2,b as b$1}from'./chunk-IKNBPOQL.js';import R from'path';import {Command}from'commander';function d(o){let t=o.noColor||"NO_COLOR"in process.env||false,i=o.ascii||process.env.TERM==="dumb"||false;return {projectRoot:e(),json:o.json??false,quiet:o.quiet??false,noColor:t,ascii:i}}var l={task:async(o,t)=>{(await import('./task-HEPJYY7D.js')).registerTaskCommand(o,t);},agent:async(o,t)=>{(await import('./agent-SI4JF5MV.js')).registerAgentCommand(o,t);},status:async(o,t)=>{(await import('./status-NYHZ7Q5G.js')).registerStatusCommand(o,t);},logs:async(o,t)=>{(await import('./logs-4ISTWUWV.js')).registerLogsCommand(o,t);},config:async(o,t)=>{(await import('./config-OOB7QEKM.js')).registerConfigCommand(o,t);},context:async(o,t)=>{(await import('./context-FXRERFSP.js')).registerContextCommand(o,t);},msg:async(o,t)=>{(await import('./msg-4ELI7Q52.js')).registerMsgCommand(o,t);},goal:async(o,t)=>{(await import('./goal-RNNZYMNR.js')).registerGoalCommand(o,t);},team:async(o,t)=>{(await import('./team-VCJSUDWX.js')).registerTeamCommand(o,t);},org:async(o,t)=>{(await import('./org-KLYK6MMJ.js')).registerOrgCommand(o,t);}},c={run:async(o,t)=>{(await import('./run-PX7O3ILN.js')).registerRunCommand(o,t);},doctor:async(o,t)=>{(await import('./doctor-Q3GHJNZL.js')).registerDoctorCommand(o,t);},tui:async(o,t)=>{(await import('./tui-P6ZOPUMZ.js')).registerTuiCommand(o,t);},serve:async(o,t)=>{(await import('./serve-FTXAEZE4.js')).registerServeCommand(o,t);}},a=new Command;a.name("orchestry").description("Agents Organizations \u2014 CLI orchestrator for AI agents").version("1.0.10").option("--json","Output as JSON").option("--quiet","Minimal output (IDs only)").option("--no-color","Disable colors").option("--ascii","ASCII-only output (no Unicode)").hook("preAction",async o=>{let t=o.opts();t.ascii&&a$1(true),t.color===false&&b(true);});var x=[["task","Manage tasks"],["agent","Manage agents"],["status","Show orchestrator status"],["logs","View run logs"],["config","Manage configuration"],["context","Shared context store for inter-agent data exchange"],["msg","Inter-agent messaging"],["goal","Manage goals"],["team","Manage teams"],["org","Pre-built AI companies"],["run","Run tasks"],["doctor","Check adapters and dependencies"],["tui","Launch TUI dashboard"],["serve","Headless daemon mode with structured logs"],["init","Initialize project"],["update","Check for updates"]],I=new Set(x.map(([o])=>o));async function k(){a.parseOptions(process.argv);let o=a.opts(),t=process.argv.slice(2).find(e=>!e.startsWith("-")),i$1=t!==void 0&&I.has(t);if((process.argv.includes("--help")||process.argv.includes("-h")||process.argv.includes("--version")||process.argv.includes("-V"))&&!i$1){for(let[e,n]of x)a.command(e).description(n);await a.parseAsync(process.argv);return}if(t==="init"){let{registerInitCommand:e}=await import('./init-6OVZBN6B.js');e(a);}else if(t==="update"){let{registerUpdateCommand:e}=await import('./update-XGJZFV4H.js');e(a);}let g=process.argv.length<=2;if(g&&!await k$1(R.join(process.cwd(),a$3))){let{runInit:e}=await import('./init-6OVZBN6B.js');await e();let n=d({json:o.json,quiet:o.quiet,noColor:o.color===false,ascii:o.ascii}),{buildFullContainer:s}=await import('./container-NS3YS47A.js'),p=await s(n);await c.tui(a,p),await a.parseAsync([...process.argv,"tui"]);return}let u=d({json:o.json,quiet:o.quiet,noColor:o.color===false,ascii:o.ascii}),j=!t||t in c,{buildFullContainer:M,buildLightContainer:A}=await import('./container-NS3YS47A.js');try{if(j){let e=await M(u),n=t?c[t]:void 0;n?await n(a,e):await Promise.all(Object.values(c).map(p=>p(a,e)));let s=t?l[t]:void 0;s&&await s(a,e);}else {let e=await A(u),n=l[t];n?await n(a,e):await Promise.all(Object.values(l).map(s=>s(a,e)));}}catch(e){if(e instanceof b$1){if(t==="doctor"){let{registerDoctorCommand:n}=await import('./doctor-Q3GHJNZL.js');n(a);}if(t==="init"||t==="doctor"||t==="update"){await a.parseAsync(process.argv);return}i(e.message,e.hint),process.exit(e.exitCode);}throw e}g&&process.argv.push("tui");let m,f=t==="tui"||t==="update"||t==="serve",S=f?Promise.resolve(null):import('./update-check-CZJC7VW6.js').then(e=>(m=e,e.checkForUpdateSWR(a.version()??"0.0.0")));if(await a.parseAsync(process.argv),!f){let e=await S;e&&m&&m.printUpdateNotification(e);}}k().catch(o=>{o instanceof a$2&&(i(o.message,o.hint),process.exit(o.exitCode)),i(o instanceof Error?o.message:String(o)),process.env.ORCHESTRY_DEBUG&&console.error(o),process.exit(1);});
2
+ import {a as a$3,e}from'./chunk-3AXNSYCM.js';import {k as k$1}from'./chunk-ZMLF5HI5.js';import {a as a$1,b,i}from'./chunk-64WUDYEM.js';import {a as a$2,b as b$1}from'./chunk-IKNBPOQL.js';import R from'path';import {Command}from'commander';function l(o){let t=o.noColor||"NO_COLOR"in process.env||false,i=o.ascii||process.env.TERM==="dumb"||false;return {projectRoot:e(),json:o.json??false,quiet:o.quiet??false,noColor:t,ascii:i}}var d={task:async(o,t)=>{(await import('./task-HEPJYY7D.js')).registerTaskCommand(o,t);},agent:async(o,t)=>{(await import('./agent-SI4JF5MV.js')).registerAgentCommand(o,t);},status:async(o,t)=>{(await import('./status-NYHZ7Q5G.js')).registerStatusCommand(o,t);},logs:async(o,t)=>{(await import('./logs-4ISTWUWV.js')).registerLogsCommand(o,t);},config:async(o,t)=>{(await import('./config-OOB7QEKM.js')).registerConfigCommand(o,t);},context:async(o,t)=>{(await import('./context-FXRERFSP.js')).registerContextCommand(o,t);},msg:async(o,t)=>{(await import('./msg-4ELI7Q52.js')).registerMsgCommand(o,t);},goal:async(o,t)=>{(await import('./goal-RNNZYMNR.js')).registerGoalCommand(o,t);},team:async(o,t)=>{(await import('./team-VCJSUDWX.js')).registerTeamCommand(o,t);},org:async(o,t)=>{(await import('./org-KLYK6MMJ.js')).registerOrgCommand(o,t);}},m={run:async(o,t)=>{(await import('./run-PX7O3ILN.js')).registerRunCommand(o,t);},doctor:async(o,t)=>{(await import('./doctor-Q3GHJNZL.js')).registerDoctorCommand(o,t);},tui:async(o,t)=>{(await import('./tui-BQYRYGFA.js')).registerTuiCommand(o,t);},serve:async(o,t)=>{(await import('./serve-JOIPYKKG.js')).registerServeCommand(o,t);}},a=new Command;a.name("orchestry").description("Agents Organizations \u2014 CLI orchestrator for AI agents").version("1.0.13").option("--json","Output as JSON").option("--quiet","Minimal output (IDs only)").option("--no-color","Disable colors").option("--ascii","ASCII-only output (no Unicode)").hook("preAction",async o=>{let t=o.opts();t.ascii&&a$1(true),t.color===false&&b(true);});var x=[["task","Manage tasks"],["agent","Manage agents"],["status","Show orchestrator status"],["logs","View run logs"],["config","Manage configuration"],["context","Shared context store for inter-agent data exchange"],["msg","Inter-agent messaging"],["goal","Manage goals"],["team","Manage teams"],["org","Pre-built AI companies"],["run","Run tasks"],["doctor","Check adapters and dependencies"],["tui","Launch TUI dashboard"],["serve","Headless daemon mode with structured logs"],["init","Initialize project"],["update","Check for updates"]],L=new Set(x.map(([o])=>o));async function k(){a.parseOptions(process.argv);let o=a.opts(),t=process.argv.slice(2).find(e=>!e.startsWith("-")),i$1=t!==void 0&&L.has(t);if((process.argv.includes("--help")||process.argv.includes("-h")||process.argv.includes("--version")||process.argv.includes("-V"))&&!i$1){for(let[e,n]of x)a.command(e).description(n);await a.parseAsync(process.argv);return}if(t==="init"){let{registerInitCommand:e}=await import('./init-6OVZBN6B.js');e(a);}else if(t==="update"){let{registerUpdateCommand:e}=await import('./update-W54LAATS.js');e(a);}let g=process.argv.length<=2;if(g&&!await k$1(R.join(process.cwd(),a$3))){let{runInit:e}=await import('./init-6OVZBN6B.js');await e();let n=l({json:o.json,quiet:o.quiet,noColor:o.color===false,ascii:o.ascii}),{buildFullContainer:s}=await import('./container-NS3YS47A.js'),p=await s(n);await m.tui(a,p),await a.parseAsync([...process.argv,"tui"]);return}let u=l({json:o.json,quiet:o.quiet,noColor:o.color===false,ascii:o.ascii}),j=!t||t in m,{buildFullContainer:A,buildLightContainer:M}=await import('./container-NS3YS47A.js');try{if(j){let e=await A(u),n=t?m[t]:void 0;n?await n(a,e):await Promise.all(Object.values(m).map(p=>p(a,e)));let s=t?d[t]:void 0;s&&await s(a,e);}else {let e=await M(u),n=d[t];n?await n(a,e):await Promise.all(Object.values(d).map(s=>s(a,e)));}}catch(e){if(e instanceof b$1){if(t==="doctor"){let{registerDoctorCommand:n}=await import('./doctor-Q3GHJNZL.js');n(a);}if(t==="init"||t==="doctor"||t==="update"){await a.parseAsync(process.argv);return}i(e.message,e.hint),process.exit(e.exitCode);}throw e}g&&process.argv.push("tui");let r,f=t==="tui"||t==="update"||t==="serve",S=f?Promise.resolve(null):import('./update-check-R5ABF6HE.js').then(e=>(r=e,e.checkForUpdateSWR(a.version()??"0.0.0")));if(await a.parseAsync(process.argv),!f){let e=await S;e&&r&&(r.printUpdateNotification(e),e.updateAvailable&&r.backgroundInstall(e.latest).catch(()=>{}));}}k().catch(o=>{o instanceof a$2&&(i(o.message,o.hint),process.exit(o.exitCode)),i(o instanceof Error?o.message:String(o)),process.env.ORCHESTRY_DEBUG&&console.error(o),process.exit(1);});
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env node
2
+ import {d}from'./chunk-ZMLF5HI5.js';import {open}from'fs/promises';var y=5*6e4,m=512*1024,I=64*1024,f=class{constructor(t){this.opts=t;this.pollIntervalMs=t.pollIntervalMs??1e3;}pollIntervalMs;handler=null;intervalHandle=null;tracked=new Map;prevRunning=new Map;isPolling=false;subscribe(t){return this.handler=t,this.intervalHandle||(this.poll().catch(()=>{}),this.intervalHandle=setInterval(()=>{this.poll().catch(()=>{});},this.pollIntervalMs)),()=>{this.handler=null,this.stop();}}stop(){this.intervalHandle&&(clearInterval(this.intervalHandle),this.intervalHandle=null);}emit(t){try{this.handler?.(t);}catch{}}async poll(){if(!(!this.handler||this.isPolling)){this.isPolling=true;try{await this.doPoll();}finally{this.isPolling=false;}}}async doPoll(){let t;try{t=await this.opts.stateStore.read();}catch{return}let a=Date.now(),n=Object.values(t.running),s=new Set;for(let e of n){let r=e.run_id;s.add(r);let i=this.tracked.get(r);if(i){i.lastSeenAt=a;continue}this.tracked.set(r,{runId:r,agentId:e.agent_id,taskId:e.task_id,offset:0,remainder:"",lastSeenAt:a}),this.emit({type:"agent:started",agentId:e.agent_id,taskId:e.task_id,runId:r});}for(let[e,r]of this.prevRunning){if(s.has(e))continue;let i=this.tracked.get(e);i&&await this.tailRunEvents(i);let o=await d(this.opts.paths.runPath(e)).catch(()=>null),d$1=o?.status==="succeeded";this.emit({type:"agent:completed",runId:e,agentId:r.agent_id,success:d$1}),o?.task_id&&this.emit({type:"task:status_changed",taskId:o.task_id,from:"in_progress",to:d$1?"review":"failed"});}for(let e of this.tracked.values())s.has(e.runId)&&await this.tailRunEvents(e);s.size>0&&this.emit({type:"orchestrator:tick",running:s.size,queued:0});let l=new Map;for(let e of n)l.set(e.run_id,e);this.prevRunning=l;for(let[e]of this.tracked)!s.has(e)&&a-this.tracked.get(e).lastSeenAt>y&&this.tracked.delete(e);}async tailRunEvents(t){let a=this.opts.paths.runEventsPath(t.runId),n=null;try{n=await open(a,"r");let s=await n.stat();if(s.size<=t.offset)return;let l=Math.min(s.size-t.offset,m),e=Buffer.alloc(l),{bytesRead:r}=await n.read(e,0,l,t.offset);if(r===0)return;let i=t.remainder+e.subarray(0,r).toString("utf8"),o=i.split(`
3
+ `),d=o.pop()??"";if(i.endsWith(`
4
+ `))t.remainder="",t.offset+=r;else {t.remainder=d.length>I?"":d;let c=t.remainder?Buffer.byteLength(d,"utf8"):0;t.offset+=r-c;}for(let c of o){let u=c.trim();if(u)try{let g=JSON.parse(u),p=this.translateEvent(g,t);p&&this.emit(p);}catch{}}}catch{}finally{await n?.close().catch(()=>{});}}translateEvent(t,a){switch(t.type){case "agent_output":{let n=typeof t.data=="string"?t.data:JSON.stringify(t.data);return {type:"agent:output",runId:a.runId,agentId:a.agentId,data:n}}case "file_changed":{let n=typeof t.data=="string"?t.data:t.data?.path??"";return {type:"agent:file_changed",runId:a.runId,agentId:a.agentId,path:n}}case "error":{let n=typeof t.data=="string"?t.data:JSON.stringify(t.data);return {type:"agent:error",runId:a.runId,agentId:a.agentId,error:n}}case "tool_call":case "command_run":{let n=typeof t.data=="string"?t.data:JSON.stringify(t.data);return {type:"agent:output",runId:a.runId,agentId:a.agentId,data:n}}case "done":return null;default:return null}}};export{f as DiskObserver};
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ import {i}from'./chunk-64WUDYEM.js';import g from'fs';var p=6;function w(o,n){let t=o.version()??"0.0.0";o.command("serve").description("Headless daemon mode \u2014 structured logs to stdout").option("--once","Process todo tasks and exit when all are terminal").option("--tick-interval <ms>","Override polling interval (ms)").option("--log-file <path>","Also write logs to file (append mode)").option("--log-format <format>","Log format: json or text (default: json)","json").option("--verbose","Include high-frequency agent:output events").action(async s=>{await u(n,t,s);});}var f=new Set(["json","text"]);async function u(o,n,t){if(t.logFormat&&!f.has(t.logFormat)){i(`Unknown --log-format "${t.logFormat}". Valid: json, text`),process.exitCode=2;return}let s=t.logFormat==="text"?"text":"json",l=[process.stdout],i$1;if(t.logFile&&(i$1=g.createWriteStream(t.logFile,{flags:"a"}),i$1.on("error",e=>{process.stderr.write(`Log file error: ${e.message}
3
+ `);}),l.push(i$1)),t.tickInterval){let e=parseInt(t.tickInterval,10);!isNaN(e)&&e>0&&(o.config.scheduling.poll_interval_ms=e);}let{StructuredLogger:m}=await import('./structured-logger-RJ6VF35J.js'),a=new m({format:s,verbose:t.verbose??false,streams:l,idleLogInterval:p}),d=a.subscribe(o.eventBus);a.log("info","serve:started",{mode:t.once?"once":"watch",pid:process.pid,poll_interval_ms:o.config.scheduling.poll_interval_ms}),import('./update-check-R5ABF6HE.js').then(e=>e.checkForUpdateSWR(n)).catch(()=>null).then(e=>{e?.updateAvailable&&(a.log("warn","update:available",{current:e.current,latest:e.latest,hint:"Run: npm install -g @oxgeneral/orch"}),import('./update-check-R5ABF6HE.js').then(r=>r.backgroundInstall(e.latest)).then(r=>{r&&a.log("info","update:installed",{version:e.latest,hint:"Restart to apply"});}).catch(()=>{}));});try{if(t.once){let{runOnce:e}=await import('./once-runner-AMKCFW22.js'),r=await e(o.orchestrator,o.taskStore,o.eventBus);a.log("info","serve:finished",{result:r,exit_code:r==="has_failed"?1:0}),process.exitCode=r==="has_failed"?1:0;}else await o.orchestrator.startWatch(),await o.orchestrator.waitForStop();}finally{d(),await a.flush();}}export{w as registerServeCommand};
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ function ct(d,e){d.command("tui").description("Launch interactive TUI dashboard").action(async()=>{let w=await e.taskService.list(),f=await e.agentService.list(),h=await e.stateStore.read(),{render:k}=await import('ink'),{createElement:T}=await import('react'),{App:b}=await import('./App-HAYW3BCT.js'),A=async t=>{await e.orchestrator.runTask(t);},C=async(t,s)=>e.taskService.create({title:t,priority:s?.priority,description:s?.description,attachments:s?.attachments}),R=async t=>{await e.orchestrator.cancelTask(t);},_=async t=>{await e.taskService.retry(t);},E=async(t,s)=>{await e.taskService.assign(t,s);},j=async()=>{await e.orchestrator.runAll();},D=async t=>{await e.agentService.disable(t);},U=async t=>{await e.agentService.enable(t);},m=t=>e.eventBus.onAny(t),P=async()=>e.taskService.list(),G=async()=>e.agentService.list(),x=async()=>e.stateStore.read(),I=async(t,s,n)=>e.agentService.create({name:t,adapter:s??"claude",model:n?.model||void 0,role:n?.role||void 0,approval_policy:n?.approval_policy||void 0,skills:n?.skills||void 0}),L=async t=>{await e.agentService.remove(t);},F=async t=>{await e.taskService.delete(t);},H=async t=>{await e.taskService.updateStatus(t,"done");},O=async(t,s)=>{await e.taskService.reject(t,s);},W=async(t,s)=>e.taskService.update(t,s),N=async(t,s)=>e.agentService.update(t,{...s,approval_policy:s.approval_policy}),B=async t=>{await e.orchestrator.forceStopAgent(t);},M=async(t,s)=>e.agentService.setAutonomous(t,s),V=async t=>{let s=await e.runService.listAll();s.sort((a,i)=>new Date(i.started_at).getTime()-new Date(a.started_at).getTime());let n=s.filter(a=>a.status==="succeeded"||a.status==="failed"),u=3,ot=10,y=n.slice(0,u),v=n.slice(u,ot),S=async a=>(await e.runService.readEventsTail(a.id,30)).map(r=>({timestamp:r.timestamp,agentId:a.agent_id,taskId:a.task_id,type:r.type,data:r.data}));if(y.length>0){let a=(await Promise.all(y.map(S))).flat();a.sort((i,r)=>new Date(i.timestamp).getTime()-new Date(r.timestamp).getTime()),t(a.slice(-200));}if(v.length>0){let a=(await Promise.all(v.map(S))).flat();a.sort((i,r)=>new Date(i.timestamp).getTime()-new Date(r.timestamp).getTime()),t(a.slice(-200));}},J=async t=>e.teamService.create(t),K=async()=>e.teamService.list(),q=async(t,s)=>e.teamService.join(t,s),z=async(t,s)=>e.teamService.leave(t,s),Q=async t=>{await e.teamService.disband(t);},X=async(t,s)=>e.teamService.setLead(t,s),Y=async()=>e.goalService.list(),Z=async t=>e.goalService.create(t),$=async(t,s)=>e.goalService.update(t,s),tt=async(t,s)=>e.goalService.updateStatus(t,s),et=async t=>{await e.goalService.delete(t);},st=async t=>e.goalService.getProgressReport(t),at=async()=>{await e.orchestrator.startWatch();},nt=async()=>{await e.orchestrator.stop();},c=d.version()??"0.0.0",rt=import('./update-check-R5ABF6HE.js').then(t=>t.checkForUpdateSWR(c)).catch(()=>null),l=false,p,g=false,o;try{await e.orchestrator.startWatch(),l=!0;}catch(t){p=t instanceof Error?t.message:String(t);let{DiskObserver:s}=await import('./disk-observer-B3NOZ2QA.js');o=new s({paths:e.paths,stateStore:e.stateStore}),g=true,m=n=>o.subscribe(n);}let{waitUntilExit:it}=k(T(b,{projectName:e.config.project.name,tasks:w,agents:f,state:h,onRunTask:A,onCreateTask:C,onCancelTask:R,onRetryTask:_,onAssignTask:E,onRunAll:j,onDisableAgent:D,onEnableAgent:U,onSubscribeEvents:m,onRefreshTasks:P,onRefreshAgents:G,onRefreshState:x,onLoadHistory:V,onAddAgent:I,onDeleteAgent:L,onApproveTask:H,onRejectTask:O,onDeleteTask:F,onUpdateTask:W,onUpdateAgent:N,onForceStopAgent:B,onToggleAutonomous:M,onRefreshGoals:Y,onCreateGoal:Z,onUpdateGoal:$,onUpdateGoalStatus:tt,onDeleteGoal:et,onGetGoalProgress:st,onCreateTeam:J,onListTeams:K,onJoinTeam:q,onLeaveTeam:z,onDisbandTeam:Q,onSetTeamLead:X,onStartWatch:at,onStopWatch:nt,initialWatchActive:l,observerMode:g,watchError:g?void 0:p,version:c,latestVersion:void 0,onCheckUpdate:async()=>{let t=await rt;if(t?.updateAvailable)return t.latest;let n=await(await import('./update-check-R5ABF6HE.js')).checkForUpdateNow(c);return n?.updateAvailable?n.latest:void 0},onBackgroundInstall:async t=>(await import('./update-check-R5ABF6HE.js')).backgroundInstall(t),initialActivityFilter:e.globalConfig.tui.activity_filter,onSaveActivityFilter:async t=>{await e.globalConfigStore.set("activity_filter",t);},initialNotifications:e.globalConfig.tui.notifications,onSaveNotifications:async t=>{await e.globalConfigStore.set("notifications",t);},initialMaxConcurrent:e.config.scheduling.max_concurrent_agents,onSaveMaxConcurrent:async t=>{await e.configStore.set("scheduling.max_concurrent_agents",t),e.config.scheduling.max_concurrent_agents=t;},onCompleteOnboarding:async()=>{let t=await e.stateStore.read();t.onboardingCompleted=true,await e.stateStore.write(t);}}),{kittyKeyboard:{mode:"auto",flags:["disambiguateEscapeCodes"]}});await it(),l&&await e.orchestrator.stop().catch(()=>{}),o&&o.stop(),e.eventBus.clear();});}export{ct as registerTuiCommand};
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- import {a}from'./chunk-XLBV2PFL.js';import {p,q}from'./chunk-64WUDYEM.js';import {execFile}from'child_process';import e from'chalk';var c="@oxgeneral/orch";function u(){return new Promise(n=>{let t=execFile("npm",["install","-g",`${c}@latest`],{timeout:6e4},(s,o,a)=>{let d=(o??"")+(a??"");n({code:s?1:0,output:d});});t.stdout?.pipe(process.stdout),t.stderr?.pipe(process.stderr);})}function h(n){n.command("update").description("Check for updates and install the latest version").option("--check","Only check, do not install").action(async t=>{console.log(),console.log(` ${p("orch update")} \xB7 checking for updates\u2026`),console.log();let s=n.version()??"0.0.0",o=await a(s);if(o||(console.log(` ${e.ansi256(167)("\u2715")} Could not reach npm registry`),console.log(" Check your network connection and try again."),console.log(),process.exit(1)),!o.updateAvailable){console.log(` ${e.ansi256(72)("\u2713")} Already up to date ${q(`(${o.current})`)}`),console.log();return}if(console.log(` ${e.ansi256(214)("\u25CF")} Update available: ${q(o.current)} \u2192 ${e.ansi256(72)(o.latest)}`),console.log(),t.check){console.log(` Run ${q("orch update")} to install.`),console.log();return}console.log(` Installing ${c}@${o.latest}\u2026`),console.log(),(await u()).code!==0&&(console.log(),console.log(` ${e.ansi256(167)("\u2715")} Update failed. Try manually:`),console.log(` npm install -g ${c}@latest`),console.log(),process.exit(1)),console.log(),console.log(` ${e.ansi256(72)("\u2713")} Updated to ${o.latest}`),console.log();});}export{h as registerUpdateCommand};
2
+ import {a}from'./chunk-EGOR4O46.js';import {p,q}from'./chunk-64WUDYEM.js';import {execFile}from'child_process';import e from'chalk';var c="@oxgeneral/orch";function u(){return new Promise(n=>{let t=execFile("npm",["install","-g",`${c}@latest`],{timeout:6e4},(s,o,a)=>{let d=(o??"")+(a??"");n({code:s?1:0,output:d});});t.stdout?.pipe(process.stdout),t.stderr?.pipe(process.stderr);})}function h(n){n.command("update").description("Check for updates and install the latest version").option("--check","Only check, do not install").action(async t=>{console.log(),console.log(` ${p("orch update")} \xB7 checking for updates\u2026`),console.log();let s=n.version()??"0.0.0",o=await a(s);if(o||(console.log(` ${e.ansi256(167)("\u2715")} Could not reach npm registry`),console.log(" Check your network connection and try again."),console.log(),process.exit(1)),!o.updateAvailable){console.log(` ${e.ansi256(72)("\u2713")} Already up to date ${q(`(${o.current})`)}`),console.log();return}if(console.log(` ${e.ansi256(214)("\u25CF")} Update available: ${q(o.current)} \u2192 ${e.ansi256(72)(o.latest)}`),console.log(),t.check){console.log(` Run ${q("orch update")} to install.`),console.log();return}console.log(` Installing ${c}@${o.latest}\u2026`),console.log(),(await u()).code!==0&&(console.log(),console.log(` ${e.ansi256(167)("\u2715")} Update failed. Try manually:`),console.log(` npm install -g ${c}@latest`),console.log(),process.exit(1)),console.log(),console.log(` ${e.ansi256(72)("\u2713")} Updated to ${o.latest}`),console.log();});}export{h as registerUpdateCommand};
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export{d as backgroundInstall,a as checkForUpdateNow,b as checkForUpdateSWR,e as isRestartNeeded,c as printUpdateNotification}from'./chunk-EGOR4O46.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oxgeneral/orch",
3
- "version": "1.0.10",
3
+ "version": "1.0.13",
4
4
  "description": "AI agent runtime — orchestrate Claude, Cursor, Codex & OpenCode as one team. Multi-agent task automation with state machine, auto-retry, inter-agent messaging, goals and teams. Zero-config CLI + programmatic API.",
5
5
  "type": "module",
6
6
  "engines": {
@@ -1,22 +0,0 @@
1
- #!/usr/bin/env node
2
- import {b,a as a$2}from'./chunk-HWEMBO36.js';import {a}from'./chunk-N4OXN2HW.js';import {c,a as a$1}from'./chunk-HXOMNULD.js';import {f,h,g}from'./chunk-64WUDYEM.js';import {m}from'./chunk-IKNBPOQL.js';import nn,{useState,useMemo,useEffect,useRef,useCallback}from'react';import {Box,Text,useInput,useApp,useStdout}from'ink';import {jsxs,jsx,Fragment}from'react/jsx-runtime';var e={amber:"#ffaf00",amberDim:"#af8700",green:"#5faf87",red:"#d75f5f",blue:"#5fafd7",yellow:"#d7af00",cyan:"#5fd7d7",purple:"#af87ff",white:"#eeeeee",silver:"#bcbcbc",gray:"#808080",dim:"#585858",ghost:"#3a3a3a",void:"#262626",errorBg:"#3d1515",warnBg:"#3d2e0a",successBg:"#0f2d1f",infoBg:"#1a1a22",toolBg:"#0f1f2d"},vn="\u2501",Ge="\u2500",ue="\xB7",Zt="\u25C8",kr="\u2605",go="\u27F3",Ht="\u25C6",_n={in_progress:e.green,retrying:e.yellow,review:e.blue,todo:e.dim,done:e.green,failed:e.red,cancelled:e.dim},ws=new Map,Ss=new Map;function ze(t){if(t<=0)return "";let o=ws.get(t);return o||(o=vn.repeat(t),ws.set(t,o)),o}function be(t){if(t<=0)return "";let o=Ss.get(t);return o||(o=Ge.repeat(t),Ss.set(t,o)),o}function et(t,o){return t.length>o?t.slice(0,o-1)+"\u2026":t}var Va=1e4;function Cr(t,o=Va){if(t)return t.length>o?t.slice(0,o)+`
3
- \u2026[truncated]`:t}var ks={active:e.green,paused:e.dim,achieved:e.amber,abandoned:e.ghost};var Ua=120,Ir=0,Qo=null,Rn=new Set;function Xa(){Qo||(Qo=setInterval(()=>{Ir++;for(let t of Rn)t(Ir);},Ua));}function qa(){Qo&&Rn.size===0&&(clearInterval(Qo),Qo=null);}function mo(){let[t,o]=useState(Ir);return useEffect(()=>{let n=r=>o(r);return Rn.add(n),Xa(),()=>{Rn.delete(n),qa();}},[]),t}var Cs=["\u280B","\u2819","\u2839","\u2838","\u283C","\u2834","\u2826","\u2827","\u2807","\u280F"];function $o({color:t}){let o=mo();return jsx(Text,{color:t,children:Cs[o%Cs.length]})}var en={in_progress:0,retrying:1,review:2,todo:3,done:4,failed:5,cancelled:6};var Ja="\u25CB",Ms="\u2713",vs="\u2715",Qa="\u21BB",el="\u2500",tl="\u25B6",Nt={green:"#0f2d1f",blue:"#0f1f2d",yellow:"#2d2a0f",red:"#2d0f0f",neutral:"#1a1a22",amber:"#2d1f0a"},ol={in_progress:{icon:tl,label:"RUN",fg:e.green,bg:Nt.green,bold:true,spinner:true},retrying:{icon:Qa,label:"RETRY",fg:e.yellow,bg:Nt.yellow,spinner:true},review:{icon:Zt,label:"REVIEW",fg:e.blue,bg:Nt.blue},todo:{icon:Ja,label:"TODO",fg:e.dim,bg:Nt.neutral},done:{icon:Ms,label:"DONE",fg:e.green,bg:Nt.green},failed:{icon:vs,label:"FAIL",fg:e.red,bg:Nt.red,bold:true},cancelled:{icon:el,label:"OFF",fg:e.dim,bg:Nt.neutral}},nl={1:{color:e.red,label:"!!!"},2:{color:e.yellow,label:"!!"},3:{color:e.dim,label:"!"},4:{color:e.ghost,label:ue}};var sl=18,il="#2d1f0a",An=nn.memo(function({task:o,selected:n,width:r,agentNameMap:l,goalMap:f$1}){let b=ol[o.status],T=o.status==="in_progress"||o.status==="retrying",x=nl[o.priority]??{color:e.ghost,label:ue},y,I;if(o.status==="done")y=Ms,I=e.green;else if(o.status==="failed")y=vs,I=e.red;else if(T){let E=Date.now()-new Date(o.updated_at).getTime();y=f(E),I=e.cyan;}else y="\u2014",I=void 0;let v=n?"\u25B8":" ",B=o.goalId?f$1?.get(o.goalId):void 0,C=!!B,H=10,V=4,F=14,P=C?sl:0,j=7,L=2+H+V+F+P+j,O=r?Math.max(10,r-L):40,N=o.assignee?l?.get(o.assignee)??o.assignee:void 0;return jsxs(Box,{children:[jsxs(Text,{color:n?e.amber:void 0,children:[v," "]}),jsx(Box,{width:H,children:jsx(Text,{backgroundColor:b.bg,color:b.fg,bold:b.bold,children:b.spinner?jsxs(Fragment,{children:[" ",jsx($o,{color:b.fg})," ",b.label," "]}):jsxs(Fragment,{children:[" ",b.icon," ",b.label," "]})})}),jsx(Box,{width:V,children:jsx(Text,{color:x.color,bold:o.priority<=2,children:x.label})}),jsxs(Box,{width:O,children:[jsx(Text,{wrap:"truncate",bold:n||T,color:n?e.white:T?e.silver:void 0,children:o.title.length>O?o.title.slice(0,O-1)+"\u2026":o.title}),(o.attachments?.length??0)>0&&jsxs(Text,{color:e.dim,children:[" ","\u{1F4CE}",o.attachments.length]})]}),C&&jsx(Box,{width:P,children:jsxs(Text,{backgroundColor:il,color:e.amberDim,wrap:"truncate",children:[" \u2295 ",et(B.title,13)," "]})}),jsx(Box,{width:F,children:N?jsxs(Text,{backgroundColor:Nt.green,color:e.green,wrap:"truncate",children:[" ",N.length>F-2?N.slice(0,F-3)+"\u2026":N," "]}):jsx(Text,{color:e.ghost,children:"\u2014"})}),jsx(Box,{width:j,justifyContent:"flex-end",children:jsx(Text,{color:I,dimColor:!I,children:y})})]})});var _s="\u2295";function Rs({goalTitle:t,taskCount:o,doneCount:n,width:r}){let l=o>0?Math.round(n/o*100):0,f=` ${_s} ${t.toUpperCase()} ${ue} ${o} task${o!==1?"s":""} ${ue} ${l}% done `,b=3,T=Math.max(0,r-b-f.length-4);return jsxs(Box,{paddingX:2,children:[jsx(Text,{color:e.ghost,children:be(b)}),jsx(Text,{backgroundColor:Nt.amber,color:e.amber,bold:true,children:f}),jsx(Text,{color:e.ghost,children:be(T)})]})}function As({taskCount:t,width:o}){let n=` ${_s} UNGROUPED ${ue} ${t} task${t!==1?"s":""} `,r=3,l=Math.max(0,o-r-n.length-4);return jsxs(Box,{paddingX:2,children:[jsx(Text,{color:e.ghost,children:be(r)}),jsx(Text,{backgroundColor:Nt.neutral,color:e.dim,children:n}),jsx(Text,{color:e.ghost,children:be(l)})]})}var ll="\u2715",$s="\u25CB",cl="\u25B6",dl="\u2713",Bo={green:"#0f2d1f",red:"#2d0f0f",neutral:"#1a1a22",amber:"#2d1f0a"},ul={running:{icon:cl,label:"ACTIVE",fg:e.green,bg:Bo.green,bold:true,spinner:true},idle:{icon:$s,label:"IDLE",fg:e.dim,bg:Bo.neutral},error:{icon:ll,label:"ERROR",fg:e.red,bg:Bo.red,bold:true},disabled:{icon:$s,label:"OFF",fg:e.ghost,bg:Bo.neutral}},Mr={running:0,idle:1,error:2,disabled:3},Es=nn.memo(function({agent:o,selected:n,width:r,runningEntry:l,currentTaskTitle:f$1,teamName:b,isLead:T}){let x=ul[o.status],y=o.status==="running",I,v;if(y&&l){let N=Date.now()-new Date(l.started_at).getTime();I=f(N),v=e.cyan;}else o.stats.total_runs>0?(I=`${o.stats.tasks_completed}/${o.stats.total_runs}`,v=o.stats.tasks_completed>0?e.green:e.dim):(I="\u2014",v=void 0);let B=n?"\u25B8":" ",C=11,H=8,V=b?Math.min(b.length+2,12):0,F=10,P=2+C+H+V+F,j=r?Math.max(8,r-P):20,L=o.stats.total_runs>0,O=L?Math.round(o.stats.tasks_completed/o.stats.total_runs*100):0;return jsxs(Box,{children:[jsxs(Text,{color:n?e.amber:void 0,children:[B," "]}),jsx(Box,{width:C,children:jsx(Text,{backgroundColor:x.bg,color:x.fg,bold:x.bold,children:x.spinner?jsxs(Fragment,{children:[" ",jsx($o,{color:x.fg})," ",x.label," "]}):jsxs(Fragment,{children:[" ",x.icon," ",x.label," "]})})}),jsx(Box,{width:j,children:jsxs(Text,{wrap:"truncate",bold:n||y,color:n?e.white:y?e.green:e.silver,children:[o.autonomous&&jsxs(Text,{color:e.cyan,children:[go," "]}),T&&jsxs(Text,{color:e.amber,children:[kr," "]}),o.name,y&&f$1&&jsxs(Text,{color:e.dim,children:[" ",ue," ",f$1]}),o.status==="error"&&o.last_error&&jsxs(Text,{color:e.red,children:[" ",ue," ",et(m[o.last_error.kind]?.message??o.last_error.message,30)]})]})}),jsx(Box,{width:H,children:jsx(Text,{color:e.dim,children:o.adapter})}),b&&jsx(Box,{width:V,children:jsx(Text,{color:e.amber,wrap:"truncate",children:b})}),jsx(Box,{width:F,justifyContent:"flex-end",children:L&&!y?jsxs(Text,{color:O>=80?e.green:O>=50?e.yellow:e.red,children:[I," ",dl]}):jsx(Text,{color:v,dimColor:!v,children:I})})]})});function Ls({teamName:t,memberCount:o,leadName:n,width:r}){let l=`${o} agent${o!==1?"s":""}`,f=n?` ${ue} ${kr} ${n}`:"",b=` ${Zt} ${t.toUpperCase()} ${ue} ${l}${f} `,T=3,x=Math.max(0,r-T-b.length-4);return jsxs(Box,{paddingX:2,children:[jsx(Text,{color:e.ghost,children:be(T)}),jsx(Text,{backgroundColor:Bo.amber,color:e.amber,bold:true,children:b}),jsx(Text,{color:e.ghost,children:be(x)})]})}var gl="\u25C7";function Os({memberCount:t,width:o}){let n=`${t} agent${t!==1?"s":""}`,r=` ${gl} UNASSIGNED ${ue} ${n} `,l=3,f=Math.max(0,o-l-r.length-4);return jsxs(Box,{paddingX:2,children:[jsx(Text,{color:e.ghost,children:be(l)}),jsx(Text,{backgroundColor:Bo.neutral,color:e.dim,children:r}),jsx(Text,{color:e.ghost,children:be(f)})]})}var Ps="\u2713",Ns="\u2715",fl="\u2016",pl="\u25C9",on={green:"#0f2d1f",amber:"#2d1f0a",neutral:"#1a1a22"},hl={active:{icon:pl,label:"ACTIVE",fg:e.green,bg:on.green,bold:true},paused:{icon:fl,label:"PAUSED",fg:e.dim,bg:on.neutral},achieved:{icon:Ps,label:"DONE",fg:e.amber,bg:on.amber,bold:true},abandoned:{icon:Ns,label:"DROP",fg:e.ghost,bg:on.neutral}},xl="\u2588",bl="\u2591",Tl=14,Ds=nn.memo(function({goal:o,selected:n,width:r,agentNameMap:l,tasksByGoal:f}){let b=hl[o.status],T=n?"\u25B8":" ",x=f?.length??0,y=f?.filter(O=>O.status==="done").length??0,I=x>0,v=11,B=I?Tl:0,C=14,H=7,V=2+v+B+C+H,F=r?Math.max(10,r-V):40,P=o.assignee?l?.get(o.assignee)??o.assignee:void 0,j,L;if(o.status==="achieved")j=Ps,L=e.amber;else if(o.status==="abandoned")j=Ns,L=e.ghost;else {let O=Date.now()-new Date(o.created_at).getTime(),N=Math.floor(O/864e5);j=N>0?`${N}d`:"<1d",L=e.dim;}return jsxs(Box,{children:[jsxs(Text,{color:n?e.amber:void 0,children:[T," "]}),jsx(Box,{width:v,children:jsxs(Text,{backgroundColor:b.bg,color:b.fg,bold:b.bold,children:[" ",b.icon," ",b.label," "]})}),jsx(Box,{width:F,children:jsx(Text,{wrap:"truncate",bold:n||o.status==="active",color:n?e.white:o.status==="active"?e.silver:void 0,children:o.title.length>F?o.title.slice(0,F-1)+"\u2026":o.title})}),I&&(()=>{let N=x>0?Math.round(y/x*6):0,E=6-N;return jsxs(Box,{width:B,children:[jsx(Text,{color:e.green,children:xl.repeat(N)}),jsx(Text,{color:e.ghost,children:bl.repeat(E)}),jsx(Text,{color:e.dim,children:` ${y}/${x}`})]})})(),jsx(Box,{width:C,children:P?jsxs(Text,{backgroundColor:on.green,color:e.green,wrap:"truncate",children:[" ",P.length>C-2?P.slice(0,C-3)+"\u2026":P," "]}):jsx(Text,{color:e.ghost,children:"\u2014"})}),jsx(Box,{width:H,justifyContent:"flex-end",children:jsx(Text,{color:L,dimColor:!L,children:j})})]})});var yl={system:"\u2666",lifecycle:"\u25B6",output:"\u2502",tool:"\u2699",result:"\u2190",error:"\u2715",file:"\u270E",info:"\u2502"};function Oo({label:t,width:o,color:n}){let r=o-4,l=` ${t} `,f=3,b=Math.max(0,r-f-l.length);return jsxs(Text,{color:n??e.ghost,children:[" ",be(f),l,be(b)]})}function Fs({task:t,height:o,width:n,taskLogs:r,agentNameMap:l,taskTitleMap:f}){let b=_n[t.status]??e.dim,T=t.priority<=2?t.priority===1?e.red:e.yellow:void 0,x=24,y=!!t.description?.trim(),I=!!t.proof?.agent_summary,v=(t.proof?.files_changed?.length??0)>0,B=(r?.length??0)>0,C=(t.attachments?.length??0)>0,H=y?t.description.split(`
4
- `):[],V=I?t.proof.agent_summary.split(`
5
- `):[],F=3;C&&(F+=2+t.attachments.length),y?(F+=1,F+=Math.min(H.length,Math.max(1,Math.ceil((o-10)*.3)))):I||(F+=2),I&&(F+=2),v&&(F+=1),B&&(F+=2);let P=Math.max(0,o-F),j=0,L=0;I&&B?(j=Math.max(1,Math.floor(P*.4)),L=Math.max(1,P-j)):I?j=P:B&&(L=P);let O=y?H.slice(0,Math.max(1,Math.ceil((o-10)*.3))):[],N=V.slice(0,j);return jsxs(Box,{flexDirection:"column",paddingX:2,children:[jsxs(Box,{children:[jsxs(Box,{width:x,children:[jsx(Text,{color:e.dim,children:" status "}),jsx(Text,{color:b,children:t.status})]}),jsxs(Box,{children:[jsx(Text,{color:e.dim,children:" assignee "}),jsx(Text,{color:t.assignee?e.green:e.dim,children:t.assignee?l?.get(t.assignee)??t.assignee:"\u2014"})]})]}),jsxs(Box,{children:[jsxs(Box,{width:x,children:[jsx(Text,{color:e.dim,children:" priority "}),jsxs(Text,{color:T,bold:t.priority<=2,children:["P",t.priority]})]}),jsxs(Box,{children:[jsx(Text,{color:e.dim,children:" attempts "}),jsxs(Text,{children:[t.attempts,"/",t.max_attempts]})]})]}),jsxs(Box,{children:[jsxs(Box,{width:x,children:[jsx(Text,{color:e.dim,children:" labels "}),jsx(Text,{color:e.purple,children:t.labels.length>0?t.labels.join(", "):"\u2014"})]}),jsxs(Box,{children:[jsx(Text,{color:e.dim,children:" depends "}),jsx(Text,{dimColor:true,children:t.depends_on.length>0?t.depends_on.map(E=>f?.get(E)??E).join(", "):"\u2014"})]})]}),C&&jsxs(Fragment,{children:[jsx(Text,{children:" "}),jsx(Oo,{label:`attachments (${t.attachments.length})`,width:n,color:e.dim}),t.attachments.map((E,G)=>jsxs(Text,{color:e.cyan,wrap:"truncate",children:[" ",E]},`a${G}`))]}),y&&jsxs(Fragment,{children:[jsx(Text,{children:" "}),O.map((E,G)=>jsxs(Text,{color:e.silver,wrap:"truncate",children:[" ",et(E,n-8)]},`d${G}`))]}),!y&&!I&&jsxs(Fragment,{children:[jsx(Text,{children:" "}),jsx(Text,{color:e.dim,children:" No description."})]}),I&&jsxs(Fragment,{children:[jsx(Text,{children:" "}),jsx(Oo,{label:"result",width:n,color:e.dim}),N.map((E,G)=>jsxs(Text,{color:e.white,wrap:"truncate",children:[" ",et(E,n-8)]},`r${G}`))]}),v&&jsxs(Box,{children:[jsx(Text,{color:e.dim,children:" files "}),jsx(Text,{color:e.cyan,children:t.proof.files_changed.length}),jsx(Text,{color:e.dim,children:" changed"}),t.proof.branch&&jsxs(Fragment,{children:[jsxs(Text,{color:e.dim,children:[" ","\xB7"," "]}),jsx(Text,{color:e.cyan,children:t.proof.branch})]})]}),B&&jsxs(Fragment,{children:[jsx(Text,{children:" "}),jsx(Oo,{label:"activity",width:n,color:e.dim}),r.slice(-L).map((E,G)=>{let z=E.msgType??"info",X=yl[z]??"\u2502",R=E.color;z==="tool"?R=e.cyan:z==="file"?R=e.purple:z==="error"?R=e.red:z==="lifecycle"?R=e.green:z==="system"&&(R=e.dim);let ie=Math.max(10,n-12),Be=et(E.text,ie);return jsxs(Box,{children:[jsxs(Text,{color:e.ghost,children:[" ",E.time," "]}),jsxs(Text,{color:z==="error"?e.red:e.dim,children:[X," "]}),jsx(Text,{color:R,bold:z==="lifecycle",children:Be})]},G)})]})]})}var $n=[{key:"G",id:"goals",label:"GOALS"},{key:"T",id:"tasks",label:"TASKS"},{key:"A",id:"agents",label:"AGENTS"},{key:"L",id:"logs",label:"ACTIONS"}];var wl="\u25CF",Gs="\u25CB",Sl="\u2713",kl="\u2715",Cl="\u2191",Il="\u2193",Ml="\u03A3",vl="\u25B6",_l="\u21BB",Rl="\u{1F9E0}",Ws=["\u280B","\u2819","\u2839","\u2838","\u283C","\u2834","\u2826","\u2827","\u2807","\u280F"],vr=[" ","\u2581","\u2582","\u2583","\u2584","\u2585","\u2586","\u2587","\u2588"],ut={green:"#0f2d1f",blue:"#0f1f2d",yellow:"#2d2a0f",red:"#2d0f0f",neutral:"#1a1a22",amber:"#2d1f0a"};function zs({color:t}){let o=mo();return jsx(Text,{color:t,children:Ws[o%Ws.length]})}function Al(){let t=mo(),o=Math.floor(t/10)%2===0;return jsx(Text,{color:o?e.amber:e.amberDim,bold:true,children:Ht})}function $l({width:t,active:o}){let n=Math.max(4,Math.floor(t*.08)),r=2,l=mo(),f=Math.ceil((t+n)/r),b=o?l%(f*2):0;if(!o)return jsx(Box,{paddingX:1,children:jsx(Text,{color:e.ghost,children:ze(t)})});let T=b<f?b*r:(f*2-b)*r,x=Math.max(0,T-n),y=Math.min(t,T),I=x,v=Math.max(0,y-x),B=Math.max(0,t-y);return jsxs(Box,{paddingX:1,children:[jsx(Text,{color:e.ghost,children:ze(I)}),jsx(Text,{color:e.amber,children:ze(v)}),jsx(Text,{color:e.ghost,children:ze(B)})]})}function Bl({data:t,width:o,color:n}){if(t.length===0)return null;let r=t.slice(-o),l=Math.max(...r,1),f=r.map(b=>{let T=Math.round(b/l*(vr.length-1));return vr[T]??vr[0]}).join("");return jsx(Text,{color:n,children:f})}function El({tab:t,flashColor:o,onComplete:n,badge:r}){let l=mo(),f=nn.useRef(l),b=nn.useRef(false),T=l-f.current,x=2,y=6*x;return nn.useEffect(()=>{T>=y&&!b.current&&(b.current=true,n());},[T,n]),Math.floor(T/x)%2===0&&T<y?jsxs(Text,{backgroundColor:o,color:"#0a0a0c",bold:true,children:[" ",t.key," ",t.label,r," "]}):jsxs(Box,{gap:0,children:[jsx(Text,{color:e.ghost,children:t.key}),jsxs(Text,{color:e.dim,children:[" ",t.label.toLowerCase(),r]})]})}function Ll({projectName:t,activeView:o,mode:n,stats:r,uptime:l,width:f,version:b,latestVersion:T,taskBadge:x,flashTab:y,flashColor:I,onFlashComplete:v}){let B=n==="watching";return jsxs(Box,{paddingX:1,justifyContent:"space-between",width:f,children:[jsxs(Box,{gap:0,children:[jsx(Al,{}),jsx(Text,{color:e.amber,bold:true,children:" ORCH"}),b&&jsxs(Text,{color:e.ghost,children:[" ",b]}),T&&T!==b&&jsxs(Text,{backgroundColor:ut.green,color:e.green,bold:true,children:[" UPDATE ",T," "]}),jsxs(Text,{color:e.ghost,children:[" ",ue," "]}),jsx(Text,{color:e.silver,children:t})]}),jsx(Box,{gap:0,children:$n.map((C,H)=>{let V=o===C.id,F=C.id==="tasks"&&x!=null&&x>0?` (${x})`:"",P=!V&&y===C.id&&I&&v;return jsxs(nn.Fragment,{children:[H>0&&jsx(Text,{children:" "}),V?jsxs(Text,{backgroundColor:e.amber,color:"#0a0a0c",bold:true,children:[" ",C.key," ",C.label,F," "]}):P?jsx(El,{tab:C,flashColor:I,onComplete:v,badge:F}):jsxs(Box,{gap:0,children:[jsx(Text,{color:e.ghost,children:C.key}),jsxs(Text,{color:e.dim,children:[" ",C.label.toLowerCase(),F]})]})]},C.id)})}),jsxs(Box,{gap:0,children:[B?jsxs(Text,{backgroundColor:ut.green,color:e.green,bold:true,children:[" ",wl," WATCHING"," "]}):jsxs(Text,{backgroundColor:ut.neutral,color:e.dim,children:[" ",Gs," IDLE"," "]}),r.running>0&&jsxs(Fragment,{children:[jsx(Text,{children:" "}),jsxs(Text,{backgroundColor:ut.green,color:e.green,children:[" ",jsx(zs,{color:e.green})," ",r.running," active"," "]})]}),l&&jsxs(Text,{color:e.ghost,children:[" ",l]})]})]})}function Ol({stats:t,tokens:o,width:n,sparklineData:r}){let f=[{icon:vl,label:"RUN",count:t.running,fg:e.green,bg:ut.green,bold:true,spinner:true,show:t.running>0},{icon:_l,label:"RETRY",count:t.retrying,fg:e.yellow,bg:ut.yellow,show:t.retrying>0},{icon:Zt,label:"REVIEW",count:t.review,fg:e.blue,bg:ut.blue,show:t.review>0},{icon:Gs,label:"TODO",count:t.todo,fg:e.dim,bg:ut.neutral,show:t.todo>0},{icon:Sl,label:"DONE",count:t.done,fg:e.green,bg:ut.green,show:t.done>0},{icon:kl,label:"FAIL",count:t.failed,fg:e.red,bg:ut.red,bold:true,show:t.failed>0},{icon:Ht,label:"TEAMS",count:t.teams,fg:e.amber,bg:ut.amber,show:t.teams>0}].filter(x=>x.show),b=o.total>0,T=r&&r.length>0?Math.min(16,r.length):0;return jsxs(Box,{paddingX:1,justifyContent:"space-between",width:n,children:[jsxs(Box,{gap:1,children:[f.map(x=>jsx(Text,{backgroundColor:x.bg,color:x.fg,bold:x.bold,children:x.spinner?jsxs(Fragment,{children:[" ",jsx(zs,{color:x.fg})," ",x.count," ",x.label," "]}):jsxs(Fragment,{children:[" ",x.icon," ",x.count," ",x.label," "]})},x.label)),f.length===0&&jsxs(Text,{backgroundColor:ut.neutral,color:e.dim,children:[" ","NO TASKS"," "]})]}),jsxs(Box,{gap:0,children:[T>0&&r&&jsxs(Fragment,{children:[jsx(Bl,{data:r,width:T,color:e.amberDim}),jsx(Text,{children:" "})]}),b&&jsxs(Text,{backgroundColor:ut.amber,color:e.cyan,children:[" ",Cl,h(o.input)," ",Il,h(o.output),o.reasoning>0?` ${Rl}${h(o.reasoning)}`:""," ",ue," ",Ml,h(o.total)," "]})]})]})}var Vs=nn.memo(function(o){let n=Math.max(10,o.width-2),r=o.stats.running>0;return jsxs(Box,{flexDirection:"column",children:[jsx(Box,{height:1}),jsx(Ll,{projectName:o.projectName,activeView:o.activeView,mode:o.mode,stats:o.stats,uptime:o.uptime,width:o.width,version:o.version,latestVersion:o.latestVersion,taskBadge:o.taskBadge,flashTab:o.flashTab,flashColor:o.flashColor,onFlashComplete:o.onFlashComplete}),jsx(Box,{height:1}),jsx(Ol,{stats:o.stats,tokens:o.tokens,width:o.width,sparklineData:o.sparklineData}),jsx($l,{width:n,active:r})]})});var rn="\u0423\u041F\u0420\u0410\u0412\u041B\u0415\u041D\u0418\u0415",Po="\u041C\u041E\u041D\u0418\u0422\u041E\u0420\u0418\u041D\u0413",En="\u041D\u0410\u0421\u0422\u0420\u041E\u0419\u041A\u0418",fo={task:{sub:["add","list","show","cancel","retry","assign","approve","reject","delete"],help:"Manage tasks",category:rn},agent:{sub:["add","list","disable","enable","delete","autonomous","shop"],help:"Manage agents",category:rn},team:{sub:["create","list","join","leave","disband","set-lead"],help:"Manage teams",category:rn},goal:{sub:["add","list","show","status","delete"],help:"Manage goals",category:rn},run:{args:"[id]",help:"Run task (or selected)",category:Po},"run-all":{help:"Run all todo tasks",category:Po},watch:{help:"Start watch mode (auto-dispatch)",category:Po},pause:{help:"Pause watch mode",category:Po},status:{help:"Show orchestrator status",category:Po},config:{sub:["activity-filter","max-concurrent"],help:"TUI settings",category:En},help:{help:"List all commands",category:En},quit:{help:"Exit the TUI",category:En}};function _r(t){if(!t.startsWith("/"))return null;let o=t.slice(1),n=o.indexOf(" ");if(n===-1){let T=o;if(!T)return null;let x=Object.keys(fo).find(y=>y.startsWith(T)&&y!==T);return x?x.slice(T.length):null}let r=o.slice(0,n),l=fo[r];if(!l?.sub)return null;let f=o.slice(n+1);if(!f)return null;let b=l.sub.find(T=>T.startsWith(f)&&T!==f);return b?b.slice(f.length):null}function Hs(t){if(!t.startsWith("/"))return [];let o=t.slice(1),n=o.indexOf(" ");if(n===-1){let T=o.toLowerCase(),x=[];if(!T){let y=[rn,Po,En];for(let I of y){x.push({cmd:"",desc:`\u2500\u2500 ${I} \u2500\u2500`});for(let[v,B]of Object.entries(fo))if(B.category===I){let C=B.args?` ${B.args}`:"";x.push({cmd:`/${v}${C}`,desc:B.help,subs:B.sub?.join(" \xB7 ")});}}return x}for(let[y,I]of Object.entries(fo))if(y.startsWith(T)){let v=I.args?` ${I.args}`:"";if(x.push({cmd:`/${y}${v}`,desc:I.help,subs:I.sub?.join(" \xB7 ")}),y===T&&I.sub)for(let B of I.sub)x.push({cmd:`/${y} ${B}`,desc:`${I.help}: ${B}`});}return x}let r=o.slice(0,n),l=fo[r];if(!l?.sub)return [];let f=o.slice(n+1).toLowerCase(),b=[];for(let T of l.sub)(!f||T.startsWith(f))&&b.push({cmd:`/${r} ${T}`,desc:`${l.help}: ${T}`});return b}var Ln=class{entries=[];cursor=0;push(o){o&&(this.entries[this.entries.length-1]!==o&&(this.entries.push(o),this.entries.length>100&&this.entries.shift()),this.cursor=this.entries.length);}prev(){return this.entries.length===0?null:(this.cursor>0&&this.cursor--,this.entries[this.cursor]??null)}next(){return this.cursor<this.entries.length-1?(this.cursor++,this.entries[this.cursor]??null):(this.cursor=this.entries.length,null)}reset(){this.cursor=this.entries.length;}};var Nl="\u2588",js=nn.memo(function({mode:o,value:n,completion:r,activeView:l,canRun:f,canNew:b,canApprove:T,canReject:x,canCancel:y,canDelete:I,canUndo:v,canEdit:B,canForceStop:C,canToggleAuto:H,autoActive:V,canPause:F,isPaused:P,canToggleShowAll:j,showAllActive:L,hasDetail:O,itemCount:N,itemLabel:E,width:G,hasSuggestions:z,onboardingCompleted:X}){if(o==="command"){let R=z?" \u2191\u2193 select Tab fill Esc \u2715":" Enter exec \u2191\u2193 history Tab complete Esc \u2715",ie=Math.max(4,G-6-R.length-(r?.length??0)-1),Be=n.length>ie?"\u2026"+n.slice(-(ie-1)):n;return jsx(Box,{paddingX:2,justifyContent:"space-between",width:G,children:jsxs(Box,{children:[jsx(Text,{color:e.amber,children:"/ "}),jsx(Text,{color:e.white,children:Be}),r&&jsx(Text,{color:e.ghost,children:r}),jsx(Text,{color:e.amber,children:Nl}),jsx(Text,{color:e.dim,children:R})]})})}return jsxs(Box,{paddingX:2,justifyContent:"space-between",width:G,children:[jsxs(Text,{color:e.dim,children:[jsx(Text,{bold:true,color:e.gray,children:"\u2191\u2193"})," ",jsx(Text,{bold:true,color:e.gray,children:"Tab"}),"/",jsx(Text,{bold:true,color:e.gray,children:"\u2190\u2192"})," ",jsx(Text,{bold:true,color:e.gray,children:"/"})," cmd",b&&jsxs(Fragment,{children:[" ",jsx(Text,{bold:true,color:e.gray,children:"N"})," new"]}),f&&jsxs(Fragment,{children:[" ",jsx(Text,{bold:true,color:e.gray,children:"R"})," run"]}),y&&jsxs(Fragment,{children:[" ",jsx(Text,{bold:true,color:e.amber,children:"C"})," cancel"]}),T&&jsxs(Fragment,{children:[" ",jsx(Text,{bold:true,color:e.green,children:"A"})," approve"]}),x&&jsxs(Fragment,{children:[" ",jsx(Text,{bold:true,color:e.red,children:"X"})," reject"]}),B&&jsxs(Fragment,{children:[" ",jsx(Text,{bold:true,color:e.cyan,children:"E"})," edit"]}),C&&jsxs(Fragment,{children:[" ",jsx(Text,{bold:true,color:e.red,children:"S"})," stop"]}),F&&jsxs(Fragment,{children:[" ",jsx(Text,{bold:true,color:e.amber,children:"P"}),P?" resume":" pause"]}),H&&jsxs(Fragment,{children:[" ",jsx(Text,{bold:true,color:e.cyan,children:"U"}),V?" auto off":" auto on"]}),j&&jsxs(Fragment,{children:[" ",jsx(Text,{bold:true,color:e.gray,children:"S"}),L?" collapse":" show all"]}),I&&!T&&jsxs(Fragment,{children:[" ",jsx(Text,{bold:true,color:e.gray,children:"D"})," delete"]}),v&&jsxs(Fragment,{children:[" ",jsx(Text,{bold:true,color:e.yellow,children:"Z"})," undo"]}),O&&jsxs(Fragment,{children:[" ",jsx(Text,{bold:true,color:e.gray,children:"Esc"})," close"]}),!O&&(l==="tasks"||l==="agents"||l==="goals")&&jsxs(Fragment,{children:[" ",jsx(Text,{bold:true,color:e.gray,children:"Enter"})," detail"]})," ",jsx(Text,{bold:true,color:e.gray,children:"Q"})," quit"," ",jsx(Text,{bold:true,color:X===false?e.amber:e.gray,children:"?"}),jsx(Text,{color:X===false?e.amber:void 0,children:" help"})]}),N>0&&jsxs(Text,{color:e.dim,children:[N," ",E]})]})});var On="\u2588",Ar=process.platform==="darwin"?"\u2318":"Ctrl";function Wl(t,o){if(o<=0||t.length<=o)return [t];let n=[];for(let r=0;r<t.length;r+=o)n.push(t.slice(r,r+o));return n}function Pn(t,o){if(o<=0)return 0;let n=o-1;for(;n>0&&t[n-1]===" ";)n--;for(;n>0&&t[n-1]!==" ";)n--;return n}function qs(t,o){if(o>=t.length)return t.length;let n=o;for(;n<t.length&&t[n]!==" ";)n++;for(;n<t.length&&t[n]===" ";)n++;return n}function Ks({title:t,steps:o,onComplete:n,onCancel:r,width:l,height:f,onPasteImage:b,footerExtra:T,onSuggestionSelected:x}){let [y,I]=useState(0),[v,B]=useState({}),[C,H]=useState(()=>{let A=o.find(S=>!S.skip?.({}));return A?.type==="text"&&A.defaultValue?A.defaultValue:""}),[V,F]=useState(()=>{let A=o.find(S=>!S.skip?.({}));return A?.type==="text"&&A.defaultValue?A.defaultValue.length:0}),[P,j]=useState(()=>{let A=o.find(S=>!S.skip?.({}));return A?.type==="textarea"&&A.defaultValue?A.defaultValue.split(`
6
- `):[""]}),[L,O]=useState(0),[N,E]=useState(0),[G,z]=useState(()=>{let A=o.find(S=>!S.skip?.({}));if(A?.type==="select"&&A.defaultValue){let M=(A.getOptions?.({})??A.options??[]).findIndex(k=>k.value===A.defaultValue);return M>=0?M:0}return 0}),X=useMemo(()=>o.filter(A=>!A.skip?.(v)),[o,v]),R=X[y],ie=X.length,{taLineNumWidth:Wt,taContentWidth:it}=useMemo(()=>{let A=String(P.length).length;return {taLineNumWidth:A,taContentWidth:Math.max(1,l-A-4)}},[P.length,l]),Re=useMemo(()=>{if(!R||R.type!=="textarea")return [];let A=[];for(let S=0;S<P.length;S++){let M=Wl(P[S]??"",it);for(let k=0;k<M.length;k++)A.push({logicalRow:S,startCol:k*it,text:M[k],isFirst:k===0});}return A},[R?.id,R?.type,P,it]),Xe=useMemo(()=>{for(let A=0;A<Re.length;A++){let S=Re[A];if(S.logicalRow===L&&(N>=S.startCol&&N<S.startCol+it||N>=S.startCol&&(A+1>=Re.length||Re[A+1].logicalRow!==L)))return A}return 0},[Re,L,N,it]),[at,mt]=useState(new Set),[Pe,qe]=useState(false),[lt,Ke]=useState(0),[oo,ke]=useState(false),[ft,$t]=useState(null),[Xt,pt]=useState(false),Je=useRef(null),ct=useRef(null),Fo=useMemo(()=>R?R.type==="text"?C:R.type==="textarea"?P.join(`
7
- `):"":"",[R,C,P]),ln=useCallback((A,S)=>{if(Je.current&&clearTimeout(Je.current),!S){$t(null);return}Je.current=setTimeout(()=>{$t(S(A));},300);},[]);useEffect(()=>(R&&R.validate&&(R.type==="text"||R.type==="textarea")&&ln(Fo,R.validate),()=>{Je.current&&clearTimeout(Je.current);}),[Fo,R,ln]),useEffect(()=>()=>{ct.current&&clearTimeout(ct.current);},[]);let Ct=useMemo(()=>!R||R.type!=="select"&&R.type!=="multiselect"?[]:R.getOptions?.(v)??R.options??[],[R,v]),qt=Math.min(G,Math.max(0,Ct.length-1)),It=useMemo(()=>{if(!R?.suggestions)return [];if(!C.trim())return R.suggestions;let A=C.toLowerCase();return R.suggestions.filter(S=>S.label.toLowerCase().includes(A)||(S.hint??"").toLowerCase().includes(A))},[R?.suggestions,C]),no=Math.min(lt,Math.max(0,It.length-1)),Gt=A=>{let S={...v,[R.id]:A};B(S),H(""),F(0),j([""]),O(0),E(0),z(0),mt(new Set),qe(false),Ke(0),ke(false),$t(null),pt(false),Je.current&&clearTimeout(Je.current);let M=R.id,Y=o.findIndex(q=>q.id===M)+1;for(;Y<o.length;){let q=o[Y];if(q&&!q.skip?.(S))break;Y++;}if(Y>=o.length)n(S);else {let q=o[Y].id,ae=o.filter(ye=>!ye.skip?.(S)).findIndex(ye=>ye.id===q);I(ae>=0?ae:0);let de=o[Y];if(de.type==="text"){let ye=de.defaultValue??"";H(ye),F(ye.length);}else if(de.type==="textarea"){let ye=de.defaultValue?de.defaultValue.split(`
8
- `):[""];j(ye),O(ye.length-1),E(ye[ye.length-1].length);}else if(de.type==="select"){let ye=de.getOptions?.(S)??de.options??[];if(de.defaultValue){let zt=ye.findIndex(Wo=>Wo.value===de.defaultValue);z(zt>=0?zt:0);}else z(0);}else de.type==="multiselect"&&(z(0),de.defaultValue?mt(new Set(de.defaultValue.split(","))):mt(new Set));}},ht=()=>{if(y===0){r();return}let A=R.id,M=o.findIndex(ae=>ae.id===A)-1;for(;M>=0;){let ae=o[M];if(ae&&!ae.skip?.(v))break;M--;}if(M<0){r();return}let k=o[M].id,Y=X.findIndex(ae=>ae.id===k);I(Y>=0?Y:0),qe(false),Ke(0),ke(false),$t(null),pt(false),Je.current&&clearTimeout(Je.current);let q=o[M];if(v[q.id]&&ke(true),q.type==="text"){let ae=v[q.id]??q.defaultValue??"";H(ae),F(ae.length);}else if(q.type==="textarea"){let ae=v[q.id]??q.defaultValue??"",de=ae?ae.split(`
9
- `):[""];j(de),O(de.length-1),E(de[de.length-1].length);}else if(q.type==="multiselect"){z(0);let ae=v[q.id];mt(ae?new Set(ae.split(",")):new Set);}else {let ae=q.getOptions?.(v)??q.options??[],de=v[q.id],ye=ae.findIndex(zt=>zt.value===de);z(ye>=0?ye:0);}};if(useInput((A,S)=>{if(R){if(S.escape){y===0?r():ht();return}if((S.ctrl||S.meta)&&(A==="v"||A==="i")&&b&&(R.type==="text"||R.type==="textarea")){b();return}if(R.type==="text"){if(Pe&&It.length>0){if(S.upArrow){no<=0?qe(false):Ke(M=>M-1);return}if(S.downArrow){Ke(M=>Math.min(It.length-1,M+1));return}if(S.return){let M=It[no];M&&x&&x(M.value);return}qe(false);}if(S.return){let M=C.trim();if(R.required&&!M){ke(true);return}if(ft!==null){ke(true),pt(true),ct.current&&clearTimeout(ct.current),ct.current=setTimeout(()=>pt(false),2e3);return}Gt(M);return}if(S.downArrow&&R.suggestions&&It.length>0){qe(true),Ke(0);return}if(S.ctrl&&A==="a"){F(0);return}if(S.ctrl&&A==="e"){F(C.length);return}if(S.ctrl&&A==="k"){ke(true),H(M=>M.slice(0,V));return}if(S.ctrl&&A==="u"){ke(true),H(M=>M.slice(V)),F(0);return}if(S.ctrl&&A==="w"){ke(true);let M=Pn(C,V);H(k=>k.slice(0,M)+k.slice(V)),F(M);return}if(S.meta&&(S.leftArrow||A==="b")){F(Pn(C,V));return}if(S.meta&&(S.rightArrow||A==="f")){F(qs(C,V));return}if(S.leftArrow){F(M=>Math.max(0,M-1));return}if(S.rightArrow){F(M=>Math.min(C.length,M+1));return}if(S.backspace||S.delete){if(V===0&&C.length===0&&y>0){ht();return}V>0&&(H(M=>M.slice(0,V-1)+M.slice(V)),F(M=>M-1));return}A&&!S.ctrl&&!S.meta&&!S.escape&&(ke(true),qe(false),Ke(0),H(M=>M.slice(0,V)+A+M.slice(V)),F(M=>M+A.length));return}if(R.type==="textarea"){if(S.return&&(S.ctrl||S.meta)){let M=P.join(`
10
- `).trim();if(R.required&&!M){ke(true);return}if(ft!==null){ke(true),pt(true),ct.current&&clearTimeout(ct.current),ct.current=setTimeout(()=>pt(false),2e3);return}Gt(M);return}if(S.return){ke(true),j(M=>{let k=M[L]??"",Y=k.slice(0,N),q=k.slice(N),Ce=[...M];return Ce.splice(L,1,Y,q),Ce}),O(M=>M+1),E(0);return}if(S.ctrl&&A==="a"){E(0);return}if(S.ctrl&&A==="e"){E((P[L]??"").length);return}if(S.ctrl&&A==="k"){ke(true),j(M=>{let k=[...M];return k[L]=(k[L]??"").slice(0,N),k});return}if(S.ctrl&&A==="u"){ke(true),j(M=>{let k=[...M];return k[L]=(k[L]??"").slice(N),k}),E(0);return}if(S.ctrl&&A==="w"){ke(true);let M=L,k=N;j(Y=>{let q=Y[M]??"",Ce=Pn(q,k),ae=[...Y];return ae[M]=q.slice(0,Ce)+q.slice(k),E(Ce),ae});return}if(S.meta&&(S.leftArrow||A==="b")){E(Pn(P[L]??"",N));return}if(S.meta&&(S.rightArrow||A==="f")){E(qs(P[L]??"",N));return}if(S.upArrow){if(Xe>0){let M=Re[Xe],k=Re[Xe-1],Y=N-(M?.startCol??0),q=Math.min(k.startCol+Y,k.startCol+k.text.length);O(k.logicalRow),E(q);}return}if(S.downArrow){if(Xe<Re.length-1){let M=Re[Xe],k=Re[Xe+1],Y=N-(M?.startCol??0),q=Math.min(k.startCol+Y,k.startCol+k.text.length);O(k.logicalRow),E(q);}return}if(S.leftArrow){N>0?E(M=>M-1):L>0&&(O(M=>M-1),E((P[L-1]??"").length));return}if(S.rightArrow){let M=(P[L]??"").length;N<M?E(k=>k+1):L<P.length-1&&(O(k=>k+1),E(0));return}if(S.backspace||S.delete){if(N===0&&L===0)return;if(N>0)j(M=>{let k=[...M],Y=k[L]??"";return k[L]=Y.slice(0,N-1)+Y.slice(N),k}),E(M=>M-1);else {let M=(P[L-1]??"").length;j(k=>{let Y=[...k],q=Y[L-1]??"",Ce=Y[L]??"";return Y.splice(L-1,2,q+Ce),Y}),E(M),O(k=>k-1);}return}if(A&&!S.ctrl&&!S.meta&&!S.escape){ke(true);let M=A.split(/\r?\n/);if(M.length===1)j(k=>{let Y=[...k],q=Y[L]??"";return Y[L]=q.slice(0,N)+A+q.slice(N),Y}),E(k=>k+A.length);else {let k=L,Y=N;j(q=>{let Ce=[...q],ae=Ce[k]??"",de=ae.slice(0,Y),ye=ae.slice(Y),zt=M[0]??"",Wo=M[M.length-1]??"",dn=[de+zt,...M.slice(1,-1),Wo+ye];return Ce.splice(k,1,...dn),Ce}),O(k+M.length-1),E((M[M.length-1]??"").length);}}return}if(R.type==="select"||R.type==="multiselect"){if(S.upArrow||A==="k"){z(M=>Math.max(0,M-1));return}if(S.downArrow||A==="j"){z(M=>Math.min(Ct.length-1,M+1));return}if(S.backspace||S.delete){ht();return}if(R.type==="select"){if(S.return||S.tab){let M=Ct[qt];if(M){if(R.validate){let k=R.validate(M.value);if(k!==null){ke(true),$t(k),pt(true),ct.current&&clearTimeout(ct.current),ct.current=setTimeout(()=>pt(false),2e3);return}}Gt(M.value);}return}if(A>="1"&&A<="9"){let M=parseInt(A,10)-1;if(M<Ct.length){let k=Ct[M];k&&Gt(k.value);}return}}else {if(A===" "){let M=Ct[qt];M&&mt(k=>{let Y=new Set(k);return Y.has(M.value)?Y.delete(M.value):Y.add(M.value),Y});return}if(S.return){let M=Array.from(at).join(",");Gt(M);return}}}}}),!R)return null;let xt=oo?ft:null,tr=Math.max(20,l-6),cn=`${y+1}/${ie}`,xo=Math.max(2,f-4),ro=0;qt>=xo&&(ro=qt-xo+1);let bt=Ct.slice(ro,ro+xo);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:[" ",Ge,Ge," "]}),jsxs(Text,{color:e.dim,children:["step ",cn]})]}),jsxs(Box,{children:[jsx(Text,{children:" "}),X.map((A,S)=>jsxs(Text,{color:S===y?e.amber:S<y?e.green:e.ghost,children:[S===y?"\u25CF":S<y?"\u2713":"\u25CB"," "]},A.id))]}),jsxs(Box,{marginTop:0,children:[jsxs(Text,{color:e.white,bold:true,children:[" ",R.label]}),R.required&&jsx(Text,{color:e.red,children:" *"}),!R.required&&jsxs(Text,{color:e.dim,children:[" (optional, ",R.type==="textarea"?`${Ar}+Enter`:"Enter"," to skip)"]})]}),R.description&&jsx(Box,{children:jsxs(Text,{color:e.dim,children:[" ",R.description]})}),R.type==="text"&&jsxs(Box,{flexDirection:"column",children:[jsxs(Box,{borderStyle:xt?"round":void 0,borderColor:xt?e.red:void 0,children:[jsxs(Text,{color:e.amber,children:[" ",">"," "]}),C.length>0?jsxs(Fragment,{children:[jsx(Text,{color:e.white,children:C.slice(0,V)}),jsx(Text,{color:e.amber,children:On}),jsx(Text,{color:e.white,children:C.slice(V)})]}):R.placeholder?jsxs(Fragment,{children:[jsx(Text,{color:e.ghost,children:R.placeholder}),jsx(Text,{color:e.amber,children:On})]}):jsx(Text,{color:e.amber,children:On})]}),xt&&jsxs(Text,{color:e.red,dimColor:true,children:[" ",xt]}),Xt&&jsx(Text,{color:e.red,children:" Fix the error above"})]}),R.type==="text"&&R.suggestions&&It.length>0&&(()=>{let A=Math.max(2,f-6),S=0;Pe&&no>=A&&(S=no-A+1);let M=It.slice(S,S+A);return jsxs(Box,{flexDirection:"column",children:[jsxs(Text,{color:e.ghost,children:[" ",Ge,Ge,Ge," or browse templates ",Ge.repeat(Math.max(0,tr-28))]}),M.map((k,Y)=>{let q=Y+S,Ce=Pe&&q===no;return jsxs(Box,{children:[jsx(Text,{color:Ce?e.amber:e.ghost,children:Ce?" \u25B8 ":" "}),jsx(Text,{color:Ce?e.white:e.silver,bold:Ce,children:k.label}),k.hint&&jsxs(Text,{color:e.dim,wrap:"truncate",children:[" ",Ge," ",k.hint.replace(/\n/g," ")]})]},k.value)})]})})(),R.type==="textarea"&&(()=>{let A=Math.max(3,f-6),S=0;Xe>=A&&(S=Xe-A+1);let M=Re.slice(S,S+A);return jsxs(Box,{flexDirection:"column",children:[jsxs(Box,{flexDirection:"column",borderStyle:xt?"round":void 0,borderColor:xt?e.red:void 0,children:[M.map((k,Y)=>{let q=Y+S,Ce=k.isFirst?String(k.logicalRow+1).padStart(Wt," "):"".padStart(Wt," "),ae=q===Xe,de=N-k.startCol;return jsxs(Box,{children:[jsxs(Text,{color:e.dim,children:[" ",Ce," "]}),jsxs(Text,{color:e.ghost,children:["\u2502"," "]}),ae?jsxs(Fragment,{children:[jsx(Text,{color:e.white,children:k.text.slice(0,de)}),jsx(Text,{color:e.amber,children:On}),jsx(Text,{color:e.white,children:k.text.slice(de)})]}):jsx(Text,{color:e.silver,children:k.text||(k.isFirst?" ":"")})]},`${k.logicalRow}-${k.startCol}`)}),P.length===1&&P[0]===""&&R.placeholder&&jsx(Box,{children:jsxs(Text,{color:e.dim,children:[" ","".padStart(Wt," ")," ",R.placeholder]})})]}),xt&&jsxs(Text,{color:e.red,dimColor:true,children:[" ",xt]}),Xt&&jsx(Text,{color:e.red,children:" Fix the error above"})]})})(),R.type==="select"&&jsxs(Box,{flexDirection:"column",children:[bt.map((A,S)=>{let M=S+ro,k=M===qt,Y=String(M+1).padStart(Ct.length>=10?2:1);return jsxs(Box,{children:[jsx(Text,{color:k?e.amber:e.ghost,children:k?" \u25B8 ":` ${Y} `}),jsx(Text,{color:k?e.white:e.silver,bold:k,children:A.label}),A.hint&&jsxs(Text,{color:e.dim,wrap:"truncate",children:[" ",Ge," ",A.hint.replace(/\n/g," ")]})]},A.value)}),xt&&jsxs(Text,{color:e.red,dimColor:true,children:[" ",xt]}),Xt&&jsx(Text,{color:e.red,children:" Fix the error above"})]}),R.type==="multiselect"&&jsxs(Box,{flexDirection:"column",children:[bt.map((A,S)=>{let k=S+ro===qt,Y=at.has(A.value);return jsxs(Box,{children:[jsx(Text,{color:k?e.amber:e.ghost,children:k?" \u25B8 ":" "}),jsx(Text,{color:Y?e.green:e.dim,children:Y?"[\u2713]":"[ ]"}),jsxs(Text,{color:k?e.white:e.silver,bold:k,children:[" ",A.label]}),A.hint&&jsxs(Text,{color:e.dim,wrap:"truncate",children:[" ",Ge," ",A.hint.replace(/\n/g," ")]})]},A.value)}),at.size>0&&jsx(Box,{children:jsxs(Text,{color:e.dim,children:[" ","\u2514"," ",at.size," selected"]})})]}),jsxs(Box,{marginTop:0,children:[jsxs(Text,{color:e.ghost,children:[" ",R.type==="select"?"\u2191\u2193 select Enter confirm":R.type==="multiselect"?"\u2191\u2193 move Space toggle Enter confirm":R.type==="textarea"?`Enter newline ${Ar}+Enter confirm \u2190\u2191\u2192\u2193 navigate`:Pe?"\u2191\u2193 browse Enter select \u2191 back to input":R.suggestions?"\u2190\u2192 move Enter confirm \u2193 browse templates":"\u2190\u2192 move Enter confirm",b&&(R.type==="text"||R.type==="textarea")?` ${Ar}+V paste image`:""," Esc ",y>0?"back":"cancel"]}),T&&jsxs(Text,{color:e.amber,children:[" ",T]})]})]})}var Js=nn.memo(function({agents:o,selected:n,msgCounts:r,colorMap:l,maxHeight:f,onConfirm:b,onCancel:T}){let [x,y]=useState(0),[I,v]=useState(()=>new Set(n));useMemo(()=>I.size===0||I.size===o.length,[I.size,o.length]);let C=Math.max(3,f-5),H=useMemo(()=>{if(o.length<=C)return 0;let P=Math.floor(C/2),j=o.length-C;return Math.min(j,Math.max(0,x-P))},[x,o.length,C]),V=o.slice(H,H+C);useInput((P,j)=>{if(j.upArrow){y(L=>L>0?L-1:o.length-1);return}if(j.downArrow){y(L=>L<o.length-1?L+1:0);return}if(P===" "){let L=o[x];if(!L)return;v(O=>{let N=new Set(O);return N.has(L.id)?N.delete(L.id):N.add(L.id),N});return}if(P==="a"||P==="A"){v(L=>new Set);return}if(j.return){b(new Set(I));return}if(j.escape){T();return}});let F=I.size===0?o.length:I.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:[ue," ",F,"/",o.length," selected"]})]}),jsx(Text,{color:e.ghost,children:Ge.repeat(36)}),V.map((P,j)=>{let O=j+H===x,N=I.size===0||I.has(P.id),E=l.get(P.id)??e.silver,G=r.get(P.id)??0;return jsxs(Box,{gap:0,children:[jsx(Text,{color:O?e.amber:e.ghost,children:O?" \u25B8 ":" "}),jsx(Text,{color:N?e.green:e.ghost,children:N?"[\u2713]":"[ ]"}),jsxs(Text,{color:O?E:N?e.silver:e.dim,bold:O,children:[" ",P.name]}),G>0&&jsxs(Text,{color:e.dim,children:[" ",ue,G]})]},P.id)}),o.length>C&&jsxs(Text,{color:e.ghost,children:[" ",H>0?"\u2191":" "," ",H+C<o.length?"\u2193":" "," ",x+1,"/",o.length]}),jsx(Text,{color:e.ghost,children:Ge.repeat(36)}),jsxs(Text,{color:e.dim,children:[" Space toggle"," ",ue," ","a all"," ",ue," ","Enter confirm"," ",ue," ","Esc cancel"]})]})});var jl={system:"\u2666",lifecycle:"\u25B6",output:"\u2502",tool:"\u2699",result:"\u2190",error:"\u2715",file:"\u270E",info:"\u2502"},Ul={system:"System",lifecycle:"Lifecycle",output:"Output",tool:"Tool calls",result:"Results",error:"Errors",file:"Files",info:"Info"},Xl={system:e.purple,lifecycle:e.cyan,output:e.white,tool:e.blue,result:e.green,error:e.red,file:e.purple,info:e.silver},St=["system","lifecycle","output","tool","result","error","file","info"],ti=[{key:"1",label:"all",types:St},{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"]}],oi=nn.memo(function({selected:o,typeCounts:n,onConfirm:r,onCancel:l}){let[f,b]=useState(0),[T,x]=useState(()=>new Set(o)),y=useMemo(()=>T.size===St.length||St.every(v=>T.has(v)),[T]);useInput((v,B)=>{if(B.upArrow){b(C=>C>0?C-1:St.length-1);return}if(B.downArrow){b(C=>C<St.length-1?C+1:0);return}if(v===" "){let C=St[f];if(!C)return;x(H=>{let V=new Set(H);return V.has(C)?V.delete(C):V.add(C),V});return}if(v==="a"||v==="A"){x(C=>C.size===St.length?new Set:new Set(St));return}for(let C of ti)if(v===C.key){x(new Set(C.types));return}if(B.return){let C=T.size===0?new Set(St):new Set(T);r(C);return}if(B.escape){l();return}});let I=y?St.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:[ue," ",I,"/",St.length," selected"]})]}),jsx(Text,{color:e.ghost,children:Ge.repeat(36)}),St.map((v,B)=>{let C=B===f,H=T.has(v),V=n[v]??0,F=Xl[v];return jsxs(Box,{gap:0,children:[jsx(Text,{color:C?e.amber:e.ghost,children:C?" \u25B8 ":" "}),jsx(Text,{color:H?e.green:e.ghost,children:H?"[\u2713]":"[ ]"}),jsxs(Text,{color:C?F:e.dim,children:[" ",jl[v]," "]}),jsx(Text,{color:C?F:H?e.silver:e.dim,bold:C,children:Ul[v]}),V>0&&jsxs(Text,{color:e.dim,children:[" ",ue,V]})]},v)}),jsx(Text,{color:e.ghost,children:Ge.repeat(36)}),jsxs(Box,{gap:0,children:[jsx(Text,{color:e.dim,children:" "}),ti.map((v,B)=>jsxs(nn.Fragment,{children:[B>0&&jsxs(Text,{color:e.ghost,children:[" ",ue," "]}),jsx(Text,{color:e.amberDim,children:v.key}),jsxs(Text,{color:e.dim,children:["=",v.label]})]},v.key))]}),jsxs(Text,{color:e.dim,children:[" Space toggle"," ",ue," ","a all"," ",ue," ","Enter confirm"," ",ue," ","Esc cancel"]})]})});var Fn="\u256D",Wn="\u256E",Gn="\u2570",zn="\u256F",Ie="\u2502";function to({children:t,cw:o}){return jsxs(Text,{children:[jsx(Text,{color:e.ghost,children:Ie}),jsxs(Text,{children:[" ",t.padEnd(o)," "]}),jsx(Text,{color:e.ghost,children:Ie})]})}function Dn({cw:t}){return jsx(to,{cw:t,children:""})}function ni({width:t,height:o}){let n=Math.min(t-4,50),r=n-6,l=be(n-2);return jsxs(Box,{flexDirection:"column",paddingX:2,marginTop:1,children:[jsxs(Text,{color:e.ghost,children:[Fn,l,Wn]}),jsx(to,{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(to,{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(to,{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(to,{cw:r,children:""}),jsxs(Text,{color:e.ghost,children:[Gn,l,zn]})]})}function ri({step:t,width:o}){let n=Math.min(o-4,50),r=n-6,l=be(n-2),f,b=null;if(t==="task_created")f="Press R to run task",b={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:[Fn,l,Wn]}),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(b?r-2-b.key.length-1-b.label.length-2:r-2)]}),b&&jsxs(Fragment,{children:[jsxs(Text,{color:e.amber,children:[" ",b.key]}),jsxs(Text,{color:e.gray,children:[" ",b.label]})]}),jsx(Text,{children:" "}),jsx(Text,{color:e.ghost,children:Ie})]}),jsxs(Text,{color:e.ghost,children:[Gn,l,zn]})]})}function si({width:t}){let o=Math.min(t-4,50),n=o-6,r=be(o-2);return jsxs(Box,{flexDirection:"column",paddingX:2,marginTop:1,children:[jsxs(Text,{color:e.ghost,children:[Fn,r,Wn]}),jsx(to,{cw:n,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,n-21))}),jsx(Text,{children:" "}),jsx(Text,{color:e.ghost,children:Ie})]}),jsx(to,{cw:n,children:""}),jsxs(Text,{children:[jsxs(Text,{color:e.ghost,children:[Ie," "]}),jsx(Text,{color:e.silver,children:"Type / to see all commands".padEnd(n)}),jsx(Text,{children:" "}),jsx(Text,{color:e.ghost,children:Ie})]}),jsx(to,{cw:n,children:""}),jsxs(Text,{color:e.ghost,children:[Gn,r,zn]})]})}function Vn({count:t,config:o,width:n}){if(t>=3)return null;let r=Math.min((n??44)-4,50),l=r-6,f=be(r-2),b=jsxs(Text,{color:e.ghost,children:[Fn,f,Wn]}),T=jsxs(Text,{color:e.ghost,children:[Gn,f,zn]});if(t>0){let y=o.hints[0],I=y?` ${y.key} ${y.label}`:"";return jsxs(Box,{flexDirection:"column",paddingX:2,marginTop:1,children:[b,jsxs(Text,{children:[jsxs(Text,{color:e.ghost,children:[Ie," "]}),jsx(Text,{color:e.amber,children:Ht}),jsxs(Text,{color:e.silver,children:[" ",o.nudge.padEnd(l-2-I.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 x=o.hints.reduce((y,I,v)=>y+I.key.length+1+I.label.length+(v>0?3:0),0);return jsxs(Box,{flexDirection:"column",paddingX:2,marginTop:1,children:[b,jsx(Dn,{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:[" ",o.title]}),jsx(Text,{children:" ".repeat(Math.max(0,l-o.title.length-2))}),jsx(Text,{children:" "}),jsx(Text,{color:e.ghost,children:Ie})]}),jsx(Dn,{cw:l}),o.description.map((y,I)=>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})]},I)),jsx(Dn,{cw:l}),jsxs(Text,{children:[jsxs(Text,{color:e.ghost,children:[Ie," "]}),o.hints.map((y,I)=>jsxs(nn.Fragment,{children:[I>0&&jsx(Text,{color:e.ghost,children:" "}),jsx(Text,{color:e.amber,children:y.key}),jsxs(Text,{color:e.gray,children:[" ",y.label]})]},I)),jsx(Text,{children:" ".repeat(Math.max(0,l-x))}),jsx(Text,{children:" "}),jsx(Text,{color:e.ghost,children:Ie})]}),jsx(Dn,{cw:l}),T]})}var Kl=2,ci=360,Yl={done:4e3,failed:8e3,review:6e3},Zl={done:"\u2713",failed:"\u2715",review:Zt},Jl={done:e.green,failed:e.red,review:e.blue},Ql={done:e.successBg,failed:e.errorBg,review:e.infoBg};function ec(t){let o=t.agentName??"Agent";switch(t.type){case "done":return `Task completed by ${o}`;case "failed":return "Task failed \u2014 press Enter for details";case "review":return "Task ready for review \u2014 press A to approve"}}var tc=nn.memo(function({toast:o,onDismiss:n}){let[r,l]=useState(true),[f,b]=useState(false);useEffect(()=>{let C=setTimeout(()=>l(false),ci);return ()=>clearTimeout(C)},[]),useEffect(()=>{let C=Yl[o.type],H=setTimeout(()=>b(true),C),V=setTimeout(()=>n(o.id),C+ci);return ()=>{clearTimeout(H),clearTimeout(V);}},[o.id,o.type,n]);let T=r||f,x=Zl[o.type],y=Jl[o.type],I=Ql[o.type],v=ec(o),B=o.title.length>40?o.title.slice(0,39)+"\u2026":o.title;return jsx(Box,{children:jsxs(Text,{backgroundColor:I,children:[jsxs(Text,{color:T?e.dim:y,children:[" ",x," "]}),jsx(Text,{color:T?e.dim:e.white,bold:!T,children:B}),jsxs(Text,{color:T?e.dim:e.silver,children:[" ",v," "]})]})})}),gi=nn.memo(function({toasts:o,onDismiss:n}){let r=o.slice(0,Kl);return r.length===0?null:jsx(Box,{flexDirection:"column",children:r.map(l=>jsx(tc,{toast:l,onDismiss:n},l.id))})});var rc="\u256D",sc="\u256E",ic="\u2570",ac="\u256F",st="\u2502",Lr=[{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"}],Or=[{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"}],Pr=[{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"}],No=10,Ut=22;function Nr(t){let o=Math.max(0,Math.floor((Ut-t.length-2)/2)),n=Math.max(0,Ut-o-t.length-2);return be(o)+" "+t+" "+be(n)}var mi=nn.memo(function({width:o,height:n}){let r=Ut*3+3+3+2,l=r+2,f=be(l-2),b="KEYBOARD SHORTCUTS",T=Math.max(0,Math.floor((r-b.length)/2)),x=Math.max(0,r-T-b.length),y="Press any key to dismiss",I=Math.max(0,Math.floor((r-y.length)/2)),v=Math.max(0,r-I-y.length),B=Math.max(Lr.length,Or.length,Pr.length),C=B+10,H=Math.max(0,Math.floor((n-C)/2)),V=[];for(let O=0;O<B;O++){let N=O<Lr.length?Lr[O]:null,E=O<Or.length?Or[O]:null,G=O<Pr.length?Pr[O]:null;V.push(jsxs(Text,{children:[jsx(Text,{color:e.amber,children:st}),jsx(Text,{children:" "}),N?jsxs(Fragment,{children:[jsx(Text,{color:e.amber,bold:true,children:N.key.padEnd(No)}),jsx(Text,{color:e.silver,children:N.label.padEnd(Ut-No)})]}):jsx(Text,{children:" ".repeat(Ut)}),jsxs(Text,{color:e.dim,children:[" ",st," "]}),E?jsxs(Fragment,{children:[jsx(Text,{color:e.amber,bold:true,children:E.key.padEnd(No)}),jsx(Text,{color:e.silver,children:E.label.padEnd(Ut-No)})]}):jsx(Text,{children:" ".repeat(Ut)}),jsxs(Text,{color:e.dim,children:[" ",st," "]}),G?jsxs(Fragment,{children:[jsx(Text,{color:e.amber,bold:true,children:G.key.padEnd(No)}),jsx(Text,{color:e.silver,children:G.label.padEnd(Ut-No)})]}):jsx(Text,{children:" ".repeat(Ut)}),jsx(Text,{children:" "}),jsx(Text,{color:e.amber,children:st})]},`r${O}`));}let F=O=>jsxs(Text,{children:[jsx(Text,{color:e.amber,children:st}),jsx(Text,{children:" ".repeat(r)}),jsx(Text,{color:e.amber,children:st})]},O),P=Nr("NAVIGATION"),j=Nr("ACTIONS"),L=Nr("COMMANDS");return jsxs(Box,{flexDirection:"column",paddingX:Math.max(0,Math.floor((o-l)/2)),marginTop:H,children:[jsxs(Text,{color:e.amber,children:[rc,f,sc]}),F("e1"),jsxs(Text,{children:[jsx(Text,{color:e.amber,children:st}),jsx(Text,{children:" ".repeat(T)}),jsx(Text,{color:e.amber,bold:true,children:b}),jsx(Text,{children:" ".repeat(x)}),jsx(Text,{color:e.amber,children:st})]}),F("e2"),jsxs(Text,{children:[jsx(Text,{color:e.amber,children:st}),jsx(Text,{children:" "}),jsx(Text,{color:e.dim,children:P}),jsxs(Text,{color:e.dim,children:[" ",st," "]}),jsx(Text,{color:e.dim,children:j}),jsxs(Text,{color:e.dim,children:[" ",st," "]}),jsx(Text,{color:e.dim,children:L}),jsx(Text,{children:" "}),jsx(Text,{color:e.amber,children:st})]}),F("e3"),V,F("e4"),jsxs(Text,{children:[jsx(Text,{color:e.amber,children:st}),jsx(Text,{children:" ".repeat(I)}),jsx(Text,{color:e.dim,children:y}),jsx(Text,{children:" ".repeat(v)}),jsx(Text,{color:e.amber,children:st})]}),F("e5"),jsxs(Text,{color:e.amber,children:[ic,f,ac]})]})});var hi=[{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"}],xi=[{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"}],bi=[{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"}],Ti=[{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"}],yi=[{value:"",label:"Default",hint:"use shell adapter default"}],lc=[{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"}],wi=[{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"}],fi=60;function Si(t){return t.filter(o=>o.status!=="disabled").map(o=>{let n=(o.role??"").split(`
11
- `)[0].trim(),r=n.length>fi?n.slice(0,fi-1)+"\u2026":n,l=r?`[${o.adapter}] ${r}`:o.adapter;return {value:o.id,label:o.name,hint:l}})}function Un(t,o="Auto-assign",n="orchestrator picks the best agent"){return [{value:"",label:o,hint:n},...Si(t)]}var Fr=[{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 ki(t){return [{value:"",label:"None",hint:"no team"},...(t??[]).filter(o=>o.status==="active").map(o=>({value:o.id,label:o.name,hint:`${o.members.length} members`}))]}function Ci(){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 Wr(t,o){return t.map(n=>{switch(n.id){case "name":return {...n,defaultValue:o.name};case "adapter":return {...n,defaultValue:o.adapter};case "model":return {...n,defaultValue:o.model};case "role":return {...n,defaultValue:"__custom__"};case "role_custom":return {...n,defaultValue:o.role,skip:void 0};case "skills":return {...n,defaultValue:o.skills.join(", ")};case "approval_policy":return {...n,defaultValue:o.approval_policy};default:return n}})}function Xn(t,o){let n=ki(o);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:lc},{id:"model",label:"Model",type:"select",getOptions:r=>r.adapter==="opencode"?Ti:r.adapter==="codex"?xi:r.adapter==="cursor"?bi:r.adapter==="shell"?yi:hi},{id:"role",label:"Role / specialization",type:"select",options:Fr},{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:n,skip:()=>n.length<=1}]}function Ii(t){let o=t.role==="__custom__"?t.role_custom||void 0:t.role||void 0,n=t.skills?t.skills.split(",").map(l=>l.trim()).filter(Boolean):void 0,r=t.approval_policy||"auto";return {name:t.name,adapter:t.adapter||"claude",role:o,model:t.model||void 0,approval_policy:r,skills:n,team_id:t.team||void 0}}function Mi(t,o){let n=Si(t);return [{id:"name",label:"Team name",type:"text",placeholder:"e.g. frontend, backend, qa",required:true,validate:r=>r.trim()?o?.some(l=>l.name===r.trim())?"Team with this name already exists":null:"Name is required"},{id:"lead",label:"Team lead",type:"select",options:n},{id:"members",label:"Team members",type:"multiselect",getOptions:r=>n.filter(l=>l.value!==r.lead),skip:r=>!n.some(l=>l.value!==r.lead)},{id:"description",label:"Description",type:"textarea",placeholder:"Optional team purpose..."}]}function vi(t){let o=t.members?t.members.split(",").filter(Boolean):[];return {name:t.name,lead_agent_id:t.lead,member_agent_ids:o.length>0?o:void 0,description:t.description||void 0}}function _i(t){let o=Un(t);return [{id:"title",label:"Task title",type:"text",placeholder:"What needs to be done?",required:true,validate:n=>n.trim()?null:"Title is required"},{id:"priority",label:"Priority",type:"select",options:wi,defaultValue:"3",validate:n=>{let r=Number(n);return !Number.isInteger(r)||r<1||r>4?"Priority must be 1-4":null}},{id:"assignee",label:"Assignee",type:"select",options:o,skip:()=>o.length<=1},{id:"description",label:"Description",type:"textarea",placeholder:"Optional details, context, acceptance criteria..."}]}function Ri(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 Ai(t,o){let n=Un(o,"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:wi,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:n,defaultValue:t.assignee??"",skip:()=>n.length<=1},{id:"description",label:"Description",type:"textarea",defaultValue:t.description||"",placeholder:"Optional details..."}]}function $i(t){return {title:t.title,priority:t.priority?parseInt(t.priority,10):void 0,assignee:t.assignee||void 0,description:t.description??""}}function Bi(t,o,n){let r=Fr.find(x=>x.value===t.role),l=r?t.role:t.role?"__custom__":"",f=t.adapter==="opencode"?Ti:t.adapter==="codex"?xi:t.adapter==="cursor"?bi:t.adapter==="shell"?yi:hi,b=ki(n),T=n?.find(x=>x.members.some(y=>y.agent_id===t.id))?.id;return [{id:"name",label:"Agent name",type:"text",defaultValue:t.name,required:true,validate:x=>x.trim()?o?.some(y=>y.id!==t.id&&y.name===x.trim())?"Agent with this name already exists":null:"Name is required"},{id:"model",label:"Model",type:"select",options:f,defaultValue:t.config.model??""},{id:"role",label:"Role / specialization",type:"select",options:Fr,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:x=>x.role!=="__custom__"},{id:"team",label:"Team",type:"select",options:b,defaultValue:T??"",skip:()=>b.length<=1}]}var cc=[{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"}],dc=[{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"}],pi=[{value:"true",label:"On"},{value:"false",label:"Off"}];function Ei(t,o,n){let r=n??{toast:true,bell:false};return [{id:"activity_filter",label:"Activity filter preset",type:"select",options:dc,defaultValue:t},{id:"max_concurrent",label:"Max concurrent agents",type:"select",options:cc,defaultValue:String(o)},{id:"notifications_toast",label:"Toast notifications",type:"select",options:pi,defaultValue:String(r.toast)},{id:"notifications_bell",label:"Bell on completion",type:"select",options:pi,defaultValue:String(r.bell)}]}function Li(t){let o=t.role==="__custom__"?t.role_custom||void 0:t.role||void 0;return {name:t.name,role:o,model:t.model||void 0,team_id:t.team||void 0}}function qn(t){let o=Un(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:n=>n.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,skip:()=>o.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 Oi(t){return {title:t.title,assignee:t.assignee||void 0,description:t.description||void 0}}function Pi(t,o){let n=Un(o,"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:n,defaultValue:t.assignee??"",skip:()=>n.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 Ni(t){return {title:t.title,assignee:t.assignee||void 0,description:t.description??""}}var Di=10,Fi=500,Qn=2048,ho=500,Wi=5,Gr=new Set(["todo","failed","cancelled"]),fc={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."},pc={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."},hc={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."},Gi=5e3,Vi=0;function Ku(){Vi=0;}var Hi=/^\[[\w_]+\]$/;function ji(t){return Hi.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 Vr=["#5faf87","#5fafd7","#af87ff","#d7af00","#5fd7d7","#d787af","#afaf5f","#d7875f"],xc=" ".repeat(9),er={system:"\u2666",lifecycle:"\u25B6",output:"\u2502",tool:"\u2699",result:"\u2190",error:"\u2715",file:"\u270E",info:"\u2502"},Zn=["system","lifecycle","output","tool","result","error","file","info"],Do=[{label:"all",types:Zn},{label:"text",types:["output"]},{label:"tools",types:["tool","result","file"]},{label:"errors",types:["error"]},{label:"events",types:["lifecycle","system"]}];function zr(t){let n=(Do.findIndex(r=>r.types.length===t.size&&r.types.every(l=>t.has(l)))+1)%Do.length;return Do[n]}function Yu({projectName:t,tasks:o,agents:n=[],state:r,onRunTask:l,onCreateTask:f,onCancelTask:b$1,onRetryTask:T,onAssignTask:x,onRunAll:y,onDisableAgent:I,onEnableAgent:v,onSubscribeEvents:B,onRefreshTasks:C,onRefreshAgents:H,onRefreshState:V,onLoadHistory:F,onAddAgent:P,onDeleteAgent:j,onApproveTask:L,onRejectTask:O,onDeleteTask:N,onUpdateTask:E,onUpdateAgent:G,onForceStopAgent:z,onCreateTeam:X,onListTeams:R,onJoinTeam:ie,onLeaveTeam:Be,onDisbandTeam:Wt,onSetTeamLead:it,onStartWatch:Re,onStopWatch:Xe,onToggleAutonomous:at,onRefreshGoals:mt,onCreateGoal:Pe,onUpdateGoal:qe,onUpdateGoalStatus:lt,onDeleteGoal:Ke,onGetGoalProgress:oo,onCompleteOnboarding:ke,initialWatchActive:ft,watchError:$t,messageBatchMs:Xt=process.env.VITEST?0:80,initialActivityFilter:pt="all",onSaveActivityFilter:Je,initialMaxConcurrent:ct=a.scheduling.max_concurrent_agents,onSaveMaxConcurrent:Fo,initialNotifications:ln,onSaveNotifications:Ct,version:qt,latestVersion:It,onCheckUpdate:no}){let{exit:Gt}=useApp(),{stdout:ht}=useStdout(),[xt,tr]=useState(It),cn=useRef(no);useEffect(()=>{if(It||!cn.current)return;let i=setTimeout(()=>{cn.current?.().then(p=>{p&&tr(p);}).catch(()=>{});},5e3);return ()=>clearTimeout(i)},[It]);let[xo,ro]=useState({w:ht?.columns??80,h:ht?.rows??24});useEffect(()=>{if(!ht)return;let i=()=>ro({w:ht.columns,h:ht.rows});return ht.on("resize",i),()=>{ht.off("resize",i);}},[ht]);let bt=xo.w,A=xo.h,[S,M]=useState(o),[k,Y]=useState(n),[q,Ce]=useState(r),[ae,de]=useState(ft??!!r.pid),[ye,zt]=useState([]),[Wo,dn]=useState(void 0),[Kt,un]=useState(()=>r.onboardingCompleted||(r.stats?.total_tasks_completed??0)>0?"dismissed":Object.keys(r.running??{}).length>0?"run_started":o.length>0?"task_created":"welcome");useEffect(()=>{if(Kt!=="completed")return;let i=setTimeout(()=>{un("dismissed"),ke?.().catch(()=>{});},5e3);return ()=>clearTimeout(i)},[Kt,ke]);let[$,bo]=useState("tasks"),[gn,Go]=useState(0),[or,Hr]=useState(0),[nr,jr]=useState(0),[Ae,zo]=useState(false),[We,Ur]=useState([]),[Ne,Ee]=useState("none"),[so,Mt]=useState(""),[Tt,Ye]=useState(null),[io,Vo]=useState([]),[Bt,rr]=useState(false),[Xr,Zi]=useState(()=>new Set),[To,sr]=useState(false),[Ho,ir]=useState(false),[qr,Kr]=useState(()=>new Set(Zn)),[jo,ar]=useState(-1),[Ji,Uo]=useState(0),[yo,lr]=useState(()=>{let i=Do.find(p=>p.label===pt);return new Set(i?.types??Zn)}),mn=useMemo(()=>Do.find(p=>p.types.length===yo.size&&p.types.every(s=>yo.has(s)))?.label??"all",[yo]),cr=useMemo(()=>yo.size>=Zn.length?We:We.filter(i=>yo.has(i.msgType??"info")),[We,yo]),[Yr,Qi]=useState(ct),[fn,ea]=useState(ln??{toast:true,bell:false}),[ta,Zr]=useState([]),oa=useRef(0),[dr,Jr]=useState(),Qr=useRef($);Qr.current=$;let es=useRef(S);es.current=S;let ts=useRef(k);ts.current=k;let pn=useRef(fn);pn.current=fn;let hn=useCallback((i,p)=>{if(!pn.current.toast)return;let s=es.current.find(h=>h.id===p),d=s?.title??p,u=s?.assignee?ts.current.find(h=>h.id===s.assignee):void 0;Zr(h=>{let g=[...h,{id:`toast_${oa.current++}`,type:i,title:d,agentName:u?.name,ts:Date.now()}];return g.length>Wi?g.slice(g.length-Wi):g}),pn.current.bell&&(i==="failed"||i==="review")&&process.stdout.write("\x07");},[]),na=useCallback(i=>{Zr(p=>p.filter(s=>s.id!==i));},[]),xn=nn.useRef(new Ln).current,[ra,wo]=useState(0),[os,ns]=useState(false),[Xo,sa]=useState(false),[ia,ur]=useState(0),[aa,gr]=useState(0),[mr,So]=useState(0),[bn,fr]=useState(false),[la,qo]=useState(0),[Tn,Yt]=useState(0),[Vt,rs]=useState([]),[ko,pr]=useState([]),Co=useRef(Vt);Co.current=Vt;let J=useCallback(async i=>{let[p,s,d,u,h]=await Promise.all([C?.()??Promise.resolve(S),H?.()??Promise.resolve(k),V?.()??Promise.resolve(q),i?.includeTeams?R?.()??Promise.resolve(Co.current):Promise.resolve(null),mt?.()??Promise.resolve(ye)]);M(p),Y(s),Ce(d),u!==null&&rs(u),zt(h),ft&&de(!!d.pid);},[C,H,V,R,mt,ft]),Io=useMemo(()=>{let i=new Map;for(let p of ye)i.set(p.id,p);return i},[ye]),Le=useMemo(()=>{let i=[...S].sort((h,g)=>(en[h.status]??9)-(en[g.status]??9));if(!Xo)return i;let p=[],s=[],d=[],u=new Map;for(let h of i)h.goalId&&Io.has(h.goalId)?(u.has(h.goalId)||(d.push(h.goalId),u.set(h.goalId,[])),u.get(h.goalId).push(h)):s.push(h);for(let h of d)p.push(...u.get(h));return [...p,...s]},[S,Xo,Io]),Et=os?Le:Le.slice(0,Di),Mo=Le.length-Et.length,U=Le[gn],Ko=useMemo(()=>{let i=new Map;for(let p of S)i.set(p.id,p.title);return i},[S]),ao=useMemo(()=>{let i=new Map;for(let p of k)i.set(p.id,p.name);return i},[k]),ca=useMemo(()=>{let i=new Map;for(let p of S)if(p.goalId){let s=i.get(p.goalId);s||(s=[],i.set(p.goalId,s)),s.push(p);}return i},[S]),yn=useMemo(()=>{let i=new Map;for(let p=0;p<k.length;p++)i.set(k[p].id,Vr[p%Vr.length]);return i},[k]),ss=useMemo(()=>{let i=new Map;for(let p of We)p.agentId&&i.set(p.agentId,(i.get(p.agentId)??0)+1);return i},[We]),da=useMemo(()=>{let i={};for(let p of We){let s=p.msgType??"info";i[s]=(i[s]??0)+1;}return i},[We]),{agentTeamMap:vo,activeTeamCount:Yo,teamLeadSet:ua}=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 u of d.members)i.set(u.agent_id,d.name);}return {agentTeamMap:i,activeTeamCount:s,teamLeadSet:p}},[Vt]),De=useMemo(()=>{let i=[...k];return i.sort((p,s)=>{let d=vo.get(p.id),u=vo.get(s.id);return d&&!u?-1:!d&&u?1:d&&u&&d!==u?d.localeCompare(u):(Mr[p.status]??9)-(Mr[s.status]??9)}),i},[k,vo]),Q=De[or],dt=useMemo(()=>[...ye].sort((i,p)=>(c[i.status]??9)-(c[p.status]??9)),[ye]),te=dt[nr],ga=useMemo(()=>te?S.filter(i=>i.goalId===te.id):[],[te,S]),hr=useRef(oo);hr.current=oo,useEffect(()=>{if(!te||!hr.current){dn(void 0);return}let i=false;return hr.current(te.id).then(p=>{i||dn(p);}).catch(()=>{}),()=>{i=true;}},[te?.id]);let lo=useRef(new Map),wn=useRef(new Map);useEffect(()=>{for(let[i,p]of Object.entries(q.running))lo.current.set(p.run_id,p.agent_id),wn.current.set(p.run_id,i);if(lo.current.size>Fi){let i=lo.current.size-Fi,p=0;for(let s of lo.current.keys()){if(p++>=i)break;lo.current.delete(s),wn.current.delete(s);}}},[q.running]);let co=useRef([]),Zo=useRef(null),xr=useCallback(()=>{if(Zo.current=null,co.current.length===0)return;let i=co.current;co.current=[],Ur(p=>{if(i.length>=ho)return i.slice(-ho);let s=ho-i.length;return (p.length>s?p.slice(-s):p).concat(i)});},[]);useEffect(()=>()=>{Zo.current&&clearTimeout(Zo.current);},[]);let a=useCallback((i,p,s)=>{let d=new Date,u=d.toLocaleTimeString("en-US",{hour12:false,hour:"2-digit",minute:"2-digit",second:"2-digit"}),h=s?.detail&&s.detail.length>Qn?s.detail.slice(0,Qn)+"\u2026[truncated]":s?.detail;co.current.push({text:i,color:p,time:u,ts:d.getTime(),...s,detail:h}),co.current.length>ho&&(co.current=co.current.slice(-ho)),Xt===0?xr():Zo.current||(Zo.current=setTimeout(xr,Xt));},[xr]);useEffect(()=>{$t&&a(`Watch mode failed: ${$t}. Tasks will not auto-dispatch.`,e.red);},[]);let _o=useCallback((i,p,s,d)=>{let u={key:++Vi,entityType:i,entityId:p,entityName:s,expiresAt:Date.now()+Gi,needsForceStop:d?.needsForceStop};pr(h=>[...h,u]),a(`\u2717 "${s}" will be deleted in ${Math.round(Gi/1e3)}s \u2014 press Z to undo`,e.yellow);},[a]),ma=useCallback(()=>{pr(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]),is=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"&&Ke&&await Ke(i.entityId),a(`\u2713 Deleted "${i.entityName}"`,e.green),J();}catch(p){a(`Failed to delete "${i.entityName}": ${p instanceof Error?p.message:String(p)}`,e.red);}},[N,j,Ke,z,a,J]),as=useRef(is);as.current=is,useEffect(()=>{if(ko.length===0)return;let i=setInterval(()=>{let p=Date.now(),s=[];pr(d=>{let u=d.filter(h=>h.expiresAt<=p?(s.push(h),false):true);return s.length>0?u:d});for(let d of s)as.current(d);},1e3);return ()=>clearInterval(i)},[ko.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),u,h=e.silver,g="output";if(p.type==="error")u=typeof p.data=="string"?p.data:JSON.stringify(p.data),u=u.slice(0,200),h=e.red,g="error";else if(p.type==="file_changed")u=String(p.data),h=e.purple,g="file";else if(p.type==="done")u="Completed",h=e.green,g="lifecycle";else if(p.type==="tool_call")u=`\u2699 ${p.data?.name??"tool"}()`,h=e.cyan,g="tool";else {let{summary:w}=Yi(d);if(!w)return null;u=w;let Z=ji(u);g=Z.msgType,h=Z.color;}return {text:u,color:h,time:s,ts:new Date(p.timestamp).getTime(),agentId:p.agentId,taskId:p.taskId,msgType:g}};F(p=>{if(p.length===0)return;let s=p.map(i).filter(d=>d!==null);Ur(d=>{let u=[...s,...d];return u.length>ho?u.slice(-ho):u});}).catch(p=>{process.stderr.write(`[TUI] onLoadHistory error: ${p instanceof Error?p.stack??p.message:String(p)}
12
- `);});},[]),useEffect(()=>{R?.().then(rs).catch(()=>{}),mt?.().then(zt).catch(()=>{});},[]);let Sn=useCallback(()=>{Ye({title:"NEW AGENT",steps:Xn(k,Co.current),kind:"agent"}),Ee("wizard");},[k]),ls=useCallback(()=>{Ye({title:"AGENT SHOP",steps:Ci(),kind:"agent_shop"}),Ee("wizard");},[]),kn=useCallback(()=>{Vo([]),Ye({title:"NEW TASK",steps:_i(k),kind:"task"}),Ee("wizard");},[k]),fa=useCallback(async()=>{try{let{detectClipboardType:i,getClipboardImage:p}=await import('./clipboard-service-WVON5ZN4.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:u,writeFile:h}=await import('fs/promises'),{tmpdir:g}=await import('os'),{join:w}=await import('path'),Z=await u(w(g(),"orch-paste-")),Ot=w(Z,`clipboard-${Date.now()}.${d.ext}`);return await h(Ot,d.data),Vo(uo=>[...uo,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]),pa=useCallback(i=>{Ye({title:"EDIT TASK",steps:Ai(i,k),kind:"edit_task",targetId:i.id}),Ee("wizard");},[k]),cs=useCallback(()=>{Ye({title:"NEW TEAM",steps:Mi(k,Vt),kind:"team"}),Ee("wizard");},[k]),ha=useCallback(i=>{Ye({title:"EDIT AGENT",steps:Bi(i,k,Vt),kind:"edit_agent",targetId:i.id}),Ee("wizard");},[Vt]),ds=useCallback(()=>{Ye({title:"SETTINGS",steps:Ei(mn,Yr,fn),kind:"config"}),Ee("wizard");},[mn,Yr]),xa=useCallback(i=>{Ee("none");let p=Tt?.kind,s=Tt?.targetId;if(Ye(null),p==="agent_shop"){let d=i.shop_template,u=d?b(d):void 0;if(u){let h=Xn(k,Co.current),g=Wr(h,u);Ye({title:`NEW AGENT \u2014 ${u.name}`,steps:g,kind:"agent_from_shop"}),Ee("wizard");}else a("No template selected",e.yellow);return}if((p==="agent"||p==="agent_from_shop")&&P){let d=Ii(i);a(`Creating agent "${d.name}"...`,e.amber),P(d.name,d.adapter,{model:d.model,role:d.role,approval_policy:d.approval_policy,skills:d.skills}).then(u=>{a(`\u2713 Created agent "${u.name}" (${u.id}, ${u.adapter})`,e.green),d.team_id&&ie?ie(d.team_id,u.id).then(h=>{a(`\u2713 Joined team "${h.name}"`,e.green),J({includeTeams:true});},h=>a(`Failed to join team: ${h instanceof Error?h.message:String(h)}`,e.red)):J();},u=>a(`Failed: ${u instanceof Error?u.message:String(u)}`,e.red));}else if(p==="team"&&X){let d=vi(i);a(`Creating team "${d.name}"...`,e.amber),X(d).then(u=>{a(`\u2713 Created team "${u.name}" (${u.id}, ${u.members.length} members)`,e.green),J({includeTeams:true});},u=>a(`Failed: ${u instanceof Error?u.message:String(u)}`,e.red));}else if(p==="task"&&f){let d=Ri(i),u=io.length>0?[...io]:void 0;Vo([]),a(`Creating "${d.title}"...`,e.amber),f(d.title,{priority:d.priority,description:d.description,attachments:u}).then(h=>{a(`\u2713 Created "${h.title}" (${h.id})${u?` \u{1F4CE}${u.length}`:""}`,e.green),d.assignee&&x&&x(h.id,d.assignee).catch(()=>{}),J();},h=>a(`Failed: ${h instanceof Error?h.message:String(h)}`,e.red));}else if(p==="edit_task"&&s&&E){let d=$i(i),u=io.length>0?[...io]:void 0;Vo([]),a("Updating task...",e.amber),E(s,{...d,attachments:u}).then(h=>{a(`\u2713 Updated "${h.title}"${u?` \u{1F4CE}${u.length}`:""}`,e.green),d.assignee&&x&&x(s,d.assignee).catch(()=>{}),J();},h=>a(`Failed: ${h instanceof Error?h.message:String(h)}`,e.red));}else if(p==="edit_agent"&&s&&G){let d=Li(i),u=d.team_id??"",h=Vt.find(g=>g.members.some(w=>w.agent_id===s))?.id??"";a("Updating agent...",e.amber),G(s,{name:d.name,role:d.role,model:d.model}).then(g=>{a(`\u2713 Updated agent "${g.name}"`,e.green);let w=[];h&&h!==u&&Be&&w.push(Be(h,s).then(Z=>a(`\u2713 Left team "${Z.name}"`,e.green),Z=>a(`Failed to leave team: ${Z instanceof Error?Z.message:String(Z)}`,e.red))),u&&u!==h&&ie&&w.push(ie(u,s).then(Z=>a(`\u2713 Joined team "${Z.name}"`,e.green),Z=>a(`Failed to join team: ${Z instanceof Error?Z.message:String(Z)}`,e.red))),Promise.all(w).then(()=>J({includeTeams:w.length>0}));},g=>a(`Failed: ${g instanceof Error?g.message:String(g)}`,e.red));}else if(p==="config"){if(i.activity_filter){let g=Do.find(w=>w.label===i.activity_filter);g&&(lr(new Set(g.types)),Je?.(g.label));}if(i.max_concurrent){let g=parseInt(i.max_concurrent,10);g>0&&(Qi(g),Fo?.(g));}let d=i.notifications_toast==="true",u=i.notifications_bell==="true",h={toast:d,bell:u};ea(h),Ct?.(h),a("Settings saved",e.green);}else if(p==="goal"&&Pe){let d=Oi(i);a(`Creating goal "${d.title}"...`,e.amber),Pe(d).then(u=>{a(`\u2713 Created goal "${u.title}" (${u.id})`,e.green),J();},u=>a(`Failed: ${u instanceof Error?u.message:String(u)}`,e.red));}else if(p==="edit_goal"&&s&&qe){let d=Ni(i);a("Updating goal...",e.amber),qe(s,d).then(u=>{a(`\u2713 Updated goal "${u.title}"`,e.green),J();},u=>a(`Failed: ${u instanceof Error?u.message:String(u)}`,e.red));}},[Tt,P,f,X,ie,Be,x,E,G,at,Pe,qe,a,J,Je,Fo,fn,Ct,Vt,io]),ba=useCallback(()=>{Ee("none"),Ye(null),Vo([]);},[]),Ta=useCallback(i=>{let p=b(i);if(!p)return;let s=Xn(k,Co.current),d=Wr(s,p);Ye({title:`NEW AGENT \u2014 ${p.name}`,steps:d,kind:"agent_from_shop"}),Ee("wizard");},[]);useEffect(()=>{if(!B)return;let i=null,p=()=>{i||(i=setTimeout(()=>{i=null,J().catch(()=>{});},150));},s=B(d=>{if(d.type==="agent:started"&&(lo.current.set(d.runId,d.agentId),wn.current.set(d.runId,d.taskId)),Pc(d,a,lo.current,wn.current),d.type==="task:created"?un(u=>u==="welcome"?"task_created":u):d.type==="agent:started"?un(u=>u==="task_created"?"run_started":u):d.type==="task:status_changed"&&d.to==="done"&&un(u=>u==="run_started"?"completed":u),d.type==="task:status_changed"&&(d.to==="done"?hn("done",d.taskId):d.to==="failed"?hn("failed",d.taskId):d.to==="review"&&hn("review",d.taskId),pn.current.toast&&Qr.current!=="tasks")){let u=d.to==="done"?e.green:d.to==="failed"?e.red:d.to==="review"?e.blue:void 0;u&&Jr({tab:"tasks",color:u});}(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);}},[B,a,J,hn]);let br=ae?"watching":"idle",ya=q.started_at?g(q.started_at):void 0,us=q.stats.total_tokens.total,gs=useMemo(()=>{let i={running:0,retrying:0,review:0,todo:0,done:0,failed:0,cancelled:0};for(let p of S)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:Yo}},[S,Yo]);gs.running;let wa=useMemo(()=>({input:q.stats.total_tokens.input??0,output:q.stats.total_tokens.output??0,reasoning:q.stats.total_tokens.reasoning??0,total:us,cache_read:q.stats.total_tokens.cache_read??0,cache_write:q.stats.total_tokens.cache_write??0}),[q.stats.total_tokens,us]),vt=Math.max(4,A-9),Sa=vo.size,ka=k.length>Sa,Ca=Yo>0?Yo+(ka?1:0):0,Ia=useMemo(()=>{if(!Xo||Io.size===0)return 0;let i=0,p=new Set,s=false;for(let d of Et)d.goalId&&Io.has(d.goalId)?p.has(d.goalId)||(p.add(d.goalId),i++):s=true;return s&&i++,i},[Xo,Io,Et]),Ma=$==="goals"?dt.length+1:$==="tasks"?Et.length+1+(Mo>0?1:0)+Ia:$==="agents"?k.length+1+Ca:0,va=Math.min(Ma+1,Math.ceil(vt*.5)),_a=$==="logs"?vt:Math.max(2,Math.min(va,vt-4)),we,Lt;if($==="logs")we=vt,Lt=0;else if(bn)we=0,Lt=Math.max(1,vt);else {let i=Math.max(3,Math.min(_a+mr,vt-4));we=i,Lt=Math.max(1,vt-i);}let ve=Math.max(10,bt-2),_t=useMemo(()=>Ne==="command"?Hs(so):[],[Ne,so]),Ro=vt-4-3;useEffect(()=>{mr>Ro&&So(Ro),mr<-Ro&&So(-Ro);},[vt]),useEffect(()=>{wo(i=>Math.min(i,Math.max(0,Et.length-we)));},[Et.length,we]),useEffect(()=>{ur(i=>Math.min(i,Math.max(0,De.length-we)));},[De.length,we]),useEffect(()=>{gr(i=>Math.min(i,Math.max(0,dt.length-we)));},[dt.length,we]);let Ra=useCallback(i=>{let s=i.trim().replace(/^\//,"").split(/\s+/),d=s[0]?.toLowerCase();if(!d)return;let u=h=>h instanceof Error?h.message:String(h);switch(d){case "cancel":{if(!U){a("No task selected",e.yellow);return}if(!b$1)return;a(`Cancelling "${U.title}"...`,e.amber),b$1(U.id).then(()=>{a(`\u2713 Cancelled "${U.title}"`,e.green),J();},h=>a(`Failed: ${u(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),J();},h=>a(`Failed: ${u(h)}`,e.red));return}case "assign":{if(!U){a("No task selected",e.yellow);return}if(!x||!s[1]){a("Usage: assign <agent>",e.yellow);return}a(`Assigning "${U.title}" to ${s[1]}...`,e.amber),x(U.id,s[1]).then(()=>{a(`\u2713 Assigned "${U.title}" to ${s[1]}`,e.green),J();},h=>a(`Failed: ${u(h)}`,e.red));return}case "task":{let h=s[1]?.toLowerCase();if(h==="add"){let g=s.slice(2).join(" ");if(!g){kn();return}if(!f){a("Create not available",e.yellow);return}a(`Creating "${g}"...`,e.amber),f(g).then(w=>{a(`\u2713 Created "${w.title}" (${w.id})`,e.green),J();},w=>a(`Failed: ${u(w)}`,e.red));}else if(h==="list"){let g=Le.map(w=>` ${w.id} ${w.status.padEnd(11)} ${w.title}`);if(g.length===0)a("No tasks",e.dim);else for(let w of g)a(w,e.cyan);}else if(h==="show"){let g=s[2]?Le.find(w=>w.id===s[2]):U;if(!g){a("No task selected or id given",e.yellow);return}a(`${g.id} ${g.status} P${g.priority} "${g.title}"`,e.cyan),g.assignee&&a(` agent: ${g.assignee}`,e.dim),g.description&&a(` ${g.description.slice(0,100)}`,e.dim);}else if(h==="cancel"){let g=s[2]?Le.find(w=>w.id===s[2]):U;if(!g){a("No task selected or id given",e.yellow);return}if(!b$1)return;a(`Cancelling "${g.title}"...`,e.amber),b$1(g.id).then(()=>{a(`\u2713 Cancelled "${g.title}"`,e.green),J();},w=>a(`Failed: ${u(w)}`,e.red));}else if(h==="retry"){let g=s[2]?Le.find(w=>w.id===s[2]):U;if(!g){a("No task selected or id given",e.yellow);return}if(!T)return;a(`Retrying "${g.title}"...`,e.amber),T(g.id).then(()=>{a(`\u2713 Retried "${g.title}"`,e.green),J();},w=>a(`Failed: ${u(w)}`,e.red));}else if(h==="assign"){let g=s[2]?Le.find(Ot=>Ot.id===s[2]):void 0,w=g??U,Z=g?s[3]:s[2];if(!w){a("No task selected or id given",e.yellow);return}if(!Z){a("Usage: /task assign [id] <agent>",e.yellow);return}if(!x)return;a(`Assigning "${w.title}" to ${Z}...`,e.amber),x(w.id,Z).then(()=>{a(`\u2713 Assigned "${w.title}" to ${Z}`,e.green),J();},Ot=>a(`Failed: ${u(Ot)}`,e.red));}else if(h==="approve"){let g=s[2]?Le.find(w=>w.id===s[2]):U;if(!g){a("No task selected or id given",e.yellow);return}if(g.status!=="review"){a(`Cannot approve \u2014 status is ${g.status}`,e.yellow);return}if(!L)return;a(`Approving "${g.title}"...`,e.amber),L(g.id).then(()=>{a(`\u2713 Approved "${g.title}"`,e.green),J();},w=>a(`Failed: ${u(w)}`,e.red));}else if(h==="reject"){let g=s[2]?Le.find(Z=>Z.id===s[2]):U;if(!g){a("No task selected or id given",e.yellow);return}if(g.status!=="review"){a(`Cannot reject \u2014 status is ${g.status}`,e.yellow);return}if(!O)return;let w=s.slice(s[2]&&Le.find(Z=>Z.id===s[2])?3:2).join(" ").trim()||void 0;a(`Rejecting "${g.title}"${w?" with feedback":""}...`,e.amber),O(g.id,w).then(()=>{a(`\u2713 Rejected "${g.title}" \u2192 todo`,e.green),J();},Z=>a(`Failed: ${u(Z)}`,e.red));}else if(h==="delete"){let g=s[2]?Le.find(w=>w.id===s[2]):U;if(!g){a("No task selected or id given",e.yellow);return}if(g.status==="in_progress"){a("Cannot delete \u2014 task is running",e.yellow);return}if(!N)return;_o("task",g.id,g.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 g=s[2];if(!g){Sn();return}if(!P){a("Agent creation not available",e.yellow);return}let w=s[3];a(`Creating agent "${g}"...`,e.amber),P(g,w).then(Z=>{a(`\u2713 Created agent "${Z.name}" (${Z.id}, ${Z.adapter})`,e.green),J();},Z=>a(`Failed: ${u(Z)}`,e.red));}else if(h==="list"){let g=De.map(w=>` ${w.id} ${w.status.padEnd(8)} ${w.name} (${w.adapter})`);if(g.length===0)a("No agents",e.dim);else for(let w of g)a(w,e.cyan);}else if(h==="disable"){let g=s[2]?De.find(w=>w.id===s[2]||w.name===s[2]):Q;if(!g){a("No agent selected or id given",e.yellow);return}if(!I)return;a(`Disabling ${g.name}...`,e.amber),I(g.id).then(()=>{a(`\u2713 Disabled ${g.name}`,e.green),J();},w=>a(`Failed: ${u(w)}`,e.red));}else if(h==="enable"){let g=s[2]?De.find(w=>w.id===s[2]||w.name===s[2]):Q;if(!g){a("No agent selected or id given",e.yellow);return}if(!v)return;a(`Enabling ${g.name}...`,e.amber),v(g.id).then(()=>{a(`\u2713 Enabled ${g.name}`,e.green),J();},w=>a(`Failed: ${u(w)}`,e.red));}else if(h==="delete"||h==="remove"){let g=s[2]?De.find(w=>w.id===s[2]||w.name===s[2]):Q;if(!g){a("No agent selected or id given",e.yellow);return}if(g.status==="running"){a("Cannot delete \u2014 agent is running",e.yellow);return}if(!j){a("Agent deletion not available",e.yellow);return}_o("agent",g.id,g.name);}else if(h==="autonomous"||h==="auto"){let g=s[2]?De.find(w=>w.id===s[2]||w.name===s[2]):Q;if(!g){a("No agent selected or id given",e.yellow);return}if(!at){a("Autonomous toggle not available",e.yellow);return}g.autonomous?(a(`Disabling autonomous mode for "${g.name}"...`,e.amber),at(g.id,false).then(()=>{a(`${go} ${g.name} autonomous OFF`,e.cyan),J();},w=>a(`Failed: ${u(w)}`,e.red))):(a(`Enabling autonomous mode for "${g.name}"...`,e.amber),at(g.id,true).then(()=>{a(`${go} ${g.name} autonomous ON`,e.cyan),J();},w=>a(`Failed: ${u(w)}`,e.red)));}else h==="shop"?ls():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")cs();else if(h==="list"){let g=Co.current;if(g.length===0)a("No teams",e.dim);else for(let w of g)a(` ${w.id} ${w.status.padEnd(8)} ${w.name} (${w.members.length} members)`,e.cyan);}else if(h==="join"){if(!ie){a("Join not available",e.yellow);return}let g=s[2],w=s[3]??Q?.id;if(!g||!w){a("Usage: /team join <teamId> [agentId]",e.yellow);return}a(`Joining team ${g}...`,e.amber),ie(g,w).then(Z=>{a(`\u2713 Agent joined team "${Z.name}"`,e.green),J({includeTeams:true});},Z=>a(`Failed: ${u(Z)}`,e.red));}else if(h==="leave"){if(!Be){a("Leave not available",e.yellow);return}let g=s[2],w=s[3]??Q?.id;if(!g||!w){a("Usage: /team leave <teamId> [agentId]",e.yellow);return}a(`Leaving team ${g}...`,e.amber),Be(g,w).then(Z=>{a(`\u2713 Agent left team "${Z.name}"`,e.green),J({includeTeams:true});},Z=>a(`Failed: ${u(Z)}`,e.red));}else if(h==="disband"){if(!Wt){a("Disband not available",e.yellow);return}let g=s[2];if(!g){a("Usage: /team disband <teamId>",e.yellow);return}a(`Disbanding team ${g}...`,e.amber),Wt(g).then(()=>{a("\u2713 Team disbanded",e.green),J({includeTeams:true});},w=>a(`Failed: ${u(w)}`,e.red));}else if(h==="set-lead"){if(!it){a("Set-lead not available",e.yellow);return}let g=s[2],w=s[3];if(!g||!w){a("Usage: /team set-lead <teamId> <agentId>",e.yellow);return}a(`Setting lead for team ${g}...`,e.amber),it(g,w).then(Z=>{a(`\u2713 New lead for team "${Z.name}"`,e.green),J({includeTeams:true});},Z=>a(`Failed: ${u(Z)}`,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 g=s.slice(2).join(" ").trim();if(!g){let w=qn(k);Ye({title:"New Goal",steps:w,kind:"goal"}),Ee("wizard");return}if(!Pe){a("Goal creation not available",e.yellow);return}a(`Creating goal "${g}"...`,e.amber),Pe({title:g}).then(w=>{a(`\u2713 Created goal "${w.title}" (${w.id})`,e.green),J();},w=>a(`Failed: ${u(w)}`,e.red));}else if(h==="list"){let g=dt.map(w=>` ${w.id} ${w.status.padEnd(8)} ${w.title}`);if(g.length===0)a("No goals",e.dim);else for(let w of g)a(w,e.cyan);}else if(h==="show"){let g=s[2]?dt.find(w=>w.id===s[2]):te;if(!g){a("No goal selected or id given",e.yellow);return}a(`${g.id} ${g.status} "${g.title}"`,e.cyan),g.description&&a(` ${g.description.slice(0,100)}`,e.dim);}else if(h==="status"){let g=s[2]?dt.find(uo=>uo.id===s[2]):void 0,w=g??te;if(!w){a("No goal selected or id given",e.yellow);return}let Z=s[g?3:2];if(!Z||!a$1.includes(Z)){a("Usage: /goal status [id] <active|paused|achieved|abandoned>",e.yellow);return}let Ot=Z;if(!lt){a("Status update not available",e.yellow);return}a(`Updating goal status to ${Ot}...`,e.amber),lt(w.id,Ot).then(uo=>{a(`\u2713 Goal "${uo.title}" \u2192 ${Ot}`,e.green),J();},uo=>a(`Failed: ${u(uo)}`,e.red));}else if(h==="delete"){let g=s[2]?dt.find(w=>w.id===s[2]):te;if(!g){a("No goal selected or id given",e.yellow);return}if(!Ke){a("Goal deletion not available",e.yellow);return}_o("goal",g.id,g.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 g=Le.find(w=>w.id===h);if(g&&!Gr.has(g.status)){a(`Cannot run \u2014 status is ${g.status}`,e.yellow);return}a(`Running ${h}...`,e.amber),l(h).then(()=>{a(`\u2713 Dispatched ${h}`,e.green),J();},w=>a(`Failed: ${u(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),J();},h=>a(`Failed: ${u(h)}`,e.red));return}case "watch":{if(ae){a("Watch mode already active",e.yellow);return}if(!Re){a("Watch not available",e.yellow);return}a("Starting watch mode...",e.amber),Re().then(()=>{de(true),a("\u2713 Watch mode started",e.green);},h=>a(`Failed: ${u(h)}`,e.red));return}case "pause":{if(!ae){a("Watch mode not active",e.yellow);return}if(!Xe){a("Pause not available",e.yellow);return}a("Pausing watch mode...",e.amber),Xe().then(()=>{de(false),a("\u2713 Watch mode paused",e.green);},h=>a(`Failed: ${u(h)}`,e.red));return}case "config":{s[1]?.toLowerCase()==="activity-filter"?lr(g=>{let w=zr(g);return Je?.(w.label),a(`Activity filter: ${w.label}`,e.amber),new Set(w.types)}):ds();return}case "status":{let h=S.filter(g=>g.status==="in_progress").length;a(`${br} ${h} running ${S.length} tasks ${De.length} agents`,e.cyan);return}case "help":{for(let[h,g]of Object.entries(fo)){let w=g.sub?" "+g.sub.join("|"):g.args?" "+g.args:"";a(` /${h}${w} \u2014 ${g.help}`,e.silver);}return}case "quit":{Gt();return}case "disable":{if(!Q){a("No agent selected",e.yellow);return}if(!I)return;a(`Disabling ${Q.name}...`,e.amber),I(Q.id).then(()=>{a(`\u2713 Disabled ${Q.name}`,e.green),J();},h=>a(`Failed: ${u(h)}`,e.red));return}case "enable":{if(!Q){a("No agent selected",e.yellow);return}if(!v)return;a(`Enabling ${Q.name}...`,e.amber),v(Q.id).then(()=>{a(`\u2713 Enabled ${Q.name}`,e.green),J();},h=>a(`Failed: ${u(h)}`,e.red));return}default:a(`Unknown: ${d}. Type /help for commands`,e.yellow);}},[U,Q,Le,De,S,br,ae,b$1,T,x,y,l,f,I,v,P,L,O,N,ie,Be,Wt,it,Re,Xe,a,Gt,J,kn,Sn,cs,ds]);useInput((i,p)=>{if(!(Bt&&(rr(false),i==="?"||p.escape||i==="\x1BOP"))&&!To){if((p.ctrl||p.meta)&&i==="s"&&Ne==="wizard"&&Tt?.kind==="agent"){ls();return}if(Ne!=="none"){if(p.escape){Ee("none"),Mt(""),xn.reset();return}if(p.return){let s=so.trim();if(!s)return;if(Ne==="new_task"){if(!f)return;Ee("none"),Mt(""),a(`Creating "${s}"...`,e.amber),f(s).then(d=>{a(`\u2713 Created "${d.title}" (${d.id})`,e.green),J();},d=>a(`Failed to create: ${d instanceof Error?d.message:String(d)}`,e.red));}else if(Ne==="command"){let d=s;if(_t.length>0&&_t[Tn]){let u=_t[Tn],h=u.cmd.replace(/\s+\[.*\]$/,"");if((h.startsWith(s)||s==="/")&&(d=h),u.subs&&!h.includes(" ")){Mt(h+" "),Yt(0);return}}Ee("none"),Mt(""),Yt(0),xn.push(d),Ra(d);}return}if(p.tab&&Ne==="command"){if(_t.length>0){let s=_t[Tn];if(s){let d=s.cmd.replace(/\s+\[.*\]$/,"");Mt(d+(s.subs?" ":"")),Yt(0);}}else {let s=_r(so);s&&Mt(d=>d+s);}return}if(p.upArrow&&Ne==="command"){if(_t.length>0)Yt(s=>Math.max(0,s-1));else {let s=xn.prev();s!==null&&Mt(s);}return}if(p.downArrow&&Ne==="command"){if(_t.length>0)Yt(s=>Math.min(_t.length-1,s+1));else {let s=xn.next();Mt(s??"");}return}if(p.backspace||p.delete){Mt(s=>s.slice(0,-1)),Yt(0);return}i&&!p.ctrl&&!p.meta&&(Mt(s=>s+i),Yt(0));return}if(i.toLowerCase()==="q"){Gt();return}if(p.escape){if(Ae){zo(false),qo(0);return}if($==="logs"&&jo>=0){ar(-1),Uo(0);return}return}if((i==="+"||i==="=")&&$!=="logs"){bn?(fr(false),So(-Math.floor(vt/2))):So(s=>Math.max(-Ro,s-3));return}if(i==="-"&&$!=="logs"){bn?(fr(false),So(Math.floor(vt/2))):So(s=>Math.min(Ro,s+3));return}if(i==="M"&&$!=="logs"){fr(s=>!s);return}if(i==="?"){rr(true);return}if(i==="\x1BOP"){rr(true);return}if(i==="/"&&!Ae){Ee("command"),Mt("/"),Yt(0);return}if((i==="a"||i==="A")&&$==="logs"&&!Ae&&!To&&!Ho){sr(true);return}if(i==="f"&&$==="logs"&&!Ae&&!To&&!Ho){ir(true);return}if(i==="F"&&$==="logs"&&!Ae&&!To&&!Ho){Kr(s=>new Set(zr(s).types));return}if((i==="z"||i==="Z")&&ko.length>0){ma();return}if((i==="f"||i==="F")&&($==="tasks"||$==="agents"||$==="goals")&&!Ae){lr(s=>{let d=zr(s);return Je?.(d.label),new Set(d.types)});return}if((i==="n"||i==="N")&&$==="tasks"&&!Ae&&f){kn();return}if((i==="n"||i==="N")&&$==="agents"&&!Ae&&P){Sn();return}if((i==="n"||i==="N")&&$==="goals"&&!Ae&&Pe){let s=qn(k);Ye({title:"New Goal",steps:s,kind:"goal"}),Ee("wizard");return}if((i==="e"||i==="E")&&$==="goals"&&te&&qe){let s=Pi(te,k);Ye({title:`Edit Goal: ${te.title}`,steps:s,kind:"edit_goal",targetId:te.id}),Ee("wizard");return}if((i==="d"||i==="D")&&$==="goals"&&te&&Ke){_o("goal",te.id,te.title);return}if((i==="c"||i==="C")&&$==="goals"&&te&&lt){(te.status==="active"||te.status==="paused")&&(a(`Marking goal "${te.title}" as achieved...`,e.amber),lt(te.id,"achieved").then(()=>{a(`\u2713 Goal "${te.title}" achieved`,e.green),J();},s=>a(`Failed: ${s instanceof Error?s.message:String(s)}`,e.red)));return}if((i==="x"||i==="X")&&$==="goals"&&te&&lt){(te.status==="active"||te.status==="paused")&&(a(`Abandoning goal "${te.title}"...`,e.amber),lt(te.id,"abandoned").then(()=>{a(`\u2713 Goal "${te.title}" abandoned`,e.dim),J();},s=>a(`Failed: ${s instanceof Error?s.message:String(s)}`,e.red)));return}if((i==="p"||i==="P")&&$==="goals"&&te&&lt){let s=te.status==="paused"?"active":"paused";(te.status==="active"||te.status==="paused")&&lt(te.id,s).then(()=>{a(`Goal "${te.title}" ${s}`,e.cyan),J();},d=>a(`Failed: ${d instanceof Error?d.message:String(d)}`,e.red));return}if((i==="a"||i==="A")&&$==="tasks"&&U?.status==="review"&&L){a(`Approving "${U.title}"...`,e.amber),L(U.id).then(()=>{a(`\u2713 Approved "${U.title}"`,e.green),J();},s=>a(`Failed: ${s instanceof Error?s.message:String(s)}`,e.red));return}if((i==="x"||i==="X")&&$==="tasks"&&U?.status==="review"&&O){a(`Rejecting "${U.title}"...`,e.amber),O(U.id).then(()=>{a(`\u2713 Rejected "${U.title}" \u2192 todo`,e.green),J();},s=>a(`Failed: ${s instanceof Error?s.message:String(s)}`,e.red));return}if((i==="c"||i==="C")&&$==="tasks"&&U&&b$1){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),b$1(U.id).then(()=>{a(`\u2713 Cancelled "${U.title}"`,e.green),J();},s=>a(`Failed: ${s instanceof Error?s.message:String(s)}`,e.red));return}if((i==="e"||i==="E")&&$==="tasks"&&U&&E){pa(U);return}if((i==="e"||i==="E")&&$==="agents"&&Q&&G){ha(Q);return}if((i==="s"||i==="S")&&$==="tasks"){ns(s=>!s),Go(0),wo(0);return}if((i==="g"||i==="G")&&$==="tasks"&&!Ae){sa(s=>!s),Go(0),wo(0);return}if((i==="s"||i==="S")&&$==="agents"&&Q&&z){if(!Object.values(q.running).some(d=>d.agent_id===Q.id)&&Q.status!=="running"){a(`Agent "${Q.name}" is not running`,e.yellow);return}a(`Force-stopping agent "${Q.name}"...`,e.amber),z(Q.id).then(()=>{a(`\u2713 Stopped agent "${Q.name}"`,e.green),J();},d=>a(`Failed: ${d instanceof Error?d.message:String(d)}`,e.red));return}if((i==="d"||i==="D")&&$==="tasks"&&U&&U.status!=="in_progress"&&N){_o("task",U.id,U.title);return}if((i==="d"||i==="D")&&$==="agents"&&Q&&j){let s=Object.values(q.running).some(d=>d.agent_id===Q.id);if(s&&!z){a(`Cannot delete \u2014 agent "${Q.name}" is running. Press S to stop first.`,e.yellow);return}_o("agent",Q.id,Q.name,{needsForceStop:s});return}if((i==="u"||i==="U")&&$==="agents"&&Q&&at){let s=!Q.autonomous;a(`${s?"Enabling":"Disabling"} autonomous mode for "${Q.name}"...`,e.amber),at(Q.id,s).then(()=>{a(`${go} ${Q.name} autonomous ${s?"ON":"OFF"}`,e.cyan),J();},d=>a(`Failed: ${d instanceof Error?d.message:String(d)}`,e.red));return}if(!Ae){if(i==="g"||i==="G"){bo("goals");return}if(i==="t"||i==="T"){bo("tasks");return}if(i==="a"||i==="A"){bo("agents");return}if(i==="l"||i==="L"){bo("logs");return}}if(!Ae){let s=$n.map(u=>u.id),d=s.indexOf($);if(p.tab||p.rightArrow){bo(s[(d+1)%s.length]);return}if(p.leftArrow){bo(s[(d+s.length-1)%s.length]);return}}if(p.return){let s=Mo>0?Et.length:-1;if($==="tasks"&&gn===s){ns(u=>!u),Go(0),wo(0);return}let d=Et.length+(Mo>0?1:0);if($==="tasks"&&gn===d&&f){kn();return}if($==="goals"&&nr===dt.length&&Pe){let u=qn(k);Ye({title:"New Goal",steps:u,kind:"goal"}),Ee("wizard");return}if($==="agents"&&or===De.length&&P){Sn();return}if($==="goals"&&te){zo(u=>!u),qo(0);return}if($==="tasks"&&U){zo(u=>!u);return}if($==="agents"&&Q){zo(u=>!u);return}if($==="logs"&&jo>=0){zo(u=>!u);return}}if((i==="r"||i==="R")&&$==="tasks"&&U&&l){if(!Gr.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),J();},s=>a(`Failed to run: ${s instanceof Error?s.message:String(s)}`,e.red));return}if(p.upArrow||i==="k"){if($==="goals"&&Ae){qo(s=>Math.max(0,s-1));return}$==="goals"?jr(s=>{let d=Math.max(0,s-1);return gr(u=>d<u?d:u),d}):$==="tasks"?Go(s=>{let d=Math.max(0,s-1);return wo(u=>d<u?d:u),d}):$==="agents"?Hr(s=>{let d=Math.max(0,s-1);return ur(u=>d<u?d:u),d}):$==="logs"&&ar(s=>{if(s===-1){let u=We.length-1;return Uo(Math.max(0,u-we+2)),Math.max(0,u)}let d=Math.max(0,s-1);return Uo(u=>d<u?d:u),d});}if(p.downArrow||i==="j"){if($==="goals"&&Ae){qo(s=>s+1);return}if($==="goals"){let s=dt.length+(Pe?1:0)-1;jr(d=>{let u=Math.min(Math.max(0,s),d+1);return gr(h=>u>=h+we?u-we+1:h),u});}else if($==="tasks"){let s=Et.length+(f?1:0)+(Mo>0?1:0)-1;Go(d=>{let u=Math.min(Math.max(0,s),d+1);return wo(h=>u>=h+we?u-we+1:h),u});}else if($==="agents"){let s=De.length+(P?1:0)-1;Hr(d=>{let u=Math.min(Math.max(0,s),d+1);return ur(h=>u>=h+we?u-we+1:h),u});}else $==="logs"&&ar(s=>{if(s===-1)return -1;let d=We.length-1;if(s>=d)return Uo(0),-1;let u=s+1;return Uo(h=>u>=h+we-1?u-we+2:h),u});}}});let Qe=Ne!=="none",ms=jo>=0?We[jo]:void 0,Cn=bn?"+/- exit max":"+/- resize \u2502 M max",fs=!Qe&&Ae&&$==="tasks"&&U,ps=!Qe&&Ae&&$==="agents"&&Q,hs=!Qe&&Ae&&$==="goals"&&te,Aa=!Qe&&Ae&&$==="logs"&&ms,Tr=U?.id,$a=useMemo(()=>Tr?We.filter(i=>i.taskId===Tr):[],[We,Tr]),Ba=!Qe&&$==="tasks"&&U&&Gr.has(U.status)&&!!l,Ea=!Qe&&!Ae&&($==="goals"&&!!Pe||$==="tasks"&&!!f||$==="agents"&&!!P),La=!Qe&&$==="tasks"&&U?.status==="review"&&!!L,Oa=!Qe&&$==="tasks"&&U?.status==="review"&&!!O,Pa=Q?Object.values(q.running).some(i=>i.agent_id===Q.id):false,Na=!Qe&&($==="goals"&&te&&!!Ke||$==="tasks"&&U&&U.status!=="in_progress"&&!!N||$==="agents"&&Q&&!!j),Da=!Qe&&!Ae&&($==="goals"&&!!te&&!!qe||$==="tasks"&&!!U&&!!E||$==="agents"&&!!Q&&!!G),Fa=!Qe&&$==="agents"&&Q&&(Pa||Q.status==="running")&&!!z,Wa=!Qe&&$==="agents"&&!!Q&&!!at,Ga=!Qe&&$==="goals"&&!!te&&(te.status==="active"||te.status==="paused")&&!!lt,za=!Qe&&ko.length>0,xs=Ne==="command"&&_t.length>0,bs=Tt?.kind==="task"||Tt?.kind==="edit_task";return jsxs(Box,{flexDirection:"column",width:bt,height:A,children:[jsx(Vs,{projectName:t,activeView:$,mode:br,stats:gs,tokens:wa,uptime:ya,width:bt,version:qt,latestVersion:xt,taskBadge:Mo>0?Le.length:void 0,flashTab:dr?.tab,flashColor:dr?.color,onFlashComplete:dr?()=>Jr(void 0):void 0}),jsx(Box,{height:1}),Bt&&jsx(mi,{width:bt,height:A-7}),!Bt&&Kt==="welcome"&&$==="tasks"&&jsx(ni,{width:bt,height:A}),!Bt&&$==="goals"&&jsx(yc,{goals:dt,selectedIndex:nr,scrollOffset:aa,height:we,width:ve,showAddRow:!!Pe,agentNameMap:ao,tasksByGoalMap:ca}),!Bt&&Kt!=="welcome"&&$==="tasks"&&jsx(Sc,{tasks:Et,selectedIndex:gn,scrollOffset:ra,height:we,width:ve,showAddRow:!!f,agentNameMap:ao,hiddenCount:Mo,goalMap:Io,groupByGoal:Xo}),!Bt&&$==="tasks"&&(Kt==="task_created"||Kt==="run_started")&&jsx(ri,{step:Kt,width:bt}),!Bt&&$==="tasks"&&Kt==="completed"&&jsx(si,{width:bt}),!Bt&&$==="agents"&&jsx(kc,{agents:De,selectedIndex:or,scrollOffset:ia,height:we,width:ve,state:q,taskTitleMap:Ko,showAddRow:!!P,agentTeamMap:vo,teamLeadSet:ua,activeTeamCount:Yo}),!Bt&&$==="logs"&&jsxs(Fragment,{children:[jsx(Ic,{messages:We,height:To||Ho?Math.max(3,we-16):we,agents:De,logAgentFilter:Xr,logTypeFilter:qr,selectedIndex:jo,scrollOffset:Ji,agentNameMap:ao,agentColorMap:yn,agentMsgCounts:ss,taskTitleMap:Ko,width:ve}),To&&jsx(Box,{paddingX:2,children:jsx(Js,{agents:De,selected:Xr,msgCounts:ss,colorMap:yn,maxHeight:Math.min(we-4,18),onConfirm:i=>{Zi(i),sr(false);},onCancel:()=>sr(false)})}),Ho&&jsx(Box,{paddingX:2,children:jsx(oi,{selected:qr,typeCounts:da,onConfirm:i=>{Kr(i),ir(false);},onCancel:()=>ir(false)})})]}),jsx(Box,{height:1}),Bt?null:Ne==="wizard"&&Tt?jsx(Ks,{title:Tt.title,steps:Tt.steps,onComplete:xa,onCancel:ba,width:ve,height:Lt,onPasteImage:bs?fa:void 0,onSuggestionSelected:Tt.kind==="agent"?Ta:void 0,footerExtra:io.length>0&&bs?`\u{1F4CE}${io.length}`:void 0},`${Tt.kind}-${Tt.title}`):xs?jsxs(Fragment,{children:[jsx(Kn,{label:"COMMANDS",width:ve}),jsx(Tc,{suggestions:_t,selectedIndex:Tn,height:Math.min(_t.length,Lt),width:ve})]}):Ne==="new_task"?jsxs(Fragment,{children:[jsx(Ec,{mode:Ne,width:ve}),jsx(Lc,{mode:Ne,value:so,width:ve})]}):fs?jsxs(Fragment,{children:[jsx(_c,{task:U,width:ve,resizeHint:Cn}),jsx(Fs,{task:U,height:Lt,width:ve,taskLogs:$a,agentNameMap:ao,taskTitleMap:Ko})]}):hs?jsxs(Fragment,{children:[jsx(Kn,{label:`GOAL: ${te.title}`,width:ve,suffixLen:Cn.length+2,suffix:jsxs(Text,{color:e.dim,children:[" ",Cn," "]})}),jsx(wc,{goal:te,height:Lt,width:ve,agentNameMap:ao,tasks:ga,progressReport:Wo,scrollOffset:la,onClampScroll:qo})]}):ps?jsxs(Fragment,{children:[jsx(Rc,{agent:Q,width:ve,resizeHint:Cn}),jsx(Ac,{agent:Q,height:Lt,state:q,taskTitleMap:Ko,teamName:vo.get(Q.id)})]}):Aa?jsxs(Fragment,{children:[jsx(Kn,{label:"LOG",width:ve}),jsx(vc,{message:ms,height:Lt,width:ve,agents:De,agentNameMap:ao,agentColorMap:yn,taskTitleMap:Ko})]}):We.length>0&&$!=="logs"?jsxs(Fragment,{children:[(()=>{let i=` F:${mn.toUpperCase()} \u2502 ${cr.length}/${We.length}`;return jsx(Kn,{label:"ACTIVITY",width:ve,suffixLen:i.length,suffix:jsxs(Fragment,{children:[jsx(Text,{color:e.dim,children:" F:"}),jsx(Text,{color:e.amber,children:mn.toUpperCase()}),jsxs(Text,{color:e.ghost,children:[" ","\u2502"," ",cr.length,"/",We.length]})]})})})(),jsx(Mc,{messages:cr,height:Math.max(1,Lt-1),width:ve,agents:De,agentNameMap:ao,agentColorMap:yn})]}):$==="goals"?jsx(Vn,{count:dt.length,config:fc,width:ve}):$==="tasks"?jsx(Vn,{count:Le.length,config:pc,width:ve}):$==="agents"?jsx(Vn,{count:De.length,config:hc,width:ve}):null,jsx(Box,{flexGrow:1}),jsx(gi,{toasts:ta,onDismiss:na}),ko.length>0&&jsx(bc,{deletions:ko,width:bt}),jsx(js,{mode:Ne==="command"?"command":"navigate",value:Ne==="command"?so:"",completion:Ne==="command"?_r(so):null,activeView:$,canRun:!!Ba,canNew:!!Ea,canApprove:!!La,canReject:!!Oa,canCancel:$==="tasks"&&!!U&&U.status==="in_progress"&&!!b$1,canDelete:!!Na,canUndo:!!za,canEdit:!!Da,canForceStop:!!Fa,canToggleAuto:!!Wa,autoActive:Q?.autonomous,canPause:!!Ga,isPaused:te?.status==="paused",canToggleShowAll:$==="tasks"&&Le.length>Di,showAllActive:os,hasDetail:!!(fs||ps||hs),itemCount:$==="goals"?dt.length:$==="tasks"?Le.length:$==="agents"?k.length:We.length,itemLabel:$==="goals"?"goals":$==="tasks"?"tasks":$==="agents"?"agents":"events",width:bt,hasSuggestions:xs,onboardingCompleted:r.onboardingCompleted})]})}var bc=nn.memo(function({deletions:o,width:n}){let[,r]=useState(0);useEffect(()=>{let f=setInterval(()=>r(b=>b+1),1e3);return ()=>clearInterval(f)},[]);let l=Date.now();return jsx(Box,{flexDirection:"column",width:n,children:o.map(f=>{let b=Math.max(0,Math.ceil((f.expiresAt-l)/1e3)),T=Math.max(0,n-4),x=f.entityType==="task"?"Task":f.entityType==="agent"?"Agent":"Goal",y=Math.max(10,T-x.length-30),I=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:x}),` "${I}" \u2014 `,jsxs(Text,{color:e.amber,bold:true,children:[b,"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 Tc({suggestions:t,selectedIndex:o,height:n,width:r}){let l=n,f=0;o>=l&&(f=o-l+1);let b=t.slice(f,f+l);return jsx(Box,{flexDirection:"column",paddingX:2,children:b.map((T,x)=>{let y=x+f,I=y===o,v=I?"\u25B6":" ",B=Math.min(20,Math.max(14,...t.map(P=>P.cmd.length+1))),C=T.cmd.padEnd(B),H=T.subs?` ${T.subs}`:"",V=Math.max(4,r-B-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:I?e.amber:e.ghost,children:` ${v} `}),jsx(Text,{color:I?e.white:e.silver,bold:I,children:C}),jsx(Text,{color:e.dim,children:F}),H&&jsx(Text,{color:e.ghost,children:H})]},y)})})}function yc({goals:t,selectedIndex:o,scrollOffset:n=0,height:r,width:l,showAddRow:f,agentNameMap:b,tasksByGoalMap:T}){let x=t.length,y=t.slice(n,n+r),I=f&&x>=n&&x<n+r;return jsxs(Box,{flexDirection:"column",height:r,children:[y.map((v,B)=>jsx(Box,{paddingX:2,children:jsx(Ds,{goal:v,selected:B+n===o,width:l-2,agentNameMap:b,tasksByGoal:T?.get(v.id)})},v.id)),I&&jsx(Box,{paddingX:2,children:jsxs(Text,{color:o===x?e.amber:e.ghost,children:[o===x?" \u25B8 ":" ",jsx(Text,{color:o===x?e.amber:e.dim,children:"+ add goal..."})]})},"__add__")]})}function wc({goal:t,height:o,width:n,agentNameMap:r,tasks:l,progressReport:f,scrollOffset:b=0,onClampScroll:T}){let y=nn.useMemo(()=>{let V=l??[],F=t.assignee?r?.get(t.assignee)??t.assignee:"\u2014",P=Math.max(20,n-6),j=(z,X)=>{if(z.length<=X)return [z];let R=[];for(let ie=0;ie<z.length;ie+=X)R.push(z.slice(ie,ie+X));return R},L=Cr(f)?.split(`
13
- `).flatMap(z=>j(z,P))??[],O=Cr(t.description)?.split(`
14
- `).flatMap(z=>j(z,P))??[],N=ks[t.status]??e.dim,E=new Map;for(let z of V)E.set(z.status,(E.get(z.status)??0)+1);let G=[];if(G.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})]})]})}),G.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&&G.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,R]of E)z.push(`${R} ${X}`);G.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(O.length>0){G.push({key:"desc-gap",node:jsx(Text,{children:" "})});for(let z=0;z<O.length;z++)G.push({key:`desc-${z}`,node:jsxs(Text,{color:e.silver,wrap:"truncate",children:[" ",O[z]]})});}else G.push({key:"desc-gap",node:jsx(Text,{children:" "})}),G.push({key:"desc-empty",node:jsx(Text,{color:e.dim,children:" No description."})});if(L.length>0){G.push({key:"prog-gap",node:jsx(Text,{children:" "})}),G.push({key:"prog-div",node:jsx(Oo,{label:"progress",width:n})});for(let z=0;z<L.length;z++)G.push({key:`prog-${z}`,node:jsxs(Text,{color:e.white,wrap:"truncate",children:[" ",L[z]]})});}if(V.length>0){G.push({key:"tasks-gap",node:jsx(Text,{children:" "})}),G.push({key:"tasks-div",node:jsx(Oo,{label:`tasks (${V.length})`,width:n})});for(let z of V){let X=_n[z.status]??e.dim;G.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,n-22))]})});}}return G},[t,l,f,n,r]),I=Math.max(0,y.length-o),v=Math.min(b,I);nn.useEffect(()=>{T&&v!==b&&T(v);},[v,b,T]);let B=y.length>o&&v<I,C=B?o-1:o,H=y.slice(v,v+C);return jsxs(Box,{flexDirection:"column",height:o,paddingX:2,children:[H.map(V=>jsx(Box,{children:V.node},V.key)),B&&jsxs(Text,{color:e.ghost,children:[" ","\u2193"," ",y.length-v-C," more ","\u2014"," ","\u2191","\u2193"," to scroll"]})]})}function Sc({tasks:t,selectedIndex:o,scrollOffset:n=0,height:r,width:l,showAddRow:f,agentNameMap:b,hiddenCount:T=0,goalMap:x,groupByGoal:y=false}){let I=T>0,v=I?t.length:-1,B=t.length+(I?1:0),C=t.slice(n,n+r),H=I&&v>=n&&v<n+r,V=f&&B>=n&&B<n+r,F=useMemo(()=>{if(!y||!x||x.size===0)return null;let N=new Map;for(let E of t)if(E.goalId&&x.has(E.goalId)){let G=N.get(E.goalId)??{total:0,done:0};G.total++,E.status==="done"&&G.done++,N.set(E.goalId,G);}return N},[t,y,x]),P=y&&x?t.filter(N=>!N.goalId||!x.has(N.goalId)).length:0,j=y&&x&&x.size>0&&F&&F.size>0,L=[],O=n>0?t[n-1]?.goalId??null:void 0;for(let N=0;N<C.length&&L.length<r;N++){let E=C[N],G=E.goalId&&x?.has(E.goalId)?E.goalId:null;if(j){if(G&&G!==O){let z=x.get(G),X=F.get(G)??{total:0,done:0};if(L.push(jsx(Rs,{goalTitle:z.title,taskCount:X.total,doneCount:X.done,width:l},`gh_${G}`)),L.length>=r)break}if(!G&&O!==null&&O!==void 0&&(L.push(jsx(As,{taskCount:P,width:l},"__ungrouped__")),L.length>=r))break}O=G,L.push(jsx(Box,{paddingX:2,children:jsx(An,{task:E,selected:N+n===o,width:l-2,agentNameMap:b,goalMap:x})},E.id));}return H&&L.length<r&&L.push(jsx(Box,{paddingX:2,children:jsxs(Text,{color:o===v?e.amber:e.ghost,children:[o===v?" \u25B8 ":" ",jsxs(Text,{color:o===v?e.amber:e.dim,children:["\u25BC"," Show all (",T," more) \u2014 press ",jsx(Text,{bold:true,color:e.gray,children:"S"})]})]})},"__show_all__")),V&&L.length<r&&L.push(jsx(Box,{paddingX:2,children:jsxs(Text,{color:o===B?e.amber:e.ghost,children:[o===B?" \u25B8 ":" ",jsx(Text,{color:o===B?e.amber:e.dim,children:"+ add task..."})]})},"__add__")),jsx(Box,{flexDirection:"column",height:r,children:L})}function kc({agents:t,selectedIndex:o,scrollOffset:n=0,height:r,width:l,state:f,taskTitleMap:b,showAddRow:T,agentTeamMap:x,teamLeadSet:y,activeTeamCount:I}){let v=new Map;for(let E of Object.values(f.running))v.set(E.agent_id,E);let B=new Map;if(I&&I>0)for(let E of t){let G=x?.get(E.id);G&&B.set(G,(B.get(G)??0)+1);}let C=t.length,H=t.slice(n,n+r),V=T&&C>=n&&C<n+r,F=I!=null&&I>0,P=new Map;if(F&&y&&x){for(let E of t)if(y.has(E.id)){let G=x.get(E.id);G&&P.set(G,E.name);}}let j=0;for(let E of B.values())j+=E;let L=t.length-j,O=[],N=n>0?x?.get(t[n-1]?.id??""):void 0;for(let E=0;E<H.length&&O.length<r;E++){let G=H[E],z=x?.get(G.id);if(F&&z&&z!==N&&(O.push(jsx(Ls,{teamName:z,memberCount:B.get(z)??0,leadName:P.get(z),width:l},`ts-${z}`)),O.length>=r)||F&&!z&&N&&(O.push(jsx(Os,{memberCount:L,width:l},"ts-unassigned")),O.length>=r))break;N=z,O.push(jsx(Box,{paddingX:2,children:jsx(Es,{agent:G,selected:E+n===o,width:l-2,runningEntry:v.get(G.id),currentTaskTitle:G.current_task?b.get(G.current_task):void 0,teamName:z,isLead:y?.has(G.id)})},G.id));}return V&&O.length<r&&O.push(jsx(Box,{paddingX:2,children:jsxs(Text,{color:o===C?e.amber:e.ghost,children:[o===C?" \u25B8 ":" ",jsx(Text,{color:o===C?e.amber:e.dim,children:"+ add agent..."})]})},"__add__")),jsx(Box,{flexDirection:"column",height:r,children:O})}function Ui(t=5e3){let[o,n]=useState(Date.now());return useEffect(()=>{let r=setInterval(()=>n(Date.now()),t);return ()=>clearInterval(r)},[t]),o}function Xi(t,o){let n=Math.max(0,o-t);return n<3e3?"now":n<6e4?`${Math.floor(n/1e3)}s`:n<36e5?`${Math.floor(n/6e4)}m`:`${Math.floor(n/36e5)}h`}function Cc(t){if(t==="error")return e.errorBg}function qi(t,o){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 o}}function Ic({messages:t,height:o,agents:n,logAgentFilter:r,logTypeFilter:l,selectedIndex:f,scrollOffset:b,agentNameMap:T,agentColorMap:x,agentMsgCounts:y,taskTitleMap:I,width:v}){let B=Ui(),C=useMemo(()=>t.filter(X=>{if(r.size>0&&X.agentId&&!r.has(X.agentId))return false;let R=X.msgType??"info";return l.has(R)}),[t,r,l]);useMemo(()=>{let X={};for(let R of t){let ie=R.msgType??"info";X[ie]=(X[ie]??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=o-2,j=f===-1?C.slice(-P):C.slice(b,b+P),L=f===-1?-1:f-b,O=Math.min(10,Math.max(6,...n.map(X=>X.name.length))),N=11+O,E=X=>{if(X===0)return true;let R=j[X],ie=j[X-1];return R.agentId!==ie.agentId?true:R.agentId?R.ts-ie.ts>3e4:false},G=Math.max(4,Math.floor((v-20)/Math.max(1,n.length))-1),z=Math.min(G,10);return jsxs(Box,{flexDirection:"column",paddingX:1,children:[jsxs(Box,{gap:0,justifyContent:"space-between",width:v,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($o,{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,"/",C.length," "]}),jsxs(Text,{color:e.dim,children:[" ",C.length," events"]}),V!=="all"&&jsxs(Text,{color:e.amber,children:[" f:",V]}),F&&jsxs(Text,{color:e.cyan,children:[" ",r.size,"/",n.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:n.map(X=>{let R=x.get(X.id)??Vr[0],ie=r.size===0||r.has(X.id),Be=X.name.length>z?X.name.slice(0,z-1)+"\u2026":X.name;return jsxs(Text,{color:ie?R:e.ghost,bold:ie,children:[" ",Be]},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,R)=>{let ie=R===L,Be=X.msgType??"info",Wt=er[Be]??"\u2502",it=X.agentId?T.get(X.agentId)??X.agentId.slice(0,8):void 0,Re=X.agentId?x.get(X.agentId):void 0,Xe=E(R),mt=(R>0?j[R-1]:void 0)?.agentId===X.agentId&&!!X.agentId,Pe=!mt&&!!it,qe=mt&&!!it,lt=qi(Be,X.color),Ke=ie?e.infoBg:Be==="error"?e.errorBg:void 0,oo=X.taskId?I.get(X.taskId):void 0,ke=Xi(X.ts,B),ft=oo&&v>80?`#${oo.slice(0,20)}`:"",$t=ft?ft.length+3:0,Xt=Math.max(10,v-2-N-$t),pt=et(X.text,Xt);return jsxs(Box,{backgroundColor:Ke,children:[jsx(Text,{color:Re??e.ghost,children:Xe&&Pe?"\u250C":qe?"\u2502":" "}),jsx(Text,{color:ie?e.amber:void 0,children:ie?"\u25B8":" "}),jsx(Box,{width:5,children:jsx(Text,{color:ke==="now"?e.green:ie?e.silver:e.ghost,children:ke.padStart(4)})}),jsx(Box,{width:O+1,children:Pe?jsxs(Text,{color:Re,bold:true,children:[" ",it.slice(0,O).padEnd(O)]}):qe?jsxs(Text,{color:Re??e.ghost,children:[" ","\xB7".padEnd(O)]}):jsxs(Text,{color:e.ghost,children:[" "," ".padEnd(O)]})}),jsxs(Text,{color:Be==="error"?e.red:Re??e.dim,children:[" ",Wt," "]}),jsx(Text,{color:ie?e.white:lt,bold:ie||Be==="lifecycle",children:pt}),ft&&jsxs(Text,{color:e.ghost,children:[" ",jsx(Text,{color:e.dim,backgroundColor:e.void,children:` ${ft} `})]})]},R)})]})}function Mc({messages:t,height:o,width:n,agents:r,agentNameMap:l,agentColorMap:f}){let b=Ui(),T=t.slice(-o),x=Math.max(10,n-2-17),y=Math.max(0,o-T.length),I=0,v=[];for(let B=0;B<T.length;B++)B>0&&T[B].agentId!==T[B-1].agentId&&I++,v.push(I);return jsxs(Box,{flexDirection:"column",paddingX:1,children:[y>0&&jsx(Box,{height:y}),T.map((B,C)=>{let H=B.agentId?l.get(B.agentId)??B.agentId.slice(0,8):void 0,V=B.agentId?f.get(B.agentId):void 0,F=B.msgType??"info",P=er[F]??"\u2502",j=qi(F,B.color),O=(C>0?T[C-1]:void 0)?.agentId===B.agentId&&!!B.agentId,N=(v[C]&1)===1,E=Cc(F)??(N?"#1a1a1a":void 0),G=Xi(B.ts,b),z=et(B.text,x);return jsxs(Box,{backgroundColor:E,children:[jsx(Text,{color:V??e.ghost,children:!O&&H?"\u258D":O?"\u258F":" "}),jsx(Box,{width:5,children:jsx(Text,{color:O?e.ghost:G==="now"?e.green:e.dim,children:O?" ":G.padStart(4)})}),jsx(Box,{width:9,children:H&&!O?jsxs(Text,{color:V,bold:true,children:[" ",H.slice(0,8)]}):jsx(Text,{color:e.ghost,children:xc})}),jsxs(Text,{color:F==="error"?e.red:O?e.ghost:V??e.dim,children:[P," "]}),jsx(Text,{color:j,children:z})]},C)})]})}function vc({message:t,height:o,width:n,agents:r,agentNameMap:l,agentColorMap:f,taskTitleMap:b}){let T=t.detail??t.text,x=t.msgType??"info",y=t.agentId?l.get(t.agentId)??t.agentId.slice(0,8):void 0,I=t.agentId?f.get(t.agentId):e.dim,v=t.taskId?b.get(t.taskId):void 0,B,C=false;try{let P=JSON.parse(T);B=JSON.stringify(P,null,2),C=!0;}catch{B=T;}let H=Math.max(4,n-6),V=Math.max(1,o-4),F=B.split(`
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:I,bold:true,children:y}),y&&jsx(Text,{color:e.ghost,children:" \u2502 "}),jsxs(Text,{color:er[x]?x==="error"?e.red:e.dim:e.dim,children:[er[x]??"\u2502"," ",x]}),v&&jsxs(Fragment,{children:[jsx(Text,{color:e.ghost,children:" \u2502 "}),jsxs(Text,{color:e.dim,children:["#",v.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 "}),C&&jsxs(Text,{color:e.ghost,children:[String(j+1).padStart(3)," "]}),jsx(Text,{wrap:"truncate",color:C&&P.includes('"')?e.cyan:C&&/^\s*[}\]]/.test(P)?e.ghost:P.startsWith("error")||P.startsWith("Error")?e.red:e.silver,children:P.slice(0,C?H-4:H)})]},j)),jsx(Box,{children:jsxs(Text,{color:e.ghost,children:["\u2570",be(H+2),"\u256F"]})})]})}function Kn({label:t,width:o,suffix:n,suffixLen:r=0}){let l=` ${t} `,f=3,b=f+l.length+2;if(!n){let y=Math.max(0,o-b);return jsxs(Box,{paddingX:1,children:[jsx(Text,{color:e.ghost,children:ze(f)}),jsx(Text,{backgroundColor:"#1a1a22",color:e.dim,bold:true,children:l}),jsx(Text,{color:e.ghost,children:ze(y)})]})}let T=2,x=Math.max(0,o-b-T-r);return jsxs(Box,{paddingX:1,children:[jsx(Text,{color:e.ghost,children:ze(f)}),jsx(Text,{backgroundColor:"#1a1a22",color:e.dim,bold:true,children:l}),jsx(Text,{color:e.ghost,children:ze(T)}),n,jsx(Text,{color:e.ghost,children:ze(x)})]})}function _c({task:t,width:o,resizeHint:n}){let r=" DETAIL ",l=n?` ${n} `:"",f=o-r.length-l.length-10,b=t.title.length>f?t.title.slice(0,f-3)+"...":t.title,T=Math.max(0,o-3-r.length-b.length-l.length-4);return jsxs(Box,{paddingX:1,children:[jsx(Text,{color:e.ghost,children:ze(3)}),jsx(Text,{backgroundColor:"#2d1f0a",color:e.amber,bold:true,children:r}),jsxs(Text,{color:e.ghost,children:[vn," "]}),jsx(Text,{color:e.white,bold:true,children:b}),jsxs(Text,{color:e.ghost,children:[" ",ze(Math.max(0,T))]}),l?jsx(Text,{color:e.dim,children:l}):null]})}function Rc({agent:t,width:o,resizeHint:n}){let r=" AGENT ",l=n?` ${n} `:"",f=o-r.length-l.length-10,b=t.name.length>f?t.name.slice(0,f-3)+"...":t.name,T=Math.max(0,o-3-r.length-b.length-l.length-4);return jsxs(Box,{paddingX:1,children:[jsx(Text,{color:e.ghost,children:ze(3)}),jsx(Text,{backgroundColor:"#0f2d1f",color:e.green,bold:true,children:r}),jsxs(Text,{color:e.ghost,children:[vn," "]}),jsx(Text,{color:e.green,bold:true,children:b}),jsxs(Text,{color:e.ghost,children:[" ",ze(Math.max(0,T))]}),l?jsx(Text,{color:e.dim,children:l}):null]})}function Ac({agent:t,height:o,state:n,taskTitleMap:r,teamName:l}){let f=$c[t.status]??e.dim;Object.values(n.running).find(y=>y.agent_id===t.id);let T=t.current_task?r.get(t.current_task):void 0,x=24;return jsxs(Box,{flexDirection:"column",paddingX:2,children:[jsxs(Box,{children:[jsxs(Box,{width:x,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:x,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:x,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:x,children:[jsx(Text,{color:e.dim,children:" auto "}),jsxs(Text,{color:e.cyan,children:[go," 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:et(t.config.skills.join(", "),500)})]}),t.last_error&&(()=>{let y=t.last_error.kind,I=m[y],v=!I||y==="unknown",B=t.last_error.timestamp,C=B?g(B)+" 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"]}),I&&jsx(Text,{color:e.white,children:I.message}),I&&jsx(Text,{color:e.cyan,children:I.fix}),I?.doctorHint&&jsx(Text,{color:e.yellow,children:"\u0414\u0438\u0430\u0433\u043D\u043E\u0441\u0442\u0438\u043A\u0430: orch doctor"}),v&&t.last_error.message&&jsx(Text,{color:e.dim,children:et(t.last_error.message,120)}),C&&jsx(Text,{color:e.dim,children:C})]})]})})(),jsx(Text,{children:" "}),t.role?t.role.split(`
16
- `).slice(0,Math.max(1,o-(t.last_error?10:4))).map((y,I)=>jsxs(Text,{color:e.silver,wrap:"truncate",children:[" ",et(y,500)]},I)):jsx(Text,{color:e.dim,children:" No role description."})]})}var $c={idle:e.dim,running:e.green,error:e.red,disabled:e.ghost},Bc="\u2588";function Ec({mode:t,width:o}){let r=` ${t==="command"?"COMMAND":"NEW TASK"} `,l=Math.max(0,o-3-r.length-2);return jsxs(Box,{paddingX:1,children:[jsx(Text,{color:e.ghost,children:ze(3)}),jsx(Text,{backgroundColor:"#2d1f0a",color:e.amber,bold:true,children:r}),jsx(Text,{color:e.ghost,children:ze(l)})]})}function Lc({mode:t,value:o,width:n}){let r=t==="command"?"/":"\u25B8",l=Math.max(10,n-8),f=o.length>l?o.slice(-l):o;return jsxs(Box,{paddingX:2,children:[jsxs(Text,{color:e.amber,children:[r," "]}),jsx(Text,{color:e.white,children:f}),jsx(Text,{color:e.amber,children:Bc})]})}function Ki(t,o){if(!o||typeof o!="object")return "";let n=o;if(n.file_path&&typeof n.file_path=="string")return n.file_path.split("/").slice(-2).join("/");if(n.command&&typeof n.command=="string")return n.command.slice(0,60);if(n.pattern&&typeof n.pattern=="string")return `"${n.pattern.slice(0,40)}"`;if(n.glob&&typeof n.glob=="string")return n.glob.slice(0,40);let r=JSON.stringify(n);return r.length>80?r.slice(0,77)+"...":r}function Yn(t,o=200){if(typeof t=="string")return t.slice(0,o);if(!Array.isArray(t))return null;let n=[],r=0;for(let l of t){if(r>=o)break;if(l?.type==="text"&&typeof l.text=="string"){let f=l.text.split(`
17
- `).find(b=>b.trim().length>0)??"";n.push(f.slice(0,o-r)),r+=f.length;}else if(l?.type==="tool_use"){let f=Ki(l.name??"tool",l.input),b=`\u2699 ${l.name??"tool"}(${f})`;n.push(b),r+=b.length;}else if(l?.type==="tool_result")n.push("\u2190 (result)"),r+=10;else if(l?.type==="thinking"&&typeof l.thinking=="string"){let f=l.thinking.slice(0,60).split(`
18
- `)[0]??"";n.push(`\u{1F4AD} ${f}`),r+=f.length+3;}}return n.length>0?n.join(" "):null}function zi(t){if(typeof t=="string"){let n=t.split(`
19
- `).length,r=t.split(`
20
- `).find(l=>l.trim().length>0)??"";return n>3?`${r.slice(0,80)}... (${n} lines)`:r.slice(0,120)}if(!Array.isArray(t))return "(result)";let o=[];for(let n of t)if(n?.type==="tool_result"){n.tool_use_id?n.tool_use_id.slice(0,8):"";let l=n.is_error,f=typeof n.content=="string"?n.content:"",b=f.split(`
21
- `).length;l?o.push(`\u2715 error: ${f.slice(0,60)}`):b>3?o.push(`\u2713 ${b} lines`):o.push(`\u2713 ${f.slice(0,80)}`);}else n?.type==="text"&&typeof n.text=="string"&&o.push(n.text.split(`
22
- `)[0]?.slice(0,80)??"");return o.join(" ")||"(result)"}function Yi(t){let o=()=>t.length>Qn?t.slice(0,Qn)+"\u2026":t;if(Hi.test(t.trim()))return {summary:t.trim(),detail:o()};try{let n=JSON.parse(t);if(n.type==="message"&&n.role==="assistant"){let r=Yn(n.content);return r?{summary:r.slice(0,200),detail:o()}:{summary:null,detail:""}}if(n.type==="assistant"||n.role==="assistant"){let r=n.message?.content??n.content,l=Yn(r);return l?{summary:l.slice(0,200),detail:o()}:{summary:null,detail:""}}if(n.type==="user"||n.role==="user"){let r=n.message?.content??n.content;return {summary:`\u2190 ${zi(r).slice(0,180)}`,detail:o()}}if(n.type==="tool_use"||typeof n.name=="string"&&"input"in n){let r=n.name??"tool",l=Ki(r,n.input);return {summary:`\u2699 ${r}(${l})`,detail:o()}}if(n.type==="tool_result")return {summary:`\u2190 ${zi(n.content).slice(0,180)}`,detail:o()};if(n.type==="result"){let r=typeof n.result=="string"?n.result:null;return {summary:r?`\u2713 ${r.slice(0,180)}`:"\u2713 Agent finished",detail:o()}}if(n.type==="rate_limit_event")return {summary:`\u23F3 Rate limited (${n.rate_limit_info?.rateLimitType??"unknown"})`,detail:o()};if(n.subtype){if(n.message){let r=n.message.content??n.message,l=Yn(r);if(l)return {summary:l.slice(0,200),detail:o()}}return {summary:`[${n.subtype}]`,detail:o()}}if(n.content){let r=Yn(n.content);if(r)return {summary:r.slice(0,200),detail:o()}}return n.type?{summary:`[${n.type}]`,detail:o()}:{summary:t.slice(0,150),detail:o()}}catch{return {summary:Oc(t),detail:o()}}}function Oc(t){let o=t.match(/"subtype"\s*:\s*"([^"]+)"/);if(o)return `[${o[1]}]`;let n=t.match(/"type"\s*:\s*"([^"]+)"/),r=t.match(/"role"\s*:\s*"([^"]+)"/),l=n?.[1],f=r?.[1];if(!l&&!f)return t.slice(0,200);if(l==="assistant"||l==="message"||f==="assistant"){let b=t.match(/"text"\s*:\s*"((?:[^"\\]|\\.)*)"/);if(b)try{return JSON.parse(`"${b[1]}"`).slice(0,200)}catch{}return "\u{1F4AC} (assistant)"}if(l==="user"||l==="tool_result"||f==="user")return "\u2190 (tool result)";if(l==="tool_use")return `\u2699 ${t.match(/"name"\s*:\s*"([^"]+)"/)?.[1]??"tool"}()`;if(l==="result"){let b=t.match(/"result"\s*:\s*"((?:[^"\\]|\\.)*)"/);if(b)try{return `\u2713 ${JSON.parse(`"${b[1]}"`).slice(0,180)}`}catch{}return "\u2713 Agent finished"}return l==="rate_limit_event"?"\u23F3 Rate limited":`[${l??f}]`}function Pc(t,o,n,r){let l=f=>r?.get(f);switch(t.type){case "agent:started":o("Started task",e.green,{agentId:t.agentId,taskId:t.taskId,msgType:"lifecycle"});break;case "agent:output":{let{summary:f,detail:b}=Yi(t.data);if(f){let T=ji(f);o(f,T.color,{agentId:t.agentId,taskId:l(t.runId),detail:b,msgType:T.msgType});}break}case "agent:file_changed":o(`${t.path}`,e.purple,{agentId:t.agentId,taskId:l(t.runId),msgType:"file"});break;case "agent:completed":o(t.success?"Completed successfully":"Failed",t.success?e.green:e.red,{agentId:t.agentId,taskId:l(t.runId),msgType:"lifecycle"});break;case "agent:error":o(`${t.error.slice(0,150)}`,e.red,{agentId:t.agentId,taskId:l(t.runId),detail:t.error,msgType:"error"});break;case "task:status_changed":o(`${t.from} \u2192 ${t.to}`,e.cyan,{taskId:t.taskId,msgType:"system"});break;case "task:assigned":o(`Assigned \u2192 ${t.agentId}`,e.cyan,{taskId:t.taskId,msgType:"system"});break;case "task:created":o(`Created: ${t.task.title}`,e.amber,{taskId:t.task.id,msgType:"system"});break;case "run:retry":o(`Retry #${t.attempt} (${Math.round(t.delay_ms/1e3)}s delay)`,e.yellow,{agentId:n?.get(t.runId),taskId:l(t.runId),msgType:"lifecycle"});break;case "orchestrator:tick":(t.running>0||t.queued>0)&&o(`${t.running} running \xB7 ${t.queued} queued`,e.ghost,{msgType:"system"});break;case "orchestrator:stall_detected":o("Stall detected",e.yellow,{agentId:n?.get(t.runId),taskId:l(t.runId),msgType:"error"});break;case "task:cascade_failed":o(`Cascade failed (dep: ${t.failedDependencyId})`,e.red,{taskId:t.taskId,detail:t.reason,msgType:"error"});break}}export{Yu as App,Ku as _resetPendingDeletionSeq};
@@ -1,5 +0,0 @@
1
- #!/usr/bin/env node
2
- import r from'fs/promises';import u from'path';import m from'os';import {execFile}from'child_process';var p="@oxgeneral/orch",l=u.join(m.homedir(),".orchestry"),c=u.join(l,"update-check.json"),d=14400*1e3,g=d*.75;function w(t,e){let n=t.split(".").map(Number),i=e.split(".").map(Number);for(let a=0;a<3;a++){let o=(n[a]??0)-(i[a]??0);if(o!==0)return o>0?1:-1}return 0}async function U(){try{let t=await r.readFile(c,"utf-8"),e=JSON.parse(t);if(Date.now()-e.checked_at<d)return e}catch{}return null}async function C(t){await r.mkdir(l,{recursive:true});let e={latest:t,checked_at:Date.now()},n=`${c}.tmp.${process.pid}`;await r.writeFile(n,JSON.stringify(e),"utf-8"),await r.rename(n,c);}function A(){return new Promise(t=>{execFile("npm",["view",p,"version","--json"],{timeout:5e3},(n,i)=>{if(n)return t(null);try{t(JSON.parse(i.trim()));}catch{t(null);}}).unref();})}function f(t,e){return {current:t,latest:e,updateAvailable:w(e,t)>0}}async function s(t){let e=await A();return e?(await C(e).catch(()=>{}),f(t,e)):null}async function y(t){try{let e=await U();return e?(Date.now()-e.checked_at>=g&&s(t).catch(()=>{}),f(t,e.latest)):s(t).catch(()=>null)}catch{return null}}function N(t){if(!t.updateAvailable)return;let e=`
3
- Update available: ${t.current} \u2192 ${t.latest}
4
- Run: npm install -g ${p}
5
- `;process.stderr.write(e);}export{s as a,y as b,N as c};
@@ -1,3 +0,0 @@
1
- #!/usr/bin/env node
2
- import {i}from'./chunk-64WUDYEM.js';import g from'fs';var f=6;function w(o,n){let e=o.version()??"0.0.0";o.command("serve").description("Headless daemon mode \u2014 structured logs to stdout").option("--once","Process todo tasks and exit when all are terminal").option("--tick-interval <ms>","Override polling interval (ms)").option("--log-file <path>","Also write logs to file (append mode)").option("--log-format <format>","Log format: json or text (default: json)","json").option("--verbose","Include high-frequency agent:output events").action(async a=>{await u(n,e,a);});}var p=new Set(["json","text"]);async function u(o,n,e){if(e.logFormat&&!p.has(e.logFormat)){i(`Unknown --log-format "${e.logFormat}". Valid: json, text`),process.exitCode=2;return}let a=e.logFormat==="text"?"text":"json",l=[process.stdout],s;if(e.logFile&&(s=g.createWriteStream(e.logFile,{flags:"a"}),s.on("error",t=>{process.stderr.write(`Log file error: ${t.message}
3
- `);}),l.push(s)),e.tickInterval){let t=parseInt(e.tickInterval,10);!isNaN(t)&&t>0&&(o.config.scheduling.poll_interval_ms=t);}let{StructuredLogger:c}=await import('./structured-logger-RJ6VF35J.js'),r=new c({format:a,verbose:e.verbose??false,streams:l,idleLogInterval:f}),d=r.subscribe(o.eventBus);r.log("info","serve:started",{mode:e.once?"once":"watch",pid:process.pid,poll_interval_ms:o.config.scheduling.poll_interval_ms}),import('./update-check-CZJC7VW6.js').then(t=>t.checkForUpdateSWR(n)).catch(()=>null).then(t=>{t?.updateAvailable&&r.log("warn","update:available",{current:t.current,latest:t.latest,hint:"Run: npm install -g @oxgeneral/orch"});});try{if(e.once){let{runOnce:t}=await import('./once-runner-AMKCFW22.js'),i=await t(o.orchestrator,o.taskStore,o.eventBus);r.log("info","serve:finished",{result:i,exit_code:i==="has_failed"?1:0}),process.exitCode=i==="has_failed"?1:0;}else await o.orchestrator.startWatch(),await o.orchestrator.waitForStop();}finally{d(),await r.flush();}}export{w as registerServeCommand};
@@ -1,2 +0,0 @@
1
- #!/usr/bin/env node
2
- function rt(c,e){c.command("tui").description("Launch interactive TUI dashboard").action(async()=>{let y=await e.taskService.list(),v=await e.agentService.list(),S=await e.stateStore.read(),{render:w}=await import('ink'),{createElement:f}=await import('react'),{App:h}=await import('./App-TTMII4MJ.js'),T=async t=>{await e.orchestrator.runTask(t);},k=async(t,s)=>e.taskService.create({title:t,priority:s?.priority,description:s?.description,attachments:s?.attachments}),A=async t=>{await e.orchestrator.cancelTask(t);},C=async t=>{await e.taskService.retry(t);},b=async(t,s)=>{await e.taskService.assign(t,s);},R=async()=>{await e.orchestrator.runAll();},_=async t=>{await e.agentService.disable(t);},E=async t=>{await e.agentService.enable(t);},j=t=>e.eventBus.onAny(t),D=async()=>e.taskService.list(),P=async()=>e.agentService.list(),U=async()=>e.stateStore.read(),G=async(t,s,n)=>e.agentService.create({name:t,adapter:s??"claude",model:n?.model||void 0,role:n?.role||void 0,approval_policy:n?.approval_policy||void 0,skills:n?.skills||void 0}),x=async t=>{await e.agentService.remove(t);},L=async t=>{await e.taskService.delete(t);},H=async t=>{await e.taskService.updateStatus(t,"done");},W=async(t,s)=>{await e.taskService.reject(t,s);},F=async(t,s)=>e.taskService.update(t,s),I=async(t,s)=>e.agentService.update(t,{...s,approval_policy:s.approval_policy}),N=async t=>{await e.orchestrator.forceStopAgent(t);},O=async(t,s)=>e.agentService.setAutonomous(t,s),B=async t=>{let s=await e.runService.listAll();s.sort((a,r)=>new Date(r.started_at).getTime()-new Date(a.started_at).getTime());let n=s.filter(a=>a.status==="succeeded"||a.status==="failed"),d=3,it=10,m=n.slice(0,d),p=n.slice(d,it),u=async a=>(await e.runService.readEventsTail(a.id,30)).map(i=>({timestamp:i.timestamp,agentId:a.agent_id,taskId:a.task_id,type:i.type,data:i.data}));if(m.length>0){let a=(await Promise.all(m.map(u))).flat();a.sort((r,i)=>new Date(r.timestamp).getTime()-new Date(i.timestamp).getTime()),t(a.slice(-200));}if(p.length>0){let a=(await Promise.all(p.map(u))).flat();a.sort((r,i)=>new Date(r.timestamp).getTime()-new Date(i.timestamp).getTime()),t(a.slice(-200));}},M=async t=>e.teamService.create(t),V=async()=>e.teamService.list(),J=async(t,s)=>e.teamService.join(t,s),K=async(t,s)=>e.teamService.leave(t,s),q=async t=>{await e.teamService.disband(t);},z=async(t,s)=>e.teamService.setLead(t,s),Q=async()=>e.goalService.list(),X=async t=>e.goalService.create(t),Y=async(t,s)=>e.goalService.update(t,s),Z=async(t,s)=>e.goalService.updateStatus(t,s),$=async t=>{await e.goalService.delete(t);},tt=async t=>e.goalService.getProgressReport(t),et=async()=>{await e.orchestrator.startWatch();},st=async()=>{await e.orchestrator.stop();},l=c.version()??"0.0.0",at=import('./update-check-CZJC7VW6.js').then(t=>t.checkForUpdateSWR(l)).catch(()=>null),o=false,g;try{await e.orchestrator.startWatch(),o=!0;}catch(t){g=t instanceof Error?t.message:String(t);}let{waitUntilExit:nt}=w(f(h,{projectName:e.config.project.name,tasks:y,agents:v,state:S,onRunTask:T,onCreateTask:k,onCancelTask:A,onRetryTask:C,onAssignTask:b,onRunAll:R,onDisableAgent:_,onEnableAgent:E,onSubscribeEvents:j,onRefreshTasks:D,onRefreshAgents:P,onRefreshState:U,onLoadHistory:B,onAddAgent:G,onDeleteAgent:x,onApproveTask:H,onRejectTask:W,onDeleteTask:L,onUpdateTask:F,onUpdateAgent:I,onForceStopAgent:N,onToggleAutonomous:O,onRefreshGoals:Q,onCreateGoal:X,onUpdateGoal:Y,onUpdateGoalStatus:Z,onDeleteGoal:$,onGetGoalProgress:tt,onCreateTeam:M,onListTeams:V,onJoinTeam:J,onLeaveTeam:K,onDisbandTeam:q,onSetTeamLead:z,onStartWatch:et,onStopWatch:st,initialWatchActive:o,watchError:g,version:l,latestVersion:void 0,onCheckUpdate:async()=>{let t=await at;return t?.updateAvailable?t.latest:void 0},initialActivityFilter:e.globalConfig.tui.activity_filter,onSaveActivityFilter:async t=>{await e.globalConfigStore.set("activity_filter",t);},initialNotifications:e.globalConfig.tui.notifications,onSaveNotifications:async t=>{await e.globalConfigStore.set("notifications",t);},initialMaxConcurrent:e.config.scheduling.max_concurrent_agents,onSaveMaxConcurrent:async t=>{await e.configStore.set("scheduling.max_concurrent_agents",t),e.config.scheduling.max_concurrent_agents=t;},onCompleteOnboarding:async()=>{let t=await e.stateStore.read();t.onboardingCompleted=true,await e.stateStore.write(t);}}),{kittyKeyboard:{mode:"auto",flags:["disambiguateEscapeCodes"]}});await nt(),o&&await e.orchestrator.stop().catch(()=>{}),e.eventBus.clear();});}export{rt as registerTuiCommand};
@@ -1,2 +0,0 @@
1
- #!/usr/bin/env node
2
- export{a as checkForUpdateNow,b as checkForUpdateSWR,c as printUpdateNotification}from'./chunk-XLBV2PFL.js';