@oxgeneral/orch 1.0.23 → 1.0.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,22 +1,23 @@
1
1
  #!/usr/bin/env node
2
- import {b,a as a$2}from'./chunk-3YGXRXS7.js';import {a as a$4}from'./chunk-JDG6ZKIM.js';import {a as a$3}from'./chunk-4O4L3Y2U.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 {n}from'./chunk-LRYVT4D4.js';import co,{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"},$o="\u2501",je="\u2500",fe="\xB7",Zt="\u25C8",$r="\u2605",xn="\u27F3",jt="\u25C6",Eo={in_progress:e.green,retrying:e.yellow,review:e.blue,todo:e.dim,done:e.green,failed:e.red,cancelled:e.dim},Os=new Map,Ls=new Map;function He(t){if(t<=0)return "";let n=Os.get(t);return n||(n=$o.repeat(t),Os.set(t,n)),n}function Te(t){if(t<=0)return "";let n=Ls.get(t);return n||(n=je.repeat(t),Ls.set(t,n)),n}function it(t,n){return t.length>n?t.slice(0,n-1)+"\u2026":t}var hl=1e4;function Er(t,n=hl){if(t)return t.length>n?t.slice(0,n)+`
3
- \u2026[truncated]`:t}var Ps={active:e.green,paused:e.dim,achieved:e.amber,abandoned:e.ghost};var Tl=120,Oo=0,so=null,Lo=new Set;function yl(){so||(so=setInterval(()=>{Oo++;for(let t of Lo)t(Oo);},Tl));}function wl(){so&&Lo.size===0&&(clearInterval(so),so=null);}function Ln(t=true){let[n,o]=useState(Oo);return useEffect(()=>{if(!t)return;o(Oo);let r=s=>o(s);return Lo.add(r),yl(),()=>{Lo.delete(r),wl();}},[t]),n}var Ns=["\u280B","\u2819","\u2839","\u2838","\u283C","\u2834","\u2826","\u2827","\u2807","\u280F"];function Ht({color:t}){let n=Ln();return jsx(Text,{color:t,children:Ns[n%Ns.length]})}var io={in_progress:0,retrying:1,review:2,todo:3,done:4,failed:5,cancelled:6};var Il="\u25CB",Fs="\u2713",Ws="\u2715",vl="\u21BB",_l="\u2500",Ml="\u25B6",Nt={green:"#0f2d1f",blue:"#0f1f2d",yellow:"#2d2a0f",red:"#2d0f0f",neutral:"#1a1a22",amber:"#2d1f0a"},Rl={in_progress:{icon:Ml,label:"RUN",fg:e.green,bg:Nt.green,bold:true,spinner:true},retrying:{icon:vl,label:"RETRY",fg:e.yellow,bg:Nt.yellow,spinner:true},review:{icon:Zt,label:"REVIEW",fg:e.blue,bg:Nt.blue},todo:{icon:Il,label:"TODO",fg:e.dim,bg:Nt.neutral},done:{icon:Fs,label:"DONE",fg:e.green,bg:Nt.green},failed:{icon:Ws,label:"FAIL",fg:e.red,bg:Nt.red,bold:true},cancelled:{icon:_l,label:"OFF",fg:e.dim,bg:Nt.neutral}},Al={1:{color:e.red,label:"!!!"},2:{color:e.yellow,label:"!!"},3:{color:e.dim,label:"!"},4:{color:e.ghost,label:fe}};var $l=18,El="#2d1f0a",Po=co.memo(function({task:n,selected:o,width:r,agentNameMap:s,goalMap:f$1}){let h=Rl[n.status],y=n.status==="in_progress"||n.status==="retrying",m=Al[n.priority]??{color:e.ghost,label:fe},T,S;if(n.status==="done")T=Fs,S=e.green;else if(n.status==="failed")T=Ws,S=e.red;else if(y){let G=Date.now()-new Date(n.updated_at).getTime();T=f(G),S=e.cyan;}else T="\u2014",S=void 0;let I=o?"\u25B8":" ",M=n.goalId?f$1?.get(n.goalId):void 0,v=!!M,L=10,_=4,R=14,C=v?$l:0,z=7,P=2+L+_+R+C+z,$=r?Math.max(10,r-P):40,H=n.assignee?s?.get(n.assignee)??n.assignee:void 0;return jsxs(Box,{children:[jsxs(Text,{color:o?e.amber:void 0,children:[I," "]}),jsx(Box,{width:L,children:jsx(Text,{backgroundColor:h.bg,color:h.fg,bold:h.bold,children:h.spinner?jsxs(Fragment,{children:[" ",jsx(Ht,{color:h.fg})," ",h.label," "]}):jsxs(Fragment,{children:[" ",h.icon," ",h.label," "]})})}),jsx(Box,{width:_,children:jsx(Text,{color:m.color,bold:n.priority<=2,children:m.label})}),jsxs(Box,{width:$,children:[jsx(Text,{wrap:"truncate",bold:o||y,color:o?e.white:y?e.silver:void 0,children:n.title.length>$?n.title.slice(0,$-1)+"\u2026":n.title}),(n.attachments?.length??0)>0&&jsxs(Text,{color:e.dim,children:[" ","\u{1F4CE}",n.attachments.length]})]}),v&&jsx(Box,{width:C,children:jsxs(Text,{backgroundColor:El,color:e.amberDim,wrap:"truncate",children:[" \u2295 ",it(M.title,13)," "]})}),jsx(Box,{width:R,children:H?jsxs(Text,{backgroundColor:Nt.green,color:e.green,wrap:"truncate",children:[" ",H.length>R-2?H.slice(0,R-3)+"\u2026":H," "]}):jsx(Text,{color:e.ghost,children:"\u2014"})}),jsx(Box,{width:z,justifyContent:"flex-end",children:jsx(Text,{color:S,dimColor:!S,children:T})})]})});var Gs="\u2295";function zs({goalTitle:t,taskCount:n,doneCount:o,width:r}){let s=n>0?Math.round(o/n*100):0,f=` ${Gs} ${t.toUpperCase()} ${fe} ${n} task${n!==1?"s":""} ${fe} ${s}% done `,h=3,y=Math.max(0,r-h-f.length-4);return jsxs(Box,{paddingX:2,children:[jsx(Text,{color:e.ghost,children:Te(h)}),jsx(Text,{backgroundColor:Nt.amber,color:e.amber,bold:true,children:f}),jsx(Text,{color:e.ghost,children:Te(y)})]})}function Vs({taskCount:t,width:n}){let o=` ${Gs} UNGROUPED ${fe} ${t} task${t!==1?"s":""} `,r=3,s=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:Nt.neutral,color:e.dim,children:o}),jsx(Text,{color:e.ghost,children:Te(s)})]})}var Ll="\u2715",js="\u25CB",Pl="\u25B6",Nl="\u2713",Pn={green:"#0f2d1f",red:"#2d0f0f",neutral:"#1a1a22",amber:"#2d1f0a"},Dl={running:{icon:Pl,label:"ACTIVE",fg:e.green,bg:Pn.green,bold:true,spinner:true},idle:{icon:js,label:"IDLE",fg:e.dim,bg:Pn.neutral},error:{icon:Ll,label:"ERROR",fg:e.red,bg:Pn.red,bold:true},disabled:{icon:js,label:"OFF",fg:e.ghost,bg:Pn.neutral}},Or={running:0,idle:1,error:2,disabled:3},Us=co.memo(function({agent:n$1,selected:o,width:r,runningEntry:s,currentTaskTitle:f$1,teamName:h,isLead:y}){let m=Dl[n$1.status],T=n$1.status==="running",S,I;if(T&&s){let H=Date.now()-new Date(s.started_at).getTime();S=f(H),I=e.cyan;}else n$1.stats.total_runs>0?(S=`${n$1.stats.tasks_completed}/${n$1.stats.total_runs}`,I=n$1.stats.tasks_completed>0?e.green:e.dim):(S="\u2014",I=void 0);let M=o?"\u25B8":" ",v=11,L=8,_=h?Math.min(h.length+2,12):0,R=10,C=2+v+L+_+R,z=r?Math.max(8,r-C):20,P=n$1.stats.total_runs>0,$=P?Math.round(n$1.stats.tasks_completed/n$1.stats.total_runs*100):0;return jsxs(Box,{children:[jsxs(Text,{color:o?e.amber:void 0,children:[M," "]}),jsx(Box,{width:v,children:jsx(Text,{backgroundColor:m.bg,color:m.fg,bold:m.bold,children:m.spinner?jsxs(Fragment,{children:[" ",jsx(Ht,{color:m.fg})," ",m.label," "]}):jsxs(Fragment,{children:[" ",m.icon," ",m.label," "]})})}),jsx(Box,{width:z,children:jsxs(Text,{wrap:"truncate",bold:o||T,color:o?e.white:T?e.green:e.silver,children:[n$1.autonomous&&jsxs(Text,{color:e.cyan,children:[xn," "]}),y&&jsxs(Text,{color:e.amber,children:[$r," "]}),n$1.name,T&&f$1&&jsxs(Text,{color:e.dim,children:[" ",fe," ",f$1]}),n$1.status==="error"&&n$1.last_error&&jsxs(Text,{color:e.red,children:[" ",fe," ",it(n[n$1.last_error.kind]?.message??n$1.last_error.message,30)]})]})}),jsx(Box,{width:L,children:jsx(Text,{color:e.dim,children:n$1.adapter})}),h&&jsx(Box,{width:_,children:jsx(Text,{color:e.amber,wrap:"truncate",children:h})}),jsx(Box,{width:R,justifyContent:"flex-end",children:P&&!T?jsxs(Text,{color:$>=80?e.green:$>=50?e.yellow:e.red,children:[S," ",Nl]}):jsx(Text,{color:I,dimColor:!I,children:S})})]})});function Xs({teamName:t,memberCount:n,leadName:o,width:r}){let s=`${n} agent${n!==1?"s":""}`,f=o?` ${fe} ${$r} ${o}`:"",h=` ${Zt} ${t.toUpperCase()} ${fe} ${s}${f} `,y=3,m=Math.max(0,r-y-h.length-4);return jsxs(Box,{paddingX:2,children:[jsx(Text,{color:e.ghost,children:Te(y)}),jsx(Text,{backgroundColor:Pn.amber,color:e.amber,bold:true,children:h}),jsx(Text,{color:e.ghost,children:Te(m)})]})}var Fl="\u25C7";function qs({memberCount:t,width:n}){let o=`${t} agent${t!==1?"s":""}`,r=` ${Fl} UNASSIGNED ${fe} ${o} `,s=3,f=Math.max(0,n-s-r.length-4);return jsxs(Box,{paddingX:2,children:[jsx(Text,{color:e.ghost,children:Te(s)}),jsx(Text,{backgroundColor:Pn.neutral,color:e.dim,children:r}),jsx(Text,{color:e.ghost,children:Te(f)})]})}var Ks="\u2713",Ys="\u2715",Gl="\u2016",zl="\u25C9",lo={green:"#0f2d1f",amber:"#2d1f0a",neutral:"#1a1a22"},Vl={active:{icon:zl,label:"ACTIVE",fg:e.green,bg:lo.green,bold:true},paused:{icon:Gl,label:"PAUSED",fg:e.dim,bg:lo.neutral},achieved:{icon:Ks,label:"DONE",fg:e.amber,bg:lo.amber,bold:true},abandoned:{icon:Ys,label:"DROP",fg:e.ghost,bg:lo.neutral}},jl="\u2588",Hl="\u2591",Ul=14,Zs=co.memo(function({goal:n,selected:o,width:r,agentNameMap:s,tasksByGoal:f}){let h=Vl[n.status],y=o?"\u25B8":" ",m=f?.length??0,T=f?.filter($=>$.status==="done").length??0,S=m>0,I=11,M=S?Ul:0,v=14,L=7,_=2+I+M+v+L,R=r?Math.max(10,r-_):40,C=n.assignee?s?.get(n.assignee)??n.assignee:void 0,z,P;if(n.status==="achieved")z=Ks,P=e.amber;else if(n.status==="abandoned")z=Ys,P=e.ghost;else {let $=Date.now()-new Date(n.created_at).getTime(),H=Math.floor($/864e5);z=H>0?`${H}d`:"<1d",P=e.dim;}return jsxs(Box,{children:[jsxs(Text,{color:o?e.amber:void 0,children:[y," "]}),jsx(Box,{width:I,children:jsxs(Text,{backgroundColor:h.bg,color:h.fg,bold:h.bold,children:[" ",h.icon," ",h.label," "]})}),jsx(Box,{width:R,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>R?n.title.slice(0,R-1)+"\u2026":n.title})}),S&&(()=>{let H=m>0?Math.round(T/m*6):0,G=6-H;return jsxs(Box,{width:M,children:[jsx(Text,{color:e.green,children:jl.repeat(H)}),jsx(Text,{color:e.ghost,children:Hl.repeat(G)}),jsx(Text,{color:e.dim,children:` ${T}/${m}`})]})})(),jsx(Box,{width:v,children:C?jsxs(Text,{backgroundColor:lo.green,color:e.green,wrap:"truncate",children:[" ",C.length>v-2?C.slice(0,v-3)+"\u2026":C," "]}):jsx(Text,{color:e.ghost,children:"\u2014"})}),jsx(Box,{width:L,justifyContent:"flex-end",children:jsx(Text,{color:P,dimColor:!P,children:z})})]})});var Xl={system:"\u2666",lifecycle:"\u25B6",output:"\u2502",tool:"\u2699",result:"\u2190",error:"\u2715",file:"\u270E",info:"\u2502"};function Fn({label:t,width:n,color:o}){let r=n-4,s=` ${t} `,f=3,h=Math.max(0,r-f-s.length);return jsxs(Text,{color:o??e.ghost,children:[" ",Te(f),s,Te(h)]})}function Js({task:t,height:n,width:o,taskLogs:r,agentNameMap:s,taskTitleMap:f}){let h=Eo[t.status]??e.dim,y=t.priority<=2?t.priority===1?e.red:e.yellow:void 0,m=24,T=!!t.description?.trim(),S=!!t.proof?.agent_summary,I=(t.proof?.files_changed?.length??0)>0,M=(r?.length??0)>0,v=(t.attachments?.length??0)>0,L=T?t.description.split(`
2
+ import {b,a as a$2}from'./chunk-3YGXRXS7.js';import {a as a$4}from'./chunk-JDG6ZKIM.js';import {a as a$3}from'./chunk-4O4L3Y2U.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 {n}from'./chunk-LRYVT4D4.js';import uo,{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"},Eo="\u2501",je="\u2500",fe="\xB7",Zt="\u25C8",Er="\u2605",xn="\u27F3",jt="\u25C6",Oo={in_progress:e.green,retrying:e.yellow,review:e.blue,todo:e.dim,done:e.green,failed:e.red,cancelled:e.dim},Ls=new Map,Ps=new Map;function He(t){if(t<=0)return "";let n=Ls.get(t);return n||(n=Eo.repeat(t),Ls.set(t,n)),n}function Te(t){if(t<=0)return "";let n=Ps.get(t);return n||(n=je.repeat(t),Ps.set(t,n)),n}function it(t,n){return t.length>n?t.slice(0,n-1)+"\u2026":t}var xl=1e4;function Or(t,n=xl){if(t)return t.length>n?t.slice(0,n)+`
3
+ \u2026[truncated]`:t}var Ns={active:e.green,paused:e.dim,achieved:e.amber,abandoned:e.ghost};var yl=120,Lo=0,io=null,Po=new Set;function wl(){io||(io=setInterval(()=>{Lo++;for(let t of Po)t(Lo);},yl));}function Sl(){io&&Po.size===0&&(clearInterval(io),io=null);}function Ln(t=true){let[n,o]=useState(Lo);return useEffect(()=>{if(!t)return;o(Lo);let r=s=>o(s);return Po.add(r),wl(),()=>{Po.delete(r),Sl();}},[t]),n}var Ds=["\u280B","\u2819","\u2839","\u2838","\u283C","\u2834","\u2826","\u2827","\u2807","\u280F"];function Ht({color:t}){let n=Ln();return jsx(Text,{color:t,children:Ds[n%Ds.length]})}var ao={in_progress:0,retrying:1,review:2,todo:3,done:4,failed:5,cancelled:6};var vl="\u25CB",Ws="\u2713",Gs="\u2715",_l="\u21BB",Ml="\u2500",Rl="\u25B6",Nt={green:"#0f2d1f",blue:"#0f1f2d",yellow:"#2d2a0f",red:"#2d0f0f",neutral:"#1a1a22",amber:"#2d1f0a"},Al={in_progress:{icon:Rl,label:"RUN",fg:e.green,bg:Nt.green,bold:true,spinner:true},retrying:{icon:_l,label:"RETRY",fg:e.yellow,bg:Nt.yellow,spinner:true},review:{icon:Zt,label:"REVIEW",fg:e.blue,bg:Nt.blue},todo:{icon:vl,label:"TODO",fg:e.dim,bg:Nt.neutral},done:{icon:Ws,label:"DONE",fg:e.green,bg:Nt.green},failed:{icon:Gs,label:"FAIL",fg:e.red,bg:Nt.red,bold:true},cancelled:{icon:Ml,label:"OFF",fg:e.dim,bg:Nt.neutral}},$l={1:{color:e.red,label:"!!!"},2:{color:e.yellow,label:"!!"},3:{color:e.dim,label:"!"},4:{color:e.ghost,label:fe}};var El=18,Ol="#2d1f0a",No=uo.memo(function({task:n,selected:o,width:r,agentNameMap:s,goalMap:f$1}){let h=Al[n.status],y=n.status==="in_progress"||n.status==="retrying",m=$l[n.priority]??{color:e.ghost,label:fe},T,S;if(n.status==="done")T=Ws,S=e.green;else if(n.status==="failed")T=Gs,S=e.red;else if(y){let G=Date.now()-new Date(n.updated_at).getTime();T=f(G),S=e.cyan;}else T="\u2014",S=void 0;let I=o?"\u25B8":" ",M=n.goalId?f$1?.get(n.goalId):void 0,v=!!M,L=10,_=4,R=14,C=v?El:0,z=7,P=2+L+_+R+C+z,B=r?Math.max(10,r-P):40,H=n.assignee?s?.get(n.assignee)??n.assignee:void 0;return jsxs(Box,{children:[jsxs(Text,{color:o?e.amber:void 0,children:[I," "]}),jsx(Box,{width:L,children:jsx(Text,{backgroundColor:h.bg,color:h.fg,bold:h.bold,children:h.spinner?jsxs(Fragment,{children:[" ",jsx(Ht,{color:h.fg})," ",h.label," "]}):jsxs(Fragment,{children:[" ",h.icon," ",h.label," "]})})}),jsx(Box,{width:_,children:jsx(Text,{color:m.color,bold:n.priority<=2,children:m.label})}),jsxs(Box,{width:B,children:[jsx(Text,{wrap:"truncate",bold:o||y,color:o?e.white:y?e.silver:void 0,children:n.title.length>B?n.title.slice(0,B-1)+"\u2026":n.title}),(n.attachments?.length??0)>0&&jsxs(Text,{color:e.dim,children:[" ","\u{1F4CE}",n.attachments.length]})]}),v&&jsx(Box,{width:C,children:jsxs(Text,{backgroundColor:Ol,color:e.amberDim,wrap:"truncate",children:[" \u2295 ",it(M.title,13)," "]})}),jsx(Box,{width:R,children:H?jsxs(Text,{backgroundColor:Nt.green,color:e.green,wrap:"truncate",children:[" ",H.length>R-2?H.slice(0,R-3)+"\u2026":H," "]}):jsx(Text,{color:e.ghost,children:"\u2014"})}),jsx(Box,{width:z,justifyContent:"flex-end",children:jsx(Text,{color:S,dimColor:!S,children:T})})]})});var zs="\u2295";function Vs({goalTitle:t,taskCount:n,doneCount:o,width:r}){let s=n>0?Math.round(o/n*100):0,f=` ${zs} ${t.toUpperCase()} ${fe} ${n} task${n!==1?"s":""} ${fe} ${s}% done `,h=3,y=Math.max(0,r-h-f.length-4);return jsxs(Box,{paddingX:2,children:[jsx(Text,{color:e.ghost,children:Te(h)}),jsx(Text,{backgroundColor:Nt.amber,color:e.amber,bold:true,children:f}),jsx(Text,{color:e.ghost,children:Te(y)})]})}function js({taskCount:t,width:n}){let o=` ${zs} UNGROUPED ${fe} ${t} task${t!==1?"s":""} `,r=3,s=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:Nt.neutral,color:e.dim,children:o}),jsx(Text,{color:e.ghost,children:Te(s)})]})}var Pl="\u2715",Hs="\u25CB",Nl="\u25B6",Dl="\u2713",Pn={green:"#0f2d1f",red:"#2d0f0f",neutral:"#1a1a22",amber:"#2d1f0a"},Fl={running:{icon:Nl,label:"ACTIVE",fg:e.green,bg:Pn.green,bold:true,spinner:true},idle:{icon:Hs,label:"IDLE",fg:e.dim,bg:Pn.neutral},error:{icon:Pl,label:"ERROR",fg:e.red,bg:Pn.red,bold:true},disabled:{icon:Hs,label:"OFF",fg:e.ghost,bg:Pn.neutral}},Lr={running:0,idle:1,error:2,disabled:3},Xs=uo.memo(function({agent:n$1,selected:o,width:r,runningEntry:s,currentTaskTitle:f$1,teamName:h,isLead:y}){let m=Fl[n$1.status],T=n$1.status==="running",S,I;if(T&&s){let H=Date.now()-new Date(s.started_at).getTime();S=f(H),I=e.cyan;}else n$1.stats.total_runs>0?(S=`${n$1.stats.tasks_completed}/${n$1.stats.total_runs}`,I=n$1.stats.tasks_completed>0?e.green:e.dim):(S="\u2014",I=void 0);let M=o?"\u25B8":" ",v=11,L=8,_=h?Math.min(h.length+2,12):0,R=10,C=2+v+L+_+R,z=r?Math.max(8,r-C):20,P=n$1.stats.total_runs>0,B=P?Math.round(n$1.stats.tasks_completed/n$1.stats.total_runs*100):0;return jsxs(Box,{children:[jsxs(Text,{color:o?e.amber:void 0,children:[M," "]}),jsx(Box,{width:v,children:jsx(Text,{backgroundColor:m.bg,color:m.fg,bold:m.bold,children:m.spinner?jsxs(Fragment,{children:[" ",jsx(Ht,{color:m.fg})," ",m.label," "]}):jsxs(Fragment,{children:[" ",m.icon," ",m.label," "]})})}),jsx(Box,{width:z,children:jsxs(Text,{wrap:"truncate",bold:o||T,color:o?e.white:T?e.green:e.silver,children:[n$1.autonomous&&jsxs(Text,{color:e.cyan,children:[xn," "]}),y&&jsxs(Text,{color:e.amber,children:[Er," "]}),n$1.name,T&&f$1&&jsxs(Text,{color:e.dim,children:[" ",fe," ",f$1]}),n$1.status==="error"&&n$1.last_error&&jsxs(Text,{color:e.red,children:[" ",fe," ",it(n[n$1.last_error.kind]?.message??n$1.last_error.message,30)]})]})}),jsx(Box,{width:L,children:jsx(Text,{color:e.dim,children:n$1.adapter})}),h&&jsx(Box,{width:_,children:jsx(Text,{color:e.amber,wrap:"truncate",children:h})}),jsx(Box,{width:R,justifyContent:"flex-end",children:P&&!T?jsxs(Text,{color:B>=80?e.green:B>=50?e.yellow:e.red,children:[S," ",Dl]}):jsx(Text,{color:I,dimColor:!I,children:S})})]})});function qs({teamName:t,memberCount:n,leadName:o,width:r}){let s=`${n} agent${n!==1?"s":""}`,f=o?` ${fe} ${Er} ${o}`:"",h=` ${Zt} ${t.toUpperCase()} ${fe} ${s}${f} `,y=3,m=Math.max(0,r-y-h.length-4);return jsxs(Box,{paddingX:2,children:[jsx(Text,{color:e.ghost,children:Te(y)}),jsx(Text,{backgroundColor:Pn.amber,color:e.amber,bold:true,children:h}),jsx(Text,{color:e.ghost,children:Te(m)})]})}var Wl="\u25C7";function Ks({memberCount:t,width:n}){let o=`${t} agent${t!==1?"s":""}`,r=` ${Wl} UNASSIGNED ${fe} ${o} `,s=3,f=Math.max(0,n-s-r.length-4);return jsxs(Box,{paddingX:2,children:[jsx(Text,{color:e.ghost,children:Te(s)}),jsx(Text,{backgroundColor:Pn.neutral,color:e.dim,children:r}),jsx(Text,{color:e.ghost,children:Te(f)})]})}var Ys="\u2713",Zs="\u2715",zl="\u2016",Vl="\u25C9",co={green:"#0f2d1f",amber:"#2d1f0a",neutral:"#1a1a22"},jl={active:{icon:Vl,label:"ACTIVE",fg:e.green,bg:co.green,bold:true},paused:{icon:zl,label:"PAUSED",fg:e.dim,bg:co.neutral},achieved:{icon:Ys,label:"DONE",fg:e.amber,bg:co.amber,bold:true},abandoned:{icon:Zs,label:"DROP",fg:e.ghost,bg:co.neutral}},Hl="\u2588",Ul="\u2591",Xl=14,Js=uo.memo(function({goal:n,selected:o,width:r,agentNameMap:s,tasksByGoal:f}){let h=jl[n.status],y=o?"\u25B8":" ",m=f?.length??0,T=f?.filter(B=>B.status==="done").length??0,S=m>0,I=11,M=S?Xl:0,v=14,L=7,_=2+I+M+v+L,R=r?Math.max(10,r-_):40,C=n.assignee?s?.get(n.assignee)??n.assignee:void 0,z,P;if(n.status==="achieved")z=Ys,P=e.amber;else if(n.status==="abandoned")z=Zs,P=e.ghost;else {let B=Date.now()-new Date(n.created_at).getTime(),H=Math.floor(B/864e5);z=H>0?`${H}d`:"<1d",P=e.dim;}return jsxs(Box,{children:[jsxs(Text,{color:o?e.amber:void 0,children:[y," "]}),jsx(Box,{width:I,children:jsxs(Text,{backgroundColor:h.bg,color:h.fg,bold:h.bold,children:[" ",h.icon," ",h.label," "]})}),jsx(Box,{width:R,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>R?n.title.slice(0,R-1)+"\u2026":n.title})}),S&&(()=>{let H=m>0?Math.round(T/m*6):0,G=6-H;return jsxs(Box,{width:M,children:[jsx(Text,{color:e.green,children:Hl.repeat(H)}),jsx(Text,{color:e.ghost,children:Ul.repeat(G)}),jsx(Text,{color:e.dim,children:` ${T}/${m}`})]})})(),jsx(Box,{width:v,children:C?jsxs(Text,{backgroundColor:co.green,color:e.green,wrap:"truncate",children:[" ",C.length>v-2?C.slice(0,v-3)+"\u2026":C," "]}):jsx(Text,{color:e.ghost,children:"\u2014"})}),jsx(Box,{width:L,justifyContent:"flex-end",children:jsx(Text,{color:P,dimColor:!P,children:z})})]})});var ql={system:"\u2666",lifecycle:"\u25B6",output:"\u2502",tool:"\u2699",result:"\u2190",error:"\u2715",file:"\u270E",info:"\u2502"};function Fn({label:t,width:n,color:o}){let r=n-4,s=` ${t} `,f=3,h=Math.max(0,r-f-s.length);return jsxs(Text,{color:o??e.ghost,children:[" ",Te(f),s,Te(h)]})}function Qs({task:t,height:n,width:o,taskLogs:r,agentNameMap:s,taskTitleMap:f}){let h=Oo[t.status]??e.dim,y=t.priority<=2?t.priority===1?e.red:e.yellow:void 0,m=24,T=!!t.description?.trim(),S=!!t.proof?.agent_summary,I=(t.proof?.files_changed?.length??0)>0,M=(r?.length??0)>0,v=(t.attachments?.length??0)>0,L=T?t.description.split(`
4
4
  `):[],_=S?t.proof.agent_summary.split(`
5
- `):[],R=3;v&&(R+=2+t.attachments.length),T?(R+=1,R+=Math.min(L.length,Math.max(1,Math.ceil((n-10)*.3)))):S||(R+=2),S&&(R+=2),I&&(R+=1),M&&(R+=2);let C=Math.max(0,n-R),z=0,P=0;S&&M?(z=Math.max(1,Math.floor(C*.4)),P=Math.max(1,C-z)):S?z=C:M&&(P=C);let $=T?L.slice(0,Math.max(1,Math.ceil((n-10)*.3))):[],H=_.slice(0,z);return jsxs(Box,{flexDirection:"column",paddingX:2,children:[jsxs(Box,{children:[jsxs(Box,{width:m,children:[jsx(Text,{color:e.dim,children:" status "}),jsx(Text,{color:h,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?s?.get(t.assignee)??t.assignee:"\u2014"})]})]}),jsxs(Box,{children:[jsxs(Box,{width:m,children:[jsx(Text,{color:e.dim,children:" priority "}),jsxs(Text,{color:y,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:m,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(G=>f?.get(G)??G).join(", "):"\u2014"})]})]}),v&&jsxs(Fragment,{children:[jsx(Text,{children:" "}),jsx(Fn,{label:`attachments (${t.attachments.length})`,width:o,color:e.dim}),t.attachments.map((G,W)=>jsxs(Text,{color:e.cyan,wrap:"truncate",children:[" ",G]},`a${W}`))]}),T&&jsxs(Fragment,{children:[jsx(Text,{children:" "}),$.map((G,W)=>jsxs(Text,{color:e.silver,wrap:"truncate",children:[" ",it(G,o-8)]},`d${W}`))]}),!T&&!S&&jsxs(Fragment,{children:[jsx(Text,{children:" "}),jsx(Text,{color:e.dim,children:" No description."})]}),S&&jsxs(Fragment,{children:[jsx(Text,{children:" "}),jsx(Fn,{label:"result",width:o,color:e.dim}),H.map((G,W)=>jsxs(Text,{color:e.white,wrap:"truncate",children:[" ",it(G,o-8)]},`r${W}`))]}),I&&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})]})]}),M&&jsxs(Fragment,{children:[jsx(Text,{children:" "}),jsx(Fn,{label:"activity",width:o,color:e.dim}),r.slice(-P).map((G,W)=>{let w=G.msgType??"info",U=Xl[w]??"\u2502",ie=G.color;w==="tool"?ie=e.cyan:w==="file"?ie=e.purple:w==="error"?ie=e.red:w==="lifecycle"?ie=e.green:w==="system"&&(ie=e.dim);let oe=Math.max(10,o-12),we=it(G.text,oe);return jsxs(Box,{children:[jsxs(Text,{color:e.ghost,children:[" ",G.time," "]}),jsxs(Text,{color:w==="error"?e.red:e.dim,children:[U," "]}),jsx(Text,{color:ie,bold:w==="lifecycle",children:we})]},W)})]})]})}var No=[{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 Qs="\u25CF",ei="\u25CB",ql="\u2713",Kl="\u2715",Yl="\u2191",Zl="\u2193",Jl="\u03A3",Ql="\u25B6",ec="\u21BB",tc="\u{1F9E0}",Lr=[" ","\u2581","\u2582","\u2583","\u2584","\u2585","\u2586","\u2587","\u2588"],et={green:"#0f2d1f",blue:"#0f1f2d",yellow:"#2d2a0f",red:"#2d0f0f",neutral:"#1a1a22",amber:"#2d1f0a"};function nc({active:t}){let n=Ln(t),o=!t||Math.floor(n/10)%2===0;return jsx(Text,{color:o?e.amber:e.amberDim,bold:true,children:jt})}function oc({width:t,active:n}){let o=Math.max(4,Math.floor(t*.08)),r=2,s=Ln(n),f=Math.ceil((t+o)/r),h=n?s%(f*2):0;if(!n)return jsx(Box,{paddingX:1,children:jsx(Text,{color:e.ghost,children:He(t)})});let y=h<f?h*r:(f*2-h)*r,m=Math.max(0,y-o),T=Math.min(t,y),S=m,I=Math.max(0,T-m),M=Math.max(0,t-T);return jsxs(Box,{paddingX:1,children:[jsx(Text,{color:e.ghost,children:He(S)}),jsx(Text,{color:e.amber,children:He(I)}),jsx(Text,{color:e.ghost,children:He(M)})]})}function rc({data:t,width:n,color:o}){if(t.length===0)return null;let r=t.slice(-n),s=Math.max(...r,1),f=r.map(h=>{let y=Math.round(h/s*(Lr.length-1));return Lr[y]??Lr[0]}).join("");return jsx(Text,{color:o,children:f})}function sc({tab:t,flashColor:n,onComplete:o,badge:r}){let s=Ln(),f=co.useRef(s),h=co.useRef(false),y=s-f.current,m=2,T=6*m;return co.useEffect(()=>{y>=T&&!h.current&&(h.current=true,o());},[y,o]),Math.floor(y/m)%2===0&&y<T?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 ic({projectName:t,activeView:n,mode:o,stats:r,uptime:s,width:f,version:h,latestVersion:y,updateInstalled:m,taskBadge:T,flashTab:S,flashColor:I,onFlashComplete:M}){return jsxs(Box,{paddingX:1,justifyContent:"space-between",width:f,children:[jsxs(Box,{gap:0,children:[jsx(nc,{active:r.running>0}),jsx(Text,{color:e.amber,bold:true,children:" ORCH"}),h&&jsxs(Text,{color:e.ghost,children:[" ",h]}),y&&y!==h&&(m?jsxs(Text,{backgroundColor:et.green,color:e.green,bold:true,children:[" v",y," INSTALLED \u2014 RESTART TO APPLY "]}):jsxs(Text,{backgroundColor:et.green,color:e.green,bold:true,children:[" UPDATE ",y," "]})),jsxs(Text,{color:e.ghost,children:[" ",fe," "]}),jsx(Text,{color:e.silver,children:t})]}),jsx(Box,{gap:0,children:No.map((v,L)=>{let _=n===v.id,R=v.id==="tasks"&&T!=null&&T>0?` (${T})`:"",C=!_&&S===v.id&&I&&M;return jsxs(co.Fragment,{children:[L>0&&jsx(Text,{children:" "}),_?jsxs(Text,{backgroundColor:e.amber,color:"#0a0a0c",bold:true,children:[" ",v.key," ",v.label,R," "]}):C?jsx(sc,{tab:v,flashColor:I,onComplete:M,badge:R}):jsxs(Box,{gap:0,children:[jsx(Text,{color:e.ghost,children:v.key}),jsxs(Text,{color:e.dim,children:[" ",v.label.toLowerCase(),R]})]})]},v.id)})}),jsxs(Box,{gap:0,children:[o==="watching"?jsxs(Text,{backgroundColor:et.green,color:e.green,bold:true,children:[" ",Qs," WATCHING"," "]}):o==="observing"?jsxs(Text,{backgroundColor:et.amber,color:e.amber,bold:true,children:[" ",Qs," OBSERVING"," "]}):jsxs(Text,{backgroundColor:et.neutral,color:e.dim,children:[" ",ei," IDLE"," "]}),r.running>0&&jsxs(Fragment,{children:[jsx(Text,{children:" "}),jsxs(Text,{backgroundColor:et.green,color:e.green,children:[" ",jsx(Ht,{color:e.green})," ",r.running," active"," "]})]}),s&&jsxs(Text,{color:e.ghost,children:[" ",s]})]})]})}function ac({stats:t,tokens:n,width:o,sparklineData:r}){let f=[{icon:Ql,label:"RUN",count:t.running,fg:e.green,bg:et.green,bold:true,spinner:true,show:t.running>0},{icon:ec,label:"RETRY",count:t.retrying,fg:e.yellow,bg:et.yellow,show:t.retrying>0},{icon:Zt,label:"REVIEW",count:t.review,fg:e.blue,bg:et.blue,show:t.review>0},{icon:ei,label:"TODO",count:t.todo,fg:e.dim,bg:et.neutral,show:t.todo>0},{icon:ql,label:"DONE",count:t.done,fg:e.green,bg:et.green,show:t.done>0},{icon:Kl,label:"FAIL",count:t.failed,fg:e.red,bg:et.red,bold:true,show:t.failed>0},{icon:jt,label:"TEAMS",count:t.teams,fg:e.amber,bg:et.amber,show:t.teams>0}].filter(m=>m.show),h$1=n.total>0,y=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:[f.map(m=>jsx(Text,{backgroundColor:m.bg,color:m.fg,bold:m.bold,children:m.spinner?jsxs(Fragment,{children:[" ",jsx(Ht,{color:m.fg})," ",m.count," ",m.label," "]}):jsxs(Fragment,{children:[" ",m.icon," ",m.count," ",m.label," "]})},m.label)),f.length===0&&jsxs(Text,{backgroundColor:et.neutral,color:e.dim,children:[" ","NO TASKS"," "]})]}),jsxs(Box,{gap:0,children:[y>0&&r&&jsxs(Fragment,{children:[jsx(rc,{data:r,width:y,color:e.amberDim}),jsx(Text,{children:" "})]}),h$1&&jsxs(Text,{backgroundColor:et.amber,color:e.cyan,children:[" ",Yl,h(n.input)," ",Zl,h(n.output),n.reasoning>0?` ${tc}${h(n.reasoning)}`:""," ",fe," ",Jl,h(n.total)," "]})]})]})}var ti=co.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(ic,{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(ac,{stats:n.stats,tokens:n.tokens,width:n.width,sparklineData:n.sparklineData}),jsx(oc,{width:o,active:r})]})});var uo="\u0423\u041F\u0420\u0410\u0412\u041B\u0415\u041D\u0418\u0415",Wn="\u041C\u041E\u041D\u0418\u0422\u041E\u0420\u0418\u041D\u0413",Fo="\u041D\u0410\u0421\u0422\u0420\u041E\u0419\u041A\u0418",bn={task:{sub:["add","list","show","cancel","retry","assign","approve","reject","delete"],help:"Manage tasks",category:uo},agent:{sub:["add","list","disable","enable","delete","autonomous","shop"],help:"Manage agents",category:uo},team:{sub:["create","list","join","leave","disband","set-lead"],help:"Manage teams",category:uo},goal:{sub:["add","list","show","status","delete"],help:"Manage goals",category:uo},run:{args:"[id]",help:"Run task (or selected)",category:Wn},"run-all":{help:"Run all todo tasks",category:Wn},watch:{help:"Start watch mode (auto-dispatch)",category:Wn},pause:{help:"Pause watch mode",category:Wn},status:{help:"Show orchestrator status",category:Wn},config:{sub:["activity-filter","max-concurrent"],help:"TUI settings",category:Fo},help:{help:"List all commands",category:Fo},quit:{help:"Exit the TUI",category:Fo}};function Pr(t){if(!t.startsWith("/"))return null;let n=t.slice(1),o=n.indexOf(" ");if(o===-1){let y=n;if(!y)return null;let m=Object.keys(bn).find(T=>T.startsWith(y)&&T!==y);return m?m.slice(y.length):null}let r=n.slice(0,o),s=bn[r];if(!s?.sub)return null;let f=n.slice(o+1);if(!f)return null;let h=s.sub.find(y=>y.startsWith(f)&&y!==f);return h?h.slice(f.length):null}function ni(t){if(!t.startsWith("/"))return [];let n=t.slice(1),o=n.indexOf(" ");if(o===-1){let y=n.toLowerCase(),m=[];if(!y){let T=[uo,Wn,Fo];for(let S of T){m.push({cmd:"",desc:`\u2500\u2500 ${S} \u2500\u2500`});for(let[I,M]of Object.entries(bn))if(M.category===S){let v=M.args?` ${M.args}`:"";m.push({cmd:`/${I}${v}`,desc:M.help,subs:M.sub?.join(" \xB7 ")});}}return m}for(let[T,S]of Object.entries(bn))if(T.startsWith(y)){let I=S.args?` ${S.args}`:"";if(m.push({cmd:`/${T}${I}`,desc:S.help,subs:S.sub?.join(" \xB7 ")}),T===y&&S.sub)for(let M of S.sub)m.push({cmd:`/${T} ${M}`,desc:`${S.help}: ${M}`});}return m}let r=n.slice(0,o),s=bn[r];if(!s?.sub)return [];let f=n.slice(o+1).toLowerCase(),h=[];for(let y of s.sub)(!f||y.startsWith(f))&&h.push({cmd:`/${r} ${y}`,desc:`${s.help}: ${y}`});return h}var Wo=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 cc="\u2588",oi=co.memo(function({mode:n,value:o,completion:r,activeView:s,canRun:f,canNew:h,canApprove:y,canReject:m,canCancel:T,canDelete:S,canUndo:I,canEdit:M,canForceStop:v,canToggleAuto:L,autoActive:_,canPause:R,isPaused:C,canToggleShowAll:z,showAllActive:P,hasDetail:$,itemCount:H,itemLabel:G,width:W,hasSuggestions:w,onboardingCompleted:U}){if(n==="command"){let ie=w?" \u2191\u2193 select Tab fill Esc \u2715":" Enter exec \u2191\u2193 history Tab complete Esc \u2715",oe=Math.max(4,W-6-ie.length-(r?.length??0)-1),we=o.length>oe?"\u2026"+o.slice(-(oe-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:we}),r&&jsx(Text,{color:e.ghost,children:r}),jsx(Text,{color:e.amber,children:cc}),jsx(Text,{color:e.dim,children:ie})]})})}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",h&&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"]}),T&&jsxs(Fragment,{children:[" ",jsx(Text,{bold:true,color:e.amber,children:"C"})," cancel"]}),y&&jsxs(Fragment,{children:[" ",jsx(Text,{bold:true,color:e.green,children:"A"})," approve"]}),m&&jsxs(Fragment,{children:[" ",jsx(Text,{bold:true,color:e.red,children:"X"})," reject"]}),M&&jsxs(Fragment,{children:[" ",jsx(Text,{bold:true,color:e.cyan,children:"E"})," edit"]}),v&&jsxs(Fragment,{children:[" ",jsx(Text,{bold:true,color:e.red,children:"S"})," stop"]}),R&&jsxs(Fragment,{children:[" ",jsx(Text,{bold:true,color:e.amber,children:"P"}),C?" resume":" pause"]}),L&&jsxs(Fragment,{children:[" ",jsx(Text,{bold:true,color:e.cyan,children:"U"}),_?" auto off":" auto on"]}),z&&jsxs(Fragment,{children:[" ",jsx(Text,{bold:true,color:e.gray,children:"S"}),P?" collapse":" show all"]}),S&&!y&&jsxs(Fragment,{children:[" ",jsx(Text,{bold:true,color:e.gray,children:"D"})," delete"]}),I&&jsxs(Fragment,{children:[" ",jsx(Text,{bold:true,color:e.yellow,children:"Z"})," undo"]}),$&&jsxs(Fragment,{children:[" ",jsx(Text,{bold:true,color:e.gray,children:"Esc"})," close"]}),!$&&(s==="tasks"||s==="agents"||s==="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:U===false?e.amber:e.gray,children:"?"}),jsx(Text,{color:U===false?e.amber:void 0,children:" help"})]}),H>0&&jsxs(Text,{color:e.dim,children:[H," ",G]})]})});var ii=new Intl.Segmenter(void 0,{granularity:"grapheme"});function ri(t){return [...ii.segment(t)].map(n=>n.segment)}function Go(t){let n=t.codePointAt(0)??0;return n>=11904&&n<=40959||n>=4352&&n<=4447||n>=43360&&n<=43391||n>=44032&&n<=55215||n>=63744&&n<=64255||n>=65040&&n<=65135||n>=65281&&n<=65376||n>=65504&&n<=65510||n>=131072&&n<=195103||n>=127744&&n<=129791?2:1}function ai(t){let n=0;for(let o of ii.segment(t))n+=Go(o.segment);return n}function si(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 dc(t,n){let o=t.length;if(n>=o)return o;let r=n;for(;r<o&&t[r]!==" ";)r++;for(;r<o&&t[r]===" ";)r++;return r}var Gn=class t{text;pos;_segs;constructor(n,o){this.text=n.normalize("NFC"),this._segs=ri(this.text),this.pos=o!==void 0?Math.max(0,Math.min(o,this._segs.length)):this._segs.length;}static _withPos(n,o,r){let s=Object.create(t.prototype);return Object.defineProperty(s,"text",{value:n,writable:false}),Object.defineProperty(s,"_segs",{value:o,writable:false}),Object.defineProperty(s,"pos",{value:Math.max(0,Math.min(r,o.length)),writable:false}),s}get length(){return this._segs.length}get beforeSegs(){return this._segs.slice(0,this.pos)}get afterSegs(){return this._segs.slice(this.pos)}get before(){return this.beforeSegs.join("")}get after(){return this.afterSegs.join("")}get isEmpty(){return this.text.length===0}moveLeft(n=1){return t._withPos(this.text,this._segs,this.pos-n)}moveRight(n=1){return t._withPos(this.text,this._segs,this.pos+n)}moveToStart(){return t._withPos(this.text,this._segs,0)}moveToEnd(){return t._withPos(this.text,this._segs,this._segs.length)}moveToWordBack(){return t._withPos(this.text,this._segs,si(this._segs,this.pos))}moveToWordForward(){return t._withPos(this.text,this._segs,dc(this._segs,this.pos))}insert(n){let o=n.normalize("NFC"),r=ri(o),s=this._segs.slice(0,this.pos).join("")+o+this._segs.slice(this.pos).join("");return new t(s,this.pos+r.length)}deleteBack(){if(this.pos<=0)return this;let n=this._segs,o=n.slice(0,this.pos-1).join("")+n.slice(this.pos).join("");return new t(o,this.pos-1)}deleteForward(){let n=this._segs;if(this.pos>=n.length)return this;let o=n.slice(0,this.pos).join("")+n.slice(this.pos+1).join("");return new t(o,this.pos)}killToEnd(){let n=this._segs,o=n.slice(this.pos).join(""),r=n.slice(0,this.pos).join("");return [new t(r,this.pos),o]}killToStart(){let n=this._segs,o=n.slice(0,this.pos).join(""),r=n.slice(this.pos).join("");return [new t(r,0),o]}killWordBack(){let n=this._segs,o=si(n,this.pos),r=n.slice(o,this.pos).join(""),s=n.slice(0,o).join("")+n.slice(this.pos).join("");return [new t(s,o),r]}replaceAll(n){return new t(n)}clear(){return new t("")}};var mc=500;function Vo(t={}){let n=t.maxUndoDepth??50,[o,r]=useState(()=>new Gn(t.initialValue??"")),s=useRef([]),f=useRef(null),h=useRef(""),y=useRef(o);y.current=o;let m=useCallback(L=>{y.current=L,r(L);},[]),T=useCallback(()=>{f.current&&(clearTimeout(f.current),f.current=null);let L=s.current,_=y.current;L.length>0&&L[L.length-1].text===_.text||(L.push(_),L.length>n&&L.shift());},[n]),S=useCallback(()=>{f.current&&clearTimeout(f.current),f.current=setTimeout(()=>{f.current=null,T();},mc);},[T]);useEffect(()=>()=>{f.current&&clearTimeout(f.current);},[]);let I=useCallback((L,_)=>{if(!L&&!_.backspace&&!_.delete&&!_.leftArrow&&!_.rightArrow&&!_.home&&!_.end)return false;let R=y.current;if(_.ctrl)switch(L){case "a":return m(R.moveToStart()),true;case "e":return m(R.moveToEnd()),true;case "k":{T();let[C,z]=R.killToEnd();return h.current=z,m(C),true}case "u":{T();let[C,z]=R.killToStart();return h.current=z,m(C),true}case "w":{T();let[C,z]=R.killWordBack();return h.current=z,m(C),true}case "y":return h.current&&(T(),m(R.insert(h.current))),true;case "z":{let C=s.current;return C.length>0&&C[C.length-1].text===R.text&&C.pop(),C.length>0&&m(C.pop()),true}case "b":return m(R.moveLeft()),true;case "f":return m(R.moveRight()),true;case "d":return R.isEmpty||(S(),m(R.deleteForward())),true;case "h":return R.pos>0&&(S(),m(R.deleteBack())),true;default:return false}if(_.meta){if(L==="z"){let C=s.current;for(;C.length>0&&C[C.length-1].text===R.text;)C.pop();return C.length>0&&m(C.pop()),true}if(L==="a")return m(R.moveToStart()),true;if(_.backspace||_.delete){T();let[C,z]=R.killToStart();return h.current=z,m(C),true}return _.leftArrow||L==="b"?(m(R.moveToWordBack()),true):_.rightArrow||L==="f"?(m(R.moveToWordForward()),true):false}return _.home?(m(R.moveToStart()),true):_.end?(m(R.moveToEnd()),true):_.leftArrow?(m(R.moveLeft()),true):_.rightArrow?(m(R.moveRight()),true):_.backspace||_.delete?(R.pos>0&&(S(),m(R.deleteBack())),true):L&&!_.escape?(S(),m(R.insert(L)),true):false},[m,T,S]),M=useCallback(L=>{let _=new Gn(L??"");m(_),s.current=[],f.current&&(clearTimeout(f.current),f.current=null);},[m]),v=useCallback(L=>{m(new Gn(L)),s.current=[];},[m]);return {cursor:o,value:o.text,handleInput:I,reset:M,setValue:v,setCursor:m}}var ci="\u2588";function fc(t,n,o){let r=0,s=t.length;for(;s>0;){let S=t[s-1],I=Go(S);if(r+I>o-1)break;r+=I,s--;}let f=t.slice(s).join(""),h=Math.max(0,o-r-1),y=0,m=0;for(;m<n.length;){let S=n[m],I=Go(S);if(y+I>h)break;y+=I,m++;}let T=n.slice(0,m).join("");return {visibleBefore:f,visibleAfter:T}}function jo({cursor:t,width:n,prefix:o,prefixColor:r=e.amber,placeholder:s,ghost:f,ghostColor:h=e.ghost,showCursor:y=true,cursorColor:m=e.amber,textColor:T=e.white,placeholderColor:S=e.ghost,hasError:I=false}){let M=o??"",v=ai(M),L=Math.max(4,n-v),_=t.isEmpty,{visibleBefore:R,visibleAfter:C}=fc(t.beforeSegs,t.afterSegs,L),z=I?"round":void 0,P=I?e.red:void 0;return _?jsxs(Box,{borderStyle:z,borderColor:P,children:[M&&jsx(Text,{color:r,children:M}),s&&jsx(Text,{color:S,children:s}),y&&jsx(Text,{color:m,children:ci})]}):jsxs(Box,{borderStyle:z,borderColor:P,children:[M&&jsx(Text,{color:r,children:M}),jsx(Text,{color:T,children:R}),y&&jsx(Text,{color:m,children:ci}),jsx(Text,{color:T,children:C}),f&&jsx(Text,{color:h,children:f})]})}var xc="\u2588",Dr=process.platform==="darwin"?"\u2318":"Ctrl";function bc(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 mi(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 Tc(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 fi({title:t,steps:n,onComplete:o,onCancel:r,width:s,height:f,onPasteImage:h,footerExtra:y,onSuggestionSelected:m}){let [T,S]=useState(0),[I,M]=useState({}),v=Vo({initialValue:(()=>{let D=n.find(O=>!O.skip?.({}));return D?.type==="text"&&D.defaultValue?D.defaultValue:""})()}),L=v.value,[_,R]=useState(()=>{let D=n.find(O=>!O.skip?.({}));return D?.type==="textarea"&&D.defaultValue?D.defaultValue.split(`
6
- `):[""]}),[C,z]=useState(0),[P,$]=useState(0),[H,G]=useState(()=>{let D=n.find(O=>!O.skip?.({}));if(D?.type==="select"&&D.defaultValue){let N=(D.getOptions?.({})??D.options??[]).findIndex(B=>B.value===D.defaultValue);return N>=0?N:0}return 0}),W=useMemo(()=>n.filter(D=>!D.skip?.(I)),[n,I]),w=W[T],U=W.length,{taLineNumWidth:oe,taContentWidth:we}=useMemo(()=>{let D=String(_.length).length;return {taLineNumWidth:D,taContentWidth:Math.max(1,s-D-4)}},[_.length,s]),We=useMemo(()=>{if(!w||w.type!=="textarea")return [];let D=[];for(let O=0;O<_.length;O++){let N=bc(_[O]??"",we);for(let B=0;B<N.length;B++)D.push({logicalRow:O,startCol:B*we,text:N[B],isFirst:B===0});}return D},[w?.id,w?.type,_,we]),Ge=useMemo(()=>{for(let D=0;D<We.length;D++){let O=We[D];if(O.logicalRow===C&&(P>=O.startCol&&P<O.startCol+we||P>=O.startCol&&(D+1>=We.length||We[D+1].logicalRow!==C)))return D}return 0},[We,C,P,we]),[ut,Ct]=useState(new Set),[gt,mt]=useState(false),[Ye,Ze]=useState(0),[ft,Ce]=useState(false),[Wt,It]=useState(null),[ht,Je]=useState(false),ot=useRef(null),Xe=useRef(null),fo=useMemo(()=>w?w.type==="text"?L:w.type==="textarea"?_.join(`
7
- `):"":"",[w,L,_]),rn=useCallback((D,O)=>{if(ot.current&&clearTimeout(ot.current),!O){It(null);return}ot.current=setTimeout(()=>{It(O(D));},300);},[]);useEffect(()=>(w&&w.validate&&(w.type==="text"||w.type==="textarea")&&rn(fo,w.validate),()=>{ot.current&&clearTimeout(ot.current);}),[fo,w,rn]),useEffect(()=>()=>{Xe.current&&clearTimeout(Xe.current);},[]);let Bt=useMemo(()=>!w||w.type!=="select"&&w.type!=="multiselect"?[]:w.getOptions?.(I)??w.options??[],[w,I]),Gt=Math.min(H,Math.max(0,Bt.length-1)),zt=useMemo(()=>{if(!w?.suggestions)return [];if(!L.trim())return w.suggestions;let D=L.toLowerCase();return w.suggestions.filter(O=>O.label.toLowerCase().includes(D)||(O.hint??"").toLowerCase().includes(D))},[w?.suggestions,L]),qt=Math.min(Ye,Math.max(0,zt.length-1)),sn=D=>{let O={...I,[w.id]:D};M(O),v.reset(""),R([""]),z(0),$(0),G(0),Ct(new Set),mt(false),Ze(0),Ce(false),It(null),Je(false),ot.current&&clearTimeout(ot.current);let N=w.id,q=n.findIndex(ne=>ne.id===N)+1;for(;q<n.length;){let ne=n[q];if(ne&&!ne.skip?.(O))break;q++;}if(q>=n.length)o(O);else {let ne=n[q].id,ae=n.filter(ce=>!ce.skip?.(O)).findIndex(ce=>ce.id===ne);S(ae>=0?ae:0);let ue=n[q];if(ue.type==="text")v.reset(ue.defaultValue??"");else if(ue.type==="textarea"){let ce=ue.defaultValue?ue.defaultValue.split(`
8
- `):[""];R(ce),z(ce.length-1),$(ce[ce.length-1].length);}else if(ue.type==="select"){let ce=ue.getOptions?.(O)??ue.options??[];if(ue.defaultValue){let Kt=ce.findIndex(de=>de.value===ue.defaultValue);G(Kt>=0?Kt:0);}else G(0);}else ue.type==="multiselect"&&(G(0),ue.defaultValue?Ct(new Set(ue.defaultValue.split(","))):Ct(new Set));}},an=()=>{if(T===0){r();return}let D=w.id,N=n.findIndex(ae=>ae.id===D)-1;for(;N>=0;){let ae=n[N];if(ae&&!ae.skip?.(I))break;N--;}if(N<0){r();return}let B=n[N].id,q=W.findIndex(ae=>ae.id===B);S(q>=0?q:0),mt(false),Ze(0),Ce(false),It(null),Je(false),ot.current&&clearTimeout(ot.current);let ne=n[N];if(I[ne.id]&&Ce(true),ne.type==="text")v.reset(I[ne.id]??ne.defaultValue??"");else if(ne.type==="textarea"){let ae=I[ne.id]??ne.defaultValue??"",ue=ae?ae.split(`
9
- `):[""];R(ue),z(ue.length-1),$(ue[ue.length-1].length);}else if(ne.type==="multiselect"){G(0);let ae=I[ne.id];Ct(ae?new Set(ae.split(",")):new Set);}else {let ae=ne.getOptions?.(I)??ne.options??[],ue=I[ne.id],ce=ae.findIndex(Kt=>Kt.value===ue);G(ce>=0?ce:0);}};if(useInput((D,O)=>{if(w){if(O.escape){T===0?r():an();return}if((O.ctrl||O.meta)&&(D==="v"||D==="i")&&h&&(w.type==="text"||w.type==="textarea")){h();return}if(w.type==="text"){if(gt&&zt.length>0){if(O.upArrow){qt<=0?mt(false):Ze(B=>B-1);return}if(O.downArrow){Ze(B=>Math.min(zt.length-1,B+1));return}if(O.return){let B=zt[qt];B&&m&&m(B.value);return}mt(false);}if(O.return){let B=L.trim();if(w.required&&!B){Ce(true);return}if(Wt!==null){Ce(true),Je(true),Xe.current&&clearTimeout(Xe.current),Xe.current=setTimeout(()=>Je(false),2e3);return}sn(B);return}if(O.downArrow&&w.suggestions&&zt.length>0){mt(true),Ze(0);return}if((O.backspace||O.delete)&&v.cursor.isEmpty&&T>0){an();return}v.handleInput(D,O)&&(Ce(true),mt(false),Ze(0));return}if(w.type==="textarea"){if(O.return&&(O.ctrl||O.meta)){let N=_.join(`
10
- `).trim();if(w.required&&!N){Ce(true);return}if(Wt!==null){Ce(true),Je(true),Xe.current&&clearTimeout(Xe.current),Xe.current=setTimeout(()=>Je(false),2e3);return}sn(N);return}if(O.return){Ce(true),R(N=>{let B=N[C]??"",q=B.slice(0,P),ne=B.slice(P),_e=[...N];return _e.splice(C,1,q,ne),_e}),z(N=>N+1),$(0);return}if(O.ctrl&&D==="a"){$(0);return}if(O.ctrl&&D==="e"){$((_[C]??"").length);return}if(O.ctrl&&D==="k"){Ce(true),R(N=>{let B=[...N];return B[C]=(B[C]??"").slice(0,P),B});return}if(O.ctrl&&D==="u"){Ce(true),R(N=>{let B=[...N];return B[C]=(B[C]??"").slice(P),B}),$(0);return}if(O.ctrl&&D==="w"){Ce(true);let N=C,B=P,q=_[N]??"",ne=mi(q,B);R(_e=>{let ae=[..._e];return ae[N]=q.slice(0,ne)+q.slice(B),ae}),$(ne);return}if(O.meta&&(O.leftArrow||D==="b")){$(mi(_[C]??"",P));return}if(O.meta&&(O.rightArrow||D==="f")){$(Tc(_[C]??"",P));return}if(O.upArrow){if(Ge>0){let N=We[Ge],B=We[Ge-1],q=P-(N?.startCol??0),ne=Math.min(B.startCol+q,B.startCol+B.text.length);z(B.logicalRow),$(ne);}return}if(O.downArrow){if(Ge<We.length-1){let N=We[Ge],B=We[Ge+1],q=P-(N?.startCol??0),ne=Math.min(B.startCol+q,B.startCol+B.text.length);z(B.logicalRow),$(ne);}return}if(O.leftArrow){P>0?$(N=>N-1):C>0&&(z(N=>N-1),$((_[C-1]??"").length));return}if(O.rightArrow){let N=(_[C]??"").length;P<N?$(B=>B+1):C<_.length-1&&(z(B=>B+1),$(0));return}if(O.backspace||O.delete){if(P===0&&C===0)return;if(P>0)R(N=>{let B=[...N],q=B[C]??"";return B[C]=q.slice(0,P-1)+q.slice(P),B}),$(N=>N-1);else {let N=(_[C-1]??"").length;R(B=>{let q=[...B],ne=q[C-1]??"",_e=q[C]??"";return q.splice(C-1,2,ne+_e),q}),$(N),z(B=>B-1);}return}if(D&&!O.ctrl&&!O.meta&&!O.escape){Ce(true);let N=D.split(/\r?\n/);if(N.length===1)R(B=>{let q=[...B],ne=q[C]??"";return q[C]=ne.slice(0,P)+D+ne.slice(P),q}),$(B=>B+D.length);else {let B=C,q=P;R(ne=>{let _e=[...ne],ae=_e[B]??"",ue=ae.slice(0,q),ce=ae.slice(q),Kt=N[0]??"",de=N[N.length-1]??"",cr=[ue+Kt,...N.slice(1,-1),de+ce];return _e.splice(B,1,...cr),_e}),z(B+N.length-1),$((N[N.length-1]??"").length);}}return}if(w.type==="select"||w.type==="multiselect"){if(O.upArrow||D==="k"){G(N=>Math.max(0,N-1));return}if(O.downArrow||D==="j"){G(N=>Math.min(Bt.length-1,N+1));return}if(O.backspace||O.delete){an();return}if(w.type==="select"){if(O.return||O.tab){let N=Bt[Gt];if(N){if(w.validate){let B=w.validate(N.value);if(B!==null){Ce(true),It(B),Je(true),Xe.current&&clearTimeout(Xe.current),Xe.current=setTimeout(()=>Je(false),2e3);return}}sn(N.value);}return}if(D>="1"&&D<="9"){let N=parseInt(D,10)-1;if(N<Bt.length){let B=Bt[N];B&&sn(B.value);}return}}else {if(D===" "){let N=Bt[Gt];N&&Ct(B=>{let q=new Set(B);return q.has(N.value)?q.delete(N.value):q.add(N.value),q});return}if(O.return){let N=Array.from(ut).join(",");sn(N);return}}}}}),!w)return null;let vt=ft?Wt:null,wn=Math.max(20,s-6),Hn=`${T+1}/${U}`,ln=Math.max(2,f-4),rt=0;Gt>=ln&&(rt=Gt-ln+1);let cn=Bt.slice(rt,rt+ln);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:[" ",je,je," "]}),jsxs(Text,{color:e.dim,children:["step ",Hn]})]}),jsxs(Box,{children:[jsx(Text,{children:" "}),W.map((D,O)=>jsxs(Text,{color:O===T?e.amber:O<T?e.green:e.ghost,children:[O===T?"\u25CF":O<T?"\u2713":"\u25CB"," "]},D.id))]}),jsxs(Box,{marginTop:0,children:[jsxs(Text,{color:e.white,bold:true,children:[" ",w.label]}),w.required&&jsx(Text,{color:e.red,children:" *"}),!w.required&&jsxs(Text,{color:e.dim,children:[" (optional, ",w.type==="textarea"?`${Dr}+Enter`:"Enter"," to skip)"]})]}),w.description&&jsx(Box,{children:jsxs(Text,{color:e.dim,children:[" ",w.description]})}),w.type==="text"&&jsxs(Box,{flexDirection:"column",paddingLeft:2,children:[jsx(jo,{cursor:v.cursor,width:wn-4,prefix:"> ",placeholder:w.placeholder,hasError:!!vt}),vt&&jsxs(Text,{color:e.red,dimColor:true,children:[" ",vt]}),ht&&jsx(Text,{color:e.red,children:" Fix the error above"})]}),w.type==="text"&&w.suggestions&&zt.length>0&&(()=>{let D=Math.max(2,f-6),O=0;gt&&qt>=D&&(O=qt-D+1);let N=zt.slice(O,O+D);return jsxs(Box,{flexDirection:"column",children:[jsxs(Text,{color:e.ghost,children:[" ",je,je,je," or browse templates ",je.repeat(Math.max(0,wn-28))]}),N.map((B,q)=>{let ne=q+O,_e=gt&&ne===qt;return jsxs(Box,{children:[jsx(Text,{color:_e?e.amber:e.ghost,children:_e?" \u25B8 ":" "}),jsx(Text,{color:_e?e.white:e.silver,bold:_e,children:B.label}),B.hint&&jsxs(Text,{color:e.dim,wrap:"truncate",children:[" ",je," ",B.hint.replace(/\n/g," ")]})]},B.value)})]})})(),w.type==="textarea"&&(()=>{let D=Math.max(3,f-6),O=0;Ge>=D&&(O=Ge-D+1);let N=We.slice(O,O+D);return jsxs(Box,{flexDirection:"column",children:[jsxs(Box,{flexDirection:"column",borderStyle:vt?"round":void 0,borderColor:vt?e.red:void 0,children:[N.map((B,q)=>{let ne=q+O,_e=B.isFirst?String(B.logicalRow+1).padStart(oe," "):"".padStart(oe," "),ae=ne===Ge,ue=P-B.startCol;return jsxs(Box,{children:[jsxs(Text,{color:e.dim,children:[" ",_e," "]}),jsxs(Text,{color:e.ghost,children:["\u2502"," "]}),ae?jsxs(Fragment,{children:[jsx(Text,{color:e.white,children:B.text.slice(0,ue)}),jsx(Text,{color:e.amber,children:xc}),jsx(Text,{color:e.white,children:B.text.slice(ue)})]}):jsx(Text,{color:e.silver,children:B.text||(B.isFirst?" ":"")})]},`${B.logicalRow}-${B.startCol}`)}),_.length===1&&_[0]===""&&w.placeholder&&jsx(Box,{children:jsxs(Text,{color:e.dim,children:[" ","".padStart(oe," ")," ",w.placeholder]})})]}),vt&&jsxs(Text,{color:e.red,dimColor:true,children:[" ",vt]}),ht&&jsx(Text,{color:e.red,children:" Fix the error above"})]})})(),w.type==="select"&&jsxs(Box,{flexDirection:"column",children:[cn.map((D,O)=>{let N=O+rt,B=N===Gt,q=String(N+1).padStart(Bt.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:D.label}),D.hint&&jsxs(Text,{color:e.dim,wrap:"truncate",children:[" ",je," ",D.hint.replace(/\n/g," ")]})]},D.value)}),vt&&jsxs(Text,{color:e.red,dimColor:true,children:[" ",vt]}),ht&&jsx(Text,{color:e.red,children:" Fix the error above"})]}),w.type==="multiselect"&&jsxs(Box,{flexDirection:"column",children:[cn.map((D,O)=>{let B=O+rt===Gt,q=ut.has(D.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:[" ",D.label]}),D.hint&&jsxs(Text,{color:e.dim,wrap:"truncate",children:[" ",je," ",D.hint.replace(/\n/g," ")]})]},D.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:[" ",w.type==="select"?"\u2191\u2193 select Enter confirm":w.type==="multiselect"?"\u2191\u2193 move Space toggle Enter confirm":w.type==="textarea"?`Enter newline ${Dr}+Enter confirm \u2190\u2191\u2192\u2193 navigate`:gt?"\u2191\u2193 browse Enter select \u2191 back to input":w.suggestions?"\u2190\u2192 move Enter confirm \u2193 browse templates":"\u2190\u2192 move Enter confirm",h&&(w.type==="text"||w.type==="textarea")?` ${Dr}+V paste image`:""," Esc ",T>0?"back":"cancel"]}),y&&jsxs(Text,{color:e.amber,children:[" ",y]})]})]})}var xi=co.memo(function({agents:n,selected:o,msgCounts:r,colorMap:s,maxHeight:f,onConfirm:h,onCancel:y}){let [m,T]=useState(0),[S,I]=useState(()=>new Set(o));useMemo(()=>S.size===0||S.size===n.length,[S.size,n.length]);let v=Math.max(3,f-5),L=useMemo(()=>{if(n.length<=v)return 0;let C=Math.floor(v/2),z=n.length-v;return Math.min(z,Math.max(0,m-C))},[m,n.length,v]),_=n.slice(L,L+v);useInput((C,z)=>{if(z.upArrow){T(P=>P>0?P-1:n.length-1);return}if(z.downArrow){T(P=>P<n.length-1?P+1:0);return}if(C===" "){let P=n[m];if(!P)return;I($=>{let H=new Set($);return H.has(P.id)?H.delete(P.id):H.add(P.id),H});return}if(C==="a"||C==="A"){I(P=>new Set);return}if(z.return){h(new Set(S));return}if(z.escape){y();return}});let R=S.size===0?n.length:S.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," ",R,"/",n.length," selected"]})]}),jsx(Text,{color:e.ghost,children:je.repeat(36)}),_.map((C,z)=>{let $=z+L===m,H=S.size===0||S.has(C.id),G=s.get(C.id)??e.silver,W=r.get(C.id)??0;return jsxs(Box,{gap:0,children:[jsx(Text,{color:$?e.amber:e.ghost,children:$?" \u25B8 ":" "}),jsx(Text,{color:H?e.green:e.ghost,children:H?"[\u2713]":"[ ]"}),jsxs(Text,{color:$?G:H?e.silver:e.dim,bold:$,children:[" ",C.name]}),W>0&&jsxs(Text,{color:e.dim,children:[" ",fe,W]})]},C.id)}),n.length>v&&jsxs(Text,{color:e.ghost,children:[" ",L>0?"\u2191":" "," ",L+v<n.length?"\u2193":" "," ",m+1,"/",n.length]}),jsx(Text,{color:e.ghost,children:je.repeat(36)}),jsxs(Text,{color:e.dim,children:[" Space toggle"," ",fe," ","a all"," ",fe," ","Enter confirm"," ",fe," ","Esc cancel"]})]})});var Ic={system:"\u2666",lifecycle:"\u25B6",output:"\u2502",tool:"\u2699",result:"\u2190",error:"\u2715",file:"\u270E",info:"\u2502"},vc={system:"System",lifecycle:"Lifecycle",output:"Output",tool:"Tool calls",result:"Results",error:"Errors",file:"Files",info:"Info"},_c={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"],yi=[{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"]}],wi=co.memo(function({selected:n,typeCounts:o,onConfirm:r,onCancel:s}){let[f,h]=useState(0),[y,m]=useState(()=>new Set(n)),T=useMemo(()=>y.size===St.length||St.every(I=>y.has(I)),[y]);useInput((I,M)=>{if(M.upArrow){h(v=>v>0?v-1:St.length-1);return}if(M.downArrow){h(v=>v<St.length-1?v+1:0);return}if(I===" "){let v=St[f];if(!v)return;m(L=>{let _=new Set(L);return _.has(v)?_.delete(v):_.add(v),_});return}if(I==="a"||I==="A"){m(v=>v.size===St.length?new Set:new Set(St));return}for(let v of yi)if(I===v.key){m(new Set(v.types));return}if(M.return){let v=y.size===0?new Set(St):new Set(y);r(v);return}if(M.escape){s();return}});let S=T?St.length:y.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," ",S,"/",St.length," selected"]})]}),jsx(Text,{color:e.ghost,children:je.repeat(36)}),St.map((I,M)=>{let v=M===f,L=y.has(I),_=o[I]??0,R=_c[I];return jsxs(Box,{gap:0,children:[jsx(Text,{color:v?e.amber:e.ghost,children:v?" \u25B8 ":" "}),jsx(Text,{color:L?e.green:e.ghost,children:L?"[\u2713]":"[ ]"}),jsxs(Text,{color:v?R:e.dim,children:[" ",Ic[I]," "]}),jsx(Text,{color:v?R:L?e.silver:e.dim,bold:v,children:vc[I]}),_>0&&jsxs(Text,{color:e.dim,children:[" ",fe,_]})]},I)}),jsx(Text,{color:e.ghost,children:je.repeat(36)}),jsxs(Box,{gap:0,children:[jsx(Text,{color:e.dim,children:" "}),yi.map((I,M)=>jsxs(co.Fragment,{children:[M>0&&jsxs(Text,{color:e.ghost,children:[" ",fe," "]}),jsx(Text,{color:e.amberDim,children:I.key}),jsxs(Text,{color:e.dim,children:["=",I.label]})]},I.key))]}),jsxs(Text,{color:e.dim,children:[" Space toggle"," ",fe," ","a all"," ",fe," ","Enter confirm"," ",fe," ","Esc cancel"]})]})});var Xo="\u256D",qo="\u256E",Ko="\u2570",Yo="\u256F",Ie="\u2502";function on({children:t,cw:n}){return jsxs(Text,{children:[jsx(Text,{color:e.ghost,children:Ie}),jsxs(Text,{children:[" ",t.padEnd(n)," "]}),jsx(Text,{color:e.ghost,children:Ie})]})}function Uo({cw:t}){return jsx(on,{cw:t,children:""})}function Si({width:t,height:n}){let o=Math.min(t-4,50),r=o-6,s=Te(o-2);return jsxs(Box,{flexDirection:"column",paddingX:2,marginTop:1,children:[jsxs(Text,{color:e.ghost,children:[Xo,s,qo]}),jsx(on,{cw:r,children:""}),jsxs(Text,{children:[jsxs(Text,{color:e.ghost,children:[Ie," "]}),jsx(Text,{color:e.amber,children:jt}),jsx(Text,{color:e.white,bold:true,children:" Welcome to Orch"}),jsx(Text,{children:" ".repeat(Math.max(0,r-15-2))}),jsx(Text,{children:" "}),jsx(Text,{color:e.ghost,children:Ie})]}),jsx(on,{cw:r,children:""}),jsxs(Text,{children:[jsxs(Text,{color:e.ghost,children:[Ie," "]}),jsx(Text,{color:e.silver,children:"Press N to create your first task".padEnd(r)}),jsx(Text,{children:" "}),jsx(Text,{color:e.ghost,children:Ie})]}),jsx(on,{cw:r,children:""}),jsxs(Text,{children:[jsxs(Text,{color:e.ghost,children:[Ie," "]}),jsx(Text,{color:e.amber,children:"N"}),jsx(Text,{color:e.gray,children:" new task"}),jsx(Text,{children:" ".repeat(Math.max(0,r-1-1-8))}),jsx(Text,{children:" "}),jsx(Text,{color:e.ghost,children:Ie})]}),jsx(on,{cw:r,children:""}),jsxs(Text,{color:e.ghost,children:[Ko,s,Yo]})]})}function ki({step:t,width:n}){let o=Math.min(n-4,50),r=o-6,s=Te(o-2),f,h=null;if(t==="task_created")f="Press R to run task",h={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:[Xo,s,qo]}),jsxs(Text,{children:[jsxs(Text,{color:e.ghost,children:[Ie," "]}),jsx(Text,{color:e.amber,children:jt}),jsxs(Text,{color:e.silver,children:[" ",f.padEnd(h?r-2-h.key.length-1-h.label.length-2:r-2)]}),h&&jsxs(Fragment,{children:[jsxs(Text,{color:e.amber,children:[" ",h.key]}),jsxs(Text,{color:e.gray,children:[" ",h.label]})]}),jsx(Text,{children:" "}),jsx(Text,{color:e.ghost,children:Ie})]}),jsxs(Text,{color:e.ghost,children:[Ko,s,Yo]})]})}function Ci({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:[Xo,r,qo]}),jsx(on,{cw:o,children:""}),jsxs(Text,{children:[jsxs(Text,{color:e.ghost,children:[Ie," "]}),jsx(Text,{color:e.green,bold:true,children:"First task completed!"}),jsx(Text,{children:" ".repeat(Math.max(0,o-21))}),jsx(Text,{children:" "}),jsx(Text,{color:e.ghost,children:Ie})]}),jsx(on,{cw:o,children:""}),jsxs(Text,{children:[jsxs(Text,{color:e.ghost,children:[Ie," "]}),jsx(Text,{color:e.silver,children:"Type / to see all commands".padEnd(o)}),jsx(Text,{children:" "}),jsx(Text,{color:e.ghost,children:Ie})]}),jsx(on,{cw:o,children:""}),jsxs(Text,{color:e.ghost,children:[Ko,r,Yo]})]})}function Zo({count:t,config:n,width:o}){if(t>=3)return null;let r=Math.min((o??44)-4,50),s=r-6,f=Te(r-2),h=jsxs(Text,{color:e.ghost,children:[Xo,f,qo]}),y=jsxs(Text,{color:e.ghost,children:[Ko,f,Yo]});if(t>0){let T=n.hints[0],S=T?` ${T.key} ${T.label}`:"";return jsxs(Box,{flexDirection:"column",paddingX:2,marginTop:1,children:[h,jsxs(Text,{children:[jsxs(Text,{color:e.ghost,children:[Ie," "]}),jsx(Text,{color:e.amber,children:jt}),jsxs(Text,{color:e.silver,children:[" ",n.nudge.padEnd(s-2-S.length)]}),T&&jsxs(Fragment,{children:[jsxs(Text,{color:e.amber,children:[" ",T.key]}),jsxs(Text,{color:e.gray,children:[" ",T.label]})]}),jsx(Text,{children:" "}),jsx(Text,{color:e.ghost,children:Ie})]}),y]})}let m=n.hints.reduce((T,S,I)=>T+S.key.length+1+S.label.length+(I>0?3:0),0);return jsxs(Box,{flexDirection:"column",paddingX:2,marginTop:1,children:[h,jsx(Uo,{cw:s}),jsxs(Text,{children:[jsxs(Text,{color:e.ghost,children:[Ie," "]}),jsx(Text,{color:e.amber,children:jt}),jsxs(Text,{color:e.white,bold:true,children:[" ",n.title]}),jsx(Text,{children:" ".repeat(Math.max(0,s-n.title.length-2))}),jsx(Text,{children:" "}),jsx(Text,{color:e.ghost,children:Ie})]}),jsx(Uo,{cw:s}),n.description.map((T,S)=>jsxs(Text,{children:[jsxs(Text,{color:e.ghost,children:[Ie," "]}),jsx(Text,{color:e.silver,children:T.padEnd(s)}),jsx(Text,{children:" "}),jsx(Text,{color:e.ghost,children:Ie})]},S)),jsx(Uo,{cw:s}),jsxs(Text,{children:[jsxs(Text,{color:e.ghost,children:[Ie," "]}),n.hints.map((T,S)=>jsxs(co.Fragment,{children:[S>0&&jsx(Text,{color:e.ghost,children:" "}),jsx(Text,{color:e.amber,children:T.key}),jsxs(Text,{color:e.gray,children:[" ",T.label]})]},S)),jsx(Text,{children:" ".repeat(Math.max(0,s-m))}),jsx(Text,{children:" "}),jsx(Text,{color:e.ghost,children:Ie})]}),jsx(Uo,{cw:s}),y]})}var vi={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."},_i={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."},Mi={title:"Agents",description:["AI workers that execute your tasks.","Each agent uses an adapter (claude,","codex, opencode, cursor, pi, shell)."],hints:[{key:"N",label:"new agent"},{key:"W",label:"start orchestrator"}],nudge:"Add more agents to increase parallelism."};var Rc=2,Bi=360,Ac={done:4e3,failed:8e3,review:6e3},Bc={done:"\u2713",failed:"\u2715",review:Zt},$c={done:e.green,failed:e.red,review:e.blue},Ec={done:e.successBg,failed:e.errorBg,review:e.infoBg};function Oc(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 Lc=co.memo(function({toast:n,onDismiss:o}){let[r,s]=useState(true),[f,h]=useState(false);useEffect(()=>{let v=setTimeout(()=>s(false),Bi);return ()=>clearTimeout(v)},[]),useEffect(()=>{let v=Ac[n.type],L=setTimeout(()=>h(true),v),_=setTimeout(()=>o(n.id),v+Bi);return ()=>{clearTimeout(L),clearTimeout(_);}},[n.id,n.type,o]);let y=r||f,m=Bc[n.type],T=$c[n.type],S=Ec[n.type],I=Oc(n),M=n.title.length>40?n.title.slice(0,39)+"\u2026":n.title;return jsx(Box,{children:jsxs(Text,{backgroundColor:S,children:[jsxs(Text,{color:y?e.dim:T,children:[" ",m," "]}),jsx(Text,{color:y?e.dim:e.white,bold:!y,children:M}),jsxs(Text,{color:y?e.dim:e.silver,children:[" ",I," "]})]})})}),Oi=co.memo(function({toasts:n,onDismiss:o}){let r=n.slice(0,Rc);return r.length===0?null:jsx(Box,{flexDirection:"column",children:r.map(s=>jsx(Lc,{toast:s,onDismiss:o},s.id))})});var Dc="\u256D",Fc="\u256E",Wc="\u2570",Gc="\u256F",dt="\u2502",Gr=[{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"}],zr=[{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"}],Vr=[{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"}],Vn=10,Xt=22;function jr(t){let n=Math.max(0,Math.floor((Xt-t.length-2)/2)),o=Math.max(0,Xt-n-t.length-2);return Te(n)+" "+t+" "+Te(o)}var Li=co.memo(function({width:n,height:o}){let r=Xt*3+3+3+2,s=r+2,f=Te(s-2),h="KEYBOARD SHORTCUTS",y=Math.max(0,Math.floor((r-h.length)/2)),m=Math.max(0,r-y-h.length),T="Press any key to dismiss",S=Math.max(0,Math.floor((r-T.length)/2)),I=Math.max(0,r-S-T.length),M=Math.max(Gr.length,zr.length,Vr.length),v=M+10,L=Math.max(0,Math.floor((o-v)/2)),_=[];for(let $=0;$<M;$++){let H=$<Gr.length?Gr[$]:null,G=$<zr.length?zr[$]:null,W=$<Vr.length?Vr[$]:null;_.push(jsxs(Text,{children:[jsx(Text,{color:e.amber,children:dt}),jsx(Text,{children:" "}),H?jsxs(Fragment,{children:[jsx(Text,{color:e.amber,bold:true,children:H.key.padEnd(Vn)}),jsx(Text,{color:e.silver,children:H.label.padEnd(Xt-Vn)})]}):jsx(Text,{children:" ".repeat(Xt)}),jsxs(Text,{color:e.dim,children:[" ",dt," "]}),G?jsxs(Fragment,{children:[jsx(Text,{color:e.amber,bold:true,children:G.key.padEnd(Vn)}),jsx(Text,{color:e.silver,children:G.label.padEnd(Xt-Vn)})]}):jsx(Text,{children:" ".repeat(Xt)}),jsxs(Text,{color:e.dim,children:[" ",dt," "]}),W?jsxs(Fragment,{children:[jsx(Text,{color:e.amber,bold:true,children:W.key.padEnd(Vn)}),jsx(Text,{color:e.silver,children:W.label.padEnd(Xt-Vn)})]}):jsx(Text,{children:" ".repeat(Xt)}),jsx(Text,{children:" "}),jsx(Text,{color:e.amber,children:dt})]},`r${$}`));}let R=$=>jsxs(Text,{children:[jsx(Text,{color:e.amber,children:dt}),jsx(Text,{children:" ".repeat(r)}),jsx(Text,{color:e.amber,children:dt})]},$),C=jr("NAVIGATION"),z=jr("ACTIONS"),P=jr("COMMANDS");return jsxs(Box,{flexDirection:"column",paddingX:Math.max(0,Math.floor((n-s)/2)),marginTop:L,children:[jsxs(Text,{color:e.amber,children:[Dc,f,Fc]}),R("e1"),jsxs(Text,{children:[jsx(Text,{color:e.amber,children:dt}),jsx(Text,{children:" ".repeat(y)}),jsx(Text,{color:e.amber,bold:true,children:h}),jsx(Text,{children:" ".repeat(m)}),jsx(Text,{color:e.amber,children:dt})]}),R("e2"),jsxs(Text,{children:[jsx(Text,{color:e.amber,children:dt}),jsx(Text,{children:" "}),jsx(Text,{color:e.dim,children:C}),jsxs(Text,{color:e.dim,children:[" ",dt," "]}),jsx(Text,{color:e.dim,children:z}),jsxs(Text,{color:e.dim,children:[" ",dt," "]}),jsx(Text,{color:e.dim,children:P}),jsx(Text,{children:" "}),jsx(Text,{color:e.amber,children:dt})]}),R("e3"),_,R("e4"),jsxs(Text,{children:[jsx(Text,{color:e.amber,children:dt}),jsx(Text,{children:" ".repeat(S)}),jsx(Text,{color:e.dim,children:T}),jsx(Text,{children:" ".repeat(I)}),jsx(Text,{color:e.amber,children:dt})]}),R("e5"),jsxs(Text,{color:e.amber,children:[Wc,f,Gc]})]})});var Di=[{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"}],Fi=[{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"}],Wi=[{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"}],Gi=[{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"}],zi=[{value:"openai-codex/gpt-5.5",label:"GPT-5.5",hint:"Pi OpenAI Codex provider"},{value:"openai-codex/gpt-5.4",label:"GPT-5.4",hint:"Pi OpenAI Codex provider"},{value:"openai-codex/gpt-5.3-codex",label:"GPT-5.3 Codex",hint:"Pi OpenAI Codex provider"},{value:"",label:"Default",hint:"use Pi configured default"}],Vi=[{value:"",label:"Default",hint:"use shell adapter default"}],ji=[{value:"",label:"Default",hint:"no override \u2014 use model default"},{value:"high",label:"High",hint:"deepest reasoning, best quality, slowest"},{value:"medium",label:"Medium",hint:"balanced speed and quality"},{value:"low",label:"Low",hint:"fastest responses, minimal reasoning"}],Hi=new Set(["claude","pi"]),zc=[{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:"pi",label:"Pi",hint:"Pi coding agent RPC"},{value:"shell",label:"Shell",hint:"custom shell command"}],Ui=[{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"}],Pi=60;function Xi(t){return t.filter(n=>n.status!=="disabled").map(n=>{let o=(n.role??"").split(`
11
- `)[0].trim(),r=o.length>Pi?o.slice(0,Pi-1)+"\u2026":o,s=r?`[${n.adapter}] ${r}`:n.adapter;return {value:n.id,label:n.name,hint:s}})}function er(t,n="Auto-assign",o="orchestrator picks the best agent"){return [{value:"",label:n,hint:o},...Xi(t)]}var Ur=[{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 qi(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 Ki(){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 Xr(t,n,o){let r=a$3(o,n.tier);return t.map(s=>{switch(s.id){case "name":return {...s,defaultValue:n.name};case "adapter":return {...s,defaultValue:o};case "model":return {...s,defaultValue:r};case "role":return {...s,defaultValue:"__custom__"};case "role_custom":return {...s,defaultValue:n.role,skip:void 0};case "skills":{let f=o==="claude"?n.skills:n.skills.filter(h=>!a$4(h));return {...s,defaultValue:f.join(", ")}}case "approval_policy":return {...s,defaultValue:n.approval_policy};default:return s}})}function tr(t,n){let o=qi(n);return [{id:"name",label:"Agent name",type:"text",placeholder:"e.g. alpha, frontend-bot, reviewer",required:true,validate:r=>r.trim()?t?.some(s=>s.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:zc},{id:"model",label:"Model",type:"select",getOptions:r=>r.adapter==="opencode"?Gi:r.adapter==="codex"?Fi:r.adapter==="cursor"?Wi:r.adapter==="pi"?zi:r.adapter==="shell"?Vi:Di},{id:"effort",label:"Reasoning effort",type:"select",options:ji,skip:r=>!Hi.has(r.adapter??"")},{id:"role",label:"Role / specialization",type:"select",options:Ur},{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 Yi(t,n="claude"){let o=t.role==="__custom__"?t.role_custom||void 0:t.role||void 0,r=t.skills?t.skills.split(",").map(h=>h.trim()).filter(Boolean):void 0,s=t.approval_policy||"auto",f=t.effort||void 0;return {name:t.name,adapter:t.adapter||n,role:o,model:t.model||void 0,effort:f,approval_policy:s,skills:r,team_id:t.team||void 0}}function Zi(t,n){let o=Xi(t);return [{id:"name",label:"Team name",type:"text",placeholder:"e.g. frontend, backend, qa",required:true,validate:r=>r.trim()?n?.some(s=>s.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(s=>s.value!==r.lead),skip:r=>!o.some(s=>s.value!==r.lead)},{id:"description",label:"Description",type:"textarea",placeholder:"Optional team purpose..."}]}function Ji(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 Qi(t){let n=er(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:Ui,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 ea(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 ta(t,n){let o=er(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:Ui,defaultValue:String(t.priority),validate:r=>{let s=Number(r);return !Number.isInteger(s)||s<1||s>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 na(t){return {title:t.title,priority:t.priority?parseInt(t.priority,10):void 0,assignee:t.assignee||void 0,description:t.description??""}}function oa(t,n,o){let r=Ur.find(m=>m.value===t.role),s=r?t.role:t.role?"__custom__":"",f=t.adapter==="opencode"?Gi:t.adapter==="codex"?Fi:t.adapter==="cursor"?Wi:t.adapter==="pi"?zi:t.adapter==="shell"?Vi:Di,h=qi(o),y=o?.find(m=>m.members.some(T=>T.agent_id===t.id))?.id;return [{id:"name",label:"Agent name",type:"text",defaultValue:t.name,required:true,validate:m=>m.trim()?n?.some(T=>T.id!==t.id&&T.name===m.trim())?"Agent with this name already exists":null:"Name is required"},{id:"model",label:"Model",type:"select",options:f,defaultValue:t.config.model??""},{id:"effort",label:"Reasoning effort",type:"select",options:ji,defaultValue:t.config.effort??"",skip:()=>!Hi.has(t.adapter)},{id:"role",label:"Role / specialization",type:"select",options:Ur,defaultValue:s},{id:"role_custom",label:"Describe the role",type:"textarea",defaultValue:t.role&&!r?t.role:"",placeholder:"e.g. Specialist in React and TypeScript",skip:m=>m.role!=="__custom__"},{id:"team",label:"Team",type:"select",options:h,defaultValue:y??"",skip:()=>h.length<=1}]}var Vc=[{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"}],jc=[{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"}],Ni=[{value:"true",label:"On"},{value:"false",label:"Off"}];function ra(t,n,o){let r=o??{toast:true,bell:false};return [{id:"activity_filter",label:"Activity filter preset",type:"select",options:jc,defaultValue:t},{id:"max_concurrent",label:"Max concurrent agents",type:"select",options:Vc,defaultValue:String(n)},{id:"notifications_toast",label:"Toast notifications",type:"select",options:Ni,defaultValue:String(r.toast)},{id:"notifications_bell",label:"Bell on completion",type:"select",options:Ni,defaultValue:String(r.bell)}]}function sa(t){let n=t.role==="__custom__"?t.role_custom||void 0:t.role||void 0,o=t.effort||void 0;return {name:t.name,role:n,model:t.model||void 0,effort:o,team_id:t.team||void 0}}function nr(t){let n=er(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 ia(t){return {title:t.title,assignee:t.assignee||void 0,description:t.description||void 0}}function aa(t,n){let o=er(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 la(t){return {title:t.title,assignee:t.assignee||void 0,description:t.description??""}}var ca=10,da=500,ar=2048,yn=500,ua=5,qr=new Set(["todo","failed","cancelled"]),ga=5e3,fa=0;function Vg(){fa=0;}var pa=/^\[[\w_]+\]$/;function ha(t){return pa.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 Zr=["#5faf87","#5fafd7","#af87ff","#d7af00","#5fd7d7","#d787af","#afaf5f","#d7875f"],qc=" ".repeat(9),lr={system:"\u2666",lifecycle:"\u25B6",output:"\u2502",tool:"\u2699",result:"\u2190",error:"\u2715",file:"\u270E",info:"\u2502"},sr=["system","lifecycle","output","tool","result","error","file","info"],jn=[{label:"all",types:sr},{label:"text",types:["output"]},{label:"tools",types:["tool","result","file"]},{label:"errors",types:["error"]},{label:"events",types:["lifecycle","system"]}];function Kr(t){let o=(jn.findIndex(r=>r.types.length===t.size&&r.types.every(s=>t.has(s)))+1)%jn.length;return jn[o]}function Yr(t,n){if(t.length!==n.length)return true;for(let o=0;o<t.length;o++)if(t[o].id!==n[o].id||t[o].updated_at!==n[o].updated_at)return true;return false}function jg({projectName:t,tasks:n,agents:o=[],state:r,onRunTask:s,onCreateTask:f,onCancelTask:h,onRetryTask:y,onAssignTask:m,onRunAll:T,onDisableAgent:S,onEnableAgent:I,onSubscribeEvents:M,onRefreshTasks:v,onRefreshAgents:L,onRefreshState:_,onLoadHistory:R,onAddAgent:C,onDeleteAgent:z,onApproveTask:P,onRejectTask:$,onDeleteTask:H,onUpdateTask:G,onUpdateAgent:W,onForceStopAgent:w,onCreateTeam:U,onListTeams:ie,onJoinTeam:oe,onLeaveTeam:we,onDisbandTeam:We,onSetTeamLead:Ge,onStartWatch:ut,onStopWatch:Ct,onToggleAutonomous:gt,onRefreshGoals:mt,onCreateGoal:Ye,onUpdateGoal:Ze,onUpdateGoalStatus:ft,onDeleteGoal:Ce,onGetGoalProgress:Wt,onCompleteOnboarding:It,initialWatchActive:ht,observerMode:Je,watchError:ot,messageBatchMs:Xe=process.env.VITEST?0:80,initialActivityFilter:fo="all",onSaveActivityFilter:rn,initialMaxConcurrent:Bt=a.scheduling.max_concurrent_agents,onSaveMaxConcurrent:Gt,initialNotifications:zt,onSaveNotifications:qt,version:sn,latestVersion:an,onCheckUpdate:vt,onBackgroundInstall:wn,defaultAdapter:Hn="claude"}){let{exit:ln}=useApp(),{stdout:rt}=useStdout(),[cn,D]=useState(an),O=useRef(vt);useEffect(()=>{if(an||!O.current)return;let i=setTimeout(()=>{O.current?.().then(x=>{x&&D(x);}).catch(()=>{});},5e3);return ()=>clearTimeout(i)},[an]);let[N,B]=useState(false),q=useRef(false);useEffect(()=>{!cn||!wn||q.current||N||(q.current=true,wn(cn).then(i=>{i&&B(true);}).catch(()=>{}));},[cn,wn,N]);let[ne,_e]=useState({w:rt?.columns??80,h:rt?.rows??24});useEffect(()=>{if(!rt)return;let i=()=>_e({w:rt.columns,h:rt.rows});return rt.on("resize",i),()=>{rt.off("resize",i);}},[rt]);let ae=ne.w,ue=ne.h,[ce,Kt]=useState(n),[de,cr]=useState(o),[ze,Sa]=useState(r),[po,dr]=useState(ht??!!r.pid),[Un,Jr]=useState([]),[ka,Qr]=useState(void 0),[Yt,ho]=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(Yt!=="completed")return;let i=setTimeout(()=>{ho("dismissed"),It?.().catch(()=>{});},5e3);return ()=>clearTimeout(i)},[Yt,It]);let[E,Sn]=useState("tasks"),[xo,Xn]=useState(0),[ur,es]=useState(0),[gr,ts]=useState(0),[Ae,qn]=useState(false),[Ve,ns]=useState([]),[Pe,Ee]=useState("none"),xt=Vo(),dn=xt.value,[bt,Qe]=useState(null),[un,Kn]=useState([]),[$t,mr]=useState(false),[os,Ca]=useState(()=>new Set),[kn,fr]=useState(false),[Yn,pr]=useState(false),[rs,ss]=useState(()=>new Set(sr)),[Zn,hr]=useState(-1),[Ia,Jn]=useState(0),[Cn,xr]=useState(()=>{let i=jn.find(x=>x.label===fo);return new Set(i?.types??sr)}),bo=useMemo(()=>jn.find(x=>x.types.length===Cn.size&&x.types.every(l=>Cn.has(l)))?.label??"all",[Cn]),br=useMemo(()=>Cn.size>=sr.length?Ve:Ve.filter(i=>Cn.has(i.msgType??"info")),[Ve,Cn]),[is,va]=useState(Bt),[To,_a]=useState(zt??{toast:true,bell:false}),[Ma,as]=useState([]),Ra=useRef(0),[Tr,ls]=useState(),cs=useRef(E);cs.current=E;let ds=useRef(ce);ds.current=ce;let us=useRef(de);us.current=de;let yo=useRef(To);yo.current=To;let wo=useCallback((i,x)=>{if(!yo.current.toast)return;let l=ds.current.find(b=>b.id===x),c=l?.title??x,u=l?.assignee?us.current.find(b=>b.id===l.assignee):void 0;as(b=>{let g=[...b,{id:`toast_${Ra.current++}`,type:i,title:c,agentName:u?.name,ts:Date.now()}];return g.length>ua?g.slice(g.length-ua):g}),yo.current.bell&&(i==="failed"||i==="review")&&process.stdout.write("\x07");},[]),Aa=useCallback(i=>{as(x=>x.filter(l=>l.id!==i));},[]),So=co.useRef(new Wo).current,[Ba,In]=useState(0),[gs,ms]=useState(false),[Qn,$a]=useState(false),[Ea,yr]=useState(0),[Oa,wr]=useState(0),[Sr,vn]=useState(0),[ko,kr]=useState(false),[La,eo]=useState(0),[Co,gn]=useState(0),[Vt,fs]=useState([]),[_n,Cr]=useState([]),Mn=useRef(Vt);Mn.current=Vt;let ps=useRef(0),K=useCallback(async i=>{ps.current=Date.now();let[x,l,c,u,b]=await Promise.all([v?.()??Promise.resolve(ce),L?.()??Promise.resolve(de),_?.()??Promise.resolve(ze),i?.includeTeams?ie?.()??Promise.resolve(Mn.current):Promise.resolve(null),mt?.()??Promise.resolve(Un)]);Kt(g=>Yr(g,x)?x:g),cr(g=>Yr(g,l)?l:g),Sa(c),u!==null&&fs(u),Jr(g=>Yr(g,b)?b:g),ht&&dr(!!c.pid);},[v,L,_,ie,mt,ht]),Rn=useMemo(()=>{let i=new Map;for(let x of Un)i.set(x.id,x);return i},[Un]),Oe=useMemo(()=>{let i=[...ce].sort((b,g)=>(io[b.status]??9)-(io[g.status]??9));if(!Qn)return i;let x=[],l=[],c=[],u=new Map;for(let b of i)b.goalId&&Rn.has(b.goalId)?(u.has(b.goalId)||(c.push(b.goalId),u.set(b.goalId,[])),u.get(b.goalId).push(b)):l.push(b);for(let b of c)x.push(...u.get(b));return [...x,...l]},[ce,Qn,Rn]),Et=gs?Oe:Oe.slice(0,ca),An=Oe.length-Et.length,j=Oe[xo],to=useMemo(()=>{let i=new Map;for(let x of ce)i.set(x.id,x.title);return i},[ce]),mn=useMemo(()=>{let i=new Map;for(let x of de)i.set(x.id,x.name);return i},[de]),Pa=useMemo(()=>{let i=new Map;for(let x of ce)if(x.goalId){let l=i.get(x.goalId);l||(l=[],i.set(x.goalId,l)),l.push(x);}return i},[ce]),Io=useMemo(()=>{let i=new Map;for(let x=0;x<de.length;x++)i.set(de[x].id,Zr[x%Zr.length]);return i},[de]),hs=useMemo(()=>{let i=new Map;for(let x of Ve)x.agentId&&i.set(x.agentId,(i.get(x.agentId)??0)+1);return i},[Ve]),Na=useMemo(()=>{let i={};for(let x of Ve){let l=x.msgType??"info";i[l]=(i[l]??0)+1;}return i},[Ve]),{agentTeamMap:Bn,activeTeamCount:no,teamLeadSet:Da}=useMemo(()=>{let i=new Map,x=new Set,l=0;for(let c of Vt)if(c.status==="active"){l++,x.add(c.lead_agent_id);for(let u of c.members)i.set(u.agent_id,c.name);}return {agentTeamMap:i,activeTeamCount:l,teamLeadSet:x}},[Vt]),Ne=useMemo(()=>{let i=[...de];return i.sort((x,l)=>{let c=Bn.get(x.id),u=Bn.get(l.id);return c&&!u?-1:!c&&u?1:c&&u&&c!==u?c.localeCompare(u):(Or[x.status]??9)-(Or[l.status]??9)}),i},[de,Bn]),Z=Ne[ur],pt=useMemo(()=>[...Un].sort((i,x)=>(c[i.status]??9)-(c[x.status]??9)),[Un]),Q=pt[gr],Fa=useMemo(()=>Q?ce.filter(i=>i.goalId===Q.id):[],[Q,ce]),Ir=useRef(Wt);Ir.current=Wt,useEffect(()=>{if(!Q||!Ir.current){Qr(void 0);return}let i=false;return Ir.current(Q.id).then(x=>{i||Qr(x);}).catch(()=>{}),()=>{i=true;}},[Q?.id]);let fn=useRef(new Map),vo=useRef(new Map);useEffect(()=>{for(let[i,x]of Object.entries(ze.running))fn.current.set(x.run_id,x.agent_id),vo.current.set(x.run_id,i);if(fn.current.size>da){let i=fn.current.size-da,x=0;for(let l of fn.current.keys()){if(x++>=i)break;fn.current.delete(l),vo.current.delete(l);}}},[ze.running]);let pn=useRef([]),oo=useRef(null),vr=useCallback(()=>{if(oo.current=null,pn.current.length===0)return;let i=pn.current;pn.current=[],ns(x=>{if(i.length>=yn)return i.slice(-yn);let l=yn-i.length;return (x.length>l?x.slice(-l):x).concat(i)});},[]);useEffect(()=>()=>{oo.current&&clearTimeout(oo.current);},[]);let a=useCallback((i,x,l)=>{let c=new Date,u=c.toLocaleTimeString("en-US",{hour12:false,hour:"2-digit",minute:"2-digit",second:"2-digit"}),b=l?.detail&&l.detail.length>ar?l.detail.slice(0,ar)+"\u2026[truncated]":l?.detail;pn.current.push({text:i,color:x,time:u,ts:c.getTime(),...l,detail:b}),pn.current.length>yn&&(pn.current=pn.current.slice(-yn)),Xe===0?vr():oo.current||(oo.current=setTimeout(vr,Xe));},[vr]);useEffect(()=>{Je?a("Observer mode: watching external orchestrator via disk polling.",e.amber):ot&&a(`Watch mode failed: ${ot}. Tasks will not auto-dispatch.`,e.red);},[]),useEffect(()=>{let i=Je?3e3:5e3,x=setInterval(()=>{Date.now()-ps.current>=i&&K().catch(()=>{});},i);return ()=>clearInterval(x)},[Je,K]);let $n=useCallback((i,x,l,c)=>{let u={key:++fa,entityType:i,entityId:x,entityName:l,expiresAt:Date.now()+ga,needsForceStop:c?.needsForceStop};Cr(b=>[...b,u]),a(`\u2717 "${l}" will be deleted in ${Math.round(ga/1e3)}s \u2014 press Z to undo`,e.yellow);},[a]),Wa=useCallback(()=>{Cr(i=>{if(i.length===0)return i;let x=i[i.length-1];return a(`\u21B6 Undo: "${x.entityName}" restored`,e.green),i.slice(0,-1)});},[a]),xs=useCallback(async i=>{try{i.entityType==="task"&&H?await H(i.entityId):i.entityType==="agent"?(i.needsForceStop&&w&&await w(i.entityId),z&&await z(i.entityId)):i.entityType==="goal"&&Ce&&await Ce(i.entityId),a(`\u2713 Deleted "${i.entityName}"`,e.green),K();}catch(x){a(`Failed to delete "${i.entityName}": ${x instanceof Error?x.message:String(x)}`,e.red);}},[H,z,Ce,w,a,K]),bs=useRef(xs);bs.current=xs,useEffect(()=>{if(_n.length===0)return;let i=setInterval(()=>{let x=Date.now(),l=[];Cr(c=>{let u=c.filter(b=>b.expiresAt<=x?(l.push(b),false):true);return l.length>0?u:c});for(let c of l)bs.current(c);},1e3);return ()=>clearInterval(i)},[_n.length>0]),useEffect(()=>{if(!R)return;let i=x=>{let l=new Date(x.timestamp).toLocaleTimeString("en-US",{hour12:false,hour:"2-digit",minute:"2-digit",second:"2-digit"}),c=typeof x.data=="string"?x.data:JSON.stringify(x.data),u,b=e.silver,g="output";if(x.type==="error")u=typeof x.data=="string"?x.data:JSON.stringify(x.data),u=u.slice(0,200),b=e.red,g="error";else if(x.type==="file_changed")u=String(x.data),b=e.purple,g="file";else if(x.type==="done")u="Completed",b=e.green,g="lifecycle";else if(x.type==="tool_call")u=`\u2699 ${x.data?.name??"tool"}()`,b=e.cyan,g="tool";else {let{summary:k}=wa(c);if(!k)return null;u=k;let Y=ha(u);g=Y.msgType,b=Y.color;}return {text:u,color:b,time:l,ts:new Date(x.timestamp).getTime(),agentId:x.agentId,taskId:x.taskId,msgType:g}};R(x=>{if(x.length===0)return;let l=x.map(i).filter(c=>c!==null);ns(c=>{let u=[...l,...c];return u.length>yn?u.slice(-yn):u});}).catch(x=>{process.stderr.write(`[TUI] onLoadHistory error: ${x instanceof Error?x.stack??x.message:String(x)}
12
- `);});},[]),useEffect(()=>{ie?.().then(fs).catch(()=>{}),mt?.().then(Jr).catch(()=>{});},[]);let _o=useCallback(()=>{Qe({title:"NEW AGENT",steps:tr(de,Mn.current),kind:"agent"}),Ee("wizard");},[de]),Ts=useCallback(()=>{Qe({title:"AGENT SHOP",steps:Ki(),kind:"agent_shop"}),Ee("wizard");},[]),Mo=useCallback(()=>{Kn([]),Qe({title:"NEW TASK",steps:Qi(de),kind:"task"}),Ee("wizard");},[de]),Ga=useCallback(async()=>{try{let{detectClipboardType:i,getClipboardImage:x}=await import('./clipboard-service-AJTJG2DJ.js'),l=await i();if(l!=="image")return a(l==="text"?"Clipboard has text, not image":"Clipboard is empty",e.dim),l;let c=await x();if(!c)return a("Failed to read clipboard image",e.red),"empty";let{mkdtemp:u,writeFile:b}=await import('fs/promises'),{tmpdir:g}=await import('os'),{join:k}=await import('path'),Y=await u(k(g(),"orch-paste-")),Lt=k(Y,`clipboard-${Date.now()}.${c.ext}`);return await b(Lt,c.data),Kn(hn=>[...hn,Lt]),a(`\u{1F4CE} Image attached (${Math.round(c.data.length/1024)}KB)`,e.green),"image"}catch{return a("Clipboard paste failed",e.red),"empty"}},[a]),za=useCallback(i=>{Qe({title:"EDIT TASK",steps:ta(i,de),kind:"edit_task",targetId:i.id}),Ee("wizard");},[de]),ys=useCallback(()=>{Qe({title:"NEW TEAM",steps:Zi(de,Vt),kind:"team"}),Ee("wizard");},[de]),Va=useCallback(i=>{Qe({title:"EDIT AGENT",steps:oa(i,de,Vt),kind:"edit_agent",targetId:i.id}),Ee("wizard");},[Vt]),ws=useCallback(()=>{Qe({title:"SETTINGS",steps:ra(bo,is,To),kind:"config"}),Ee("wizard");},[bo,is]),ja=useCallback(i=>{Ee("none");let x=bt?.kind,l=bt?.targetId;if(Qe(null),x==="agent_shop"){let c=i.shop_template,u=c?b(c):void 0;if(u){let b=tr(de,Mn.current),g=Xr(b,u,Hn);Qe({title:`NEW AGENT \u2014 ${u.name}`,steps:g,kind:"agent_from_shop"}),Ee("wizard");}else a("No template selected",e.yellow);return}if((x==="agent"||x==="agent_from_shop")&&C){let c=Yi(i,Hn);a(`Creating agent "${c.name}"...`,e.amber),C(c.name,c.adapter,{model:c.model,effort:c.effort,role:c.role,approval_policy:c.approval_policy,skills:c.skills}).then(u=>{a(`\u2713 Created agent "${u.name}" (${u.id}, ${u.adapter})`,e.green),c.team_id&&oe?oe(c.team_id,u.id).then(b=>{a(`\u2713 Joined team "${b.name}"`,e.green),K({includeTeams:true});},b=>a(`Failed to join team: ${b instanceof Error?b.message:String(b)}`,e.red)):K();},u=>a(`Failed: ${u instanceof Error?u.message:String(u)}`,e.red));}else if(x==="team"&&U){let c=Ji(i);a(`Creating team "${c.name}"...`,e.amber),U(c).then(u=>{a(`\u2713 Created team "${u.name}" (${u.id}, ${u.members.length} members)`,e.green),K({includeTeams:true});},u=>a(`Failed: ${u instanceof Error?u.message:String(u)}`,e.red));}else if(x==="task"&&f){let c=ea(i),u=un.length>0?[...un]:void 0;Kn([]),a(`Creating "${c.title}"...`,e.amber),f(c.title,{priority:c.priority,description:c.description,attachments:u}).then(b=>{a(`\u2713 Created "${b.title}" (${b.id})${u?` \u{1F4CE}${u.length}`:""}`,e.green),c.assignee&&m&&m(b.id,c.assignee).catch(()=>{}),K();},b=>a(`Failed: ${b instanceof Error?b.message:String(b)}`,e.red));}else if(x==="edit_task"&&l&&G){let c=na(i),u=un.length>0?[...un]:void 0;Kn([]),a("Updating task...",e.amber),G(l,{...c,attachments:u}).then(b=>{a(`\u2713 Updated "${b.title}"${u?` \u{1F4CE}${u.length}`:""}`,e.green),c.assignee&&m&&m(l,c.assignee).catch(()=>{}),K();},b=>a(`Failed: ${b instanceof Error?b.message:String(b)}`,e.red));}else if(x==="edit_agent"&&l&&W){let c=sa(i),u=c.team_id??"",b=Vt.find(g=>g.members.some(k=>k.agent_id===l))?.id??"";a("Updating agent...",e.amber),W(l,{name:c.name,role:c.role,model:c.model,effort:c.effort}).then(g=>{a(`\u2713 Updated agent "${g.name}"`,e.green);let k=[];b&&b!==u&&we&&k.push(we(b,l).then(Y=>a(`\u2713 Left team "${Y.name}"`,e.green),Y=>a(`Failed to leave team: ${Y instanceof Error?Y.message:String(Y)}`,e.red))),u&&u!==b&&oe&&k.push(oe(u,l).then(Y=>a(`\u2713 Joined team "${Y.name}"`,e.green),Y=>a(`Failed to join team: ${Y instanceof Error?Y.message:String(Y)}`,e.red))),Promise.all(k).then(()=>K({includeTeams:k.length>0}));},g=>a(`Failed: ${g instanceof Error?g.message:String(g)}`,e.red));}else if(x==="config"){if(i.activity_filter){let g=jn.find(k=>k.label===i.activity_filter);g&&(xr(new Set(g.types)),rn?.(g.label));}if(i.max_concurrent){let g=parseInt(i.max_concurrent,10);g>0&&(va(g),Gt?.(g));}let c=i.notifications_toast==="true",u=i.notifications_bell==="true",b={toast:c,bell:u};_a(b),qt?.(b),a("Settings saved",e.green);}else if(x==="goal"&&Ye){let c=ia(i);a(`Creating goal "${c.title}"...`,e.amber),Ye(c).then(u=>{a(`\u2713 Created goal "${u.title}" (${u.id})`,e.green),K();},u=>a(`Failed: ${u instanceof Error?u.message:String(u)}`,e.red));}else if(x==="edit_goal"&&l&&Ze){let c=la(i);a("Updating goal...",e.amber),Ze(l,c).then(u=>{a(`\u2713 Updated goal "${u.title}"`,e.green),K();},u=>a(`Failed: ${u instanceof Error?u.message:String(u)}`,e.red));}},[bt,C,f,U,oe,we,m,G,W,gt,Ye,Ze,a,K,rn,Gt,To,qt,Vt,un]),Ha=useCallback(()=>{Ee("none"),Qe(null),Kn([]);},[]),Ua=useCallback(i=>{let x=b(i);if(!x)return;let l=tr(de,Mn.current),c=Xr(l,x,Hn);Qe({title:`NEW AGENT \u2014 ${x.name}`,steps:c,kind:"agent_from_shop"}),Ee("wizard");},[]);useEffect(()=>{if(!M)return;let i=null,x=()=>{i||(i=setTimeout(()=>{i=null,K().catch(()=>{});},150));},l=M(c=>{if(c.type==="agent:started"&&(fn.current.set(c.runId,c.agentId),vo.current.set(c.runId,c.taskId)),gd(c,a,fn.current,vo.current),c.type==="task:created"?ho(u=>u==="welcome"?"task_created":u):c.type==="agent:started"?ho(u=>u==="task_created"?"run_started":u):c.type==="task:status_changed"&&c.to==="done"&&ho(u=>u==="run_started"?"completed":u),c.type==="task:status_changed"&&(c.to==="done"?wo("done",c.taskId):c.to==="failed"?wo("failed",c.taskId):c.to==="review"&&wo("review",c.taskId),yo.current.toast&&cs.current!=="tasks")){let u=c.to==="done"?e.green:c.to==="failed"?e.red:c.to==="review"?e.blue:void 0;u&&ls({tab:"tasks",color:u});}(c.type==="task:status_changed"||c.type==="task:created"||c.type==="task:assigned"||c.type==="agent:started"||c.type==="agent:completed"||c.type==="run:retry"||c.type==="goal:created"||c.type==="goal:status_changed"||c.type==="goal:updated"||c.type==="goal:deleted")&&x();});return ()=>{l(),i&&clearTimeout(i);}},[M,a,K,wo]);let _r=Je?"observing":po?"watching":"idle",Xa=ze.started_at?g(ze.started_at):void 0,Ss=ze.stats.total_tokens.total,ks=useMemo(()=>{let i={running:0,retrying:0,review:0,todo:0,done:0,failed:0,cancelled:0};for(let x of ce)x.status==="in_progress"?i.running++:x.status==="retrying"?i.retrying++:x.status==="review"?i.review++:x.status==="todo"?i.todo++:x.status==="done"?i.done++:x.status==="failed"?i.failed++:x.status==="cancelled"&&i.cancelled++;return {...i,teams:no}},[ce,no]);ks.running;let qa=useMemo(()=>({input:ze.stats.total_tokens.input??0,output:ze.stats.total_tokens.output??0,reasoning:ze.stats.total_tokens.reasoning??0,total:Ss,cache_read:ze.stats.total_tokens.cache_read??0,cache_write:ze.stats.total_tokens.cache_write??0}),[ze.stats.total_tokens,Ss]),_t=Math.max(4,ue-9),Ka=Bn.size,Ya=de.length>Ka,Za=no>0?no+(Ya?1:0):0,Ja=useMemo(()=>{if(!Qn||Rn.size===0)return 0;let i=0,x=new Set,l=false;for(let c of Et)c.goalId&&Rn.has(c.goalId)?x.has(c.goalId)||(x.add(c.goalId),i++):l=true;return l&&i++,i},[Qn,Rn,Et]),Qa=E==="goals"?pt.length+1:E==="tasks"?Et.length+1+(An>0?1:0)+Ja:E==="agents"?de.length+1+Za:0,el=Math.min(Qa+1,Math.ceil(_t*.5)),tl=E==="logs"?_t:Math.max(2,Math.min(el,_t-4)),Se,Ot;if(E==="logs")Se=_t,Ot=0;else if(ko)Se=0,Ot=Math.max(1,_t);else {let i=Math.max(3,Math.min(tl+Sr,_t-4));Se=i,Ot=Math.max(1,_t-i);}let Me=Math.max(10,ae-2),Mt=useMemo(()=>Pe==="command"?ni(dn):[],[Pe,dn]),En=_t-4-3;useEffect(()=>{Sr>En&&vn(En),Sr<-En&&vn(-En);},[_t]),useEffect(()=>{In(i=>Math.min(i,Math.max(0,Et.length-Se)));},[Et.length,Se]),useEffect(()=>{yr(i=>Math.min(i,Math.max(0,Ne.length-Se)));},[Ne.length,Se]),useEffect(()=>{wr(i=>Math.min(i,Math.max(0,pt.length-Se)));},[pt.length,Se]);let nl=useCallback(i=>{let l=i.trim().replace(/^\//,"").split(/\s+/),c=l[0]?.toLowerCase();if(!c)return;let u=b=>b instanceof Error?b.message:String(b);switch(c){case "cancel":{if(!j){a("No task selected",e.yellow);return}if(!h)return;a(`Cancelling "${j.title}"...`,e.amber),h(j.id).then(()=>{a(`\u2713 Cancelled "${j.title}"`,e.green),K();},b=>a(`Failed: ${u(b)}`,e.red));return}case "retry":{if(!j){a("No task selected",e.yellow);return}if(!y)return;a(`Retrying "${j.title}"...`,e.amber),y(j.id).then(()=>{a(`\u2713 Retried "${j.title}"`,e.green),K();},b=>a(`Failed: ${u(b)}`,e.red));return}case "assign":{if(!j){a("No task selected",e.yellow);return}if(!m||!l[1]){a("Usage: assign <agent>",e.yellow);return}a(`Assigning "${j.title}" to ${l[1]}...`,e.amber),m(j.id,l[1]).then(()=>{a(`\u2713 Assigned "${j.title}" to ${l[1]}`,e.green),K();},b=>a(`Failed: ${u(b)}`,e.red));return}case "task":{let b=l[1]?.toLowerCase();if(b==="add"){let g=l.slice(2).join(" ");if(!g){Mo();return}if(!f){a("Create not available",e.yellow);return}a(`Creating "${g}"...`,e.amber),f(g).then(k=>{a(`\u2713 Created "${k.title}" (${k.id})`,e.green),K();},k=>a(`Failed: ${u(k)}`,e.red));}else if(b==="list"){let g=Oe.map(k=>` ${k.id} ${k.status.padEnd(11)} ${k.title}`);if(g.length===0)a("No tasks",e.dim);else for(let k of g)a(k,e.cyan);}else if(b==="show"){let g=l[2]?Oe.find(k=>k.id===l[2]):j;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(b==="cancel"){let g=l[2]?Oe.find(k=>k.id===l[2]):j;if(!g){a("No task selected or id given",e.yellow);return}if(!h)return;a(`Cancelling "${g.title}"...`,e.amber),h(g.id).then(()=>{a(`\u2713 Cancelled "${g.title}"`,e.green),K();},k=>a(`Failed: ${u(k)}`,e.red));}else if(b==="retry"){let g=l[2]?Oe.find(k=>k.id===l[2]):j;if(!g){a("No task selected or id given",e.yellow);return}if(!y)return;a(`Retrying "${g.title}"...`,e.amber),y(g.id).then(()=>{a(`\u2713 Retried "${g.title}"`,e.green),K();},k=>a(`Failed: ${u(k)}`,e.red));}else if(b==="assign"){let g=l[2]?Oe.find(Lt=>Lt.id===l[2]):void 0,k=g??j,Y=g?l[3]:l[2];if(!k){a("No task selected or id given",e.yellow);return}if(!Y){a("Usage: /task assign [id] <agent>",e.yellow);return}if(!m)return;a(`Assigning "${k.title}" to ${Y}...`,e.amber),m(k.id,Y).then(()=>{a(`\u2713 Assigned "${k.title}" to ${Y}`,e.green),K();},Lt=>a(`Failed: ${u(Lt)}`,e.red));}else if(b==="approve"){let g=l[2]?Oe.find(k=>k.id===l[2]):j;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(!P)return;a(`Approving "${g.title}"...`,e.amber),P(g.id).then(()=>{a(`\u2713 Approved "${g.title}"`,e.green),K();},k=>a(`Failed: ${u(k)}`,e.red));}else if(b==="reject"){let g=l[2]?Oe.find(Y=>Y.id===l[2]):j;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(!$)return;let k=l.slice(l[2]&&Oe.find(Y=>Y.id===l[2])?3:2).join(" ").trim()||void 0;a(`Rejecting "${g.title}"${k?" with feedback":""}...`,e.amber),$(g.id,k).then(()=>{a(`\u2713 Rejected "${g.title}" \u2192 todo`,e.green),K();},Y=>a(`Failed: ${u(Y)}`,e.red));}else if(b==="delete"){let g=l[2]?Oe.find(k=>k.id===l[2]):j;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(!H)return;$n("task",g.id,g.title);}else a("Usage: /task add|list|show|cancel|retry|assign|approve|reject|delete",e.yellow);return}case "agent":{let b=l[1]?.toLowerCase();if(b==="add"){let g=l[2];if(!g){_o();return}if(!C){a("Agent creation not available",e.yellow);return}let k=l[3];a(`Creating agent "${g}"...`,e.amber),C(g,k).then(Y=>{a(`\u2713 Created agent "${Y.name}" (${Y.id}, ${Y.adapter})`,e.green),K();},Y=>a(`Failed: ${u(Y)}`,e.red));}else if(b==="list"){let g=Ne.map(k=>` ${k.id} ${k.status.padEnd(8)} ${k.name} (${k.adapter})`);if(g.length===0)a("No agents",e.dim);else for(let k of g)a(k,e.cyan);}else if(b==="disable"){let g=l[2]?Ne.find(k=>k.id===l[2]||k.name===l[2]):Z;if(!g){a("No agent selected or id given",e.yellow);return}if(!S)return;a(`Disabling ${g.name}...`,e.amber),S(g.id).then(()=>{a(`\u2713 Disabled ${g.name}`,e.green),K();},k=>a(`Failed: ${u(k)}`,e.red));}else if(b==="enable"){let g=l[2]?Ne.find(k=>k.id===l[2]||k.name===l[2]):Z;if(!g){a("No agent selected or id given",e.yellow);return}if(!I)return;a(`Enabling ${g.name}...`,e.amber),I(g.id).then(()=>{a(`\u2713 Enabled ${g.name}`,e.green),K();},k=>a(`Failed: ${u(k)}`,e.red));}else if(b==="delete"||b==="remove"){let g=l[2]?Ne.find(k=>k.id===l[2]||k.name===l[2]):Z;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(!z){a("Agent deletion not available",e.yellow);return}$n("agent",g.id,g.name);}else if(b==="autonomous"||b==="auto"){let g=l[2]?Ne.find(k=>k.id===l[2]||k.name===l[2]):Z;if(!g){a("No agent selected or id given",e.yellow);return}if(!gt){a("Autonomous toggle not available",e.yellow);return}g.autonomous?(a(`Disabling autonomous mode for "${g.name}"...`,e.amber),gt(g.id,false).then(()=>{a(`${xn} ${g.name} autonomous OFF`,e.cyan),K();},k=>a(`Failed: ${u(k)}`,e.red))):(a(`Enabling autonomous mode for "${g.name}"...`,e.amber),gt(g.id,true).then(()=>{a(`${xn} ${g.name} autonomous ON`,e.cyan),K();},k=>a(`Failed: ${u(k)}`,e.red)));}else b==="shop"?Ts():a("Usage: /agent add|list|disable|enable|delete|autonomous|shop",e.yellow);return}case "team":{let b=l[1]?.toLowerCase();if(b==="create"||b==="add")ys();else if(b==="list"){let g=Mn.current;if(g.length===0)a("No teams",e.dim);else for(let k of g)a(` ${k.id} ${k.status.padEnd(8)} ${k.name} (${k.members.length} members)`,e.cyan);}else if(b==="join"){if(!oe){a("Join not available",e.yellow);return}let g=l[2],k=l[3]??Z?.id;if(!g||!k){a("Usage: /team join <teamId> [agentId]",e.yellow);return}a(`Joining team ${g}...`,e.amber),oe(g,k).then(Y=>{a(`\u2713 Agent joined team "${Y.name}"`,e.green),K({includeTeams:true});},Y=>a(`Failed: ${u(Y)}`,e.red));}else if(b==="leave"){if(!we){a("Leave not available",e.yellow);return}let g=l[2],k=l[3]??Z?.id;if(!g||!k){a("Usage: /team leave <teamId> [agentId]",e.yellow);return}a(`Leaving team ${g}...`,e.amber),we(g,k).then(Y=>{a(`\u2713 Agent left team "${Y.name}"`,e.green),K({includeTeams:true});},Y=>a(`Failed: ${u(Y)}`,e.red));}else if(b==="disband"){if(!We){a("Disband not available",e.yellow);return}let g=l[2];if(!g){a("Usage: /team disband <teamId>",e.yellow);return}a(`Disbanding team ${g}...`,e.amber),We(g).then(()=>{a("\u2713 Team disbanded",e.green),K({includeTeams:true});},k=>a(`Failed: ${u(k)}`,e.red));}else if(b==="set-lead"){if(!Ge){a("Set-lead not available",e.yellow);return}let g=l[2],k=l[3];if(!g||!k){a("Usage: /team set-lead <teamId> <agentId>",e.yellow);return}a(`Setting lead for team ${g}...`,e.amber),Ge(g,k).then(Y=>{a(`\u2713 New lead for team "${Y.name}"`,e.green),K({includeTeams:true});},Y=>a(`Failed: ${u(Y)}`,e.red));}else a("Usage: /team create|list|join|leave|disband|set-lead",e.yellow);return}case "goal":{let b=l[1]?.toLowerCase();if(b==="add"||b==="create"){let g=l.slice(2).join(" ").trim();if(!g){let k=nr(de);Qe({title:"New Goal",steps:k,kind:"goal"}),Ee("wizard");return}if(!Ye){a("Goal creation not available",e.yellow);return}a(`Creating goal "${g}"...`,e.amber),Ye({title:g}).then(k=>{a(`\u2713 Created goal "${k.title}" (${k.id})`,e.green),K();},k=>a(`Failed: ${u(k)}`,e.red));}else if(b==="list"){let g=pt.map(k=>` ${k.id} ${k.status.padEnd(8)} ${k.title}`);if(g.length===0)a("No goals",e.dim);else for(let k of g)a(k,e.cyan);}else if(b==="show"){let g=l[2]?pt.find(k=>k.id===l[2]):Q;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(b==="status"){let g=l[2]?pt.find(hn=>hn.id===l[2]):void 0,k=g??Q;if(!k){a("No goal selected or id given",e.yellow);return}let Y=l[g?3:2];if(!Y||!a$1.includes(Y)){a("Usage: /goal status [id] <active|paused|achieved|abandoned>",e.yellow);return}let Lt=Y;if(!ft){a("Status update not available",e.yellow);return}a(`Updating goal status to ${Lt}...`,e.amber),ft(k.id,Lt).then(hn=>{a(`\u2713 Goal "${hn.title}" \u2192 ${Lt}`,e.green),K();},hn=>a(`Failed: ${u(hn)}`,e.red));}else if(b==="delete"){let g=l[2]?pt.find(k=>k.id===l[2]):Q;if(!g){a("No goal selected or id given",e.yellow);return}if(!Ce){a("Goal deletion not available",e.yellow);return}$n("goal",g.id,g.title);}else a("Usage: /goal add|list|show|status|delete",e.yellow);return}case "run":{let b=l[1]??j?.id;if(!b){a("No task selected or id given",e.yellow);return}if(!s){a("Run not available",e.yellow);return}let g=Oe.find(k=>k.id===b);if(g&&!qr.has(g.status)){a(`Cannot run \u2014 status is ${g.status}`,e.yellow);return}a(`Running ${b}...`,e.amber),s(b).then(()=>{a(`\u2713 Dispatched ${b}`,e.green),K();},k=>a(`Failed: ${u(k)}`,e.red));return}case "run-all":{if(!T){a("Run-all not available",e.yellow);return}a("Running all todo tasks...",e.amber),T().then(()=>{a("\u2713 Dispatched all todo tasks",e.green),K();},b=>a(`Failed: ${u(b)}`,e.red));return}case "watch":{if(po){a("Watch mode already active",e.yellow);return}if(!ut){a("Watch not available",e.yellow);return}a("Starting watch mode...",e.amber),ut().then(()=>{dr(true),a("\u2713 Watch mode started",e.green);},b=>a(`Failed: ${u(b)}`,e.red));return}case "pause":{if(!po){a("Watch mode not active",e.yellow);return}if(!Ct){a("Pause not available",e.yellow);return}a("Pausing watch mode...",e.amber),Ct().then(()=>{dr(false),a("\u2713 Watch mode paused",e.green);},b=>a(`Failed: ${u(b)}`,e.red));return}case "config":{l[1]?.toLowerCase()==="activity-filter"?xr(g=>{let k=Kr(g);return rn?.(k.label),a(`Activity filter: ${k.label}`,e.amber),new Set(k.types)}):ws();return}case "status":{let b=ce.filter(g=>g.status==="in_progress").length;a(`${_r} ${b} running ${ce.length} tasks ${Ne.length} agents`,e.cyan);return}case "help":{for(let[b,g]of Object.entries(bn)){let k=g.sub?" "+g.sub.join("|"):g.args?" "+g.args:"";a(` /${b}${k} \u2014 ${g.help}`,e.silver);}return}case "quit":{ln();return}case "disable":{if(!Z){a("No agent selected",e.yellow);return}if(!S)return;a(`Disabling ${Z.name}...`,e.amber),S(Z.id).then(()=>{a(`\u2713 Disabled ${Z.name}`,e.green),K();},b=>a(`Failed: ${u(b)}`,e.red));return}case "enable":{if(!Z){a("No agent selected",e.yellow);return}if(!I)return;a(`Enabling ${Z.name}...`,e.amber),I(Z.id).then(()=>{a(`\u2713 Enabled ${Z.name}`,e.green),K();},b=>a(`Failed: ${u(b)}`,e.red));return}default:a(`Unknown: ${c}. Type /help for commands`,e.yellow);}},[j,Z,Oe,Ne,ce,_r,po,h,y,m,T,s,f,S,I,C,P,$,H,oe,we,We,Ge,ut,Ct,a,ln,K,Mo,_o,ys,ws]);useInput((i,x)=>{if(!($t&&(mr(false),i==="?"||x.escape||i==="\x1BOP"))&&!kn){if((x.ctrl||x.meta)&&i==="s"&&Pe==="wizard"&&bt?.kind==="agent"){Ts();return}if(Pe!=="none"){if(x.escape){Ee("none"),xt.reset(""),So.reset();return}if(x.return){let c=dn.trim();if(!c)return;if(Pe==="new_task"){if(!f)return;Ee("none"),xt.reset(""),a(`Creating "${c}"...`,e.amber),f(c).then(u=>{a(`\u2713 Created "${u.title}" (${u.id})`,e.green),K();},u=>a(`Failed to create: ${u instanceof Error?u.message:String(u)}`,e.red));}else if(Pe==="command"){let u=c;if(Mt.length>0&&Mt[Co]){let b=Mt[Co],g=b.cmd.replace(/\s+\[.*\]$/,"");if((g.startsWith(c)||c==="/")&&(u=g),b.subs&&!g.includes(" ")){xt.setValue(g+" "),gn(0);return}}Ee("none"),xt.reset(""),gn(0),So.push(u),nl(u);}return}if(x.tab&&Pe==="command"){if(Mt.length>0){let c=Mt[Co];if(c){let u=c.cmd.replace(/\s+\[.*\]$/,"");xt.setValue(u+(c.subs?" ":"")),gn(0);}}else {let c=Pr(dn);c&&xt.setValue(dn+c);}return}if(x.upArrow&&Pe==="command"){if(Mt.length>0)gn(c=>Math.max(0,c-1));else {let c=So.prev();c!==null&&xt.setValue(c);}return}if(x.downArrow&&Pe==="command"){if(Mt.length>0)gn(c=>Math.min(Mt.length-1,c+1));else {let c=So.next();xt.setValue(c??"");}return}xt.handleInput(i,x)&&gn(0);return}if(i.toLowerCase()==="q"){ln();return}if(x.escape){if(Ae){qn(false),eo(0);return}if(E==="logs"&&Zn>=0){hr(-1),Jn(0);return}return}if((i==="+"||i==="=")&&E!=="logs"){ko?(kr(false),vn(-Math.floor(_t/2))):vn(l=>Math.max(-En,l-3));return}if(i==="-"&&E!=="logs"){ko?(kr(false),vn(Math.floor(_t/2))):vn(l=>Math.min(En,l+3));return}if(i==="M"&&E!=="logs"){kr(l=>!l);return}if(i==="?"){mr(true);return}if(i==="\x1BOP"){mr(true);return}if(i==="/"&&!Ae){Ee("command"),xt.setValue("/"),gn(0);return}if((i==="a"||i==="A")&&E==="logs"&&!Ae&&!kn&&!Yn){fr(true);return}if(i==="f"&&E==="logs"&&!Ae&&!kn&&!Yn){pr(true);return}if(i==="F"&&E==="logs"&&!Ae&&!kn&&!Yn){ss(l=>new Set(Kr(l).types));return}if((i==="z"||i==="Z")&&_n.length>0){Wa();return}if((i==="f"||i==="F")&&(E==="tasks"||E==="agents"||E==="goals")&&!Ae){xr(l=>{let c=Kr(l);return rn?.(c.label),new Set(c.types)});return}if((i==="n"||i==="N")&&E==="tasks"&&!Ae&&f){Mo();return}if((i==="n"||i==="N")&&E==="agents"&&!Ae&&C){_o();return}if((i==="n"||i==="N")&&E==="goals"&&!Ae&&Ye){let l=nr(de);Qe({title:"New Goal",steps:l,kind:"goal"}),Ee("wizard");return}if((i==="e"||i==="E")&&E==="goals"&&Q&&Ze){let l=aa(Q,de);Qe({title:`Edit Goal: ${Q.title}`,steps:l,kind:"edit_goal",targetId:Q.id}),Ee("wizard");return}if((i==="d"||i==="D")&&E==="goals"&&Q&&Ce){$n("goal",Q.id,Q.title);return}if((i==="c"||i==="C")&&E==="goals"&&Q&&ft){(Q.status==="active"||Q.status==="paused")&&(a(`Marking goal "${Q.title}" as achieved (pending tasks will be cancelled)...`,e.amber),ft(Q.id,"achieved",{force:true}).then(()=>{a(`\u2713 Goal "${Q.title}" achieved`,e.green),K();},l=>a(`Failed: ${l instanceof Error?l.message:String(l)}`,e.red)));return}if((i==="x"||i==="X")&&E==="goals"&&Q&&ft){(Q.status==="active"||Q.status==="paused")&&(a(`Abandoning goal "${Q.title}"...`,e.amber),ft(Q.id,"abandoned").then(()=>{a(`\u2713 Goal "${Q.title}" abandoned`,e.dim),K();},l=>a(`Failed: ${l instanceof Error?l.message:String(l)}`,e.red)));return}if((i==="p"||i==="P")&&E==="goals"&&Q&&ft){let l=Q.status==="paused"?"active":"paused";(Q.status==="active"||Q.status==="paused")&&ft(Q.id,l).then(()=>{a(`Goal "${Q.title}" ${l}`,e.cyan),K();},c=>a(`Failed: ${c instanceof Error?c.message:String(c)}`,e.red));return}if((i==="a"||i==="A")&&E==="tasks"&&j?.status==="review"&&P){a(`Approving "${j.title}"...`,e.amber),P(j.id).then(()=>{a(`\u2713 Approved "${j.title}"`,e.green),K();},l=>a(`Failed: ${l instanceof Error?l.message:String(l)}`,e.red));return}if((i==="x"||i==="X")&&E==="tasks"&&j?.status==="review"&&$){a(`Rejecting "${j.title}"...`,e.amber),$(j.id).then(()=>{a(`\u2713 Rejected "${j.title}" \u2192 todo`,e.green),K();},l=>a(`Failed: ${l instanceof Error?l.message:String(l)}`,e.red));return}if((i==="c"||i==="C")&&E==="tasks"&&j&&h){if(j.status==="done"||j.status==="failed"||j.status==="cancelled"){a(`Cannot cancel \u2014 status is ${j.status}`,e.yellow);return}a(`Cancelling "${j.title}"...`,e.amber),h(j.id).then(()=>{a(`\u2713 Cancelled "${j.title}"`,e.green),K();},l=>a(`Failed: ${l instanceof Error?l.message:String(l)}`,e.red));return}if((i==="e"||i==="E")&&E==="tasks"&&j&&G){za(j);return}if((i==="e"||i==="E")&&E==="agents"&&Z&&W){Va(Z);return}if((i==="s"||i==="S")&&E==="tasks"){ms(l=>!l),Xn(0),In(0);return}if((i==="g"||i==="G")&&E==="tasks"&&!Ae){$a(l=>!l),Xn(0),In(0);return}if((i==="s"||i==="S")&&E==="agents"&&Z&&w){if(!Object.values(ze.running).some(c=>c.agent_id===Z.id)&&Z.status!=="running"){a(`Agent "${Z.name}" is not running`,e.yellow);return}a(`Force-stopping agent "${Z.name}"...`,e.amber),w(Z.id).then(()=>{a(`\u2713 Stopped agent "${Z.name}"`,e.green),K();},c=>a(`Failed: ${c instanceof Error?c.message:String(c)}`,e.red));return}if((i==="d"||i==="D")&&E==="tasks"&&j&&j.status!=="in_progress"&&H){$n("task",j.id,j.title);return}if((i==="d"||i==="D")&&E==="agents"&&Z&&z){let l=Object.values(ze.running).some(c=>c.agent_id===Z.id);if(l&&!w){a(`Cannot delete \u2014 agent "${Z.name}" is running. Press S to stop first.`,e.yellow);return}$n("agent",Z.id,Z.name,{needsForceStop:l});return}if((i==="u"||i==="U")&&E==="agents"&&Z&&gt){let l=!Z.autonomous;a(`${l?"Enabling":"Disabling"} autonomous mode for "${Z.name}"...`,e.amber),gt(Z.id,l).then(()=>{a(`${xn} ${Z.name} autonomous ${l?"ON":"OFF"}`,e.cyan),K();},c=>a(`Failed: ${c instanceof Error?c.message:String(c)}`,e.red));return}if(!Ae){if(i==="g"||i==="G"){Sn("goals");return}if(i==="t"||i==="T"){Sn("tasks");return}if(i==="a"||i==="A"){Sn("agents");return}if(i==="l"||i==="L"){Sn("logs");return}}if(!Ae){let l=No.map(u=>u.id),c=l.indexOf(E);if(x.tab||x.rightArrow){Sn(l[(c+1)%l.length]);return}if(x.leftArrow){Sn(l[(c+l.length-1)%l.length]);return}}if(x.return){let l=An>0?Et.length:-1;if(E==="tasks"&&xo===l){ms(u=>!u),Xn(0),In(0);return}let c=Et.length+(An>0?1:0);if(E==="tasks"&&xo===c&&f){Mo();return}if(E==="goals"&&gr===pt.length&&Ye){let u=nr(de);Qe({title:"New Goal",steps:u,kind:"goal"}),Ee("wizard");return}if(E==="agents"&&ur===Ne.length&&C){_o();return}if(E==="goals"&&Q){qn(u=>!u),eo(0);return}if(E==="tasks"&&j){qn(u=>!u);return}if(E==="agents"&&Z){qn(u=>!u);return}if(E==="logs"&&Zn>=0){qn(u=>!u);return}}if((i==="r"||i==="R")&&E==="tasks"&&j&&s){if(!qr.has(j.status)){a(`Cannot run "${j.title}" \u2014 status is ${j.status}`,e.yellow);return}a(`Running "${j.title}"...`,e.green),s(j.id).then(()=>{a(`Dispatched "${j.title}"`,e.green),K();},l=>a(`Failed to run: ${l instanceof Error?l.message:String(l)}`,e.red));return}if(x.upArrow||i==="k"){if(E==="goals"&&Ae){eo(l=>Math.max(0,l-1));return}E==="goals"?ts(l=>{let c=Math.max(0,l-1);return wr(u=>c<u?c:u),c}):E==="tasks"?Xn(l=>{let c=Math.max(0,l-1);return In(u=>c<u?c:u),c}):E==="agents"?es(l=>{let c=Math.max(0,l-1);return yr(u=>c<u?c:u),c}):E==="logs"&&hr(l=>{if(l===-1){let u=Ve.length-1;return Jn(Math.max(0,u-Se+2)),Math.max(0,u)}let c=Math.max(0,l-1);return Jn(u=>c<u?c:u),c});}if(x.downArrow||i==="j"){if(E==="goals"&&Ae){eo(l=>l+1);return}if(E==="goals"){let l=pt.length+(Ye?1:0)-1;ts(c=>{let u=Math.min(Math.max(0,l),c+1);return wr(b=>u>=b+Se?u-Se+1:b),u});}else if(E==="tasks"){let l=Et.length+(f?1:0)+(An>0?1:0)-1;Xn(c=>{let u=Math.min(Math.max(0,l),c+1);return In(b=>u>=b+Se?u-Se+1:b),u});}else if(E==="agents"){let l=Ne.length+(C?1:0)-1;es(c=>{let u=Math.min(Math.max(0,l),c+1);return yr(b=>u>=b+Se?u-Se+1:b),u});}else E==="logs"&&hr(l=>{if(l===-1)return -1;let c=Ve.length-1;if(l>=c)return Jn(0),-1;let u=l+1;return Jn(b=>u>=b+Se-1?u-Se+2:b),u});}}});let st=Pe!=="none",Cs=Zn>=0?Ve[Zn]:void 0,Ro=ko?"+/- exit max":"+/- resize \u2502 M max",Is=!st&&Ae&&E==="tasks"&&j,vs=!st&&Ae&&E==="agents"&&Z,_s=!st&&Ae&&E==="goals"&&Q,ol=!st&&Ae&&E==="logs"&&Cs,Mr=j?.id,rl=useMemo(()=>Mr?Ve.filter(i=>i.taskId===Mr):[],[Ve,Mr]),sl=!st&&E==="tasks"&&j&&qr.has(j.status)&&!!s,il=!st&&!Ae&&(E==="goals"&&!!Ye||E==="tasks"&&!!f||E==="agents"&&!!C),al=!st&&E==="tasks"&&j?.status==="review"&&!!P,ll=!st&&E==="tasks"&&j?.status==="review"&&!!$,cl=Z?Object.values(ze.running).some(i=>i.agent_id===Z.id):false,dl=!st&&(E==="goals"&&Q&&!!Ce||E==="tasks"&&j&&j.status!=="in_progress"&&!!H||E==="agents"&&Z&&!!z),ul=!st&&!Ae&&(E==="goals"&&!!Q&&!!Ze||E==="tasks"&&!!j&&!!G||E==="agents"&&!!Z&&!!W),gl=!st&&E==="agents"&&Z&&(cl||Z.status==="running")&&!!w,ml=!st&&E==="agents"&&!!Z&&!!gt,fl=!st&&E==="goals"&&!!Q&&(Q.status==="active"||Q.status==="paused")&&!!ft,pl=!st&&_n.length>0,Ms=Pe==="command"&&Mt.length>0,Rs=bt?.kind==="task"||bt?.kind==="edit_task";return jsxs(Box,{flexDirection:"column",width:ae,height:ue,children:[jsx(ti,{projectName:t,activeView:E,mode:_r,stats:ks,tokens:qa,uptime:Xa,width:ae,version:sn,latestVersion:cn,updateInstalled:N,taskBadge:An>0?Oe.length:void 0,flashTab:Tr?.tab,flashColor:Tr?.color,onFlashComplete:Tr?()=>ls(void 0):void 0}),jsx(Box,{height:1}),$t&&jsx(Li,{width:ae,height:ue-7}),!$t&&Yt==="welcome"&&E==="tasks"&&jsx(Si,{width:ae,height:ue}),!$t&&E==="goals"&&jsx(Zc,{goals:pt,selectedIndex:gr,scrollOffset:Oa,height:Se,width:Me,showAddRow:!!Ye,agentNameMap:mn,tasksByGoalMap:Pa}),!$t&&Yt!=="welcome"&&E==="tasks"&&jsx(Qc,{tasks:Et,selectedIndex:xo,scrollOffset:Ba,height:Se,width:Me,showAddRow:!!f,agentNameMap:mn,hiddenCount:An,goalMap:Rn,groupByGoal:Qn}),!$t&&E==="tasks"&&(Yt==="task_created"||Yt==="run_started")&&jsx(ki,{step:Yt,width:ae}),!$t&&E==="tasks"&&Yt==="completed"&&jsx(Ci,{width:ae}),!$t&&E==="agents"&&jsx(ed,{agents:Ne,selectedIndex:ur,scrollOffset:Ea,height:Se,width:Me,state:ze,taskTitleMap:to,showAddRow:!!C,agentTeamMap:Bn,teamLeadSet:Da,activeTeamCount:no}),!$t&&E==="logs"&&jsxs(Fragment,{children:[jsx(nd,{messages:Ve,height:kn||Yn?Math.max(3,Se-16):Se,agents:Ne,logAgentFilter:os,logTypeFilter:rs,selectedIndex:Zn,scrollOffset:Ia,agentNameMap:mn,agentColorMap:Io,agentMsgCounts:hs,taskTitleMap:to,width:Me}),kn&&jsx(Box,{paddingX:2,children:jsx(xi,{agents:Ne,selected:os,msgCounts:hs,colorMap:Io,maxHeight:Math.min(Se-4,18),onConfirm:i=>{Ca(i),fr(false);},onCancel:()=>fr(false)})}),Yn&&jsx(Box,{paddingX:2,children:jsx(wi,{selected:rs,typeCounts:Na,onConfirm:i=>{ss(i),pr(false);},onCancel:()=>pr(false)})})]}),jsx(Box,{height:1}),$t?null:Pe==="wizard"&&bt?jsx(fi,{title:bt.title,steps:bt.steps,onComplete:ja,onCancel:Ha,width:Me,height:Ot,onPasteImage:Rs?Ga:void 0,onSuggestionSelected:bt.kind==="agent"?Ua:void 0,footerExtra:un.length>0&&Rs?`\u{1F4CE}${un.length}`:void 0},`${bt.kind}-${bt.title}`):Ms?jsxs(Fragment,{children:[jsx(or,{label:"COMMANDS",width:Me}),jsx(Yc,{suggestions:Mt,selectedIndex:Co,height:Math.min(Mt.length,Ot),width:Me})]}):Pe==="new_task"?jsxs(Fragment,{children:[jsx(cd,{mode:Pe,width:Me}),jsx(dd,{mode:Pe,cursor:xt.cursor,width:Me})]}):Is?jsxs(Fragment,{children:[jsx(sd,{task:j,width:Me,resizeHint:Ro}),jsx(Js,{task:j,height:Ot,width:Me,taskLogs:rl,agentNameMap:mn,taskTitleMap:to})]}):_s?jsxs(Fragment,{children:[jsx(or,{label:`GOAL: ${Q.title}`,width:Me,suffixLen:Ro.length+2,suffix:jsxs(Text,{color:e.dim,children:[" ",Ro," "]})}),jsx(Jc,{goal:Q,height:Ot,width:Me,agentNameMap:mn,tasks:Fa,progressReport:ka,scrollOffset:La,onClampScroll:eo})]}):vs?jsxs(Fragment,{children:[jsx(id,{agent:Z,width:Me,resizeHint:Ro}),jsx(ad,{agent:Z,height:Ot,state:ze,taskTitleMap:to,teamName:Bn.get(Z.id)})]}):ol?jsxs(Fragment,{children:[jsx(or,{label:"LOG",width:Me}),jsx(rd,{message:Cs,height:Ot,width:Me,agents:Ne,agentNameMap:mn,agentColorMap:Io,taskTitleMap:to})]}):Ve.length>0&&E!=="logs"?jsxs(Fragment,{children:[(()=>{let i=` F:${bo.toUpperCase()} \u2502 ${br.length}/${Ve.length}`;return jsx(or,{label:"ACTIVITY",width:Me,suffixLen:i.length,suffix:jsxs(Fragment,{children:[jsx(Text,{color:e.dim,children:" F:"}),jsx(Text,{color:e.amber,children:bo.toUpperCase()}),jsxs(Text,{color:e.ghost,children:[" ","\u2502"," ",br.length,"/",Ve.length]})]})})})(),jsx(od,{messages:br,height:Math.max(1,Ot-1),width:Me,agents:Ne,agentNameMap:mn,agentColorMap:Io})]}):E==="goals"?jsx(Zo,{count:pt.length,config:vi,width:Me}):E==="tasks"?jsx(Zo,{count:Oe.length,config:_i,width:Me}):E==="agents"?jsx(Zo,{count:Ne.length,config:Mi,width:Me}):null,jsx(Box,{flexGrow:1}),jsx(Oi,{toasts:Ma,onDismiss:Aa}),_n.length>0&&jsx(Kc,{deletions:_n,width:ae}),jsx(oi,{mode:Pe==="command"?"command":"navigate",value:Pe==="command"?dn:"",completion:Pe==="command"?Pr(dn):null,activeView:E,canRun:!!sl,canNew:!!il,canApprove:!!al,canReject:!!ll,canCancel:E==="tasks"&&!!j&&j.status==="in_progress"&&!!h,canDelete:!!dl,canUndo:!!pl,canEdit:!!ul,canForceStop:!!gl,canToggleAuto:!!ml,autoActive:Z?.autonomous,canPause:!!fl,isPaused:Q?.status==="paused",canToggleShowAll:E==="tasks"&&Oe.length>ca,showAllActive:gs,hasDetail:!!(Is||vs||_s),itemCount:E==="goals"?pt.length:E==="tasks"?Oe.length:E==="agents"?de.length:Ve.length,itemLabel:E==="goals"?"goals":E==="tasks"?"tasks":E==="agents"?"agents":"events",width:ae,hasSuggestions:Ms,onboardingCompleted:r.onboardingCompleted})]})}var Kc=co.memo(function({deletions:n,width:o}){let[,r]=useState(0);useEffect(()=>{let f=setInterval(()=>r(h=>h+1),1e3);return ()=>clearInterval(f)},[]);let s=Date.now();return jsx(Box,{flexDirection:"column",width:o,children:n.map(f=>{let h=Math.max(0,Math.ceil((f.expiresAt-s)/1e3)),y=Math.max(0,o-4),m=f.entityType==="task"?"Task":f.entityType==="agent"?"Agent":"Goal",T=Math.max(10,y-m.length-30),S=f.entityName.length>T?f.entityName.slice(0,T-1)+"\u2026":f.entityName;return jsx(Box,{paddingX:2,children:jsxs(Text,{color:e.yellow,children:["\u2717 ",jsx(Text,{bold:true,children:m}),` "${S}" \u2014 `,jsxs(Text,{color:e.amber,bold:true,children:[h,"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 Yc({suggestions:t,selectedIndex:n,height:o,width:r}){let s=o,f=0;n>=s&&(f=n-s+1);let h=t.slice(f,f+s);return jsx(Box,{flexDirection:"column",paddingX:2,children:h.map((y,m)=>{let T=m+f,S=T===n,I=S?"\u25B6":" ",M=Math.min(20,Math.max(14,...t.map(C=>C.cmd.length+1))),v=y.cmd.padEnd(M),L=y.subs?` ${y.subs}`:"",_=Math.max(4,r-M-L.length-8),R=y.desc.length>_?y.desc.slice(0,_-1)+"\u2026":y.desc;return jsxs(Text,{wrap:"truncate",children:[jsx(Text,{color:S?e.amber:e.ghost,children:` ${I} `}),jsx(Text,{color:S?e.white:e.silver,bold:S,children:v}),jsx(Text,{color:e.dim,children:R}),L&&jsx(Text,{color:e.ghost,children:L})]},T)})})}function Zc({goals:t,selectedIndex:n,scrollOffset:o=0,height:r,width:s,showAddRow:f,agentNameMap:h,tasksByGoalMap:y}){let m=t.length,T=t.slice(o,o+r),S=f&&m>=o&&m<o+r;return jsxs(Box,{flexDirection:"column",height:r,children:[T.map((I,M)=>jsx(Box,{paddingX:2,children:jsx(Zs,{goal:I,selected:M+o===n,width:s-2,agentNameMap:h,tasksByGoal:y?.get(I.id)})},I.id)),S&&jsx(Box,{paddingX:2,children:jsxs(Text,{color:n===m?e.amber:e.ghost,children:[n===m?" \u25B8 ":" ",jsx(Text,{color:n===m?e.amber:e.dim,children:"+ add goal..."})]})},"__add__")]})}function Jc({goal:t,height:n,width:o,agentNameMap:r,tasks:s,progressReport:f,scrollOffset:h=0,onClampScroll:y}){let T=co.useMemo(()=>{let _=s??[],R=t.assignee?r?.get(t.assignee)??t.assignee:"\u2014",C=Math.max(20,o-6),z=(w,U)=>{if(w.length<=U)return [w];let ie=[];for(let oe=0;oe<w.length;oe+=U)ie.push(w.slice(oe,oe+U));return ie},P=Er(f)?.split(`
13
- `).flatMap(w=>z(w,C))??[],$=Er(t.description)?.split(`
14
- `).flatMap(w=>z(w,C))??[],H=Ps[t.status]??e.dim,G=new Map;for(let w of _)G.set(w.status,(G.get(w.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:H,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:R})]})]})}),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)})]})]})}),_.length>0){let w=[];for(let[U,ie]of G)w.push(`${ie} ${U}`);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:_.length})]}),jsxs(Box,{children:[jsx(Text,{color:e.dim,children:" "}),jsx(Text,{color:e.dim,children:w.join(" \xB7 ")})]})]})});}if($.length>0){W.push({key:"desc-gap",node:jsx(Text,{children:" "})});for(let w=0;w<$.length;w++)W.push({key:`desc-${w}`,node:jsxs(Text,{color:e.silver,wrap:"truncate",children:[" ",$[w]]})});}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(P.length>0){W.push({key:"prog-gap",node:jsx(Text,{children:" "})}),W.push({key:"prog-div",node:jsx(Fn,{label:"progress",width:o})});for(let w=0;w<P.length;w++)W.push({key:`prog-${w}`,node:jsxs(Text,{color:e.white,wrap:"truncate",children:[" ",P[w]]})});}if(_.length>0){W.push({key:"tasks-gap",node:jsx(Text,{children:" "})}),W.push({key:"tasks-div",node:jsx(Fn,{label:`tasks (${_.length})`,width:o})});for(let w of _){let U=Eo[w.status]??e.dim;W.push({key:`task-${w.id}`,node:jsxs(Text,{color:e.silver,wrap:"truncate",children:[" ",jsx(Text,{color:U,children:w.status.padEnd(12)}),w.title.slice(0,Math.max(10,o-22))]})});}}return W},[t,s,f,o,r]),S=Math.max(0,T.length-n),I=Math.min(h,S);co.useEffect(()=>{y&&I!==h&&y(I);},[I,h,y]);let M=T.length>n&&I<S,v=M?n-1:n,L=T.slice(I,I+v);return jsxs(Box,{flexDirection:"column",height:n,paddingX:2,children:[L.map(_=>jsx(Box,{children:_.node},_.key)),M&&jsxs(Text,{color:e.ghost,children:[" ","\u2193"," ",T.length-I-v," more ","\u2014"," ","\u2191","\u2193"," to scroll"]})]})}function Qc({tasks:t,selectedIndex:n,scrollOffset:o=0,height:r,width:s,showAddRow:f,agentNameMap:h,hiddenCount:y=0,goalMap:m,groupByGoal:T=false}){let S=y>0,I=S?t.length:-1,M=t.length+(S?1:0),v=t.slice(o,o+r),L=S&&I>=o&&I<o+r,_=f&&M>=o&&M<o+r,R=useMemo(()=>{if(!T||!m||m.size===0)return null;let H=new Map;for(let G of t)if(G.goalId&&m.has(G.goalId)){let W=H.get(G.goalId)??{total:0,done:0};W.total++,G.status==="done"&&W.done++,H.set(G.goalId,W);}return H},[t,T,m]),C=T&&m?t.filter(H=>!H.goalId||!m.has(H.goalId)).length:0,z=T&&m&&m.size>0&&R&&R.size>0,P=[],$=o>0?t[o-1]?.goalId??null:void 0;for(let H=0;H<v.length&&P.length<r;H++){let G=v[H],W=G.goalId&&m?.has(G.goalId)?G.goalId:null;if(z){if(W&&W!==$){let w=m.get(W),U=R.get(W)??{total:0,done:0};if(P.push(jsx(zs,{goalTitle:w.title,taskCount:U.total,doneCount:U.done,width:s},`gh_${W}`)),P.length>=r)break}if(!W&&$!==null&&$!==void 0&&(P.push(jsx(Vs,{taskCount:C,width:s},"__ungrouped__")),P.length>=r))break}$=W,P.push(jsx(Box,{paddingX:2,children:jsx(Po,{task:G,selected:H+o===n,width:s-2,agentNameMap:h,goalMap:m})},G.id));}return L&&P.length<r&&P.push(jsx(Box,{paddingX:2,children:jsxs(Text,{color:n===I?e.amber:e.ghost,children:[n===I?" \u25B8 ":" ",jsxs(Text,{color:n===I?e.amber:e.dim,children:["\u25BC"," Show all (",y," more) \u2014 press ",jsx(Text,{bold:true,color:e.gray,children:"S"})]})]})},"__show_all__")),_&&P.length<r&&P.push(jsx(Box,{paddingX:2,children:jsxs(Text,{color:n===M?e.amber:e.ghost,children:[n===M?" \u25B8 ":" ",jsx(Text,{color:n===M?e.amber:e.dim,children:"+ add task..."})]})},"__add__")),jsx(Box,{flexDirection:"column",height:r,children:P})}function ed({agents:t,selectedIndex:n,scrollOffset:o=0,height:r,width:s,state:f,taskTitleMap:h,showAddRow:y,agentTeamMap:m,teamLeadSet:T,activeTeamCount:S}){let I=new Map;for(let G of Object.values(f.running))I.set(G.agent_id,G);let M=new Map;if(S&&S>0)for(let G of t){let W=m?.get(G.id);W&&M.set(W,(M.get(W)??0)+1);}let v=t.length,L=t.slice(o,o+r),_=y&&v>=o&&v<o+r,R=S!=null&&S>0,C=new Map;if(R&&T&&m){for(let G of t)if(T.has(G.id)){let W=m.get(G.id);W&&C.set(W,G.name);}}let z=0;for(let G of M.values())z+=G;let P=t.length-z,$=[],H=o>0?m?.get(t[o-1]?.id??""):void 0;for(let G=0;G<L.length&&$.length<r;G++){let W=L[G],w=m?.get(W.id);if(R&&w&&w!==H&&($.push(jsx(Xs,{teamName:w,memberCount:M.get(w)??0,leadName:C.get(w),width:s},`ts-${w}`)),$.length>=r)||R&&!w&&H&&($.push(jsx(qs,{memberCount:P,width:s},"ts-unassigned")),$.length>=r))break;H=w,$.push(jsx(Box,{paddingX:2,children:jsx(Us,{agent:W,selected:G+o===n,width:s-2,runningEntry:I.get(W.id),currentTaskTitle:W.current_task?h.get(W.current_task):void 0,teamName:w,isLead:T?.has(W.id)})},W.id));}return _&&$.length<r&&$.push(jsx(Box,{paddingX:2,children:jsxs(Text,{color:n===v?e.amber:e.ghost,children:[n===v?" \u25B8 ":" ",jsx(Text,{color:n===v?e.amber:e.dim,children:"+ add agent..."})]})},"__add__")),jsx(Box,{flexDirection:"column",height:r,children:$})}function xa(t=5e3){let[n,o]=useState(Date.now());return useEffect(()=>{let r=setInterval(()=>o(Date.now()),t);return ()=>clearInterval(r)},[t]),n}function ba(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 td(t){if(t==="error")return e.errorBg}function Ta(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 nd({messages:t,height:n,agents:o,logAgentFilter:r,logTypeFilter:s,selectedIndex:f,scrollOffset:h,agentNameMap:y,agentColorMap:m,agentMsgCounts:T,taskTitleMap:S,width:I}){let M=xa(),v=useMemo(()=>t.filter(U=>{if(r.size>0&&U.agentId&&!r.has(U.agentId))return false;let ie=U.msgType??"info";return s.has(ie)}),[t,r,s]);useMemo(()=>{let U={};for(let ie of t){let oe=ie.msgType??"info";U[oe]=(U[oe]??0)+1;}return U},[t]);let _=s.size>=8?"all":s.size===1&&s.has("output")?"text":s.size===1&&s.has("error")?"errors":s.has("tool")&&!s.has("output")?"tools":s.has("lifecycle")&&!s.has("output")?"events":`${s.size} types`,R=r.size>0,C=n-2,z=f===-1?v.slice(-C):v.slice(h,h+C),P=f===-1?-1:f-h,$=Math.min(10,Math.max(6,...o.map(U=>U.name.length))),H=11+$,G=U=>{if(U===0)return true;let ie=z[U],oe=z[U-1];return ie.agentId!==oe.agentId?true:ie.agentId?ie.ts-oe.ts>3e4:false},W=Math.max(4,Math.floor((I-20)/Math.max(1,o.length))-1),w=Math.min(W,10);return jsxs(Box,{flexDirection:"column",paddingX:1,children:[jsxs(Box,{gap:0,justifyContent:"space-between",width:I,children:[jsxs(Box,{gap:0,children:[f===-1?jsxs(Box,{gap:0,children:[jsx(Text,{backgroundColor:e.successBg,color:e.green,children:" "}),jsx(Text,{backgroundColor:e.successBg,color:e.green,children:jsx(Ht,{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,"/",v.length," "]}),jsxs(Text,{color:e.dim,children:[" ",v.length," events"]}),_!=="all"&&jsxs(Text,{color:e.amber,children:[" f:",_]}),R&&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(U=>{let ie=m.get(U.id)??Zr[0],oe=r.size===0||r.has(U.id),we=U.name.length>w?U.name.slice(0,w-1)+"\u2026":U.name;return jsxs(Text,{color:oe?ie:e.ghost,bold:oe,children:[" ",we]},U.id)})}),z.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"})]})]}):z.map((U,ie)=>{let oe=ie===P,we=U.msgType??"info",We=lr[we]??"\u2502",Ge=U.agentId?y.get(U.agentId)??U.agentId.slice(0,8):void 0,ut=U.agentId?m.get(U.agentId):void 0,Ct=G(ie),mt=(ie>0?z[ie-1]:void 0)?.agentId===U.agentId&&!!U.agentId,Ye=!mt&&!!Ge,Ze=mt&&!!Ge,ft=Ta(we,U.color),Ce=oe?e.infoBg:we==="error"?e.errorBg:void 0,Wt=U.taskId?S.get(U.taskId):void 0,It=ba(U.ts,M),ht=Wt&&I>80?`#${Wt.slice(0,20)}`:"",Je=ht?ht.length+3:0,ot=Math.max(10,I-2-H-Je),Xe=it(U.text,ot);return jsxs(Box,{backgroundColor:Ce,children:[jsx(Text,{color:ut??e.ghost,children:Ct&&Ye?"\u250C":Ze?"\u2502":" "}),jsx(Text,{color:oe?e.amber:void 0,children:oe?"\u25B8":" "}),jsx(Box,{width:5,children:jsx(Text,{color:It==="now"?e.green:oe?e.silver:e.ghost,children:It.padStart(4)})}),jsx(Box,{width:$+1,children:Ye?jsxs(Text,{color:ut,bold:true,children:[" ",Ge.slice(0,$).padEnd($)]}):Ze?jsxs(Text,{color:ut??e.ghost,children:[" ","\xB7".padEnd($)]}):jsxs(Text,{color:e.ghost,children:[" "," ".padEnd($)]})}),jsxs(Text,{color:we==="error"?e.red:ut??e.dim,children:[" ",We," "]}),jsx(Text,{color:oe?e.white:ft,bold:oe||we==="lifecycle",children:Xe}),ht&&jsxs(Text,{color:e.ghost,children:[" ",jsx(Text,{color:e.dim,backgroundColor:e.void,children:` ${ht} `})]})]},ie)})]})}function od({messages:t,height:n,width:o,agents:r,agentNameMap:s,agentColorMap:f}){let h=xa(),y=t.slice(-n),m=Math.max(10,o-2-17),T=Math.max(0,n-y.length),S=0,I=[];for(let M=0;M<y.length;M++)M>0&&y[M].agentId!==y[M-1].agentId&&S++,I.push(S);return jsxs(Box,{flexDirection:"column",paddingX:1,children:[T>0&&jsx(Box,{height:T}),y.map((M,v)=>{let L=M.agentId?s.get(M.agentId)??M.agentId.slice(0,8):void 0,_=M.agentId?f.get(M.agentId):void 0,R=M.msgType??"info",C=lr[R]??"\u2502",z=Ta(R,M.color),$=(v>0?y[v-1]:void 0)?.agentId===M.agentId&&!!M.agentId,H=(I[v]&1)===1,G=td(R)??(H?"#1a1a1a":void 0),W=ba(M.ts,h),w=it(M.text,m);return jsxs(Box,{backgroundColor:G,children:[jsx(Text,{color:_??e.ghost,children:!$&&L?"\u258D":$?"\u258F":" "}),jsx(Box,{width:5,children:jsx(Text,{color:$?e.ghost:W==="now"?e.green:e.dim,children:$?" ":W.padStart(4)})}),jsx(Box,{width:9,children:L&&!$?jsxs(Text,{color:_,bold:true,children:[" ",L.slice(0,8)]}):jsx(Text,{color:e.ghost,children:qc})}),jsxs(Text,{color:R==="error"?e.red:$?e.ghost:_??e.dim,children:[C," "]}),jsx(Text,{color:z,children:w})]},v)})]})}function rd({message:t,height:n,width:o,agents:r,agentNameMap:s,agentColorMap:f,taskTitleMap:h}){let y=t.detail??t.text,m=t.msgType??"info",T=t.agentId?s.get(t.agentId)??t.agentId.slice(0,8):void 0,S=t.agentId?f.get(t.agentId):e.dim,I=t.taskId?h.get(t.taskId):void 0,M,v=false;try{let C=JSON.parse(y);M=JSON.stringify(C,null,2),v=!0;}catch{M=y;}let L=Math.max(4,o-6),_=Math.max(1,n-4),R=M.split(`
15
- `).slice(0,_);return jsxs(Box,{flexDirection:"column",paddingX:1,children:[jsx(Box,{children:jsxs(Text,{color:e.ghost,children:["\u256D",Te(L+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 "}),T&&jsx(Text,{color:S,bold:true,children:T}),T&&jsx(Text,{color:e.ghost,children:" \u2502 "}),jsxs(Text,{color:lr[m]?m==="error"?e.red:e.dim:e.dim,children:[lr[m]??"\u2502"," ",m]}),I&&jsxs(Fragment,{children:[jsx(Text,{color:e.ghost,children:" \u2502 "}),jsxs(Text,{color:e.dim,children:["#",I.slice(0,30)]})]})]}),jsxs(Box,{children:[jsx(Text,{color:e.ghost,children:"\u2502 "}),jsx(Text,{color:t.color,bold:true,wrap:"truncate",children:t.text.slice(0,L)})]}),jsx(Box,{children:jsxs(Text,{color:e.ghost,children:["\u251C",Te(L+2),"\u2524"]})}),R.map((C,z)=>jsxs(Box,{children:[jsx(Text,{color:e.ghost,children:"\u2502 "}),v&&jsxs(Text,{color:e.ghost,children:[String(z+1).padStart(3)," "]}),jsx(Text,{wrap:"truncate",color:v&&C.includes('"')?e.cyan:v&&/^\s*[}\]]/.test(C)?e.ghost:C.startsWith("error")||C.startsWith("Error")?e.red:e.silver,children:C.slice(0,v?L-4:L)})]},z)),jsx(Box,{children:jsxs(Text,{color:e.ghost,children:["\u2570",Te(L+2),"\u256F"]})})]})}function or({label:t,width:n,suffix:o,suffixLen:r=0}){let s=` ${t} `,f=3,h=f+s.length+2;if(!o){let T=Math.max(0,n-h);return jsxs(Box,{paddingX:1,children:[jsx(Text,{color:e.ghost,children:He(f)}),jsx(Text,{backgroundColor:"#1a1a22",color:e.dim,bold:true,children:s}),jsx(Text,{color:e.ghost,children:He(T)})]})}let y=2,m=Math.max(0,n-h-y-r);return jsxs(Box,{paddingX:1,children:[jsx(Text,{color:e.ghost,children:He(f)}),jsx(Text,{backgroundColor:"#1a1a22",color:e.dim,bold:true,children:s}),jsx(Text,{color:e.ghost,children:He(y)}),o,jsx(Text,{color:e.ghost,children:He(m)})]})}function sd({task:t,width:n,resizeHint:o}){let r=" DETAIL ",s=o?` ${o} `:"",f=n-r.length-s.length-10,h=t.title.length>f?t.title.slice(0,f-3)+"...":t.title,y=Math.max(0,n-3-r.length-h.length-s.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:[$o," "]}),jsx(Text,{color:e.white,bold:true,children:h}),jsxs(Text,{color:e.ghost,children:[" ",He(Math.max(0,y))]}),s?jsx(Text,{color:e.dim,children:s}):null]})}function id({agent:t,width:n,resizeHint:o}){let r=" AGENT ",s=o?` ${o} `:"",f=n-r.length-s.length-10,h=t.name.length>f?t.name.slice(0,f-3)+"...":t.name,y=Math.max(0,n-3-r.length-h.length-s.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:[$o," "]}),jsx(Text,{color:e.green,bold:true,children:h}),jsxs(Text,{color:e.ghost,children:[" ",He(Math.max(0,y))]}),s?jsx(Text,{color:e.dim,children:s}):null]})}function ad({agent:t,height:n$1,state:o,taskTitleMap:r,teamName:s}){let f=ld[t.status]??e.dim;Object.values(o.running).find(T=>T.agent_id===t.id);let y=t.current_task?r.get(t.current_task):void 0,m=24;return jsxs(Box,{flexDirection:"column",paddingX:2,children:[jsxs(Box,{children:[jsxs(Box,{width:m,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:m,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:y?e.white:e.dim,children:y??"\u2014"})]})]}),jsxs(Box,{children:[jsxs(Box,{width:m,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:s?e.amber:e.dim,children:s??"\u2014"})]})]}),t.autonomous&&jsx(Box,{children:jsxs(Box,{width:m,children:[jsx(Text,{color:e.dim,children:" auto "}),jsxs(Text,{color:e.cyan,children:[xn," 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:it(t.config.skills.join(", "),500)})]}),t.last_error&&(()=>{let T=t.last_error.kind,S=n[T],I=!S||T==="unknown",M=t.last_error.timestamp,v=M?g(M)+" 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"]}),S&&jsx(Text,{color:e.white,children:S.message}),S&&jsx(Text,{color:e.cyan,children:S.fix}),S?.doctorHint&&jsx(Text,{color:e.yellow,children:"\u0414\u0438\u0430\u0433\u043D\u043E\u0441\u0442\u0438\u043A\u0430: orch doctor"}),I&&t.last_error.message&&jsx(Text,{color:e.dim,children:it(t.last_error.message,120)}),v&&jsx(Text,{color:e.dim,children:v})]})]})})(),jsx(Text,{children:" "}),t.role?t.role.split(`
16
- `).slice(0,Math.max(1,n$1-(t.last_error?10:4))).map((T,S)=>jsxs(Text,{color:e.silver,wrap:"truncate",children:[" ",it(T,500)]},S)):jsx(Text,{color:e.dim,children:" No role description."})]})}var ld={idle:e.dim,running:e.green,error:e.red,disabled:e.ghost};function cd({mode:t,width:n}){let r=` ${t==="command"?"COMMAND":"NEW TASK"} `,s=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(s)})]})}function dd({mode:t,cursor:n,width:o}){let r=t==="command"?"/ ":"\u25B8 ";return jsx(Box,{paddingX:2,children:jsx(jo,{cursor:n,width:Math.max(10,o-4),prefix:r})})}function ya(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 rr(t,n=200){if(typeof t=="string")return t.slice(0,n);if(!Array.isArray(t))return null;let o=[],r=0;for(let s of t){if(r>=n)break;if(s?.type==="text"&&typeof s.text=="string"){let f=s.text.split(`
17
- `).find(h=>h.trim().length>0)??"";o.push(f.slice(0,n-r)),r+=f.length;}else if(s?.type==="tool_use"){let f=ya(s.name??"tool",s.input),h=`\u2699 ${s.name??"tool"}(${f})`;o.push(h),r+=h.length;}else if(s?.type==="tool_result")o.push("\u2190 (result)"),r+=10;else if(s?.type==="thinking"&&typeof s.thinking=="string"){let f=s.thinking.slice(0,60).split(`
18
- `)[0]??"";o.push(`\u{1F4AD} ${f}`),r+=f.length+3;}}return o.length>0?o.join(" "):null}function ma(t){if(typeof t=="string"){let o=t.split(`
19
- `).length,r=t.split(`
20
- `).find(s=>s.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 s=o.is_error,f=typeof o.content=="string"?o.content:"",h=f.split(`
5
+ `):[],R=3;v&&(R+=2+t.attachments.length),T?(R+=1,R+=Math.min(L.length,Math.max(1,Math.ceil((n-10)*.3)))):S||(R+=2),S&&(R+=2),I&&(R+=1),M&&(R+=2);let C=Math.max(0,n-R),z=0,P=0;S&&M?(z=Math.max(1,Math.floor(C*.4)),P=Math.max(1,C-z)):S?z=C:M&&(P=C);let B=T?L.slice(0,Math.max(1,Math.ceil((n-10)*.3))):[],H=_.slice(0,z);return jsxs(Box,{flexDirection:"column",paddingX:2,children:[jsxs(Box,{children:[jsxs(Box,{width:m,children:[jsx(Text,{color:e.dim,children:" status "}),jsx(Text,{color:h,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?s?.get(t.assignee)??t.assignee:"\u2014"})]})]}),jsxs(Box,{children:[jsxs(Box,{width:m,children:[jsx(Text,{color:e.dim,children:" priority "}),jsxs(Text,{color:y,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:m,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(G=>f?.get(G)??G).join(", "):"\u2014"})]})]}),v&&jsxs(Fragment,{children:[jsx(Text,{children:" "}),jsx(Fn,{label:`attachments (${t.attachments.length})`,width:o,color:e.dim}),t.attachments.map((G,W)=>jsxs(Text,{color:e.cyan,wrap:"truncate",children:[" ",G]},`a${W}`))]}),T&&jsxs(Fragment,{children:[jsx(Text,{children:" "}),B.map((G,W)=>jsxs(Text,{color:e.silver,wrap:"truncate",children:[" ",it(G,o-8)]},`d${W}`))]}),!T&&!S&&jsxs(Fragment,{children:[jsx(Text,{children:" "}),jsx(Text,{color:e.dim,children:" No description."})]}),S&&jsxs(Fragment,{children:[jsx(Text,{children:" "}),jsx(Fn,{label:"result",width:o,color:e.dim}),H.map((G,W)=>jsxs(Text,{color:e.white,wrap:"truncate",children:[" ",it(G,o-8)]},`r${W}`))]}),I&&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})]})]}),M&&jsxs(Fragment,{children:[jsx(Text,{children:" "}),jsx(Fn,{label:"activity",width:o,color:e.dim}),r.slice(-P).map((G,W)=>{let w=G.msgType??"info",U=ql[w]??"\u2502",ie=G.color;w==="tool"?ie=e.cyan:w==="file"?ie=e.purple:w==="error"?ie=e.red:w==="lifecycle"?ie=e.green:w==="system"&&(ie=e.dim);let oe=Math.max(10,o-12),we=it(G.text,oe);return jsxs(Box,{children:[jsxs(Text,{color:e.ghost,children:[" ",G.time," "]}),jsxs(Text,{color:w==="error"?e.red:e.dim,children:[U," "]}),jsx(Text,{color:ie,bold:w==="lifecycle",children:we})]},W)})]})]})}var Do=[{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 ei="\u25CF",ti="\u25CB",Kl="\u2713",Yl="\u2715",Zl="\u2191",Jl="\u2193",Ql="\u03A3",ec="\u25B6",tc="\u21BB",nc="\u{1F9E0}",Pr=[" ","\u2581","\u2582","\u2583","\u2584","\u2585","\u2586","\u2587","\u2588"],et={green:"#0f2d1f",blue:"#0f1f2d",yellow:"#2d2a0f",red:"#2d0f0f",neutral:"#1a1a22",amber:"#2d1f0a"};function oc({active:t}){let n=Ln(t),o=!t||Math.floor(n/10)%2===0;return jsx(Text,{color:o?e.amber:e.amberDim,bold:true,children:jt})}function rc({width:t,active:n}){let o=Math.max(4,Math.floor(t*.08)),r=2,s=Ln(n),f=Math.ceil((t+o)/r),h=n?s%(f*2):0;if(!n)return jsx(Box,{paddingX:1,children:jsx(Text,{color:e.ghost,children:He(t)})});let y=h<f?h*r:(f*2-h)*r,m=Math.max(0,y-o),T=Math.min(t,y),S=m,I=Math.max(0,T-m),M=Math.max(0,t-T);return jsxs(Box,{paddingX:1,children:[jsx(Text,{color:e.ghost,children:He(S)}),jsx(Text,{color:e.amber,children:He(I)}),jsx(Text,{color:e.ghost,children:He(M)})]})}function sc({data:t,width:n,color:o}){if(t.length===0)return null;let r=t.slice(-n),s=Math.max(...r,1),f=r.map(h=>{let y=Math.round(h/s*(Pr.length-1));return Pr[y]??Pr[0]}).join("");return jsx(Text,{color:o,children:f})}function ic({tab:t,flashColor:n,onComplete:o,badge:r}){let s=Ln(),f=uo.useRef(s),h=uo.useRef(false),y=s-f.current,m=2,T=6*m;return uo.useEffect(()=>{y>=T&&!h.current&&(h.current=true,o());},[y,o]),Math.floor(y/m)%2===0&&y<T?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 ac({projectName:t,activeView:n,mode:o,stats:r,uptime:s,width:f,version:h,latestVersion:y,updateInstalled:m,taskBadge:T,flashTab:S,flashColor:I,onFlashComplete:M}){return jsxs(Box,{paddingX:1,justifyContent:"space-between",width:f,children:[jsxs(Box,{gap:0,children:[jsx(oc,{active:r.running>0}),jsx(Text,{color:e.amber,bold:true,children:" ORCH"}),h&&jsxs(Text,{color:e.ghost,children:[" ",h]}),y&&y!==h&&(m?jsxs(Text,{backgroundColor:et.green,color:e.green,bold:true,children:[" v",y," INSTALLED \u2014 RESTART TO APPLY "]}):jsxs(Text,{backgroundColor:et.green,color:e.green,bold:true,children:[" UPDATE ",y," "]})),jsxs(Text,{color:e.ghost,children:[" ",fe," "]}),jsx(Text,{color:e.silver,children:t})]}),jsx(Box,{gap:0,children:Do.map((v,L)=>{let _=n===v.id,R=v.id==="tasks"&&T!=null&&T>0?` (${T})`:"",C=!_&&S===v.id&&I&&M;return jsxs(uo.Fragment,{children:[L>0&&jsx(Text,{children:" "}),_?jsxs(Text,{backgroundColor:e.amber,color:"#0a0a0c",bold:true,children:[" ",v.key," ",v.label,R," "]}):C?jsx(ic,{tab:v,flashColor:I,onComplete:M,badge:R}):jsxs(Box,{gap:0,children:[jsx(Text,{color:e.ghost,children:v.key}),jsxs(Text,{color:e.dim,children:[" ",v.label.toLowerCase(),R]})]})]},v.id)})}),jsxs(Box,{gap:0,children:[o==="watching"?jsxs(Text,{backgroundColor:et.green,color:e.green,bold:true,children:[" ",ei," WATCHING"," "]}):o==="observing"?jsxs(Text,{backgroundColor:et.amber,color:e.amber,bold:true,children:[" ",ei," OBSERVING"," "]}):jsxs(Text,{backgroundColor:et.neutral,color:e.dim,children:[" ",ti," IDLE"," "]}),r.running>0&&jsxs(Fragment,{children:[jsx(Text,{children:" "}),jsxs(Text,{backgroundColor:et.green,color:e.green,children:[" ",jsx(Ht,{color:e.green})," ",r.running," active"," "]})]}),s&&jsxs(Text,{color:e.ghost,children:[" ",s]})]})]})}function lc({stats:t,tokens:n,width:o,sparklineData:r}){let f=[{icon:ec,label:"RUN",count:t.running,fg:e.green,bg:et.green,bold:true,spinner:true,show:t.running>0},{icon:tc,label:"RETRY",count:t.retrying,fg:e.yellow,bg:et.yellow,show:t.retrying>0},{icon:Zt,label:"REVIEW",count:t.review,fg:e.blue,bg:et.blue,show:t.review>0},{icon:ti,label:"TODO",count:t.todo,fg:e.dim,bg:et.neutral,show:t.todo>0},{icon:Kl,label:"DONE",count:t.done,fg:e.green,bg:et.green,show:t.done>0},{icon:Yl,label:"FAIL",count:t.failed,fg:e.red,bg:et.red,bold:true,show:t.failed>0},{icon:jt,label:"TEAMS",count:t.teams,fg:e.amber,bg:et.amber,show:t.teams>0}].filter(m=>m.show),h$1=n.total>0,y=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:[f.map(m=>jsx(Text,{backgroundColor:m.bg,color:m.fg,bold:m.bold,children:m.spinner?jsxs(Fragment,{children:[" ",jsx(Ht,{color:m.fg})," ",m.count," ",m.label," "]}):jsxs(Fragment,{children:[" ",m.icon," ",m.count," ",m.label," "]})},m.label)),f.length===0&&jsxs(Text,{backgroundColor:et.neutral,color:e.dim,children:[" ","NO TASKS"," "]})]}),jsxs(Box,{gap:0,children:[y>0&&r&&jsxs(Fragment,{children:[jsx(sc,{data:r,width:y,color:e.amberDim}),jsx(Text,{children:" "})]}),h$1&&jsxs(Text,{backgroundColor:et.amber,color:e.cyan,children:[" ",Zl,h(n.input)," ",Jl,h(n.output),n.reasoning>0?` ${nc}${h(n.reasoning)}`:""," ",fe," ",Ql,h(n.total)," "]})]})]})}var ni=uo.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(ac,{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(lc,{stats:n.stats,tokens:n.tokens,width:n.width,sparklineData:n.sparklineData}),jsx(rc,{width:o,active:r})]})});var go="\u0423\u041F\u0420\u0410\u0412\u041B\u0415\u041D\u0418\u0415",Wn="\u041C\u041E\u041D\u0418\u0422\u041E\u0420\u0418\u041D\u0413",Wo="\u041D\u0410\u0421\u0422\u0420\u041E\u0419\u041A\u0418",bn={task:{sub:["add","list","show","cancel","retry","assign","approve","reject","delete"],help:"Manage tasks",category:go},agent:{sub:["add","list","disable","enable","delete","autonomous","shop"],help:"Manage agents",category:go},team:{sub:["create","list","join","leave","disband","set-lead"],help:"Manage teams",category:go},goal:{sub:["add","list","show","status","delete"],help:"Manage goals",category:go},run:{args:"[id]",help:"Run task (or selected)",category:Wn},"run-all":{help:"Run all todo tasks",category:Wn},watch:{help:"Start watch mode (auto-dispatch)",category:Wn},pause:{help:"Pause watch mode",category:Wn},status:{help:"Show orchestrator status",category:Wn},config:{sub:["activity-filter","max-concurrent"],help:"TUI settings",category:Wo},help:{help:"List all commands",category:Wo},quit:{help:"Exit the TUI",category:Wo}};function Nr(t){if(!t.startsWith("/"))return null;let n=t.slice(1),o=n.indexOf(" ");if(o===-1){let y=n;if(!y)return null;let m=Object.keys(bn).find(T=>T.startsWith(y)&&T!==y);return m?m.slice(y.length):null}let r=n.slice(0,o),s=bn[r];if(!s?.sub)return null;let f=n.slice(o+1);if(!f)return null;let h=s.sub.find(y=>y.startsWith(f)&&y!==f);return h?h.slice(f.length):null}function oi(t){if(!t.startsWith("/"))return [];let n=t.slice(1),o=n.indexOf(" ");if(o===-1){let y=n.toLowerCase(),m=[];if(!y){let T=[go,Wn,Wo];for(let S of T){m.push({cmd:"",desc:`\u2500\u2500 ${S} \u2500\u2500`});for(let[I,M]of Object.entries(bn))if(M.category===S){let v=M.args?` ${M.args}`:"";m.push({cmd:`/${I}${v}`,desc:M.help,subs:M.sub?.join(" \xB7 ")});}}return m}for(let[T,S]of Object.entries(bn))if(T.startsWith(y)){let I=S.args?` ${S.args}`:"";if(m.push({cmd:`/${T}${I}`,desc:S.help,subs:S.sub?.join(" \xB7 ")}),T===y&&S.sub)for(let M of S.sub)m.push({cmd:`/${T} ${M}`,desc:`${S.help}: ${M}`});}return m}let r=n.slice(0,o),s=bn[r];if(!s?.sub)return [];let f=n.slice(o+1).toLowerCase(),h=[];for(let y of s.sub)(!f||y.startsWith(f))&&h.push({cmd:`/${r} ${y}`,desc:`${s.help}: ${y}`});return h}var Go=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 dc="\u2588",ri=uo.memo(function({mode:n,value:o,completion:r,activeView:s,canRun:f,canNew:h,canApprove:y,canReject:m,canCancel:T,canDelete:S,canUndo:I,canEdit:M,canForceStop:v,canToggleAuto:L,autoActive:_,canPause:R,isPaused:C,canToggleShowAll:z,showAllActive:P,hasDetail:B,itemCount:H,itemLabel:G,width:W,hasSuggestions:w,onboardingCompleted:U}){if(n==="command"){let ie=w?" \u2191\u2193 select Tab fill Esc \u2715":" Enter exec \u2191\u2193 history Tab complete Esc \u2715",oe=Math.max(4,W-6-ie.length-(r?.length??0)-1),we=o.length>oe?"\u2026"+o.slice(-(oe-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:we}),r&&jsx(Text,{color:e.ghost,children:r}),jsx(Text,{color:e.amber,children:dc}),jsx(Text,{color:e.dim,children:ie})]})})}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",h&&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"]}),T&&jsxs(Fragment,{children:[" ",jsx(Text,{bold:true,color:e.amber,children:"C"})," cancel"]}),y&&jsxs(Fragment,{children:[" ",jsx(Text,{bold:true,color:e.green,children:"A"})," approve"]}),m&&jsxs(Fragment,{children:[" ",jsx(Text,{bold:true,color:e.red,children:"X"})," reject"]}),M&&jsxs(Fragment,{children:[" ",jsx(Text,{bold:true,color:e.cyan,children:"E"})," edit"]}),v&&jsxs(Fragment,{children:[" ",jsx(Text,{bold:true,color:e.red,children:"S"})," stop"]}),R&&jsxs(Fragment,{children:[" ",jsx(Text,{bold:true,color:e.amber,children:"P"}),C?" resume":" pause"]}),L&&jsxs(Fragment,{children:[" ",jsx(Text,{bold:true,color:e.cyan,children:"U"}),_?" auto off":" auto on"]}),z&&jsxs(Fragment,{children:[" ",jsx(Text,{bold:true,color:e.gray,children:"S"}),P?" collapse":" show all"]}),S&&!y&&jsxs(Fragment,{children:[" ",jsx(Text,{bold:true,color:e.gray,children:"D"})," delete"]}),I&&jsxs(Fragment,{children:[" ",jsx(Text,{bold:true,color:e.yellow,children:"Z"})," undo"]}),B&&jsxs(Fragment,{children:[" ",jsx(Text,{bold:true,color:e.gray,children:"Esc"})," close"]}),!B&&(s==="tasks"||s==="agents"||s==="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:U===false?e.amber:e.gray,children:"?"}),jsx(Text,{color:U===false?e.amber:void 0,children:" help"})]}),H>0&&jsxs(Text,{color:e.dim,children:[H," ",G]})]})});var ai=new Intl.Segmenter(void 0,{granularity:"grapheme"});function si(t){return [...ai.segment(t)].map(n=>n.segment)}function zo(t){let n=t.codePointAt(0)??0;return n>=11904&&n<=40959||n>=4352&&n<=4447||n>=43360&&n<=43391||n>=44032&&n<=55215||n>=63744&&n<=64255||n>=65040&&n<=65135||n>=65281&&n<=65376||n>=65504&&n<=65510||n>=131072&&n<=195103||n>=127744&&n<=129791?2:1}function li(t){let n=0;for(let o of ai.segment(t))n+=zo(o.segment);return n}function ii(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 uc(t,n){let o=t.length;if(n>=o)return o;let r=n;for(;r<o&&t[r]!==" ";)r++;for(;r<o&&t[r]===" ";)r++;return r}var Gn=class t{text;pos;_segs;constructor(n,o){this.text=n.normalize("NFC"),this._segs=si(this.text),this.pos=o!==void 0?Math.max(0,Math.min(o,this._segs.length)):this._segs.length;}static _withPos(n,o,r){let s=Object.create(t.prototype);return Object.defineProperty(s,"text",{value:n,writable:false}),Object.defineProperty(s,"_segs",{value:o,writable:false}),Object.defineProperty(s,"pos",{value:Math.max(0,Math.min(r,o.length)),writable:false}),s}get length(){return this._segs.length}get beforeSegs(){return this._segs.slice(0,this.pos)}get afterSegs(){return this._segs.slice(this.pos)}get before(){return this.beforeSegs.join("")}get after(){return this.afterSegs.join("")}get isEmpty(){return this.text.length===0}moveLeft(n=1){return t._withPos(this.text,this._segs,this.pos-n)}moveRight(n=1){return t._withPos(this.text,this._segs,this.pos+n)}moveToStart(){return t._withPos(this.text,this._segs,0)}moveToEnd(){return t._withPos(this.text,this._segs,this._segs.length)}moveToWordBack(){return t._withPos(this.text,this._segs,ii(this._segs,this.pos))}moveToWordForward(){return t._withPos(this.text,this._segs,uc(this._segs,this.pos))}insert(n){let o=n.normalize("NFC"),r=si(o),s=this._segs.slice(0,this.pos).join("")+o+this._segs.slice(this.pos).join("");return new t(s,this.pos+r.length)}deleteBack(){if(this.pos<=0)return this;let n=this._segs,o=n.slice(0,this.pos-1).join("")+n.slice(this.pos).join("");return new t(o,this.pos-1)}deleteForward(){let n=this._segs;if(this.pos>=n.length)return this;let o=n.slice(0,this.pos).join("")+n.slice(this.pos+1).join("");return new t(o,this.pos)}killToEnd(){let n=this._segs,o=n.slice(this.pos).join(""),r=n.slice(0,this.pos).join("");return [new t(r,this.pos),o]}killToStart(){let n=this._segs,o=n.slice(0,this.pos).join(""),r=n.slice(this.pos).join("");return [new t(r,0),o]}killWordBack(){let n=this._segs,o=ii(n,this.pos),r=n.slice(o,this.pos).join(""),s=n.slice(0,o).join("")+n.slice(this.pos).join("");return [new t(s,o),r]}replaceAll(n){return new t(n)}clear(){return new t("")}};var fc=500;function jo(t={}){let n=t.maxUndoDepth??50,[o,r]=useState(()=>new Gn(t.initialValue??"")),s=useRef([]),f=useRef(null),h=useRef(""),y=useRef(o);y.current=o;let m=useCallback(L=>{y.current=L,r(L);},[]),T=useCallback(()=>{f.current&&(clearTimeout(f.current),f.current=null);let L=s.current,_=y.current;L.length>0&&L[L.length-1].text===_.text||(L.push(_),L.length>n&&L.shift());},[n]),S=useCallback(()=>{f.current&&clearTimeout(f.current),f.current=setTimeout(()=>{f.current=null,T();},fc);},[T]);useEffect(()=>()=>{f.current&&clearTimeout(f.current);},[]);let I=useCallback((L,_)=>{if(!L&&!_.backspace&&!_.delete&&!_.leftArrow&&!_.rightArrow&&!_.home&&!_.end)return false;let R=y.current;if(_.ctrl)switch(L){case "a":return m(R.moveToStart()),true;case "e":return m(R.moveToEnd()),true;case "k":{T();let[C,z]=R.killToEnd();return h.current=z,m(C),true}case "u":{T();let[C,z]=R.killToStart();return h.current=z,m(C),true}case "w":{T();let[C,z]=R.killWordBack();return h.current=z,m(C),true}case "y":return h.current&&(T(),m(R.insert(h.current))),true;case "z":{let C=s.current;return C.length>0&&C[C.length-1].text===R.text&&C.pop(),C.length>0&&m(C.pop()),true}case "b":return m(R.moveLeft()),true;case "f":return m(R.moveRight()),true;case "d":return R.isEmpty||(S(),m(R.deleteForward())),true;case "h":return R.pos>0&&(S(),m(R.deleteBack())),true;default:return false}if(_.meta){if(L==="z"){let C=s.current;for(;C.length>0&&C[C.length-1].text===R.text;)C.pop();return C.length>0&&m(C.pop()),true}if(L==="a")return m(R.moveToStart()),true;if(_.backspace||_.delete){T();let[C,z]=R.killToStart();return h.current=z,m(C),true}return _.leftArrow||L==="b"?(m(R.moveToWordBack()),true):_.rightArrow||L==="f"?(m(R.moveToWordForward()),true):false}return _.home?(m(R.moveToStart()),true):_.end?(m(R.moveToEnd()),true):_.leftArrow?(m(R.moveLeft()),true):_.rightArrow?(m(R.moveRight()),true):_.backspace||_.delete?(R.pos>0&&(S(),m(R.deleteBack())),true):L&&!_.escape?(S(),m(R.insert(L)),true):false},[m,T,S]),M=useCallback(L=>{let _=new Gn(L??"");m(_),s.current=[],f.current&&(clearTimeout(f.current),f.current=null);},[m]),v=useCallback(L=>{m(new Gn(L)),s.current=[];},[m]);return {cursor:o,value:o.text,handleInput:I,reset:M,setValue:v,setCursor:m}}var di="\u2588";function pc(t,n,o){let r=0,s=t.length;for(;s>0;){let S=t[s-1],I=zo(S);if(r+I>o-1)break;r+=I,s--;}let f=t.slice(s).join(""),h=Math.max(0,o-r-1),y=0,m=0;for(;m<n.length;){let S=n[m],I=zo(S);if(y+I>h)break;y+=I,m++;}let T=n.slice(0,m).join("");return {visibleBefore:f,visibleAfter:T}}function Ho({cursor:t,width:n,prefix:o,prefixColor:r=e.amber,placeholder:s,ghost:f,ghostColor:h=e.ghost,showCursor:y=true,cursorColor:m=e.amber,textColor:T=e.white,placeholderColor:S=e.ghost,hasError:I=false}){let M=o??"",v=li(M),L=Math.max(4,n-v),_=t.isEmpty,{visibleBefore:R,visibleAfter:C}=pc(t.beforeSegs,t.afterSegs,L),z=I?"round":void 0,P=I?e.red:void 0;return _?jsxs(Box,{borderStyle:z,borderColor:P,children:[M&&jsx(Text,{color:r,children:M}),s&&jsx(Text,{color:S,children:s}),y&&jsx(Text,{color:m,children:di})]}):jsxs(Box,{borderStyle:z,borderColor:P,children:[M&&jsx(Text,{color:r,children:M}),jsx(Text,{color:T,children:R}),y&&jsx(Text,{color:m,children:di}),jsx(Text,{color:T,children:C}),f&&jsx(Text,{color:h,children:f})]})}var bc="\u2588",Fr=process.platform==="darwin"?"\u2318":"Ctrl";function Tc(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 fi(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 yc(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 pi({title:t,steps:n,onComplete:o,onCancel:r,width:s,height:f,onPasteImage:h,footerExtra:y,onSuggestionSelected:m}){let [T,S]=useState(0),[I,M]=useState({}),v=jo({initialValue:(()=>{let D=n.find(O=>!O.skip?.({}));return D?.type==="text"&&D.defaultValue?D.defaultValue:""})()}),L=v.value,[_,R]=useState(()=>{let D=n.find(O=>!O.skip?.({}));return D?.type==="textarea"&&D.defaultValue?D.defaultValue.split(`
6
+ `):[""]}),[C,z]=useState(0),[P,B]=useState(0),[H,G]=useState(()=>{let D=n.find(O=>!O.skip?.({}));if(D?.type==="select"&&D.defaultValue){let N=(D.getOptions?.({})??D.options??[]).findIndex($=>$.value===D.defaultValue);return N>=0?N:0}return 0}),W=useMemo(()=>n.filter(D=>!D.skip?.(I)),[n,I]),w=W[T],U=W.length,{taLineNumWidth:oe,taContentWidth:we}=useMemo(()=>{let D=String(_.length).length;return {taLineNumWidth:D,taContentWidth:Math.max(1,s-D-4)}},[_.length,s]),We=useMemo(()=>{if(!w||w.type!=="textarea")return [];let D=[];for(let O=0;O<_.length;O++){let N=Tc(_[O]??"",we);for(let $=0;$<N.length;$++)D.push({logicalRow:O,startCol:$*we,text:N[$],isFirst:$===0});}return D},[w?.id,w?.type,_,we]),Ge=useMemo(()=>{for(let D=0;D<We.length;D++){let O=We[D];if(O.logicalRow===C&&(P>=O.startCol&&P<O.startCol+we||P>=O.startCol&&(D+1>=We.length||We[D+1].logicalRow!==C)))return D}return 0},[We,C,P,we]),[ut,Ct]=useState(new Set),[gt,mt]=useState(false),[Ye,Ze]=useState(0),[ft,Ce]=useState(false),[Wt,It]=useState(null),[ht,Je]=useState(false),ot=useRef(null),Xe=useRef(null),po=useMemo(()=>w?w.type==="text"?L:w.type==="textarea"?_.join(`
7
+ `):"":"",[w,L,_]),rn=useCallback((D,O)=>{if(ot.current&&clearTimeout(ot.current),!O){It(null);return}ot.current=setTimeout(()=>{It(O(D));},300);},[]);useEffect(()=>(w&&w.validate&&(w.type==="text"||w.type==="textarea")&&rn(po,w.validate),()=>{ot.current&&clearTimeout(ot.current);}),[po,w,rn]),useEffect(()=>()=>{Xe.current&&clearTimeout(Xe.current);},[]);let $t=useMemo(()=>!w||w.type!=="select"&&w.type!=="multiselect"?[]:w.getOptions?.(I)??w.options??[],[w,I]),Gt=Math.min(H,Math.max(0,$t.length-1)),zt=useMemo(()=>{if(!w?.suggestions)return [];if(!L.trim())return w.suggestions;let D=L.toLowerCase();return w.suggestions.filter(O=>O.label.toLowerCase().includes(D)||(O.hint??"").toLowerCase().includes(D))},[w?.suggestions,L]),qt=Math.min(Ye,Math.max(0,zt.length-1)),sn=D=>{let O={...I,[w.id]:D};M(O),v.reset(""),R([""]),z(0),B(0),G(0),Ct(new Set),mt(false),Ze(0),Ce(false),It(null),Je(false),ot.current&&clearTimeout(ot.current);let N=w.id,q=n.findIndex(ne=>ne.id===N)+1;for(;q<n.length;){let ne=n[q];if(ne&&!ne.skip?.(O))break;q++;}if(q>=n.length)o(O);else {let ne=n[q].id,ae=n.filter(ce=>!ce.skip?.(O)).findIndex(ce=>ce.id===ne);S(ae>=0?ae:0);let ue=n[q];if(ue.type==="text")v.reset(ue.defaultValue??"");else if(ue.type==="textarea"){let ce=ue.defaultValue?ue.defaultValue.split(`
8
+ `):[""];R(ce),z(ce.length-1),B(ce[ce.length-1].length);}else if(ue.type==="select"){let ce=ue.getOptions?.(O)??ue.options??[];if(ue.defaultValue){let Kt=ce.findIndex(de=>de.value===ue.defaultValue);G(Kt>=0?Kt:0);}else G(0);}else ue.type==="multiselect"&&(G(0),ue.defaultValue?Ct(new Set(ue.defaultValue.split(","))):Ct(new Set));}},an=()=>{if(T===0){r();return}let D=w.id,N=n.findIndex(ae=>ae.id===D)-1;for(;N>=0;){let ae=n[N];if(ae&&!ae.skip?.(I))break;N--;}if(N<0){r();return}let $=n[N].id,q=W.findIndex(ae=>ae.id===$);S(q>=0?q:0),mt(false),Ze(0),Ce(false),It(null),Je(false),ot.current&&clearTimeout(ot.current);let ne=n[N];if(I[ne.id]&&Ce(true),ne.type==="text")v.reset(I[ne.id]??ne.defaultValue??"");else if(ne.type==="textarea"){let ae=I[ne.id]??ne.defaultValue??"",ue=ae?ae.split(`
9
+ `):[""];R(ue),z(ue.length-1),B(ue[ue.length-1].length);}else if(ne.type==="multiselect"){G(0);let ae=I[ne.id];Ct(ae?new Set(ae.split(",")):new Set);}else {let ae=ne.getOptions?.(I)??ne.options??[],ue=I[ne.id],ce=ae.findIndex(Kt=>Kt.value===ue);G(ce>=0?ce:0);}};if(useInput((D,O)=>{if(w){if(O.escape){T===0?r():an();return}if((O.ctrl||O.meta)&&(D==="v"||D==="i")&&h&&(w.type==="text"||w.type==="textarea")){h();return}if(w.type==="text"){if(gt&&zt.length>0){if(O.upArrow){qt<=0?mt(false):Ze($=>$-1);return}if(O.downArrow){Ze($=>Math.min(zt.length-1,$+1));return}if(O.return){let $=zt[qt];$&&m&&m($.value);return}mt(false);}if(O.return){let $=L.trim();if(w.required&&!$){Ce(true);return}if(Wt!==null){Ce(true),Je(true),Xe.current&&clearTimeout(Xe.current),Xe.current=setTimeout(()=>Je(false),2e3);return}sn($);return}if(O.downArrow&&w.suggestions&&zt.length>0){mt(true),Ze(0);return}if((O.backspace||O.delete)&&v.cursor.isEmpty&&T>0){an();return}v.handleInput(D,O)&&(Ce(true),mt(false),Ze(0));return}if(w.type==="textarea"){if(O.return&&(O.ctrl||O.meta)){let N=_.join(`
10
+ `).trim();if(w.required&&!N){Ce(true);return}if(Wt!==null){Ce(true),Je(true),Xe.current&&clearTimeout(Xe.current),Xe.current=setTimeout(()=>Je(false),2e3);return}sn(N);return}if(O.return){Ce(true),R(N=>{let $=N[C]??"",q=$.slice(0,P),ne=$.slice(P),_e=[...N];return _e.splice(C,1,q,ne),_e}),z(N=>N+1),B(0);return}if(O.ctrl&&D==="a"){B(0);return}if(O.ctrl&&D==="e"){B((_[C]??"").length);return}if(O.ctrl&&D==="k"){Ce(true),R(N=>{let $=[...N];return $[C]=($[C]??"").slice(0,P),$});return}if(O.ctrl&&D==="u"){Ce(true),R(N=>{let $=[...N];return $[C]=($[C]??"").slice(P),$}),B(0);return}if(O.ctrl&&D==="w"){Ce(true);let N=C,$=P,q=_[N]??"",ne=fi(q,$);R(_e=>{let ae=[..._e];return ae[N]=q.slice(0,ne)+q.slice($),ae}),B(ne);return}if(O.meta&&(O.leftArrow||D==="b")){B(fi(_[C]??"",P));return}if(O.meta&&(O.rightArrow||D==="f")){B(yc(_[C]??"",P));return}if(O.upArrow){if(Ge>0){let N=We[Ge],$=We[Ge-1],q=P-(N?.startCol??0),ne=Math.min($.startCol+q,$.startCol+$.text.length);z($.logicalRow),B(ne);}return}if(O.downArrow){if(Ge<We.length-1){let N=We[Ge],$=We[Ge+1],q=P-(N?.startCol??0),ne=Math.min($.startCol+q,$.startCol+$.text.length);z($.logicalRow),B(ne);}return}if(O.leftArrow){P>0?B(N=>N-1):C>0&&(z(N=>N-1),B((_[C-1]??"").length));return}if(O.rightArrow){let N=(_[C]??"").length;P<N?B($=>$+1):C<_.length-1&&(z($=>$+1),B(0));return}if(O.backspace||O.delete){if(P===0&&C===0)return;if(P>0)R(N=>{let $=[...N],q=$[C]??"";return $[C]=q.slice(0,P-1)+q.slice(P),$}),B(N=>N-1);else {let N=(_[C-1]??"").length;R($=>{let q=[...$],ne=q[C-1]??"",_e=q[C]??"";return q.splice(C-1,2,ne+_e),q}),B(N),z($=>$-1);}return}if(D&&!O.ctrl&&!O.meta&&!O.escape){Ce(true);let N=D.split(/\r?\n/);if(N.length===1)R($=>{let q=[...$],ne=q[C]??"";return q[C]=ne.slice(0,P)+D+ne.slice(P),q}),B($=>$+D.length);else {let $=C,q=P;R(ne=>{let _e=[...ne],ae=_e[$]??"",ue=ae.slice(0,q),ce=ae.slice(q),Kt=N[0]??"",de=N[N.length-1]??"",dr=[ue+Kt,...N.slice(1,-1),de+ce];return _e.splice($,1,...dr),_e}),z($+N.length-1),B((N[N.length-1]??"").length);}}return}if(w.type==="select"||w.type==="multiselect"){if(O.upArrow||D==="k"){G(N=>Math.max(0,N-1));return}if(O.downArrow||D==="j"){G(N=>Math.min($t.length-1,N+1));return}if(O.backspace||O.delete){an();return}if(w.type==="select"){if(O.return||O.tab){let N=$t[Gt];if(N){if(w.validate){let $=w.validate(N.value);if($!==null){Ce(true),It($),Je(true),Xe.current&&clearTimeout(Xe.current),Xe.current=setTimeout(()=>Je(false),2e3);return}}sn(N.value);}return}if(D>="1"&&D<="9"){let N=parseInt(D,10)-1;if(N<$t.length){let $=$t[N];$&&sn($.value);}return}}else {if(D===" "){let N=$t[Gt];N&&Ct($=>{let q=new Set($);return q.has(N.value)?q.delete(N.value):q.add(N.value),q});return}if(O.return){let N=Array.from(ut).join(",");sn(N);return}}}}}),!w)return null;let vt=ft?Wt:null,wn=Math.max(20,s-6),Un=`${T+1}/${U}`,ln=Math.max(2,f-4),rt=0;Gt>=ln&&(rt=Gt-ln+1);let cn=$t.slice(rt,rt+ln);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:[" ",je,je," "]}),jsxs(Text,{color:e.dim,children:["step ",Un]})]}),jsxs(Box,{children:[jsx(Text,{children:" "}),W.map((D,O)=>jsxs(Text,{color:O===T?e.amber:O<T?e.green:e.ghost,children:[O===T?"\u25CF":O<T?"\u2713":"\u25CB"," "]},D.id))]}),jsxs(Box,{marginTop:0,children:[jsxs(Text,{color:e.white,bold:true,children:[" ",w.label]}),w.required&&jsx(Text,{color:e.red,children:" *"}),!w.required&&jsxs(Text,{color:e.dim,children:[" (optional, ",w.type==="textarea"?`${Fr}+Enter`:"Enter"," to skip)"]})]}),w.description&&jsx(Box,{children:jsxs(Text,{color:e.dim,children:[" ",w.description]})}),w.type==="text"&&jsxs(Box,{flexDirection:"column",paddingLeft:2,children:[jsx(Ho,{cursor:v.cursor,width:wn-4,prefix:"> ",placeholder:w.placeholder,hasError:!!vt}),vt&&jsxs(Text,{color:e.red,dimColor:true,children:[" ",vt]}),ht&&jsx(Text,{color:e.red,children:" Fix the error above"})]}),w.type==="text"&&w.suggestions&&zt.length>0&&(()=>{let D=Math.max(2,f-6),O=0;gt&&qt>=D&&(O=qt-D+1);let N=zt.slice(O,O+D);return jsxs(Box,{flexDirection:"column",children:[jsxs(Text,{color:e.ghost,children:[" ",je,je,je," or browse templates ",je.repeat(Math.max(0,wn-28))]}),N.map(($,q)=>{let ne=q+O,_e=gt&&ne===qt;return jsxs(Box,{children:[jsx(Text,{color:_e?e.amber:e.ghost,children:_e?" \u25B8 ":" "}),jsx(Text,{color:_e?e.white:e.silver,bold:_e,children:$.label}),$.hint&&jsxs(Text,{color:e.dim,wrap:"truncate",children:[" ",je," ",$.hint.replace(/\n/g," ")]})]},$.value)})]})})(),w.type==="textarea"&&(()=>{let D=Math.max(3,f-6),O=0;Ge>=D&&(O=Ge-D+1);let N=We.slice(O,O+D);return jsxs(Box,{flexDirection:"column",children:[jsxs(Box,{flexDirection:"column",borderStyle:vt?"round":void 0,borderColor:vt?e.red:void 0,children:[N.map(($,q)=>{let ne=q+O,_e=$.isFirst?String($.logicalRow+1).padStart(oe," "):"".padStart(oe," "),ae=ne===Ge,ue=P-$.startCol;return jsxs(Box,{children:[jsxs(Text,{color:e.dim,children:[" ",_e," "]}),jsxs(Text,{color:e.ghost,children:["\u2502"," "]}),ae?jsxs(Fragment,{children:[jsx(Text,{color:e.white,children:$.text.slice(0,ue)}),jsx(Text,{color:e.amber,children:bc}),jsx(Text,{color:e.white,children:$.text.slice(ue)})]}):jsx(Text,{color:e.silver,children:$.text||($.isFirst?" ":"")})]},`${$.logicalRow}-${$.startCol}`)}),_.length===1&&_[0]===""&&w.placeholder&&jsx(Box,{children:jsxs(Text,{color:e.dim,children:[" ","".padStart(oe," ")," ",w.placeholder]})})]}),vt&&jsxs(Text,{color:e.red,dimColor:true,children:[" ",vt]}),ht&&jsx(Text,{color:e.red,children:" Fix the error above"})]})})(),w.type==="select"&&jsxs(Box,{flexDirection:"column",children:[cn.map((D,O)=>{let N=O+rt,$=N===Gt,q=String(N+1).padStart($t.length>=10?2:1);return jsxs(Box,{children:[jsx(Text,{color:$?e.amber:e.ghost,children:$?" \u25B8 ":` ${q} `}),jsx(Text,{color:$?e.white:e.silver,bold:$,children:D.label}),D.hint&&jsxs(Text,{color:e.dim,wrap:"truncate",children:[" ",je," ",D.hint.replace(/\n/g," ")]})]},D.value)}),vt&&jsxs(Text,{color:e.red,dimColor:true,children:[" ",vt]}),ht&&jsx(Text,{color:e.red,children:" Fix the error above"})]}),w.type==="multiselect"&&jsxs(Box,{flexDirection:"column",children:[cn.map((D,O)=>{let $=O+rt===Gt,q=ut.has(D.value);return jsxs(Box,{children:[jsx(Text,{color:$?e.amber:e.ghost,children:$?" \u25B8 ":" "}),jsx(Text,{color:q?e.green:e.dim,children:q?"[\u2713]":"[ ]"}),jsxs(Text,{color:$?e.white:e.silver,bold:$,children:[" ",D.label]}),D.hint&&jsxs(Text,{color:e.dim,wrap:"truncate",children:[" ",je," ",D.hint.replace(/\n/g," ")]})]},D.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:[" ",w.type==="select"?"\u2191\u2193 select Enter confirm":w.type==="multiselect"?"\u2191\u2193 move Space toggle Enter confirm":w.type==="textarea"?`Enter newline ${Fr}+Enter confirm \u2190\u2191\u2192\u2193 navigate`:gt?"\u2191\u2193 browse Enter select \u2191 back to input":w.suggestions?"\u2190\u2192 move Enter confirm \u2193 browse templates":"\u2190\u2192 move Enter confirm",h&&(w.type==="text"||w.type==="textarea")?` ${Fr}+V paste image`:""," Esc ",T>0?"back":"cancel"]}),y&&jsxs(Text,{color:e.amber,children:[" ",y]})]})]})}var bi=uo.memo(function({agents:n,selected:o,msgCounts:r,colorMap:s,maxHeight:f,onConfirm:h,onCancel:y}){let [m,T]=useState(0),[S,I]=useState(()=>new Set(o));useMemo(()=>S.size===0||S.size===n.length,[S.size,n.length]);let v=Math.max(3,f-5),L=useMemo(()=>{if(n.length<=v)return 0;let C=Math.floor(v/2),z=n.length-v;return Math.min(z,Math.max(0,m-C))},[m,n.length,v]),_=n.slice(L,L+v);useInput((C,z)=>{if(z.upArrow){T(P=>P>0?P-1:n.length-1);return}if(z.downArrow){T(P=>P<n.length-1?P+1:0);return}if(C===" "){let P=n[m];if(!P)return;I(B=>{let H=new Set(B);return H.has(P.id)?H.delete(P.id):H.add(P.id),H});return}if(C==="a"||C==="A"){I(P=>new Set);return}if(z.return){h(new Set(S));return}if(z.escape){y();return}});let R=S.size===0?n.length:S.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," ",R,"/",n.length," selected"]})]}),jsx(Text,{color:e.ghost,children:je.repeat(36)}),_.map((C,z)=>{let B=z+L===m,H=S.size===0||S.has(C.id),G=s.get(C.id)??e.silver,W=r.get(C.id)??0;return jsxs(Box,{gap:0,children:[jsx(Text,{color:B?e.amber:e.ghost,children:B?" \u25B8 ":" "}),jsx(Text,{color:H?e.green:e.ghost,children:H?"[\u2713]":"[ ]"}),jsxs(Text,{color:B?G:H?e.silver:e.dim,bold:B,children:[" ",C.name]}),W>0&&jsxs(Text,{color:e.dim,children:[" ",fe,W]})]},C.id)}),n.length>v&&jsxs(Text,{color:e.ghost,children:[" ",L>0?"\u2191":" "," ",L+v<n.length?"\u2193":" "," ",m+1,"/",n.length]}),jsx(Text,{color:e.ghost,children:je.repeat(36)}),jsxs(Text,{color:e.dim,children:[" Space toggle"," ",fe," ","a all"," ",fe," ","Enter confirm"," ",fe," ","Esc cancel"]})]})});var vc={system:"\u2666",lifecycle:"\u25B6",output:"\u2502",tool:"\u2699",result:"\u2190",error:"\u2715",file:"\u270E",info:"\u2502"},_c={system:"System",lifecycle:"Lifecycle",output:"Output",tool:"Tool calls",result:"Results",error:"Errors",file:"Files",info:"Info"},Mc={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"],wi=[{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"]}],Si=uo.memo(function({selected:n,typeCounts:o,onConfirm:r,onCancel:s}){let[f,h]=useState(0),[y,m]=useState(()=>new Set(n)),T=useMemo(()=>y.size===St.length||St.every(I=>y.has(I)),[y]);useInput((I,M)=>{if(M.upArrow){h(v=>v>0?v-1:St.length-1);return}if(M.downArrow){h(v=>v<St.length-1?v+1:0);return}if(I===" "){let v=St[f];if(!v)return;m(L=>{let _=new Set(L);return _.has(v)?_.delete(v):_.add(v),_});return}if(I==="a"||I==="A"){m(v=>v.size===St.length?new Set:new Set(St));return}for(let v of wi)if(I===v.key){m(new Set(v.types));return}if(M.return){let v=y.size===0?new Set(St):new Set(y);r(v);return}if(M.escape){s();return}});let S=T?St.length:y.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," ",S,"/",St.length," selected"]})]}),jsx(Text,{color:e.ghost,children:je.repeat(36)}),St.map((I,M)=>{let v=M===f,L=y.has(I),_=o[I]??0,R=Mc[I];return jsxs(Box,{gap:0,children:[jsx(Text,{color:v?e.amber:e.ghost,children:v?" \u25B8 ":" "}),jsx(Text,{color:L?e.green:e.ghost,children:L?"[\u2713]":"[ ]"}),jsxs(Text,{color:v?R:e.dim,children:[" ",vc[I]," "]}),jsx(Text,{color:v?R:L?e.silver:e.dim,bold:v,children:_c[I]}),_>0&&jsxs(Text,{color:e.dim,children:[" ",fe,_]})]},I)}),jsx(Text,{color:e.ghost,children:je.repeat(36)}),jsxs(Box,{gap:0,children:[jsx(Text,{color:e.dim,children:" "}),wi.map((I,M)=>jsxs(uo.Fragment,{children:[M>0&&jsxs(Text,{color:e.ghost,children:[" ",fe," "]}),jsx(Text,{color:e.amberDim,children:I.key}),jsxs(Text,{color:e.dim,children:["=",I.label]})]},I.key))]}),jsxs(Text,{color:e.dim,children:[" Space toggle"," ",fe," ","a all"," ",fe," ","Enter confirm"," ",fe," ","Esc cancel"]})]})});var qo="\u256D",Ko="\u256E",Yo="\u2570",Zo="\u256F",Ie="\u2502";function on({children:t,cw:n}){return jsxs(Text,{children:[jsx(Text,{color:e.ghost,children:Ie}),jsxs(Text,{children:[" ",t.padEnd(n)," "]}),jsx(Text,{color:e.ghost,children:Ie})]})}function Xo({cw:t}){return jsx(on,{cw:t,children:""})}function ki({width:t,height:n}){let o=Math.min(t-4,50),r=o-6,s=Te(o-2);return jsxs(Box,{flexDirection:"column",paddingX:2,marginTop:1,children:[jsxs(Text,{color:e.ghost,children:[qo,s,Ko]}),jsx(on,{cw:r,children:""}),jsxs(Text,{children:[jsxs(Text,{color:e.ghost,children:[Ie," "]}),jsx(Text,{color:e.amber,children:jt}),jsx(Text,{color:e.white,bold:true,children:" Welcome to Orch"}),jsx(Text,{children:" ".repeat(Math.max(0,r-15-2))}),jsx(Text,{children:" "}),jsx(Text,{color:e.ghost,children:Ie})]}),jsx(on,{cw:r,children:""}),jsxs(Text,{children:[jsxs(Text,{color:e.ghost,children:[Ie," "]}),jsx(Text,{color:e.silver,children:"Press N to create your first task".padEnd(r)}),jsx(Text,{children:" "}),jsx(Text,{color:e.ghost,children:Ie})]}),jsx(on,{cw:r,children:""}),jsxs(Text,{children:[jsxs(Text,{color:e.ghost,children:[Ie," "]}),jsx(Text,{color:e.amber,children:"N"}),jsx(Text,{color:e.gray,children:" new task"}),jsx(Text,{children:" ".repeat(Math.max(0,r-1-1-8))}),jsx(Text,{children:" "}),jsx(Text,{color:e.ghost,children:Ie})]}),jsx(on,{cw:r,children:""}),jsxs(Text,{color:e.ghost,children:[Yo,s,Zo]})]})}function Ci({step:t,width:n}){let o=Math.min(n-4,50),r=o-6,s=Te(o-2),f,h=null;if(t==="task_created")f="Press R to run task",h={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:[qo,s,Ko]}),jsxs(Text,{children:[jsxs(Text,{color:e.ghost,children:[Ie," "]}),jsx(Text,{color:e.amber,children:jt}),jsxs(Text,{color:e.silver,children:[" ",f.padEnd(h?r-2-h.key.length-1-h.label.length-2:r-2)]}),h&&jsxs(Fragment,{children:[jsxs(Text,{color:e.amber,children:[" ",h.key]}),jsxs(Text,{color:e.gray,children:[" ",h.label]})]}),jsx(Text,{children:" "}),jsx(Text,{color:e.ghost,children:Ie})]}),jsxs(Text,{color:e.ghost,children:[Yo,s,Zo]})]})}function Ii({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:[qo,r,Ko]}),jsx(on,{cw:o,children:""}),jsxs(Text,{children:[jsxs(Text,{color:e.ghost,children:[Ie," "]}),jsx(Text,{color:e.green,bold:true,children:"First task completed!"}),jsx(Text,{children:" ".repeat(Math.max(0,o-21))}),jsx(Text,{children:" "}),jsx(Text,{color:e.ghost,children:Ie})]}),jsx(on,{cw:o,children:""}),jsxs(Text,{children:[jsxs(Text,{color:e.ghost,children:[Ie," "]}),jsx(Text,{color:e.silver,children:"Type / to see all commands".padEnd(o)}),jsx(Text,{children:" "}),jsx(Text,{color:e.ghost,children:Ie})]}),jsx(on,{cw:o,children:""}),jsxs(Text,{color:e.ghost,children:[Yo,r,Zo]})]})}function Jo({count:t,config:n,width:o}){if(t>=3)return null;let r=Math.min((o??44)-4,50),s=r-6,f=Te(r-2),h=jsxs(Text,{color:e.ghost,children:[qo,f,Ko]}),y=jsxs(Text,{color:e.ghost,children:[Yo,f,Zo]});if(t>0){let T=n.hints[0],S=T?` ${T.key} ${T.label}`:"";return jsxs(Box,{flexDirection:"column",paddingX:2,marginTop:1,children:[h,jsxs(Text,{children:[jsxs(Text,{color:e.ghost,children:[Ie," "]}),jsx(Text,{color:e.amber,children:jt}),jsxs(Text,{color:e.silver,children:[" ",n.nudge.padEnd(s-2-S.length)]}),T&&jsxs(Fragment,{children:[jsxs(Text,{color:e.amber,children:[" ",T.key]}),jsxs(Text,{color:e.gray,children:[" ",T.label]})]}),jsx(Text,{children:" "}),jsx(Text,{color:e.ghost,children:Ie})]}),y]})}let m=n.hints.reduce((T,S,I)=>T+S.key.length+1+S.label.length+(I>0?3:0),0);return jsxs(Box,{flexDirection:"column",paddingX:2,marginTop:1,children:[h,jsx(Xo,{cw:s}),jsxs(Text,{children:[jsxs(Text,{color:e.ghost,children:[Ie," "]}),jsx(Text,{color:e.amber,children:jt}),jsxs(Text,{color:e.white,bold:true,children:[" ",n.title]}),jsx(Text,{children:" ".repeat(Math.max(0,s-n.title.length-2))}),jsx(Text,{children:" "}),jsx(Text,{color:e.ghost,children:Ie})]}),jsx(Xo,{cw:s}),n.description.map((T,S)=>jsxs(Text,{children:[jsxs(Text,{color:e.ghost,children:[Ie," "]}),jsx(Text,{color:e.silver,children:T.padEnd(s)}),jsx(Text,{children:" "}),jsx(Text,{color:e.ghost,children:Ie})]},S)),jsx(Xo,{cw:s}),jsxs(Text,{children:[jsxs(Text,{color:e.ghost,children:[Ie," "]}),n.hints.map((T,S)=>jsxs(uo.Fragment,{children:[S>0&&jsx(Text,{color:e.ghost,children:" "}),jsx(Text,{color:e.amber,children:T.key}),jsxs(Text,{color:e.gray,children:[" ",T.label]})]},S)),jsx(Text,{children:" ".repeat(Math.max(0,s-m))}),jsx(Text,{children:" "}),jsx(Text,{color:e.ghost,children:Ie})]}),jsx(Xo,{cw:s}),y]})}var _i={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."},Mi={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."},Ri={title:"Agents",description:["AI workers that execute your tasks.","Each agent uses an adapter (claude,","codex, opencode, cursor, pi, shell)."],hints:[{key:"N",label:"new agent"},{key:"W",label:"start orchestrator"}],nudge:"Add more agents to increase parallelism."};var Ac=2,Bi=360,$c={done:4e3,failed:8e3,review:6e3},Bc={done:"\u2713",failed:"\u2715",review:Zt},Ec={done:e.green,failed:e.red,review:e.blue},Oc={done:e.successBg,failed:e.errorBg,review:e.infoBg};function Lc(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 Pc=uo.memo(function({toast:n,onDismiss:o}){let[r,s]=useState(true),[f,h]=useState(false);useEffect(()=>{let v=setTimeout(()=>s(false),Bi);return ()=>clearTimeout(v)},[]),useEffect(()=>{let v=$c[n.type],L=setTimeout(()=>h(true),v),_=setTimeout(()=>o(n.id),v+Bi);return ()=>{clearTimeout(L),clearTimeout(_);}},[n.id,n.type,o]);let y=r||f,m=Bc[n.type],T=Ec[n.type],S=Oc[n.type],I=Lc(n),M=n.title.length>40?n.title.slice(0,39)+"\u2026":n.title;return jsx(Box,{children:jsxs(Text,{backgroundColor:S,children:[jsxs(Text,{color:y?e.dim:T,children:[" ",m," "]}),jsx(Text,{color:y?e.dim:e.white,bold:!y,children:M}),jsxs(Text,{color:y?e.dim:e.silver,children:[" ",I," "]})]})})}),Li=uo.memo(function({toasts:n,onDismiss:o}){let r=n.slice(0,Ac);return r.length===0?null:jsx(Box,{flexDirection:"column",children:r.map(s=>jsx(Pc,{toast:s,onDismiss:o},s.id))})});var Fc="\u256D",Wc="\u256E",Gc="\u2570",zc="\u256F",dt="\u2502",zr=[{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"}],Vr=[{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"}],jr=[{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"}],Vn=10,Xt=22;function Hr(t){let n=Math.max(0,Math.floor((Xt-t.length-2)/2)),o=Math.max(0,Xt-n-t.length-2);return Te(n)+" "+t+" "+Te(o)}var Pi=uo.memo(function({width:n,height:o}){let r=Xt*3+3+3+2,s=r+2,f=Te(s-2),h="KEYBOARD SHORTCUTS",y=Math.max(0,Math.floor((r-h.length)/2)),m=Math.max(0,r-y-h.length),T="Press any key to dismiss",S=Math.max(0,Math.floor((r-T.length)/2)),I=Math.max(0,r-S-T.length),M=Math.max(zr.length,Vr.length,jr.length),v=M+10,L=Math.max(0,Math.floor((o-v)/2)),_=[];for(let B=0;B<M;B++){let H=B<zr.length?zr[B]:null,G=B<Vr.length?Vr[B]:null,W=B<jr.length?jr[B]:null;_.push(jsxs(Text,{children:[jsx(Text,{color:e.amber,children:dt}),jsx(Text,{children:" "}),H?jsxs(Fragment,{children:[jsx(Text,{color:e.amber,bold:true,children:H.key.padEnd(Vn)}),jsx(Text,{color:e.silver,children:H.label.padEnd(Xt-Vn)})]}):jsx(Text,{children:" ".repeat(Xt)}),jsxs(Text,{color:e.dim,children:[" ",dt," "]}),G?jsxs(Fragment,{children:[jsx(Text,{color:e.amber,bold:true,children:G.key.padEnd(Vn)}),jsx(Text,{color:e.silver,children:G.label.padEnd(Xt-Vn)})]}):jsx(Text,{children:" ".repeat(Xt)}),jsxs(Text,{color:e.dim,children:[" ",dt," "]}),W?jsxs(Fragment,{children:[jsx(Text,{color:e.amber,bold:true,children:W.key.padEnd(Vn)}),jsx(Text,{color:e.silver,children:W.label.padEnd(Xt-Vn)})]}):jsx(Text,{children:" ".repeat(Xt)}),jsx(Text,{children:" "}),jsx(Text,{color:e.amber,children:dt})]},`r${B}`));}let R=B=>jsxs(Text,{children:[jsx(Text,{color:e.amber,children:dt}),jsx(Text,{children:" ".repeat(r)}),jsx(Text,{color:e.amber,children:dt})]},B),C=Hr("NAVIGATION"),z=Hr("ACTIONS"),P=Hr("COMMANDS");return jsxs(Box,{flexDirection:"column",paddingX:Math.max(0,Math.floor((n-s)/2)),marginTop:L,children:[jsxs(Text,{color:e.amber,children:[Fc,f,Wc]}),R("e1"),jsxs(Text,{children:[jsx(Text,{color:e.amber,children:dt}),jsx(Text,{children:" ".repeat(y)}),jsx(Text,{color:e.amber,bold:true,children:h}),jsx(Text,{children:" ".repeat(m)}),jsx(Text,{color:e.amber,children:dt})]}),R("e2"),jsxs(Text,{children:[jsx(Text,{color:e.amber,children:dt}),jsx(Text,{children:" "}),jsx(Text,{color:e.dim,children:C}),jsxs(Text,{color:e.dim,children:[" ",dt," "]}),jsx(Text,{color:e.dim,children:z}),jsxs(Text,{color:e.dim,children:[" ",dt," "]}),jsx(Text,{color:e.dim,children:P}),jsx(Text,{children:" "}),jsx(Text,{color:e.amber,children:dt})]}),R("e3"),_,R("e4"),jsxs(Text,{children:[jsx(Text,{color:e.amber,children:dt}),jsx(Text,{children:" ".repeat(S)}),jsx(Text,{color:e.dim,children:T}),jsx(Text,{children:" ".repeat(I)}),jsx(Text,{color:e.amber,children:dt})]}),R("e5"),jsxs(Text,{color:e.amber,children:[Gc,f,zc]})]})});var Fi=[{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"}],Wi=[{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"}],Gi=[{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"}],zi=[{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"}],Vi=[{value:"openai-codex/gpt-5.5",label:"GPT-5.5",hint:"Pi OpenAI Codex provider"},{value:"openai-codex/gpt-5.4",label:"GPT-5.4",hint:"Pi OpenAI Codex provider"},{value:"openai-codex/gpt-5.3-codex",label:"GPT-5.3 Codex",hint:"Pi OpenAI Codex provider"},{value:"",label:"Default",hint:"use Pi configured default"}],ji=[{value:"",label:"Default",hint:"use shell adapter default"}],Hi=[{value:"",label:"Default",hint:"no override \u2014 use model default"},{value:"high",label:"High",hint:"deepest reasoning, best quality, slowest"},{value:"medium",label:"Medium",hint:"balanced speed and quality"},{value:"low",label:"Low",hint:"fastest responses, minimal reasoning"}],Ui=new Set(["claude","pi"]),Vc=[{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:"pi",label:"Pi",hint:"Pi coding agent RPC"},{value:"shell",label:"Shell",hint:"custom shell command"}],Xi=[{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"}],Ni=60;function qi(t){return t.filter(n=>n.status!=="disabled").map(n=>{let o=(n.role??"").split(`
11
+ `)[0].trim(),r=o.length>Ni?o.slice(0,Ni-1)+"\u2026":o,s=r?`[${n.adapter}] ${r}`:n.adapter;return {value:n.id,label:n.name,hint:s}})}function tr(t,n="Auto-assign",o="orchestrator picks the best agent"){return [{value:"",label:n,hint:o},...qi(t)]}var Xr=[{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(n=>n.status==="active").map(n=>({value:n.id,label:n.name,hint:`${n.members.length} members`}))]}function Yi(){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 qr(t,n,o){let r=a$3(o,n.tier);return t.map(s=>{switch(s.id){case "name":return {...s,defaultValue:n.name};case "adapter":return {...s,defaultValue:o};case "model":return {...s,defaultValue:r};case "role":return {...s,defaultValue:"__custom__"};case "role_custom":return {...s,defaultValue:n.role,skip:void 0};case "skills":{let f=o==="claude"?n.skills:n.skills.filter(h=>!a$4(h));return {...s,defaultValue:f.join(", ")}}case "approval_policy":return {...s,defaultValue:n.approval_policy};default:return s}})}function nr(t,n){let o=Ki(n);return [{id:"name",label:"Agent name",type:"text",placeholder:"e.g. alpha, frontend-bot, reviewer",required:true,validate:r=>r.trim()?t?.some(s=>s.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:Vc},{id:"model",label:"Model",type:"select",getOptions:r=>r.adapter==="opencode"?zi:r.adapter==="codex"?Wi:r.adapter==="cursor"?Gi:r.adapter==="pi"?Vi:r.adapter==="shell"?ji:Fi},{id:"effort",label:"Reasoning effort",type:"select",options:Hi,skip:r=>!Ui.has(r.adapter??"")},{id:"role",label:"Role / specialization",type:"select",options:Xr},{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 Zi(t,n="claude"){let o=t.role==="__custom__"?t.role_custom||void 0:t.role||void 0,r=t.skills?t.skills.split(",").map(h=>h.trim()).filter(Boolean):void 0,s=t.approval_policy||"auto",f=t.effort||void 0;return {name:t.name,adapter:t.adapter||n,role:o,model:t.model||void 0,effort:f,approval_policy:s,skills:r,team_id:t.team||void 0}}function Ji(t,n){let o=qi(t);return [{id:"name",label:"Team name",type:"text",placeholder:"e.g. frontend, backend, qa",required:true,validate:r=>r.trim()?n?.some(s=>s.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(s=>s.value!==r.lead),skip:r=>!o.some(s=>s.value!==r.lead)},{id:"description",label:"Description",type:"textarea",placeholder:"Optional team purpose..."}]}function Qi(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 ea(t){let n=tr(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:Xi,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 ta(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 na(t,n){let o=tr(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:Xi,defaultValue:String(t.priority),validate:r=>{let s=Number(r);return !Number.isInteger(s)||s<1||s>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 oa(t){return {title:t.title,priority:t.priority?parseInt(t.priority,10):void 0,assignee:t.assignee||void 0,description:t.description??""}}function ra(t,n,o){let r=Xr.find(m=>m.value===t.role),s=r?t.role:t.role?"__custom__":"",f=t.adapter==="opencode"?zi:t.adapter==="codex"?Wi:t.adapter==="cursor"?Gi:t.adapter==="pi"?Vi:t.adapter==="shell"?ji:Fi,h=Ki(o),y=o?.find(m=>m.members.some(T=>T.agent_id===t.id))?.id;return [{id:"name",label:"Agent name",type:"text",defaultValue:t.name,required:true,validate:m=>m.trim()?n?.some(T=>T.id!==t.id&&T.name===m.trim())?"Agent with this name already exists":null:"Name is required"},{id:"model",label:"Model",type:"select",options:f,defaultValue:t.config.model??""},{id:"effort",label:"Reasoning effort",type:"select",options:Hi,defaultValue:t.config.effort??"",skip:()=>!Ui.has(t.adapter)},{id:"role",label:"Role / specialization",type:"select",options:Xr,defaultValue:s},{id:"role_custom",label:"Describe the role",type:"textarea",defaultValue:t.role&&!r?t.role:"",placeholder:"e.g. Specialist in React and TypeScript",skip:m=>m.role!=="__custom__"},{id:"team",label:"Team",type:"select",options:h,defaultValue:y??"",skip:()=>h.length<=1}]}var jc=[{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"}],Di=[{value:"true",label:"On"},{value:"false",label:"Off"}];function sa(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:jc,defaultValue:String(n)},{id:"notifications_toast",label:"Toast notifications",type:"select",options:Di,defaultValue:String(r.toast)},{id:"notifications_bell",label:"Bell on completion",type:"select",options:Di,defaultValue:String(r.bell)}]}function ia(t){let n=t.role==="__custom__"?t.role_custom||void 0:t.role||void 0,o=t.effort||void 0;return {name:t.name,role:n,model:t.model||void 0,effort:o,team_id:t.team||void 0}}function or(t){let n=tr(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 aa(t){return {title:t.title,assignee:t.assignee||void 0,description:t.description||void 0}}function la(t,n){let o=tr(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 ca(t){return {title:t.title,assignee:t.assignee||void 0,description:t.description??""}}var da=10,ua=500,cr=2048,yn=500,ga=5,Kr=new Set(["todo","failed","cancelled"]),ma=5e3,pa=0;function jg(){pa=0;}var ha=/^\[[\w_]+\]$/;function xa(t){return ha.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),Hn={system:"\u2666",lifecycle:"\u25B6",output:"\u2502",tool:"\u2699",result:"\u2190",error:"\u2715",file:"\u270E",info:"\u2502"},ar=["system","lifecycle","output","tool","result","error","file","info"],jn=[{label:"all",types:ar},{label:"text",types:["output"]},{label:"tools",types:["tool","result","file"]},{label:"errors",types:["error"]},{label:"events",types:["lifecycle","system"]}];function Yr(t){let o=(jn.findIndex(r=>r.types.length===t.size&&r.types.every(s=>t.has(s)))+1)%jn.length;return jn[o]}function Zr(t,n){if(t.length!==n.length)return true;for(let o=0;o<t.length;o++)if(t[o].id!==n[o].id||t[o].updated_at!==n[o].updated_at)return true;return false}function Hg({projectName:t,tasks:n,agents:o=[],state:r,onRunTask:s,onCreateTask:f,onCancelTask:h,onRetryTask:y,onAssignTask:m,onRunAll:T,onDisableAgent:S,onEnableAgent:I,onSubscribeEvents:M,onRefreshTasks:v,onRefreshAgents:L,onRefreshState:_,onLoadHistory:R,onAddAgent:C,onDeleteAgent:z,onApproveTask:P,onRejectTask:B,onDeleteTask:H,onUpdateTask:G,onUpdateAgent:W,onForceStopAgent:w,onCreateTeam:U,onListTeams:ie,onJoinTeam:oe,onLeaveTeam:we,onDisbandTeam:We,onSetTeamLead:Ge,onStartWatch:ut,onStopWatch:Ct,onToggleAutonomous:gt,onRefreshGoals:mt,onCreateGoal:Ye,onUpdateGoal:Ze,onUpdateGoalStatus:ft,onDeleteGoal:Ce,onGetGoalProgress:Wt,onCompleteOnboarding:It,initialWatchActive:ht,observerMode:Je,watchError:ot,messageBatchMs:Xe=process.env.VITEST?0:80,initialActivityFilter:po="all",onSaveActivityFilter:rn,initialMaxConcurrent:$t=a.scheduling.max_concurrent_agents,onSaveMaxConcurrent:Gt,initialNotifications:zt,onSaveNotifications:qt,version:sn,latestVersion:an,onCheckUpdate:vt,onBackgroundInstall:wn,defaultAdapter:Un="claude"}){let{exit:ln}=useApp(),{stdout:rt}=useStdout(),[cn,D]=useState(an),O=useRef(vt);useEffect(()=>{if(an||!O.current)return;let i=setTimeout(()=>{O.current?.().then(x=>{x&&D(x);}).catch(()=>{});},5e3);return ()=>clearTimeout(i)},[an]);let[N,$]=useState(false),q=useRef(false);useEffect(()=>{!cn||!wn||q.current||N||(q.current=true,wn(cn).then(i=>{i&&$(true);}).catch(()=>{}));},[cn,wn,N]);let[ne,_e]=useState({w:rt?.columns??80,h:rt?.rows??24});useEffect(()=>{if(!rt)return;let i=()=>_e({w:rt.columns,h:rt.rows});return rt.on("resize",i),()=>{rt.off("resize",i);}},[rt]);let ae=ne.w,ue=ne.h,[ce,Kt]=useState(n),[de,dr]=useState(o),[ze,ka]=useState(r),[ho,ur]=useState(ht??!!r.pid),[Xn,Qr]=useState([]),[Ca,es]=useState(void 0),[Yt,xo]=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(Yt!=="completed")return;let i=setTimeout(()=>{xo("dismissed"),It?.().catch(()=>{});},5e3);return ()=>clearTimeout(i)},[Yt,It]);let[E,Sn]=useState("tasks"),[bo,qn]=useState(0),[gr,ts]=useState(0),[mr,ns]=useState(0),[Ae,Kn]=useState(false),[Ve,os]=useState([]),[Pe,Ee]=useState("none"),xt=jo(),dn=xt.value,[bt,Qe]=useState(null),[un,Yn]=useState([]),[Bt,fr]=useState(false),[rs,Ia]=useState(()=>new Set),[kn,pr]=useState(false),[Zn,hr]=useState(false),[ss,is]=useState(()=>new Set(ar)),[Jn,xr]=useState(-1),[va,Qn]=useState(0),[Cn,br]=useState(()=>{let i=jn.find(x=>x.label===po);return new Set(i?.types??ar)}),To=useMemo(()=>jn.find(x=>x.types.length===Cn.size&&x.types.every(l=>Cn.has(l)))?.label??"all",[Cn]),Tr=useMemo(()=>Cn.size>=ar.length?Ve:Ve.filter(i=>Cn.has(i.msgType??"info")),[Ve,Cn]),[as,_a]=useState($t),[yo,Ma]=useState(zt??{toast:true,bell:false}),[Ra,ls]=useState([]),Aa=useRef(0),[yr,cs]=useState(),ds=useRef(E);ds.current=E;let us=useRef(ce);us.current=ce;let gs=useRef(de);gs.current=de;let wo=useRef(yo);wo.current=yo;let So=useCallback((i,x)=>{if(!wo.current.toast)return;let l=us.current.find(b=>b.id===x),c=l?.title??x,u=l?.assignee?gs.current.find(b=>b.id===l.assignee):void 0;ls(b=>{let g=[...b,{id:`toast_${Aa.current++}`,type:i,title:c,agentName:u?.name,ts:Date.now()}];return g.length>ga?g.slice(g.length-ga):g}),wo.current.bell&&(i==="failed"||i==="review")&&process.stdout.write("\x07");},[]),$a=useCallback(i=>{ls(x=>x.filter(l=>l.id!==i));},[]),ko=uo.useRef(new Go).current,[Ba,In]=useState(0),[ms,fs]=useState(false),[eo,Ea]=useState(false),[Oa,wr]=useState(0),[La,Sr]=useState(0),[kr,vn]=useState(0),[Co,Cr]=useState(false),[Pa,to]=useState(0),[Io,gn]=useState(0),[Vt,ps]=useState([]),[_n,Ir]=useState([]),Mn=useRef(Vt);Mn.current=Vt;let hs=useRef(0),K=useCallback(async i=>{hs.current=Date.now();let[x,l,c,u,b]=await Promise.all([v?.()??Promise.resolve(ce),L?.()??Promise.resolve(de),_?.()??Promise.resolve(ze),i?.includeTeams?ie?.()??Promise.resolve(Mn.current):Promise.resolve(null),mt?.()??Promise.resolve(Xn)]);Kt(g=>Zr(g,x)?x:g),dr(g=>Zr(g,l)?l:g),ka(c),u!==null&&ps(u),Qr(g=>Zr(g,b)?b:g),ht&&ur(!!c.pid);},[v,L,_,ie,mt,ht]),Rn=useMemo(()=>{let i=new Map;for(let x of Xn)i.set(x.id,x);return i},[Xn]),Oe=useMemo(()=>{let i=[...ce].sort((b,g)=>(ao[b.status]??9)-(ao[g.status]??9));if(!eo)return i;let x=[],l=[],c=[],u=new Map;for(let b of i)b.goalId&&Rn.has(b.goalId)?(u.has(b.goalId)||(c.push(b.goalId),u.set(b.goalId,[])),u.get(b.goalId).push(b)):l.push(b);for(let b of c)x.push(...u.get(b));return [...x,...l]},[ce,eo,Rn]),Et=ms?Oe:Oe.slice(0,da),An=Oe.length-Et.length,j=Oe[bo],no=useMemo(()=>{let i=new Map;for(let x of ce)i.set(x.id,x.title);return i},[ce]),mn=useMemo(()=>{let i=new Map;for(let x of de)i.set(x.id,x.name);return i},[de]),Na=useMemo(()=>{let i=new Map;for(let x of ce)if(x.goalId){let l=i.get(x.goalId);l||(l=[],i.set(x.goalId,l)),l.push(x);}return i},[ce]),vo=useMemo(()=>{let i=new Map;for(let x=0;x<de.length;x++)i.set(de[x].id,Jr[x%Jr.length]);return i},[de]),xs=useMemo(()=>{let i=new Map;for(let x of Ve)x.agentId&&i.set(x.agentId,(i.get(x.agentId)??0)+1);return i},[Ve]),Da=useMemo(()=>{let i={};for(let x of Ve){let l=x.msgType??"info";i[l]=(i[l]??0)+1;}return i},[Ve]),{agentTeamMap:$n,activeTeamCount:oo,teamLeadSet:Fa}=useMemo(()=>{let i=new Map,x=new Set,l=0;for(let c of Vt)if(c.status==="active"){l++,x.add(c.lead_agent_id);for(let u of c.members)i.set(u.agent_id,c.name);}return {agentTeamMap:i,activeTeamCount:l,teamLeadSet:x}},[Vt]),Ne=useMemo(()=>{let i=[...de];return i.sort((x,l)=>{let c=$n.get(x.id),u=$n.get(l.id);return c&&!u?-1:!c&&u?1:c&&u&&c!==u?c.localeCompare(u):(Lr[x.status]??9)-(Lr[l.status]??9)}),i},[de,$n]),Z=Ne[gr],pt=useMemo(()=>[...Xn].sort((i,x)=>(c[i.status]??9)-(c[x.status]??9)),[Xn]),Q=pt[mr],Wa=useMemo(()=>Q?ce.filter(i=>i.goalId===Q.id):[],[Q,ce]),vr=useRef(Wt);vr.current=Wt,useEffect(()=>{if(!Q||!vr.current){es(void 0);return}let i=false;return vr.current(Q.id).then(x=>{i||es(x);}).catch(()=>{}),()=>{i=true;}},[Q?.id]);let fn=useRef(new Map),_o=useRef(new Map);useEffect(()=>{for(let[i,x]of Object.entries(ze.running))fn.current.set(x.run_id,x.agent_id),_o.current.set(x.run_id,i);if(fn.current.size>ua){let i=fn.current.size-ua,x=0;for(let l of fn.current.keys()){if(x++>=i)break;fn.current.delete(l),_o.current.delete(l);}}},[ze.running]);let pn=useRef([]),ro=useRef(null),_r=useCallback(()=>{if(ro.current=null,pn.current.length===0)return;let i=pn.current;pn.current=[],os(x=>{if(i.length>=yn)return i.slice(-yn);let l=yn-i.length;return (x.length>l?x.slice(-l):x).concat(i)});},[]);useEffect(()=>()=>{ro.current&&clearTimeout(ro.current);},[]);let a=useCallback((i,x,l)=>{let c=new Date,u=c.toLocaleTimeString("en-US",{hour12:false,hour:"2-digit",minute:"2-digit",second:"2-digit"}),b=l?.detail&&l.detail.length>cr?l.detail.slice(0,cr)+"\u2026[truncated]":l?.detail;pn.current.push({text:i,color:x,time:u,ts:c.getTime(),...l,detail:b}),pn.current.length>yn&&(pn.current=pn.current.slice(-yn)),Xe===0?_r():ro.current||(ro.current=setTimeout(_r,Xe));},[_r]);useEffect(()=>{Je?a("Observer mode: watching external orchestrator via disk polling.",e.amber):ot&&a(`Watch mode failed: ${ot}. Tasks will not auto-dispatch.`,e.red);},[]),useEffect(()=>{let i=Je?3e3:5e3,x=setInterval(()=>{Date.now()-hs.current>=i&&K().catch(()=>{});},i);return ()=>clearInterval(x)},[Je,K]);let Bn=useCallback((i,x,l,c)=>{let u={key:++pa,entityType:i,entityId:x,entityName:l,expiresAt:Date.now()+ma,needsForceStop:c?.needsForceStop};Ir(b=>[...b,u]),a(`\u2717 "${l}" will be deleted in ${Math.round(ma/1e3)}s \u2014 press Z to undo`,e.yellow);},[a]),Ga=useCallback(()=>{Ir(i=>{if(i.length===0)return i;let x=i[i.length-1];return a(`\u21B6 Undo: "${x.entityName}" restored`,e.green),i.slice(0,-1)});},[a]),bs=useCallback(async i=>{try{i.entityType==="task"&&H?await H(i.entityId):i.entityType==="agent"?(i.needsForceStop&&w&&await w(i.entityId),z&&await z(i.entityId)):i.entityType==="goal"&&Ce&&await Ce(i.entityId),a(`\u2713 Deleted "${i.entityName}"`,e.green),K();}catch(x){a(`Failed to delete "${i.entityName}": ${x instanceof Error?x.message:String(x)}`,e.red);}},[H,z,Ce,w,a,K]),Ts=useRef(bs);Ts.current=bs,useEffect(()=>{if(_n.length===0)return;let i=setInterval(()=>{let x=Date.now(),l=[];Ir(c=>{let u=c.filter(b=>b.expiresAt<=x?(l.push(b),false):true);return l.length>0?u:c});for(let c of l)Ts.current(c);},1e3);return ()=>clearInterval(i)},[_n.length>0]),useEffect(()=>{if(!R)return;let i=x=>{let l=new Date(x.timestamp).toLocaleTimeString("en-US",{hour12:false,hour:"2-digit",minute:"2-digit",second:"2-digit"}),c=typeof x.data=="string"?x.data:JSON.stringify(x.data),u,b=e.silver,g="output";if(x.type==="error")u=typeof x.data=="string"?x.data:JSON.stringify(x.data),u=u.slice(0,200),b=e.red,g="error";else if(x.type==="file_changed")u=String(x.data),b=e.purple,g="file";else if(x.type==="done")u="Completed",b=e.green,g="lifecycle";else if(x.type==="tool_call")u=`\u2699 ${x.data?.name??"tool"}()`,b=e.cyan,g="tool";else {let{summary:k}=Sa(c);if(!k)return null;u=k;let Y=xa(u);g=Y.msgType,b=Y.color;}return {text:u,color:b,time:l,ts:new Date(x.timestamp).getTime(),agentId:x.agentId,taskId:x.taskId,msgType:g}};R(x=>{if(x.length===0)return;let l=x.map(i).filter(c=>c!==null);os(c=>{let u=[...l,...c];return u.length>yn?u.slice(-yn):u});}).catch(x=>{process.stderr.write(`[TUI] onLoadHistory error: ${x instanceof Error?x.stack??x.message:String(x)}
12
+ `);});},[]),useEffect(()=>{ie?.().then(ps).catch(()=>{}),mt?.().then(Qr).catch(()=>{});},[]);let Mo=useCallback(()=>{Qe({title:"NEW AGENT",steps:nr(de,Mn.current),kind:"agent"}),Ee("wizard");},[de]),ys=useCallback(()=>{Qe({title:"AGENT SHOP",steps:Yi(),kind:"agent_shop"}),Ee("wizard");},[]),Ro=useCallback(()=>{Yn([]),Qe({title:"NEW TASK",steps:ea(de),kind:"task"}),Ee("wizard");},[de]),za=useCallback(async()=>{try{let{detectClipboardType:i,getClipboardImage:x}=await import('./clipboard-service-AJTJG2DJ.js'),l=await i();if(l!=="image")return a(l==="text"?"Clipboard has text, not image":"Clipboard is empty",e.dim),l;let c=await x();if(!c)return a("Failed to read clipboard image",e.red),"empty";let{mkdtemp:u,writeFile:b}=await import('fs/promises'),{tmpdir:g}=await import('os'),{join:k}=await import('path'),Y=await u(k(g(),"orch-paste-")),Lt=k(Y,`clipboard-${Date.now()}.${c.ext}`);return await b(Lt,c.data),Yn(hn=>[...hn,Lt]),a(`\u{1F4CE} Image attached (${Math.round(c.data.length/1024)}KB)`,e.green),"image"}catch{return a("Clipboard paste failed",e.red),"empty"}},[a]),Va=useCallback(i=>{Qe({title:"EDIT TASK",steps:na(i,de),kind:"edit_task",targetId:i.id}),Ee("wizard");},[de]),ws=useCallback(()=>{Qe({title:"NEW TEAM",steps:Ji(de,Vt),kind:"team"}),Ee("wizard");},[de]),ja=useCallback(i=>{Qe({title:"EDIT AGENT",steps:ra(i,de,Vt),kind:"edit_agent",targetId:i.id}),Ee("wizard");},[Vt]),Ss=useCallback(()=>{Qe({title:"SETTINGS",steps:sa(To,as,yo),kind:"config"}),Ee("wizard");},[To,as]),Ha=useCallback(i=>{Ee("none");let x=bt?.kind,l=bt?.targetId;if(Qe(null),x==="agent_shop"){let c=i.shop_template,u=c?b(c):void 0;if(u){let b=nr(de,Mn.current),g=qr(b,u,Un);Qe({title:`NEW AGENT \u2014 ${u.name}`,steps:g,kind:"agent_from_shop"}),Ee("wizard");}else a("No template selected",e.yellow);return}if((x==="agent"||x==="agent_from_shop")&&C){let c=Zi(i,Un);a(`Creating agent "${c.name}"...`,e.amber),C(c.name,c.adapter,{model:c.model,effort:c.effort,role:c.role,approval_policy:c.approval_policy,skills:c.skills}).then(u=>{a(`\u2713 Created agent "${u.name}" (${u.id}, ${u.adapter})`,e.green),c.team_id&&oe?oe(c.team_id,u.id).then(b=>{a(`\u2713 Joined team "${b.name}"`,e.green),K({includeTeams:true});},b=>a(`Failed to join team: ${b instanceof Error?b.message:String(b)}`,e.red)):K();},u=>a(`Failed: ${u instanceof Error?u.message:String(u)}`,e.red));}else if(x==="team"&&U){let c=Qi(i);a(`Creating team "${c.name}"...`,e.amber),U(c).then(u=>{a(`\u2713 Created team "${u.name}" (${u.id}, ${u.members.length} members)`,e.green),K({includeTeams:true});},u=>a(`Failed: ${u instanceof Error?u.message:String(u)}`,e.red));}else if(x==="task"&&f){let c=ta(i),u=un.length>0?[...un]:void 0;Yn([]),a(`Creating "${c.title}"...`,e.amber),f(c.title,{priority:c.priority,description:c.description,attachments:u}).then(b=>{a(`\u2713 Created "${b.title}" (${b.id})${u?` \u{1F4CE}${u.length}`:""}`,e.green),c.assignee&&m&&m(b.id,c.assignee).catch(()=>{}),K();},b=>a(`Failed: ${b instanceof Error?b.message:String(b)}`,e.red));}else if(x==="edit_task"&&l&&G){let c=oa(i),u=un.length>0?[...un]:void 0;Yn([]),a("Updating task...",e.amber),G(l,{...c,attachments:u}).then(b=>{a(`\u2713 Updated "${b.title}"${u?` \u{1F4CE}${u.length}`:""}`,e.green),c.assignee&&m&&m(l,c.assignee).catch(()=>{}),K();},b=>a(`Failed: ${b instanceof Error?b.message:String(b)}`,e.red));}else if(x==="edit_agent"&&l&&W){let c=ia(i),u=c.team_id??"",b=Vt.find(g=>g.members.some(k=>k.agent_id===l))?.id??"";a("Updating agent...",e.amber),W(l,{name:c.name,role:c.role,model:c.model,effort:c.effort}).then(g=>{a(`\u2713 Updated agent "${g.name}"`,e.green);let k=[];b&&b!==u&&we&&k.push(we(b,l).then(Y=>a(`\u2713 Left team "${Y.name}"`,e.green),Y=>a(`Failed to leave team: ${Y instanceof Error?Y.message:String(Y)}`,e.red))),u&&u!==b&&oe&&k.push(oe(u,l).then(Y=>a(`\u2713 Joined team "${Y.name}"`,e.green),Y=>a(`Failed to join team: ${Y instanceof Error?Y.message:String(Y)}`,e.red))),Promise.all(k).then(()=>K({includeTeams:k.length>0}));},g=>a(`Failed: ${g instanceof Error?g.message:String(g)}`,e.red));}else if(x==="config"){if(i.activity_filter){let g=jn.find(k=>k.label===i.activity_filter);g&&(br(new Set(g.types)),rn?.(g.label));}if(i.max_concurrent){let g=parseInt(i.max_concurrent,10);g>0&&(_a(g),Gt?.(g));}let c=i.notifications_toast==="true",u=i.notifications_bell==="true",b={toast:c,bell:u};Ma(b),qt?.(b),a("Settings saved",e.green);}else if(x==="goal"&&Ye){let c=aa(i);a(`Creating goal "${c.title}"...`,e.amber),Ye(c).then(u=>{a(`\u2713 Created goal "${u.title}" (${u.id})`,e.green),K();},u=>a(`Failed: ${u instanceof Error?u.message:String(u)}`,e.red));}else if(x==="edit_goal"&&l&&Ze){let c=ca(i);a("Updating goal...",e.amber),Ze(l,c).then(u=>{a(`\u2713 Updated goal "${u.title}"`,e.green),K();},u=>a(`Failed: ${u instanceof Error?u.message:String(u)}`,e.red));}},[bt,C,f,U,oe,we,m,G,W,gt,Ye,Ze,a,K,rn,Gt,yo,qt,Vt,un]),Ua=useCallback(()=>{Ee("none"),Qe(null),Yn([]);},[]),Xa=useCallback(i=>{let x=b(i);if(!x)return;let l=nr(de,Mn.current),c=qr(l,x,Un);Qe({title:`NEW AGENT \u2014 ${x.name}`,steps:c,kind:"agent_from_shop"}),Ee("wizard");},[]);useEffect(()=>{if(!M)return;let i=null,x=()=>{i||(i=setTimeout(()=>{i=null,K().catch(()=>{});},150));},l=M(c=>{if(c.type==="agent:started"&&(fn.current.set(c.runId,c.agentId),_o.current.set(c.runId,c.taskId)),md(c,a,fn.current,_o.current),c.type==="task:created"?xo(u=>u==="welcome"?"task_created":u):c.type==="agent:started"?xo(u=>u==="task_created"?"run_started":u):c.type==="task:status_changed"&&c.to==="done"&&xo(u=>u==="run_started"?"completed":u),c.type==="task:status_changed"&&(c.to==="done"?So("done",c.taskId):c.to==="failed"?So("failed",c.taskId):c.to==="review"&&So("review",c.taskId),wo.current.toast&&ds.current!=="tasks")){let u=c.to==="done"?e.green:c.to==="failed"?e.red:c.to==="review"?e.blue:void 0;u&&cs({tab:"tasks",color:u});}(c.type==="task:status_changed"||c.type==="task:created"||c.type==="task:assigned"||c.type==="agent:started"||c.type==="agent:completed"||c.type==="run:retry"||c.type==="goal:created"||c.type==="goal:status_changed"||c.type==="goal:updated"||c.type==="goal:deleted")&&x();});return ()=>{l(),i&&clearTimeout(i);}},[M,a,K,So]);let Mr=Je?"observing":ho?"watching":"idle",qa=ze.started_at?g(ze.started_at):void 0,ks=ze.stats.total_tokens.total,Cs=useMemo(()=>{let i={running:0,retrying:0,review:0,todo:0,done:0,failed:0,cancelled:0};for(let x of ce)x.status==="in_progress"?i.running++:x.status==="retrying"?i.retrying++:x.status==="review"?i.review++:x.status==="todo"?i.todo++:x.status==="done"?i.done++:x.status==="failed"?i.failed++:x.status==="cancelled"&&i.cancelled++;return {...i,teams:oo}},[ce,oo]);Cs.running;let Ka=useMemo(()=>({input:ze.stats.total_tokens.input??0,output:ze.stats.total_tokens.output??0,reasoning:ze.stats.total_tokens.reasoning??0,total:ks,cache_read:ze.stats.total_tokens.cache_read??0,cache_write:ze.stats.total_tokens.cache_write??0}),[ze.stats.total_tokens,ks]),_t=Math.max(4,ue-9),Ya=$n.size,Za=de.length>Ya,Ja=oo>0?oo+(Za?1:0):0,Qa=useMemo(()=>{if(!eo||Rn.size===0)return 0;let i=0,x=new Set,l=false;for(let c of Et)c.goalId&&Rn.has(c.goalId)?x.has(c.goalId)||(x.add(c.goalId),i++):l=true;return l&&i++,i},[eo,Rn,Et]),el=E==="goals"?pt.length+1:E==="tasks"?Et.length+1+(An>0?1:0)+Qa:E==="agents"?de.length+1+Ja:0,tl=Math.min(el+1,Math.ceil(_t*.5)),nl=E==="logs"?_t:Math.max(2,Math.min(tl,_t-4)),Se,Ot;if(E==="logs")Se=_t,Ot=0;else if(Co)Se=0,Ot=Math.max(1,_t);else {let i=Math.max(3,Math.min(nl+kr,_t-4));Se=i,Ot=Math.max(1,_t-i);}let Me=Math.max(10,ae-2),Mt=useMemo(()=>Pe==="command"?oi(dn):[],[Pe,dn]),En=_t-4-3;useEffect(()=>{kr>En&&vn(En),kr<-En&&vn(-En);},[_t]),useEffect(()=>{In(i=>Math.min(i,Math.max(0,Et.length-Se)));},[Et.length,Se]),useEffect(()=>{wr(i=>Math.min(i,Math.max(0,Ne.length-Se)));},[Ne.length,Se]),useEffect(()=>{Sr(i=>Math.min(i,Math.max(0,pt.length-Se)));},[pt.length,Se]);let ol=useCallback(i=>{let l=i.trim().replace(/^\//,"").split(/\s+/),c=l[0]?.toLowerCase();if(!c)return;let u=b=>b instanceof Error?b.message:String(b);switch(c){case "cancel":{if(!j){a("No task selected",e.yellow);return}if(!h)return;a(`Cancelling "${j.title}"...`,e.amber),h(j.id).then(()=>{a(`\u2713 Cancelled "${j.title}"`,e.green),K();},b=>a(`Failed: ${u(b)}`,e.red));return}case "retry":{if(!j){a("No task selected",e.yellow);return}if(!y)return;a(`Retrying "${j.title}"...`,e.amber),y(j.id).then(()=>{a(`\u2713 Retried "${j.title}"`,e.green),K();},b=>a(`Failed: ${u(b)}`,e.red));return}case "assign":{if(!j){a("No task selected",e.yellow);return}if(!m||!l[1]){a("Usage: assign <agent>",e.yellow);return}a(`Assigning "${j.title}" to ${l[1]}...`,e.amber),m(j.id,l[1]).then(()=>{a(`\u2713 Assigned "${j.title}" to ${l[1]}`,e.green),K();},b=>a(`Failed: ${u(b)}`,e.red));return}case "task":{let b=l[1]?.toLowerCase();if(b==="add"){let g=l.slice(2).join(" ");if(!g){Ro();return}if(!f){a("Create not available",e.yellow);return}a(`Creating "${g}"...`,e.amber),f(g).then(k=>{a(`\u2713 Created "${k.title}" (${k.id})`,e.green),K();},k=>a(`Failed: ${u(k)}`,e.red));}else if(b==="list"){let g=Oe.map(k=>` ${k.id} ${k.status.padEnd(11)} ${k.title}`);if(g.length===0)a("No tasks",e.dim);else for(let k of g)a(k,e.cyan);}else if(b==="show"){let g=l[2]?Oe.find(k=>k.id===l[2]):j;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(b==="cancel"){let g=l[2]?Oe.find(k=>k.id===l[2]):j;if(!g){a("No task selected or id given",e.yellow);return}if(!h)return;a(`Cancelling "${g.title}"...`,e.amber),h(g.id).then(()=>{a(`\u2713 Cancelled "${g.title}"`,e.green),K();},k=>a(`Failed: ${u(k)}`,e.red));}else if(b==="retry"){let g=l[2]?Oe.find(k=>k.id===l[2]):j;if(!g){a("No task selected or id given",e.yellow);return}if(!y)return;a(`Retrying "${g.title}"...`,e.amber),y(g.id).then(()=>{a(`\u2713 Retried "${g.title}"`,e.green),K();},k=>a(`Failed: ${u(k)}`,e.red));}else if(b==="assign"){let g=l[2]?Oe.find(Lt=>Lt.id===l[2]):void 0,k=g??j,Y=g?l[3]:l[2];if(!k){a("No task selected or id given",e.yellow);return}if(!Y){a("Usage: /task assign [id] <agent>",e.yellow);return}if(!m)return;a(`Assigning "${k.title}" to ${Y}...`,e.amber),m(k.id,Y).then(()=>{a(`\u2713 Assigned "${k.title}" to ${Y}`,e.green),K();},Lt=>a(`Failed: ${u(Lt)}`,e.red));}else if(b==="approve"){let g=l[2]?Oe.find(k=>k.id===l[2]):j;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(!P)return;a(`Approving "${g.title}"...`,e.amber),P(g.id).then(()=>{a(`\u2713 Approved "${g.title}"`,e.green),K();},k=>a(`Failed: ${u(k)}`,e.red));}else if(b==="reject"){let g=l[2]?Oe.find(Y=>Y.id===l[2]):j;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(!B)return;let k=l.slice(l[2]&&Oe.find(Y=>Y.id===l[2])?3:2).join(" ").trim()||void 0;a(`Rejecting "${g.title}"${k?" with feedback":""}...`,e.amber),B(g.id,k).then(()=>{a(`\u2713 Rejected "${g.title}" \u2192 todo`,e.green),K();},Y=>a(`Failed: ${u(Y)}`,e.red));}else if(b==="delete"){let g=l[2]?Oe.find(k=>k.id===l[2]):j;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(!H)return;Bn("task",g.id,g.title);}else a("Usage: /task add|list|show|cancel|retry|assign|approve|reject|delete",e.yellow);return}case "agent":{let b=l[1]?.toLowerCase();if(b==="add"){let g=l[2];if(!g){Mo();return}if(!C){a("Agent creation not available",e.yellow);return}let k=l[3];a(`Creating agent "${g}"...`,e.amber),C(g,k).then(Y=>{a(`\u2713 Created agent "${Y.name}" (${Y.id}, ${Y.adapter})`,e.green),K();},Y=>a(`Failed: ${u(Y)}`,e.red));}else if(b==="list"){let g=Ne.map(k=>` ${k.id} ${k.status.padEnd(8)} ${k.name} (${k.adapter})`);if(g.length===0)a("No agents",e.dim);else for(let k of g)a(k,e.cyan);}else if(b==="disable"){let g=l[2]?Ne.find(k=>k.id===l[2]||k.name===l[2]):Z;if(!g){a("No agent selected or id given",e.yellow);return}if(!S)return;a(`Disabling ${g.name}...`,e.amber),S(g.id).then(()=>{a(`\u2713 Disabled ${g.name}`,e.green),K();},k=>a(`Failed: ${u(k)}`,e.red));}else if(b==="enable"){let g=l[2]?Ne.find(k=>k.id===l[2]||k.name===l[2]):Z;if(!g){a("No agent selected or id given",e.yellow);return}if(!I)return;a(`Enabling ${g.name}...`,e.amber),I(g.id).then(()=>{a(`\u2713 Enabled ${g.name}`,e.green),K();},k=>a(`Failed: ${u(k)}`,e.red));}else if(b==="delete"||b==="remove"){let g=l[2]?Ne.find(k=>k.id===l[2]||k.name===l[2]):Z;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(!z){a("Agent deletion not available",e.yellow);return}Bn("agent",g.id,g.name);}else if(b==="autonomous"||b==="auto"){let g=l[2]?Ne.find(k=>k.id===l[2]||k.name===l[2]):Z;if(!g){a("No agent selected or id given",e.yellow);return}if(!gt){a("Autonomous toggle not available",e.yellow);return}g.autonomous?(a(`Disabling autonomous mode for "${g.name}"...`,e.amber),gt(g.id,false).then(()=>{a(`${xn} ${g.name} autonomous OFF`,e.cyan),K();},k=>a(`Failed: ${u(k)}`,e.red))):(a(`Enabling autonomous mode for "${g.name}"...`,e.amber),gt(g.id,true).then(()=>{a(`${xn} ${g.name} autonomous ON`,e.cyan),K();},k=>a(`Failed: ${u(k)}`,e.red)));}else b==="shop"?ys():a("Usage: /agent add|list|disable|enable|delete|autonomous|shop",e.yellow);return}case "team":{let b=l[1]?.toLowerCase();if(b==="create"||b==="add")ws();else if(b==="list"){let g=Mn.current;if(g.length===0)a("No teams",e.dim);else for(let k of g)a(` ${k.id} ${k.status.padEnd(8)} ${k.name} (${k.members.length} members)`,e.cyan);}else if(b==="join"){if(!oe){a("Join not available",e.yellow);return}let g=l[2],k=l[3]??Z?.id;if(!g||!k){a("Usage: /team join <teamId> [agentId]",e.yellow);return}a(`Joining team ${g}...`,e.amber),oe(g,k).then(Y=>{a(`\u2713 Agent joined team "${Y.name}"`,e.green),K({includeTeams:true});},Y=>a(`Failed: ${u(Y)}`,e.red));}else if(b==="leave"){if(!we){a("Leave not available",e.yellow);return}let g=l[2],k=l[3]??Z?.id;if(!g||!k){a("Usage: /team leave <teamId> [agentId]",e.yellow);return}a(`Leaving team ${g}...`,e.amber),we(g,k).then(Y=>{a(`\u2713 Agent left team "${Y.name}"`,e.green),K({includeTeams:true});},Y=>a(`Failed: ${u(Y)}`,e.red));}else if(b==="disband"){if(!We){a("Disband not available",e.yellow);return}let g=l[2];if(!g){a("Usage: /team disband <teamId>",e.yellow);return}a(`Disbanding team ${g}...`,e.amber),We(g).then(()=>{a("\u2713 Team disbanded",e.green),K({includeTeams:true});},k=>a(`Failed: ${u(k)}`,e.red));}else if(b==="set-lead"){if(!Ge){a("Set-lead not available",e.yellow);return}let g=l[2],k=l[3];if(!g||!k){a("Usage: /team set-lead <teamId> <agentId>",e.yellow);return}a(`Setting lead for team ${g}...`,e.amber),Ge(g,k).then(Y=>{a(`\u2713 New lead for team "${Y.name}"`,e.green),K({includeTeams:true});},Y=>a(`Failed: ${u(Y)}`,e.red));}else a("Usage: /team create|list|join|leave|disband|set-lead",e.yellow);return}case "goal":{let b=l[1]?.toLowerCase();if(b==="add"||b==="create"){let g=l.slice(2).join(" ").trim();if(!g){let k=or(de);Qe({title:"New Goal",steps:k,kind:"goal"}),Ee("wizard");return}if(!Ye){a("Goal creation not available",e.yellow);return}a(`Creating goal "${g}"...`,e.amber),Ye({title:g}).then(k=>{a(`\u2713 Created goal "${k.title}" (${k.id})`,e.green),K();},k=>a(`Failed: ${u(k)}`,e.red));}else if(b==="list"){let g=pt.map(k=>` ${k.id} ${k.status.padEnd(8)} ${k.title}`);if(g.length===0)a("No goals",e.dim);else for(let k of g)a(k,e.cyan);}else if(b==="show"){let g=l[2]?pt.find(k=>k.id===l[2]):Q;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(b==="status"){let g=l[2]?pt.find(hn=>hn.id===l[2]):void 0,k=g??Q;if(!k){a("No goal selected or id given",e.yellow);return}let Y=l[g?3:2];if(!Y||!a$1.includes(Y)){a("Usage: /goal status [id] <active|paused|achieved|abandoned>",e.yellow);return}let Lt=Y;if(!ft){a("Status update not available",e.yellow);return}a(`Updating goal status to ${Lt}...`,e.amber),ft(k.id,Lt).then(hn=>{a(`\u2713 Goal "${hn.title}" \u2192 ${Lt}`,e.green),K();},hn=>a(`Failed: ${u(hn)}`,e.red));}else if(b==="delete"){let g=l[2]?pt.find(k=>k.id===l[2]):Q;if(!g){a("No goal selected or id given",e.yellow);return}if(!Ce){a("Goal deletion not available",e.yellow);return}Bn("goal",g.id,g.title);}else a("Usage: /goal add|list|show|status|delete",e.yellow);return}case "run":{let b=l[1]??j?.id;if(!b){a("No task selected or id given",e.yellow);return}if(!s){a("Run not available",e.yellow);return}let g=Oe.find(k=>k.id===b);if(g&&!Kr.has(g.status)){a(`Cannot run \u2014 status is ${g.status}`,e.yellow);return}a(`Running ${b}...`,e.amber),s(b).then(()=>{a(`\u2713 Dispatched ${b}`,e.green),K();},k=>a(`Failed: ${u(k)}`,e.red));return}case "run-all":{if(!T){a("Run-all not available",e.yellow);return}a("Running all todo tasks...",e.amber),T().then(()=>{a("\u2713 Dispatched all todo tasks",e.green),K();},b=>a(`Failed: ${u(b)}`,e.red));return}case "watch":{if(ho){a("Watch mode already active",e.yellow);return}if(!ut){a("Watch not available",e.yellow);return}a("Starting watch mode...",e.amber),ut().then(()=>{ur(true),a("\u2713 Watch mode started",e.green);},b=>a(`Failed: ${u(b)}`,e.red));return}case "pause":{if(!ho){a("Watch mode not active",e.yellow);return}if(!Ct){a("Pause not available",e.yellow);return}a("Pausing watch mode...",e.amber),Ct().then(()=>{ur(false),a("\u2713 Watch mode paused",e.green);},b=>a(`Failed: ${u(b)}`,e.red));return}case "config":{l[1]?.toLowerCase()==="activity-filter"?br(g=>{let k=Yr(g);return rn?.(k.label),a(`Activity filter: ${k.label}`,e.amber),new Set(k.types)}):Ss();return}case "status":{let b=ce.filter(g=>g.status==="in_progress").length;a(`${Mr} ${b} running ${ce.length} tasks ${Ne.length} agents`,e.cyan);return}case "help":{for(let[b,g]of Object.entries(bn)){let k=g.sub?" "+g.sub.join("|"):g.args?" "+g.args:"";a(` /${b}${k} \u2014 ${g.help}`,e.silver);}return}case "quit":{ln();return}case "disable":{if(!Z){a("No agent selected",e.yellow);return}if(!S)return;a(`Disabling ${Z.name}...`,e.amber),S(Z.id).then(()=>{a(`\u2713 Disabled ${Z.name}`,e.green),K();},b=>a(`Failed: ${u(b)}`,e.red));return}case "enable":{if(!Z){a("No agent selected",e.yellow);return}if(!I)return;a(`Enabling ${Z.name}...`,e.amber),I(Z.id).then(()=>{a(`\u2713 Enabled ${Z.name}`,e.green),K();},b=>a(`Failed: ${u(b)}`,e.red));return}default:a(`Unknown: ${c}. Type /help for commands`,e.yellow);}},[j,Z,Oe,Ne,ce,Mr,ho,h,y,m,T,s,f,S,I,C,P,B,H,oe,we,We,Ge,ut,Ct,a,ln,K,Ro,Mo,ws,Ss]);useInput((i,x)=>{if(!(Bt&&(fr(false),i==="?"||x.escape||i==="\x1BOP"))&&!kn){if((x.ctrl||x.meta)&&i==="s"&&Pe==="wizard"&&bt?.kind==="agent"){ys();return}if(Pe!=="none"){if(x.escape){Ee("none"),xt.reset(""),ko.reset();return}if(x.return){let c=dn.trim();if(!c)return;if(Pe==="new_task"){if(!f)return;Ee("none"),xt.reset(""),a(`Creating "${c}"...`,e.amber),f(c).then(u=>{a(`\u2713 Created "${u.title}" (${u.id})`,e.green),K();},u=>a(`Failed to create: ${u instanceof Error?u.message:String(u)}`,e.red));}else if(Pe==="command"){let u=c;if(Mt.length>0&&Mt[Io]){let b=Mt[Io],g=b.cmd.replace(/\s+\[.*\]$/,"");if((g.startsWith(c)||c==="/")&&(u=g),b.subs&&!g.includes(" ")){xt.setValue(g+" "),gn(0);return}}Ee("none"),xt.reset(""),gn(0),ko.push(u),ol(u);}return}if(x.tab&&Pe==="command"){if(Mt.length>0){let c=Mt[Io];if(c){let u=c.cmd.replace(/\s+\[.*\]$/,"");xt.setValue(u+(c.subs?" ":"")),gn(0);}}else {let c=Nr(dn);c&&xt.setValue(dn+c);}return}if(x.upArrow&&Pe==="command"){if(Mt.length>0)gn(c=>Math.max(0,c-1));else {let c=ko.prev();c!==null&&xt.setValue(c);}return}if(x.downArrow&&Pe==="command"){if(Mt.length>0)gn(c=>Math.min(Mt.length-1,c+1));else {let c=ko.next();xt.setValue(c??"");}return}xt.handleInput(i,x)&&gn(0);return}if(i.toLowerCase()==="q"){ln();return}if(x.escape){if(Ae){Kn(false),to(0);return}if(E==="logs"&&Jn>=0){xr(-1),Qn(0);return}return}if((i==="+"||i==="=")&&E!=="logs"){Co?(Cr(false),vn(-Math.floor(_t/2))):vn(l=>Math.max(-En,l-3));return}if(i==="-"&&E!=="logs"){Co?(Cr(false),vn(Math.floor(_t/2))):vn(l=>Math.min(En,l+3));return}if(i==="M"&&E!=="logs"){Cr(l=>!l);return}if(i==="?"){fr(true);return}if(i==="\x1BOP"){fr(true);return}if(i==="/"&&!Ae){Ee("command"),xt.setValue("/"),gn(0);return}if((i==="a"||i==="A")&&E==="logs"&&!Ae&&!kn&&!Zn){pr(true);return}if(i==="f"&&E==="logs"&&!Ae&&!kn&&!Zn){hr(true);return}if(i==="F"&&E==="logs"&&!Ae&&!kn&&!Zn){is(l=>new Set(Yr(l).types));return}if((i==="z"||i==="Z")&&_n.length>0){Ga();return}if((i==="f"||i==="F")&&(E==="tasks"||E==="agents"||E==="goals")&&!Ae){br(l=>{let c=Yr(l);return rn?.(c.label),new Set(c.types)});return}if((i==="n"||i==="N")&&E==="tasks"&&!Ae&&f){Ro();return}if((i==="n"||i==="N")&&E==="agents"&&!Ae&&C){Mo();return}if((i==="n"||i==="N")&&E==="goals"&&!Ae&&Ye){let l=or(de);Qe({title:"New Goal",steps:l,kind:"goal"}),Ee("wizard");return}if((i==="e"||i==="E")&&E==="goals"&&Q&&Ze){let l=la(Q,de);Qe({title:`Edit Goal: ${Q.title}`,steps:l,kind:"edit_goal",targetId:Q.id}),Ee("wizard");return}if((i==="d"||i==="D")&&E==="goals"&&Q&&Ce){Bn("goal",Q.id,Q.title);return}if((i==="c"||i==="C")&&E==="goals"&&Q&&ft){(Q.status==="active"||Q.status==="paused")&&(a(`Marking goal "${Q.title}" as achieved (pending tasks will be cancelled)...`,e.amber),ft(Q.id,"achieved",{force:true}).then(()=>{a(`\u2713 Goal "${Q.title}" achieved`,e.green),K();},l=>a(`Failed: ${l instanceof Error?l.message:String(l)}`,e.red)));return}if((i==="x"||i==="X")&&E==="goals"&&Q&&ft){(Q.status==="active"||Q.status==="paused")&&(a(`Abandoning goal "${Q.title}"...`,e.amber),ft(Q.id,"abandoned").then(()=>{a(`\u2713 Goal "${Q.title}" abandoned`,e.dim),K();},l=>a(`Failed: ${l instanceof Error?l.message:String(l)}`,e.red)));return}if((i==="p"||i==="P")&&E==="goals"&&Q&&ft){let l=Q.status==="paused"?"active":"paused";(Q.status==="active"||Q.status==="paused")&&ft(Q.id,l).then(()=>{a(`Goal "${Q.title}" ${l}`,e.cyan),K();},c=>a(`Failed: ${c instanceof Error?c.message:String(c)}`,e.red));return}if((i==="a"||i==="A")&&E==="tasks"&&j?.status==="review"&&P){a(`Approving "${j.title}"...`,e.amber),P(j.id).then(()=>{a(`\u2713 Approved "${j.title}"`,e.green),K();},l=>a(`Failed: ${l instanceof Error?l.message:String(l)}`,e.red));return}if((i==="x"||i==="X")&&E==="tasks"&&j?.status==="review"&&B){a(`Rejecting "${j.title}"...`,e.amber),B(j.id).then(()=>{a(`\u2713 Rejected "${j.title}" \u2192 todo`,e.green),K();},l=>a(`Failed: ${l instanceof Error?l.message:String(l)}`,e.red));return}if((i==="c"||i==="C")&&E==="tasks"&&j&&h){if(j.status==="done"||j.status==="failed"||j.status==="cancelled"){a(`Cannot cancel \u2014 status is ${j.status}`,e.yellow);return}a(`Cancelling "${j.title}"...`,e.amber),h(j.id).then(()=>{a(`\u2713 Cancelled "${j.title}"`,e.green),K();},l=>a(`Failed: ${l instanceof Error?l.message:String(l)}`,e.red));return}if((i==="e"||i==="E")&&E==="tasks"&&j&&G){Va(j);return}if((i==="e"||i==="E")&&E==="agents"&&Z&&W){ja(Z);return}if((i==="s"||i==="S")&&E==="tasks"){fs(l=>!l),qn(0),In(0);return}if((i==="g"||i==="G")&&E==="tasks"&&!Ae){Ea(l=>!l),qn(0),In(0);return}if((i==="s"||i==="S")&&E==="agents"&&Z&&w){if(!Object.values(ze.running).some(c=>c.agent_id===Z.id)&&Z.status!=="running"){a(`Agent "${Z.name}" is not running`,e.yellow);return}a(`Force-stopping agent "${Z.name}"...`,e.amber),w(Z.id).then(()=>{a(`\u2713 Stopped agent "${Z.name}"`,e.green),K();},c=>a(`Failed: ${c instanceof Error?c.message:String(c)}`,e.red));return}if((i==="d"||i==="D")&&E==="tasks"&&j&&j.status!=="in_progress"&&H){Bn("task",j.id,j.title);return}if((i==="d"||i==="D")&&E==="agents"&&Z&&z){let l=Object.values(ze.running).some(c=>c.agent_id===Z.id);if(l&&!w){a(`Cannot delete \u2014 agent "${Z.name}" is running. Press S to stop first.`,e.yellow);return}Bn("agent",Z.id,Z.name,{needsForceStop:l});return}if((i==="u"||i==="U")&&E==="agents"&&Z&&gt){let l=!Z.autonomous;a(`${l?"Enabling":"Disabling"} autonomous mode for "${Z.name}"...`,e.amber),gt(Z.id,l).then(()=>{a(`${xn} ${Z.name} autonomous ${l?"ON":"OFF"}`,e.cyan),K();},c=>a(`Failed: ${c instanceof Error?c.message:String(c)}`,e.red));return}if(!Ae){if(i==="g"||i==="G"){Sn("goals");return}if(i==="t"||i==="T"){Sn("tasks");return}if(i==="a"||i==="A"){Sn("agents");return}if(i==="l"||i==="L"){Sn("logs");return}}if(!Ae){let l=Do.map(u=>u.id),c=l.indexOf(E);if(x.tab||x.rightArrow){Sn(l[(c+1)%l.length]);return}if(x.leftArrow){Sn(l[(c+l.length-1)%l.length]);return}}if(x.return){let l=An>0?Et.length:-1;if(E==="tasks"&&bo===l){fs(u=>!u),qn(0),In(0);return}let c=Et.length+(An>0?1:0);if(E==="tasks"&&bo===c&&f){Ro();return}if(E==="goals"&&mr===pt.length&&Ye){let u=or(de);Qe({title:"New Goal",steps:u,kind:"goal"}),Ee("wizard");return}if(E==="agents"&&gr===Ne.length&&C){Mo();return}if(E==="goals"&&Q){Kn(u=>!u),to(0);return}if(E==="tasks"&&j){Kn(u=>!u);return}if(E==="agents"&&Z){Kn(u=>!u);return}if(E==="logs"&&Jn>=0){Kn(u=>!u);return}}if((i==="r"||i==="R")&&E==="tasks"&&j&&s){if(!Kr.has(j.status)){a(`Cannot run "${j.title}" \u2014 status is ${j.status}`,e.yellow);return}a(`Running "${j.title}"...`,e.green),s(j.id).then(()=>{a(`Dispatched "${j.title}"`,e.green),K();},l=>a(`Failed to run: ${l instanceof Error?l.message:String(l)}`,e.red));return}if(x.upArrow||i==="k"){if(E==="goals"&&Ae){to(l=>Math.max(0,l-1));return}E==="goals"?ns(l=>{let c=Math.max(0,l-1);return Sr(u=>c<u?c:u),c}):E==="tasks"?qn(l=>{let c=Math.max(0,l-1);return In(u=>c<u?c:u),c}):E==="agents"?ts(l=>{let c=Math.max(0,l-1);return wr(u=>c<u?c:u),c}):E==="logs"&&xr(l=>{if(l===-1){let u=Ve.length-1;return Qn(Math.max(0,u-Se+2)),Math.max(0,u)}let c=Math.max(0,l-1);return Qn(u=>c<u?c:u),c});}if(x.downArrow||i==="j"){if(E==="goals"&&Ae){to(l=>l+1);return}if(E==="goals"){let l=pt.length+(Ye?1:0)-1;ns(c=>{let u=Math.min(Math.max(0,l),c+1);return Sr(b=>u>=b+Se?u-Se+1:b),u});}else if(E==="tasks"){let l=Et.length+(f?1:0)+(An>0?1:0)-1;qn(c=>{let u=Math.min(Math.max(0,l),c+1);return In(b=>u>=b+Se?u-Se+1:b),u});}else if(E==="agents"){let l=Ne.length+(C?1:0)-1;ts(c=>{let u=Math.min(Math.max(0,l),c+1);return wr(b=>u>=b+Se?u-Se+1:b),u});}else E==="logs"&&xr(l=>{if(l===-1)return -1;let c=Ve.length-1;if(l>=c)return Qn(0),-1;let u=l+1;return Qn(b=>u>=b+Se-1?u-Se+2:b),u});}}});let st=Pe!=="none",Is=Jn>=0?Ve[Jn]:void 0,Ao=Co?"+/- exit max":"+/- resize \u2502 M max",vs=!st&&Ae&&E==="tasks"&&j,_s=!st&&Ae&&E==="agents"&&Z,Ms=!st&&Ae&&E==="goals"&&Q,rl=!st&&Ae&&E==="logs"&&Is,Rr=j?.id,sl=useMemo(()=>Rr?Ve.filter(i=>i.taskId===Rr):[],[Ve,Rr]),il=!st&&E==="tasks"&&j&&Kr.has(j.status)&&!!s,al=!st&&!Ae&&(E==="goals"&&!!Ye||E==="tasks"&&!!f||E==="agents"&&!!C),ll=!st&&E==="tasks"&&j?.status==="review"&&!!P,cl=!st&&E==="tasks"&&j?.status==="review"&&!!B,dl=Z?Object.values(ze.running).some(i=>i.agent_id===Z.id):false,ul=!st&&(E==="goals"&&Q&&!!Ce||E==="tasks"&&j&&j.status!=="in_progress"&&!!H||E==="agents"&&Z&&!!z),gl=!st&&!Ae&&(E==="goals"&&!!Q&&!!Ze||E==="tasks"&&!!j&&!!G||E==="agents"&&!!Z&&!!W),ml=!st&&E==="agents"&&Z&&(dl||Z.status==="running")&&!!w,fl=!st&&E==="agents"&&!!Z&&!!gt,pl=!st&&E==="goals"&&!!Q&&(Q.status==="active"||Q.status==="paused")&&!!ft,hl=!st&&_n.length>0,Rs=Pe==="command"&&Mt.length>0,As=bt?.kind==="task"||bt?.kind==="edit_task";return jsxs(Box,{flexDirection:"column",width:ae,height:ue,children:[jsx(ni,{projectName:t,activeView:E,mode:Mr,stats:Cs,tokens:Ka,uptime:qa,width:ae,version:sn,latestVersion:cn,updateInstalled:N,taskBadge:An>0?Oe.length:void 0,flashTab:yr?.tab,flashColor:yr?.color,onFlashComplete:yr?()=>cs(void 0):void 0}),jsx(Box,{height:1}),Bt&&jsx(Pi,{width:ae,height:ue-7}),!Bt&&Yt==="welcome"&&E==="tasks"&&jsx(ki,{width:ae,height:ue}),!Bt&&E==="goals"&&jsx(Jc,{goals:pt,selectedIndex:mr,scrollOffset:La,height:Se,width:Me,showAddRow:!!Ye,agentNameMap:mn,tasksByGoalMap:Na}),!Bt&&Yt!=="welcome"&&E==="tasks"&&jsx(ed,{tasks:Et,selectedIndex:bo,scrollOffset:Ba,height:Se,width:Me,showAddRow:!!f,agentNameMap:mn,hiddenCount:An,goalMap:Rn,groupByGoal:eo}),!Bt&&E==="tasks"&&(Yt==="task_created"||Yt==="run_started")&&jsx(Ci,{step:Yt,width:ae}),!Bt&&E==="tasks"&&Yt==="completed"&&jsx(Ii,{width:ae}),!Bt&&E==="agents"&&jsx(td,{agents:Ne,selectedIndex:gr,scrollOffset:Oa,height:Se,width:Me,state:ze,taskTitleMap:no,showAddRow:!!C,agentTeamMap:$n,teamLeadSet:Fa,activeTeamCount:oo}),!Bt&&E==="logs"&&jsxs(Fragment,{children:[jsx(od,{messages:Ve,height:kn||Zn?Math.max(3,Se-16):Se,agents:Ne,logAgentFilter:rs,logTypeFilter:ss,selectedIndex:Jn,scrollOffset:va,agentNameMap:mn,agentColorMap:vo,agentMsgCounts:xs,taskTitleMap:no,width:Me}),kn&&jsx(Box,{paddingX:2,children:jsx(bi,{agents:Ne,selected:rs,msgCounts:xs,colorMap:vo,maxHeight:Math.min(Se-4,18),onConfirm:i=>{Ia(i),pr(false);},onCancel:()=>pr(false)})}),Zn&&jsx(Box,{paddingX:2,children:jsx(Si,{selected:ss,typeCounts:Da,onConfirm:i=>{is(i),hr(false);},onCancel:()=>hr(false)})})]}),jsx(Box,{height:1}),Bt?null:Pe==="wizard"&&bt?jsx(pi,{title:bt.title,steps:bt.steps,onComplete:Ha,onCancel:Ua,width:Me,height:Ot,onPasteImage:As?za:void 0,onSuggestionSelected:bt.kind==="agent"?Xa:void 0,footerExtra:un.length>0&&As?`\u{1F4CE}${un.length}`:void 0},`${bt.kind}-${bt.title}`):Rs?jsxs(Fragment,{children:[jsx(rr,{label:"COMMANDS",width:Me}),jsx(Zc,{suggestions:Mt,selectedIndex:Io,height:Math.min(Mt.length,Ot),width:Me})]}):Pe==="new_task"?jsxs(Fragment,{children:[jsx(dd,{mode:Pe,width:Me}),jsx(ud,{mode:Pe,cursor:xt.cursor,width:Me})]}):vs?jsxs(Fragment,{children:[jsx(id,{task:j,width:Me,resizeHint:Ao}),jsx(Qs,{task:j,height:Ot,width:Me,taskLogs:sl,agentNameMap:mn,taskTitleMap:no})]}):Ms?jsxs(Fragment,{children:[jsx(rr,{label:`GOAL: ${Q.title}`,width:Me,suffixLen:Ao.length+2,suffix:jsxs(Text,{color:e.dim,children:[" ",Ao," "]})}),jsx(Qc,{goal:Q,height:Ot,width:Me,agentNameMap:mn,tasks:Wa,progressReport:Ca,scrollOffset:Pa,onClampScroll:to})]}):_s?jsxs(Fragment,{children:[jsx(ad,{agent:Z,width:Me,resizeHint:Ao}),jsx(ld,{agent:Z,height:Ot,state:ze,taskTitleMap:no,teamName:$n.get(Z.id)})]}):rl?jsxs(Fragment,{children:[jsx(rr,{label:"LOG",width:Me}),jsx(sd,{message:Is,height:Ot,width:Me,agents:Ne,agentNameMap:mn,agentColorMap:vo,taskTitleMap:no})]}):Ve.length>0&&E!=="logs"?jsxs(Fragment,{children:[(()=>{let i=` F:${To.toUpperCase()} \u2502 ${Tr.length}/${Ve.length}`;return jsx(rr,{label:"ACTIVITY",width:Me,suffixLen:i.length,suffix:jsxs(Fragment,{children:[jsx(Text,{color:e.dim,children:" F:"}),jsx(Text,{color:e.amber,children:To.toUpperCase()}),jsxs(Text,{color:e.ghost,children:[" ","\u2502"," ",Tr.length,"/",Ve.length]})]})})})(),jsx(rd,{messages:Tr,height:Math.max(1,Ot-1),width:Me,agents:Ne,agentNameMap:mn,agentColorMap:vo})]}):E==="goals"?jsx(Jo,{count:pt.length,config:_i,width:Me}):E==="tasks"?jsx(Jo,{count:Oe.length,config:Mi,width:Me}):E==="agents"?jsx(Jo,{count:Ne.length,config:Ri,width:Me}):null,jsx(Box,{flexGrow:1}),jsx(Li,{toasts:Ra,onDismiss:$a}),_n.length>0&&jsx(Yc,{deletions:_n,width:ae}),jsx(ri,{mode:Pe==="command"?"command":"navigate",value:Pe==="command"?dn:"",completion:Pe==="command"?Nr(dn):null,activeView:E,canRun:!!il,canNew:!!al,canApprove:!!ll,canReject:!!cl,canCancel:E==="tasks"&&!!j&&j.status==="in_progress"&&!!h,canDelete:!!ul,canUndo:!!hl,canEdit:!!gl,canForceStop:!!ml,canToggleAuto:!!fl,autoActive:Z?.autonomous,canPause:!!pl,isPaused:Q?.status==="paused",canToggleShowAll:E==="tasks"&&Oe.length>da,showAllActive:ms,hasDetail:!!(vs||_s||Ms),itemCount:E==="goals"?pt.length:E==="tasks"?Oe.length:E==="agents"?de.length:Ve.length,itemLabel:E==="goals"?"goals":E==="tasks"?"tasks":E==="agents"?"agents":"events",width:ae,hasSuggestions:Rs,onboardingCompleted:r.onboardingCompleted})]})}var Yc=uo.memo(function({deletions:n,width:o}){let[,r]=useState(0);useEffect(()=>{let f=setInterval(()=>r(h=>h+1),1e3);return ()=>clearInterval(f)},[]);let s=Date.now();return jsx(Box,{flexDirection:"column",width:o,children:n.map(f=>{let h=Math.max(0,Math.ceil((f.expiresAt-s)/1e3)),y=Math.max(0,o-4),m=f.entityType==="task"?"Task":f.entityType==="agent"?"Agent":"Goal",T=Math.max(10,y-m.length-30),S=f.entityName.length>T?f.entityName.slice(0,T-1)+"\u2026":f.entityName;return jsx(Box,{paddingX:2,children:jsxs(Text,{color:e.yellow,children:["\u2717 ",jsx(Text,{bold:true,children:m}),` "${S}" \u2014 `,jsxs(Text,{color:e.amber,bold:true,children:[h,"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 Zc({suggestions:t,selectedIndex:n,height:o,width:r}){let s=o,f=0;n>=s&&(f=n-s+1);let h=t.slice(f,f+s);return jsx(Box,{flexDirection:"column",paddingX:2,children:h.map((y,m)=>{let T=m+f,S=T===n,I=S?"\u25B6":" ",M=Math.min(20,Math.max(14,...t.map(C=>C.cmd.length+1))),v=y.cmd.padEnd(M),L=y.subs?` ${y.subs}`:"",_=Math.max(4,r-M-L.length-8),R=y.desc.length>_?y.desc.slice(0,_-1)+"\u2026":y.desc;return jsxs(Text,{wrap:"truncate",children:[jsx(Text,{color:S?e.amber:e.ghost,children:` ${I} `}),jsx(Text,{color:S?e.white:e.silver,bold:S,children:v}),jsx(Text,{color:e.dim,children:R}),L&&jsx(Text,{color:e.ghost,children:L})]},T)})})}function Jc({goals:t,selectedIndex:n,scrollOffset:o=0,height:r,width:s,showAddRow:f,agentNameMap:h,tasksByGoalMap:y}){let m=t.length,T=t.slice(o,o+r),S=f&&m>=o&&m<o+r;return jsxs(Box,{flexDirection:"column",height:r,children:[T.map((I,M)=>jsx(Box,{paddingX:2,children:jsx(Js,{goal:I,selected:M+o===n,width:s-2,agentNameMap:h,tasksByGoal:y?.get(I.id)})},I.id)),S&&jsx(Box,{paddingX:2,children:jsxs(Text,{color:n===m?e.amber:e.ghost,children:[n===m?" \u25B8 ":" ",jsx(Text,{color:n===m?e.amber:e.dim,children:"+ add goal..."})]})},"__add__")]})}function Qc({goal:t,height:n,width:o,agentNameMap:r,tasks:s,progressReport:f,scrollOffset:h=0,onClampScroll:y}){let T=uo.useMemo(()=>{let _=s??[],R=t.assignee?r?.get(t.assignee)??t.assignee:"\u2014",C=Math.max(20,o-6),z=(w,U)=>{if(w.length<=U)return [w];let ie=[];for(let oe=0;oe<w.length;oe+=U)ie.push(w.slice(oe,oe+U));return ie},P=Or(f)?.split(`
13
+ `).flatMap(w=>z(w,C))??[],B=Or(t.description)?.split(`
14
+ `).flatMap(w=>z(w,C))??[],H=Ns[t.status]??e.dim,G=new Map;for(let w of _)G.set(w.status,(G.get(w.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:H,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:R})]})]})}),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)})]})]})}),_.length>0){let w=[];for(let[U,ie]of G)w.push(`${ie} ${U}`);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:_.length})]}),jsxs(Box,{children:[jsx(Text,{color:e.dim,children:" "}),jsx(Text,{color:e.dim,children:w.join(" \xB7 ")})]})]})});}if(B.length>0){W.push({key:"desc-gap",node:jsx(Text,{children:" "})});for(let w=0;w<B.length;w++)W.push({key:`desc-${w}`,node:jsxs(Text,{color:e.silver,wrap:"truncate",children:[" ",B[w]]})});}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(P.length>0){W.push({key:"prog-gap",node:jsx(Text,{children:" "})}),W.push({key:"prog-div",node:jsx(Fn,{label:"progress",width:o})});for(let w=0;w<P.length;w++)W.push({key:`prog-${w}`,node:jsxs(Text,{color:e.white,wrap:"truncate",children:[" ",P[w]]})});}if(_.length>0){W.push({key:"tasks-gap",node:jsx(Text,{children:" "})}),W.push({key:"tasks-div",node:jsx(Fn,{label:`tasks (${_.length})`,width:o})});for(let w of _){let U=Oo[w.status]??e.dim;W.push({key:`task-${w.id}`,node:jsxs(Text,{color:e.silver,wrap:"truncate",children:[" ",jsx(Text,{color:U,children:w.status.padEnd(12)}),w.title.slice(0,Math.max(10,o-22))]})});}}return W},[t,s,f,o,r]),S=Math.max(0,T.length-n),I=Math.min(h,S);uo.useEffect(()=>{y&&I!==h&&y(I);},[I,h,y]);let M=T.length>n&&I<S,v=M?n-1:n,L=T.slice(I,I+v);return jsxs(Box,{flexDirection:"column",height:n,paddingX:2,children:[L.map(_=>jsx(Box,{children:_.node},_.key)),M&&jsxs(Text,{color:e.ghost,children:[" ","\u2193"," ",T.length-I-v," more ","\u2014"," ","\u2191","\u2193"," to scroll"]})]})}function ed({tasks:t,selectedIndex:n,scrollOffset:o=0,height:r,width:s,showAddRow:f,agentNameMap:h,hiddenCount:y=0,goalMap:m,groupByGoal:T=false}){let S=y>0,I=S?t.length:-1,M=t.length+(S?1:0),v=t.slice(o,o+r),L=S&&I>=o&&I<o+r,_=f&&M>=o&&M<o+r,R=useMemo(()=>{if(!T||!m||m.size===0)return null;let H=new Map;for(let G of t)if(G.goalId&&m.has(G.goalId)){let W=H.get(G.goalId)??{total:0,done:0};W.total++,G.status==="done"&&W.done++,H.set(G.goalId,W);}return H},[t,T,m]),C=T&&m?t.filter(H=>!H.goalId||!m.has(H.goalId)).length:0,z=T&&m&&m.size>0&&R&&R.size>0,P=[],B=o>0?t[o-1]?.goalId??null:void 0;for(let H=0;H<v.length&&P.length<r;H++){let G=v[H],W=G.goalId&&m?.has(G.goalId)?G.goalId:null;if(z){if(W&&W!==B){let w=m.get(W),U=R.get(W)??{total:0,done:0};if(P.push(jsx(Vs,{goalTitle:w.title,taskCount:U.total,doneCount:U.done,width:s},`gh_${W}`)),P.length>=r)break}if(!W&&B!==null&&B!==void 0&&(P.push(jsx(js,{taskCount:C,width:s},"__ungrouped__")),P.length>=r))break}B=W,P.push(jsx(Box,{paddingX:2,children:jsx(No,{task:G,selected:H+o===n,width:s-2,agentNameMap:h,goalMap:m})},G.id));}return L&&P.length<r&&P.push(jsx(Box,{paddingX:2,children:jsxs(Text,{color:n===I?e.amber:e.ghost,children:[n===I?" \u25B8 ":" ",jsxs(Text,{color:n===I?e.amber:e.dim,children:["\u25BC"," Show all (",y," more) \u2014 press ",jsx(Text,{bold:true,color:e.gray,children:"S"})]})]})},"__show_all__")),_&&P.length<r&&P.push(jsx(Box,{paddingX:2,children:jsxs(Text,{color:n===M?e.amber:e.ghost,children:[n===M?" \u25B8 ":" ",jsx(Text,{color:n===M?e.amber:e.dim,children:"+ add task..."})]})},"__add__")),jsx(Box,{flexDirection:"column",height:r,children:P})}function td({agents:t,selectedIndex:n,scrollOffset:o=0,height:r,width:s,state:f,taskTitleMap:h,showAddRow:y,agentTeamMap:m,teamLeadSet:T,activeTeamCount:S}){let I=new Map;for(let G of Object.values(f.running))I.set(G.agent_id,G);let M=new Map;if(S&&S>0)for(let G of t){let W=m?.get(G.id);W&&M.set(W,(M.get(W)??0)+1);}let v=t.length,L=t.slice(o,o+r),_=y&&v>=o&&v<o+r,R=S!=null&&S>0,C=new Map;if(R&&T&&m){for(let G of t)if(T.has(G.id)){let W=m.get(G.id);W&&C.set(W,G.name);}}let z=0;for(let G of M.values())z+=G;let P=t.length-z,B=[],H=o>0?m?.get(t[o-1]?.id??""):void 0;for(let G=0;G<L.length&&B.length<r;G++){let W=L[G],w=m?.get(W.id);if(R&&w&&w!==H&&(B.push(jsx(qs,{teamName:w,memberCount:M.get(w)??0,leadName:C.get(w),width:s},`ts-${w}`)),B.length>=r)||R&&!w&&H&&(B.push(jsx(Ks,{memberCount:P,width:s},"ts-unassigned")),B.length>=r))break;H=w,B.push(jsx(Box,{paddingX:2,children:jsx(Xs,{agent:W,selected:G+o===n,width:s-2,runningEntry:I.get(W.id),currentTaskTitle:W.current_task?h.get(W.current_task):void 0,teamName:w,isLead:T?.has(W.id)})},W.id));}return _&&B.length<r&&B.push(jsx(Box,{paddingX:2,children:jsxs(Text,{color:n===v?e.amber:e.ghost,children:[n===v?" \u25B8 ":" ",jsx(Text,{color:n===v?e.amber:e.dim,children:"+ add agent..."})]})},"__add__")),jsx(Box,{flexDirection:"column",height:r,children:B})}function ba(t=5e3){let[n,o]=useState(Date.now());return useEffect(()=>{let r=setInterval(()=>o(Date.now()),t);return ()=>clearInterval(r)},[t]),n}function Ta(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 nd(t){if(t==="error")return e.errorBg}function ya(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 od({messages:t,height:n,agents:o,logAgentFilter:r,logTypeFilter:s,selectedIndex:f,scrollOffset:h,agentNameMap:y,agentColorMap:m,agentMsgCounts:T,taskTitleMap:S,width:I}){let M=ba(),v=useMemo(()=>t.filter(U=>{if(r.size>0&&U.agentId&&!r.has(U.agentId))return false;let ie=U.msgType??"info";return s.has(ie)}),[t,r,s]);useMemo(()=>{let U={};for(let ie of t){let oe=ie.msgType??"info";U[oe]=(U[oe]??0)+1;}return U},[t]);let _=s.size>=8?"all":s.size===1&&s.has("output")?"text":s.size===1&&s.has("error")?"errors":s.has("tool")&&!s.has("output")?"tools":s.has("lifecycle")&&!s.has("output")?"events":`${s.size} types`,R=r.size>0,C=n-2,z=f===-1?v.slice(-C):v.slice(h,h+C),P=f===-1?-1:f-h,B=Math.min(10,Math.max(6,...o.map(U=>U.name.length))),H=11+B,G=U=>{if(U===0)return true;let ie=z[U],oe=z[U-1];return ie.agentId!==oe.agentId?true:ie.agentId?ie.ts-oe.ts>3e4:false},W=Math.max(4,Math.floor((I-20)/Math.max(1,o.length))-1),w=Math.min(W,10);return jsxs(Box,{flexDirection:"column",paddingX:1,children:[jsxs(Box,{gap:0,justifyContent:"space-between",width:I,children:[jsxs(Box,{gap:0,children:[f===-1?jsxs(Box,{gap:0,children:[jsx(Text,{backgroundColor:e.successBg,color:e.green,children:" "}),jsx(Text,{backgroundColor:e.successBg,color:e.green,children:jsx(Ht,{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,"/",v.length," "]}),jsxs(Text,{color:e.dim,children:[" ",v.length," events"]}),_!=="all"&&jsxs(Text,{color:e.amber,children:[" f:",_]}),R&&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(U=>{let ie=m.get(U.id)??Jr[0],oe=r.size===0||r.has(U.id),we=U.name.length>w?U.name.slice(0,w-1)+"\u2026":U.name;return jsxs(Text,{color:oe?ie:e.ghost,bold:oe,children:[" ",we]},U.id)})}),z.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"})]})]}):z.map((U,ie)=>{let oe=ie===P,we=U.msgType??"info",We=Hn[we]??"\u2502",Ge=U.agentId?y.get(U.agentId)??U.agentId.slice(0,8):void 0,ut=U.agentId?m.get(U.agentId):void 0,Ct=G(ie),mt=(ie>0?z[ie-1]:void 0)?.agentId===U.agentId&&!!U.agentId,Ye=!mt&&!!Ge,Ze=mt&&!!Ge,ft=ya(we,U.color),Ce=oe?e.infoBg:we==="error"?e.errorBg:void 0,Wt=U.taskId?S.get(U.taskId):void 0,It=Ta(U.ts,M),ht=Wt&&I>80?`#${Wt.slice(0,20)}`:"",Je=ht?ht.length+3:0,ot=Math.max(10,I-2-H-Je),Xe=it(U.text,ot);return jsxs(Box,{backgroundColor:Ce,children:[jsx(Text,{color:ut??e.ghost,children:Ct&&Ye?"\u250C":Ze?"\u2502":" "}),jsx(Text,{color:oe?e.amber:void 0,children:oe?"\u25B8":" "}),jsx(Box,{width:5,children:jsx(Text,{color:It==="now"?e.green:oe?e.silver:e.ghost,children:It.padStart(4)})}),jsx(Box,{width:B+1,children:Ye?jsxs(Text,{color:ut,bold:true,children:[" ",Ge.slice(0,B).padEnd(B)]}):Ze?jsxs(Text,{color:ut??e.ghost,children:[" ","\xB7".padEnd(B)]}):jsxs(Text,{color:e.ghost,children:[" "," ".padEnd(B)]})}),jsxs(Text,{color:we==="error"?e.red:ut??e.dim,children:[" ",We," "]}),jsx(Text,{color:oe?e.white:ft,bold:oe||we==="lifecycle",children:Xe}),ht&&jsxs(Text,{color:e.ghost,children:[" ",jsx(Text,{color:e.dim,backgroundColor:e.void,children:` ${ht} `})]})]},ie)})]})}function rd({messages:t,height:n,width:o,agents:r,agentNameMap:s,agentColorMap:f}){let h=ba(),y=t.slice(-n),m=Math.max(10,o-2-17),T=Math.max(0,n-y.length),S=0,I=[];for(let M=0;M<y.length;M++)M>0&&y[M].agentId!==y[M-1].agentId&&S++,I.push(S);return jsxs(Box,{flexDirection:"column",paddingX:1,children:[T>0&&jsx(Box,{height:T}),y.map((M,v)=>{let L=M.agentId?s.get(M.agentId)??M.agentId.slice(0,8):void 0,_=M.agentId?f.get(M.agentId):void 0,R=M.msgType??"info",C=Hn[R]??"\u2502",z=ya(R,M.color),B=(v>0?y[v-1]:void 0)?.agentId===M.agentId&&!!M.agentId,H=(I[v]&1)===1,G=nd(R)??(H?"#1a1a1a":void 0),W=Ta(M.ts,h),w=it(M.text,m);return jsxs(Box,{backgroundColor:G,children:[jsx(Text,{color:_??e.ghost,children:!B&&L?"\u258D":B?"\u258F":" "}),jsx(Box,{width:5,children:jsx(Text,{color:B?e.ghost:W==="now"?e.green:e.dim,children:B?" ":W.padStart(4)})}),jsx(Box,{width:9,children:L&&!B?jsxs(Text,{color:_,bold:true,children:[" ",L.slice(0,8)]}):jsx(Text,{color:e.ghost,children:Kc})}),jsxs(Text,{color:R==="error"?e.red:B?e.ghost:_??e.dim,children:[C," "]}),jsx(Text,{color:z,children:w})]},v)})]})}function sd({message:t,height:n,width:o,agents:r,agentNameMap:s,agentColorMap:f,taskTitleMap:h}){let y=t.detail??t.text,m=t.msgType??"info",T=t.agentId?s.get(t.agentId)??t.agentId.slice(0,8):void 0,S=t.agentId?f.get(t.agentId):e.dim,I=t.taskId?h.get(t.taskId):void 0,M,v=false;try{let C=JSON.parse(y);M=JSON.stringify(C,null,2),v=!0;}catch{M=y;}let L=Math.max(4,o-6),_=Math.max(1,n-4),R=M.split(`
15
+ `).slice(0,_);return jsxs(Box,{flexDirection:"column",paddingX:1,children:[jsx(Box,{children:jsxs(Text,{color:e.ghost,children:["\u256D",Te(L+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 "}),T&&jsx(Text,{color:S,bold:true,children:T}),T&&jsx(Text,{color:e.ghost,children:" \u2502 "}),jsxs(Text,{color:Hn[m]?m==="error"?e.red:e.dim:e.dim,children:[Hn[m]??"\u2502"," ",m]}),I&&jsxs(Fragment,{children:[jsx(Text,{color:e.ghost,children:" \u2502 "}),jsxs(Text,{color:e.dim,children:["#",I.slice(0,30)]})]})]}),jsxs(Box,{children:[jsx(Text,{color:e.ghost,children:"\u2502 "}),jsx(Text,{color:t.color,bold:true,wrap:"truncate",children:t.text.slice(0,L)})]}),jsx(Box,{children:jsxs(Text,{color:e.ghost,children:["\u251C",Te(L+2),"\u2524"]})}),R.map((C,z)=>jsxs(Box,{children:[jsx(Text,{color:e.ghost,children:"\u2502 "}),v&&jsxs(Text,{color:e.ghost,children:[String(z+1).padStart(3)," "]}),jsx(Text,{wrap:"truncate",color:v&&C.includes('"')?e.cyan:v&&/^\s*[}\]]/.test(C)?e.ghost:C.startsWith("error")||C.startsWith("Error")?e.red:e.silver,children:C.slice(0,v?L-4:L)})]},z)),jsx(Box,{children:jsxs(Text,{color:e.ghost,children:["\u2570",Te(L+2),"\u256F"]})})]})}function rr({label:t,width:n,suffix:o,suffixLen:r=0}){let s=` ${t} `,f=3,h=f+s.length+2;if(!o){let T=Math.max(0,n-h);return jsxs(Box,{paddingX:1,children:[jsx(Text,{color:e.ghost,children:He(f)}),jsx(Text,{backgroundColor:"#1a1a22",color:e.dim,bold:true,children:s}),jsx(Text,{color:e.ghost,children:He(T)})]})}let y=2,m=Math.max(0,n-h-y-r);return jsxs(Box,{paddingX:1,children:[jsx(Text,{color:e.ghost,children:He(f)}),jsx(Text,{backgroundColor:"#1a1a22",color:e.dim,bold:true,children:s}),jsx(Text,{color:e.ghost,children:He(y)}),o,jsx(Text,{color:e.ghost,children:He(m)})]})}function id({task:t,width:n,resizeHint:o}){let r=" DETAIL ",s=o?` ${o} `:"",f=n-r.length-s.length-10,h=t.title.length>f?t.title.slice(0,f-3)+"...":t.title,y=Math.max(0,n-3-r.length-h.length-s.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:[Eo," "]}),jsx(Text,{color:e.white,bold:true,children:h}),jsxs(Text,{color:e.ghost,children:[" ",He(Math.max(0,y))]}),s?jsx(Text,{color:e.dim,children:s}):null]})}function ad({agent:t,width:n,resizeHint:o}){let r=" AGENT ",s=o?` ${o} `:"",f=n-r.length-s.length-10,h=t.name.length>f?t.name.slice(0,f-3)+"...":t.name,y=Math.max(0,n-3-r.length-h.length-s.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:[Eo," "]}),jsx(Text,{color:e.green,bold:true,children:h}),jsxs(Text,{color:e.ghost,children:[" ",He(Math.max(0,y))]}),s?jsx(Text,{color:e.dim,children:s}):null]})}function ld({agent:t,height:n$1,state:o,taskTitleMap:r,teamName:s}){let f=cd[t.status]??e.dim;Object.values(o.running).find(T=>T.agent_id===t.id);let y=t.current_task?r.get(t.current_task):void 0,m=24;return jsxs(Box,{flexDirection:"column",paddingX:2,children:[jsxs(Box,{children:[jsxs(Box,{width:m,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:m,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:y?e.white:e.dim,children:y??"\u2014"})]})]}),jsxs(Box,{children:[jsxs(Box,{width:m,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:s?e.amber:e.dim,children:s??"\u2014"})]})]}),t.autonomous&&jsx(Box,{children:jsxs(Box,{width:m,children:[jsx(Text,{color:e.dim,children:" auto "}),jsxs(Text,{color:e.cyan,children:[xn," 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:it(t.config.skills.join(", "),500)})]}),t.last_error&&(()=>{let T=t.last_error.kind,S=n[T],I=!S||T==="unknown",M=t.last_error.timestamp,v=M?g(M)+" 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"]}),S&&jsx(Text,{color:e.white,children:S.message}),S&&jsx(Text,{color:e.cyan,children:S.fix}),S?.doctorHint&&jsx(Text,{color:e.yellow,children:"\u0414\u0438\u0430\u0433\u043D\u043E\u0441\u0442\u0438\u043A\u0430: orch doctor"}),I&&t.last_error.message&&jsx(Text,{color:e.dim,children:it(t.last_error.message,120)}),v&&jsx(Text,{color:e.dim,children:v})]})]})})(),jsx(Text,{children:" "}),t.role?t.role.split(`
16
+ `).slice(0,Math.max(1,n$1-(t.last_error?10:4))).map((T,S)=>jsxs(Text,{color:e.silver,wrap:"truncate",children:[" ",it(T,500)]},S)):jsx(Text,{color:e.dim,children:" No role description."})]})}var cd={idle:e.dim,running:e.green,error:e.red,disabled:e.ghost};function dd({mode:t,width:n}){let r=` ${t==="command"?"COMMAND":"NEW TASK"} `,s=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(s)})]})}function ud({mode:t,cursor:n,width:o}){let r=t==="command"?"/ ":"\u25B8 ";return jsx(Box,{paddingX:2,children:jsx(Ho,{cursor:n,width:Math.max(10,o-4),prefix:r})})}function wa(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 sr(t,n=200){if(typeof t=="string")return t.slice(0,n);if(!Array.isArray(t))return null;let o=[],r=0;for(let s of t){if(r>=n)break;if(s?.type==="text"&&typeof s.text=="string"){let f=s.text.split(`
17
+ `).find(h=>h.trim().length>0)??"";o.push(f.slice(0,n-r)),r+=f.length;}else if(s?.type==="tool_use"){let f=wa(s.name??"tool",s.input),h=`\u2699 ${s.name??"tool"}(${f})`;o.push(h),r+=h.length;}else if(s?.type==="tool_result")o.push("\u2190 (result)"),r+=10;else if(s?.type==="thinking"&&typeof s.thinking=="string"){let f=s.thinking.slice(0,60).split(`
18
+ `)[0]??"";o.push(`\u{1F4AD} ${f}`),r+=f.length+3;}}return o.length>0?o.join(" "):null}function fa(t){if(typeof t=="string"){let o=t.split(`
19
+ `),r=o.find(s=>/\S/.test(s))??"";return o.length>3?`${r.slice(0,80)}... (${o.length} 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 s=o.is_error,f=typeof o.content=="string"?o.content:"",h=f.split(`
21
20
  `).length;s?n.push(`\u2715 error: ${f.slice(0,60)}`):h>3?n.push(`\u2713 ${h} lines`):n.push(`\u2713 ${f.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 wa(t){let n=()=>t.length>ar?t.slice(0,ar)+"\u2026":t;if(pa.test(t.trim()))return {summary:t.trim(),detail:n()};try{let o=JSON.parse(t);if(o.type==="message"&&o.role==="assistant"){let r=rr(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,s=rr(r);return s?{summary:s.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 ${ma(r).slice(0,180)}`,detail:n()}}if(o.type==="tool_use"||typeof o.name=="string"&&"input"in o){let r=o.name??"tool",s=ya(r,o.input);return {summary:`\u2699 ${r}(${s})`,detail:n()}}if(o.type==="tool_result")return {summary:`\u2190 ${ma(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,s=rr(r);if(s)return {summary:s.slice(0,200),detail:n()}}return {summary:`[${o.subtype}]`,detail:n()}}if(o.content){let r=rr(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:ud(t),detail:n()}}}function ud(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*"([^"]+)"/),s=o?.[1],f=r?.[1];if(!s&&!f)return t.slice(0,200);if(s==="assistant"||s==="message"||f==="assistant"){let h=t.match(/"text"\s*:\s*"((?:[^"\\]|\\.)*)"/);if(h)try{return JSON.parse(`"${h[1]}"`).slice(0,200)}catch{}return "\u{1F4AC} (assistant)"}if(s==="user"||s==="tool_result"||f==="user")return "\u2190 (tool result)";if(s==="tool_use")return `\u2699 ${t.match(/"name"\s*:\s*"([^"]+)"/)?.[1]??"tool"}()`;if(s==="result"){let h=t.match(/"result"\s*:\s*"((?:[^"\\]|\\.)*)"/);if(h)try{return `\u2713 ${JSON.parse(`"${h[1]}"`).slice(0,180)}`}catch{}return "\u2713 Agent finished"}return s==="rate_limit_event"?"\u23F3 Rate limited":`[${s??f}]`}function gd(t,n,o,r){let s=f=>r?.get(f);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:f,detail:h}=wa(t.data);if(f){let y=ha(f);n(f,y.color,{agentId:t.agentId,taskId:s(t.runId),detail:h,msgType:y.msgType});}break}case "agent:file_changed":n(`${t.path}`,e.purple,{agentId:t.agentId,taskId:s(t.runId),msgType:"file"});break;case "agent:completed":n(t.success?"Completed successfully":"Failed",t.success?e.green:e.red,{agentId:t.agentId,taskId:s(t.runId),msgType:"lifecycle"});break;case "agent:error":n(`${t.error.slice(0,150)}`,e.red,{agentId:t.agentId,taskId:s(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:s(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:s(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{jg as App,Vg as _resetPendingDeletionSeq};
21
+ `)[0]?.slice(0,80)??"");return n.join(" ")||"(result)"}function ir(t,n){return t.indexOf(`
22
+ `)===-1?t.slice(0,n):(t.split(`
23
+ `).find(o=>/\S/.test(o))??t).slice(0,n)}function Sa(t){let n=()=>t.length>cr?t.slice(0,cr)+"\u2026":t;if(ha.test(t.trim()))return {summary:t.trim(),detail:n()};try{let o=JSON.parse(t);if(typeof o.text=="string"&&o.text.length>0&&!o.type&&!o.role)return {summary:ir(o.text,200),detail:n()};if(typeof o.command=="string"&&!o.type){let r=typeof o.result=="string"&&o.result?` \u2192 ${ir(o.result,80)}`:"";return {summary:`$ ${o.command.slice(0,120)}${r}`,detail:n()}}if(Array.isArray(o.paths)&&o.paths.length>0&&!o.type)return {summary:`${Hn.file} ${o.paths.join(", ").slice(0,180)}`,detail:n()};if(typeof o.message=="string"&&!o.role&&!o.content&&!o.subtype)return {summary:`${Hn.error} ${ir(o.message,200)}`,detail:n()};if(typeof o.result=="string"&&!o.type)return {summary:`\u2713 ${ir(o.result,200)}`,detail:n()};if(o.type==="message"&&o.role==="assistant"){let r=sr(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,s=sr(r);return s?{summary:s.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 ${fa(r).slice(0,180)}`,detail:n()}}if(o.type==="tool_use"||typeof o.name=="string"&&"input"in o){let r=o.name??"tool",s=wa(r,o.input);return {summary:`\u2699 ${r}(${s})`,detail:n()}}if(o.type==="tool_result")return {summary:`\u2190 ${fa(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,s=sr(r);if(s)return {summary:s.slice(0,200),detail:n()}}return {summary:`[${o.subtype}]`,detail:n()}}if(o.content){let r=sr(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:gd(t),detail:n()}}}function gd(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*"([^"]+)"/),s=o?.[1],f=r?.[1];if(!s&&!f)return t.slice(0,200);if(s==="assistant"||s==="message"||f==="assistant"){let h=t.match(/"text"\s*:\s*"((?:[^"\\]|\\.)*)"/);if(h)try{return JSON.parse(`"${h[1]}"`).slice(0,200)}catch{}return "\u{1F4AC} (assistant)"}if(s==="user"||s==="tool_result"||f==="user")return "\u2190 (tool result)";if(s==="tool_use")return `\u2699 ${t.match(/"name"\s*:\s*"([^"]+)"/)?.[1]??"tool"}()`;if(s==="result"){let h=t.match(/"result"\s*:\s*"((?:[^"\\]|\\.)*)"/);if(h)try{return `\u2713 ${JSON.parse(`"${h[1]}"`).slice(0,180)}`}catch{}return "\u2713 Agent finished"}return s==="rate_limit_event"?"\u23F3 Rate limited":`[${s??f}]`}function md(t,n,o,r){let s=f=>r?.get(f);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:f,detail:h}=Sa(t.data);if(f){let y=xa(f);n(f,y.color,{agentId:t.agentId,taskId:s(t.runId),detail:h,msgType:y.msgType});}break}case "agent:file_changed":n(`${t.path}`,e.purple,{agentId:t.agentId,taskId:s(t.runId),msgType:"file"});break;case "agent:completed":n(t.success?"Completed successfully":"Failed",t.success?e.green:e.red,{agentId:t.agentId,taskId:s(t.runId),msgType:"lifecycle"});break;case "agent:error":n(`${t.error.slice(0,150)}`,e.red,{agentId:t.agentId,taskId:s(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:s(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:s(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{Hg as App,jg as _resetPendingDeletionSeq};