@oxgeneral/orch 1.0.1 → 1.0.3

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 (132) hide show
  1. package/dist/App-A5TZETZ2.js +21 -0
  2. package/dist/agent-Q34L27AY.js +9 -0
  3. package/dist/agent-shop-D2RS4BZK.js +2 -0
  4. package/dist/chunk-4MMHVHA6.js +112 -0
  5. package/dist/chunk-64WUDYEM.js +6 -0
  6. package/dist/chunk-6MJ7V6VY.js +2 -0
  7. package/dist/{chunk-DAVHOWGD.js → chunk-BCPUTULS.js} +16 -188
  8. package/dist/{chunk-UIJYU3J7.js → chunk-BSJVYRI3.js} +5 -2
  9. package/dist/chunk-BSJVYRI3.js.map +1 -0
  10. package/dist/chunk-CDFA4IIQ.js +2 -0
  11. package/dist/chunk-CHRW4CLD.js +2 -0
  12. package/dist/{chunk-O2OQCSBL.js → chunk-FDSFFFMT.js} +46 -29
  13. package/dist/chunk-FDSFFFMT.js.map +1 -0
  14. package/dist/chunk-HMMPM7MF.js +3 -0
  15. package/dist/chunk-HXOMNULD.js +2 -0
  16. package/dist/chunk-IKNBPOQL.js +2 -0
  17. package/dist/chunk-KFQTWMZI.js +3 -0
  18. package/dist/chunk-LXNRCJ22.js +2 -0
  19. package/dist/{chunk-C6XZ3FJT.js → chunk-MOWC2CHX.js} +7 -4
  20. package/dist/chunk-MOWC2CHX.js.map +1 -0
  21. package/dist/chunk-P4JTJBWO.js +2 -0
  22. package/dist/chunk-PJ5DKXGR.js +2 -0
  23. package/dist/chunk-QNZ6D63E.js +4 -0
  24. package/dist/chunk-RHFRHCN5.js +16 -0
  25. package/dist/chunk-RHFRHCN5.js.map +1 -0
  26. package/dist/chunk-TPTHLFOB.js +2 -0
  27. package/dist/chunk-UMZEA3JT.js +5 -0
  28. package/dist/chunk-X54D5JZG.js +11 -0
  29. package/dist/{claude-WUJU5KIE.js → claude-4R6L6BWY.js} +4 -4
  30. package/dist/{claude-WUJU5KIE.js.map → claude-4R6L6BWY.js.map} +1 -1
  31. package/dist/claude-ZLVOLRUG.js +2 -0
  32. package/dist/cli.js +1 -199
  33. package/dist/clipboard-service-WVON5ZN4.js +25 -0
  34. package/dist/{codex-NYJWEPRQ.js → codex-IMOW5ZUZ.js} +4 -4
  35. package/dist/{codex-NYJWEPRQ.js.map → codex-IMOW5ZUZ.js.map} +1 -1
  36. package/dist/codex-YRSODLH4.js +2 -0
  37. package/dist/config-OOB7QEKM.js +2 -0
  38. package/dist/container-CFMUT5KS.js +4 -0
  39. package/dist/context-FXRERFSP.js +7 -0
  40. package/dist/cursor-2HILMNM3.js +2 -0
  41. package/dist/{cursor-3YHVD4NP.js → cursor-NHV7X3WG.js} +4 -4
  42. package/dist/{cursor-3YHVD4NP.js.map → cursor-NHV7X3WG.js.map} +1 -1
  43. package/dist/doctor-GKTV4YYD.js +2 -0
  44. package/dist/doctor-service-PB7YBH3F.js +2 -0
  45. package/dist/editor-7IFRWVTL.js +8 -0
  46. package/dist/goal-RNNZYMNR.js +8 -0
  47. package/dist/index.d.ts +16 -14
  48. package/dist/index.js +247 -75
  49. package/dist/index.js.map +1 -1
  50. package/dist/init-56QC5QVX.js +53 -0
  51. package/dist/logs-4ISTWUWV.js +12 -0
  52. package/dist/msg-4ELI7Q52.js +9 -0
  53. package/dist/opencode-3S4VDXRG.js +2 -0
  54. package/dist/{opencode-FAMPSA6X.js → opencode-ULT6DYCT.js} +6 -5
  55. package/dist/opencode-ULT6DYCT.js.map +1 -0
  56. package/dist/orchestrator-6XH2TY3T.js +6 -0
  57. package/dist/{orchestrator-X2CWGFCL.js.map → orchestrator-6XH2TY3T.js.map} +1 -1
  58. package/dist/orchestrator-DRITPUWT.js +13 -0
  59. package/dist/org-WAK3CDPG.js +3 -0
  60. package/dist/process-manager-33H27MQF.js +2 -0
  61. package/dist/registry-BO2PPRNG.js +2 -0
  62. package/dist/run-NE5E4JPW.js +3 -0
  63. package/dist/shell-OBHIVC2H.js +2 -0
  64. package/dist/{shell-NJNW3O6K.js → shell-UXEJRK3D.js} +4 -4
  65. package/dist/{shell-NJNW3O6K.js.map → shell-UXEJRK3D.js.map} +1 -1
  66. package/dist/shop-picker-LE3SKFOX.js +5 -0
  67. package/dist/status-NYHZ7Q5G.js +2 -0
  68. package/dist/task-JUS5OZJR.js +20 -0
  69. package/dist/team-VCJSUDWX.js +4 -0
  70. package/dist/template-engine-42PKL5KD.js +2 -0
  71. package/dist/tui-R6LXKKSH.js +2 -0
  72. package/dist/update-FFKCOV63.js +2 -0
  73. package/dist/update-check-HGMBDYHL.js +2 -0
  74. package/dist/{workspace-manager-EVD67GCG.js → workspace-manager-ABXFBL2A.js} +3 -3
  75. package/dist/{workspace-manager-EVD67GCG.js.map → workspace-manager-ABXFBL2A.js.map} +1 -1
  76. package/dist/workspace-manager-Q6WWXSTR.js +3 -0
  77. package/package.json +1 -1
  78. package/readme.md +5 -5
  79. package/dist/App-GJVTVGRU.js +0 -6717
  80. package/dist/agent-7ZJ3ZDJ7.js +0 -183
  81. package/dist/agent-shop-YN2BSLHM.js +0 -2
  82. package/dist/chunk-2C2TFQ7K.js +0 -136
  83. package/dist/chunk-45K2XID7.js +0 -29
  84. package/dist/chunk-4IFIOMCW.js +0 -86
  85. package/dist/chunk-7X2GI5OV.js +0 -181
  86. package/dist/chunk-C6XZ3FJT.js.map +0 -1
  87. package/dist/chunk-CHIP7O6V.js +0 -83
  88. package/dist/chunk-FRTKB575.js +0 -87
  89. package/dist/chunk-HXYAZGLP.js +0 -15
  90. package/dist/chunk-I3SMISEF.js +0 -29
  91. package/dist/chunk-K6DMQERQ.js +0 -89
  92. package/dist/chunk-LV6GDBBI.js +0 -297
  93. package/dist/chunk-MGGSRXWJ.js +0 -69
  94. package/dist/chunk-O2OQCSBL.js.map +0 -1
  95. package/dist/chunk-P6ATSXGL.js +0 -107
  96. package/dist/chunk-PNE6LQRF.js +0 -5
  97. package/dist/chunk-U2VDNUZL.js +0 -52
  98. package/dist/chunk-UIJYU3J7.js.map +0 -1
  99. package/dist/chunk-VXS2CJFH.js +0 -273
  100. package/dist/chunk-XDVMX2FO.js +0 -8
  101. package/dist/chunk-XDVMX2FO.js.map +0 -1
  102. package/dist/chunk-XJTJ2TJV.js +0 -221
  103. package/dist/claude-ZUEKJJ4X.js +0 -5
  104. package/dist/clipboard-service-RTDUUQQU.js +0 -200
  105. package/dist/codex-7IXXXG5U.js +0 -123
  106. package/dist/config-OTAVSMOD.js +0 -75
  107. package/dist/container-RY54L3XC.js +0 -1596
  108. package/dist/context-OL4BVUV5.js +0 -83
  109. package/dist/cursor-622RBRHH.js +0 -97
  110. package/dist/doctor-XSGQSD57.js +0 -67
  111. package/dist/doctor-service-TPOMFAIG.js +0 -2
  112. package/dist/goal-FMYYN2FR.js +0 -138
  113. package/dist/init-45BEMVL6.js +0 -199
  114. package/dist/logs-PHPYWQ6I.js +0 -207
  115. package/dist/msg-FUWWLEKM.js +0 -95
  116. package/dist/opencode-FAMPSA6X.js.map +0 -1
  117. package/dist/opencode-WOR53TSC.js +0 -98
  118. package/dist/orchestrator-O6MFMATT.js +0 -1448
  119. package/dist/orchestrator-X2CWGFCL.js +0 -5
  120. package/dist/process-manager-HUVNAPQV.js +0 -2
  121. package/dist/registry-PQWRVNF2.js +0 -2
  122. package/dist/run-N72G5V2H.js +0 -95
  123. package/dist/shell-DVFHHYAZ.js +0 -5
  124. package/dist/shop-picker-2HY67UWP.js +0 -79
  125. package/dist/status-RZWN2C6C.js +0 -56
  126. package/dist/task-5EL2RNGW.js +0 -221
  127. package/dist/team-PFLP4PPL.js +0 -97
  128. package/dist/template-engine-AWIS56BL.js +0 -3
  129. package/dist/tui-LN5XHSQY.js +0 -245
  130. package/dist/update-YLP7FPNY.js +0 -64
  131. package/dist/update-check-4YKLGBFB.js +0 -2
  132. package/dist/workspace-manager-JM6U7JOH.js +0 -215
