vibora 4.7.1 → 4.7.2

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.
@@ -110,7 +110,7 @@ ${n.map(([a,s])=>{const o=s.theme?.[r]||s.color;return o?` --color-${a}: ${o};`
110
110
  `)}
111
111
  }
112
112
  `).join(`
113
- `)}}):null},WX=zo;function VX({active:e,payload:t,className:n,indicator:r="dot",hideLabel:i=!1,hideIndicator:a=!1,label:s,labelFormatter:o,labelClassName:l,formatter:u,color:f,nameKey:d,labelKey:p}){const{config:m}=QHe(),E=k.useMemo(()=>{if(i||!t?.length)return null;const[g]=t,y=`${p||g?.dataKey||g?.name||"value"}`,v=GX(m,g,y),x=!p&&typeof s=="string"?m[s]?.label||s:v?.label;return o?b.jsx("div",{className:Be("font-medium",l),children:o(x,t)}):x?b.jsx("div",{className:Be("font-medium",l),children:x}):null},[s,o,t,i,l,m,p]);if(!e||!t?.length)return null;const S=t.length===1&&r!=="dot";return b.jsxs("div",{className:Be("border-border/50 bg-background gap-1.5 rounded-lg border px-2.5 py-1.5 text-xs/relaxed shadow-xl grid min-w-[8rem] items-start",n),children:[S?null:E,b.jsx("div",{className:"grid gap-1.5",children:t.filter(g=>g.type!=="none").map((g,y)=>{const v=`${d||g.name||g.dataKey||"value"}`,x=GX(m,g,v),T=f||g.payload.fill||g.color;return b.jsx("div",{className:Be("[&>svg]:text-muted-foreground flex w-full flex-wrap items-stretch gap-2 [&>svg]:h-2.5 [&>svg]:w-2.5",r==="dot"&&"items-center"),children:u&&g?.value!==void 0&&g.name?u(g.value,g.name,g,y,g.payload):b.jsxs(b.Fragment,{children:[x?.icon?b.jsx(x.icon,{}):!a&&b.jsx("div",{className:Be("shrink-0 rounded-[2px] border-(--color-border) bg-(--color-bg)",{"h-2.5 w-2.5":r==="dot","w-1":r==="line","w-0 border-[1.5px] border-dashed bg-transparent":r==="dashed","my-0.5":S&&r==="dashed"}),style:{"--color-bg":T,"--color-border":T}}),b.jsxs("div",{className:Be("flex flex-1 justify-between leading-none",S?"items-end":"items-center"),children:[b.jsxs("div",{className:"grid gap-1.5",children:[S?E:null,b.jsx("span",{className:"text-muted-foreground",children:x?.label||g.name})]}),g.value&&b.jsx("span",{className:"text-foreground font-mono font-medium tabular-nums",children:g.value.toLocaleString()})]})]})},g.dataKey)})})]})}function GX(e,t,n){if(typeof t!="object"||t===null)return;const r="payload"in t&&typeof t.payload=="object"&&t.payload!==null?t.payload:void 0;let i=n;return n in t&&typeof t[n]=="string"?i=t[n]:r&&n in r&&typeof r[n]=="string"&&(i=r[n]),i in e?e[i]:e[n]}const ku="";function eWe(e="vibora"){return qn({queryKey:["monitoring","claude-instances",e],queryFn:()=>zt(`${ku}/api/monitoring/claude-instances?filter=${e}`),refetchInterval:5e3})}function tWe(e="1h"){return qn({queryKey:["monitoring","system-metrics",e],queryFn:()=>zt(`${ku}/api/monitoring/system-metrics?window=${e}`),refetchInterval:5e3})}function nWe(){const e=wr();return Fn({mutationFn:({terminalId:t,pid:n})=>{if(t)return zt(`${ku}/api/monitoring/claude-instances/${t}/kill`,{method:"POST"});if(n)return zt(`${ku}/api/monitoring/claude-instances/${n}/kill-pid`,{method:"POST"});throw new Error("Either terminalId or pid must be provided")},onSuccess:()=>{e.invalidateQueries({queryKey:["monitoring","claude-instances"]})}})}function _b(e){if(e===0)return"0 B";const t=1024,n=["B","KB","MB","GB","TB"],r=Math.floor(Math.log(e)/Math.log(t));return`${parseFloat((e/Math.pow(t,r)).toFixed(1))} ${n[r]}`}function qX(e){return{"1m":"1 min","10m":"10 min","1h":"1 hour","3h":"3 hours","6h":"6 hours","12h":"12 hours","24h":"24 hours"}[e]}function rWe(e="memory",t=10){return qn({queryKey:["monitoring","top-processes",e,t],queryFn:()=>zt(`${ku}/api/monitoring/top-processes?sort=${e}&limit=${t}`),refetchInterval:5e3})}function iWe(){return qn({queryKey:["monitoring","docker-stats"],queryFn:()=>zt(`${ku}/api/monitoring/docker-stats`),refetchInterval:5e3})}function aWe(){return qn({queryKey:["monitoring","vibora-instances"],queryFn:()=>zt(`${ku}/api/monitoring/vibora-instances`),refetchInterval:5e3})}function sWe(){const e=wr();return Fn({mutationFn:({backendPid:t})=>zt(`${ku}/api/monitoring/vibora-instances/${t}/kill`,{method:"POST"}),onSuccess:()=>{e.invalidateQueries({queryKey:["monitoring","vibora-instances"]})}})}function oWe(){return qn({queryKey:["monitoring","claude-usage"],queryFn:()=>zt(`${ku}/api/monitoring/claude-usage`),refetchInterval:5e3})}const lWe=["system","processes","claude","vibora","worktrees","usage"],$le=js("/monitoring/")({component:yWe,validateSearch:e=>({tab:lWe.includes(e.tab)?e.tab:void 0})}),KX=["1m","10m","1h","3h","6h","12h","24h"],YX={cpu:{label:"CPU",color:"var(--chart-system)"},memoryUsed:{label:"Used",color:"var(--chart-system)"},memoryCache:{label:"Cache / Buffers",color:"var(--muted-foreground)"},disk:{label:"Disk",color:"var(--muted-foreground)"}};function uWe(){const{t:e}=rn("monitoring"),[t,n]=k.useState("vibora"),[r,i]=k.useState(null),[a,s]=k.useState(new Set),[o,l]=k.useState(!1),{data:u,isLoading:f,error:d}=eWe(t),p=nWe(),m=u?.reduce((x,T)=>x+T.ramMB,0)||0,E=r!==null||o;k.useEffect(()=>{r!==null&&u&&!u.some(x=>x.pid===r)&&i(null)},[r,u]),k.useEffect(()=>{if(a.size>0&&u){const x=new Set([...a].filter(T=>u.some(w=>w.pid===T)));x.size!==a.size&&s(x)}},[a,u]);const S=x=>{i(x.pid);const T=x.isViboraManaged&&x.terminalId?{terminalId:x.terminalId}:{pid:x.pid};p.mutate(T,{onError:()=>i(null)})},g=x=>{s(T=>{const w=new Set(T);return w.has(x)?w.delete(x):w.add(x),w})},y=()=>{u&&(a.size===u.length?s(new Set):s(new Set(u.map(x=>x.pid))))},v=async()=>{if(!u||a.size===0)return;l(!0);const x=u.filter(T=>a.has(T.pid));for(const T of x){const w=T.isViboraManaged&&T.terminalId?{terminalId:T.terminalId}:{pid:T.pid};try{await p.mutateAsync(w)}catch{}}s(new Set),l(!1)};return b.jsxs("div",{className:"space-y-4",children:[b.jsxs("div",{className:"flex items-center justify-between",children:[b.jsxs("div",{className:"flex items-center gap-4",children:[b.jsxs("div",{className:"flex items-center gap-2",children:[b.jsx($o,{id:"show-all",checked:t==="all",onCheckedChange:x=>n(x?"all":"vibora")}),b.jsx(Ute,{htmlFor:"show-all",className:"text-sm text-muted-foreground",children:e("claude.showAllInstances")})]}),a.size>0&&b.jsxs(qe,{variant:"destructive",size:"sm",onClick:v,disabled:E,className:"gap-1.5",children:[o?b.jsx(fe,{icon:tn,className:"size-3.5 animate-spin"}):b.jsx(fe,{icon:fi,className:"size-3.5"}),e("claude.killSelected",{count:a.size})]})]}),u&&b.jsxs("span",{className:"text-sm text-muted-foreground",children:[e("claude.instanceCount",{count:u.length}),m>0&&` · ${e("claude.totalRam",{ram:m.toFixed(0)})}`]})]}),f&&b.jsx("div",{className:"flex items-center justify-center py-12",children:b.jsx(fe,{icon:tn,className:"size-6 animate-spin text-muted-foreground"})}),d&&b.jsx("div",{className:"rounded-lg border border-destructive/50 bg-destructive/10 p-4 text-sm text-destructive",children:e("claude.error",{message:d.message})}),u&&u.length===0&&b.jsxs("div",{className:"py-12 text-center text-muted-foreground",children:[e("claude.empty"),t==="vibora"&&e("claude.emptyVibora")]}),u&&u.length>0&&b.jsxs("div",{className:"space-y-2",children:[b.jsxs("div",{className:"hidden lg:grid grid-cols-[32px_60px_150px_1fr_1fr_80px_80px] gap-4 px-3 py-2 text-xs font-medium text-muted-foreground",children:[b.jsx("div",{className:"flex items-center justify-center",children:b.jsx(hi,{checked:a.size===u.length,onCheckedChange:y,disabled:E})}),b.jsx("span",{children:e("claude.headers.pid")}),b.jsx("span",{children:e("claude.headers.terminal")}),b.jsx("span",{children:e("claude.headers.task")}),b.jsx("span",{children:e("claude.headers.workingDirectory")}),b.jsx("span",{className:"text-right",children:e("claude.headers.ram")}),b.jsx("span",{className:"text-right",children:e("claude.headers.actions")})]}),u.map(x=>b.jsxs(wa,{className:"px-3 py-2",children:[b.jsxs("div",{className:"flex flex-col gap-1 lg:hidden",children:[b.jsxs("div",{className:"flex items-center justify-between gap-2",children:[b.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[b.jsx(hi,{checked:a.has(x.pid),onCheckedChange:()=>g(x.pid),disabled:E,className:"shrink-0"}),b.jsx("span",{className:"text-sm font-medium truncate",children:x.taskId?b.jsx(Ai,{to:"/tasks/$taskId",params:{taskId:x.taskId},className:"hover:text-foreground hover:underline",children:x.taskTitle}):b.jsx("span",{className:"text-muted-foreground",children:x.isViboraManaged?x.terminalName:e("claude.source.external")})})]}),b.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[b.jsxs("span",{className:"tabular-nums text-sm text-muted-foreground",children:[x.ramMB.toFixed(0)," MB"]}),b.jsx(qe,{variant:"ghost",size:"xs",onClick:()=>S(x),disabled:E,className:`text-destructive hover:text-destructive hover:bg-destructive/10 ${E?"opacity-50":""}`,children:b.jsx(fe,{icon:r===x.pid?tn:fi,className:`size-3.5 ${r===x.pid?"animate-spin":""}`})})]})]}),b.jsx("span",{className:"text-xs text-muted-foreground truncate pl-6",title:x.cwd,children:x.cwd})]}),b.jsxs("div",{className:"hidden lg:grid grid-cols-[32px_60px_150px_1fr_1fr_80px_80px] items-center gap-4",children:[b.jsx("div",{className:"flex items-center justify-center",children:b.jsx(hi,{checked:a.has(x.pid),onCheckedChange:()=>g(x.pid),disabled:E})}),b.jsx("span",{className:"font-mono text-xs",children:x.pid}),b.jsx("span",{className:"truncate text-sm",children:x.isViboraManaged?b.jsx("span",{children:x.terminalName||`Terminal ${x.terminalId?.slice(0,8)}`}):b.jsx("span",{className:"text-muted-foreground",children:e("claude.source.external")})}),b.jsx("span",{className:"text-muted-foreground truncate text-sm",children:x.taskId?b.jsx(Ai,{to:"/tasks/$taskId",params:{taskId:x.taskId},className:"hover:text-foreground hover:underline",children:x.taskTitle}):e("claude.noTask")}),b.jsx("span",{className:"text-muted-foreground truncate text-sm",title:x.cwd,children:x.cwd}),b.jsxs("span",{className:"text-right tabular-nums text-sm",children:[x.ramMB.toFixed(0)," MB"]}),b.jsx("div",{className:"flex justify-end",children:b.jsxs(qe,{variant:"ghost",size:"xs",onClick:()=>S(x),disabled:E,className:`text-destructive hover:text-destructive hover:bg-destructive/10 ${E?"opacity-50":""}`,children:[b.jsx(fe,{icon:r===x.pid?tn:fi,className:`size-3.5 ${r===x.pid?"animate-spin":""}`}),r===x.pid?e("claude.killing"):e("claude.kill")]})})]})]},x.pid))]})]})}function cWe(){const{t:e}=rn("monitoring"),[t,n]=k.useState("1h"),{data:r,isLoading:i,error:a}=tWe(t),s=r?.dataPoints.map(o=>({time:new Date(o.timestamp*1e3).toLocaleTimeString(),timestamp:o.timestamp,cpu:Math.round(o.cpuPercent*10)/10,memoryUsed:Math.round(o.memoryUsedPercent*10)/10,memoryCache:Math.round(o.memoryCachePercent*10)/10}))||[];return b.jsxs("div",{className:"space-y-6",children:[b.jsx("div",{className:"sm:hidden",children:b.jsxs(Bi,{value:t,onValueChange:o=>n(o),children:[b.jsx($i,{size:"sm",className:"w-auto gap-2",children:b.jsx(Ui,{})}),b.jsx(zi,{children:KX.map(o=>b.jsx(Cn,{value:o,children:qX(o)},o))})]})}),b.jsx("div",{className:"hidden sm:flex gap-1",children:KX.map(o=>b.jsx(qe,{variant:t===o?"secondary":"ghost",size:"xs",onClick:()=>n(o),children:qX(o)},o))}),i&&b.jsx("div",{className:"flex items-center justify-center py-12",children:b.jsx(fe,{icon:tn,className:"size-6 animate-spin text-muted-foreground"})}),a&&b.jsx("div",{className:"rounded-lg border border-destructive/50 bg-destructive/10 p-4 text-sm text-destructive",children:e("system.error",{message:a.message})}),r&&b.jsxs("div",{className:"space-y-6",children:[b.jsxs(wa,{className:"p-4",children:[b.jsxs("div",{className:"mb-4 flex items-center justify-between",children:[b.jsx("h3",{className:"font-medium",children:e("system.cpuUsage")}),b.jsxs("span",{className:"text-sm text-muted-foreground tabular-nums",children:[r.current.cpu.toFixed(1),"%"]})]}),b.jsx(HX,{config:YX,className:"h-[150px] w-full",children:b.jsxs(zX,{data:s,margin:{left:0,right:0},children:[b.jsx(FL,{strokeDasharray:"3 3",vertical:!1}),b.jsx(wy,{dataKey:"time",tickLine:!1,axisLine:!1,tickMargin:8,minTickGap:40}),b.jsx(Ty,{domain:[0,100],tickLine:!1,axisLine:!1,tickMargin:8,tickFormatter:o=>`${o}%`}),b.jsx(WX,{content:b.jsx(VX,{hideLabel:!0,formatter:o=>[`${o}% `,"CPU"]})}),b.jsx(il,{type:"monotone",dataKey:"cpu",stroke:"var(--color-cpu)",fill:"var(--color-cpu)",fillOpacity:.4,strokeWidth:2})]})})]}),b.jsxs(wa,{className:"p-4",children:[b.jsxs("div",{className:"mb-4 flex items-center justify-between",children:[b.jsx("h3",{className:"font-medium",children:e("system.memoryUsage")}),b.jsxs("span",{className:"text-sm text-muted-foreground tabular-nums",children:[_b(r.current.memory.used)," ",e("system.memoryLabels.used").toLowerCase()," + ",_b(r.current.memory.cache)," ",e("system.memoryLabels.cache").toLowerCase()," / ",_b(r.current.memory.total)]})]}),b.jsx(HX,{config:YX,className:"h-[150px] w-full",children:b.jsxs(zX,{data:s,margin:{left:0,right:0},children:[b.jsx(FL,{strokeDasharray:"3 3",vertical:!1}),b.jsx(wy,{dataKey:"time",tickLine:!1,axisLine:!1,tickMargin:8,minTickGap:40}),b.jsx(Ty,{domain:[0,100],tickLine:!1,axisLine:!1,tickMargin:8,tickFormatter:o=>`${o}%`}),b.jsx(WX,{content:b.jsx(VX,{hideLabel:!0,formatter:(o,l)=>{const u=e(l==="memoryUsed"?"system.memoryLabels.used":"system.memoryLabels.cache");return[`${o}% `,u]}})}),b.jsx(il,{type:"monotone",dataKey:"memoryUsed",stroke:"var(--color-memoryUsed)",fill:"var(--color-memoryUsed)",fillOpacity:.5,strokeWidth:2,stackId:"memory"}),b.jsx(il,{type:"monotone",dataKey:"memoryCache",stroke:"var(--color-memoryCache)",fill:"var(--color-memoryCache)",fillOpacity:.4,strokeWidth:1,stackId:"memory"})]})})]}),b.jsxs(wa,{className:"p-4",children:[b.jsxs("div",{className:"mb-4 flex items-center justify-between",children:[b.jsx("h3",{className:"font-medium",children:e("system.diskUsage",{path:r.current.disk.path})}),b.jsxs("span",{className:"text-sm text-muted-foreground tabular-nums",children:[r.current.disk.usedPercent.toFixed(1),"% (",_b(r.current.disk.used)," /"," ",_b(r.current.disk.total),")"]})]}),b.jsx("div",{className:"h-4 w-full overflow-hidden rounded-full bg-muted",children:b.jsx("div",{className:"h-full bg-chart-system transition-all",style:{width:`${Math.min(r.current.disk.usedPercent,100)}%`}})})]})]})]})}function dWe(){const{t:e}=rn("monitoring"),[t,n]=k.useState("memory"),{data:r,isLoading:i,error:a}=rWe(t),{data:s,isLoading:o}=iWe();return b.jsxs("div",{className:"flex flex-col gap-6 lg:flex-row lg:items-start",children:[b.jsxs(wa,{className:"p-4 lg:flex-1 lg:min-w-0 h-[400px] flex flex-col",children:[b.jsxs("div",{className:"mb-4 flex items-center justify-between shrink-0",children:[b.jsx("h3",{className:"font-medium",children:e("processes.topProcesses")}),b.jsxs(Bi,{value:t,onValueChange:l=>n(l),children:[b.jsx($i,{className:"w-32",children:b.jsx(Ui,{})}),b.jsxs(zi,{children:[b.jsx(Cn,{value:"memory",children:e("processes.sortBy.memory")}),b.jsx(Cn,{value:"cpu",children:e("processes.sortBy.cpu")})]})]})]}),i&&b.jsx("div",{className:"flex items-center justify-center flex-1",children:b.jsx(fe,{icon:tn,className:"size-6 animate-spin text-muted-foreground"})}),a&&b.jsx("div",{className:"rounded-lg border border-destructive/50 bg-destructive/10 p-4 text-sm text-destructive",children:e("processes.error",{message:a.message})}),r&&r.length>0&&b.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto",children:b.jsxs("div",{className:"space-y-1",children:[b.jsxs("div",{className:"grid grid-cols-[60px_120px_1fr_70px_80px] gap-2 px-2 py-1 text-xs font-medium text-muted-foreground",children:[b.jsx("span",{children:e("processes.headers.pid")}),b.jsx("span",{children:e("processes.headers.name")}),b.jsx("span",{children:e("processes.headers.command")}),b.jsx("span",{className:"text-right",children:e("processes.headers.memory")}),b.jsx("span",{className:"text-right",children:"%"})]}),r.map(l=>b.jsxs("div",{className:"grid grid-cols-[60px_120px_1fr_70px_80px] gap-2 rounded px-2 py-1.5 text-sm hover:bg-muted/50",children:[b.jsx("span",{className:"font-mono text-xs text-muted-foreground",children:l.pid}),b.jsx("span",{className:"truncate font-medium",title:l.name,children:l.name}),b.jsx("span",{className:"truncate text-muted-foreground text-xs",title:l.command,children:l.command}),b.jsxs("span",{className:"text-right tabular-nums",children:[l.memoryMB.toFixed(0)," MB"]}),b.jsxs("span",{className:"text-right tabular-nums text-muted-foreground",children:[l.memoryPercent.toFixed(1),"%"]})]},l.pid))]})}),r&&r.length===0&&b.jsx("div",{className:"flex-1 flex items-center justify-center text-muted-foreground",children:e("processes.empty")})]}),b.jsxs(wa,{className:"p-4 lg:flex-1 lg:min-w-0 h-[400px] flex flex-col",children:[b.jsx("div",{className:"mb-4 flex items-center justify-between shrink-0",children:b.jsxs("h3",{className:"font-medium",children:[e("processes.containers"),s?.runtime&&b.jsxs("span",{className:"ml-2 text-xs font-normal text-muted-foreground",children:["(",s.runtime,")"]})]})}),o&&b.jsx("div",{className:"flex items-center justify-center flex-1",children:b.jsx(fe,{icon:tn,className:"size-6 animate-spin text-muted-foreground"})}),s&&!s.available&&b.jsx("div",{className:"flex-1 flex items-center justify-center text-muted-foreground",children:e("processes.containersUnavailable")}),s&&s.available&&s.containers.length===0&&b.jsx("div",{className:"flex-1 flex items-center justify-center text-muted-foreground",children:e("processes.containersEmpty")}),s&&s.available&&s.containers.length>0&&b.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto",children:b.jsxs("div",{className:"space-y-1",children:[b.jsxs("div",{className:"grid grid-cols-[1fr_70px_100px_80px] gap-2 px-2 py-1 text-xs font-medium text-muted-foreground",children:[b.jsx("span",{children:e("processes.headers.name")}),b.jsx("span",{className:"text-right",children:"CPU"}),b.jsx("span",{className:"text-right",children:e("processes.headers.memory")}),b.jsx("span",{className:"text-right",children:"%"})]}),s.containers.map(l=>b.jsxs("div",{className:"grid grid-cols-[1fr_70px_100px_80px] gap-2 rounded px-2 py-1.5 text-sm hover:bg-muted/50",children:[b.jsx("span",{className:"truncate font-medium",title:l.name,children:l.name}),b.jsxs("span",{className:"text-right tabular-nums",children:[l.cpuPercent.toFixed(1),"%"]}),b.jsxs("span",{className:"text-right tabular-nums",children:[l.memoryMB.toFixed(0)," / ",l.memoryLimit.toFixed(0)," MB"]}),b.jsxs("span",{className:"text-right tabular-nums text-muted-foreground",children:[l.memoryPercent.toFixed(1),"%"]})]},l.id))]})})]})]})}function fWe(){const{t:e}=rn("monitoring"),[t,n]=k.useState(null),{data:r,isLoading:i,error:a}=aWe(),s=sWe();k.useEffect(()=>{t!==null&&r&&!r.some(l=>l.backend?.pid===t)&&n(null)},[t,r]);const o=l=>{l.backend&&(n(l.backend.pid),s.mutate({backendPid:l.backend.pid},{onError:()=>n(null)}))};return b.jsxs("div",{className:"space-y-4",children:[b.jsxs("div",{className:"flex items-center justify-between",children:[b.jsx("span",{className:"text-sm text-muted-foreground",children:e("vibora.description")}),r&&r.length>0&&b.jsx("span",{className:"text-sm text-muted-foreground",children:e("vibora.instanceCount",{count:r.length})})]}),i&&b.jsx("div",{className:"flex items-center justify-center py-12",children:b.jsx(fe,{icon:tn,className:"size-6 animate-spin text-muted-foreground"})}),a&&b.jsx("div",{className:"rounded-lg border border-destructive/50 bg-destructive/10 p-4 text-sm text-destructive",children:e("vibora.error",{message:a.message})}),r&&r.length===0&&b.jsx("div",{className:"py-12 text-center text-muted-foreground",children:e("vibora.empty")}),r&&r.length>0&&b.jsxs("div",{className:"space-y-2",children:[b.jsxs("div",{className:"hidden lg:grid grid-cols-[80px_100px_1fr_100px_80px] gap-4 px-3 py-2 text-xs font-medium text-muted-foreground",children:[b.jsx("span",{children:e("vibora.headers.port")}),b.jsx("span",{children:e("vibora.headers.mode")}),b.jsx("span",{children:e("vibora.headers.directory")}),b.jsx("span",{className:"text-right",children:e("vibora.headers.ram")}),b.jsx("span",{className:"text-right",children:e("vibora.headers.actions")})]}),r.map(l=>{const u=t===l.backend?.pid,f=t!==null;return b.jsxs(wa,{className:"px-3 py-2",children:[b.jsxs("div",{className:"flex flex-col gap-1 lg:hidden",children:[b.jsxs("div",{className:"flex items-center justify-between gap-2",children:[b.jsxs("span",{className:"text-sm font-medium",children:[b.jsxs("span",{className:"font-mono",children:[":",l.port]}),b.jsxs("span",{className:`ml-2 text-xs ${l.mode==="development"?"text-muted-foreground":""}`,children:[l.mode==="development"?e("vibora.mode.dev"):e("vibora.mode.prod"),l.frontend&&` + ${e("vibora.vite")}`]})]}),b.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[b.jsxs("span",{className:"tabular-nums text-sm text-muted-foreground",children:[l.totalMemoryMB.toFixed(0)," MB"]}),b.jsx(qe,{variant:"ghost",size:"xs",onClick:()=>o(l),disabled:f||!l.backend,className:`text-destructive hover:text-destructive hover:bg-destructive/10 ${f?"opacity-50":""}`,children:b.jsx(fe,{icon:u?tn:fi,className:`size-3.5 ${u?"animate-spin":""}`})})]})]}),b.jsx("span",{className:"text-xs text-muted-foreground truncate",title:l.viboraDir,children:l.viboraDir})]}),b.jsxs("div",{className:"hidden lg:grid grid-cols-[80px_100px_1fr_100px_80px] items-center gap-4",children:[b.jsx("span",{className:"font-mono text-sm",children:l.port}),b.jsxs("span",{className:`text-xs ${l.mode==="development"?"text-muted-foreground":""}`,children:[l.mode==="development"?e("vibora.mode.dev"):e("vibora.mode.prod"),l.frontend&&` + ${e("vibora.vite")}`]}),b.jsx("span",{className:"text-muted-foreground truncate text-sm",title:l.viboraDir,children:l.viboraDir}),b.jsxs("span",{className:"text-right tabular-nums text-sm",children:[l.totalMemoryMB.toFixed(0)," MB"]}),b.jsx("div",{className:"flex justify-end",children:b.jsxs(qe,{variant:"ghost",size:"xs",onClick:()=>o(l),disabled:f||!l.backend,className:`text-destructive hover:text-destructive hover:bg-destructive/10 ${f?"opacity-50":""}`,children:[b.jsx(fe,{icon:u?tn:fi,className:`size-3.5 ${u?"animate-spin":""}`}),e(u?"vibora.killing":"vibora.kill")]})})]})]},l.backend?.pid||l.port)})]})]})}function hWe(e){return e>=90?"text-destructive":e>=70?"text-muted-foreground":"text-chart-system"}function pWe(e){if(e<60)return`${e}m`;const t=Math.floor(e/60),n=e%60;return n>0?`${t}h ${n}m`:`${t}h`}function WN(e){const t=new Date(e),n=new Date,r=t.getTime()-n.getTime(),i=Math.floor(r/(1e3*60*60*24));return i===0?t.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):i===1?`Tomorrow ${t.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})}`:i<7?t.toLocaleDateString([],{weekday:"short",hour:"2-digit",minute:"2-digit"}):t.toLocaleDateString([],{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}function W_({percent:e,label:t,subtitle:n,color:r}){const i=[{value:Math.min(e,100),fill:r}],a=Math.round(96*yc),s=Math.round(48*yc),o=Math.round(32*yc),l=Math.round(44*yc),u=Math.round(10*yc),f=Math.round(5*yc);return b.jsx(wa,{className:"p-4",children:b.jsxs("div",{className:"flex items-center gap-4",children:[b.jsxs("div",{className:"relative size-24 shrink-0",children:[b.jsxs(XHe,{width:a,height:a,cx:s,cy:s,innerRadius:o,outerRadius:l,barSize:u,data:i,startAngle:90,endAngle:-270,children:[b.jsx(_0,{type:"number",domain:[0,100],angleAxisId:0,tick:!1}),b.jsx(E0,{background:{fill:"var(--border)"},dataKey:"value",cornerRadius:f,angleAxisId:0})]}),b.jsx("div",{className:"absolute inset-0 flex items-center justify-center",children:b.jsxs("span",{className:`text-lg font-semibold tabular-nums ${hWe(e)}`,children:[e.toFixed(0),"%"]})})]}),b.jsxs("div",{className:"flex-1 min-w-0",children:[b.jsx("h3",{className:"text-sm font-medium truncate",children:t}),b.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:n})]})]})})}function mWe(){const{t:e}=rn("monitoring"),{data:t,isLoading:n,error:r}=oWe(),i=a=>a>=90?"var(--destructive)":a>=70?"var(--muted-foreground)":"var(--chart-system)";return b.jsxs("div",{className:"space-y-4",children:[n&&b.jsx("div",{className:"flex items-center justify-center py-12",children:b.jsx(fe,{icon:tn,className:"size-6 animate-spin text-muted-foreground"})}),r&&b.jsx("div",{className:"rounded-lg border border-destructive/50 bg-destructive/10 p-4 text-sm text-destructive",children:e("usage.error",{message:r.message})}),t&&!t.available&&b.jsx("div",{className:"rounded-lg border border-muted-foreground/50 bg-muted p-4 text-sm text-muted-foreground",children:t.error||e("usage.unavailable")}),t&&t.available&&b.jsxs("div",{className:"space-y-3",children:[b.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[t.fiveHour&&b.jsx(W_,{percent:t.fiveHour.percentUsed,label:e("usage.fiveHourBlock"),subtitle:e("usage.resetsIn",{time:pWe(t.fiveHour.timeRemainingMinutes)}),color:i(t.fiveHour.percentUsed)}),t.sevenDay&&b.jsx(W_,{percent:t.sevenDay.percentUsed,label:e("usage.sevenDayRolling"),subtitle:`${e("usage.resetsAt",{time:WN(t.sevenDay.resetAt)})} · ${e("usage.weekProgress",{percent:t.sevenDay.weekProgressPercent})}`,color:i(t.sevenDay.percentUsed)})]}),(t.sevenDayOpus||t.sevenDaySonnet)&&b.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[t.sevenDayOpus&&b.jsx(W_,{percent:t.sevenDayOpus.percentUsed,label:e("usage.opusWeekly"),subtitle:e("usage.resetsAt",{time:WN(t.sevenDayOpus.resetAt)}),color:i(t.sevenDayOpus.percentUsed)}),t.sevenDaySonnet&&b.jsx(W_,{percent:t.sevenDaySonnet.percentUsed,label:e("usage.sonnetWeekly"),subtitle:e("usage.resetsAt",{time:WN(t.sevenDaySonnet.resetAt)}),color:i(t.sevenDaySonnet.percentUsed)})]})]})]})}const VN={IN_PROGRESS:"bg-muted-foreground/20 text-muted-foreground",IN_REVIEW:"bg-primary/20 text-primary",DONE:"bg-accent/20 text-accent",CANCELED:"bg-destructive/20 text-destructive",ORPHANED:"bg-destructive/20 text-destructive"},gWe=["IN_PROGRESS","IN_REVIEW","DONE","CANCELED","ORPHANED"];function bWe(){const{t:e}=rn("common");return t=>{const n=new Date(t),i=new Date().getTime()-n.getTime(),a=Math.floor(i/1e3),s=Math.floor(a/60),o=Math.floor(s/60),l=Math.floor(o/24);return l>0?l===1?e("time.dayAgo"):e("time.daysAgo",{count:l}):o>0?o===1?e("time.hourAgo"):e("time.hoursAgo",{count:o}):s>0?s===1?e("time.minuteAgo"):e("time.minutesAgo",{count:s}):e("time.justNow")}}function vWe(){const{t:e}=rn("common"),{t}=rn("worktrees"),n=bWe(),{worktrees:r,summary:i,isLoading:a,isLoadingDetails:s,error:o,refetch:l}=wie(),u=Tie(),[f,d]=k.useState(new Set),[p,m]=k.useState(!1),[E,S]=k.useState(!1),[g,y]=k.useState(!1),[v,x]=k.useState(null),[T,w]=k.useState(null),[C,R]=k.useState(!1),O=B=>{d(q=>{const K=new Set(q);return K.has(B)?K.delete(B):K.add(B),K})},N=()=>{d(new Set)},D=k.useMemo(()=>f.size===0?r:r.filter(B=>!!(B.isOrphaned&&f.has("ORPHANED")||B.taskStatus&&f.has(B.taskStatus))),[r,f]),L=k.useMemo(()=>r.filter(B=>B.taskStatus==="DONE"||B.taskStatus==="CANCELED"),[r]),z=async()=>{if(L.length!==0){S(!0);try{for(const B of L)await u.mutateAsync({worktreePath:B.path,repoPath:B.repoPath,deleteLinkedTask:g});m(!1),l()}catch{}finally{S(!1)}}},M=async(B,q)=>{x(B.path);try{await u.mutateAsync({worktreePath:B.path,repoPath:B.repoPath,deleteLinkedTask:q}),w(null),l()}catch{}finally{x(null)}},V=B=>{B||(w(null),R(!1))},H=B=>{m(B),B||y(!1)};return b.jsxs("div",{className:"space-y-4",children:[b.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[b.jsx("div",{className:"flex items-center gap-3 text-sm text-muted-foreground",children:(i||r.length>0)&&b.jsxs(b.Fragment,{children:[b.jsx("span",{children:t("summary.total",{count:i?.total??r.length})}),(i?.orphaned??r.filter(B=>B.isOrphaned).length)>0&&b.jsx("span",{className:"text-destructive",children:t("summary.orphaned",{count:i?.orphaned??r.filter(B=>B.isOrphaned).length})}),s?b.jsx("span",{className:"animate-pulse",children:e("status.calculating")}):i?b.jsx("span",{children:i.totalSizeFormatted}):null]})}),b.jsxs("div",{className:"flex items-center gap-2",children:[L.length>0&&b.jsxs(go,{open:p,onOpenChange:H,children:[b.jsxs(wu,{render:b.jsx(qe,{variant:"ghost",size:"sm",className:"gap-1.5 text-xs text-muted-foreground hover:text-destructive",disabled:s}),children:[b.jsx(fe,{icon:hte,size:12,strokeWidth:2}),t("cleanup.button",{count:L.length})]}),b.jsxs(bo,{children:[b.jsxs(vo,{children:[b.jsx(_o,{children:t("cleanup.title")}),b.jsxs(Eo,{children:[t("cleanup.description",{count:L.length}),g&&` ${t("cleanup.linkedTasksWillBeDeleted")}`]}),b.jsxs("div",{className:"space-y-3",children:[b.jsxs("label",{className:"flex items-center gap-2 text-sm text-foreground",children:[b.jsx(hi,{checked:g,onCheckedChange:B=>y(B===!0),disabled:E}),t("cleanup.alsoDeleteLinkedTasks")]}),b.jsx("p",{className:"font-medium text-destructive text-xs",children:t("cleanup.cannotUndo")})]})]}),b.jsxs(yo,{children:[b.jsx(So,{disabled:E,children:e("buttons.cancel")}),b.jsxs(qe,{variant:"destructive",onClick:z,disabled:E,className:"gap-2",children:[E&&b.jsx(fe,{icon:tn,size:14,strokeWidth:2,className:"animate-spin"}),E?e("status.deleting"):t("delete.button",{count:L.length})]})]})]})]}),f.size>0&&b.jsxs(qe,{variant:"ghost",size:"sm",onClick:N,className:"gap-1.5 text-xs",children:[b.jsx(fe,{icon:fi,size:12,strokeWidth:2}),e("buttons.clearFilters")]})]})]}),b.jsx("div",{className:"flex flex-wrap items-center gap-1.5",children:gWe.map(B=>{const q=f.has(B);return b.jsx("button",{onClick:()=>O(B),className:Be("rounded-full px-2.5 py-1 text-xs font-medium transition-colors",q?VN[B]:"bg-muted text-muted-foreground hover:bg-muted/80"),children:e(`statuses.${B}`)},B)})}),a&&b.jsx("div",{className:"flex items-center justify-center py-12",children:b.jsx(fe,{icon:tn,className:"size-6 animate-spin text-muted-foreground"})}),o&&b.jsx("div",{className:"rounded-lg border border-destructive/50 bg-destructive/10 p-4 text-sm text-destructive",children:t("error.failedToLoad",{message:o.message})}),!a&&!o&&D.length===0&&b.jsx("div",{className:"py-12 text-center text-muted-foreground",children:f.size>0?t("empty.noMatch"):t("empty.noWorktrees")}),!a&&D.length>0&&b.jsx("div",{className:"grid grid-cols-1 gap-2 sm:grid-cols-2 xl:grid-cols-3",children:D.map(B=>{const q=B.sizeFormatted==="..."||B.branch==="...",K=!B.isOrphaned&&B.taskId,U=v===B.path;return b.jsx(wa,{className:"transition-colors hover:border-border/80",children:b.jsxs(Mf,{className:"flex items-start justify-between gap-4 py-4",children:[b.jsxs("div",{className:"min-w-0 flex-1 space-y-2",children:[b.jsxs("div",{className:"flex items-center gap-2",children:[b.jsx("span",{className:"truncate font-medium",children:B.name}),B.isOrphaned?b.jsx(co,{className:Be("shrink-0",VN.ORPHANED),children:e("statuses.ORPHANED")}):B.taskStatus?b.jsx(co,{className:Be("shrink-0",VN[B.taskStatus]),children:e(`statuses.${B.taskStatus}`)}):null]}),b.jsxs("div",{className:"space-y-1 text-xs text-muted-foreground",children:[b.jsxs("div",{className:"flex items-center gap-1.5",children:[b.jsx(fe,{icon:Vi,size:12,strokeWidth:2,className:"shrink-0"}),b.jsx("span",{className:"truncate font-mono",children:B.path})]}),b.jsxs("div",{className:"flex flex-wrap items-center gap-x-4 gap-y-1",children:[b.jsxs("div",{className:"flex items-center gap-1.5",children:[b.jsx(fe,{icon:Vx,size:12,strokeWidth:2,className:"shrink-0"}),B.branch==="..."?b.jsx("span",{className:"inline-block animate-pulse rounded bg-muted h-3 w-16"}):b.jsx("span",{className:"font-mono",children:B.branch})]}),b.jsxs("div",{className:"flex items-center gap-1.5",children:[b.jsx(fe,{icon:mte,size:12,strokeWidth:2,className:"shrink-0"}),B.sizeFormatted==="..."?b.jsx("span",{className:"inline-block animate-pulse rounded bg-muted h-3 w-12"}):b.jsx("span",{children:B.sizeFormatted})]}),b.jsxs("div",{className:"flex items-center gap-1.5",children:[b.jsx(fe,{icon:cte,size:12,strokeWidth:2,className:"shrink-0"}),b.jsx("span",{children:n(B.lastModified)})]})]}),B.taskId&&B.taskTitle&&b.jsx("div",{className:"flex items-center gap-1.5 pt-1",children:b.jsxs(Ai,{to:"/tasks/$taskId",params:{taskId:B.taskId},className:"inline-flex items-center gap-1 text-foreground hover:underline",children:[b.jsx("span",{className:"truncate",children:B.taskTitle}),b.jsx(fe,{icon:Xy,size:12,strokeWidth:2,className:"shrink-0"})]})})]})]}),b.jsxs(go,{open:T?.path===B.path,onOpenChange:V,children:[b.jsx(wu,{render:b.jsx(qe,{variant:"ghost",size:"icon-sm",className:"shrink-0 text-muted-foreground hover:text-destructive",disabled:q||U,onClick:()=>w(B)}),children:b.jsx(fe,{icon:U?tn:bu,size:14,strokeWidth:2,className:U?"animate-spin":""})}),b.jsxs(bo,{children:[b.jsxs(vo,{children:[b.jsx(_o,{children:t("delete.title")}),b.jsxs(Eo,{children:[t("delete.description")," ",b.jsx("span",{className:"font-mono",children:B.name}),".",C&&K&&b.jsxs(b.Fragment,{children:[" ",t("delete.linkedTaskWillBeDeleted",{title:B.taskTitle})]})," ",t("delete.cannotUndo")]}),K&&b.jsxs("label",{className:"flex items-center gap-2 text-sm text-foreground",children:[b.jsx(hi,{checked:C,onCheckedChange:j=>R(j===!0),disabled:U}),t("delete.alsoDeleteLinkedTask",{title:B.taskTitle})]})]}),b.jsxs(yo,{children:[b.jsx(So,{disabled:U,children:e("buttons.cancel")}),b.jsxs(qe,{variant:"destructive",onClick:()=>M(B,C),disabled:U,className:"gap-2",children:[U&&b.jsx(fe,{icon:tn,size:14,strokeWidth:2,className:"animate-spin"}),e(U?"status.deleting":"buttons.delete")]})]})]})]})]})},B.path)})})]})}function yWe(){const{t:e}=rn("monitoring"),{data:t}=Bne(),n=Ri(),{tab:r}=$le.useSearch(),i=r||"system",a=k.useCallback(l=>{n({to:"/monitoring",search:l==="system"?{}:{tab:l},replace:!0})},[n]),o=[{value:"system",label:e("tabs.system")},{value:"processes",label:e("tabs.processes")},{value:"claude",label:e("tabs.claude")},{value:"vibora",label:e("tabs.vibora"),devOnly:!0},{value:"worktrees",label:e("tabs.worktrees")},{value:"usage",label:e("tabs.usage")}].filter(l=>!l.devOnly||t?.enabled);return b.jsxs("div",{className:"flex h-full flex-col overflow-hidden",children:[b.jsxs("div",{className:"flex shrink-0 items-center border-b border-border bg-background px-4 py-2",children:[b.jsx("div",{className:"sm:hidden",children:b.jsxs(Bi,{value:i,onValueChange:l=>a(l),children:[b.jsx($i,{size:"sm",className:"w-auto gap-2",children:b.jsx(Ui,{})}),b.jsx(zi,{children:o.map(l=>b.jsx(Cn,{value:l.value,children:l.label},l.value))})]})}),b.jsx("div",{className:"hidden sm:block",children:b.jsx(Zo,{value:i,onValueChange:l=>a(l),children:b.jsx(Qo,{variant:"line",children:o.map(l=>b.jsx(Wr,{value:l.value,className:"px-3 py-1.5",children:l.label},l.value))})})})]}),b.jsxs("div",{className:"flex-1 overflow-auto p-4",children:[i==="system"&&b.jsx(cWe,{}),i==="processes"&&b.jsx(dWe,{}),i==="claude"&&b.jsx(uWe,{}),i==="vibora"&&t?.enabled&&b.jsx(fWe,{}),i==="worktrees"&&b.jsx(vWe,{}),i==="usage"&&b.jsx(mWe,{})]})]})}const _We=()=>"http://localhost:3000",Eb={activeTab:"diff",browserUrl:_We(),diffOptions:{wrap:!0,ignoreWhitespace:!0,includeUntracked:!1,collapsedFiles:[]},filesViewState:{selectedFile:null,expandedDirs:[]}};function g5(e){const t=wr(),n=k.useRef(void 0),r=k.useRef({}),{data:i}=Mne(e),a=k.useMemo(()=>{const p=i?.viewState;return p?{activeTab:p.activeTab??Eb.activeTab,browserUrl:p.browserUrl??Eb.browserUrl,diffOptions:{...Eb.diffOptions,...p.diffOptions},filesViewState:{...Eb.filesViewState,...p.filesViewState}}:Eb},[i?.viewState]),s=Fn({mutationFn:async p=>{const m=await fetch(`/api/tasks/${e}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({viewState:p})});if(!m.ok)throw new Error("Failed to update view state");return m.json()},onSuccess:p=>{t.setQueryData(["tasks",e],p),t.setQueryData(["tasks"],m=>m&&m.map(E=>E.id===e?p:E))}}),o=k.useCallback(p=>{const m=r.current;r.current={...m,...p,diffOptions:p.diffOptions||m.diffOptions?{...m.diffOptions,...p.diffOptions}:void 0,filesViewState:p.filesViewState||m.filesViewState?{...m.filesViewState,...p.filesViewState}:void 0};const E=r.current,S={activeTab:E.activeTab??a.activeTab,browserUrl:E.browserUrl??a.browserUrl,diffOptions:{...a.diffOptions,...E.diffOptions},filesViewState:{...a.filesViewState,...E.filesViewState}};t.setQueryData(["tasks",e],g=>g&&{...g,viewState:S}),t.setQueryData(["tasks"],g=>g&&g.map(y=>y.id===e?{...y,viewState:S}:y)),n.current&&clearTimeout(n.current),n.current=setTimeout(()=>{s.mutate(S),r.current={}},500)},[t,e,a,s]),l=k.useCallback(p=>{o({activeTab:p})},[o]),u=k.useCallback(p=>{o({browserUrl:p})},[o]),f=k.useCallback(p=>{o({diffOptions:p})},[o]),d=k.useCallback(p=>{o({filesViewState:p})},[o]);return{viewState:a,setActiveTab:l,setBrowserUrl:u,setDiffOptions:f,setFilesViewState:d}}function EWe(e){return qn({queryKey:["linear-ticket",e],queryFn:async()=>{if(!e)return null;const t=await fetch(`/api/linear/ticket/${e}`);return t.ok?t.json():null},enabled:!!e,staleTime:300*1e3})}function SWe(e){return{id:e.id,name:e.name,cwd:e.cwd,status:e.status,exitCode:e.exitCode,cols:e.cols,rows:e.rows,createdAt:e.createdAt,tabId:e.tabId??void 0,positionInTab:e.positionInTab}}function xWe(e){return{id:e.id,name:e.name,position:e.position,directory:e.directory??void 0,createdAt:e.createdAt}}function b5(e={}){const t=bie();return{get terminals(){return t.terminals.map(SWe)},get terminalsLoaded(){return t.terminalsLoaded},get tabs(){return t.tabs.map(xWe)},get connected(){return t.connected},get newTerminalIds(){return t.newTerminalIds},createTerminal:t.createTerminal,destroyTerminal:t.destroyTerminal,writeToTerminal:t.writeToTerminal,sendInputToTerminal:t.sendInputToTerminal,resizeTerminal:t.resizeTerminal,renameTerminal:t.renameTerminal,clearTerminalBuffer:t.clearTerminalBuffer,assignTerminalToTab:t.assignTerminalToTab,createTab:t.createTab,updateTab:t.updateTab,deleteTab:t.deleteTab,reorderTab:t.reorderTab,attachXterm:t.attachXterm,setupImagePaste:t.setupImagePaste,consumePendingStartup:t.consumePendingStartup,clearStartingUp:t.clearStartingUp}}function V_(e){return`$'${e.replace(/\\/g,"\\\\").replace(/'/g,"\\'").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/\t/g,"\\t")}'`}function XX({taskName:e,cwd:t,className:n,aiMode:r,description:i,startupScript:a,serverPort:s=7777}){const o=k.useRef(null),l=k.useRef(null),u=k.useRef(null),f=k.useRef(!1),d=k.useRef(!1),[p,m]=k.useState(null),[E,S]=k.useState(!1),[g,y]=k.useState(!1),[v,x]=k.useState(!1),[T,w]=k.useState(!1),{resolvedTheme:C}=Kc(),R=C==="dark",O=R?Vie:Wie;k.useEffect(()=>{At.taskTerminal.debug("cwd changed, resetting refs",{cwd:t}),f.current=!1,d.current=!1,m(null),S(!1)},[t]);const{setTerminalFocused:N}=vM(),{terminals:D,terminalsLoaded:L,connected:z,createTerminal:M,attachXterm:V,resizeTerminal:H,setupImagePaste:B,writeToTerminal:q,consumePendingStartup:K,clearStartingUp:U}=b5(),j=k.useRef(V),$=k.useRef(B),Y=k.useRef(q),W=k.useRef(K),J=k.useRef(U);k.useEffect(()=>{j.current=V},[V]),k.useEffect(()=>{$.current=B},[B]),k.useEffect(()=>{Y.current=q},[q]),k.useEffect(()=>{W.current=K},[K]),k.useEffect(()=>{J.current=U},[U]);const ae=p?D.find(Z=>Z.id===p):null,se=ae?.status;k.useEffect(()=>{if(!o.current||l.current)return;const Z=new $ie.Terminal({cursorBlink:!0,fontSize:Math.round(13*yc),fontFamily:"JetBrains Mono Variable, PureNerdFont, Menlo, Monaco, monospace",lineHeight:1.2,theme:O}),ee=new zie.FitAddon,ne=new Hie.WebLinksAddon;Z.loadAddon(ee),Z.loadAddon(ne),Z.open(o.current),l.current=Z,u.current=ee,x(!0),requestAnimationFrame(()=>{ee.fit()});const te=setTimeout(()=>{ee.fit(),Z.refresh(0,Z.rows-1)},100),ye=()=>N(!0),Ee=()=>N(!1);return Z.textarea&&(Z.textarea.addEventListener("focus",ye),Z.textarea.addEventListener("blur",Ee)),()=>{clearTimeout(te),Z.textarea&&(Z.textarea.removeEventListener("focus",ye),Z.textarea.removeEventListener("blur",Ee)),N(!1),Z.dispose(),l.current=null,u.current=null,x(!1)}},[N]);const Q=k.useCallback(()=>{if(!u.current||!l.current)return;u.current.fit();const{cols:Z,rows:ee}=l.current;p&&H(p,Z,ee)},[p,H]);k.useEffect(()=>{if(!o.current)return;const Z=()=>{requestAnimationFrame(Q)};window.addEventListener("resize",Z);const ee=()=>{document.visibilityState==="visible"&&requestAnimationFrame(()=>{Q(),l.current&&l.current.refresh(0,l.current.rows-1)})};document.addEventListener("visibilitychange",ee);const ne=new ResizeObserver(Z);ne.observe(o.current);const te=new IntersectionObserver(ye=>{ye[0]?.isIntersecting&&requestAnimationFrame(()=>{Q(),l.current&&l.current.refresh(0,l.current.rows-1)})},{threshold:.1});return te.observe(o.current),()=>{window.removeEventListener("resize",Z),document.removeEventListener("visibilitychange",ee),ne.disconnect(),te.disconnect()}},[Q]),k.useEffect(()=>{if(!z||!t||!v||!L)return;const Z=D.find(ee=>ee.cwd===t);if(Z){m(Z.id);return}if(!f.current&&l.current){f.current=!0,S(!0);const{cols:ee,rows:ne}=l.current;M({name:e,cols:ee,rows:ne,cwd:t,startup:{startupScript:a,aiMode:r,description:i,taskName:e,serverPort:s}})}},[z,t,v,L,D,e,M]),k.useEffect(()=>{if(!t)return;const Z=D.find(ne=>ne.cwd===t);if(!Z)return;const ee=p&&D.some(ne=>ne.id===p);(!p||!ee)&&(At.taskTerminal.debug("setting terminalId",{newId:Z.id,prevId:p,reason:p?"tempId replaced":"initial",cwd:t,terminalCount:D.length}),m(Z.id),S(!1),p&&!ee&&(d.current=!1))},[D,t,p]),k.useEffect(()=>{if(At.taskTerminal.debug("attach effect",{terminalId:p,hasTermRef:!!l.current,hasContainerRef:!!o.current,attachedRef:d.current}),!p||!l.current||!o.current||d.current)return;At.taskTerminal.debug("attach effect passed guards, calling attachXterm",{terminalId:p});const Z=te=>{requestAnimationFrame(Q);const ye=W.current(te);if(At.taskTerminal.debug("onAttached checking pending startup",{terminalId:te,hasPendingStartup:!!ye}),ye){At.taskTerminal.info("onAttached: running startup commands",{terminalId:te}),y(!0);const{startupScript:Ee,aiMode:pe,description:_e,taskName:Se,serverPort:Te}=ye;Ee&&setTimeout(()=>{const Ne="VIBORA_STARTUP_"+Date.now(),Pe=`source /dev/stdin <<'${Ne}'
113
+ `)}}):null},WX=zo;function VX({active:e,payload:t,className:n,indicator:r="dot",hideLabel:i=!1,hideIndicator:a=!1,label:s,labelFormatter:o,labelClassName:l,formatter:u,color:f,nameKey:d,labelKey:p}){const{config:m}=QHe(),E=k.useMemo(()=>{if(i||!t?.length)return null;const[g]=t,y=`${p||g?.dataKey||g?.name||"value"}`,v=GX(m,g,y),x=!p&&typeof s=="string"?m[s]?.label||s:v?.label;return o?b.jsx("div",{className:Be("font-medium",l),children:o(x,t)}):x?b.jsx("div",{className:Be("font-medium",l),children:x}):null},[s,o,t,i,l,m,p]);if(!e||!t?.length)return null;const S=t.length===1&&r!=="dot";return b.jsxs("div",{className:Be("border-border/50 bg-background gap-1.5 rounded-lg border px-2.5 py-1.5 text-xs/relaxed shadow-xl grid min-w-[8rem] items-start",n),children:[S?null:E,b.jsx("div",{className:"grid gap-1.5",children:t.filter(g=>g.type!=="none").map((g,y)=>{const v=`${d||g.name||g.dataKey||"value"}`,x=GX(m,g,v),T=f||g.payload.fill||g.color;return b.jsx("div",{className:Be("[&>svg]:text-muted-foreground flex w-full flex-wrap items-stretch gap-2 [&>svg]:h-2.5 [&>svg]:w-2.5",r==="dot"&&"items-center"),children:u&&g?.value!==void 0&&g.name?u(g.value,g.name,g,y,g.payload):b.jsxs(b.Fragment,{children:[x?.icon?b.jsx(x.icon,{}):!a&&b.jsx("div",{className:Be("shrink-0 rounded-[2px] border-(--color-border) bg-(--color-bg)",{"h-2.5 w-2.5":r==="dot","w-1":r==="line","w-0 border-[1.5px] border-dashed bg-transparent":r==="dashed","my-0.5":S&&r==="dashed"}),style:{"--color-bg":T,"--color-border":T}}),b.jsxs("div",{className:Be("flex flex-1 justify-between leading-none",S?"items-end":"items-center"),children:[b.jsxs("div",{className:"grid gap-1.5",children:[S?E:null,b.jsx("span",{className:"text-muted-foreground",children:x?.label||g.name})]}),g.value&&b.jsx("span",{className:"text-foreground font-mono font-medium tabular-nums",children:g.value.toLocaleString()})]})]})},g.dataKey)})})]})}function GX(e,t,n){if(typeof t!="object"||t===null)return;const r="payload"in t&&typeof t.payload=="object"&&t.payload!==null?t.payload:void 0;let i=n;return n in t&&typeof t[n]=="string"?i=t[n]:r&&n in r&&typeof r[n]=="string"&&(i=r[n]),i in e?e[i]:e[n]}const ku="";function eWe(e="vibora"){return qn({queryKey:["monitoring","claude-instances",e],queryFn:()=>zt(`${ku}/api/monitoring/claude-instances?filter=${e}`),refetchInterval:5e3})}function tWe(e="1h"){return qn({queryKey:["monitoring","system-metrics",e],queryFn:()=>zt(`${ku}/api/monitoring/system-metrics?window=${e}`),refetchInterval:5e3})}function nWe(){const e=wr();return Fn({mutationFn:({terminalId:t,pid:n})=>{if(t)return zt(`${ku}/api/monitoring/claude-instances/${t}/kill`,{method:"POST"});if(n)return zt(`${ku}/api/monitoring/claude-instances/${n}/kill-pid`,{method:"POST"});throw new Error("Either terminalId or pid must be provided")},onSuccess:()=>{e.invalidateQueries({queryKey:["monitoring","claude-instances"]})}})}function _b(e){if(e===0)return"0 B";const t=1024,n=["B","KB","MB","GB","TB"],r=Math.floor(Math.log(e)/Math.log(t));return`${parseFloat((e/Math.pow(t,r)).toFixed(1))} ${n[r]}`}function qX(e){return{"1m":"1 min","10m":"10 min","1h":"1 hour","3h":"3 hours","6h":"6 hours","12h":"12 hours","24h":"24 hours"}[e]}function rWe(e="memory",t=10){return qn({queryKey:["monitoring","top-processes",e,t],queryFn:()=>zt(`${ku}/api/monitoring/top-processes?sort=${e}&limit=${t}`),refetchInterval:5e3})}function iWe(){return qn({queryKey:["monitoring","docker-stats"],queryFn:()=>zt(`${ku}/api/monitoring/docker-stats`),refetchInterval:5e3})}function aWe(){return qn({queryKey:["monitoring","vibora-instances"],queryFn:()=>zt(`${ku}/api/monitoring/vibora-instances`),refetchInterval:5e3})}function sWe(){const e=wr();return Fn({mutationFn:({backendPid:t})=>zt(`${ku}/api/monitoring/vibora-instances/${t}/kill`,{method:"POST"}),onSuccess:()=>{e.invalidateQueries({queryKey:["monitoring","vibora-instances"]})}})}function oWe(){return qn({queryKey:["monitoring","claude-usage"],queryFn:()=>zt(`${ku}/api/monitoring/claude-usage`),refetchInterval:5e3})}const lWe=["system","processes","claude","vibora","worktrees","usage"],$le=js("/monitoring/")({component:yWe,validateSearch:e=>({tab:lWe.includes(e.tab)?e.tab:void 0})}),KX=["1m","10m","1h","3h","6h","12h","24h"],YX={cpu:{label:"CPU",color:"var(--chart-system)"},memoryUsed:{label:"Used",color:"var(--chart-system)"},memoryCache:{label:"Cache / Buffers",color:"var(--muted-foreground)"},disk:{label:"Disk",color:"var(--muted-foreground)"}};function uWe(){const{t:e}=rn("monitoring"),[t,n]=k.useState("vibora"),[r,i]=k.useState(null),[a,s]=k.useState(new Set),[o,l]=k.useState(!1),{data:u,isLoading:f,error:d}=eWe(t),p=nWe(),m=u?.reduce((x,T)=>x+T.ramMB,0)||0,E=r!==null||o;k.useEffect(()=>{r!==null&&u&&!u.some(x=>x.pid===r)&&i(null)},[r,u]),k.useEffect(()=>{if(a.size>0&&u){const x=new Set([...a].filter(T=>u.some(w=>w.pid===T)));x.size!==a.size&&s(x)}},[a,u]);const S=x=>{i(x.pid);const T=x.isViboraManaged&&x.terminalId?{terminalId:x.terminalId}:{pid:x.pid};p.mutate(T,{onError:()=>i(null)})},g=x=>{s(T=>{const w=new Set(T);return w.has(x)?w.delete(x):w.add(x),w})},y=()=>{u&&(a.size===u.length?s(new Set):s(new Set(u.map(x=>x.pid))))},v=async()=>{if(!u||a.size===0)return;l(!0);const x=u.filter(T=>a.has(T.pid));for(const T of x){const w=T.isViboraManaged&&T.terminalId?{terminalId:T.terminalId}:{pid:T.pid};try{await p.mutateAsync(w)}catch{}}s(new Set),l(!1)};return b.jsxs("div",{className:"space-y-4",children:[b.jsxs("div",{className:"flex items-center justify-between",children:[b.jsxs("div",{className:"flex items-center gap-4",children:[b.jsxs("div",{className:"flex items-center gap-2",children:[b.jsx($o,{id:"show-all",checked:t==="all",onCheckedChange:x=>n(x?"all":"vibora")}),b.jsx(Ute,{htmlFor:"show-all",className:"text-sm text-muted-foreground",children:e("claude.showAllInstances")})]}),a.size>0&&b.jsxs(qe,{variant:"destructive",size:"sm",onClick:v,disabled:E,className:"gap-1.5",children:[o?b.jsx(fe,{icon:tn,className:"size-3.5 animate-spin"}):b.jsx(fe,{icon:fi,className:"size-3.5"}),e("claude.killSelected",{count:a.size})]})]}),u&&b.jsxs("span",{className:"text-sm text-muted-foreground",children:[e("claude.instanceCount",{count:u.length}),m>0&&` · ${e("claude.totalRam",{ram:m.toFixed(0)})}`]})]}),f&&b.jsx("div",{className:"flex items-center justify-center py-12",children:b.jsx(fe,{icon:tn,className:"size-6 animate-spin text-muted-foreground"})}),d&&b.jsx("div",{className:"rounded-lg border border-destructive/50 bg-destructive/10 p-4 text-sm text-destructive",children:e("claude.error",{message:d.message})}),u&&u.length===0&&b.jsxs("div",{className:"py-12 text-center text-muted-foreground",children:[e("claude.empty"),t==="vibora"&&e("claude.emptyVibora")]}),u&&u.length>0&&b.jsxs("div",{className:"space-y-2",children:[b.jsxs("div",{className:"hidden lg:grid grid-cols-[32px_60px_150px_1fr_1fr_80px_80px] gap-4 px-3 py-2 text-xs font-medium text-muted-foreground",children:[b.jsx("div",{className:"flex items-center justify-center",children:b.jsx(hi,{checked:a.size===u.length,onCheckedChange:y,disabled:E})}),b.jsx("span",{children:e("claude.headers.pid")}),b.jsx("span",{children:e("claude.headers.terminal")}),b.jsx("span",{children:e("claude.headers.task")}),b.jsx("span",{children:e("claude.headers.workingDirectory")}),b.jsx("span",{className:"text-right",children:e("claude.headers.ram")}),b.jsx("span",{className:"text-right",children:e("claude.headers.actions")})]}),u.map(x=>b.jsxs(wa,{className:"px-3 py-2",children:[b.jsxs("div",{className:"flex flex-col gap-1 lg:hidden",children:[b.jsxs("div",{className:"flex items-center justify-between gap-2",children:[b.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[b.jsx(hi,{checked:a.has(x.pid),onCheckedChange:()=>g(x.pid),disabled:E,className:"shrink-0"}),b.jsx("span",{className:"text-sm font-medium truncate",children:x.taskId?b.jsx(Ai,{to:"/tasks/$taskId",params:{taskId:x.taskId},className:"hover:text-foreground hover:underline",children:x.taskTitle}):b.jsx("span",{className:"text-muted-foreground",children:x.isViboraManaged?x.terminalName:e("claude.source.external")})})]}),b.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[b.jsxs("span",{className:"tabular-nums text-sm text-muted-foreground",children:[x.ramMB.toFixed(0)," MB"]}),b.jsx(qe,{variant:"ghost",size:"xs",onClick:()=>S(x),disabled:E,className:`text-destructive hover:text-destructive hover:bg-destructive/10 ${E?"opacity-50":""}`,children:b.jsx(fe,{icon:r===x.pid?tn:fi,className:`size-3.5 ${r===x.pid?"animate-spin":""}`})})]})]}),b.jsx("span",{className:"text-xs text-muted-foreground truncate pl-6",title:x.cwd,children:x.cwd})]}),b.jsxs("div",{className:"hidden lg:grid grid-cols-[32px_60px_150px_1fr_1fr_80px_80px] items-center gap-4",children:[b.jsx("div",{className:"flex items-center justify-center",children:b.jsx(hi,{checked:a.has(x.pid),onCheckedChange:()=>g(x.pid),disabled:E})}),b.jsx("span",{className:"font-mono text-xs",children:x.pid}),b.jsx("span",{className:"truncate text-sm",children:x.isViboraManaged?b.jsx("span",{children:x.terminalName||`Terminal ${x.terminalId?.slice(0,8)}`}):b.jsx("span",{className:"text-muted-foreground",children:e("claude.source.external")})}),b.jsx("span",{className:"text-muted-foreground truncate text-sm",children:x.taskId?b.jsx(Ai,{to:"/tasks/$taskId",params:{taskId:x.taskId},className:"hover:text-foreground hover:underline",children:x.taskTitle}):e("claude.noTask")}),b.jsx("span",{className:"text-muted-foreground truncate text-sm",title:x.cwd,children:x.cwd}),b.jsxs("span",{className:"text-right tabular-nums text-sm",children:[x.ramMB.toFixed(0)," MB"]}),b.jsx("div",{className:"flex justify-end",children:b.jsxs(qe,{variant:"ghost",size:"xs",onClick:()=>S(x),disabled:E,className:`text-destructive hover:text-destructive hover:bg-destructive/10 ${E?"opacity-50":""}`,children:[b.jsx(fe,{icon:r===x.pid?tn:fi,className:`size-3.5 ${r===x.pid?"animate-spin":""}`}),r===x.pid?e("claude.killing"):e("claude.kill")]})})]})]},x.pid))]})]})}function cWe(){const{t:e}=rn("monitoring"),[t,n]=k.useState("1h"),{data:r,isLoading:i,error:a}=tWe(t),s=r?.dataPoints.map(o=>({time:new Date(o.timestamp*1e3).toLocaleTimeString(),timestamp:o.timestamp,cpu:Math.round(o.cpuPercent*10)/10,memoryUsed:Math.round(o.memoryUsedPercent*10)/10,memoryCache:Math.round(o.memoryCachePercent*10)/10}))||[];return b.jsxs("div",{className:"space-y-6",children:[b.jsx("div",{className:"sm:hidden",children:b.jsxs(Bi,{value:t,onValueChange:o=>n(o),children:[b.jsx($i,{size:"sm",className:"w-auto gap-2",children:b.jsx(Ui,{})}),b.jsx(zi,{children:KX.map(o=>b.jsx(Cn,{value:o,children:qX(o)},o))})]})}),b.jsx("div",{className:"hidden sm:flex gap-1",children:KX.map(o=>b.jsx(qe,{variant:t===o?"default":"ghost",size:"xs",onClick:()=>n(o),children:qX(o)},o))}),i&&b.jsx("div",{className:"flex items-center justify-center py-12",children:b.jsx(fe,{icon:tn,className:"size-6 animate-spin text-muted-foreground"})}),a&&b.jsx("div",{className:"rounded-lg border border-destructive/50 bg-destructive/10 p-4 text-sm text-destructive",children:e("system.error",{message:a.message})}),r&&b.jsxs("div",{className:"space-y-6",children:[b.jsxs(wa,{className:"p-4",children:[b.jsxs("div",{className:"mb-4 flex items-center justify-between",children:[b.jsx("h3",{className:"font-medium",children:e("system.cpuUsage")}),b.jsxs("span",{className:"text-sm text-muted-foreground tabular-nums",children:[r.current.cpu.toFixed(1),"%"]})]}),b.jsx(HX,{config:YX,className:"h-[150px] w-full",children:b.jsxs(zX,{data:s,margin:{left:0,right:0},children:[b.jsx(FL,{strokeDasharray:"3 3",vertical:!1}),b.jsx(wy,{dataKey:"time",tickLine:!1,axisLine:!1,tickMargin:8,minTickGap:40}),b.jsx(Ty,{domain:[0,100],tickLine:!1,axisLine:!1,tickMargin:8,tickFormatter:o=>`${o}%`}),b.jsx(WX,{content:b.jsx(VX,{hideLabel:!0,formatter:o=>[`${o}% `,"CPU"]})}),b.jsx(il,{type:"monotone",dataKey:"cpu",stroke:"var(--color-cpu)",fill:"var(--color-cpu)",fillOpacity:.4,strokeWidth:2})]})})]}),b.jsxs(wa,{className:"p-4",children:[b.jsxs("div",{className:"mb-4 flex items-center justify-between",children:[b.jsx("h3",{className:"font-medium",children:e("system.memoryUsage")}),b.jsxs("span",{className:"text-sm text-muted-foreground tabular-nums",children:[_b(r.current.memory.used)," ",e("system.memoryLabels.used").toLowerCase()," + ",_b(r.current.memory.cache)," ",e("system.memoryLabels.cache").toLowerCase()," / ",_b(r.current.memory.total)]})]}),b.jsx(HX,{config:YX,className:"h-[150px] w-full",children:b.jsxs(zX,{data:s,margin:{left:0,right:0},children:[b.jsx(FL,{strokeDasharray:"3 3",vertical:!1}),b.jsx(wy,{dataKey:"time",tickLine:!1,axisLine:!1,tickMargin:8,minTickGap:40}),b.jsx(Ty,{domain:[0,100],tickLine:!1,axisLine:!1,tickMargin:8,tickFormatter:o=>`${o}%`}),b.jsx(WX,{content:b.jsx(VX,{hideLabel:!0,formatter:(o,l)=>{const u=e(l==="memoryUsed"?"system.memoryLabels.used":"system.memoryLabels.cache");return[`${o}% `,u]}})}),b.jsx(il,{type:"monotone",dataKey:"memoryUsed",stroke:"var(--color-memoryUsed)",fill:"var(--color-memoryUsed)",fillOpacity:.5,strokeWidth:2,stackId:"memory"}),b.jsx(il,{type:"monotone",dataKey:"memoryCache",stroke:"var(--color-memoryCache)",fill:"var(--color-memoryCache)",fillOpacity:.4,strokeWidth:1,stackId:"memory"})]})})]}),b.jsxs(wa,{className:"p-4",children:[b.jsxs("div",{className:"mb-4 flex items-center justify-between",children:[b.jsx("h3",{className:"font-medium",children:e("system.diskUsage",{path:r.current.disk.path})}),b.jsxs("span",{className:"text-sm text-muted-foreground tabular-nums",children:[r.current.disk.usedPercent.toFixed(1),"% (",_b(r.current.disk.used)," /"," ",_b(r.current.disk.total),")"]})]}),b.jsx("div",{className:"h-4 w-full overflow-hidden rounded-full bg-muted",children:b.jsx("div",{className:"h-full bg-chart-system transition-all",style:{width:`${Math.min(r.current.disk.usedPercent,100)}%`}})})]})]})]})}function dWe(){const{t:e}=rn("monitoring"),[t,n]=k.useState("memory"),{data:r,isLoading:i,error:a}=rWe(t),{data:s,isLoading:o}=iWe();return b.jsxs("div",{className:"flex flex-col gap-6 lg:flex-row lg:items-start",children:[b.jsxs(wa,{className:"p-4 lg:flex-1 lg:min-w-0 h-[400px] flex flex-col",children:[b.jsxs("div",{className:"mb-4 flex items-center justify-between shrink-0",children:[b.jsx("h3",{className:"font-medium",children:e("processes.topProcesses")}),b.jsxs(Bi,{value:t,onValueChange:l=>n(l),children:[b.jsx($i,{className:"w-32",children:b.jsx(Ui,{})}),b.jsxs(zi,{children:[b.jsx(Cn,{value:"memory",children:e("processes.sortBy.memory")}),b.jsx(Cn,{value:"cpu",children:e("processes.sortBy.cpu")})]})]})]}),i&&b.jsx("div",{className:"flex items-center justify-center flex-1",children:b.jsx(fe,{icon:tn,className:"size-6 animate-spin text-muted-foreground"})}),a&&b.jsx("div",{className:"rounded-lg border border-destructive/50 bg-destructive/10 p-4 text-sm text-destructive",children:e("processes.error",{message:a.message})}),r&&r.length>0&&b.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto",children:b.jsxs("div",{className:"space-y-1",children:[b.jsxs("div",{className:"grid grid-cols-[60px_120px_1fr_70px_80px] gap-2 px-2 py-1 text-xs font-medium text-muted-foreground",children:[b.jsx("span",{children:e("processes.headers.pid")}),b.jsx("span",{children:e("processes.headers.name")}),b.jsx("span",{children:e("processes.headers.command")}),b.jsx("span",{className:"text-right",children:e("processes.headers.memory")}),b.jsx("span",{className:"text-right",children:"%"})]}),r.map(l=>b.jsxs("div",{className:"grid grid-cols-[60px_120px_1fr_70px_80px] gap-2 rounded px-2 py-1.5 text-sm hover:bg-muted/50",children:[b.jsx("span",{className:"font-mono text-xs text-muted-foreground",children:l.pid}),b.jsx("span",{className:"truncate font-medium",title:l.name,children:l.name}),b.jsx("span",{className:"truncate text-muted-foreground text-xs",title:l.command,children:l.command}),b.jsxs("span",{className:"text-right tabular-nums",children:[l.memoryMB.toFixed(0)," MB"]}),b.jsxs("span",{className:"text-right tabular-nums text-muted-foreground",children:[l.memoryPercent.toFixed(1),"%"]})]},l.pid))]})}),r&&r.length===0&&b.jsx("div",{className:"flex-1 flex items-center justify-center text-muted-foreground",children:e("processes.empty")})]}),b.jsxs(wa,{className:"p-4 lg:flex-1 lg:min-w-0 h-[400px] flex flex-col",children:[b.jsx("div",{className:"mb-4 flex items-center justify-between shrink-0",children:b.jsxs("h3",{className:"font-medium",children:[e("processes.containers"),s?.runtime&&b.jsxs("span",{className:"ml-2 text-xs font-normal text-muted-foreground",children:["(",s.runtime,")"]})]})}),o&&b.jsx("div",{className:"flex items-center justify-center flex-1",children:b.jsx(fe,{icon:tn,className:"size-6 animate-spin text-muted-foreground"})}),s&&!s.available&&b.jsx("div",{className:"flex-1 flex items-center justify-center text-muted-foreground",children:e("processes.containersUnavailable")}),s&&s.available&&s.containers.length===0&&b.jsx("div",{className:"flex-1 flex items-center justify-center text-muted-foreground",children:e("processes.containersEmpty")}),s&&s.available&&s.containers.length>0&&b.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto",children:b.jsxs("div",{className:"space-y-1",children:[b.jsxs("div",{className:"grid grid-cols-[1fr_70px_100px_80px] gap-2 px-2 py-1 text-xs font-medium text-muted-foreground",children:[b.jsx("span",{children:e("processes.headers.name")}),b.jsx("span",{className:"text-right",children:"CPU"}),b.jsx("span",{className:"text-right",children:e("processes.headers.memory")}),b.jsx("span",{className:"text-right",children:"%"})]}),s.containers.map(l=>b.jsxs("div",{className:"grid grid-cols-[1fr_70px_100px_80px] gap-2 rounded px-2 py-1.5 text-sm hover:bg-muted/50",children:[b.jsx("span",{className:"truncate font-medium",title:l.name,children:l.name}),b.jsxs("span",{className:"text-right tabular-nums",children:[l.cpuPercent.toFixed(1),"%"]}),b.jsxs("span",{className:"text-right tabular-nums",children:[l.memoryMB.toFixed(0)," / ",l.memoryLimit.toFixed(0)," MB"]}),b.jsxs("span",{className:"text-right tabular-nums text-muted-foreground",children:[l.memoryPercent.toFixed(1),"%"]})]},l.id))]})})]})]})}function fWe(){const{t:e}=rn("monitoring"),[t,n]=k.useState(null),{data:r,isLoading:i,error:a}=aWe(),s=sWe();k.useEffect(()=>{t!==null&&r&&!r.some(l=>l.backend?.pid===t)&&n(null)},[t,r]);const o=l=>{l.backend&&(n(l.backend.pid),s.mutate({backendPid:l.backend.pid},{onError:()=>n(null)}))};return b.jsxs("div",{className:"space-y-4",children:[b.jsxs("div",{className:"flex items-center justify-between",children:[b.jsx("span",{className:"text-sm text-muted-foreground",children:e("vibora.description")}),r&&r.length>0&&b.jsx("span",{className:"text-sm text-muted-foreground",children:e("vibora.instanceCount",{count:r.length})})]}),i&&b.jsx("div",{className:"flex items-center justify-center py-12",children:b.jsx(fe,{icon:tn,className:"size-6 animate-spin text-muted-foreground"})}),a&&b.jsx("div",{className:"rounded-lg border border-destructive/50 bg-destructive/10 p-4 text-sm text-destructive",children:e("vibora.error",{message:a.message})}),r&&r.length===0&&b.jsx("div",{className:"py-12 text-center text-muted-foreground",children:e("vibora.empty")}),r&&r.length>0&&b.jsxs("div",{className:"space-y-2",children:[b.jsxs("div",{className:"hidden lg:grid grid-cols-[80px_100px_1fr_100px_80px] gap-4 px-3 py-2 text-xs font-medium text-muted-foreground",children:[b.jsx("span",{children:e("vibora.headers.port")}),b.jsx("span",{children:e("vibora.headers.mode")}),b.jsx("span",{children:e("vibora.headers.directory")}),b.jsx("span",{className:"text-right",children:e("vibora.headers.ram")}),b.jsx("span",{className:"text-right",children:e("vibora.headers.actions")})]}),r.map(l=>{const u=t===l.backend?.pid,f=t!==null;return b.jsxs(wa,{className:"px-3 py-2",children:[b.jsxs("div",{className:"flex flex-col gap-1 lg:hidden",children:[b.jsxs("div",{className:"flex items-center justify-between gap-2",children:[b.jsxs("span",{className:"text-sm font-medium",children:[b.jsxs("span",{className:"font-mono",children:[":",l.port]}),b.jsxs("span",{className:`ml-2 text-xs ${l.mode==="development"?"text-muted-foreground":""}`,children:[l.mode==="development"?e("vibora.mode.dev"):e("vibora.mode.prod"),l.frontend&&` + ${e("vibora.vite")}`]})]}),b.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[b.jsxs("span",{className:"tabular-nums text-sm text-muted-foreground",children:[l.totalMemoryMB.toFixed(0)," MB"]}),b.jsx(qe,{variant:"ghost",size:"xs",onClick:()=>o(l),disabled:f||!l.backend,className:`text-destructive hover:text-destructive hover:bg-destructive/10 ${f?"opacity-50":""}`,children:b.jsx(fe,{icon:u?tn:fi,className:`size-3.5 ${u?"animate-spin":""}`})})]})]}),b.jsx("span",{className:"text-xs text-muted-foreground truncate",title:l.viboraDir,children:l.viboraDir})]}),b.jsxs("div",{className:"hidden lg:grid grid-cols-[80px_100px_1fr_100px_80px] items-center gap-4",children:[b.jsx("span",{className:"font-mono text-sm",children:l.port}),b.jsxs("span",{className:`text-xs ${l.mode==="development"?"text-muted-foreground":""}`,children:[l.mode==="development"?e("vibora.mode.dev"):e("vibora.mode.prod"),l.frontend&&` + ${e("vibora.vite")}`]}),b.jsx("span",{className:"text-muted-foreground truncate text-sm",title:l.viboraDir,children:l.viboraDir}),b.jsxs("span",{className:"text-right tabular-nums text-sm",children:[l.totalMemoryMB.toFixed(0)," MB"]}),b.jsx("div",{className:"flex justify-end",children:b.jsxs(qe,{variant:"ghost",size:"xs",onClick:()=>o(l),disabled:f||!l.backend,className:`text-destructive hover:text-destructive hover:bg-destructive/10 ${f?"opacity-50":""}`,children:[b.jsx(fe,{icon:u?tn:fi,className:`size-3.5 ${u?"animate-spin":""}`}),e(u?"vibora.killing":"vibora.kill")]})})]})]},l.backend?.pid||l.port)})]})]})}function hWe(e){return e>=90?"text-destructive":e>=70?"text-muted-foreground":"text-chart-system"}function pWe(e){if(e<60)return`${e}m`;const t=Math.floor(e/60),n=e%60;return n>0?`${t}h ${n}m`:`${t}h`}function WN(e){const t=new Date(e),n=new Date,r=t.getTime()-n.getTime(),i=Math.floor(r/(1e3*60*60*24));return i===0?t.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):i===1?`Tomorrow ${t.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})}`:i<7?t.toLocaleDateString([],{weekday:"short",hour:"2-digit",minute:"2-digit"}):t.toLocaleDateString([],{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}function W_({percent:e,label:t,subtitle:n,color:r}){const i=[{value:Math.min(e,100),fill:r}],a=Math.round(96*yc),s=Math.round(48*yc),o=Math.round(32*yc),l=Math.round(44*yc),u=Math.round(10*yc),f=Math.round(5*yc);return b.jsx(wa,{className:"p-4",children:b.jsxs("div",{className:"flex items-center gap-4",children:[b.jsxs("div",{className:"relative size-24 shrink-0",children:[b.jsxs(XHe,{width:a,height:a,cx:s,cy:s,innerRadius:o,outerRadius:l,barSize:u,data:i,startAngle:90,endAngle:-270,children:[b.jsx(_0,{type:"number",domain:[0,100],angleAxisId:0,tick:!1}),b.jsx(E0,{background:{fill:"var(--border)"},dataKey:"value",cornerRadius:f,angleAxisId:0})]}),b.jsx("div",{className:"absolute inset-0 flex items-center justify-center",children:b.jsxs("span",{className:`text-lg font-semibold tabular-nums ${hWe(e)}`,children:[e.toFixed(0),"%"]})})]}),b.jsxs("div",{className:"flex-1 min-w-0",children:[b.jsx("h3",{className:"text-sm font-medium truncate",children:t}),b.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:n})]})]})})}function mWe(){const{t:e}=rn("monitoring"),{data:t,isLoading:n,error:r}=oWe(),i=a=>a>=90?"var(--destructive)":a>=70?"var(--muted-foreground)":"var(--chart-system)";return b.jsxs("div",{className:"space-y-4",children:[n&&b.jsx("div",{className:"flex items-center justify-center py-12",children:b.jsx(fe,{icon:tn,className:"size-6 animate-spin text-muted-foreground"})}),r&&b.jsx("div",{className:"rounded-lg border border-destructive/50 bg-destructive/10 p-4 text-sm text-destructive",children:e("usage.error",{message:r.message})}),t&&!t.available&&b.jsx("div",{className:"rounded-lg border border-muted-foreground/50 bg-muted p-4 text-sm text-muted-foreground",children:t.error||e("usage.unavailable")}),t&&t.available&&b.jsxs("div",{className:"space-y-3",children:[b.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[t.fiveHour&&b.jsx(W_,{percent:t.fiveHour.percentUsed,label:e("usage.fiveHourBlock"),subtitle:e("usage.resetsIn",{time:pWe(t.fiveHour.timeRemainingMinutes)}),color:i(t.fiveHour.percentUsed)}),t.sevenDay&&b.jsx(W_,{percent:t.sevenDay.percentUsed,label:e("usage.sevenDayRolling"),subtitle:`${e("usage.resetsAt",{time:WN(t.sevenDay.resetAt)})} · ${e("usage.weekProgress",{percent:t.sevenDay.weekProgressPercent})}`,color:i(t.sevenDay.percentUsed)})]}),(t.sevenDayOpus||t.sevenDaySonnet)&&b.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[t.sevenDayOpus&&b.jsx(W_,{percent:t.sevenDayOpus.percentUsed,label:e("usage.opusWeekly"),subtitle:e("usage.resetsAt",{time:WN(t.sevenDayOpus.resetAt)}),color:i(t.sevenDayOpus.percentUsed)}),t.sevenDaySonnet&&b.jsx(W_,{percent:t.sevenDaySonnet.percentUsed,label:e("usage.sonnetWeekly"),subtitle:e("usage.resetsAt",{time:WN(t.sevenDaySonnet.resetAt)}),color:i(t.sevenDaySonnet.percentUsed)})]})]})]})}const VN={IN_PROGRESS:"bg-muted-foreground/20 text-muted-foreground",IN_REVIEW:"bg-primary/20 text-primary",DONE:"bg-accent/20 text-accent",CANCELED:"bg-destructive/20 text-destructive",ORPHANED:"bg-destructive/20 text-destructive"},gWe=["IN_PROGRESS","IN_REVIEW","DONE","CANCELED","ORPHANED"];function bWe(){const{t:e}=rn("common");return t=>{const n=new Date(t),i=new Date().getTime()-n.getTime(),a=Math.floor(i/1e3),s=Math.floor(a/60),o=Math.floor(s/60),l=Math.floor(o/24);return l>0?l===1?e("time.dayAgo"):e("time.daysAgo",{count:l}):o>0?o===1?e("time.hourAgo"):e("time.hoursAgo",{count:o}):s>0?s===1?e("time.minuteAgo"):e("time.minutesAgo",{count:s}):e("time.justNow")}}function vWe(){const{t:e}=rn("common"),{t}=rn("worktrees"),n=bWe(),{worktrees:r,summary:i,isLoading:a,isLoadingDetails:s,error:o,refetch:l}=wie(),u=Tie(),[f,d]=k.useState(new Set),[p,m]=k.useState(!1),[E,S]=k.useState(!1),[g,y]=k.useState(!1),[v,x]=k.useState(null),[T,w]=k.useState(null),[C,R]=k.useState(!1),O=B=>{d(q=>{const K=new Set(q);return K.has(B)?K.delete(B):K.add(B),K})},N=()=>{d(new Set)},D=k.useMemo(()=>f.size===0?r:r.filter(B=>!!(B.isOrphaned&&f.has("ORPHANED")||B.taskStatus&&f.has(B.taskStatus))),[r,f]),L=k.useMemo(()=>r.filter(B=>B.taskStatus==="DONE"||B.taskStatus==="CANCELED"),[r]),z=async()=>{if(L.length!==0){S(!0);try{for(const B of L)await u.mutateAsync({worktreePath:B.path,repoPath:B.repoPath,deleteLinkedTask:g});m(!1),l()}catch{}finally{S(!1)}}},M=async(B,q)=>{x(B.path);try{await u.mutateAsync({worktreePath:B.path,repoPath:B.repoPath,deleteLinkedTask:q}),w(null),l()}catch{}finally{x(null)}},V=B=>{B||(w(null),R(!1))},H=B=>{m(B),B||y(!1)};return b.jsxs("div",{className:"space-y-4",children:[b.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[b.jsx("div",{className:"flex items-center gap-3 text-sm text-muted-foreground",children:(i||r.length>0)&&b.jsxs(b.Fragment,{children:[b.jsx("span",{children:t("summary.total",{count:i?.total??r.length})}),(i?.orphaned??r.filter(B=>B.isOrphaned).length)>0&&b.jsx("span",{className:"text-destructive",children:t("summary.orphaned",{count:i?.orphaned??r.filter(B=>B.isOrphaned).length})}),s?b.jsx("span",{className:"animate-pulse",children:e("status.calculating")}):i?b.jsx("span",{children:i.totalSizeFormatted}):null]})}),b.jsxs("div",{className:"flex items-center gap-2",children:[L.length>0&&b.jsxs(go,{open:p,onOpenChange:H,children:[b.jsxs(wu,{render:b.jsx(qe,{variant:"ghost",size:"sm",className:"gap-1.5 text-xs text-muted-foreground hover:text-destructive",disabled:s}),children:[b.jsx(fe,{icon:hte,size:12,strokeWidth:2}),t("cleanup.button",{count:L.length})]}),b.jsxs(bo,{children:[b.jsxs(vo,{children:[b.jsx(_o,{children:t("cleanup.title")}),b.jsxs(Eo,{children:[t("cleanup.description",{count:L.length}),g&&` ${t("cleanup.linkedTasksWillBeDeleted")}`]}),b.jsxs("div",{className:"space-y-3",children:[b.jsxs("label",{className:"flex items-center gap-2 text-sm text-foreground",children:[b.jsx(hi,{checked:g,onCheckedChange:B=>y(B===!0),disabled:E}),t("cleanup.alsoDeleteLinkedTasks")]}),b.jsx("p",{className:"font-medium text-destructive text-xs",children:t("cleanup.cannotUndo")})]})]}),b.jsxs(yo,{children:[b.jsx(So,{disabled:E,children:e("buttons.cancel")}),b.jsxs(qe,{variant:"destructive",onClick:z,disabled:E,className:"gap-2",children:[E&&b.jsx(fe,{icon:tn,size:14,strokeWidth:2,className:"animate-spin"}),E?e("status.deleting"):t("delete.button",{count:L.length})]})]})]})]}),f.size>0&&b.jsxs(qe,{variant:"ghost",size:"sm",onClick:N,className:"gap-1.5 text-xs",children:[b.jsx(fe,{icon:fi,size:12,strokeWidth:2}),e("buttons.clearFilters")]})]})]}),b.jsx("div",{className:"flex flex-wrap items-center gap-1.5",children:gWe.map(B=>{const q=f.has(B);return b.jsx("button",{onClick:()=>O(B),className:Be("rounded-full px-2.5 py-1 text-xs font-medium transition-colors",q?VN[B]:"bg-muted text-muted-foreground hover:bg-muted/80"),children:e(`statuses.${B}`)},B)})}),a&&b.jsx("div",{className:"flex items-center justify-center py-12",children:b.jsx(fe,{icon:tn,className:"size-6 animate-spin text-muted-foreground"})}),o&&b.jsx("div",{className:"rounded-lg border border-destructive/50 bg-destructive/10 p-4 text-sm text-destructive",children:t("error.failedToLoad",{message:o.message})}),!a&&!o&&D.length===0&&b.jsx("div",{className:"py-12 text-center text-muted-foreground",children:f.size>0?t("empty.noMatch"):t("empty.noWorktrees")}),!a&&D.length>0&&b.jsx("div",{className:"grid grid-cols-1 gap-2 sm:grid-cols-2 xl:grid-cols-3",children:D.map(B=>{const q=B.sizeFormatted==="..."||B.branch==="...",K=!B.isOrphaned&&B.taskId,U=v===B.path;return b.jsx(wa,{className:"transition-colors hover:border-border/80",children:b.jsxs(Mf,{className:"flex items-start justify-between gap-4 py-4",children:[b.jsxs("div",{className:"min-w-0 flex-1 space-y-2",children:[b.jsxs("div",{className:"flex items-center gap-2",children:[b.jsx("span",{className:"truncate font-medium",children:B.name}),B.isOrphaned?b.jsx(co,{className:Be("shrink-0",VN.ORPHANED),children:e("statuses.ORPHANED")}):B.taskStatus?b.jsx(co,{className:Be("shrink-0",VN[B.taskStatus]),children:e(`statuses.${B.taskStatus}`)}):null]}),b.jsxs("div",{className:"space-y-1 text-xs text-muted-foreground",children:[b.jsxs("div",{className:"flex items-center gap-1.5",children:[b.jsx(fe,{icon:Vi,size:12,strokeWidth:2,className:"shrink-0"}),b.jsx("span",{className:"truncate font-mono",children:B.path})]}),b.jsxs("div",{className:"flex flex-wrap items-center gap-x-4 gap-y-1",children:[b.jsxs("div",{className:"flex items-center gap-1.5",children:[b.jsx(fe,{icon:Vx,size:12,strokeWidth:2,className:"shrink-0"}),B.branch==="..."?b.jsx("span",{className:"inline-block animate-pulse rounded bg-muted h-3 w-16"}):b.jsx("span",{className:"font-mono",children:B.branch})]}),b.jsxs("div",{className:"flex items-center gap-1.5",children:[b.jsx(fe,{icon:mte,size:12,strokeWidth:2,className:"shrink-0"}),B.sizeFormatted==="..."?b.jsx("span",{className:"inline-block animate-pulse rounded bg-muted h-3 w-12"}):b.jsx("span",{children:B.sizeFormatted})]}),b.jsxs("div",{className:"flex items-center gap-1.5",children:[b.jsx(fe,{icon:cte,size:12,strokeWidth:2,className:"shrink-0"}),b.jsx("span",{children:n(B.lastModified)})]})]}),B.taskId&&B.taskTitle&&b.jsx("div",{className:"flex items-center gap-1.5 pt-1",children:b.jsxs(Ai,{to:"/tasks/$taskId",params:{taskId:B.taskId},className:"inline-flex items-center gap-1 text-foreground hover:underline",children:[b.jsx("span",{className:"truncate",children:B.taskTitle}),b.jsx(fe,{icon:Xy,size:12,strokeWidth:2,className:"shrink-0"})]})})]})]}),b.jsxs(go,{open:T?.path===B.path,onOpenChange:V,children:[b.jsx(wu,{render:b.jsx(qe,{variant:"ghost",size:"icon-sm",className:"shrink-0 text-muted-foreground hover:text-destructive",disabled:q||U,onClick:()=>w(B)}),children:b.jsx(fe,{icon:U?tn:bu,size:14,strokeWidth:2,className:U?"animate-spin":""})}),b.jsxs(bo,{children:[b.jsxs(vo,{children:[b.jsx(_o,{children:t("delete.title")}),b.jsxs(Eo,{children:[t("delete.description")," ",b.jsx("span",{className:"font-mono",children:B.name}),".",C&&K&&b.jsxs(b.Fragment,{children:[" ",t("delete.linkedTaskWillBeDeleted",{title:B.taskTitle})]})," ",t("delete.cannotUndo")]}),K&&b.jsxs("label",{className:"flex items-center gap-2 text-sm text-foreground",children:[b.jsx(hi,{checked:C,onCheckedChange:j=>R(j===!0),disabled:U}),t("delete.alsoDeleteLinkedTask",{title:B.taskTitle})]})]}),b.jsxs(yo,{children:[b.jsx(So,{disabled:U,children:e("buttons.cancel")}),b.jsxs(qe,{variant:"destructive",onClick:()=>M(B,C),disabled:U,className:"gap-2",children:[U&&b.jsx(fe,{icon:tn,size:14,strokeWidth:2,className:"animate-spin"}),e(U?"status.deleting":"buttons.delete")]})]})]})]})]})},B.path)})})]})}function yWe(){const{t:e}=rn("monitoring"),{data:t}=Bne(),n=Ri(),{tab:r}=$le.useSearch(),i=r||"system",a=k.useCallback(l=>{n({to:"/monitoring",search:l==="system"?{}:{tab:l},replace:!0})},[n]),o=[{value:"system",label:e("tabs.system")},{value:"processes",label:e("tabs.processes")},{value:"claude",label:e("tabs.claude")},{value:"vibora",label:e("tabs.vibora"),devOnly:!0},{value:"worktrees",label:e("tabs.worktrees")},{value:"usage",label:e("tabs.usage")}].filter(l=>!l.devOnly||t?.enabled);return b.jsxs("div",{className:"flex h-full flex-col overflow-hidden",children:[b.jsxs("div",{className:"flex shrink-0 items-center border-b border-border bg-background px-4 py-2",children:[b.jsx("div",{className:"sm:hidden",children:b.jsxs(Bi,{value:i,onValueChange:l=>a(l),children:[b.jsx($i,{size:"sm",className:"w-auto gap-2",children:b.jsx(Ui,{})}),b.jsx(zi,{children:o.map(l=>b.jsx(Cn,{value:l.value,children:l.label},l.value))})]})}),b.jsx("div",{className:"hidden sm:block",children:b.jsx(Zo,{value:i,onValueChange:l=>a(l),children:b.jsx(Qo,{variant:"line",children:o.map(l=>b.jsx(Wr,{value:l.value,className:"px-3 py-1.5",children:l.label},l.value))})})})]}),b.jsxs("div",{className:"flex-1 overflow-auto p-4",children:[i==="system"&&b.jsx(cWe,{}),i==="processes"&&b.jsx(dWe,{}),i==="claude"&&b.jsx(uWe,{}),i==="vibora"&&t?.enabled&&b.jsx(fWe,{}),i==="worktrees"&&b.jsx(vWe,{}),i==="usage"&&b.jsx(mWe,{})]})]})}const _We=()=>"http://localhost:3000",Eb={activeTab:"diff",browserUrl:_We(),diffOptions:{wrap:!0,ignoreWhitespace:!0,includeUntracked:!1,collapsedFiles:[]},filesViewState:{selectedFile:null,expandedDirs:[]}};function g5(e){const t=wr(),n=k.useRef(void 0),r=k.useRef({}),{data:i}=Mne(e),a=k.useMemo(()=>{const p=i?.viewState;return p?{activeTab:p.activeTab??Eb.activeTab,browserUrl:p.browserUrl??Eb.browserUrl,diffOptions:{...Eb.diffOptions,...p.diffOptions},filesViewState:{...Eb.filesViewState,...p.filesViewState}}:Eb},[i?.viewState]),s=Fn({mutationFn:async p=>{const m=await fetch(`/api/tasks/${e}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({viewState:p})});if(!m.ok)throw new Error("Failed to update view state");return m.json()},onSuccess:p=>{t.setQueryData(["tasks",e],p),t.setQueryData(["tasks"],m=>m&&m.map(E=>E.id===e?p:E))}}),o=k.useCallback(p=>{const m=r.current;r.current={...m,...p,diffOptions:p.diffOptions||m.diffOptions?{...m.diffOptions,...p.diffOptions}:void 0,filesViewState:p.filesViewState||m.filesViewState?{...m.filesViewState,...p.filesViewState}:void 0};const E=r.current,S={activeTab:E.activeTab??a.activeTab,browserUrl:E.browserUrl??a.browserUrl,diffOptions:{...a.diffOptions,...E.diffOptions},filesViewState:{...a.filesViewState,...E.filesViewState}};t.setQueryData(["tasks",e],g=>g&&{...g,viewState:S}),t.setQueryData(["tasks"],g=>g&&g.map(y=>y.id===e?{...y,viewState:S}:y)),n.current&&clearTimeout(n.current),n.current=setTimeout(()=>{s.mutate(S),r.current={}},500)},[t,e,a,s]),l=k.useCallback(p=>{o({activeTab:p})},[o]),u=k.useCallback(p=>{o({browserUrl:p})},[o]),f=k.useCallback(p=>{o({diffOptions:p})},[o]),d=k.useCallback(p=>{o({filesViewState:p})},[o]);return{viewState:a,setActiveTab:l,setBrowserUrl:u,setDiffOptions:f,setFilesViewState:d}}function EWe(e){return qn({queryKey:["linear-ticket",e],queryFn:async()=>{if(!e)return null;const t=await fetch(`/api/linear/ticket/${e}`);return t.ok?t.json():null},enabled:!!e,staleTime:300*1e3})}function SWe(e){return{id:e.id,name:e.name,cwd:e.cwd,status:e.status,exitCode:e.exitCode,cols:e.cols,rows:e.rows,createdAt:e.createdAt,tabId:e.tabId??void 0,positionInTab:e.positionInTab}}function xWe(e){return{id:e.id,name:e.name,position:e.position,directory:e.directory??void 0,createdAt:e.createdAt}}function b5(e={}){const t=bie();return{get terminals(){return t.terminals.map(SWe)},get terminalsLoaded(){return t.terminalsLoaded},get tabs(){return t.tabs.map(xWe)},get connected(){return t.connected},get newTerminalIds(){return t.newTerminalIds},createTerminal:t.createTerminal,destroyTerminal:t.destroyTerminal,writeToTerminal:t.writeToTerminal,sendInputToTerminal:t.sendInputToTerminal,resizeTerminal:t.resizeTerminal,renameTerminal:t.renameTerminal,clearTerminalBuffer:t.clearTerminalBuffer,assignTerminalToTab:t.assignTerminalToTab,createTab:t.createTab,updateTab:t.updateTab,deleteTab:t.deleteTab,reorderTab:t.reorderTab,attachXterm:t.attachXterm,setupImagePaste:t.setupImagePaste,consumePendingStartup:t.consumePendingStartup,clearStartingUp:t.clearStartingUp}}function V_(e){return`$'${e.replace(/\\/g,"\\\\").replace(/'/g,"\\'").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/\t/g,"\\t")}'`}function XX({taskName:e,cwd:t,className:n,aiMode:r,description:i,startupScript:a,serverPort:s=7777}){const o=k.useRef(null),l=k.useRef(null),u=k.useRef(null),f=k.useRef(!1),d=k.useRef(!1),[p,m]=k.useState(null),[E,S]=k.useState(!1),[g,y]=k.useState(!1),[v,x]=k.useState(!1),[T,w]=k.useState(!1),{resolvedTheme:C}=Kc(),R=C==="dark",O=R?Vie:Wie;k.useEffect(()=>{At.taskTerminal.debug("cwd changed, resetting refs",{cwd:t}),f.current=!1,d.current=!1,m(null),S(!1)},[t]);const{setTerminalFocused:N}=vM(),{terminals:D,terminalsLoaded:L,connected:z,createTerminal:M,attachXterm:V,resizeTerminal:H,setupImagePaste:B,writeToTerminal:q,consumePendingStartup:K,clearStartingUp:U}=b5(),j=k.useRef(V),$=k.useRef(B),Y=k.useRef(q),W=k.useRef(K),J=k.useRef(U);k.useEffect(()=>{j.current=V},[V]),k.useEffect(()=>{$.current=B},[B]),k.useEffect(()=>{Y.current=q},[q]),k.useEffect(()=>{W.current=K},[K]),k.useEffect(()=>{J.current=U},[U]);const ae=p?D.find(Z=>Z.id===p):null,se=ae?.status;k.useEffect(()=>{if(!o.current||l.current)return;const Z=new $ie.Terminal({cursorBlink:!0,fontSize:Math.round(13*yc),fontFamily:"JetBrains Mono Variable, PureNerdFont, Menlo, Monaco, monospace",lineHeight:1.2,theme:O}),ee=new zie.FitAddon,ne=new Hie.WebLinksAddon;Z.loadAddon(ee),Z.loadAddon(ne),Z.open(o.current),l.current=Z,u.current=ee,x(!0),requestAnimationFrame(()=>{ee.fit()});const te=setTimeout(()=>{ee.fit(),Z.refresh(0,Z.rows-1)},100),ye=()=>N(!0),Ee=()=>N(!1);return Z.textarea&&(Z.textarea.addEventListener("focus",ye),Z.textarea.addEventListener("blur",Ee)),()=>{clearTimeout(te),Z.textarea&&(Z.textarea.removeEventListener("focus",ye),Z.textarea.removeEventListener("blur",Ee)),N(!1),Z.dispose(),l.current=null,u.current=null,x(!1)}},[N]);const Q=k.useCallback(()=>{if(!u.current||!l.current)return;u.current.fit();const{cols:Z,rows:ee}=l.current;p&&H(p,Z,ee)},[p,H]);k.useEffect(()=>{if(!o.current)return;const Z=()=>{requestAnimationFrame(Q)};window.addEventListener("resize",Z);const ee=()=>{document.visibilityState==="visible"&&requestAnimationFrame(()=>{Q(),l.current&&l.current.refresh(0,l.current.rows-1)})};document.addEventListener("visibilitychange",ee);const ne=new ResizeObserver(Z);ne.observe(o.current);const te=new IntersectionObserver(ye=>{ye[0]?.isIntersecting&&requestAnimationFrame(()=>{Q(),l.current&&l.current.refresh(0,l.current.rows-1)})},{threshold:.1});return te.observe(o.current),()=>{window.removeEventListener("resize",Z),document.removeEventListener("visibilitychange",ee),ne.disconnect(),te.disconnect()}},[Q]),k.useEffect(()=>{if(!z||!t||!v||!L)return;const Z=D.find(ee=>ee.cwd===t);if(Z){m(Z.id);return}if(!f.current&&l.current){f.current=!0,S(!0);const{cols:ee,rows:ne}=l.current;M({name:e,cols:ee,rows:ne,cwd:t,startup:{startupScript:a,aiMode:r,description:i,taskName:e,serverPort:s}})}},[z,t,v,L,D,e,M]),k.useEffect(()=>{if(!t)return;const Z=D.find(ne=>ne.cwd===t);if(!Z)return;const ee=p&&D.some(ne=>ne.id===p);(!p||!ee)&&(At.taskTerminal.debug("setting terminalId",{newId:Z.id,prevId:p,reason:p?"tempId replaced":"initial",cwd:t,terminalCount:D.length}),m(Z.id),S(!1),p&&!ee&&(d.current=!1))},[D,t,p]),k.useEffect(()=>{if(At.taskTerminal.debug("attach effect",{terminalId:p,hasTermRef:!!l.current,hasContainerRef:!!o.current,attachedRef:d.current}),!p||!l.current||!o.current||d.current)return;At.taskTerminal.debug("attach effect passed guards, calling attachXterm",{terminalId:p});const Z=te=>{requestAnimationFrame(Q);const ye=W.current(te);if(At.taskTerminal.debug("onAttached checking pending startup",{terminalId:te,hasPendingStartup:!!ye}),ye){At.taskTerminal.info("onAttached: running startup commands",{terminalId:te}),y(!0);const{startupScript:Ee,aiMode:pe,description:_e,taskName:Se,serverPort:Te}=ye;Ee&&setTimeout(()=>{const Ne="VIBORA_STARTUP_"+Date.now(),Pe=`source /dev/stdin <<'${Ne}'
114
114
  ${Ee}
115
115
  ${Ne}`;Y.current(te,Pe+"\r")},100);const de=Te??7777,Ce=de!==7777?` --port=${de}`:"",ge=`You are working in a Vibora task worktree. Commit after completing each logical unit of work (feature, fix, refactor) to preserve progress. When you finish working and need user input, run: vibora current-task review${Ce}. When linking a PR: vibora current-task pr <url>${Ce}. For notifications: vibora notify "Title" "Message"${Ce}.`,he=_e?`${Se}: ${_e}`:Se,ce=pe==="plan"?`claude ${V_(he)} --append-system-prompt ${V_(ge)} --session-id "${te}" --allow-dangerously-skip-permissions --permission-mode plan`:`claude ${V_(he)} --append-system-prompt ${V_(ge)} --session-id "${te}" --dangerously-skip-permissions`;setTimeout(()=>{At.taskTerminal.debug("writing claude command to terminal",{terminalId:te,taskCommand:ce.substring(0,50)+"..."}),Y.current(te,ce+"\r"),y(!1),J.current(te)},Ee?5e3:100)}},ee=j.current(p,l.current,{onAttached:Z}),ne=$.current(o.current,p);return d.current=!0,At.taskTerminal.debug("attachedRef set to true",{terminalId:p}),()=>{At.taskTerminal.debug("cleanup running, setting attachedRef to false",{terminalId:p}),ee(),ne(),d.current=!1}},[p,Q]),k.useEffect(()=>{l.current&&(l.current.options.theme=O)},[O]),k.useEffect(()=>{if(!l.current||T)return;const Z=l.current,ee=()=>{const te=Z.buffer.active;for(let ye=Math.max(0,te.cursorY-3);ye<=te.cursorY;ye++){const Ee=te.getLine(ye);if(Ee){const pe=Ee.translateToString();if(pe.includes("claude: command not found")||pe.includes("claude: not found")||pe.includes("'claude' is not recognized")||pe.includes("command not found: claude")){w(!0);return}}}},ne=Z.onLineFeed(ee);return()=>{ne.dispose()}},[T]);const G=k.useCallback(Z=>{p&&Y.current(p,Z)},[p]);return t?b.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[!z&&b.jsx("div",{className:"shrink-0 px-2 py-1 bg-muted-foreground/20 text-muted-foreground text-xs",children:"Connecting to terminal server..."}),se==="error"&&b.jsx("div",{className:"shrink-0 px-2 py-1 bg-destructive/20 text-destructive text-xs",children:"Terminal failed to start. The worktree directory may not exist."}),se==="exited"&&b.jsxs("div",{className:"shrink-0 px-2 py-1 bg-muted text-muted-foreground text-xs",children:["Terminal exited (code: ",ae?.exitCode,")"]}),b.jsxs("div",{className:"relative min-h-0 flex-1",children:[b.jsx("div",{ref:o,className:Be("h-full w-full overflow-hidden p-2 bg-terminal-background",n)}),E&&!p&&b.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-terminal-background",children:b.jsxs("div",{className:"flex flex-col items-center gap-3",children:[b.jsx(fe,{icon:tn,size:24,strokeWidth:2,className:Be("animate-spin",R?"text-white/50":"text-black/50")}),b.jsx("span",{className:Be("font-mono text-sm",R?"text-white/50":"text-black/50"),children:"Initializing terminal..."})]})}),g&&b.jsx("div",{className:"pointer-events-auto absolute inset-0 z-10 flex items-center justify-center bg-terminal-background/90",children:b.jsxs("div",{className:"flex flex-col items-center gap-3",children:[b.jsx(fe,{icon:tn,size:24,strokeWidth:2,className:Be("animate-spin",R?"text-white/60":"text-black/60")}),b.jsx("span",{className:Be("font-mono text-sm",R?"text-white/60":"text-black/60"),children:"Starting Claude Code..."})]})}),T&&b.jsx("div",{className:"absolute bottom-4 left-4 right-4 z-10",children:b.jsxs("div",{className:Be("flex items-start gap-3 rounded-lg border p-4","bg-amber-500/10 border-amber-500/30"),children:[b.jsx(fe,{icon:rs,size:18,strokeWidth:2,className:"shrink-0 mt-0.5 text-amber-600 dark:text-amber-400"}),b.jsxs("div",{className:"flex-1 space-y-2",children:[b.jsx("p",{className:"text-sm font-medium text-amber-600 dark:text-amber-400",children:"Claude Code CLI not found"}),b.jsxs("p",{className:"text-xs text-amber-600/80 dark:text-amber-400/80",children:["Install it with:"," ",b.jsx("code",{className:"rounded bg-amber-500/20 px-1.5 py-0.5 font-mono",children:"npm install -g @anthropic/claude-code"})]}),b.jsx("a",{href:"https://docs.anthropic.com/en/docs/claude-code/overview",target:"_blank",rel:"noopener noreferrer",className:"inline-block text-xs font-medium text-amber-600 hover:text-amber-700 dark:text-amber-400 dark:hover:text-amber-300 underline",children:"View documentation"})]}),b.jsx("button",{onClick:()=>w(!1),className:"shrink-0 p-1 rounded text-amber-600 hover:text-amber-700 hover:bg-amber-500/20 dark:text-amber-400 dark:hover:text-amber-300",children:b.jsx(fe,{icon:fi,size:14,strokeWidth:2})})]})}),b.jsx("button",{onClick:()=>l.current?.scrollToBottom(),className:Be("absolute top-2 right-5 p-1 transition-colors",R?"text-white/50 hover:text-white/80":"text-black/50 hover:text-black/80"),children:b.jsx(fe,{icon:pM,size:20,strokeWidth:2})})]}),b.jsx(oS,{onSend:G})]}):b.jsx("div",{className:Be("flex h-full items-center justify-center text-muted-foreground text-sm bg-terminal-background",n),children:"No worktree path configured for this task"})}function wWe(e,t,{checkForDefaultPrevented:n=!0}={}){return function(i){if(e?.(i),n===!1||!i.defaultPrevented)return t?.(i)}}function TWe(e,t=[]){let n=[];function r(a,s){const o=k.createContext(s),l=n.length;n=[...n,s];const u=d=>{const{scope:p,children:m,...E}=d,S=p?.[e]?.[l]||o,g=k.useMemo(()=>E,Object.values(E));return b.jsx(S.Provider,{value:g,children:m})};u.displayName=a+"Provider";function f(d,p){const m=p?.[e]?.[l]||o,E=k.useContext(m);if(E)return E;if(s!==void 0)return s;throw new Error(`\`${d}\` must be used within \`${a}\``)}return[u,f]}const i=()=>{const a=n.map(s=>k.createContext(s));return function(o){const l=o?.[e]||a;return k.useMemo(()=>({[`__scope${e}`]:{...o,[e]:l}}),[o,l])}};return i.scopeName=e,[r,CWe(i,...t)]}function CWe(...e){const t=e[0];if(e.length===1)return t;const n=()=>{const r=e.map(i=>({useScope:i(),scopeName:i.scopeName}));return function(a){const s=r.reduce((o,{useScope:l,scopeName:u})=>{const d=l(a)[`__scope${u}`];return{...o,...d}},{});return k.useMemo(()=>({[`__scope${t.scopeName}`]:s}),[s])}};return n.scopeName=t.scopeName,n}var ky=globalThis?.document?k.useLayoutEffect:()=>{},AWe=_x[" useInsertionEffect ".trim().toString()]||ky;function kWe({prop:e,defaultProp:t,onChange:n=()=>{},caller:r}){const[i,a,s]=OWe({defaultProp:t,onChange:n}),o=e!==void 0,l=o?e:i;{const f=k.useRef(e!==void 0);k.useEffect(()=>{const d=f.current;d!==o&&console.warn(`${r} is changing from ${d?"controlled":"uncontrolled"} to ${o?"controlled":"uncontrolled"}. Components should not switch from controlled to uncontrolled (or vice versa). Decide between using a controlled or uncontrolled value for the lifetime of the component.`),f.current=o},[o,r])}const u=k.useCallback(f=>{if(o){const d=RWe(f)?f(e):f;d!==e&&s.current?.(d)}else a(f)},[o,e,a,s]);return[l,u]}function OWe({defaultProp:e,onChange:t}){const[n,r]=k.useState(e),i=k.useRef(n),a=k.useRef(t);return AWe(()=>{a.current=t},[t]),k.useEffect(()=>{i.current!==n&&(a.current?.(n),i.current=n)},[n,i]),[n,r,a]}function RWe(e){return typeof e=="function"}function ZX(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}function zle(...e){return t=>{let n=!1;const r=e.map(i=>{const a=ZX(i,t);return!n&&typeof a=="function"&&(n=!0),a});if(n)return()=>{for(let i=0;i<r.length;i++){const a=r[i];typeof a=="function"?a():ZX(e[i],null)}}}}function Hle(...e){return k.useCallback(zle(...e),e)}function NWe(e){const t=IWe(e),n=k.forwardRef((r,i)=>{const{children:a,...s}=r,o=k.Children.toArray(a),l=o.find(LWe);if(l){const u=l.props.children,f=o.map(d=>d===l?k.Children.count(u)>1?k.Children.only(null):k.isValidElement(u)?u.props.children:null:d);return b.jsx(t,{...s,ref:i,children:k.isValidElement(u)?k.cloneElement(u,void 0,f):null})}return b.jsx(t,{...s,ref:i,children:a})});return n.displayName=`${e}.Slot`,n}function IWe(e){const t=k.forwardRef((n,r)=>{const{children:i,...a}=n;if(k.isValidElement(i)){const s=MWe(i),o=PWe(a,i.props);return i.type!==k.Fragment&&(o.ref=r?zle(r,s):s),k.cloneElement(i,o)}return k.Children.count(i)>1?k.Children.only(null):null});return t.displayName=`${e}.SlotClone`,t}var DWe=Symbol("radix.slottable");function LWe(e){return k.isValidElement(e)&&typeof e.type=="function"&&"__radixId"in e.type&&e.type.__radixId===DWe}function PWe(e,t){const n={...t};for(const r in t){const i=e[r],a=t[r];/^on[A-Z]/.test(r)?i&&a?n[r]=(...o)=>{const l=a(...o);return i(...o),l}:i&&(n[r]=i):r==="style"?n[r]={...i,...a}:r==="className"&&(n[r]=[i,a].filter(Boolean).join(" "))}return{...e,...n}}function MWe(e){let t=Object.getOwnPropertyDescriptor(e.props,"ref")?.get,n=t&&"isReactWarning"in t&&t.isReactWarning;return n?e.ref:(t=Object.getOwnPropertyDescriptor(e,"ref")?.get,n=t&&"isReactWarning"in t&&t.isReactWarning,n?e.props.ref:e.props.ref||e.ref)}var jWe=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],v5=jWe.reduce((e,t)=>{const n=NWe(`Primitive.${t}`),r=k.forwardRef((i,a)=>{const{asChild:s,...o}=i,l=s?n:t;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),b.jsx(l,{...o,ref:a})});return r.displayName=`Primitive.${t}`,{...e,[t]:r}},{});function FWe(e,t){return k.useReducer((n,r)=>t[n][r]??n,e)}var Wle=e=>{const{present:t,children:n}=e,r=BWe(t),i=typeof n=="function"?n({present:r.isPresent}):k.Children.only(n),a=Hle(r.ref,UWe(i));return typeof n=="function"||r.isPresent?k.cloneElement(i,{ref:a}):null};Wle.displayName="Presence";function BWe(e){const[t,n]=k.useState(),r=k.useRef(null),i=k.useRef(e),a=k.useRef("none"),s=e?"mounted":"unmounted",[o,l]=FWe(s,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return k.useEffect(()=>{const u=G_(r.current);a.current=o==="mounted"?u:"none"},[o]),ky(()=>{const u=r.current,f=i.current;if(f!==e){const p=a.current,m=G_(u);e?l("MOUNT"):m==="none"||u?.display==="none"?l("UNMOUNT"):l(f&&p!==m?"ANIMATION_OUT":"UNMOUNT"),i.current=e}},[e,l]),ky(()=>{if(t){let u;const f=t.ownerDocument.defaultView??window,d=m=>{const S=G_(r.current).includes(CSS.escape(m.animationName));if(m.target===t&&S&&(l("ANIMATION_END"),!i.current)){const g=t.style.animationFillMode;t.style.animationFillMode="forwards",u=f.setTimeout(()=>{t.style.animationFillMode==="forwards"&&(t.style.animationFillMode=g)})}},p=m=>{m.target===t&&(a.current=G_(r.current))};return t.addEventListener("animationstart",p),t.addEventListener("animationcancel",d),t.addEventListener("animationend",d),()=>{f.clearTimeout(u),t.removeEventListener("animationstart",p),t.removeEventListener("animationcancel",d),t.removeEventListener("animationend",d)}}else l("ANIMATION_END")},[t,l]),{isPresent:["mounted","unmountSuspended"].includes(o),ref:k.useCallback(u=>{r.current=u?getComputedStyle(u):null,n(u)},[])}}function G_(e){return e?.animationName||"none"}function UWe(e){let t=Object.getOwnPropertyDescriptor(e.props,"ref")?.get,n=t&&"isReactWarning"in t&&t.isReactWarning;return n?e.ref:(t=Object.getOwnPropertyDescriptor(e,"ref")?.get,n=t&&"isReactWarning"in t&&t.isReactWarning,n?e.props.ref:e.props.ref||e.ref)}var $We=_x[" useId ".trim().toString()]||(()=>{}),zWe=0;function HWe(e){const[t,n]=k.useState($We());return ky(()=>{n(r=>r??String(zWe++))},[e]),e||(t?`radix-${t}`:"")}var nT="Collapsible",[WWe]=TWe(nT),[VWe,y5]=WWe(nT),Vle=k.forwardRef((e,t)=>{const{__scopeCollapsible:n,open:r,defaultOpen:i,disabled:a,onOpenChange:s,...o}=e,[l,u]=kWe({prop:r,defaultProp:i??!1,onChange:s,caller:nT});return b.jsx(VWe,{scope:n,disabled:a,contentId:HWe(),open:l,onOpenToggle:k.useCallback(()=>u(f=>!f),[u]),children:b.jsx(v5.div,{"data-state":E5(l),"data-disabled":a?"":void 0,...o,ref:t})})});Vle.displayName=nT;var Gle="CollapsibleTrigger",qle=k.forwardRef((e,t)=>{const{__scopeCollapsible:n,...r}=e,i=y5(Gle,n);return b.jsx(v5.button,{type:"button","aria-controls":i.contentId,"aria-expanded":i.open||!1,"data-state":E5(i.open),"data-disabled":i.disabled?"":void 0,disabled:i.disabled,...r,ref:t,onClick:wWe(e.onClick,i.onOpenToggle)})});qle.displayName=Gle;var _5="CollapsibleContent",Kle=k.forwardRef((e,t)=>{const{forceMount:n,...r}=e,i=y5(_5,e.__scopeCollapsible);return b.jsx(Wle,{present:n||i.open,children:({present:a})=>b.jsx(GWe,{...r,ref:t,present:a})})});Kle.displayName=_5;var GWe=k.forwardRef((e,t)=>{const{__scopeCollapsible:n,present:r,children:i,...a}=e,s=y5(_5,n),[o,l]=k.useState(r),u=k.useRef(null),f=Hle(t,u),d=k.useRef(0),p=d.current,m=k.useRef(0),E=m.current,S=s.open||o,g=k.useRef(S),y=k.useRef(void 0);return k.useEffect(()=>{const v=requestAnimationFrame(()=>g.current=!1);return()=>cancelAnimationFrame(v)},[]),ky(()=>{const v=u.current;if(v){y.current=y.current||{transitionDuration:v.style.transitionDuration,animationName:v.style.animationName},v.style.transitionDuration="0s",v.style.animationName="none";const x=v.getBoundingClientRect();d.current=x.height,m.current=x.width,g.current||(v.style.transitionDuration=y.current.transitionDuration,v.style.animationName=y.current.animationName),l(r)}},[s.open,r]),b.jsx(v5.div,{"data-state":E5(s.open),"data-disabled":s.disabled?"":void 0,id:s.contentId,hidden:!S,...a,ref:f,style:{"--radix-collapsible-content-height":p?`${p}px`:void 0,"--radix-collapsible-content-width":E?`${E}px`:void 0,...e.style},children:S&&i})});function E5(e){return e?"open":"closed"}var qWe=Vle;const KWe=qWe,YWe=qle,XWe=Kle;function ZWe(e){const{viewState:t,setDiffOptions:n}=g5(e),{collapsedFiles:r}=t.diffOptions,i=k.useCallback(l=>{const u=r.includes(l);n({collapsedFiles:u?r.filter(f=>f!==l):[...r,l]})},[r,n]),a=k.useCallback(l=>{n({collapsedFiles:l})},[n]),s=k.useCallback(()=>{n({collapsedFiles:[]})},[n]),o=k.useCallback(l=>r.includes(l),[r]);return{options:t.diffOptions,setOption:(l,u)=>{n({[l]:u})},setOptions:n,toggleFileCollapse:i,collapseAll:a,expandAll:s,isFileCollapsed:o}}function QWe(e){const t=[];let n=null,r=0,i=0;for(const a of e.split(`
116
116
  `))if(a.startsWith("diff --git"))n={path:a.match(/diff --git a\/(.+?) b\//)?.[1]??"unknown",lines:[],additions:0,deletions:0},t.push(n),n.lines.push({type:"header",content:a});else if(a.startsWith("index ")||a.startsWith("---")||a.startsWith("+++"))n?.lines.push({type:"header",content:a});else if(a.startsWith("@@")){const s=a.match(/@@ -(\d+),?\d* \+(\d+),?\d* @@/);s&&(r=parseInt(s[1],10),i=parseInt(s[2],10)),n?.lines.push({type:"hunk",content:a})}else a.startsWith("+")?n&&(n.additions++,n.lines.push({type:"added",content:a.slice(1),newLineNumber:i++})):a.startsWith("-")?n&&(n.deletions++,n.lines.push({type:"removed",content:a.slice(1),oldLineNumber:r++})):a.startsWith(" ")&&n?.lines.push({type:"context",content:a.slice(1),oldLineNumber:r++,newLineNumber:i++});return t}function JWe({file:e,wrap:t,isCollapsed:n,onToggle:r}){return b.jsxs(KWe,{open:!n,onOpenChange:()=>r(),children:[b.jsx(YWe,{asChild:!0,children:b.jsxs("div",{className:"flex items-center gap-2 px-2 py-1.5 bg-card border-b border-border cursor-pointer hover:bg-muted select-none",children:[b.jsx(fe,{icon:n?Xy:Yy,size:12,strokeWidth:2,className:"text-muted-foreground shrink-0"}),b.jsx("span",{className:"font-mono text-xs text-foreground truncate flex-1",children:e.path}),b.jsxs("span",{className:"text-xs text-muted-foreground shrink-0",children:[e.additions>0&&b.jsxs("span",{className:"text-accent",children:["+",e.additions]}),e.additions>0&&e.deletions>0&&" ",e.deletions>0&&b.jsxs("span",{className:"text-destructive",children:["-",e.deletions]})]})]})}),b.jsx(XWe,{children:b.jsx("div",{className:"font-mono text-xs",children:e.lines.slice(1).map((i,a)=>b.jsxs("div",{className:Be("flex px-2 py-0.5",i.type==="added"&&"bg-accent/10",i.type==="removed"&&"bg-destructive/10",i.type==="header"&&"bg-muted/50 text-muted-foreground",i.type==="hunk"&&"bg-accent/10 text-accent"),children:[(i.type==="added"||i.type==="removed"||i.type==="context")&&b.jsxs(b.Fragment,{children:[b.jsx("span",{className:"w-10 shrink-0 select-none pr-2 text-right text-muted-foreground",children:i.oldLineNumber??""}),b.jsx("span",{className:"w-10 shrink-0 select-none pr-2 text-right text-muted-foreground",children:i.newLineNumber??""})]}),b.jsxs("span",{className:Be("w-4 shrink-0 select-none text-center",i.type==="added"&&"text-accent",i.type==="removed"&&"text-destructive"),children:[i.type==="added"&&"+",i.type==="removed"&&"-"]}),b.jsx("span",{className:Be("flex-1",t?"whitespace-pre-wrap break-all":"whitespace-pre",i.type==="added"&&"text-accent",i.type==="removed"&&"text-destructive"),children:i.content})]},a))})})]})}function QX({taskId:e,worktreePath:t}){const{options:n,setOption:r,toggleFileCollapse:i,collapseAll:a,expandAll:s,isFileCollapsed:o}=ZWe(e),{wrap:l,ignoreWhitespace:u,includeUntracked:f,collapsedFiles:d}=n,{data:p,isLoading:m,error:E}=Kxe(t,{ignoreWhitespace:u,includeUntracked:f}),S=k.useMemo(()=>p?.diff?QWe(p.diff):[],[p?.diff]),g=k.useMemo(()=>S.map(w=>w.path),[S]),y=S.length>0&&d.length===S.length,v=k.useMemo(()=>S.reduce((w,C)=>w+C.additions,0),[S]),x=k.useMemo(()=>S.reduce((w,C)=>w+C.deletions,0),[S]);if(k.useEffect(()=>{const w=C=>{if(C.shiftKey&&C.key==="C"&&!C.ctrlKey&&!C.metaKey&&!C.altKey){const R=C.target;if(R.tagName==="INPUT"||R.tagName==="TEXTAREA"||R.isContentEditable)return;C.preventDefault(),y?s():a(g)}};return window.addEventListener("keydown",w),()=>window.removeEventListener("keydown",w)},[y,g,a,s]),!t)return b.jsx("div",{className:"flex h-full items-center justify-center text-muted-foreground text-sm",children:"No worktree selected"});if(m)return b.jsx("div",{className:"flex h-full items-center justify-center text-muted-foreground text-sm",children:"Loading diff..."});if(E)return b.jsx("div",{className:"flex h-full items-center justify-center text-destructive text-sm",children:E.message});const T=p?.files?.some(w=>w.status==="untracked")??!1;return S.length===0?b.jsxs("div",{className:"flex h-full flex-col items-center justify-center text-muted-foreground text-sm gap-2",children:[b.jsx("p",{children:"No changes detected"}),p?.files&&p.files.length>0&&b.jsxs("div",{className:"text-xs",children:[b.jsx("p",{className:"text-center mb-2",children:"Modified files:"}),b.jsxs("div",{className:"flex flex-col gap-1",children:[p.files.map(w=>b.jsxs("div",{className:"flex gap-2",children:[b.jsxs("span",{className:Be("w-4 text-center",w.status==="added"&&"text-accent",w.status==="deleted"&&"text-destructive",w.status==="modified"&&"text-muted-foreground",w.status==="untracked"&&"text-muted-foreground"),children:[w.status==="added"&&"A",w.status==="deleted"&&"D",w.status==="modified"&&"M",w.status==="untracked"&&"?"]}),b.jsx("span",{children:w.path})]},w.path)),T&&b.jsxs("label",{className:"flex items-center gap-2 cursor-pointer text-muted-foreground hover:text-foreground mt-1",children:[b.jsx("input",{type:"checkbox",checked:f,onChange:w=>r("includeUntracked",w.target.checked),className:"w-4 h-3"}),b.jsx("span",{children:"Show untracked files"})]})]})]})]}):b.jsxs("div",{className:"flex flex-col h-full bg-background",children:[b.jsxs("div",{className:"flex items-center gap-3 px-2 py-1.5 bg-card border-b border-border text-xs",children:[p?.branch&&b.jsxs("span",{className:"text-muted-foreground",children:[p.branch,p.isBranchDiff&&b.jsx("span",{className:"opacity-70",children:" (vs master)"})]}),(v>0||x>0)&&b.jsxs("span",{className:"text-muted-foreground",children:[b.jsxs("span",{className:"text-accent",children:["+",v]})," ",b.jsxs("span",{className:"text-destructive",children:["-",x]})]}),b.jsx("div",{className:"flex-1"}),b.jsxs("button",{onClick:()=>y?s():a(g),className:"flex items-center gap-1 px-1.5 py-0.5 text-muted-foreground hover:text-foreground rounded hover:bg-muted/50",title:y?"Expand all (Shift+C)":"Collapse all (Shift+C)",children:[b.jsx(fe,{icon:y?Ste:yte,size:12,strokeWidth:2}),b.jsx("span",{className:"hidden sm:inline",children:y?"Expand":"Collapse"})]}),b.jsxs("label",{className:"flex items-center gap-1.5 cursor-pointer text-muted-foreground hover:text-foreground",children:[b.jsx("input",{type:"checkbox",checked:l,onChange:w=>r("wrap",w.target.checked),className:"w-3 h-3"}),"Wrap"]}),b.jsxs("label",{className:"flex items-center gap-1.5 cursor-pointer text-muted-foreground hover:text-foreground",children:[b.jsx("input",{type:"checkbox",checked:u,onChange:w=>r("ignoreWhitespace",w.target.checked),className:"w-3 h-3"}),"Ignore whitespace"]}),b.jsxs("label",{className:"flex items-center gap-1.5 cursor-pointer text-muted-foreground hover:text-foreground",children:[b.jsx("input",{type:"checkbox",checked:f,onChange:w=>r("includeUntracked",w.target.checked),className:"w-3 h-3"}),"Untracked"]})]}),b.jsx(n0,{className:"flex-1 min-h-0",children:S.map(w=>b.jsx(JWe,{file:w,wrap:l,isCollapsed:o(w.path),onToggle:()=>i(w.path)},w.path))})]})}function eVe(e){const{viewState:t,setBrowserUrl:n}=g5(e);return{url:t.browserUrl,setUrl:n}}function JX({taskId:e}){const{url:t,setUrl:n}=eVe(e),[r,i]=k.useState(t),[a,s]=k.useState(0);k.useEffect(()=>{i(t)},[t]);const o=k.useCallback(()=>{s(u=>u+1)},[]),l=k.useCallback(u=>{u.preventDefault();let f=r.trim();!f.startsWith("http://")&&!f.startsWith("https://")&&(f=`http://${f}`),n(f),s(d=>d+1)},[r,n]);return b.jsxs("div",{className:"flex h-full flex-col bg-background",children:[b.jsxs("div",{className:"flex shrink-0 items-center gap-1 border-b border-border bg-card px-2 py-1.5",children:[b.jsx(qe,{variant:"ghost",size:"icon-xs",disabled:!0,children:b.jsx(fe,{icon:lte,size:14,strokeWidth:2})}),b.jsx(qe,{variant:"ghost",size:"icon-xs",disabled:!0,children:b.jsx(fe,{icon:Xy,size:14,strokeWidth:2})}),b.jsx(qe,{variant:"ghost",size:"icon-xs",onClick:o,children:b.jsx(fe,{icon:W1e,size:14,strokeWidth:2})}),b.jsx("form",{onSubmit:l,className:"flex-1",children:b.jsx(dn,{value:r,onChange:u=>i(u.target.value),className:"h-7 bg-background text-xs",placeholder:"Enter URL..."})})]}),b.jsx("div",{className:"flex-1 overflow-hidden bg-card",children:b.jsx("iframe",{src:t,className:"h-full w-full border-0",title:"Browser Preview",sandbox:"allow-scripts allow-same-origin allow-forms allow-popups"},a)})]})}function tVe(e){const t=[];function n(r){for(const i of r)i.type==="file"?t.push({name:i.name,path:i.path}):i.children&&n(i.children)}return n(e),t}function Yle(e){const t=e.split(".").pop()?.toLowerCase()||"";return["png","jpg","jpeg","gif","svg","webp","ico"].includes(t)?F1e:["ts","tsx","js","jsx","json","css","html","md","yaml","yml","toml","sh","py","rs","go","sql"].includes(t)?D1e:L1e}function Xle({entry:e,depth:t,selectedFile:n,expandedDirs:r,onSelectFile:i,onToggleDir:a}){const s=r.includes(e.path),o=n===e.path,l=e.type==="directory",u=k.useCallback(()=>{l?a(e.path):i(e.path)},[l,e.path,i,a]);return b.jsxs("div",{children:[b.jsxs("div",{className:Be("flex items-center gap-1.5 px-2 py-0.5 cursor-pointer text-sm hover:bg-muted/50",o&&"bg-primary/10 text-primary"),style:{paddingLeft:`${t*12+8}px`},onClick:u,children:[b.jsx(fe,{icon:l?s?JI:Vi:Yle(e.name),size:14,strokeWidth:2,className:Be("shrink-0",l?"text-accent":"text-muted-foreground")}),b.jsx("span",{className:"break-all",children:e.name})]}),l&&s&&e.children&&b.jsx("div",{children:e.children.map(f=>b.jsx(Xle,{entry:f,depth:t+1,selectedFile:n,expandedDirs:r,onSelectFile:i,onToggleDir:a},f.path))})]})}function nVe({entries:e,selectedFile:t,expandedDirs:n,onSelectFile:r,onToggleDir:i,onCollapseAll:a}){const[s,o]=k.useState(""),l=k.useMemo(()=>tVe(e),[e]),u=k.useMemo(()=>{if(!s.trim())return null;const d=s.trim();return l.map(p=>({...p,score:Math.max(no(p.name,d),no(p.path,d))})).filter(p=>p.score>0).sort((p,m)=>m.score-p.score)},[l,s]),f=k.useCallback(()=>{o("")},[]);return e.length===0?b.jsx("div",{className:"flex items-center justify-center h-full text-muted-foreground text-sm",children:"No files"}):b.jsxs("div",{className:"flex flex-col h-full bg-background",children:[b.jsxs("div",{className:"flex shrink-0 items-center justify-between px-2 py-1 border-b border-border bg-card",children:[b.jsx("span",{className:"text-xs text-muted-foreground",children:"Files"}),b.jsx("button",{onClick:a,className:"p-1 text-muted-foreground hover:text-foreground rounded hover:bg-muted/50",title:"Collapse all folders",children:b.jsx(fe,{icon:yte,size:14,strokeWidth:2})})]}),b.jsx("div",{className:"shrink-0 px-2 py-1.5 border-b border-border bg-card",children:b.jsxs("div",{className:"relative",children:[b.jsx("input",{type:"text",value:s,onChange:d=>o(d.target.value),placeholder:"Search files...",className:"w-full text-sm bg-muted/50 border border-border rounded px-2 py-1 pr-7 placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-ring"}),s&&b.jsx("button",{onClick:f,className:"absolute right-1.5 top-1/2 -translate-y-1/2 p-0.5 text-muted-foreground hover:text-foreground rounded hover:bg-muted",children:b.jsx(fe,{icon:fi,size:12,strokeWidth:2})})]})}),b.jsx("div",{className:"py-1 flex-1 overflow-auto",children:u?u.length>0?u.map(d=>b.jsxs("div",{className:Be("flex items-center gap-1.5 px-2 py-0.5 cursor-pointer text-sm hover:bg-muted/50",t===d.path&&"bg-primary/10 text-primary"),onClick:()=>r(d.path),children:[b.jsx(fe,{icon:Yle(d.name),size:14,strokeWidth:2,className:"shrink-0 text-muted-foreground"}),b.jsx("span",{className:"truncate",title:d.path,children:d.name}),b.jsx("span",{className:"text-xs text-muted-foreground truncate ml-auto",children:d.path.split("/").slice(0,-1).join("/")})]},d.path)):b.jsx("div",{className:"px-2 py-4 text-center text-sm text-muted-foreground",children:"No matching files"}):e.map(d=>b.jsx(Xle,{entry:d,depth:0,selectedFile:t,expandedDirs:n,onSelectFile:r,onToggleDir:i},d.path))})]})}function eZ(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function rVe(e){if(Array.isArray(e))return e}function iVe(e,t,n){return(t=dVe(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function aVe(e,t){var n=e==null?null:typeof Symbol<"u"&&e[Symbol.iterator]||e["@@iterator"];if(n!=null){var r,i,a,s,o=[],l=!0,u=!1;try{if(a=(n=n.call(e)).next,t!==0)for(;!(l=(r=a.call(n)).done)&&(o.push(r.value),o.length!==t);l=!0);}catch(f){u=!0,i=f}finally{try{if(!l&&n.return!=null&&(s=n.return(),Object(s)!==s))return}finally{if(u)throw i}}return o}}function sVe(){throw new TypeError(`Invalid attempt to destructure non-iterable instance.
package/dist/index.html CHANGED
@@ -5,7 +5,7 @@
5
5
  <link rel="icon" type="image/jpeg" href="/logo-dark.jpg" />
6
6
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
7
7
  <title>Vibora</title>
8
- <script type="module" crossorigin src="/assets/index-D2-XYqt8.js"></script>
8
+ <script type="module" crossorigin src="/assets/index-C1C5XQSE.js"></script>
9
9
  <link rel="stylesheet" crossorigin href="/assets/index-uq7fsilP.css">
10
10
  </head>
11
11
  <body>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vibora",
3
- "version": "4.7.1",
3
+ "version": "4.7.2",
4
4
  "description": "The Vibe Engineer's Cockpit",
5
5
  "license": "PolyForm-Shield-1.0.0",
6
6
  "repository": {