@oxgeneral/orch 0.3.3 → 1.0.0

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.
Files changed (131) hide show
  1. package/dist/App-GJVTVGRU.js +6717 -0
  2. package/dist/agent-7ZJ3ZDJ7.js +183 -0
  3. package/dist/agent-shop-YN2BSLHM.js +2 -0
  4. package/dist/chunk-2C2TFQ7K.js +136 -0
  5. package/dist/chunk-45K2XID7.js +29 -0
  6. package/dist/chunk-4IFIOMCW.js +86 -0
  7. package/dist/chunk-7X2GI5OV.js +181 -0
  8. package/dist/{chunk-S3QYSBW4.js → chunk-C6XZ3FJT.js} +6 -3
  9. package/dist/chunk-C6XZ3FJT.js.map +1 -0
  10. package/dist/chunk-CHIP7O6V.js +83 -0
  11. package/dist/{chunk-BCPUTULS.js → chunk-DAVHOWGD.js} +188 -16
  12. package/dist/chunk-FRTKB575.js +87 -0
  13. package/dist/{chunk-BGHCY7WY.js → chunk-GBXUNDKN.js} +32 -13
  14. package/dist/chunk-GBXUNDKN.js.map +1 -0
  15. package/dist/chunk-HXYAZGLP.js +15 -0
  16. package/dist/chunk-I3SMISEF.js +29 -0
  17. package/dist/chunk-K6DMQERQ.js +89 -0
  18. package/dist/chunk-LV6GDBBI.js +297 -0
  19. package/dist/chunk-MGGSRXWJ.js +69 -0
  20. package/dist/chunk-P6ATSXGL.js +107 -0
  21. package/dist/chunk-PNE6LQRF.js +5 -0
  22. package/dist/chunk-U2VDNUZL.js +52 -0
  23. package/dist/chunk-VG4465AG.js +275 -0
  24. package/dist/chunk-VG4465AG.js.map +1 -0
  25. package/dist/{chunk-B4JQM4NU.js → chunk-VXS2CJFH.js} +119 -47
  26. package/dist/chunk-XJTJ2TJV.js +221 -0
  27. package/dist/{claude-INM52PTH.js → claude-WUJU5KIE.js} +6 -5
  28. package/dist/claude-WUJU5KIE.js.map +1 -0
  29. package/dist/claude-ZUEKJJ4X.js +5 -0
  30. package/dist/cli.js +199 -1
  31. package/dist/clipboard-service-RTDUUQQU.js +200 -0
  32. package/dist/codex-7IXXXG5U.js +123 -0
  33. package/dist/{codex-QGH2GRV6.js → codex-NYJWEPRQ.js} +4 -4
  34. package/dist/codex-NYJWEPRQ.js.map +1 -0
  35. package/dist/config-OTAVSMOD.js +75 -0
  36. package/dist/container-LUWGNBSS.js +1596 -0
  37. package/dist/context-OL4BVUV5.js +83 -0
  38. package/dist/{cursor-KQJTQ73D.js → cursor-3YHVD4NP.js} +4 -4
  39. package/dist/cursor-3YHVD4NP.js.map +1 -0
  40. package/dist/cursor-622RBRHH.js +97 -0
  41. package/dist/doctor-XSGQSD57.js +67 -0
  42. package/dist/doctor-service-TPOMFAIG.js +2 -0
  43. package/dist/goal-FMYYN2FR.js +138 -0
  44. package/dist/index.d.ts +16 -2
  45. package/dist/index.js +25 -16
  46. package/dist/index.js.map +1 -1
  47. package/dist/init-JU343RXK.js +165 -0
  48. package/dist/logs-PHPYWQ6I.js +207 -0
  49. package/dist/msg-FUWWLEKM.js +95 -0
  50. package/dist/opencode-FAMPSA6X.js +100 -0
  51. package/dist/opencode-FAMPSA6X.js.map +1 -0
  52. package/dist/opencode-WOR53TSC.js +98 -0
  53. package/dist/orchestrator-IYWBVA7J.js +5 -0
  54. package/dist/{orchestrator-KF4UY5GD.js.map → orchestrator-IYWBVA7J.js.map} +1 -1
  55. package/dist/orchestrator-QNAD7MFH.js +1433 -0
  56. package/dist/process-manager-HUVNAPQV.js +2 -0
  57. package/dist/registry-PQWRVNF2.js +2 -0
  58. package/dist/run-N72G5V2H.js +95 -0
  59. package/dist/shell-DVFHHYAZ.js +5 -0
  60. package/dist/{shell-UXJNTNBC.js → shell-NJNW3O6K.js} +6 -4
  61. package/dist/shell-NJNW3O6K.js.map +1 -0
  62. package/dist/shop-picker-2HY67UWP.js +79 -0
  63. package/dist/status-RZWN2C6C.js +56 -0
  64. package/dist/task-3O2OFSP6.js +221 -0
  65. package/dist/team-PFLP4PPL.js +97 -0
  66. package/dist/template-engine-5ZKVJMYA.js +3 -0
  67. package/dist/{template-engine-MFL5B677.js.map → template-engine-5ZKVJMYA.js.map} +1 -1
  68. package/dist/template-engine-AWIS56BL.js +3 -0
  69. package/dist/tui-LN5XHSQY.js +245 -0
  70. package/dist/update-YLP7FPNY.js +64 -0
  71. package/dist/update-check-4YKLGBFB.js +2 -0
  72. package/dist/workspace-manager-JM6U7JOH.js +215 -0
  73. package/package.json +2 -1
  74. package/readme.md +11 -4
  75. package/scripts/load-test.ts +478 -0
  76. package/scripts/postinstall.js +44 -2
  77. package/dist/App-NN7HR7UE.js +0 -20
  78. package/dist/agent-S4DKSX63.js +0 -9
  79. package/dist/agent-shop-D2RS4BZK.js +0 -2
  80. package/dist/chunk-3MQNQ7QW.js +0 -2
  81. package/dist/chunk-5AJ4LYO5.js +0 -8
  82. package/dist/chunk-6MJ7V6VY.js +0 -2
  83. package/dist/chunk-B4JQM4NU.js.map +0 -1
  84. package/dist/chunk-BGHCY7WY.js.map +0 -1
  85. package/dist/chunk-CDFA4IIQ.js +0 -2
  86. package/dist/chunk-CHRW4CLD.js +0 -2
  87. package/dist/chunk-HMMPM7MF.js +0 -3
  88. package/dist/chunk-HSBYJ5C5.js +0 -112
  89. package/dist/chunk-HXOMNULD.js +0 -2
  90. package/dist/chunk-IS3YBE2B.js +0 -3
  91. package/dist/chunk-KPCT44WU.js +0 -2
  92. package/dist/chunk-L26TK7Y5.js +0 -2
  93. package/dist/chunk-LXNRCJ22.js +0 -2
  94. package/dist/chunk-OQKREZUF.js +0 -11
  95. package/dist/chunk-PJ5DKXGR.js +0 -2
  96. package/dist/chunk-QFKVCNKL.js +0 -2
  97. package/dist/chunk-S3QYSBW4.js.map +0 -1
  98. package/dist/chunk-UMZEA3JT.js +0 -5
  99. package/dist/claude-GQZNDJ6L.js +0 -2
  100. package/dist/claude-INM52PTH.js.map +0 -1
  101. package/dist/clipboard-service-MYLSWM5E.js +0 -25
  102. package/dist/codex-QGH2GRV6.js.map +0 -1
  103. package/dist/codex-SJV7ZZBY.js +0 -2
  104. package/dist/config-CCSS2P7R.js +0 -2
  105. package/dist/container-NEKK5W2B.js +0 -6
  106. package/dist/context-GSMQHQES.js +0 -7
  107. package/dist/cursor-4JQOCP5X.js +0 -2
  108. package/dist/cursor-KQJTQ73D.js.map +0 -1
  109. package/dist/doctor-UAII4VWN.js +0 -2
  110. package/dist/doctor-service-PB7YBH3F.js +0 -2
  111. package/dist/goal-RFKFPR7M.js +0 -8
  112. package/dist/init-2D4RAN7B.js +0 -53
  113. package/dist/logs-UXFXVYCP.js +0 -12
  114. package/dist/msg-4SCLBO4K.js +0 -9
  115. package/dist/orchestrator-KF4UY5GD.js +0 -5
  116. package/dist/orchestrator-MFL3XK5L.js +0 -13
  117. package/dist/process-manager-33H27MQF.js +0 -2
  118. package/dist/registry-BO2PPRNG.js +0 -2
  119. package/dist/run-HSHRELOP.js +0 -3
  120. package/dist/shell-F42UUF3U.js +0 -2
  121. package/dist/shell-UXJNTNBC.js.map +0 -1
  122. package/dist/shop-picker-LE3SKFOX.js +0 -5
  123. package/dist/status-DLBNWSWM.js +0 -2
  124. package/dist/task-AP2TIOOF.js +0 -20
  125. package/dist/team-MSIBKOQC.js +0 -4
  126. package/dist/template-engine-MFL5B677.js +0 -3
  127. package/dist/template-engine-ONIDVD4F.js +0 -2
  128. package/dist/tui-PIQT4ZZ2.js +0 -2
  129. package/dist/update-PC2ENCKU.js +0 -2
  130. package/dist/update-check-HGMBDYHL.js +0 -2
  131. package/dist/workspace-manager-DYN3XJ7X.js +0 -3