@@ -0,0 +1,21 @@
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,h,g}from'./chunk-64WUDYEM.js';import {m}from'./chunk-IKNBPOQL.js';import tn,{useState,useMemo,useEffect,useRef,useCallback}from'react';import {Box,Text,useInput,useApp,useStdout}from'ink';import {jsxs,jsx,Fragment}from'react/jsx-runtime';var e={amber:"#ffaf00",amberDim:"#af8700",green:"#5faf87",red:"#d75f5f",blue:"#5fafd7",yellow:"#d7af00",cyan:"#5fd7d7",purple:"#af87ff",white:"#eeeeee",silver:"#bcbcbc",gray:"#808080",dim:"#585858",ghost:"#3a3a3a",void:"#262626",errorBg:"#3d1515",warnBg:"#3d2e0a",successBg:"#0f2d1f",infoBg:"#1a1a22",toolBg:"#0f1f2d"},kn="\u2501",We="\u2500",de="\xB7",qt="\u25C8",br="\u2605",lo="\u27F3",Gt="\u25C6",Cn={in_progress:e.green,retrying:e.yellow,review:e.blue,todo:e.dim,done:e.green,failed:e.red,cancelled:e.dim},ps=new Map,hs=new Map;function Ge(t){if(t<=0)return "";let o=ps.get(t);return o||(o=kn.repeat(t),ps.set(t,o)),o}function be(t){if(t<=0)return "";let o=hs.get(t);return o||(o=We.repeat(t),hs.set(t,o)),o}function et(t,o){return t.length>o?t.slice(0,o-1)+"\u2026":t}var Pa=1e4;function Tr(t,o=Pa){if(t)return t.length>o?t.slice(0,o)+`
3
+ \u2026[truncated]`:t}var xs={active:e.green,paused:e.dim,achieved:e.amber,abandoned:e.ghost};var Fa=120,yr=0,Zo=null,In=new Set;function Wa(){Zo||(Zo=setInterval(()=>{yr++;for(let t of In)t(yr);},Fa));}function Ga(){Zo&&In.size===0&&(clearInterval(Zo),Zo=null);}function co(){let[t,o]=useState(yr);return useEffect(()=>{let n=r=>o(r);return In.add(n),Wa(),()=>{In.delete(n),Ga();}},[]),t}var bs=["\u280B","\u2819","\u2839","\u2838","\u283C","\u2834","\u2826","\u2827","\u2807","\u280F"];function _o({color:t}){let o=co();return jsx(Text,{color:t,children:bs[o%bs.length]})}var Jo={in_progress:0,retrying:1,review:2,todo:3,done:4,failed:5,cancelled:6};var ja="\u25CB",ys="\u2713",ws="\u2715",Ua="\u21BB",Xa="\u2500",qa="\u25B6",Lt={green:"#0f2d1f",blue:"#0f1f2d",yellow:"#2d2a0f",red:"#2d0f0f",neutral:"#1a1a22",amber:"#2d1f0a"},Ka={in_progress:{icon:qa,label:"RUN",fg:e.green,bg:Lt.green,bold:true,spinner:true},retrying:{icon:Ua,label:"RETRY",fg:e.yellow,bg:Lt.yellow,spinner:true},review:{icon:qt,label:"REVIEW",fg:e.blue,bg:Lt.blue},todo:{icon:ja,label:"TODO",fg:e.dim,bg:Lt.neutral},done:{icon:ys,label:"DONE",fg:e.green,bg:Lt.green},failed:{icon:ws,label:"FAIL",fg:e.red,bg:Lt.red,bold:true},cancelled:{icon:Xa,label:"OFF",fg:e.dim,bg:Lt.neutral}},Ya={1:{color:e.red,label:"!!!"},2:{color:e.yellow,label:"!!"},3:{color:e.dim,label:"!"},4:{color:e.ghost,label:de}};var Ja=18,Qa="#2d1f0a",Mn=tn.memo(function({task:o,selected:n,width:r,agentNameMap:l,goalMap:f$1}){let b=Ka[o.status],T=o.status==="in_progress"||o.status==="retrying",h=Ya[o.priority]??{color:e.ghost,label:de},y,S;if(o.status==="done")y=ys,S=e.green;else if(o.status==="failed")y=ws,S=e.red;else if(T){let O=Date.now()-new Date(o.updated_at).getTime();y=f(O),S=e.cyan;}else y="\u2014",S=void 0;let C=n?"\u25B8":" ",_=o.goalId?f$1?.get(o.goalId):void 0,k=!!_,j=10,V=4,z=14,E=k?Ja:0,U=7,B=2+j+V+z+E+U,$=r?Math.max(10,r-B):40,D=o.assignee?l?.get(o.assignee)??o.assignee:void 0;return jsxs(Box,{children:[jsxs(Text,{color:n?e.amber:void 0,children:[C," "]}),jsx(Box,{width:j,children:jsx(Text,{backgroundColor:b.bg,color:b.fg,bold:b.bold,children:b.spinner?jsxs(Fragment,{children:[" ",jsx(_o,{color:b.fg})," ",b.label," "]}):jsxs(Fragment,{children:[" ",b.icon," ",b.label," "]})})}),jsx(Box,{width:V,children:jsx(Text,{color:h.color,bold:o.priority<=2,children:h.label})}),jsxs(Box,{width:$,children:[jsx(Text,{wrap:"truncate",bold:n||T,color:n?e.white:T?e.silver:void 0,children:o.title.length>$?o.title.slice(0,$-1)+"\u2026":o.title}),(o.attachments?.length??0)>0&&jsxs(Text,{color:e.dim,children:[" ","\u{1F4CE}",o.attachments.length]})]}),k&&jsx(Box,{width:E,children:jsxs(Text,{backgroundColor:Qa,color:e.amberDim,wrap:"truncate",children:[" \u2295 ",et(_.title,13)," "]})}),jsx(Box,{width:z,children:D?jsxs(Text,{backgroundColor:Lt.green,color:e.green,wrap:"truncate",children:[" ",D.length>z-2?D.slice(0,z-3)+"\u2026":D," "]}):jsx(Text,{color:e.ghost,children:"\u2014"})}),jsx(Box,{width:U,justifyContent:"flex-end",children:jsx(Text,{color:S,dimColor:!S,children:y})})]})});var Ss="\u2295";function ks({goalTitle:t,taskCount:o,doneCount:n,width:r}){let l=o>0?Math.round(n/o*100):0,f=` ${Ss} ${t.toUpperCase()} ${de} ${o} task${o!==1?"s":""} ${de} ${l}% done `,b=3,T=Math.max(0,r-b-f.length-4);return jsxs(Box,{paddingX:2,children:[jsx(Text,{color:e.ghost,children:be(b)}),jsx(Text,{backgroundColor:Lt.amber,color:e.amber,bold:true,children:f}),jsx(Text,{color:e.ghost,children:be(T)})]})}function Cs({taskCount:t,width:o}){let n=` ${Ss} UNGROUPED ${de} ${t} task${t!==1?"s":""} `,r=3,l=Math.max(0,o-r-n.length-4);return jsxs(Box,{paddingX:2,children:[jsx(Text,{color:e.ghost,children:be(r)}),jsx(Text,{backgroundColor:Lt.neutral,color:e.dim,children:n}),jsx(Text,{color:e.ghost,children:be(l)})]})}var tl="\u2715",Is="\u25CB",ol="\u25B6",nl="\u2713",Ao={green:"#0f2d1f",red:"#2d0f0f",neutral:"#1a1a22",amber:"#2d1f0a"},rl={running:{icon:ol,label:"ACTIVE",fg:e.green,bg:Ao.green,bold:true,spinner:true},idle:{icon:Is,label:"IDLE",fg:e.dim,bg:Ao.neutral},error:{icon:tl,label:"ERROR",fg:e.red,bg:Ao.red,bold:true},disabled:{icon:Is,label:"OFF",fg:e.ghost,bg:Ao.neutral}},wr={running:0,idle:1,error:2,disabled:3},vs=tn.memo(function({agent:o,selected:n,width:r,runningEntry:l,currentTaskTitle:f$1,teamName:b,isLead:T}){let h=rl[o.status],y=o.status==="running",S,C;if(y&&l){let D=Date.now()-new Date(l.started_at).getTime();S=f(D),C=e.cyan;}else o.stats.total_runs>0?(S=`${o.stats.tasks_completed}/${o.stats.total_runs}`,C=o.stats.tasks_completed>0?e.green:e.dim):(S="\u2014",C=void 0);let _=n?"\u25B8":" ",k=11,j=8,V=b?Math.min(b.length+2,12):0,z=10,E=2+k+j+V+z,U=r?Math.max(8,r-E):20,B=o.stats.total_runs>0,$=B?Math.round(o.stats.tasks_completed/o.stats.total_runs*100):0;return jsxs(Box,{children:[jsxs(Text,{color:n?e.amber:void 0,children:[_," "]}),jsx(Box,{width:k,children:jsx(Text,{backgroundColor:h.bg,color:h.fg,bold:h.bold,children:h.spinner?jsxs(Fragment,{children:[" ",jsx(_o,{color:h.fg})," ",h.label," "]}):jsxs(Fragment,{children:[" ",h.icon," ",h.label," "]})})}),jsx(Box,{width:U,children:jsxs(Text,{wrap:"truncate",bold:n||y,color:n?e.white:y?e.green:e.silver,children:[o.autonomous&&jsxs(Text,{color:e.cyan,children:[lo," "]}),T&&jsxs(Text,{color:e.amber,children:[br," "]}),o.name,y&&f$1&&jsxs(Text,{color:e.dim,children:[" ",de," ",f$1]}),o.status==="error"&&o.last_error&&jsxs(Text,{color:e.red,children:[" ",de," ",et(m[o.last_error.kind]?.message??o.last_error.message,30)]})]})}),jsx(Box,{width:j,children:jsx(Text,{color:e.dim,children:o.adapter})}),b&&jsx(Box,{width:V,children:jsx(Text,{color:e.amber,wrap:"truncate",children:b})}),jsx(Box,{width:z,justifyContent:"flex-end",children:B&&!y?jsxs(Text,{color:$>=80?e.green:$>=50?e.yellow:e.red,children:[S," ",nl]}):jsx(Text,{color:C,dimColor:!C,children:S})})]})});function _s({teamName:t,memberCount:o,leadName:n,width:r}){let l=`${o} agent${o!==1?"s":""}`,f=n?` ${de} ${br} ${n}`:"",b=` ${qt} ${t.toUpperCase()} ${de} ${l}${f} `,T=3,h=Math.max(0,r-T-b.length-4);return jsxs(Box,{paddingX:2,children:[jsx(Text,{color:e.ghost,children:be(T)}),jsx(Text,{backgroundColor:Ao.amber,color:e.amber,bold:true,children:b}),jsx(Text,{color:e.ghost,children:be(h)})]})}var sl="\u25C7";function As({memberCount:t,width:o}){let n=`${t} agent${t!==1?"s":""}`,r=` ${sl} UNASSIGNED ${de} ${n} `,l=3,f=Math.max(0,o-l-r.length-4);return jsxs(Box,{paddingX:2,children:[jsx(Text,{color:e.ghost,children:be(l)}),jsx(Text,{backgroundColor:Ao.neutral,color:e.dim,children:r}),jsx(Text,{color:e.ghost,children:be(f)})]})}var Rs="\u2713",$s="\u2715",al="\u2016",ll="\u25C9",en={green:"#0f2d1f",amber:"#2d1f0a",neutral:"#1a1a22"},cl={active:{icon:ll,label:"ACTIVE",fg:e.green,bg:en.green,bold:true},paused:{icon:al,label:"PAUSED",fg:e.dim,bg:en.neutral},achieved:{icon:Rs,label:"DONE",fg:e.amber,bg:en.amber,bold:true},abandoned:{icon:$s,label:"DROP",fg:e.ghost,bg:en.neutral}},dl="\u2588",ul="\u2591",gl=14,Bs=tn.memo(function({goal:o,selected:n,width:r,agentNameMap:l,tasksByGoal:f}){let b=cl[o.status],T=n?"\u25B8":" ",h=f?.length??0,y=f?.filter($=>$.status==="done").length??0,S=h>0,C=11,_=S?gl:0,k=14,j=7,V=2+C+_+k+j,z=r?Math.max(10,r-V):40,E=o.assignee?l?.get(o.assignee)??o.assignee:void 0,U,B;if(o.status==="achieved")U=Rs,B=e.amber;else if(o.status==="abandoned")U=$s,B=e.ghost;else {let $=Date.now()-new Date(o.created_at).getTime(),D=Math.floor($/864e5);U=D>0?`${D}d`:"<1d",B=e.dim;}return jsxs(Box,{children:[jsxs(Text,{color:n?e.amber:void 0,children:[T," "]}),jsx(Box,{width:C,children:jsxs(Text,{backgroundColor:b.bg,color:b.fg,bold:b.bold,children:[" ",b.icon," ",b.label," "]})}),jsx(Box,{width:z,children:jsx(Text,{wrap:"truncate",bold:n||o.status==="active",color:n?e.white:o.status==="active"?e.silver:void 0,children:o.title.length>z?o.title.slice(0,z-1)+"\u2026":o.title})}),S&&(()=>{let D=h>0?Math.round(y/h*6):0,O=6-D;return jsxs(Box,{width:_,children:[jsx(Text,{color:e.green,children:dl.repeat(D)}),jsx(Text,{color:e.ghost,children:ul.repeat(O)}),jsx(Text,{color:e.dim,children:` ${y}/${h}`})]})})(),jsx(Box,{width:k,children:E?jsxs(Text,{backgroundColor:en.green,color:e.green,wrap:"truncate",children:[" ",E.length>k-2?E.slice(0,k-3)+"\u2026":E," "]}):jsx(Text,{color:e.ghost,children:"\u2014"})}),jsx(Box,{width:j,justifyContent:"flex-end",children:jsx(Text,{color:B,dimColor:!B,children:U})})]})});var ml={system:"\u2666",lifecycle:"\u25B6",output:"\u2502",tool:"\u2699",result:"\u2190",error:"\u2715",file:"\u270E",info:"\u2502"};function Bo({label:t,width:o,color:n}){let r=o-4,l=` ${t} `,f=3,b=Math.max(0,r-f-l.length);return jsxs(Text,{color:n??e.ghost,children:[" ",be(f),l,be(b)]})}function Es({task:t,height:o,width:n,taskLogs:r,agentNameMap:l,taskTitleMap:f}){let b=Cn[t.status]??e.dim,T=t.priority<=2?t.priority===1?e.red:e.yellow:void 0,h=24,y=!!t.description?.trim(),S=!!t.proof?.agent_summary,C=(t.proof?.files_changed?.length??0)>0,_=(r?.length??0)>0,k=(t.attachments?.length??0)>0,j=y?t.description.split(`
4
+ `):[],V=S?t.proof.agent_summary.split(`
5
+ `):[],z=3;k&&(z+=2+t.attachments.length),y?(z+=1,z+=Math.min(j.length,Math.max(1,Math.ceil((o-10)*.3)))):S||(z+=2),S&&(z+=2),C&&(z+=1),_&&(z+=2);let E=Math.max(0,o-z),U=0,B=0;S&&_?(U=Math.max(1,Math.floor(E*.4)),B=Math.max(1,E-U)):S?U=E:_&&(B=E);let $=y?j.slice(0,Math.max(1,Math.ceil((o-10)*.3))):[],D=V.slice(0,U);return jsxs(Box,{flexDirection:"column",paddingX:2,children:[jsxs(Box,{children:[jsxs(Box,{width:h,children:[jsx(Text,{color:e.dim,children:" status "}),jsx(Text,{color:b,children:t.status})]}),jsxs(Box,{children:[jsx(Text,{color:e.dim,children:" assignee "}),jsx(Text,{color:t.assignee?e.green:e.dim,children:t.assignee?l?.get(t.assignee)??t.assignee:"\u2014"})]})]}),jsxs(Box,{children:[jsxs(Box,{width:h,children:[jsx(Text,{color:e.dim,children:" priority "}),jsxs(Text,{color:T,bold:t.priority<=2,children:["P",t.priority]})]}),jsxs(Box,{children:[jsx(Text,{color:e.dim,children:" attempts "}),jsxs(Text,{children:[t.attempts,"/",t.max_attempts]})]})]}),jsxs(Box,{children:[jsxs(Box,{width:h,children:[jsx(Text,{color:e.dim,children:" labels "}),jsx(Text,{color:e.purple,children:t.labels.length>0?t.labels.join(", "):"\u2014"})]}),jsxs(Box,{children:[jsx(Text,{color:e.dim,children:" depends "}),jsx(Text,{dimColor:true,children:t.depends_on.length>0?t.depends_on.map(O=>f?.get(O)??O).join(", "):"\u2014"})]})]}),k&&jsxs(Fragment,{children:[jsx(Text,{children:" "}),jsx(Bo,{label:`attachments (${t.attachments.length})`,width:n,color:e.dim}),t.attachments.map((O,F)=>jsxs(Text,{color:e.cyan,wrap:"truncate",children:[" ",O]},`a${F}`))]}),y&&jsxs(Fragment,{children:[jsx(Text,{children:" "}),$.map((O,F)=>jsxs(Text,{color:e.silver,wrap:"truncate",children:[" ",et(O,n-8)]},`d${F}`))]}),!y&&!S&&jsxs(Fragment,{children:[jsx(Text,{children:" "}),jsx(Text,{color:e.dim,children:" No description."})]}),S&&jsxs(Fragment,{children:[jsx(Text,{children:" "}),jsx(Bo,{label:"result",width:n,color:e.dim}),D.map((O,F)=>jsxs(Text,{color:e.white,wrap:"truncate",children:[" ",et(O,n-8)]},`r${F}`))]}),C&&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})]})]}),_&&jsxs(Fragment,{children:[jsx(Text,{children:" "}),jsx(Bo,{label:"activity",width:n,color:e.dim}),r.slice(-B).map((O,F)=>{let W=O.msgType??"info",X=ml[W]??"\u2502",A=O.color;W==="tool"?A=e.cyan:W==="file"?A=e.purple:W==="error"?A=e.red:W==="lifecycle"?A=e.green:W==="system"&&(A=e.dim);let ie=Math.max(10,n-12),Re=et(O.text,ie);return jsxs(Box,{children:[jsxs(Text,{color:e.ghost,children:[" ",O.time," "]}),jsxs(Text,{color:W==="error"?e.red:e.dim,children:[X," "]}),jsx(Text,{color:A,bold:W==="lifecycle",children:Re})]},F)})]})]})}var vn=[{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 fl="\u25CF",Ls="\u25CB",pl="\u2713",hl="\u2715",xl="\u2191",bl="\u2193",Tl="\u03A3",yl="\u25B6",wl="\u21BB",Sl="\u{1F9E0}",Os=["\u280B","\u2819","\u2839","\u2838","\u283C","\u2834","\u2826","\u2827","\u2807","\u280F"],Sr=[" ","\u2581","\u2582","\u2583","\u2584","\u2585","\u2586","\u2587","\u2588"],ut={green:"#0f2d1f",blue:"#0f1f2d",yellow:"#2d2a0f",red:"#2d0f0f",neutral:"#1a1a22",amber:"#2d1f0a"};function Ps({color:t}){let o=co();return jsx(Text,{color:t,children:Os[o%Os.length]})}function kl(){let t=co(),o=Math.floor(t/10)%2===0;return jsx(Text,{color:o?e.amber:e.amberDim,bold:true,children:Gt})}function Cl({width:t,active:o}){let n=Math.max(4,Math.floor(t*.08)),r=2,l=co(),f=Math.ceil((t+n)/r),b=o?l%(f*2):0;if(!o)return jsx(Box,{paddingX:1,children:jsx(Text,{color:e.ghost,children:Ge(t)})});let T=b<f?b*r:(f*2-b)*r,h=Math.max(0,T-n),y=Math.min(t,T),S=h,C=Math.max(0,y-h),_=Math.max(0,t-y);return jsxs(Box,{paddingX:1,children:[jsx(Text,{color:e.ghost,children:Ge(S)}),jsx(Text,{color:e.amber,children:Ge(C)}),jsx(Text,{color:e.ghost,children:Ge(_)})]})}function Il({data:t,width:o,color:n}){if(t.length===0)return null;let r=t.slice(-o),l=Math.max(...r,1),f=r.map(b=>{let T=Math.round(b/l*(Sr.length-1));return Sr[T]??Sr[0]}).join("");return jsx(Text,{color:n,children:f})}function Ml({tab:t,flashColor:o,onComplete:n,badge:r}){let l=co(),f=tn.useRef(l),b=tn.useRef(false),T=l-f.current,h=2,y=6*h;return tn.useEffect(()=>{T>=y&&!b.current&&(b.current=true,n());},[T,n]),Math.floor(T/h)%2===0&&T<y?jsxs(Text,{backgroundColor:o,color:"#0a0a0c",bold:true,children:[" ",t.key," ",t.label,r," "]}):jsxs(Box,{gap:0,children:[jsx(Text,{color:e.ghost,children:t.key}),jsxs(Text,{color:e.dim,children:[" ",t.label.toLowerCase(),r]})]})}function vl({projectName:t,activeView:o,mode:n,stats:r,uptime:l,width:f,version:b,latestVersion:T,taskBadge:h,flashTab:y,flashColor:S,onFlashComplete:C}){let _=n==="watching";return jsxs(Box,{paddingX:1,justifyContent:"space-between",width:f,children:[jsxs(Box,{gap:0,children:[jsx(kl,{}),jsx(Text,{color:e.amber,bold:true,children:" ORCH"}),b&&jsxs(Text,{color:e.ghost,children:[" ",b]}),T&&T!==b&&jsxs(Text,{backgroundColor:ut.green,color:e.green,bold:true,children:[" UPDATE ",T," "]}),jsxs(Text,{color:e.ghost,children:[" ",de," "]}),jsx(Text,{color:e.silver,children:t})]}),jsx(Box,{gap:0,children:vn.map((k,j)=>{let V=o===k.id,z=k.id==="tasks"&&h!=null&&h>0?` (${h})`:"",E=!V&&y===k.id&&S&&C;return jsxs(tn.Fragment,{children:[j>0&&jsx(Text,{children:" "}),V?jsxs(Text,{backgroundColor:e.amber,color:"#0a0a0c",bold:true,children:[" ",k.key," ",k.label,z," "]}):E?jsx(Ml,{tab:k,flashColor:S,onComplete:C,badge:z}):jsxs(Box,{gap:0,children:[jsx(Text,{color:e.ghost,children:k.key}),jsxs(Text,{color:e.dim,children:[" ",k.label.toLowerCase(),z]})]})]},k.id)})}),jsxs(Box,{gap:0,children:[_?jsxs(Text,{backgroundColor:ut.green,color:e.green,bold:true,children:[" ",fl," WATCHING"," "]}):jsxs(Text,{backgroundColor:ut.neutral,color:e.dim,children:[" ",Ls," IDLE"," "]}),r.running>0&&jsxs(Fragment,{children:[jsx(Text,{children:" "}),jsxs(Text,{backgroundColor:ut.green,color:e.green,children:[" ",jsx(Ps,{color:e.green})," ",r.running," active"," "]})]}),l&&jsxs(Text,{color:e.ghost,children:[" ",l]})]})]})}function _l({stats:t,tokens:o,width:n,sparklineData:r}){let f=[{icon:yl,label:"RUN",count:t.running,fg:e.green,bg:ut.green,bold:true,spinner:true,show:t.running>0},{icon:wl,label:"RETRY",count:t.retrying,fg:e.yellow,bg:ut.yellow,show:t.retrying>0},{icon:qt,label:"REVIEW",count:t.review,fg:e.blue,bg:ut.blue,show:t.review>0},{icon:Ls,label:"TODO",count:t.todo,fg:e.dim,bg:ut.neutral,show:t.todo>0},{icon:pl,label:"DONE",count:t.done,fg:e.green,bg:ut.green,show:t.done>0},{icon:hl,label:"FAIL",count:t.failed,fg:e.red,bg:ut.red,bold:true,show:t.failed>0},{icon:Gt,label:"TEAMS",count:t.teams,fg:e.amber,bg:ut.amber,show:t.teams>0}].filter(h=>h.show),b=o.total>0,T=r&&r.length>0?Math.min(16,r.length):0;return jsxs(Box,{paddingX:1,justifyContent:"space-between",width:n,children:[jsxs(Box,{gap:1,children:[f.map(h=>jsx(Text,{backgroundColor:h.bg,color:h.fg,bold:h.bold,children:h.spinner?jsxs(Fragment,{children:[" ",jsx(Ps,{color:h.fg})," ",h.count," ",h.label," "]}):jsxs(Fragment,{children:[" ",h.icon," ",h.count," ",h.label," "]})},h.label)),f.length===0&&jsxs(Text,{backgroundColor:ut.neutral,color:e.dim,children:[" ","NO TASKS"," "]})]}),jsxs(Box,{gap:0,children:[T>0&&r&&jsxs(Fragment,{children:[jsx(Il,{data:r,width:T,color:e.amberDim}),jsx(Text,{children:" "})]}),b&&jsxs(Text,{backgroundColor:ut.amber,color:e.cyan,children:[" ",xl,h(o.input)," ",bl,h(o.output),o.reasoning>0?` ${Sl}${h(o.reasoning)}`:""," ",de," ",Tl,h(o.total)," "]})]})]})}var Ns=tn.memo(function(o){let n=Math.max(10,o.width-2),r=o.stats.running>0;return jsxs(Box,{flexDirection:"column",children:[jsx(Box,{height:1}),jsx(vl,{projectName:o.projectName,activeView:o.activeView,mode:o.mode,stats:o.stats,uptime:o.uptime,width:o.width,version:o.version,latestVersion:o.latestVersion,taskBadge:o.taskBadge,flashTab:o.flashTab,flashColor:o.flashColor,onFlashComplete:o.onFlashComplete}),jsx(Box,{height:1}),jsx(_l,{stats:o.stats,tokens:o.tokens,width:o.width,sparklineData:o.sparklineData}),jsx(Cl,{width:n,active:r})]})});var on="\u0423\u041F\u0420\u0410\u0412\u041B\u0415\u041D\u0418\u0415",Eo="\u041C\u041E\u041D\u0418\u0422\u041E\u0420\u0418\u041D\u0413",An="\u041D\u0410\u0421\u0422\u0420\u041E\u0419\u041A\u0418",uo={task:{sub:["add","list","show","cancel","retry","assign","approve","reject","delete"],help:"Manage tasks",category:on},agent:{sub:["add","list","disable","enable","delete","autonomous","shop"],help:"Manage agents",category:on},team:{sub:["create","list","join","leave","disband","set-lead"],help:"Manage teams",category:on},goal:{sub:["add","list","show","status","delete"],help:"Manage goals",category:on},run:{args:"[id]",help:"Run task (or selected)",category:Eo},"run-all":{help:"Run all todo tasks",category:Eo},watch:{help:"Start watch mode (auto-dispatch)",category:Eo},pause:{help:"Pause watch mode",category:Eo},status:{help:"Show orchestrator status",category:Eo},config:{sub:["activity-filter","max-concurrent"],help:"TUI settings",category:An},help:{help:"List all commands",category:An},quit:{help:"Exit the TUI",category:An}};function kr(t){if(!t.startsWith("/"))return null;let o=t.slice(1),n=o.indexOf(" ");if(n===-1){let T=o;if(!T)return null;let h=Object.keys(uo).find(y=>y.startsWith(T)&&y!==T);return h?h.slice(T.length):null}let r=o.slice(0,n),l=uo[r];if(!l?.sub)return null;let f=o.slice(n+1);if(!f)return null;let b=l.sub.find(T=>T.startsWith(f)&&T!==f);return b?b.slice(f.length):null}function Ds(t){if(!t.startsWith("/"))return [];let o=t.slice(1),n=o.indexOf(" ");if(n===-1){let T=o.toLowerCase(),h=[];if(!T){let y=[on,Eo,An];for(let S of y){h.push({cmd:"",desc:`\u2500\u2500 ${S} \u2500\u2500`});for(let[C,_]of Object.entries(uo))if(_.category===S){let k=_.args?` ${_.args}`:"";h.push({cmd:`/${C}${k}`,desc:_.help,subs:_.sub?.join(" \xB7 ")});}}return h}for(let[y,S]of Object.entries(uo))if(y.startsWith(T)){let C=S.args?` ${S.args}`:"";if(h.push({cmd:`/${y}${C}`,desc:S.help,subs:S.sub?.join(" \xB7 ")}),y===T&&S.sub)for(let _ of S.sub)h.push({cmd:`/${y} ${_}`,desc:`${S.help}: ${_}`});}return h}let r=o.slice(0,n),l=uo[r];if(!l?.sub)return [];let f=o.slice(n+1).toLowerCase(),b=[];for(let T of l.sub)(!f||T.startsWith(f))&&b.push({cmd:`/${r} ${T}`,desc:`${l.help}: ${T}`});return b}var Rn=class{entries=[];cursor=0;push(o){o&&(this.entries[this.entries.length-1]!==o&&(this.entries.push(o),this.entries.length>100&&this.entries.shift()),this.cursor=this.entries.length);}prev(){return this.entries.length===0?null:(this.cursor>0&&this.cursor--,this.entries[this.cursor]??null)}next(){return this.cursor<this.entries.length-1?(this.cursor++,this.entries[this.cursor]??null):(this.cursor=this.entries.length,null)}reset(){this.cursor=this.entries.length;}};var Rl="\u2588",Fs=tn.memo(function({mode:o,value:n,completion:r,activeView:l,canRun:f,canNew:b,canApprove:T,canReject:h,canCancel:y,canDelete:S,canUndo:C,canEdit:_,canForceStop:k,canToggleAuto:j,autoActive:V,canPause:z,isPaused:E,canToggleShowAll:U,showAllActive:B,hasDetail:$,itemCount:D,itemLabel:O,width:F,hasSuggestions:W,onboardingCompleted:X}){if(o==="command"){let A=W?" \u2191\u2193 select Tab fill Esc \u2715":" Enter exec \u2191\u2193 history Tab complete Esc \u2715",ie=Math.max(4,F-6-A.length-(r?.length??0)-1),Re=n.length>ie?"\u2026"+n.slice(-(ie-1)):n;return jsx(Box,{paddingX:2,justifyContent:"space-between",width:F,children:jsxs(Box,{children:[jsx(Text,{color:e.amber,children:"/ "}),jsx(Text,{color:e.white,children:Re}),r&&jsx(Text,{color:e.ghost,children:r}),jsx(Text,{color:e.amber,children:Rl}),jsx(Text,{color:e.dim,children:A})]})})}return jsxs(Box,{paddingX:2,justifyContent:"space-between",width:F,children:[jsxs(Text,{color:e.dim,children:[jsx(Text,{bold:true,color:e.gray,children:"\u2191\u2193"})," ",jsx(Text,{bold:true,color:e.gray,children:"Tab"}),"/",jsx(Text,{bold:true,color:e.gray,children:"\u2190\u2192"})," ",jsx(Text,{bold:true,color:e.gray,children:"/"})," cmd",b&&jsxs(Fragment,{children:[" ",jsx(Text,{bold:true,color:e.gray,children:"N"})," new"]}),f&&jsxs(Fragment,{children:[" ",jsx(Text,{bold:true,color:e.gray,children:"R"})," run"]}),y&&jsxs(Fragment,{children:[" ",jsx(Text,{bold:true,color:e.amber,children:"C"})," cancel"]}),T&&jsxs(Fragment,{children:[" ",jsx(Text,{bold:true,color:e.green,children:"A"})," approve"]}),h&&jsxs(Fragment,{children:[" ",jsx(Text,{bold:true,color:e.red,children:"X"})," reject"]}),_&&jsxs(Fragment,{children:[" ",jsx(Text,{bold:true,color:e.cyan,children:"E"})," edit"]}),k&&jsxs(Fragment,{children:[" ",jsx(Text,{bold:true,color:e.red,children:"S"})," stop"]}),z&&jsxs(Fragment,{children:[" ",jsx(Text,{bold:true,color:e.amber,children:"P"}),E?" resume":" pause"]}),j&&jsxs(Fragment,{children:[" ",jsx(Text,{bold:true,color:e.cyan,children:"U"}),V?" auto off":" auto on"]}),U&&jsxs(Fragment,{children:[" ",jsx(Text,{bold:true,color:e.gray,children:"S"}),B?" collapse":" show all"]}),S&&!T&&jsxs(Fragment,{children:[" ",jsx(Text,{bold:true,color:e.gray,children:"D"})," delete"]}),C&&jsxs(Fragment,{children:[" ",jsx(Text,{bold:true,color:e.yellow,children:"Z"})," undo"]}),$&&jsxs(Fragment,{children:[" ",jsx(Text,{bold:true,color:e.gray,children:"Esc"})," close"]}),!$&&(l==="tasks"||l==="agents"||l==="goals")&&jsxs(Fragment,{children:[" ",jsx(Text,{bold:true,color:e.gray,children:"Enter"})," detail"]})," ",jsx(Text,{bold:true,color:e.gray,children:"Q"})," quit"," ",jsx(Text,{bold:true,color:X===false?e.amber:e.gray,children:"?"}),jsx(Text,{color:X===false?e.amber:void 0,children:" help"})]}),D>0&&jsxs(Text,{color:e.dim,children:[D," ",O]})]})});var Bn="\u2588";function zs({title:t,steps:o,onComplete:n,onCancel:r,width:l,height:f,onPasteImage:b,footerExtra:T,onSuggestionSelected:h}){let [y,S]=useState(0),[C,_]=useState({}),[k,j]=useState(()=>{let G=o.find(R=>!R.skip?.({}));return G?.type==="text"&&G.defaultValue?G.defaultValue:""}),[V,z]=useState(()=>{let G=o.find(R=>!R.skip?.({}));return G?.type==="text"&&G.defaultValue?G.defaultValue.length:0}),[E,U]=useState(()=>{let G=o.find(R=>!R.skip?.({}));return G?.type==="textarea"&&G.defaultValue?G.defaultValue.split(`
6
+ `):[""]}),[B,$]=useState(0),[D,O]=useState(0),[F,W]=useState(()=>{let G=o.find(R=>!R.skip?.({}));if(G?.type==="select"&&G.defaultValue){let M=(G.getOptions?.({})??G.options??[]).findIndex(L=>L.value===G.defaultValue);return M>=0?M:0}return 0}),X=useMemo(()=>o.filter(G=>!G.skip?.(C)),[o,C]),A=X[y],ie=X.length,[Mt,it]=useState(new Set),[at,gt]=useState(false),[vt,lt]=useState(0),[Xe,$e]=useState(false),[qe,Ze]=useState(null),[Dt,Je]=useState(false),Le=useRef(null),Ve=useRef(null),Qt=useMemo(()=>A?A.type==="text"?k:A.type==="textarea"?E.join(`
7
+ `):"":"",[A,k,E]),mo=useCallback((G,R)=>{if(Le.current&&clearTimeout(Le.current),!R){Ze(null);return}Le.current=setTimeout(()=>{Ze(R(G));},300);},[]);useEffect(()=>(A&&A.validate&&(A.type==="text"||A.type==="textarea")&&mo(Qt,A.validate),()=>{Le.current&&clearTimeout(Le.current);}),[Qt,A,mo]),useEffect(()=>()=>{Ve.current&&clearTimeout(Ve.current);},[]);let ct=useMemo(()=>!A||A.type!=="select"&&A.type!=="multiselect"?[]:A.getOptions?.(C)??A.options??[],[A,C]),Ht=Math.min(F,Math.max(0,ct.length-1)),_t=useMemo(()=>{if(!A?.suggestions)return [];if(!k.trim())return A.suggestions;let G=k.toLowerCase();return A.suggestions.filter(R=>R.label.toLowerCase().includes(G)||(R.hint??"").toLowerCase().includes(G))},[A?.suggestions,k]),eo=Math.min(vt,Math.max(0,_t.length-1)),jt=G=>{let R={...C,[A.id]:G};_(R),j(""),z(0),U([""]),$(0),O(0),W(0),it(new Set),gt(false),lt(0),$e(false),Ze(null),Je(false),Le.current&&clearTimeout(Le.current);let M=A.id,ee=o.findIndex(K=>K.id===M)+1;for(;ee<o.length;){let K=o[ee];if(K&&!K.skip?.(R))break;ee++;}if(ee>=o.length)n(R);else {let K=o[ee].id,le=o.filter(ye=>!ye.skip?.(R)).findIndex(ye=>ye.id===K);S(le>=0?le:0);let ue=o[ee];if(ue.type==="text"){let ye=ue.defaultValue??"";j(ye),z(ye.length);}else if(ue.type==="textarea"){let ye=ue.defaultValue?ue.defaultValue.split(`
8
+ `):[""];U(ye),$(ye.length-1),O(ye[ye.length-1].length);}else if(ue.type==="select"){let ye=ue.getOptions?.(R)??ue.options??[];if(ue.defaultValue){let Ft=ye.findIndex(Do=>Do.value===ue.defaultValue);W(Ft>=0?Ft:0);}else W(0);}else ue.type==="multiselect"&&(W(0),ue.defaultValue?it(new Set(ue.defaultValue.split(","))):it(new Set));}},Po=()=>{if(y===0){r();return}let G=A.id,M=o.findIndex(le=>le.id===G)-1;for(;M>=0;){let le=o[M];if(le&&!le.skip?.(C))break;M--;}if(M<0){r();return}let L=o[M].id,ee=X.findIndex(le=>le.id===L);S(ee>=0?ee:0),gt(false),lt(0),$e(false),Ze(null),Je(false),Le.current&&clearTimeout(Le.current);let K=o[M];if(C[K.id]&&$e(true),K.type==="text"){let le=C[K.id]??K.defaultValue??"";j(le),z(le.length);}else if(K.type==="textarea"){let le=C[K.id]??K.defaultValue??"",ue=le?le.split(`
9
+ `):[""];U(ue),$(ue.length-1),O(ue[ue.length-1].length);}else if(K.type==="multiselect"){W(0);let le=C[K.id];it(le?new Set(le.split(",")):new Set);}else {let le=K.getOptions?.(C)??K.options??[],ue=C[K.id],ye=le.findIndex(Ft=>Ft.value===ue);W(ye>=0?ye:0);}};if(useInput((G,R)=>{if(A){if(R.escape){y===0?r():Po();return}if((R.ctrl||R.meta)&&(G==="v"||G==="i")&&b&&(A.type==="text"||A.type==="textarea")){b();return}if(A.type==="text"){if(at&&_t.length>0){if(R.upArrow){eo<=0?gt(false):lt(M=>M-1);return}if(R.downArrow){lt(M=>Math.min(_t.length-1,M+1));return}if(R.return){let M=_t[eo];M&&h&&h(M.value);return}gt(false);}if(R.return){let M=k.trim();if(A.required&&!M){$e(true);return}if(qe!==null){$e(true),Je(true),Ve.current&&clearTimeout(Ve.current),Ve.current=setTimeout(()=>Je(false),2e3);return}jt(M);return}if(R.downArrow&&A.suggestions&&_t.length>0){gt(true),lt(0);return}if(R.leftArrow){z(M=>Math.max(0,M-1));return}if(R.rightArrow){z(M=>Math.min(k.length,M+1));return}if(R.backspace||R.delete){if(V===0&&k.length===0&&y>0){Po();return}V>0&&(j(M=>M.slice(0,V-1)+M.slice(V)),z(M=>M-1));return}G&&!R.ctrl&&!R.meta&&!R.escape&&($e(true),gt(false),lt(0),j(M=>M.slice(0,V)+G+M.slice(V)),z(M=>M+G.length));return}if(A.type==="textarea"){if(R.return&&!R.shift){let M=E.join(`
10
+ `).trim();if(A.required&&!M){$e(true);return}if(qe!==null){$e(true),Je(true),Ve.current&&clearTimeout(Ve.current),Ve.current=setTimeout(()=>Je(false),2e3);return}jt(M);return}if(R.return&&R.shift){U(M=>{let L=M[B]??"",ee=L.slice(0,D),K=L.slice(D),Ie=[...M];return Ie.splice(B,1,ee,K),Ie}),$(M=>M+1),O(0);return}if(R.upArrow){B>0&&($(M=>M-1),O(M=>Math.min(M,(E[B-1]??"").length)));return}if(R.downArrow){B<E.length-1&&($(M=>M+1),O(M=>Math.min(M,(E[B+1]??"").length)));return}if(R.leftArrow){D>0?O(M=>M-1):B>0&&($(M=>M-1),O((E[B-1]??"").length));return}if(R.rightArrow){let M=(E[B]??"").length;D<M?O(L=>L+1):B<E.length-1&&($(L=>L+1),O(0));return}if(R.backspace||R.delete){if(D===0&&B===0)return;if(D>0)U(M=>{let L=[...M],ee=L[B]??"";return L[B]=ee.slice(0,D-1)+ee.slice(D),L}),O(M=>M-1);else {let M=(E[B-1]??"").length;U(L=>{let ee=[...L],K=ee[B-1]??"",Ie=ee[B]??"";return ee.splice(B-1,2,K+Ie),ee}),O(M),$(L=>L-1);}return}if(G&&!R.ctrl&&!R.meta&&!R.escape){$e(true);let M=G.split(/\r?\n/);if(M.length===1)U(L=>{let ee=[...L],K=ee[B]??"";return ee[B]=K.slice(0,D)+G+K.slice(D),ee}),O(L=>L+G.length);else {let L=B,ee=D;U(K=>{let Ie=[...K],le=Ie[L]??"",ue=le.slice(0,ee),ye=le.slice(ee),Ft=M[0]??"",Do=M[M.length-1]??"",sn=[ue+Ft,...M.slice(1,-1),Do+ye];return Ie.splice(L,1,...sn),Ie}),$(L+M.length-1),O((M[M.length-1]??"").length);}}return}if(A.type==="select"||A.type==="multiselect"){if(R.upArrow||G==="k"){W(M=>Math.max(0,M-1));return}if(R.downArrow||G==="j"){W(M=>Math.min(ct.length-1,M+1));return}if(R.backspace||R.delete){Po();return}if(A.type==="select"){if(R.return||R.tab){let M=ct[Ht];if(M){if(A.validate){let L=A.validate(M.value);if(L!==null){$e(true),Ze(L),Je(true),Ve.current&&clearTimeout(Ve.current),Ve.current=setTimeout(()=>Je(false),2e3);return}}jt(M.value);}return}if(G>="1"&&G<="9"){let M=parseInt(G,10)-1;if(M<ct.length){let L=ct[M];L&&jt(L.value);}return}}else {if(G===" "){let M=ct[Ht];M&&it(L=>{let ee=new Set(L);return ee.has(M.value)?ee.delete(M.value):ee.add(M.value),ee});return}if(R.return){let M=Array.from(Mt).join(",");jt(M);return}}}}}),!A)return null;let mt=Xe?qe:null,No=Math.max(20,l-6),At=`${y+1}/${ie}`,fo=Math.max(2,f-4),to=0;Ht>=fo&&(to=Ht-fo+1);let ft=ct.slice(to,to+fo);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:[" ",We,We," "]}),jsxs(Text,{color:e.dim,children:["step ",At]})]}),jsxs(Box,{children:[jsx(Text,{children:" "}),X.map((G,R)=>jsxs(Text,{color:R===y?e.amber:R<y?e.green:e.ghost,children:[R===y?"\u25CF":R<y?"\u2713":"\u25CB"," "]},G.id))]}),jsxs(Box,{marginTop:0,children:[jsxs(Text,{color:e.white,bold:true,children:[" ",A.label]}),A.required&&jsx(Text,{color:e.red,children:" *"}),!A.required&&jsx(Text,{color:e.dim,children:" (optional, Enter to skip)"})]}),A.description&&jsx(Box,{children:jsxs(Text,{color:e.dim,children:[" ",A.description]})}),A.type==="text"&&jsxs(Box,{flexDirection:"column",children:[jsxs(Box,{borderStyle:mt?"round":void 0,borderColor:mt?e.red:void 0,children:[jsxs(Text,{color:e.amber,children:[" ",">"," "]}),k.length>0?jsxs(Fragment,{children:[jsx(Text,{color:e.white,children:k.slice(0,V)}),jsx(Text,{color:e.amber,children:Bn}),jsx(Text,{color:e.white,children:k.slice(V)})]}):A.placeholder?jsxs(Fragment,{children:[jsx(Text,{color:e.ghost,children:A.placeholder}),jsx(Text,{color:e.amber,children:Bn})]}):jsx(Text,{color:e.amber,children:Bn})]}),mt&&jsxs(Text,{color:e.red,dimColor:true,children:[" ",mt]}),Dt&&jsx(Text,{color:e.red,children:" Fix the error above"})]}),A.type==="text"&&A.suggestions&&_t.length>0&&(()=>{let G=Math.max(2,f-6),R=0;at&&eo>=G&&(R=eo-G+1);let M=_t.slice(R,R+G);return jsxs(Box,{flexDirection:"column",children:[jsxs(Text,{color:e.ghost,children:[" ",We,We,We," or browse templates ",We.repeat(Math.max(0,No-28))]}),M.map((L,ee)=>{let K=ee+R,Ie=at&&K===eo;return jsxs(Box,{children:[jsx(Text,{color:Ie?e.amber:e.ghost,children:Ie?" \u25B8 ":" "}),jsx(Text,{color:Ie?e.white:e.silver,bold:Ie,children:L.label}),L.hint&&jsxs(Text,{color:e.dim,wrap:"truncate",children:[" ",We," ",L.hint.replace(/\n/g," ")]})]},L.value)})]})})(),A.type==="textarea"&&(()=>{let G=Math.max(3,f-6),R=0;B>=G&&(R=B-G+1);let M=E.slice(R,R+G),L=String(E.length).length;return jsxs(Box,{flexDirection:"column",children:[jsxs(Box,{flexDirection:"column",borderStyle:mt?"round":void 0,borderColor:mt?e.red:void 0,children:[M.map((ee,K)=>{let Ie=K+R,le=String(Ie+1).padStart(L," "),ue=Ie===B;return jsxs(Box,{children:[jsxs(Text,{color:e.dim,children:[" ",le," "]}),jsxs(Text,{color:e.ghost,children:["\u2502"," "]}),ue?jsxs(Fragment,{children:[jsx(Text,{color:e.white,children:ee.slice(0,D)}),jsx(Text,{color:e.amber,children:Bn}),jsx(Text,{color:e.white,children:ee.slice(D)})]}):jsx(Text,{color:e.silver,children:ee||" "})]},Ie)}),E.length===1&&E[0]===""&&A.placeholder&&jsx(Box,{children:jsxs(Text,{color:e.dim,children:[" ","".padStart(L," ")," ",A.placeholder]})})]}),mt&&jsxs(Text,{color:e.red,dimColor:true,children:[" ",mt]}),Dt&&jsx(Text,{color:e.red,children:" Fix the error above"})]})})(),A.type==="select"&&jsxs(Box,{flexDirection:"column",children:[ft.map((G,R)=>{let M=R+to,L=M===Ht,ee=String(M+1).padStart(ct.length>=10?2:1);return jsxs(Box,{children:[jsx(Text,{color:L?e.amber:e.ghost,children:L?" \u25B8 ":` ${ee} `}),jsx(Text,{color:L?e.white:e.silver,bold:L,children:G.label}),G.hint&&jsxs(Text,{color:e.dim,wrap:"truncate",children:[" ",We," ",G.hint.replace(/\n/g," ")]})]},G.value)}),mt&&jsxs(Text,{color:e.red,dimColor:true,children:[" ",mt]}),Dt&&jsx(Text,{color:e.red,children:" Fix the error above"})]}),A.type==="multiselect"&&jsxs(Box,{flexDirection:"column",children:[ft.map((G,R)=>{let L=R+to===Ht,ee=Mt.has(G.value);return jsxs(Box,{children:[jsx(Text,{color:L?e.amber:e.ghost,children:L?" \u25B8 ":" "}),jsx(Text,{color:ee?e.green:e.dim,children:ee?"[\u2713]":"[ ]"}),jsxs(Text,{color:L?e.white:e.silver,bold:L,children:[" ",G.label]}),G.hint&&jsxs(Text,{color:e.dim,wrap:"truncate",children:[" ",We," ",G.hint.replace(/\n/g," ")]})]},G.value)}),Mt.size>0&&jsx(Box,{children:jsxs(Text,{color:e.dim,children:[" ","\u2514"," ",Mt.size," selected"]})})]}),jsxs(Box,{marginTop:0,children:[jsxs(Text,{color:e.ghost,children:[" ",A.type==="select"?"\u2191\u2193 select Enter confirm":A.type==="multiselect"?"\u2191\u2193 move Space toggle Enter confirm":A.type==="textarea"?"Shift+Enter newline Enter confirm \u2190\u2191\u2192\u2193 navigate":at?"\u2191\u2193 browse Enter select \u2191 back to input":A.suggestions?"\u2190\u2192 move Enter confirm \u2193 browse templates":"\u2190\u2192 move Enter confirm",b&&(A.type==="text"||A.type==="textarea")?` ${process.platform==="darwin"?"\u2318":"Ctrl"}+V paste image`:""," Esc ",y>0?"back":"cancel"]}),T&&jsxs(Text,{color:e.amber,children:[" ",T]})]})]})}var js=tn.memo(function({agents:o,selected:n,msgCounts:r,colorMap:l,maxHeight:f,onConfirm:b,onCancel:T}){let [h,y]=useState(0),[S,C]=useState(()=>new Set(n));useMemo(()=>S.size===0||S.size===o.length,[S.size,o.length]);let k=Math.max(3,f-5),j=useMemo(()=>{if(o.length<=k)return 0;let E=Math.floor(k/2),U=o.length-k;return Math.min(U,Math.max(0,h-E))},[h,o.length,k]),V=o.slice(j,j+k);useInput((E,U)=>{if(U.upArrow){y(B=>B>0?B-1:o.length-1);return}if(U.downArrow){y(B=>B<o.length-1?B+1:0);return}if(E===" "){let B=o[h];if(!B)return;C($=>{let D=new Set($);return D.has(B.id)?D.delete(B.id):D.add(B.id),D});return}if(E==="a"||E==="A"){C(B=>new Set);return}if(U.return){b(new Set(S));return}if(U.escape){T();return}});let z=S.size===0?o.length:S.size;return jsxs(Box,{flexDirection:"column",borderStyle:"round",borderColor:e.amber,paddingX:1,children:[jsxs(Box,{gap:1,children:[jsx(Text,{color:e.amber,bold:true,children:" \u25C8 Agent Filter"}),jsxs(Text,{color:e.dim,children:[de," ",z,"/",o.length," selected"]})]}),jsx(Text,{color:e.ghost,children:We.repeat(36)}),V.map((E,U)=>{let $=U+j===h,D=S.size===0||S.has(E.id),O=l.get(E.id)??e.silver,F=r.get(E.id)??0;return jsxs(Box,{gap:0,children:[jsx(Text,{color:$?e.amber:e.ghost,children:$?" \u25B8 ":" "}),jsx(Text,{color:D?e.green:e.ghost,children:D?"[\u2713]":"[ ]"}),jsxs(Text,{color:$?O:D?e.silver:e.dim,bold:$,children:[" ",E.name]}),F>0&&jsxs(Text,{color:e.dim,children:[" ",de,F]})]},E.id)}),o.length>k&&jsxs(Text,{color:e.ghost,children:[" ",j>0?"\u2191":" "," ",j+k<o.length?"\u2193":" "," ",h+1,"/",o.length]}),jsx(Text,{color:e.ghost,children:We.repeat(36)}),jsxs(Text,{color:e.dim,children:[" Space toggle"," ",de," ","a all"," ",de," ","Enter confirm"," ",de," ","Esc cancel"]})]})});var Nl={system:"\u2666",lifecycle:"\u25B6",output:"\u2502",tool:"\u2699",result:"\u2190",error:"\u2715",file:"\u270E",info:"\u2502"},Dl={system:"System",lifecycle:"Lifecycle",output:"Output",tool:"Tool calls",result:"Results",error:"Errors",file:"Files",info:"Info"},Fl={system:e.purple,lifecycle:e.cyan,output:e.white,tool:e.blue,result:e.green,error:e.red,file:e.purple,info:e.silver},bt=["system","lifecycle","output","tool","result","error","file","info"],qs=[{key:"1",label:"all",types:bt},{key:"2",label:"text",types:["output"]},{key:"3",label:"tools",types:["tool","result","file"]},{key:"4",label:"errors",types:["error"]},{key:"5",label:"events",types:["lifecycle","system"]}],Ks=tn.memo(function({selected:o,typeCounts:n,onConfirm:r,onCancel:l}){let[f,b]=useState(0),[T,h]=useState(()=>new Set(o)),y=useMemo(()=>T.size===bt.length||bt.every(C=>T.has(C)),[T]);useInput((C,_)=>{if(_.upArrow){b(k=>k>0?k-1:bt.length-1);return}if(_.downArrow){b(k=>k<bt.length-1?k+1:0);return}if(C===" "){let k=bt[f];if(!k)return;h(j=>{let V=new Set(j);return V.has(k)?V.delete(k):V.add(k),V});return}if(C==="a"||C==="A"){h(k=>k.size===bt.length?new Set:new Set(bt));return}for(let k of qs)if(C===k.key){h(new Set(k.types));return}if(_.return){let k=T.size===0?new Set(bt):new Set(T);r(k);return}if(_.escape){l();return}});let S=y?bt.length:T.size;return jsxs(Box,{flexDirection:"column",borderStyle:"round",borderColor:e.amber,paddingX:1,children:[jsxs(Box,{gap:1,children:[jsx(Text,{color:e.amber,bold:true,children:" \u25C8 Type Filter"}),jsxs(Text,{color:e.dim,children:[de," ",S,"/",bt.length," selected"]})]}),jsx(Text,{color:e.ghost,children:We.repeat(36)}),bt.map((C,_)=>{let k=_===f,j=T.has(C),V=n[C]??0,z=Fl[C];return jsxs(Box,{gap:0,children:[jsx(Text,{color:k?e.amber:e.ghost,children:k?" \u25B8 ":" "}),jsx(Text,{color:j?e.green:e.ghost,children:j?"[\u2713]":"[ ]"}),jsxs(Text,{color:k?z:e.dim,children:[" ",Nl[C]," "]}),jsx(Text,{color:k?z:j?e.silver:e.dim,bold:k,children:Dl[C]}),V>0&&jsxs(Text,{color:e.dim,children:[" ",de,V]})]},C)}),jsx(Text,{color:e.ghost,children:We.repeat(36)}),jsxs(Box,{gap:0,children:[jsx(Text,{color:e.dim,children:" "}),qs.map((C,_)=>jsxs(tn.Fragment,{children:[_>0&&jsxs(Text,{color:e.ghost,children:[" ",de," "]}),jsx(Text,{color:e.amberDim,children:C.key}),jsxs(Text,{color:e.dim,children:["=",C.label]})]},C.key))]}),jsxs(Text,{color:e.dim,children:[" Space toggle"," ",de," ","a all"," ",de," ","Enter confirm"," ",de," ","Esc cancel"]})]})});var Ln="\u256D",Pn="\u256E",Nn="\u2570",Dn="\u256F",ke="\u2502";function Jt({children:t,cw:o}){return jsxs(Text,{children:[jsx(Text,{color:e.ghost,children:ke}),jsxs(Text,{children:[" ",t.padEnd(o)," "]}),jsx(Text,{color:e.ghost,children:ke})]})}function On({cw:t}){return jsx(Jt,{cw:t,children:""})}function Ys({width:t,height:o}){let n=Math.min(t-4,50),r=n-6,l=be(n-2);return jsxs(Box,{flexDirection:"column",paddingX:2,marginTop:1,children:[jsxs(Text,{color:e.ghost,children:[Ln,l,Pn]}),jsx(Jt,{cw:r,children:""}),jsxs(Text,{children:[jsxs(Text,{color:e.ghost,children:[ke," "]}),jsx(Text,{color:e.amber,children:Gt}),jsx(Text,{color:e.white,bold:true,children:" Welcome to Orch"}),jsx(Text,{children:" ".repeat(Math.max(0,r-15-2))}),jsx(Text,{children:" "}),jsx(Text,{color:e.ghost,children:ke})]}),jsx(Jt,{cw:r,children:""}),jsxs(Text,{children:[jsxs(Text,{color:e.ghost,children:[ke," "]}),jsx(Text,{color:e.silver,children:"Press N to create your first task".padEnd(r)}),jsx(Text,{children:" "}),jsx(Text,{color:e.ghost,children:ke})]}),jsx(Jt,{cw:r,children:""}),jsxs(Text,{children:[jsxs(Text,{color:e.ghost,children:[ke," "]}),jsx(Text,{color:e.amber,children:"N"}),jsx(Text,{color:e.gray,children:" new task"}),jsx(Text,{children:" ".repeat(Math.max(0,r-1-1-8))}),jsx(Text,{children:" "}),jsx(Text,{color:e.ghost,children:ke})]}),jsx(Jt,{cw:r,children:""}),jsxs(Text,{color:e.ghost,children:[Nn,l,Dn]})]})}function Zs({step:t,width:o}){let n=Math.min(o-4,50),r=n-6,l=be(n-2),f,b=null;if(t==="task_created")f="Press R to run task",b={key:"R",label:"run task"};else if(t==="run_started")f="Agent is running your task...";else return null;return jsxs(Box,{flexDirection:"column",paddingX:2,marginTop:1,children:[jsxs(Text,{color:e.ghost,children:[Ln,l,Pn]}),jsxs(Text,{children:[jsxs(Text,{color:e.ghost,children:[ke," "]}),jsx(Text,{color:e.amber,children:Gt}),jsxs(Text,{color:e.silver,children:[" ",f.padEnd(b?r-2-b.key.length-1-b.label.length-2:r-2)]}),b&&jsxs(Fragment,{children:[jsxs(Text,{color:e.amber,children:[" ",b.key]}),jsxs(Text,{color:e.gray,children:[" ",b.label]})]}),jsx(Text,{children:" "}),jsx(Text,{color:e.ghost,children:ke})]}),jsxs(Text,{color:e.ghost,children:[Nn,l,Dn]})]})}function Js({width:t}){let o=Math.min(t-4,50),n=o-6,r=be(o-2);return jsxs(Box,{flexDirection:"column",paddingX:2,marginTop:1,children:[jsxs(Text,{color:e.ghost,children:[Ln,r,Pn]}),jsx(Jt,{cw:n,children:""}),jsxs(Text,{children:[jsxs(Text,{color:e.ghost,children:[ke," "]}),jsx(Text,{color:e.green,bold:true,children:"First task completed!"}),jsx(Text,{children:" ".repeat(Math.max(0,n-21))}),jsx(Text,{children:" "}),jsx(Text,{color:e.ghost,children:ke})]}),jsx(Jt,{cw:n,children:""}),jsxs(Text,{children:[jsxs(Text,{color:e.ghost,children:[ke," "]}),jsx(Text,{color:e.silver,children:"Type / to see all commands".padEnd(n)}),jsx(Text,{children:" "}),jsx(Text,{color:e.ghost,children:ke})]}),jsx(Jt,{cw:n,children:""}),jsxs(Text,{color:e.ghost,children:[Nn,r,Dn]})]})}function Fn({count:t,config:o,width:n}){if(t>=3)return null;let r=Math.min((n??44)-4,50),l=r-6,f=be(r-2),b=jsxs(Text,{color:e.ghost,children:[Ln,f,Pn]}),T=jsxs(Text,{color:e.ghost,children:[Nn,f,Dn]});if(t>0){let y=o.hints[0],S=y?` ${y.key} ${y.label}`:"";return jsxs(Box,{flexDirection:"column",paddingX:2,marginTop:1,children:[b,jsxs(Text,{children:[jsxs(Text,{color:e.ghost,children:[ke," "]}),jsx(Text,{color:e.amber,children:Gt}),jsxs(Text,{color:e.silver,children:[" ",o.nudge.padEnd(l-2-S.length)]}),y&&jsxs(Fragment,{children:[jsxs(Text,{color:e.amber,children:[" ",y.key]}),jsxs(Text,{color:e.gray,children:[" ",y.label]})]}),jsx(Text,{children:" "}),jsx(Text,{color:e.ghost,children:ke})]}),T]})}let h=o.hints.reduce((y,S,C)=>y+S.key.length+1+S.label.length+(C>0?3:0),0);return jsxs(Box,{flexDirection:"column",paddingX:2,marginTop:1,children:[b,jsx(On,{cw:l}),jsxs(Text,{children:[jsxs(Text,{color:e.ghost,children:[ke," "]}),jsx(Text,{color:e.amber,children:Gt}),jsxs(Text,{color:e.white,bold:true,children:[" ",o.title]}),jsx(Text,{children:" ".repeat(Math.max(0,l-o.title.length-2))}),jsx(Text,{children:" "}),jsx(Text,{color:e.ghost,children:ke})]}),jsx(On,{cw:l}),o.description.map((y,S)=>jsxs(Text,{children:[jsxs(Text,{color:e.ghost,children:[ke," "]}),jsx(Text,{color:e.silver,children:y.padEnd(l)}),jsx(Text,{children:" "}),jsx(Text,{color:e.ghost,children:ke})]},S)),jsx(On,{cw:l}),jsxs(Text,{children:[jsxs(Text,{color:e.ghost,children:[ke," "]}),o.hints.map((y,S)=>jsxs(tn.Fragment,{children:[S>0&&jsx(Text,{color:e.ghost,children:" "}),jsx(Text,{color:e.amber,children:y.key}),jsxs(Text,{color:e.gray,children:[" ",y.label]})]},S)),jsx(Text,{children:" ".repeat(Math.max(0,l-h))}),jsx(Text,{children:" "}),jsx(Text,{color:e.ghost,children:ke})]}),jsx(On,{cw:l}),T]})}var Gl=2,oi=360,zl={done:4e3,failed:8e3,review:6e3},Vl={done:"\u2713",failed:"\u2715",review:qt},Hl={done:e.green,failed:e.red,review:e.blue},jl={done:e.successBg,failed:e.errorBg,review:e.infoBg};function Ul(t){let o=t.agentName??"Agent";switch(t.type){case "done":return `Task completed by ${o}`;case "failed":return "Task failed \u2014 press Enter for details";case "review":return "Task ready for review \u2014 press A to approve"}}var Xl=tn.memo(function({toast:o,onDismiss:n}){let[r,l]=useState(true),[f,b]=useState(false);useEffect(()=>{let k=setTimeout(()=>l(false),oi);return ()=>clearTimeout(k)},[]),useEffect(()=>{let k=zl[o.type],j=setTimeout(()=>b(true),k),V=setTimeout(()=>n(o.id),k+oi);return ()=>{clearTimeout(j),clearTimeout(V);}},[o.id,o.type,n]);let T=r||f,h=Vl[o.type],y=Hl[o.type],S=jl[o.type],C=Ul(o),_=o.title.length>40?o.title.slice(0,39)+"\u2026":o.title;return jsx(Box,{children:jsxs(Text,{backgroundColor:S,children:[jsxs(Text,{color:T?e.dim:y,children:[" ",h," "]}),jsx(Text,{color:T?e.dim:e.white,bold:!T,children:_}),jsxs(Text,{color:T?e.dim:e.silver,children:[" ",C," "]})]})})}),si=tn.memo(function({toasts:o,onDismiss:n}){let r=o.slice(0,Gl);return r.length===0?null:jsx(Box,{flexDirection:"column",children:r.map(l=>jsx(Xl,{toast:l,onDismiss:n},l.id))})});var Yl="\u256D",Zl="\u256E",Jl="\u2570",Ql="\u256F",st="\u2502",_r=[{key:"\u2191\u2193/j/k",label:"Navigate"},{key:"Tab/\u2190\u2192",label:"Switch tabs"},{key:"Enter",label:"Detail view"},{key:"G",label:"Goals tab"},{key:"T",label:"Tasks tab"},{key:"A",label:"Agents tab"},{key:"L",label:"Logs tab"}],Ar=[{key:"N",label:"New item"},{key:"E",label:"Edit"},{key:"D",label:"Delete"},{key:"R",label:"Run task"},{key:"S",label:"Show / Stop"},{key:"C",label:"Cancel"},{key:"A",label:"Approve"},{key:"X",label:"Reject"},{key:"U",label:"Autonomous"},{key:"Z",label:"Undo delete"}],Rr=[{key:"/",label:"Command mode"},{key:"/task add",label:"Create task"},{key:"/run",label:"Execute"},{key:"/watch",label:"Auto-dispatch"},{key:"/config",label:"Settings"},{key:"/help",label:"Help"},{key:"/quit",label:"Exit"}],Oo=10,Vt=22;function $r(t){let o=Math.max(0,Math.floor((Vt-t.length-2)/2)),n=Math.max(0,Vt-o-t.length-2);return be(o)+" "+t+" "+be(n)}var ii=tn.memo(function({width:o,height:n}){let r=Vt*3+3+3+2,l=r+2,f=be(l-2),b="KEYBOARD SHORTCUTS",T=Math.max(0,Math.floor((r-b.length)/2)),h=Math.max(0,r-T-b.length),y="Press any key to dismiss",S=Math.max(0,Math.floor((r-y.length)/2)),C=Math.max(0,r-S-y.length),_=Math.max(_r.length,Ar.length,Rr.length),k=_+10,j=Math.max(0,Math.floor((n-k)/2)),V=[];for(let $=0;$<_;$++){let D=$<_r.length?_r[$]:null,O=$<Ar.length?Ar[$]:null,F=$<Rr.length?Rr[$]:null;V.push(jsxs(Text,{children:[jsx(Text,{color:e.amber,children:st}),jsx(Text,{children:" "}),D?jsxs(Fragment,{children:[jsx(Text,{color:e.amber,bold:true,children:D.key.padEnd(Oo)}),jsx(Text,{color:e.silver,children:D.label.padEnd(Vt-Oo)})]}):jsx(Text,{children:" ".repeat(Vt)}),jsxs(Text,{color:e.dim,children:[" ",st," "]}),O?jsxs(Fragment,{children:[jsx(Text,{color:e.amber,bold:true,children:O.key.padEnd(Oo)}),jsx(Text,{color:e.silver,children:O.label.padEnd(Vt-Oo)})]}):jsx(Text,{children:" ".repeat(Vt)}),jsxs(Text,{color:e.dim,children:[" ",st," "]}),F?jsxs(Fragment,{children:[jsx(Text,{color:e.amber,bold:true,children:F.key.padEnd(Oo)}),jsx(Text,{color:e.silver,children:F.label.padEnd(Vt-Oo)})]}):jsx(Text,{children:" ".repeat(Vt)}),jsx(Text,{children:" "}),jsx(Text,{color:e.amber,children:st})]},`r${$}`));}let z=$=>jsxs(Text,{children:[jsx(Text,{color:e.amber,children:st}),jsx(Text,{children:" ".repeat(r)}),jsx(Text,{color:e.amber,children:st})]},$),E=$r("NAVIGATION"),U=$r("ACTIONS"),B=$r("COMMANDS");return jsxs(Box,{flexDirection:"column",paddingX:Math.max(0,Math.floor((o-l)/2)),marginTop:j,children:[jsxs(Text,{color:e.amber,children:[Yl,f,Zl]}),z("e1"),jsxs(Text,{children:[jsx(Text,{color:e.amber,children:st}),jsx(Text,{children:" ".repeat(T)}),jsx(Text,{color:e.amber,bold:true,children:b}),jsx(Text,{children:" ".repeat(h)}),jsx(Text,{color:e.amber,children:st})]}),z("e2"),jsxs(Text,{children:[jsx(Text,{color:e.amber,children:st}),jsx(Text,{children:" "}),jsx(Text,{color:e.dim,children:E}),jsxs(Text,{color:e.dim,children:[" ",st," "]}),jsx(Text,{color:e.dim,children:U}),jsxs(Text,{color:e.dim,children:[" ",st," "]}),jsx(Text,{color:e.dim,children:B}),jsx(Text,{children:" "}),jsx(Text,{color:e.amber,children:st})]}),z("e3"),V,z("e4"),jsxs(Text,{children:[jsx(Text,{color:e.amber,children:st}),jsx(Text,{children:" ".repeat(S)}),jsx(Text,{color:e.dim,children:y}),jsx(Text,{children:" ".repeat(C)}),jsx(Text,{color:e.amber,children:st})]}),z("e5"),jsxs(Text,{color:e.amber,children:[Jl,f,Ql]})]})});var ci=[{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"}],di=[{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"}],ui=[{value:"auto",label:"Auto",hint:"let Cursor decide"},{value:"composer-1.5",label:"Composer 1.5",hint:"latest agent"},{value:"composer-1",label:"Composer 1",hint:"stable agent"},{value:"gpt-5.3-codex",label:"GPT-5.3 Codex",hint:"OpenAI"},{value:"claude-sonnet-4-6",label:"Claude Sonnet 4.6",hint:"Anthropic"}],gi=[{value:"",label:"Default",hint:"use model configured in opencode"},{value:"openrouter/anthropic/claude-sonnet-4.6",label:"Claude Sonnet 4.6",hint:"fast, balanced"},{value:"openrouter/anthropic/claude-opus-4.6",label:"Claude Opus 4.6",hint:"most capable"},{value:"openrouter/google/gemini-2.5-pro",label:"Gemini 2.5 Pro",hint:"Google"},{value:"openrouter/google/gemini-2.5-flash",label:"Gemini 2.5 Flash",hint:"Google, fast"},{value:"openrouter/deepseek/deepseek-v3.2",label:"DeepSeek V3.2",hint:"open-source"},{value:"openrouter/deepseek/deepseek-r1:free",label:"DeepSeek R1",hint:"reasoning, free"},{value:"opencode/big-pickle",label:"Big Pickle",hint:"opencode native"}],mi=[{value:"",label:"Default",hint:"use shell adapter default"}],ec=[{value:"claude",label:"Claude",hint:"Claude Code CLI"},{value:"opencode",label:"OpenCode",hint:"OpenCode \u2014 multi-provider"},{value:"codex",label:"Codex",hint:"OpenAI Codex CLI"},{value:"cursor",label:"Cursor",hint:"Cursor Agent CLI"},{value:"shell",label:"Shell",hint:"custom shell command"}],fi=[{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"}],ai=60;function pi(t){return t.filter(o=>o.status!=="disabled").map(o=>{let n=(o.role??"").split(`
11
+ `)[0].trim(),r=n.length>ai?n.slice(0,ai-1)+"\u2026":n,l=r?`[${o.adapter}] ${r}`:o.adapter;return {value:o.id,label:o.name,hint:l}})}function zn(t,o="Auto-assign",n="orchestrator picks the best agent"){return [{value:"",label:o,hint:n},...pi(t)]}var Er=[{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 hi(t){return [{value:"",label:"None",hint:"no team"},...(t??[]).filter(o=>o.status==="active").map(o=>({value:o.id,label:o.name,hint:`${o.members.length} members`}))]}function xi(){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 Or(t,o){return t.map(n=>{switch(n.id){case "name":return {...n,defaultValue:o.name};case "adapter":return {...n,defaultValue:o.adapter};case "model":return {...n,defaultValue:o.model};case "role":return {...n,defaultValue:"__custom__"};case "role_custom":return {...n,defaultValue:o.role,skip:void 0};case "skills":return {...n,defaultValue:o.skills.join(", ")};case "approval_policy":return {...n,defaultValue:o.approval_policy};default:return n}})}function Vn(t,o){let n=hi(o);return [{id:"name",label:"Agent name",type:"text",placeholder:"e.g. alpha, frontend-bot, reviewer",required:true,validate:r=>r.trim()?t?.some(l=>l.name===r.trim())?"Agent with this name already exists":null:"Name is required",suggestions:a$2.map(r=>({value:r.key,label:r.name,hint:r.description}))},{id:"adapter",label:"Provider",type:"select",options:ec},{id:"model",label:"Model",type:"select",getOptions:r=>r.adapter==="opencode"?gi:r.adapter==="codex"?di:r.adapter==="cursor"?ui:r.adapter==="shell"?mi:ci},{id:"role",label:"Role / specialization",type:"select",options:Er},{id:"role_custom",label:"Describe the role",type:"textarea",placeholder:"e.g. Specialist in React and TypeScript",skip:r=>r.role!=="__custom__"},{id:"skills",label:"Skills (comma-separated)",type:"text",placeholder:"e.g. feature-dev:feature-dev, testing-suite:generate-tests"},{id:"approval_policy",label:"Approval policy",type:"text",skip:()=>true},{id:"team",label:"Join team",type:"select",options:n,skip:()=>n.length<=1}]}function bi(t){let o=t.role==="__custom__"?t.role_custom||void 0:t.role||void 0,n=t.skills?t.skills.split(",").map(l=>l.trim()).filter(Boolean):void 0,r=t.approval_policy||"auto";return {name:t.name,adapter:t.adapter||"claude",role:o,model:t.model||void 0,approval_policy:r,skills:n,team_id:t.team||void 0}}function Ti(t,o){let n=pi(t);return [{id:"name",label:"Team name",type:"text",placeholder:"e.g. frontend, backend, qa",required:true,validate:r=>r.trim()?o?.some(l=>l.name===r.trim())?"Team with this name already exists":null:"Name is required"},{id:"lead",label:"Team lead",type:"select",options:n},{id:"members",label:"Team members",type:"multiselect",getOptions:r=>n.filter(l=>l.value!==r.lead),skip:r=>!n.some(l=>l.value!==r.lead)},{id:"description",label:"Description",type:"textarea",placeholder:"Optional team purpose..."}]}function yi(t){let o=t.members?t.members.split(",").filter(Boolean):[];return {name:t.name,lead_agent_id:t.lead,member_agent_ids:o.length>0?o:void 0,description:t.description||void 0}}function wi(t){let o=zn(t);return [{id:"title",label:"Task title",type:"text",placeholder:"What needs to be done?",required:true,validate:n=>n.trim()?null:"Title is required"},{id:"priority",label:"Priority",type:"select",options:fi,defaultValue:"3",validate:n=>{let r=Number(n);return !Number.isInteger(r)||r<1||r>4?"Priority must be 1-4":null}},{id:"assignee",label:"Assignee",type:"select",options:o,skip:()=>o.length<=1},{id:"description",label:"Description",type:"textarea",placeholder:"Optional details, context, acceptance criteria..."}]}function Si(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 ki(t,o){let n=zn(o,"None / Auto","remove assignee");return [{id:"title",label:"Task title",type:"text",defaultValue:t.title,required:true,validate:r=>r.trim()?null:"Title is required"},{id:"priority",label:"Priority",type:"select",options:fi,defaultValue:String(t.priority),validate:r=>{let l=Number(r);return !Number.isInteger(l)||l<1||l>4?"Priority must be 1-4":null}},{id:"assignee",label:"Assignee",type:"select",options:n,defaultValue:t.assignee??"",skip:()=>n.length<=1},{id:"description",label:"Description",type:"textarea",defaultValue:t.description||"",placeholder:"Optional details..."}]}function Ci(t){return {title:t.title,priority:t.priority?parseInt(t.priority,10):void 0,assignee:t.assignee||void 0,description:t.description??""}}function Ii(t,o,n){let r=Er.find(h=>h.value===t.role),l=r?t.role:t.role?"__custom__":"",f=t.adapter==="opencode"?gi:t.adapter==="codex"?di:t.adapter==="cursor"?ui:t.adapter==="shell"?mi:ci,b=hi(n),T=n?.find(h=>h.members.some(y=>y.agent_id===t.id))?.id;return [{id:"name",label:"Agent name",type:"text",defaultValue:t.name,required:true,validate:h=>h.trim()?o?.some(y=>y.id!==t.id&&y.name===h.trim())?"Agent with this name already exists":null:"Name is required"},{id:"model",label:"Model",type:"select",options:f,defaultValue:t.config.model??""},{id:"role",label:"Role / specialization",type:"select",options:Er,defaultValue:l},{id:"role_custom",label:"Describe the role",type:"textarea",defaultValue:t.role&&!r?t.role:"",placeholder:"e.g. Specialist in React and TypeScript",skip:h=>h.role!=="__custom__"},{id:"team",label:"Team",type:"select",options:b,defaultValue:T??"",skip:()=>b.length<=1}]}var tc=[{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"}],oc=[{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"}],li=[{value:"true",label:"On"},{value:"false",label:"Off"}];function Mi(t,o,n){let r=n??{toast:true,bell:false};return [{id:"activity_filter",label:"Activity filter preset",type:"select",options:oc,defaultValue:t},{id:"max_concurrent",label:"Max concurrent agents",type:"select",options:tc,defaultValue:String(o)},{id:"notifications_toast",label:"Toast notifications",type:"select",options:li,defaultValue:String(r.toast)},{id:"notifications_bell",label:"Bell on completion",type:"select",options:li,defaultValue:String(r.bell)}]}function vi(t){let o=t.role==="__custom__"?t.role_custom||void 0:t.role||void 0;return {name:t.name,role:o,model:t.model||void 0,team_id:t.team||void 0}}function Hn(t){let o=zn(t,"Any agent","auto-assign to autonomous agents");return [{id:"title",label:"Goal title",type:"text",placeholder:'e.g. "Implement OAuth2 login with Google and GitHub"',description:"Be specific \u2014 agents work better with clear, measurable objectives",required:true,validate:n=>n.trim()?null:"Title is required"},{id:"assignee",label:"Assignee",type:"select",description:"Assigned agent gets autonomous mode \u2014 it will plan and execute without prompts",options:o,skip:()=>o.length<=1},{id:"description",label:"Description",type:"textarea",placeholder:"Success criteria, constraints, technical context...",description:'Context matters \u2014 include tech stack, constraints, and what "done" looks like'}]}function _i(t){return {title:t.title,assignee:t.assignee||void 0,description:t.description||void 0}}function Ai(t,o){let n=zn(o,"Any agent","auto-assign");return [{id:"title",label:"Goal title",type:"text",defaultValue:t.title,description:"Be specific \u2014 agents work better with clear, measurable objectives",required:true,validate:r=>r.trim()?null:"Title is required"},{id:"assignee",label:"Assignee",type:"select",description:"Assigned agent gets autonomous mode \u2014 it will plan and execute without prompts",options:n,defaultValue:t.assignee??"",skip:()=>n.length<=1},{id:"description",label:"Description",type:"textarea",defaultValue:t.description||"",placeholder:"Success criteria, constraints, technical context...",description:'Context matters \u2014 include tech stack, constraints, and what "done" looks like'}]}function Ri(t){return {title:t.title,assignee:t.assignee||void 0,description:t.description??""}}var $i=10,Bi=500,Kn=2048,go=500,Ei=5,Lr=new Set(["todo","failed","cancelled"]),ic={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."},ac={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."},lc={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."},Oi=5e3,Pi=0;function Gu(){Pi=0;}var Ni=/^\[[\w_]+\]$/;function Di(t){return Ni.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 Nr=["#5faf87","#5fafd7","#af87ff","#d7af00","#5fd7d7","#d787af","#afaf5f","#d7875f"],cc=" ".repeat(9),Yn={system:"\u2666",lifecycle:"\u25B6",output:"\u2502",tool:"\u2699",result:"\u2190",error:"\u2715",file:"\u270E",info:"\u2502"},Xn=["system","lifecycle","output","tool","result","error","file","info"],Lo=[{label:"all",types:Xn},{label:"text",types:["output"]},{label:"tools",types:["tool","result","file"]},{label:"errors",types:["error"]},{label:"events",types:["lifecycle","system"]}];function Pr(t){let n=(Lo.findIndex(r=>r.types.length===t.size&&r.types.every(l=>t.has(l)))+1)%Lo.length;return Lo[n]}function zu({projectName:t,tasks:o,agents:n=[],state:r,onRunTask:l,onCreateTask:f,onCancelTask:b$1,onRetryTask:T,onAssignTask:h,onRunAll:y,onDisableAgent:S,onEnableAgent:C,onSubscribeEvents:_,onRefreshTasks:k,onRefreshAgents:j,onRefreshState:V,onLoadHistory:z,onAddAgent:E,onDeleteAgent:U,onApproveTask:B,onRejectTask:$,onDeleteTask:D,onUpdateTask:O,onUpdateAgent:F,onForceStopAgent:W,onCreateTeam:X,onListTeams:A,onJoinTeam:ie,onLeaveTeam:Re,onDisbandTeam:Mt,onSetTeamLead:it,onStartWatch:at,onStopWatch:gt,onToggleAutonomous:vt,onRefreshGoals:lt,onCreateGoal:Xe,onUpdateGoal:$e,onUpdateGoalStatus:qe,onDeleteGoal:Ze,onGetGoalProgress:Dt,onCompleteOnboarding:Je,initialWatchActive:Le,watchError:Ve,messageBatchMs:Qt=process.env.VITEST?0:80,initialActivityFilter:mo="all",onSaveActivityFilter:ct,initialMaxConcurrent:Ht=a.scheduling.max_concurrent_agents,onSaveMaxConcurrent:_t,initialNotifications:eo,onSaveNotifications:jt,version:Po,latestVersion:mt}){let{exit:No}=useApp(),{stdout:At}=useStdout(),[fo,to]=useState({w:At?.columns??80,h:At?.rows??24});useEffect(()=>{if(!At)return;let i=()=>to({w:At.columns,h:At.rows});return At.on("resize",i),()=>{At.off("resize",i);}},[At]);let ft=fo.w,G=fo.h,[R,M]=useState(o),[L,ee]=useState(n),[K,Ie]=useState(r),[le,ue]=useState(Le??!!r.pid),[ye,Ft]=useState([]),[Do,sn]=useState(void 0),[Ut,an]=useState(()=>r.onboardingCompleted||(r.stats?.total_tasks_completed??0)>0?"dismissed":Object.keys(r.running??{}).length>0?"run_started":o.length>0?"task_created":"welcome");useEffect(()=>{if(Ut!=="completed")return;let i=setTimeout(()=>{an("dismissed"),Je?.().catch(()=>{});},5e3);return ()=>clearTimeout(i)},[Ut,Je]);let[v,po]=useState("tasks"),[ln,Fo]=useState(0),[Zn,Dr]=useState(0),[Jn,Fr]=useState(0),[_e,Wo]=useState(false),[Fe,Wr]=useState([]),[Pe,Be]=useState("none"),[oo,wt]=useState(""),[pt,Ke]=useState(null),[no,Go]=useState([]),[Rt,Qn]=useState(false),[Gr,Hi]=useState(()=>new Set),[ho,er]=useState(false),[zo,tr]=useState(false),[zr,Vr]=useState(()=>new Set(Xn)),[Vo,or]=useState(-1),[ji,Ho]=useState(0),[xo,nr]=useState(()=>{let i=Lo.find(x=>x.label===mo);return new Set(i?.types??Xn)}),cn=useMemo(()=>Lo.find(x=>x.types.length===xo.size&&x.types.every(s=>xo.has(s)))?.label??"all",[xo]),rr=useMemo(()=>xo.size>=Xn.length?Fe:Fe.filter(i=>xo.has(i.msgType??"info")),[Fe,xo]),[Hr,Ui]=useState(Ht),[dn,Xi]=useState(eo??{toast:true,bell:false}),[qi,jr]=useState([]),Ki=useRef(0),[sr,Ur]=useState(),Xr=useRef(v);Xr.current=v;let qr=useRef(R);qr.current=R;let Kr=useRef(L);Kr.current=L;let un=useRef(dn);un.current=dn;let gn=useCallback((i,x)=>{if(!un.current.toast)return;let s=qr.current.find(p=>p.id===x),d=s?.title??x,u=s?.assignee?Kr.current.find(p=>p.id===s.assignee):void 0;jr(p=>{let g=[...p,{id:`toast_${Ki.current++}`,type:i,title:d,agentName:u?.name,ts:Date.now()}];return g.length>Ei?g.slice(g.length-Ei):g}),un.current.bell&&(i==="failed"||i==="review")&&process.stdout.write("\x07");},[]),Yi=useCallback(i=>{jr(x=>x.filter(s=>s.id!==i));},[]),mn=tn.useRef(new Rn).current,[Zi,bo]=useState(0),[Yr,Zr]=useState(false),[jo,Ji]=useState(false),[Qi,ir]=useState(0),[ea,ar]=useState(0),[lr,To]=useState(0),[fn,cr]=useState(false),[ta,Uo]=useState(0),[pn,Xt]=useState(0),[Wt,Jr]=useState([]),[yo,dr]=useState([]),wo=useRef(Wt);wo.current=Wt;let Z=useCallback(async i=>{let[x,s,d,u,p]=await Promise.all([k?.()??Promise.resolve(R),j?.()??Promise.resolve(L),V?.()??Promise.resolve(K),i?.includeTeams?A?.()??Promise.resolve(wo.current):Promise.resolve(null),lt?.()??Promise.resolve(ye)]);M(x),ee(s),Ie(d),u!==null&&Jr(u),Ft(p),Le&&ue(!!d.pid);},[k,j,V,A,lt,Le]),So=useMemo(()=>{let i=new Map;for(let x of ye)i.set(x.id,x);return i},[ye]),Ee=useMemo(()=>{let i=[...R].sort((p,g)=>(Jo[p.status]??9)-(Jo[g.status]??9));if(!jo)return i;let x=[],s=[],d=[],u=new Map;for(let p of i)p.goalId&&So.has(p.goalId)?(u.has(p.goalId)||(d.push(p.goalId),u.set(p.goalId,[])),u.get(p.goalId).push(p)):s.push(p);for(let p of d)x.push(...u.get(p));return [...x,...s]},[R,jo,So]),$t=Yr?Ee:Ee.slice(0,$i),ko=Ee.length-$t.length,H=Ee[ln],Xo=useMemo(()=>{let i=new Map;for(let x of R)i.set(x.id,x.title);return i},[R]),ro=useMemo(()=>{let i=new Map;for(let x of L)i.set(x.id,x.name);return i},[L]),oa=useMemo(()=>{let i=new Map;for(let x of R)if(x.goalId){let s=i.get(x.goalId);s||(s=[],i.set(x.goalId,s)),s.push(x);}return i},[R]),hn=useMemo(()=>{let i=new Map;for(let x=0;x<L.length;x++)i.set(L[x].id,Nr[x%Nr.length]);return i},[L]),Qr=useMemo(()=>{let i=new Map;for(let x of Fe)x.agentId&&i.set(x.agentId,(i.get(x.agentId)??0)+1);return i},[Fe]),na=useMemo(()=>{let i={};for(let x of Fe){let s=x.msgType??"info";i[s]=(i[s]??0)+1;}return i},[Fe]),{agentTeamMap:Co,activeTeamCount:qo,teamLeadSet:ra}=useMemo(()=>{let i=new Map,x=new Set,s=0;for(let d of Wt)if(d.status==="active"){s++,x.add(d.lead_agent_id);for(let u of d.members)i.set(u.agent_id,d.name);}return {agentTeamMap:i,activeTeamCount:s,teamLeadSet:x}},[Wt]),Ne=useMemo(()=>{let i=[...L];return i.sort((x,s)=>{let d=Co.get(x.id),u=Co.get(s.id);return d&&!u?-1:!d&&u?1:d&&u&&d!==u?d.localeCompare(u):(wr[x.status]??9)-(wr[s.status]??9)}),i},[L,Co]),J=Ne[Zn],dt=useMemo(()=>[...ye].sort((i,x)=>(c[i.status]??9)-(c[x.status]??9)),[ye]),te=dt[Jn],sa=useMemo(()=>te?R.filter(i=>i.goalId===te.id):[],[te,R]),ur=useRef(Dt);ur.current=Dt,useEffect(()=>{if(!te||!ur.current){sn(void 0);return}let i=false;return ur.current(te.id).then(x=>{i||sn(x);}).catch(()=>{}),()=>{i=true;}},[te?.id]);let so=useRef(new Map),xn=useRef(new Map);useEffect(()=>{for(let[i,x]of Object.entries(K.running))so.current.set(x.run_id,x.agent_id),xn.current.set(x.run_id,i);if(so.current.size>Bi){let i=so.current.size-Bi,x=0;for(let s of so.current.keys()){if(x++>=i)break;so.current.delete(s),xn.current.delete(s);}}},[K.running]);let io=useRef([]),Ko=useRef(null),gr=useCallback(()=>{if(Ko.current=null,io.current.length===0)return;let i=io.current;io.current=[],Wr(x=>{if(i.length>=go)return i.slice(-go);let s=go-i.length;return (x.length>s?x.slice(-s):x).concat(i)});},[]);useEffect(()=>()=>{Ko.current&&clearTimeout(Ko.current);},[]);let a=useCallback((i,x,s)=>{let d=new Date,u=d.toLocaleTimeString("en-US",{hour12:false,hour:"2-digit",minute:"2-digit",second:"2-digit"}),p=s?.detail&&s.detail.length>Kn?s.detail.slice(0,Kn)+"\u2026[truncated]":s?.detail;io.current.push({text:i,color:x,time:u,ts:d.getTime(),...s,detail:p}),io.current.length>go*2&&(io.current=io.current.slice(-go)),Qt===0?gr():Ko.current||(Ko.current=setTimeout(gr,Qt));},[gr]);useEffect(()=>{Ve&&a(`Watch mode failed: ${Ve}. Tasks will not auto-dispatch.`,e.red);},[]);let Io=useCallback((i,x,s,d)=>{let u={key:++Pi,entityType:i,entityId:x,entityName:s,expiresAt:Date.now()+Oi,needsForceStop:d?.needsForceStop};dr(p=>[...p,u]),a(`\u2717 "${s}" will be deleted in ${Math.round(Oi/1e3)}s \u2014 press Z to undo`,e.yellow);},[a]),ia=useCallback(()=>{dr(i=>{if(i.length===0)return i;let x=i[i.length-1];return a(`\u21B6 Undo: "${x.entityName}" restored`,e.green),i.slice(0,-1)});},[a]),es=useCallback(async i=>{try{i.entityType==="task"&&D?await D(i.entityId):i.entityType==="agent"?(i.needsForceStop&&W&&await W(i.entityId),U&&await U(i.entityId)):i.entityType==="goal"&&Ze&&await Ze(i.entityId),a(`\u2713 Deleted "${i.entityName}"`,e.green),Z();}catch(x){a(`Failed to delete "${i.entityName}": ${x instanceof Error?x.message:String(x)}`,e.red);}},[D,U,Ze,W,a,Z]),ts=useRef(es);ts.current=es,useEffect(()=>{if(yo.length===0)return;let i=setInterval(()=>{let x=Date.now(),s=[];dr(d=>{let u=d.filter(p=>p.expiresAt<=x?(s.push(p),false):true);return s.length>0?u:d});for(let d of s)ts.current(d);},1e3);return ()=>clearInterval(i)},[yo.length>0]),useEffect(()=>{if(!z)return;let i=x=>{let s=new Date(x.timestamp).toLocaleTimeString("en-US",{hour12:false,hour:"2-digit",minute:"2-digit",second:"2-digit"}),d=typeof x.data=="string"?x.data:JSON.stringify(x.data),u,p=e.silver,g="output";if(x.type==="error")u=typeof x.data=="string"?x.data:JSON.stringify(x.data),u=u.slice(0,200),p=e.red,g="error";else if(x.type==="file_changed")u=String(x.data),p=e.purple,g="file";else if(x.type==="done")u="Completed",p=e.green,g="lifecycle";else if(x.type==="tool_call")u=`\u2699 ${x.data?.name??"tool"}()`,p=e.cyan,g="tool";else {let{summary:w}=Vi(d);if(!w)return null;u=w;let Y=Di(u);g=Y.msgType,p=Y.color;}return {text:u,color:p,time:s,ts:new Date(x.timestamp).getTime(),agentId:x.agentId,taskId:x.taskId,msgType:g}};z(x=>{if(x.length===0)return;let s=x.map(i).filter(d=>d!==null);Wr(d=>{let u=[...s,...d];return u.length>go?u.slice(-go):u});}).catch(()=>{});},[]),useEffect(()=>{A?.().then(Jr).catch(()=>{}),lt?.().then(Ft).catch(()=>{});},[]);let bn=useCallback(()=>{Ke({title:"NEW AGENT",steps:Vn(L,wo.current),kind:"agent"}),Be("wizard");},[L]),os=useCallback(()=>{Ke({title:"AGENT SHOP",steps:xi(),kind:"agent_shop"}),Be("wizard");},[]),Tn=useCallback(()=>{Go([]),Ke({title:"NEW TASK",steps:wi(L),kind:"task"}),Be("wizard");},[L]),aa=useCallback(async()=>{try{let{detectClipboardType:i,getClipboardImage:x}=await import('./clipboard-service-WVON5ZN4.js'),s=await i();if(s!=="image")return a(s==="text"?"Clipboard has text, not image":"Clipboard is empty",e.dim),s;let d=await x();if(!d)return a("Failed to read clipboard image",e.red),"empty";let{mkdtemp:u,writeFile:p}=await import('fs/promises'),{tmpdir:g}=await import('os'),{join:w}=await import('path'),Y=await u(w(g(),"orch-paste-")),Et=w(Y,`clipboard-${Date.now()}.${d.ext}`);return await p(Et,d.data),Go(ao=>[...ao,Et]),a(`\u{1F4CE} Image attached (${Math.round(d.data.length/1024)}KB)`,e.green),"image"}catch{return a("Clipboard paste failed",e.red),"empty"}},[a]),la=useCallback(i=>{Ke({title:"EDIT TASK",steps:ki(i,L),kind:"edit_task",targetId:i.id}),Be("wizard");},[L]),ns=useCallback(()=>{Ke({title:"NEW TEAM",steps:Ti(L,Wt),kind:"team"}),Be("wizard");},[L]),ca=useCallback(i=>{Ke({title:"EDIT AGENT",steps:Ii(i,L,Wt),kind:"edit_agent",targetId:i.id}),Be("wizard");},[Wt]),rs=useCallback(()=>{Ke({title:"SETTINGS",steps:Mi(cn,Hr,dn),kind:"config"}),Be("wizard");},[cn,Hr]),da=useCallback(i=>{Be("none");let x=pt?.kind,s=pt?.targetId;if(Ke(null),x==="agent_shop"){let d=i.shop_template,u=d?b(d):void 0;if(u){let p=Vn(L,wo.current),g=Or(p,u);Ke({title:`NEW AGENT \u2014 ${u.name}`,steps:g,kind:"agent_from_shop"}),Be("wizard");}else a("No template selected",e.yellow);return}if((x==="agent"||x==="agent_from_shop")&&E){let d=bi(i);a(`Creating agent "${d.name}"...`,e.amber),E(d.name,d.adapter,{model:d.model,role:d.role,approval_policy:d.approval_policy,skills:d.skills}).then(u=>{a(`\u2713 Created agent "${u.name}" (${u.id}, ${u.adapter})`,e.green),d.team_id&&ie?ie(d.team_id,u.id).then(p=>{a(`\u2713 Joined team "${p.name}"`,e.green),Z({includeTeams:true});},p=>a(`Failed to join team: ${p instanceof Error?p.message:String(p)}`,e.red)):Z();},u=>a(`Failed: ${u instanceof Error?u.message:String(u)}`,e.red));}else if(x==="team"&&X){let d=yi(i);a(`Creating team "${d.name}"...`,e.amber),X(d).then(u=>{a(`\u2713 Created team "${u.name}" (${u.id}, ${u.members.length} members)`,e.green),Z({includeTeams:true});},u=>a(`Failed: ${u instanceof Error?u.message:String(u)}`,e.red));}else if(x==="task"&&f){let d=Si(i),u=no.length>0?[...no]:void 0;Go([]),a(`Creating "${d.title}"...`,e.amber),f(d.title,{priority:d.priority,description:d.description,attachments:u}).then(p=>{a(`\u2713 Created "${p.title}" (${p.id})${u?` \u{1F4CE}${u.length}`:""}`,e.green),d.assignee&&h&&h(p.id,d.assignee).catch(()=>{}),Z();},p=>a(`Failed: ${p instanceof Error?p.message:String(p)}`,e.red));}else if(x==="edit_task"&&s&&O){let d=Ci(i),u=no.length>0?[...no]:void 0;Go([]),a("Updating task...",e.amber),O(s,{...d,attachments:u}).then(p=>{a(`\u2713 Updated "${p.title}"${u?` \u{1F4CE}${u.length}`:""}`,e.green),d.assignee&&h&&h(s,d.assignee).catch(()=>{}),Z();},p=>a(`Failed: ${p instanceof Error?p.message:String(p)}`,e.red));}else if(x==="edit_agent"&&s&&F){let d=vi(i),u=d.team_id??"",p=Wt.find(g=>g.members.some(w=>w.agent_id===s))?.id??"";a("Updating agent...",e.amber),F(s,{name:d.name,role:d.role,model:d.model}).then(g=>{a(`\u2713 Updated agent "${g.name}"`,e.green);let w=[];p&&p!==u&&Re&&w.push(Re(p,s).then(Y=>a(`\u2713 Left team "${Y.name}"`,e.green),Y=>a(`Failed to leave team: ${Y instanceof Error?Y.message:String(Y)}`,e.red))),u&&u!==p&&ie&&w.push(ie(u,s).then(Y=>a(`\u2713 Joined team "${Y.name}"`,e.green),Y=>a(`Failed to join team: ${Y instanceof Error?Y.message:String(Y)}`,e.red))),Promise.all(w).then(()=>Z({includeTeams:w.length>0}));},g=>a(`Failed: ${g instanceof Error?g.message:String(g)}`,e.red));}else if(x==="config"){if(i.activity_filter){let g=Lo.find(w=>w.label===i.activity_filter);g&&(nr(new Set(g.types)),ct?.(g.label));}if(i.max_concurrent){let g=parseInt(i.max_concurrent,10);g>0&&(Ui(g),_t?.(g));}let d=i.notifications_toast==="true",u=i.notifications_bell==="true",p={toast:d,bell:u};Xi(p),jt?.(p),a("Settings saved",e.green);}else if(x==="goal"&&Xe){let d=_i(i);a(`Creating goal "${d.title}"...`,e.amber),Xe(d).then(u=>{a(`\u2713 Created goal "${u.title}" (${u.id})`,e.green),Z();},u=>a(`Failed: ${u instanceof Error?u.message:String(u)}`,e.red));}else if(x==="edit_goal"&&s&&$e){let d=Ri(i);a("Updating goal...",e.amber),$e(s,d).then(u=>{a(`\u2713 Updated goal "${u.title}"`,e.green),Z();},u=>a(`Failed: ${u instanceof Error?u.message:String(u)}`,e.red));}},[pt,E,f,X,ie,Re,h,O,F,vt,Xe,$e,a,Z,ct,_t,dn,jt,Wt,no]),ua=useCallback(()=>{Be("none"),Ke(null),Go([]);},[]),ga=useCallback(i=>{let x=b(i);if(!x)return;let s=Vn(L,wo.current),d=Or(s,x);Ke({title:`NEW AGENT \u2014 ${x.name}`,steps:d,kind:"agent_from_shop"}),Be("wizard");},[]);useEffect(()=>{if(!_)return;let i=null,x=()=>{i||(i=setTimeout(()=>{i=null,Z().catch(()=>{});},150));},s=_(d=>{if(d.type==="agent:started"&&(so.current.set(d.runId,d.agentId),xn.current.set(d.runId,d.taskId)),_c(d,a,so.current,xn.current),d.type==="task:created"?an(u=>u==="welcome"?"task_created":u):d.type==="agent:started"?an(u=>u==="task_created"?"run_started":u):d.type==="task:status_changed"&&d.to==="done"&&an(u=>u==="run_started"?"completed":u),d.type==="task:status_changed"&&(d.to==="done"?gn("done",d.taskId):d.to==="failed"?gn("failed",d.taskId):d.to==="review"&&gn("review",d.taskId),un.current.toast&&Xr.current!=="tasks")){let u=d.to==="done"?e.green:d.to==="failed"?e.red:d.to==="review"?e.blue:void 0;u&&Ur({tab:"tasks",color:u});}(d.type==="task:status_changed"||d.type==="task:created"||d.type==="task:assigned"||d.type==="agent:started"||d.type==="agent:completed"||d.type==="run:retry"||d.type==="goal:created"||d.type==="goal:status_changed"||d.type==="goal:updated"||d.type==="goal:deleted")&&x();});return ()=>{s(),i&&clearTimeout(i);}},[_,a,Z,gn]);let mr=le?"watching":"idle",ma=K.started_at?g(K.started_at):void 0,ss=K.stats.total_tokens.total,is=useMemo(()=>{let i={running:0,retrying:0,review:0,todo:0,done:0,failed:0,cancelled:0};for(let x of R)x.status==="in_progress"?i.running++:x.status==="retrying"?i.retrying++:x.status==="review"?i.review++:x.status==="todo"?i.todo++:x.status==="done"?i.done++:x.status==="failed"?i.failed++:x.status==="cancelled"&&i.cancelled++;return {...i,teams:qo}},[R,qo]);is.running;let fa=useMemo(()=>({input:K.stats.total_tokens.input??0,output:K.stats.total_tokens.output??0,reasoning:K.stats.total_tokens.reasoning??0,total:ss,cache_read:K.stats.total_tokens.cache_read??0,cache_write:K.stats.total_tokens.cache_write??0}),[K.stats.total_tokens,ss]),St=Math.max(4,G-9),pa=Co.size,ha=L.length>pa,xa=qo>0?qo+(ha?1:0):0,ba=useMemo(()=>{if(!jo||So.size===0)return 0;let i=0,x=new Set,s=false;for(let d of $t)d.goalId&&So.has(d.goalId)?x.has(d.goalId)||(x.add(d.goalId),i++):s=true;return s&&i++,i},[jo,So,$t]),Ta=v==="goals"?dt.length+1:v==="tasks"?$t.length+1+(ko>0?1:0)+ba:v==="agents"?L.length+1+xa:0,ya=Math.min(Ta+1,Math.ceil(St*.5)),wa=v==="logs"?St:Math.max(2,Math.min(ya,St-4)),we,Bt;if(v==="logs")we=St,Bt=0;else if(fn)we=0,Bt=Math.max(1,St);else {let i=Math.max(3,Math.min(wa+lr,St-4));we=i,Bt=Math.max(1,St-i);}let Me=Math.max(10,ft-2),kt=useMemo(()=>Pe==="command"?Ds(oo):[],[Pe,oo]),Mo=St-4-3;useEffect(()=>{lr>Mo&&To(Mo),lr<-Mo&&To(-Mo);},[St]),useEffect(()=>{bo(i=>Math.min(i,Math.max(0,$t.length-we)));},[$t.length,we]),useEffect(()=>{ir(i=>Math.min(i,Math.max(0,Ne.length-we)));},[Ne.length,we]),useEffect(()=>{ar(i=>Math.min(i,Math.max(0,dt.length-we)));},[dt.length,we]);let Sa=useCallback(i=>{let s=i.trim().replace(/^\//,"").split(/\s+/),d=s[0]?.toLowerCase();if(!d)return;let u=p=>p instanceof Error?p.message:String(p);switch(d){case "cancel":{if(!H){a("No task selected",e.yellow);return}if(!b$1)return;a(`Cancelling "${H.title}"...`,e.amber),b$1(H.id).then(()=>{a(`\u2713 Cancelled "${H.title}"`,e.green),Z();},p=>a(`Failed: ${u(p)}`,e.red));return}case "retry":{if(!H){a("No task selected",e.yellow);return}if(!T)return;a(`Retrying "${H.title}"...`,e.amber),T(H.id).then(()=>{a(`\u2713 Retried "${H.title}"`,e.green),Z();},p=>a(`Failed: ${u(p)}`,e.red));return}case "assign":{if(!H){a("No task selected",e.yellow);return}if(!h||!s[1]){a("Usage: assign <agent>",e.yellow);return}a(`Assigning "${H.title}" to ${s[1]}...`,e.amber),h(H.id,s[1]).then(()=>{a(`\u2713 Assigned "${H.title}" to ${s[1]}`,e.green),Z();},p=>a(`Failed: ${u(p)}`,e.red));return}case "task":{let p=s[1]?.toLowerCase();if(p==="add"){let g=s.slice(2).join(" ");if(!g){Tn();return}if(!f){a("Create not available",e.yellow);return}a(`Creating "${g}"...`,e.amber),f(g).then(w=>{a(`\u2713 Created "${w.title}" (${w.id})`,e.green),Z();},w=>a(`Failed: ${u(w)}`,e.red));}else if(p==="list"){let g=Ee.map(w=>` ${w.id} ${w.status.padEnd(11)} ${w.title}`);if(g.length===0)a("No tasks",e.dim);else for(let w of g)a(w,e.cyan);}else if(p==="show"){let g=s[2]?Ee.find(w=>w.id===s[2]):H;if(!g){a("No task selected or id given",e.yellow);return}a(`${g.id} ${g.status} P${g.priority} "${g.title}"`,e.cyan),g.assignee&&a(` agent: ${g.assignee}`,e.dim),g.description&&a(` ${g.description.slice(0,100)}`,e.dim);}else if(p==="cancel"){let g=s[2]?Ee.find(w=>w.id===s[2]):H;if(!g){a("No task selected or id given",e.yellow);return}if(!b$1)return;a(`Cancelling "${g.title}"...`,e.amber),b$1(g.id).then(()=>{a(`\u2713 Cancelled "${g.title}"`,e.green),Z();},w=>a(`Failed: ${u(w)}`,e.red));}else if(p==="retry"){let g=s[2]?Ee.find(w=>w.id===s[2]):H;if(!g){a("No task selected or id given",e.yellow);return}if(!T)return;a(`Retrying "${g.title}"...`,e.amber),T(g.id).then(()=>{a(`\u2713 Retried "${g.title}"`,e.green),Z();},w=>a(`Failed: ${u(w)}`,e.red));}else if(p==="assign"){let g=s[2]?Ee.find(Et=>Et.id===s[2]):void 0,w=g??H,Y=g?s[3]:s[2];if(!w){a("No task selected or id given",e.yellow);return}if(!Y){a("Usage: /task assign [id] <agent>",e.yellow);return}if(!h)return;a(`Assigning "${w.title}" to ${Y}...`,e.amber),h(w.id,Y).then(()=>{a(`\u2713 Assigned "${w.title}" to ${Y}`,e.green),Z();},Et=>a(`Failed: ${u(Et)}`,e.red));}else if(p==="approve"){let g=s[2]?Ee.find(w=>w.id===s[2]):H;if(!g){a("No task selected or id given",e.yellow);return}if(g.status!=="review"){a(`Cannot approve \u2014 status is ${g.status}`,e.yellow);return}if(!B)return;a(`Approving "${g.title}"...`,e.amber),B(g.id).then(()=>{a(`\u2713 Approved "${g.title}"`,e.green),Z();},w=>a(`Failed: ${u(w)}`,e.red));}else if(p==="reject"){let g=s[2]?Ee.find(Y=>Y.id===s[2]):H;if(!g){a("No task selected or id given",e.yellow);return}if(g.status!=="review"){a(`Cannot reject \u2014 status is ${g.status}`,e.yellow);return}if(!$)return;let w=s.slice(s[2]&&Ee.find(Y=>Y.id===s[2])?3:2).join(" ").trim()||void 0;a(`Rejecting "${g.title}"${w?" with feedback":""}...`,e.amber),$(g.id,w).then(()=>{a(`\u2713 Rejected "${g.title}" \u2192 todo`,e.green),Z();},Y=>a(`Failed: ${u(Y)}`,e.red));}else if(p==="delete"){let g=s[2]?Ee.find(w=>w.id===s[2]):H;if(!g){a("No task selected or id given",e.yellow);return}if(g.status==="in_progress"){a("Cannot delete \u2014 task is running",e.yellow);return}if(!D)return;Io("task",g.id,g.title);}else a("Usage: /task add|list|show|cancel|retry|assign|approve|reject|delete",e.yellow);return}case "agent":{let p=s[1]?.toLowerCase();if(p==="add"){let g=s[2];if(!g){bn();return}if(!E){a("Agent creation not available",e.yellow);return}let w=s[3];a(`Creating agent "${g}"...`,e.amber),E(g,w).then(Y=>{a(`\u2713 Created agent "${Y.name}" (${Y.id}, ${Y.adapter})`,e.green),Z();},Y=>a(`Failed: ${u(Y)}`,e.red));}else if(p==="list"){let g=Ne.map(w=>` ${w.id} ${w.status.padEnd(8)} ${w.name} (${w.adapter})`);if(g.length===0)a("No agents",e.dim);else for(let w of g)a(w,e.cyan);}else if(p==="disable"){let g=s[2]?Ne.find(w=>w.id===s[2]||w.name===s[2]):J;if(!g){a("No agent selected or id given",e.yellow);return}if(!S)return;a(`Disabling ${g.name}...`,e.amber),S(g.id).then(()=>{a(`\u2713 Disabled ${g.name}`,e.green),Z();},w=>a(`Failed: ${u(w)}`,e.red));}else if(p==="enable"){let g=s[2]?Ne.find(w=>w.id===s[2]||w.name===s[2]):J;if(!g){a("No agent selected or id given",e.yellow);return}if(!C)return;a(`Enabling ${g.name}...`,e.amber),C(g.id).then(()=>{a(`\u2713 Enabled ${g.name}`,e.green),Z();},w=>a(`Failed: ${u(w)}`,e.red));}else if(p==="delete"||p==="remove"){let g=s[2]?Ne.find(w=>w.id===s[2]||w.name===s[2]):J;if(!g){a("No agent selected or id given",e.yellow);return}if(g.status==="running"){a("Cannot delete \u2014 agent is running",e.yellow);return}if(!U){a("Agent deletion not available",e.yellow);return}Io("agent",g.id,g.name);}else if(p==="autonomous"||p==="auto"){let g=s[2]?Ne.find(w=>w.id===s[2]||w.name===s[2]):J;if(!g){a("No agent selected or id given",e.yellow);return}if(!vt){a("Autonomous toggle not available",e.yellow);return}g.autonomous?(a(`Disabling autonomous mode for "${g.name}"...`,e.amber),vt(g.id,false).then(()=>{a(`${lo} ${g.name} autonomous OFF`,e.cyan),Z();},w=>a(`Failed: ${u(w)}`,e.red))):(a(`Enabling autonomous mode for "${g.name}"...`,e.amber),vt(g.id,true).then(()=>{a(`${lo} ${g.name} autonomous ON`,e.cyan),Z();},w=>a(`Failed: ${u(w)}`,e.red)));}else p==="shop"?os():a("Usage: /agent add|list|disable|enable|delete|autonomous|shop",e.yellow);return}case "team":{let p=s[1]?.toLowerCase();if(p==="create"||p==="add")ns();else if(p==="list"){let g=wo.current;if(g.length===0)a("No teams",e.dim);else for(let w of g)a(` ${w.id} ${w.status.padEnd(8)} ${w.name} (${w.members.length} members)`,e.cyan);}else if(p==="join"){if(!ie){a("Join not available",e.yellow);return}let g=s[2],w=s[3]??J?.id;if(!g||!w){a("Usage: /team join <teamId> [agentId]",e.yellow);return}a(`Joining team ${g}...`,e.amber),ie(g,w).then(Y=>{a(`\u2713 Agent joined team "${Y.name}"`,e.green),Z({includeTeams:true});},Y=>a(`Failed: ${u(Y)}`,e.red));}else if(p==="leave"){if(!Re){a("Leave not available",e.yellow);return}let g=s[2],w=s[3]??J?.id;if(!g||!w){a("Usage: /team leave <teamId> [agentId]",e.yellow);return}a(`Leaving team ${g}...`,e.amber),Re(g,w).then(Y=>{a(`\u2713 Agent left team "${Y.name}"`,e.green),Z({includeTeams:true});},Y=>a(`Failed: ${u(Y)}`,e.red));}else if(p==="disband"){if(!Mt){a("Disband not available",e.yellow);return}let g=s[2];if(!g){a("Usage: /team disband <teamId>",e.yellow);return}a(`Disbanding team ${g}...`,e.amber),Mt(g).then(()=>{a("\u2713 Team disbanded",e.green),Z({includeTeams:true});},w=>a(`Failed: ${u(w)}`,e.red));}else if(p==="set-lead"){if(!it){a("Set-lead not available",e.yellow);return}let g=s[2],w=s[3];if(!g||!w){a("Usage: /team set-lead <teamId> <agentId>",e.yellow);return}a(`Setting lead for team ${g}...`,e.amber),it(g,w).then(Y=>{a(`\u2713 New lead for team "${Y.name}"`,e.green),Z({includeTeams:true});},Y=>a(`Failed: ${u(Y)}`,e.red));}else a("Usage: /team create|list|join|leave|disband|set-lead",e.yellow);return}case "goal":{let p=s[1]?.toLowerCase();if(p==="add"||p==="create"){let g=s.slice(2).join(" ").trim();if(!g){let w=Hn(L);Ke({title:"New Goal",steps:w,kind:"goal"}),Be("wizard");return}if(!Xe){a("Goal creation not available",e.yellow);return}a(`Creating goal "${g}"...`,e.amber),Xe({title:g}).then(w=>{a(`\u2713 Created goal "${w.title}" (${w.id})`,e.green),Z();},w=>a(`Failed: ${u(w)}`,e.red));}else if(p==="list"){let g=dt.map(w=>` ${w.id} ${w.status.padEnd(8)} ${w.title}`);if(g.length===0)a("No goals",e.dim);else for(let w of g)a(w,e.cyan);}else if(p==="show"){let g=s[2]?dt.find(w=>w.id===s[2]):te;if(!g){a("No goal selected or id given",e.yellow);return}a(`${g.id} ${g.status} "${g.title}"`,e.cyan),g.description&&a(` ${g.description.slice(0,100)}`,e.dim);}else if(p==="status"){let g=s[2]?dt.find(ao=>ao.id===s[2]):void 0,w=g??te;if(!w){a("No goal selected or id given",e.yellow);return}let Y=s[g?3:2];if(!Y||!a$1.includes(Y)){a("Usage: /goal status [id] <active|paused|achieved|abandoned>",e.yellow);return}let Et=Y;if(!qe){a("Status update not available",e.yellow);return}a(`Updating goal status to ${Et}...`,e.amber),qe(w.id,Et).then(ao=>{a(`\u2713 Goal "${ao.title}" \u2192 ${Et}`,e.green),Z();},ao=>a(`Failed: ${u(ao)}`,e.red));}else if(p==="delete"){let g=s[2]?dt.find(w=>w.id===s[2]):te;if(!g){a("No goal selected or id given",e.yellow);return}if(!Ze){a("Goal deletion not available",e.yellow);return}Io("goal",g.id,g.title);}else a("Usage: /goal add|list|show|status|delete",e.yellow);return}case "run":{let p=s[1]??H?.id;if(!p){a("No task selected or id given",e.yellow);return}if(!l){a("Run not available",e.yellow);return}let g=Ee.find(w=>w.id===p);if(g&&!Lr.has(g.status)){a(`Cannot run \u2014 status is ${g.status}`,e.yellow);return}a(`Running ${p}...`,e.amber),l(p).then(()=>{a(`\u2713 Dispatched ${p}`,e.green),Z();},w=>a(`Failed: ${u(w)}`,e.red));return}case "run-all":{if(!y){a("Run-all not available",e.yellow);return}a("Running all todo tasks...",e.amber),y().then(()=>{a("\u2713 Dispatched all todo tasks",e.green),Z();},p=>a(`Failed: ${u(p)}`,e.red));return}case "watch":{if(le){a("Watch mode already active",e.yellow);return}if(!at){a("Watch not available",e.yellow);return}a("Starting watch mode...",e.amber),at().then(()=>{ue(true),a("\u2713 Watch mode started",e.green);},p=>a(`Failed: ${u(p)}`,e.red));return}case "pause":{if(!le){a("Watch mode not active",e.yellow);return}if(!gt){a("Pause not available",e.yellow);return}a("Pausing watch mode...",e.amber),gt().then(()=>{ue(false),a("\u2713 Watch mode paused",e.green);},p=>a(`Failed: ${u(p)}`,e.red));return}case "config":{s[1]?.toLowerCase()==="activity-filter"?nr(g=>{let w=Pr(g);return ct?.(w.label),a(`Activity filter: ${w.label}`,e.amber),new Set(w.types)}):rs();return}case "status":{let p=R.filter(g=>g.status==="in_progress").length;a(`${mr} ${p} running ${R.length} tasks ${Ne.length} agents`,e.cyan);return}case "help":{for(let[p,g]of Object.entries(uo)){let w=g.sub?" "+g.sub.join("|"):g.args?" "+g.args:"";a(` /${p}${w} \u2014 ${g.help}`,e.silver);}return}case "quit":{No();return}case "disable":{if(!J){a("No agent selected",e.yellow);return}if(!S)return;a(`Disabling ${J.name}...`,e.amber),S(J.id).then(()=>{a(`\u2713 Disabled ${J.name}`,e.green),Z();},p=>a(`Failed: ${u(p)}`,e.red));return}case "enable":{if(!J){a("No agent selected",e.yellow);return}if(!C)return;a(`Enabling ${J.name}...`,e.amber),C(J.id).then(()=>{a(`\u2713 Enabled ${J.name}`,e.green),Z();},p=>a(`Failed: ${u(p)}`,e.red));return}default:a(`Unknown: ${d}. Type /help for commands`,e.yellow);}},[H,J,Ee,Ne,R,mr,le,b$1,T,h,y,l,f,S,C,E,B,$,D,ie,Re,Mt,it,at,gt,a,No,Z,Tn,bn,ns,rs]);useInput((i,x)=>{if(!(Rt&&(Qn(false),i==="?"||x.escape||i==="\x1BOP"))&&!ho){if((x.ctrl||x.meta)&&i==="s"&&Pe==="wizard"&&pt?.kind==="agent"){os();return}if(Pe!=="none"){if(x.escape){Be("none"),wt(""),mn.reset();return}if(x.return){let s=oo.trim();if(!s)return;if(Pe==="new_task"){if(!f)return;Be("none"),wt(""),a(`Creating "${s}"...`,e.amber),f(s).then(d=>{a(`\u2713 Created "${d.title}" (${d.id})`,e.green),Z();},d=>a(`Failed to create: ${d instanceof Error?d.message:String(d)}`,e.red));}else if(Pe==="command"){let d=s;if(kt.length>0&&kt[pn]){let u=kt[pn],p=u.cmd.replace(/\s+\[.*\]$/,"");if((p.startsWith(s)||s==="/")&&(d=p),u.subs&&!p.includes(" ")){wt(p+" "),Xt(0);return}}Be("none"),wt(""),Xt(0),mn.push(d),Sa(d);}return}if(x.tab&&Pe==="command"){if(kt.length>0){let s=kt[pn];if(s){let d=s.cmd.replace(/\s+\[.*\]$/,"");wt(d+(s.subs?" ":"")),Xt(0);}}else {let s=kr(oo);s&&wt(d=>d+s);}return}if(x.upArrow&&Pe==="command"){if(kt.length>0)Xt(s=>Math.max(0,s-1));else {let s=mn.prev();s!==null&&wt(s);}return}if(x.downArrow&&Pe==="command"){if(kt.length>0)Xt(s=>Math.min(kt.length-1,s+1));else {let s=mn.next();wt(s??"");}return}if(x.backspace||x.delete){wt(s=>s.slice(0,-1)),Xt(0);return}i&&!x.ctrl&&!x.meta&&(wt(s=>s+i),Xt(0));return}if(i.toLowerCase()==="q"){No();return}if(x.escape){if(_e){Wo(false),Uo(0);return}if(v==="logs"&&Vo>=0){or(-1),Ho(0);return}return}if((i==="+"||i==="=")&&v!=="logs"){fn?(cr(false),To(-Math.floor(St/2))):To(s=>Math.max(-Mo,s-3));return}if(i==="-"&&v!=="logs"){fn?(cr(false),To(Math.floor(St/2))):To(s=>Math.min(Mo,s+3));return}if(i==="M"&&v!=="logs"){cr(s=>!s);return}if(i==="?"){Qn(true);return}if(i==="\x1BOP"){Qn(true);return}if(i==="/"&&!_e){Be("command"),wt("/"),Xt(0);return}if((i==="a"||i==="A")&&v==="logs"&&!_e&&!ho&&!zo){er(true);return}if(i==="f"&&v==="logs"&&!_e&&!ho&&!zo){tr(true);return}if(i==="F"&&v==="logs"&&!_e&&!ho&&!zo){Vr(s=>new Set(Pr(s).types));return}if((i==="z"||i==="Z")&&yo.length>0){ia();return}if((i==="f"||i==="F")&&(v==="tasks"||v==="agents"||v==="goals")&&!_e){nr(s=>{let d=Pr(s);return ct?.(d.label),new Set(d.types)});return}if((i==="n"||i==="N")&&v==="tasks"&&!_e&&f){Tn();return}if((i==="n"||i==="N")&&v==="agents"&&!_e&&E){bn();return}if((i==="n"||i==="N")&&v==="goals"&&!_e&&Xe){let s=Hn(L);Ke({title:"New Goal",steps:s,kind:"goal"}),Be("wizard");return}if((i==="e"||i==="E")&&v==="goals"&&te&&$e){let s=Ai(te,L);Ke({title:`Edit Goal: ${te.title}`,steps:s,kind:"edit_goal",targetId:te.id}),Be("wizard");return}if((i==="d"||i==="D")&&v==="goals"&&te&&Ze){Io("goal",te.id,te.title);return}if((i==="c"||i==="C")&&v==="goals"&&te&&qe){(te.status==="active"||te.status==="paused")&&(a(`Marking goal "${te.title}" as achieved...`,e.amber),qe(te.id,"achieved").then(()=>{a(`\u2713 Goal "${te.title}" achieved`,e.green),Z();},s=>a(`Failed: ${s instanceof Error?s.message:String(s)}`,e.red)));return}if((i==="x"||i==="X")&&v==="goals"&&te&&qe){(te.status==="active"||te.status==="paused")&&(a(`Abandoning goal "${te.title}"...`,e.amber),qe(te.id,"abandoned").then(()=>{a(`\u2713 Goal "${te.title}" abandoned`,e.dim),Z();},s=>a(`Failed: ${s instanceof Error?s.message:String(s)}`,e.red)));return}if((i==="p"||i==="P")&&v==="goals"&&te&&qe){let s=te.status==="paused"?"active":"paused";(te.status==="active"||te.status==="paused")&&qe(te.id,s).then(()=>{a(`Goal "${te.title}" ${s}`,e.cyan),Z();},d=>a(`Failed: ${d instanceof Error?d.message:String(d)}`,e.red));return}if((i==="a"||i==="A")&&v==="tasks"&&H?.status==="review"&&B){a(`Approving "${H.title}"...`,e.amber),B(H.id).then(()=>{a(`\u2713 Approved "${H.title}"`,e.green),Z();},s=>a(`Failed: ${s instanceof Error?s.message:String(s)}`,e.red));return}if((i==="x"||i==="X")&&v==="tasks"&&H?.status==="review"&&$){a(`Rejecting "${H.title}"...`,e.amber),$(H.id).then(()=>{a(`\u2713 Rejected "${H.title}" \u2192 todo`,e.green),Z();},s=>a(`Failed: ${s instanceof Error?s.message:String(s)}`,e.red));return}if((i==="c"||i==="C")&&v==="tasks"&&H&&b$1){if(H.status==="done"||H.status==="failed"||H.status==="cancelled"){a(`Cannot cancel \u2014 status is ${H.status}`,e.yellow);return}a(`Cancelling "${H.title}"...`,e.amber),b$1(H.id).then(()=>{a(`\u2713 Cancelled "${H.title}"`,e.green),Z();},s=>a(`Failed: ${s instanceof Error?s.message:String(s)}`,e.red));return}if((i==="e"||i==="E")&&v==="tasks"&&H&&O){la(H);return}if((i==="e"||i==="E")&&v==="agents"&&J&&F){ca(J);return}if((i==="s"||i==="S")&&v==="tasks"){Zr(s=>!s),Fo(0),bo(0);return}if((i==="g"||i==="G")&&v==="tasks"&&!_e){Ji(s=>!s),Fo(0),bo(0);return}if((i==="s"||i==="S")&&v==="agents"&&J&&W){if(!Object.values(K.running).some(d=>d.agent_id===J.id)&&J.status!=="running"){a(`Agent "${J.name}" is not running`,e.yellow);return}a(`Force-stopping agent "${J.name}"...`,e.amber),W(J.id).then(()=>{a(`\u2713 Stopped agent "${J.name}"`,e.green),Z();},d=>a(`Failed: ${d instanceof Error?d.message:String(d)}`,e.red));return}if((i==="d"||i==="D")&&v==="tasks"&&H&&H.status!=="in_progress"&&D){Io("task",H.id,H.title);return}if((i==="d"||i==="D")&&v==="agents"&&J&&U){let s=Object.values(K.running).some(d=>d.agent_id===J.id);if(s&&!W){a(`Cannot delete \u2014 agent "${J.name}" is running. Press S to stop first.`,e.yellow);return}Io("agent",J.id,J.name,{needsForceStop:s});return}if((i==="u"||i==="U")&&v==="agents"&&J&&vt){let s=!J.autonomous;a(`${s?"Enabling":"Disabling"} autonomous mode for "${J.name}"...`,e.amber),vt(J.id,s).then(()=>{a(`${lo} ${J.name} autonomous ${s?"ON":"OFF"}`,e.cyan),Z();},d=>a(`Failed: ${d instanceof Error?d.message:String(d)}`,e.red));return}if(!_e){if(i==="g"||i==="G"){po("goals");return}if(i==="t"||i==="T"){po("tasks");return}if(i==="a"||i==="A"){po("agents");return}if(i==="l"||i==="L"){po("logs");return}}if(!_e){let s=vn.map(u=>u.id),d=s.indexOf(v);if(x.tab||x.rightArrow){po(s[(d+1)%s.length]);return}if(x.leftArrow){po(s[(d+s.length-1)%s.length]);return}}if(x.return){let s=ko>0?$t.length:-1;if(v==="tasks"&&ln===s){Zr(u=>!u),Fo(0),bo(0);return}let d=$t.length+(ko>0?1:0);if(v==="tasks"&&ln===d&&f){Tn();return}if(v==="goals"&&Jn===dt.length&&Xe){let u=Hn(L);Ke({title:"New Goal",steps:u,kind:"goal"}),Be("wizard");return}if(v==="agents"&&Zn===Ne.length&&E){bn();return}if(v==="goals"&&te){Wo(u=>!u),Uo(0);return}if(v==="tasks"&&H){Wo(u=>!u);return}if(v==="agents"&&J){Wo(u=>!u);return}if(v==="logs"&&Vo>=0){Wo(u=>!u);return}}if((i==="r"||i==="R")&&v==="tasks"&&H&&l){if(!Lr.has(H.status)){a(`Cannot run "${H.title}" \u2014 status is ${H.status}`,e.yellow);return}a(`Running "${H.title}"...`,e.green),l(H.id).then(()=>{a(`Dispatched "${H.title}"`,e.green),Z();},s=>a(`Failed to run: ${s instanceof Error?s.message:String(s)}`,e.red));return}if(x.upArrow||i==="k"){if(v==="goals"&&_e){Uo(s=>Math.max(0,s-1));return}v==="goals"?Fr(s=>{let d=Math.max(0,s-1);return ar(u=>d<u?d:u),d}):v==="tasks"?Fo(s=>{let d=Math.max(0,s-1);return bo(u=>d<u?d:u),d}):v==="agents"?Dr(s=>{let d=Math.max(0,s-1);return ir(u=>d<u?d:u),d}):v==="logs"&&or(s=>{if(s===-1){let u=Fe.length-1;return Ho(Math.max(0,u-we+2)),Math.max(0,u)}let d=Math.max(0,s-1);return Ho(u=>d<u?d:u),d});}if(x.downArrow||i==="j"){if(v==="goals"&&_e){Uo(s=>s+1);return}if(v==="goals"){let s=dt.length+(Xe?1:0)-1;Fr(d=>{let u=Math.min(Math.max(0,s),d+1);return ar(p=>u>=p+we?u-we+1:p),u});}else if(v==="tasks"){let s=$t.length+(f?1:0)+(ko>0?1:0)-1;Fo(d=>{let u=Math.min(Math.max(0,s),d+1);return bo(p=>u>=p+we?u-we+1:p),u});}else if(v==="agents"){let s=Ne.length+(E?1:0)-1;Dr(d=>{let u=Math.min(Math.max(0,s),d+1);return ir(p=>u>=p+we?u-we+1:p),u});}else v==="logs"&&or(s=>{if(s===-1)return -1;let d=Fe.length-1;if(s>=d)return Ho(0),-1;let u=s+1;return Ho(p=>u>=p+we-1?u-we+2:p),u});}}});let Qe=Pe!=="none",as=Vo>=0?Fe[Vo]:void 0,yn=fn?"+/- exit max":"+/- resize \u2502 M max",ls=!Qe&&_e&&v==="tasks"&&H,cs=!Qe&&_e&&v==="agents"&&J,ds=!Qe&&_e&&v==="goals"&&te,ka=!Qe&&_e&&v==="logs"&&as,fr=H?.id,Ca=useMemo(()=>fr?Fe.filter(i=>i.taskId===fr):[],[Fe,fr]),Ia=!Qe&&v==="tasks"&&H&&Lr.has(H.status)&&!!l,Ma=!Qe&&!_e&&(v==="goals"&&!!Xe||v==="tasks"&&!!f||v==="agents"&&!!E),va=!Qe&&v==="tasks"&&H?.status==="review"&&!!B,_a=!Qe&&v==="tasks"&&H?.status==="review"&&!!$,Aa=J?Object.values(K.running).some(i=>i.agent_id===J.id):false,Ra=!Qe&&(v==="goals"&&te&&!!Ze||v==="tasks"&&H&&H.status!=="in_progress"&&!!D||v==="agents"&&J&&!!U),$a=!Qe&&!_e&&(v==="goals"&&!!te&&!!$e||v==="tasks"&&!!H&&!!O||v==="agents"&&!!J&&!!F),Ba=!Qe&&v==="agents"&&J&&(Aa||J.status==="running")&&!!W,Ea=!Qe&&v==="agents"&&!!J&&!!vt,Oa=!Qe&&v==="goals"&&!!te&&(te.status==="active"||te.status==="paused")&&!!qe,La=!Qe&&yo.length>0,us=Pe==="command"&&kt.length>0,gs=pt?.kind==="task"||pt?.kind==="edit_task";return jsxs(Box,{flexDirection:"column",width:ft,height:G,children:[jsx(Ns,{projectName:t,activeView:v,mode:mr,stats:is,tokens:fa,uptime:ma,width:ft,version:Po,latestVersion:mt,taskBadge:ko>0?Ee.length:void 0,flashTab:sr?.tab,flashColor:sr?.color,onFlashComplete:sr?()=>Ur(void 0):void 0}),jsx(Box,{height:1}),Rt&&jsx(ii,{width:ft,height:G-7}),!Rt&&Ut==="welcome"&&v==="tasks"&&jsx(Ys,{width:ft,height:G}),!Rt&&v==="goals"&&jsx(gc,{goals:dt,selectedIndex:Jn,scrollOffset:ea,height:we,width:Me,showAddRow:!!Xe,agentNameMap:ro,tasksByGoalMap:oa}),!Rt&&Ut!=="welcome"&&v==="tasks"&&jsx(fc,{tasks:$t,selectedIndex:ln,scrollOffset:Zi,height:we,width:Me,showAddRow:!!f,agentNameMap:ro,hiddenCount:ko,goalMap:So,groupByGoal:jo}),!Rt&&v==="tasks"&&(Ut==="task_created"||Ut==="run_started")&&jsx(Zs,{step:Ut,width:ft}),!Rt&&v==="tasks"&&Ut==="completed"&&jsx(Js,{width:ft}),!Rt&&v==="agents"&&jsx(pc,{agents:Ne,selectedIndex:Zn,scrollOffset:Qi,height:we,width:Me,state:K,taskTitleMap:Xo,showAddRow:!!E,agentTeamMap:Co,teamLeadSet:ra,activeTeamCount:qo}),!Rt&&v==="logs"&&jsxs(Fragment,{children:[jsx(xc,{messages:Fe,height:ho||zo?Math.max(3,we-16):we,agents:Ne,logAgentFilter:Gr,logTypeFilter:zr,selectedIndex:Vo,scrollOffset:ji,agentNameMap:ro,agentColorMap:hn,agentMsgCounts:Qr,taskTitleMap:Xo,width:Me}),ho&&jsx(Box,{paddingX:2,children:jsx(js,{agents:Ne,selected:Gr,msgCounts:Qr,colorMap:hn,maxHeight:Math.min(we-4,18),onConfirm:i=>{Hi(i),er(false);},onCancel:()=>er(false)})}),zo&&jsx(Box,{paddingX:2,children:jsx(Ks,{selected:zr,typeCounts:na,onConfirm:i=>{Vr(i),tr(false);},onCancel:()=>tr(false)})})]}),jsx(Box,{height:1}),Rt?null:Pe==="wizard"&&pt?jsx(zs,{title:pt.title,steps:pt.steps,onComplete:da,onCancel:ua,width:Me,height:Bt,onPasteImage:gs?aa:void 0,onSuggestionSelected:pt.kind==="agent"?ga:void 0,footerExtra:no.length>0&&gs?`\u{1F4CE}${no.length}`:void 0},`${pt.kind}-${pt.title}`):us?jsxs(Fragment,{children:[jsx(jn,{label:"COMMANDS",width:Me}),jsx(uc,{suggestions:kt,selectedIndex:pn,height:Math.min(kt.length,Bt),width:Me})]}):Pe==="new_task"?jsxs(Fragment,{children:[jsx(Ic,{mode:Pe,width:Me}),jsx(Mc,{mode:Pe,value:oo,width:Me})]}):ls?jsxs(Fragment,{children:[jsx(yc,{task:H,width:Me,resizeHint:yn}),jsx(Es,{task:H,height:Bt,width:Me,taskLogs:Ca,agentNameMap:ro,taskTitleMap:Xo})]}):ds?jsxs(Fragment,{children:[jsx(jn,{label:`GOAL: ${te.title}`,width:Me,suffixLen:yn.length+2,suffix:jsxs(Text,{color:e.dim,children:[" ",yn," "]})}),jsx(mc,{goal:te,height:Bt,width:Me,agentNameMap:ro,tasks:sa,progressReport:Do,scrollOffset:ta,onClampScroll:Uo})]}):cs?jsxs(Fragment,{children:[jsx(wc,{agent:J,width:Me,resizeHint:yn}),jsx(Sc,{agent:J,height:Bt,state:K,taskTitleMap:Xo,teamName:Co.get(J.id)})]}):ka?jsxs(Fragment,{children:[jsx(jn,{label:"LOG",width:Me}),jsx(Tc,{message:as,height:Bt,width:Me,agents:Ne,agentNameMap:ro,agentColorMap:hn,taskTitleMap:Xo})]}):Fe.length>0&&v!=="logs"?jsxs(Fragment,{children:[(()=>{let i=` F:${cn.toUpperCase()} \u2502 ${rr.length}/${Fe.length}`;return jsx(jn,{label:"ACTIVITY",width:Me,suffixLen:i.length,suffix:jsxs(Fragment,{children:[jsx(Text,{color:e.dim,children:" F:"}),jsx(Text,{color:e.amber,children:cn.toUpperCase()}),jsxs(Text,{color:e.ghost,children:[" ","\u2502"," ",rr.length,"/",Fe.length]})]})})})(),jsx(bc,{messages:rr,height:Math.max(1,Bt-1),width:Me,agents:Ne,agentNameMap:ro,agentColorMap:hn})]}):v==="goals"?jsx(Fn,{count:dt.length,config:ic,width:Me}):v==="tasks"?jsx(Fn,{count:Ee.length,config:ac,width:Me}):v==="agents"?jsx(Fn,{count:Ne.length,config:lc,width:Me}):null,jsx(Box,{flexGrow:1}),jsx(si,{toasts:qi,onDismiss:Yi}),yo.length>0&&jsx(dc,{deletions:yo,width:ft}),jsx(Fs,{mode:Pe==="command"?"command":"navigate",value:Pe==="command"?oo:"",completion:Pe==="command"?kr(oo):null,activeView:v,canRun:!!Ia,canNew:!!Ma,canApprove:!!va,canReject:!!_a,canCancel:v==="tasks"&&!!H&&H.status==="in_progress"&&!!b$1,canDelete:!!Ra,canUndo:!!La,canEdit:!!$a,canForceStop:!!Ba,canToggleAuto:!!Ea,autoActive:J?.autonomous,canPause:!!Oa,isPaused:te?.status==="paused",canToggleShowAll:v==="tasks"&&Ee.length>$i,showAllActive:Yr,hasDetail:!!(ls||cs||ds),itemCount:v==="goals"?dt.length:v==="tasks"?Ee.length:v==="agents"?L.length:Fe.length,itemLabel:v==="goals"?"goals":v==="tasks"?"tasks":v==="agents"?"agents":"events",width:ft,hasSuggestions:us,onboardingCompleted:r.onboardingCompleted})]})}var dc=tn.memo(function({deletions:o,width:n}){let[,r]=useState(0);useEffect(()=>{let f=setInterval(()=>r(b=>b+1),1e3);return ()=>clearInterval(f)},[]);let l=Date.now();return jsx(Box,{flexDirection:"column",width:n,children:o.map(f=>{let b=Math.max(0,Math.ceil((f.expiresAt-l)/1e3)),T=Math.max(0,n-4),h=f.entityType==="task"?"Task":f.entityType==="agent"?"Agent":"Goal",y=Math.max(10,T-h.length-30),S=f.entityName.length>y?f.entityName.slice(0,y-1)+"\u2026":f.entityName;return jsx(Box,{paddingX:2,children:jsxs(Text,{color:e.yellow,children:["\u2717 ",jsx(Text,{bold:true,children:h}),` "${S}" \u2014 `,jsxs(Text,{color:e.amber,bold:true,children:[b,"s"]}),jsx(Text,{color:e.dim,children:" \u2502 "}),jsx(Text,{color:e.gray,bold:true,children:"Z"}),jsx(Text,{color:e.dim,children:" undo"})]})},f.key)})})});function uc({suggestions:t,selectedIndex:o,height:n,width:r}){let l=n,f=0;o>=l&&(f=o-l+1);let b=t.slice(f,f+l);return jsx(Box,{flexDirection:"column",paddingX:2,children:b.map((T,h)=>{let y=h+f,S=y===o,C=S?"\u25B6":" ",_=Math.min(20,Math.max(14,...t.map(E=>E.cmd.length+1))),k=T.cmd.padEnd(_),j=T.subs?` ${T.subs}`:"",V=Math.max(4,r-_-j.length-8),z=T.desc.length>V?T.desc.slice(0,V-1)+"\u2026":T.desc;return jsxs(Text,{wrap:"truncate",children:[jsx(Text,{color:S?e.amber:e.ghost,children:` ${C} `}),jsx(Text,{color:S?e.white:e.silver,bold:S,children:k}),jsx(Text,{color:e.dim,children:z}),j&&jsx(Text,{color:e.ghost,children:j})]},y)})})}function gc({goals:t,selectedIndex:o,scrollOffset:n=0,height:r,width:l,showAddRow:f,agentNameMap:b,tasksByGoalMap:T}){let h=t.length,y=t.slice(n,n+r),S=f&&h>=n&&h<n+r;return jsxs(Box,{flexDirection:"column",height:r,children:[y.map((C,_)=>jsx(Box,{paddingX:2,children:jsx(Bs,{goal:C,selected:_+n===o,width:l-2,agentNameMap:b,tasksByGoal:T?.get(C.id)})},C.id)),S&&jsx(Box,{paddingX:2,children:jsxs(Text,{color:o===h?e.amber:e.ghost,children:[o===h?" \u25B8 ":" ",jsx(Text,{color:o===h?e.amber:e.dim,children:"+ add goal..."})]})},"__add__")]})}function mc({goal:t,height:o,width:n,agentNameMap:r,tasks:l,progressReport:f,scrollOffset:b=0,onClampScroll:T}){let y=tn.useMemo(()=>{let V=l??[],z=t.assignee?r?.get(t.assignee)??t.assignee:"\u2014",E=Math.max(20,n-6),U=(W,X)=>{if(W.length<=X)return [W];let A=[];for(let ie=0;ie<W.length;ie+=X)A.push(W.slice(ie,ie+X));return A},B=Tr(f)?.split(`
12
+ `).flatMap(W=>U(W,E))??[],$=Tr(t.description)?.split(`
13
+ `).flatMap(W=>U(W,E))??[],D=xs[t.status]??e.dim,O=new Map;for(let W of V)O.set(W.status,(O.get(W.status)??0)+1);let F=[];if(F.push({key:"row-status",node:jsxs(Box,{children:[jsxs(Box,{width:24,children:[jsx(Text,{color:e.dim,children:" status "}),jsx(Text,{color:D,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:z})]})]})}),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&&F.push({key:"row-updated",node:jsxs(Box,{children:[jsx(Box,{width:24,children:jsxs(Text,{color:e.dim,children:[" "," "]})}),jsxs(Box,{children:[jsx(Text,{color:e.dim,children:" Updated "}),jsx(Text,{children:t.updated_at.slice(0,10)})]})]})}),V.length>0){let W=[];for(let[X,A]of O)W.push(`${A} ${X}`);F.push({key:"row-tasks-summary",node:jsxs(Box,{children:[jsxs(Box,{width:24,children:[jsx(Text,{color:e.dim,children:" tasks "}),jsx(Text,{color:e.cyan,children:V.length})]}),jsxs(Box,{children:[jsx(Text,{color:e.dim,children:" "}),jsx(Text,{color:e.dim,children:W.join(" \xB7 ")})]})]})});}if($.length>0){F.push({key:"desc-gap",node:jsx(Text,{children:" "})});for(let W=0;W<$.length;W++)F.push({key:`desc-${W}`,node:jsxs(Text,{color:e.silver,wrap:"truncate",children:[" ",$[W]]})});}else F.push({key:"desc-gap",node:jsx(Text,{children:" "})}),F.push({key:"desc-empty",node:jsx(Text,{color:e.dim,children:" No description."})});if(B.length>0){F.push({key:"prog-gap",node:jsx(Text,{children:" "})}),F.push({key:"prog-div",node:jsx(Bo,{label:"progress",width:n})});for(let W=0;W<B.length;W++)F.push({key:`prog-${W}`,node:jsxs(Text,{color:e.white,wrap:"truncate",children:[" ",B[W]]})});}if(V.length>0){F.push({key:"tasks-gap",node:jsx(Text,{children:" "})}),F.push({key:"tasks-div",node:jsx(Bo,{label:`tasks (${V.length})`,width:n})});for(let W of V){let X=Cn[W.status]??e.dim;F.push({key:`task-${W.id}`,node:jsxs(Text,{color:e.silver,wrap:"truncate",children:[" ",jsx(Text,{color:X,children:W.status.padEnd(12)}),W.title.slice(0,Math.max(10,n-22))]})});}}return F},[t,l,f,n,r]),S=Math.max(0,y.length-o),C=Math.min(b,S);tn.useEffect(()=>{T&&C!==b&&T(C);},[C,b,T]);let _=y.length>o&&C<S,k=_?o-1:o,j=y.slice(C,C+k);return jsxs(Box,{flexDirection:"column",height:o,paddingX:2,children:[j.map(V=>jsx(Box,{children:V.node},V.key)),_&&jsxs(Text,{color:e.ghost,children:[" ","\u2193"," ",y.length-C-k," more ","\u2014"," ","\u2191","\u2193"," to scroll"]})]})}function fc({tasks:t,selectedIndex:o,scrollOffset:n=0,height:r,width:l,showAddRow:f,agentNameMap:b,hiddenCount:T=0,goalMap:h,groupByGoal:y=false}){let S=T>0,C=S?t.length:-1,_=t.length+(S?1:0),k=t.slice(n,n+r),j=S&&C>=n&&C<n+r,V=f&&_>=n&&_<n+r,z=useMemo(()=>{if(!y||!h||h.size===0)return null;let D=new Map;for(let O of t)if(O.goalId&&h.has(O.goalId)){let F=D.get(O.goalId)??{total:0,done:0};F.total++,O.status==="done"&&F.done++,D.set(O.goalId,F);}return D},[t,y,h]),E=y&&h?t.filter(D=>!D.goalId||!h.has(D.goalId)).length:0,U=y&&h&&h.size>0&&z&&z.size>0,B=[],$=n>0?t[n-1]?.goalId??null:void 0;for(let D=0;D<k.length&&B.length<r;D++){let O=k[D],F=O.goalId&&h?.has(O.goalId)?O.goalId:null;if(U){if(F&&F!==$){let W=h.get(F),X=z.get(F)??{total:0,done:0};if(B.push(jsx(ks,{goalTitle:W.title,taskCount:X.total,doneCount:X.done,width:l},`gh_${F}`)),B.length>=r)break}if(!F&&$!==null&&$!==void 0&&(B.push(jsx(Cs,{taskCount:E,width:l},"__ungrouped__")),B.length>=r))break}$=F,B.push(jsx(Box,{paddingX:2,children:jsx(Mn,{task:O,selected:D+n===o,width:l-2,agentNameMap:b,goalMap:h})},O.id));}return j&&B.length<r&&B.push(jsx(Box,{paddingX:2,children:jsxs(Text,{color:o===C?e.amber:e.ghost,children:[o===C?" \u25B8 ":" ",jsxs(Text,{color:o===C?e.amber:e.dim,children:["\u25BC"," Show all (",T," more) \u2014 press ",jsx(Text,{bold:true,color:e.gray,children:"S"})]})]})},"__show_all__")),V&&B.length<r&&B.push(jsx(Box,{paddingX:2,children:jsxs(Text,{color:o===_?e.amber:e.ghost,children:[o===_?" \u25B8 ":" ",jsx(Text,{color:o===_?e.amber:e.dim,children:"+ add task..."})]})},"__add__")),jsx(Box,{flexDirection:"column",height:r,children:B})}function pc({agents:t,selectedIndex:o,scrollOffset:n=0,height:r,width:l,state:f,taskTitleMap:b,showAddRow:T,agentTeamMap:h,teamLeadSet:y,activeTeamCount:S}){let C=new Map;for(let O of Object.values(f.running))C.set(O.agent_id,O);let _=new Map;if(S&&S>0)for(let O of t){let F=h?.get(O.id);F&&_.set(F,(_.get(F)??0)+1);}let k=t.length,j=t.slice(n,n+r),V=T&&k>=n&&k<n+r,z=S!=null&&S>0,E=new Map;if(z&&y&&h){for(let O of t)if(y.has(O.id)){let F=h.get(O.id);F&&E.set(F,O.name);}}let U=0;for(let O of _.values())U+=O;let B=t.length-U,$=[],D=n>0?h?.get(t[n-1]?.id??""):void 0;for(let O=0;O<j.length&&$.length<r;O++){let F=j[O],W=h?.get(F.id);if(z&&W&&W!==D&&($.push(jsx(_s,{teamName:W,memberCount:_.get(W)??0,leadName:E.get(W),width:l},`ts-${W}`)),$.length>=r)||z&&!W&&D&&($.push(jsx(As,{memberCount:B,width:l},"ts-unassigned")),$.length>=r))break;D=W,$.push(jsx(Box,{paddingX:2,children:jsx(vs,{agent:F,selected:O+n===o,width:l-2,runningEntry:C.get(F.id),currentTaskTitle:F.current_task?b.get(F.current_task):void 0,teamName:W,isLead:y?.has(F.id)})},F.id));}return V&&$.length<r&&$.push(jsx(Box,{paddingX:2,children:jsxs(Text,{color:o===k?e.amber:e.ghost,children:[o===k?" \u25B8 ":" ",jsx(Text,{color:o===k?e.amber:e.dim,children:"+ add agent..."})]})},"__add__")),jsx(Box,{flexDirection:"column",height:r,children:$})}function Fi(t=5e3){let[o,n]=useState(Date.now());return useEffect(()=>{let r=setInterval(()=>n(Date.now()),t);return ()=>clearInterval(r)},[t]),o}function Wi(t,o){let n=Math.max(0,o-t);return n<3e3?"now":n<6e4?`${Math.floor(n/1e3)}s`:n<36e5?`${Math.floor(n/6e4)}m`:`${Math.floor(n/36e5)}h`}function hc(t){if(t==="error")return e.errorBg}function Gi(t,o){switch(t){case "output":return e.white;case "tool":return e.dim;case "result":return e.dim;case "file":return e.gray;case "error":return e.red;case "lifecycle":return e.dim;case "system":return e.dim;default:return o}}function xc({messages:t,height:o,agents:n,logAgentFilter:r,logTypeFilter:l,selectedIndex:f,scrollOffset:b,agentNameMap:T,agentColorMap:h,agentMsgCounts:y,taskTitleMap:S,width:C}){let _=Fi(),k=useMemo(()=>t.filter(X=>{if(r.size>0&&X.agentId&&!r.has(X.agentId))return false;let A=X.msgType??"info";return l.has(A)}),[t,r,l]);useMemo(()=>{let X={};for(let A of t){let ie=A.msgType??"info";X[ie]=(X[ie]??0)+1;}return X},[t]);let V=l.size>=8?"all":l.size===1&&l.has("output")?"text":l.size===1&&l.has("error")?"errors":l.has("tool")&&!l.has("output")?"tools":l.has("lifecycle")&&!l.has("output")?"events":`${l.size} types`,z=r.size>0,E=o-2,U=f===-1?k.slice(-E):k.slice(b,b+E),B=f===-1?-1:f-b,$=Math.min(10,Math.max(6,...n.map(X=>X.name.length))),D=11+$,O=X=>{if(X===0)return true;let A=U[X],ie=U[X-1];return A.agentId!==ie.agentId?true:A.agentId?A.ts-ie.ts>3e4:false},F=Math.max(4,Math.floor((C-20)/Math.max(1,n.length))-1),W=Math.min(F,10);return jsxs(Box,{flexDirection:"column",paddingX:1,children:[jsxs(Box,{gap:0,justifyContent:"space-between",width:C,children:[jsxs(Box,{gap:0,children:[f===-1?jsxs(Box,{gap:0,children:[jsx(Text,{backgroundColor:e.successBg,color:e.green,children:" "}),jsx(Text,{backgroundColor:e.successBg,color:e.green,children:jsx(_o,{color:e.green})}),jsx(Text,{backgroundColor:e.successBg,color:e.green,children:" LIVE "})]}):jsxs(Text,{backgroundColor:e.warnBg,color:e.amber,children:[" \u2191\u2193 ",f+1,"/",k.length," "]}),jsxs(Text,{color:e.dim,children:[" ",k.length," events"]}),V!=="all"&&jsxs(Text,{color:e.amber,children:[" f:",V]}),z&&jsxs(Text,{color:e.cyan,children:[" ",r.size,"/",n.length," agents"]})]}),jsxs(Box,{gap:0,children:[jsx(Text,{color:e.amber,bold:true,children:"a"}),jsx(Text,{color:e.dim,children:" filter "}),jsx(Text,{color:e.amber,bold:true,children:"f"}),jsx(Text,{color:e.dim,children:" type "}),jsx(Text,{color:e.amber,bold:true,children:"F"}),jsx(Text,{color:e.dim,children:" cycle"})]})]}),jsx(Box,{gap:0,children:n.map(X=>{let A=h.get(X.id)??Nr[0],ie=r.size===0||r.has(X.id),Re=X.name.length>W?X.name.slice(0,W-1)+"\u2026":X.name;return jsxs(Text,{color:ie?A:e.ghost,bold:ie,children:[" ",Re]},X.id)})}),U.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"})]})]}):U.map((X,A)=>{let ie=A===B,Re=X.msgType??"info",Mt=Yn[Re]??"\u2502",it=X.agentId?T.get(X.agentId)??X.agentId.slice(0,8):void 0,at=X.agentId?h.get(X.agentId):void 0,gt=O(A),lt=(A>0?U[A-1]:void 0)?.agentId===X.agentId&&!!X.agentId,Xe=!lt&&!!it,$e=lt&&!!it,qe=Gi(Re,X.color),Ze=ie?e.infoBg:Re==="error"?e.errorBg:void 0,Dt=X.taskId?S.get(X.taskId):void 0,Je=Wi(X.ts,_),Le=Dt&&C>80?`#${Dt.slice(0,20)}`:"",Ve=Le?Le.length+3:0,Qt=Math.max(10,C-2-D-Ve),mo=et(X.text,Qt);return jsxs(Box,{backgroundColor:Ze,children:[jsx(Text,{color:at??e.ghost,children:gt&&Xe?"\u250C":$e?"\u2502":" "}),jsx(Text,{color:ie?e.amber:void 0,children:ie?"\u25B8":" "}),jsx(Box,{width:5,children:jsx(Text,{color:Je==="now"?e.green:ie?e.silver:e.ghost,children:Je.padStart(4)})}),jsx(Box,{width:$+1,children:Xe?jsxs(Text,{color:at,bold:true,children:[" ",it.slice(0,$).padEnd($)]}):$e?jsxs(Text,{color:at??e.ghost,children:[" ","\xB7".padEnd($)]}):jsxs(Text,{color:e.ghost,children:[" "," ".padEnd($)]})}),jsxs(Text,{color:Re==="error"?e.red:at??e.dim,children:[" ",Mt," "]}),jsx(Text,{color:ie?e.white:qe,bold:ie||Re==="lifecycle",children:mo}),Le&&jsxs(Text,{color:e.ghost,children:[" ",jsx(Text,{color:e.dim,backgroundColor:e.void,children:` ${Le} `})]})]},A)})]})}function bc({messages:t,height:o,width:n,agents:r,agentNameMap:l,agentColorMap:f}){let b=Fi(),T=t.slice(-o),h=Math.max(10,n-2-17),y=Math.max(0,o-T.length),S=0,C=[];for(let _=0;_<T.length;_++)_>0&&T[_].agentId!==T[_-1].agentId&&S++,C.push(S);return jsxs(Box,{flexDirection:"column",paddingX:1,children:[y>0&&jsx(Box,{height:y}),T.map((_,k)=>{let j=_.agentId?l.get(_.agentId)??_.agentId.slice(0,8):void 0,V=_.agentId?f.get(_.agentId):void 0,z=_.msgType??"info",E=Yn[z]??"\u2502",U=Gi(z,_.color),$=(k>0?T[k-1]:void 0)?.agentId===_.agentId&&!!_.agentId,D=(C[k]&1)===1,O=hc(z)??(D?"#1a1a1a":void 0),F=Wi(_.ts,b),W=et(_.text,h);return jsxs(Box,{backgroundColor:O,children:[jsx(Text,{color:V??e.ghost,children:!$&&j?"\u258D":$?"\u258F":" "}),jsx(Box,{width:5,children:jsx(Text,{color:$?e.ghost:F==="now"?e.green:e.dim,children:$?" ":F.padStart(4)})}),jsx(Box,{width:9,children:j&&!$?jsxs(Text,{color:V,bold:true,children:[" ",j.slice(0,8)]}):jsx(Text,{color:e.ghost,children:cc})}),jsxs(Text,{color:z==="error"?e.red:$?e.ghost:V??e.dim,children:[E," "]}),jsx(Text,{color:U,children:W})]},k)})]})}function Tc({message:t,height:o,width:n,agents:r,agentNameMap:l,agentColorMap:f,taskTitleMap:b}){let T=t.detail??t.text,h=t.msgType??"info",y=t.agentId?l.get(t.agentId)??t.agentId.slice(0,8):void 0,S=t.agentId?f.get(t.agentId):e.dim,C=t.taskId?b.get(t.taskId):void 0,_,k=false;try{let E=JSON.parse(T);_=JSON.stringify(E,null,2),k=!0;}catch{_=T;}let j=Math.max(4,n-6),V=Math.max(1,o-4),z=_.split(`
14
+ `).slice(0,V);return jsxs(Box,{flexDirection:"column",paddingX:1,children:[jsx(Box,{children:jsxs(Text,{color:e.ghost,children:["\u256D",be(j+2),"\u256E"]})}),jsxs(Box,{children:[jsx(Text,{color:e.ghost,children:"\u2502 "}),jsx(Text,{color:e.dim,children:t.time}),jsx(Text,{color:e.ghost,children:" \u2502 "}),y&&jsx(Text,{color:S,bold:true,children:y}),y&&jsx(Text,{color:e.ghost,children:" \u2502 "}),jsxs(Text,{color:Yn[h]?h==="error"?e.red:e.dim:e.dim,children:[Yn[h]??"\u2502"," ",h]}),C&&jsxs(Fragment,{children:[jsx(Text,{color:e.ghost,children:" \u2502 "}),jsxs(Text,{color:e.dim,children:["#",C.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,j)})]}),jsx(Box,{children:jsxs(Text,{color:e.ghost,children:["\u251C",be(j+2),"\u2524"]})}),z.map((E,U)=>jsxs(Box,{children:[jsx(Text,{color:e.ghost,children:"\u2502 "}),k&&jsxs(Text,{color:e.ghost,children:[String(U+1).padStart(3)," "]}),jsx(Text,{wrap:"truncate",color:k&&E.includes('"')?e.cyan:k&&/^\s*[}\]]/.test(E)?e.ghost:E.startsWith("error")||E.startsWith("Error")?e.red:e.silver,children:E.slice(0,k?j-4:j)})]},U)),jsx(Box,{children:jsxs(Text,{color:e.ghost,children:["\u2570",be(j+2),"\u256F"]})})]})}function jn({label:t,width:o,suffix:n,suffixLen:r=0}){let l=` ${t} `,f=3,b=f+l.length+2;if(!n){let y=Math.max(0,o-b);return jsxs(Box,{paddingX:1,children:[jsx(Text,{color:e.ghost,children:Ge(f)}),jsx(Text,{backgroundColor:"#1a1a22",color:e.dim,bold:true,children:l}),jsx(Text,{color:e.ghost,children:Ge(y)})]})}let T=2,h=Math.max(0,o-b-T-r);return jsxs(Box,{paddingX:1,children:[jsx(Text,{color:e.ghost,children:Ge(f)}),jsx(Text,{backgroundColor:"#1a1a22",color:e.dim,bold:true,children:l}),jsx(Text,{color:e.ghost,children:Ge(T)}),n,jsx(Text,{color:e.ghost,children:Ge(h)})]})}function yc({task:t,width:o,resizeHint:n}){let r=" DETAIL ",l=n?` ${n} `:"",f=o-r.length-l.length-10,b=t.title.length>f?t.title.slice(0,f-3)+"...":t.title,T=Math.max(0,o-3-r.length-b.length-l.length-4);return jsxs(Box,{paddingX:1,children:[jsx(Text,{color:e.ghost,children:Ge(3)}),jsx(Text,{backgroundColor:"#2d1f0a",color:e.amber,bold:true,children:r}),jsxs(Text,{color:e.ghost,children:[kn," "]}),jsx(Text,{color:e.white,bold:true,children:b}),jsxs(Text,{color:e.ghost,children:[" ",Ge(Math.max(0,T))]}),l?jsx(Text,{color:e.dim,children:l}):null]})}function wc({agent:t,width:o,resizeHint:n}){let r=" AGENT ",l=n?` ${n} `:"",f=o-r.length-l.length-10,b=t.name.length>f?t.name.slice(0,f-3)+"...":t.name,T=Math.max(0,o-3-r.length-b.length-l.length-4);return jsxs(Box,{paddingX:1,children:[jsx(Text,{color:e.ghost,children:Ge(3)}),jsx(Text,{backgroundColor:"#0f2d1f",color:e.green,bold:true,children:r}),jsxs(Text,{color:e.ghost,children:[kn," "]}),jsx(Text,{color:e.green,bold:true,children:b}),jsxs(Text,{color:e.ghost,children:[" ",Ge(Math.max(0,T))]}),l?jsx(Text,{color:e.dim,children:l}):null]})}function Sc({agent:t,height:o,state:n,taskTitleMap:r,teamName:l}){let f=kc[t.status]??e.dim;Object.values(n.running).find(y=>y.agent_id===t.id);let T=t.current_task?r.get(t.current_task):void 0,h=24;return jsxs(Box,{flexDirection:"column",paddingX:2,children:[jsxs(Box,{children:[jsxs(Box,{width:h,children:[jsx(Text,{color:e.dim,children:" status "}),jsx(Text,{color:f,children:t.status})]}),jsxs(Box,{children:[jsx(Text,{color:e.dim,children:" adapter "}),jsx(Text,{color:e.cyan,children:t.adapter})]})]}),jsxs(Box,{children:[jsxs(Box,{width:h,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:h,children:[jsx(Text,{color:e.dim,children:" runs "}),jsx(Text,{children:t.stats.total_runs}),jsx(Text,{color:e.dim,children:" ("}),jsx(Text,{color:e.green,children:t.stats.tasks_completed}),jsx(Text,{color:e.dim,children:"/"}),jsx(Text,{color:t.stats.tasks_failed>0?e.red:e.dim,children:t.stats.tasks_failed}),jsx(Text,{color:e.dim,children:")"})]}),jsxs(Box,{children:[jsx(Text,{color:e.dim,children:" team "}),jsx(Text,{color:l?e.amber:e.dim,children:l??"\u2014"})]})]}),t.autonomous&&jsx(Box,{children:jsxs(Box,{width:h,children:[jsx(Text,{color:e.dim,children:" auto "}),jsxs(Text,{color:e.cyan,children:[lo," ON"]})]})}),t.config.skills&&t.config.skills.length>0&&jsxs(Box,{children:[jsx(Text,{color:e.dim,children:" skills "}),jsx(Text,{color:e.cyan,wrap:"truncate",children:et(t.config.skills.join(", "),500)})]}),t.last_error&&(()=>{let y=t.last_error.kind,S=m[y],C=!S||y==="unknown",_=t.last_error.timestamp,k=_?g(_)+" ago":"";return jsxs(Fragment,{children:[jsx(Text,{children:" "}),jsxs(Box,{flexDirection:"column",borderStyle:"single",borderColor:e.red,paddingX:1,children:[jsxs(Text,{color:e.red,bold:true,children:["\u26A0"," \u041E\u0448\u0438\u0431\u043A\u0430"]}),S&&jsx(Text,{color:e.white,children:S.message}),S&&jsx(Text,{color:e.cyan,children:S.fix}),S?.doctorHint&&jsx(Text,{color:e.yellow,children:"\u0414\u0438\u0430\u0433\u043D\u043E\u0441\u0442\u0438\u043A\u0430: orch doctor"}),C&&t.last_error.message&&jsx(Text,{color:e.dim,children:et(t.last_error.message,120)}),k&&jsx(Text,{color:e.dim,children:k})]})]})})(),jsx(Text,{children:" "}),t.role?t.role.split(`
15
+ `).slice(0,Math.max(1,o-(t.last_error?10:4))).map((y,S)=>jsxs(Text,{color:e.silver,wrap:"truncate",children:[" ",et(y,500)]},S)):jsx(Text,{color:e.dim,children:" No role description."})]})}var kc={idle:e.dim,running:e.green,error:e.red,disabled:e.ghost},Cc="\u2588";function Ic({mode:t,width:o}){let r=` ${t==="command"?"COMMAND":"NEW TASK"} `,l=Math.max(0,o-3-r.length-2);return jsxs(Box,{paddingX:1,children:[jsx(Text,{color:e.ghost,children:Ge(3)}),jsx(Text,{backgroundColor:"#2d1f0a",color:e.amber,bold:true,children:r}),jsx(Text,{color:e.ghost,children:Ge(l)})]})}function Mc({mode:t,value:o,width:n}){let r=t==="command"?"/":"\u25B8",l=Math.max(10,n-8),f=o.length>l?o.slice(-l):o;return jsxs(Box,{paddingX:2,children:[jsxs(Text,{color:e.amber,children:[r," "]}),jsx(Text,{color:e.white,children:f}),jsx(Text,{color:e.amber,children:Cc})]})}function zi(t,o){if(!o||typeof o!="object")return "";let n=o;if(n.file_path&&typeof n.file_path=="string")return n.file_path.split("/").slice(-2).join("/");if(n.command&&typeof n.command=="string")return n.command.slice(0,60);if(n.pattern&&typeof n.pattern=="string")return `"${n.pattern.slice(0,40)}"`;if(n.glob&&typeof n.glob=="string")return n.glob.slice(0,40);let r=JSON.stringify(n);return r.length>80?r.slice(0,77)+"...":r}function Un(t,o=200){if(typeof t=="string")return t.slice(0,o);if(!Array.isArray(t))return null;let n=[],r=0;for(let l of t){if(r>=o)break;if(l?.type==="text"&&typeof l.text=="string"){let f=l.text.split(`
16
+ `).find(b=>b.trim().length>0)??"";n.push(f.slice(0,o-r)),r+=f.length;}else if(l?.type==="tool_use"){let f=zi(l.name??"tool",l.input),b=`\u2699 ${l.name??"tool"}(${f})`;n.push(b),r+=b.length;}else if(l?.type==="tool_result")n.push("\u2190 (result)"),r+=10;else if(l?.type==="thinking"&&typeof l.thinking=="string"){let f=l.thinking.slice(0,60).split(`
17
+ `)[0]??"";n.push(`\u{1F4AD} ${f}`),r+=f.length+3;}}return n.length>0?n.join(" "):null}function Li(t){if(typeof t=="string"){let n=t.split(`
18
+ `).length,r=t.split(`
19
+ `).find(l=>l.trim().length>0)??"";return n>3?`${r.slice(0,80)}... (${n} lines)`:r.slice(0,120)}if(!Array.isArray(t))return "(result)";let o=[];for(let n of t)if(n?.type==="tool_result"){n.tool_use_id?n.tool_use_id.slice(0,8):"";let l=n.is_error,f=typeof n.content=="string"?n.content:"",b=f.split(`
20
+ `).length;l?o.push(`\u2715 error: ${f.slice(0,60)}`):b>3?o.push(`\u2713 ${b} lines`):o.push(`\u2713 ${f.slice(0,80)}`);}else n?.type==="text"&&typeof n.text=="string"&&o.push(n.text.split(`
21
+ `)[0]?.slice(0,80)??"");return o.join(" ")||"(result)"}function Vi(t){let o=()=>t.length>Kn?t.slice(0,Kn)+"\u2026":t;if(Ni.test(t.trim()))return {summary:t.trim(),detail:o()};try{let n=JSON.parse(t);if(n.type==="message"&&n.role==="assistant"){let r=Un(n.content);return r?{summary:r.slice(0,200),detail:o()}:{summary:null,detail:""}}if(n.type==="assistant"||n.role==="assistant"){let r=n.message?.content??n.content,l=Un(r);return l?{summary:l.slice(0,200),detail:o()}:{summary:null,detail:""}}if(n.type==="user"||n.role==="user"){let r=n.message?.content??n.content;return {summary:`\u2190 ${Li(r).slice(0,180)}`,detail:o()}}if(n.type==="tool_use"||typeof n.name=="string"&&"input"in n){let r=n.name??"tool",l=zi(r,n.input);return {summary:`\u2699 ${r}(${l})`,detail:o()}}if(n.type==="tool_result")return {summary:`\u2190 ${Li(n.content).slice(0,180)}`,detail:o()};if(n.type==="result"){let r=typeof n.result=="string"?n.result:null;return {summary:r?`\u2713 ${r.slice(0,180)}`:"\u2713 Agent finished",detail:o()}}if(n.type==="rate_limit_event")return {summary:`\u23F3 Rate limited (${n.rate_limit_info?.rateLimitType??"unknown"})`,detail:o()};if(n.subtype){if(n.message){let r=n.message.content??n.message,l=Un(r);if(l)return {summary:l.slice(0,200),detail:o()}}return {summary:`[${n.subtype}]`,detail:o()}}if(n.content){let r=Un(n.content);if(r)return {summary:r.slice(0,200),detail:o()}}return n.type?{summary:`[${n.type}]`,detail:o()}:{summary:t.slice(0,150),detail:o()}}catch{return {summary:vc(t),detail:o()}}}function vc(t){let o=t.match(/"subtype"\s*:\s*"([^"]+)"/);if(o)return `[${o[1]}]`;let n=t.match(/"type"\s*:\s*"([^"]+)"/),r=t.match(/"role"\s*:\s*"([^"]+)"/),l=n?.[1],f=r?.[1];if(!l&&!f)return t.slice(0,200);if(l==="assistant"||l==="message"||f==="assistant"){let b=t.match(/"text"\s*:\s*"((?:[^"\\]|\\.)*)"/);if(b)try{return JSON.parse(`"${b[1]}"`).slice(0,200)}catch{}return "\u{1F4AC} (assistant)"}if(l==="user"||l==="tool_result"||f==="user")return "\u2190 (tool result)";if(l==="tool_use")return `\u2699 ${t.match(/"name"\s*:\s*"([^"]+)"/)?.[1]??"tool"}()`;if(l==="result"){let b=t.match(/"result"\s*:\s*"((?:[^"\\]|\\.)*)"/);if(b)try{return `\u2713 ${JSON.parse(`"${b[1]}"`).slice(0,180)}`}catch{}return "\u2713 Agent finished"}return l==="rate_limit_event"?"\u23F3 Rate limited":`[${l??f}]`}function _c(t,o,n,r){let l=f=>r?.get(f);switch(t.type){case "agent:started":o("Started task",e.green,{agentId:t.agentId,taskId:t.taskId,msgType:"lifecycle"});break;case "agent:output":{let{summary:f,detail:b}=Vi(t.data);if(f){let T=Di(f);o(f,T.color,{agentId:t.agentId,taskId:l(t.runId),detail:b,msgType:T.msgType});}break}case "agent:file_changed":o(`${t.path}`,e.purple,{agentId:t.agentId,taskId:l(t.runId),msgType:"file"});break;case "agent:completed":o(t.success?"Completed successfully":"Failed",t.success?e.green:e.red,{agentId:t.agentId,taskId:l(t.runId),msgType:"lifecycle"});break;case "agent:error":o(`${t.error.slice(0,150)}`,e.red,{agentId:t.agentId,taskId:l(t.runId),detail:t.error,msgType:"error"});break;case "task:status_changed":o(`${t.from} \u2192 ${t.to}`,e.cyan,{taskId:t.taskId,msgType:"system"});break;case "task:assigned":o(`Assigned \u2192 ${t.agentId}`,e.cyan,{taskId:t.taskId,msgType:"system"});break;case "task:created":o(`Created: ${t.task.title}`,e.amber,{taskId:t.task.id,msgType:"system"});break;case "run:retry":o(`Retry #${t.attempt} (${Math.round(t.delay_ms/1e3)}s delay)`,e.yellow,{agentId:n?.get(t.runId),taskId:l(t.runId),msgType:"lifecycle"});break;case "orchestrator:tick":(t.running>0||t.queued>0)&&o(`${t.running} running \xB7 ${t.queued} queued`,e.ghost,{msgType:"system"});break;case "orchestrator:stall_detected":o("Stall detected",e.yellow,{agentId:n?.get(t.runId),taskId:l(t.runId),msgType:"error"});break}}export{zu as App,Gu as _resetPendingDeletionSeq};
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env node
2
+ import {j,o,l,q,d,h,m}from'./chunk-64WUDYEM.js';function T(y,n){let l$1=y.command("agent").description("Manage agents");l$1.command("add <name>").description("Add a new agent").requiredOption("--adapter <adapter>","Adapter type: claude, opencode, codex, cursor, shell").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(o$1,e)=>{let i=e.role;if(e.edit){let{openInEditor:t,agentToEditorContent:s,agentFromEditorContent:u}=await import('./editor-7IFRWVTL.js'),g=s({name:o$1,model:e.model,role:i}),d=await t(g),c=u(d);c.name&&(o$1=c.name),c.model&&(e.model=c.model),c.role&&(i=c.role);}let a=await n.agentService.create({name:o$1,adapter:e.adapter,role:i,command:e.command,model:e.model,max_turns:e.maxTurns?parseInt(e.maxTurns,10):void 0,timeout_ms:e.timeout?parseInt(e.timeout,10):void 0,approval_policy:e.approvalPolicy,workspace_mode:e.workspaceMode,skills:e.skills?e.skills.split(",").map(t=>t.trim()):void 0});n.context.json?console.log(JSON.stringify(a,null,2)):n.context.quiet?console.log(a.id):j(`Added agent ${o(a.name)} (${a.adapter}) \u2192 ${a.id}`);}),l$1.command("shop").description("Browse and install pre-built agent templates").option("--list","Print all templates (non-interactive)").action(async o$1=>{let{AGENT_SHOP_TEMPLATES:e}=await import('./agent-shop-D2RS4BZK.js');if(o$1.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'),a=await i(e);if(!a){console.log(" Cancelled.");return}let t=await n.agentService.create({name:a.name,adapter:a.adapter,model:a.model,role:a.role,skills:a.skills,approval_policy:a.approval_policy});j(`Added agent ${o(t.name)} (${t.adapter}) \u2192 ${t.id}`);}),l$1.command("list").description("List all agents").action(async()=>{let o$1=await n.agentService.list();if(n.context.json){console.log(JSON.stringify(o$1,null,2));return}if(n.context.quiet){o$1.forEach(t=>console.log(t.id));return}if(o$1.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=o$1.map(t=>[`${d(t.status)} ${t.status}`,o(t.name),t.adapter,t.current_task??q("\u2014"),q("\u2014")]);console.log(),l(e,i);let a=o$1.filter(t=>t.status==="running").length;console.log(`
5
+ ${o$1.length} agents \xB7 ${a} running \xB7 ${h(o$1.reduce((t,s)=>t+(s.stats.tokens_used??0),0))} tokens total
6
+ `);}),l$1.command("status <id>").description("Show agent details").action(async o=>{let e=await n.agentService.get(o);if(n.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(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 o$1=>{let e=await n.agentService.get(o$1),{openInEditor:i,agentToEditorContent:a,agentFromEditorContent:t}=await import('./editor-7IFRWVTL.js'),s=a({name:e.name,model:e.config.model,role:e.role}),u=await i(s),g=t(u),d=await n.agentService.update(o$1,{name:g.name,role:g.role,model:g.model});n.context.json?console.log(JSON.stringify(d,null,2)):n.context.quiet?console.log(d.id):j(`Updated agent ${o(d.name)} (${d.id})`);}),l$1.command("remove <id>").description("Remove an agent").action(async o=>{await n.agentService.remove(o),j(`Removed agent ${o}`);}),l$1.command("disable <id>").description("Disable an agent").action(async o=>{await n.agentService.disable(o),j(`Disabled agent ${o}`);}),l$1.command("enable <id>").description("Enable an agent").action(async o=>{await n.agentService.enable(o),j(`Enabled agent ${o}`);}),l$1.command("autonomous <id>").description("Toggle autonomous mode for an agent").option("--on","Enable autonomous mode").option("--off","Disable autonomous mode").action(async(o$1,e)=>{let i=await n.agentService.get(o$1),a=e.on?true:e.off?false:!i.autonomous,t=await n.agentService.setAutonomous(o$1,a);n.context.json?console.log(JSON.stringify(t,null,2)):n.context.quiet?console.log(t.id):j(`Autonomous mode ${a?"enabled":"disabled"} for agent ${o(t.name)} (${t.id})`);});}export{T as registerAgentCommand};
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export{a as AGENT_SHOP_TEMPLATES,b as getShopTemplateByKey}from'./chunk-BCPUTULS.js';
@@ -0,0 +1,112 @@
1
+ #!/usr/bin/env node
2
+ import {a}from'./chunk-CHRW4CLD.js';var k=class{engine;renderTimeoutMs;constructor(e){this.renderTimeoutMs=e?.renderTimeoutMs??5e3;}async getEngine(){if(!this.engine){let{Liquid:e}=await import('liquidjs');this.engine=new e({strictFilters:false,strictVariables:false});}return this.engine}async render(e,r){let n=(await this.getEngine()).parseAndRender(e,r);if(this.renderTimeoutMs<=0)return n;let d,c=new Promise((u,s)=>{d=setTimeout(()=>s(new Error(`Template render timed out after ${this.renderTimeoutMs}ms`)),this.renderTimeoutMs);});try{return await Promise.race([n,c])}finally{clearTimeout(d);}}},f=15;function y(t,e){let r=Object.entries(t);if(r.length===0)return {};let a=e.agentName.toLowerCase(),n=b(a,e.agentRole),d=[];for(let[s,i]of r){let g=0,l=s.toLowerCase();if(e.goalId&&l.startsWith(e.goalId.toLowerCase())&&(g+=10),(l.includes(a)||i.toLowerCase().includes(a))&&(g+=8),e.taskScope?.length)for(let p of e.taskScope){let m=p.replace(/\*+/g,"").replace(/\/+$/,"");if(m&&(l.includes(m.toLowerCase())||i.toLowerCase().includes(m.toLowerCase()))){g+=6;break}}for(let p of n)if(l.startsWith(p+"-")||l.startsWith(p+"_")){g+=4;break}/^(bug|perf|stability|docs|arch|spec)-/i.test(s)&&(g+=1),d.push({key:s,value:i,score:g});}d.sort((s,i)=>i.score-s.score);let c=d.filter(s=>s.score>0).slice(0,f);if(c.length<f){let s=d.filter(i=>i.score===0).slice(0,f-c.length);c.push(...s);}let u={};for(let{key:s,value:i}of c)u[s]=i;return u}function b(t,e){let r=[],a=t.split(/[\s_-]/)[0];if(a&&a.length>1&&r.push(a),(t.includes("front")||t.includes("tui"))&&r.push("front-end","frontend","tui"),(t.includes("market")||t.includes("cmo"))&&r.push("marketer","marketing","cmo"),e){let n=e.toLowerCase().split(/[\s_-]/)[0];n&&n.length>2&&!r.includes(n)&&r.push(n);}return r}function T(t,e,r,a$1,n,d){let{allAgents:c,retryContext:u,sharedContext:s,feedback:i,messages:g,goal:l}=d??{},p=new Map((c??[]).map(o=>[o.id,o])),m=g?.length?g.map(o=>({id:o.id,from:p.get(o.from_agent_id)?.name??o.from_agent_id,subject:o.subject,body:o.body,sent_at:o.created_at,reply_to:o.reply_to})):void 0;return {project:{name:n.project.name,description:n.project.description},task:{id:t.id,title:t.title,description:t.description,priority:t.priority,labels:t.labels,scope:t.scope,is_autonomous:t.labels?.includes(a)??false,goal_id:t.goalId},agent:{id:e.id,name:e.name,role:e.role},agents:(c??[]).map(o=>({id:o.id,name:o.name,role:o.id===e.id?void 0:o.role,adapter:o.adapter})),attempt:r>1?r:null,workspace_path:a$1,retry:r>1?u:void 0,feedback:i,shared_context:s&&Object.keys(s).length>0?y(s,{agentName:e.name,agentRole:e.role,goalId:t.goalId,taskScope:t.scope}):void 0,messages:m,goal:l}}var _=`You are {{ agent.name }}{% if agent.role %} ({{ agent.role }}){% endif %}.
3
+
4
+ ## Orchestrator CLI
5
+ Manage tasks and coordinate with other agents using \`orch\`:
6
+
7
+ **Tasks:**
8
+ - \`orch task add "<title>" -d "<description>" -p <1-4> --assignee <agent-id>\` \u2014 create and assign a task
9
+ - \`orch task add "<title>" -d "<description>" --scope "src/path/**" --depends-on <task-id>\` \u2014 scoped task with dependency
10
+ - \`orch task list [--status todo|in_progress|done|failed]\` \u2014 list tasks
11
+
12
+ **Messaging:**
13
+ - \`orch msg send <agent-id> "<body>" -s "<subject>"\` \u2014 direct message
14
+ - \`orch msg broadcast "<body>" -s "<subject>"\` \u2014 broadcast to all
15
+ - \`orch msg inbox {{ agent.id }}\` \u2014 your pending messages
16
+
17
+ **Shared context:**
18
+ - \`orch context set <key> <value>\` / \`orch context get <key>\` / \`orch context list\`
19
+
20
+ {% if task.is_autonomous %}
21
+ ## Autonomous Goal Mode
22
+ This is an autonomous task driven by a goal. Work in a continuous loop until the goal is achieved:
23
+
24
+ 1. **Understand the goal** \u2014 read the Goal section above.
25
+ 2. **Decompose** \u2014 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.
26
+ 3. **Execute** \u2014 follow your standard workflow for each subtask.
27
+ 4. **Track progress** \u2014 after each iteration: \`orch context set {{ task.goal_id | default: "<goal>" }}-progress "<summary of what's done and what remains>"\`.
28
+ 5. **Be proactive** \u2014 do NOT wait for tasks from others. Create your own subtasks and keep working.
29
+ 6. **Do NOT finish** the [auto] task until the goal is achieved \u2014 keep creating subtasks.
30
+ 7. **When done** \u2014 mark the goal as achieved: \`orch goal status {{ task.goal_id | default: "<goal-id>" }} achieved\`.
31
+
32
+ **Deep inspection:** Use \`orch goal show {{ task.goal_id | default: "<goal-id>" }}\` to see full goal details at any time.
33
+ {% endif %}
34
+
35
+ ## Rules
36
+ - Do NOT ask clarifying questions. You are running autonomously without human input.
37
+ - Make reasonable assumptions and proceed with the best approach.
38
+ - If critical information is missing, document your assumptions and continue.
39
+ - When a task is too large or spans multiple domains, break it into subtasks using \`orch task add\`.
40
+ - When creating subtasks, use \`--scope\` to declare which files each task will touch, and \`--depends-on\` to order dependent work.
41
+ `,w=`## Task: {{ task.title }}
42
+ {{ task.description }}
43
+
44
+ Priority: {{ task.priority }}
45
+ {% if attempt %}Attempt: {{ attempt }}{% endif %}
46
+ {% if retry %}
47
+ ## Previous attempt failed
48
+ **Error:** {{ retry.previous_error }}
49
+ {% if retry.previous_output != "" %}
50
+ **Last output:**
51
+ \`\`\`
52
+ {{ retry.previous_output }}
53
+ \`\`\`
54
+ {% endif %}
55
+ **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.
56
+ {% endif %}
57
+
58
+ ## Context
59
+ Project: {{ project.name }}
60
+ Working directory: {{ workspace_path }}
61
+
62
+ ## Team
63
+ You are part of a multi-agent team. Available agents:
64
+ {% for a in agents %}- **{{ a.name }}** ({{ a.adapter }}){% if a.role %} \u2014 {{ a.role }}{% endif %} \xB7 ID: \`{{ a.id }}\`
65
+ {% endfor %}
66
+ Use \`orch agent list\` to check current agent statuses. Find teammates by name/role \u2014 do NOT hardcode agent IDs.
67
+
68
+ {% if feedback %}
69
+ ## Review Feedback
70
+ This task was previously completed but **rejected** during review with the following feedback:
71
+ > {{ feedback }}
72
+
73
+ **Important:** Address the feedback above. Focus on what the reviewer asked to change. Do NOT redo work that was already accepted.
74
+ {% endif %}
75
+
76
+ {% if shared_context %}
77
+ ## Shared Context
78
+ Other agents have shared the following information:
79
+ {% for entry in shared_context %}- **{{ entry[0] }}**: {{ entry[1] }}
80
+ {% endfor %}
81
+ {% endif %}
82
+
83
+ {% if messages %}
84
+ ## Inbox ({{ messages.size }} message{% if messages.size != 1 %}s{% endif %})
85
+ {% for msg in messages %}
86
+ ---
87
+ **From:** {{ msg.from }}{% if msg.subject != "" %} \xB7 **Subject:** {{ msg.subject }}{% endif %}
88
+ {{ msg.body }}
89
+ {% if msg.reply_to %}*(Reply to: {{ msg.reply_to }})*{% endif %}
90
+ ---
91
+ {% endfor %}
92
+ {% endif %}
93
+
94
+ {% if goal %}
95
+ ## Goal: {{ goal.title }}
96
+ **Status:** {{ goal.status }} \xB7 **ID:** \`{{ goal.id }}\`
97
+ {% if goal.description != "" %}
98
+ {{ goal.description }}
99
+ {% endif %}
100
+ {% if goal.task_names.size > 0 %}
101
+ **Linked tasks ({{ goal.task_names.size }}):**
102
+ {% for name in goal.task_names %}- {{ name }}
103
+ {% endfor %}
104
+ Use \`orch task list --goal-id {{ goal.id }}\` and \`orch task show <id>\` to inspect details.
105
+ {% endif %}
106
+ {% if goal.progress %}
107
+ **Latest progress report:**
108
+ {{ goal.progress }}
109
+ {% endif %}
110
+ {% endif %}
111
+ `,v=_+`
112
+ `+w;export{k as a,y as b,T as c,_ as d,w as e,v as f};
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env node
2
+ import p from'chalk';var y={running:"\u25CF",todo:"\u25CB",review:"\u25C8",done:"\u2713",failed:"\u2715",retrying:"\u21BB",cancelled:"\u25CB",idle:"\u25CB",error:"\u2715",disabled:"\u2500",agentAction:"\u25B8",orchestratorEvent:"\u2192",warning:"\u26A0"},b={running:"*",todo:"o",review:"#",done:"+",failed:"x",retrying:"~",cancelled:"o",idle:"o",error:"x",disabled:"-",agentAction:">",orchestratorEvent:"->",warning:"!!"},w={amber:214,green:72,red:167,blue:74,yellow:178,dim:240,ghost:236,white:255,purple:141},l;function C(){if(!l){l={};for(let[e,r]of Object.entries(w))l[e]=p.ansi256(r);}return l}var n=new Proxy({},{get(e,r){return C()[r]}}),f=false;function v(e){f=e;}function S(e){e&&(p.level=0);}function t(e){return f?b[e]:y[e]}function N(e){let r=t(e);switch(e){case "running":case "in_progress":return n.green(t("running"));case "todo":return n.dim(t("todo"));case "review":return n.blue(t("review"));case "done":return n.green(t("done"));case "failed":return n.red(t("failed"));case "retrying":return n.yellow(t("retrying"));case "cancelled":return n.dim(t("cancelled"));case "idle":return n.dim(t("idle"));case "error":return n.red(t("error"));case "disabled":return n.ghost(t("disabled"));default:return r}}function A(e){switch(e){case 1:return n.red("P1");case 2:return n.yellow("P2");case 3:return "P3";case 4:return n.dim("P4");default:return `P${e}`}}function $(e){let r=Math.floor(e/1e3);if(r<60)return `${r}s`;let o=Math.floor(r/60),i=r%60;if(o<60)return `${o}:${String(i).padStart(2,"0")}`;let s=Math.floor(o/60),d=o%60;return `${s}h${String(d).padStart(2,"0")}m`}function R(e){let r=Date.now()-new Date(e).getTime();return $(r)}function j(e){return e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}function E(e,r){console.error(` ${n.red(t("failed"))} ${e}`),r&&console.error(` ${r}`);}function M(e){console.log(` ${n.green(t("done"))} ${e}`);}function O(e){console.log(` ${n.yellow(t("warning"))} ${e}`);}function P(e,r,o=2){let i=e.map((a,c)=>Math.max(a.length,...r.map(u=>g(u[c]??"").length))),s=[],d=e.map((a,c)=>a.padEnd(i[c]+o)).join("");s.push(` ${n.dim(d)}`);for(let a of r){let c=a.map((u,m)=>{let h=g(u),x=(i[m]??0)+o-h.length;return u+" ".repeat(Math.max(0,x))}).join("");s.push(` ${c}`);}process.stdout.write(s.join(`
3
+ `)+`
4
+ `);}function D(e){let r=Math.max(...e.map(([i])=>i.length)),o=e.map(([i,s])=>` ${n.dim(i.padEnd(r+2))}${s}`);process.stdout.write(o.join(`
5
+ `)+`
6
+ `);}function F(e){return n.purple(e)}function T(e){return n.green(e)}function _(e){return n.amber(e)}function L(e){return n.dim(e)}function g(e){return e.replace(/\x1b\[[0-9;]*m/g,"")}export{v as a,S as b,t as c,N as d,A as e,$ as f,R as g,j as h,E as i,M as j,O as k,P as l,D as m,F as n,T as o,_ as p,L as q};
@@ -0,0 +1,2 @@
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};