@oxgeneral/orch 1.0.9 → 1.0.11
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-AMHLKLQC.js +22 -0
- package/dist/chunk-EGOR4O46.js +5 -0
- package/dist/{chunk-4MMHVHA6.js → chunk-LY3X2UHQ.js} +7 -3
- package/dist/{chunk-5YSW77VI.js → chunk-OLKQBQ4I.js} +20 -7
- package/dist/chunk-OLKQBQ4I.js.map +1 -0
- 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-LV3WOPMS.js → container-NS3YS47A.js} +1 -1
- package/dist/index.d.ts +6 -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-WLWIAFXH.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-JOIPYKKG.js +3 -0
- package/dist/{structured-logger-EXMGTUDB.js → structured-logger-RJ6VF35J.js} +2 -2
- package/dist/{task-6Z5P7ODZ.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-H3L67RHY.js +2 -0
- package/dist/{update-XGJZFV4H.js → update-W54LAATS.js} +1 -1
- package/dist/update-check-R5ABF6HE.js +2 -0
- 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/dist/App-Q6LOPAZT.js +0 -22
- package/dist/chunk-5YSW77VI.js.map +0 -1
- package/dist/chunk-VG4465AG.js.map +0 -1
- package/dist/chunk-XLBV2PFL.js +0 -5
- package/dist/orchestrator-PSXVHP2L.js +0 -17
- package/dist/orchestrator-WLWIAFXH.js +0 -6
- package/dist/run-NE5E4JPW.js +0 -3
- package/dist/serve-4RT4HERL.js +0 -3
- package/dist/template-engine-5ZKVJMYA.js +0 -3
- package/dist/tui-GH3Z5CO4.js +0 -2
- package/dist/update-check-CZJC7VW6.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 so,{useState,useMemo,useEffect,useRef,useCallback}from'react';import {Box,Text,useInput,useApp,useStdout}from'ink';import {jsxs,jsx,Fragment}from'react/jsx-runtime';var e={amber:"#ffaf00",amberDim:"#af8700",green:"#5faf87",red:"#d75f5f",blue:"#5fafd7",yellow:"#d7af00",cyan:"#5fd7d7",purple:"#af87ff",white:"#eeeeee",silver:"#bcbcbc",gray:"#808080",dim:"#585858",ghost:"#3a3a3a",void:"#262626",errorBg:"#3d1515",warnBg:"#3d2e0a",successBg:"#0f2d1f",infoBg:"#1a1a22",toolBg:"#0f1f2d"},_o="\u2501",Ve="\u2500",ue="\xB7",Zt="\u25C8",Cr="\u2605",gn="\u27F3",zt="\u25C6",Ro={in_progress:e.green,retrying:e.yellow,review:e.blue,todo:e.dim,done:e.green,failed:e.red,cancelled:e.dim},Cs=new Map,Is=new Map;function He(t){if(t<=0)return "";let n=Cs.get(t);return n||(n=_o.repeat(t),Cs.set(t,n)),n}function Te(t){if(t<=0)return "";let n=Is.get(t);return n||(n=Ve.repeat(t),Is.set(t,n)),n}function tt(t,n){return t.length>n?t.slice(0,n-1)+"\u2026":t}var Xa=1e4;function Ir(t,n=Xa){if(t)return t.length>n?t.slice(0,n)+`
|
|
3
|
+
\u2026[truncated]`:t}var Ms={active:e.green,paused:e.dim,achieved:e.amber,abandoned:e.ghost};var Ya=120,Mr=0,to=null,Ao=new Set;function Za(){to||(to=setInterval(()=>{Mr++;for(let t of Ao)t(Mr);},Ya));}function Ja(){to&&Ao.size===0&&(clearInterval(to),to=null);}function mn(){let[t,n]=useState(Mr);return useEffect(()=>{let o=r=>n(r);return Ao.add(o),Za(),()=>{Ao.delete(o),Ja();}},[]),t}var vs=["\u280B","\u2819","\u2839","\u2838","\u283C","\u2834","\u2826","\u2827","\u2807","\u280F"];function Bn({color:t}){let n=mn();return jsx(Text,{color:t,children:vs[n%vs.length]})}var no={in_progress:0,retrying:1,review:2,todo:3,done:4,failed:5,cancelled:6};var nl="\u25CB",Rs="\u2713",As="\u2715",ol="\u21BB",rl="\u2500",sl="\u25B6",Ot={green:"#0f2d1f",blue:"#0f1f2d",yellow:"#2d2a0f",red:"#2d0f0f",neutral:"#1a1a22",amber:"#2d1f0a"},il={in_progress:{icon:sl,label:"RUN",fg:e.green,bg:Ot.green,bold:true,spinner:true},retrying:{icon:ol,label:"RETRY",fg:e.yellow,bg:Ot.yellow,spinner:true},review:{icon:Zt,label:"REVIEW",fg:e.blue,bg:Ot.blue},todo:{icon:nl,label:"TODO",fg:e.dim,bg:Ot.neutral},done:{icon:Rs,label:"DONE",fg:e.green,bg:Ot.green},failed:{icon:As,label:"FAIL",fg:e.red,bg:Ot.red,bold:true},cancelled:{icon:rl,label:"OFF",fg:e.dim,bg:Ot.neutral}},al={1:{color:e.red,label:"!!!"},2:{color:e.yellow,label:"!!"},3:{color:e.dim,label:"!"},4:{color:e.ghost,label:ue}};var cl=18,dl="#2d1f0a",$o=so.memo(function({task:n,selected:o,width:r,agentNameMap:l,goalMap:f$1}){let b=il[n.status],T=n.status==="in_progress"||n.status==="retrying",x=al[n.priority]??{color:e.ghost,label:ue},y,S;if(n.status==="done")y=Rs,S=e.green;else if(n.status==="failed")y=As,S=e.red;else if(T){let E=Date.now()-new Date(n.updated_at).getTime();y=f(E),S=e.cyan;}else y="\u2014",S=void 0;let M=o?"\u25B8":" ",B=n.goalId?f$1?.get(n.goalId):void 0,C=!!B,W=10,H=4,G=14,L=C?cl:0,j=7,O=2+W+H+G+L+j,P=r?Math.max(10,r-O):40,N=n.assignee?l?.get(n.assignee)??n.assignee:void 0;return jsxs(Box,{children:[jsxs(Text,{color:o?e.amber:void 0,children:[M," "]}),jsx(Box,{width:W,children:jsx(Text,{backgroundColor:b.bg,color:b.fg,bold:b.bold,children:b.spinner?jsxs(Fragment,{children:[" ",jsx(Bn,{color:b.fg})," ",b.label," "]}):jsxs(Fragment,{children:[" ",b.icon," ",b.label," "]})})}),jsx(Box,{width:H,children:jsx(Text,{color:x.color,bold:n.priority<=2,children:x.label})}),jsxs(Box,{width:P,children:[jsx(Text,{wrap:"truncate",bold:o||T,color:o?e.white:T?e.silver:void 0,children:n.title.length>P?n.title.slice(0,P-1)+"\u2026":n.title}),(n.attachments?.length??0)>0&&jsxs(Text,{color:e.dim,children:[" ","\u{1F4CE}",n.attachments.length]})]}),C&&jsx(Box,{width:L,children:jsxs(Text,{backgroundColor:dl,color:e.amberDim,wrap:"truncate",children:[" \u2295 ",tt(B.title,13)," "]})}),jsx(Box,{width:G,children:N?jsxs(Text,{backgroundColor:Ot.green,color:e.green,wrap:"truncate",children:[" ",N.length>G-2?N.slice(0,G-3)+"\u2026":N," "]}):jsx(Text,{color:e.ghost,children:"\u2014"})}),jsx(Box,{width:j,justifyContent:"flex-end",children:jsx(Text,{color:S,dimColor:!S,children:y})})]})});var $s="\u2295";function Bs({goalTitle:t,taskCount:n,doneCount:o,width:r}){let l=n>0?Math.round(o/n*100):0,f=` ${$s} ${t.toUpperCase()} ${ue} ${n} task${n!==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:Te(b)}),jsx(Text,{backgroundColor:Ot.amber,color:e.amber,bold:true,children:f}),jsx(Text,{color:e.ghost,children:Te(T)})]})}function Es({taskCount:t,width:n}){let o=` ${$s} UNGROUPED ${ue} ${t} task${t!==1?"s":""} `,r=3,l=Math.max(0,n-r-o.length-4);return jsxs(Box,{paddingX:2,children:[jsx(Text,{color:e.ghost,children:Te(r)}),jsx(Text,{backgroundColor:Ot.neutral,color:e.dim,children:o}),jsx(Text,{color:e.ghost,children:Te(l)})]})}var gl="\u2715",Ls="\u25CB",ml="\u25B6",fl="\u2713",En={green:"#0f2d1f",red:"#2d0f0f",neutral:"#1a1a22",amber:"#2d1f0a"},pl={running:{icon:ml,label:"ACTIVE",fg:e.green,bg:En.green,bold:true,spinner:true},idle:{icon:Ls,label:"IDLE",fg:e.dim,bg:En.neutral},error:{icon:gl,label:"ERROR",fg:e.red,bg:En.red,bold:true},disabled:{icon:Ls,label:"OFF",fg:e.ghost,bg:En.neutral}},vr={running:0,idle:1,error:2,disabled:3},Ps=so.memo(function({agent:n,selected:o,width:r,runningEntry:l,currentTaskTitle:f$1,teamName:b,isLead:T}){let x=pl[n.status],y=n.status==="running",S,M;if(y&&l){let N=Date.now()-new Date(l.started_at).getTime();S=f(N),M=e.cyan;}else n.stats.total_runs>0?(S=`${n.stats.tasks_completed}/${n.stats.total_runs}`,M=n.stats.tasks_completed>0?e.green:e.dim):(S="\u2014",M=void 0);let B=o?"\u25B8":" ",C=11,W=8,H=b?Math.min(b.length+2,12):0,G=10,L=2+C+W+H+G,j=r?Math.max(8,r-L):20,O=n.stats.total_runs>0,P=O?Math.round(n.stats.tasks_completed/n.stats.total_runs*100):0;return jsxs(Box,{children:[jsxs(Text,{color:o?e.amber:void 0,children:[B," "]}),jsx(Box,{width:C,children:jsx(Text,{backgroundColor:x.bg,color:x.fg,bold:x.bold,children:x.spinner?jsxs(Fragment,{children:[" ",jsx(Bn,{color:x.fg})," ",x.label," "]}):jsxs(Fragment,{children:[" ",x.icon," ",x.label," "]})})}),jsx(Box,{width:j,children:jsxs(Text,{wrap:"truncate",bold:o||y,color:o?e.white:y?e.green:e.silver,children:[n.autonomous&&jsxs(Text,{color:e.cyan,children:[gn," "]}),T&&jsxs(Text,{color:e.amber,children:[Cr," "]}),n.name,y&&f$1&&jsxs(Text,{color:e.dim,children:[" ",ue," ",f$1]}),n.status==="error"&&n.last_error&&jsxs(Text,{color:e.red,children:[" ",ue," ",tt(m[n.last_error.kind]?.message??n.last_error.message,30)]})]})}),jsx(Box,{width:W,children:jsx(Text,{color:e.dim,children:n.adapter})}),b&&jsx(Box,{width:H,children:jsx(Text,{color:e.amber,wrap:"truncate",children:b})}),jsx(Box,{width:G,justifyContent:"flex-end",children:O&&!y?jsxs(Text,{color:P>=80?e.green:P>=50?e.yellow:e.red,children:[S," ",fl]}):jsx(Text,{color:M,dimColor:!M,children:S})})]})});function Ns({teamName:t,memberCount:n,leadName:o,width:r}){let l=`${n} agent${n!==1?"s":""}`,f=o?` ${ue} ${Cr} ${o}`:"",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:Te(T)}),jsx(Text,{backgroundColor:En.amber,color:e.amber,bold:true,children:b}),jsx(Text,{color:e.ghost,children:Te(x)})]})}var hl="\u25C7";function Ds({memberCount:t,width:n}){let o=`${t} agent${t!==1?"s":""}`,r=` ${hl} UNASSIGNED ${ue} ${o} `,l=3,f=Math.max(0,n-l-r.length-4);return jsxs(Box,{paddingX:2,children:[jsx(Text,{color:e.ghost,children:Te(l)}),jsx(Text,{backgroundColor:En.neutral,color:e.dim,children:r}),jsx(Text,{color:e.ghost,children:Te(f)})]})}var Fs="\u2713",Ws="\u2715",bl="\u2016",Tl="\u25C9",ro={green:"#0f2d1f",amber:"#2d1f0a",neutral:"#1a1a22"},yl={active:{icon:Tl,label:"ACTIVE",fg:e.green,bg:ro.green,bold:true},paused:{icon:bl,label:"PAUSED",fg:e.dim,bg:ro.neutral},achieved:{icon:Fs,label:"DONE",fg:e.amber,bg:ro.amber,bold:true},abandoned:{icon:Ws,label:"DROP",fg:e.ghost,bg:ro.neutral}},wl="\u2588",Sl="\u2591",kl=14,Gs=so.memo(function({goal:n,selected:o,width:r,agentNameMap:l,tasksByGoal:f}){let b=yl[n.status],T=o?"\u25B8":" ",x=f?.length??0,y=f?.filter(P=>P.status==="done").length??0,S=x>0,M=11,B=S?kl:0,C=14,W=7,H=2+M+B+C+W,G=r?Math.max(10,r-H):40,L=n.assignee?l?.get(n.assignee)??n.assignee:void 0,j,O;if(n.status==="achieved")j=Fs,O=e.amber;else if(n.status==="abandoned")j=Ws,O=e.ghost;else {let P=Date.now()-new Date(n.created_at).getTime(),N=Math.floor(P/864e5);j=N>0?`${N}d`:"<1d",O=e.dim;}return jsxs(Box,{children:[jsxs(Text,{color:o?e.amber:void 0,children:[T," "]}),jsx(Box,{width:M,children:jsxs(Text,{backgroundColor:b.bg,color:b.fg,bold:b.bold,children:[" ",b.icon," ",b.label," "]})}),jsx(Box,{width:G,children:jsx(Text,{wrap:"truncate",bold:o||n.status==="active",color:o?e.white:n.status==="active"?e.silver:void 0,children:n.title.length>G?n.title.slice(0,G-1)+"\u2026":n.title})}),S&&(()=>{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:wl.repeat(N)}),jsx(Text,{color:e.ghost,children:Sl.repeat(E)}),jsx(Text,{color:e.dim,children:` ${y}/${x}`})]})})(),jsx(Box,{width:C,children:L?jsxs(Text,{backgroundColor:ro.green,color:e.green,wrap:"truncate",children:[" ",L.length>C-2?L.slice(0,C-3)+"\u2026":L," "]}):jsx(Text,{color:e.ghost,children:"\u2014"})}),jsx(Box,{width:W,justifyContent:"flex-end",children:jsx(Text,{color:O,dimColor:!O,children:j})})]})});var Cl={system:"\u2666",lifecycle:"\u25B6",output:"\u2502",tool:"\u2699",result:"\u2190",error:"\u2715",file:"\u270E",info:"\u2502"};function Pn({label:t,width:n,color:o}){let r=n-4,l=` ${t} `,f=3,b=Math.max(0,r-f-l.length);return jsxs(Text,{color:o??e.ghost,children:[" ",Te(f),l,Te(b)]})}function zs({task:t,height:n,width:o,taskLogs:r,agentNameMap:l,taskTitleMap:f}){let b=Ro[t.status]??e.dim,T=t.priority<=2?t.priority===1?e.red:e.yellow:void 0,x=24,y=!!t.description?.trim(),S=!!t.proof?.agent_summary,M=(t.proof?.files_changed?.length??0)>0,B=(r?.length??0)>0,C=(t.attachments?.length??0)>0,W=y?t.description.split(`
|
|
4
|
+
`):[],H=S?t.proof.agent_summary.split(`
|
|
5
|
+
`):[],G=3;C&&(G+=2+t.attachments.length),y?(G+=1,G+=Math.min(W.length,Math.max(1,Math.ceil((n-10)*.3)))):S||(G+=2),S&&(G+=2),M&&(G+=1),B&&(G+=2);let L=Math.max(0,n-G),j=0,O=0;S&&B?(j=Math.max(1,Math.floor(L*.4)),O=Math.max(1,L-j)):S?j=L:B&&(O=L);let P=y?W.slice(0,Math.max(1,Math.ceil((n-10)*.3))):[],N=H.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(Pn,{label:`attachments (${t.attachments.length})`,width:o,color:e.dim}),t.attachments.map((E,z)=>jsxs(Text,{color:e.cyan,wrap:"truncate",children:[" ",E]},`a${z}`))]}),y&&jsxs(Fragment,{children:[jsx(Text,{children:" "}),P.map((E,z)=>jsxs(Text,{color:e.silver,wrap:"truncate",children:[" ",tt(E,o-8)]},`d${z}`))]}),!y&&!S&&jsxs(Fragment,{children:[jsx(Text,{children:" "}),jsx(Text,{color:e.dim,children:" No description."})]}),S&&jsxs(Fragment,{children:[jsx(Text,{children:" "}),jsx(Pn,{label:"result",width:o,color:e.dim}),N.map((E,z)=>jsxs(Text,{color:e.white,wrap:"truncate",children:[" ",tt(E,o-8)]},`r${z}`))]}),M&&jsxs(Box,{children:[jsx(Text,{color:e.dim,children:" files "}),jsx(Text,{color:e.cyan,children:t.proof.files_changed.length}),jsx(Text,{color:e.dim,children:" changed"}),t.proof.branch&&jsxs(Fragment,{children:[jsxs(Text,{color:e.dim,children:[" ","\xB7"," "]}),jsx(Text,{color:e.cyan,children:t.proof.branch})]})]}),B&&jsxs(Fragment,{children:[jsx(Text,{children:" "}),jsx(Pn,{label:"activity",width:o,color:e.dim}),r.slice(-O).map((E,z)=>{let V=E.msgType??"info",X=Cl[V]??"\u2502",R=E.color;V==="tool"?R=e.cyan:V==="file"?R=e.purple:V==="error"?R=e.red:V==="lifecycle"?R=e.green:V==="system"&&(R=e.dim);let ae=Math.max(10,o-12),Be=tt(E.text,ae);return jsxs(Box,{children:[jsxs(Text,{color:e.ghost,children:[" ",E.time," "]}),jsxs(Text,{color:V==="error"?e.red:e.dim,children:[X," "]}),jsx(Text,{color:R,bold:V==="lifecycle",children:Be})]},z)})]})]})}var Bo=[{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 Il="\u25CF",Hs="\u25CB",Ml="\u2713",vl="\u2715",_l="\u2191",Rl="\u2193",Al="\u03A3",$l="\u25B6",Bl="\u21BB",El="\u{1F9E0}",Vs=["\u280B","\u2819","\u2839","\u2838","\u283C","\u2834","\u2826","\u2827","\u2807","\u280F"],_r=[" ","\u2581","\u2582","\u2583","\u2584","\u2585","\u2586","\u2587","\u2588"],nt={green:"#0f2d1f",blue:"#0f1f2d",yellow:"#2d2a0f",red:"#2d0f0f",neutral:"#1a1a22",amber:"#2d1f0a"};function js({color:t}){let n=mn();return jsx(Text,{color:t,children:Vs[n%Vs.length]})}function Ll(){let t=mn(),n=Math.floor(t/10)%2===0;return jsx(Text,{color:n?e.amber:e.amberDim,bold:true,children:zt})}function Ol({width:t,active:n}){let o=Math.max(4,Math.floor(t*.08)),r=2,l=mn(),f=Math.ceil((t+o)/r),b=n?l%(f*2):0;if(!n)return jsx(Box,{paddingX:1,children:jsx(Text,{color:e.ghost,children:He(t)})});let T=b<f?b*r:(f*2-b)*r,x=Math.max(0,T-o),y=Math.min(t,T),S=x,M=Math.max(0,y-x),B=Math.max(0,t-y);return jsxs(Box,{paddingX:1,children:[jsx(Text,{color:e.ghost,children:He(S)}),jsx(Text,{color:e.amber,children:He(M)}),jsx(Text,{color:e.ghost,children:He(B)})]})}function Pl({data:t,width:n,color:o}){if(t.length===0)return null;let r=t.slice(-n),l=Math.max(...r,1),f=r.map(b=>{let T=Math.round(b/l*(_r.length-1));return _r[T]??_r[0]}).join("");return jsx(Text,{color:o,children:f})}function Nl({tab:t,flashColor:n,onComplete:o,badge:r}){let l=mn(),f=so.useRef(l),b=so.useRef(false),T=l-f.current,x=2,y=6*x;return so.useEffect(()=>{T>=y&&!b.current&&(b.current=true,o());},[T,o]),Math.floor(T/x)%2===0&&T<y?jsxs(Text,{backgroundColor:n,color:"#0a0a0c",bold:true,children:[" ",t.key," ",t.label,r," "]}):jsxs(Box,{gap:0,children:[jsx(Text,{color:e.ghost,children:t.key}),jsxs(Text,{color:e.dim,children:[" ",t.label.toLowerCase(),r]})]})}function Dl({projectName:t,activeView:n,mode:o,stats:r,uptime:l,width:f,version:b,latestVersion:T,updateInstalled:x,taskBadge:y,flashTab:S,flashColor:M,onFlashComplete:B}){let C=o==="watching";return jsxs(Box,{paddingX:1,justifyContent:"space-between",width:f,children:[jsxs(Box,{gap:0,children:[jsx(Ll,{}),jsx(Text,{color:e.amber,bold:true,children:" ORCH"}),b&&jsxs(Text,{color:e.ghost,children:[" ",b]}),T&&T!==b&&(x?jsxs(Text,{backgroundColor:nt.green,color:e.green,bold:true,children:[" v",T," INSTALLED \u2014 RESTART TO APPLY "]}):jsxs(Text,{backgroundColor:nt.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:Bo.map((W,H)=>{let G=n===W.id,L=W.id==="tasks"&&y!=null&&y>0?` (${y})`:"",j=!G&&S===W.id&&M&&B;return jsxs(so.Fragment,{children:[H>0&&jsx(Text,{children:" "}),G?jsxs(Text,{backgroundColor:e.amber,color:"#0a0a0c",bold:true,children:[" ",W.key," ",W.label,L," "]}):j?jsx(Nl,{tab:W,flashColor:M,onComplete:B,badge:L}):jsxs(Box,{gap:0,children:[jsx(Text,{color:e.ghost,children:W.key}),jsxs(Text,{color:e.dim,children:[" ",W.label.toLowerCase(),L]})]})]},W.id)})}),jsxs(Box,{gap:0,children:[C?jsxs(Text,{backgroundColor:nt.green,color:e.green,bold:true,children:[" ",Il," WATCHING"," "]}):jsxs(Text,{backgroundColor:nt.neutral,color:e.dim,children:[" ",Hs," IDLE"," "]}),r.running>0&&jsxs(Fragment,{children:[jsx(Text,{children:" "}),jsxs(Text,{backgroundColor:nt.green,color:e.green,children:[" ",jsx(js,{color:e.green})," ",r.running," active"," "]})]}),l&&jsxs(Text,{color:e.ghost,children:[" ",l]})]})]})}function Fl({stats:t,tokens:n,width:o,sparklineData:r}){let f=[{icon:$l,label:"RUN",count:t.running,fg:e.green,bg:nt.green,bold:true,spinner:true,show:t.running>0},{icon:Bl,label:"RETRY",count:t.retrying,fg:e.yellow,bg:nt.yellow,show:t.retrying>0},{icon:Zt,label:"REVIEW",count:t.review,fg:e.blue,bg:nt.blue,show:t.review>0},{icon:Hs,label:"TODO",count:t.todo,fg:e.dim,bg:nt.neutral,show:t.todo>0},{icon:Ml,label:"DONE",count:t.done,fg:e.green,bg:nt.green,show:t.done>0},{icon:vl,label:"FAIL",count:t.failed,fg:e.red,bg:nt.red,bold:true,show:t.failed>0},{icon:zt,label:"TEAMS",count:t.teams,fg:e.amber,bg:nt.amber,show:t.teams>0}].filter(x=>x.show),b=n.total>0,T=r&&r.length>0?Math.min(16,r.length):0;return jsxs(Box,{paddingX:1,justifyContent:"space-between",width:o,children:[jsxs(Box,{gap:1,children:[f.map(x=>jsx(Text,{backgroundColor:x.bg,color:x.fg,bold:x.bold,children:x.spinner?jsxs(Fragment,{children:[" ",jsx(js,{color:x.fg})," ",x.count," ",x.label," "]}):jsxs(Fragment,{children:[" ",x.icon," ",x.count," ",x.label," "]})},x.label)),f.length===0&&jsxs(Text,{backgroundColor:nt.neutral,color:e.dim,children:[" ","NO TASKS"," "]})]}),jsxs(Box,{gap:0,children:[T>0&&r&&jsxs(Fragment,{children:[jsx(Pl,{data:r,width:T,color:e.amberDim}),jsx(Text,{children:" "})]}),b&&jsxs(Text,{backgroundColor:nt.amber,color:e.cyan,children:[" ",_l,h(n.input)," ",Rl,h(n.output),n.reasoning>0?` ${El}${h(n.reasoning)}`:""," ",ue," ",Al,h(n.total)," "]})]})]})}var Us=so.memo(function(n){let o=Math.max(10,n.width-2),r=n.stats.running>0;return jsxs(Box,{flexDirection:"column",children:[jsx(Box,{height:1}),jsx(Dl,{projectName:n.projectName,activeView:n.activeView,mode:n.mode,stats:n.stats,uptime:n.uptime,width:n.width,version:n.version,latestVersion:n.latestVersion,updateInstalled:n.updateInstalled,taskBadge:n.taskBadge,flashTab:n.flashTab,flashColor:n.flashColor,onFlashComplete:n.onFlashComplete}),jsx(Box,{height:1}),jsx(Fl,{stats:n.stats,tokens:n.tokens,width:n.width,sparklineData:n.sparklineData}),jsx(Ol,{width:o,active:r})]})});var io="\u0423\u041F\u0420\u0410\u0412\u041B\u0415\u041D\u0418\u0415",Nn="\u041C\u041E\u041D\u0418\u0422\u041E\u0420\u0418\u041D\u0413",Lo="\u041D\u0410\u0421\u0422\u0420\u041E\u0419\u041A\u0418",fn={task:{sub:["add","list","show","cancel","retry","assign","approve","reject","delete"],help:"Manage tasks",category:io},agent:{sub:["add","list","disable","enable","delete","autonomous","shop"],help:"Manage agents",category:io},team:{sub:["create","list","join","leave","disband","set-lead"],help:"Manage teams",category:io},goal:{sub:["add","list","show","status","delete"],help:"Manage goals",category:io},run:{args:"[id]",help:"Run task (or selected)",category:Nn},"run-all":{help:"Run all todo tasks",category:Nn},watch:{help:"Start watch mode (auto-dispatch)",category:Nn},pause:{help:"Pause watch mode",category:Nn},status:{help:"Show orchestrator status",category:Nn},config:{sub:["activity-filter","max-concurrent"],help:"TUI settings",category:Lo},help:{help:"List all commands",category:Lo},quit:{help:"Exit the TUI",category:Lo}};function Rr(t){if(!t.startsWith("/"))return null;let n=t.slice(1),o=n.indexOf(" ");if(o===-1){let T=n;if(!T)return null;let x=Object.keys(fn).find(y=>y.startsWith(T)&&y!==T);return x?x.slice(T.length):null}let r=n.slice(0,o),l=fn[r];if(!l?.sub)return null;let f=n.slice(o+1);if(!f)return null;let b=l.sub.find(T=>T.startsWith(f)&&T!==f);return b?b.slice(f.length):null}function Xs(t){if(!t.startsWith("/"))return [];let n=t.slice(1),o=n.indexOf(" ");if(o===-1){let T=n.toLowerCase(),x=[];if(!T){let y=[io,Nn,Lo];for(let S of y){x.push({cmd:"",desc:`\u2500\u2500 ${S} \u2500\u2500`});for(let[M,B]of Object.entries(fn))if(B.category===S){let C=B.args?` ${B.args}`:"";x.push({cmd:`/${M}${C}`,desc:B.help,subs:B.sub?.join(" \xB7 ")});}}return x}for(let[y,S]of Object.entries(fn))if(y.startsWith(T)){let M=S.args?` ${S.args}`:"";if(x.push({cmd:`/${y}${M}`,desc:S.help,subs:S.sub?.join(" \xB7 ")}),y===T&&S.sub)for(let B of S.sub)x.push({cmd:`/${y} ${B}`,desc:`${S.help}: ${B}`});}return x}let r=n.slice(0,o),l=fn[r];if(!l?.sub)return [];let f=n.slice(o+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 Oo=class{entries=[];cursor=0;push(n){n&&(this.entries[this.entries.length-1]!==n&&(this.entries.push(n),this.entries.length>100&&this.entries.shift()),this.cursor=this.entries.length);}prev(){return this.entries.length===0?null:(this.cursor>0&&this.cursor--,this.entries[this.cursor]??null)}next(){return this.cursor<this.entries.length-1?(this.cursor++,this.entries[this.cursor]??null):(this.cursor=this.entries.length,null)}reset(){this.cursor=this.entries.length;}};var Gl="\u2588",qs=so.memo(function({mode:n,value:o,completion:r,activeView:l,canRun:f,canNew:b,canApprove:T,canReject:x,canCancel:y,canDelete:S,canUndo:M,canEdit:B,canForceStop:C,canToggleAuto:W,autoActive:H,canPause:G,isPaused:L,canToggleShowAll:j,showAllActive:O,hasDetail:P,itemCount:N,itemLabel:E,width:z,hasSuggestions:V,onboardingCompleted:X}){if(n==="command"){let R=V?" \u2191\u2193 select Tab fill Esc \u2715":" Enter exec \u2191\u2193 history Tab complete Esc \u2715",ae=Math.max(4,z-6-R.length-(r?.length??0)-1),Be=o.length>ae?"\u2026"+o.slice(-(ae-1)):o;return jsx(Box,{paddingX:2,justifyContent:"space-between",width:z,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:Gl}),jsx(Text,{color:e.dim,children:R})]})})}return jsxs(Box,{paddingX:2,justifyContent:"space-between",width:z,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"]}),G&&jsxs(Fragment,{children:[" ",jsx(Text,{bold:true,color:e.amber,children:"P"}),L?" resume":" pause"]}),W&&jsxs(Fragment,{children:[" ",jsx(Text,{bold:true,color:e.cyan,children:"U"}),H?" auto off":" auto on"]}),j&&jsxs(Fragment,{children:[" ",jsx(Text,{bold:true,color:e.gray,children:"S"}),O?" collapse":" show all"]}),S&&!T&&jsxs(Fragment,{children:[" ",jsx(Text,{bold:true,color:e.gray,children:"D"})," delete"]}),M&&jsxs(Fragment,{children:[" ",jsx(Text,{bold:true,color:e.yellow,children:"Z"})," undo"]}),P&&jsxs(Fragment,{children:[" ",jsx(Text,{bold:true,color:e.gray,children:"Esc"})," close"]}),!P&&(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 Po="\u2588",$r=process.platform==="darwin"?"\u2318":"Ctrl";function Hl(t,n){if(n<=0||t.length<=n)return [t];let o=[];for(let r=0;r<t.length;r+=n)o.push(t.slice(r,r+n));return o}function No(t,n){if(n<=0)return 0;let o=n-1;for(;o>0&&t[o-1]===" ";)o--;for(;o>0&&t[o-1]!==" ";)o--;return o}function Zs(t,n){if(n>=t.length)return t.length;let o=n;for(;o<t.length&&t[o]!==" ";)o++;for(;o<t.length&&t[o]===" ";)o++;return o}function Js({title:t,steps:n,onComplete:o,onCancel:r,width:l,height:f,onPasteImage:b,footerExtra:T,onSuggestionSelected:x}){let [y,S]=useState(0),[M,B]=useState({}),[C,W]=useState(()=>{let A=n.find(I=>!I.skip?.({}));return A?.type==="text"&&A.defaultValue?A.defaultValue:""}),[H,G]=useState(()=>{let A=n.find(I=>!I.skip?.({}));return A?.type==="text"&&A.defaultValue?A.defaultValue.length:0}),[L,j]=useState(()=>{let A=n.find(I=>!I.skip?.({}));return A?.type==="textarea"&&A.defaultValue?A.defaultValue.split(`
|
|
6
|
+
`):[""]}),[O,P]=useState(0),[N,E]=useState(0),[z,V]=useState(()=>{let A=n.find(I=>!I.skip?.({}));if(A?.type==="select"&&A.defaultValue){let k=(A.getOptions?.({})??A.options??[]).findIndex(_=>_.value===A.defaultValue);return k>=0?k:0}return 0}),X=useMemo(()=>n.filter(A=>!A.skip?.(M)),[n,M]),R=X[y],ae=X.length,{taLineNumWidth:Dt,taContentWidth:ct}=useMemo(()=>{let A=String(L.length).length;return {taLineNumWidth:A,taContentWidth:Math.max(1,l-A-4)}},[L.length,l]),Re=useMemo(()=>{if(!R||R.type!=="textarea")return [];let A=[];for(let I=0;I<L.length;I++){let k=Hl(L[I]??"",ct);for(let _=0;_<k.length;_++)A.push({logicalRow:I,startCol:_*ct,text:k[_],isFirst:_===0});}return A},[R?.id,R?.type,L,ct]),qe=useMemo(()=>{for(let A=0;A<Re.length;A++){let I=Re[A];if(I.logicalRow===O&&(N>=I.startCol&&N<I.startCol+ct||N>=I.startCol&&(A+1>=Re.length||Re[A+1].logicalRow!==O)))return A}return 0},[Re,O,N,ct]),[dt,ft]=useState(new Set),[Ne,Ke]=useState(false),[ut,Ye]=useState(0),[nn,ke]=useState(false),[pt,Rt]=useState(null),[jt,ht]=useState(false),Qe=useRef(null),gt=useRef(null),Wn=useMemo(()=>R?R.type==="text"?C:R.type==="textarea"?L.join(`
|
|
7
|
+
`):"":"",[R,C,L]),co=useCallback((A,I)=>{if(Qe.current&&clearTimeout(Qe.current),!I){Rt(null);return}Qe.current=setTimeout(()=>{Rt(I(A));},300);},[]);useEffect(()=>(R&&R.validate&&(R.type==="text"||R.type==="textarea")&&co(Wn,R.validate),()=>{Qe.current&&clearTimeout(Qe.current);}),[Wn,R,co]),useEffect(()=>()=>{gt.current&&clearTimeout(gt.current);},[]);let St=useMemo(()=>!R||R.type!=="select"&&R.type!=="multiselect"?[]:R.getOptions?.(M)??R.options??[],[R,M]),Ut=Math.min(z,Math.max(0,St.length-1)),kt=useMemo(()=>{if(!R?.suggestions)return [];if(!C.trim())return R.suggestions;let A=C.toLowerCase();return R.suggestions.filter(I=>I.label.toLowerCase().includes(A)||(I.hint??"").toLowerCase().includes(A))},[R?.suggestions,C]),on=Math.min(ut,Math.max(0,kt.length-1)),Ft=A=>{let I={...M,[R.id]:A};B(I),W(""),G(0),j([""]),P(0),E(0),V(0),ft(new Set),Ke(false),Ye(0),ke(false),Rt(null),ht(false),Qe.current&&clearTimeout(Qe.current);let k=R.id,Y=n.findIndex(q=>q.id===k)+1;for(;Y<n.length;){let q=n[Y];if(q&&!q.skip?.(I))break;Y++;}if(Y>=n.length)o(I);else {let q=n[Y].id,K=n.filter(le=>!le.skip?.(I)).findIndex(le=>le.id===q);S(K>=0?K:0);let pe=n[Y];if(pe.type==="text"){let le=pe.defaultValue??"";W(le),G(le.length);}else if(pe.type==="textarea"){let le=pe.defaultValue?pe.defaultValue.split(`
|
|
8
|
+
`):[""];j(le),P(le.length-1),E(le[le.length-1].length);}else if(pe.type==="select"){let le=pe.getOptions?.(I)??pe.options??[];if(pe.defaultValue){let Xt=le.findIndex(qt=>qt.value===pe.defaultValue);V(Xt>=0?Xt:0);}else V(0);}else pe.type==="multiselect"&&(V(0),pe.defaultValue?ft(new Set(pe.defaultValue.split(","))):ft(new Set));}},rn=()=>{if(y===0){r();return}let A=R.id,k=n.findIndex(K=>K.id===A)-1;for(;k>=0;){let K=n[k];if(K&&!K.skip?.(M))break;k--;}if(k<0){r();return}let _=n[k].id,Y=X.findIndex(K=>K.id===_);S(Y>=0?Y:0),Ke(false),Ye(0),ke(false),Rt(null),ht(false),Qe.current&&clearTimeout(Qe.current);let q=n[k];if(M[q.id]&&ke(true),q.type==="text"){let K=M[q.id]??q.defaultValue??"";W(K),G(K.length);}else if(q.type==="textarea"){let K=M[q.id]??q.defaultValue??"",pe=K?K.split(`
|
|
9
|
+
`):[""];j(pe),P(pe.length-1),E(pe[pe.length-1].length);}else if(q.type==="multiselect"){V(0);let K=M[q.id];ft(K?new Set(K.split(",")):new Set);}else {let K=q.getOptions?.(M)??q.options??[],pe=M[q.id],le=K.findIndex(Xt=>Xt.value===pe);V(le>=0?le:0);}};if(useInput((A,I)=>{if(R){if(I.escape){y===0?r():rn();return}if((I.ctrl||I.meta)&&(A==="v"||A==="i")&&b&&(R.type==="text"||R.type==="textarea")){b();return}if(R.type==="text"){if(Ne&&kt.length>0){if(I.upArrow){on<=0?Ke(false):Ye(k=>k-1);return}if(I.downArrow){Ye(k=>Math.min(kt.length-1,k+1));return}if(I.return){let k=kt[on];k&&x&&x(k.value);return}Ke(false);}if(I.return){let k=C.trim();if(R.required&&!k){ke(true);return}if(pt!==null){ke(true),ht(true),gt.current&&clearTimeout(gt.current),gt.current=setTimeout(()=>ht(false),2e3);return}Ft(k);return}if(I.downArrow&&R.suggestions&&kt.length>0){Ke(true),Ye(0);return}if(I.ctrl&&A==="a"){G(0);return}if(I.ctrl&&A==="e"){G(C.length);return}if(I.ctrl&&A==="k"){ke(true),W(k=>k.slice(0,H));return}if(I.ctrl&&A==="u"){ke(true),W(k=>k.slice(H)),G(0);return}if(I.ctrl&&A==="w"){ke(true);let k=No(C,H);W(_=>_.slice(0,k)+_.slice(H)),G(k);return}if(I.meta&&(I.leftArrow||A==="b")){G(No(C,H));return}if(I.meta&&(I.rightArrow||A==="f")){G(Zs(C,H));return}if(I.leftArrow){G(k=>Math.max(0,k-1));return}if(I.rightArrow){G(k=>Math.min(C.length,k+1));return}if(I.backspace||I.delete){if(H===0&&C.length===0&&y>0){rn();return}H>0&&(W(k=>k.slice(0,H-1)+k.slice(H)),G(k=>k-1));return}A&&!I.ctrl&&!I.meta&&!I.escape&&(ke(true),Ke(false),Ye(0),W(k=>k.slice(0,H)+A+k.slice(H)),G(k=>k+A.length));return}if(R.type==="textarea"){if(I.return&&(I.ctrl||I.meta)){let k=L.join(`
|
|
10
|
+
`).trim();if(R.required&&!k){ke(true);return}if(pt!==null){ke(true),ht(true),gt.current&&clearTimeout(gt.current),gt.current=setTimeout(()=>ht(false),2e3);return}Ft(k);return}if(I.return){ke(true),j(k=>{let _=k[O]??"",Y=_.slice(0,N),q=_.slice(N),Ce=[...k];return Ce.splice(O,1,Y,q),Ce}),P(k=>k+1),E(0);return}if(I.ctrl&&A==="a"){E(0);return}if(I.ctrl&&A==="e"){E((L[O]??"").length);return}if(I.ctrl&&A==="k"){ke(true),j(k=>{let _=[...k];return _[O]=(_[O]??"").slice(0,N),_});return}if(I.ctrl&&A==="u"){ke(true),j(k=>{let _=[...k];return _[O]=(_[O]??"").slice(N),_}),E(0);return}if(I.ctrl&&A==="w"){ke(true);let k=O,_=N;j(Y=>{let q=Y[k]??"",Ce=No(q,_),K=[...Y];return K[k]=q.slice(0,Ce)+q.slice(_),E(Ce),K});return}if(I.meta&&(I.leftArrow||A==="b")){E(No(L[O]??"",N));return}if(I.meta&&(I.rightArrow||A==="f")){E(Zs(L[O]??"",N));return}if(I.upArrow){if(qe>0){let k=Re[qe],_=Re[qe-1],Y=N-(k?.startCol??0),q=Math.min(_.startCol+Y,_.startCol+_.text.length);P(_.logicalRow),E(q);}return}if(I.downArrow){if(qe<Re.length-1){let k=Re[qe],_=Re[qe+1],Y=N-(k?.startCol??0),q=Math.min(_.startCol+Y,_.startCol+_.text.length);P(_.logicalRow),E(q);}return}if(I.leftArrow){N>0?E(k=>k-1):O>0&&(P(k=>k-1),E((L[O-1]??"").length));return}if(I.rightArrow){let k=(L[O]??"").length;N<k?E(_=>_+1):O<L.length-1&&(P(_=>_+1),E(0));return}if(I.backspace||I.delete){if(N===0&&O===0)return;if(N>0)j(k=>{let _=[...k],Y=_[O]??"";return _[O]=Y.slice(0,N-1)+Y.slice(N),_}),E(k=>k-1);else {let k=(L[O-1]??"").length;j(_=>{let Y=[..._],q=Y[O-1]??"",Ce=Y[O]??"";return Y.splice(O-1,2,q+Ce),Y}),E(k),P(_=>_-1);}return}if(A&&!I.ctrl&&!I.meta&&!I.escape){ke(true);let k=A.split(/\r?\n/);if(k.length===1)j(_=>{let Y=[..._],q=Y[O]??"";return Y[O]=q.slice(0,N)+A+q.slice(N),Y}),E(_=>_+A.length);else {let _=O,Y=N;j(q=>{let Ce=[...q],K=Ce[_]??"",pe=K.slice(0,Y),le=K.slice(Y),Xt=k[0]??"",qt=k[k.length-1]??"",Gn=[pe+Xt,...k.slice(1,-1),qt+le];return Ce.splice(_,1,...Gn),Ce}),P(_+k.length-1),E((k[k.length-1]??"").length);}}return}if(R.type==="select"||R.type==="multiselect"){if(I.upArrow||A==="k"){V(k=>Math.max(0,k-1));return}if(I.downArrow||A==="j"){V(k=>Math.min(St.length-1,k+1));return}if(I.backspace||I.delete){rn();return}if(R.type==="select"){if(I.return||I.tab){let k=St[Ut];if(k){if(R.validate){let _=R.validate(k.value);if(_!==null){ke(true),Rt(_),ht(true),gt.current&&clearTimeout(gt.current),gt.current=setTimeout(()=>ht(false),2e3);return}}Ft(k.value);}return}if(A>="1"&&A<="9"){let k=parseInt(A,10)-1;if(k<St.length){let _=St[k];_&&Ft(_.value);}return}}else {if(A===" "){let k=St[Ut];k&&ft(_=>{let Y=new Set(_);return Y.has(k.value)?Y.delete(k.value):Y.add(k.value),Y});return}if(I.return){let k=Array.from(dt).join(",");Ft(k);return}}}}}),!R)return null;let Ee=nn?pt:null,xn=Math.max(20,l-6),nr=`${y+1}/${ae}`,bn=Math.max(2,f-4),Wt=0;Ut>=bn&&(Wt=Ut-bn+1);let uo=St.slice(Wt,Wt+bn);return jsxs(Box,{flexDirection:"column",paddingX:2,children:[jsxs(Box,{children:[jsx(Text,{color:e.amber,bold:true,children:t}),jsxs(Text,{color:e.ghost,children:[" ",Ve,Ve," "]}),jsxs(Text,{color:e.dim,children:["step ",nr]})]}),jsxs(Box,{children:[jsx(Text,{children:" "}),X.map((A,I)=>jsxs(Text,{color:I===y?e.amber:I<y?e.green:e.ghost,children:[I===y?"\u25CF":I<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"?`${$r}+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:Ee?"round":void 0,borderColor:Ee?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,H)}),jsx(Text,{color:e.amber,children:Po}),jsx(Text,{color:e.white,children:C.slice(H)})]}):R.placeholder?jsxs(Fragment,{children:[jsx(Text,{color:e.ghost,children:R.placeholder}),jsx(Text,{color:e.amber,children:Po})]}):jsx(Text,{color:e.amber,children:Po})]}),Ee&&jsxs(Text,{color:e.red,dimColor:true,children:[" ",Ee]}),jt&&jsx(Text,{color:e.red,children:" Fix the error above"})]}),R.type==="text"&&R.suggestions&&kt.length>0&&(()=>{let A=Math.max(2,f-6),I=0;Ne&&on>=A&&(I=on-A+1);let k=kt.slice(I,I+A);return jsxs(Box,{flexDirection:"column",children:[jsxs(Text,{color:e.ghost,children:[" ",Ve,Ve,Ve," or browse templates ",Ve.repeat(Math.max(0,xn-28))]}),k.map((_,Y)=>{let q=Y+I,Ce=Ne&&q===on;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:_.label}),_.hint&&jsxs(Text,{color:e.dim,wrap:"truncate",children:[" ",Ve," ",_.hint.replace(/\n/g," ")]})]},_.value)})]})})(),R.type==="textarea"&&(()=>{let A=Math.max(3,f-6),I=0;qe>=A&&(I=qe-A+1);let k=Re.slice(I,I+A);return jsxs(Box,{flexDirection:"column",children:[jsxs(Box,{flexDirection:"column",borderStyle:Ee?"round":void 0,borderColor:Ee?e.red:void 0,children:[k.map((_,Y)=>{let q=Y+I,Ce=_.isFirst?String(_.logicalRow+1).padStart(Dt," "):"".padStart(Dt," "),K=q===qe,pe=N-_.startCol;return jsxs(Box,{children:[jsxs(Text,{color:e.dim,children:[" ",Ce," "]}),jsxs(Text,{color:e.ghost,children:["\u2502"," "]}),K?jsxs(Fragment,{children:[jsx(Text,{color:e.white,children:_.text.slice(0,pe)}),jsx(Text,{color:e.amber,children:Po}),jsx(Text,{color:e.white,children:_.text.slice(pe)})]}):jsx(Text,{color:e.silver,children:_.text||(_.isFirst?" ":"")})]},`${_.logicalRow}-${_.startCol}`)}),L.length===1&&L[0]===""&&R.placeholder&&jsx(Box,{children:jsxs(Text,{color:e.dim,children:[" ","".padStart(Dt," ")," ",R.placeholder]})})]}),Ee&&jsxs(Text,{color:e.red,dimColor:true,children:[" ",Ee]}),jt&&jsx(Text,{color:e.red,children:" Fix the error above"})]})})(),R.type==="select"&&jsxs(Box,{flexDirection:"column",children:[uo.map((A,I)=>{let k=I+Wt,_=k===Ut,Y=String(k+1).padStart(St.length>=10?2:1);return jsxs(Box,{children:[jsx(Text,{color:_?e.amber:e.ghost,children:_?" \u25B8 ":` ${Y} `}),jsx(Text,{color:_?e.white:e.silver,bold:_,children:A.label}),A.hint&&jsxs(Text,{color:e.dim,wrap:"truncate",children:[" ",Ve," ",A.hint.replace(/\n/g," ")]})]},A.value)}),Ee&&jsxs(Text,{color:e.red,dimColor:true,children:[" ",Ee]}),jt&&jsx(Text,{color:e.red,children:" Fix the error above"})]}),R.type==="multiselect"&&jsxs(Box,{flexDirection:"column",children:[uo.map((A,I)=>{let _=I+Wt===Ut,Y=dt.has(A.value);return jsxs(Box,{children:[jsx(Text,{color:_?e.amber:e.ghost,children:_?" \u25B8 ":" "}),jsx(Text,{color:Y?e.green:e.dim,children:Y?"[\u2713]":"[ ]"}),jsxs(Text,{color:_?e.white:e.silver,bold:_,children:[" ",A.label]}),A.hint&&jsxs(Text,{color:e.dim,wrap:"truncate",children:[" ",Ve," ",A.hint.replace(/\n/g," ")]})]},A.value)}),dt.size>0&&jsx(Box,{children:jsxs(Text,{color:e.dim,children:[" ","\u2514"," ",dt.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 ${$r}+Enter confirm \u2190\u2191\u2192\u2193 navigate`:Ne?"\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")?` ${$r}+V paste image`:""," Esc ",y>0?"back":"cancel"]}),T&&jsxs(Text,{color:e.amber,children:[" ",T]})]})]})}var ti=so.memo(function({agents:n,selected:o,msgCounts:r,colorMap:l,maxHeight:f,onConfirm:b,onCancel:T}){let [x,y]=useState(0),[S,M]=useState(()=>new Set(o));useMemo(()=>S.size===0||S.size===n.length,[S.size,n.length]);let C=Math.max(3,f-5),W=useMemo(()=>{if(n.length<=C)return 0;let L=Math.floor(C/2),j=n.length-C;return Math.min(j,Math.max(0,x-L))},[x,n.length,C]),H=n.slice(W,W+C);useInput((L,j)=>{if(j.upArrow){y(O=>O>0?O-1:n.length-1);return}if(j.downArrow){y(O=>O<n.length-1?O+1:0);return}if(L===" "){let O=n[x];if(!O)return;M(P=>{let N=new Set(P);return N.has(O.id)?N.delete(O.id):N.add(O.id),N});return}if(L==="a"||L==="A"){M(O=>new Set);return}if(j.return){b(new Set(S));return}if(j.escape){T();return}});let G=S.size===0?n.length:S.size;return jsxs(Box,{flexDirection:"column",borderStyle:"round",borderColor:e.amber,paddingX:1,children:[jsxs(Box,{gap:1,children:[jsx(Text,{color:e.amber,bold:true,children:" \u25C8 Agent Filter"}),jsxs(Text,{color:e.dim,children:[ue," ",G,"/",n.length," selected"]})]}),jsx(Text,{color:e.ghost,children:Ve.repeat(36)}),H.map((L,j)=>{let P=j+W===x,N=S.size===0||S.has(L.id),E=l.get(L.id)??e.silver,z=r.get(L.id)??0;return jsxs(Box,{gap:0,children:[jsx(Text,{color:P?e.amber:e.ghost,children:P?" \u25B8 ":" "}),jsx(Text,{color:N?e.green:e.ghost,children:N?"[\u2713]":"[ ]"}),jsxs(Text,{color:P?E:N?e.silver:e.dim,bold:P,children:[" ",L.name]}),z>0&&jsxs(Text,{color:e.dim,children:[" ",ue,z]})]},L.id)}),n.length>C&&jsxs(Text,{color:e.ghost,children:[" ",W>0?"\u2191":" "," ",W+C<n.length?"\u2193":" "," ",x+1,"/",n.length]}),jsx(Text,{color:e.ghost,children:Ve.repeat(36)}),jsxs(Text,{color:e.dim,children:[" Space toggle"," ",ue," ","a all"," ",ue," ","Enter confirm"," ",ue," ","Esc cancel"]})]})});var Kl={system:"\u2666",lifecycle:"\u25B6",output:"\u2502",tool:"\u2699",result:"\u2190",error:"\u2715",file:"\u270E",info:"\u2502"},Yl={system:"System",lifecycle:"Lifecycle",output:"Output",tool:"Tool calls",result:"Results",error:"Errors",file:"Files",info:"Info"},Zl={system:e.purple,lifecycle:e.cyan,output:e.white,tool:e.blue,result:e.green,error:e.red,file:e.purple,info:e.silver},yt=["system","lifecycle","output","tool","result","error","file","info"],ri=[{key:"1",label:"all",types:yt},{key:"2",label:"text",types:["output"]},{key:"3",label:"tools",types:["tool","result","file"]},{key:"4",label:"errors",types:["error"]},{key:"5",label:"events",types:["lifecycle","system"]}],si=so.memo(function({selected:n,typeCounts:o,onConfirm:r,onCancel:l}){let[f,b]=useState(0),[T,x]=useState(()=>new Set(n)),y=useMemo(()=>T.size===yt.length||yt.every(M=>T.has(M)),[T]);useInput((M,B)=>{if(B.upArrow){b(C=>C>0?C-1:yt.length-1);return}if(B.downArrow){b(C=>C<yt.length-1?C+1:0);return}if(M===" "){let C=yt[f];if(!C)return;x(W=>{let H=new Set(W);return H.has(C)?H.delete(C):H.add(C),H});return}if(M==="a"||M==="A"){x(C=>C.size===yt.length?new Set:new Set(yt));return}for(let C of ri)if(M===C.key){x(new Set(C.types));return}if(B.return){let C=T.size===0?new Set(yt):new Set(T);r(C);return}if(B.escape){l();return}});let S=y?yt.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," ",S,"/",yt.length," selected"]})]}),jsx(Text,{color:e.ghost,children:Ve.repeat(36)}),yt.map((M,B)=>{let C=B===f,W=T.has(M),H=o[M]??0,G=Zl[M];return jsxs(Box,{gap:0,children:[jsx(Text,{color:C?e.amber:e.ghost,children:C?" \u25B8 ":" "}),jsx(Text,{color:W?e.green:e.ghost,children:W?"[\u2713]":"[ ]"}),jsxs(Text,{color:C?G:e.dim,children:[" ",Kl[M]," "]}),jsx(Text,{color:C?G:W?e.silver:e.dim,bold:C,children:Yl[M]}),H>0&&jsxs(Text,{color:e.dim,children:[" ",ue,H]})]},M)}),jsx(Text,{color:e.ghost,children:Ve.repeat(36)}),jsxs(Box,{gap:0,children:[jsx(Text,{color:e.dim,children:" "}),ri.map((M,B)=>jsxs(so.Fragment,{children:[B>0&&jsxs(Text,{color:e.ghost,children:[" ",ue," "]}),jsx(Text,{color:e.amberDim,children:M.key}),jsxs(Text,{color:e.dim,children:["=",M.label]})]},M.key))]}),jsxs(Text,{color:e.dim,children:[" Space toggle"," ",ue," ","a all"," ",ue," ","Enter confirm"," ",ue," ","Esc cancel"]})]})});var Wo="\u256D",Go="\u256E",zo="\u2570",Vo="\u256F",Ie="\u2502";function tn({children:t,cw:n}){return jsxs(Text,{children:[jsx(Text,{color:e.ghost,children:Ie}),jsxs(Text,{children:[" ",t.padEnd(n)," "]}),jsx(Text,{color:e.ghost,children:Ie})]})}function Fo({cw:t}){return jsx(tn,{cw:t,children:""})}function ii({width:t,height:n}){let o=Math.min(t-4,50),r=o-6,l=Te(o-2);return jsxs(Box,{flexDirection:"column",paddingX:2,marginTop:1,children:[jsxs(Text,{color:e.ghost,children:[Wo,l,Go]}),jsx(tn,{cw:r,children:""}),jsxs(Text,{children:[jsxs(Text,{color:e.ghost,children:[Ie," "]}),jsx(Text,{color:e.amber,children:zt}),jsx(Text,{color:e.white,bold:true,children:" Welcome to Orch"}),jsx(Text,{children:" ".repeat(Math.max(0,r-15-2))}),jsx(Text,{children:" "}),jsx(Text,{color:e.ghost,children:Ie})]}),jsx(tn,{cw:r,children:""}),jsxs(Text,{children:[jsxs(Text,{color:e.ghost,children:[Ie," "]}),jsx(Text,{color:e.silver,children:"Press N to create your first task".padEnd(r)}),jsx(Text,{children:" "}),jsx(Text,{color:e.ghost,children:Ie})]}),jsx(tn,{cw:r,children:""}),jsxs(Text,{children:[jsxs(Text,{color:e.ghost,children:[Ie," "]}),jsx(Text,{color:e.amber,children:"N"}),jsx(Text,{color:e.gray,children:" new task"}),jsx(Text,{children:" ".repeat(Math.max(0,r-1-1-8))}),jsx(Text,{children:" "}),jsx(Text,{color:e.ghost,children:Ie})]}),jsx(tn,{cw:r,children:""}),jsxs(Text,{color:e.ghost,children:[zo,l,Vo]})]})}function ai({step:t,width:n}){let o=Math.min(n-4,50),r=o-6,l=Te(o-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:[Wo,l,Go]}),jsxs(Text,{children:[jsxs(Text,{color:e.ghost,children:[Ie," "]}),jsx(Text,{color:e.amber,children:zt}),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:[zo,l,Vo]})]})}function li({width:t}){let n=Math.min(t-4,50),o=n-6,r=Te(n-2);return jsxs(Box,{flexDirection:"column",paddingX:2,marginTop:1,children:[jsxs(Text,{color:e.ghost,children:[Wo,r,Go]}),jsx(tn,{cw:o,children:""}),jsxs(Text,{children:[jsxs(Text,{color:e.ghost,children:[Ie," "]}),jsx(Text,{color:e.green,bold:true,children:"First task completed!"}),jsx(Text,{children:" ".repeat(Math.max(0,o-21))}),jsx(Text,{children:" "}),jsx(Text,{color:e.ghost,children:Ie})]}),jsx(tn,{cw:o,children:""}),jsxs(Text,{children:[jsxs(Text,{color:e.ghost,children:[Ie," "]}),jsx(Text,{color:e.silver,children:"Type / to see all commands".padEnd(o)}),jsx(Text,{children:" "}),jsx(Text,{color:e.ghost,children:Ie})]}),jsx(tn,{cw:o,children:""}),jsxs(Text,{color:e.ghost,children:[zo,r,Vo]})]})}function Ho({count:t,config:n,width:o}){if(t>=3)return null;let r=Math.min((o??44)-4,50),l=r-6,f=Te(r-2),b=jsxs(Text,{color:e.ghost,children:[Wo,f,Go]}),T=jsxs(Text,{color:e.ghost,children:[zo,f,Vo]});if(t>0){let y=n.hints[0],S=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:zt}),jsxs(Text,{color:e.silver,children:[" ",n.nudge.padEnd(l-2-S.length)]}),y&&jsxs(Fragment,{children:[jsxs(Text,{color:e.amber,children:[" ",y.key]}),jsxs(Text,{color:e.gray,children:[" ",y.label]})]}),jsx(Text,{children:" "}),jsx(Text,{color:e.ghost,children:Ie})]}),T]})}let x=n.hints.reduce((y,S,M)=>y+S.key.length+1+S.label.length+(M>0?3:0),0);return jsxs(Box,{flexDirection:"column",paddingX:2,marginTop:1,children:[b,jsx(Fo,{cw:l}),jsxs(Text,{children:[jsxs(Text,{color:e.ghost,children:[Ie," "]}),jsx(Text,{color:e.amber,children:zt}),jsxs(Text,{color:e.white,bold:true,children:[" ",n.title]}),jsx(Text,{children:" ".repeat(Math.max(0,l-n.title.length-2))}),jsx(Text,{children:" "}),jsx(Text,{color:e.ghost,children:Ie})]}),jsx(Fo,{cw:l}),n.description.map((y,S)=>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})]},S)),jsx(Fo,{cw:l}),jsxs(Text,{children:[jsxs(Text,{color:e.ghost,children:[Ie," "]}),n.hints.map((y,S)=>jsxs(so.Fragment,{children:[S>0&&jsx(Text,{color:e.ghost,children:" "}),jsx(Text,{color:e.amber,children:y.key}),jsxs(Text,{color:e.gray,children:[" ",y.label]})]},S)),jsx(Text,{children:" ".repeat(Math.max(0,l-x))}),jsx(Text,{children:" "}),jsx(Text,{color:e.ghost,children:Ie})]}),jsx(Fo,{cw:l}),T]})}var Ql=2,gi=360,ec={done:4e3,failed:8e3,review:6e3},tc={done:"\u2713",failed:"\u2715",review:Zt},nc={done:e.green,failed:e.red,review:e.blue},oc={done:e.successBg,failed:e.errorBg,review:e.infoBg};function rc(t){let n=t.agentName??"Agent";switch(t.type){case "done":return `Task completed by ${n}`;case "failed":return "Task failed \u2014 press Enter for details";case "review":return "Task ready for review \u2014 press A to approve"}}var sc=so.memo(function({toast:n,onDismiss:o}){let[r,l]=useState(true),[f,b]=useState(false);useEffect(()=>{let C=setTimeout(()=>l(false),gi);return ()=>clearTimeout(C)},[]),useEffect(()=>{let C=ec[n.type],W=setTimeout(()=>b(true),C),H=setTimeout(()=>o(n.id),C+gi);return ()=>{clearTimeout(W),clearTimeout(H);}},[n.id,n.type,o]);let T=r||f,x=tc[n.type],y=nc[n.type],S=oc[n.type],M=rc(n),B=n.title.length>40?n.title.slice(0,39)+"\u2026":n.title;return jsx(Box,{children:jsxs(Text,{backgroundColor:S,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:[" ",M," "]})]})})}),pi=so.memo(function({toasts:n,onDismiss:o}){let r=n.slice(0,Ql);return r.length===0?null:jsx(Box,{flexDirection:"column",children:r.map(l=>jsx(sc,{toast:l,onDismiss:o},l.id))})});var lc="\u256D",cc="\u256E",dc="\u2570",uc="\u256F",at="\u2502",Or=[{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"}],Pr=[{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"}],Nr=[{key:"/",label:"Command mode"},{key:"/task add",label:"Create task"},{key:"/run",label:"Execute"},{key:"/watch",label:"Auto-dispatch"},{key:"/config",label:"Settings"},{key:"/help",label:"Help"},{key:"/quit",label:"Exit"}],Dn=10,Ht=22;function Dr(t){let n=Math.max(0,Math.floor((Ht-t.length-2)/2)),o=Math.max(0,Ht-n-t.length-2);return Te(n)+" "+t+" "+Te(o)}var hi=so.memo(function({width:n,height:o}){let r=Ht*3+3+3+2,l=r+2,f=Te(l-2),b="KEYBOARD SHORTCUTS",T=Math.max(0,Math.floor((r-b.length)/2)),x=Math.max(0,r-T-b.length),y="Press any key to dismiss",S=Math.max(0,Math.floor((r-y.length)/2)),M=Math.max(0,r-S-y.length),B=Math.max(Or.length,Pr.length,Nr.length),C=B+10,W=Math.max(0,Math.floor((o-C)/2)),H=[];for(let P=0;P<B;P++){let N=P<Or.length?Or[P]:null,E=P<Pr.length?Pr[P]:null,z=P<Nr.length?Nr[P]:null;H.push(jsxs(Text,{children:[jsx(Text,{color:e.amber,children:at}),jsx(Text,{children:" "}),N?jsxs(Fragment,{children:[jsx(Text,{color:e.amber,bold:true,children:N.key.padEnd(Dn)}),jsx(Text,{color:e.silver,children:N.label.padEnd(Ht-Dn)})]}):jsx(Text,{children:" ".repeat(Ht)}),jsxs(Text,{color:e.dim,children:[" ",at," "]}),E?jsxs(Fragment,{children:[jsx(Text,{color:e.amber,bold:true,children:E.key.padEnd(Dn)}),jsx(Text,{color:e.silver,children:E.label.padEnd(Ht-Dn)})]}):jsx(Text,{children:" ".repeat(Ht)}),jsxs(Text,{color:e.dim,children:[" ",at," "]}),z?jsxs(Fragment,{children:[jsx(Text,{color:e.amber,bold:true,children:z.key.padEnd(Dn)}),jsx(Text,{color:e.silver,children:z.label.padEnd(Ht-Dn)})]}):jsx(Text,{children:" ".repeat(Ht)}),jsx(Text,{children:" "}),jsx(Text,{color:e.amber,children:at})]},`r${P}`));}let G=P=>jsxs(Text,{children:[jsx(Text,{color:e.amber,children:at}),jsx(Text,{children:" ".repeat(r)}),jsx(Text,{color:e.amber,children:at})]},P),L=Dr("NAVIGATION"),j=Dr("ACTIONS"),O=Dr("COMMANDS");return jsxs(Box,{flexDirection:"column",paddingX:Math.max(0,Math.floor((n-l)/2)),marginTop:W,children:[jsxs(Text,{color:e.amber,children:[lc,f,cc]}),G("e1"),jsxs(Text,{children:[jsx(Text,{color:e.amber,children:at}),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:at})]}),G("e2"),jsxs(Text,{children:[jsx(Text,{color:e.amber,children:at}),jsx(Text,{children:" "}),jsx(Text,{color:e.dim,children:L}),jsxs(Text,{color:e.dim,children:[" ",at," "]}),jsx(Text,{color:e.dim,children:j}),jsxs(Text,{color:e.dim,children:[" ",at," "]}),jsx(Text,{color:e.dim,children:O}),jsx(Text,{children:" "}),jsx(Text,{color:e.amber,children:at})]}),G("e3"),H,G("e4"),jsxs(Text,{children:[jsx(Text,{color:e.amber,children:at}),jsx(Text,{children:" ".repeat(S)}),jsx(Text,{color:e.dim,children:y}),jsx(Text,{children:" ".repeat(M)}),jsx(Text,{color:e.amber,children:at})]}),G("e5"),jsxs(Text,{color:e.amber,children:[dc,f,uc]})]})});var Ti=[{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"}],yi=[{value:"gpt-5.3-codex",label:"GPT-5.3 Codex",hint:"default, balanced"},{value:"gpt-5.4",label:"GPT-5.4",hint:"latest"},{value:"gpt-5",label:"GPT-5",hint:"capable"},{value:"gpt-5.3-codex-spark",label:"GPT-5.3 Codex Spark",hint:"fast"},{value:"o3",label:"o3",hint:"reasoning"},{value:"o4-mini",label:"o4-mini",hint:"fast reasoning"},{value:"gpt-5-mini",label:"GPT-5 Mini",hint:"light"},{value:"gpt-5-nano",label:"GPT-5 Nano",hint:"cheapest"},{value:"codex-mini-latest",label:"Codex Mini",hint:"legacy"}],wi=[{value:"auto",label:"Auto",hint:"let Cursor decide"},{value:"composer-1.5",label:"Composer 1.5",hint:"latest agent"},{value:"composer-1",label:"Composer 1",hint:"stable agent"},{value:"gpt-5.3-codex",label:"GPT-5.3 Codex",hint:"OpenAI"},{value:"claude-sonnet-4-6",label:"Claude Sonnet 4.6",hint:"Anthropic"}],Si=[{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"}],ki=[{value:"",label:"Default",hint:"use shell adapter default"}],gc=[{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"}],Ci=[{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"}],xi=60;function Ii(t){return t.filter(n=>n.status!=="disabled").map(n=>{let o=(n.role??"").split(`
|
|
11
|
+
`)[0].trim(),r=o.length>xi?o.slice(0,xi-1)+"\u2026":o,l=r?`[${n.adapter}] ${r}`:n.adapter;return {value:n.id,label:n.name,hint:l}})}function Xo(t,n="Auto-assign",o="orchestrator picks the best agent"){return [{value:"",label:n,hint:o},...Ii(t)]}var Wr=[{value:"",label:"Skip",hint:"no role description"},{value:"Full-stack developer",label:"Full-stack developer",hint:"general purpose"},{value:"Frontend developer",label:"Frontend developer",hint:"React, CSS, UI"},{value:"Backend developer",label:"Backend developer",hint:"APIs, databases, services"},{value:"DevOps engineer",label:"DevOps engineer",hint:"CI/CD, infra, deploys"},{value:"QA / Test engineer",label:"QA / Test engineer",hint:"testing, quality"},{value:"Code reviewer",label:"Code reviewer",hint:"review PRs, find bugs"},{value:"Technical writer",label:"Technical writer",hint:"docs, READMEs"},{value:"__custom__",label:"Custom...",hint:"type your own"}];function Mi(t){return [{value:"",label:"None",hint:"no team"},...(t??[]).filter(n=>n.status==="active").map(n=>({value:n.id,label:n.name,hint:`${n.members.length} members`}))]}function vi(){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 Gr(t,n){return t.map(o=>{switch(o.id){case "name":return {...o,defaultValue:n.name};case "adapter":return {...o,defaultValue:n.adapter};case "model":return {...o,defaultValue:n.model};case "role":return {...o,defaultValue:"__custom__"};case "role_custom":return {...o,defaultValue:n.role,skip:void 0};case "skills":return {...o,defaultValue:n.skills.join(", ")};case "approval_policy":return {...o,defaultValue:n.approval_policy};default:return o}})}function qo(t,n){let o=Mi(n);return [{id:"name",label:"Agent name",type:"text",placeholder:"e.g. alpha, frontend-bot, reviewer",required:true,validate:r=>r.trim()?t?.some(l=>l.name===r.trim())?"Agent with this name already exists":null:"Name is required",suggestions:a$2.map(r=>({value:r.key,label:r.name,hint:r.description}))},{id:"adapter",label:"Provider",type:"select",options:gc},{id:"model",label:"Model",type:"select",getOptions:r=>r.adapter==="opencode"?Si:r.adapter==="codex"?yi:r.adapter==="cursor"?wi:r.adapter==="shell"?ki:Ti},{id:"role",label:"Role / specialization",type:"select",options:Wr},{id:"role_custom",label:"Describe the role",type:"textarea",placeholder:"e.g. Specialist in React and TypeScript",skip:r=>r.role!=="__custom__"},{id:"skills",label:"Skills (comma-separated)",type:"text",placeholder:"e.g. feature-dev:feature-dev, testing-suite:generate-tests"},{id:"approval_policy",label:"Approval policy",type:"text",skip:()=>true},{id:"team",label:"Join team",type:"select",options:o,skip:()=>o.length<=1}]}function _i(t){let n=t.role==="__custom__"?t.role_custom||void 0:t.role||void 0,o=t.skills?t.skills.split(",").map(l=>l.trim()).filter(Boolean):void 0,r=t.approval_policy||"auto";return {name:t.name,adapter:t.adapter||"claude",role:n,model:t.model||void 0,approval_policy:r,skills:o,team_id:t.team||void 0}}function Ri(t,n){let o=Ii(t);return [{id:"name",label:"Team name",type:"text",placeholder:"e.g. frontend, backend, qa",required:true,validate:r=>r.trim()?n?.some(l=>l.name===r.trim())?"Team with this name already exists":null:"Name is required"},{id:"lead",label:"Team lead",type:"select",options:o},{id:"members",label:"Team members",type:"multiselect",getOptions:r=>o.filter(l=>l.value!==r.lead),skip:r=>!o.some(l=>l.value!==r.lead)},{id:"description",label:"Description",type:"textarea",placeholder:"Optional team purpose..."}]}function Ai(t){let n=t.members?t.members.split(",").filter(Boolean):[];return {name:t.name,lead_agent_id:t.lead,member_agent_ids:n.length>0?n:void 0,description:t.description||void 0}}function $i(t){let n=Xo(t);return [{id:"title",label:"Task title",type:"text",placeholder:"What needs to be done?",required:true,validate:o=>o.trim()?null:"Title is required"},{id:"priority",label:"Priority",type:"select",options:Ci,defaultValue:"3",validate:o=>{let r=Number(o);return !Number.isInteger(r)||r<1||r>4?"Priority must be 1-4":null}},{id:"assignee",label:"Assignee",type:"select",options:n,skip:()=>n.length<=1},{id:"description",label:"Description",type:"textarea",placeholder:"Optional details, context, acceptance criteria..."}]}function Bi(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 Ei(t,n){let o=Xo(n,"None / Auto","remove assignee");return [{id:"title",label:"Task title",type:"text",defaultValue:t.title,required:true,validate:r=>r.trim()?null:"Title is required"},{id:"priority",label:"Priority",type:"select",options:Ci,defaultValue:String(t.priority),validate:r=>{let l=Number(r);return !Number.isInteger(l)||l<1||l>4?"Priority must be 1-4":null}},{id:"assignee",label:"Assignee",type:"select",options:o,defaultValue:t.assignee??"",skip:()=>o.length<=1},{id:"description",label:"Description",type:"textarea",defaultValue:t.description||"",placeholder:"Optional details..."}]}function Li(t){return {title:t.title,priority:t.priority?parseInt(t.priority,10):void 0,assignee:t.assignee||void 0,description:t.description??""}}function Oi(t,n,o){let r=Wr.find(x=>x.value===t.role),l=r?t.role:t.role?"__custom__":"",f=t.adapter==="opencode"?Si:t.adapter==="codex"?yi:t.adapter==="cursor"?wi:t.adapter==="shell"?ki:Ti,b=Mi(o),T=o?.find(x=>x.members.some(y=>y.agent_id===t.id))?.id;return [{id:"name",label:"Agent name",type:"text",defaultValue:t.name,required:true,validate:x=>x.trim()?n?.some(y=>y.id!==t.id&&y.name===x.trim())?"Agent with this name already exists":null:"Name is required"},{id:"model",label:"Model",type:"select",options:f,defaultValue:t.config.model??""},{id:"role",label:"Role / specialization",type:"select",options:Wr,defaultValue:l},{id:"role_custom",label:"Describe the role",type:"textarea",defaultValue:t.role&&!r?t.role:"",placeholder:"e.g. Specialist in React and TypeScript",skip:x=>x.role!=="__custom__"},{id:"team",label:"Team",type:"select",options:b,defaultValue:T??"",skip:()=>b.length<=1}]}var mc=[{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"}],fc=[{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"}],bi=[{value:"true",label:"On"},{value:"false",label:"Off"}];function Pi(t,n,o){let r=o??{toast:true,bell:false};return [{id:"activity_filter",label:"Activity filter preset",type:"select",options:fc,defaultValue:t},{id:"max_concurrent",label:"Max concurrent agents",type:"select",options:mc,defaultValue:String(n)},{id:"notifications_toast",label:"Toast notifications",type:"select",options:bi,defaultValue:String(r.toast)},{id:"notifications_bell",label:"Bell on completion",type:"select",options:bi,defaultValue:String(r.bell)}]}function Ni(t){let n=t.role==="__custom__"?t.role_custom||void 0:t.role||void 0;return {name:t.name,role:n,model:t.model||void 0,team_id:t.team||void 0}}function Ko(t){let n=Xo(t,"Any agent","auto-assign to autonomous agents");return [{id:"title",label:"Goal title",type:"text",placeholder:'e.g. "Implement OAuth2 login with Google and GitHub"',description:"Be specific \u2014 agents work better with clear, measurable objectives",required:true,validate:o=>o.trim()?null:"Title is required"},{id:"assignee",label:"Assignee",type:"select",description:"Assigned agent gets autonomous mode \u2014 it will plan and execute without prompts",options:n,skip:()=>n.length<=1},{id:"description",label:"Description",type:"textarea",placeholder:"Success criteria, constraints, technical context...",description:'Context matters \u2014 include tech stack, constraints, and what "done" looks like'}]}function Di(t){return {title:t.title,assignee:t.assignee||void 0,description:t.description||void 0}}function Fi(t,n){let o=Xo(n,"Any agent","auto-assign");return [{id:"title",label:"Goal title",type:"text",defaultValue:t.title,description:"Be specific \u2014 agents work better with clear, measurable objectives",required:true,validate:r=>r.trim()?null:"Title is required"},{id:"assignee",label:"Assignee",type:"select",description:"Assigned agent gets autonomous mode \u2014 it will plan and execute without prompts",options:o,defaultValue:t.assignee??"",skip:()=>o.length<=1},{id:"description",label:"Description",type:"textarea",defaultValue:t.description||"",placeholder:"Success criteria, constraints, technical context...",description:'Context matters \u2014 include tech stack, constraints, and what "done" looks like'}]}function Wi(t){return {title:t.title,assignee:t.assignee||void 0,description:t.description??""}}var Gi=10,zi=500,er=2048,hn=500,Vi=5,zr=new Set(["todo","failed","cancelled"]),bc={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."},Tc={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."},yc={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."},Hi=5e3,Ui=0;function Qu(){Ui=0;}var Xi=/^\[[\w_]+\]$/;function qi(t){return Xi.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 Hr=["#5faf87","#5fafd7","#af87ff","#d7af00","#5fd7d7","#d787af","#afaf5f","#d7875f"],wc=" ".repeat(9),tr={system:"\u2666",lifecycle:"\u25B6",output:"\u2502",tool:"\u2699",result:"\u2190",error:"\u2715",file:"\u270E",info:"\u2502"},Jo=["system","lifecycle","output","tool","result","error","file","info"],Fn=[{label:"all",types:Jo},{label:"text",types:["output"]},{label:"tools",types:["tool","result","file"]},{label:"errors",types:["error"]},{label:"events",types:["lifecycle","system"]}];function Vr(t){let o=(Fn.findIndex(r=>r.types.length===t.size&&r.types.every(l=>t.has(l)))+1)%Fn.length;return Fn[o]}function eg({projectName:t,tasks:n,agents:o=[],state:r,onRunTask:l,onCreateTask:f,onCancelTask:b$1,onRetryTask:T,onAssignTask:x,onRunAll:y,onDisableAgent:S,onEnableAgent:M,onSubscribeEvents:B,onRefreshTasks:C,onRefreshAgents:W,onRefreshState:H,onLoadHistory:G,onAddAgent:L,onDeleteAgent:j,onApproveTask:O,onRejectTask:P,onDeleteTask:N,onUpdateTask:E,onUpdateAgent:z,onForceStopAgent:V,onCreateTeam:X,onListTeams:R,onJoinTeam:ae,onLeaveTeam:Be,onDisbandTeam:Dt,onSetTeamLead:ct,onStartWatch:Re,onStopWatch:qe,onToggleAutonomous:dt,onRefreshGoals:ft,onCreateGoal:Ne,onUpdateGoal:Ke,onUpdateGoalStatus:ut,onDeleteGoal:Ye,onGetGoalProgress:nn,onCompleteOnboarding:ke,initialWatchActive:pt,watchError:Rt,messageBatchMs:jt=process.env.VITEST?0:80,initialActivityFilter:ht="all",onSaveActivityFilter:Qe,initialMaxConcurrent:gt=a.scheduling.max_concurrent_agents,onSaveMaxConcurrent:Wn,initialNotifications:co,onSaveNotifications:St,version:Ut,latestVersion:kt,onCheckUpdate:on,onBackgroundInstall:Ft}){let{exit:rn}=useApp(),{stdout:Ee}=useStdout(),[xn,nr]=useState(kt),bn=useRef(on);useEffect(()=>{if(kt||!bn.current)return;let i=setTimeout(()=>{bn.current?.().then(p=>{p&&nr(p);}).catch(()=>{});},5e3);return ()=>clearTimeout(i)},[kt]);let[Wt,uo]=useState(false),A=useRef(false);useEffect(()=>{!xn||!Ft||A.current||Wt||(A.current=true,Ft(xn).then(i=>{i&&uo(true);}).catch(()=>{}));},[xn,Ft,Wt]);let[I,k]=useState({w:Ee?.columns??80,h:Ee?.rows??24});useEffect(()=>{if(!Ee)return;let i=()=>k({w:Ee.columns,h:Ee.rows});return Ee.on("resize",i),()=>{Ee.off("resize",i);}},[Ee]);let _=I.w,Y=I.h,[q,Ce]=useState(n),[K,pe]=useState(o),[le,Xt]=useState(r),[qt,Gn]=useState(pt??!!r.pid),[zn,jr]=useState([]),[ea,Ur]=useState(void 0),[Kt,go]=useState(()=>r.onboardingCompleted||(r.stats?.total_tasks_completed??0)>0?"dismissed":Object.keys(r.running??{}).length>0?"run_started":n.length>0?"task_created":"welcome");useEffect(()=>{if(Kt!=="completed")return;let i=setTimeout(()=>{go("dismissed"),ke?.().catch(()=>{});},5e3);return ()=>clearTimeout(i)},[Kt,ke]);let[$,Tn]=useState("tasks"),[mo,Vn]=useState(0),[or,Xr]=useState(0),[rr,qr]=useState(0),[Ae,Hn]=useState(false),[ze,Kr]=useState([]),[De,Le]=useState("none"),[sn,Ct]=useState(""),[xt,Ze]=useState(null),[an,jn]=useState([]),[At,sr]=useState(false),[Yr,ta]=useState(()=>new Set),[yn,ir]=useState(false),[Un,ar]=useState(false),[Zr,Jr]=useState(()=>new Set(Jo)),[Xn,lr]=useState(-1),[na,qn]=useState(0),[wn,cr]=useState(()=>{let i=Fn.find(p=>p.label===ht);return new Set(i?.types??Jo)}),fo=useMemo(()=>Fn.find(p=>p.types.length===wn.size&&p.types.every(s=>wn.has(s)))?.label??"all",[wn]),dr=useMemo(()=>wn.size>=Jo.length?ze:ze.filter(i=>wn.has(i.msgType??"info")),[ze,wn]),[Qr,oa]=useState(gt),[po,ra]=useState(co??{toast:true,bell:false}),[sa,es]=useState([]),ia=useRef(0),[ur,ts]=useState(),ns=useRef($);ns.current=$;let os=useRef(q);os.current=q;let rs=useRef(K);rs.current=K;let ho=useRef(po);ho.current=po;let xo=useCallback((i,p)=>{if(!ho.current.toast)return;let s=os.current.find(h=>h.id===p),d=s?.title??p,u=s?.assignee?rs.current.find(h=>h.id===s.assignee):void 0;es(h=>{let g=[...h,{id:`toast_${ia.current++}`,type:i,title:d,agentName:u?.name,ts:Date.now()}];return g.length>Vi?g.slice(g.length-Vi):g}),ho.current.bell&&(i==="failed"||i==="review")&&process.stdout.write("\x07");},[]),aa=useCallback(i=>{es(p=>p.filter(s=>s.id!==i));},[]),bo=so.useRef(new Oo).current,[la,Sn]=useState(0),[ss,is]=useState(false),[Kn,ca]=useState(false),[da,gr]=useState(0),[ua,mr]=useState(0),[fr,kn]=useState(0),[To,pr]=useState(false),[ga,Yn]=useState(0),[yo,Yt]=useState(0),[Gt,as]=useState([]),[Cn,hr]=useState([]),In=useRef(Gt);In.current=Gt;let Q=useCallback(async i=>{let[p,s,d,u,h]=await Promise.all([C?.()??Promise.resolve(q),W?.()??Promise.resolve(K),H?.()??Promise.resolve(le),i?.includeTeams?R?.()??Promise.resolve(In.current):Promise.resolve(null),ft?.()??Promise.resolve(zn)]);Ce(p),pe(s),Xt(d),u!==null&&as(u),jr(h),pt&&Gn(!!d.pid);},[C,W,H,R,ft,pt]),Mn=useMemo(()=>{let i=new Map;for(let p of zn)i.set(p.id,p);return i},[zn]),Oe=useMemo(()=>{let i=[...q].sort((h,g)=>(no[h.status]??9)-(no[g.status]??9));if(!Kn)return i;let p=[],s=[],d=[],u=new Map;for(let h of i)h.goalId&&Mn.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]},[q,Kn,Mn]),$t=ss?Oe:Oe.slice(0,Gi),vn=Oe.length-$t.length,U=Oe[mo],Zn=useMemo(()=>{let i=new Map;for(let p of q)i.set(p.id,p.title);return i},[q]),ln=useMemo(()=>{let i=new Map;for(let p of K)i.set(p.id,p.name);return i},[K]),ma=useMemo(()=>{let i=new Map;for(let p of q)if(p.goalId){let s=i.get(p.goalId);s||(s=[],i.set(p.goalId,s)),s.push(p);}return i},[q]),wo=useMemo(()=>{let i=new Map;for(let p=0;p<K.length;p++)i.set(K[p].id,Hr[p%Hr.length]);return i},[K]),ls=useMemo(()=>{let i=new Map;for(let p of ze)p.agentId&&i.set(p.agentId,(i.get(p.agentId)??0)+1);return i},[ze]),fa=useMemo(()=>{let i={};for(let p of ze){let s=p.msgType??"info";i[s]=(i[s]??0)+1;}return i},[ze]),{agentTeamMap:_n,activeTeamCount:Jn,teamLeadSet:pa}=useMemo(()=>{let i=new Map,p=new Set,s=0;for(let d of Gt)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}},[Gt]),Fe=useMemo(()=>{let i=[...K];return i.sort((p,s)=>{let d=_n.get(p.id),u=_n.get(s.id);return d&&!u?-1:!d&&u?1:d&&u&&d!==u?d.localeCompare(u):(vr[p.status]??9)-(vr[s.status]??9)}),i},[K,_n]),ee=Fe[or],mt=useMemo(()=>[...zn].sort((i,p)=>(c[i.status]??9)-(c[p.status]??9)),[zn]),oe=mt[rr],ha=useMemo(()=>oe?q.filter(i=>i.goalId===oe.id):[],[oe,q]),xr=useRef(nn);xr.current=nn,useEffect(()=>{if(!oe||!xr.current){Ur(void 0);return}let i=false;return xr.current(oe.id).then(p=>{i||Ur(p);}).catch(()=>{}),()=>{i=true;}},[oe?.id]);let cn=useRef(new Map),So=useRef(new Map);useEffect(()=>{for(let[i,p]of Object.entries(le.running))cn.current.set(p.run_id,p.agent_id),So.current.set(p.run_id,i);if(cn.current.size>zi){let i=cn.current.size-zi,p=0;for(let s of cn.current.keys()){if(p++>=i)break;cn.current.delete(s),So.current.delete(s);}}},[le.running]);let dn=useRef([]),Qn=useRef(null),br=useCallback(()=>{if(Qn.current=null,dn.current.length===0)return;let i=dn.current;dn.current=[],Kr(p=>{if(i.length>=hn)return i.slice(-hn);let s=hn-i.length;return (p.length>s?p.slice(-s):p).concat(i)});},[]);useEffect(()=>()=>{Qn.current&&clearTimeout(Qn.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>er?s.detail.slice(0,er)+"\u2026[truncated]":s?.detail;dn.current.push({text:i,color:p,time:u,ts:d.getTime(),...s,detail:h}),dn.current.length>hn&&(dn.current=dn.current.slice(-hn)),jt===0?br():Qn.current||(Qn.current=setTimeout(br,jt));},[br]);useEffect(()=>{Rt&&a(`Watch mode failed: ${Rt}. Tasks will not auto-dispatch.`,e.red);},[]);let Rn=useCallback((i,p,s,d)=>{let u={key:++Ui,entityType:i,entityId:p,entityName:s,expiresAt:Date.now()+Hi,needsForceStop:d?.needsForceStop};hr(h=>[...h,u]),a(`\u2717 "${s}" will be deleted in ${Math.round(Hi/1e3)}s \u2014 press Z to undo`,e.yellow);},[a]),xa=useCallback(()=>{hr(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]),cs=useCallback(async i=>{try{i.entityType==="task"&&N?await N(i.entityId):i.entityType==="agent"?(i.needsForceStop&&V&&await V(i.entityId),j&&await j(i.entityId)):i.entityType==="goal"&&Ye&&await Ye(i.entityId),a(`\u2713 Deleted "${i.entityName}"`,e.green),Q();}catch(p){a(`Failed to delete "${i.entityName}": ${p instanceof Error?p.message:String(p)}`,e.red);}},[N,j,Ye,V,a,Q]),ds=useRef(cs);ds.current=cs,useEffect(()=>{if(Cn.length===0)return;let i=setInterval(()=>{let p=Date.now(),s=[];hr(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)ds.current(d);},1e3);return ()=>clearInterval(i)},[Cn.length>0]),useEffect(()=>{if(!G)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}=Qi(d);if(!w)return null;u=w;let J=qi(u);g=J.msgType,h=J.color;}return {text:u,color:h,time:s,ts:new Date(p.timestamp).getTime(),agentId:p.agentId,taskId:p.taskId,msgType:g}};G(p=>{if(p.length===0)return;let s=p.map(i).filter(d=>d!==null);Kr(d=>{let u=[...s,...d];return u.length>hn?u.slice(-hn):u});}).catch(p=>{process.stderr.write(`[TUI] onLoadHistory error: ${p instanceof Error?p.stack??p.message:String(p)}
|
|
12
|
+
`);});},[]),useEffect(()=>{R?.().then(as).catch(()=>{}),ft?.().then(jr).catch(()=>{});},[]);let ko=useCallback(()=>{Ze({title:"NEW AGENT",steps:qo(K,In.current),kind:"agent"}),Le("wizard");},[K]),us=useCallback(()=>{Ze({title:"AGENT SHOP",steps:vi(),kind:"agent_shop"}),Le("wizard");},[]),Co=useCallback(()=>{jn([]),Ze({title:"NEW TASK",steps:$i(K),kind:"task"}),Le("wizard");},[K]),ba=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'),J=await u(w(g(),"orch-paste-")),Et=w(J,`clipboard-${Date.now()}.${d.ext}`);return await h(Et,d.data),jn(un=>[...un,Et]),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]),Ta=useCallback(i=>{Ze({title:"EDIT TASK",steps:Ei(i,K),kind:"edit_task",targetId:i.id}),Le("wizard");},[K]),gs=useCallback(()=>{Ze({title:"NEW TEAM",steps:Ri(K,Gt),kind:"team"}),Le("wizard");},[K]),ya=useCallback(i=>{Ze({title:"EDIT AGENT",steps:Oi(i,K,Gt),kind:"edit_agent",targetId:i.id}),Le("wizard");},[Gt]),ms=useCallback(()=>{Ze({title:"SETTINGS",steps:Pi(fo,Qr,po),kind:"config"}),Le("wizard");},[fo,Qr]),wa=useCallback(i=>{Le("none");let p=xt?.kind,s=xt?.targetId;if(Ze(null),p==="agent_shop"){let d=i.shop_template,u=d?b(d):void 0;if(u){let h=qo(K,In.current),g=Gr(h,u);Ze({title:`NEW AGENT \u2014 ${u.name}`,steps:g,kind:"agent_from_shop"}),Le("wizard");}else a("No template selected",e.yellow);return}if((p==="agent"||p==="agent_from_shop")&&L){let d=_i(i);a(`Creating agent "${d.name}"...`,e.amber),L(d.name,d.adapter,{model:d.model,role:d.role,approval_policy:d.approval_policy,skills:d.skills}).then(u=>{a(`\u2713 Created agent "${u.name}" (${u.id}, ${u.adapter})`,e.green),d.team_id&&ae?ae(d.team_id,u.id).then(h=>{a(`\u2713 Joined team "${h.name}"`,e.green),Q({includeTeams:true});},h=>a(`Failed to join team: ${h instanceof Error?h.message:String(h)}`,e.red)):Q();},u=>a(`Failed: ${u instanceof Error?u.message:String(u)}`,e.red));}else if(p==="team"&&X){let d=Ai(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),Q({includeTeams:true});},u=>a(`Failed: ${u instanceof Error?u.message:String(u)}`,e.red));}else if(p==="task"&&f){let d=Bi(i),u=an.length>0?[...an]:void 0;jn([]),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(()=>{}),Q();},h=>a(`Failed: ${h instanceof Error?h.message:String(h)}`,e.red));}else if(p==="edit_task"&&s&&E){let d=Li(i),u=an.length>0?[...an]:void 0;jn([]),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(()=>{}),Q();},h=>a(`Failed: ${h instanceof Error?h.message:String(h)}`,e.red));}else if(p==="edit_agent"&&s&&z){let d=Ni(i),u=d.team_id??"",h=Gt.find(g=>g.members.some(w=>w.agent_id===s))?.id??"";a("Updating agent...",e.amber),z(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(J=>a(`\u2713 Left team "${J.name}"`,e.green),J=>a(`Failed to leave team: ${J instanceof Error?J.message:String(J)}`,e.red))),u&&u!==h&&ae&&w.push(ae(u,s).then(J=>a(`\u2713 Joined team "${J.name}"`,e.green),J=>a(`Failed to join team: ${J instanceof Error?J.message:String(J)}`,e.red))),Promise.all(w).then(()=>Q({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=Fn.find(w=>w.label===i.activity_filter);g&&(cr(new Set(g.types)),Qe?.(g.label));}if(i.max_concurrent){let g=parseInt(i.max_concurrent,10);g>0&&(oa(g),Wn?.(g));}let d=i.notifications_toast==="true",u=i.notifications_bell==="true",h={toast:d,bell:u};ra(h),St?.(h),a("Settings saved",e.green);}else if(p==="goal"&&Ne){let d=Di(i);a(`Creating goal "${d.title}"...`,e.amber),Ne(d).then(u=>{a(`\u2713 Created goal "${u.title}" (${u.id})`,e.green),Q();},u=>a(`Failed: ${u instanceof Error?u.message:String(u)}`,e.red));}else if(p==="edit_goal"&&s&&Ke){let d=Wi(i);a("Updating goal...",e.amber),Ke(s,d).then(u=>{a(`\u2713 Updated goal "${u.title}"`,e.green),Q();},u=>a(`Failed: ${u instanceof Error?u.message:String(u)}`,e.red));}},[xt,L,f,X,ae,Be,x,E,z,dt,Ne,Ke,a,Q,Qe,Wn,po,St,Gt,an]),Sa=useCallback(()=>{Le("none"),Ze(null),jn([]);},[]),ka=useCallback(i=>{let p=b(i);if(!p)return;let s=qo(K,In.current),d=Gr(s,p);Ze({title:`NEW AGENT \u2014 ${p.name}`,steps:d,kind:"agent_from_shop"}),Le("wizard");},[]);useEffect(()=>{if(!B)return;let i=null,p=()=>{i||(i=setTimeout(()=>{i=null,Q().catch(()=>{});},150));},s=B(d=>{if(d.type==="agent:started"&&(cn.current.set(d.runId,d.agentId),So.current.set(d.runId,d.taskId)),Wc(d,a,cn.current,So.current),d.type==="task:created"?go(u=>u==="welcome"?"task_created":u):d.type==="agent:started"?go(u=>u==="task_created"?"run_started":u):d.type==="task:status_changed"&&d.to==="done"&&go(u=>u==="run_started"?"completed":u),d.type==="task:status_changed"&&(d.to==="done"?xo("done",d.taskId):d.to==="failed"?xo("failed",d.taskId):d.to==="review"&&xo("review",d.taskId),ho.current.toast&&ns.current!=="tasks")){let u=d.to==="done"?e.green:d.to==="failed"?e.red:d.to==="review"?e.blue:void 0;u&&ts({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,Q,xo]);let Tr=qt?"watching":"idle",Ca=le.started_at?g(le.started_at):void 0,fs=le.stats.total_tokens.total,ps=useMemo(()=>{let i={running:0,retrying:0,review:0,todo:0,done:0,failed:0,cancelled:0};for(let p of q)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:Jn}},[q,Jn]);ps.running;let Ia=useMemo(()=>({input:le.stats.total_tokens.input??0,output:le.stats.total_tokens.output??0,reasoning:le.stats.total_tokens.reasoning??0,total:fs,cache_read:le.stats.total_tokens.cache_read??0,cache_write:le.stats.total_tokens.cache_write??0}),[le.stats.total_tokens,fs]),It=Math.max(4,Y-9),Ma=_n.size,va=K.length>Ma,_a=Jn>0?Jn+(va?1:0):0,Ra=useMemo(()=>{if(!Kn||Mn.size===0)return 0;let i=0,p=new Set,s=false;for(let d of $t)d.goalId&&Mn.has(d.goalId)?p.has(d.goalId)||(p.add(d.goalId),i++):s=true;return s&&i++,i},[Kn,Mn,$t]),Aa=$==="goals"?mt.length+1:$==="tasks"?$t.length+1+(vn>0?1:0)+Ra:$==="agents"?K.length+1+_a:0,$a=Math.min(Aa+1,Math.ceil(It*.5)),Ba=$==="logs"?It:Math.max(2,Math.min($a,It-4)),we,Bt;if($==="logs")we=It,Bt=0;else if(To)we=0,Bt=Math.max(1,It);else {let i=Math.max(3,Math.min(Ba+fr,It-4));we=i,Bt=Math.max(1,It-i);}let ve=Math.max(10,_-2),Mt=useMemo(()=>De==="command"?Xs(sn):[],[De,sn]),An=It-4-3;useEffect(()=>{fr>An&&kn(An),fr<-An&&kn(-An);},[It]),useEffect(()=>{Sn(i=>Math.min(i,Math.max(0,$t.length-we)));},[$t.length,we]),useEffect(()=>{gr(i=>Math.min(i,Math.max(0,Fe.length-we)));},[Fe.length,we]),useEffect(()=>{mr(i=>Math.min(i,Math.max(0,mt.length-we)));},[mt.length,we]);let Ea=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),Q();},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),Q();},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),Q();},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){Co();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),Q();},w=>a(`Failed: ${u(w)}`,e.red));}else if(h==="list"){let g=Oe.map(w=>` ${w.id} ${w.status.padEnd(11)} ${w.title}`);if(g.length===0)a("No tasks",e.dim);else for(let w of g)a(w,e.cyan);}else if(h==="show"){let g=s[2]?Oe.find(w=>w.id===s[2]):U;if(!g){a("No task selected or id given",e.yellow);return}a(`${g.id} ${g.status} P${g.priority} "${g.title}"`,e.cyan),g.assignee&&a(` agent: ${g.assignee}`,e.dim),g.description&&a(` ${g.description.slice(0,100)}`,e.dim);}else if(h==="cancel"){let g=s[2]?Oe.find(w=>w.id===s[2]):U;if(!g){a("No task selected or id given",e.yellow);return}if(!b$1)return;a(`Cancelling "${g.title}"...`,e.amber),b$1(g.id).then(()=>{a(`\u2713 Cancelled "${g.title}"`,e.green),Q();},w=>a(`Failed: ${u(w)}`,e.red));}else if(h==="retry"){let g=s[2]?Oe.find(w=>w.id===s[2]):U;if(!g){a("No task selected or id given",e.yellow);return}if(!T)return;a(`Retrying "${g.title}"...`,e.amber),T(g.id).then(()=>{a(`\u2713 Retried "${g.title}"`,e.green),Q();},w=>a(`Failed: ${u(w)}`,e.red));}else if(h==="assign"){let g=s[2]?Oe.find(Et=>Et.id===s[2]):void 0,w=g??U,J=g?s[3]:s[2];if(!w){a("No task selected or id given",e.yellow);return}if(!J){a("Usage: /task assign [id] <agent>",e.yellow);return}if(!x)return;a(`Assigning "${w.title}" to ${J}...`,e.amber),x(w.id,J).then(()=>{a(`\u2713 Assigned "${w.title}" to ${J}`,e.green),Q();},Et=>a(`Failed: ${u(Et)}`,e.red));}else if(h==="approve"){let g=s[2]?Oe.find(w=>w.id===s[2]):U;if(!g){a("No task selected or id given",e.yellow);return}if(g.status!=="review"){a(`Cannot approve \u2014 status is ${g.status}`,e.yellow);return}if(!O)return;a(`Approving "${g.title}"...`,e.amber),O(g.id).then(()=>{a(`\u2713 Approved "${g.title}"`,e.green),Q();},w=>a(`Failed: ${u(w)}`,e.red));}else if(h==="reject"){let g=s[2]?Oe.find(J=>J.id===s[2]):U;if(!g){a("No task selected or id given",e.yellow);return}if(g.status!=="review"){a(`Cannot reject \u2014 status is ${g.status}`,e.yellow);return}if(!P)return;let w=s.slice(s[2]&&Oe.find(J=>J.id===s[2])?3:2).join(" ").trim()||void 0;a(`Rejecting "${g.title}"${w?" with feedback":""}...`,e.amber),P(g.id,w).then(()=>{a(`\u2713 Rejected "${g.title}" \u2192 todo`,e.green),Q();},J=>a(`Failed: ${u(J)}`,e.red));}else if(h==="delete"){let g=s[2]?Oe.find(w=>w.id===s[2]):U;if(!g){a("No task selected or id given",e.yellow);return}if(g.status==="in_progress"){a("Cannot delete \u2014 task is running",e.yellow);return}if(!N)return;Rn("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){ko();return}if(!L){a("Agent creation not available",e.yellow);return}let w=s[3];a(`Creating agent "${g}"...`,e.amber),L(g,w).then(J=>{a(`\u2713 Created agent "${J.name}" (${J.id}, ${J.adapter})`,e.green),Q();},J=>a(`Failed: ${u(J)}`,e.red));}else if(h==="list"){let g=Fe.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]?Fe.find(w=>w.id===s[2]||w.name===s[2]):ee;if(!g){a("No agent selected or id given",e.yellow);return}if(!S)return;a(`Disabling ${g.name}...`,e.amber),S(g.id).then(()=>{a(`\u2713 Disabled ${g.name}`,e.green),Q();},w=>a(`Failed: ${u(w)}`,e.red));}else if(h==="enable"){let g=s[2]?Fe.find(w=>w.id===s[2]||w.name===s[2]):ee;if(!g){a("No agent selected or id given",e.yellow);return}if(!M)return;a(`Enabling ${g.name}...`,e.amber),M(g.id).then(()=>{a(`\u2713 Enabled ${g.name}`,e.green),Q();},w=>a(`Failed: ${u(w)}`,e.red));}else if(h==="delete"||h==="remove"){let g=s[2]?Fe.find(w=>w.id===s[2]||w.name===s[2]):ee;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}Rn("agent",g.id,g.name);}else if(h==="autonomous"||h==="auto"){let g=s[2]?Fe.find(w=>w.id===s[2]||w.name===s[2]):ee;if(!g){a("No agent selected or id given",e.yellow);return}if(!dt){a("Autonomous toggle not available",e.yellow);return}g.autonomous?(a(`Disabling autonomous mode for "${g.name}"...`,e.amber),dt(g.id,false).then(()=>{a(`${gn} ${g.name} autonomous OFF`,e.cyan),Q();},w=>a(`Failed: ${u(w)}`,e.red))):(a(`Enabling autonomous mode for "${g.name}"...`,e.amber),dt(g.id,true).then(()=>{a(`${gn} ${g.name} autonomous ON`,e.cyan),Q();},w=>a(`Failed: ${u(w)}`,e.red)));}else h==="shop"?us():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")gs();else if(h==="list"){let g=In.current;if(g.length===0)a("No teams",e.dim);else for(let w of g)a(` ${w.id} ${w.status.padEnd(8)} ${w.name} (${w.members.length} members)`,e.cyan);}else if(h==="join"){if(!ae){a("Join not available",e.yellow);return}let g=s[2],w=s[3]??ee?.id;if(!g||!w){a("Usage: /team join <teamId> [agentId]",e.yellow);return}a(`Joining team ${g}...`,e.amber),ae(g,w).then(J=>{a(`\u2713 Agent joined team "${J.name}"`,e.green),Q({includeTeams:true});},J=>a(`Failed: ${u(J)}`,e.red));}else if(h==="leave"){if(!Be){a("Leave not available",e.yellow);return}let g=s[2],w=s[3]??ee?.id;if(!g||!w){a("Usage: /team leave <teamId> [agentId]",e.yellow);return}a(`Leaving team ${g}...`,e.amber),Be(g,w).then(J=>{a(`\u2713 Agent left team "${J.name}"`,e.green),Q({includeTeams:true});},J=>a(`Failed: ${u(J)}`,e.red));}else if(h==="disband"){if(!Dt){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),Dt(g).then(()=>{a("\u2713 Team disbanded",e.green),Q({includeTeams:true});},w=>a(`Failed: ${u(w)}`,e.red));}else if(h==="set-lead"){if(!ct){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),ct(g,w).then(J=>{a(`\u2713 New lead for team "${J.name}"`,e.green),Q({includeTeams:true});},J=>a(`Failed: ${u(J)}`,e.red));}else a("Usage: /team create|list|join|leave|disband|set-lead",e.yellow);return}case "goal":{let h=s[1]?.toLowerCase();if(h==="add"||h==="create"){let g=s.slice(2).join(" ").trim();if(!g){let w=Ko(K);Ze({title:"New Goal",steps:w,kind:"goal"}),Le("wizard");return}if(!Ne){a("Goal creation not available",e.yellow);return}a(`Creating goal "${g}"...`,e.amber),Ne({title:g}).then(w=>{a(`\u2713 Created goal "${w.title}" (${w.id})`,e.green),Q();},w=>a(`Failed: ${u(w)}`,e.red));}else if(h==="list"){let g=mt.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]?mt.find(w=>w.id===s[2]):oe;if(!g){a("No goal selected or id given",e.yellow);return}a(`${g.id} ${g.status} "${g.title}"`,e.cyan),g.description&&a(` ${g.description.slice(0,100)}`,e.dim);}else if(h==="status"){let g=s[2]?mt.find(un=>un.id===s[2]):void 0,w=g??oe;if(!w){a("No goal selected or id given",e.yellow);return}let J=s[g?3:2];if(!J||!a$1.includes(J)){a("Usage: /goal status [id] <active|paused|achieved|abandoned>",e.yellow);return}let Et=J;if(!ut){a("Status update not available",e.yellow);return}a(`Updating goal status to ${Et}...`,e.amber),ut(w.id,Et).then(un=>{a(`\u2713 Goal "${un.title}" \u2192 ${Et}`,e.green),Q();},un=>a(`Failed: ${u(un)}`,e.red));}else if(h==="delete"){let g=s[2]?mt.find(w=>w.id===s[2]):oe;if(!g){a("No goal selected or id given",e.yellow);return}if(!Ye){a("Goal deletion not available",e.yellow);return}Rn("goal",g.id,g.title);}else a("Usage: /goal add|list|show|status|delete",e.yellow);return}case "run":{let h=s[1]??U?.id;if(!h){a("No task selected or id given",e.yellow);return}if(!l){a("Run not available",e.yellow);return}let g=Oe.find(w=>w.id===h);if(g&&!zr.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),Q();},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),Q();},h=>a(`Failed: ${u(h)}`,e.red));return}case "watch":{if(qt){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(()=>{Gn(true),a("\u2713 Watch mode started",e.green);},h=>a(`Failed: ${u(h)}`,e.red));return}case "pause":{if(!qt){a("Watch mode not active",e.yellow);return}if(!qe){a("Pause not available",e.yellow);return}a("Pausing watch mode...",e.amber),qe().then(()=>{Gn(false),a("\u2713 Watch mode paused",e.green);},h=>a(`Failed: ${u(h)}`,e.red));return}case "config":{s[1]?.toLowerCase()==="activity-filter"?cr(g=>{let w=Vr(g);return Qe?.(w.label),a(`Activity filter: ${w.label}`,e.amber),new Set(w.types)}):ms();return}case "status":{let h=q.filter(g=>g.status==="in_progress").length;a(`${Tr} ${h} running ${q.length} tasks ${Fe.length} agents`,e.cyan);return}case "help":{for(let[h,g]of Object.entries(fn)){let w=g.sub?" "+g.sub.join("|"):g.args?" "+g.args:"";a(` /${h}${w} \u2014 ${g.help}`,e.silver);}return}case "quit":{rn();return}case "disable":{if(!ee){a("No agent selected",e.yellow);return}if(!S)return;a(`Disabling ${ee.name}...`,e.amber),S(ee.id).then(()=>{a(`\u2713 Disabled ${ee.name}`,e.green),Q();},h=>a(`Failed: ${u(h)}`,e.red));return}case "enable":{if(!ee){a("No agent selected",e.yellow);return}if(!M)return;a(`Enabling ${ee.name}...`,e.amber),M(ee.id).then(()=>{a(`\u2713 Enabled ${ee.name}`,e.green),Q();},h=>a(`Failed: ${u(h)}`,e.red));return}default:a(`Unknown: ${d}. Type /help for commands`,e.yellow);}},[U,ee,Oe,Fe,q,Tr,qt,b$1,T,x,y,l,f,S,M,L,O,P,N,ae,Be,Dt,ct,Re,qe,a,rn,Q,Co,ko,gs,ms]);useInput((i,p)=>{if(!(At&&(sr(false),i==="?"||p.escape||i==="\x1BOP"))&&!yn){if((p.ctrl||p.meta)&&i==="s"&&De==="wizard"&&xt?.kind==="agent"){us();return}if(De!=="none"){if(p.escape){Le("none"),Ct(""),bo.reset();return}if(p.return){let s=sn.trim();if(!s)return;if(De==="new_task"){if(!f)return;Le("none"),Ct(""),a(`Creating "${s}"...`,e.amber),f(s).then(d=>{a(`\u2713 Created "${d.title}" (${d.id})`,e.green),Q();},d=>a(`Failed to create: ${d instanceof Error?d.message:String(d)}`,e.red));}else if(De==="command"){let d=s;if(Mt.length>0&&Mt[yo]){let u=Mt[yo],h=u.cmd.replace(/\s+\[.*\]$/,"");if((h.startsWith(s)||s==="/")&&(d=h),u.subs&&!h.includes(" ")){Ct(h+" "),Yt(0);return}}Le("none"),Ct(""),Yt(0),bo.push(d),Ea(d);}return}if(p.tab&&De==="command"){if(Mt.length>0){let s=Mt[yo];if(s){let d=s.cmd.replace(/\s+\[.*\]$/,"");Ct(d+(s.subs?" ":"")),Yt(0);}}else {let s=Rr(sn);s&&Ct(d=>d+s);}return}if(p.upArrow&&De==="command"){if(Mt.length>0)Yt(s=>Math.max(0,s-1));else {let s=bo.prev();s!==null&&Ct(s);}return}if(p.downArrow&&De==="command"){if(Mt.length>0)Yt(s=>Math.min(Mt.length-1,s+1));else {let s=bo.next();Ct(s??"");}return}if(p.backspace||p.delete){Ct(s=>s.slice(0,-1)),Yt(0);return}i&&!p.ctrl&&!p.meta&&(Ct(s=>s+i),Yt(0));return}if(i.toLowerCase()==="q"){rn();return}if(p.escape){if(Ae){Hn(false),Yn(0);return}if($==="logs"&&Xn>=0){lr(-1),qn(0);return}return}if((i==="+"||i==="=")&&$!=="logs"){To?(pr(false),kn(-Math.floor(It/2))):kn(s=>Math.max(-An,s-3));return}if(i==="-"&&$!=="logs"){To?(pr(false),kn(Math.floor(It/2))):kn(s=>Math.min(An,s+3));return}if(i==="M"&&$!=="logs"){pr(s=>!s);return}if(i==="?"){sr(true);return}if(i==="\x1BOP"){sr(true);return}if(i==="/"&&!Ae){Le("command"),Ct("/"),Yt(0);return}if((i==="a"||i==="A")&&$==="logs"&&!Ae&&!yn&&!Un){ir(true);return}if(i==="f"&&$==="logs"&&!Ae&&!yn&&!Un){ar(true);return}if(i==="F"&&$==="logs"&&!Ae&&!yn&&!Un){Jr(s=>new Set(Vr(s).types));return}if((i==="z"||i==="Z")&&Cn.length>0){xa();return}if((i==="f"||i==="F")&&($==="tasks"||$==="agents"||$==="goals")&&!Ae){cr(s=>{let d=Vr(s);return Qe?.(d.label),new Set(d.types)});return}if((i==="n"||i==="N")&&$==="tasks"&&!Ae&&f){Co();return}if((i==="n"||i==="N")&&$==="agents"&&!Ae&&L){ko();return}if((i==="n"||i==="N")&&$==="goals"&&!Ae&&Ne){let s=Ko(K);Ze({title:"New Goal",steps:s,kind:"goal"}),Le("wizard");return}if((i==="e"||i==="E")&&$==="goals"&&oe&&Ke){let s=Fi(oe,K);Ze({title:`Edit Goal: ${oe.title}`,steps:s,kind:"edit_goal",targetId:oe.id}),Le("wizard");return}if((i==="d"||i==="D")&&$==="goals"&&oe&&Ye){Rn("goal",oe.id,oe.title);return}if((i==="c"||i==="C")&&$==="goals"&&oe&&ut){(oe.status==="active"||oe.status==="paused")&&(a(`Marking goal "${oe.title}" as achieved...`,e.amber),ut(oe.id,"achieved").then(()=>{a(`\u2713 Goal "${oe.title}" achieved`,e.green),Q();},s=>a(`Failed: ${s instanceof Error?s.message:String(s)}`,e.red)));return}if((i==="x"||i==="X")&&$==="goals"&&oe&&ut){(oe.status==="active"||oe.status==="paused")&&(a(`Abandoning goal "${oe.title}"...`,e.amber),ut(oe.id,"abandoned").then(()=>{a(`\u2713 Goal "${oe.title}" abandoned`,e.dim),Q();},s=>a(`Failed: ${s instanceof Error?s.message:String(s)}`,e.red)));return}if((i==="p"||i==="P")&&$==="goals"&&oe&&ut){let s=oe.status==="paused"?"active":"paused";(oe.status==="active"||oe.status==="paused")&&ut(oe.id,s).then(()=>{a(`Goal "${oe.title}" ${s}`,e.cyan),Q();},d=>a(`Failed: ${d instanceof Error?d.message:String(d)}`,e.red));return}if((i==="a"||i==="A")&&$==="tasks"&&U?.status==="review"&&O){a(`Approving "${U.title}"...`,e.amber),O(U.id).then(()=>{a(`\u2713 Approved "${U.title}"`,e.green),Q();},s=>a(`Failed: ${s instanceof Error?s.message:String(s)}`,e.red));return}if((i==="x"||i==="X")&&$==="tasks"&&U?.status==="review"&&P){a(`Rejecting "${U.title}"...`,e.amber),P(U.id).then(()=>{a(`\u2713 Rejected "${U.title}" \u2192 todo`,e.green),Q();},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),Q();},s=>a(`Failed: ${s instanceof Error?s.message:String(s)}`,e.red));return}if((i==="e"||i==="E")&&$==="tasks"&&U&&E){Ta(U);return}if((i==="e"||i==="E")&&$==="agents"&&ee&&z){ya(ee);return}if((i==="s"||i==="S")&&$==="tasks"){is(s=>!s),Vn(0),Sn(0);return}if((i==="g"||i==="G")&&$==="tasks"&&!Ae){ca(s=>!s),Vn(0),Sn(0);return}if((i==="s"||i==="S")&&$==="agents"&&ee&&V){if(!Object.values(le.running).some(d=>d.agent_id===ee.id)&&ee.status!=="running"){a(`Agent "${ee.name}" is not running`,e.yellow);return}a(`Force-stopping agent "${ee.name}"...`,e.amber),V(ee.id).then(()=>{a(`\u2713 Stopped agent "${ee.name}"`,e.green),Q();},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){Rn("task",U.id,U.title);return}if((i==="d"||i==="D")&&$==="agents"&&ee&&j){let s=Object.values(le.running).some(d=>d.agent_id===ee.id);if(s&&!V){a(`Cannot delete \u2014 agent "${ee.name}" is running. Press S to stop first.`,e.yellow);return}Rn("agent",ee.id,ee.name,{needsForceStop:s});return}if((i==="u"||i==="U")&&$==="agents"&&ee&&dt){let s=!ee.autonomous;a(`${s?"Enabling":"Disabling"} autonomous mode for "${ee.name}"...`,e.amber),dt(ee.id,s).then(()=>{a(`${gn} ${ee.name} autonomous ${s?"ON":"OFF"}`,e.cyan),Q();},d=>a(`Failed: ${d instanceof Error?d.message:String(d)}`,e.red));return}if(!Ae){if(i==="g"||i==="G"){Tn("goals");return}if(i==="t"||i==="T"){Tn("tasks");return}if(i==="a"||i==="A"){Tn("agents");return}if(i==="l"||i==="L"){Tn("logs");return}}if(!Ae){let s=Bo.map(u=>u.id),d=s.indexOf($);if(p.tab||p.rightArrow){Tn(s[(d+1)%s.length]);return}if(p.leftArrow){Tn(s[(d+s.length-1)%s.length]);return}}if(p.return){let s=vn>0?$t.length:-1;if($==="tasks"&&mo===s){is(u=>!u),Vn(0),Sn(0);return}let d=$t.length+(vn>0?1:0);if($==="tasks"&&mo===d&&f){Co();return}if($==="goals"&&rr===mt.length&&Ne){let u=Ko(K);Ze({title:"New Goal",steps:u,kind:"goal"}),Le("wizard");return}if($==="agents"&&or===Fe.length&&L){ko();return}if($==="goals"&&oe){Hn(u=>!u),Yn(0);return}if($==="tasks"&&U){Hn(u=>!u);return}if($==="agents"&&ee){Hn(u=>!u);return}if($==="logs"&&Xn>=0){Hn(u=>!u);return}}if((i==="r"||i==="R")&&$==="tasks"&&U&&l){if(!zr.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),Q();},s=>a(`Failed to run: ${s instanceof Error?s.message:String(s)}`,e.red));return}if(p.upArrow||i==="k"){if($==="goals"&&Ae){Yn(s=>Math.max(0,s-1));return}$==="goals"?qr(s=>{let d=Math.max(0,s-1);return mr(u=>d<u?d:u),d}):$==="tasks"?Vn(s=>{let d=Math.max(0,s-1);return Sn(u=>d<u?d:u),d}):$==="agents"?Xr(s=>{let d=Math.max(0,s-1);return gr(u=>d<u?d:u),d}):$==="logs"&&lr(s=>{if(s===-1){let u=ze.length-1;return qn(Math.max(0,u-we+2)),Math.max(0,u)}let d=Math.max(0,s-1);return qn(u=>d<u?d:u),d});}if(p.downArrow||i==="j"){if($==="goals"&&Ae){Yn(s=>s+1);return}if($==="goals"){let s=mt.length+(Ne?1:0)-1;qr(d=>{let u=Math.min(Math.max(0,s),d+1);return mr(h=>u>=h+we?u-we+1:h),u});}else if($==="tasks"){let s=$t.length+(f?1:0)+(vn>0?1:0)-1;Vn(d=>{let u=Math.min(Math.max(0,s),d+1);return Sn(h=>u>=h+we?u-we+1:h),u});}else if($==="agents"){let s=Fe.length+(L?1:0)-1;Xr(d=>{let u=Math.min(Math.max(0,s),d+1);return gr(h=>u>=h+we?u-we+1:h),u});}else $==="logs"&&lr(s=>{if(s===-1)return -1;let d=ze.length-1;if(s>=d)return qn(0),-1;let u=s+1;return qn(h=>u>=h+we-1?u-we+2:h),u});}}});let et=De!=="none",hs=Xn>=0?ze[Xn]:void 0,Io=To?"+/- exit max":"+/- resize \u2502 M max",xs=!et&&Ae&&$==="tasks"&&U,bs=!et&&Ae&&$==="agents"&&ee,Ts=!et&&Ae&&$==="goals"&&oe,La=!et&&Ae&&$==="logs"&&hs,yr=U?.id,Oa=useMemo(()=>yr?ze.filter(i=>i.taskId===yr):[],[ze,yr]),Pa=!et&&$==="tasks"&&U&&zr.has(U.status)&&!!l,Na=!et&&!Ae&&($==="goals"&&!!Ne||$==="tasks"&&!!f||$==="agents"&&!!L),Da=!et&&$==="tasks"&&U?.status==="review"&&!!O,Fa=!et&&$==="tasks"&&U?.status==="review"&&!!P,Wa=ee?Object.values(le.running).some(i=>i.agent_id===ee.id):false,Ga=!et&&($==="goals"&&oe&&!!Ye||$==="tasks"&&U&&U.status!=="in_progress"&&!!N||$==="agents"&&ee&&!!j),za=!et&&!Ae&&($==="goals"&&!!oe&&!!Ke||$==="tasks"&&!!U&&!!E||$==="agents"&&!!ee&&!!z),Va=!et&&$==="agents"&&ee&&(Wa||ee.status==="running")&&!!V,Ha=!et&&$==="agents"&&!!ee&&!!dt,ja=!et&&$==="goals"&&!!oe&&(oe.status==="active"||oe.status==="paused")&&!!ut,Ua=!et&&Cn.length>0,ys=De==="command"&&Mt.length>0,ws=xt?.kind==="task"||xt?.kind==="edit_task";return jsxs(Box,{flexDirection:"column",width:_,height:Y,children:[jsx(Us,{projectName:t,activeView:$,mode:Tr,stats:ps,tokens:Ia,uptime:Ca,width:_,version:Ut,latestVersion:xn,updateInstalled:Wt,taskBadge:vn>0?Oe.length:void 0,flashTab:ur?.tab,flashColor:ur?.color,onFlashComplete:ur?()=>ts(void 0):void 0}),jsx(Box,{height:1}),At&&jsx(hi,{width:_,height:Y-7}),!At&&Kt==="welcome"&&$==="tasks"&&jsx(ii,{width:_,height:Y}),!At&&$==="goals"&&jsx(Cc,{goals:mt,selectedIndex:rr,scrollOffset:ua,height:we,width:ve,showAddRow:!!Ne,agentNameMap:ln,tasksByGoalMap:ma}),!At&&Kt!=="welcome"&&$==="tasks"&&jsx(Mc,{tasks:$t,selectedIndex:mo,scrollOffset:la,height:we,width:ve,showAddRow:!!f,agentNameMap:ln,hiddenCount:vn,goalMap:Mn,groupByGoal:Kn}),!At&&$==="tasks"&&(Kt==="task_created"||Kt==="run_started")&&jsx(ai,{step:Kt,width:_}),!At&&$==="tasks"&&Kt==="completed"&&jsx(li,{width:_}),!At&&$==="agents"&&jsx(vc,{agents:Fe,selectedIndex:or,scrollOffset:da,height:we,width:ve,state:le,taskTitleMap:Zn,showAddRow:!!L,agentTeamMap:_n,teamLeadSet:pa,activeTeamCount:Jn}),!At&&$==="logs"&&jsxs(Fragment,{children:[jsx(Rc,{messages:ze,height:yn||Un?Math.max(3,we-16):we,agents:Fe,logAgentFilter:Yr,logTypeFilter:Zr,selectedIndex:Xn,scrollOffset:na,agentNameMap:ln,agentColorMap:wo,agentMsgCounts:ls,taskTitleMap:Zn,width:ve}),yn&&jsx(Box,{paddingX:2,children:jsx(ti,{agents:Fe,selected:Yr,msgCounts:ls,colorMap:wo,maxHeight:Math.min(we-4,18),onConfirm:i=>{ta(i),ir(false);},onCancel:()=>ir(false)})}),Un&&jsx(Box,{paddingX:2,children:jsx(si,{selected:Zr,typeCounts:fa,onConfirm:i=>{Jr(i),ar(false);},onCancel:()=>ar(false)})})]}),jsx(Box,{height:1}),At?null:De==="wizard"&&xt?jsx(Js,{title:xt.title,steps:xt.steps,onComplete:wa,onCancel:Sa,width:ve,height:Bt,onPasteImage:ws?ba:void 0,onSuggestionSelected:xt.kind==="agent"?ka:void 0,footerExtra:an.length>0&&ws?`\u{1F4CE}${an.length}`:void 0},`${xt.kind}-${xt.title}`):ys?jsxs(Fragment,{children:[jsx(Yo,{label:"COMMANDS",width:ve}),jsx(kc,{suggestions:Mt,selectedIndex:yo,height:Math.min(Mt.length,Bt),width:ve})]}):De==="new_task"?jsxs(Fragment,{children:[jsx(Nc,{mode:De,width:ve}),jsx(Dc,{mode:De,value:sn,width:ve})]}):xs?jsxs(Fragment,{children:[jsx(Bc,{task:U,width:ve,resizeHint:Io}),jsx(zs,{task:U,height:Bt,width:ve,taskLogs:Oa,agentNameMap:ln,taskTitleMap:Zn})]}):Ts?jsxs(Fragment,{children:[jsx(Yo,{label:`GOAL: ${oe.title}`,width:ve,suffixLen:Io.length+2,suffix:jsxs(Text,{color:e.dim,children:[" ",Io," "]})}),jsx(Ic,{goal:oe,height:Bt,width:ve,agentNameMap:ln,tasks:ha,progressReport:ea,scrollOffset:ga,onClampScroll:Yn})]}):bs?jsxs(Fragment,{children:[jsx(Ec,{agent:ee,width:ve,resizeHint:Io}),jsx(Lc,{agent:ee,height:Bt,state:le,taskTitleMap:Zn,teamName:_n.get(ee.id)})]}):La?jsxs(Fragment,{children:[jsx(Yo,{label:"LOG",width:ve}),jsx($c,{message:hs,height:Bt,width:ve,agents:Fe,agentNameMap:ln,agentColorMap:wo,taskTitleMap:Zn})]}):ze.length>0&&$!=="logs"?jsxs(Fragment,{children:[(()=>{let i=` F:${fo.toUpperCase()} \u2502 ${dr.length}/${ze.length}`;return jsx(Yo,{label:"ACTIVITY",width:ve,suffixLen:i.length,suffix:jsxs(Fragment,{children:[jsx(Text,{color:e.dim,children:" F:"}),jsx(Text,{color:e.amber,children:fo.toUpperCase()}),jsxs(Text,{color:e.ghost,children:[" ","\u2502"," ",dr.length,"/",ze.length]})]})})})(),jsx(Ac,{messages:dr,height:Math.max(1,Bt-1),width:ve,agents:Fe,agentNameMap:ln,agentColorMap:wo})]}):$==="goals"?jsx(Ho,{count:mt.length,config:bc,width:ve}):$==="tasks"?jsx(Ho,{count:Oe.length,config:Tc,width:ve}):$==="agents"?jsx(Ho,{count:Fe.length,config:yc,width:ve}):null,jsx(Box,{flexGrow:1}),jsx(pi,{toasts:sa,onDismiss:aa}),Cn.length>0&&jsx(Sc,{deletions:Cn,width:_}),jsx(qs,{mode:De==="command"?"command":"navigate",value:De==="command"?sn:"",completion:De==="command"?Rr(sn):null,activeView:$,canRun:!!Pa,canNew:!!Na,canApprove:!!Da,canReject:!!Fa,canCancel:$==="tasks"&&!!U&&U.status==="in_progress"&&!!b$1,canDelete:!!Ga,canUndo:!!Ua,canEdit:!!za,canForceStop:!!Va,canToggleAuto:!!Ha,autoActive:ee?.autonomous,canPause:!!ja,isPaused:oe?.status==="paused",canToggleShowAll:$==="tasks"&&Oe.length>Gi,showAllActive:ss,hasDetail:!!(xs||bs||Ts),itemCount:$==="goals"?mt.length:$==="tasks"?Oe.length:$==="agents"?K.length:ze.length,itemLabel:$==="goals"?"goals":$==="tasks"?"tasks":$==="agents"?"agents":"events",width:_,hasSuggestions:ys,onboardingCompleted:r.onboardingCompleted})]})}var Sc=so.memo(function({deletions:n,width:o}){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:o,children:n.map(f=>{let b=Math.max(0,Math.ceil((f.expiresAt-l)/1e3)),T=Math.max(0,o-4),x=f.entityType==="task"?"Task":f.entityType==="agent"?"Agent":"Goal",y=Math.max(10,T-x.length-30),S=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}),` "${S}" \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 kc({suggestions:t,selectedIndex:n,height:o,width:r}){let l=o,f=0;n>=l&&(f=n-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,S=y===n,M=S?"\u25B6":" ",B=Math.min(20,Math.max(14,...t.map(L=>L.cmd.length+1))),C=T.cmd.padEnd(B),W=T.subs?` ${T.subs}`:"",H=Math.max(4,r-B-W.length-8),G=T.desc.length>H?T.desc.slice(0,H-1)+"\u2026":T.desc;return jsxs(Text,{wrap:"truncate",children:[jsx(Text,{color:S?e.amber:e.ghost,children:` ${M} `}),jsx(Text,{color:S?e.white:e.silver,bold:S,children:C}),jsx(Text,{color:e.dim,children:G}),W&&jsx(Text,{color:e.ghost,children:W})]},y)})})}function Cc({goals:t,selectedIndex:n,scrollOffset:o=0,height:r,width:l,showAddRow:f,agentNameMap:b,tasksByGoalMap:T}){let x=t.length,y=t.slice(o,o+r),S=f&&x>=o&&x<o+r;return jsxs(Box,{flexDirection:"column",height:r,children:[y.map((M,B)=>jsx(Box,{paddingX:2,children:jsx(Gs,{goal:M,selected:B+o===n,width:l-2,agentNameMap:b,tasksByGoal:T?.get(M.id)})},M.id)),S&&jsx(Box,{paddingX:2,children:jsxs(Text,{color:n===x?e.amber:e.ghost,children:[n===x?" \u25B8 ":" ",jsx(Text,{color:n===x?e.amber:e.dim,children:"+ add goal..."})]})},"__add__")]})}function Ic({goal:t,height:n,width:o,agentNameMap:r,tasks:l,progressReport:f,scrollOffset:b=0,onClampScroll:T}){let y=so.useMemo(()=>{let H=l??[],G=t.assignee?r?.get(t.assignee)??t.assignee:"\u2014",L=Math.max(20,o-6),j=(V,X)=>{if(V.length<=X)return [V];let R=[];for(let ae=0;ae<V.length;ae+=X)R.push(V.slice(ae,ae+X));return R},O=Ir(f)?.split(`
|
|
13
|
+
`).flatMap(V=>j(V,L))??[],P=Ir(t.description)?.split(`
|
|
14
|
+
`).flatMap(V=>j(V,L))??[],N=Ms[t.status]??e.dim,E=new Map;for(let V of H)E.set(V.status,(E.get(V.status)??0)+1);let z=[];if(z.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:G})]})]})}),z.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&&z.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)})]})]})}),H.length>0){let V=[];for(let[X,R]of E)V.push(`${R} ${X}`);z.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:H.length})]}),jsxs(Box,{children:[jsx(Text,{color:e.dim,children:" "}),jsx(Text,{color:e.dim,children:V.join(" \xB7 ")})]})]})});}if(P.length>0){z.push({key:"desc-gap",node:jsx(Text,{children:" "})});for(let V=0;V<P.length;V++)z.push({key:`desc-${V}`,node:jsxs(Text,{color:e.silver,wrap:"truncate",children:[" ",P[V]]})});}else z.push({key:"desc-gap",node:jsx(Text,{children:" "})}),z.push({key:"desc-empty",node:jsx(Text,{color:e.dim,children:" No description."})});if(O.length>0){z.push({key:"prog-gap",node:jsx(Text,{children:" "})}),z.push({key:"prog-div",node:jsx(Pn,{label:"progress",width:o})});for(let V=0;V<O.length;V++)z.push({key:`prog-${V}`,node:jsxs(Text,{color:e.white,wrap:"truncate",children:[" ",O[V]]})});}if(H.length>0){z.push({key:"tasks-gap",node:jsx(Text,{children:" "})}),z.push({key:"tasks-div",node:jsx(Pn,{label:`tasks (${H.length})`,width:o})});for(let V of H){let X=Ro[V.status]??e.dim;z.push({key:`task-${V.id}`,node:jsxs(Text,{color:e.silver,wrap:"truncate",children:[" ",jsx(Text,{color:X,children:V.status.padEnd(12)}),V.title.slice(0,Math.max(10,o-22))]})});}}return z},[t,l,f,o,r]),S=Math.max(0,y.length-n),M=Math.min(b,S);so.useEffect(()=>{T&&M!==b&&T(M);},[M,b,T]);let B=y.length>n&&M<S,C=B?n-1:n,W=y.slice(M,M+C);return jsxs(Box,{flexDirection:"column",height:n,paddingX:2,children:[W.map(H=>jsx(Box,{children:H.node},H.key)),B&&jsxs(Text,{color:e.ghost,children:[" ","\u2193"," ",y.length-M-C," more ","\u2014"," ","\u2191","\u2193"," to scroll"]})]})}function Mc({tasks:t,selectedIndex:n,scrollOffset:o=0,height:r,width:l,showAddRow:f,agentNameMap:b,hiddenCount:T=0,goalMap:x,groupByGoal:y=false}){let S=T>0,M=S?t.length:-1,B=t.length+(S?1:0),C=t.slice(o,o+r),W=S&&M>=o&&M<o+r,H=f&&B>=o&&B<o+r,G=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 z=N.get(E.goalId)??{total:0,done:0};z.total++,E.status==="done"&&z.done++,N.set(E.goalId,z);}return N},[t,y,x]),L=y&&x?t.filter(N=>!N.goalId||!x.has(N.goalId)).length:0,j=y&&x&&x.size>0&&G&&G.size>0,O=[],P=o>0?t[o-1]?.goalId??null:void 0;for(let N=0;N<C.length&&O.length<r;N++){let E=C[N],z=E.goalId&&x?.has(E.goalId)?E.goalId:null;if(j){if(z&&z!==P){let V=x.get(z),X=G.get(z)??{total:0,done:0};if(O.push(jsx(Bs,{goalTitle:V.title,taskCount:X.total,doneCount:X.done,width:l},`gh_${z}`)),O.length>=r)break}if(!z&&P!==null&&P!==void 0&&(O.push(jsx(Es,{taskCount:L,width:l},"__ungrouped__")),O.length>=r))break}P=z,O.push(jsx(Box,{paddingX:2,children:jsx($o,{task:E,selected:N+o===n,width:l-2,agentNameMap:b,goalMap:x})},E.id));}return W&&O.length<r&&O.push(jsx(Box,{paddingX:2,children:jsxs(Text,{color:n===M?e.amber:e.ghost,children:[n===M?" \u25B8 ":" ",jsxs(Text,{color:n===M?e.amber:e.dim,children:["\u25BC"," Show all (",T," more) \u2014 press ",jsx(Text,{bold:true,color:e.gray,children:"S"})]})]})},"__show_all__")),H&&O.length<r&&O.push(jsx(Box,{paddingX:2,children:jsxs(Text,{color:n===B?e.amber:e.ghost,children:[n===B?" \u25B8 ":" ",jsx(Text,{color:n===B?e.amber:e.dim,children:"+ add task..."})]})},"__add__")),jsx(Box,{flexDirection:"column",height:r,children:O})}function vc({agents:t,selectedIndex:n,scrollOffset:o=0,height:r,width:l,state:f,taskTitleMap:b,showAddRow:T,agentTeamMap:x,teamLeadSet:y,activeTeamCount:S}){let M=new Map;for(let E of Object.values(f.running))M.set(E.agent_id,E);let B=new Map;if(S&&S>0)for(let E of t){let z=x?.get(E.id);z&&B.set(z,(B.get(z)??0)+1);}let C=t.length,W=t.slice(o,o+r),H=T&&C>=o&&C<o+r,G=S!=null&&S>0,L=new Map;if(G&&y&&x){for(let E of t)if(y.has(E.id)){let z=x.get(E.id);z&&L.set(z,E.name);}}let j=0;for(let E of B.values())j+=E;let O=t.length-j,P=[],N=o>0?x?.get(t[o-1]?.id??""):void 0;for(let E=0;E<W.length&&P.length<r;E++){let z=W[E],V=x?.get(z.id);if(G&&V&&V!==N&&(P.push(jsx(Ns,{teamName:V,memberCount:B.get(V)??0,leadName:L.get(V),width:l},`ts-${V}`)),P.length>=r)||G&&!V&&N&&(P.push(jsx(Ds,{memberCount:O,width:l},"ts-unassigned")),P.length>=r))break;N=V,P.push(jsx(Box,{paddingX:2,children:jsx(Ps,{agent:z,selected:E+o===n,width:l-2,runningEntry:M.get(z.id),currentTaskTitle:z.current_task?b.get(z.current_task):void 0,teamName:V,isLead:y?.has(z.id)})},z.id));}return H&&P.length<r&&P.push(jsx(Box,{paddingX:2,children:jsxs(Text,{color:n===C?e.amber:e.ghost,children:[n===C?" \u25B8 ":" ",jsx(Text,{color:n===C?e.amber:e.dim,children:"+ add agent..."})]})},"__add__")),jsx(Box,{flexDirection:"column",height:r,children:P})}function Ki(t=5e3){let[n,o]=useState(Date.now());return useEffect(()=>{let r=setInterval(()=>o(Date.now()),t);return ()=>clearInterval(r)},[t]),n}function Yi(t,n){let o=Math.max(0,n-t);return o<3e3?"now":o<6e4?`${Math.floor(o/1e3)}s`:o<36e5?`${Math.floor(o/6e4)}m`:`${Math.floor(o/36e5)}h`}function _c(t){if(t==="error")return e.errorBg}function Zi(t,n){switch(t){case "output":return e.white;case "tool":return e.dim;case "result":return e.dim;case "file":return e.gray;case "error":return e.red;case "lifecycle":return e.dim;case "system":return e.dim;default:return n}}function Rc({messages:t,height:n,agents:o,logAgentFilter:r,logTypeFilter:l,selectedIndex:f,scrollOffset:b,agentNameMap:T,agentColorMap:x,agentMsgCounts:y,taskTitleMap:S,width:M}){let B=Ki(),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 ae=R.msgType??"info";X[ae]=(X[ae]??0)+1;}return X},[t]);let H=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`,G=r.size>0,L=n-2,j=f===-1?C.slice(-L):C.slice(b,b+L),O=f===-1?-1:f-b,P=Math.min(10,Math.max(6,...o.map(X=>X.name.length))),N=11+P,E=X=>{if(X===0)return true;let R=j[X],ae=j[X-1];return R.agentId!==ae.agentId?true:R.agentId?R.ts-ae.ts>3e4:false},z=Math.max(4,Math.floor((M-20)/Math.max(1,o.length))-1),V=Math.min(z,10);return jsxs(Box,{flexDirection:"column",paddingX:1,children:[jsxs(Box,{gap:0,justifyContent:"space-between",width:M,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(Bn,{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"]}),H!=="all"&&jsxs(Text,{color:e.amber,children:[" f:",H]}),G&&jsxs(Text,{color:e.cyan,children:[" ",r.size,"/",o.length," agents"]})]}),jsxs(Box,{gap:0,children:[jsx(Text,{color:e.amber,bold:true,children:"a"}),jsx(Text,{color:e.dim,children:" filter "}),jsx(Text,{color:e.amber,bold:true,children:"f"}),jsx(Text,{color:e.dim,children:" type "}),jsx(Text,{color:e.amber,bold:true,children:"F"}),jsx(Text,{color:e.dim,children:" cycle"})]})]}),jsx(Box,{gap:0,children:o.map(X=>{let R=x.get(X.id)??Hr[0],ae=r.size===0||r.has(X.id),Be=X.name.length>V?X.name.slice(0,V-1)+"\u2026":X.name;return jsxs(Text,{color:ae?R:e.ghost,bold:ae,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 ae=R===O,Be=X.msgType??"info",Dt=tr[Be]??"\u2502",ct=X.agentId?T.get(X.agentId)??X.agentId.slice(0,8):void 0,Re=X.agentId?x.get(X.agentId):void 0,qe=E(R),ft=(R>0?j[R-1]:void 0)?.agentId===X.agentId&&!!X.agentId,Ne=!ft&&!!ct,Ke=ft&&!!ct,ut=Zi(Be,X.color),Ye=ae?e.infoBg:Be==="error"?e.errorBg:void 0,nn=X.taskId?S.get(X.taskId):void 0,ke=Yi(X.ts,B),pt=nn&&M>80?`#${nn.slice(0,20)}`:"",Rt=pt?pt.length+3:0,jt=Math.max(10,M-2-N-Rt),ht=tt(X.text,jt);return jsxs(Box,{backgroundColor:Ye,children:[jsx(Text,{color:Re??e.ghost,children:qe&&Ne?"\u250C":Ke?"\u2502":" "}),jsx(Text,{color:ae?e.amber:void 0,children:ae?"\u25B8":" "}),jsx(Box,{width:5,children:jsx(Text,{color:ke==="now"?e.green:ae?e.silver:e.ghost,children:ke.padStart(4)})}),jsx(Box,{width:P+1,children:Ne?jsxs(Text,{color:Re,bold:true,children:[" ",ct.slice(0,P).padEnd(P)]}):Ke?jsxs(Text,{color:Re??e.ghost,children:[" ","\xB7".padEnd(P)]}):jsxs(Text,{color:e.ghost,children:[" "," ".padEnd(P)]})}),jsxs(Text,{color:Be==="error"?e.red:Re??e.dim,children:[" ",Dt," "]}),jsx(Text,{color:ae?e.white:ut,bold:ae||Be==="lifecycle",children:ht}),pt&&jsxs(Text,{color:e.ghost,children:[" ",jsx(Text,{color:e.dim,backgroundColor:e.void,children:` ${pt} `})]})]},R)})]})}function Ac({messages:t,height:n,width:o,agents:r,agentNameMap:l,agentColorMap:f}){let b=Ki(),T=t.slice(-n),x=Math.max(10,o-2-17),y=Math.max(0,n-T.length),S=0,M=[];for(let B=0;B<T.length;B++)B>0&&T[B].agentId!==T[B-1].agentId&&S++,M.push(S);return jsxs(Box,{flexDirection:"column",paddingX:1,children:[y>0&&jsx(Box,{height:y}),T.map((B,C)=>{let W=B.agentId?l.get(B.agentId)??B.agentId.slice(0,8):void 0,H=B.agentId?f.get(B.agentId):void 0,G=B.msgType??"info",L=tr[G]??"\u2502",j=Zi(G,B.color),P=(C>0?T[C-1]:void 0)?.agentId===B.agentId&&!!B.agentId,N=(M[C]&1)===1,E=_c(G)??(N?"#1a1a1a":void 0),z=Yi(B.ts,b),V=tt(B.text,x);return jsxs(Box,{backgroundColor:E,children:[jsx(Text,{color:H??e.ghost,children:!P&&W?"\u258D":P?"\u258F":" "}),jsx(Box,{width:5,children:jsx(Text,{color:P?e.ghost:z==="now"?e.green:e.dim,children:P?" ":z.padStart(4)})}),jsx(Box,{width:9,children:W&&!P?jsxs(Text,{color:H,bold:true,children:[" ",W.slice(0,8)]}):jsx(Text,{color:e.ghost,children:wc})}),jsxs(Text,{color:G==="error"?e.red:P?e.ghost:H??e.dim,children:[L," "]}),jsx(Text,{color:j,children:V})]},C)})]})}function $c({message:t,height:n,width:o,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,S=t.agentId?f.get(t.agentId):e.dim,M=t.taskId?b.get(t.taskId):void 0,B,C=false;try{let L=JSON.parse(T);B=JSON.stringify(L,null,2),C=!0;}catch{B=T;}let W=Math.max(4,o-6),H=Math.max(1,n-4),G=B.split(`
|
|
15
|
+
`).slice(0,H);return jsxs(Box,{flexDirection:"column",paddingX:1,children:[jsx(Box,{children:jsxs(Text,{color:e.ghost,children:["\u256D",Te(W+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:S,bold:true,children:y}),y&&jsx(Text,{color:e.ghost,children:" \u2502 "}),jsxs(Text,{color:tr[x]?x==="error"?e.red:e.dim:e.dim,children:[tr[x]??"\u2502"," ",x]}),M&&jsxs(Fragment,{children:[jsx(Text,{color:e.ghost,children:" \u2502 "}),jsxs(Text,{color:e.dim,children:["#",M.slice(0,30)]})]})]}),jsxs(Box,{children:[jsx(Text,{color:e.ghost,children:"\u2502 "}),jsx(Text,{color:t.color,bold:true,wrap:"truncate",children:t.text.slice(0,W)})]}),jsx(Box,{children:jsxs(Text,{color:e.ghost,children:["\u251C",Te(W+2),"\u2524"]})}),G.map((L,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&&L.includes('"')?e.cyan:C&&/^\s*[}\]]/.test(L)?e.ghost:L.startsWith("error")||L.startsWith("Error")?e.red:e.silver,children:L.slice(0,C?W-4:W)})]},j)),jsx(Box,{children:jsxs(Text,{color:e.ghost,children:["\u2570",Te(W+2),"\u256F"]})})]})}function Yo({label:t,width:n,suffix:o,suffixLen:r=0}){let l=` ${t} `,f=3,b=f+l.length+2;if(!o){let y=Math.max(0,n-b);return jsxs(Box,{paddingX:1,children:[jsx(Text,{color:e.ghost,children:He(f)}),jsx(Text,{backgroundColor:"#1a1a22",color:e.dim,bold:true,children:l}),jsx(Text,{color:e.ghost,children:He(y)})]})}let T=2,x=Math.max(0,n-b-T-r);return jsxs(Box,{paddingX:1,children:[jsx(Text,{color:e.ghost,children:He(f)}),jsx(Text,{backgroundColor:"#1a1a22",color:e.dim,bold:true,children:l}),jsx(Text,{color:e.ghost,children:He(T)}),o,jsx(Text,{color:e.ghost,children:He(x)})]})}function Bc({task:t,width:n,resizeHint:o}){let r=" DETAIL ",l=o?` ${o} `:"",f=n-r.length-l.length-10,b=t.title.length>f?t.title.slice(0,f-3)+"...":t.title,T=Math.max(0,n-3-r.length-b.length-l.length-4);return jsxs(Box,{paddingX:1,children:[jsx(Text,{color:e.ghost,children:He(3)}),jsx(Text,{backgroundColor:"#2d1f0a",color:e.amber,bold:true,children:r}),jsxs(Text,{color:e.ghost,children:[_o," "]}),jsx(Text,{color:e.white,bold:true,children:b}),jsxs(Text,{color:e.ghost,children:[" ",He(Math.max(0,T))]}),l?jsx(Text,{color:e.dim,children:l}):null]})}function Ec({agent:t,width:n,resizeHint:o}){let r=" AGENT ",l=o?` ${o} `:"",f=n-r.length-l.length-10,b=t.name.length>f?t.name.slice(0,f-3)+"...":t.name,T=Math.max(0,n-3-r.length-b.length-l.length-4);return jsxs(Box,{paddingX:1,children:[jsx(Text,{color:e.ghost,children:He(3)}),jsx(Text,{backgroundColor:"#0f2d1f",color:e.green,bold:true,children:r}),jsxs(Text,{color:e.ghost,children:[_o," "]}),jsx(Text,{color:e.green,bold:true,children:b}),jsxs(Text,{color:e.ghost,children:[" ",He(Math.max(0,T))]}),l?jsx(Text,{color:e.dim,children:l}):null]})}function Lc({agent:t,height:n,state:o,taskTitleMap:r,teamName:l}){let f=Oc[t.status]??e.dim;Object.values(o.running).find(y=>y.agent_id===t.id);let T=t.current_task?r.get(t.current_task):void 0,x=24;return jsxs(Box,{flexDirection:"column",paddingX:2,children:[jsxs(Box,{children:[jsxs(Box,{width:x,children:[jsx(Text,{color:e.dim,children:" status "}),jsx(Text,{color: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:[gn," ON"]})]})}),t.config.skills&&t.config.skills.length>0&&jsxs(Box,{children:[jsx(Text,{color:e.dim,children:" skills "}),jsx(Text,{color:e.cyan,wrap:"truncate",children:tt(t.config.skills.join(", "),500)})]}),t.last_error&&(()=>{let y=t.last_error.kind,S=m[y],M=!S||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"]}),S&&jsx(Text,{color:e.white,children:S.message}),S&&jsx(Text,{color:e.cyan,children:S.fix}),S?.doctorHint&&jsx(Text,{color:e.yellow,children:"\u0414\u0438\u0430\u0433\u043D\u043E\u0441\u0442\u0438\u043A\u0430: orch doctor"}),M&&t.last_error.message&&jsx(Text,{color:e.dim,children:tt(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,n-(t.last_error?10:4))).map((y,S)=>jsxs(Text,{color:e.silver,wrap:"truncate",children:[" ",tt(y,500)]},S)):jsx(Text,{color:e.dim,children:" No role description."})]})}var Oc={idle:e.dim,running:e.green,error:e.red,disabled:e.ghost},Pc="\u2588";function Nc({mode:t,width:n}){let r=` ${t==="command"?"COMMAND":"NEW TASK"} `,l=Math.max(0,n-3-r.length-2);return jsxs(Box,{paddingX:1,children:[jsx(Text,{color:e.ghost,children:He(3)}),jsx(Text,{backgroundColor:"#2d1f0a",color:e.amber,bold:true,children:r}),jsx(Text,{color:e.ghost,children:He(l)})]})}function Dc({mode:t,value:n,width:o}){let r=t==="command"?"/":"\u25B8",l=Math.max(10,o-8),f=n.length>l?n.slice(-l):n;return jsxs(Box,{paddingX:2,children:[jsxs(Text,{color:e.amber,children:[r," "]}),jsx(Text,{color:e.white,children:f}),jsx(Text,{color:e.amber,children:Pc})]})}function Ji(t,n){if(!n||typeof n!="object")return "";let o=n;if(o.file_path&&typeof o.file_path=="string")return o.file_path.split("/").slice(-2).join("/");if(o.command&&typeof o.command=="string")return o.command.slice(0,60);if(o.pattern&&typeof o.pattern=="string")return `"${o.pattern.slice(0,40)}"`;if(o.glob&&typeof o.glob=="string")return o.glob.slice(0,40);let r=JSON.stringify(o);return r.length>80?r.slice(0,77)+"...":r}function Zo(t,n=200){if(typeof t=="string")return t.slice(0,n);if(!Array.isArray(t))return null;let o=[],r=0;for(let l of t){if(r>=n)break;if(l?.type==="text"&&typeof l.text=="string"){let f=l.text.split(`
|
|
17
|
+
`).find(b=>b.trim().length>0)??"";o.push(f.slice(0,n-r)),r+=f.length;}else if(l?.type==="tool_use"){let f=Ji(l.name??"tool",l.input),b=`\u2699 ${l.name??"tool"}(${f})`;o.push(b),r+=b.length;}else if(l?.type==="tool_result")o.push("\u2190 (result)"),r+=10;else if(l?.type==="thinking"&&typeof l.thinking=="string"){let f=l.thinking.slice(0,60).split(`
|
|
18
|
+
`)[0]??"";o.push(`\u{1F4AD} ${f}`),r+=f.length+3;}}return o.length>0?o.join(" "):null}function ji(t){if(typeof t=="string"){let o=t.split(`
|
|
19
|
+
`).length,r=t.split(`
|
|
20
|
+
`).find(l=>l.trim().length>0)??"";return o>3?`${r.slice(0,80)}... (${o} lines)`:r.slice(0,120)}if(!Array.isArray(t))return "(result)";let n=[];for(let o of t)if(o?.type==="tool_result"){o.tool_use_id?o.tool_use_id.slice(0,8):"";let l=o.is_error,f=typeof o.content=="string"?o.content:"",b=f.split(`
|
|
21
|
+
`).length;l?n.push(`\u2715 error: ${f.slice(0,60)}`):b>3?n.push(`\u2713 ${b} lines`):n.push(`\u2713 ${f.slice(0,80)}`);}else o?.type==="text"&&typeof o.text=="string"&&n.push(o.text.split(`
|
|
22
|
+
`)[0]?.slice(0,80)??"");return n.join(" ")||"(result)"}function Qi(t){let n=()=>t.length>er?t.slice(0,er)+"\u2026":t;if(Xi.test(t.trim()))return {summary:t.trim(),detail:n()};try{let o=JSON.parse(t);if(o.type==="message"&&o.role==="assistant"){let r=Zo(o.content);return r?{summary:r.slice(0,200),detail:n()}:{summary:null,detail:""}}if(o.type==="assistant"||o.role==="assistant"){let r=o.message?.content??o.content,l=Zo(r);return l?{summary:l.slice(0,200),detail:n()}:{summary:null,detail:""}}if(o.type==="user"||o.role==="user"){let r=o.message?.content??o.content;return {summary:`\u2190 ${ji(r).slice(0,180)}`,detail:n()}}if(o.type==="tool_use"||typeof o.name=="string"&&"input"in o){let r=o.name??"tool",l=Ji(r,o.input);return {summary:`\u2699 ${r}(${l})`,detail:n()}}if(o.type==="tool_result")return {summary:`\u2190 ${ji(o.content).slice(0,180)}`,detail:n()};if(o.type==="result"){let r=typeof o.result=="string"?o.result:null;return {summary:r?`\u2713 ${r.slice(0,180)}`:"\u2713 Agent finished",detail:n()}}if(o.type==="rate_limit_event")return {summary:`\u23F3 Rate limited (${o.rate_limit_info?.rateLimitType??"unknown"})`,detail:n()};if(o.subtype){if(o.message){let r=o.message.content??o.message,l=Zo(r);if(l)return {summary:l.slice(0,200),detail:n()}}return {summary:`[${o.subtype}]`,detail:n()}}if(o.content){let r=Zo(o.content);if(r)return {summary:r.slice(0,200),detail:n()}}return o.type?{summary:`[${o.type}]`,detail:n()}:{summary:t.slice(0,150),detail:n()}}catch{return {summary:Fc(t),detail:n()}}}function Fc(t){let n=t.match(/"subtype"\s*:\s*"([^"]+)"/);if(n)return `[${n[1]}]`;let o=t.match(/"type"\s*:\s*"([^"]+)"/),r=t.match(/"role"\s*:\s*"([^"]+)"/),l=o?.[1],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 Wc(t,n,o,r){let l=f=>r?.get(f);switch(t.type){case "agent:started":n("Started task",e.green,{agentId:t.agentId,taskId:t.taskId,msgType:"lifecycle"});break;case "agent:output":{let{summary:f,detail:b}=Qi(t.data);if(f){let T=qi(f);n(f,T.color,{agentId:t.agentId,taskId:l(t.runId),detail:b,msgType:T.msgType});}break}case "agent:file_changed":n(`${t.path}`,e.purple,{agentId:t.agentId,taskId:l(t.runId),msgType:"file"});break;case "agent:completed":n(t.success?"Completed successfully":"Failed",t.success?e.green:e.red,{agentId:t.agentId,taskId:l(t.runId),msgType:"lifecycle"});break;case "agent:error":n(`${t.error.slice(0,150)}`,e.red,{agentId:t.agentId,taskId:l(t.runId),detail:t.error,msgType:"error"});break;case "task:status_changed":n(`${t.from} \u2192 ${t.to}`,e.cyan,{taskId:t.taskId,msgType:"system"});break;case "task:assigned":n(`Assigned \u2192 ${t.agentId}`,e.cyan,{taskId:t.taskId,msgType:"system"});break;case "task:created":n(`Created: ${t.task.title}`,e.amber,{taskId:t.task.id,msgType:"system"});break;case "run:retry":n(`Retry #${t.attempt} (${Math.round(t.delay_ms/1e3)}s delay)`,e.yellow,{agentId:o?.get(t.runId),taskId:l(t.runId),msgType:"lifecycle"});break;case "orchestrator:tick":(t.running>0||t.queued>0)&&n(`${t.running} running \xB7 ${t.queued} queued`,e.ghost,{msgType:"system"});break;case "orchestrator:stall_detected":n("Stall detected",e.yellow,{agentId:o?.get(t.runId),taskId:l(t.runId),msgType:"error"});break;case "task:cascade_failed":n(`Cascade failed (dep: ${t.failedDependencyId})`,e.red,{taskId:t.taskId,detail:t.reason,msgType:"error"});break}}export{eg as App,Qu as _resetPendingDeletionSeq};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import i from'fs/promises';import {readFileSync,mkdirSync,writeFileSync}from'fs';import u from'path';import y from'os';import {execFile}from'child_process';var p="@oxgeneral/orch",o=u.join(y.homedir(),".orchestry"),s=u.join(o,"update-check.json"),c=14400*1e3,b=c*.75;function A(t,e){let r=t.split(".").map(Number),n=e.split(".").map(Number);for(let a=0;a<3;a++){let d=(r[a]??0)-(n[a]??0);if(d!==0)return d>0?1:-1}return 0}async function N(){try{let t=await i.readFile(s,"utf-8"),e=JSON.parse(t);if(Date.now()-e.checked_at<c)return e}catch{}return null}async function S(t){await i.mkdir(o,{recursive:true});let e={latest:t,checked_at:Date.now()},r=`${s}.tmp.${process.pid}`;await i.writeFile(r,JSON.stringify(e),"utf-8"),await i.rename(r,s);}function U(){return new Promise(t=>{execFile("npm",["view",p,"version","--json"],{timeout:5e3},(r,n)=>{if(r)return t(null);try{t(JSON.parse(n.trim()));}catch{t(null);}}).unref();})}function g(t,e){return {current:t,latest:e,updateAvailable:A(e,t)>0}}async function f(t){let e=await U();return e?(await S(e).catch(()=>{}),g(t,e)):null}async function P(t){try{let e=await N();return e?(Date.now()-e.checked_at>=b&&f(t).catch(()=>{}),g(t,e.latest)):f(t).catch(()=>null)}catch{return null}}function R(t){if(!t.updateAvailable)return;let e=`
|
|
3
|
+
Update available: ${t.current} \u2192 ${t.latest}
|
|
4
|
+
Run: npm install -g ${p}
|
|
5
|
+
`;process.stderr.write(e);}var l=u.join(o,"update-installed.json");function v(t){return new Promise(e=>{try{let n=JSON.parse(readFileSync(l,"utf-8"));if(n.version===t&&Date.now()-n.installed_at<c){e(!1);return}}catch{}execFile("npm",["install","-g",`${p}@${t}`],{timeout:6e4},n=>{n||(mkdirSync(o,{recursive:true}),writeFileSync(l,JSON.stringify({version:t,installed_at:Date.now()}))),e(!n);});})}function x(t){try{let e=JSON.parse(readFileSync(l,"utf-8"));return e.version!==t&&Date.now()-e.installed_at<c}catch{return false}}export{f as a,P as b,R as c,v as d,x as e};
|
|
@@ -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};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AUTONOMOUS_LABEL, DEFAULT_SYSTEM_TEMPLATE, DEFAULT_USER_TEMPLATE, buildPromptContext } from './chunk-
|
|
1
|
+
import { AUTONOMOUS_LABEL, DEFAULT_SYSTEM_TEMPLATE, DEFAULT_USER_TEMPLATE, buildPromptContext } from './chunk-XUZZJCKG.js';
|
|
2
2
|
import { createTokenUsage } from './chunk-RHFRHCN5.js';
|
|
3
3
|
import { LockConflictError, WorkspaceError, TaskAlreadyRunningError, NoAgentsError, classifyAdapterError } from './chunk-NLQAJ7TW.js';
|
|
4
4
|
import { dirname } from 'path';
|
|
@@ -363,7 +363,7 @@ var ReviewRunner = class {
|
|
|
363
363
|
// src/application/orchestrator.ts
|
|
364
364
|
var MAX_EVENT_DATA_LEN = 8192;
|
|
365
365
|
var MAX_BUS_DATA_LEN = 4096;
|
|
366
|
-
var Orchestrator = class {
|
|
366
|
+
var Orchestrator = class _Orchestrator {
|
|
367
367
|
constructor(deps) {
|
|
368
368
|
this.deps = deps;
|
|
369
369
|
this.cachedTaskStore = new CachedTaskStore(deps.taskStore);
|
|
@@ -390,6 +390,10 @@ var Orchestrator = class {
|
|
|
390
390
|
stoppedResolvers = [];
|
|
391
391
|
/** When true, `tick()` skips `seedAutonomousTasks()`. Set via `startWatch()` options. */
|
|
392
392
|
skipAutonomousSeeding = false;
|
|
393
|
+
/** Cooldown: track last auto-seed time per agent to prevent re-seed spam. */
|
|
394
|
+
lastAutoSeedAt = /* @__PURE__ */ new Map();
|
|
395
|
+
/** Minimum interval between auto-seed tasks for the same agent (30 seconds). */
|
|
396
|
+
static AUTO_SEED_COOLDOWN_MS = 3e4;
|
|
393
397
|
/** Promise-chain mutex to serialize critical state mutations. */
|
|
394
398
|
stateMutex = Promise.resolve();
|
|
395
399
|
/**
|
|
@@ -863,6 +867,8 @@ var Orchestrator = class {
|
|
|
863
867
|
(t) => t.assignee === agent.id && !isTerminal(t.status)
|
|
864
868
|
);
|
|
865
869
|
if (hasActiveTask) continue;
|
|
870
|
+
const lastSeed = this.lastAutoSeedAt.get(agent.id) ?? 0;
|
|
871
|
+
if (Date.now() - lastSeed < _Orchestrator.AUTO_SEED_COOLDOWN_MS) continue;
|
|
866
872
|
const goal = activeGoals.find(
|
|
867
873
|
(g) => g.assignee === agent.id && !claimedGoalIds.has(g.id)
|
|
868
874
|
) ?? activeGoals.find(
|
|
@@ -886,6 +892,7 @@ Agent role: ${role}` : `Autonomous work cycle. Agent role: ${role}`;
|
|
|
886
892
|
priority: 3,
|
|
887
893
|
goalId: goal?.id
|
|
888
894
|
});
|
|
895
|
+
this.lastAutoSeedAt.set(agent.id, Date.now());
|
|
889
896
|
anyCreated = true;
|
|
890
897
|
} catch (err) {
|
|
891
898
|
this.deps.eventBus.emit({
|
|
@@ -952,8 +959,9 @@ Agent role: ${role}` : `Autonomous work cycle. Agent role: ${role}`;
|
|
|
952
959
|
const updated = { ...withAttempt, status: nextStatus };
|
|
953
960
|
await this.deps.taskStore.save(updated);
|
|
954
961
|
if (nextStatus === "failed") {
|
|
955
|
-
const
|
|
956
|
-
|
|
962
|
+
const patchedTasks = allTasks.map((at) => at.id === updated.id ? updated : at);
|
|
963
|
+
this.cachedTaskStore.invalidate();
|
|
964
|
+
await this.cascadeFailDependents(updated.id, patchedTasks, `dependency ${updated.id} failed: ${err.message}`);
|
|
957
965
|
} else {
|
|
958
966
|
const delay = calculateRetryDelay(
|
|
959
967
|
updated.attempts - 1,
|
|
@@ -1318,10 +1326,14 @@ Agent role: ${role}` : `Autonomous work cycle. Agent role: ${role}`;
|
|
|
1318
1326
|
if (!state.running[taskId]) return;
|
|
1319
1327
|
const task = await this.deps.taskStore.get(taskId);
|
|
1320
1328
|
if (!task) return;
|
|
1329
|
+
let effectiveFilesChanged = filesChanged;
|
|
1330
|
+
if ((!effectiveFilesChanged || effectiveFilesChanged.length === 0) && task.proof?.branch) {
|
|
1331
|
+
effectiveFilesChanged = await this.deps.workspaceManager.getChangedFiles(task.proof.branch);
|
|
1332
|
+
}
|
|
1321
1333
|
task.proof = {
|
|
1322
1334
|
...task.proof,
|
|
1323
1335
|
agent_summary: resultText?.slice(0, 2e3) ?? task.proof?.agent_summary,
|
|
1324
|
-
files_changed:
|
|
1336
|
+
files_changed: effectiveFilesChanged?.length ? effectiveFilesChanged : task.proof?.files_changed ?? []
|
|
1325
1337
|
};
|
|
1326
1338
|
delete task.feedback;
|
|
1327
1339
|
await this.deps.taskStore.save(task);
|
|
@@ -1476,6 +1488,7 @@ Agent role: ${role}` : `Autonomous work cycle. Agent role: ${role}`;
|
|
|
1476
1488
|
});
|
|
1477
1489
|
} else {
|
|
1478
1490
|
state.stats.total_tasks_failed++;
|
|
1491
|
+
this.cachedTaskStore.invalidate();
|
|
1479
1492
|
const allTasks = await this.cachedTaskStore.list();
|
|
1480
1493
|
await this.cascadeFailDependents(taskId, allTasks, `dependency ${taskId} failed: ${error}`);
|
|
1481
1494
|
}
|
|
@@ -1702,5 +1715,5 @@ function serializeEventData(data, maxLen) {
|
|
|
1702
1715
|
}
|
|
1703
1716
|
|
|
1704
1717
|
export { Orchestrator, canTransition, isBlocked, isDispatchable, isTerminal, resolveFailureStatus };
|
|
1705
|
-
//# sourceMappingURL=chunk-
|
|
1706
|
-
//# sourceMappingURL=chunk-
|
|
1718
|
+
//# sourceMappingURL=chunk-OLKQBQ4I.js.map
|
|
1719
|
+
//# sourceMappingURL=chunk-OLKQBQ4I.js.map
|