@@ -1,20 +0,0 @@
1
- #!/usr/bin/env node
2
- import {a}from'./chunk-PJ5DKXGR.js';import {c,a as a$1}from'./chunk-HXOMNULD.js';import {b,a as a$2}from'./chunk-BCPUTULS.js';import {f,g}from'./chunk-L26TK7Y5.js';import Xn,{useState,useEffect,useMemo,useRef,useCallback}from'react';import {Box,Text,useApp,useStdout,useInput}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"},Mn="\u2501",Ut="\u2500",ct="\xB7",Ht="\u25C8",go="\u2605",Bt="\u27F3",wt="\u25C6",Rn={in_progress:e.green,retrying:e.yellow,review:e.blue,todo:e.dim,done:e.green,failed:e.red,cancelled:e.dim},Jo=new Map,Qo=new Map;function Me(t){if(t<=0)return "";let n=Jo.get(t);return n||(n=Mn.repeat(t),Jo.set(t,n)),n}function Pe(t){if(t<=0)return "";let n=Qo.get(t);return n||(n=Ut.repeat(t),Qo.set(t,n)),n}function mt(t,n){return t.length>n?t.slice(0,n-1)+"\u2026":t}var ti=1e4;function mo(t,n=ti){if(t)return t.length>n?t.slice(0,n)+`
3
- \u2026[truncated]`:t}var er={active:e.green,paused:e.dim,achieved:e.amber,abandoned:e.ghost};var ri=120,po=0,un=null,Bn=new Set;function si(){un||(un=setInterval(()=>{po++;for(let t of Bn)t(po);},ri));}function ii(){un&&Bn.size===0&&(clearInterval(un),un=null);}function Xt(){let[t,n]=useState(po);return useEffect(()=>{let o=a=>n(a);return Bn.add(o),si(),()=>{Bn.delete(o),ii();}},[]),t}var tr=["\u280B","\u2819","\u2839","\u2838","\u283C","\u2834","\u2826","\u2827","\u2807","\u280F"];function qt({color:t}){let n=Xt();return jsx(Text,{color:t,children:tr[n%tr.length]})}var gn={in_progress:0,retrying:1,review:2,todo:3,done:4,failed:5,cancelled:6};var di="\u25CB",or="\u2713",rr="\u2715",ui="\u21BB",gi="\u2500",mi="\u25B6",St={green:"#0f2d1f",blue:"#0f1f2d",yellow:"#2d2a0f",red:"#2d0f0f",neutral:"#1a1a22"},pi={in_progress:{icon:mi,label:"RUN",fg:e.green,bg:St.green,bold:true,spinner:true},retrying:{icon:ui,label:"RETRY",fg:e.yellow,bg:St.yellow,spinner:true},review:{icon:Ht,label:"REVIEW",fg:e.blue,bg:St.blue},todo:{icon:di,label:"TODO",fg:e.dim,bg:St.neutral},done:{icon:or,label:"DONE",fg:e.green,bg:St.green},failed:{icon:rr,label:"FAIL",fg:e.red,bg:St.red,bold:true},cancelled:{icon:gi,label:"OFF",fg:e.dim,bg:St.neutral}},fi={1:{color:e.red,label:"!!!"},2:{color:e.yellow,label:"!!"},3:{color:e.dim,label:"!"},4:{color:e.ghost,label:ct}};var En=Xn.memo(function({task:n,selected:o,width:a,agentNameMap:d}){let p=pi[n.status],w=n.status==="in_progress"||n.status==="retrying",T=fi[n.priority]??{color:e.ghost,label:ct},b,x;if(n.status==="done")b=or,x=e.green;else if(n.status==="failed")b=rr,x=e.red;else if(w){let z=Date.now()-new Date(n.updated_at).getTime();b=f(z),x=e.cyan;}else b="\u2014",x=void 0;let k=o?"\u25B8":" ",v=10,O=4,P=14,X=7,N=2+v+O+P+X,F=a?Math.max(10,a-N):40,W=n.assignee?d?.get(n.assignee)??n.assignee:void 0;return jsxs(Box,{children:[jsxs(Text,{color:o?e.amber:void 0,children:[k," "]}),jsx(Box,{width:v,children:jsx(Text,{backgroundColor:p.bg,color:p.fg,bold:p.bold,children:p.spinner?jsxs(Fragment,{children:[" ",jsx(qt,{color:p.fg})," ",p.label," "]}):jsxs(Fragment,{children:[" ",p.icon," ",p.label," "]})})}),jsx(Box,{width:O,children:jsx(Text,{color:T.color,bold:n.priority<=2,children:T.label})}),jsxs(Box,{width:F,children:[jsx(Text,{wrap:"truncate",bold:o||w,color:o?e.white:w?e.silver:void 0,children:n.title.length>F?n.title.slice(0,F-1)+"\u2026":n.title}),(n.attachments?.length??0)>0&&jsxs(Text,{color:e.dim,children:[" ","\u{1F4CE}",n.attachments.length]})]}),jsx(Box,{width:P,children:W?jsxs(Text,{backgroundColor:St.green,color:e.green,wrap:"truncate",children:[" ",W.length>P-2?W.slice(0,P-3)+"\u2026":W," "]}):jsx(Text,{color:e.ghost,children:"\u2014"})}),jsx(Box,{width:X,justifyContent:"flex-end",children:jsx(Text,{color:x,dimColor:!x,children:b})})]})});var bi="\u2715",sr="\u25CB",Ti="\u25B6",yi="\u2713",Ct={green:"#0f2d1f",red:"#2d0f0f",neutral:"#1a1a22",amber:"#2d1f0a"},wi={running:{icon:Ti,label:"ACTIVE",fg:e.green,bg:Ct.green,bold:true,spinner:true},idle:{icon:sr,label:"IDLE",fg:e.dim,bg:Ct.neutral},error:{icon:bi,label:"ERROR",fg:e.red,bg:Ct.red,bold:true},disabled:{icon:sr,label:"OFF",fg:e.ghost,bg:Ct.neutral}},fo={running:0,idle:1,error:2,disabled:3},ar=Xn.memo(function({agent:n,selected:o,width:a,runningEntry:d,currentTaskTitle:p,teamName:w,isLead:T}){let b=wi[n.status],x=n.status==="running",k,v;if(x&&d){let R=Date.now()-new Date(d.started_at).getTime();k=f(R),v=e.cyan;}else n.stats.total_runs>0?(k=`${n.stats.tasks_completed}/${n.stats.total_runs}`,v=n.stats.tasks_completed>0?e.green:e.dim):(k="\u2014",v=void 0);let O=o?"\u25B8":" ",P=11,X=10,N=w?Math.min(w.length+2,14):0,F=Math.max(6,22-N),W=7,z=2+P+X+N+F+W,K=a?Math.max(8,a-z):20,j,G,_=false;x&&p?(j=p,G=e.white,_=true):n.role?(j=n.role,G=e.dim):(j="\u2014",G=e.ghost);let $=n.stats.total_runs>0,A=$?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:[O," "]}),jsx(Box,{width:P,children:jsx(Text,{backgroundColor:b.bg,color:b.fg,bold:b.bold,children:b.spinner?jsxs(Fragment,{children:[" ",jsx(qt,{color:b.fg})," ",b.label," "]}):jsxs(Fragment,{children:[" ",b.icon," ",b.label," "]})})}),jsx(Box,{width:K,children:jsxs(Text,{wrap:"truncate",bold:o||x,color:o?e.white:x?e.green:e.silver,children:[n.autonomous&&jsxs(Text,{color:e.cyan,children:[Bt," "]}),T&&jsxs(Text,{color:e.amber,children:[go," "]}),n.name]})}),jsx(Box,{width:X,children:jsxs(Text,{backgroundColor:Ct.neutral,color:e.dim,children:[" ",n.adapter," "]})}),w&&jsx(Box,{width:N,children:jsxs(Text,{backgroundColor:Ct.amber,color:e.amber,wrap:"truncate",children:[" ",w," "]})}),jsx(Box,{width:F,children:jsx(Text,{color:G,bold:_,wrap:"truncate",children:j})}),jsx(Box,{width:W,justifyContent:"flex-end",children:$&&!x?jsxs(Text,{color:A>=80?e.green:A>=50?e.yellow:e.red,children:[k," ",yi]}):jsx(Text,{color:v,dimColor:!v,children:k})})]})});function lr({teamName:t,memberCount:n,leadName:o,width:a}){let d=`${n} agent${n!==1?"s":""}`,p=o?` ${ct} ${go} ${o}`:"",w=` ${Ht} ${t.toUpperCase()} ${ct} ${d}${p} `,T=3,b=Math.max(0,a-T-w.length-4);return jsxs(Box,{paddingX:2,children:[jsx(Text,{color:e.ghost,children:Pe(T)}),jsx(Text,{backgroundColor:Ct.amber,color:e.amber,bold:true,children:w}),jsx(Text,{color:e.ghost,children:Pe(b)})]})}var Si="\u25C7";function cr({memberCount:t,width:n}){let o=`${t} agent${t!==1?"s":""}`,a=` ${Si} UNASSIGNED ${ct} ${o} `,d=3,p=Math.max(0,n-d-a.length-4);return jsxs(Box,{paddingX:2,children:[jsx(Text,{color:e.ghost,children:Pe(d)}),jsx(Text,{backgroundColor:Ct.neutral,color:e.dim,children:a}),jsx(Text,{color:e.ghost,children:Pe(p)})]})}var dr="\u2713",ur="\u2715",Ci="\u2016",Ii="\u25C9",pn={green:"#0f2d1f",amber:"#2d1f0a",neutral:"#1a1a22"},$i={active:{icon:Ii,label:"ACTIVE",fg:e.green,bg:pn.green,bold:true},paused:{icon:Ci,label:"PAUSED",fg:e.dim,bg:pn.neutral},achieved:{icon:dr,label:"DONE",fg:e.amber,bg:pn.amber,bold:true},abandoned:{icon:ur,label:"DROP",fg:e.ghost,bg:pn.neutral}},gr=Xn.memo(function({goal:n,selected:o,width:a,agentNameMap:d}){let p=$i[n.status],w=o?"\u25B8":" ",T=11,b=14,x=7,k=2+T+b+x,v=a?Math.max(10,a-k):40,O=n.assignee?d?.get(n.assignee)??n.assignee:void 0,P,X;if(n.status==="achieved")P=dr,X=e.amber;else if(n.status==="abandoned")P=ur,X=e.ghost;else {let N=Date.now()-new Date(n.created_at).getTime(),F=Math.floor(N/864e5);P=F>0?`${F}d`:"<1d",X=e.dim;}return jsxs(Box,{children:[jsxs(Text,{color:o?e.amber:void 0,children:[w," "]}),jsx(Box,{width:T,children:jsxs(Text,{backgroundColor:p.bg,color:p.fg,bold:p.bold,children:[" ",p.icon," ",p.label," "]})}),jsx(Box,{width:v,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>v?n.title.slice(0,v-1)+"\u2026":n.title})}),jsx(Box,{width:b,children:O?jsxs(Text,{backgroundColor:pn.green,color:e.green,wrap:"truncate",children:[" ",O.length>b-2?O.slice(0,b-3)+"\u2026":O," "]}):jsx(Text,{color:e.ghost,children:"\u2014"})}),jsx(Box,{width:x,justifyContent:"flex-end",children:jsx(Text,{color:X,dimColor:!X,children:P})})]})});var vi={system:"\u2666",lifecycle:"\u25B6",output:"\u2502",tool:"\u2699",result:"\u2190",error:"\u2715",file:"\u270E",info:"\u2502"};function Zt({label:t,width:n,color:o}){let a=n-4,d=` ${t} `,p=3,w=Math.max(0,a-p-d.length);return jsxs(Text,{color:o??e.ghost,children:[" ",Pe(p),d,Pe(w)]})}function mr({task:t,height:n,width:o,taskLogs:a,agentNameMap:d}){let p=Rn[t.status]??e.dim,w=t.priority<=2?t.priority===1?e.red:e.yellow:void 0,T=24,b=!!t.description?.trim(),x=!!t.proof?.agent_summary,k=(t.proof?.files_changed?.length??0)>0,v=(a?.length??0)>0,O=(t.attachments?.length??0)>0,P=b?t.description.split(`
4
- `):[],X=x?t.proof.agent_summary.split(`
5
- `):[],N=3;O&&(N+=2+t.attachments.length),b?(N+=1,N+=Math.min(P.length,Math.max(1,Math.ceil((n-10)*.3)))):x||(N+=2),x&&(N+=2),k&&(N+=1),v&&(N+=2);let F=Math.max(0,n-N),W=0,z=0;x&&v?(W=Math.max(1,Math.floor(F*.4)),z=Math.max(1,F-W)):x?W=F:v&&(z=F);let K=b?P.slice(0,Math.max(1,Math.ceil((n-10)*.3))):[],j=X.slice(0,W);return jsxs(Box,{flexDirection:"column",paddingX:2,children:[jsxs(Box,{children:[jsxs(Box,{width:T,children:[jsx(Text,{color:e.dim,children:" status "}),jsx(Text,{color:p,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?d?.get(t.assignee)??t.assignee:"\u2014"})]})]}),jsxs(Box,{children:[jsxs(Box,{width:T,children:[jsx(Text,{color:e.dim,children:" priority "}),jsxs(Text,{color:w,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:T,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.join(", "):"\u2014"})]})]}),O&&jsxs(Fragment,{children:[jsx(Text,{children:" "}),jsx(Zt,{label:`attachments (${t.attachments.length})`,width:o,color:e.dim}),t.attachments.map((G,_)=>jsxs(Text,{color:e.cyan,wrap:"truncate",children:[" ",G]},`a${_}`))]}),b&&jsxs(Fragment,{children:[jsx(Text,{children:" "}),K.map((G,_)=>jsxs(Text,{color:e.silver,wrap:"truncate",children:[" ",mt(G,o-8)]},`d${_}`))]}),!b&&!x&&jsxs(Fragment,{children:[jsx(Text,{children:" "}),jsx(Text,{color:e.dim,children:" No description."})]}),x&&jsxs(Fragment,{children:[jsx(Text,{children:" "}),jsx(Zt,{label:"result",width:o,color:e.dim}),j.map((G,_)=>jsxs(Text,{color:e.white,wrap:"truncate",children:[" ",mt(G,o-8)]},`r${_}`))]}),k&&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})]})]}),v&&jsxs(Fragment,{children:[jsx(Text,{children:" "}),jsx(Zt,{label:"activity",width:o,color:e.dim}),a.slice(-z).map((G,_)=>{let $=G.msgType??"info",A=vi[$]??"\u2502",R=G.color;$==="tool"?R=e.cyan:$==="file"?R=e.purple:$==="error"?R=e.red:$==="lifecycle"?R=e.green:$==="system"&&(R=e.dim);let pe=Math.max(10,o-12),ce=mt(G.text,pe);return jsxs(Box,{children:[jsxs(Text,{color:e.ghost,children:[" ",G.time," "]}),jsxs(Text,{color:$==="error"?e.red:e.dim,children:[A," "]}),jsx(Text,{color:R,bold:$==="lifecycle",children:ce})]},_)})]})]})}var Ln=[{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 _i="\u25CF",hr="\u25CB",Ai="\u2713",Mi="\u2715",Ri="\u2191",Bi="\u2193",Ei="\u03A3",Oi="\u25B6",Li="\u21BB",pr=["\u280B","\u2819","\u2839","\u2838","\u283C","\u2834","\u2826","\u2827","\u2807","\u280F"],ho=[" ","\u2581","\u2582","\u2583","\u2584","\u2585","\u2586","\u2587","\u2588"],Ke={green:"#0f2d1f",blue:"#0f1f2d",yellow:"#2d2a0f",red:"#2d0f0f",neutral:"#1a1a22",amber:"#2d1f0a"};function xr({color:t}){let n=Xt();return jsx(Text,{color:t,children:pr[n%pr.length]})}function Pi(){let t=Xt(),n=Math.floor(t/10)%2===0;return jsx(Text,{color:n?e.amber:e.amberDim,bold:true,children:wt})}function Ni({width:t,active:n}){let o=Math.max(4,Math.floor(t*.08)),a=2,d=Xt(),p=Math.ceil((t+o)/a),w=n?d%(p*2):0;if(!n)return jsx(Box,{paddingX:1,children:jsx(Text,{color:e.ghost,children:Me(t)})});let T=w<p?w*a:(p*2-w)*a,b=Math.max(0,T-o),x=Math.min(t,T),k=b,v=Math.max(0,x-b),O=Math.max(0,t-x);return jsxs(Box,{paddingX:1,children:[jsx(Text,{color:e.ghost,children:Me(k)}),jsx(Text,{color:e.amber,children:Me(v)}),jsx(Text,{color:e.ghost,children:Me(O)})]})}function Di({data:t,width:n,color:o}){if(t.length===0)return null;let a=t.slice(-n),d=Math.max(...a,1),p=a.map(w=>{let T=Math.round(w/d*(ho.length-1));return ho[T]??ho[0]}).join("");return jsx(Text,{color:o,children:p})}function Wi({projectName:t,activeView:n,mode:o,stats:a,uptime:d,width:p,version:w,latestVersion:T,taskBadge:b}){let x=o==="watching";return jsxs(Box,{paddingX:1,justifyContent:"space-between",width:p,children:[jsxs(Box,{gap:0,children:[jsx(Pi,{}),jsx(Text,{color:e.amber,bold:true,children:" ORCH"}),w&&jsxs(Text,{color:e.ghost,children:[" ",w]}),T&&T!==w&&jsxs(Text,{backgroundColor:Ke.green,color:e.green,bold:true,children:[" UPDATE ",T," "]}),jsxs(Text,{color:e.ghost,children:[" ",ct," "]}),jsx(Text,{color:e.silver,children:t})]}),jsx(Box,{gap:0,children:Ln.map((k,v)=>{let O=n===k.id,P=k.id==="tasks"&&b!=null&&b>0?` (${b})`:"";return jsxs(Xn.Fragment,{children:[v>0&&jsx(Text,{children:" "}),O?jsxs(Text,{backgroundColor:e.amber,color:"#0a0a0c",bold:true,children:[" ",k.key," ",k.label,P," "]}):jsxs(Box,{gap:0,children:[jsx(Text,{color:e.ghost,children:k.key}),jsxs(Text,{color:e.dim,children:[" ",k.label.toLowerCase(),P]})]})]},k.id)})}),jsxs(Box,{gap:0,children:[x?jsxs(Text,{backgroundColor:Ke.green,color:e.green,bold:true,children:[" ",_i," WATCHING"," "]}):jsxs(Text,{backgroundColor:Ke.neutral,color:e.dim,children:[" ",hr," IDLE"," "]}),a.running>0&&jsxs(Fragment,{children:[jsx(Text,{children:" "}),jsxs(Text,{backgroundColor:Ke.green,color:e.green,children:[" ",jsx(xr,{color:e.green})," ",a.running," active"," "]})]}),d&&jsxs(Text,{color:e.ghost,children:[" ",d]})]})]})}function Fi({stats:t,tokens:n,width:o,sparklineData:a}){let p=[{icon:Oi,label:"RUN",count:t.running,fg:e.green,bg:Ke.green,bold:true,spinner:true,show:t.running>0},{icon:Li,label:"RETRY",count:t.retrying,fg:e.yellow,bg:Ke.yellow,show:t.retrying>0},{icon:Ht,label:"REVIEW",count:t.review,fg:e.blue,bg:Ke.blue,show:t.review>0},{icon:hr,label:"TODO",count:t.todo,fg:e.dim,bg:Ke.neutral,show:t.todo>0},{icon:Ai,label:"DONE",count:t.done,fg:e.green,bg:Ke.green,show:t.done>0},{icon:Mi,label:"FAIL",count:t.failed,fg:e.red,bg:Ke.red,bold:true,show:t.failed>0},{icon:wt,label:"TEAMS",count:t.teams,fg:e.amber,bg:Ke.amber,show:t.teams>0}].filter(x=>x.show),w=n.total>0,T=x=>x>=1e3?`${(x/1e3).toFixed(1)}k`:String(x),b=a&&a.length>0?Math.min(16,a.length):0;return jsxs(Box,{paddingX:1,justifyContent:"space-between",width:o,children:[jsxs(Box,{gap:1,children:[p.map(x=>jsx(Text,{backgroundColor:x.bg,color:x.fg,bold:x.bold,children:x.spinner?jsxs(Fragment,{children:[" ",jsx(xr,{color:x.fg})," ",x.count," ",x.label," "]}):jsxs(Fragment,{children:[" ",x.icon," ",x.count," ",x.label," "]})},x.label)),p.length===0&&jsxs(Text,{backgroundColor:Ke.neutral,color:e.dim,children:[" ","NO TASKS"," "]})]}),jsxs(Box,{gap:0,children:[b>0&&a&&jsxs(Fragment,{children:[jsx(Di,{data:a,width:b,color:e.amberDim}),jsx(Text,{children:" "})]}),w&&jsxs(Text,{backgroundColor:Ke.amber,color:e.cyan,children:[" ",Ri,T(n.input)," ",Bi,T(n.output)," ",ct," ",Ei,T(n.total)," "]})]})]})}var br=Xn.memo(function(n){let o=Math.max(10,n.width-2),a=n.stats.running>0;return jsxs(Box,{flexDirection:"column",children:[jsx(Box,{height:1}),jsx(Wi,{projectName:n.projectName,activeView:n.activeView,mode:n.mode,stats:n.stats,uptime:n.uptime,width:n.width,version:n.version,latestVersion:n.latestVersion,taskBadge:n.taskBadge}),jsx(Box,{height:1}),jsx(Fi,{stats:n.stats,tokens:n.tokens,width:n.width,sparklineData:n.sparklineData}),jsx(Ni,{width:o,active:a})]})});var fn="\u0423\u041F\u0420\u0410\u0412\u041B\u0415\u041D\u0418\u0415",Jt="\u041C\u041E\u041D\u0418\u0422\u041E\u0420\u0418\u041D\u0413",Nn="\u041D\u0410\u0421\u0422\u0420\u041E\u0419\u041A\u0418",Lt={task:{sub:["add","list","show","cancel","retry","assign","approve","reject","delete"],help:"Manage tasks",category:fn},agent:{sub:["add","list","disable","enable","delete","autonomous","shop"],help:"Manage agents",category:fn},team:{sub:["create","list","join","leave","disband","set-lead"],help:"Manage teams",category:fn},goal:{sub:["add","list","show","status","delete"],help:"Manage goals",category:fn},run:{args:"[id]",help:"Run task (or selected)",category:Jt},"run-all":{help:"Run all todo tasks",category:Jt},watch:{help:"Start watch mode (auto-dispatch)",category:Jt},pause:{help:"Pause watch mode",category:Jt},status:{help:"Show orchestrator status",category:Jt},config:{sub:["activity-filter","max-concurrent"],help:"TUI settings",category:Nn},help:{help:"List all commands",category:Nn},quit:{help:"Exit the TUI",category:Nn}};function xo(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 b=Object.keys(Lt).find(x=>x.startsWith(T)&&x!==T);return b?b.slice(T.length):null}let a=n.slice(0,o),d=Lt[a];if(!d?.sub)return null;let p=n.slice(o+1);if(!p)return null;let w=d.sub.find(T=>T.startsWith(p)&&T!==p);return w?w.slice(p.length):null}function Tr(t){if(!t.startsWith("/"))return [];let n=t.slice(1),o=n.indexOf(" ");if(o===-1){let T=n.toLowerCase(),b=[];if(!T){let x=[fn,Jt,Nn];for(let k of x){b.push({cmd:"",desc:`\u2500\u2500 ${k} \u2500\u2500`});for(let[v,O]of Object.entries(Lt))if(O.category===k){let P=O.args?` ${O.args}`:"";b.push({cmd:`/${v}${P}`,desc:O.help,subs:O.sub?.join(" \xB7 ")});}}return b}for(let[x,k]of Object.entries(Lt))if(x.startsWith(T)){let v=k.args?` ${k.args}`:"";if(b.push({cmd:`/${x}${v}`,desc:k.help,subs:k.sub?.join(" \xB7 ")}),x===T&&k.sub)for(let O of k.sub)b.push({cmd:`/${x} ${O}`,desc:`${k.help}: ${O}`});}return b}let a=n.slice(0,o),d=Lt[a];if(!d?.sub)return [];let p=n.slice(o+1).toLowerCase(),w=[];for(let T of d.sub)(!p||T.startsWith(p))&&w.push({cmd:`/${a} ${T}`,desc:`${d.help}: ${T}`});return w}var Dn=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 zi="\u2588",yr=Xn.memo(function({mode:n,value:o,completion:a,activeView:d,canRun:p,canNew:w,canApprove:T,canReject:b,canCancel:x,canDelete:k,canUndo:v,canEdit:O,canForceStop:P,canToggleAuto:X,autoActive:N,canPause:F,isPaused:W,canToggleShowAll:z,showAllActive:K,hasDetail:j,itemCount:G,itemLabel:_,width:$,hasSuggestions:A,onboardingCompleted:R}){if(n==="command"){let pe=A?" \u2191\u2193 select Tab fill Esc \u2715":" Enter exec \u2191\u2193 history Tab complete Esc \u2715",ce=Math.max(4,$-6-pe.length-(a?.length??0)-1),we=o.length>ce?"\u2026"+o.slice(-(ce-1)):o;return jsx(Box,{paddingX:2,justifyContent:"space-between",width:$,children:jsxs(Box,{children:[jsx(Text,{color:e.amber,children:"/ "}),jsx(Text,{color:e.white,children:we}),a&&jsx(Text,{color:e.ghost,children:a}),jsx(Text,{color:e.amber,children:zi}),jsx(Text,{color:e.dim,children:pe})]})})}return jsxs(Box,{paddingX:2,justifyContent:"space-between",width:$,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",w&&jsxs(Fragment,{children:[" ",jsx(Text,{bold:true,color:e.gray,children:"N"})," new"]}),p&&jsxs(Fragment,{children:[" ",jsx(Text,{bold:true,color:e.gray,children:"R"})," run"]}),x&&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"]}),b&&jsxs(Fragment,{children:[" ",jsx(Text,{bold:true,color:e.red,children:"X"})," reject"]}),O&&jsxs(Fragment,{children:[" ",jsx(Text,{bold:true,color:e.cyan,children:"E"})," edit"]}),P&&jsxs(Fragment,{children:[" ",jsx(Text,{bold:true,color:e.red,children:"S"})," stop"]}),F&&jsxs(Fragment,{children:[" ",jsx(Text,{bold:true,color:e.amber,children:"P"}),W?" resume":" pause"]}),X&&jsxs(Fragment,{children:[" ",jsx(Text,{bold:true,color:e.cyan,children:"U"}),N?" auto off":" auto on"]}),z&&jsxs(Fragment,{children:[" ",jsx(Text,{bold:true,color:e.gray,children:"S"}),K?" collapse":" show all"]}),k&&!T&&jsxs(Fragment,{children:[" ",jsx(Text,{bold:true,color:e.gray,children:"D"})," delete"]}),v&&jsxs(Fragment,{children:[" ",jsx(Text,{bold:true,color:e.yellow,children:"Z"})," undo"]}),j&&jsxs(Fragment,{children:[" ",jsx(Text,{bold:true,color:e.gray,children:"Esc"})," close"]}),!j&&(d==="tasks"||d==="agents"||d==="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:R===false?e.amber:e.gray,children:"?"}),jsx(Text,{color:R===false?e.amber:void 0,children:" help"})]}),G>0&&jsxs(Text,{color:e.dim,children:[G," ",_]})]})});var Wn="\u2588";function Sr({title:t,steps:n,onComplete:o,onCancel:a,width:d,height:p,onPasteImage:w,footerExtra:T}){let [b,x]=useState(0),[k,v]=useState({}),[O,P]=useState(()=>{let L=n.find(B=>!B.skip?.({}));return L?.type==="text"&&L.defaultValue?L.defaultValue:""}),[X,N]=useState(()=>{let L=n.find(B=>!B.skip?.({}));return L?.type==="text"&&L.defaultValue?L.defaultValue.length:0}),[F,W]=useState(()=>{let L=n.find(B=>!B.skip?.({}));return L?.type==="textarea"&&L.defaultValue?L.defaultValue.split(`
6
- `):[""]}),[z,K]=useState(0),[j,G]=useState(0),[_,$]=useState(()=>{let L=n.find(B=>!B.skip?.({}));if(L?.type==="select"&&L.defaultValue){let C=(L.getOptions?.({})??L.options??[]).findIndex(U=>U.value===L.defaultValue);return C>=0?C:0}return 0}),A=useMemo(()=>n.filter(L=>!L.skip?.(k)),[n,k]),R=A[b],pe=A.length,[we,it]=useState(new Set),He=useMemo(()=>!R||R.type!=="select"&&R.type!=="multiselect"?[]:R.getOptions?.(k)??R.options??[],[R,k]),Xe=Math.min(_,Math.max(0,He.length-1)),Je=L=>{let B={...k,[R.id]:L};v(B),P(""),N(0),W([""]),K(0),G(0),$(0),it(new Set);let C=R.id,Z=n.findIndex(Q=>Q.id===C)+1;for(;Z<n.length;){let Q=n[Z];if(Q&&!Q.skip?.(B))break;Z++;}if(Z>=n.length)o(B);else {let Q=n[Z].id,_e=n.filter(ye=>!ye.skip?.(B)).findIndex(ye=>ye.id===Q);x(_e>=0?_e:0);let fe=n[Z];if(fe.type==="text"){let ye=fe.defaultValue??"";P(ye),N(ye.length);}else if(fe.type==="textarea"){let ye=fe.defaultValue?fe.defaultValue.split(`
7
- `):[""];W(ye),K(ye.length-1),G(ye[ye.length-1].length);}else if(fe.type==="select"){let ye=fe.getOptions?.(B)??fe.options??[];if(fe.defaultValue){let xt=ye.findIndex(et=>et.value===fe.defaultValue);$(xt>=0?xt:0);}else $(0);}else fe.type==="multiselect"&&($(0),fe.defaultValue?it(new Set(fe.defaultValue.split(","))):it(new Set));}},Ne=()=>{if(b===0){a();return}let L=R.id,C=n.findIndex(ee=>ee.id===L)-1;for(;C>=0;){let ee=n[C];if(ee&&!ee.skip?.(k))break;C--;}if(C<0){a();return}let U=n[C].id,Z=A.findIndex(ee=>ee.id===U);x(Z>=0?Z:0);let Q=n[C];if(Q.type==="text"){let ee=k[Q.id]??Q.defaultValue??"";P(ee),N(ee.length);}else if(Q.type==="textarea"){let ee=k[Q.id]??Q.defaultValue??"",_e=ee?ee.split(`
8
- `):[""];W(_e),K(_e.length-1),G(_e[_e.length-1].length);}else if(Q.type==="multiselect"){$(0);let ee=k[Q.id];it(ee?new Set(ee.split(",")):new Set);}else {let ee=Q.getOptions?.(k)??Q.options??[],_e=k[Q.id],fe=ee.findIndex(ye=>ye.value===_e);$(fe>=0?fe:0);}};if(useInput((L,B)=>{if(R){if(B.escape){b===0?a():Ne();return}if((B.ctrl||B.meta)&&(L==="v"||L==="i")&&w&&(R.type==="text"||R.type==="textarea")){w();return}if(R.type==="text"){if(B.return){let C=O.trim();if(R.required&&!C)return;Je(C);return}if(B.leftArrow){N(C=>Math.max(0,C-1));return}if(B.rightArrow){N(C=>Math.min(O.length,C+1));return}if(B.backspace||B.delete){if(X===0&&O.length===0&&b>0){Ne();return}X>0&&(P(C=>C.slice(0,X-1)+C.slice(X)),N(C=>C-1));return}L&&!B.ctrl&&!B.meta&&!B.escape&&(P(C=>C.slice(0,X)+L+C.slice(X)),N(C=>C+L.length));return}if(R.type==="textarea"){if(B.return&&!B.shift){let C=F.join(`
9
- `).trim();if(R.required&&!C)return;Je(C);return}if(B.return&&B.shift){W(C=>{let U=C[z]??"",Z=U.slice(0,j),Q=U.slice(j),ee=[...C];return ee.splice(z,1,Z,Q),ee}),K(C=>C+1),G(0);return}if(B.upArrow){z>0&&(K(C=>C-1),G(C=>Math.min(C,(F[z-1]??"").length)));return}if(B.downArrow){z<F.length-1&&(K(C=>C+1),G(C=>Math.min(C,(F[z+1]??"").length)));return}if(B.leftArrow){j>0?G(C=>C-1):z>0&&(K(C=>C-1),G((F[z-1]??"").length));return}if(B.rightArrow){let C=(F[z]??"").length;j<C?G(U=>U+1):z<F.length-1&&(K(U=>U+1),G(0));return}if(B.backspace||B.delete){if(j===0&&z===0)return;if(j>0)W(C=>{let U=[...C],Z=U[z]??"";return U[z]=Z.slice(0,j-1)+Z.slice(j),U}),G(C=>C-1);else {let C=(F[z-1]??"").length;W(U=>{let Z=[...U],Q=Z[z-1]??"",ee=Z[z]??"";return Z.splice(z-1,2,Q+ee),Z}),G(C),K(U=>U-1);}return}if(L&&!B.ctrl&&!B.meta&&!B.escape){let C=L.split(/\r?\n/);if(C.length===1)W(U=>{let Z=[...U],Q=Z[z]??"";return Z[z]=Q.slice(0,j)+L+Q.slice(j),Z}),G(U=>U+L.length);else {let U=z,Z=j;W(Q=>{let ee=[...Q],_e=ee[U]??"",fe=_e.slice(0,Z),ye=_e.slice(Z),xt=C[0]??"",et=C[C.length-1]??"",xn=[fe+xt,...C.slice(1,-1),et+ye];return ee.splice(U,1,...xn),ee}),K(U+C.length-1),G((C[C.length-1]??"").length);}}return}if(R.type==="select"||R.type==="multiselect"){if(B.upArrow||L==="k"){$(C=>Math.max(0,C-1));return}if(B.downArrow||L==="j"){$(C=>Math.min(He.length-1,C+1));return}if(B.backspace||B.delete){Ne();return}if(R.type==="select"){if(B.return||B.tab){let C=He[Xe];C&&Je(C.value);return}if(L>="1"&&L<="9"){let C=parseInt(L,10)-1;if(C<He.length){let U=He[C];U&&Je(U.value);}return}}else {if(L===" "){let C=He[Xe];C&&it(U=>{let Z=new Set(U);return Z.has(C.value)?Z.delete(C.value):Z.add(C.value),Z});return}if(B.return){let C=Array.from(we).join(",");Je(C);return}}}}}),!R)return null;let De=`${b+1}/${pe}`,Qe=Math.max(2,p-4),Se=0;Xe>=Qe&&(Se=Xe-Qe+1);let We=He.slice(Se,Se+Qe);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:[" ",Ut,Ut," "]}),jsxs(Text,{color:e.dim,children:["step ",De]})]}),jsxs(Box,{children:[jsx(Text,{children:" "}),A.map((L,B)=>jsxs(Text,{color:B===b?e.amber:B<b?e.green:e.ghost,children:[B===b?"\u25CF":B<b?"\u2713":"\u25CB"," "]},L.id))]}),jsxs(Box,{marginTop:0,children:[jsxs(Text,{color:e.white,bold:true,children:[" ",R.label]}),!R.required&&jsx(Text,{color:e.dim,children:" (optional, Enter to skip)"})]}),R.type==="text"&&jsxs(Box,{children:[jsxs(Text,{color:e.amber,children:[" ",">"," "]}),O.length>0?jsxs(Fragment,{children:[jsx(Text,{color:e.white,children:O.slice(0,X)}),jsx(Text,{color:e.amber,children:Wn}),jsx(Text,{color:e.white,children:O.slice(X)})]}):R.placeholder?jsxs(Fragment,{children:[jsx(Text,{color:e.ghost,children:R.placeholder}),jsx(Text,{color:e.amber,children:Wn})]}):jsx(Text,{color:e.amber,children:Wn})]}),R.type==="textarea"&&(()=>{let L=Math.max(3,p-6),B=0;z>=L&&(B=z-L+1);let C=F.slice(B,B+L),U=String(F.length).length;return jsxs(Box,{flexDirection:"column",children:[C.map((Z,Q)=>{let ee=Q+B,_e=String(ee+1).padStart(U," "),fe=ee===z;return jsxs(Box,{children:[jsxs(Text,{color:e.dim,children:[" ",_e," "]}),jsxs(Text,{color:e.ghost,children:["\u2502"," "]}),fe?jsxs(Fragment,{children:[jsx(Text,{color:e.white,children:Z.slice(0,j)}),jsx(Text,{color:e.amber,children:Wn}),jsx(Text,{color:e.white,children:Z.slice(j)})]}):jsx(Text,{color:e.silver,children:Z||" "})]},ee)}),F.length===1&&F[0]===""&&R.placeholder&&jsx(Box,{children:jsxs(Text,{color:e.dim,children:[" ","".padStart(U," ")," ",R.placeholder]})})]})})(),R.type==="select"&&jsx(Box,{flexDirection:"column",children:We.map((L,B)=>{let C=B+Se,U=C===Xe,Z=String(C+1).padStart(He.length>=10?2:1);return jsxs(Box,{children:[jsx(Text,{color:U?e.amber:e.ghost,children:U?" \u25B8 ":` ${Z} `}),jsx(Text,{color:U?e.white:e.silver,bold:U,children:L.label}),L.hint&&jsxs(Text,{color:e.dim,wrap:"truncate",children:[" ",Ut," ",L.hint.replace(/\n/g," ")]})]},L.value)})}),R.type==="multiselect"&&jsxs(Box,{flexDirection:"column",children:[We.map((L,B)=>{let U=B+Se===Xe,Z=we.has(L.value);return jsxs(Box,{children:[jsx(Text,{color:U?e.amber:e.ghost,children:U?" \u25B8 ":" "}),jsx(Text,{color:Z?e.green:e.dim,children:Z?"[\u2713]":"[ ]"}),jsxs(Text,{color:U?e.white:e.silver,bold:U,children:[" ",L.label]}),L.hint&&jsxs(Text,{color:e.dim,wrap:"truncate",children:[" ",Ut," ",L.hint.replace(/\n/g," ")]})]},L.value)}),we.size>0&&jsx(Box,{children:jsxs(Text,{color:e.dim,children:[" ","\u2514"," ",we.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"?"Shift+Enter newline Enter confirm \u2190\u2191\u2192\u2193 navigate":"\u2190\u2192 move Enter confirm",w&&(R.type==="text"||R.type==="textarea")?` ${process.platform==="darwin"?"\u2318":"Ctrl"}+V paste image`:""," Esc ",b>0?"back":"cancel"]}),T&&jsxs(Text,{color:e.amber,children:[" ",T]})]})]})}var kr="\u256D",Cr="\u256E",Ir="\u2570",$r="\u256F",Oe="\u2502";function hn({children:t,cw:n}){return jsxs(Text,{children:[jsx(Text,{color:e.ghost,children:Oe}),jsxs(Text,{children:[" ",t.padEnd(n)," "]}),jsx(Text,{color:e.ghost,children:Oe})]})}function Fn({cw:t}){return jsx(hn,{cw:t,children:""})}function vr({width:t,height:n}){let o=Math.min(t-4,50),a=o-6,d=Pe(o-2);return jsxs(Box,{flexDirection:"column",paddingX:2,marginTop:1,children:[jsxs(Text,{color:e.ghost,children:[kr,d,Cr]}),jsx(hn,{cw:a,children:""}),jsxs(Text,{children:[jsxs(Text,{color:e.ghost,children:[Oe," "]}),jsx(Text,{color:e.amber,children:wt}),jsx(Text,{color:e.white,bold:true,children:" Welcome to Orch"}),jsx(Text,{children:" ".repeat(Math.max(0,a-15-2))}),jsx(Text,{children:" "}),jsx(Text,{color:e.ghost,children:Oe})]}),jsx(hn,{cw:a,children:""}),jsxs(Text,{children:[jsxs(Text,{color:e.ghost,children:[Oe," "]}),jsx(Text,{color:e.silver,children:"Press N to create your first task".padEnd(a)}),jsx(Text,{children:" "}),jsx(Text,{color:e.ghost,children:Oe})]}),jsx(hn,{cw:a,children:""}),jsxs(Text,{children:[jsxs(Text,{color:e.ghost,children:[Oe," "]}),jsx(Text,{color:e.amber,children:"N"}),jsx(Text,{color:e.gray,children:" new task"}),jsx(Text,{children:" ".repeat(Math.max(0,a-1-1-8))}),jsx(Text,{children:" "}),jsx(Text,{color:e.ghost,children:Oe})]}),jsx(hn,{cw:a,children:""}),jsxs(Text,{color:e.ghost,children:[Ir,d,$r]})]})}function Gn({count:t,config:n,width:o}){if(t>=3)return null;let a=Math.min((o??44)-4,50),d=a-6,p=Pe(a-2),w=jsxs(Text,{color:e.ghost,children:[kr,p,Cr]}),T=jsxs(Text,{color:e.ghost,children:[Ir,p,$r]});if(t>0){let x=n.hints[0],k=x?` ${x.key} ${x.label}`:"";return jsxs(Box,{flexDirection:"column",paddingX:2,marginTop:1,children:[w,jsxs(Text,{children:[jsxs(Text,{color:e.ghost,children:[Oe," "]}),jsx(Text,{color:e.amber,children:wt}),jsxs(Text,{color:e.silver,children:[" ",n.nudge.padEnd(d-2-k.length)]}),x&&jsxs(Fragment,{children:[jsxs(Text,{color:e.amber,children:[" ",x.key]}),jsxs(Text,{color:e.gray,children:[" ",x.label]})]}),jsx(Text,{children:" "}),jsx(Text,{color:e.ghost,children:Oe})]}),T]})}let b=n.hints.reduce((x,k,v)=>x+k.key.length+1+k.label.length+(v>0?3:0),0);return jsxs(Box,{flexDirection:"column",paddingX:2,marginTop:1,children:[w,jsx(Fn,{cw:d}),jsxs(Text,{children:[jsxs(Text,{color:e.ghost,children:[Oe," "]}),jsx(Text,{color:e.amber,children:wt}),jsxs(Text,{color:e.white,bold:true,children:[" ",n.title]}),jsx(Text,{children:" ".repeat(Math.max(0,d-n.title.length-2))}),jsx(Text,{children:" "}),jsx(Text,{color:e.ghost,children:Oe})]}),jsx(Fn,{cw:d}),n.description.map((x,k)=>jsxs(Text,{children:[jsxs(Text,{color:e.ghost,children:[Oe," "]}),jsx(Text,{color:e.silver,children:x.padEnd(d)}),jsx(Text,{children:" "}),jsx(Text,{color:e.ghost,children:Oe})]},k)),jsx(Fn,{cw:d}),jsxs(Text,{children:[jsxs(Text,{color:e.ghost,children:[Oe," "]}),n.hints.map((x,k)=>jsxs(Xn.Fragment,{children:[k>0&&jsx(Text,{color:e.ghost,children:" "}),jsx(Text,{color:e.amber,children:x.key}),jsxs(Text,{color:e.gray,children:[" ",x.label]})]},k)),jsx(Text,{children:" ".repeat(Math.max(0,d-b))}),jsx(Text,{children:" "}),jsx(Text,{color:e.ghost,children:Oe})]}),jsx(Fn,{cw:d}),T]})}var Ar=[{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"}],Mr=[{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"}],Rr=[{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"}],Br=[{value:"",label:"Default",hint:"use shell adapter default"}],Hi=[{value:"claude",label:"Claude",hint:"Claude Code CLI"},{value:"codex",label:"Codex",hint:"OpenAI Codex CLI"},{value:"cursor",label:"Cursor",hint:"Cursor Agent CLI"},{value:"shell",label:"Shell",hint:"custom shell command"}],Er=[{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"}],_r=80;function Or(t){return t.filter(n=>n.status!=="disabled").map(n=>{let o=(n.role??n.adapter).split(`
10
- `)[0].trim(),a=o.length>_r?o.slice(0,_r-1)+"\u2026":o;return {value:n.id,label:n.name,hint:a}})}function zn(t,n="Auto-assign",o="orchestrator picks the best agent"){return [{value:"",label:n,hint:o},...Or(t)]}var wo=[{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 Lr(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 Pr(){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 Nr(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 So(t){let n=Lr(t);return [{id:"name",label:"Agent name",type:"text",placeholder:"e.g. alpha, frontend-bot, reviewer",required:true},{id:"adapter",label:"Provider",type:"select",options:Hi},{id:"model",label:"Model",type:"select",getOptions:o=>o.adapter==="codex"?Mr:o.adapter==="cursor"?Rr:o.adapter==="shell"?Br:Ar},{id:"role",label:"Role / specialization",type:"select",options:wo},{id:"role_custom",label:"Describe the role",type:"textarea",placeholder:"e.g. Specialist in React and TypeScript",skip:o=>o.role!=="__custom__"},{id:"skills",label:"Skills (comma-separated)",type:"text",placeholder:"e.g. feature-dev:feature-dev, testing-suite:generate-tests"},{id:"approval_policy",label:"Approval policy",type:"text",skip:()=>true},{id:"team",label:"Join team",type:"select",options:n,skip:()=>n.length<=1}]}function Dr(t){let n=t.role==="__custom__"?t.role_custom||void 0:t.role||void 0,o=t.skills?t.skills.split(",").map(d=>d.trim()).filter(Boolean):void 0,a=t.approval_policy||"auto";return {name:t.name,adapter:t.adapter||"claude",role:n,model:t.model||void 0,approval_policy:a,skills:o,team_id:t.team||void 0}}function Wr(t){let n=Or(t);return [{id:"name",label:"Team name",type:"text",placeholder:"e.g. frontend, backend, qa",required:true},{id:"lead",label:"Team lead",type:"select",options:n},{id:"members",label:"Team members",type:"multiselect",getOptions:o=>n.filter(a=>a.value!==o.lead),skip:o=>!n.some(a=>a.value!==o.lead)},{id:"description",label:"Description",type:"textarea",placeholder:"Optional team purpose..."}]}function Fr(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 Gr(t){let n=zn(t);return [{id:"title",label:"Task title",type:"text",placeholder:"What needs to be done?",required:true},{id:"priority",label:"Priority",type:"select",options:Er,defaultValue:"3"},{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 zr(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 Vr(t,n){let o=zn(n,"None / Auto","remove assignee");return [{id:"title",label:"Task title",type:"text",defaultValue:t.title,required:true},{id:"priority",label:"Priority",type:"select",options:Er,defaultValue:String(t.priority)},{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 jr(t){return {title:t.title,priority:t.priority?parseInt(t.priority,10):void 0,assignee:t.assignee||void 0,description:t.description??""}}function Ur(t,n){let o=wo.find(T=>T.value===t.role),a=o?t.role:t.role?"__custom__":"",d=t.adapter==="codex"?Mr:t.adapter==="cursor"?Rr:t.adapter==="shell"?Br:Ar,p=Lr(n),w=n?.find(T=>T.members.some(b=>b.agent_id===t.id))?.id;return [{id:"name",label:"Agent name",type:"text",defaultValue:t.name,required:true},{id:"model",label:"Model",type:"select",options:d,defaultValue:t.config.model??""},{id:"role",label:"Role / specialization",type:"select",options:wo,defaultValue:a},{id:"role_custom",label:"Describe the role",type:"textarea",defaultValue:t.role&&!o?t.role:"",placeholder:"e.g. Specialist in React and TypeScript",skip:T=>T.role!=="__custom__"},{id:"team",label:"Team",type:"select",options:p,defaultValue:w??"",skip:()=>p.length<=1}]}var Xi=[{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"}],qi=[{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"}];function Hr(t,n){return [{id:"setting",label:"Setting",type:"select",options:[{value:"activity_filter",label:"Activity filter",hint:`current: ${t}`},{value:"max_concurrent",label:"Max concurrent agents",hint:`current: ${n}`}]},{id:"activity_filter",label:"Activity filter preset",type:"select",options:qi,defaultValue:t,skip:o=>o.setting!=="activity_filter"},{id:"max_concurrent",label:"Max concurrent agents",type:"select",options:Xi,defaultValue:String(n),skip:o=>o.setting!=="max_concurrent"}]}function Xr(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 Vn(t){let n=zn(t,"Any agent","auto-assign to autonomous agents");return [{id:"title",label:"Goal title",type:"text",placeholder:"What should be achieved?",required:true},{id:"assignee",label:"Assignee",type:"select",options:n,skip:()=>n.length<=1},{id:"description",label:"Description",type:"textarea",placeholder:"Detailed goal description, success criteria..."}]}function qr(t){return {title:t.title,assignee:t.assignee||void 0,description:t.description||void 0}}function Yr(t,n){let o=zn(n,"Any agent","auto-assign");return [{id:"title",label:"Goal title",type:"text",defaultValue:t.title,required:true},{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:"Detailed goal description..."}]}function Kr(t){return {title:t.title,assignee:t.assignee||void 0,description:t.description??""}}var Zr=10,Jr=500,qn=2048,Nt=500,ko=new Set(["todo","failed","cancelled"]),Ji={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."},Qi={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."},ea={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."},Qr=5e3,ns=0;function cc(){ns=0;}var os=/^\[[\w_]+\]$/;function rs(t){return os.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 es=["#5faf87","#5fafd7","#af87ff","#d7af00","#5fd7d7","#d787af","#afaf5f","#d7875f"];function Yn(t,n){let o=n.findIndex(a=>a.id===t);return es[o>=0?o%es.length:0]}var ta=" ".repeat(9),Kn={system:"\u2666",lifecycle:"\u25B6",output:"\u2502",tool:"\u2699",result:"\u2190",error:"\u2715",file:"\u270E",info:"\u2502"},Hn=["system","lifecycle","output","tool","result","error","file","info"],Qt=[{label:"all",types:Hn},{label:"text",types:["output"]},{label:"tools",types:["tool","result","file"]},{label:"errors",types:["error"]},{label:"events",types:["lifecycle","system"]}];function Co(t){let o=(Qt.findIndex(a=>a.types.length===t.size&&a.types.every(d=>t.has(d)))+1)%Qt.length;return Qt[o]}function dc({projectName:t,tasks:n,agents:o=[],state:a$2,onRunTask:d,onCreateTask:p,onCancelTask:w,onRetryTask:T,onAssignTask:b$1,onRunAll:x,onDisableAgent:k,onEnableAgent:v,onSubscribeEvents:O,onRefreshTasks:P,onRefreshAgents:X,onRefreshState:N,onLoadHistory:F,onAddAgent:W,onDeleteAgent:z,onApproveTask:K,onRejectTask:j,onDeleteTask:G,onUpdateTask:_,onUpdateAgent:$,onForceStopAgent:A,onCreateTeam:R,onListTeams:pe,onJoinTeam:ce,onLeaveTeam:we,onDisbandTeam:it,onSetTeamLead:He,onStartWatch:Xe,onStopWatch:Je,onToggleAutonomous:Ne,onRefreshGoals:Dt,onCreateGoal:De,onUpdateGoal:Qe,onUpdateGoalStatus:Se,onDeleteGoal:We,onGetGoalProgress:L,initialWatchActive:B,watchError:C,messageBatchMs:U=process.env.VITEST?0:80,initialActivityFilter:Z="all",onSaveActivityFilter:Q,initialMaxConcurrent:ee=a.scheduling.max_concurrent_agents,onSaveMaxConcurrent:_e,version:fe,latestVersion:ye}){let{exit:xt}=useApp(),{stdout:et}=useStdout(),[xn,ds]=useState({w:et?.columns??80,h:et?.rows??24});useEffect(()=>{if(!et)return;let i=()=>ds({w:et.columns,h:et.rows});return et.on("resize",i),()=>{et.off("resize",i);}},[et]);let Wt=xn.w,Zn=xn.h,[tt,us]=useState(n),[ke,gs]=useState(o),[qe,ms]=useState(a$2),[bn,Jn]=useState(B??!!a$2.pid),[Qn,Io]=useState([]),[ps,$o]=useState(void 0),vo=useMemo(()=>a$2.onboardingCompleted||(a$2.stats?.total_tasks_completed??0)>0?"dismissed":Object.keys(a$2.running??{}).length>0?"run_started":n.length>0?"task_created":"welcome",[]),[I,Ft]=useState("tasks"),[Tn,yn]=useState(0),[eo,_o]=useState(0),[to,Ao]=useState(0),[Ce,en]=useState(false),[nt,Mo]=useState([]),[Ie,$e]=useState("none"),[It,at]=useState(""),[ot,Fe]=useState(null),[$t,tn]=useState([]),[fs,hs]=useState(0),[xs,bs]=useState(()=>new Set(Hn)),[nn,no]=useState(-1),[Ts,on]=useState(0),[Gt,oo]=useState(()=>{let i=Qt.find(y=>y.label===Z);return new Set(i?.types??Hn)}),wn=useMemo(()=>Qt.find(y=>y.types.length===Gt.size&&y.types.every(s=>Gt.has(s)))?.label??"all",[Gt]),ro=useMemo(()=>Gt.size>=Hn.length?nt:nt.filter(i=>Gt.has(i.msgType??"info")),[nt,Gt]),[Ro,ys]=useState(ee),Sn=Xn.useRef(new Dn).current,[ws,rn]=useState(0),[Bo,Eo]=useState(false),[Ss,so]=useState(0),[ks,io]=useState(0),[Cs,sn]=useState(0),[kn,bt]=useState(0),[Tt,Oo]=useState([]),[zt,ao]=useState([]),an=useRef(Tt);an.current=Tt;let H=useCallback(async i=>{let[y,s,c,g,f]=await Promise.all([P?.()??Promise.resolve(tt),X?.()??Promise.resolve(ke),N?.()??Promise.resolve(qe),i?.includeTeams?pe?.()??Promise.resolve(an.current):Promise.resolve(null),Dt?.()??Promise.resolve(Qn)]);us(y),gs(s),ms(c),g!==null&&Oo(g),Io(f),B&&Jn(!!c.pid);},[P,X,N,pe,Dt,B]),xe=useMemo(()=>[...tt].sort((i,y)=>(gn[i.status]??9)-(gn[y.status]??9)),[tt]),gt=Bo?xe:xe.slice(0,Zr),yt=xe.length-gt.length,E=xe[Tn],Cn=useMemo(()=>{let i=new Map;for(let y of tt)i.set(y.id,y.title);return i},[tt]),vt=useMemo(()=>{let i=new Map;for(let y of ke)i.set(y.id,y.name);return i},[ke]),{agentTeamMap:Vt,activeTeamCount:ln,teamLeadSet:Is}=useMemo(()=>{let i=new Map,y=new Set,s=0;for(let c of Tt)if(c.status==="active"){s++,y.add(c.lead_agent_id);for(let g of c.members)i.set(g.agent_id,c.name);}return {agentTeamMap:i,activeTeamCount:s,teamLeadSet:y}},[Tt]),Ae=useMemo(()=>{let i=[...ke];return i.sort((y,s)=>{let c=Vt.get(y.id),g=Vt.get(s.id);return c&&!g?-1:!c&&g?1:c&&g&&c!==g?c.localeCompare(g):(fo[y.status]??9)-(fo[s.status]??9)}),i},[ke,Vt]),q=Ae[eo],Ye=useMemo(()=>[...Qn].sort((i,y)=>(c[i.status]??9)-(c[y.status]??9)),[Qn]),Y=Ye[to],$s=useMemo(()=>Y?tt.filter(i=>i.goalId===Y.id):[],[Y,tt]),lo=useRef(L);lo.current=L,useEffect(()=>{if(!Y||!lo.current){$o(void 0);return}let i=false;return lo.current(Y.id).then(y=>{i||$o(y);}).catch(()=>{}),()=>{i=true;}},[Y?.id]);let _t=useRef(new Map),In=useRef(new Map);useEffect(()=>{for(let[i,y]of Object.entries(qe.running))_t.current.set(y.run_id,y.agent_id),In.current.set(y.run_id,i);if(_t.current.size>Jr){let i=_t.current.size-Jr,y=0;for(let s of _t.current.keys()){if(y++>=i)break;_t.current.delete(s),In.current.delete(s);}}},[qe.running]);let At=useRef([]),cn=useRef(null),co=useCallback(()=>{if(cn.current=null,At.current.length===0)return;let i=At.current;At.current=[],Mo(y=>{if(i.length>=Nt)return i.slice(-Nt);let s=Nt-i.length;return (y.length>s?y.slice(-s):y).concat(i)});},[]);useEffect(()=>()=>{cn.current&&clearTimeout(cn.current);},[]);let r=useCallback((i,y,s)=>{let c=new Date,g=c.toLocaleTimeString("en-US",{hour12:false,hour:"2-digit",minute:"2-digit",second:"2-digit"}),f=s?.detail&&s.detail.length>qn?s.detail.slice(0,qn)+"\u2026[truncated]":s?.detail;At.current.push({text:i,color:y,time:g,ts:c.getTime(),...s,detail:f}),At.current.length>Nt*2&&(At.current=At.current.slice(-Nt)),U===0?co():cn.current||(cn.current=setTimeout(co,U));},[co]);useEffect(()=>{C&&r(`Watch mode failed: ${C}. Tasks will not auto-dispatch.`,e.red);},[]);let jt=useCallback((i,y,s,c)=>{let g={key:++ns,entityType:i,entityId:y,entityName:s,expiresAt:Date.now()+Qr,needsForceStop:c?.needsForceStop};ao(f=>[...f,g]),r(`\u2717 "${s}" will be deleted in ${Math.round(Qr/1e3)}s \u2014 press Z to undo`,e.yellow);},[r]),vs=useCallback(()=>{ao(i=>{if(i.length===0)return i;let y=i[i.length-1];return r(`\u21B6 Undo: "${y.entityName}" restored`,e.green),i.slice(0,-1)});},[r]),Lo=useCallback(async i=>{try{i.entityType==="task"&&G?await G(i.entityId):i.entityType==="agent"?(i.needsForceStop&&A&&await A(i.entityId),z&&await z(i.entityId)):i.entityType==="goal"&&We&&await We(i.entityId),r(`\u2713 Deleted "${i.entityName}"`,e.green),H();}catch(y){r(`Failed to delete "${i.entityName}": ${y instanceof Error?y.message:String(y)}`,e.red);}},[G,z,We,A,r,H]),Po=useRef(Lo);Po.current=Lo,useEffect(()=>{if(zt.length===0)return;let i=setInterval(()=>{let y=Date.now(),s=[];ao(c=>{let g=c.filter(f=>f.expiresAt<=y?(s.push(f),false):true);return s.length>0?g:c});for(let c of s)Po.current(c);},1e3);return ()=>clearInterval(i)},[zt.length>0]),useEffect(()=>{if(!F)return;let i=y=>{let s=new Date(y.timestamp).toLocaleTimeString("en-US",{hour12:false,hour:"2-digit",minute:"2-digit",second:"2-digit"}),c=typeof y.data=="string"?y.data:JSON.stringify(y.data),g,f=e.silver,m="output";if(y.type==="error")g=typeof y.data=="string"?y.data:JSON.stringify(y.data),g=g.slice(0,200),f=e.red,m="error";else if(y.type==="file_changed")g=String(y.data),f=e.purple,m="file";else if(y.type==="done")g="Completed",f=e.green,m="lifecycle";else if(y.type==="tool_call")g=`\u2699 ${y.data?.name??"tool"}()`,f=e.cyan,m="tool";else {let{summary:h}=cs(c);if(!h)return null;g=h;let V=rs(g);m=V.msgType,f=V.color;}return {text:g,color:f,time:s,ts:new Date(y.timestamp).getTime(),agentId:y.agentId,taskId:y.taskId,msgType:m}};F(y=>{if(y.length===0)return;let s=y.map(i).filter(c=>c!==null);Mo(c=>{let g=[...s,...c];return g.length>Nt?g.slice(-Nt):g});}).catch(()=>{});},[]),useEffect(()=>{pe?.().then(Oo).catch(()=>{}),Dt?.().then(Io).catch(()=>{});},[]);let $n=useCallback(()=>{Fe({title:"NEW AGENT",steps:So(an.current),kind:"agent"}),$e("wizard");},[]),No=useCallback(()=>{Fe({title:"AGENT SHOP",steps:Pr(),kind:"agent_shop"}),$e("wizard");},[]),vn=useCallback(()=>{tn([]),Fe({title:"NEW TASK",steps:Gr(ke),kind:"task"}),$e("wizard");},[ke]),_s=useCallback(async()=>{try{let{detectClipboardType:i,getClipboardImage:y}=await import('./clipboard-service-MYLSWM5E.js'),s=await i();if(s!=="image")return r(s==="text"?"Clipboard has text, not image":"Clipboard is empty",e.dim),s;let c=await y();if(!c)return r("Failed to read clipboard image",e.red),"empty";let{mkdtemp:g,writeFile:f}=await import('fs/promises'),{tmpdir:m}=await import('os'),{join:h}=await import('path'),V=await g(h(m(),"orch-paste-")),dt=h(V,`clipboard-${Date.now()}.${c.ext}`);return await f(dt,c.data),tn(Rt=>[...Rt,dt]),r(`\u{1F4CE} Image attached (${Math.round(c.data.length/1024)}KB)`,e.green),"image"}catch{return r("Clipboard paste failed",e.red),"empty"}},[r]),As=useCallback(i=>{Fe({title:"EDIT TASK",steps:Vr(i,ke),kind:"edit_task",targetId:i.id}),$e("wizard");},[ke]),Do=useCallback(()=>{Fe({title:"NEW TEAM",steps:Wr(ke),kind:"team"}),$e("wizard");},[ke]),Ms=useCallback(i=>{Fe({title:"EDIT AGENT",steps:Ur(i,Tt),kind:"edit_agent",targetId:i.id}),$e("wizard");},[Tt]),Wo=useCallback(()=>{Fe({title:"SETTINGS",steps:Hr(wn,Ro),kind:"config"}),$e("wizard");},[wn,Ro]),Rs=useCallback(i=>{$e("none");let y=ot?.kind,s=ot?.targetId;if(Fe(null),y==="agent_shop"){let c=i.shop_template,g=c?b(c):void 0;if(g){let f=So(an.current),m=Nr(f,g);Fe({title:`NEW AGENT \u2014 ${g.name}`,steps:m,kind:"agent_from_shop"}),$e("wizard");}else r("No template selected",e.yellow);return}if((y==="agent"||y==="agent_from_shop")&&W){let c=Dr(i);r(`Creating agent "${c.name}"...`,e.amber),W(c.name,c.adapter,{model:c.model,role:c.role,approval_policy:c.approval_policy,skills:c.skills}).then(g=>{r(`\u2713 Created agent "${g.name}" (${g.id}, ${g.adapter})`,e.green),c.team_id&&ce?ce(c.team_id,g.id).then(f=>{r(`\u2713 Joined team "${f.name}"`,e.green),H({includeTeams:true});},f=>r(`Failed to join team: ${f instanceof Error?f.message:String(f)}`,e.red)):H();},g=>r(`Failed: ${g instanceof Error?g.message:String(g)}`,e.red));}else if(y==="team"&&R){let c=Fr(i);r(`Creating team "${c.name}"...`,e.amber),R(c).then(g=>{r(`\u2713 Created team "${g.name}" (${g.id}, ${g.members.length} members)`,e.green),H({includeTeams:true});},g=>r(`Failed: ${g instanceof Error?g.message:String(g)}`,e.red));}else if(y==="task"&&p){let c=zr(i),g=$t.length>0?[...$t]:void 0;tn([]),r(`Creating "${c.title}"...`,e.amber),p(c.title,{priority:c.priority,description:c.description,attachments:g}).then(f=>{r(`\u2713 Created "${f.title}" (${f.id})${g?` \u{1F4CE}${g.length}`:""}`,e.green),c.assignee&&b$1&&b$1(f.id,c.assignee).catch(()=>{}),H();},f=>r(`Failed: ${f instanceof Error?f.message:String(f)}`,e.red));}else if(y==="edit_task"&&s&&_){let c=jr(i),g=$t.length>0?[...$t]:void 0;tn([]),r("Updating task...",e.amber),_(s,{...c,attachments:g}).then(f=>{r(`\u2713 Updated "${f.title}"${g?` \u{1F4CE}${g.length}`:""}`,e.green),c.assignee&&b$1&&b$1(s,c.assignee).catch(()=>{}),H();},f=>r(`Failed: ${f instanceof Error?f.message:String(f)}`,e.red));}else if(y==="edit_agent"&&s&&$){let c=Xr(i),g=c.team_id??"",f=Tt.find(m=>m.members.some(h=>h.agent_id===s))?.id??"";r("Updating agent...",e.amber),$(s,{name:c.name,role:c.role,model:c.model}).then(m=>{r(`\u2713 Updated agent "${m.name}"`,e.green);let h=[];f&&f!==g&&we&&h.push(we(f,s).then(V=>r(`\u2713 Left team "${V.name}"`,e.green),V=>r(`Failed to leave team: ${V instanceof Error?V.message:String(V)}`,e.red))),g&&g!==f&&ce&&h.push(ce(g,s).then(V=>r(`\u2713 Joined team "${V.name}"`,e.green),V=>r(`Failed to join team: ${V instanceof Error?V.message:String(V)}`,e.red))),Promise.all(h).then(()=>H({includeTeams:h.length>0}));},m=>r(`Failed: ${m instanceof Error?m.message:String(m)}`,e.red));}else if(y==="config"){if(i.setting==="activity_filter"&&i.activity_filter){let c=Qt.find(g=>g.label===i.activity_filter);c&&(oo(new Set(c.types)),Q?.(c.label),r(`Activity filter: ${c.label}`,e.amber));}else if(i.setting==="max_concurrent"&&i.max_concurrent){let c=parseInt(i.max_concurrent,10);c>0&&(ys(c),_e?.(c),r(`Max concurrent agents: ${c}`,e.amber));}}else if(y==="goal"&&De){let c=qr(i);r(`Creating goal "${c.title}"...`,e.amber),De(c).then(g=>{r(`\u2713 Created goal "${g.title}" (${g.id})`,e.green),H();},g=>r(`Failed: ${g instanceof Error?g.message:String(g)}`,e.red));}else if(y==="edit_goal"&&s&&Qe){let c=Kr(i);r("Updating goal...",e.amber),Qe(s,c).then(g=>{r(`\u2713 Updated goal "${g.title}"`,e.green),H();},g=>r(`Failed: ${g instanceof Error?g.message:String(g)}`,e.red));}},[ot,W,p,R,ce,we,b$1,_,$,Ne,De,Qe,r,H,Q,_e,Tt,$t]),Bs=useCallback(()=>{$e("none"),Fe(null),tn([]);},[]);useEffect(()=>{if(!O)return;let i=null,y=()=>{i||(i=setTimeout(()=>{i=null,H().catch(()=>{});},150));},s=O(c=>{c.type==="agent:started"&&(_t.current.set(c.runId,c.agentId),In.current.set(c.runId,c.taskId)),Sa(c,r,_t.current,In.current),(c.type==="task:status_changed"||c.type==="task:created"||c.type==="task:assigned"||c.type==="agent:started"||c.type==="agent:completed"||c.type==="run:retry"||c.type==="goal:created"||c.type==="goal:status_changed"||c.type==="goal:updated"||c.type==="goal:deleted")&&y();});return ()=>{s(),i&&clearTimeout(i);}},[O,r,H]);let uo=bn?"watching":"idle",Es=qe.started_at?g(qe.started_at):void 0,Os=qe.stats.total_tokens.total,Fo=useMemo(()=>{let i={running:0,retrying:0,review:0,todo:0,done:0,failed:0,cancelled:0};for(let y of tt)y.status==="in_progress"?i.running++:y.status==="retrying"?i.retrying++:y.status==="review"?i.review++:y.status==="todo"?i.todo++:y.status==="done"?i.done++:y.status==="failed"?i.failed++:y.status==="cancelled"&&i.cancelled++;return {...i,teams:ln}},[tt,ln]);Fo.running;let Ls={input:qe.stats.total_tokens.input??0,output:qe.stats.total_tokens.output??0,total:Os},_n=Math.max(4,Zn-9),Ps=Vt.size,Ns=ke.length>Ps,Ds=ln>0?ln+(Ns?1:0):0,Ws=I==="goals"?Ye.length+1:I==="tasks"?gt.length+1+(yt>0?1:0):I==="agents"?ke.length+1+Ds:0,Fs=Math.min(Ws+1,Math.ceil(_n*.5)),Gs=I==="tasks"&&yt>0,be=I==="logs"?_n:Math.max(2,Math.min(Fs,_n-4)),Mt=Math.max(1,_n-be-(Gs?1:0)),he=Math.max(10,Wt-2),lt=useMemo(()=>Ie==="command"?Tr(It):[],[Ie,It]);useEffect(()=>{rn(i=>Math.min(i,Math.max(0,gt.length-be)));},[gt.length,be]),useEffect(()=>{so(i=>Math.min(i,Math.max(0,Ae.length-be)));},[Ae.length,be]),useEffect(()=>{io(i=>Math.min(i,Math.max(0,Ye.length-be)));},[Ye.length,be]);let zs=useCallback(i=>{let s=i.trim().replace(/^\//,"").split(/\s+/),c=s[0]?.toLowerCase();if(!c)return;let g=f=>f instanceof Error?f.message:String(f);switch(c){case "cancel":{if(!E){r("No task selected",e.yellow);return}if(!w)return;r(`Cancelling "${E.title}"...`,e.amber),w(E.id).then(()=>{r(`\u2713 Cancelled "${E.title}"`,e.green),H();},f=>r(`Failed: ${g(f)}`,e.red));return}case "retry":{if(!E){r("No task selected",e.yellow);return}if(!T)return;r(`Retrying "${E.title}"...`,e.amber),T(E.id).then(()=>{r(`\u2713 Retried "${E.title}"`,e.green),H();},f=>r(`Failed: ${g(f)}`,e.red));return}case "assign":{if(!E){r("No task selected",e.yellow);return}if(!b$1||!s[1]){r("Usage: assign <agent>",e.yellow);return}r(`Assigning "${E.title}" to ${s[1]}...`,e.amber),b$1(E.id,s[1]).then(()=>{r(`\u2713 Assigned "${E.title}" to ${s[1]}`,e.green),H();},f=>r(`Failed: ${g(f)}`,e.red));return}case "task":{let f=s[1]?.toLowerCase();if(f==="add"){let m=s.slice(2).join(" ");if(!m){vn();return}if(!p){r("Create not available",e.yellow);return}r(`Creating "${m}"...`,e.amber),p(m).then(h=>{r(`\u2713 Created "${h.title}" (${h.id})`,e.green),H();},h=>r(`Failed: ${g(h)}`,e.red));}else if(f==="list"){let m=xe.map(h=>` ${h.id} ${h.status.padEnd(11)} ${h.title}`);if(m.length===0)r("No tasks",e.dim);else for(let h of m)r(h,e.cyan);}else if(f==="show"){let m=s[2]?xe.find(h=>h.id===s[2]):E;if(!m){r("No task selected or id given",e.yellow);return}r(`${m.id} ${m.status} P${m.priority} "${m.title}"`,e.cyan),m.assignee&&r(` agent: ${m.assignee}`,e.dim),m.description&&r(` ${m.description.slice(0,100)}`,e.dim);}else if(f==="cancel"){let m=s[2]?xe.find(h=>h.id===s[2]):E;if(!m){r("No task selected or id given",e.yellow);return}if(!w)return;r(`Cancelling "${m.title}"...`,e.amber),w(m.id).then(()=>{r(`\u2713 Cancelled "${m.title}"`,e.green),H();},h=>r(`Failed: ${g(h)}`,e.red));}else if(f==="retry"){let m=s[2]?xe.find(h=>h.id===s[2]):E;if(!m){r("No task selected or id given",e.yellow);return}if(!T)return;r(`Retrying "${m.title}"...`,e.amber),T(m.id).then(()=>{r(`\u2713 Retried "${m.title}"`,e.green),H();},h=>r(`Failed: ${g(h)}`,e.red));}else if(f==="assign"){let m=s[2]?xe.find(dt=>dt.id===s[2]):void 0,h=m??E,V=m?s[3]:s[2];if(!h){r("No task selected or id given",e.yellow);return}if(!V){r("Usage: /task assign [id] <agent>",e.yellow);return}if(!b$1)return;r(`Assigning "${h.title}" to ${V}...`,e.amber),b$1(h.id,V).then(()=>{r(`\u2713 Assigned "${h.title}" to ${V}`,e.green),H();},dt=>r(`Failed: ${g(dt)}`,e.red));}else if(f==="approve"){let m=s[2]?xe.find(h=>h.id===s[2]):E;if(!m){r("No task selected or id given",e.yellow);return}if(m.status!=="review"){r(`Cannot approve \u2014 status is ${m.status}`,e.yellow);return}if(!K)return;r(`Approving "${m.title}"...`,e.amber),K(m.id).then(()=>{r(`\u2713 Approved "${m.title}"`,e.green),H();},h=>r(`Failed: ${g(h)}`,e.red));}else if(f==="reject"){let m=s[2]?xe.find(V=>V.id===s[2]):E;if(!m){r("No task selected or id given",e.yellow);return}if(m.status!=="review"){r(`Cannot reject \u2014 status is ${m.status}`,e.yellow);return}if(!j)return;let h=s.slice(s[2]&&xe.find(V=>V.id===s[2])?3:2).join(" ").trim()||void 0;r(`Rejecting "${m.title}"${h?" with feedback":""}...`,e.amber),j(m.id,h).then(()=>{r(`\u2713 Rejected "${m.title}" \u2192 todo`,e.green),H();},V=>r(`Failed: ${g(V)}`,e.red));}else if(f==="delete"){let m=s[2]?xe.find(h=>h.id===s[2]):E;if(!m){r("No task selected or id given",e.yellow);return}if(m.status==="in_progress"){r("Cannot delete \u2014 task is running",e.yellow);return}if(!G)return;jt("task",m.id,m.title);}else r("Usage: /task add|list|show|cancel|retry|assign|approve|reject|delete",e.yellow);return}case "agent":{let f=s[1]?.toLowerCase();if(f==="add"){let m=s[2];if(!m){$n();return}if(!W){r("Agent creation not available",e.yellow);return}let h=s[3];r(`Creating agent "${m}"...`,e.amber),W(m,h).then(V=>{r(`\u2713 Created agent "${V.name}" (${V.id}, ${V.adapter})`,e.green),H();},V=>r(`Failed: ${g(V)}`,e.red));}else if(f==="list"){let m=Ae.map(h=>` ${h.id} ${h.status.padEnd(8)} ${h.name} (${h.adapter})`);if(m.length===0)r("No agents",e.dim);else for(let h of m)r(h,e.cyan);}else if(f==="disable"){let m=s[2]?Ae.find(h=>h.id===s[2]||h.name===s[2]):q;if(!m){r("No agent selected or id given",e.yellow);return}if(!k)return;r(`Disabling ${m.name}...`,e.amber),k(m.id).then(()=>{r(`\u2713 Disabled ${m.name}`,e.green),H();},h=>r(`Failed: ${g(h)}`,e.red));}else if(f==="enable"){let m=s[2]?Ae.find(h=>h.id===s[2]||h.name===s[2]):q;if(!m){r("No agent selected or id given",e.yellow);return}if(!v)return;r(`Enabling ${m.name}...`,e.amber),v(m.id).then(()=>{r(`\u2713 Enabled ${m.name}`,e.green),H();},h=>r(`Failed: ${g(h)}`,e.red));}else if(f==="delete"||f==="remove"){let m=s[2]?Ae.find(h=>h.id===s[2]||h.name===s[2]):q;if(!m){r("No agent selected or id given",e.yellow);return}if(m.status==="running"){r("Cannot delete \u2014 agent is running",e.yellow);return}if(!z){r("Agent deletion not available",e.yellow);return}jt("agent",m.id,m.name);}else if(f==="autonomous"||f==="auto"){let m=s[2]?Ae.find(h=>h.id===s[2]||h.name===s[2]):q;if(!m){r("No agent selected or id given",e.yellow);return}if(!Ne){r("Autonomous toggle not available",e.yellow);return}m.autonomous?(r(`Disabling autonomous mode for "${m.name}"...`,e.amber),Ne(m.id,false).then(()=>{r(`${Bt} ${m.name} autonomous OFF`,e.cyan),H();},h=>r(`Failed: ${g(h)}`,e.red))):(r(`Enabling autonomous mode for "${m.name}"...`,e.amber),Ne(m.id,true).then(()=>{r(`${Bt} ${m.name} autonomous ON`,e.cyan),H();},h=>r(`Failed: ${g(h)}`,e.red)));}else f==="shop"?No():r("Usage: /agent add|list|disable|enable|delete|autonomous|shop",e.yellow);return}case "team":{let f=s[1]?.toLowerCase();if(f==="create"||f==="add")Do();else if(f==="list"){let m=an.current;if(m.length===0)r("No teams",e.dim);else for(let h of m)r(` ${h.id} ${h.status.padEnd(8)} ${h.name} (${h.members.length} members)`,e.cyan);}else if(f==="join"){if(!ce){r("Join not available",e.yellow);return}let m=s[2],h=s[3]??q?.id;if(!m||!h){r("Usage: /team join <teamId> [agentId]",e.yellow);return}r(`Joining team ${m}...`,e.amber),ce(m,h).then(V=>{r(`\u2713 Agent joined team "${V.name}"`,e.green),H({includeTeams:true});},V=>r(`Failed: ${g(V)}`,e.red));}else if(f==="leave"){if(!we){r("Leave not available",e.yellow);return}let m=s[2],h=s[3]??q?.id;if(!m||!h){r("Usage: /team leave <teamId> [agentId]",e.yellow);return}r(`Leaving team ${m}...`,e.amber),we(m,h).then(V=>{r(`\u2713 Agent left team "${V.name}"`,e.green),H({includeTeams:true});},V=>r(`Failed: ${g(V)}`,e.red));}else if(f==="disband"){if(!it){r("Disband not available",e.yellow);return}let m=s[2];if(!m){r("Usage: /team disband <teamId>",e.yellow);return}r(`Disbanding team ${m}...`,e.amber),it(m).then(()=>{r("\u2713 Team disbanded",e.green),H({includeTeams:true});},h=>r(`Failed: ${g(h)}`,e.red));}else if(f==="set-lead"){if(!He){r("Set-lead not available",e.yellow);return}let m=s[2],h=s[3];if(!m||!h){r("Usage: /team set-lead <teamId> <agentId>",e.yellow);return}r(`Setting lead for team ${m}...`,e.amber),He(m,h).then(V=>{r(`\u2713 New lead for team "${V.name}"`,e.green),H({includeTeams:true});},V=>r(`Failed: ${g(V)}`,e.red));}else r("Usage: /team create|list|join|leave|disband|set-lead",e.yellow);return}case "goal":{let f=s[1]?.toLowerCase();if(f==="add"||f==="create"){let m=s.slice(2).join(" ").trim();if(!m){let h=Vn(ke);Fe({title:"New Goal",steps:h,kind:"goal"}),$e("wizard");return}if(!De){r("Goal creation not available",e.yellow);return}r(`Creating goal "${m}"...`,e.amber),De({title:m}).then(h=>{r(`\u2713 Created goal "${h.title}" (${h.id})`,e.green),H();},h=>r(`Failed: ${g(h)}`,e.red));}else if(f==="list"){let m=Ye.map(h=>` ${h.id} ${h.status.padEnd(8)} ${h.title}`);if(m.length===0)r("No goals",e.dim);else for(let h of m)r(h,e.cyan);}else if(f==="show"){let m=s[2]?Ye.find(h=>h.id===s[2]):Y;if(!m){r("No goal selected or id given",e.yellow);return}r(`${m.id} ${m.status} "${m.title}"`,e.cyan),m.description&&r(` ${m.description.slice(0,100)}`,e.dim);}else if(f==="status"){let m=s[2]?Ye.find(Rt=>Rt.id===s[2]):void 0,h=m??Y;if(!h){r("No goal selected or id given",e.yellow);return}let V=s[m?3:2];if(!V||!a$1.includes(V)){r("Usage: /goal status [id] <active|paused|achieved|abandoned>",e.yellow);return}let dt=V;if(!Se){r("Status update not available",e.yellow);return}r(`Updating goal status to ${dt}...`,e.amber),Se(h.id,dt).then(Rt=>{r(`\u2713 Goal "${Rt.title}" \u2192 ${dt}`,e.green),H();},Rt=>r(`Failed: ${g(Rt)}`,e.red));}else if(f==="delete"){let m=s[2]?Ye.find(h=>h.id===s[2]):Y;if(!m){r("No goal selected or id given",e.yellow);return}if(!We){r("Goal deletion not available",e.yellow);return}jt("goal",m.id,m.title);}else r("Usage: /goal add|list|show|status|delete",e.yellow);return}case "run":{let f=s[1]??E?.id;if(!f){r("No task selected or id given",e.yellow);return}if(!d){r("Run not available",e.yellow);return}let m=xe.find(h=>h.id===f);if(m&&!ko.has(m.status)){r(`Cannot run \u2014 status is ${m.status}`,e.yellow);return}r(`Running ${f}...`,e.amber),d(f).then(()=>{r(`\u2713 Dispatched ${f}`,e.green),H();},h=>r(`Failed: ${g(h)}`,e.red));return}case "run-all":{if(!x){r("Run-all not available",e.yellow);return}r("Running all todo tasks...",e.amber),x().then(()=>{r("\u2713 Dispatched all todo tasks",e.green),H();},f=>r(`Failed: ${g(f)}`,e.red));return}case "watch":{if(bn){r("Watch mode already active",e.yellow);return}if(!Xe){r("Watch not available",e.yellow);return}r("Starting watch mode...",e.amber),Xe().then(()=>{Jn(true),r("\u2713 Watch mode started",e.green);},f=>r(`Failed: ${g(f)}`,e.red));return}case "pause":{if(!bn){r("Watch mode not active",e.yellow);return}if(!Je){r("Pause not available",e.yellow);return}r("Pausing watch mode...",e.amber),Je().then(()=>{Jn(false),r("\u2713 Watch mode paused",e.green);},f=>r(`Failed: ${g(f)}`,e.red));return}case "config":{s[1]?.toLowerCase()==="activity-filter"?oo(m=>{let h=Co(m);return Q?.(h.label),r(`Activity filter: ${h.label}`,e.amber),new Set(h.types)}):Wo();return}case "status":{let f=tt.filter(m=>m.status==="in_progress").length;r(`${uo} ${f} running ${tt.length} tasks ${Ae.length} agents`,e.cyan);return}case "help":{for(let[f,m]of Object.entries(Lt)){let h=m.sub?" "+m.sub.join("|"):m.args?" "+m.args:"";r(` /${f}${h} \u2014 ${m.help}`,e.silver);}return}case "quit":{xt();return}case "disable":{if(!q){r("No agent selected",e.yellow);return}if(!k)return;r(`Disabling ${q.name}...`,e.amber),k(q.id).then(()=>{r(`\u2713 Disabled ${q.name}`,e.green),H();},f=>r(`Failed: ${g(f)}`,e.red));return}case "enable":{if(!q){r("No agent selected",e.yellow);return}if(!v)return;r(`Enabling ${q.name}...`,e.amber),v(q.id).then(()=>{r(`\u2713 Enabled ${q.name}`,e.green),H();},f=>r(`Failed: ${g(f)}`,e.red));return}default:r(`Unknown: ${c}. Type /help for commands`,e.yellow);}},[E,q,xe,Ae,tt,uo,bn,w,T,b$1,x,d,p,k,v,W,K,j,G,ce,we,it,He,Xe,Je,r,xt,H,vn,$n,Do,Wo]);useInput((i,y)=>{if((y.ctrl||y.meta)&&i==="s"&&Ie==="wizard"&&ot?.kind==="agent"){No();return}if(Ie!=="none"){if(y.escape){$e("none"),at(""),Sn.reset();return}if(y.return){let s=It.trim();if(!s)return;if(Ie==="new_task"){if(!p)return;$e("none"),at(""),r(`Creating "${s}"...`,e.amber),p(s).then(c=>{r(`\u2713 Created "${c.title}" (${c.id})`,e.green),H();},c=>r(`Failed to create: ${c instanceof Error?c.message:String(c)}`,e.red));}else if(Ie==="command"){let c=s;if(lt.length>0&&lt[kn]){let g=lt[kn],f=g.cmd.replace(/\s+\[.*\]$/,"");if((f.startsWith(s)||s==="/")&&(c=f),g.subs&&!f.includes(" ")){at(f+" "),bt(0);return}}$e("none"),at(""),bt(0),Sn.push(c),zs(c);}return}if(y.tab&&Ie==="command"){if(lt.length>0){let s=lt[kn];if(s){let c=s.cmd.replace(/\s+\[.*\]$/,"");at(c+(s.subs?" ":"")),bt(0);}}else {let s=xo(It);s&&at(c=>c+s);}return}if(y.upArrow&&Ie==="command"){if(lt.length>0)bt(s=>Math.max(0,s-1));else {let s=Sn.prev();s!==null&&at(s);}return}if(y.downArrow&&Ie==="command"){if(lt.length>0)bt(s=>Math.min(lt.length-1,s+1));else {let s=Sn.next();at(s??"");}return}if(y.backspace||y.delete){at(s=>s.slice(0,-1)),bt(0);return}i&&!y.ctrl&&!y.meta&&(at(s=>s+i),bt(0));return}if(i.toLowerCase()==="q"){xt();return}if(y.escape){if(Ce){en(false),sn(0);return}if(I==="logs"&&nn>=0){no(-1),on(0);return}return}if(i==="/"&&!Ce){$e("command"),at("/"),bt(0);return}if(I==="logs"&&!Ce&&i>="0"&&i<="9"){hs(parseInt(i,10));return}if((i==="f"||i==="F")&&I==="logs"&&!Ce){bs(s=>new Set(Co(s).types));return}if((i==="z"||i==="Z")&&zt.length>0){vs();return}if((i==="f"||i==="F")&&(I==="tasks"||I==="agents"||I==="goals")&&!Ce){oo(s=>{let c=Co(s);return Q?.(c.label),new Set(c.types)});return}if((i==="n"||i==="N")&&I==="tasks"&&!Ce&&p){vn();return}if((i==="n"||i==="N")&&I==="agents"&&!Ce&&W){$n();return}if((i==="n"||i==="N")&&I==="goals"&&!Ce&&De){let s=Vn(ke);Fe({title:"New Goal",steps:s,kind:"goal"}),$e("wizard");return}if((i==="e"||i==="E")&&I==="goals"&&Y&&Qe){let s=Yr(Y,ke);Fe({title:`Edit Goal: ${Y.title}`,steps:s,kind:"edit_goal",targetId:Y.id}),$e("wizard");return}if((i==="d"||i==="D")&&I==="goals"&&Y&&We){jt("goal",Y.id,Y.title);return}if((i==="c"||i==="C")&&I==="goals"&&Y&&Se){(Y.status==="active"||Y.status==="paused")&&(r(`Marking goal "${Y.title}" as achieved...`,e.amber),Se(Y.id,"achieved").then(()=>{r(`\u2713 Goal "${Y.title}" achieved`,e.green),H();},s=>r(`Failed: ${s instanceof Error?s.message:String(s)}`,e.red)));return}if((i==="x"||i==="X")&&I==="goals"&&Y&&Se){(Y.status==="active"||Y.status==="paused")&&(r(`Abandoning goal "${Y.title}"...`,e.amber),Se(Y.id,"abandoned").then(()=>{r(`\u2713 Goal "${Y.title}" abandoned`,e.dim),H();},s=>r(`Failed: ${s instanceof Error?s.message:String(s)}`,e.red)));return}if((i==="p"||i==="P")&&I==="goals"&&Y&&Se){let s=Y.status==="paused"?"active":"paused";(Y.status==="active"||Y.status==="paused")&&Se(Y.id,s).then(()=>{r(`Goal "${Y.title}" ${s}`,e.cyan),H();},c=>r(`Failed: ${c instanceof Error?c.message:String(c)}`,e.red));return}if((i==="a"||i==="A")&&I==="tasks"&&E?.status==="review"&&K){r(`Approving "${E.title}"...`,e.amber),K(E.id).then(()=>{r(`\u2713 Approved "${E.title}"`,e.green),H();},s=>r(`Failed: ${s instanceof Error?s.message:String(s)}`,e.red));return}if((i==="x"||i==="X")&&I==="tasks"&&E?.status==="review"&&j){r(`Rejecting "${E.title}"...`,e.amber),j(E.id).then(()=>{r(`\u2713 Rejected "${E.title}" \u2192 todo`,e.green),H();},s=>r(`Failed: ${s instanceof Error?s.message:String(s)}`,e.red));return}if((i==="c"||i==="C")&&I==="tasks"&&E&&w){if(E.status==="done"||E.status==="failed"||E.status==="cancelled"){r(`Cannot cancel \u2014 status is ${E.status}`,e.yellow);return}r(`Cancelling "${E.title}"...`,e.amber),w(E.id).then(()=>{r(`\u2713 Cancelled "${E.title}"`,e.green),H();},s=>r(`Failed: ${s instanceof Error?s.message:String(s)}`,e.red));return}if((i==="e"||i==="E")&&I==="tasks"&&E&&_){As(E);return}if((i==="e"||i==="E")&&I==="agents"&&q&&$){Ms(q);return}if((i==="s"||i==="S")&&I==="tasks"){Eo(s=>!s),yn(0),rn(0);return}if((i==="s"||i==="S")&&I==="agents"&&q&&A){if(!Object.values(qe.running).some(c=>c.agent_id===q.id)&&q.status!=="running"){r(`Agent "${q.name}" is not running`,e.yellow);return}r(`Force-stopping agent "${q.name}"...`,e.amber),A(q.id).then(()=>{r(`\u2713 Stopped agent "${q.name}"`,e.green),H();},c=>r(`Failed: ${c instanceof Error?c.message:String(c)}`,e.red));return}if((i==="d"||i==="D")&&I==="tasks"&&E&&E.status!=="in_progress"&&G){jt("task",E.id,E.title);return}if((i==="d"||i==="D")&&I==="agents"&&q&&z){let s=Object.values(qe.running).some(c=>c.agent_id===q.id);if(s&&!A){r(`Cannot delete \u2014 agent "${q.name}" is running. Press S to stop first.`,e.yellow);return}jt("agent",q.id,q.name,{needsForceStop:s});return}if((i==="u"||i==="U")&&I==="agents"&&q&&Ne){let s=!q.autonomous;r(`${s?"Enabling":"Disabling"} autonomous mode for "${q.name}"...`,e.amber),Ne(q.id,s).then(()=>{r(`${Bt} ${q.name} autonomous ${s?"ON":"OFF"}`,e.cyan),H();},c=>r(`Failed: ${c instanceof Error?c.message:String(c)}`,e.red));return}if(!Ce){if(i==="g"||i==="G"){Ft("goals");return}if(i==="t"||i==="T"){Ft("tasks");return}if(i==="a"||i==="A"){Ft("agents");return}if(i==="l"||i==="L"){Ft("logs");return}}if(!Ce){let s=Ln.map(g=>g.id),c=s.indexOf(I);if(y.tab||y.rightArrow){Ft(s[(c+1)%s.length]);return}if(y.leftArrow){Ft(s[(c+s.length-1)%s.length]);return}}if(y.return){let s=yt>0?gt.length:-1;if(I==="tasks"&&Tn===s){Eo(g=>!g),yn(0),rn(0);return}let c=gt.length+(yt>0?1:0);if(I==="tasks"&&Tn===c&&p){vn();return}if(I==="goals"&&to===Ye.length&&De){let g=Vn(ke);Fe({title:"New Goal",steps:g,kind:"goal"}),$e("wizard");return}if(I==="agents"&&eo===Ae.length&&W){$n();return}if(I==="goals"&&Y){en(g=>!g),sn(0);return}if(I==="tasks"&&E){en(g=>!g);return}if(I==="agents"&&q){en(g=>!g);return}if(I==="logs"&&nn>=0){en(g=>!g);return}}if((i==="r"||i==="R")&&I==="tasks"&&E&&d){if(!ko.has(E.status)){r(`Cannot run "${E.title}" \u2014 status is ${E.status}`,e.yellow);return}r(`Running "${E.title}"...`,e.green),d(E.id).then(()=>{r(`Dispatched "${E.title}"`,e.green),H();},s=>r(`Failed to run: ${s instanceof Error?s.message:String(s)}`,e.red));return}if(y.upArrow||i==="k"){if(I==="goals"&&Ce){sn(s=>Math.max(0,s-1));return}I==="goals"?Ao(s=>{let c=Math.max(0,s-1);return io(g=>c<g?c:g),c}):I==="tasks"?yn(s=>{let c=Math.max(0,s-1);return rn(g=>c<g?c:g),c}):I==="agents"?_o(s=>{let c=Math.max(0,s-1);return so(g=>c<g?c:g),c}):I==="logs"&&no(s=>{if(s===-1){let g=nt.length-1;return on(Math.max(0,g-be+2)),Math.max(0,g)}let c=Math.max(0,s-1);return on(g=>c<g?c:g),c});}if(y.downArrow||i==="j"){if(I==="goals"&&Ce){sn(s=>s+1);return}if(I==="goals"){let s=Ye.length+(De?1:0)-1;Ao(c=>{let g=Math.min(Math.max(0,s),c+1);return io(f=>g>=f+be?g-be+1:f),g});}else if(I==="tasks"){let s=gt.length+(p?1:0)+(yt>0?1:0)-1;yn(c=>{let g=Math.min(Math.max(0,s),c+1);return rn(f=>g>=f+be?g-be+1:f),g});}else if(I==="agents"){let s=Ae.length+(W?1:0)-1;_o(c=>{let g=Math.min(Math.max(0,s),c+1);return so(f=>g>=f+be?g-be+1:f),g});}else I==="logs"&&no(s=>{if(s===-1)return -1;let c=nt.length-1;if(s>=c)return on(0),-1;let g=s+1;return on(f=>g>=f+be-1?g-be+2:f),g});}});let Ge=Ie!=="none",Go=nn>=0?nt[nn]:void 0,zo=!Ge&&Ce&&I==="tasks"&&E,Vo=!Ge&&Ce&&I==="agents"&&q,jo=!Ge&&Ce&&I==="goals"&&Y,Vs=!Ge&&Ce&&I==="logs"&&Go,js=!Ge&&I==="tasks"&&E&&ko.has(E.status)&&!!d,Us=!Ge&&!Ce&&(I==="goals"&&!!De||I==="tasks"&&!!p||I==="agents"&&!!W),Hs=!Ge&&I==="tasks"&&E?.status==="review"&&!!K,Xs=!Ge&&I==="tasks"&&E?.status==="review"&&!!j,qs=q?Object.values(qe.running).some(i=>i.agent_id===q.id):false,Ys=!Ge&&(I==="goals"&&Y&&!!We||I==="tasks"&&E&&E.status!=="in_progress"&&!!G||I==="agents"&&q&&!!z),Ks=!Ge&&!Ce&&(I==="goals"&&!!Y&&!!Qe||I==="tasks"&&!!E&&!!_||I==="agents"&&!!q&&!!$),Zs=!Ge&&I==="agents"&&q&&(qs||q.status==="running")&&!!A,Js=!Ge&&I==="agents"&&!!q&&!!Ne,Qs=!Ge&&I==="goals"&&!!Y&&(Y.status==="active"||Y.status==="paused")&&!!Se,ei=!Ge&&zt.length>0,Uo=Ie==="command"&&lt.length>0,Ho=ot?.kind==="task"||ot?.kind==="edit_task";return jsxs(Box,{flexDirection:"column",width:Wt,height:Zn,children:[jsx(br,{projectName:t,activeView:I,mode:uo,stats:Fo,tokens:Ls,uptime:Es,width:Wt,version:fe,latestVersion:ye,taskBadge:yt>0?xe.length:void 0}),jsx(Box,{height:1}),vo==="welcome"&&I==="tasks"&&jsx(vr,{width:Wt,height:Zn}),I==="goals"&&jsx(ra,{goals:Ye,selectedIndex:to,scrollOffset:ks,height:be,width:he,showAddRow:!!De,agentNameMap:vt}),vo!=="welcome"&&I==="tasks"&&jsx(ia,{tasks:gt,selectedIndex:Tn,scrollOffset:ws,height:be,width:he,showAddRow:!!p,agentNameMap:vt,hiddenCount:yt}),I==="tasks"&&yt>0&&jsx(Box,{paddingX:1,backgroundColor:e.ghost,children:jsxs(Text,{color:e.amber,children:["showing ",gt.length," of ",xe.length," tasks ","\xB7"," press ",jsx(Text,{bold:true,color:e.amber,children:"S"})," to show all"]})}),I==="agents"&&jsx(aa,{agents:Ae,selectedIndex:eo,scrollOffset:Ss,height:be,width:he,state:qe,taskTitleMap:Cn,showAddRow:!!W,agentTeamMap:Vt,teamLeadSet:Is,activeTeamCount:ln}),I==="logs"&&jsx(ua,{messages:nt,height:be,agents:Ae,logFilter:fs,logTypeFilter:xs,selectedIndex:nn,scrollOffset:Ts,agentNameMap:vt,taskTitleMap:Cn,width:he}),jsx(Box,{height:1}),Ie==="wizard"&&ot?jsx(Sr,{title:ot.title,steps:ot.steps,onComplete:Rs,onCancel:Bs,width:he,height:Mt,onPasteImage:Ho?_s:void 0,footerExtra:ot.kind==="agent"?`${process.platform==="darwin"?"\u2318":"Ctrl"}+S browse shop`:$t.length>0&&Ho?`\u{1F4CE}${$t.length}`:void 0},`${ot.kind}-${ot.title}`):Uo?jsxs(Fragment,{children:[jsx(jn,{label:"COMMANDS",width:he}),jsx(oa,{suggestions:lt,selectedIndex:kn,height:Math.min(lt.length,Mt),width:he})]}):Ie==="new_task"?jsxs(Fragment,{children:[jsx(Ta,{mode:Ie,width:he}),jsx(ya,{mode:Ie,value:It,width:he})]}):zo?jsxs(Fragment,{children:[jsx(pa,{task:E,width:he}),jsx(mr,{task:E,height:Mt,width:he,taskLogs:nt.filter(i=>i.taskId===E.id),agentNameMap:vt})]}):jo?jsxs(Fragment,{children:[jsx(jn,{label:`GOAL: ${Y.title}`,width:he}),jsx(sa,{goal:Y,height:Mt,width:he,agentNameMap:vt,tasks:$s,progressReport:ps,scrollOffset:Cs,onClampScroll:sn})]}):Vo?jsxs(Fragment,{children:[jsx(fa,{agent:q,width:he}),jsx(ha,{agent:q,height:Mt,state:qe,taskTitleMap:Cn,teamName:Vt.get(q.id)})]}):Vs?jsxs(Fragment,{children:[jsx(jn,{label:"LOG",width:he}),jsx(ma,{message:Go,height:Mt,width:he,agents:Ae,agentNameMap:vt,taskTitleMap:Cn})]}):nt.length>0&&I!=="logs"?jsxs(Fragment,{children:[(()=>{let i=` F:${wn.toUpperCase()} \u2502 ${ro.length}/${nt.length}`;return jsx(jn,{label:"ACTIVITY",width:he,suffixLen:i.length,suffix:jsxs(Fragment,{children:[jsx(Text,{color:e.dim,children:" F:"}),jsx(Text,{color:e.amber,children:wn.toUpperCase()}),jsxs(Text,{color:e.ghost,children:[" ","\u2502"," ",ro.length,"/",nt.length]})]})})})(),jsx(ga,{messages:ro,height:Math.max(1,Mt-1),width:he,agents:Ae,agentNameMap:vt})]}):I==="goals"?jsx(Gn,{count:Ye.length,config:Ji,width:he}):I==="tasks"?jsx(Gn,{count:xe.length,config:Qi,width:he}):I==="agents"?jsx(Gn,{count:Ae.length,config:ea,width:he}):null,jsx(Box,{flexGrow:1}),zt.length>0&&jsx(na,{deletions:zt,width:Wt}),jsx(yr,{mode:Ie==="command"?"command":"navigate",value:Ie==="command"?It:"",completion:Ie==="command"?xo(It):null,activeView:I,canRun:!!js,canNew:!!Us,canApprove:!!Hs,canReject:!!Xs,canCancel:I==="tasks"&&!!E&&E.status==="in_progress"&&!!w,canDelete:!!Ys,canUndo:!!ei,canEdit:!!Ks,canForceStop:!!Zs,canToggleAuto:!!Js,autoActive:q?.autonomous,canPause:!!Qs,isPaused:Y?.status==="paused",canToggleShowAll:I==="tasks"&&xe.length>Zr,showAllActive:Bo,hasDetail:!!(zo||Vo||jo),itemCount:I==="goals"?Ye.length:I==="tasks"?xe.length:I==="agents"?ke.length:nt.length,itemLabel:I==="goals"?"goals":I==="tasks"?"tasks":I==="agents"?"agents":"events",width:Wt,hasSuggestions:Uo})]})}var na=Xn.memo(function({deletions:n,width:o}){let[,a]=useState(0);useEffect(()=>{let p=setInterval(()=>a(w=>w+1),1e3);return ()=>clearInterval(p)},[]);let d=Date.now();return jsx(Box,{flexDirection:"column",width:o,children:n.map(p=>{let w=Math.max(0,Math.ceil((p.expiresAt-d)/1e3)),T=Math.max(0,o-4),b=p.entityType==="task"?"Task":p.entityType==="agent"?"Agent":"Goal",x=Math.max(10,T-b.length-30),k=p.entityName.length>x?p.entityName.slice(0,x-1)+"\u2026":p.entityName;return jsx(Box,{paddingX:2,children:jsxs(Text,{color:e.yellow,children:["\u2717 ",jsx(Text,{bold:true,children:b}),` "${k}" \u2014 `,jsxs(Text,{color:e.amber,bold:true,children:[w,"s"]}),jsx(Text,{color:e.dim,children:" \u2502 "}),jsx(Text,{color:e.gray,bold:true,children:"Z"}),jsx(Text,{color:e.dim,children:" undo"})]})},p.key)})})});function oa({suggestions:t,selectedIndex:n,height:o,width:a}){let d=o,p=0;n>=d&&(p=n-d+1);let w=t.slice(p,p+d);return jsx(Box,{flexDirection:"column",paddingX:2,children:w.map((T,b)=>{let x=b+p,k=x===n,v=k?"\u25B6":" ",O=Math.min(20,Math.max(14,...t.map(W=>W.cmd.length+1))),P=T.cmd.padEnd(O),X=T.subs?` ${T.subs}`:"",N=Math.max(4,a-O-X.length-8),F=T.desc.length>N?T.desc.slice(0,N-1)+"\u2026":T.desc;return jsxs(Text,{wrap:"truncate",children:[jsx(Text,{color:k?e.amber:e.ghost,children:` ${v} `}),jsx(Text,{color:k?e.white:e.silver,bold:k,children:P}),jsx(Text,{color:e.dim,children:F}),X&&jsx(Text,{color:e.ghost,children:X})]},x)})})}function ra({goals:t,selectedIndex:n,scrollOffset:o=0,height:a,width:d,showAddRow:p,agentNameMap:w}){let T=t.length,b=t.slice(o,o+a),x=p&&T>=o&&T<o+a;return jsxs(Box,{flexDirection:"column",height:a,children:[b.map((k,v)=>jsx(Box,{paddingX:2,children:jsx(gr,{goal:k,selected:v+o===n,width:d-2,agentNameMap:w})},k.id)),x&&jsx(Box,{paddingX:2,children:jsxs(Text,{color:n===T?e.amber:e.ghost,children:[n===T?" \u25B8 ":" ",jsx(Text,{color:n===T?e.amber:e.dim,children:"+ add goal..."})]})},"__add__")]})}function sa({goal:t,height:n,width:o,agentNameMap:a,tasks:d,progressReport:p,scrollOffset:w=0,onClampScroll:T}){let x=Xn.useMemo(()=>{let N=d??[],F=t.assignee?a?.get(t.assignee)??t.assignee:"\u2014",W=Math.max(20,o-6),z=(A,R)=>{if(A.length<=R)return [A];let pe=[];for(let ce=0;ce<A.length;ce+=R)pe.push(A.slice(ce,ce+R));return pe},K=mo(p)?.split(`
11
- `).flatMap(A=>z(A,W))??[],j=mo(t.description)?.split(`
12
- `).flatMap(A=>z(A,W))??[],G=er[t.status]??e.dim,_=new Map;for(let A of N)_.set(A.status,(_.get(A.status)??0)+1);let $=[];if($.push({key:"row-status",node:jsxs(Box,{children:[jsxs(Box,{width:24,children:[jsx(Text,{color:e.dim,children:" status "}),jsx(Text,{color:G,bold:true,children:t.status})]}),jsxs(Box,{children:[jsx(Text,{color:e.dim,children:" assignee "}),jsx(Text,{color:t.assignee?e.green:e.dim,children:F})]})]})}),$.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&&$.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)})]})]})}),N.length>0){let A=[];for(let[R,pe]of _)A.push(`${pe} ${R}`);$.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:N.length})]}),jsxs(Box,{children:[jsx(Text,{color:e.dim,children:" "}),jsx(Text,{color:e.dim,children:A.join(" \xB7 ")})]})]})});}if(j.length>0){$.push({key:"desc-gap",node:jsx(Text,{children:" "})});for(let A=0;A<j.length;A++)$.push({key:`desc-${A}`,node:jsxs(Text,{color:e.silver,wrap:"truncate",children:[" ",j[A]]})});}else $.push({key:"desc-gap",node:jsx(Text,{children:" "})}),$.push({key:"desc-empty",node:jsx(Text,{color:e.dim,children:" No description."})});if(K.length>0){$.push({key:"prog-gap",node:jsx(Text,{children:" "})}),$.push({key:"prog-div",node:jsx(Zt,{label:"progress",width:o})});for(let A=0;A<K.length;A++)$.push({key:`prog-${A}`,node:jsxs(Text,{color:e.white,wrap:"truncate",children:[" ",K[A]]})});}if(N.length>0){$.push({key:"tasks-gap",node:jsx(Text,{children:" "})}),$.push({key:"tasks-div",node:jsx(Zt,{label:`tasks (${N.length})`,width:o})});for(let A of N){let R=Rn[A.status]??e.dim;$.push({key:`task-${A.id}`,node:jsxs(Text,{color:e.silver,wrap:"truncate",children:[" ",jsx(Text,{color:R,children:A.status.padEnd(12)}),A.title.slice(0,Math.max(10,o-22))]})});}}return $},[t,d,p,o,a]),k=Math.max(0,x.length-n),v=Math.min(w,k);Xn.useEffect(()=>{T&&v!==w&&T(v);},[v,w,T]);let O=x.length>n&&v<k,P=O?n-1:n,X=x.slice(v,v+P);return jsxs(Box,{flexDirection:"column",height:n,paddingX:2,children:[X.map(N=>jsx(Box,{children:N.node},N.key)),O&&jsxs(Text,{color:e.ghost,children:[" ","\u2193"," ",x.length-v-P," more ","\u2014"," ","\u2191","\u2193"," to scroll"]})]})}function ia({tasks:t,selectedIndex:n,scrollOffset:o=0,height:a,width:d,showAddRow:p,agentNameMap:w,hiddenCount:T=0}){let b=T>0,x=b?t.length:-1,k=t.length+(b?1:0),v=t.slice(o,o+a),O=b&&x>=o&&x<o+a,P=p&&k>=o&&k<o+a;return jsxs(Box,{flexDirection:"column",height:a,children:[v.map((X,N)=>jsx(Box,{paddingX:2,children:jsx(En,{task:X,selected:N+o===n,width:d-2,agentNameMap:w})},X.id)),O&&jsx(Box,{paddingX:2,children:jsxs(Text,{color:n===x?e.amber:e.ghost,children:[n===x?" \u25B8 ":" ",jsxs(Text,{color:n===x?e.amber:e.dim,children:["\u25BC"," Show all (",T," more) \u2014 press ",jsx(Text,{bold:true,color:e.gray,children:"S"})]})]})},"__show_all__"),P&&jsx(Box,{paddingX:2,children:jsxs(Text,{color:n===k?e.amber:e.ghost,children:[n===k?" \u25B8 ":" ",jsx(Text,{color:n===k?e.amber:e.dim,children:"+ add task..."})]})},"__add__")]})}function aa({agents:t,selectedIndex:n,scrollOffset:o=0,height:a,width:d,state:p,taskTitleMap:w,showAddRow:T,agentTeamMap:b,teamLeadSet:x,activeTeamCount:k}){let v=new Map;for(let _ of Object.values(p.running))v.set(_.agent_id,_);let O=new Map;if(k&&k>0)for(let _ of t){let $=b?.get(_.id);$&&O.set($,(O.get($)??0)+1);}let P=t.length,X=t.slice(o,o+a),N=T&&P>=o&&P<o+a,F=k!=null&&k>0,W=new Map;if(F&&x&&b){for(let _ of t)if(x.has(_.id)){let $=b.get(_.id);$&&W.set($,_.name);}}let z=0;for(let _ of O.values())z+=_;let K=t.length-z,j=[],G=o>0?b?.get(t[o-1]?.id??""):void 0;for(let _=0;_<X.length&&j.length<a;_++){let $=X[_],A=b?.get($.id);if(F&&A&&A!==G&&(j.push(jsx(lr,{teamName:A,memberCount:O.get(A)??0,leadName:W.get(A),width:d},`ts-${A}`)),j.length>=a)||F&&!A&&G&&(j.push(jsx(cr,{memberCount:K,width:d},"ts-unassigned")),j.length>=a))break;G=A,j.push(jsx(Box,{paddingX:2,children:jsx(ar,{agent:$,selected:_+o===n,width:d-2,runningEntry:v.get($.id),currentTaskTitle:$.current_task?w.get($.current_task):void 0,teamName:A,isLead:x?.has($.id)})},$.id));}return N&&j.length<a&&j.push(jsx(Box,{paddingX:2,children:jsxs(Text,{color:n===P?e.amber:e.ghost,children:[n===P?" \u25B8 ":" ",jsx(Text,{color:n===P?e.amber:e.dim,children:"+ add agent..."})]})},"__add__")),jsx(Box,{flexDirection:"column",height:a,children:j})}function ss(t=5e3){let[n,o]=useState(Date.now());return useEffect(()=>{let a=setInterval(()=>o(Date.now()),t);return ()=>clearInterval(a)},[t]),n}function is(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`}var la=" \u2581\u2582\u2583\u2584\u2585\u2586\u2587\u2588";function ca(t,n,o,a){let d=new Array(n).fill(0),p=a-n*o;for(let T of t){if(T.ts<p)continue;let b=Math.min(n-1,Math.floor((T.ts-p)/o));d[b]++;}let w=Math.max(1,...d);return d.map(T=>la[Math.round(T/w*8)]).join("")}function da(t){if(t==="error")return e.errorBg}function as(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 ua({messages:t,height:n,agents:o,logFilter:a,logTypeFilter:d,selectedIndex:p,scrollOffset:w,agentNameMap:T,taskTitleMap:b,width:x}){let k=ss(),v=useMemo(()=>t.filter(_=>{if(a!==0){let A=o[a-1];if(A&&_.agentId!==A.id)return false}let $=_.msgType??"info";return d.has($)}),[t,o,a,d]);useMemo(()=>{let _={};for(let $ of t){let A=$.msgType??"info";_[A]=(_[A]??0)+1;}return _},[t]);let P=useMemo(()=>{let _=new Map;for(let $ of t)$.agentId&&_.set($.agentId,(_.get($.agentId)??0)+1);return _},[t]),X=useMemo(()=>ca(v,30,1e4,k),[v,k]),N=d.size>=8?"all":d.size===1&&d.has("output")?"text":d.size===1&&d.has("error")?"errors":d.has("tool")&&!d.has("output")?"tools":d.has("lifecycle")&&!d.has("output")?"events":`${d.size} types`,F=n-3,W=p===-1?v.slice(-F):v.slice(w,w+F),z=p===-1?-1:p-w,K=Math.min(10,Math.max(6,...o.map(_=>_.name.length))),j=11+K,G=_=>{if(_===0)return true;let $=W[_],A=W[_-1];return $.agentId!==A.agentId?true:$.agentId?$.ts-A.ts>3e4:false};return jsxs(Box,{flexDirection:"column",paddingX:1,children:[jsxs(Box,{gap:0,children:[a===0?jsx(Text,{backgroundColor:e.infoBg,color:e.silver,bold:true,children:" \u25CF ALL "}):jsx(Text,{color:e.ghost,children:" \u25CB all "}),jsx(Text,{color:e.ghost,children:" "}),o.slice(0,9).map((_,$)=>{let A=Yn(_.id,o),R=a===$+1,pe=P.get(_.id)??0,ce=pe>0?`\xB7${pe}`:"";return R?jsxs(Text,{backgroundColor:e.successBg,color:A,bold:true,children:[" ",$+1,":",_.name,ce," "]},_.id):jsxs(Text,{color:pe>0?e.dim:e.ghost,children:[" ",$+1,":",_.name,ce]},_.id)})]}),jsxs(Box,{gap:0,children:[N==="all"?jsx(Text,{color:e.dim,children:" F:all"}):jsxs(Text,{backgroundColor:e.warnBg,color:e.amber,bold:true,children:[" F:",N.toUpperCase()," "]}),jsxs(Text,{color:e.ghost,children:[" ","\u2502"," "]}),jsxs(Text,{color:e.dim,children:[v.length," events"]}),jsxs(Text,{color:e.ghost,children:[" ","\u2502"," "]}),p===-1?jsxs(Box,{gap:0,children:[jsx(Text,{backgroundColor:e.successBg,color:e.green,children:" "}),jsx(Text,{backgroundColor:e.successBg,color:e.green,children:jsx(qt,{color:e.green})}),jsx(Text,{backgroundColor:e.successBg,color:e.green,children:" LIVE "})]}):jsxs(Text,{backgroundColor:e.warnBg,color:e.amber,children:[" \u2191\u2193 ",p+1,"/",v.length," "]}),jsx(Text,{color:e.ghost,children:" "}),jsx(Text,{color:e.amberDim,children:X}),jsx(Text,{color:e.ghost,children:" 5m"})]}),W.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"})]})]}):W.map((_,$)=>{let A=$===z,R=_.msgType??"info",pe=Kn[R]??"\u2502",ce=_.agentId?T.get(_.agentId)??_.agentId.slice(0,8):void 0,we=_.agentId?Yn(_.agentId,o):void 0,it=G($),Xe=($>0?W[$-1]:void 0)?.agentId===_.agentId&&!!_.agentId,Je=!Xe&&!!ce,Ne=Xe&&!!ce,Dt=as(R,_.color),De=A?e.infoBg:R==="error"?e.errorBg:void 0,Qe=_.taskId?b.get(_.taskId):void 0,Se=is(_.ts,k),We=Qe&&x>80?`#${Qe.slice(0,20)}`:"",L=We?We.length+3:0,B=Math.max(10,x-2-j-L),C=mt(_.text,B);return jsxs(Box,{backgroundColor:De,children:[jsx(Text,{color:we??e.ghost,children:it&&Je?"\u250C":Ne?"\u2502":" "}),jsx(Text,{color:A?e.amber:void 0,children:A?"\u25B8":" "}),jsx(Box,{width:5,children:jsx(Text,{color:Se==="now"?e.green:A?e.silver:e.ghost,children:Se.padStart(4)})}),jsx(Box,{width:K+1,children:Je?jsxs(Text,{color:we,bold:true,children:[" ",ce.slice(0,K).padEnd(K)]}):Ne?jsxs(Text,{color:we??e.ghost,children:[" ","\xB7".padEnd(K)]}):jsxs(Text,{color:e.ghost,children:[" "," ".padEnd(K)]})}),jsxs(Text,{color:R==="error"?e.red:we??e.dim,children:[" ",pe," "]}),jsx(Text,{color:A?e.white:Dt,bold:A||R==="lifecycle",children:C}),We&&jsxs(Text,{color:e.ghost,children:[" ",jsx(Text,{color:e.dim,backgroundColor:e.void,children:` ${We} `})]})]},$)})]})}function ga({messages:t,height:n,width:o,agents:a,agentNameMap:d}){let p=ss(),w=t.slice(-n),T=Math.max(10,o-2-17),b=Math.max(0,n-w.length),x=0,k=[];for(let v=0;v<w.length;v++)v>0&&w[v].agentId!==w[v-1].agentId&&x++,k.push(x);return jsxs(Box,{flexDirection:"column",paddingX:1,children:[b>0&&jsx(Box,{height:b}),w.map((v,O)=>{let P=v.agentId?d.get(v.agentId)??v.agentId.slice(0,8):void 0,X=v.agentId?Yn(v.agentId,a):void 0,N=v.msgType??"info",F=Kn[N]??"\u2502",W=as(N,v.color),K=(O>0?w[O-1]:void 0)?.agentId===v.agentId&&!!v.agentId,j=(k[O]&1)===1,G=da(N)??(j?"#1a1a1a":void 0),_=is(v.ts,p),$=mt(v.text,T);return jsxs(Box,{backgroundColor:G,children:[jsx(Text,{color:X??e.ghost,children:!K&&P?"\u258D":K?"\u258F":" "}),jsx(Box,{width:5,children:jsx(Text,{color:K?e.ghost:_==="now"?e.green:e.dim,children:K?" ":_.padStart(4)})}),jsx(Box,{width:9,children:P&&!K?jsxs(Text,{color:X,bold:true,children:[" ",P.slice(0,8)]}):jsx(Text,{color:e.ghost,children:ta})}),jsxs(Text,{color:N==="error"?e.red:K?e.ghost:X??e.dim,children:[F," "]}),jsx(Text,{color:W,children:$})]},O)})]})}function ma({message:t,height:n,width:o,agents:a,agentNameMap:d,taskTitleMap:p}){let w=t.detail??t.text,T=t.msgType??"info",b=t.agentId?d.get(t.agentId)??t.agentId.slice(0,8):void 0,x=t.agentId?Yn(t.agentId,a):e.dim,k=t.taskId?p.get(t.taskId):void 0,v,O=false;try{let F=JSON.parse(w);v=JSON.stringify(F,null,2),O=!0;}catch{v=w;}let P=Math.max(4,o-6),X=Math.max(1,n-4),N=v.split(`
13
- `).slice(0,X);return jsxs(Box,{flexDirection:"column",paddingX:1,children:[jsx(Box,{children:jsxs(Text,{color:e.ghost,children:["\u256D",Pe(P+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 "}),b&&jsx(Text,{color:x,bold:true,children:b}),b&&jsx(Text,{color:e.ghost,children:" \u2502 "}),jsxs(Text,{color:Kn[T]?T==="error"?e.red:e.dim:e.dim,children:[Kn[T]??"\u2502"," ",T]}),k&&jsxs(Fragment,{children:[jsx(Text,{color:e.ghost,children:" \u2502 "}),jsxs(Text,{color:e.dim,children:["#",k.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,P)})]}),jsx(Box,{children:jsxs(Text,{color:e.ghost,children:["\u251C",Pe(P+2),"\u2524"]})}),N.map((F,W)=>jsxs(Box,{children:[jsx(Text,{color:e.ghost,children:"\u2502 "}),O&&jsxs(Text,{color:e.ghost,children:[String(W+1).padStart(3)," "]}),jsx(Text,{wrap:"truncate",color:O&&F.includes('"')?e.cyan:O&&/^\s*[}\]]/.test(F)?e.ghost:F.startsWith("error")||F.startsWith("Error")?e.red:e.silver,children:F.slice(0,O?P-4:P)})]},W)),jsx(Box,{children:jsxs(Text,{color:e.ghost,children:["\u2570",Pe(P+2),"\u256F"]})})]})}function jn({label:t,width:n,suffix:o,suffixLen:a=0}){let d=` ${t} `,p=3,w=p+d.length+2;if(!o){let x=Math.max(0,n-w);return jsxs(Box,{paddingX:1,children:[jsx(Text,{color:e.ghost,children:Me(p)}),jsx(Text,{backgroundColor:"#1a1a22",color:e.dim,bold:true,children:d}),jsx(Text,{color:e.ghost,children:Me(x)})]})}let T=2,b=Math.max(0,n-w-T-a);return jsxs(Box,{paddingX:1,children:[jsx(Text,{color:e.ghost,children:Me(p)}),jsx(Text,{backgroundColor:"#1a1a22",color:e.dim,bold:true,children:d}),jsx(Text,{color:e.ghost,children:Me(T)}),o,jsx(Text,{color:e.ghost,children:Me(b)})]})}function pa({task:t,width:n}){let o=" DETAIL ",a=n-o.length-10,d=t.title.length>a?t.title.slice(0,a-3)+"...":t.title,p=Math.max(0,n-3-o.length-d.length-4);return jsxs(Box,{paddingX:1,children:[jsx(Text,{color:e.ghost,children:Me(3)}),jsx(Text,{backgroundColor:"#2d1f0a",color:e.amber,bold:true,children:o}),jsxs(Text,{color:e.ghost,children:[Mn," "]}),jsx(Text,{color:e.white,bold:true,children:d}),jsxs(Text,{color:e.ghost,children:[" ",Me(Math.max(0,p))]})]})}function fa({agent:t,width:n}){let o=" AGENT ",a=n-o.length-10,d=t.name.length>a?t.name.slice(0,a-3)+"...":t.name,p=Math.max(0,n-3-o.length-d.length-4);return jsxs(Box,{paddingX:1,children:[jsx(Text,{color:e.ghost,children:Me(3)}),jsx(Text,{backgroundColor:"#0f2d1f",color:e.green,bold:true,children:o}),jsxs(Text,{color:e.ghost,children:[Mn," "]}),jsx(Text,{color:e.green,bold:true,children:d}),jsxs(Text,{color:e.ghost,children:[" ",Me(Math.max(0,p))]})]})}function ha({agent:t,height:n,state:o,taskTitleMap:a,teamName:d}){let p=xa[t.status]??e.dim;Object.values(o.running).find(x=>x.agent_id===t.id);let T=t.current_task?a.get(t.current_task):void 0,b=24;return jsxs(Box,{flexDirection:"column",paddingX:2,children:[jsxs(Box,{children:[jsxs(Box,{width:b,children:[jsx(Text,{color:e.dim,children:" status "}),jsx(Text,{color:p,children:t.status})]}),jsxs(Box,{children:[jsx(Text,{color:e.dim,children:" adapter "}),jsx(Text,{color:e.cyan,children:t.adapter})]})]}),jsxs(Box,{children:[jsxs(Box,{width:b,children:[jsx(Text,{color:e.dim,children:" model "}),jsx(Text,{children:t.config.model??"\u2014"})]}),jsxs(Box,{children:[jsx(Text,{color:e.dim,children:" task "}),jsx(Text,{color:T?e.white:e.dim,children:T??"\u2014"})]})]}),jsxs(Box,{children:[jsxs(Box,{width:b,children:[jsx(Text,{color:e.dim,children:" runs "}),jsx(Text,{children:t.stats.total_runs}),jsx(Text,{color:e.dim,children:" ("}),jsx(Text,{color:e.green,children:t.stats.tasks_completed}),jsx(Text,{color:e.dim,children:"/"}),jsx(Text,{color:t.stats.tasks_failed>0?e.red:e.dim,children:t.stats.tasks_failed}),jsx(Text,{color:e.dim,children:")"})]}),jsxs(Box,{children:[jsx(Text,{color:e.dim,children:" team "}),jsx(Text,{color:d?e.amber:e.dim,children:d??"\u2014"})]})]}),t.autonomous&&jsx(Box,{children:jsxs(Box,{width:b,children:[jsx(Text,{color:e.dim,children:" auto "}),jsxs(Text,{color:e.cyan,children:[Bt," 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:mt(t.config.skills.join(", "),500)})]}),jsx(Text,{children:" "}),t.role?t.role.split(`
14
- `).slice(0,Math.max(1,n-4)).map((x,k)=>jsxs(Text,{color:e.silver,wrap:"truncate",children:[" ",mt(x,500)]},k)):jsx(Text,{color:e.dim,children:" No role description."})]})}var xa={idle:e.dim,running:e.green,error:e.red,disabled:e.ghost},ba="\u2588";function Ta({mode:t,width:n}){let a=` ${t==="command"?"COMMAND":"NEW TASK"} `,d=Math.max(0,n-3-a.length-2);return jsxs(Box,{paddingX:1,children:[jsx(Text,{color:e.ghost,children:Me(3)}),jsx(Text,{backgroundColor:"#2d1f0a",color:e.amber,bold:true,children:a}),jsx(Text,{color:e.ghost,children:Me(d)})]})}function ya({mode:t,value:n,width:o}){let a=t==="command"?"/":"\u25B8",d=Math.max(10,o-8),p=n.length>d?n.slice(-d):n;return jsxs(Box,{paddingX:2,children:[jsxs(Text,{color:e.amber,children:[a," "]}),jsx(Text,{color:e.white,children:p}),jsx(Text,{color:e.amber,children:ba})]})}function ls(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 a=JSON.stringify(o);return a.length>80?a.slice(0,77)+"...":a}function Un(t,n=200){if(typeof t=="string")return t.slice(0,n);if(!Array.isArray(t))return null;let o=[],a=0;for(let d of t){if(a>=n)break;if(d?.type==="text"&&typeof d.text=="string"){let p=d.text.split(`
15
- `).find(w=>w.trim().length>0)??"";o.push(p.slice(0,n-a)),a+=p.length;}else if(d?.type==="tool_use"){let p=ls(d.name??"tool",d.input),w=`\u2699 ${d.name??"tool"}(${p})`;o.push(w),a+=w.length;}else if(d?.type==="tool_result")o.push("\u2190 (result)"),a+=10;else if(d?.type==="thinking"&&typeof d.thinking=="string"){let p=d.thinking.slice(0,60).split(`
16
- `)[0]??"";o.push(`\u{1F4AD} ${p}`),a+=p.length+3;}}return o.length>0?o.join(" "):null}function ts(t){if(typeof t=="string"){let o=t.split(`
17
- `).length,a=t.split(`
18
- `).find(d=>d.trim().length>0)??"";return o>3?`${a.slice(0,80)}... (${o} lines)`:a.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 d=o.is_error,p=typeof o.content=="string"?o.content:"",w=p.split(`
19
- `).length;d?n.push(`\u2715 error: ${p.slice(0,60)}`):w>3?n.push(`\u2713 ${w} lines`):n.push(`\u2713 ${p.slice(0,80)}`);}else o?.type==="text"&&typeof o.text=="string"&&n.push(o.text.split(`
20
- `)[0]?.slice(0,80)??"");return n.join(" ")||"(result)"}function cs(t){let n=()=>t.length>qn?t.slice(0,qn)+"\u2026":t;if(os.test(t.trim()))return {summary:t.trim(),detail:n()};try{let o=JSON.parse(t);if(o.type==="message"&&o.role==="assistant"){let a=Un(o.content);return a?{summary:a.slice(0,200),detail:n()}:{summary:null,detail:""}}if(o.type==="assistant"||o.role==="assistant"){let a=o.message?.content??o.content,d=Un(a);return d?{summary:d.slice(0,200),detail:n()}:{summary:null,detail:""}}if(o.type==="user"||o.role==="user"){let a=o.message?.content??o.content;return {summary:`\u2190 ${ts(a).slice(0,180)}`,detail:n()}}if(o.type==="tool_use"){let a=o.name??"tool",d=ls(a,o.input);return {summary:`\u2699 ${a}(${d})`,detail:n()}}if(o.type==="tool_result")return {summary:`\u2190 ${ts(o.content).slice(0,180)}`,detail:n()};if(o.type==="result"){let a=typeof o.result=="string"?o.result:null;return {summary:a?`\u2713 ${a.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 a=o.message.content??o.message,d=Un(a);if(d)return {summary:d.slice(0,200),detail:n()}}return {summary:`[${o.subtype}]`,detail:n()}}if(o.content){let a=Un(o.content);if(a)return {summary:a.slice(0,200),detail:n()}}return o.type?{summary:`[${o.type}]`,detail:n()}:{summary:t.slice(0,150),detail:n()}}catch{return {summary:wa(t),detail:n()}}}function wa(t){let n=t.match(/"subtype"\s*:\s*"([^"]+)"/);if(n)return `[${n[1]}]`;let o=t.match(/"type"\s*:\s*"([^"]+)"/),a=t.match(/"role"\s*:\s*"([^"]+)"/),d=o?.[1],p=a?.[1];if(!d&&!p)return t.slice(0,200);if(d==="assistant"||d==="message"||p==="assistant"){let w=t.match(/"text"\s*:\s*"((?:[^"\\]|\\.)*)"/);if(w)try{return JSON.parse(`"${w[1]}"`).slice(0,200)}catch{}return "\u{1F4AC} (assistant)"}if(d==="user"||d==="tool_result"||p==="user")return "\u2190 (tool result)";if(d==="tool_use")return `\u2699 ${t.match(/"name"\s*:\s*"([^"]+)"/)?.[1]??"tool"}()`;if(d==="result"){let w=t.match(/"result"\s*:\s*"((?:[^"\\]|\\.)*)"/);if(w)try{return `\u2713 ${JSON.parse(`"${w[1]}"`).slice(0,180)}`}catch{}return "\u2713 Agent finished"}return d==="rate_limit_event"?"\u23F3 Rate limited":`[${d??p}]`}function Sa(t,n,o,a){let d=p=>a?.get(p);switch(t.type){case "agent:started":n("Started task",e.green,{agentId:t.agentId,taskId:t.taskId,msgType:"lifecycle"});break;case "agent:output":{let{summary:p,detail:w}=cs(t.data);if(p){let T=rs(p);n(p,T.color,{agentId:t.agentId,taskId:d(t.runId),detail:w,msgType:T.msgType});}break}case "agent:file_changed":n(`${t.path}`,e.purple,{agentId:t.agentId,taskId:d(t.runId),msgType:"file"});break;case "agent:completed":n(t.success?"Completed successfully":"Failed",t.success?e.green:e.red,{agentId:t.agentId,taskId:d(t.runId),msgType:"lifecycle"});break;case "agent:error":n(`${t.error.slice(0,150)}`,e.red,{agentId:t.agentId,taskId:d(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:d(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:d(t.runId),msgType:"error"});break}}export{dc as App,cc as _resetPendingDeletionSeq};
@@ -1,9 +0,0 @@
1
- #!/usr/bin/env node
2
- import {d,a,e}from'./chunk-5AJ4LYO5.js';import {j,o,l,q,d as d$1,h,m}from'./chunk-L26TK7Y5.js';function T($,o$1){let l$1=$.command("agent").description("Manage agents");l$1.command("add <name>").description("Add a new agent").requiredOption("--adapter <adapter>","Adapter type: claude, shell, codex, cursor").option("--role <role>","Agent role description").option("--command <cmd>","Shell command (for shell adapter)").option("--model <model>","Model name (for AI adapters)").option("--max-turns <n>","Max turns per run").option("--timeout <ms>","Timeout in ms").option("--approval-policy <policy>","suggest|auto|manual").option("--workspace-mode <mode>","shared|worktree|isolated").option("--skills <skills>","Comma-separated list of agent skills").option("-e, --edit","Open $EDITOR to write the role description").action(async(t,e$1)=>{await o$1.paths.requireInit();let i=e$1.role;if(e$1.edit){let a$1=d({name:t,model:e$1.model,role:i}),s=await a(a$1),d$1=e(s);d$1.name&&(t=d$1.name),d$1.model&&(e$1.model=d$1.model),d$1.role&&(i=d$1.role);}let n=await o$1.agentService.create({name:t,adapter:e$1.adapter,role:i,command:e$1.command,model:e$1.model,max_turns:e$1.maxTurns?parseInt(e$1.maxTurns,10):void 0,timeout_ms:e$1.timeout?parseInt(e$1.timeout,10):void 0,approval_policy:e$1.approvalPolicy,workspace_mode:e$1.workspaceMode,skills:e$1.skills?e$1.skills.split(",").map(a=>a.trim()):void 0});o$1.context.json?console.log(JSON.stringify(n,null,2)):o$1.context.quiet?console.log(n.id):j(`Added agent ${o(n.name)} (${n.adapter}) \u2192 ${n.id}`);}),l$1.command("shop").description("Browse and install pre-built agent templates").option("--list","Print all templates (non-interactive)").action(async t=>{await o$1.paths.requireInit();let{AGENT_SHOP_TEMPLATES:e}=await import('./agent-shop-D2RS4BZK.js');if(t.list||!process.stdout.isTTY){l(["Key","Name","Adapter","Model","Skills"],e.map(s=>[s.key,s.name,s.adapter,s.model.replace("claude-",""),s.skills.slice(0,2).join(", ")]));return}let{pickFromShop:i}=await import('./shop-picker-LE3SKFOX.js'),n=await i(e);if(!n){console.log(" Cancelled.");return}let a=await o$1.agentService.create({name:n.name,adapter:n.adapter,model:n.model,role:n.role,skills:n.skills,approval_policy:n.approval_policy});j(`Added agent ${o(a.name)} (${a.adapter}) \u2192 ${a.id}`);}),l$1.command("list").description("List all agents").action(async()=>{await o$1.paths.requireInit();let t=await o$1.agentService.list();if(o$1.context.json){console.log(JSON.stringify(t,null,2));return}if(o$1.context.quiet){t.forEach(a=>console.log(a.id));return}if(t.length===0){console.log(`
3
- No agents. Add one: ${q("orch agent add <name> --adapter claude")}
4
- `);return}let e=["STATUS","AGENT","ADAPTER","TASK","TIME"],i=t.map(a=>[`${d$1(a.status)} ${a.status}`,o(a.name),a.adapter,a.current_task??q("\u2014"),q("\u2014")]);console.log(),l(e,i);let n=t.filter(a=>a.status==="running").length;console.log(`
5
- ${t.length} agents \xB7 ${n} running \xB7 ${h(t.reduce((a,s)=>a+(s.stats.tokens_used??0),0))} tokens total
6
- `);}),l$1.command("status <id>").description("Show agent details").action(async t=>{await o$1.paths.requireInit();let e=await o$1.agentService.get(t);if(o$1.context.json){console.log(JSON.stringify(e,null,2));return}console.log(`
7
- ${e.name}`),console.log(` ${"\u2550".repeat(42)}`),console.log();let i=[["Adapter",`${e.adapter}${e.config.model?` (${e.config.model})`:""}`],["Status",`${d$1(e.status)} ${e.status}`],["Policy",e.config.approval_policy??"auto"]];e.current_task&&i.push(["Task",e.current_task]),e.role&&i.push(["Role",e.role]),e.config.skills?.length&&i.push(["Skills",e.config.skills.join(", ")]),m(i),console.log(`
8
- Stats
9
- ${"\u2500".repeat(42)}`),m([["Tasks completed",String(e.stats.tasks_completed)],["Tasks failed",String(e.stats.tasks_failed)],["Total runs",String(e.stats.total_runs)],["Tokens used",h(e.stats.tokens_used??0)]]),console.log();}),l$1.command("edit <id>").description("Edit an agent in $EDITOR").action(async t=>{await o$1.paths.requireInit();let e$1=await o$1.agentService.get(t),i=d({name:e$1.name,model:e$1.config.model,role:e$1.role}),n=await a(i),a$1=e(n),s=await o$1.agentService.update(t,{name:a$1.name,role:a$1.role,model:a$1.model});o$1.context.json?console.log(JSON.stringify(s,null,2)):o$1.context.quiet?console.log(s.id):j(`Updated agent ${o(s.name)} (${s.id})`);}),l$1.command("remove <id>").description("Remove an agent").action(async t=>{await o$1.paths.requireInit(),await o$1.agentService.remove(t),j(`Removed agent ${t}`);}),l$1.command("disable <id>").description("Disable an agent").action(async t=>{await o$1.paths.requireInit(),await o$1.agentService.disable(t),j(`Disabled agent ${t}`);}),l$1.command("enable <id>").description("Enable an agent").action(async t=>{await o$1.paths.requireInit(),await o$1.agentService.enable(t),j(`Enabled agent ${t}`);}),l$1.command("autonomous <id>").description("Toggle autonomous mode for an agent").option("--on","Enable autonomous mode").option("--off","Disable autonomous mode").action(async(t,e)=>{await o$1.paths.requireInit();let i=await o$1.agentService.get(t),n=e.on?true:e.off?false:!i.autonomous,a=await o$1.agentService.setAutonomous(t,n);o$1.context.json?console.log(JSON.stringify(a,null,2)):o$1.context.quiet?console.log(a.id):j(`Autonomous mode ${n?"enabled":"disabled"} for agent ${o(a.name)} (${a.id})`);});}export{T as registerAgentCommand};
@@ -1,2 +0,0 @@
1
- #!/usr/bin/env node
2
- export{a as AGENT_SHOP_TEMPLATES,b as getShopTemplateByKey}from'./chunk-BCPUTULS.js';
@@ -1,2 +0,0 @@
1
- #!/usr/bin/env node
2
- var n=class extends Error{constructor(r,s,x){super(r);this.exitCode=s;this.hint=x;this.name="OrchestryError";}},o=class extends n{constructor(){super("Not initialized",3,"Run: orch init"),this.name="NotInitializedError";}},i=class extends n{constructor(e){super(e,2),this.name="InvalidArgumentsError";}},a=class extends n{constructor(e){super(`Orchestrator already running (PID: ${e})`,4,"Use: orch status"),this.name="LockConflictError";}};var u=class extends n{constructor(){super("No agents configured",1,"Run: orch agent add <name> --adapter claude"),this.name="NoAgentsError";}},c=class extends n{constructor(e){super(`Task not found: ${e}`,1),this.name="TaskNotFoundError";}},d=class extends n{constructor(e){super(`Agent not found: ${e}`,1),this.name="AgentNotFoundError";}},l=class extends n{constructor(e,r,s){super(`Task ${e} is already running (run: ${r}, agent: ${s})`,1,`Use: orch logs --task ${e} --follow`),this.name="TaskAlreadyRunningError";}},p=class extends n{constructor(e,r,s){super(`Invalid transition for ${e}: ${r} \u2192 ${s}`,1),this.name="InvalidTransitionError";}},g=class extends n{constructor(e){super(`Goal not found: ${e}`,1),this.name="GoalNotFoundError";}},A=class extends n{constructor(e){super(`Team not found: ${e}`,1),this.name="TeamNotFoundError";}};var m=class extends n{constructor(e,r){super(e,6,r),this.name="WorkspaceError";}};function f(t,e){let r=t.toLowerCase();return r.includes("enoent")||r.includes("spawn failed")?"spawn_failed":r.includes("not found")||r.includes("command not found")||r.includes("no such file")?"adapter_not_found":r.includes("auth")||r.includes("unauthorized")||r.includes("401")||r.includes("invalid api key")||r.includes("authentication")?"auth_failed":r.includes("timeout")||r.includes("timed out")||r.includes("etimedout")?"timeout":r.includes("rate limit")||r.includes("429")||r.includes("too many requests")?"rate_limit":e!==void 0&&e!==0?"process_crash":"unknown"}export{n as a,o as b,i as c,a as d,u as e,c as f,d as g,l as h,p as i,g as j,A as k,m as l,f as m};
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env node
2
- import {mkdtemp,writeFile,readFile,unlink,rm}from'fs/promises';import {tmpdir}from'os';import {join}from'path';import {spawn}from'child_process';async function I(t,n={}){let{extension:l=".yml",prefix:a="orch-"}=n,e=process.env.EDITOR||process.env.VISUAL||"vi",m=await mkdtemp(join(tmpdir(),a)),c=join(m,`edit${l}`);await writeFile(c,t,"utf8");try{let r=e.split(/\s+/),i=spawn(r[0],[...r.slice(1),c],{stdio:"inherit"});return await new Promise((o,s)=>{i.on("close",d=>{d===0?o():s(new Error(`Editor exited with code ${d}`));}),i.on("error",s);}),await readFile(c,"utf8")}finally{await unlink(c).catch(()=>{}),await rm(m,{recursive:true}).catch(()=>{});}}function b(t){return ["---",`title: ${t.title}`,`priority: ${t.priority}`,"---","",t.description??""].join(`
3
- `)}function k(t){let n=t.match(/^---\n([\s\S]*?)\n---\n?([\s\S]*)$/);if(!n)return {description:t.trim()||void 0};let l=n[1]??"",a=n[2]??"",e={};for(let c of l.split(`
4
- `)){let r=c.match(/^([\w]+):\s*(.*)$/);if(!r)continue;let i=r[1],o=r[2]??"";if(i==="title"&&o.trim())e.title=o.trim();else if(i==="priority"){let s=parseInt(o.trim(),10);s>=1&&s<=4&&(e.priority=s);}}let m=a.trim();return m&&(e.description=m),e}function S(t){return ["# Edit agent configuration.","# Lines starting with # are ignored.","# Role description goes below the second --- separator.","---",`name: ${t.name}`,`model: ${t.model??""}`,"---","",t.role??""].join(`
5
- `)}function O(t){let n=t.split(`
6
- `),l=n.findIndex(i=>i.trimEnd()==="---"),a=(l>=0?[...n.slice(0,l).filter(i=>!i.startsWith("#")),...n.slice(l)]:n.filter(i=>!i.startsWith("#"))).join(`
7
- `),e=a.trimStart().match(/^---\n([\s\S]*?)\n---\n?([\s\S]*)$/);if(!e)return {role:a.trim()||void 0};let m=e[1]??"",c=e[2]??"",r={};for(let i of m.split(`
8
- `)){let o=i.match(/^([\w]+):\s*(.*)$/);if(!o)continue;let s=o[1],d=o[2]??"";s==="name"?r.name=d.trim():s==="model"&&(r.model=d.trim());}return r.role=c.trim(),r}export{I as a,b,k as c,S as d,O as e};
@@ -1,2 +0,0 @@
1
- #!/usr/bin/env node
2
- import {spawn}from'child_process';var c=class{isAlive(e){try{return process.kill(e,0),!0}catch(n){return n.code==="EPERM"}}kill(e,n="SIGTERM"){try{process.kill(-e,n);}catch{try{process.kill(e,n);}catch{}}}async killWithGrace(e,n=1e4){if(!this.isAlive(e))return;this.kill(e,"SIGTERM");let r=Date.now()+n;for(;Date.now()<r;){if(!this.isAlive(e))return;await new Promise(t=>setTimeout(t,200));}this.kill(e,"SIGKILL");}spawn(e,n,r){let t=spawn(e,n,{stdio:["ignore","pipe","pipe"],detached:true,...r});if(!t.pid)throw new Error(`Failed to spawn process: ${e}`);return t.unref(),{process:t,pid:t.pid}}},u=16384;function p(i){return i.length>u?i.slice(0,u):i}async function*h(i){let e=[],n=0;for await(let r of i){let t=Buffer.isBuffer(r)?r:Buffer.from(r,"utf-8");if(t.length===0)continue;e.push(t),n+=t.length;let o=e.length===1?e[0]:Buffer.concat(e,n);e.length=0,n=0;let s=0,l;for(;(l=o.indexOf(10,s))!==-1;)l>s&&(yield p(o.toString("utf-8",s,l))),s=l+1;if(s<o.length){let a=o.subarray(s);e.push(a),n=a.length;}}if(n>0){let r=e.length===1?e[0]:Buffer.concat(e,n);yield p(r.toString("utf-8"));}}export{c as a,h as b};
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/domain/task.ts","../src/infrastructure/template/template-engine.ts"],"names":[],"mappings":";AAiBO,IAAM,gBAAA,GAAmB;;;AC0DzB,IAAM,uBAAN,MAAsD;AAAA,EACnD,MAAA;AAAA,EACS,eAAA;AAAA,EAEjB,YAAY,OAAA,EAAwC;AAClD,IAAA,IAAA,CAAK,eAAA,GAAkB,SAAS,eAAA,IAAmB,GAAA;AAAA,EACrD;AAAA,EAEA,MAAc,SAAA,GAA6B;AACzC,IAAA,IAAI,CAAC,KAAK,MAAA,EAAQ;AAChB,MAAA,MAAM,EAAE,MAAA,EAAO,GAAI,MAAM,OAAO,UAAU,CAAA;AAC1C,MAAA,IAAA,CAAK,MAAA,GAAS,IAAI,MAAA,CAAO;AAAA,QACvB,aAAA,EAAe,KAAA;AAAA,QACf,eAAA,EAAiB;AAAA,OAClB,CAAA;AAAA,IACH;AACA,IAAA,OAAO,IAAA,CAAK,MAAA;AAAA,EACd;AAAA,EAEA,MAAM,MAAA,CAAO,QAAA,EAAkB,OAAA,EAAyC;AACtE,IAAA,MAAM,MAAA,GAAS,MAAM,IAAA,CAAK,SAAA,EAAU;AACpC,IAAA,MAAM,aAAA,GAAgB,MAAA,CAAO,cAAA,CAAe,QAAA,EAAU,OAAO,CAAA;AAE7D,IAAA,IAAI,IAAA,CAAK,mBAAmB,CAAA,EAAG;AAC7B,MAAA,OAAO,aAAA;AAAA,IACT;AAEA,IAAA,IAAI,KAAA;AACJ,IAAA,MAAM,cAAA,GAAiB,IAAI,OAAA,CAAe,CAAC,GAAG,MAAA,KAAW;AACvD,MAAA,KAAA,GAAQ,UAAA;AAAA,QACN,MAAM,OAAO,IAAI,KAAA,CAAM,mCAAmC,IAAA,CAAK,eAAe,IAAI,CAAC,CAAA;AAAA,QACnF,IAAA,CAAK;AAAA,OACP;AAAA,IACF,CAAC,CAAA;AAED,IAAA,IAAI;AACF,MAAA,OAAO,MAAM,OAAA,CAAQ,IAAA,CAAK,CAAC,aAAA,EAAe,cAAc,CAAC,CAAA;AAAA,IAC3D,CAAA,SAAE;AACA,MAAA,YAAA,CAAa,KAAM,CAAA;AAAA,IACrB;AAAA,EACF;AACF;AAcO,SAAS,mBACd,IAAA,EACA,KAAA,EACA,OAAA,EACA,aAAA,EACA,QACA,OAAA,EACe;AACf,EAAA,MAAM,EAAE,SAAA,EAAW,YAAA,EAAc,aAAA,EAAe,QAAA,EAAU,UAAU,WAAA,EAAa,IAAA,EAAK,GAAI,OAAA,IAAW,EAAC;AAGtG,EAAA,MAAM,SAAA,GAAY,IAAI,GAAA,CAAA,CAAK,SAAA,IAAa,EAAC,EAAG,GAAA,CAAI,CAAC,CAAA,KAAM,CAAC,CAAA,CAAE,EAAA,EAAI,CAAC,CAAC,CAAC,CAAA;AACjE,EAAA,MAAM,WAAW,WAAA,EAAa,MAAA,GAC1B,WAAA,CAAY,GAAA,CAAI,CAAC,CAAA,MAAO;AAAA,IACtB,IAAI,CAAA,CAAE,EAAA;AAAA,IACN,MAAM,SAAA,CAAU,GAAA,CAAI,EAAE,aAAa,CAAA,EAAG,QAAQ,CAAA,CAAE,aAAA;AAAA,IAChD,SAAS,CAAA,CAAE,OAAA;AAAA,IACX,MAAM,CAAA,CAAE,IAAA;AAAA,IACR,SAAS,CAAA,CAAE,UAAA;AAAA,IACX,UAAU,CAAA,CAAE;AAAA,IACZ,CAAA,GACF,MAAA;AAEJ,EAAA,OAAO;AAAA,IACL,OAAA,EAAS;AAAA,MACP,IAAA,EAAM,OAAO,OAAA,CAAQ,IAAA;AAAA,MACrB,WAAA,EAAa,OAAO,OAAA,CAAQ;AAAA,KAC9B;AAAA,IACA,IAAA,EAAM;AAAA,MACJ,IAAI,IAAA,CAAK,EAAA;AAAA,MACT,OAAO,IAAA,CAAK,KAAA;AAAA,MACZ,aAAa,IAAA,CAAK,WAAA;AAAA,MAClB,UAAU,IAAA,CAAK,QAAA;AAAA,MACf,QAAQ,IAAA,CAAK,MAAA;AAAA,MACb,OAAO,IAAA,CAAK,KAAA;AAAA,MACZ,aAAA,EAAe,IAAA,CAAK,MAAA,EAAQ,QAAA,CAAS,gBAAgB,CAAA,IAAK,KAAA;AAAA,MAC1D,SAAS,IAAA,CAAK;AAAA,KAChB;AAAA,IACA,KAAA,EAAO;AAAA,MACL,IAAI,KAAA,CAAM,EAAA;AAAA,MACV,MAAM,KAAA,CAAM,IAAA;AAAA,MACZ,MAAM,KAAA,CAAM;AAAA,KACd;AAAA,IACA,SAAS,SAAA,IAAa,EAAC,EAAG,GAAA,CAAI,CAAC,CAAA,MAAO;AAAA,MACpC,IAAI,CAAA,CAAE,EAAA;AAAA,MACN,MAAM,CAAA,CAAE,IAAA;AAAA,MACR,MAAM,CAAA,CAAE,IAAA;AAAA,MACR,SAAS,CAAA,CAAE;AAAA,KACb,CAAE,CAAA;AAAA,IACF,OAAA,EAAS,OAAA,GAAU,CAAA,GAAI,OAAA,GAAU,IAAA;AAAA,IACjC,cAAA,EAAgB,aAAA;AAAA,IAChB,KAAA,EAAO,OAAA,GAAU,CAAA,GAAI,YAAA,GAAe,MAAA;AAAA,IACpC,QAAA;AAAA,IACA,cAAA,EAAgB,iBAAiB,MAAA,CAAO,IAAA,CAAK,aAAa,CAAA,CAAE,MAAA,GAAS,IAAI,aAAA,GAAgB,MAAA;AAAA,IACzF,QAAA;AAAA,IACA;AAAA,GACF;AACF;AAGO,IAAM,uBAAA,GAA0B,CAAA;;AAAA;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;;AAAA;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAAA;AAAA;AAAA;AAAA;;AAAA;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA","file":"chunk-B4JQM4NU.js","sourcesContent":["/**\n * Task domain model.\n *\n * A Task is the unit of work in the orchestrator.\n * It moves through a state machine: todo → in_progress → review → done.\n */\n\nexport type TaskStatus =\n | 'todo'\n | 'in_progress'\n | 'retrying'\n | 'review'\n | 'done'\n | 'failed'\n | 'cancelled';\n\n/** Label applied to tasks auto-generated by the orchestrator for autonomous agents. */\nexport const AUTONOMOUS_LABEL = 'autonomous' as const;\n\nexport type WorkspaceMode = 'shared' | 'worktree' | 'isolated';\n\nexport type ReviewCriterion = 'test_pass' | 'typecheck' | 'lint';\n\nexport interface ReviewResult {\n criterion: ReviewCriterion;\n passed: boolean;\n output: string;\n}\n\nexport interface TaskProof {\n branch?: string;\n pr_url?: string;\n files_changed: string[];\n test_results?: string;\n agent_summary?: string;\n}\n\nexport interface Task {\n id: string;\n title: string;\n description: string;\n status: TaskStatus;\n priority: number;\n assignee?: string;\n labels: string[];\n depends_on: string[];\n created_at: string;\n updated_at: string;\n attempts: number;\n max_attempts: number;\n workspace_mode?: WorkspaceMode;\n workspace?: string;\n proof?: TaskProof;\n review_criteria?: ReviewCriterion[];\n review_results?: ReviewResult[];\n scope?: string[];\n feedback?: string;\n goalId?: string;\n attachments?: string[];\n}\n\nexport interface CreateTaskInput {\n title: string;\n description?: string;\n priority?: number;\n assignee?: string;\n labels?: string[];\n depends_on?: string[];\n max_attempts?: number;\n workspace_mode?: WorkspaceMode;\n review_criteria?: ReviewCriterion[];\n scope?: string[];\n goalId?: string;\n attachments?: string[];\n}\n","/**\n * Template engine for prompt construction.\n *\n * Uses LiquidJS for Liquid-compatible templating with\n * task, agent, project, and run context variables.\n */\n\nimport type { Liquid } from 'liquidjs';\nimport type { Agent } from '../../domain/agent.js';\nimport type { GoalStatus } from '../../domain/goal.js';\nimport type { OrchestratorConfig } from '../../domain/config.js';\nimport { AUTONOMOUS_LABEL, type Task } from '../../domain/task.js';\n\nexport interface ITemplateEngine {\n render(template: string, context: PromptContext): Promise<string>;\n}\n\nexport interface AgentInfo {\n id: string;\n name: string;\n role?: string;\n adapter: string;\n}\n\nexport interface RetryContext {\n previous_error: string;\n previous_output: string;\n}\n\nexport interface GoalContext {\n id: string;\n title: string;\n description: string;\n status: GoalStatus;\n task_names: string[];\n progress?: string;\n}\n\nexport interface PromptContext {\n project: {\n name: string;\n description?: string;\n };\n task: {\n id: string;\n title: string;\n description: string;\n priority: number;\n labels: string[];\n scope?: string[];\n is_autonomous: boolean;\n goal_id?: string;\n };\n agent: {\n id: string;\n name: string;\n role?: string;\n };\n agents: AgentInfo[];\n attempt: number | null;\n workspace_path: string;\n retry?: RetryContext;\n feedback?: string;\n shared_context?: Record<string, string>;\n messages?: Array<{\n id: string;\n from: string;\n subject: string;\n body: string;\n sent_at: string;\n reply_to?: string;\n }>;\n goal?: GoalContext;\n}\n\nexport class LiquidTemplateEngine implements ITemplateEngine {\n private engine: Liquid | undefined;\n private readonly renderTimeoutMs: number;\n\n constructor(options?: { renderTimeoutMs?: number }) {\n this.renderTimeoutMs = options?.renderTimeoutMs ?? 5_000;\n }\n\n private async getEngine(): Promise<Liquid> {\n if (!this.engine) {\n const { Liquid } = await import('liquidjs');\n this.engine = new Liquid({\n strictFilters: false,\n strictVariables: false,\n });\n }\n return this.engine;\n }\n\n async render(template: string, context: PromptContext): Promise<string> {\n const engine = await this.getEngine();\n const renderPromise = engine.parseAndRender(template, context);\n\n if (this.renderTimeoutMs <= 0) {\n return renderPromise;\n }\n\n let timer: ReturnType<typeof setTimeout>;\n const timeoutPromise = new Promise<never>((_, reject) => {\n timer = setTimeout(\n () => reject(new Error(`Template render timed out after ${this.renderTimeoutMs}ms`)),\n this.renderTimeoutMs,\n );\n });\n\n try {\n return await Promise.race([renderPromise, timeoutPromise]);\n } finally {\n clearTimeout(timer!);\n }\n }\n}\n\n/**\n * Build prompt context from domain objects.\n */\nexport interface BuildPromptOptions {\n allAgents?: Agent[];\n retryContext?: RetryContext;\n sharedContext?: Record<string, string>;\n feedback?: string;\n messages?: import('../../domain/message.js').Message[];\n goal?: GoalContext;\n}\n\nexport function buildPromptContext(\n task: Task,\n agent: Agent,\n attempt: number,\n workspacePath: string,\n config: OrchestratorConfig,\n options?: BuildPromptOptions,\n): PromptContext {\n const { allAgents, retryContext, sharedContext, feedback, messages: rawMessages, goal } = options ?? {};\n\n // Map messages to prompt-friendly shape\n const agentById = new Map((allAgents ?? []).map((a) => [a.id, a]));\n const messages = rawMessages?.length\n ? rawMessages.map((m) => ({\n id: m.id,\n from: agentById.get(m.from_agent_id)?.name ?? m.from_agent_id,\n subject: m.subject,\n body: m.body,\n sent_at: m.created_at,\n reply_to: m.reply_to,\n }))\n : undefined;\n\n return {\n project: {\n name: config.project.name,\n description: config.project.description,\n },\n task: {\n id: task.id,\n title: task.title,\n description: task.description,\n priority: task.priority,\n labels: task.labels,\n scope: task.scope,\n is_autonomous: task.labels?.includes(AUTONOMOUS_LABEL) ?? false,\n goal_id: task.goalId,\n },\n agent: {\n id: agent.id,\n name: agent.name,\n role: agent.role,\n },\n agents: (allAgents ?? []).map((a) => ({\n id: a.id,\n name: a.name,\n role: a.role,\n adapter: a.adapter,\n })),\n attempt: attempt > 1 ? attempt : null,\n workspace_path: workspacePath,\n retry: attempt > 1 ? retryContext : undefined,\n feedback,\n shared_context: sharedContext && Object.keys(sharedContext).length > 0 ? sharedContext : undefined,\n messages,\n goal,\n };\n}\n\n/** Default prompt template */\nexport const DEFAULT_PROMPT_TEMPLATE = `You are {{ agent.name }}{% if agent.role %} ({{ agent.role }}){% endif %}.\n\n## Task: {{ task.title }}\n{{ task.description }}\n\nPriority: {{ task.priority }}\n{% if attempt %}Attempt: {{ attempt }}{% endif %}\n{% if retry %}\n## Previous attempt failed\n**Error:** {{ retry.previous_error }}\n{% if retry.previous_output != \"\" %}\n**Last output:**\n\\`\\`\\`\n{{ retry.previous_output }}\n\\`\\`\\`\n{% endif %}\n**Important:** The previous approach failed. Analyze the error above and try a different strategy. Do NOT repeat the same steps that led to the failure.\n{% endif %}\n\n## Context\nProject: {{ project.name }}\nWorking directory: {{ workspace_path }}\n\n## Team\nYou are part of a multi-agent team. Available agents:\n{% for a in agents %}- **{{ a.name }}** ({{ a.adapter }}){% if a.role %} — {{ a.role }}{% endif %} · ID: \\`{{ a.id }}\\`\n{% endfor %}\nUse \\`orch agent list\\` to check current agent statuses. Find teammates by name/role — do NOT hardcode agent IDs.\n\n{% if feedback %}\n## Review Feedback\nThis task was previously completed but **rejected** during review with the following feedback:\n> {{ feedback }}\n\n**Important:** Address the feedback above. Focus on what the reviewer asked to change. Do NOT redo work that was already accepted.\n{% endif %}\n\n{% if shared_context %}\n## Shared Context\nOther agents have shared the following information:\n{% for entry in shared_context %}- **{{ entry[0] }}**: {{ entry[1] }}\n{% endfor %}\n{% endif %}\n\n{% if messages %}\n## Inbox ({{ messages.size }} message{% if messages.size != 1 %}s{% endif %})\n{% for msg in messages %}\n---\n**From:** {{ msg.from }}{% if msg.subject != \"\" %} · **Subject:** {{ msg.subject }}{% endif %}\n{{ msg.body }}\n{% if msg.reply_to %}*(Reply to: {{ msg.reply_to }})*{% endif %}\n---\n{% endfor %}\n{% endif %}\n\n## Orchestrator CLI\nManage tasks and coordinate with other agents using \\`orch\\`:\n\n**Tasks:**\n- \\`orch task add \"<title>\" -d \"<description>\" -p <1-4> --assignee <agent-id>\\` — create and assign a task\n- \\`orch task add \"<title>\" -d \"<description>\" --scope \"src/path/**\" --depends-on <task-id>\\` — scoped task with dependency\n- \\`orch task list [--status todo|in_progress|done|failed]\\` — list tasks\n\n**Messaging:**\n- \\`orch msg send <agent-id> \"<body>\" -s \"<subject>\"\\` — direct message\n- \\`orch msg broadcast \"<body>\" -s \"<subject>\"\\` — broadcast to all\n- \\`orch msg inbox {{ agent.id }}\\` — your pending messages\n\n**Shared context:**\n- \\`orch context set <key> <value>\\` / \\`orch context get <key>\\` / \\`orch context list\\`\n\n{% if goal %}\n## Goal: {{ goal.title }}\n**Status:** {{ goal.status }} · **ID:** \\`{{ goal.id }}\\`\n{% if goal.description != \"\" %}\n{{ goal.description }}\n{% endif %}\n{% if goal.task_names.size > 0 %}\n**Linked tasks ({{ goal.task_names.size }}):**\n{% for name in goal.task_names %}- {{ name }}\n{% endfor %}\nUse \\`orch task list --goal-id {{ goal.id }}\\` and \\`orch task show <id>\\` to inspect details.\n{% endif %}\n{% if goal.progress %}\n**Latest progress report:**\n{{ goal.progress }}\n{% endif %}\n{% endif %}\n\n{% if task.is_autonomous %}\n## Autonomous Goal Mode\nThis is an autonomous task driven by a goal. Work in a continuous loop until the goal is achieved:\n\n1. **Understand the goal** — read the Goal section above.\n2. **Decompose** — break the goal into concrete subtasks via \\`orch task add\\`. {% if task.goal_id %}Pass \\`--goal-id {{ task.goal_id }}\\` so subtasks are linked to this goal. {% endif %}Assign yourself for your specialty, delegate other work to appropriate teammates by role.\n3. **Execute** — follow your standard workflow for each subtask.\n4. **Track progress** — after each iteration: \\`orch context set {{ task.goal_id | default: \"<goal>\" }}-progress \"<summary of what's done and what remains>\"\\`.\n5. **Be proactive** — do NOT wait for tasks from others. Create your own subtasks and keep working.\n6. **Do NOT finish** the [auto] task until the goal is achieved — keep creating subtasks.\n7. **When done** — mark the goal as achieved: \\`orch goal status {{ task.goal_id | default: \"<goal-id>\" }} achieved\\`.\n\n**Deep inspection:** Use \\`orch goal show {{ task.goal_id | default: \"<goal-id>\" }}\\` to see full goal details at any time.\n{% endif %}\n\n## Rules\n- Do NOT ask clarifying questions. You are running autonomously without human input.\n- Make reasonable assumptions and proceed with the best approach.\n- If critical information is missing, document your assumptions and continue.\n- When a task is too large or spans multiple domains, break it into subtasks using \\`orch task add\\`.\n- When creating subtasks, use \\`--scope\\` to declare which files each task will touch, and \\`--depends-on\\` to order dependent work.\n`;\n"]}