@oxgeneral/orch 1.0.5 → 1.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/App-LEVUTWQN.js +22 -0
- package/dist/{chunk-UTDC3OB3.js → chunk-4TDXD3LA.js} +53 -6
- package/dist/chunk-4TDXD3LA.js.map +1 -0
- package/dist/{chunk-BSJVYRI3.js → chunk-EH3HRQP4.js} +59 -8
- package/dist/chunk-EH3HRQP4.js.map +1 -0
- package/dist/chunk-FQ5YUP4J.js +4 -0
- package/dist/{chunk-TPTHLFOB.js → chunk-HYPSQAQX.js} +1 -1
- package/dist/{chunk-LXNRCJ22.js → chunk-KR7VDF23.js} +1 -1
- package/dist/{chunk-KFQTWMZI.js → chunk-LOJ26OVK.js} +1 -1
- package/dist/{chunk-PJ5DKXGR.js → chunk-N4OXN2HW.js} +1 -1
- package/dist/{chunk-MOWC2CHX.js → chunk-TWEMIPRN.js} +12 -8
- package/dist/chunk-TWEMIPRN.js.map +1 -0
- package/dist/chunk-WVJTXBPL.js +11 -0
- package/dist/claude-ADMRIWTR.js +2 -0
- package/dist/{claude-4R6L6BWY.js → claude-OTQ2NSJR.js} +3 -3
- package/dist/{claude-4R6L6BWY.js.map → claude-OTQ2NSJR.js.map} +1 -1
- package/dist/cli.js +1 -1
- package/dist/{codex-YRSODLH4.js → codex-AZD52UPS.js} +1 -1
- package/dist/{codex-IMOW5ZUZ.js → codex-WQ3LU3MM.js} +3 -3
- package/dist/{codex-IMOW5ZUZ.js.map → codex-WQ3LU3MM.js.map} +1 -1
- package/dist/container-FXUUV6PP.js +4 -0
- package/dist/{cursor-2HILMNM3.js → cursor-M3EJ432K.js} +1 -1
- package/dist/{cursor-NHV7X3WG.js → cursor-TKV5FFCN.js} +3 -3
- package/dist/{cursor-NHV7X3WG.js.map → cursor-TKV5FFCN.js.map} +1 -1
- package/dist/doctor-P2J6VAUX.js +2 -0
- package/dist/index.d.ts +13 -1
- package/dist/index.js +14 -11
- package/dist/index.js.map +1 -1
- package/dist/{init-56QC5QVX.js → init-PTAYCSMO.js} +4 -4
- package/dist/{once-runner-UCMXCY6C.js → once-runner-AMKCFW22.js} +1 -1
- package/dist/{opencode-3S4VDXRG.js → opencode-4G7VAZGY.js} +1 -1
- package/dist/{opencode-ULT6DYCT.js → opencode-YWT3M4NX.js} +3 -3
- package/dist/{opencode-ULT6DYCT.js.map → opencode-YWT3M4NX.js.map} +1 -1
- package/dist/orchestrator-JOTMB5XT.js +13 -0
- package/dist/orchestrator-XPEMMBOO.js +6 -0
- package/dist/{orchestrator-64BHTD42.js.map → orchestrator-XPEMMBOO.js.map} +1 -1
- package/dist/{serve-3DV74ZSO.js → serve-5OAANN6J.js} +1 -1
- package/dist/shell-JC2WDWBR.js +2 -0
- package/dist/{shell-UXEJRK3D.js → shell-PMLIRG3N.js} +3 -3
- package/dist/{shell-UXEJRK3D.js.map → shell-PMLIRG3N.js.map} +1 -1
- package/dist/{task-M2JGNUYW.js → task-QFLIIRKZ.js} +1 -1
- package/dist/{tui-4VRDSRVB.js → tui-BJHZBCIR.js} +1 -1
- package/dist/{workspace-manager-ABXFBL2A.js → workspace-manager-5EYCMAEO.js} +25 -9
- package/dist/workspace-manager-5EYCMAEO.js.map +1 -0
- package/dist/workspace-manager-XKOZ5WM6.js +3 -0
- package/package.json +19 -9
- package/readme.md +111 -2
- package/scripts/demo.sh +202 -0
- package/scripts/{postinstall.js → postinstall.cjs} +25 -4
- package/skills/orch/SKILL.md +278 -0
- package/dist/App-SSYYVFGW.js +0 -22
- package/dist/chunk-BSJVYRI3.js.map +0 -1
- package/dist/chunk-MOWC2CHX.js.map +0 -1
- package/dist/chunk-QNZ6D63E.js +0 -4
- package/dist/chunk-UTDC3OB3.js.map +0 -1
- package/dist/chunk-X54D5JZG.js +0 -11
- package/dist/claude-ZLVOLRUG.js +0 -2
- package/dist/container-FUHRQOV4.js +0 -4
- package/dist/doctor-GKTV4YYD.js +0 -2
- package/dist/orchestrator-64BHTD42.js +0 -6
- package/dist/orchestrator-KEH7RQAV.js +0 -13
- package/dist/shell-OBHIVC2H.js +0 -2
- package/dist/workspace-manager-ABXFBL2A.js.map +0 -1
- package/dist/workspace-manager-Q6WWXSTR.js +0 -3
package/dist/App-SSYYVFGW.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import {a}from'./chunk-PJ5DKXGR.js';import {c,a as a$1}from'./chunk-HXOMNULD.js';import {b,a as a$2}from'./chunk-BCPUTULS.js';import {f,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",x=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:x.color,bold:o.priority<=2,children:x.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 x=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:x.bg,color:x.fg,bold:x.bold,children:x.spinner?jsxs(Fragment,{children:[" ",jsx(_o,{color:x.fg})," ",x.label," "]}):jsxs(Fragment,{children:[" ",x.icon," ",x.label," "]})})}),jsx(Box,{width: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,x=Math.max(0,r-T-b.length-4);return jsxs(Box,{paddingX:2,children:[jsx(Text,{color:e.ghost,children:be(T)}),jsx(Text,{backgroundColor:Ao.amber,color:e.amber,bold:true,children:b}),jsx(Text,{color:e.ghost,children:be(x)})]})}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":" ",x=f?.length??0,y=f?.filter($=>$.status==="done").length??0,S=x>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=x>0?Math.round(y/x*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}/${x}`})]})})(),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,x=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:x,children:[jsx(Text,{color:e.dim,children:" status "}),jsx(Text,{color:b,children:t.status})]}),jsxs(Box,{children:[jsx(Text,{color:e.dim,children:" assignee "}),jsx(Text,{color:t.assignee?e.green:e.dim,children:t.assignee?l?.get(t.assignee)??t.assignee:"\u2014"})]})]}),jsxs(Box,{children:[jsxs(Box,{width:x,children:[jsx(Text,{color:e.dim,children:" priority "}),jsxs(Text,{color:T,bold:t.priority<=2,children:["P",t.priority]})]}),jsxs(Box,{children:[jsx(Text,{color:e.dim,children:" attempts "}),jsxs(Text,{children:[t.attempts,"/",t.max_attempts]})]})]}),jsxs(Box,{children:[jsxs(Box,{width:x,children:[jsx(Text,{color:e.dim,children:" labels "}),jsx(Text,{color:e.purple,children:t.labels.length>0?t.labels.join(", "):"\u2014"})]}),jsxs(Box,{children:[jsx(Text,{color:e.dim,children:" depends "}),jsx(Text,{dimColor:true,children:t.depends_on.length>0?t.depends_on.map(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,x=Math.max(0,T-n),y=Math.min(t,T),S=x,C=Math.max(0,y-x),_=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,x=2,y=6*x;return tn.useEffect(()=>{T>=y&&!b.current&&(b.current=true,n());},[T,n]),Math.floor(T/x)%2===0&&T<y?jsxs(Text,{backgroundColor:o,color:"#0a0a0c",bold:true,children:[" ",t.key," ",t.label,r," "]}):jsxs(Box,{gap:0,children:[jsx(Text,{color:e.ghost,children:t.key}),jsxs(Text,{color:e.dim,children:[" ",t.label.toLowerCase(),r]})]})}function vl({projectName:t,activeView:o,mode:n,stats:r,uptime:l,width:f,version:b,latestVersion:T,taskBadge:x,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"&&x!=null&&x>0?` (${x})`:"",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(x=>x.show),b=o.total>0,T=r&&r.length>0?Math.min(16,r.length):0;return jsxs(Box,{paddingX:1,justifyContent:"space-between",width:n,children:[jsxs(Box,{gap:1,children:[f.map(x=>jsx(Text,{backgroundColor:x.bg,color:x.fg,bold:x.bold,children:x.spinner?jsxs(Fragment,{children:[" ",jsx(Ps,{color:x.fg})," ",x.count," ",x.label," "]}):jsxs(Fragment,{children:[" ",x.icon," ",x.count," ",x.label," "]})},x.label)),f.length===0&&jsxs(Text,{backgroundColor:ut.neutral,color:e.dim,children:[" ","NO TASKS"," "]})]}),jsxs(Box,{gap:0,children:[T>0&&r&&jsxs(Fragment,{children:[jsx(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 x=Object.keys(uo).find(y=>y.startsWith(T)&&y!==T);return x?x.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(),x=[];if(!T){let y=[on,Eo,An];for(let S of y){x.push({cmd:"",desc:`\u2500\u2500 ${S} \u2500\u2500`});for(let[C,_]of Object.entries(uo))if(_.category===S){let k=_.args?` ${_.args}`:"";x.push({cmd:`/${C}${k}`,desc:_.help,subs:_.sub?.join(" \xB7 ")});}}return x}for(let[y,S]of Object.entries(uo))if(y.startsWith(T)){let C=S.args?` ${S.args}`:"";if(x.push({cmd:`/${y}${C}`,desc:S.help,subs:S.sub?.join(" \xB7 ")}),y===T&&S.sub)for(let _ of S.sub)x.push({cmd:`/${y} ${_}`,desc:`${S.help}: ${_}`});}return x}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:x,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"]}),x&&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:x}){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&&x&&x(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 [x,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,x-E))},[x,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[x];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===x,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":" "," ",x+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,x]=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;x(j=>{let V=new Set(j);return V.has(k)?V.delete(k):V.add(k),V});return}if(C==="a"||C==="A"){x(k=>k.size===bt.length?new Set:new Set(bt));return}for(let k of qs)if(C===k.key){x(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 x=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-x))}),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,x=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:[" ",x," "]}),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)),x=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(x)}),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(x=>x.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(x=>x.members.some(y=>y.agent_id===t.id))?.id;return [{id:"name",label:"Agent name",type:"text",defaultValue:t.name,required:true,validate:x=>x.trim()?o?.some(y=>y.id!==t.id&&y.name===x.trim())?"Agent with this name already exists":null:"Name is required"},{id:"model",label:"Model",type:"select",options:f,defaultValue:t.config.model??""},{id:"role",label:"Role / specialization",type:"select",options: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:x=>x.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:x,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(h=>h.label===mo);return new Set(i?.types??Xn)}),cn=useMemo(()=>Lo.find(h=>h.types.length===xo.size&&h.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,h)=>{if(!un.current.toast)return;let s=qr.current.find(p=>p.id===h),d=s?.title??h,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(h=>h.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[h,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(h),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 h of ye)i.set(h.id,h);return i},[ye]),Ee=useMemo(()=>{let i=[...R].sort((p,g)=>(Jo[p.status]??9)-(Jo[g.status]??9));if(!jo)return i;let h=[],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)h.push(...u.get(p));return [...h,...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 h of R)i.set(h.id,h.title);return i},[R]),ro=useMemo(()=>{let i=new Map;for(let h of L)i.set(h.id,h.name);return i},[L]),oa=useMemo(()=>{let i=new Map;for(let h of R)if(h.goalId){let s=i.get(h.goalId);s||(s=[],i.set(h.goalId,s)),s.push(h);}return i},[R]),hn=useMemo(()=>{let i=new Map;for(let h=0;h<L.length;h++)i.set(L[h].id,Nr[h%Nr.length]);return i},[L]),Qr=useMemo(()=>{let i=new Map;for(let h of Fe)h.agentId&&i.set(h.agentId,(i.get(h.agentId)??0)+1);return i},[Fe]),na=useMemo(()=>{let i={};for(let h of Fe){let s=h.msgType??"info";i[s]=(i[s]??0)+1;}return i},[Fe]),{agentTeamMap:Co,activeTeamCount:qo,teamLeadSet:ra}=useMemo(()=>{let i=new Map,h=new Set,s=0;for(let d of Wt)if(d.status==="active"){s++,h.add(d.lead_agent_id);for(let u of d.members)i.set(u.agent_id,d.name);}return {agentTeamMap:i,activeTeamCount:s,teamLeadSet:h}},[Wt]),Ne=useMemo(()=>{let i=[...L];return i.sort((h,s)=>{let d=Co.get(h.id),u=Co.get(s.id);return d&&!u?-1:!d&&u?1:d&&u&&d!==u?d.localeCompare(u):(wr[h.status]??9)-(wr[s.status]??9)}),i},[L,Co]),J=Ne[Zn],dt=useMemo(()=>[...ye].sort((i,h)=>(c[i.status]??9)-(c[h.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(h=>{i||sn(h);}).catch(()=>{}),()=>{i=true;}},[te?.id]);let so=useRef(new Map),xn=useRef(new Map);useEffect(()=>{for(let[i,h]of Object.entries(K.running))so.current.set(h.run_id,h.agent_id),xn.current.set(h.run_id,i);if(so.current.size>Bi){let i=so.current.size-Bi,h=0;for(let s of so.current.keys()){if(h++>=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(h=>{if(i.length>=go)return i.slice(-go);let s=go-i.length;return (h.length>s?h.slice(-s):h).concat(i)});},[]);useEffect(()=>()=>{Ko.current&&clearTimeout(Ko.current);},[]);let a=useCallback((i,h,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:h,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,h,s,d)=>{let u={key:++Pi,entityType:i,entityId:h,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 h=i[i.length-1];return a(`\u21B6 Undo: "${h.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(h){a(`Failed to delete "${i.entityName}": ${h instanceof Error?h.message:String(h)}`,e.red);}},[D,U,Ze,W,a,Z]),ts=useRef(es);ts.current=es,useEffect(()=>{if(yo.length===0)return;let i=setInterval(()=>{let h=Date.now(),s=[];dr(d=>{let u=d.filter(p=>p.expiresAt<=h?(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=h=>{let s=new Date(h.timestamp).toLocaleTimeString("en-US",{hour12:false,hour:"2-digit",minute:"2-digit",second:"2-digit"}),d=typeof h.data=="string"?h.data:JSON.stringify(h.data),u,p=e.silver,g="output";if(h.type==="error")u=typeof h.data=="string"?h.data:JSON.stringify(h.data),u=u.slice(0,200),p=e.red,g="error";else if(h.type==="file_changed")u=String(h.data),p=e.purple,g="file";else if(h.type==="done")u="Completed",p=e.green,g="lifecycle";else if(h.type==="tool_call")u=`\u2699 ${h.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(h.timestamp).getTime(),agentId:h.agentId,taskId:h.taskId,msgType:g}};z(h=>{if(h.length===0)return;let s=h.map(i).filter(d=>d!==null);Wr(d=>{let u=[...s,...d];return u.length>go?u.slice(-go):u});}).catch(h=>{process.stderr.write(`[TUI] onLoadHistory error: ${h instanceof Error?h.stack??h.message:String(h)}
|
|
12
|
-
`);});},[]),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:h}=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 h();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 h=pt?.kind,s=pt?.targetId;if(Ke(null),h==="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((h==="agent"||h==="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(h==="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(h==="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&&x&&x(p.id,d.assignee).catch(()=>{}),Z();},p=>a(`Failed: ${p instanceof Error?p.message:String(p)}`,e.red));}else if(h==="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&&x&&x(s,d.assignee).catch(()=>{}),Z();},p=>a(`Failed: ${p instanceof Error?p.message:String(p)}`,e.red));}else if(h==="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(h==="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(h==="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(h==="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,x,O,F,vt,Xe,$e,a,Z,ct,_t,dn,jt,Wt,no]),ua=useCallback(()=>{Be("none"),Ke(null),Go([]);},[]),ga=useCallback(i=>{let h=b(i);if(!h)return;let s=Vn(L,wo.current),d=Or(s,h);Ke({title:`NEW AGENT \u2014 ${h.name}`,steps:d,kind:"agent_from_shop"}),Be("wizard");},[]);useEffect(()=>{if(!_)return;let i=null,h=()=>{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")&&h();});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 h of R)h.status==="in_progress"?i.running++:h.status==="retrying"?i.retrying++:h.status==="review"?i.review++:h.status==="todo"?i.todo++:h.status==="done"?i.done++:h.status==="failed"?i.failed++:h.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,h=new Set,s=false;for(let d of $t)d.goalId&&So.has(d.goalId)?h.has(d.goalId)||(h.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(!x||!s[1]){a("Usage: assign <agent>",e.yellow);return}a(`Assigning "${H.title}" to ${s[1]}...`,e.amber),x(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(!x)return;a(`Assigning "${w.title}" to ${Y}...`,e.amber),x(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,x,y,l,f,S,C,E,B,$,D,ie,Re,Mt,it,at,gt,a,No,Z,Tn,bn,ns,rs]);useInput((i,h)=>{if(!(Rt&&(Qn(false),i==="?"||h.escape||i==="\x1BOP"))&&!ho){if((h.ctrl||h.meta)&&i==="s"&&Pe==="wizard"&&pt?.kind==="agent"){os();return}if(Pe!=="none"){if(h.escape){Be("none"),wt(""),mn.reset();return}if(h.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(h.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(h.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(h.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(h.backspace||h.delete){wt(s=>s.slice(0,-1)),Xt(0);return}i&&!h.ctrl&&!h.meta&&(wt(s=>s+i),Xt(0));return}if(i.toLowerCase()==="q"){No();return}if(h.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(h.tab||h.rightArrow){po(s[(d+1)%s.length]);return}if(h.leftArrow){po(s[(d+s.length-1)%s.length]);return}}if(h.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(h.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(h.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),x=f.entityType==="task"?"Task":f.entityType==="agent"?"Agent":"Goal",y=Math.max(10,T-x.length-30),S=f.entityName.length>y?f.entityName.slice(0,y-1)+"\u2026":f.entityName;return jsx(Box,{paddingX:2,children:jsxs(Text,{color:e.yellow,children:["\u2717 ",jsx(Text,{bold:true,children:x}),` "${S}" \u2014 `,jsxs(Text,{color:e.amber,bold:true,children:[b,"s"]}),jsx(Text,{color:e.dim,children:" \u2502 "}),jsx(Text,{color:e.gray,bold:true,children:"Z"}),jsx(Text,{color:e.dim,children:" undo"})]})},f.key)})})});function 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,x)=>{let y=x+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 x=t.length,y=t.slice(n,n+r),S=f&&x>=n&&x<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===x?e.amber:e.ghost,children:[o===x?" \u25B8 ":" ",jsx(Text,{color:o===x?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(`
|
|
13
|
-
`).flatMap(W=>U(W,E))??[],$=Tr(t.description)?.split(`
|
|
14
|
-
`).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:x,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||!x||x.size===0)return null;let D=new Map;for(let O of t)if(O.goalId&&x.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,x]),E=y&&x?t.filter(D=>!D.goalId||!x.has(D.goalId)).length:0,U=y&&x&&x.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&&x?.has(O.goalId)?O.goalId:null;if(U){if(F&&F!==$){let W=x.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:x})},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:x,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=x?.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&&x){for(let O of t)if(y.has(O.id)){let F=x.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?x?.get(t[n-1]?.id??""):void 0;for(let O=0;O<j.length&&$.length<r;O++){let F=j[O],W=x?.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:x,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=x.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?x.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),x=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,x);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,x=t.msgType??"info",y=t.agentId?l.get(t.agentId)??t.agentId.slice(0,8):void 0,S=t.agentId?f.get(t.agentId):e.dim,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(`
|
|
15
|
-
`).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[x]?x==="error"?e.red:e.dim:e.dim,children:[Yn[x]??"\u2502"," ",x]}),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,x=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(x)})]})}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,x=24;return jsxs(Box,{flexDirection:"column",paddingX:2,children:[jsxs(Box,{children:[jsxs(Box,{width:x,children:[jsx(Text,{color:e.dim,children:" status "}),jsx(Text,{color:f,children:t.status})]}),jsxs(Box,{children:[jsx(Text,{color:e.dim,children:" adapter "}),jsx(Text,{color:e.cyan,children:t.adapter})]})]}),jsxs(Box,{children:[jsxs(Box,{width:x,children:[jsx(Text,{color:e.dim,children:" model "}),jsx(Text,{children:t.config.model??"\u2014"})]}),jsxs(Box,{children:[jsx(Text,{color:e.dim,children:" task "}),jsx(Text,{color:T?e.white:e.dim,children:T??"\u2014"})]})]}),jsxs(Box,{children:[jsxs(Box,{width:x,children:[jsx(Text,{color:e.dim,children:" runs "}),jsx(Text,{children:t.stats.total_runs}),jsx(Text,{color:e.dim,children:" ("}),jsx(Text,{color:e.green,children:t.stats.tasks_completed}),jsx(Text,{color:e.dim,children:"/"}),jsx(Text,{color:t.stats.tasks_failed>0?e.red:e.dim,children:t.stats.tasks_failed}),jsx(Text,{color:e.dim,children:")"})]}),jsxs(Box,{children:[jsx(Text,{color:e.dim,children:" team "}),jsx(Text,{color:l?e.amber:e.dim,children:l??"\u2014"})]})]}),t.autonomous&&jsx(Box,{children:jsxs(Box,{width:x,children:[jsx(Text,{color:e.dim,children:" auto "}),jsxs(Text,{color:e.cyan,children:[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(`
|
|
16
|
-
`).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(`
|
|
17
|
-
`).find(b=>b.trim().length>0)??"";n.push(f.slice(0,o-r)),r+=f.length;}else if(l?.type==="tool_use"){let f=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(`
|
|
18
|
-
`)[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(`
|
|
19
|
-
`).length,r=t.split(`
|
|
20
|
-
`).find(l=>l.trim().length>0)??"";return n>3?`${r.slice(0,80)}... (${n} lines)`:r.slice(0,120)}if(!Array.isArray(t))return "(result)";let o=[];for(let n of t)if(n?.type==="tool_result"){n.tool_use_id?n.tool_use_id.slice(0,8):"";let l=n.is_error,f=typeof n.content=="string"?n.content:"",b=f.split(`
|
|
21
|
-
`).length;l?o.push(`\u2715 error: ${f.slice(0,60)}`):b>3?o.push(`\u2713 ${b} lines`):o.push(`\u2713 ${f.slice(0,80)}`);}else n?.type==="text"&&typeof n.text=="string"&&o.push(n.text.split(`
|
|
22
|
-
`)[0]?.slice(0,80)??"");return o.join(" ")||"(result)"}function 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};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/infrastructure/storage/fs-utils.ts","../src/infrastructure/storage/paths.ts"],"names":["path","lines"],"mappings":";;;;;;;AAgBA,eAAsB,WAAA,CAAY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cesContent":["/**\n * Low-level filesystem utilities.\n *\n * All file persistence goes through these functions.\n * atomicWrite guarantees no partial reads via temp → rename.\n */\n\nimport { randomBytes } from 'node:crypto';\nimport fs from 'node:fs/promises';\nimport path from 'node:path';\nimport yaml from 'js-yaml';\n\n/**\n * Write file atomically: write to temp file, then rename.\n * Prevents corrupted reads on concurrent access.\n */\nexport async function atomicWrite(filePath: string, content: string): Promise<void> {\n const dir = path.dirname(filePath);\n await ensureDir(dir);\n\n const tmpPath = path.join(dir, `.${path.basename(filePath)}.${randomBytes(4).toString('hex')}.tmp`);\n\n try {\n await fs.writeFile(tmpPath, content, 'utf-8');\n await fs.rename(tmpPath, filePath);\n } catch (err) {\n // Clean up temp file on failure\n await fs.unlink(tmpPath).catch(() => {});\n throw err;\n }\n}\n\n/**\n * Read and parse a YAML file. Returns null if file does not exist.\n */\nexport async function readYaml<T>(filePath: string): Promise<T | null> {\n try {\n const content = await fs.readFile(filePath, 'utf-8');\n return yaml.load(content) as T;\n } catch (err) {\n if (isENOENT(err)) return null;\n throw err;\n }\n}\n\n/**\n * Write data as YAML atomically.\n */\nexport async function writeYaml<T>(filePath: string, data: T): Promise<void> {\n const content = yaml.dump(data, {\n indent: 2,\n lineWidth: 120,\n noRefs: true,\n sortKeys: false,\n });\n await atomicWrite(filePath, content);\n}\n\n/**\n * Read and parse a JSON file. Returns null if file does not exist.\n */\nexport async function readJson<T>(filePath: string): Promise<T | null> {\n try {\n const content = await fs.readFile(filePath, 'utf-8');\n return JSON.parse(content) as T;\n } catch (err) {\n if (isENOENT(err)) return null;\n throw err;\n }\n}\n\n/**\n * Write data as JSON atomically.\n */\nexport async function writeJson<T>(filePath: string, data: T): Promise<void> {\n const content = JSON.stringify(data, null, 2) + '\\n';\n await atomicWrite(filePath, content);\n}\n\n/**\n * POSIX PIPE_BUF — writes up to this size are guaranteed atomic with O_APPEND.\n * 4096 on Linux/macOS. We leave some room for encoding overhead.\n */\nconst PIPE_BUF = 4096;\n\n/**\n * Append a JSON record to a .jsonl file (newline-delimited JSON).\n *\n * Uses a file handle opened with 'a' (O_APPEND) to ensure atomic writes.\n * On POSIX, O_APPEND guarantees that each write() call appends atomically\n * when the data fits within PIPE_BUF (typically 4096 bytes), preventing\n * interleaving from concurrent writers.\n *\n * If the serialized line exceeds PIPE_BUF, the record's `data` field is\n * truncated so the entire line fits within the atomic-write limit.\n * This prevents interleaving corruption from concurrent writers.\n */\nexport async function appendJsonl(filePath: string, record: unknown): Promise<void> {\n const dir = path.dirname(filePath);\n await ensureDir(dir);\n let line = JSON.stringify(record) + '\\n';\n\n // If the line exceeds PIPE_BUF, truncate the `data` field to fit\n const byteLen = Buffer.byteLength(line, 'utf-8');\n if (byteLen > PIPE_BUF && record !== null && typeof record === 'object') {\n const obj = record as Record<string, unknown>;\n if (typeof obj.data === 'string' && obj.data.length > 0) {\n // Measure overhead without data to know how much room data gets\n const shell = JSON.stringify({ ...obj, data: '' }) + '\\n';\n const overhead = Buffer.byteLength(shell, 'utf-8');\n const budget = PIPE_BUF - overhead - 3; // 3 bytes for the '…' suffix (UTF-8 ellipsis)\n if (budget > 0) {\n // Slice to budget chars — for ASCII (most event data) this equals bytes.\n // For multi-byte chars the result may be slightly over PIPE_BUF,\n // which is acceptable on local filesystems (ext4/APFS hold inode lock).\n const truncated = obj.data.slice(0, budget);\n line = JSON.stringify({ ...obj, data: truncated + '…' }) + '\\n';\n }\n }\n }\n\n const fd = await fs.open(filePath, 'a');\n try {\n await fd.write(line, null, 'utf-8');\n } finally {\n await fd.close();\n }\n}\n\n/** Max file size for full readJsonl (50 MB). Larger files use tail read. */\nconst MAX_JSONL_READ_SIZE = 50 * 1024 * 1024;\n\n/**\n * Read all records from a .jsonl file.\n * Falls back to reading only the last 200 records if the file exceeds MAX_JSONL_READ_SIZE.\n */\nexport async function readJsonl<T>(filePath: string): Promise<T[]> {\n try {\n const stat = await fs.stat(filePath);\n if (stat.size > MAX_JSONL_READ_SIZE) {\n process.stderr.write(\n `[readJsonl] file too large (${(stat.size / 1024 / 1024).toFixed(1)} MB), reading tail only: ${filePath}\\n`,\n );\n return readJsonlTail<T>(filePath, 200);\n }\n return readAndParseJsonl<T>(filePath);\n } catch (err) {\n if (isENOENT(err)) return [];\n throw err;\n }\n}\n\n/**\n * Read the last N records from a .jsonl file.\n *\n * Reads the file in reverse chunks to avoid loading multi-MB files into memory.\n * Falls back to full read for small files (< 32KB).\n */\nexport async function readJsonlTail<T>(filePath: string, count: number): Promise<T[]> {\n try {\n const stat = await fs.stat(filePath);\n // For small files, read directly and slice (avoid mutual recursion with readJsonl)\n if (stat.size < 32768) {\n return (await readAndParseJsonl<T>(filePath)).slice(-count);\n }\n\n // Read from end in chunks to find enough lines\n // Use larger chunks for bigger files (tool_result events can be 8KB+ per line)\n const fd = await fs.open(filePath, 'r');\n try {\n const chunkSize = Math.min(stat.size, stat.size > 1_048_576 ? 131072 : 65536);\n let position = Math.max(0, stat.size - chunkSize);\n let earliestReadPosition = position;\n let tail = '';\n\n // Read up to 4 chunks from the end\n for (let attempt = 0; attempt < 4 && position >= 0; attempt++) {\n earliestReadPosition = position;\n const readSize = Math.min(chunkSize, stat.size - position);\n const buf = Buffer.alloc(readSize);\n await fd.read(buf, 0, readSize, position);\n tail = buf.toString('utf-8') + tail;\n\n const lines = tail.split('\\n').filter((l) => l.trim().length > 0);\n if (lines.length >= count + 1) {\n // +1 because first line might be partial\n return parseJsonlLines<T>(lines.slice(-count));\n }\n if (position === 0) break;\n position = Math.max(0, position - chunkSize);\n }\n\n // Parse whatever we got\n const lines = tail.split('\\n').filter((l) => l.trim().length > 0);\n // Skip first line if we didn't read from start (could be partial)\n const safeLines = earliestReadPosition > 0 ? lines.slice(1) : lines;\n return parseJsonlLines<T>(safeLines.slice(-count));\n } finally {\n await fd.close();\n }\n } catch (err) {\n if (isENOENT(err)) return [];\n throw err;\n }\n}\n\n/** Read a file and parse all JSONL records. */\nasync function readAndParseJsonl<T>(filePath: string): Promise<T[]> {\n const content = await fs.readFile(filePath, 'utf-8');\n const lines = content.split('\\n').filter((l) => l.trim().length > 0);\n return parseJsonlLines<T>(lines);\n}\n\n/**\n * Parse JSONL lines with error tolerance — corrupt lines are logged and skipped.\n */\nfunction parseJsonlLines<T>(lines: string[]): T[] {\n const results: T[] = [];\n for (const raw of lines) {\n const line = raw.trim();\n if (!line) continue;\n try {\n results.push(JSON.parse(line) as T);\n } catch {\n process.stderr.write(`[readJsonl] skipping corrupt line: ${line.slice(0, 200)}\\n`);\n }\n }\n return results;\n}\n\n/**\n * Module-level cache of directories already ensured during this process lifetime.\n * Eliminates redundant fs.mkdir syscalls (~50 per tick loop).\n */\nconst ensuredDirs = new Set<string>();\n\n/**\n * Ensure a directory exists, creating it recursively if needed.\n * Uses an in-memory cache to skip redundant mkdir syscalls.\n */\nexport async function ensureDir(dirPath: string): Promise<void> {\n if (ensuredDirs.has(dirPath)) return;\n await fs.mkdir(dirPath, { recursive: true });\n ensuredDirs.add(dirPath);\n}\n\n/**\n * Clear the ensureDir cache. Intended for tests only.\n */\nexport function clearEnsuredDirs(): void {\n ensuredDirs.clear();\n}\n\n/**\n * Check if a path exists.\n */\nexport async function pathExists(filePath: string): Promise<boolean> {\n try {\n await fs.access(filePath);\n return true;\n } catch {\n return false;\n }\n}\n\n/**\n * List files in a directory matching an optional extension filter.\n */\nexport async function listFiles(dirPath: string, ext?: string): Promise<string[]> {\n try {\n const entries = await fs.readdir(dirPath);\n if (ext) {\n return entries.filter((e) => e.endsWith(ext));\n }\n return entries;\n } catch (err) {\n if (isENOENT(err)) return [];\n throw err;\n }\n}\n\nfunction isENOENT(err: unknown): boolean {\n return err instanceof Error && 'code' in err && (err as NodeJS.ErrnoException).code === 'ENOENT';\n}\n","/**\n * Path resolution for .orchestry/ directory.\n *\n * All path construction goes through this module.\n * Validates initialization state and sanitizes identifiers.\n */\n\nimport path from 'node:path';\nimport { accessSync } from 'node:fs';\nimport { NotInitializedError } from '../../domain/errors.js';\nimport { pathExists } from './fs-utils.js';\n\nexport const ORCHESTRY_DIR = '.orchestry';\nconst ID_PATTERN = /^[A-Za-z0-9._-]+$/;\n\nexport class Paths {\n constructor(private readonly projectRoot: string) {}\n\n /** Root .orchestry/ directory */\n get root(): string {\n return path.join(this.projectRoot, ORCHESTRY_DIR);\n }\n\n get configPath(): string {\n return path.join(this.root, 'config.yml');\n }\n\n get statePath(): string {\n return path.join(this.root, 'state.json');\n }\n\n get lockPath(): string {\n return path.join(this.root, 'orchestry.lock');\n }\n\n get tasksDir(): string {\n return path.join(this.root, 'tasks');\n }\n\n get agentsDir(): string {\n return path.join(this.root, 'agents');\n }\n\n get runsDir(): string {\n return path.join(this.root, 'runs');\n }\n\n get templatesDir(): string {\n return path.join(this.root, 'templates');\n }\n\n get logsDir(): string {\n return path.join(this.root, 'logs');\n }\n\n get contextDir(): string {\n return path.join(this.root, 'context');\n }\n\n contextPath(key: string): string {\n return path.join(this.contextDir, `${sanitizeId(key)}.json`);\n }\n\n get messagesDir(): string {\n return path.join(this.root, 'messages');\n }\n\n messagePath(id: string): string {\n return path.join(this.messagesDir, `${sanitizeId(id)}.json`);\n }\n\n get goalsDir(): string {\n return path.join(this.root, 'goals');\n }\n\n goalPath(id: string): string {\n return path.join(this.goalsDir, `${sanitizeId(id)}.yml`);\n }\n\n get teamsDir(): string {\n return path.join(this.root, 'teams');\n }\n\n get attachmentsDir(): string {\n return path.join(this.root, 'attachments');\n }\n\n taskAttachmentsDir(taskId: string): string {\n return path.join(this.attachmentsDir, sanitizeId(taskId));\n }\n\n teamPath(id: string): string {\n return path.join(this.teamsDir, `${sanitizeId(id)}.yml`);\n }\n\n get gitignorePath(): string {\n return path.join(this.root, '.gitignore');\n }\n\n get workspaceExcludePath(): string {\n return path.join(this.root, 'workspace-exclude');\n }\n\n taskPath(id: string): string {\n return path.join(this.tasksDir, `${sanitizeId(id)}.yml`);\n }\n\n agentPath(id: string): string {\n return path.join(this.agentsDir, `${sanitizeId(id)}.yml`);\n }\n\n runPath(id: string): string {\n return path.join(this.runsDir, `${sanitizeId(id)}.json`);\n }\n\n runEventsPath(id: string): string {\n return path.join(this.runsDir, `${sanitizeId(id)}.jsonl`);\n }\n\n defaultTemplatePath(): string {\n return path.join(this.templatesDir, 'default.md');\n }\n\n async isInitialized(): Promise<boolean> {\n return pathExists(this.root);\n }\n\n async requireInit(): Promise<void> {\n if (!(await this.isInitialized())) {\n throw new NotInitializedError();\n }\n }\n}\n\n/**\n * Validate an identifier for use in file paths.\n * Only allows [A-Za-z0-9._-] characters.\n * Rejects identifiers containing forbidden characters (path separators, etc.)\n * to prevent path traversal attacks.\n */\nexport function sanitizeId(id: string): string {\n if (!ID_PATTERN.test(id)) {\n throw new Error(`Invalid identifier: \"${id}\"`);\n }\n return id;\n}\n\n/**\n * Validate that a workspace path is within the project root.\n * Prevents path traversal attacks.\n */\nexport function validateWorkspacePath(workspacePath: string, projectRoot: string): void {\n const resolved = path.resolve(workspacePath);\n const root = path.resolve(projectRoot);\n\n if (!resolved.startsWith(root + path.sep) && resolved !== root) {\n throw new Error(`Workspace path \"${workspacePath}\" is outside project root`);\n }\n}\n\n/**\n * Module-level cache for findProjectRoot().\n * Key: resolved startDir, Value: found project root.\n * Avoids repeated accessSync() traversals on every CLI invocation.\n */\nconst projectRootCache = new Map<string, string>();\n\n/**\n * Resolve project root by walking up from cwd looking for .orchestry/.\n * Returns cwd if not found (for init command).\n *\n * Results are cached per startDir to avoid redundant filesystem traversals.\n */\nexport function findProjectRoot(startDir: string = process.cwd()): string {\n const resolvedStart = path.resolve(startDir);\n const cached = projectRootCache.get(resolvedStart);\n if (cached !== undefined) return cached;\n\n let dir = resolvedStart;\n const root = path.parse(dir).root;\n\n while (dir !== root) {\n try {\n accessSync(path.join(dir, '.orchestry'));\n projectRootCache.set(resolvedStart, dir);\n return dir;\n } catch {\n // Not found, go up\n }\n dir = path.dirname(dir);\n }\n\n // Not found — return resolved dir (for init command)\n projectRootCache.set(resolvedStart, resolvedStart);\n return resolvedStart;\n}\n\n/**\n * Clear the findProjectRoot cache.\n * Useful in tests or after `orch init` changes the project structure.\n */\nexport function clearProjectRootCache(): void {\n projectRootCache.clear();\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/infrastructure/adapters/utils.ts"],"names":[],"mappings":";;;;;AAcO,SAAS,eAAA,CAAgB,cAAkC,UAAA,EAA4B;AAC5F,EAAA,OAAO,YAAA,GAAe,YAAA,GAAe,MAAA,GAAS,UAAA,GAAa,UAAA;AAC7D;AAQO,SAAS,aAAA,CACd,QACA,IAAA,EACwB;AACxB,EAAA,IAAI,QAAQ,MAAA,CAAO,KAAA;AAEnB,EAAA,IAAI,CAAC,KAAA,IAAS,IAAA,EAAM,aAAA,EAAe;AACjC,IAAA,MAAM,QAAQ,MAAA,CAAO,KAAA;AACrB,IAAA,KAAA,GAAQ,KAAA,EAAO,KAAA;AAAA,EACjB;AAEA,EAAA,IAAI,KAAA,IAAS,OAAO,KAAA,CAAM,YAAA,KAAiB,QAAA,EAAU;AACnD,IAAA,MAAM,QAAQ,KAAA,CAAM,YAAA;AACpB,IAAA,MAAM,SAAS,OAAO,KAAA,CAAM,aAAA,KAAkB,QAAA,GAAW,MAAM,aAAA,GAAgB,CAAA;AAC/E,IAAA,MAAM,YAAY,OAAO,KAAA,CAAM,gBAAA,KAAqB,QAAA,GAAW,MAAM,gBAAA,GAAmB,CAAA;AACxF,IAAA,MAAM,aAAa,OAAO,KAAA,CAAM,uBAAA,KAA4B,QAAA,GAAW,MAAM,uBAAA,GAA0B,CAAA;AACvG,IAAA,MAAM,cAAc,OAAO,KAAA,CAAM,2BAAA,KAAgC,QAAA,GAAW,MAAM,2BAAA,GAA8B,CAAA;AAChH,IAAA,OAAO,iBAAiB,KAAA,EAAO,MAAA,EAAQ,EAAE,SAAA,EAAW,UAAA,EAAY,aAAa,CAAA;AAAA,EAC/E;AACA,EAAA,OAAO,MAAA;AACT;AAYO,SAAS,qBAAA,CACd,IAAA,EACA,UAAA,EACA,WAA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AAO,CAAA,EAAG,EAAE,SAAA,EAAW,UAAA,EAAY,CAAA;AAChF,MAAA,MAAM,GAAA;AAAA,IACR;AACA,IAAA,IAAI,QAAA,KAAa,KAAK,QAAA,KAAa,IAAA,IAAQ,CAAC,MAAA,EAAQ,OAAA,IAAW,CAAC,YAAA,EAAc;AAC5E,MAAA,MAAM,GAAA,GAAM,CAAA,EAAG,WAAW,CAAA,0BAAA,EAA6B,QAAQ,CAAA,CAAA;AAC/D,MAAA,MAAM,UAAA,GAAa,oBAAA,CAAqB,GAAA,EAAK,QAAQ,CAAA;AACrD,MAAA,MAAM,GAAA,GAAM,MAAA,CAAO,MAAA,CAAO,IAAI,KAAA,CAAM,GAAG,CAAA,EAAG,EAAE,SAAA,EAAW,UAAA,EAAY,CAAA;AACnE,MAAA,MAAM,GAAA;AAAA,IACR;AAAA,EACF;AAEA,EAAA,OAAO,QAAA,EAAS;AAClB","file":"chunk-MOWC2CHX.js","sourcesContent":["/**\n * Shared utilities for agent adapters.\n *\n * Deduplicates extractTokens and streaming event generation logic\n * common to claude, codex, and cursor adapters.\n */\n\nimport type { ChildProcess } from 'node:child_process';\nimport type { AgentEvent } from './interface.js';\nimport { readLines } from '../process/process-manager.js';\nimport { type TokenUsage, createTokenUsage } from '../../domain/run.js';\nimport { classifyAdapterError } from '../../domain/errors.js';\n\n/** Combine system and user prompts. Adapters without native system prompt support use this. */\nexport function buildFullPrompt(systemPrompt: string | undefined, userPrompt: string): string {\n return systemPrompt ? systemPrompt + '\\n\\n' + userPrompt : userPrompt;\n}\n\n/**\n * Extract token usage from a parsed JSON event.\n *\n * @param parsed - The parsed JSON object from an adapter event line.\n * @param opts.statsFallback - If true, also checks `parsed.stats?.usage` (Claude-specific).\n */\nexport function extractTokens(\n parsed: Record<string, unknown>,\n opts?: { statsFallback?: boolean },\n): TokenUsage | undefined {\n let usage = parsed.usage as Record<string, unknown> | undefined;\n\n if (!usage && opts?.statsFallback) {\n const stats = parsed.stats as Record<string, unknown> | undefined;\n usage = stats?.usage as Record<string, unknown> | undefined;\n }\n\n if (usage && typeof usage.input_tokens === 'number') {\n const input = usage.input_tokens;\n const output = typeof usage.output_tokens === 'number' ? usage.output_tokens : 0;\n const reasoning = typeof usage.reasoning_tokens === 'number' ? usage.reasoning_tokens : 0;\n const cache_read = typeof usage.cache_read_input_tokens === 'number' ? usage.cache_read_input_tokens : 0;\n const cache_write = typeof usage.cache_creation_input_tokens === 'number' ? usage.cache_creation_input_tokens : 0;\n return createTokenUsage(input, output, { reasoning, cache_read, cache_write });\n }\n return undefined;\n}\n\n/**\n * Create an async generator that streams AgentEvents from a child process.\n *\n * Handles: exit promise setup, line-by-line reading, abort signal, exit code checking.\n *\n * @param proc - The spawned child process.\n * @param parseEvent - Adapter-specific function to parse a line into an AgentEvent.\n * @param adapterName - Name used in error messages (e.g. \"Claude\", \"Codex\").\n * @param signal - Optional abort signal.\n */\nexport function createStreamingEvents(\n proc: ChildProcess,\n parseEvent: (line: string) => AgentEvent | null,\n adapterName: string,\n signal?: AbortSignal,\n): AsyncGenerator<AgentEvent> {\n async function* generate(): AsyncGenerator<AgentEvent> {\n let gotDoneEvent = false;\n\n let exitCode: number | null = null;\n let exitError: Error | null = null;\n const exitPromise = new Promise<void>((resolve) => {\n proc.on('close', (code) => { exitCode = code; resolve(); });\n proc.on('error', (err) => { exitError = err; resolve(); });\n });\n\n if (proc.stdout) {\n for await (const line of readLines(proc.stdout)) {\n if (signal?.aborted) break;\n const event = parseEvent(line);\n if (event) {\n if (event.type === 'done') gotDoneEvent = true;\n yield event;\n }\n }\n }\n\n await exitPromise;\n\n if (exitError && !signal?.aborted && !gotDoneEvent) {\n const spawnErr = exitError as Error;\n const classified = classifyAdapterError(spawnErr.message, exitCode ?? undefined);\n const err = Object.assign(new Error(spawnErr.message), { errorKind: classified });\n throw err;\n }\n if (exitCode !== 0 && exitCode !== null && !signal?.aborted && !gotDoneEvent) {\n const msg = `${adapterName} process exited with code ${exitCode}`;\n const classified = classifyAdapterError(msg, exitCode);\n const err = Object.assign(new Error(msg), { errorKind: classified });\n throw err;\n }\n }\n\n return generate();\n}\n"]}
|
package/dist/chunk-QNZ6D63E.js
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import {a}from'./chunk-P4JTJBWO.js';import {n}from'./chunk-IKNBPOQL.js';import {b as b$1}from'./chunk-6MJ7V6VY.js';function b(t,s){return t?t+`
|
|
3
|
-
|
|
4
|
-
`+s:s}function w(t,s){let e=t.usage;if(!e&&s?.statsFallback&&(e=t.stats?.usage),e&&typeof e.input_tokens=="number"){let i=e.input_tokens,u=typeof e.output_tokens=="number"?e.output_tokens:0,a$1=typeof e.reasoning_tokens=="number"?e.reasoning_tokens:0,o=typeof e.cache_read_input_tokens=="number"?e.cache_read_input_tokens:0,c=typeof e.cache_creation_input_tokens=="number"?e.cache_creation_input_tokens:0;return a(i,u,{reasoning:a$1,cache_read:o,cache_write:c})}}function y(t,s,e,i){async function*u(){let a=false,o=null,c=null,g=new Promise(r=>{t.on("close",n=>{o=n,r();}),t.on("error",n=>{c=n,r();});});if(t.stdout)for await(let r of b$1(t.stdout)){if(i?.aborted)break;let n=s(r);n&&(n.type==="done"&&(a=true),yield n);}if(await g,c&&!i?.aborted&&!a){let r=c,n$1=n(r.message,o??void 0);throw Object.assign(new Error(r.message),{errorKind:n$1})}if(o!==0&&o!==null&&!i?.aborted&&!a){let r=`${e} process exited with code ${o}`,n$1=n(r,o);throw Object.assign(new Error(r),{errorKind:n$1})}}return u()}export{b as a,w as b,y as c};
|