@oxgeneral/orch 1.0.8 → 1.0.10
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.
- package/dist/App-TTMII4MJ.js +22 -0
- package/dist/{chunk-4MMHVHA6.js → chunk-LY3X2UHQ.js} +7 -3
- package/dist/{chunk-SWNSNPBO.js → chunk-OLKQBQ4I.js} +110 -24
- package/dist/chunk-OLKQBQ4I.js.map +1 -0
- package/dist/{chunk-UMZEA3JT.js → chunk-XLBV2PFL.js} +1 -1
- package/dist/{chunk-VG4465AG.js → chunk-XUZZJCKG.js} +6 -2
- package/dist/chunk-XUZZJCKG.js.map +1 -0
- package/dist/cli.js +1 -1
- package/dist/{container-SEIWOLHY.js → container-NS3YS47A.js} +1 -1
- package/dist/index.d.ts +18 -0
- package/dist/index.js +6 -6
- package/dist/{init-D4356W7G.js → init-6OVZBN6B.js} +1 -1
- package/dist/orchestrator-47LRXS6X.js +6 -0
- package/dist/{orchestrator-G3Y7THMG.js.map → orchestrator-47LRXS6X.js.map} +1 -1
- package/dist/orchestrator-R23BOZDZ.js +17 -0
- package/dist/run-PX7O3ILN.js +3 -0
- package/dist/serve-FTXAEZE4.js +3 -0
- package/dist/{structured-logger-EXMGTUDB.js → structured-logger-RJ6VF35J.js} +2 -2
- package/dist/{task-3R2IX4HM.js → task-HEPJYY7D.js} +1 -1
- package/dist/{template-engine-42PKL5KD.js → template-engine-VLIOJ3WX.js} +1 -1
- package/dist/template-engine-XOH3FZPU.js +3 -0
- package/dist/{template-engine-5ZKVJMYA.js.map → template-engine-XOH3FZPU.js.map} +1 -1
- package/dist/tui-P6ZOPUMZ.js +2 -0
- package/dist/{update-FFKCOV63.js → update-XGJZFV4H.js} +1 -1
- package/dist/{update-check-HGMBDYHL.js → update-check-CZJC7VW6.js} +1 -1
- package/dist/workspace-manager-DG4IFFG3.js +4 -0
- package/dist/{workspace-manager-RH24FSNT.js → workspace-manager-KUU7UMMC.js} +84 -74
- package/dist/workspace-manager-KUU7UMMC.js.map +1 -0
- package/package.json +1 -1
- package/readme.md +2 -2
- package/dist/App-5OVBVRCD.js +0 -22
- package/dist/chunk-SWNSNPBO.js.map +0 -1
- package/dist/chunk-VG4465AG.js.map +0 -1
- package/dist/orchestrator-G3Y7THMG.js +0 -6
- package/dist/orchestrator-GQLNLOXB.js +0 -17
- package/dist/run-NE5E4JPW.js +0 -3
- package/dist/serve-5OAANN6J.js +0 -3
- package/dist/template-engine-5ZKVJMYA.js +0 -3
- package/dist/tui-47O2OCKC.js +0 -2
- package/dist/workspace-manager-RH24FSNT.js.map +0 -1
- package/dist/workspace-manager-VJ4FN5PJ.js +0 -3
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {b,a as a$2}from'./chunk-HWEMBO36.js';import {a}from'./chunk-N4OXN2HW.js';import {c,a as a$1}from'./chunk-HXOMNULD.js';import {f,h,g}from'./chunk-64WUDYEM.js';import {m}from'./chunk-IKNBPOQL.js';import nn,{useState,useMemo,useEffect,useRef,useCallback}from'react';import {Box,Text,useInput,useApp,useStdout}from'ink';import {jsxs,jsx,Fragment}from'react/jsx-runtime';var e={amber:"#ffaf00",amberDim:"#af8700",green:"#5faf87",red:"#d75f5f",blue:"#5fafd7",yellow:"#d7af00",cyan:"#5fd7d7",purple:"#af87ff",white:"#eeeeee",silver:"#bcbcbc",gray:"#808080",dim:"#585858",ghost:"#3a3a3a",void:"#262626",errorBg:"#3d1515",warnBg:"#3d2e0a",successBg:"#0f2d1f",infoBg:"#1a1a22",toolBg:"#0f1f2d"},vn="\u2501",Ge="\u2500",ue="\xB7",Zt="\u25C8",kr="\u2605",go="\u27F3",Ht="\u25C6",_n={in_progress:e.green,retrying:e.yellow,review:e.blue,todo:e.dim,done:e.green,failed:e.red,cancelled:e.dim},ws=new Map,Ss=new Map;function ze(t){if(t<=0)return "";let o=ws.get(t);return o||(o=vn.repeat(t),ws.set(t,o)),o}function be(t){if(t<=0)return "";let o=Ss.get(t);return o||(o=Ge.repeat(t),Ss.set(t,o)),o}function et(t,o){return t.length>o?t.slice(0,o-1)+"\u2026":t}var Va=1e4;function Cr(t,o=Va){if(t)return t.length>o?t.slice(0,o)+`
|
|
3
|
+
\u2026[truncated]`:t}var ks={active:e.green,paused:e.dim,achieved:e.amber,abandoned:e.ghost};var Ua=120,Ir=0,Qo=null,Rn=new Set;function Xa(){Qo||(Qo=setInterval(()=>{Ir++;for(let t of Rn)t(Ir);},Ua));}function qa(){Qo&&Rn.size===0&&(clearInterval(Qo),Qo=null);}function mo(){let[t,o]=useState(Ir);return useEffect(()=>{let n=r=>o(r);return Rn.add(n),Xa(),()=>{Rn.delete(n),qa();}},[]),t}var Cs=["\u280B","\u2819","\u2839","\u2838","\u283C","\u2834","\u2826","\u2827","\u2807","\u280F"];function $o({color:t}){let o=mo();return jsx(Text,{color:t,children:Cs[o%Cs.length]})}var en={in_progress:0,retrying:1,review:2,todo:3,done:4,failed:5,cancelled:6};var Ja="\u25CB",Ms="\u2713",vs="\u2715",Qa="\u21BB",el="\u2500",tl="\u25B6",Nt={green:"#0f2d1f",blue:"#0f1f2d",yellow:"#2d2a0f",red:"#2d0f0f",neutral:"#1a1a22",amber:"#2d1f0a"},ol={in_progress:{icon:tl,label:"RUN",fg:e.green,bg:Nt.green,bold:true,spinner:true},retrying:{icon:Qa,label:"RETRY",fg:e.yellow,bg:Nt.yellow,spinner:true},review:{icon:Zt,label:"REVIEW",fg:e.blue,bg:Nt.blue},todo:{icon:Ja,label:"TODO",fg:e.dim,bg:Nt.neutral},done:{icon:Ms,label:"DONE",fg:e.green,bg:Nt.green},failed:{icon:vs,label:"FAIL",fg:e.red,bg:Nt.red,bold:true},cancelled:{icon:el,label:"OFF",fg:e.dim,bg:Nt.neutral}},nl={1:{color:e.red,label:"!!!"},2:{color:e.yellow,label:"!!"},3:{color:e.dim,label:"!"},4:{color:e.ghost,label:ue}};var sl=18,il="#2d1f0a",An=nn.memo(function({task:o,selected:n,width:r,agentNameMap:l,goalMap:f$1}){let b=ol[o.status],T=o.status==="in_progress"||o.status==="retrying",x=nl[o.priority]??{color:e.ghost,label:ue},y,I;if(o.status==="done")y=Ms,I=e.green;else if(o.status==="failed")y=vs,I=e.red;else if(T){let E=Date.now()-new Date(o.updated_at).getTime();y=f(E),I=e.cyan;}else y="\u2014",I=void 0;let v=n?"\u25B8":" ",B=o.goalId?f$1?.get(o.goalId):void 0,C=!!B,H=10,V=4,F=14,P=C?sl:0,j=7,L=2+H+V+F+P+j,O=r?Math.max(10,r-L):40,N=o.assignee?l?.get(o.assignee)??o.assignee:void 0;return jsxs(Box,{children:[jsxs(Text,{color:n?e.amber:void 0,children:[v," "]}),jsx(Box,{width:H,children:jsx(Text,{backgroundColor:b.bg,color:b.fg,bold:b.bold,children:b.spinner?jsxs(Fragment,{children:[" ",jsx($o,{color:b.fg})," ",b.label," "]}):jsxs(Fragment,{children:[" ",b.icon," ",b.label," "]})})}),jsx(Box,{width:V,children:jsx(Text,{color:x.color,bold:o.priority<=2,children:x.label})}),jsxs(Box,{width:O,children:[jsx(Text,{wrap:"truncate",bold:n||T,color:n?e.white:T?e.silver:void 0,children:o.title.length>O?o.title.slice(0,O-1)+"\u2026":o.title}),(o.attachments?.length??0)>0&&jsxs(Text,{color:e.dim,children:[" ","\u{1F4CE}",o.attachments.length]})]}),C&&jsx(Box,{width:P,children:jsxs(Text,{backgroundColor:il,color:e.amberDim,wrap:"truncate",children:[" \u2295 ",et(B.title,13)," "]})}),jsx(Box,{width:F,children:N?jsxs(Text,{backgroundColor:Nt.green,color:e.green,wrap:"truncate",children:[" ",N.length>F-2?N.slice(0,F-3)+"\u2026":N," "]}):jsx(Text,{color:e.ghost,children:"\u2014"})}),jsx(Box,{width:j,justifyContent:"flex-end",children:jsx(Text,{color:I,dimColor:!I,children:y})})]})});var _s="\u2295";function Rs({goalTitle:t,taskCount:o,doneCount:n,width:r}){let l=o>0?Math.round(n/o*100):0,f=` ${_s} ${t.toUpperCase()} ${ue} ${o} task${o!==1?"s":""} ${ue} ${l}% done `,b=3,T=Math.max(0,r-b-f.length-4);return jsxs(Box,{paddingX:2,children:[jsx(Text,{color:e.ghost,children:be(b)}),jsx(Text,{backgroundColor:Nt.amber,color:e.amber,bold:true,children:f}),jsx(Text,{color:e.ghost,children:be(T)})]})}function As({taskCount:t,width:o}){let n=` ${_s} UNGROUPED ${ue} ${t} task${t!==1?"s":""} `,r=3,l=Math.max(0,o-r-n.length-4);return jsxs(Box,{paddingX:2,children:[jsx(Text,{color:e.ghost,children:be(r)}),jsx(Text,{backgroundColor:Nt.neutral,color:e.dim,children:n}),jsx(Text,{color:e.ghost,children:be(l)})]})}var ll="\u2715",$s="\u25CB",cl="\u25B6",dl="\u2713",Bo={green:"#0f2d1f",red:"#2d0f0f",neutral:"#1a1a22",amber:"#2d1f0a"},ul={running:{icon:cl,label:"ACTIVE",fg:e.green,bg:Bo.green,bold:true,spinner:true},idle:{icon:$s,label:"IDLE",fg:e.dim,bg:Bo.neutral},error:{icon:ll,label:"ERROR",fg:e.red,bg:Bo.red,bold:true},disabled:{icon:$s,label:"OFF",fg:e.ghost,bg:Bo.neutral}},Mr={running:0,idle:1,error:2,disabled:3},Es=nn.memo(function({agent:o,selected:n,width:r,runningEntry:l,currentTaskTitle:f$1,teamName:b,isLead:T}){let x=ul[o.status],y=o.status==="running",I,v;if(y&&l){let N=Date.now()-new Date(l.started_at).getTime();I=f(N),v=e.cyan;}else o.stats.total_runs>0?(I=`${o.stats.tasks_completed}/${o.stats.total_runs}`,v=o.stats.tasks_completed>0?e.green:e.dim):(I="\u2014",v=void 0);let B=n?"\u25B8":" ",C=11,H=8,V=b?Math.min(b.length+2,12):0,F=10,P=2+C+H+V+F,j=r?Math.max(8,r-P):20,L=o.stats.total_runs>0,O=L?Math.round(o.stats.tasks_completed/o.stats.total_runs*100):0;return jsxs(Box,{children:[jsxs(Text,{color:n?e.amber:void 0,children:[B," "]}),jsx(Box,{width:C,children:jsx(Text,{backgroundColor:x.bg,color:x.fg,bold:x.bold,children:x.spinner?jsxs(Fragment,{children:[" ",jsx($o,{color:x.fg})," ",x.label," "]}):jsxs(Fragment,{children:[" ",x.icon," ",x.label," "]})})}),jsx(Box,{width:j,children:jsxs(Text,{wrap:"truncate",bold:n||y,color:n?e.white:y?e.green:e.silver,children:[o.autonomous&&jsxs(Text,{color:e.cyan,children:[go," "]}),T&&jsxs(Text,{color:e.amber,children:[kr," "]}),o.name,y&&f$1&&jsxs(Text,{color:e.dim,children:[" ",ue," ",f$1]}),o.status==="error"&&o.last_error&&jsxs(Text,{color:e.red,children:[" ",ue," ",et(m[o.last_error.kind]?.message??o.last_error.message,30)]})]})}),jsx(Box,{width:H,children:jsx(Text,{color:e.dim,children:o.adapter})}),b&&jsx(Box,{width:V,children:jsx(Text,{color:e.amber,wrap:"truncate",children:b})}),jsx(Box,{width:F,justifyContent:"flex-end",children:L&&!y?jsxs(Text,{color:O>=80?e.green:O>=50?e.yellow:e.red,children:[I," ",dl]}):jsx(Text,{color:v,dimColor:!v,children:I})})]})});function Ls({teamName:t,memberCount:o,leadName:n,width:r}){let l=`${o} agent${o!==1?"s":""}`,f=n?` ${ue} ${kr} ${n}`:"",b=` ${Zt} ${t.toUpperCase()} ${ue} ${l}${f} `,T=3,x=Math.max(0,r-T-b.length-4);return jsxs(Box,{paddingX:2,children:[jsx(Text,{color:e.ghost,children:be(T)}),jsx(Text,{backgroundColor:Bo.amber,color:e.amber,bold:true,children:b}),jsx(Text,{color:e.ghost,children:be(x)})]})}var gl="\u25C7";function Os({memberCount:t,width:o}){let n=`${t} agent${t!==1?"s":""}`,r=` ${gl} UNASSIGNED ${ue} ${n} `,l=3,f=Math.max(0,o-l-r.length-4);return jsxs(Box,{paddingX:2,children:[jsx(Text,{color:e.ghost,children:be(l)}),jsx(Text,{backgroundColor:Bo.neutral,color:e.dim,children:r}),jsx(Text,{color:e.ghost,children:be(f)})]})}var Ps="\u2713",Ns="\u2715",fl="\u2016",pl="\u25C9",on={green:"#0f2d1f",amber:"#2d1f0a",neutral:"#1a1a22"},hl={active:{icon:pl,label:"ACTIVE",fg:e.green,bg:on.green,bold:true},paused:{icon:fl,label:"PAUSED",fg:e.dim,bg:on.neutral},achieved:{icon:Ps,label:"DONE",fg:e.amber,bg:on.amber,bold:true},abandoned:{icon:Ns,label:"DROP",fg:e.ghost,bg:on.neutral}},xl="\u2588",bl="\u2591",Tl=14,Ds=nn.memo(function({goal:o,selected:n,width:r,agentNameMap:l,tasksByGoal:f}){let b=hl[o.status],T=n?"\u25B8":" ",x=f?.length??0,y=f?.filter(O=>O.status==="done").length??0,I=x>0,v=11,B=I?Tl:0,C=14,H=7,V=2+v+B+C+H,F=r?Math.max(10,r-V):40,P=o.assignee?l?.get(o.assignee)??o.assignee:void 0,j,L;if(o.status==="achieved")j=Ps,L=e.amber;else if(o.status==="abandoned")j=Ns,L=e.ghost;else {let O=Date.now()-new Date(o.created_at).getTime(),N=Math.floor(O/864e5);j=N>0?`${N}d`:"<1d",L=e.dim;}return jsxs(Box,{children:[jsxs(Text,{color:n?e.amber:void 0,children:[T," "]}),jsx(Box,{width:v,children:jsxs(Text,{backgroundColor:b.bg,color:b.fg,bold:b.bold,children:[" ",b.icon," ",b.label," "]})}),jsx(Box,{width:F,children:jsx(Text,{wrap:"truncate",bold:n||o.status==="active",color:n?e.white:o.status==="active"?e.silver:void 0,children:o.title.length>F?o.title.slice(0,F-1)+"\u2026":o.title})}),I&&(()=>{let N=x>0?Math.round(y/x*6):0,E=6-N;return jsxs(Box,{width:B,children:[jsx(Text,{color:e.green,children:xl.repeat(N)}),jsx(Text,{color:e.ghost,children:bl.repeat(E)}),jsx(Text,{color:e.dim,children:` ${y}/${x}`})]})})(),jsx(Box,{width:C,children:P?jsxs(Text,{backgroundColor:on.green,color:e.green,wrap:"truncate",children:[" ",P.length>C-2?P.slice(0,C-3)+"\u2026":P," "]}):jsx(Text,{color:e.ghost,children:"\u2014"})}),jsx(Box,{width:H,justifyContent:"flex-end",children:jsx(Text,{color:L,dimColor:!L,children:j})})]})});var yl={system:"\u2666",lifecycle:"\u25B6",output:"\u2502",tool:"\u2699",result:"\u2190",error:"\u2715",file:"\u270E",info:"\u2502"};function Oo({label:t,width:o,color:n}){let r=o-4,l=` ${t} `,f=3,b=Math.max(0,r-f-l.length);return jsxs(Text,{color:n??e.ghost,children:[" ",be(f),l,be(b)]})}function Fs({task:t,height:o,width:n,taskLogs:r,agentNameMap:l,taskTitleMap:f}){let b=_n[t.status]??e.dim,T=t.priority<=2?t.priority===1?e.red:e.yellow:void 0,x=24,y=!!t.description?.trim(),I=!!t.proof?.agent_summary,v=(t.proof?.files_changed?.length??0)>0,B=(r?.length??0)>0,C=(t.attachments?.length??0)>0,H=y?t.description.split(`
|
|
4
|
+
`):[],V=I?t.proof.agent_summary.split(`
|
|
5
|
+
`):[],F=3;C&&(F+=2+t.attachments.length),y?(F+=1,F+=Math.min(H.length,Math.max(1,Math.ceil((o-10)*.3)))):I||(F+=2),I&&(F+=2),v&&(F+=1),B&&(F+=2);let P=Math.max(0,o-F),j=0,L=0;I&&B?(j=Math.max(1,Math.floor(P*.4)),L=Math.max(1,P-j)):I?j=P:B&&(L=P);let O=y?H.slice(0,Math.max(1,Math.ceil((o-10)*.3))):[],N=V.slice(0,j);return jsxs(Box,{flexDirection:"column",paddingX:2,children:[jsxs(Box,{children:[jsxs(Box,{width:x,children:[jsx(Text,{color:e.dim,children:" status "}),jsx(Text,{color:b,children:t.status})]}),jsxs(Box,{children:[jsx(Text,{color:e.dim,children:" assignee "}),jsx(Text,{color:t.assignee?e.green:e.dim,children:t.assignee?l?.get(t.assignee)??t.assignee:"\u2014"})]})]}),jsxs(Box,{children:[jsxs(Box,{width:x,children:[jsx(Text,{color:e.dim,children:" priority "}),jsxs(Text,{color:T,bold:t.priority<=2,children:["P",t.priority]})]}),jsxs(Box,{children:[jsx(Text,{color:e.dim,children:" attempts "}),jsxs(Text,{children:[t.attempts,"/",t.max_attempts]})]})]}),jsxs(Box,{children:[jsxs(Box,{width:x,children:[jsx(Text,{color:e.dim,children:" labels "}),jsx(Text,{color:e.purple,children:t.labels.length>0?t.labels.join(", "):"\u2014"})]}),jsxs(Box,{children:[jsx(Text,{color:e.dim,children:" depends "}),jsx(Text,{dimColor:true,children:t.depends_on.length>0?t.depends_on.map(E=>f?.get(E)??E).join(", "):"\u2014"})]})]}),C&&jsxs(Fragment,{children:[jsx(Text,{children:" "}),jsx(Oo,{label:`attachments (${t.attachments.length})`,width:n,color:e.dim}),t.attachments.map((E,G)=>jsxs(Text,{color:e.cyan,wrap:"truncate",children:[" ",E]},`a${G}`))]}),y&&jsxs(Fragment,{children:[jsx(Text,{children:" "}),O.map((E,G)=>jsxs(Text,{color:e.silver,wrap:"truncate",children:[" ",et(E,n-8)]},`d${G}`))]}),!y&&!I&&jsxs(Fragment,{children:[jsx(Text,{children:" "}),jsx(Text,{color:e.dim,children:" No description."})]}),I&&jsxs(Fragment,{children:[jsx(Text,{children:" "}),jsx(Oo,{label:"result",width:n,color:e.dim}),N.map((E,G)=>jsxs(Text,{color:e.white,wrap:"truncate",children:[" ",et(E,n-8)]},`r${G}`))]}),v&&jsxs(Box,{children:[jsx(Text,{color:e.dim,children:" files "}),jsx(Text,{color:e.cyan,children:t.proof.files_changed.length}),jsx(Text,{color:e.dim,children:" changed"}),t.proof.branch&&jsxs(Fragment,{children:[jsxs(Text,{color:e.dim,children:[" ","\xB7"," "]}),jsx(Text,{color:e.cyan,children:t.proof.branch})]})]}),B&&jsxs(Fragment,{children:[jsx(Text,{children:" "}),jsx(Oo,{label:"activity",width:n,color:e.dim}),r.slice(-L).map((E,G)=>{let z=E.msgType??"info",X=yl[z]??"\u2502",R=E.color;z==="tool"?R=e.cyan:z==="file"?R=e.purple:z==="error"?R=e.red:z==="lifecycle"?R=e.green:z==="system"&&(R=e.dim);let ie=Math.max(10,n-12),Be=et(E.text,ie);return jsxs(Box,{children:[jsxs(Text,{color:e.ghost,children:[" ",E.time," "]}),jsxs(Text,{color:z==="error"?e.red:e.dim,children:[X," "]}),jsx(Text,{color:R,bold:z==="lifecycle",children:Be})]},G)})]})]})}var $n=[{key:"G",id:"goals",label:"GOALS"},{key:"T",id:"tasks",label:"TASKS"},{key:"A",id:"agents",label:"AGENTS"},{key:"L",id:"logs",label:"ACTIONS"}];var wl="\u25CF",Gs="\u25CB",Sl="\u2713",kl="\u2715",Cl="\u2191",Il="\u2193",Ml="\u03A3",vl="\u25B6",_l="\u21BB",Rl="\u{1F9E0}",Ws=["\u280B","\u2819","\u2839","\u2838","\u283C","\u2834","\u2826","\u2827","\u2807","\u280F"],vr=[" ","\u2581","\u2582","\u2583","\u2584","\u2585","\u2586","\u2587","\u2588"],ut={green:"#0f2d1f",blue:"#0f1f2d",yellow:"#2d2a0f",red:"#2d0f0f",neutral:"#1a1a22",amber:"#2d1f0a"};function zs({color:t}){let o=mo();return jsx(Text,{color:t,children:Ws[o%Ws.length]})}function Al(){let t=mo(),o=Math.floor(t/10)%2===0;return jsx(Text,{color:o?e.amber:e.amberDim,bold:true,children:Ht})}function $l({width:t,active:o}){let n=Math.max(4,Math.floor(t*.08)),r=2,l=mo(),f=Math.ceil((t+n)/r),b=o?l%(f*2):0;if(!o)return jsx(Box,{paddingX:1,children:jsx(Text,{color:e.ghost,children:ze(t)})});let T=b<f?b*r:(f*2-b)*r,x=Math.max(0,T-n),y=Math.min(t,T),I=x,v=Math.max(0,y-x),B=Math.max(0,t-y);return jsxs(Box,{paddingX:1,children:[jsx(Text,{color:e.ghost,children:ze(I)}),jsx(Text,{color:e.amber,children:ze(v)}),jsx(Text,{color:e.ghost,children:ze(B)})]})}function Bl({data:t,width:o,color:n}){if(t.length===0)return null;let r=t.slice(-o),l=Math.max(...r,1),f=r.map(b=>{let T=Math.round(b/l*(vr.length-1));return vr[T]??vr[0]}).join("");return jsx(Text,{color:n,children:f})}function El({tab:t,flashColor:o,onComplete:n,badge:r}){let l=mo(),f=nn.useRef(l),b=nn.useRef(false),T=l-f.current,x=2,y=6*x;return nn.useEffect(()=>{T>=y&&!b.current&&(b.current=true,n());},[T,n]),Math.floor(T/x)%2===0&&T<y?jsxs(Text,{backgroundColor:o,color:"#0a0a0c",bold:true,children:[" ",t.key," ",t.label,r," "]}):jsxs(Box,{gap:0,children:[jsx(Text,{color:e.ghost,children:t.key}),jsxs(Text,{color:e.dim,children:[" ",t.label.toLowerCase(),r]})]})}function Ll({projectName:t,activeView:o,mode:n,stats:r,uptime:l,width:f,version:b,latestVersion:T,taskBadge:x,flashTab:y,flashColor:I,onFlashComplete:v}){let B=n==="watching";return jsxs(Box,{paddingX:1,justifyContent:"space-between",width:f,children:[jsxs(Box,{gap:0,children:[jsx(Al,{}),jsx(Text,{color:e.amber,bold:true,children:" ORCH"}),b&&jsxs(Text,{color:e.ghost,children:[" ",b]}),T&&T!==b&&jsxs(Text,{backgroundColor:ut.green,color:e.green,bold:true,children:[" UPDATE ",T," "]}),jsxs(Text,{color:e.ghost,children:[" ",ue," "]}),jsx(Text,{color:e.silver,children:t})]}),jsx(Box,{gap:0,children:$n.map((C,H)=>{let V=o===C.id,F=C.id==="tasks"&&x!=null&&x>0?` (${x})`:"",P=!V&&y===C.id&&I&&v;return jsxs(nn.Fragment,{children:[H>0&&jsx(Text,{children:" "}),V?jsxs(Text,{backgroundColor:e.amber,color:"#0a0a0c",bold:true,children:[" ",C.key," ",C.label,F," "]}):P?jsx(El,{tab:C,flashColor:I,onComplete:v,badge:F}):jsxs(Box,{gap:0,children:[jsx(Text,{color:e.ghost,children:C.key}),jsxs(Text,{color:e.dim,children:[" ",C.label.toLowerCase(),F]})]})]},C.id)})}),jsxs(Box,{gap:0,children:[B?jsxs(Text,{backgroundColor:ut.green,color:e.green,bold:true,children:[" ",wl," WATCHING"," "]}):jsxs(Text,{backgroundColor:ut.neutral,color:e.dim,children:[" ",Gs," IDLE"," "]}),r.running>0&&jsxs(Fragment,{children:[jsx(Text,{children:" "}),jsxs(Text,{backgroundColor:ut.green,color:e.green,children:[" ",jsx(zs,{color:e.green})," ",r.running," active"," "]})]}),l&&jsxs(Text,{color:e.ghost,children:[" ",l]})]})]})}function Ol({stats:t,tokens:o,width:n,sparklineData:r}){let f=[{icon:vl,label:"RUN",count:t.running,fg:e.green,bg:ut.green,bold:true,spinner:true,show:t.running>0},{icon:_l,label:"RETRY",count:t.retrying,fg:e.yellow,bg:ut.yellow,show:t.retrying>0},{icon:Zt,label:"REVIEW",count:t.review,fg:e.blue,bg:ut.blue,show:t.review>0},{icon:Gs,label:"TODO",count:t.todo,fg:e.dim,bg:ut.neutral,show:t.todo>0},{icon:Sl,label:"DONE",count:t.done,fg:e.green,bg:ut.green,show:t.done>0},{icon:kl,label:"FAIL",count:t.failed,fg:e.red,bg:ut.red,bold:true,show:t.failed>0},{icon:Ht,label:"TEAMS",count:t.teams,fg:e.amber,bg:ut.amber,show:t.teams>0}].filter(x=>x.show),b=o.total>0,T=r&&r.length>0?Math.min(16,r.length):0;return jsxs(Box,{paddingX:1,justifyContent:"space-between",width:n,children:[jsxs(Box,{gap:1,children:[f.map(x=>jsx(Text,{backgroundColor:x.bg,color:x.fg,bold:x.bold,children:x.spinner?jsxs(Fragment,{children:[" ",jsx(zs,{color:x.fg})," ",x.count," ",x.label," "]}):jsxs(Fragment,{children:[" ",x.icon," ",x.count," ",x.label," "]})},x.label)),f.length===0&&jsxs(Text,{backgroundColor:ut.neutral,color:e.dim,children:[" ","NO TASKS"," "]})]}),jsxs(Box,{gap:0,children:[T>0&&r&&jsxs(Fragment,{children:[jsx(Bl,{data:r,width:T,color:e.amberDim}),jsx(Text,{children:" "})]}),b&&jsxs(Text,{backgroundColor:ut.amber,color:e.cyan,children:[" ",Cl,h(o.input)," ",Il,h(o.output),o.reasoning>0?` ${Rl}${h(o.reasoning)}`:""," ",ue," ",Ml,h(o.total)," "]})]})]})}var Vs=nn.memo(function(o){let n=Math.max(10,o.width-2),r=o.stats.running>0;return jsxs(Box,{flexDirection:"column",children:[jsx(Box,{height:1}),jsx(Ll,{projectName:o.projectName,activeView:o.activeView,mode:o.mode,stats:o.stats,uptime:o.uptime,width:o.width,version:o.version,latestVersion:o.latestVersion,taskBadge:o.taskBadge,flashTab:o.flashTab,flashColor:o.flashColor,onFlashComplete:o.onFlashComplete}),jsx(Box,{height:1}),jsx(Ol,{stats:o.stats,tokens:o.tokens,width:o.width,sparklineData:o.sparklineData}),jsx($l,{width:n,active:r})]})});var rn="\u0423\u041F\u0420\u0410\u0412\u041B\u0415\u041D\u0418\u0415",Po="\u041C\u041E\u041D\u0418\u0422\u041E\u0420\u0418\u041D\u0413",En="\u041D\u0410\u0421\u0422\u0420\u041E\u0419\u041A\u0418",fo={task:{sub:["add","list","show","cancel","retry","assign","approve","reject","delete"],help:"Manage tasks",category:rn},agent:{sub:["add","list","disable","enable","delete","autonomous","shop"],help:"Manage agents",category:rn},team:{sub:["create","list","join","leave","disband","set-lead"],help:"Manage teams",category:rn},goal:{sub:["add","list","show","status","delete"],help:"Manage goals",category:rn},run:{args:"[id]",help:"Run task (or selected)",category:Po},"run-all":{help:"Run all todo tasks",category:Po},watch:{help:"Start watch mode (auto-dispatch)",category:Po},pause:{help:"Pause watch mode",category:Po},status:{help:"Show orchestrator status",category:Po},config:{sub:["activity-filter","max-concurrent"],help:"TUI settings",category:En},help:{help:"List all commands",category:En},quit:{help:"Exit the TUI",category:En}};function _r(t){if(!t.startsWith("/"))return null;let o=t.slice(1),n=o.indexOf(" ");if(n===-1){let T=o;if(!T)return null;let x=Object.keys(fo).find(y=>y.startsWith(T)&&y!==T);return x?x.slice(T.length):null}let r=o.slice(0,n),l=fo[r];if(!l?.sub)return null;let f=o.slice(n+1);if(!f)return null;let b=l.sub.find(T=>T.startsWith(f)&&T!==f);return b?b.slice(f.length):null}function Hs(t){if(!t.startsWith("/"))return [];let o=t.slice(1),n=o.indexOf(" ");if(n===-1){let T=o.toLowerCase(),x=[];if(!T){let y=[rn,Po,En];for(let I of y){x.push({cmd:"",desc:`\u2500\u2500 ${I} \u2500\u2500`});for(let[v,B]of Object.entries(fo))if(B.category===I){let C=B.args?` ${B.args}`:"";x.push({cmd:`/${v}${C}`,desc:B.help,subs:B.sub?.join(" \xB7 ")});}}return x}for(let[y,I]of Object.entries(fo))if(y.startsWith(T)){let v=I.args?` ${I.args}`:"";if(x.push({cmd:`/${y}${v}`,desc:I.help,subs:I.sub?.join(" \xB7 ")}),y===T&&I.sub)for(let B of I.sub)x.push({cmd:`/${y} ${B}`,desc:`${I.help}: ${B}`});}return x}let r=o.slice(0,n),l=fo[r];if(!l?.sub)return [];let f=o.slice(n+1).toLowerCase(),b=[];for(let T of l.sub)(!f||T.startsWith(f))&&b.push({cmd:`/${r} ${T}`,desc:`${l.help}: ${T}`});return b}var Ln=class{entries=[];cursor=0;push(o){o&&(this.entries[this.entries.length-1]!==o&&(this.entries.push(o),this.entries.length>100&&this.entries.shift()),this.cursor=this.entries.length);}prev(){return this.entries.length===0?null:(this.cursor>0&&this.cursor--,this.entries[this.cursor]??null)}next(){return this.cursor<this.entries.length-1?(this.cursor++,this.entries[this.cursor]??null):(this.cursor=this.entries.length,null)}reset(){this.cursor=this.entries.length;}};var Nl="\u2588",js=nn.memo(function({mode:o,value:n,completion:r,activeView:l,canRun:f,canNew:b,canApprove:T,canReject:x,canCancel:y,canDelete:I,canUndo:v,canEdit:B,canForceStop:C,canToggleAuto:H,autoActive:V,canPause:F,isPaused:P,canToggleShowAll:j,showAllActive:L,hasDetail:O,itemCount:N,itemLabel:E,width:G,hasSuggestions:z,onboardingCompleted:X}){if(o==="command"){let R=z?" \u2191\u2193 select Tab fill Esc \u2715":" Enter exec \u2191\u2193 history Tab complete Esc \u2715",ie=Math.max(4,G-6-R.length-(r?.length??0)-1),Be=n.length>ie?"\u2026"+n.slice(-(ie-1)):n;return jsx(Box,{paddingX:2,justifyContent:"space-between",width:G,children:jsxs(Box,{children:[jsx(Text,{color:e.amber,children:"/ "}),jsx(Text,{color:e.white,children:Be}),r&&jsx(Text,{color:e.ghost,children:r}),jsx(Text,{color:e.amber,children:Nl}),jsx(Text,{color:e.dim,children:R})]})})}return jsxs(Box,{paddingX:2,justifyContent:"space-between",width:G,children:[jsxs(Text,{color:e.dim,children:[jsx(Text,{bold:true,color:e.gray,children:"\u2191\u2193"})," ",jsx(Text,{bold:true,color:e.gray,children:"Tab"}),"/",jsx(Text,{bold:true,color:e.gray,children:"\u2190\u2192"})," ",jsx(Text,{bold:true,color:e.gray,children:"/"})," cmd",b&&jsxs(Fragment,{children:[" ",jsx(Text,{bold:true,color:e.gray,children:"N"})," new"]}),f&&jsxs(Fragment,{children:[" ",jsx(Text,{bold:true,color:e.gray,children:"R"})," run"]}),y&&jsxs(Fragment,{children:[" ",jsx(Text,{bold:true,color:e.amber,children:"C"})," cancel"]}),T&&jsxs(Fragment,{children:[" ",jsx(Text,{bold:true,color:e.green,children:"A"})," approve"]}),x&&jsxs(Fragment,{children:[" ",jsx(Text,{bold:true,color:e.red,children:"X"})," reject"]}),B&&jsxs(Fragment,{children:[" ",jsx(Text,{bold:true,color:e.cyan,children:"E"})," edit"]}),C&&jsxs(Fragment,{children:[" ",jsx(Text,{bold:true,color:e.red,children:"S"})," stop"]}),F&&jsxs(Fragment,{children:[" ",jsx(Text,{bold:true,color:e.amber,children:"P"}),P?" resume":" pause"]}),H&&jsxs(Fragment,{children:[" ",jsx(Text,{bold:true,color:e.cyan,children:"U"}),V?" auto off":" auto on"]}),j&&jsxs(Fragment,{children:[" ",jsx(Text,{bold:true,color:e.gray,children:"S"}),L?" collapse":" show all"]}),I&&!T&&jsxs(Fragment,{children:[" ",jsx(Text,{bold:true,color:e.gray,children:"D"})," delete"]}),v&&jsxs(Fragment,{children:[" ",jsx(Text,{bold:true,color:e.yellow,children:"Z"})," undo"]}),O&&jsxs(Fragment,{children:[" ",jsx(Text,{bold:true,color:e.gray,children:"Esc"})," close"]}),!O&&(l==="tasks"||l==="agents"||l==="goals")&&jsxs(Fragment,{children:[" ",jsx(Text,{bold:true,color:e.gray,children:"Enter"})," detail"]})," ",jsx(Text,{bold:true,color:e.gray,children:"Q"})," quit"," ",jsx(Text,{bold:true,color:X===false?e.amber:e.gray,children:"?"}),jsx(Text,{color:X===false?e.amber:void 0,children:" help"})]}),N>0&&jsxs(Text,{color:e.dim,children:[N," ",E]})]})});var On="\u2588",Ar=process.platform==="darwin"?"\u2318":"Ctrl";function Wl(t,o){if(o<=0||t.length<=o)return [t];let n=[];for(let r=0;r<t.length;r+=o)n.push(t.slice(r,r+o));return n}function Pn(t,o){if(o<=0)return 0;let n=o-1;for(;n>0&&t[n-1]===" ";)n--;for(;n>0&&t[n-1]!==" ";)n--;return n}function qs(t,o){if(o>=t.length)return t.length;let n=o;for(;n<t.length&&t[n]!==" ";)n++;for(;n<t.length&&t[n]===" ";)n++;return n}function Ks({title:t,steps:o,onComplete:n,onCancel:r,width:l,height:f,onPasteImage:b,footerExtra:T,onSuggestionSelected:x}){let [y,I]=useState(0),[v,B]=useState({}),[C,H]=useState(()=>{let A=o.find(S=>!S.skip?.({}));return A?.type==="text"&&A.defaultValue?A.defaultValue:""}),[V,F]=useState(()=>{let A=o.find(S=>!S.skip?.({}));return A?.type==="text"&&A.defaultValue?A.defaultValue.length:0}),[P,j]=useState(()=>{let A=o.find(S=>!S.skip?.({}));return A?.type==="textarea"&&A.defaultValue?A.defaultValue.split(`
|
|
6
|
+
`):[""]}),[L,O]=useState(0),[N,E]=useState(0),[G,z]=useState(()=>{let A=o.find(S=>!S.skip?.({}));if(A?.type==="select"&&A.defaultValue){let M=(A.getOptions?.({})??A.options??[]).findIndex(k=>k.value===A.defaultValue);return M>=0?M:0}return 0}),X=useMemo(()=>o.filter(A=>!A.skip?.(v)),[o,v]),R=X[y],ie=X.length,{taLineNumWidth:Wt,taContentWidth:it}=useMemo(()=>{let A=String(P.length).length;return {taLineNumWidth:A,taContentWidth:Math.max(1,l-A-4)}},[P.length,l]),Re=useMemo(()=>{if(!R||R.type!=="textarea")return [];let A=[];for(let S=0;S<P.length;S++){let M=Wl(P[S]??"",it);for(let k=0;k<M.length;k++)A.push({logicalRow:S,startCol:k*it,text:M[k],isFirst:k===0});}return A},[R?.id,R?.type,P,it]),Xe=useMemo(()=>{for(let A=0;A<Re.length;A++){let S=Re[A];if(S.logicalRow===L&&(N>=S.startCol&&N<S.startCol+it||N>=S.startCol&&(A+1>=Re.length||Re[A+1].logicalRow!==L)))return A}return 0},[Re,L,N,it]),[at,mt]=useState(new Set),[Pe,qe]=useState(false),[lt,Ke]=useState(0),[oo,ke]=useState(false),[ft,$t]=useState(null),[Xt,pt]=useState(false),Je=useRef(null),ct=useRef(null),Fo=useMemo(()=>R?R.type==="text"?C:R.type==="textarea"?P.join(`
|
|
7
|
+
`):"":"",[R,C,P]),ln=useCallback((A,S)=>{if(Je.current&&clearTimeout(Je.current),!S){$t(null);return}Je.current=setTimeout(()=>{$t(S(A));},300);},[]);useEffect(()=>(R&&R.validate&&(R.type==="text"||R.type==="textarea")&&ln(Fo,R.validate),()=>{Je.current&&clearTimeout(Je.current);}),[Fo,R,ln]),useEffect(()=>()=>{ct.current&&clearTimeout(ct.current);},[]);let Ct=useMemo(()=>!R||R.type!=="select"&&R.type!=="multiselect"?[]:R.getOptions?.(v)??R.options??[],[R,v]),qt=Math.min(G,Math.max(0,Ct.length-1)),It=useMemo(()=>{if(!R?.suggestions)return [];if(!C.trim())return R.suggestions;let A=C.toLowerCase();return R.suggestions.filter(S=>S.label.toLowerCase().includes(A)||(S.hint??"").toLowerCase().includes(A))},[R?.suggestions,C]),no=Math.min(lt,Math.max(0,It.length-1)),Gt=A=>{let S={...v,[R.id]:A};B(S),H(""),F(0),j([""]),O(0),E(0),z(0),mt(new Set),qe(false),Ke(0),ke(false),$t(null),pt(false),Je.current&&clearTimeout(Je.current);let M=R.id,Y=o.findIndex(q=>q.id===M)+1;for(;Y<o.length;){let q=o[Y];if(q&&!q.skip?.(S))break;Y++;}if(Y>=o.length)n(S);else {let q=o[Y].id,ae=o.filter(ye=>!ye.skip?.(S)).findIndex(ye=>ye.id===q);I(ae>=0?ae:0);let de=o[Y];if(de.type==="text"){let ye=de.defaultValue??"";H(ye),F(ye.length);}else if(de.type==="textarea"){let ye=de.defaultValue?de.defaultValue.split(`
|
|
8
|
+
`):[""];j(ye),O(ye.length-1),E(ye[ye.length-1].length);}else if(de.type==="select"){let ye=de.getOptions?.(S)??de.options??[];if(de.defaultValue){let zt=ye.findIndex(Wo=>Wo.value===de.defaultValue);z(zt>=0?zt:0);}else z(0);}else de.type==="multiselect"&&(z(0),de.defaultValue?mt(new Set(de.defaultValue.split(","))):mt(new Set));}},ht=()=>{if(y===0){r();return}let A=R.id,M=o.findIndex(ae=>ae.id===A)-1;for(;M>=0;){let ae=o[M];if(ae&&!ae.skip?.(v))break;M--;}if(M<0){r();return}let k=o[M].id,Y=X.findIndex(ae=>ae.id===k);I(Y>=0?Y:0),qe(false),Ke(0),ke(false),$t(null),pt(false),Je.current&&clearTimeout(Je.current);let q=o[M];if(v[q.id]&&ke(true),q.type==="text"){let ae=v[q.id]??q.defaultValue??"";H(ae),F(ae.length);}else if(q.type==="textarea"){let ae=v[q.id]??q.defaultValue??"",de=ae?ae.split(`
|
|
9
|
+
`):[""];j(de),O(de.length-1),E(de[de.length-1].length);}else if(q.type==="multiselect"){z(0);let ae=v[q.id];mt(ae?new Set(ae.split(",")):new Set);}else {let ae=q.getOptions?.(v)??q.options??[],de=v[q.id],ye=ae.findIndex(zt=>zt.value===de);z(ye>=0?ye:0);}};if(useInput((A,S)=>{if(R){if(S.escape){y===0?r():ht();return}if((S.ctrl||S.meta)&&(A==="v"||A==="i")&&b&&(R.type==="text"||R.type==="textarea")){b();return}if(R.type==="text"){if(Pe&&It.length>0){if(S.upArrow){no<=0?qe(false):Ke(M=>M-1);return}if(S.downArrow){Ke(M=>Math.min(It.length-1,M+1));return}if(S.return){let M=It[no];M&&x&&x(M.value);return}qe(false);}if(S.return){let M=C.trim();if(R.required&&!M){ke(true);return}if(ft!==null){ke(true),pt(true),ct.current&&clearTimeout(ct.current),ct.current=setTimeout(()=>pt(false),2e3);return}Gt(M);return}if(S.downArrow&&R.suggestions&&It.length>0){qe(true),Ke(0);return}if(S.ctrl&&A==="a"){F(0);return}if(S.ctrl&&A==="e"){F(C.length);return}if(S.ctrl&&A==="k"){ke(true),H(M=>M.slice(0,V));return}if(S.ctrl&&A==="u"){ke(true),H(M=>M.slice(V)),F(0);return}if(S.ctrl&&A==="w"){ke(true);let M=Pn(C,V);H(k=>k.slice(0,M)+k.slice(V)),F(M);return}if(S.meta&&(S.leftArrow||A==="b")){F(Pn(C,V));return}if(S.meta&&(S.rightArrow||A==="f")){F(qs(C,V));return}if(S.leftArrow){F(M=>Math.max(0,M-1));return}if(S.rightArrow){F(M=>Math.min(C.length,M+1));return}if(S.backspace||S.delete){if(V===0&&C.length===0&&y>0){ht();return}V>0&&(H(M=>M.slice(0,V-1)+M.slice(V)),F(M=>M-1));return}A&&!S.ctrl&&!S.meta&&!S.escape&&(ke(true),qe(false),Ke(0),H(M=>M.slice(0,V)+A+M.slice(V)),F(M=>M+A.length));return}if(R.type==="textarea"){if(S.return&&(S.ctrl||S.meta)){let M=P.join(`
|
|
10
|
+
`).trim();if(R.required&&!M){ke(true);return}if(ft!==null){ke(true),pt(true),ct.current&&clearTimeout(ct.current),ct.current=setTimeout(()=>pt(false),2e3);return}Gt(M);return}if(S.return){ke(true),j(M=>{let k=M[L]??"",Y=k.slice(0,N),q=k.slice(N),Ce=[...M];return Ce.splice(L,1,Y,q),Ce}),O(M=>M+1),E(0);return}if(S.ctrl&&A==="a"){E(0);return}if(S.ctrl&&A==="e"){E((P[L]??"").length);return}if(S.ctrl&&A==="k"){ke(true),j(M=>{let k=[...M];return k[L]=(k[L]??"").slice(0,N),k});return}if(S.ctrl&&A==="u"){ke(true),j(M=>{let k=[...M];return k[L]=(k[L]??"").slice(N),k}),E(0);return}if(S.ctrl&&A==="w"){ke(true);let M=L,k=N;j(Y=>{let q=Y[M]??"",Ce=Pn(q,k),ae=[...Y];return ae[M]=q.slice(0,Ce)+q.slice(k),E(Ce),ae});return}if(S.meta&&(S.leftArrow||A==="b")){E(Pn(P[L]??"",N));return}if(S.meta&&(S.rightArrow||A==="f")){E(qs(P[L]??"",N));return}if(S.upArrow){if(Xe>0){let M=Re[Xe],k=Re[Xe-1],Y=N-(M?.startCol??0),q=Math.min(k.startCol+Y,k.startCol+k.text.length);O(k.logicalRow),E(q);}return}if(S.downArrow){if(Xe<Re.length-1){let M=Re[Xe],k=Re[Xe+1],Y=N-(M?.startCol??0),q=Math.min(k.startCol+Y,k.startCol+k.text.length);O(k.logicalRow),E(q);}return}if(S.leftArrow){N>0?E(M=>M-1):L>0&&(O(M=>M-1),E((P[L-1]??"").length));return}if(S.rightArrow){let M=(P[L]??"").length;N<M?E(k=>k+1):L<P.length-1&&(O(k=>k+1),E(0));return}if(S.backspace||S.delete){if(N===0&&L===0)return;if(N>0)j(M=>{let k=[...M],Y=k[L]??"";return k[L]=Y.slice(0,N-1)+Y.slice(N),k}),E(M=>M-1);else {let M=(P[L-1]??"").length;j(k=>{let Y=[...k],q=Y[L-1]??"",Ce=Y[L]??"";return Y.splice(L-1,2,q+Ce),Y}),E(M),O(k=>k-1);}return}if(A&&!S.ctrl&&!S.meta&&!S.escape){ke(true);let M=A.split(/\r?\n/);if(M.length===1)j(k=>{let Y=[...k],q=Y[L]??"";return Y[L]=q.slice(0,N)+A+q.slice(N),Y}),E(k=>k+A.length);else {let k=L,Y=N;j(q=>{let Ce=[...q],ae=Ce[k]??"",de=ae.slice(0,Y),ye=ae.slice(Y),zt=M[0]??"",Wo=M[M.length-1]??"",dn=[de+zt,...M.slice(1,-1),Wo+ye];return Ce.splice(k,1,...dn),Ce}),O(k+M.length-1),E((M[M.length-1]??"").length);}}return}if(R.type==="select"||R.type==="multiselect"){if(S.upArrow||A==="k"){z(M=>Math.max(0,M-1));return}if(S.downArrow||A==="j"){z(M=>Math.min(Ct.length-1,M+1));return}if(S.backspace||S.delete){ht();return}if(R.type==="select"){if(S.return||S.tab){let M=Ct[qt];if(M){if(R.validate){let k=R.validate(M.value);if(k!==null){ke(true),$t(k),pt(true),ct.current&&clearTimeout(ct.current),ct.current=setTimeout(()=>pt(false),2e3);return}}Gt(M.value);}return}if(A>="1"&&A<="9"){let M=parseInt(A,10)-1;if(M<Ct.length){let k=Ct[M];k&&Gt(k.value);}return}}else {if(A===" "){let M=Ct[qt];M&&mt(k=>{let Y=new Set(k);return Y.has(M.value)?Y.delete(M.value):Y.add(M.value),Y});return}if(S.return){let M=Array.from(at).join(",");Gt(M);return}}}}}),!R)return null;let xt=oo?ft:null,tr=Math.max(20,l-6),cn=`${y+1}/${ie}`,xo=Math.max(2,f-4),ro=0;qt>=xo&&(ro=qt-xo+1);let bt=Ct.slice(ro,ro+xo);return jsxs(Box,{flexDirection:"column",paddingX:2,children:[jsxs(Box,{children:[jsx(Text,{color:e.amber,bold:true,children:t}),jsxs(Text,{color:e.ghost,children:[" ",Ge,Ge," "]}),jsxs(Text,{color:e.dim,children:["step ",cn]})]}),jsxs(Box,{children:[jsx(Text,{children:" "}),X.map((A,S)=>jsxs(Text,{color:S===y?e.amber:S<y?e.green:e.ghost,children:[S===y?"\u25CF":S<y?"\u2713":"\u25CB"," "]},A.id))]}),jsxs(Box,{marginTop:0,children:[jsxs(Text,{color:e.white,bold:true,children:[" ",R.label]}),R.required&&jsx(Text,{color:e.red,children:" *"}),!R.required&&jsxs(Text,{color:e.dim,children:[" (optional, ",R.type==="textarea"?`${Ar}+Enter`:"Enter"," to skip)"]})]}),R.description&&jsx(Box,{children:jsxs(Text,{color:e.dim,children:[" ",R.description]})}),R.type==="text"&&jsxs(Box,{flexDirection:"column",children:[jsxs(Box,{borderStyle:xt?"round":void 0,borderColor:xt?e.red:void 0,children:[jsxs(Text,{color:e.amber,children:[" ",">"," "]}),C.length>0?jsxs(Fragment,{children:[jsx(Text,{color:e.white,children:C.slice(0,V)}),jsx(Text,{color:e.amber,children:On}),jsx(Text,{color:e.white,children:C.slice(V)})]}):R.placeholder?jsxs(Fragment,{children:[jsx(Text,{color:e.ghost,children:R.placeholder}),jsx(Text,{color:e.amber,children:On})]}):jsx(Text,{color:e.amber,children:On})]}),xt&&jsxs(Text,{color:e.red,dimColor:true,children:[" ",xt]}),Xt&&jsx(Text,{color:e.red,children:" Fix the error above"})]}),R.type==="text"&&R.suggestions&&It.length>0&&(()=>{let A=Math.max(2,f-6),S=0;Pe&&no>=A&&(S=no-A+1);let M=It.slice(S,S+A);return jsxs(Box,{flexDirection:"column",children:[jsxs(Text,{color:e.ghost,children:[" ",Ge,Ge,Ge," or browse templates ",Ge.repeat(Math.max(0,tr-28))]}),M.map((k,Y)=>{let q=Y+S,Ce=Pe&&q===no;return jsxs(Box,{children:[jsx(Text,{color:Ce?e.amber:e.ghost,children:Ce?" \u25B8 ":" "}),jsx(Text,{color:Ce?e.white:e.silver,bold:Ce,children:k.label}),k.hint&&jsxs(Text,{color:e.dim,wrap:"truncate",children:[" ",Ge," ",k.hint.replace(/\n/g," ")]})]},k.value)})]})})(),R.type==="textarea"&&(()=>{let A=Math.max(3,f-6),S=0;Xe>=A&&(S=Xe-A+1);let M=Re.slice(S,S+A);return jsxs(Box,{flexDirection:"column",children:[jsxs(Box,{flexDirection:"column",borderStyle:xt?"round":void 0,borderColor:xt?e.red:void 0,children:[M.map((k,Y)=>{let q=Y+S,Ce=k.isFirst?String(k.logicalRow+1).padStart(Wt," "):"".padStart(Wt," "),ae=q===Xe,de=N-k.startCol;return jsxs(Box,{children:[jsxs(Text,{color:e.dim,children:[" ",Ce," "]}),jsxs(Text,{color:e.ghost,children:["\u2502"," "]}),ae?jsxs(Fragment,{children:[jsx(Text,{color:e.white,children:k.text.slice(0,de)}),jsx(Text,{color:e.amber,children:On}),jsx(Text,{color:e.white,children:k.text.slice(de)})]}):jsx(Text,{color:e.silver,children:k.text||(k.isFirst?" ":"")})]},`${k.logicalRow}-${k.startCol}`)}),P.length===1&&P[0]===""&&R.placeholder&&jsx(Box,{children:jsxs(Text,{color:e.dim,children:[" ","".padStart(Wt," ")," ",R.placeholder]})})]}),xt&&jsxs(Text,{color:e.red,dimColor:true,children:[" ",xt]}),Xt&&jsx(Text,{color:e.red,children:" Fix the error above"})]})})(),R.type==="select"&&jsxs(Box,{flexDirection:"column",children:[bt.map((A,S)=>{let M=S+ro,k=M===qt,Y=String(M+1).padStart(Ct.length>=10?2:1);return jsxs(Box,{children:[jsx(Text,{color:k?e.amber:e.ghost,children:k?" \u25B8 ":` ${Y} `}),jsx(Text,{color:k?e.white:e.silver,bold:k,children:A.label}),A.hint&&jsxs(Text,{color:e.dim,wrap:"truncate",children:[" ",Ge," ",A.hint.replace(/\n/g," ")]})]},A.value)}),xt&&jsxs(Text,{color:e.red,dimColor:true,children:[" ",xt]}),Xt&&jsx(Text,{color:e.red,children:" Fix the error above"})]}),R.type==="multiselect"&&jsxs(Box,{flexDirection:"column",children:[bt.map((A,S)=>{let k=S+ro===qt,Y=at.has(A.value);return jsxs(Box,{children:[jsx(Text,{color:k?e.amber:e.ghost,children:k?" \u25B8 ":" "}),jsx(Text,{color:Y?e.green:e.dim,children:Y?"[\u2713]":"[ ]"}),jsxs(Text,{color:k?e.white:e.silver,bold:k,children:[" ",A.label]}),A.hint&&jsxs(Text,{color:e.dim,wrap:"truncate",children:[" ",Ge," ",A.hint.replace(/\n/g," ")]})]},A.value)}),at.size>0&&jsx(Box,{children:jsxs(Text,{color:e.dim,children:[" ","\u2514"," ",at.size," selected"]})})]}),jsxs(Box,{marginTop:0,children:[jsxs(Text,{color:e.ghost,children:[" ",R.type==="select"?"\u2191\u2193 select Enter confirm":R.type==="multiselect"?"\u2191\u2193 move Space toggle Enter confirm":R.type==="textarea"?`Enter newline ${Ar}+Enter confirm \u2190\u2191\u2192\u2193 navigate`:Pe?"\u2191\u2193 browse Enter select \u2191 back to input":R.suggestions?"\u2190\u2192 move Enter confirm \u2193 browse templates":"\u2190\u2192 move Enter confirm",b&&(R.type==="text"||R.type==="textarea")?` ${Ar}+V paste image`:""," Esc ",y>0?"back":"cancel"]}),T&&jsxs(Text,{color:e.amber,children:[" ",T]})]})]})}var Js=nn.memo(function({agents:o,selected:n,msgCounts:r,colorMap:l,maxHeight:f,onConfirm:b,onCancel:T}){let [x,y]=useState(0),[I,v]=useState(()=>new Set(n));useMemo(()=>I.size===0||I.size===o.length,[I.size,o.length]);let C=Math.max(3,f-5),H=useMemo(()=>{if(o.length<=C)return 0;let P=Math.floor(C/2),j=o.length-C;return Math.min(j,Math.max(0,x-P))},[x,o.length,C]),V=o.slice(H,H+C);useInput((P,j)=>{if(j.upArrow){y(L=>L>0?L-1:o.length-1);return}if(j.downArrow){y(L=>L<o.length-1?L+1:0);return}if(P===" "){let L=o[x];if(!L)return;v(O=>{let N=new Set(O);return N.has(L.id)?N.delete(L.id):N.add(L.id),N});return}if(P==="a"||P==="A"){v(L=>new Set);return}if(j.return){b(new Set(I));return}if(j.escape){T();return}});let F=I.size===0?o.length:I.size;return jsxs(Box,{flexDirection:"column",borderStyle:"round",borderColor:e.amber,paddingX:1,children:[jsxs(Box,{gap:1,children:[jsx(Text,{color:e.amber,bold:true,children:" \u25C8 Agent Filter"}),jsxs(Text,{color:e.dim,children:[ue," ",F,"/",o.length," selected"]})]}),jsx(Text,{color:e.ghost,children:Ge.repeat(36)}),V.map((P,j)=>{let O=j+H===x,N=I.size===0||I.has(P.id),E=l.get(P.id)??e.silver,G=r.get(P.id)??0;return jsxs(Box,{gap:0,children:[jsx(Text,{color:O?e.amber:e.ghost,children:O?" \u25B8 ":" "}),jsx(Text,{color:N?e.green:e.ghost,children:N?"[\u2713]":"[ ]"}),jsxs(Text,{color:O?E:N?e.silver:e.dim,bold:O,children:[" ",P.name]}),G>0&&jsxs(Text,{color:e.dim,children:[" ",ue,G]})]},P.id)}),o.length>C&&jsxs(Text,{color:e.ghost,children:[" ",H>0?"\u2191":" "," ",H+C<o.length?"\u2193":" "," ",x+1,"/",o.length]}),jsx(Text,{color:e.ghost,children:Ge.repeat(36)}),jsxs(Text,{color:e.dim,children:[" Space toggle"," ",ue," ","a all"," ",ue," ","Enter confirm"," ",ue," ","Esc cancel"]})]})});var jl={system:"\u2666",lifecycle:"\u25B6",output:"\u2502",tool:"\u2699",result:"\u2190",error:"\u2715",file:"\u270E",info:"\u2502"},Ul={system:"System",lifecycle:"Lifecycle",output:"Output",tool:"Tool calls",result:"Results",error:"Errors",file:"Files",info:"Info"},Xl={system:e.purple,lifecycle:e.cyan,output:e.white,tool:e.blue,result:e.green,error:e.red,file:e.purple,info:e.silver},St=["system","lifecycle","output","tool","result","error","file","info"],ti=[{key:"1",label:"all",types:St},{key:"2",label:"text",types:["output"]},{key:"3",label:"tools",types:["tool","result","file"]},{key:"4",label:"errors",types:["error"]},{key:"5",label:"events",types:["lifecycle","system"]}],oi=nn.memo(function({selected:o,typeCounts:n,onConfirm:r,onCancel:l}){let[f,b]=useState(0),[T,x]=useState(()=>new Set(o)),y=useMemo(()=>T.size===St.length||St.every(v=>T.has(v)),[T]);useInput((v,B)=>{if(B.upArrow){b(C=>C>0?C-1:St.length-1);return}if(B.downArrow){b(C=>C<St.length-1?C+1:0);return}if(v===" "){let C=St[f];if(!C)return;x(H=>{let V=new Set(H);return V.has(C)?V.delete(C):V.add(C),V});return}if(v==="a"||v==="A"){x(C=>C.size===St.length?new Set:new Set(St));return}for(let C of ti)if(v===C.key){x(new Set(C.types));return}if(B.return){let C=T.size===0?new Set(St):new Set(T);r(C);return}if(B.escape){l();return}});let I=y?St.length:T.size;return jsxs(Box,{flexDirection:"column",borderStyle:"round",borderColor:e.amber,paddingX:1,children:[jsxs(Box,{gap:1,children:[jsx(Text,{color:e.amber,bold:true,children:" \u25C8 Type Filter"}),jsxs(Text,{color:e.dim,children:[ue," ",I,"/",St.length," selected"]})]}),jsx(Text,{color:e.ghost,children:Ge.repeat(36)}),St.map((v,B)=>{let C=B===f,H=T.has(v),V=n[v]??0,F=Xl[v];return jsxs(Box,{gap:0,children:[jsx(Text,{color:C?e.amber:e.ghost,children:C?" \u25B8 ":" "}),jsx(Text,{color:H?e.green:e.ghost,children:H?"[\u2713]":"[ ]"}),jsxs(Text,{color:C?F:e.dim,children:[" ",jl[v]," "]}),jsx(Text,{color:C?F:H?e.silver:e.dim,bold:C,children:Ul[v]}),V>0&&jsxs(Text,{color:e.dim,children:[" ",ue,V]})]},v)}),jsx(Text,{color:e.ghost,children:Ge.repeat(36)}),jsxs(Box,{gap:0,children:[jsx(Text,{color:e.dim,children:" "}),ti.map((v,B)=>jsxs(nn.Fragment,{children:[B>0&&jsxs(Text,{color:e.ghost,children:[" ",ue," "]}),jsx(Text,{color:e.amberDim,children:v.key}),jsxs(Text,{color:e.dim,children:["=",v.label]})]},v.key))]}),jsxs(Text,{color:e.dim,children:[" Space toggle"," ",ue," ","a all"," ",ue," ","Enter confirm"," ",ue," ","Esc cancel"]})]})});var Fn="\u256D",Wn="\u256E",Gn="\u2570",zn="\u256F",Ie="\u2502";function to({children:t,cw:o}){return jsxs(Text,{children:[jsx(Text,{color:e.ghost,children:Ie}),jsxs(Text,{children:[" ",t.padEnd(o)," "]}),jsx(Text,{color:e.ghost,children:Ie})]})}function Dn({cw:t}){return jsx(to,{cw:t,children:""})}function ni({width:t,height:o}){let n=Math.min(t-4,50),r=n-6,l=be(n-2);return jsxs(Box,{flexDirection:"column",paddingX:2,marginTop:1,children:[jsxs(Text,{color:e.ghost,children:[Fn,l,Wn]}),jsx(to,{cw:r,children:""}),jsxs(Text,{children:[jsxs(Text,{color:e.ghost,children:[Ie," "]}),jsx(Text,{color:e.amber,children:Ht}),jsx(Text,{color:e.white,bold:true,children:" Welcome to Orch"}),jsx(Text,{children:" ".repeat(Math.max(0,r-15-2))}),jsx(Text,{children:" "}),jsx(Text,{color:e.ghost,children:Ie})]}),jsx(to,{cw:r,children:""}),jsxs(Text,{children:[jsxs(Text,{color:e.ghost,children:[Ie," "]}),jsx(Text,{color:e.silver,children:"Press N to create your first task".padEnd(r)}),jsx(Text,{children:" "}),jsx(Text,{color:e.ghost,children:Ie})]}),jsx(to,{cw:r,children:""}),jsxs(Text,{children:[jsxs(Text,{color:e.ghost,children:[Ie," "]}),jsx(Text,{color:e.amber,children:"N"}),jsx(Text,{color:e.gray,children:" new task"}),jsx(Text,{children:" ".repeat(Math.max(0,r-1-1-8))}),jsx(Text,{children:" "}),jsx(Text,{color:e.ghost,children:Ie})]}),jsx(to,{cw:r,children:""}),jsxs(Text,{color:e.ghost,children:[Gn,l,zn]})]})}function ri({step:t,width:o}){let n=Math.min(o-4,50),r=n-6,l=be(n-2),f,b=null;if(t==="task_created")f="Press R to run task",b={key:"R",label:"run task"};else if(t==="run_started")f="Agent is running your task...";else return null;return jsxs(Box,{flexDirection:"column",paddingX:2,marginTop:1,children:[jsxs(Text,{color:e.ghost,children:[Fn,l,Wn]}),jsxs(Text,{children:[jsxs(Text,{color:e.ghost,children:[Ie," "]}),jsx(Text,{color:e.amber,children:Ht}),jsxs(Text,{color:e.silver,children:[" ",f.padEnd(b?r-2-b.key.length-1-b.label.length-2:r-2)]}),b&&jsxs(Fragment,{children:[jsxs(Text,{color:e.amber,children:[" ",b.key]}),jsxs(Text,{color:e.gray,children:[" ",b.label]})]}),jsx(Text,{children:" "}),jsx(Text,{color:e.ghost,children:Ie})]}),jsxs(Text,{color:e.ghost,children:[Gn,l,zn]})]})}function si({width:t}){let o=Math.min(t-4,50),n=o-6,r=be(o-2);return jsxs(Box,{flexDirection:"column",paddingX:2,marginTop:1,children:[jsxs(Text,{color:e.ghost,children:[Fn,r,Wn]}),jsx(to,{cw:n,children:""}),jsxs(Text,{children:[jsxs(Text,{color:e.ghost,children:[Ie," "]}),jsx(Text,{color:e.green,bold:true,children:"First task completed!"}),jsx(Text,{children:" ".repeat(Math.max(0,n-21))}),jsx(Text,{children:" "}),jsx(Text,{color:e.ghost,children:Ie})]}),jsx(to,{cw:n,children:""}),jsxs(Text,{children:[jsxs(Text,{color:e.ghost,children:[Ie," "]}),jsx(Text,{color:e.silver,children:"Type / to see all commands".padEnd(n)}),jsx(Text,{children:" "}),jsx(Text,{color:e.ghost,children:Ie})]}),jsx(to,{cw:n,children:""}),jsxs(Text,{color:e.ghost,children:[Gn,r,zn]})]})}function Vn({count:t,config:o,width:n}){if(t>=3)return null;let r=Math.min((n??44)-4,50),l=r-6,f=be(r-2),b=jsxs(Text,{color:e.ghost,children:[Fn,f,Wn]}),T=jsxs(Text,{color:e.ghost,children:[Gn,f,zn]});if(t>0){let y=o.hints[0],I=y?` ${y.key} ${y.label}`:"";return jsxs(Box,{flexDirection:"column",paddingX:2,marginTop:1,children:[b,jsxs(Text,{children:[jsxs(Text,{color:e.ghost,children:[Ie," "]}),jsx(Text,{color:e.amber,children:Ht}),jsxs(Text,{color:e.silver,children:[" ",o.nudge.padEnd(l-2-I.length)]}),y&&jsxs(Fragment,{children:[jsxs(Text,{color:e.amber,children:[" ",y.key]}),jsxs(Text,{color:e.gray,children:[" ",y.label]})]}),jsx(Text,{children:" "}),jsx(Text,{color:e.ghost,children:Ie})]}),T]})}let x=o.hints.reduce((y,I,v)=>y+I.key.length+1+I.label.length+(v>0?3:0),0);return jsxs(Box,{flexDirection:"column",paddingX:2,marginTop:1,children:[b,jsx(Dn,{cw:l}),jsxs(Text,{children:[jsxs(Text,{color:e.ghost,children:[Ie," "]}),jsx(Text,{color:e.amber,children:Ht}),jsxs(Text,{color:e.white,bold:true,children:[" ",o.title]}),jsx(Text,{children:" ".repeat(Math.max(0,l-o.title.length-2))}),jsx(Text,{children:" "}),jsx(Text,{color:e.ghost,children:Ie})]}),jsx(Dn,{cw:l}),o.description.map((y,I)=>jsxs(Text,{children:[jsxs(Text,{color:e.ghost,children:[Ie," "]}),jsx(Text,{color:e.silver,children:y.padEnd(l)}),jsx(Text,{children:" "}),jsx(Text,{color:e.ghost,children:Ie})]},I)),jsx(Dn,{cw:l}),jsxs(Text,{children:[jsxs(Text,{color:e.ghost,children:[Ie," "]}),o.hints.map((y,I)=>jsxs(nn.Fragment,{children:[I>0&&jsx(Text,{color:e.ghost,children:" "}),jsx(Text,{color:e.amber,children:y.key}),jsxs(Text,{color:e.gray,children:[" ",y.label]})]},I)),jsx(Text,{children:" ".repeat(Math.max(0,l-x))}),jsx(Text,{children:" "}),jsx(Text,{color:e.ghost,children:Ie})]}),jsx(Dn,{cw:l}),T]})}var Kl=2,ci=360,Yl={done:4e3,failed:8e3,review:6e3},Zl={done:"\u2713",failed:"\u2715",review:Zt},Jl={done:e.green,failed:e.red,review:e.blue},Ql={done:e.successBg,failed:e.errorBg,review:e.infoBg};function ec(t){let o=t.agentName??"Agent";switch(t.type){case "done":return `Task completed by ${o}`;case "failed":return "Task failed \u2014 press Enter for details";case "review":return "Task ready for review \u2014 press A to approve"}}var tc=nn.memo(function({toast:o,onDismiss:n}){let[r,l]=useState(true),[f,b]=useState(false);useEffect(()=>{let C=setTimeout(()=>l(false),ci);return ()=>clearTimeout(C)},[]),useEffect(()=>{let C=Yl[o.type],H=setTimeout(()=>b(true),C),V=setTimeout(()=>n(o.id),C+ci);return ()=>{clearTimeout(H),clearTimeout(V);}},[o.id,o.type,n]);let T=r||f,x=Zl[o.type],y=Jl[o.type],I=Ql[o.type],v=ec(o),B=o.title.length>40?o.title.slice(0,39)+"\u2026":o.title;return jsx(Box,{children:jsxs(Text,{backgroundColor:I,children:[jsxs(Text,{color:T?e.dim:y,children:[" ",x," "]}),jsx(Text,{color:T?e.dim:e.white,bold:!T,children:B}),jsxs(Text,{color:T?e.dim:e.silver,children:[" ",v," "]})]})})}),gi=nn.memo(function({toasts:o,onDismiss:n}){let r=o.slice(0,Kl);return r.length===0?null:jsx(Box,{flexDirection:"column",children:r.map(l=>jsx(tc,{toast:l,onDismiss:n},l.id))})});var rc="\u256D",sc="\u256E",ic="\u2570",ac="\u256F",st="\u2502",Lr=[{key:"\u2191\u2193/j/k",label:"Navigate"},{key:"Tab/\u2190\u2192",label:"Switch tabs"},{key:"Enter",label:"Detail view"},{key:"G",label:"Goals tab"},{key:"T",label:"Tasks tab"},{key:"A",label:"Agents tab"},{key:"L",label:"Logs tab"}],Or=[{key:"N",label:"New item"},{key:"E",label:"Edit"},{key:"D",label:"Delete"},{key:"R",label:"Run task"},{key:"S",label:"Show / Stop"},{key:"C",label:"Cancel"},{key:"A",label:"Approve"},{key:"X",label:"Reject"},{key:"U",label:"Autonomous"},{key:"Z",label:"Undo delete"}],Pr=[{key:"/",label:"Command mode"},{key:"/task add",label:"Create task"},{key:"/run",label:"Execute"},{key:"/watch",label:"Auto-dispatch"},{key:"/config",label:"Settings"},{key:"/help",label:"Help"},{key:"/quit",label:"Exit"}],No=10,Ut=22;function Nr(t){let o=Math.max(0,Math.floor((Ut-t.length-2)/2)),n=Math.max(0,Ut-o-t.length-2);return be(o)+" "+t+" "+be(n)}var mi=nn.memo(function({width:o,height:n}){let r=Ut*3+3+3+2,l=r+2,f=be(l-2),b="KEYBOARD SHORTCUTS",T=Math.max(0,Math.floor((r-b.length)/2)),x=Math.max(0,r-T-b.length),y="Press any key to dismiss",I=Math.max(0,Math.floor((r-y.length)/2)),v=Math.max(0,r-I-y.length),B=Math.max(Lr.length,Or.length,Pr.length),C=B+10,H=Math.max(0,Math.floor((n-C)/2)),V=[];for(let O=0;O<B;O++){let N=O<Lr.length?Lr[O]:null,E=O<Or.length?Or[O]:null,G=O<Pr.length?Pr[O]:null;V.push(jsxs(Text,{children:[jsx(Text,{color:e.amber,children:st}),jsx(Text,{children:" "}),N?jsxs(Fragment,{children:[jsx(Text,{color:e.amber,bold:true,children:N.key.padEnd(No)}),jsx(Text,{color:e.silver,children:N.label.padEnd(Ut-No)})]}):jsx(Text,{children:" ".repeat(Ut)}),jsxs(Text,{color:e.dim,children:[" ",st," "]}),E?jsxs(Fragment,{children:[jsx(Text,{color:e.amber,bold:true,children:E.key.padEnd(No)}),jsx(Text,{color:e.silver,children:E.label.padEnd(Ut-No)})]}):jsx(Text,{children:" ".repeat(Ut)}),jsxs(Text,{color:e.dim,children:[" ",st," "]}),G?jsxs(Fragment,{children:[jsx(Text,{color:e.amber,bold:true,children:G.key.padEnd(No)}),jsx(Text,{color:e.silver,children:G.label.padEnd(Ut-No)})]}):jsx(Text,{children:" ".repeat(Ut)}),jsx(Text,{children:" "}),jsx(Text,{color:e.amber,children:st})]},`r${O}`));}let F=O=>jsxs(Text,{children:[jsx(Text,{color:e.amber,children:st}),jsx(Text,{children:" ".repeat(r)}),jsx(Text,{color:e.amber,children:st})]},O),P=Nr("NAVIGATION"),j=Nr("ACTIONS"),L=Nr("COMMANDS");return jsxs(Box,{flexDirection:"column",paddingX:Math.max(0,Math.floor((o-l)/2)),marginTop:H,children:[jsxs(Text,{color:e.amber,children:[rc,f,sc]}),F("e1"),jsxs(Text,{children:[jsx(Text,{color:e.amber,children:st}),jsx(Text,{children:" ".repeat(T)}),jsx(Text,{color:e.amber,bold:true,children:b}),jsx(Text,{children:" ".repeat(x)}),jsx(Text,{color:e.amber,children:st})]}),F("e2"),jsxs(Text,{children:[jsx(Text,{color:e.amber,children:st}),jsx(Text,{children:" "}),jsx(Text,{color:e.dim,children:P}),jsxs(Text,{color:e.dim,children:[" ",st," "]}),jsx(Text,{color:e.dim,children:j}),jsxs(Text,{color:e.dim,children:[" ",st," "]}),jsx(Text,{color:e.dim,children:L}),jsx(Text,{children:" "}),jsx(Text,{color:e.amber,children:st})]}),F("e3"),V,F("e4"),jsxs(Text,{children:[jsx(Text,{color:e.amber,children:st}),jsx(Text,{children:" ".repeat(I)}),jsx(Text,{color:e.dim,children:y}),jsx(Text,{children:" ".repeat(v)}),jsx(Text,{color:e.amber,children:st})]}),F("e5"),jsxs(Text,{color:e.amber,children:[ic,f,ac]})]})});var hi=[{value:"claude-opus-4-6",label:"Claude Opus 4.6",hint:"most capable"},{value:"claude-sonnet-4-6",label:"Claude Sonnet 4.6",hint:"fast, balanced"},{value:"claude-haiku-4-6",label:"Claude Haiku 4.6",hint:"fastest, cheapest"},{value:"claude-sonnet-4-5-20250929",label:"Claude Sonnet 4.5",hint:"extended thinking"},{value:"claude-haiku-4-5-20251001",label:"Claude Haiku 4.5",hint:"legacy"}],xi=[{value:"gpt-5.3-codex",label:"GPT-5.3 Codex",hint:"default, balanced"},{value:"gpt-5.4",label:"GPT-5.4",hint:"latest"},{value:"gpt-5",label:"GPT-5",hint:"capable"},{value:"gpt-5.3-codex-spark",label:"GPT-5.3 Codex Spark",hint:"fast"},{value:"o3",label:"o3",hint:"reasoning"},{value:"o4-mini",label:"o4-mini",hint:"fast reasoning"},{value:"gpt-5-mini",label:"GPT-5 Mini",hint:"light"},{value:"gpt-5-nano",label:"GPT-5 Nano",hint:"cheapest"},{value:"codex-mini-latest",label:"Codex Mini",hint:"legacy"}],bi=[{value:"auto",label:"Auto",hint:"let Cursor decide"},{value:"composer-1.5",label:"Composer 1.5",hint:"latest agent"},{value:"composer-1",label:"Composer 1",hint:"stable agent"},{value:"gpt-5.3-codex",label:"GPT-5.3 Codex",hint:"OpenAI"},{value:"claude-sonnet-4-6",label:"Claude Sonnet 4.6",hint:"Anthropic"}],Ti=[{value:"",label:"Default",hint:"use model configured in opencode"},{value:"openrouter/anthropic/claude-sonnet-4.6",label:"Claude Sonnet 4.6",hint:"fast, balanced"},{value:"openrouter/anthropic/claude-opus-4.6",label:"Claude Opus 4.6",hint:"most capable"},{value:"openrouter/google/gemini-2.5-pro",label:"Gemini 2.5 Pro",hint:"Google"},{value:"openrouter/google/gemini-2.5-flash",label:"Gemini 2.5 Flash",hint:"Google, fast"},{value:"openrouter/deepseek/deepseek-v3.2",label:"DeepSeek V3.2",hint:"open-source"},{value:"openrouter/deepseek/deepseek-r1:free",label:"DeepSeek R1",hint:"reasoning, free"},{value:"opencode/big-pickle",label:"Big Pickle",hint:"opencode native"}],yi=[{value:"",label:"Default",hint:"use shell adapter default"}],lc=[{value:"claude",label:"Claude",hint:"Claude Code CLI"},{value:"opencode",label:"OpenCode",hint:"OpenCode \u2014 multi-provider"},{value:"codex",label:"Codex",hint:"OpenAI Codex CLI"},{value:"cursor",label:"Cursor",hint:"Cursor Agent CLI"},{value:"shell",label:"Shell",hint:"custom shell command"}],wi=[{value:"1",label:"P1 Critical",hint:"urgent, do first"},{value:"2",label:"P2 High",hint:"important"},{value:"3",label:"P3 Medium",hint:"default priority"},{value:"4",label:"P4 Low",hint:"nice to have"}],fi=60;function Si(t){return t.filter(o=>o.status!=="disabled").map(o=>{let n=(o.role??"").split(`
|
|
11
|
+
`)[0].trim(),r=n.length>fi?n.slice(0,fi-1)+"\u2026":n,l=r?`[${o.adapter}] ${r}`:o.adapter;return {value:o.id,label:o.name,hint:l}})}function Un(t,o="Auto-assign",n="orchestrator picks the best agent"){return [{value:"",label:o,hint:n},...Si(t)]}var Fr=[{value:"",label:"Skip",hint:"no role description"},{value:"Full-stack developer",label:"Full-stack developer",hint:"general purpose"},{value:"Frontend developer",label:"Frontend developer",hint:"React, CSS, UI"},{value:"Backend developer",label:"Backend developer",hint:"APIs, databases, services"},{value:"DevOps engineer",label:"DevOps engineer",hint:"CI/CD, infra, deploys"},{value:"QA / Test engineer",label:"QA / Test engineer",hint:"testing, quality"},{value:"Code reviewer",label:"Code reviewer",hint:"review PRs, find bugs"},{value:"Technical writer",label:"Technical writer",hint:"docs, READMEs"},{value:"__custom__",label:"Custom...",hint:"type your own"}];function ki(t){return [{value:"",label:"None",hint:"no team"},...(t??[]).filter(o=>o.status==="active").map(o=>({value:o.id,label:o.name,hint:`${o.members.length} members`}))]}function Ci(){return [{id:"shop_template",label:"Agent Shop \u2014 choose a template",type:"select",options:a$2.map(t=>({value:t.key,label:t.name,hint:t.description}))}]}function Wr(t,o){return t.map(n=>{switch(n.id){case "name":return {...n,defaultValue:o.name};case "adapter":return {...n,defaultValue:o.adapter};case "model":return {...n,defaultValue:o.model};case "role":return {...n,defaultValue:"__custom__"};case "role_custom":return {...n,defaultValue:o.role,skip:void 0};case "skills":return {...n,defaultValue:o.skills.join(", ")};case "approval_policy":return {...n,defaultValue:o.approval_policy};default:return n}})}function Xn(t,o){let n=ki(o);return [{id:"name",label:"Agent name",type:"text",placeholder:"e.g. alpha, frontend-bot, reviewer",required:true,validate:r=>r.trim()?t?.some(l=>l.name===r.trim())?"Agent with this name already exists":null:"Name is required",suggestions:a$2.map(r=>({value:r.key,label:r.name,hint:r.description}))},{id:"adapter",label:"Provider",type:"select",options:lc},{id:"model",label:"Model",type:"select",getOptions:r=>r.adapter==="opencode"?Ti:r.adapter==="codex"?xi:r.adapter==="cursor"?bi:r.adapter==="shell"?yi:hi},{id:"role",label:"Role / specialization",type:"select",options:Fr},{id:"role_custom",label:"Describe the role",type:"textarea",placeholder:"e.g. Specialist in React and TypeScript",skip:r=>r.role!=="__custom__"},{id:"skills",label:"Skills (comma-separated)",type:"text",placeholder:"e.g. feature-dev:feature-dev, testing-suite:generate-tests"},{id:"approval_policy",label:"Approval policy",type:"text",skip:()=>true},{id:"team",label:"Join team",type:"select",options:n,skip:()=>n.length<=1}]}function Ii(t){let o=t.role==="__custom__"?t.role_custom||void 0:t.role||void 0,n=t.skills?t.skills.split(",").map(l=>l.trim()).filter(Boolean):void 0,r=t.approval_policy||"auto";return {name:t.name,adapter:t.adapter||"claude",role:o,model:t.model||void 0,approval_policy:r,skills:n,team_id:t.team||void 0}}function Mi(t,o){let n=Si(t);return [{id:"name",label:"Team name",type:"text",placeholder:"e.g. frontend, backend, qa",required:true,validate:r=>r.trim()?o?.some(l=>l.name===r.trim())?"Team with this name already exists":null:"Name is required"},{id:"lead",label:"Team lead",type:"select",options:n},{id:"members",label:"Team members",type:"multiselect",getOptions:r=>n.filter(l=>l.value!==r.lead),skip:r=>!n.some(l=>l.value!==r.lead)},{id:"description",label:"Description",type:"textarea",placeholder:"Optional team purpose..."}]}function vi(t){let o=t.members?t.members.split(",").filter(Boolean):[];return {name:t.name,lead_agent_id:t.lead,member_agent_ids:o.length>0?o:void 0,description:t.description||void 0}}function _i(t){let o=Un(t);return [{id:"title",label:"Task title",type:"text",placeholder:"What needs to be done?",required:true,validate:n=>n.trim()?null:"Title is required"},{id:"priority",label:"Priority",type:"select",options:wi,defaultValue:"3",validate:n=>{let r=Number(n);return !Number.isInteger(r)||r<1||r>4?"Priority must be 1-4":null}},{id:"assignee",label:"Assignee",type:"select",options:o,skip:()=>o.length<=1},{id:"description",label:"Description",type:"textarea",placeholder:"Optional details, context, acceptance criteria..."}]}function Ri(t){return {title:t.title,priority:t.priority?parseInt(t.priority,10):void 0,assignee:t.assignee||void 0,description:t.description||void 0}}function Ai(t,o){let n=Un(o,"None / Auto","remove assignee");return [{id:"title",label:"Task title",type:"text",defaultValue:t.title,required:true,validate:r=>r.trim()?null:"Title is required"},{id:"priority",label:"Priority",type:"select",options:wi,defaultValue:String(t.priority),validate:r=>{let l=Number(r);return !Number.isInteger(l)||l<1||l>4?"Priority must be 1-4":null}},{id:"assignee",label:"Assignee",type:"select",options:n,defaultValue:t.assignee??"",skip:()=>n.length<=1},{id:"description",label:"Description",type:"textarea",defaultValue:t.description||"",placeholder:"Optional details..."}]}function $i(t){return {title:t.title,priority:t.priority?parseInt(t.priority,10):void 0,assignee:t.assignee||void 0,description:t.description??""}}function Bi(t,o,n){let r=Fr.find(x=>x.value===t.role),l=r?t.role:t.role?"__custom__":"",f=t.adapter==="opencode"?Ti:t.adapter==="codex"?xi:t.adapter==="cursor"?bi:t.adapter==="shell"?yi:hi,b=ki(n),T=n?.find(x=>x.members.some(y=>y.agent_id===t.id))?.id;return [{id:"name",label:"Agent name",type:"text",defaultValue:t.name,required:true,validate:x=>x.trim()?o?.some(y=>y.id!==t.id&&y.name===x.trim())?"Agent with this name already exists":null:"Name is required"},{id:"model",label:"Model",type:"select",options:f,defaultValue:t.config.model??""},{id:"role",label:"Role / specialization",type:"select",options:Fr,defaultValue:l},{id:"role_custom",label:"Describe the role",type:"textarea",defaultValue:t.role&&!r?t.role:"",placeholder:"e.g. Specialist in React and TypeScript",skip:x=>x.role!=="__custom__"},{id:"team",label:"Team",type:"select",options:b,defaultValue:T??"",skip:()=>b.length<=1}]}var cc=[{value:"1",label:"1 agent",hint:"~0.5 GB RAM, 1 subprocess"},{value:"2",label:"2 agents",hint:"~1 GB RAM, 2 subprocesses"},{value:"3",label:"3 agents",hint:"~1.5 GB RAM, 3 subprocesses"},{value:"4",label:"4 agents",hint:"~2 GB RAM, 4 subprocesses"},{value:"6",label:"6 agents",hint:"~3 GB RAM, 6 subprocesses"},{value:"8",label:"8 agents",hint:"~4 GB RAM, 8 subprocesses"},{value:"10",label:"10 agents",hint:"~5 GB RAM, 10 subprocesses"}],dc=[{value:"all",label:"All",hint:"show everything"},{value:"text",label:"Text",hint:"agent output only"},{value:"tools",label:"Tools",hint:"tool calls, results, files"},{value:"errors",label:"Errors",hint:"errors only"},{value:"events",label:"Events",hint:"lifecycle, system events"}],pi=[{value:"true",label:"On"},{value:"false",label:"Off"}];function Ei(t,o,n){let r=n??{toast:true,bell:false};return [{id:"activity_filter",label:"Activity filter preset",type:"select",options:dc,defaultValue:t},{id:"max_concurrent",label:"Max concurrent agents",type:"select",options:cc,defaultValue:String(o)},{id:"notifications_toast",label:"Toast notifications",type:"select",options:pi,defaultValue:String(r.toast)},{id:"notifications_bell",label:"Bell on completion",type:"select",options:pi,defaultValue:String(r.bell)}]}function Li(t){let o=t.role==="__custom__"?t.role_custom||void 0:t.role||void 0;return {name:t.name,role:o,model:t.model||void 0,team_id:t.team||void 0}}function qn(t){let o=Un(t,"Any agent","auto-assign to autonomous agents");return [{id:"title",label:"Goal title",type:"text",placeholder:'e.g. "Implement OAuth2 login with Google and GitHub"',description:"Be specific \u2014 agents work better with clear, measurable objectives",required:true,validate:n=>n.trim()?null:"Title is required"},{id:"assignee",label:"Assignee",type:"select",description:"Assigned agent gets autonomous mode \u2014 it will plan and execute without prompts",options:o,skip:()=>o.length<=1},{id:"description",label:"Description",type:"textarea",placeholder:"Success criteria, constraints, technical context...",description:'Context matters \u2014 include tech stack, constraints, and what "done" looks like'}]}function Oi(t){return {title:t.title,assignee:t.assignee||void 0,description:t.description||void 0}}function Pi(t,o){let n=Un(o,"Any agent","auto-assign");return [{id:"title",label:"Goal title",type:"text",defaultValue:t.title,description:"Be specific \u2014 agents work better with clear, measurable objectives",required:true,validate:r=>r.trim()?null:"Title is required"},{id:"assignee",label:"Assignee",type:"select",description:"Assigned agent gets autonomous mode \u2014 it will plan and execute without prompts",options:n,defaultValue:t.assignee??"",skip:()=>n.length<=1},{id:"description",label:"Description",type:"textarea",defaultValue:t.description||"",placeholder:"Success criteria, constraints, technical context...",description:'Context matters \u2014 include tech stack, constraints, and what "done" looks like'}]}function Ni(t){return {title:t.title,assignee:t.assignee||void 0,description:t.description??""}}var Di=10,Fi=500,Qn=2048,ho=500,Wi=5,Gr=new Set(["todo","failed","cancelled"]),fc={title:"Goals",description:["Define what your team should achieve.","The orchestrator breaks goals into tasks","and assigns them to agents automatically."],hints:[{key:"N",label:"new goal"},{key:"/",label:"commands"}],nudge:"Add more goals to keep your team focused."},pc={title:"Tasks",description:["Units of work dispatched to agents.","Create them manually or let goals","generate them automatically."],hints:[{key:"N",label:"new task"},{key:"W",label:"start orchestrator"}],nudge:"Add more tasks to keep agents busy."},hc={title:"Agents",description:["AI workers that execute your tasks.","Each agent uses an adapter (claude, codex,","cursor, shell) and has its own role."],hints:[{key:"N",label:"new agent"},{key:"W",label:"start orchestrator"}],nudge:"Add more agents to increase parallelism."},Gi=5e3,Vi=0;function Ku(){Vi=0;}var Hi=/^\[[\w_]+\]$/;function ji(t){return Hi.test(t)?{msgType:"lifecycle",color:e.dim}:t.startsWith("\u2699")?{msgType:"tool",color:e.dim}:t.startsWith("\u2190")?{msgType:"result",color:e.dim}:t.startsWith("\u2713")?{msgType:"lifecycle",color:e.dim}:t.startsWith("\u23F3")?{msgType:"info",color:e.silver}:{msgType:"output",color:e.silver}}var Vr=["#5faf87","#5fafd7","#af87ff","#d7af00","#5fd7d7","#d787af","#afaf5f","#d7875f"],xc=" ".repeat(9),er={system:"\u2666",lifecycle:"\u25B6",output:"\u2502",tool:"\u2699",result:"\u2190",error:"\u2715",file:"\u270E",info:"\u2502"},Zn=["system","lifecycle","output","tool","result","error","file","info"],Do=[{label:"all",types:Zn},{label:"text",types:["output"]},{label:"tools",types:["tool","result","file"]},{label:"errors",types:["error"]},{label:"events",types:["lifecycle","system"]}];function zr(t){let n=(Do.findIndex(r=>r.types.length===t.size&&r.types.every(l=>t.has(l)))+1)%Do.length;return Do[n]}function Yu({projectName:t,tasks:o,agents:n=[],state:r,onRunTask:l,onCreateTask:f,onCancelTask:b$1,onRetryTask:T,onAssignTask:x,onRunAll:y,onDisableAgent:I,onEnableAgent:v,onSubscribeEvents:B,onRefreshTasks:C,onRefreshAgents:H,onRefreshState:V,onLoadHistory:F,onAddAgent:P,onDeleteAgent:j,onApproveTask:L,onRejectTask:O,onDeleteTask:N,onUpdateTask:E,onUpdateAgent:G,onForceStopAgent:z,onCreateTeam:X,onListTeams:R,onJoinTeam:ie,onLeaveTeam:Be,onDisbandTeam:Wt,onSetTeamLead:it,onStartWatch:Re,onStopWatch:Xe,onToggleAutonomous:at,onRefreshGoals:mt,onCreateGoal:Pe,onUpdateGoal:qe,onUpdateGoalStatus:lt,onDeleteGoal:Ke,onGetGoalProgress:oo,onCompleteOnboarding:ke,initialWatchActive:ft,watchError:$t,messageBatchMs:Xt=process.env.VITEST?0:80,initialActivityFilter:pt="all",onSaveActivityFilter:Je,initialMaxConcurrent:ct=a.scheduling.max_concurrent_agents,onSaveMaxConcurrent:Fo,initialNotifications:ln,onSaveNotifications:Ct,version:qt,latestVersion:It,onCheckUpdate:no}){let{exit:Gt}=useApp(),{stdout:ht}=useStdout(),[xt,tr]=useState(It),cn=useRef(no);useEffect(()=>{if(It||!cn.current)return;let i=setTimeout(()=>{cn.current?.().then(p=>{p&&tr(p);}).catch(()=>{});},5e3);return ()=>clearTimeout(i)},[It]);let[xo,ro]=useState({w:ht?.columns??80,h:ht?.rows??24});useEffect(()=>{if(!ht)return;let i=()=>ro({w:ht.columns,h:ht.rows});return ht.on("resize",i),()=>{ht.off("resize",i);}},[ht]);let bt=xo.w,A=xo.h,[S,M]=useState(o),[k,Y]=useState(n),[q,Ce]=useState(r),[ae,de]=useState(ft??!!r.pid),[ye,zt]=useState([]),[Wo,dn]=useState(void 0),[Kt,un]=useState(()=>r.onboardingCompleted||(r.stats?.total_tasks_completed??0)>0?"dismissed":Object.keys(r.running??{}).length>0?"run_started":o.length>0?"task_created":"welcome");useEffect(()=>{if(Kt!=="completed")return;let i=setTimeout(()=>{un("dismissed"),ke?.().catch(()=>{});},5e3);return ()=>clearTimeout(i)},[Kt,ke]);let[$,bo]=useState("tasks"),[gn,Go]=useState(0),[or,Hr]=useState(0),[nr,jr]=useState(0),[Ae,zo]=useState(false),[We,Ur]=useState([]),[Ne,Ee]=useState("none"),[so,Mt]=useState(""),[Tt,Ye]=useState(null),[io,Vo]=useState([]),[Bt,rr]=useState(false),[Xr,Zi]=useState(()=>new Set),[To,sr]=useState(false),[Ho,ir]=useState(false),[qr,Kr]=useState(()=>new Set(Zn)),[jo,ar]=useState(-1),[Ji,Uo]=useState(0),[yo,lr]=useState(()=>{let i=Do.find(p=>p.label===pt);return new Set(i?.types??Zn)}),mn=useMemo(()=>Do.find(p=>p.types.length===yo.size&&p.types.every(s=>yo.has(s)))?.label??"all",[yo]),cr=useMemo(()=>yo.size>=Zn.length?We:We.filter(i=>yo.has(i.msgType??"info")),[We,yo]),[Yr,Qi]=useState(ct),[fn,ea]=useState(ln??{toast:true,bell:false}),[ta,Zr]=useState([]),oa=useRef(0),[dr,Jr]=useState(),Qr=useRef($);Qr.current=$;let es=useRef(S);es.current=S;let ts=useRef(k);ts.current=k;let pn=useRef(fn);pn.current=fn;let hn=useCallback((i,p)=>{if(!pn.current.toast)return;let s=es.current.find(h=>h.id===p),d=s?.title??p,u=s?.assignee?ts.current.find(h=>h.id===s.assignee):void 0;Zr(h=>{let g=[...h,{id:`toast_${oa.current++}`,type:i,title:d,agentName:u?.name,ts:Date.now()}];return g.length>Wi?g.slice(g.length-Wi):g}),pn.current.bell&&(i==="failed"||i==="review")&&process.stdout.write("\x07");},[]),na=useCallback(i=>{Zr(p=>p.filter(s=>s.id!==i));},[]),xn=nn.useRef(new Ln).current,[ra,wo]=useState(0),[os,ns]=useState(false),[Xo,sa]=useState(false),[ia,ur]=useState(0),[aa,gr]=useState(0),[mr,So]=useState(0),[bn,fr]=useState(false),[la,qo]=useState(0),[Tn,Yt]=useState(0),[Vt,rs]=useState([]),[ko,pr]=useState([]),Co=useRef(Vt);Co.current=Vt;let J=useCallback(async i=>{let[p,s,d,u,h]=await Promise.all([C?.()??Promise.resolve(S),H?.()??Promise.resolve(k),V?.()??Promise.resolve(q),i?.includeTeams?R?.()??Promise.resolve(Co.current):Promise.resolve(null),mt?.()??Promise.resolve(ye)]);M(p),Y(s),Ce(d),u!==null&&rs(u),zt(h),ft&&de(!!d.pid);},[C,H,V,R,mt,ft]),Io=useMemo(()=>{let i=new Map;for(let p of ye)i.set(p.id,p);return i},[ye]),Le=useMemo(()=>{let i=[...S].sort((h,g)=>(en[h.status]??9)-(en[g.status]??9));if(!Xo)return i;let p=[],s=[],d=[],u=new Map;for(let h of i)h.goalId&&Io.has(h.goalId)?(u.has(h.goalId)||(d.push(h.goalId),u.set(h.goalId,[])),u.get(h.goalId).push(h)):s.push(h);for(let h of d)p.push(...u.get(h));return [...p,...s]},[S,Xo,Io]),Et=os?Le:Le.slice(0,Di),Mo=Le.length-Et.length,U=Le[gn],Ko=useMemo(()=>{let i=new Map;for(let p of S)i.set(p.id,p.title);return i},[S]),ao=useMemo(()=>{let i=new Map;for(let p of k)i.set(p.id,p.name);return i},[k]),ca=useMemo(()=>{let i=new Map;for(let p of S)if(p.goalId){let s=i.get(p.goalId);s||(s=[],i.set(p.goalId,s)),s.push(p);}return i},[S]),yn=useMemo(()=>{let i=new Map;for(let p=0;p<k.length;p++)i.set(k[p].id,Vr[p%Vr.length]);return i},[k]),ss=useMemo(()=>{let i=new Map;for(let p of We)p.agentId&&i.set(p.agentId,(i.get(p.agentId)??0)+1);return i},[We]),da=useMemo(()=>{let i={};for(let p of We){let s=p.msgType??"info";i[s]=(i[s]??0)+1;}return i},[We]),{agentTeamMap:vo,activeTeamCount:Yo,teamLeadSet:ua}=useMemo(()=>{let i=new Map,p=new Set,s=0;for(let d of Vt)if(d.status==="active"){s++,p.add(d.lead_agent_id);for(let u of d.members)i.set(u.agent_id,d.name);}return {agentTeamMap:i,activeTeamCount:s,teamLeadSet:p}},[Vt]),De=useMemo(()=>{let i=[...k];return i.sort((p,s)=>{let d=vo.get(p.id),u=vo.get(s.id);return d&&!u?-1:!d&&u?1:d&&u&&d!==u?d.localeCompare(u):(Mr[p.status]??9)-(Mr[s.status]??9)}),i},[k,vo]),Q=De[or],dt=useMemo(()=>[...ye].sort((i,p)=>(c[i.status]??9)-(c[p.status]??9)),[ye]),te=dt[nr],ga=useMemo(()=>te?S.filter(i=>i.goalId===te.id):[],[te,S]),hr=useRef(oo);hr.current=oo,useEffect(()=>{if(!te||!hr.current){dn(void 0);return}let i=false;return hr.current(te.id).then(p=>{i||dn(p);}).catch(()=>{}),()=>{i=true;}},[te?.id]);let lo=useRef(new Map),wn=useRef(new Map);useEffect(()=>{for(let[i,p]of Object.entries(q.running))lo.current.set(p.run_id,p.agent_id),wn.current.set(p.run_id,i);if(lo.current.size>Fi){let i=lo.current.size-Fi,p=0;for(let s of lo.current.keys()){if(p++>=i)break;lo.current.delete(s),wn.current.delete(s);}}},[q.running]);let co=useRef([]),Zo=useRef(null),xr=useCallback(()=>{if(Zo.current=null,co.current.length===0)return;let i=co.current;co.current=[],Ur(p=>{if(i.length>=ho)return i.slice(-ho);let s=ho-i.length;return (p.length>s?p.slice(-s):p).concat(i)});},[]);useEffect(()=>()=>{Zo.current&&clearTimeout(Zo.current);},[]);let a=useCallback((i,p,s)=>{let d=new Date,u=d.toLocaleTimeString("en-US",{hour12:false,hour:"2-digit",minute:"2-digit",second:"2-digit"}),h=s?.detail&&s.detail.length>Qn?s.detail.slice(0,Qn)+"\u2026[truncated]":s?.detail;co.current.push({text:i,color:p,time:u,ts:d.getTime(),...s,detail:h}),co.current.length>ho&&(co.current=co.current.slice(-ho)),Xt===0?xr():Zo.current||(Zo.current=setTimeout(xr,Xt));},[xr]);useEffect(()=>{$t&&a(`Watch mode failed: ${$t}. Tasks will not auto-dispatch.`,e.red);},[]);let _o=useCallback((i,p,s,d)=>{let u={key:++Vi,entityType:i,entityId:p,entityName:s,expiresAt:Date.now()+Gi,needsForceStop:d?.needsForceStop};pr(h=>[...h,u]),a(`\u2717 "${s}" will be deleted in ${Math.round(Gi/1e3)}s \u2014 press Z to undo`,e.yellow);},[a]),ma=useCallback(()=>{pr(i=>{if(i.length===0)return i;let p=i[i.length-1];return a(`\u21B6 Undo: "${p.entityName}" restored`,e.green),i.slice(0,-1)});},[a]),is=useCallback(async i=>{try{i.entityType==="task"&&N?await N(i.entityId):i.entityType==="agent"?(i.needsForceStop&&z&&await z(i.entityId),j&&await j(i.entityId)):i.entityType==="goal"&&Ke&&await Ke(i.entityId),a(`\u2713 Deleted "${i.entityName}"`,e.green),J();}catch(p){a(`Failed to delete "${i.entityName}": ${p instanceof Error?p.message:String(p)}`,e.red);}},[N,j,Ke,z,a,J]),as=useRef(is);as.current=is,useEffect(()=>{if(ko.length===0)return;let i=setInterval(()=>{let p=Date.now(),s=[];pr(d=>{let u=d.filter(h=>h.expiresAt<=p?(s.push(h),false):true);return s.length>0?u:d});for(let d of s)as.current(d);},1e3);return ()=>clearInterval(i)},[ko.length>0]),useEffect(()=>{if(!F)return;let i=p=>{let s=new Date(p.timestamp).toLocaleTimeString("en-US",{hour12:false,hour:"2-digit",minute:"2-digit",second:"2-digit"}),d=typeof p.data=="string"?p.data:JSON.stringify(p.data),u,h=e.silver,g="output";if(p.type==="error")u=typeof p.data=="string"?p.data:JSON.stringify(p.data),u=u.slice(0,200),h=e.red,g="error";else if(p.type==="file_changed")u=String(p.data),h=e.purple,g="file";else if(p.type==="done")u="Completed",h=e.green,g="lifecycle";else if(p.type==="tool_call")u=`\u2699 ${p.data?.name??"tool"}()`,h=e.cyan,g="tool";else {let{summary:w}=Yi(d);if(!w)return null;u=w;let Z=ji(u);g=Z.msgType,h=Z.color;}return {text:u,color:h,time:s,ts:new Date(p.timestamp).getTime(),agentId:p.agentId,taskId:p.taskId,msgType:g}};F(p=>{if(p.length===0)return;let s=p.map(i).filter(d=>d!==null);Ur(d=>{let u=[...s,...d];return u.length>ho?u.slice(-ho):u});}).catch(p=>{process.stderr.write(`[TUI] onLoadHistory error: ${p instanceof Error?p.stack??p.message:String(p)}
|
|
12
|
+
`);});},[]),useEffect(()=>{R?.().then(rs).catch(()=>{}),mt?.().then(zt).catch(()=>{});},[]);let Sn=useCallback(()=>{Ye({title:"NEW AGENT",steps:Xn(k,Co.current),kind:"agent"}),Ee("wizard");},[k]),ls=useCallback(()=>{Ye({title:"AGENT SHOP",steps:Ci(),kind:"agent_shop"}),Ee("wizard");},[]),kn=useCallback(()=>{Vo([]),Ye({title:"NEW TASK",steps:_i(k),kind:"task"}),Ee("wizard");},[k]),fa=useCallback(async()=>{try{let{detectClipboardType:i,getClipboardImage:p}=await import('./clipboard-service-WVON5ZN4.js'),s=await i();if(s!=="image")return a(s==="text"?"Clipboard has text, not image":"Clipboard is empty",e.dim),s;let d=await p();if(!d)return a("Failed to read clipboard image",e.red),"empty";let{mkdtemp:u,writeFile:h}=await import('fs/promises'),{tmpdir:g}=await import('os'),{join:w}=await import('path'),Z=await u(w(g(),"orch-paste-")),Ot=w(Z,`clipboard-${Date.now()}.${d.ext}`);return await h(Ot,d.data),Vo(uo=>[...uo,Ot]),a(`\u{1F4CE} Image attached (${Math.round(d.data.length/1024)}KB)`,e.green),"image"}catch{return a("Clipboard paste failed",e.red),"empty"}},[a]),pa=useCallback(i=>{Ye({title:"EDIT TASK",steps:Ai(i,k),kind:"edit_task",targetId:i.id}),Ee("wizard");},[k]),cs=useCallback(()=>{Ye({title:"NEW TEAM",steps:Mi(k,Vt),kind:"team"}),Ee("wizard");},[k]),ha=useCallback(i=>{Ye({title:"EDIT AGENT",steps:Bi(i,k,Vt),kind:"edit_agent",targetId:i.id}),Ee("wizard");},[Vt]),ds=useCallback(()=>{Ye({title:"SETTINGS",steps:Ei(mn,Yr,fn),kind:"config"}),Ee("wizard");},[mn,Yr]),xa=useCallback(i=>{Ee("none");let p=Tt?.kind,s=Tt?.targetId;if(Ye(null),p==="agent_shop"){let d=i.shop_template,u=d?b(d):void 0;if(u){let h=Xn(k,Co.current),g=Wr(h,u);Ye({title:`NEW AGENT \u2014 ${u.name}`,steps:g,kind:"agent_from_shop"}),Ee("wizard");}else a("No template selected",e.yellow);return}if((p==="agent"||p==="agent_from_shop")&&P){let d=Ii(i);a(`Creating agent "${d.name}"...`,e.amber),P(d.name,d.adapter,{model:d.model,role:d.role,approval_policy:d.approval_policy,skills:d.skills}).then(u=>{a(`\u2713 Created agent "${u.name}" (${u.id}, ${u.adapter})`,e.green),d.team_id&&ie?ie(d.team_id,u.id).then(h=>{a(`\u2713 Joined team "${h.name}"`,e.green),J({includeTeams:true});},h=>a(`Failed to join team: ${h instanceof Error?h.message:String(h)}`,e.red)):J();},u=>a(`Failed: ${u instanceof Error?u.message:String(u)}`,e.red));}else if(p==="team"&&X){let d=vi(i);a(`Creating team "${d.name}"...`,e.amber),X(d).then(u=>{a(`\u2713 Created team "${u.name}" (${u.id}, ${u.members.length} members)`,e.green),J({includeTeams:true});},u=>a(`Failed: ${u instanceof Error?u.message:String(u)}`,e.red));}else if(p==="task"&&f){let d=Ri(i),u=io.length>0?[...io]:void 0;Vo([]),a(`Creating "${d.title}"...`,e.amber),f(d.title,{priority:d.priority,description:d.description,attachments:u}).then(h=>{a(`\u2713 Created "${h.title}" (${h.id})${u?` \u{1F4CE}${u.length}`:""}`,e.green),d.assignee&&x&&x(h.id,d.assignee).catch(()=>{}),J();},h=>a(`Failed: ${h instanceof Error?h.message:String(h)}`,e.red));}else if(p==="edit_task"&&s&&E){let d=$i(i),u=io.length>0?[...io]:void 0;Vo([]),a("Updating task...",e.amber),E(s,{...d,attachments:u}).then(h=>{a(`\u2713 Updated "${h.title}"${u?` \u{1F4CE}${u.length}`:""}`,e.green),d.assignee&&x&&x(s,d.assignee).catch(()=>{}),J();},h=>a(`Failed: ${h instanceof Error?h.message:String(h)}`,e.red));}else if(p==="edit_agent"&&s&&G){let d=Li(i),u=d.team_id??"",h=Vt.find(g=>g.members.some(w=>w.agent_id===s))?.id??"";a("Updating agent...",e.amber),G(s,{name:d.name,role:d.role,model:d.model}).then(g=>{a(`\u2713 Updated agent "${g.name}"`,e.green);let w=[];h&&h!==u&&Be&&w.push(Be(h,s).then(Z=>a(`\u2713 Left team "${Z.name}"`,e.green),Z=>a(`Failed to leave team: ${Z instanceof Error?Z.message:String(Z)}`,e.red))),u&&u!==h&&ie&&w.push(ie(u,s).then(Z=>a(`\u2713 Joined team "${Z.name}"`,e.green),Z=>a(`Failed to join team: ${Z instanceof Error?Z.message:String(Z)}`,e.red))),Promise.all(w).then(()=>J({includeTeams:w.length>0}));},g=>a(`Failed: ${g instanceof Error?g.message:String(g)}`,e.red));}else if(p==="config"){if(i.activity_filter){let g=Do.find(w=>w.label===i.activity_filter);g&&(lr(new Set(g.types)),Je?.(g.label));}if(i.max_concurrent){let g=parseInt(i.max_concurrent,10);g>0&&(Qi(g),Fo?.(g));}let d=i.notifications_toast==="true",u=i.notifications_bell==="true",h={toast:d,bell:u};ea(h),Ct?.(h),a("Settings saved",e.green);}else if(p==="goal"&&Pe){let d=Oi(i);a(`Creating goal "${d.title}"...`,e.amber),Pe(d).then(u=>{a(`\u2713 Created goal "${u.title}" (${u.id})`,e.green),J();},u=>a(`Failed: ${u instanceof Error?u.message:String(u)}`,e.red));}else if(p==="edit_goal"&&s&&qe){let d=Ni(i);a("Updating goal...",e.amber),qe(s,d).then(u=>{a(`\u2713 Updated goal "${u.title}"`,e.green),J();},u=>a(`Failed: ${u instanceof Error?u.message:String(u)}`,e.red));}},[Tt,P,f,X,ie,Be,x,E,G,at,Pe,qe,a,J,Je,Fo,fn,Ct,Vt,io]),ba=useCallback(()=>{Ee("none"),Ye(null),Vo([]);},[]),Ta=useCallback(i=>{let p=b(i);if(!p)return;let s=Xn(k,Co.current),d=Wr(s,p);Ye({title:`NEW AGENT \u2014 ${p.name}`,steps:d,kind:"agent_from_shop"}),Ee("wizard");},[]);useEffect(()=>{if(!B)return;let i=null,p=()=>{i||(i=setTimeout(()=>{i=null,J().catch(()=>{});},150));},s=B(d=>{if(d.type==="agent:started"&&(lo.current.set(d.runId,d.agentId),wn.current.set(d.runId,d.taskId)),Pc(d,a,lo.current,wn.current),d.type==="task:created"?un(u=>u==="welcome"?"task_created":u):d.type==="agent:started"?un(u=>u==="task_created"?"run_started":u):d.type==="task:status_changed"&&d.to==="done"&&un(u=>u==="run_started"?"completed":u),d.type==="task:status_changed"&&(d.to==="done"?hn("done",d.taskId):d.to==="failed"?hn("failed",d.taskId):d.to==="review"&&hn("review",d.taskId),pn.current.toast&&Qr.current!=="tasks")){let u=d.to==="done"?e.green:d.to==="failed"?e.red:d.to==="review"?e.blue:void 0;u&&Jr({tab:"tasks",color:u});}(d.type==="task:status_changed"||d.type==="task:created"||d.type==="task:assigned"||d.type==="agent:started"||d.type==="agent:completed"||d.type==="run:retry"||d.type==="goal:created"||d.type==="goal:status_changed"||d.type==="goal:updated"||d.type==="goal:deleted")&&p();});return ()=>{s(),i&&clearTimeout(i);}},[B,a,J,hn]);let br=ae?"watching":"idle",ya=q.started_at?g(q.started_at):void 0,us=q.stats.total_tokens.total,gs=useMemo(()=>{let i={running:0,retrying:0,review:0,todo:0,done:0,failed:0,cancelled:0};for(let p of S)p.status==="in_progress"?i.running++:p.status==="retrying"?i.retrying++:p.status==="review"?i.review++:p.status==="todo"?i.todo++:p.status==="done"?i.done++:p.status==="failed"?i.failed++:p.status==="cancelled"&&i.cancelled++;return {...i,teams:Yo}},[S,Yo]);gs.running;let wa=useMemo(()=>({input:q.stats.total_tokens.input??0,output:q.stats.total_tokens.output??0,reasoning:q.stats.total_tokens.reasoning??0,total:us,cache_read:q.stats.total_tokens.cache_read??0,cache_write:q.stats.total_tokens.cache_write??0}),[q.stats.total_tokens,us]),vt=Math.max(4,A-9),Sa=vo.size,ka=k.length>Sa,Ca=Yo>0?Yo+(ka?1:0):0,Ia=useMemo(()=>{if(!Xo||Io.size===0)return 0;let i=0,p=new Set,s=false;for(let d of Et)d.goalId&&Io.has(d.goalId)?p.has(d.goalId)||(p.add(d.goalId),i++):s=true;return s&&i++,i},[Xo,Io,Et]),Ma=$==="goals"?dt.length+1:$==="tasks"?Et.length+1+(Mo>0?1:0)+Ia:$==="agents"?k.length+1+Ca:0,va=Math.min(Ma+1,Math.ceil(vt*.5)),_a=$==="logs"?vt:Math.max(2,Math.min(va,vt-4)),we,Lt;if($==="logs")we=vt,Lt=0;else if(bn)we=0,Lt=Math.max(1,vt);else {let i=Math.max(3,Math.min(_a+mr,vt-4));we=i,Lt=Math.max(1,vt-i);}let ve=Math.max(10,bt-2),_t=useMemo(()=>Ne==="command"?Hs(so):[],[Ne,so]),Ro=vt-4-3;useEffect(()=>{mr>Ro&&So(Ro),mr<-Ro&&So(-Ro);},[vt]),useEffect(()=>{wo(i=>Math.min(i,Math.max(0,Et.length-we)));},[Et.length,we]),useEffect(()=>{ur(i=>Math.min(i,Math.max(0,De.length-we)));},[De.length,we]),useEffect(()=>{gr(i=>Math.min(i,Math.max(0,dt.length-we)));},[dt.length,we]);let Ra=useCallback(i=>{let s=i.trim().replace(/^\//,"").split(/\s+/),d=s[0]?.toLowerCase();if(!d)return;let u=h=>h instanceof Error?h.message:String(h);switch(d){case "cancel":{if(!U){a("No task selected",e.yellow);return}if(!b$1)return;a(`Cancelling "${U.title}"...`,e.amber),b$1(U.id).then(()=>{a(`\u2713 Cancelled "${U.title}"`,e.green),J();},h=>a(`Failed: ${u(h)}`,e.red));return}case "retry":{if(!U){a("No task selected",e.yellow);return}if(!T)return;a(`Retrying "${U.title}"...`,e.amber),T(U.id).then(()=>{a(`\u2713 Retried "${U.title}"`,e.green),J();},h=>a(`Failed: ${u(h)}`,e.red));return}case "assign":{if(!U){a("No task selected",e.yellow);return}if(!x||!s[1]){a("Usage: assign <agent>",e.yellow);return}a(`Assigning "${U.title}" to ${s[1]}...`,e.amber),x(U.id,s[1]).then(()=>{a(`\u2713 Assigned "${U.title}" to ${s[1]}`,e.green),J();},h=>a(`Failed: ${u(h)}`,e.red));return}case "task":{let h=s[1]?.toLowerCase();if(h==="add"){let g=s.slice(2).join(" ");if(!g){kn();return}if(!f){a("Create not available",e.yellow);return}a(`Creating "${g}"...`,e.amber),f(g).then(w=>{a(`\u2713 Created "${w.title}" (${w.id})`,e.green),J();},w=>a(`Failed: ${u(w)}`,e.red));}else if(h==="list"){let g=Le.map(w=>` ${w.id} ${w.status.padEnd(11)} ${w.title}`);if(g.length===0)a("No tasks",e.dim);else for(let w of g)a(w,e.cyan);}else if(h==="show"){let g=s[2]?Le.find(w=>w.id===s[2]):U;if(!g){a("No task selected or id given",e.yellow);return}a(`${g.id} ${g.status} P${g.priority} "${g.title}"`,e.cyan),g.assignee&&a(` agent: ${g.assignee}`,e.dim),g.description&&a(` ${g.description.slice(0,100)}`,e.dim);}else if(h==="cancel"){let g=s[2]?Le.find(w=>w.id===s[2]):U;if(!g){a("No task selected or id given",e.yellow);return}if(!b$1)return;a(`Cancelling "${g.title}"...`,e.amber),b$1(g.id).then(()=>{a(`\u2713 Cancelled "${g.title}"`,e.green),J();},w=>a(`Failed: ${u(w)}`,e.red));}else if(h==="retry"){let g=s[2]?Le.find(w=>w.id===s[2]):U;if(!g){a("No task selected or id given",e.yellow);return}if(!T)return;a(`Retrying "${g.title}"...`,e.amber),T(g.id).then(()=>{a(`\u2713 Retried "${g.title}"`,e.green),J();},w=>a(`Failed: ${u(w)}`,e.red));}else if(h==="assign"){let g=s[2]?Le.find(Ot=>Ot.id===s[2]):void 0,w=g??U,Z=g?s[3]:s[2];if(!w){a("No task selected or id given",e.yellow);return}if(!Z){a("Usage: /task assign [id] <agent>",e.yellow);return}if(!x)return;a(`Assigning "${w.title}" to ${Z}...`,e.amber),x(w.id,Z).then(()=>{a(`\u2713 Assigned "${w.title}" to ${Z}`,e.green),J();},Ot=>a(`Failed: ${u(Ot)}`,e.red));}else if(h==="approve"){let g=s[2]?Le.find(w=>w.id===s[2]):U;if(!g){a("No task selected or id given",e.yellow);return}if(g.status!=="review"){a(`Cannot approve \u2014 status is ${g.status}`,e.yellow);return}if(!L)return;a(`Approving "${g.title}"...`,e.amber),L(g.id).then(()=>{a(`\u2713 Approved "${g.title}"`,e.green),J();},w=>a(`Failed: ${u(w)}`,e.red));}else if(h==="reject"){let g=s[2]?Le.find(Z=>Z.id===s[2]):U;if(!g){a("No task selected or id given",e.yellow);return}if(g.status!=="review"){a(`Cannot reject \u2014 status is ${g.status}`,e.yellow);return}if(!O)return;let w=s.slice(s[2]&&Le.find(Z=>Z.id===s[2])?3:2).join(" ").trim()||void 0;a(`Rejecting "${g.title}"${w?" with feedback":""}...`,e.amber),O(g.id,w).then(()=>{a(`\u2713 Rejected "${g.title}" \u2192 todo`,e.green),J();},Z=>a(`Failed: ${u(Z)}`,e.red));}else if(h==="delete"){let g=s[2]?Le.find(w=>w.id===s[2]):U;if(!g){a("No task selected or id given",e.yellow);return}if(g.status==="in_progress"){a("Cannot delete \u2014 task is running",e.yellow);return}if(!N)return;_o("task",g.id,g.title);}else a("Usage: /task add|list|show|cancel|retry|assign|approve|reject|delete",e.yellow);return}case "agent":{let h=s[1]?.toLowerCase();if(h==="add"){let g=s[2];if(!g){Sn();return}if(!P){a("Agent creation not available",e.yellow);return}let w=s[3];a(`Creating agent "${g}"...`,e.amber),P(g,w).then(Z=>{a(`\u2713 Created agent "${Z.name}" (${Z.id}, ${Z.adapter})`,e.green),J();},Z=>a(`Failed: ${u(Z)}`,e.red));}else if(h==="list"){let g=De.map(w=>` ${w.id} ${w.status.padEnd(8)} ${w.name} (${w.adapter})`);if(g.length===0)a("No agents",e.dim);else for(let w of g)a(w,e.cyan);}else if(h==="disable"){let g=s[2]?De.find(w=>w.id===s[2]||w.name===s[2]):Q;if(!g){a("No agent selected or id given",e.yellow);return}if(!I)return;a(`Disabling ${g.name}...`,e.amber),I(g.id).then(()=>{a(`\u2713 Disabled ${g.name}`,e.green),J();},w=>a(`Failed: ${u(w)}`,e.red));}else if(h==="enable"){let g=s[2]?De.find(w=>w.id===s[2]||w.name===s[2]):Q;if(!g){a("No agent selected or id given",e.yellow);return}if(!v)return;a(`Enabling ${g.name}...`,e.amber),v(g.id).then(()=>{a(`\u2713 Enabled ${g.name}`,e.green),J();},w=>a(`Failed: ${u(w)}`,e.red));}else if(h==="delete"||h==="remove"){let g=s[2]?De.find(w=>w.id===s[2]||w.name===s[2]):Q;if(!g){a("No agent selected or id given",e.yellow);return}if(g.status==="running"){a("Cannot delete \u2014 agent is running",e.yellow);return}if(!j){a("Agent deletion not available",e.yellow);return}_o("agent",g.id,g.name);}else if(h==="autonomous"||h==="auto"){let g=s[2]?De.find(w=>w.id===s[2]||w.name===s[2]):Q;if(!g){a("No agent selected or id given",e.yellow);return}if(!at){a("Autonomous toggle not available",e.yellow);return}g.autonomous?(a(`Disabling autonomous mode for "${g.name}"...`,e.amber),at(g.id,false).then(()=>{a(`${go} ${g.name} autonomous OFF`,e.cyan),J();},w=>a(`Failed: ${u(w)}`,e.red))):(a(`Enabling autonomous mode for "${g.name}"...`,e.amber),at(g.id,true).then(()=>{a(`${go} ${g.name} autonomous ON`,e.cyan),J();},w=>a(`Failed: ${u(w)}`,e.red)));}else h==="shop"?ls():a("Usage: /agent add|list|disable|enable|delete|autonomous|shop",e.yellow);return}case "team":{let h=s[1]?.toLowerCase();if(h==="create"||h==="add")cs();else if(h==="list"){let g=Co.current;if(g.length===0)a("No teams",e.dim);else for(let w of g)a(` ${w.id} ${w.status.padEnd(8)} ${w.name} (${w.members.length} members)`,e.cyan);}else if(h==="join"){if(!ie){a("Join not available",e.yellow);return}let g=s[2],w=s[3]??Q?.id;if(!g||!w){a("Usage: /team join <teamId> [agentId]",e.yellow);return}a(`Joining team ${g}...`,e.amber),ie(g,w).then(Z=>{a(`\u2713 Agent joined team "${Z.name}"`,e.green),J({includeTeams:true});},Z=>a(`Failed: ${u(Z)}`,e.red));}else if(h==="leave"){if(!Be){a("Leave not available",e.yellow);return}let g=s[2],w=s[3]??Q?.id;if(!g||!w){a("Usage: /team leave <teamId> [agentId]",e.yellow);return}a(`Leaving team ${g}...`,e.amber),Be(g,w).then(Z=>{a(`\u2713 Agent left team "${Z.name}"`,e.green),J({includeTeams:true});},Z=>a(`Failed: ${u(Z)}`,e.red));}else if(h==="disband"){if(!Wt){a("Disband not available",e.yellow);return}let g=s[2];if(!g){a("Usage: /team disband <teamId>",e.yellow);return}a(`Disbanding team ${g}...`,e.amber),Wt(g).then(()=>{a("\u2713 Team disbanded",e.green),J({includeTeams:true});},w=>a(`Failed: ${u(w)}`,e.red));}else if(h==="set-lead"){if(!it){a("Set-lead not available",e.yellow);return}let g=s[2],w=s[3];if(!g||!w){a("Usage: /team set-lead <teamId> <agentId>",e.yellow);return}a(`Setting lead for team ${g}...`,e.amber),it(g,w).then(Z=>{a(`\u2713 New lead for team "${Z.name}"`,e.green),J({includeTeams:true});},Z=>a(`Failed: ${u(Z)}`,e.red));}else a("Usage: /team create|list|join|leave|disband|set-lead",e.yellow);return}case "goal":{let h=s[1]?.toLowerCase();if(h==="add"||h==="create"){let g=s.slice(2).join(" ").trim();if(!g){let w=qn(k);Ye({title:"New Goal",steps:w,kind:"goal"}),Ee("wizard");return}if(!Pe){a("Goal creation not available",e.yellow);return}a(`Creating goal "${g}"...`,e.amber),Pe({title:g}).then(w=>{a(`\u2713 Created goal "${w.title}" (${w.id})`,e.green),J();},w=>a(`Failed: ${u(w)}`,e.red));}else if(h==="list"){let g=dt.map(w=>` ${w.id} ${w.status.padEnd(8)} ${w.title}`);if(g.length===0)a("No goals",e.dim);else for(let w of g)a(w,e.cyan);}else if(h==="show"){let g=s[2]?dt.find(w=>w.id===s[2]):te;if(!g){a("No goal selected or id given",e.yellow);return}a(`${g.id} ${g.status} "${g.title}"`,e.cyan),g.description&&a(` ${g.description.slice(0,100)}`,e.dim);}else if(h==="status"){let g=s[2]?dt.find(uo=>uo.id===s[2]):void 0,w=g??te;if(!w){a("No goal selected or id given",e.yellow);return}let Z=s[g?3:2];if(!Z||!a$1.includes(Z)){a("Usage: /goal status [id] <active|paused|achieved|abandoned>",e.yellow);return}let Ot=Z;if(!lt){a("Status update not available",e.yellow);return}a(`Updating goal status to ${Ot}...`,e.amber),lt(w.id,Ot).then(uo=>{a(`\u2713 Goal "${uo.title}" \u2192 ${Ot}`,e.green),J();},uo=>a(`Failed: ${u(uo)}`,e.red));}else if(h==="delete"){let g=s[2]?dt.find(w=>w.id===s[2]):te;if(!g){a("No goal selected or id given",e.yellow);return}if(!Ke){a("Goal deletion not available",e.yellow);return}_o("goal",g.id,g.title);}else a("Usage: /goal add|list|show|status|delete",e.yellow);return}case "run":{let h=s[1]??U?.id;if(!h){a("No task selected or id given",e.yellow);return}if(!l){a("Run not available",e.yellow);return}let g=Le.find(w=>w.id===h);if(g&&!Gr.has(g.status)){a(`Cannot run \u2014 status is ${g.status}`,e.yellow);return}a(`Running ${h}...`,e.amber),l(h).then(()=>{a(`\u2713 Dispatched ${h}`,e.green),J();},w=>a(`Failed: ${u(w)}`,e.red));return}case "run-all":{if(!y){a("Run-all not available",e.yellow);return}a("Running all todo tasks...",e.amber),y().then(()=>{a("\u2713 Dispatched all todo tasks",e.green),J();},h=>a(`Failed: ${u(h)}`,e.red));return}case "watch":{if(ae){a("Watch mode already active",e.yellow);return}if(!Re){a("Watch not available",e.yellow);return}a("Starting watch mode...",e.amber),Re().then(()=>{de(true),a("\u2713 Watch mode started",e.green);},h=>a(`Failed: ${u(h)}`,e.red));return}case "pause":{if(!ae){a("Watch mode not active",e.yellow);return}if(!Xe){a("Pause not available",e.yellow);return}a("Pausing watch mode...",e.amber),Xe().then(()=>{de(false),a("\u2713 Watch mode paused",e.green);},h=>a(`Failed: ${u(h)}`,e.red));return}case "config":{s[1]?.toLowerCase()==="activity-filter"?lr(g=>{let w=zr(g);return Je?.(w.label),a(`Activity filter: ${w.label}`,e.amber),new Set(w.types)}):ds();return}case "status":{let h=S.filter(g=>g.status==="in_progress").length;a(`${br} ${h} running ${S.length} tasks ${De.length} agents`,e.cyan);return}case "help":{for(let[h,g]of Object.entries(fo)){let w=g.sub?" "+g.sub.join("|"):g.args?" "+g.args:"";a(` /${h}${w} \u2014 ${g.help}`,e.silver);}return}case "quit":{Gt();return}case "disable":{if(!Q){a("No agent selected",e.yellow);return}if(!I)return;a(`Disabling ${Q.name}...`,e.amber),I(Q.id).then(()=>{a(`\u2713 Disabled ${Q.name}`,e.green),J();},h=>a(`Failed: ${u(h)}`,e.red));return}case "enable":{if(!Q){a("No agent selected",e.yellow);return}if(!v)return;a(`Enabling ${Q.name}...`,e.amber),v(Q.id).then(()=>{a(`\u2713 Enabled ${Q.name}`,e.green),J();},h=>a(`Failed: ${u(h)}`,e.red));return}default:a(`Unknown: ${d}. Type /help for commands`,e.yellow);}},[U,Q,Le,De,S,br,ae,b$1,T,x,y,l,f,I,v,P,L,O,N,ie,Be,Wt,it,Re,Xe,a,Gt,J,kn,Sn,cs,ds]);useInput((i,p)=>{if(!(Bt&&(rr(false),i==="?"||p.escape||i==="\x1BOP"))&&!To){if((p.ctrl||p.meta)&&i==="s"&&Ne==="wizard"&&Tt?.kind==="agent"){ls();return}if(Ne!=="none"){if(p.escape){Ee("none"),Mt(""),xn.reset();return}if(p.return){let s=so.trim();if(!s)return;if(Ne==="new_task"){if(!f)return;Ee("none"),Mt(""),a(`Creating "${s}"...`,e.amber),f(s).then(d=>{a(`\u2713 Created "${d.title}" (${d.id})`,e.green),J();},d=>a(`Failed to create: ${d instanceof Error?d.message:String(d)}`,e.red));}else if(Ne==="command"){let d=s;if(_t.length>0&&_t[Tn]){let u=_t[Tn],h=u.cmd.replace(/\s+\[.*\]$/,"");if((h.startsWith(s)||s==="/")&&(d=h),u.subs&&!h.includes(" ")){Mt(h+" "),Yt(0);return}}Ee("none"),Mt(""),Yt(0),xn.push(d),Ra(d);}return}if(p.tab&&Ne==="command"){if(_t.length>0){let s=_t[Tn];if(s){let d=s.cmd.replace(/\s+\[.*\]$/,"");Mt(d+(s.subs?" ":"")),Yt(0);}}else {let s=_r(so);s&&Mt(d=>d+s);}return}if(p.upArrow&&Ne==="command"){if(_t.length>0)Yt(s=>Math.max(0,s-1));else {let s=xn.prev();s!==null&&Mt(s);}return}if(p.downArrow&&Ne==="command"){if(_t.length>0)Yt(s=>Math.min(_t.length-1,s+1));else {let s=xn.next();Mt(s??"");}return}if(p.backspace||p.delete){Mt(s=>s.slice(0,-1)),Yt(0);return}i&&!p.ctrl&&!p.meta&&(Mt(s=>s+i),Yt(0));return}if(i.toLowerCase()==="q"){Gt();return}if(p.escape){if(Ae){zo(false),qo(0);return}if($==="logs"&&jo>=0){ar(-1),Uo(0);return}return}if((i==="+"||i==="=")&&$!=="logs"){bn?(fr(false),So(-Math.floor(vt/2))):So(s=>Math.max(-Ro,s-3));return}if(i==="-"&&$!=="logs"){bn?(fr(false),So(Math.floor(vt/2))):So(s=>Math.min(Ro,s+3));return}if(i==="M"&&$!=="logs"){fr(s=>!s);return}if(i==="?"){rr(true);return}if(i==="\x1BOP"){rr(true);return}if(i==="/"&&!Ae){Ee("command"),Mt("/"),Yt(0);return}if((i==="a"||i==="A")&&$==="logs"&&!Ae&&!To&&!Ho){sr(true);return}if(i==="f"&&$==="logs"&&!Ae&&!To&&!Ho){ir(true);return}if(i==="F"&&$==="logs"&&!Ae&&!To&&!Ho){Kr(s=>new Set(zr(s).types));return}if((i==="z"||i==="Z")&&ko.length>0){ma();return}if((i==="f"||i==="F")&&($==="tasks"||$==="agents"||$==="goals")&&!Ae){lr(s=>{let d=zr(s);return Je?.(d.label),new Set(d.types)});return}if((i==="n"||i==="N")&&$==="tasks"&&!Ae&&f){kn();return}if((i==="n"||i==="N")&&$==="agents"&&!Ae&&P){Sn();return}if((i==="n"||i==="N")&&$==="goals"&&!Ae&&Pe){let s=qn(k);Ye({title:"New Goal",steps:s,kind:"goal"}),Ee("wizard");return}if((i==="e"||i==="E")&&$==="goals"&&te&&qe){let s=Pi(te,k);Ye({title:`Edit Goal: ${te.title}`,steps:s,kind:"edit_goal",targetId:te.id}),Ee("wizard");return}if((i==="d"||i==="D")&&$==="goals"&&te&&Ke){_o("goal",te.id,te.title);return}if((i==="c"||i==="C")&&$==="goals"&&te&<){(te.status==="active"||te.status==="paused")&&(a(`Marking goal "${te.title}" as achieved...`,e.amber),lt(te.id,"achieved").then(()=>{a(`\u2713 Goal "${te.title}" achieved`,e.green),J();},s=>a(`Failed: ${s instanceof Error?s.message:String(s)}`,e.red)));return}if((i==="x"||i==="X")&&$==="goals"&&te&<){(te.status==="active"||te.status==="paused")&&(a(`Abandoning goal "${te.title}"...`,e.amber),lt(te.id,"abandoned").then(()=>{a(`\u2713 Goal "${te.title}" abandoned`,e.dim),J();},s=>a(`Failed: ${s instanceof Error?s.message:String(s)}`,e.red)));return}if((i==="p"||i==="P")&&$==="goals"&&te&<){let s=te.status==="paused"?"active":"paused";(te.status==="active"||te.status==="paused")&<(te.id,s).then(()=>{a(`Goal "${te.title}" ${s}`,e.cyan),J();},d=>a(`Failed: ${d instanceof Error?d.message:String(d)}`,e.red));return}if((i==="a"||i==="A")&&$==="tasks"&&U?.status==="review"&&L){a(`Approving "${U.title}"...`,e.amber),L(U.id).then(()=>{a(`\u2713 Approved "${U.title}"`,e.green),J();},s=>a(`Failed: ${s instanceof Error?s.message:String(s)}`,e.red));return}if((i==="x"||i==="X")&&$==="tasks"&&U?.status==="review"&&O){a(`Rejecting "${U.title}"...`,e.amber),O(U.id).then(()=>{a(`\u2713 Rejected "${U.title}" \u2192 todo`,e.green),J();},s=>a(`Failed: ${s instanceof Error?s.message:String(s)}`,e.red));return}if((i==="c"||i==="C")&&$==="tasks"&&U&&b$1){if(U.status==="done"||U.status==="failed"||U.status==="cancelled"){a(`Cannot cancel \u2014 status is ${U.status}`,e.yellow);return}a(`Cancelling "${U.title}"...`,e.amber),b$1(U.id).then(()=>{a(`\u2713 Cancelled "${U.title}"`,e.green),J();},s=>a(`Failed: ${s instanceof Error?s.message:String(s)}`,e.red));return}if((i==="e"||i==="E")&&$==="tasks"&&U&&E){pa(U);return}if((i==="e"||i==="E")&&$==="agents"&&Q&&G){ha(Q);return}if((i==="s"||i==="S")&&$==="tasks"){ns(s=>!s),Go(0),wo(0);return}if((i==="g"||i==="G")&&$==="tasks"&&!Ae){sa(s=>!s),Go(0),wo(0);return}if((i==="s"||i==="S")&&$==="agents"&&Q&&z){if(!Object.values(q.running).some(d=>d.agent_id===Q.id)&&Q.status!=="running"){a(`Agent "${Q.name}" is not running`,e.yellow);return}a(`Force-stopping agent "${Q.name}"...`,e.amber),z(Q.id).then(()=>{a(`\u2713 Stopped agent "${Q.name}"`,e.green),J();},d=>a(`Failed: ${d instanceof Error?d.message:String(d)}`,e.red));return}if((i==="d"||i==="D")&&$==="tasks"&&U&&U.status!=="in_progress"&&N){_o("task",U.id,U.title);return}if((i==="d"||i==="D")&&$==="agents"&&Q&&j){let s=Object.values(q.running).some(d=>d.agent_id===Q.id);if(s&&!z){a(`Cannot delete \u2014 agent "${Q.name}" is running. Press S to stop first.`,e.yellow);return}_o("agent",Q.id,Q.name,{needsForceStop:s});return}if((i==="u"||i==="U")&&$==="agents"&&Q&&at){let s=!Q.autonomous;a(`${s?"Enabling":"Disabling"} autonomous mode for "${Q.name}"...`,e.amber),at(Q.id,s).then(()=>{a(`${go} ${Q.name} autonomous ${s?"ON":"OFF"}`,e.cyan),J();},d=>a(`Failed: ${d instanceof Error?d.message:String(d)}`,e.red));return}if(!Ae){if(i==="g"||i==="G"){bo("goals");return}if(i==="t"||i==="T"){bo("tasks");return}if(i==="a"||i==="A"){bo("agents");return}if(i==="l"||i==="L"){bo("logs");return}}if(!Ae){let s=$n.map(u=>u.id),d=s.indexOf($);if(p.tab||p.rightArrow){bo(s[(d+1)%s.length]);return}if(p.leftArrow){bo(s[(d+s.length-1)%s.length]);return}}if(p.return){let s=Mo>0?Et.length:-1;if($==="tasks"&&gn===s){ns(u=>!u),Go(0),wo(0);return}let d=Et.length+(Mo>0?1:0);if($==="tasks"&&gn===d&&f){kn();return}if($==="goals"&&nr===dt.length&&Pe){let u=qn(k);Ye({title:"New Goal",steps:u,kind:"goal"}),Ee("wizard");return}if($==="agents"&&or===De.length&&P){Sn();return}if($==="goals"&&te){zo(u=>!u),qo(0);return}if($==="tasks"&&U){zo(u=>!u);return}if($==="agents"&&Q){zo(u=>!u);return}if($==="logs"&&jo>=0){zo(u=>!u);return}}if((i==="r"||i==="R")&&$==="tasks"&&U&&l){if(!Gr.has(U.status)){a(`Cannot run "${U.title}" \u2014 status is ${U.status}`,e.yellow);return}a(`Running "${U.title}"...`,e.green),l(U.id).then(()=>{a(`Dispatched "${U.title}"`,e.green),J();},s=>a(`Failed to run: ${s instanceof Error?s.message:String(s)}`,e.red));return}if(p.upArrow||i==="k"){if($==="goals"&&Ae){qo(s=>Math.max(0,s-1));return}$==="goals"?jr(s=>{let d=Math.max(0,s-1);return gr(u=>d<u?d:u),d}):$==="tasks"?Go(s=>{let d=Math.max(0,s-1);return wo(u=>d<u?d:u),d}):$==="agents"?Hr(s=>{let d=Math.max(0,s-1);return ur(u=>d<u?d:u),d}):$==="logs"&&ar(s=>{if(s===-1){let u=We.length-1;return Uo(Math.max(0,u-we+2)),Math.max(0,u)}let d=Math.max(0,s-1);return Uo(u=>d<u?d:u),d});}if(p.downArrow||i==="j"){if($==="goals"&&Ae){qo(s=>s+1);return}if($==="goals"){let s=dt.length+(Pe?1:0)-1;jr(d=>{let u=Math.min(Math.max(0,s),d+1);return gr(h=>u>=h+we?u-we+1:h),u});}else if($==="tasks"){let s=Et.length+(f?1:0)+(Mo>0?1:0)-1;Go(d=>{let u=Math.min(Math.max(0,s),d+1);return wo(h=>u>=h+we?u-we+1:h),u});}else if($==="agents"){let s=De.length+(P?1:0)-1;Hr(d=>{let u=Math.min(Math.max(0,s),d+1);return ur(h=>u>=h+we?u-we+1:h),u});}else $==="logs"&&ar(s=>{if(s===-1)return -1;let d=We.length-1;if(s>=d)return Uo(0),-1;let u=s+1;return Uo(h=>u>=h+we-1?u-we+2:h),u});}}});let Qe=Ne!=="none",ms=jo>=0?We[jo]:void 0,Cn=bn?"+/- exit max":"+/- resize \u2502 M max",fs=!Qe&&Ae&&$==="tasks"&&U,ps=!Qe&&Ae&&$==="agents"&&Q,hs=!Qe&&Ae&&$==="goals"&&te,Aa=!Qe&&Ae&&$==="logs"&&ms,Tr=U?.id,$a=useMemo(()=>Tr?We.filter(i=>i.taskId===Tr):[],[We,Tr]),Ba=!Qe&&$==="tasks"&&U&&Gr.has(U.status)&&!!l,Ea=!Qe&&!Ae&&($==="goals"&&!!Pe||$==="tasks"&&!!f||$==="agents"&&!!P),La=!Qe&&$==="tasks"&&U?.status==="review"&&!!L,Oa=!Qe&&$==="tasks"&&U?.status==="review"&&!!O,Pa=Q?Object.values(q.running).some(i=>i.agent_id===Q.id):false,Na=!Qe&&($==="goals"&&te&&!!Ke||$==="tasks"&&U&&U.status!=="in_progress"&&!!N||$==="agents"&&Q&&!!j),Da=!Qe&&!Ae&&($==="goals"&&!!te&&!!qe||$==="tasks"&&!!U&&!!E||$==="agents"&&!!Q&&!!G),Fa=!Qe&&$==="agents"&&Q&&(Pa||Q.status==="running")&&!!z,Wa=!Qe&&$==="agents"&&!!Q&&!!at,Ga=!Qe&&$==="goals"&&!!te&&(te.status==="active"||te.status==="paused")&&!!lt,za=!Qe&&ko.length>0,xs=Ne==="command"&&_t.length>0,bs=Tt?.kind==="task"||Tt?.kind==="edit_task";return jsxs(Box,{flexDirection:"column",width:bt,height:A,children:[jsx(Vs,{projectName:t,activeView:$,mode:br,stats:gs,tokens:wa,uptime:ya,width:bt,version:qt,latestVersion:xt,taskBadge:Mo>0?Le.length:void 0,flashTab:dr?.tab,flashColor:dr?.color,onFlashComplete:dr?()=>Jr(void 0):void 0}),jsx(Box,{height:1}),Bt&&jsx(mi,{width:bt,height:A-7}),!Bt&&Kt==="welcome"&&$==="tasks"&&jsx(ni,{width:bt,height:A}),!Bt&&$==="goals"&&jsx(yc,{goals:dt,selectedIndex:nr,scrollOffset:aa,height:we,width:ve,showAddRow:!!Pe,agentNameMap:ao,tasksByGoalMap:ca}),!Bt&&Kt!=="welcome"&&$==="tasks"&&jsx(Sc,{tasks:Et,selectedIndex:gn,scrollOffset:ra,height:we,width:ve,showAddRow:!!f,agentNameMap:ao,hiddenCount:Mo,goalMap:Io,groupByGoal:Xo}),!Bt&&$==="tasks"&&(Kt==="task_created"||Kt==="run_started")&&jsx(ri,{step:Kt,width:bt}),!Bt&&$==="tasks"&&Kt==="completed"&&jsx(si,{width:bt}),!Bt&&$==="agents"&&jsx(kc,{agents:De,selectedIndex:or,scrollOffset:ia,height:we,width:ve,state:q,taskTitleMap:Ko,showAddRow:!!P,agentTeamMap:vo,teamLeadSet:ua,activeTeamCount:Yo}),!Bt&&$==="logs"&&jsxs(Fragment,{children:[jsx(Ic,{messages:We,height:To||Ho?Math.max(3,we-16):we,agents:De,logAgentFilter:Xr,logTypeFilter:qr,selectedIndex:jo,scrollOffset:Ji,agentNameMap:ao,agentColorMap:yn,agentMsgCounts:ss,taskTitleMap:Ko,width:ve}),To&&jsx(Box,{paddingX:2,children:jsx(Js,{agents:De,selected:Xr,msgCounts:ss,colorMap:yn,maxHeight:Math.min(we-4,18),onConfirm:i=>{Zi(i),sr(false);},onCancel:()=>sr(false)})}),Ho&&jsx(Box,{paddingX:2,children:jsx(oi,{selected:qr,typeCounts:da,onConfirm:i=>{Kr(i),ir(false);},onCancel:()=>ir(false)})})]}),jsx(Box,{height:1}),Bt?null:Ne==="wizard"&&Tt?jsx(Ks,{title:Tt.title,steps:Tt.steps,onComplete:xa,onCancel:ba,width:ve,height:Lt,onPasteImage:bs?fa:void 0,onSuggestionSelected:Tt.kind==="agent"?Ta:void 0,footerExtra:io.length>0&&bs?`\u{1F4CE}${io.length}`:void 0},`${Tt.kind}-${Tt.title}`):xs?jsxs(Fragment,{children:[jsx(Kn,{label:"COMMANDS",width:ve}),jsx(Tc,{suggestions:_t,selectedIndex:Tn,height:Math.min(_t.length,Lt),width:ve})]}):Ne==="new_task"?jsxs(Fragment,{children:[jsx(Ec,{mode:Ne,width:ve}),jsx(Lc,{mode:Ne,value:so,width:ve})]}):fs?jsxs(Fragment,{children:[jsx(_c,{task:U,width:ve,resizeHint:Cn}),jsx(Fs,{task:U,height:Lt,width:ve,taskLogs:$a,agentNameMap:ao,taskTitleMap:Ko})]}):hs?jsxs(Fragment,{children:[jsx(Kn,{label:`GOAL: ${te.title}`,width:ve,suffixLen:Cn.length+2,suffix:jsxs(Text,{color:e.dim,children:[" ",Cn," "]})}),jsx(wc,{goal:te,height:Lt,width:ve,agentNameMap:ao,tasks:ga,progressReport:Wo,scrollOffset:la,onClampScroll:qo})]}):ps?jsxs(Fragment,{children:[jsx(Rc,{agent:Q,width:ve,resizeHint:Cn}),jsx(Ac,{agent:Q,height:Lt,state:q,taskTitleMap:Ko,teamName:vo.get(Q.id)})]}):Aa?jsxs(Fragment,{children:[jsx(Kn,{label:"LOG",width:ve}),jsx(vc,{message:ms,height:Lt,width:ve,agents:De,agentNameMap:ao,agentColorMap:yn,taskTitleMap:Ko})]}):We.length>0&&$!=="logs"?jsxs(Fragment,{children:[(()=>{let i=` F:${mn.toUpperCase()} \u2502 ${cr.length}/${We.length}`;return jsx(Kn,{label:"ACTIVITY",width:ve,suffixLen:i.length,suffix:jsxs(Fragment,{children:[jsx(Text,{color:e.dim,children:" F:"}),jsx(Text,{color:e.amber,children:mn.toUpperCase()}),jsxs(Text,{color:e.ghost,children:[" ","\u2502"," ",cr.length,"/",We.length]})]})})})(),jsx(Mc,{messages:cr,height:Math.max(1,Lt-1),width:ve,agents:De,agentNameMap:ao,agentColorMap:yn})]}):$==="goals"?jsx(Vn,{count:dt.length,config:fc,width:ve}):$==="tasks"?jsx(Vn,{count:Le.length,config:pc,width:ve}):$==="agents"?jsx(Vn,{count:De.length,config:hc,width:ve}):null,jsx(Box,{flexGrow:1}),jsx(gi,{toasts:ta,onDismiss:na}),ko.length>0&&jsx(bc,{deletions:ko,width:bt}),jsx(js,{mode:Ne==="command"?"command":"navigate",value:Ne==="command"?so:"",completion:Ne==="command"?_r(so):null,activeView:$,canRun:!!Ba,canNew:!!Ea,canApprove:!!La,canReject:!!Oa,canCancel:$==="tasks"&&!!U&&U.status==="in_progress"&&!!b$1,canDelete:!!Na,canUndo:!!za,canEdit:!!Da,canForceStop:!!Fa,canToggleAuto:!!Wa,autoActive:Q?.autonomous,canPause:!!Ga,isPaused:te?.status==="paused",canToggleShowAll:$==="tasks"&&Le.length>Di,showAllActive:os,hasDetail:!!(fs||ps||hs),itemCount:$==="goals"?dt.length:$==="tasks"?Le.length:$==="agents"?k.length:We.length,itemLabel:$==="goals"?"goals":$==="tasks"?"tasks":$==="agents"?"agents":"events",width:bt,hasSuggestions:xs,onboardingCompleted:r.onboardingCompleted})]})}var bc=nn.memo(function({deletions:o,width:n}){let[,r]=useState(0);useEffect(()=>{let f=setInterval(()=>r(b=>b+1),1e3);return ()=>clearInterval(f)},[]);let l=Date.now();return jsx(Box,{flexDirection:"column",width:n,children:o.map(f=>{let b=Math.max(0,Math.ceil((f.expiresAt-l)/1e3)),T=Math.max(0,n-4),x=f.entityType==="task"?"Task":f.entityType==="agent"?"Agent":"Goal",y=Math.max(10,T-x.length-30),I=f.entityName.length>y?f.entityName.slice(0,y-1)+"\u2026":f.entityName;return jsx(Box,{paddingX:2,children:jsxs(Text,{color:e.yellow,children:["\u2717 ",jsx(Text,{bold:true,children:x}),` "${I}" \u2014 `,jsxs(Text,{color:e.amber,bold:true,children:[b,"s"]}),jsx(Text,{color:e.dim,children:" \u2502 "}),jsx(Text,{color:e.gray,bold:true,children:"Z"}),jsx(Text,{color:e.dim,children:" undo"})]})},f.key)})})});function Tc({suggestions:t,selectedIndex:o,height:n,width:r}){let l=n,f=0;o>=l&&(f=o-l+1);let b=t.slice(f,f+l);return jsx(Box,{flexDirection:"column",paddingX:2,children:b.map((T,x)=>{let y=x+f,I=y===o,v=I?"\u25B6":" ",B=Math.min(20,Math.max(14,...t.map(P=>P.cmd.length+1))),C=T.cmd.padEnd(B),H=T.subs?` ${T.subs}`:"",V=Math.max(4,r-B-H.length-8),F=T.desc.length>V?T.desc.slice(0,V-1)+"\u2026":T.desc;return jsxs(Text,{wrap:"truncate",children:[jsx(Text,{color:I?e.amber:e.ghost,children:` ${v} `}),jsx(Text,{color:I?e.white:e.silver,bold:I,children:C}),jsx(Text,{color:e.dim,children:F}),H&&jsx(Text,{color:e.ghost,children:H})]},y)})})}function yc({goals:t,selectedIndex:o,scrollOffset:n=0,height:r,width:l,showAddRow:f,agentNameMap:b,tasksByGoalMap:T}){let x=t.length,y=t.slice(n,n+r),I=f&&x>=n&&x<n+r;return jsxs(Box,{flexDirection:"column",height:r,children:[y.map((v,B)=>jsx(Box,{paddingX:2,children:jsx(Ds,{goal:v,selected:B+n===o,width:l-2,agentNameMap:b,tasksByGoal:T?.get(v.id)})},v.id)),I&&jsx(Box,{paddingX:2,children:jsxs(Text,{color:o===x?e.amber:e.ghost,children:[o===x?" \u25B8 ":" ",jsx(Text,{color:o===x?e.amber:e.dim,children:"+ add goal..."})]})},"__add__")]})}function wc({goal:t,height:o,width:n,agentNameMap:r,tasks:l,progressReport:f,scrollOffset:b=0,onClampScroll:T}){let y=nn.useMemo(()=>{let V=l??[],F=t.assignee?r?.get(t.assignee)??t.assignee:"\u2014",P=Math.max(20,n-6),j=(z,X)=>{if(z.length<=X)return [z];let R=[];for(let ie=0;ie<z.length;ie+=X)R.push(z.slice(ie,ie+X));return R},L=Cr(f)?.split(`
|
|
13
|
+
`).flatMap(z=>j(z,P))??[],O=Cr(t.description)?.split(`
|
|
14
|
+
`).flatMap(z=>j(z,P))??[],N=ks[t.status]??e.dim,E=new Map;for(let z of V)E.set(z.status,(E.get(z.status)??0)+1);let G=[];if(G.push({key:"row-status",node:jsxs(Box,{children:[jsxs(Box,{width:24,children:[jsx(Text,{color:e.dim,children:" status "}),jsx(Text,{color:N,bold:true,children:t.status})]}),jsxs(Box,{children:[jsx(Text,{color:e.dim,children:" assignee "}),jsx(Text,{color:t.assignee?e.green:e.dim,children:F})]})]})}),G.push({key:"row-id",node:jsxs(Box,{children:[jsxs(Box,{width:24,children:[jsx(Text,{color:e.dim,children:" id "}),jsx(Text,{color:e.dim,children:t.id})]}),jsxs(Box,{children:[jsx(Text,{color:e.dim,children:" created "}),jsx(Text,{children:t.created_at.slice(0,10)})]})]})}),t.updated_at&&t.updated_at!==t.created_at&&G.push({key:"row-updated",node:jsxs(Box,{children:[jsx(Box,{width:24,children:jsxs(Text,{color:e.dim,children:[" "," "]})}),jsxs(Box,{children:[jsx(Text,{color:e.dim,children:" Updated "}),jsx(Text,{children:t.updated_at.slice(0,10)})]})]})}),V.length>0){let z=[];for(let[X,R]of E)z.push(`${R} ${X}`);G.push({key:"row-tasks-summary",node:jsxs(Box,{children:[jsxs(Box,{width:24,children:[jsx(Text,{color:e.dim,children:" tasks "}),jsx(Text,{color:e.cyan,children:V.length})]}),jsxs(Box,{children:[jsx(Text,{color:e.dim,children:" "}),jsx(Text,{color:e.dim,children:z.join(" \xB7 ")})]})]})});}if(O.length>0){G.push({key:"desc-gap",node:jsx(Text,{children:" "})});for(let z=0;z<O.length;z++)G.push({key:`desc-${z}`,node:jsxs(Text,{color:e.silver,wrap:"truncate",children:[" ",O[z]]})});}else G.push({key:"desc-gap",node:jsx(Text,{children:" "})}),G.push({key:"desc-empty",node:jsx(Text,{color:e.dim,children:" No description."})});if(L.length>0){G.push({key:"prog-gap",node:jsx(Text,{children:" "})}),G.push({key:"prog-div",node:jsx(Oo,{label:"progress",width:n})});for(let z=0;z<L.length;z++)G.push({key:`prog-${z}`,node:jsxs(Text,{color:e.white,wrap:"truncate",children:[" ",L[z]]})});}if(V.length>0){G.push({key:"tasks-gap",node:jsx(Text,{children:" "})}),G.push({key:"tasks-div",node:jsx(Oo,{label:`tasks (${V.length})`,width:n})});for(let z of V){let X=_n[z.status]??e.dim;G.push({key:`task-${z.id}`,node:jsxs(Text,{color:e.silver,wrap:"truncate",children:[" ",jsx(Text,{color:X,children:z.status.padEnd(12)}),z.title.slice(0,Math.max(10,n-22))]})});}}return G},[t,l,f,n,r]),I=Math.max(0,y.length-o),v=Math.min(b,I);nn.useEffect(()=>{T&&v!==b&&T(v);},[v,b,T]);let B=y.length>o&&v<I,C=B?o-1:o,H=y.slice(v,v+C);return jsxs(Box,{flexDirection:"column",height:o,paddingX:2,children:[H.map(V=>jsx(Box,{children:V.node},V.key)),B&&jsxs(Text,{color:e.ghost,children:[" ","\u2193"," ",y.length-v-C," more ","\u2014"," ","\u2191","\u2193"," to scroll"]})]})}function Sc({tasks:t,selectedIndex:o,scrollOffset:n=0,height:r,width:l,showAddRow:f,agentNameMap:b,hiddenCount:T=0,goalMap:x,groupByGoal:y=false}){let I=T>0,v=I?t.length:-1,B=t.length+(I?1:0),C=t.slice(n,n+r),H=I&&v>=n&&v<n+r,V=f&&B>=n&&B<n+r,F=useMemo(()=>{if(!y||!x||x.size===0)return null;let N=new Map;for(let E of t)if(E.goalId&&x.has(E.goalId)){let G=N.get(E.goalId)??{total:0,done:0};G.total++,E.status==="done"&&G.done++,N.set(E.goalId,G);}return N},[t,y,x]),P=y&&x?t.filter(N=>!N.goalId||!x.has(N.goalId)).length:0,j=y&&x&&x.size>0&&F&&F.size>0,L=[],O=n>0?t[n-1]?.goalId??null:void 0;for(let N=0;N<C.length&&L.length<r;N++){let E=C[N],G=E.goalId&&x?.has(E.goalId)?E.goalId:null;if(j){if(G&&G!==O){let z=x.get(G),X=F.get(G)??{total:0,done:0};if(L.push(jsx(Rs,{goalTitle:z.title,taskCount:X.total,doneCount:X.done,width:l},`gh_${G}`)),L.length>=r)break}if(!G&&O!==null&&O!==void 0&&(L.push(jsx(As,{taskCount:P,width:l},"__ungrouped__")),L.length>=r))break}O=G,L.push(jsx(Box,{paddingX:2,children:jsx(An,{task:E,selected:N+n===o,width:l-2,agentNameMap:b,goalMap:x})},E.id));}return H&&L.length<r&&L.push(jsx(Box,{paddingX:2,children:jsxs(Text,{color:o===v?e.amber:e.ghost,children:[o===v?" \u25B8 ":" ",jsxs(Text,{color:o===v?e.amber:e.dim,children:["\u25BC"," Show all (",T," more) \u2014 press ",jsx(Text,{bold:true,color:e.gray,children:"S"})]})]})},"__show_all__")),V&&L.length<r&&L.push(jsx(Box,{paddingX:2,children:jsxs(Text,{color:o===B?e.amber:e.ghost,children:[o===B?" \u25B8 ":" ",jsx(Text,{color:o===B?e.amber:e.dim,children:"+ add task..."})]})},"__add__")),jsx(Box,{flexDirection:"column",height:r,children:L})}function kc({agents:t,selectedIndex:o,scrollOffset:n=0,height:r,width:l,state:f,taskTitleMap:b,showAddRow:T,agentTeamMap:x,teamLeadSet:y,activeTeamCount:I}){let v=new Map;for(let E of Object.values(f.running))v.set(E.agent_id,E);let B=new Map;if(I&&I>0)for(let E of t){let G=x?.get(E.id);G&&B.set(G,(B.get(G)??0)+1);}let C=t.length,H=t.slice(n,n+r),V=T&&C>=n&&C<n+r,F=I!=null&&I>0,P=new Map;if(F&&y&&x){for(let E of t)if(y.has(E.id)){let G=x.get(E.id);G&&P.set(G,E.name);}}let j=0;for(let E of B.values())j+=E;let L=t.length-j,O=[],N=n>0?x?.get(t[n-1]?.id??""):void 0;for(let E=0;E<H.length&&O.length<r;E++){let G=H[E],z=x?.get(G.id);if(F&&z&&z!==N&&(O.push(jsx(Ls,{teamName:z,memberCount:B.get(z)??0,leadName:P.get(z),width:l},`ts-${z}`)),O.length>=r)||F&&!z&&N&&(O.push(jsx(Os,{memberCount:L,width:l},"ts-unassigned")),O.length>=r))break;N=z,O.push(jsx(Box,{paddingX:2,children:jsx(Es,{agent:G,selected:E+n===o,width:l-2,runningEntry:v.get(G.id),currentTaskTitle:G.current_task?b.get(G.current_task):void 0,teamName:z,isLead:y?.has(G.id)})},G.id));}return V&&O.length<r&&O.push(jsx(Box,{paddingX:2,children:jsxs(Text,{color:o===C?e.amber:e.ghost,children:[o===C?" \u25B8 ":" ",jsx(Text,{color:o===C?e.amber:e.dim,children:"+ add agent..."})]})},"__add__")),jsx(Box,{flexDirection:"column",height:r,children:O})}function Ui(t=5e3){let[o,n]=useState(Date.now());return useEffect(()=>{let r=setInterval(()=>n(Date.now()),t);return ()=>clearInterval(r)},[t]),o}function Xi(t,o){let n=Math.max(0,o-t);return n<3e3?"now":n<6e4?`${Math.floor(n/1e3)}s`:n<36e5?`${Math.floor(n/6e4)}m`:`${Math.floor(n/36e5)}h`}function Cc(t){if(t==="error")return e.errorBg}function qi(t,o){switch(t){case "output":return e.white;case "tool":return e.dim;case "result":return e.dim;case "file":return e.gray;case "error":return e.red;case "lifecycle":return e.dim;case "system":return e.dim;default:return o}}function Ic({messages:t,height:o,agents:n,logAgentFilter:r,logTypeFilter:l,selectedIndex:f,scrollOffset:b,agentNameMap:T,agentColorMap:x,agentMsgCounts:y,taskTitleMap:I,width:v}){let B=Ui(),C=useMemo(()=>t.filter(X=>{if(r.size>0&&X.agentId&&!r.has(X.agentId))return false;let R=X.msgType??"info";return l.has(R)}),[t,r,l]);useMemo(()=>{let X={};for(let R of t){let ie=R.msgType??"info";X[ie]=(X[ie]??0)+1;}return X},[t]);let V=l.size>=8?"all":l.size===1&&l.has("output")?"text":l.size===1&&l.has("error")?"errors":l.has("tool")&&!l.has("output")?"tools":l.has("lifecycle")&&!l.has("output")?"events":`${l.size} types`,F=r.size>0,P=o-2,j=f===-1?C.slice(-P):C.slice(b,b+P),L=f===-1?-1:f-b,O=Math.min(10,Math.max(6,...n.map(X=>X.name.length))),N=11+O,E=X=>{if(X===0)return true;let R=j[X],ie=j[X-1];return R.agentId!==ie.agentId?true:R.agentId?R.ts-ie.ts>3e4:false},G=Math.max(4,Math.floor((v-20)/Math.max(1,n.length))-1),z=Math.min(G,10);return jsxs(Box,{flexDirection:"column",paddingX:1,children:[jsxs(Box,{gap:0,justifyContent:"space-between",width:v,children:[jsxs(Box,{gap:0,children:[f===-1?jsxs(Box,{gap:0,children:[jsx(Text,{backgroundColor:e.successBg,color:e.green,children:" "}),jsx(Text,{backgroundColor:e.successBg,color:e.green,children:jsx($o,{color:e.green})}),jsx(Text,{backgroundColor:e.successBg,color:e.green,children:" LIVE "})]}):jsxs(Text,{backgroundColor:e.warnBg,color:e.amber,children:[" \u2191\u2193 ",f+1,"/",C.length," "]}),jsxs(Text,{color:e.dim,children:[" ",C.length," events"]}),V!=="all"&&jsxs(Text,{color:e.amber,children:[" f:",V]}),F&&jsxs(Text,{color:e.cyan,children:[" ",r.size,"/",n.length," agents"]})]}),jsxs(Box,{gap:0,children:[jsx(Text,{color:e.amber,bold:true,children:"a"}),jsx(Text,{color:e.dim,children:" filter "}),jsx(Text,{color:e.amber,bold:true,children:"f"}),jsx(Text,{color:e.dim,children:" type "}),jsx(Text,{color:e.amber,bold:true,children:"F"}),jsx(Text,{color:e.dim,children:" cycle"})]})]}),jsx(Box,{gap:0,children:n.map(X=>{let R=x.get(X.id)??Vr[0],ie=r.size===0||r.has(X.id),Be=X.name.length>z?X.name.slice(0,z-1)+"\u2026":X.name;return jsxs(Text,{color:ie?R:e.ghost,bold:ie,children:[" ",Be]},X.id)})}),j.length===0?jsxs(Box,{flexDirection:"column",paddingX:2,paddingTop:1,children:[jsx(Text,{color:e.dim,children:t.length===0?" \u256D\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u256E":"No events for current filter."}),t.length===0&&jsxs(Fragment,{children:[jsx(Text,{color:e.dim,children:" \u2502 \u2502"}),jsxs(Text,{color:e.dim,children:[" \u2502 ",jsx(Text,{color:e.ghost,children:"\u25C7"}),jsx(Text,{color:e.gray,children:" Waiting for activity "}),"\u2502"]}),jsxs(Text,{color:e.dim,children:[" \u2502 ",jsx(Text,{color:e.ghost,children:"\u2502"}),jsx(Text,{color:e.dim,children:" Run tasks or start "}),"\u2502"]}),jsxs(Text,{color:e.dim,children:[" \u2502 ",jsx(Text,{color:e.ghost,children:"\u2502"}),jsx(Text,{color:e.dim,children:" the orchestrator "}),"\u2502"]}),jsxs(Text,{color:e.dim,children:[" \u2502 ",jsx(Text,{color:e.ghost,children:"\u25C7"}),jsx(Text,{color:e.dim,children:" "}),"\u2502"]}),jsx(Text,{color:e.dim,children:" \u2570\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u256F"})]})]}):j.map((X,R)=>{let ie=R===L,Be=X.msgType??"info",Wt=er[Be]??"\u2502",it=X.agentId?T.get(X.agentId)??X.agentId.slice(0,8):void 0,Re=X.agentId?x.get(X.agentId):void 0,Xe=E(R),mt=(R>0?j[R-1]:void 0)?.agentId===X.agentId&&!!X.agentId,Pe=!mt&&!!it,qe=mt&&!!it,lt=qi(Be,X.color),Ke=ie?e.infoBg:Be==="error"?e.errorBg:void 0,oo=X.taskId?I.get(X.taskId):void 0,ke=Xi(X.ts,B),ft=oo&&v>80?`#${oo.slice(0,20)}`:"",$t=ft?ft.length+3:0,Xt=Math.max(10,v-2-N-$t),pt=et(X.text,Xt);return jsxs(Box,{backgroundColor:Ke,children:[jsx(Text,{color:Re??e.ghost,children:Xe&&Pe?"\u250C":qe?"\u2502":" "}),jsx(Text,{color:ie?e.amber:void 0,children:ie?"\u25B8":" "}),jsx(Box,{width:5,children:jsx(Text,{color:ke==="now"?e.green:ie?e.silver:e.ghost,children:ke.padStart(4)})}),jsx(Box,{width:O+1,children:Pe?jsxs(Text,{color:Re,bold:true,children:[" ",it.slice(0,O).padEnd(O)]}):qe?jsxs(Text,{color:Re??e.ghost,children:[" ","\xB7".padEnd(O)]}):jsxs(Text,{color:e.ghost,children:[" "," ".padEnd(O)]})}),jsxs(Text,{color:Be==="error"?e.red:Re??e.dim,children:[" ",Wt," "]}),jsx(Text,{color:ie?e.white:lt,bold:ie||Be==="lifecycle",children:pt}),ft&&jsxs(Text,{color:e.ghost,children:[" ",jsx(Text,{color:e.dim,backgroundColor:e.void,children:` ${ft} `})]})]},R)})]})}function Mc({messages:t,height:o,width:n,agents:r,agentNameMap:l,agentColorMap:f}){let b=Ui(),T=t.slice(-o),x=Math.max(10,n-2-17),y=Math.max(0,o-T.length),I=0,v=[];for(let B=0;B<T.length;B++)B>0&&T[B].agentId!==T[B-1].agentId&&I++,v.push(I);return jsxs(Box,{flexDirection:"column",paddingX:1,children:[y>0&&jsx(Box,{height:y}),T.map((B,C)=>{let H=B.agentId?l.get(B.agentId)??B.agentId.slice(0,8):void 0,V=B.agentId?f.get(B.agentId):void 0,F=B.msgType??"info",P=er[F]??"\u2502",j=qi(F,B.color),O=(C>0?T[C-1]:void 0)?.agentId===B.agentId&&!!B.agentId,N=(v[C]&1)===1,E=Cc(F)??(N?"#1a1a1a":void 0),G=Xi(B.ts,b),z=et(B.text,x);return jsxs(Box,{backgroundColor:E,children:[jsx(Text,{color:V??e.ghost,children:!O&&H?"\u258D":O?"\u258F":" "}),jsx(Box,{width:5,children:jsx(Text,{color:O?e.ghost:G==="now"?e.green:e.dim,children:O?" ":G.padStart(4)})}),jsx(Box,{width:9,children:H&&!O?jsxs(Text,{color:V,bold:true,children:[" ",H.slice(0,8)]}):jsx(Text,{color:e.ghost,children:xc})}),jsxs(Text,{color:F==="error"?e.red:O?e.ghost:V??e.dim,children:[P," "]}),jsx(Text,{color:j,children:z})]},C)})]})}function vc({message:t,height:o,width:n,agents:r,agentNameMap:l,agentColorMap:f,taskTitleMap:b}){let T=t.detail??t.text,x=t.msgType??"info",y=t.agentId?l.get(t.agentId)??t.agentId.slice(0,8):void 0,I=t.agentId?f.get(t.agentId):e.dim,v=t.taskId?b.get(t.taskId):void 0,B,C=false;try{let P=JSON.parse(T);B=JSON.stringify(P,null,2),C=!0;}catch{B=T;}let H=Math.max(4,n-6),V=Math.max(1,o-4),F=B.split(`
|
|
15
|
+
`).slice(0,V);return jsxs(Box,{flexDirection:"column",paddingX:1,children:[jsx(Box,{children:jsxs(Text,{color:e.ghost,children:["\u256D",be(H+2),"\u256E"]})}),jsxs(Box,{children:[jsx(Text,{color:e.ghost,children:"\u2502 "}),jsx(Text,{color:e.dim,children:t.time}),jsx(Text,{color:e.ghost,children:" \u2502 "}),y&&jsx(Text,{color:I,bold:true,children:y}),y&&jsx(Text,{color:e.ghost,children:" \u2502 "}),jsxs(Text,{color:er[x]?x==="error"?e.red:e.dim:e.dim,children:[er[x]??"\u2502"," ",x]}),v&&jsxs(Fragment,{children:[jsx(Text,{color:e.ghost,children:" \u2502 "}),jsxs(Text,{color:e.dim,children:["#",v.slice(0,30)]})]})]}),jsxs(Box,{children:[jsx(Text,{color:e.ghost,children:"\u2502 "}),jsx(Text,{color:t.color,bold:true,wrap:"truncate",children:t.text.slice(0,H)})]}),jsx(Box,{children:jsxs(Text,{color:e.ghost,children:["\u251C",be(H+2),"\u2524"]})}),F.map((P,j)=>jsxs(Box,{children:[jsx(Text,{color:e.ghost,children:"\u2502 "}),C&&jsxs(Text,{color:e.ghost,children:[String(j+1).padStart(3)," "]}),jsx(Text,{wrap:"truncate",color:C&&P.includes('"')?e.cyan:C&&/^\s*[}\]]/.test(P)?e.ghost:P.startsWith("error")||P.startsWith("Error")?e.red:e.silver,children:P.slice(0,C?H-4:H)})]},j)),jsx(Box,{children:jsxs(Text,{color:e.ghost,children:["\u2570",be(H+2),"\u256F"]})})]})}function Kn({label:t,width:o,suffix:n,suffixLen:r=0}){let l=` ${t} `,f=3,b=f+l.length+2;if(!n){let y=Math.max(0,o-b);return jsxs(Box,{paddingX:1,children:[jsx(Text,{color:e.ghost,children:ze(f)}),jsx(Text,{backgroundColor:"#1a1a22",color:e.dim,bold:true,children:l}),jsx(Text,{color:e.ghost,children:ze(y)})]})}let T=2,x=Math.max(0,o-b-T-r);return jsxs(Box,{paddingX:1,children:[jsx(Text,{color:e.ghost,children:ze(f)}),jsx(Text,{backgroundColor:"#1a1a22",color:e.dim,bold:true,children:l}),jsx(Text,{color:e.ghost,children:ze(T)}),n,jsx(Text,{color:e.ghost,children:ze(x)})]})}function _c({task:t,width:o,resizeHint:n}){let r=" DETAIL ",l=n?` ${n} `:"",f=o-r.length-l.length-10,b=t.title.length>f?t.title.slice(0,f-3)+"...":t.title,T=Math.max(0,o-3-r.length-b.length-l.length-4);return jsxs(Box,{paddingX:1,children:[jsx(Text,{color:e.ghost,children:ze(3)}),jsx(Text,{backgroundColor:"#2d1f0a",color:e.amber,bold:true,children:r}),jsxs(Text,{color:e.ghost,children:[vn," "]}),jsx(Text,{color:e.white,bold:true,children:b}),jsxs(Text,{color:e.ghost,children:[" ",ze(Math.max(0,T))]}),l?jsx(Text,{color:e.dim,children:l}):null]})}function Rc({agent:t,width:o,resizeHint:n}){let r=" AGENT ",l=n?` ${n} `:"",f=o-r.length-l.length-10,b=t.name.length>f?t.name.slice(0,f-3)+"...":t.name,T=Math.max(0,o-3-r.length-b.length-l.length-4);return jsxs(Box,{paddingX:1,children:[jsx(Text,{color:e.ghost,children:ze(3)}),jsx(Text,{backgroundColor:"#0f2d1f",color:e.green,bold:true,children:r}),jsxs(Text,{color:e.ghost,children:[vn," "]}),jsx(Text,{color:e.green,bold:true,children:b}),jsxs(Text,{color:e.ghost,children:[" ",ze(Math.max(0,T))]}),l?jsx(Text,{color:e.dim,children:l}):null]})}function Ac({agent:t,height:o,state:n,taskTitleMap:r,teamName:l}){let f=$c[t.status]??e.dim;Object.values(n.running).find(y=>y.agent_id===t.id);let T=t.current_task?r.get(t.current_task):void 0,x=24;return jsxs(Box,{flexDirection:"column",paddingX:2,children:[jsxs(Box,{children:[jsxs(Box,{width:x,children:[jsx(Text,{color:e.dim,children:" status "}),jsx(Text,{color:f,children:t.status})]}),jsxs(Box,{children:[jsx(Text,{color:e.dim,children:" adapter "}),jsx(Text,{color:e.cyan,children:t.adapter})]})]}),jsxs(Box,{children:[jsxs(Box,{width:x,children:[jsx(Text,{color:e.dim,children:" model "}),jsx(Text,{children:t.config.model??"\u2014"})]}),jsxs(Box,{children:[jsx(Text,{color:e.dim,children:" task "}),jsx(Text,{color:T?e.white:e.dim,children:T??"\u2014"})]})]}),jsxs(Box,{children:[jsxs(Box,{width:x,children:[jsx(Text,{color:e.dim,children:" runs "}),jsx(Text,{children:t.stats.total_runs}),jsx(Text,{color:e.dim,children:" ("}),jsx(Text,{color:e.green,children:t.stats.tasks_completed}),jsx(Text,{color:e.dim,children:"/"}),jsx(Text,{color:t.stats.tasks_failed>0?e.red:e.dim,children:t.stats.tasks_failed}),jsx(Text,{color:e.dim,children:")"})]}),jsxs(Box,{children:[jsx(Text,{color:e.dim,children:" team "}),jsx(Text,{color:l?e.amber:e.dim,children:l??"\u2014"})]})]}),t.autonomous&&jsx(Box,{children:jsxs(Box,{width:x,children:[jsx(Text,{color:e.dim,children:" auto "}),jsxs(Text,{color:e.cyan,children:[go," ON"]})]})}),t.config.skills&&t.config.skills.length>0&&jsxs(Box,{children:[jsx(Text,{color:e.dim,children:" skills "}),jsx(Text,{color:e.cyan,wrap:"truncate",children:et(t.config.skills.join(", "),500)})]}),t.last_error&&(()=>{let y=t.last_error.kind,I=m[y],v=!I||y==="unknown",B=t.last_error.timestamp,C=B?g(B)+" ago":"";return jsxs(Fragment,{children:[jsx(Text,{children:" "}),jsxs(Box,{flexDirection:"column",borderStyle:"single",borderColor:e.red,paddingX:1,children:[jsxs(Text,{color:e.red,bold:true,children:["\u26A0"," \u041E\u0448\u0438\u0431\u043A\u0430"]}),I&&jsx(Text,{color:e.white,children:I.message}),I&&jsx(Text,{color:e.cyan,children:I.fix}),I?.doctorHint&&jsx(Text,{color:e.yellow,children:"\u0414\u0438\u0430\u0433\u043D\u043E\u0441\u0442\u0438\u043A\u0430: orch doctor"}),v&&t.last_error.message&&jsx(Text,{color:e.dim,children:et(t.last_error.message,120)}),C&&jsx(Text,{color:e.dim,children:C})]})]})})(),jsx(Text,{children:" "}),t.role?t.role.split(`
|
|
16
|
+
`).slice(0,Math.max(1,o-(t.last_error?10:4))).map((y,I)=>jsxs(Text,{color:e.silver,wrap:"truncate",children:[" ",et(y,500)]},I)):jsx(Text,{color:e.dim,children:" No role description."})]})}var $c={idle:e.dim,running:e.green,error:e.red,disabled:e.ghost},Bc="\u2588";function Ec({mode:t,width:o}){let r=` ${t==="command"?"COMMAND":"NEW TASK"} `,l=Math.max(0,o-3-r.length-2);return jsxs(Box,{paddingX:1,children:[jsx(Text,{color:e.ghost,children:ze(3)}),jsx(Text,{backgroundColor:"#2d1f0a",color:e.amber,bold:true,children:r}),jsx(Text,{color:e.ghost,children:ze(l)})]})}function Lc({mode:t,value:o,width:n}){let r=t==="command"?"/":"\u25B8",l=Math.max(10,n-8),f=o.length>l?o.slice(-l):o;return jsxs(Box,{paddingX:2,children:[jsxs(Text,{color:e.amber,children:[r," "]}),jsx(Text,{color:e.white,children:f}),jsx(Text,{color:e.amber,children:Bc})]})}function Ki(t,o){if(!o||typeof o!="object")return "";let n=o;if(n.file_path&&typeof n.file_path=="string")return n.file_path.split("/").slice(-2).join("/");if(n.command&&typeof n.command=="string")return n.command.slice(0,60);if(n.pattern&&typeof n.pattern=="string")return `"${n.pattern.slice(0,40)}"`;if(n.glob&&typeof n.glob=="string")return n.glob.slice(0,40);let r=JSON.stringify(n);return r.length>80?r.slice(0,77)+"...":r}function Yn(t,o=200){if(typeof t=="string")return t.slice(0,o);if(!Array.isArray(t))return null;let n=[],r=0;for(let l of t){if(r>=o)break;if(l?.type==="text"&&typeof l.text=="string"){let f=l.text.split(`
|
|
17
|
+
`).find(b=>b.trim().length>0)??"";n.push(f.slice(0,o-r)),r+=f.length;}else if(l?.type==="tool_use"){let f=Ki(l.name??"tool",l.input),b=`\u2699 ${l.name??"tool"}(${f})`;n.push(b),r+=b.length;}else if(l?.type==="tool_result")n.push("\u2190 (result)"),r+=10;else if(l?.type==="thinking"&&typeof l.thinking=="string"){let f=l.thinking.slice(0,60).split(`
|
|
18
|
+
`)[0]??"";n.push(`\u{1F4AD} ${f}`),r+=f.length+3;}}return n.length>0?n.join(" "):null}function zi(t){if(typeof t=="string"){let n=t.split(`
|
|
19
|
+
`).length,r=t.split(`
|
|
20
|
+
`).find(l=>l.trim().length>0)??"";return n>3?`${r.slice(0,80)}... (${n} lines)`:r.slice(0,120)}if(!Array.isArray(t))return "(result)";let o=[];for(let n of t)if(n?.type==="tool_result"){n.tool_use_id?n.tool_use_id.slice(0,8):"";let l=n.is_error,f=typeof n.content=="string"?n.content:"",b=f.split(`
|
|
21
|
+
`).length;l?o.push(`\u2715 error: ${f.slice(0,60)}`):b>3?o.push(`\u2713 ${b} lines`):o.push(`\u2713 ${f.slice(0,80)}`);}else n?.type==="text"&&typeof n.text=="string"&&o.push(n.text.split(`
|
|
22
|
+
`)[0]?.slice(0,80)??"");return o.join(" ")||"(result)"}function Yi(t){let o=()=>t.length>Qn?t.slice(0,Qn)+"\u2026":t;if(Hi.test(t.trim()))return {summary:t.trim(),detail:o()};try{let n=JSON.parse(t);if(n.type==="message"&&n.role==="assistant"){let r=Yn(n.content);return r?{summary:r.slice(0,200),detail:o()}:{summary:null,detail:""}}if(n.type==="assistant"||n.role==="assistant"){let r=n.message?.content??n.content,l=Yn(r);return l?{summary:l.slice(0,200),detail:o()}:{summary:null,detail:""}}if(n.type==="user"||n.role==="user"){let r=n.message?.content??n.content;return {summary:`\u2190 ${zi(r).slice(0,180)}`,detail:o()}}if(n.type==="tool_use"||typeof n.name=="string"&&"input"in n){let r=n.name??"tool",l=Ki(r,n.input);return {summary:`\u2699 ${r}(${l})`,detail:o()}}if(n.type==="tool_result")return {summary:`\u2190 ${zi(n.content).slice(0,180)}`,detail:o()};if(n.type==="result"){let r=typeof n.result=="string"?n.result:null;return {summary:r?`\u2713 ${r.slice(0,180)}`:"\u2713 Agent finished",detail:o()}}if(n.type==="rate_limit_event")return {summary:`\u23F3 Rate limited (${n.rate_limit_info?.rateLimitType??"unknown"})`,detail:o()};if(n.subtype){if(n.message){let r=n.message.content??n.message,l=Yn(r);if(l)return {summary:l.slice(0,200),detail:o()}}return {summary:`[${n.subtype}]`,detail:o()}}if(n.content){let r=Yn(n.content);if(r)return {summary:r.slice(0,200),detail:o()}}return n.type?{summary:`[${n.type}]`,detail:o()}:{summary:t.slice(0,150),detail:o()}}catch{return {summary:Oc(t),detail:o()}}}function Oc(t){let o=t.match(/"subtype"\s*:\s*"([^"]+)"/);if(o)return `[${o[1]}]`;let n=t.match(/"type"\s*:\s*"([^"]+)"/),r=t.match(/"role"\s*:\s*"([^"]+)"/),l=n?.[1],f=r?.[1];if(!l&&!f)return t.slice(0,200);if(l==="assistant"||l==="message"||f==="assistant"){let b=t.match(/"text"\s*:\s*"((?:[^"\\]|\\.)*)"/);if(b)try{return JSON.parse(`"${b[1]}"`).slice(0,200)}catch{}return "\u{1F4AC} (assistant)"}if(l==="user"||l==="tool_result"||f==="user")return "\u2190 (tool result)";if(l==="tool_use")return `\u2699 ${t.match(/"name"\s*:\s*"([^"]+)"/)?.[1]??"tool"}()`;if(l==="result"){let b=t.match(/"result"\s*:\s*"((?:[^"\\]|\\.)*)"/);if(b)try{return `\u2713 ${JSON.parse(`"${b[1]}"`).slice(0,180)}`}catch{}return "\u2713 Agent finished"}return l==="rate_limit_event"?"\u23F3 Rate limited":`[${l??f}]`}function Pc(t,o,n,r){let l=f=>r?.get(f);switch(t.type){case "agent:started":o("Started task",e.green,{agentId:t.agentId,taskId:t.taskId,msgType:"lifecycle"});break;case "agent:output":{let{summary:f,detail:b}=Yi(t.data);if(f){let T=ji(f);o(f,T.color,{agentId:t.agentId,taskId:l(t.runId),detail:b,msgType:T.msgType});}break}case "agent:file_changed":o(`${t.path}`,e.purple,{agentId:t.agentId,taskId:l(t.runId),msgType:"file"});break;case "agent:completed":o(t.success?"Completed successfully":"Failed",t.success?e.green:e.red,{agentId:t.agentId,taskId:l(t.runId),msgType:"lifecycle"});break;case "agent:error":o(`${t.error.slice(0,150)}`,e.red,{agentId:t.agentId,taskId:l(t.runId),detail:t.error,msgType:"error"});break;case "task:status_changed":o(`${t.from} \u2192 ${t.to}`,e.cyan,{taskId:t.taskId,msgType:"system"});break;case "task:assigned":o(`Assigned \u2192 ${t.agentId}`,e.cyan,{taskId:t.taskId,msgType:"system"});break;case "task:created":o(`Created: ${t.task.title}`,e.amber,{taskId:t.task.id,msgType:"system"});break;case "run:retry":o(`Retry #${t.attempt} (${Math.round(t.delay_ms/1e3)}s delay)`,e.yellow,{agentId:n?.get(t.runId),taskId:l(t.runId),msgType:"lifecycle"});break;case "orchestrator:tick":(t.running>0||t.queued>0)&&o(`${t.running} running \xB7 ${t.queued} queued`,e.ghost,{msgType:"system"});break;case "orchestrator:stall_detected":o("Stall detected",e.yellow,{agentId:n?.get(t.runId),taskId:l(t.runId),msgType:"error"});break;case "task:cascade_failed":o(`Cascade failed (dep: ${t.failedDependencyId})`,e.red,{taskId:t.taskId,detail:t.reason,msgType:"error"});break}}export{Yu as App,Ku as _resetPendingDeletionSeq};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {a}from'./chunk-CHRW4CLD.js';var k=class{engine;renderTimeoutMs;constructor(e){this.renderTimeoutMs=e?.renderTimeoutMs??5e3;}async getEngine(){if(!this.engine){let{Liquid:e}=await import('liquidjs');this.engine=new e({strictFilters:false,strictVariables:false});}return this.engine}async render(e,r){let n=(await this.getEngine()).parseAndRender(e,r);if(this.renderTimeoutMs<=0)return n;let d,c=new Promise((u,
|
|
2
|
+
import {a}from'./chunk-CHRW4CLD.js';var k=class{engine;renderTimeoutMs;constructor(e){this.renderTimeoutMs=e?.renderTimeoutMs??5e3;}async getEngine(){if(!this.engine){let{Liquid:e}=await import('liquidjs');this.engine=new e({strictFilters:false,strictVariables:false});}return this.engine}async render(e,r){let n=(await this.getEngine()).parseAndRender(e,r);if(this.renderTimeoutMs<=0)return n;let d,c=new Promise((u,o)=>{d=setTimeout(()=>o(new Error(`Template render timed out after ${this.renderTimeoutMs}ms`)),this.renderTimeoutMs);});try{return await Promise.race([n,c])}finally{clearTimeout(d);}}},f=15;function y(t,e){let r=Object.entries(t);if(r.length===0)return {};let a=e.agentName.toLowerCase(),n=b(a,e.agentRole),d=[];for(let[o,i]of r){let g=0,l=o.toLowerCase();if(e.goalId&&l.startsWith(e.goalId.toLowerCase())&&(g+=10),(l.includes(a)||i.toLowerCase().includes(a))&&(g+=8),e.taskScope?.length)for(let p of e.taskScope){let m=p.replace(/\*+/g,"").replace(/\/+$/,"");if(m&&(l.includes(m.toLowerCase())||i.toLowerCase().includes(m.toLowerCase()))){g+=6;break}}for(let p of n)if(l.startsWith(p+"-")||l.startsWith(p+"_")){g+=4;break}/^(bug|perf|stability|docs|arch|spec)-/i.test(o)&&(g+=1),d.push({key:o,value:i,score:g});}d.sort((o,i)=>i.score-o.score);let c=d.filter(o=>o.score>0).slice(0,f);if(c.length<f){let o=d.filter(i=>i.score===0).slice(0,f-c.length);c.push(...o);}let u={};for(let{key:o,value:i}of c)u[o]=i;return u}function b(t,e){let r=[],a=t.split(/[\s_-]/)[0];if(a&&a.length>1&&r.push(a),(t.includes("front")||t.includes("tui"))&&r.push("front-end","frontend","tui"),(t.includes("market")||t.includes("cmo"))&&r.push("marketer","marketing","cmo"),e){let n=e.toLowerCase().split(/[\s_-]/)[0];n&&n.length>2&&!r.includes(n)&&r.push(n);}return r}function T(t,e,r,a$1,n,d){let{allAgents:c,retryContext:u,sharedContext:o,feedback:i,messages:g,goal:l}=d??{},p=new Map((c??[]).map(s=>[s.id,s])),m=g?.length?g.map(s=>({id:s.id,from:p.get(s.from_agent_id)?.name??s.from_agent_id,subject:s.subject,body:s.body,sent_at:s.created_at,reply_to:s.reply_to})):void 0;return {project:{name:n.project.name,description:n.project.description},task:{id:t.id,title:t.title,description:t.description,priority:t.priority,labels:t.labels,scope:t.scope,is_autonomous:t.labels?.includes(a)??false,goal_id:t.goalId},agent:{id:e.id,name:e.name,role:e.role},agents:(c??[]).map(s=>({id:s.id,name:s.name,role:s.id===e.id?void 0:s.role,adapter:s.adapter})),attempt:r>1?r:null,workspace_path:a$1,retry:r>1?u:void 0,feedback:i,shared_context:o&&Object.keys(o).length>0?y(o,{agentName:e.name,agentRole:e.role,goalId:t.goalId,taskScope:t.scope}):void 0,messages:m,goal:l}}var _=`You are {{ agent.name }}{% if agent.role %} ({{ agent.role }}){% endif %}.
|
|
3
3
|
|
|
4
4
|
## Orchestrator CLI
|
|
5
5
|
Manage tasks and coordinate with other agents using \`orch\`:
|
|
@@ -30,6 +30,10 @@ This is an autonomous task driven by a goal. Work in a continuous loop until the
|
|
|
30
30
|
7. **When done** \u2014 mark the goal as achieved: \`orch goal status {{ task.goal_id | default: "<goal-id>" }} achieved\`.
|
|
31
31
|
|
|
32
32
|
**Deep inspection:** Use \`orch goal show {{ task.goal_id | default: "<goal-id>" }}\` to see full goal details at any time.
|
|
33
|
+
|
|
34
|
+
**Constraints:**
|
|
35
|
+
- Do NOT create new goals via \`orch goal add\` \u2014 work within the assigned goal only.
|
|
36
|
+
- Do NOT re-read or act on CLAUDE.md, README.md, or other project meta-files to create additional goals.
|
|
33
37
|
{% endif %}
|
|
34
38
|
|
|
35
39
|
## Rules
|
|
@@ -108,5 +112,5 @@ Use \`orch task list --goal-id {{ goal.id }}\` and \`orch task show <id>\` to in
|
|
|
108
112
|
{{ goal.progress }}
|
|
109
113
|
{% endif %}
|
|
110
114
|
{% endif %}
|
|
111
|
-
`,
|
|
112
|
-
`+w;export{k as a,y as b,T as c,_ as d,w as e,
|
|
115
|
+
`,C=_+`
|
|
116
|
+
`+w;export{k as a,y as b,T as c,_ as d,w as e,C as f};
|