@hasna/todos 0.11.65 → 0.11.67
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +78 -49
- package/dashboard/dist/assets/{index-aJefI7kh.js → index-DVotjwab.js} +1 -1
- package/dashboard/dist/index.html +1 -1
- package/dist/cli/commands/project-commands.d.ts.map +1 -1
- package/dist/cli/commands/query-commands.d.ts.map +1 -1
- package/dist/cli/commands/storage-commands.d.ts +5 -0
- package/dist/cli/commands/storage-commands.d.ts.map +1 -1
- package/dist/cli/commands/task-commands.d.ts.map +1 -1
- package/dist/cli/index.js +1034 -231
- package/dist/contracts.js +409 -129
- package/dist/db/agents.d.ts.map +1 -1
- package/dist/db/audit.d.ts.map +1 -1
- package/dist/db/migrations.d.ts.map +1 -1
- package/dist/db/plans.d.ts.map +1 -1
- package/dist/db/projects.d.ts.map +1 -1
- package/dist/db/schema.d.ts.map +1 -1
- package/dist/db/storage-tombstones.d.ts +26 -0
- package/dist/db/storage-tombstones.d.ts.map +1 -0
- package/dist/db/task-crud.d.ts.map +1 -1
- package/dist/db/task-lifecycle.d.ts.map +1 -1
- package/dist/db/task-lists.d.ts.map +1 -1
- package/dist/db/task-runs.d.ts.map +1 -1
- package/dist/db/templates.d.ts.map +1 -1
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +928 -219
- package/dist/lib/approval-gates.d.ts.map +1 -1
- package/dist/lib/event-emission-safety.d.ts +9 -0
- package/dist/lib/event-emission-safety.d.ts.map +1 -0
- package/dist/lib/event-hooks.d.ts +1 -0
- package/dist/lib/event-hooks.d.ts.map +1 -1
- package/dist/lib/feature-manifest.d.ts.map +1 -1
- package/dist/lib/project-bootstrap.d.ts +1 -0
- package/dist/lib/project-bootstrap.d.ts.map +1 -1
- package/dist/lib/review-queues.d.ts.map +1 -1
- package/dist/lib/shared-events.d.ts +1 -0
- package/dist/lib/shared-events.d.ts.map +1 -1
- package/dist/lib/task-route-contract.d.ts +33 -0
- package/dist/lib/task-route-contract.d.ts.map +1 -0
- package/dist/lib/task-routing.d.ts +55 -0
- package/dist/lib/task-routing.d.ts.map +1 -0
- package/dist/mcp/index.js +459 -162
- package/dist/registry.js +409 -129
- package/dist/release-provenance.json +3 -3
- package/dist/server/index.js +482 -185
- package/dist/storage/interfaces.d.ts +20 -0
- package/dist/storage/interfaces.d.ts.map +1 -1
- package/dist/storage/postgres-adapter.d.ts.map +1 -1
- package/dist/storage/postgres-sync.d.ts +6 -1
- package/dist/storage/postgres-sync.d.ts.map +1 -1
- package/dist/storage/sqlite-snapshot.d.ts.map +1 -1
- package/dist/storage.js +677 -152
- package/dist/types/index.d.ts +22 -0
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -336,7 +336,7 @@ For more information, see https://radix-ui.com/primitives/docs/components/${a.do
|
|
|
336
336
|
* LICENSE.md file in the root directory of this source tree.
|
|
337
337
|
*
|
|
338
338
|
* @license MIT
|
|
339
|
-
*/function bl(e,a){return e?NT(e)?x.createElement(e,a):e:null}function NT(e){return jT(e)||typeof e=="function"||MT(e)}function jT(e){return typeof e=="function"&&(()=>{const a=Object.getPrototypeOf(e);return a.prototype&&a.prototype.isReactComponent})()}function MT(e){return typeof e=="object"&&typeof e.$$typeof=="symbol"&&["react.memo","react.forward_ref"].includes(e.$$typeof.description)}function fu(e){const a={state:{},onStateChange:()=>{},renderFallbackValue:null,...e},[l]=x.useState(()=>({current:yT(a)})),[r,s]=x.useState(()=>l.current.initialState);return l.current.setOptions(u=>({...u,...e,state:{...r,...e.state},onStateChange:f=>{s(f),e.onStateChange==null||e.onStateChange(f)}})),l.current}const _T=i0("inline-flex items-center rounded-full border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",{variants:{variant:{default:"border-transparent bg-primary text-primary-foreground",secondary:"border-transparent bg-secondary text-secondary-foreground",destructive:"border-transparent bg-destructive text-white",outline:"text-foreground"}},defaultVariants:{variant:"default"}});function Ht({className:e,variant:a,...l}){return c.jsx("div",{className:Ae(_T({variant:a}),e),...l})}const It=x.forwardRef(({className:e,type:a,...l},r)=>c.jsx("input",{type:a,className:Ae("flex h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-base shadow-sm transition-colors file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50 md:text-sm dark:bg-input/30",e),ref:r,...l}));It.displayName="Input";const Fs=x.forwardRef(({className:e,...a},l)=>c.jsx("div",{className:"relative w-full overflow-auto",children:c.jsx("table",{ref:l,className:Ae("w-full caption-bottom text-sm",e),...a})}));Fs.displayName="Table";const Bs=x.forwardRef(({className:e,...a},l)=>c.jsx("thead",{ref:l,className:Ae("[&_tr]:border-b",e),...a}));Bs.displayName="TableHeader";const Vs=x.forwardRef(({className:e,...a},l)=>c.jsx("tbody",{ref:l,className:Ae("[&_tr:last-child]:border-0",e),...a}));Vs.displayName="TableBody";const RT=x.forwardRef(({className:e,...a},l)=>c.jsx("tfoot",{ref:l,className:Ae("border-t bg-muted/50 font-medium [&>tr]:last:border-b-0",e),...a}));RT.displayName="TableFooter";const mn=x.forwardRef(({className:e,...a},l)=>c.jsx("tr",{ref:l,className:Ae("border-b transition-colors hover:bg-muted/50 data-[state=selected]:bg-muted",e),...a}));mn.displayName="TableRow";const Us=x.forwardRef(({className:e,...a},l)=>c.jsx("th",{ref:l,className:Ae("h-10 px-2 text-left align-middle font-medium text-muted-foreground [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",e),...a}));Us.displayName="TableHead";const Pa=x.forwardRef(({className:e,...a},l)=>c.jsx("td",{ref:l,className:Ae("p-2 align-middle [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",e),...a}));Pa.displayName="TableCell";const ET=x.forwardRef(({className:e,...a},l)=>c.jsx("caption",{ref:l,className:Ae("mt-4 text-sm text-muted-foreground",e),...a}));ET.displayName="TableCaption";const gn=v2,hn=y2,Zt=x.forwardRef(({className:e,children:a,...l},r)=>c.jsxs(x2,{ref:r,className:Ae("flex h-9 w-full items-center justify-between gap-2 rounded-md border border-input bg-transparent px-3 py-2 text-sm shadow-sm ring-offset-background placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-ring disabled:cursor-not-allowed disabled:opacity-50 [&>span]:line-clamp-1",e),...l,children:[a,c.jsx(b2,{asChild:!0,children:c.jsx(n0,{className:"size-4 opacity-50"})})]}));Zt.displayName="SelectTrigger";const Jt=x.forwardRef(({className:e,children:a,position:l="popper",...r},s)=>c.jsx(S2,{children:c.jsx(w2,{ref:s,className:Ae("relative z-50 max-h-96 min-w-[8rem] overflow-hidden rounded-md border bg-popover text-popover-foreground shadow-md animate-in",l==="popper"&&"translate-y-1",e),position:l,...r,children:c.jsx(C2,{className:Ae("p-1",l==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"),children:a})})}));Jt.displayName="SelectContent";const Te=x.forwardRef(({className:e,children:a,...l},r)=>c.jsxs(N2,{ref:r,className:Ae("relative flex w-full cursor-default select-none items-center rounded-sm py-1.5 pl-2 pr-8 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",e),...l,children:[c.jsx("span",{className:"absolute right-2 flex h-3.5 w-3.5 items-center justify-center",children:c.jsx(M2,{children:c.jsx(t0,{className:"h-4 w-4"})})}),c.jsx(j2,{children:a})]}));Te.displayName="SelectItem";const DT=x.forwardRef(({className:e,...a},l)=>c.jsx(_2,{ref:l,className:Ae("-mx-1 my-1 h-px bg-muted",e),...a}));DT.displayName="SelectSeparator";const ra=g_,TT=h_,dw=x.forwardRef(({className:e,...a},l)=>c.jsx(p_,{ref:l,className:Ae("fixed inset-0 z-50 bg-black/50 data-[state=open]:animate-in data-[state=closed]:animate-out",e),...a}));dw.displayName="DialogOverlay";const In=x.forwardRef(({className:e,children:a,...l},r)=>c.jsxs(TT,{children:[c.jsx(dw,{}),c.jsxs(v_,{ref:r,className:Ae("fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out sm:rounded-lg",e),...l,children:[a,c.jsxs(b_,{className:"absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none",children:[c.jsx(Fm,{className:"h-4 w-4"}),c.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));In.displayName="DialogContent";const Ba=({className:e,...a})=>c.jsx("div",{className:Ae("flex flex-col space-y-1.5 text-center sm:text-left",e),...a}),Is=({className:e,...a})=>c.jsx("div",{className:Ae("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",e),...a}),sa=x.forwardRef(({className:e,...a},l)=>c.jsx(x_,{ref:l,className:Ae("text-lg font-semibold leading-none tracking-tight",e),...a}));sa.displayName="DialogTitle";const OT=x.forwardRef(({className:e,...a},l)=>c.jsx(y_,{ref:l,className:Ae("text-sm text-muted-foreground",e),...a}));OT.displayName="DialogDescription";function Cy(e){const a=Math.floor((Date.now()-new Date(e).getTime())/1e3);if(a<60)return`${a}s`;const l=Math.floor(a/60);if(l<60)return`${l}m`;const r=Math.floor(l/60);return r<24?`${r}h`:`${Math.floor(r/24)}d`}const Ny={critical:{border:"border-l-red-500",dot:"bg-red-500",label:"Critical"},high:{border:"border-l-orange-500",dot:"bg-orange-500",label:"High"},medium:{border:"border-l-blue-500",dot:"bg-blue-500",label:"Medium"},low:{border:"border-l-gray-400",dot:"bg-gray-400",label:"Low"}},jy={pending:{text:"text-yellow-500",bg:"bg-yellow-500"},in_progress:{text:"text-blue-500",bg:"bg-blue-500"},completed:{text:"text-green-500",bg:"bg-green-500"},failed:{text:"text-red-500",bg:"bg-red-500"},cancelled:{text:"text-gray-400",bg:"bg-gray-400"}},My=["bg-blue-500","bg-green-500","bg-purple-500","bg-orange-500","bg-pink-500","bg-teal-500","bg-indigo-500","bg-red-500"];function AT(e){let a=0;for(const l of e)a=(a<<5)-a+l.charCodeAt(0)|0;return My[Math.abs(a)%My.length]}function _y({name:e}){return c.jsx("span",{className:`inline-flex size-5 items-center justify-center rounded-full text-[10px] font-bold text-white ${AT(e)}`,title:e,children:e[0].toUpperCase()})}function kT(e,a){const l={critical:0,high:1,medium:2,low:3};return[...e].sort((r,s)=>a==="priority"?(l[r.priority]??4)-(l[s.priority]??4):a==="updated"?new Date(s.updated_at).getTime()-new Date(r.updated_at).getTime():a==="created"?new Date(s.created_at).getTime()-new Date(r.created_at).getTime():0)}function zT({task:e,projectMap:a,compact:l,onStart:r,onComplete:s,onDelete:u,onEdit:f,onSelect:m,onDragStart:h}){const[p,v]=x.useState(!1),y=e.project_id?a.get(e.project_id):null,w=Ny[e.priority]||Ny.medium,S=e.assigned_to||e.agent_id;return l?c.jsxs("div",{draggable:!0,onDragStart:N=>h(N,e),onClick:()=>m(e),className:`flex items-center gap-2 rounded-md border border-l-4 ${w.border} px-2 py-1.5 cursor-pointer hover:bg-accent/50 transition-colors`,children:[c.jsx("span",{className:`size-2 rounded-full shrink-0 ${w.dot}`}),c.jsx("span",{className:"text-sm truncate flex-1",children:e.title}),S&&c.jsx(_y,{name:S}),c.jsx("span",{className:"text-sm text-muted-foreground shrink-0",children:Cy(e.updated_at)})]}):c.jsxs("div",{draggable:!0,onDragStart:N=>h(N,e),onClick:()=>m(e),onMouseEnter:()=>v(!0),onMouseLeave:()=>v(!1),className:`rounded-lg border border-l-4 ${w.border} bg-card p-3 cursor-pointer hover:bg-accent/50 transition-colors relative`,children:[c.jsxs("div",{className:"flex items-start justify-between gap-2",children:[c.jsxs("div",{className:"min-w-0 flex-1",children:[c.jsxs("div",{className:"flex items-center gap-1.5 mb-1",children:[c.jsx("span",{className:`size-2 rounded-full shrink-0 ${w.dot}`,title:w.label}),c.jsx("code",{className:"text-sm text-muted-foreground",children:e.short_id||e.id.slice(0,8)})]}),c.jsx("p",{className:"text-sm font-medium leading-tight line-clamp-2",children:e.title}),p&&e.description&&c.jsx("p",{className:"mt-1 text-sm text-muted-foreground line-clamp-2",children:e.description})]}),c.jsx("div",{onClick:N=>N.stopPropagation(),className:"shrink-0",children:c.jsxs(jl,{children:[c.jsx(Ml,{asChild:!0,children:c.jsx(se,{variant:"ghost",size:"icon",className:"size-6",children:c.jsx(_s,{className:"size-3.5"})})}),c.jsxs(Fa,{align:"end",children:[c.jsxs(dt,{onClick:()=>f(e),children:[c.jsx(oo,{className:"size-3.5 mr-2"})," Edit"]}),e.status==="pending"&&c.jsxs(dt,{onClick:()=>r(e.id),children:[c.jsx(eo,{className:"size-3.5 mr-2"})," Start"]}),e.status==="in_progress"&&c.jsxs(dt,{onClick:()=>s(e.id),children:[c.jsx(Jr,{className:"size-3.5 mr-2"})," Complete"]}),c.jsx(mo,{}),c.jsxs(dt,{className:"text-red-500 focus:text-red-500",onClick:()=>u(e.id),children:[c.jsx(la,{className:"size-3.5 mr-2"})," Delete"]})]})]})})]}),c.jsxs("div",{className:"mt-2 flex items-center gap-2 text-sm text-muted-foreground",children:[y&&c.jsx(Ht,{variant:"outline",className:"text-sm px-1.5 py-0",children:y}),c.jsx("div",{className:"flex-1"}),c.jsxs("div",{onClick:N=>N.stopPropagation(),className:"flex items-center gap-0.5",children:[e.status==="pending"&&c.jsx(se,{variant:"ghost",size:"icon",className:"size-5",title:"Start",onClick:()=>r(e.id),children:c.jsx(eo,{className:"size-3 text-blue-500"})}),e.status==="in_progress"&&c.jsx(se,{variant:"ghost",size:"icon",className:"size-5",title:"Complete",onClick:()=>s(e.id),children:c.jsx(Jr,{className:"size-3 text-green-500"})})]}),S&&c.jsx(_y,{name:S}),c.jsx("span",{children:Cy(e.updated_at)})]})]})}function Ry({status:e,label:a,tasks:l,collapsed:r,onToggleCollapse:s,sortField:u,onSortChange:f,showLimit:m,onShowMore:h,compact:p,projectMap:v,onStart:y,onComplete:w,onDelete:S,onEdit:N,onSelect:C,onDragStart:M,onDrop:T,onDragOver:D}){const _=jy[e]||jy.pending,O=kT(l,u),H=O.slice(0,m),E=O.length-H.length;return c.jsxs("div",{className:"flex flex-col",onDragOver:D,onDrop:()=>T(e),children:[c.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[c.jsx(se,{variant:"ghost",size:"icon",className:"size-5",onClick:s,children:r?c.jsx(ro,{className:"size-3.5"}):c.jsx(n0,{className:"size-3.5"})}),c.jsx("span",{className:`size-2.5 rounded-full ${_.bg}`}),c.jsx("h3",{className:`text-sm font-semibold ${_.text}`,children:a}),c.jsx(Ht,{variant:"secondary",className:"text-sm px-1.5 py-0 ml-auto",children:l.length}),!r&&c.jsx("div",{onClick:k=>k.stopPropagation(),children:c.jsxs(jl,{children:[c.jsx(Ml,{asChild:!0,children:c.jsx(se,{variant:"ghost",size:"icon",className:"size-5",children:c.jsx(dn,{className:"size-3"})})}),c.jsxs(Fa,{align:"end",children:[c.jsxs(dt,{onClick:()=>f("priority"),children:[u==="priority"&&"• ","Priority"]}),c.jsxs(dt,{onClick:()=>f("updated"),children:[u==="updated"&&"• ","Updated"]}),c.jsxs(dt,{onClick:()=>f("created"),children:[u==="created"&&"• ","Created"]})]})]})})]}),!r&&c.jsxs("div",{className:"space-y-2 min-h-[100px]",children:[H.length===0?c.jsx("div",{className:"rounded-lg border border-dashed p-4 text-center text-sm text-muted-foreground",children:"No tasks"}):H.map(k=>c.jsx(zT,{task:k,projectMap:v,compact:p,onStart:y,onComplete:w,onDelete:S,onEdit:N,onSelect:C,onDragStart:M},k.id)),E>0&&c.jsxs(se,{variant:"ghost",size:"sm",className:"w-full text-sm text-muted-foreground",onClick:h,children:["Show ",Math.min(E,20)," more (",E," remaining)"]})]}),r&&c.jsxs("div",{className:"text-sm text-muted-foreground text-center py-2 border border-dashed rounded-lg",children:[l.length," task(s)"]})]})}const Ey=[{key:"pending",label:"Pending"},{key:"in_progress",label:"In Progress"},{key:"completed",label:"Completed"},{key:"failed",label:"Failed"},{key:"cancelled",label:"Cancelled"}];function PT({data:e,projectMap:a,onStart:l,onComplete:r,onDelete:s,onEdit:u,onSelect:f,onStatusChange:m}){const[h,p]=x.useState({completed:!0,cancelled:!0}),[v,y]=x.useState({}),[w,S]=x.useState({}),[N,C]=x.useState(!1),[M,T]=x.useState(!1),[D,_]=x.useState("all"),[O,H]=x.useState(!1),[E,k]=x.useState(null),[F,K]=x.useState(null),W=15,Z=x.useMemo(()=>D==="all"?e:e.filter(G=>G.priority===D),[e,D]),re=M?Ey:Ey.filter(G=>G.key!=="cancelled");function ne(G,A){k(A),G.dataTransfer.effectAllowed="move",G.dataTransfer.setData("text/plain",A.id)}function ue(G){G.preventDefault(),G.dataTransfer.dropEffect="move"}function me(G){if(!E||E.status===G){k(null),K(null);return}m?m(E.id,G):G==="in_progress"&&E.status==="pending"?l(E.id):G==="completed"&&E.status==="in_progress"&&r(E.id),k(null),K(null)}function z(G){p(A=>({...A,[G]:!A[G]}))}function Y(G,A){y(R=>({...R,[G]:A}))}function Q(G){S(A=>({...A,[G]:(A[G]||W)+20}))}if(O){const A=[...new Set(Z.map(R=>R.project_id||"__none__"))].map(R=>({id:R,name:R==="__none__"?"No Project":a.get(R)||R.slice(0,8),tasks:Z.filter(V=>(V.project_id||"__none__")===R)}));return A.sort((R,V)=>V.tasks.length-R.tasks.length),c.jsxs("div",{className:"space-y-6",children:[c.jsx(Dy,{compact:N,onCompactChange:C,showCancelled:M,onShowCancelledChange:T,priorityFilter:D,onPriorityFilterChange:_,groupByProject:O,onGroupByProjectChange:H}),A.map(R=>c.jsxs("div",{children:[c.jsxs("h3",{className:"text-sm font-semibold mb-3 flex items-center gap-2",children:[c.jsx("span",{className:"size-3 rounded bg-muted"}),R.name,c.jsx(Ht,{variant:"secondary",className:"text-sm",children:R.tasks.length})]}),c.jsx("div",{className:`grid gap-4 ${re.length<=4?"grid-cols-4":"grid-cols-5"}`,children:re.map(V=>{const te=`${R.id}_${V.key}`;return c.jsx(Ry,{status:V.key,label:V.label,tasks:R.tasks.filter(ae=>ae.status===V.key),collapsed:!!h[te],onToggleCollapse:()=>p(ae=>({...ae,[te]:!ae[te]})),sortField:v[te]||"priority",onSortChange:ae=>Y(te,ae),showLimit:w[te]||W,onShowMore:()=>Q(te),compact:N,projectMap:a,onStart:l,onComplete:r,onDelete:s,onEdit:u,onSelect:f,onDragStart:ne,onDrop:me,onDragOver:ue},te)})})]},R.id))]})}return c.jsxs("div",{className:"space-y-4",children:[c.jsx(Dy,{compact:N,onCompactChange:C,showCancelled:M,onShowCancelledChange:T,priorityFilter:D,onPriorityFilterChange:_,groupByProject:O,onGroupByProjectChange:H}),c.jsx("div",{className:`grid gap-4 ${re.length<=4?"grid-cols-4":"grid-cols-5"}`,children:re.map(G=>c.jsx(Ry,{status:G.key,label:G.label,tasks:Z.filter(A=>A.status===G.key),collapsed:!!h[G.key],onToggleCollapse:()=>z(G.key),sortField:v[G.key]||"priority",onSortChange:A=>Y(G.key,A),showLimit:w[G.key]||W,onShowMore:()=>Q(G.key),compact:N,projectMap:a,onStart:l,onComplete:r,onDelete:s,onEdit:u,onSelect:f,onDragStart:ne,onDrop:me,onDragOver:ue},G.key))})]})}function Dy({compact:e,onCompactChange:a,showCancelled:l,onShowCancelledChange:r,priorityFilter:s,onPriorityFilterChange:u,groupByProject:f,onGroupByProjectChange:m}){return c.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[c.jsxs(gn,{value:s,onValueChange:u,children:[c.jsx(Zt,{className:"w-[130px] h-8",children:c.jsx(hn,{placeholder:"Priority"})}),c.jsxs(Jt,{children:[c.jsx(Te,{value:"all",children:"All Priorities"}),c.jsx(Te,{value:"critical",children:"Critical"}),c.jsx(Te,{value:"high",children:"High"}),c.jsx(Te,{value:"medium",children:"Medium"}),c.jsx(Te,{value:"low",children:"Low"})]})]}),c.jsx(se,{variant:f?"secondary":"outline",size:"sm",className:"h-8 text-sm",onClick:()=>m(!f),children:"Group by Project"}),c.jsx(se,{variant:l?"secondary":"outline",size:"sm",className:"h-8 text-sm",onClick:()=>r(!l),children:"Cancelled"}),c.jsx(se,{variant:e?"secondary":"outline",size:"sm",className:"h-8 text-sm ml-auto",onClick:()=>a(!e),children:e?"Detailed":"Compact"})]})}function HT(e){let a=e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">");return a=a.replace(/```(\w*)\n([\s\S]*?)```/g,(l,r,s)=>`<pre class="my-2 rounded bg-muted p-3 text-xs font-mono overflow-x-auto"><code>${s.trim()}</code></pre>`),a=a.replace(/`([^`]+)`/g,'<code class="rounded bg-muted px-1 py-0.5 text-xs font-mono">$1</code>'),a=a.replace(/\*\*([^*]+)\*\*/g,"<strong>$1</strong>"),a=a.replace(new RegExp("(?<!\\*)\\*([^*]+)\\*(?!\\*)","g"),"<em>$1</em>"),a=a.replace(/^### (.+)$/gm,'<h3 class="text-sm font-semibold mt-3 mb-1">$1</h3>'),a=a.replace(/^## (.+)$/gm,'<h2 class="text-base font-semibold mt-4 mb-1">$1</h2>'),a=a.replace(/^- (.+)$/gm,'<li class="ml-4 list-disc">$1</li>'),a=a.replace(/((?:<li[^>]*>.*<\/li>\n?)+)/g,'<ul class="my-1 space-y-0.5 text-sm">$1</ul>'),a=a.replace(/^\d+\. (.+)$/gm,'<li class="ml-4 list-decimal">$1</li>'),a=a.replace(/\n\n/g,'</p><p class="my-1.5">'),a=a.replace(new RegExp("(?<!<\\/pre>|<\\/li>|<\\/ul>|<\\/h[23]>)\\n(?!<)","g"),"<br>"),`<p class="my-1.5">${a}</p>`}function LT({content:e}){return c.jsx("div",{className:"prose prose-sm dark:prose-invert max-w-none text-sm text-foreground leading-relaxed",dangerouslySetInnerHTML:{__html:HT(e)}})}function fw({status:e}){const l={pending:{label:"Pending",variant:"outline"},in_progress:{label:"In Progress",variant:"default"},completed:{label:"Completed",variant:"secondary"},failed:{label:"Failed",variant:"destructive"},cancelled:{label:"Cancelled",variant:"outline"}}[e]||{label:e,variant:"outline"};return c.jsx(Ht,{variant:l.variant,children:l.label})}function mw({priority:e}){const a={critical:"bg-red-100 text-red-800 dark:bg-red-900 dark:text-red-200",high:"bg-orange-100 text-orange-800 dark:bg-orange-900 dark:text-orange-200",medium:"bg-blue-100 text-blue-800 dark:bg-blue-900 dark:text-blue-200",low:"bg-gray-100 text-gray-700 dark:bg-gray-800 dark:text-gray-300"};return c.jsx("span",{className:`inline-flex items-center rounded-full px-2 py-0.5 text-xs font-medium ${a[e]||""}`,children:e})}function Dc(e){const a=Math.floor((Date.now()-new Date(e).getTime())/1e3);if(a<60)return`${a}s ago`;const l=Math.floor(a/60);if(l<60)return`${l}m ago`;const r=Math.floor(l/60);return r<24?`${r}h ago`:`${Math.floor(r/24)}d ago`}function FT(e){return e<6e4?`${Math.round(e/1e3)}s`:e<36e5?`${Math.round(e/6e4)}m`:`${(e/36e5).toFixed(1)}h`}function gw(e){return e?new Date(e).getTime()<Date.now():!1}function BT({task:e,projectName:a,onBack:l,onStart:r,onComplete:s,onDelete:u,onEdit:f}){const m=new Date(e.created_at).getTime(),p=((e.completed_at?new Date(e.completed_at).getTime():null)||Date.now())-m;return c.jsx("div",{className:"space-y-4",children:c.jsxs(St,{children:[c.jsx(Vt,{className:"pb-3",children:c.jsxs("div",{className:"flex items-start justify-between gap-4",children:[c.jsxs("div",{className:"space-y-1.5 min-w-0 flex-1",children:[c.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[c.jsx("code",{className:"text-xs text-muted-foreground bg-muted px-1.5 py-0.5 rounded",children:e.short_id||e.id.slice(0,8)}),c.jsx(fw,{status:e.status}),c.jsx(mw,{priority:e.priority}),e.due_at&&c.jsxs("span",{className:`inline-flex items-center gap-1 text-xs ${gw(e.due_at)&&e.status!=="completed"?"text-red-500 font-medium":"text-muted-foreground"}`,children:[c.jsx(Jy,{className:"size-3"}),"Due ",new Date(e.due_at).toLocaleDateString()]})]}),c.jsx(Ut,{className:"text-lg leading-tight",children:e.title})]}),c.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[c.jsxs(se,{variant:"outline",size:"sm",onClick:()=>f(e),children:[c.jsx(oo,{className:"size-3.5"})," Edit"]}),e.status==="pending"&&c.jsxs(se,{variant:"outline",size:"sm",onClick:()=>r(e.id),children:[c.jsx(eo,{className:"size-3.5"})," Start"]}),e.status==="in_progress"&&c.jsxs(se,{variant:"outline",size:"sm",onClick:()=>s(e.id),children:[c.jsx(Jr,{className:"size-3.5"})," Complete"]}),c.jsxs(se,{variant:"outline",size:"sm",className:"text-red-500 hover:text-red-600",onClick:()=>{u(e.id),l()},children:[c.jsx(Fm,{className:"size-3.5"})," Delete"]})]})]})}),c.jsxs(wt,{className:"space-y-4",children:[e.description&&c.jsx("div",{className:"rounded-lg border bg-muted/30 p-4",children:c.jsx(LT,{content:e.description})}),c.jsx("div",{className:"flex flex-wrap gap-3",children:c.jsxs("div",{className:"flex items-center gap-1.5 rounded-lg border px-3 py-1.5 text-xs",children:[c.jsx(a0,{className:"size-3 text-muted-foreground"}),c.jsx("span",{className:"text-muted-foreground",children:"Total:"}),c.jsx("span",{className:"font-medium",children:FT(p)})]})}),c.jsxs("div",{className:"grid grid-cols-2 gap-x-8 gap-y-2 text-sm sm:grid-cols-3",children:[c.jsxs("div",{children:[c.jsx("span",{className:"text-muted-foreground",children:"Project:"})," ",c.jsx("span",{className:"font-medium",children:a||"None"})]}),e.task_list_id&&c.jsxs("div",{children:[c.jsx("span",{className:"text-muted-foreground",children:"Task List:"})," ",c.jsx("span",{className:"font-medium",children:e.task_list_id})]}),e.assigned_to&&c.jsxs("div",{children:[c.jsx("span",{className:"text-muted-foreground",children:"Assigned to:"})," ",c.jsx("span",{className:"font-medium",children:e.assigned_to})]}),e.agent_id&&c.jsxs("div",{children:[c.jsx("span",{className:"text-muted-foreground",children:"Agent:"})," ",c.jsx("span",{className:"font-medium",children:e.agent_id})]}),e.locked_by&&c.jsxs("div",{children:[c.jsx("span",{className:"text-muted-foreground",children:"Locked by:"})," ",c.jsx("span",{className:"font-medium",children:e.locked_by})]}),c.jsxs("div",{children:[c.jsx("span",{className:"text-muted-foreground",children:"Created:"})," ",c.jsx("span",{children:Dc(e.created_at)})]}),c.jsxs("div",{children:[c.jsx("span",{className:"text-muted-foreground",children:"Updated:"})," ",c.jsx("span",{children:Dc(e.updated_at)})]}),e.completed_at&&c.jsxs("div",{children:[c.jsx("span",{className:"text-muted-foreground",children:"Completed:"})," ",c.jsx("span",{children:Dc(e.completed_at)})]}),c.jsxs("div",{children:[c.jsx("span",{className:"text-muted-foreground",children:"Version:"})," ",c.jsx("span",{children:e.version})]})]}),e.tags.length>0&&c.jsx("div",{className:"flex flex-wrap gap-1.5",children:e.tags.map(v=>c.jsx(Ht,{variant:"outline",className:"text-xs",children:v},v))})]})]})})}const VT=[{id:"select",header:({table:e})=>c.jsx("input",{type:"checkbox",className:"rounded",checked:e.getIsAllPageRowsSelected(),onChange:a=>e.toggleAllPageRowsSelected(a.target.checked)}),cell:({row:e})=>c.jsx("input",{type:"checkbox",className:"rounded",checked:e.getIsSelected(),onChange:a=>{a.stopPropagation(),e.toggleSelected(a.target.checked)},onClick:a=>a.stopPropagation()}),size:30,enableSorting:!1},{accessorKey:"short_id",header:"ID",cell:({row:e})=>c.jsx("code",{className:"text-xs text-muted-foreground",children:e.original.short_id||e.original.id.slice(0,8)}),size:100},{accessorKey:"title",header:({column:e})=>c.jsxs(se,{variant:"ghost",size:"sm",className:"-ml-3",onClick:()=>e.toggleSorting(),children:["Title ",c.jsx(dn,{className:"size-3"})]}),cell:({row:e})=>c.jsxs("div",{className:"max-w-[400px]",children:[c.jsx("div",{className:"font-medium truncate",children:e.original.title}),e.original.due_at&&gw(e.original.due_at)&&e.original.status!=="completed"&&c.jsx("span",{className:"text-[10px] text-red-500 font-medium",children:"Overdue"})]})},{accessorKey:"status",header:"Status",cell:({row:e})=>c.jsx(fw,{status:e.original.status}),filterFn:(e,a,l)=>!l||l==="all"?!0:e.original.status===l},{accessorKey:"priority",header:({column:e})=>c.jsxs(se,{variant:"ghost",size:"sm",className:"-ml-3",onClick:()=>e.toggleSorting(),children:["Priority ",c.jsx(dn,{className:"size-3"})]}),cell:({row:e})=>c.jsx(mw,{priority:e.original.priority}),sortingFn:(e,a)=>{const l={critical:0,high:1,medium:2,low:3};return(l[e.original.priority]??4)-(l[a.original.priority]??4)}},{accessorKey:"assigned_to",header:"Assigned",cell:({row:e})=>c.jsx("span",{className:"text-xs text-muted-foreground",children:e.original.assigned_to||e.original.agent_id||"—"})},{accessorKey:"updated_at",header:({column:e})=>c.jsxs(se,{variant:"ghost",size:"sm",className:"-ml-3",onClick:()=>e.toggleSorting(),children:["Updated ",c.jsx(dn,{className:"size-3"})]}),cell:({row:e})=>c.jsx("span",{className:"text-xs text-muted-foreground whitespace-nowrap",children:Dc(e.original.updated_at)})},{id:"actions",header:"",cell:({row:e,table:a})=>{const l=a.options.meta,r=e.original;return c.jsx("div",{onClick:s=>s.stopPropagation(),children:c.jsxs(jl,{children:[c.jsx(Ml,{asChild:!0,children:c.jsx(se,{variant:"ghost",size:"icon",className:"size-7",children:c.jsx(_s,{className:"size-4"})})}),c.jsxs(Fa,{align:"end",children:[c.jsxs(dt,{onClick:()=>l==null?void 0:l.onEdit(r),children:[c.jsx(oo,{className:"size-3.5 mr-2"})," Edit"]}),r.status==="pending"&&c.jsxs(dt,{onClick:()=>l==null?void 0:l.onStart(r.id),children:[c.jsx(eo,{className:"size-3.5 mr-2"})," Start"]}),r.status==="in_progress"&&c.jsxs(dt,{onClick:()=>l==null?void 0:l.onComplete(r.id),children:[c.jsx(Jr,{className:"size-3.5 mr-2"})," Complete"]}),c.jsx(mo,{}),c.jsxs(dt,{className:"text-red-500 focus:text-red-500",onClick:()=>l==null?void 0:l.onConfirmDelete(r.id),children:[c.jsx(la,{className:"size-3.5 mr-2"})," Delete"]})]})]})})},size:50}];function UT({data:e,projectMap:a,projects:l,onStart:r,onComplete:s,onDelete:u,onEdit:f,onBulkAction:m,onNewTask:h}){var G;const[p,v]=x.useState([]),[y,w]=x.useState([]),[S,N]=x.useState(""),[C,M]=x.useState("table"),[T,D]=x.useState(null),[_,O]=x.useState(null),[H,E]=x.useState({}),[k,F]=x.useState("all"),K=x.useRef(null);x.useEffect(()=>{function A(R){var V,te,ae;if(R.key==="/"&&!R.ctrlKey&&!R.metaKey){const oe=(V=R.target)==null?void 0:V.tagName;oe!=="INPUT"&&oe!=="TEXTAREA"&&(R.preventDefault(),(te=K.current)==null||te.focus())}R.key==="Escape"&&(T?D(null):(N(""),(ae=K.current)==null||ae.blur()))}return document.addEventListener("keydown",A),()=>document.removeEventListener("keydown",A)},[T]),x.useEffect(()=>{if(T){const A=e.find(R=>R.id===T.id);D(A||null)}},[e,T==null?void 0:T.id]);const W=x.useMemo(()=>k==="all"?e:k==="none"?e.filter(A=>!A.project_id):e.filter(A=>A.project_id===k),[e,k]),Z=x.useMemo(()=>{const A={all:W.length};for(const R of W)A[R.status]=(A[R.status]||0)+1;return A},[W]),re=x.useMemo(()=>{const A=[...VT];return A.splice(4,0,{accessorKey:"project_id",header:"Project",cell:({row:R})=>{const V=R.original.project_id;return V?c.jsx("span",{className:"text-xs text-muted-foreground truncate max-w-[120px] block",children:a.get(V)||V.slice(0,8)}):c.jsx("span",{className:"text-xs text-muted-foreground",children:"—"})}}),A},[a]),ne=fu({data:W,columns:re,state:{sorting:p,columnFilters:y,globalFilter:S,rowSelection:H},onSortingChange:v,onColumnFiltersChange:w,onGlobalFilterChange:N,onRowSelectionChange:E,getCoreRowModel:iu(),getSortedRowModel:du(),getFilteredRowModel:cu(),getPaginationRowModel:uu(),enableRowSelection:!0,getRowId:A=>A.id,initialState:{pagination:{pageSize:15}},meta:{onStart:r,onComplete:s,onDelete:u,onConfirmDelete:Y,onEdit:f}}),ue=((G=ne.getColumn("status"))==null?void 0:G.getFilterValue())||"all",me=Object.keys(H).filter(A=>H[A]),z=me.length>0;function Y(A){O(A)}function Q(){_&&(u(_),O(null),(T==null?void 0:T.id)===_&&D(null))}return c.jsxs(c.Fragment,{children:[c.jsxs("div",{className:"space-y-4",children:[c.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[h&&c.jsxs(se,{size:"sm",className:"h-9",onClick:h,title:"Press n",children:[c.jsx(hl,{className:"size-4"})," New Task"]}),c.jsxs("div",{className:"relative flex-1 min-w-[180px] max-w-xs",children:[c.jsx(Ic,{className:"absolute left-2.5 top-2.5 size-4 text-muted-foreground"}),c.jsx(It,{ref:K,placeholder:"Search... (/)",value:S,onChange:A=>N(A.target.value),className:"pl-8 h-9"})]}),c.jsxs(gn,{value:k,onValueChange:F,children:[c.jsx(Zt,{className:"w-[140px] h-9",children:c.jsx(hn,{placeholder:"All Projects"})}),c.jsxs(Jt,{children:[c.jsx(Te,{value:"all",children:"All Projects"}),c.jsx(Te,{value:"none",children:"No Project"}),l.map(A=>c.jsx(Te,{value:A.id,children:A.name},A.id))]})]}),c.jsxs(gn,{value:ue,onValueChange:A=>{var R;return(R=ne.getColumn("status"))==null?void 0:R.setFilterValue(A==="all"?void 0:A)},children:[c.jsx(Zt,{className:"w-[140px] h-9",children:c.jsx(hn,{placeholder:"All Statuses"})}),c.jsx(Jt,{children:["all","pending","in_progress","completed","failed","cancelled"].map(A=>{const R=Z[A]||0,V=A==="all"?"All":A==="in_progress"?"In Progress":A.charAt(0).toUpperCase()+A.slice(1);return c.jsxs(Te,{value:A,children:[V," (",R,")"]},A)})})]}),c.jsxs(jl,{children:[c.jsx(Ml,{asChild:!0,children:c.jsx(se,{variant:"outline",size:"icon",className:"size-9 shrink-0",title:"Export",children:c.jsx(PN,{className:"size-4"})})}),c.jsxs(Fa,{align:"end",children:[c.jsx(dt,{onClick:()=>window.open("/api/tasks/export?format=csv","_blank"),children:"Export CSV"}),c.jsx(dt,{onClick:()=>window.open("/api/tasks/export?format=json","_blank"),children:"Export JSON"})]})]}),c.jsxs("div",{className:"flex items-center border rounded-md",children:[c.jsx(se,{variant:C==="table"?"secondary":"ghost",size:"icon",className:"size-8 rounded-r-none",onClick:()=>M("table"),title:"Table view",children:c.jsx(BN,{className:"size-4"})}),c.jsx(se,{variant:C==="kanban"?"secondary":"ghost",size:"icon",className:"size-8 rounded-l-none",onClick:()=>M("kanban"),title:"Kanban view",children:c.jsx(FN,{className:"size-4"})})]})]}),C==="kanban"&&c.jsx(PT,{data:ne.getFilteredRowModel().rows.map(A=>A.original),projectMap:a,onStart:r,onComplete:s,onDelete:Y,onEdit:f,onSelect:D,onStatusChange:async(A,R)=>{try{const V=e.find(te=>te.id===A);if(!V)return;R==="in_progress"&&V.status==="pending"?r(A):R==="completed"&&V.status==="in_progress"?s(A):(await fetch(`/api/tasks/${A}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({status:R})}),r("__reload__"))}catch{}}}),C==="table"&&c.jsx("div",{className:"rounded-md border",children:c.jsxs(Fs,{children:[c.jsx(Bs,{children:ne.getHeaderGroups().map(A=>c.jsx(mn,{children:A.headers.map(R=>c.jsx(Us,{children:R.isPlaceholder?null:bl(R.column.columnDef.header,R.getContext())},R.id))},A.id))}),c.jsx(Vs,{children:ne.getRowModel().rows.length?ne.getRowModel().rows.map(A=>c.jsx(mn,{className:"cursor-pointer","data-state":A.getIsSelected()?"selected":void 0,onClick:()=>D(A.original),children:A.getVisibleCells().map(R=>c.jsx(Pa,{children:bl(R.column.columnDef.cell,R.getContext())},R.id))},A.id)):c.jsx(mn,{children:c.jsx(Pa,{colSpan:re.length,className:"h-24 text-center text-muted-foreground",children:"No tasks found."})})})]})}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("p",{className:"text-sm text-muted-foreground",children:[ne.getFilteredRowModel().rows.length," task(s)"]}),c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx(se,{variant:"outline",size:"sm",onClick:()=>ne.previousPage(),disabled:!ne.getCanPreviousPage(),children:c.jsx(Ms,{className:"size-4"})}),c.jsxs("span",{className:"text-sm text-muted-foreground",children:["Page ",ne.getState().pagination.pageIndex+1," of ",ne.getPageCount()]}),c.jsx(se,{variant:"outline",size:"sm",onClick:()=>ne.nextPage(),disabled:!ne.getCanNextPage(),children:c.jsx(ro,{className:"size-4"})})]})]}),z&&c.jsxs("div",{className:"fixed bottom-6 left-1/2 -translate-x-1/2 z-50 flex items-center gap-3 rounded-xl border bg-background px-5 py-3 shadow-xl",children:[c.jsxs("span",{className:"text-sm font-medium",children:[me.length," selected"]}),c.jsx("div",{className:"h-4 w-px bg-border"}),c.jsxs(se,{variant:"outline",size:"sm",onClick:()=>{m(me,"start"),E({})},children:[c.jsx(eo,{className:"size-4"})," Start"]}),c.jsxs(se,{variant:"outline",size:"sm",onClick:()=>{m(me,"complete"),E({})},children:[c.jsx(Jr,{className:"size-4"})," Complete"]}),c.jsxs(se,{variant:"outline",size:"sm",className:"text-red-500",onClick:()=>{m(me,"delete"),E({})},children:[c.jsx(la,{className:"size-4"})," Delete"]}),c.jsx("div",{className:"h-4 w-px bg-border"}),c.jsx(se,{variant:"ghost",size:"sm",onClick:()=>E({}),children:"Clear"})]})]}),c.jsx(ra,{open:!!T,onOpenChange:A=>{A||D(null)},children:c.jsx(In,{className:"max-w-2xl max-h-[85vh] overflow-y-auto",children:T&&c.jsx(BT,{task:T,projectName:T.project_id&&a.get(T.project_id)||null,onBack:()=>D(null),onStart:r,onComplete:s,onDelete:A=>{D(null),Y(A)},onEdit:f})})}),c.jsx(ra,{open:!!_,onOpenChange:A=>{A||O(null)},children:c.jsxs(In,{className:"max-w-sm",children:[c.jsx(Ba,{children:c.jsx(sa,{children:"Delete Task"})}),c.jsx("p",{className:"text-sm text-muted-foreground",children:"Are you sure you want to delete this task? This action cannot be undone."}),c.jsxs("div",{className:"flex justify-end gap-2 pt-2",children:[c.jsx(se,{variant:"outline",onClick:()=>O(null),children:"Cancel"}),c.jsxs(se,{variant:"destructive",onClick:Q,children:[c.jsx(la,{className:"size-4"})," Delete"]})]})]})})]})}function hw(e){const a=Math.floor((Date.now()-new Date(e).getTime())/1e3);if(a<60)return`${a}s ago`;const l=Math.floor(a/60);if(l<60)return`${l}m ago`;const r=Math.floor(l/60);return r<24?`${r}h ago`:`${Math.floor(r/24)}d ago`}function Ty(e){return{pending:"text-yellow-500",in_progress:"text-blue-500",completed:"text-green-500",failed:"text-red-500",cancelled:"text-muted-foreground"}[e]||"text-foreground"}function Oy({open:e,onOpenChange:a,onCreated:l}){const[r,s]=x.useState(""),[u,f]=x.useState(""),[m,h]=x.useState(""),[p,v]=x.useState(!1),[y,w]=x.useState(null);async function S(N){if(N.preventDefault(),!(!r.trim()||!u.trim())){v(!0),w(null);try{const M=await(await fetch("/api/projects",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:r.trim(),path:u.trim(),description:m.trim()||void 0})})).json();M.error?w(M.error):(s(""),f(""),h(""),a(!1),l())}catch{w("Failed to create project")}finally{v(!1)}}}return c.jsx(ra,{open:e,onOpenChange:a,children:c.jsxs(In,{children:[c.jsx(Ba,{children:c.jsx(sa,{children:"New Project"})}),c.jsxs("form",{onSubmit:S,className:"space-y-4",children:[c.jsxs("div",{className:"space-y-1.5",children:[c.jsx("label",{className:"text-sm font-medium",children:"Name"}),c.jsx(It,{value:r,onChange:N=>s(N.target.value),placeholder:"Project name",className:"h-9",autoFocus:!0})]}),c.jsxs("div",{className:"space-y-1.5",children:[c.jsx("label",{className:"text-sm font-medium",children:"Path"}),c.jsx(It,{value:u,onChange:N=>f(N.target.value),placeholder:"/path/to/project",className:"h-9"})]}),c.jsxs("div",{className:"space-y-1.5",children:[c.jsx("label",{className:"text-sm font-medium",children:"Description"}),c.jsx(It,{value:m,onChange:N=>h(N.target.value),placeholder:"Optional description",className:"h-9"})]}),y&&c.jsx("p",{className:"text-sm text-red-500",children:y}),c.jsxs(Is,{children:[c.jsx(se,{type:"button",variant:"outline",onClick:()=>a(!1),children:"Cancel"}),c.jsx(se,{type:"submit",disabled:!r.trim()||!u.trim()||p,children:p?"Creating...":"Create"})]})]})]})})}function IT({project:e,onBack:a}){const[l,r]=x.useState([]),[s,u]=x.useState(!0);x.useEffect(()=>{fetch(`/api/tasks?project_id=${e.id}`).then(m=>m.json()).then(r).finally(()=>u(!1))},[e.id]);const f={};for(const m of l)f[m.status]=(f[m.status]||0)+1;return c.jsxs("div",{className:"space-y-4",children:[c.jsxs(se,{variant:"ghost",size:"sm",onClick:a,className:"gap-1.5 -ml-2",children:[c.jsx(TN,{className:"size-3.5"})," Back to projects"]}),c.jsxs(St,{className:"shadow-none",children:[c.jsxs(Vt,{children:[c.jsxs("div",{className:"flex items-start justify-between",children:[c.jsxs("div",{children:[c.jsxs(Ut,{className:"text-lg flex items-center gap-2",children:[c.jsx(Uc,{className:"size-5 text-purple-500"}),e.name]}),c.jsx("code",{className:"text-sm text-muted-foreground mt-1 block",children:e.path})]}),e.task_prefix&&c.jsx(Ht,{variant:"outline",children:e.task_prefix})]}),e.description&&c.jsx("p",{className:"text-sm text-muted-foreground mt-2",children:e.description})]}),c.jsxs(wt,{className:"space-y-4",children:[c.jsx("div",{className:"grid grid-cols-5 gap-2 text-center",children:["pending","in_progress","completed","failed","cancelled"].map(m=>c.jsxs("div",{className:"rounded-lg border p-2",children:[c.jsx("div",{className:`text-xl font-bold ${Ty(m)}`,children:f[m]||0}),c.jsx("div",{className:"text-sm text-muted-foreground capitalize",children:m==="in_progress"?"Active":m})]},m))}),c.jsxs("div",{children:[c.jsxs("h3",{className:"text-sm font-medium mb-2",children:["Tasks (",l.length,")"]}),s?c.jsx("p",{className:"text-sm text-muted-foreground",children:"Loading..."}):l.length===0?c.jsx("p",{className:"text-sm text-muted-foreground",children:"No tasks in this project."}):c.jsx("div",{className:"space-y-1 max-h-[400px] overflow-y-auto",children:l.map(m=>c.jsxs("div",{className:"flex items-center gap-2 rounded-md px-2 py-1.5 text-sm hover:bg-muted/50",children:[c.jsx("span",{className:`size-2 rounded-full shrink-0 ${Ty(m.status).replace("text-","bg-")}`}),c.jsx("code",{className:"text-sm text-muted-foreground shrink-0",children:m.short_id||m.id.slice(0,8)}),c.jsx("span",{className:"truncate flex-1",children:m.title}),c.jsx("span",{className:"text-sm text-muted-foreground shrink-0",children:m.assigned_to||"—"}),c.jsx("span",{className:"text-sm text-muted-foreground shrink-0",children:hw(m.updated_at)})]},m.id))})]})]})]})]})}function GT(){return[{id:"select",header:({table:e})=>c.jsx("input",{type:"checkbox",className:"rounded",checked:e.getIsAllPageRowsSelected(),onChange:a=>e.toggleAllPageRowsSelected(a.target.checked)}),cell:({row:e})=>c.jsx("input",{type:"checkbox",className:"rounded",checked:e.getIsSelected(),onChange:a=>{a.stopPropagation(),e.toggleSelected(a.target.checked)},onClick:a=>a.stopPropagation()}),size:30,enableSorting:!1},{accessorKey:"name",header:({column:e})=>c.jsxs(se,{variant:"ghost",size:"sm",className:"-ml-3",onClick:()=>e.toggleSorting(),children:["Name ",c.jsx(dn,{className:"size-3"})]}),cell:({row:e})=>c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx(Uc,{className:"size-4 text-purple-500 shrink-0"}),c.jsx("span",{className:"font-medium text-sm",children:e.original.name})]})},{accessorKey:"path",header:"Path",cell:({row:e})=>c.jsx("code",{className:"text-sm text-muted-foreground truncate max-w-[300px] block",children:e.original.path})},{accessorKey:"task_prefix",header:"Prefix",cell:({row:e})=>e.original.task_prefix?c.jsx(Ht,{variant:"outline",className:"text-sm",children:e.original.task_prefix}):c.jsx("span",{className:"text-sm text-muted-foreground",children:"—"})},{accessorKey:"task_counter",header:({column:e})=>c.jsxs(se,{variant:"ghost",size:"sm",className:"-ml-3",onClick:()=>e.toggleSorting(),children:["Tasks ",c.jsx(dn,{className:"size-3"})]}),cell:({row:e})=>c.jsx("span",{className:"text-sm",children:e.original.task_counter})},{accessorKey:"task_list_id",header:"Task List",cell:({row:e})=>c.jsx("span",{className:"text-sm text-muted-foreground truncate max-w-[150px] block",children:e.original.task_list_id||"—"})},{accessorKey:"created_at",header:({column:e})=>c.jsxs(se,{variant:"ghost",size:"sm",className:"-ml-3",onClick:()=>e.toggleSorting(),children:["Created ",c.jsx(dn,{className:"size-3"})]}),cell:({row:e})=>c.jsx("span",{className:"text-sm text-muted-foreground whitespace-nowrap",children:hw(e.original.created_at)})},{id:"actions",header:"",cell:({row:e,table:a})=>{const l=a.options.meta;return c.jsx("div",{onClick:r=>r.stopPropagation(),children:c.jsxs(jl,{children:[c.jsx(Ml,{asChild:!0,children:c.jsx(se,{variant:"ghost",size:"icon",className:"size-7",children:c.jsx(_s,{className:"size-4"})})}),c.jsxs(Fa,{align:"end",children:[c.jsx(mo,{className:"hidden"}),c.jsxs(dt,{className:"text-red-500 focus:text-red-500",onClick:()=>l==null?void 0:l.onDelete(e.original.id),children:[c.jsx(la,{className:"size-3.5 mr-2"})," Delete"]})]})]})})},size:50}]}function YT(){const[e,a]=x.useState([]),[l,r]=x.useState(!0),[s,u]=x.useState(null),[f,m]=x.useState([]),[h,p]=x.useState(""),[v,y]=x.useState({}),[w,S]=x.useState(!1),N=x.useRef(null),C=x.useMemo(()=>GT(),[]);function M(){fetch("/api/projects").then(E=>E.json()).then(a).finally(()=>r(!1))}x.useEffect(()=>{M()},[]),x.useEffect(()=>{function E(k){var F,K,W;if(k.key==="/"&&!k.ctrlKey&&!k.metaKey){const Z=(F=k.target)==null?void 0:F.tagName;Z!=="INPUT"&&Z!=="TEXTAREA"&&(k.preventDefault(),(K=N.current)==null||K.focus())}k.key==="Escape"&&(s?u(null):(p(""),(W=N.current)==null||W.blur()))}return document.addEventListener("keydown",E),()=>document.removeEventListener("keydown",E)},[s]);async function T(E){await fetch(`/api/projects/${E}`,{method:"DELETE"}),a(k=>k.filter(F=>F.id!==E))}async function D(E){await Promise.all(E.map(k=>fetch(`/api/projects/${k}`,{method:"DELETE"}))),a(k=>k.filter(F=>!E.includes(F.id))),y({})}const _=fu({data:e,columns:C,state:{sorting:f,globalFilter:h,rowSelection:v},onSortingChange:m,onGlobalFilterChange:p,onRowSelectionChange:y,getCoreRowModel:iu(),getSortedRowModel:du(),getFilteredRowModel:cu(),getPaginationRowModel:uu(),enableRowSelection:!0,getRowId:E=>E.id,initialState:{pagination:{pageSize:15}},meta:{onDelete:T}}),O=Object.keys(v).filter(E=>v[E]),H=O.length>0;return l?c.jsx("div",{className:"text-center text-muted-foreground py-12",children:"Loading projects..."}):s?c.jsx(IT,{project:s,onBack:()=>u(null)}):e.length===0&&!w?c.jsxs("div",{className:"text-center py-12",children:[c.jsx(Uc,{className:"mx-auto size-10 text-muted-foreground/50 mb-3"}),c.jsx("p",{className:"text-muted-foreground",children:"No projects registered."}),c.jsxs("p",{className:"text-sm text-muted-foreground mt-1",children:["Projects are auto-created when you run ",c.jsx("code",{className:"bg-muted px-1.5 py-0.5 rounded text-sm",children:"todos add"})," from a git repo."]}),c.jsxs(se,{variant:"outline",size:"sm",className:"mt-4 gap-1.5",onClick:()=>S(!0),children:[c.jsx(hl,{className:"size-3.5"})," New Project"]}),c.jsx(Oy,{open:w,onOpenChange:S,onCreated:M})]}):c.jsxs("div",{className:"space-y-4",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsxs("div",{className:"relative flex-1 min-w-[200px] max-w-sm",children:[c.jsx(Ic,{className:"absolute left-2.5 top-2.5 size-3.5 text-muted-foreground"}),c.jsx(It,{ref:N,placeholder:"Search projects... (press /)",value:h,onChange:E=>p(E.target.value),className:"pl-8 h-9"})]}),c.jsxs("span",{className:"text-sm text-muted-foreground",children:[e.length," project(s)"]}),c.jsx("div",{className:"flex-1"}),c.jsxs(se,{variant:"outline",size:"sm",className:"gap-1.5 h-9",onClick:()=>S(!0),children:[c.jsx(hl,{className:"size-3.5"})," New Project"]})]}),c.jsx("div",{className:"rounded-md border",children:c.jsxs(Fs,{children:[c.jsx(Bs,{children:_.getHeaderGroups().map(E=>c.jsx(mn,{children:E.headers.map(k=>c.jsx(Us,{children:k.isPlaceholder?null:bl(k.column.columnDef.header,k.getContext())},k.id))},E.id))}),c.jsx(Vs,{children:_.getRowModel().rows.length?_.getRowModel().rows.map(E=>c.jsx(mn,{className:"cursor-pointer","data-state":E.getIsSelected()?"selected":void 0,onClick:()=>u(E.original),children:E.getVisibleCells().map(k=>c.jsx(Pa,{children:bl(k.column.columnDef.cell,k.getContext())},k.id))},E.id)):c.jsx(mn,{children:c.jsx(Pa,{colSpan:C.length,className:"h-24 text-center text-muted-foreground",children:"No projects found."})})})]})}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("p",{className:"text-sm text-muted-foreground",children:[_.getFilteredRowModel().rows.length," project(s)"]}),_.getPageCount()>1&&c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx(se,{variant:"outline",size:"sm",onClick:()=>_.previousPage(),disabled:!_.getCanPreviousPage(),children:c.jsx(Ms,{className:"size-3.5"})}),c.jsxs("span",{className:"text-sm text-muted-foreground",children:["Page ",_.getState().pagination.pageIndex+1," of ",_.getPageCount()]}),c.jsx(se,{variant:"outline",size:"sm",onClick:()=>_.nextPage(),disabled:!_.getCanNextPage(),children:c.jsx(ro,{className:"size-3.5"})})]})]}),H&&c.jsxs("div",{className:"fixed bottom-6 left-1/2 -translate-x-1/2 z-50 flex items-center gap-3 rounded-xl border bg-background px-5 py-3 shadow-xl",children:[c.jsxs("span",{className:"text-sm font-medium",children:[O.length," selected"]}),c.jsx("div",{className:"h-4 w-px bg-border"}),c.jsxs(se,{variant:"outline",size:"sm",className:"h-7 text-sm text-red-500",onClick:()=>D(O),children:[c.jsx(la,{className:"size-3"})," Delete"]}),c.jsx("div",{className:"h-4 w-px bg-border"}),c.jsx(se,{variant:"ghost",size:"sm",className:"h-7 text-sm",onClick:()=>y({}),children:"Clear"})]}),c.jsx(Oy,{open:w,onOpenChange:S,onCreated:M})]})}function pw(e){const a=Math.floor((Date.now()-new Date(e).getTime())/1e3);if(a<60)return`${a}s ago`;const l=Math.floor(a/60);if(l<60)return`${l}m ago`;const r=Math.floor(l/60);return r<24?`${r}h ago`:`${Math.floor(r/24)}d ago`}function vw(e){return e<6e4?`${Math.round(e/1e3)}s`:e<36e5?`${Math.round(e/6e4)}m`:`${(e/36e5).toFixed(1)}h`}function Sg(e){const a=Date.now()-new Date(e).getTime();return a<300*1e3?{color:"bg-green-500",label:"Online"}:a<3600*1e3?{color:"bg-yellow-500",label:"Away"}:{color:"bg-gray-400",label:"Offline"}}function wg({role:e}){const a=e||"agent",l={admin:"bg-purple-100 text-purple-800 dark:bg-purple-900 dark:text-purple-200",agent:"bg-blue-100 text-blue-800 dark:bg-blue-900 dark:text-blue-200",observer:"bg-gray-100 text-gray-700 dark:bg-gray-800 dark:text-gray-300"};return c.jsx("span",{className:`inline-flex items-center rounded-full px-2 py-0.5 text-xs font-medium ${l[a]||l.agent}`,children:a})}function xw(e,a){return e.filter(l=>l.assigned_to===a.name||l.assigned_to===a.id||l.agent_id===a.id||l.agent_id===a.name)}function $T(e){return e.length===0?null:e.reduce((a,l)=>{const r=new Date(a.updated_at||a.created_at).getTime();return new Date(l.updated_at||l.created_at).getTime()>r?l:a})}function Ay(e,a){const l=e.length,r=a.length,s=Array.from({length:l+1},()=>Array(r+1).fill(0));for(let u=0;u<=l;u++)s[u][0]=u;for(let u=0;u<=r;u++)s[0][u]=u;for(let u=1;u<=l;u++)for(let f=1;f<=r;f++)s[u][f]=Math.min(s[u-1][f]+1,s[u][f-1]+1,s[u-1][f-1]+(e[u-1]===a[f-1]?0:1));return s[l][r]}function ky({open:e,onOpenChange:a,onCreated:l}){const[r,s]=x.useState(""),[u,f]=x.useState(""),[m,h]=x.useState("agent"),[p,v]=x.useState(!1),[y,w]=x.useState(null);async function S(N){if(N.preventDefault(),!!r.trim()){v(!0),w(null);try{const M=await(await fetch("/api/agents",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:r.trim(),description:u.trim()||void 0,role:m})})).json();M.error?w(M.error):(s(""),f(""),h("agent"),a(!1),l())}catch{w("Failed to register agent")}finally{v(!1)}}}return c.jsx(ra,{open:e,onOpenChange:a,children:c.jsxs(In,{children:[c.jsx(Ba,{children:c.jsx(sa,{children:"New Agent"})}),c.jsxs("form",{onSubmit:S,className:"space-y-4",children:[c.jsxs("div",{className:"space-y-1.5",children:[c.jsx("label",{className:"text-sm font-medium",children:"Name"}),c.jsx(It,{value:r,onChange:N=>s(N.target.value),placeholder:"Agent name",className:"h-9",autoFocus:!0})]}),c.jsxs("div",{className:"space-y-1.5",children:[c.jsx("label",{className:"text-sm font-medium",children:"Description"}),c.jsx(It,{value:u,onChange:N=>f(N.target.value),placeholder:"Optional description",className:"h-9"})]}),c.jsxs("div",{className:"space-y-1.5",children:[c.jsx("label",{className:"text-sm font-medium",children:"Role"}),c.jsxs(gn,{value:m,onValueChange:h,children:[c.jsx(Zt,{className:"h-9",children:c.jsx(hn,{})}),c.jsxs(Jt,{children:[c.jsx(Te,{value:"agent",children:"Agent"}),c.jsx(Te,{value:"admin",children:"Admin"}),c.jsx(Te,{value:"observer",children:"Observer"})]})]})]}),y&&c.jsx("p",{className:"text-sm text-red-500",children:y}),c.jsxs(Is,{children:[c.jsx(se,{type:"button",variant:"outline",onClick:()=>a(!1),children:"Cancel"}),c.jsx(se,{type:"submit",disabled:!r.trim()||p,children:p?"Creating...":"Create"})]})]})]})})}function qT({agent:e,tasks:a,open:l,onOpenChange:r,onUpdated:s}){const[u,f]=x.useState(!1),[m,h]=x.useState(""),[p,v]=x.useState(""),[y,w]=x.useState("agent"),[S,N]=x.useState(!1),[C,M]=x.useState(null);if(x.useEffect(()=>{e&&(h(e.name),v(e.description||""),w(e.role||"agent"),f(!1),M(null))},[e]),!e)return null;const T=Sg(e.last_seen_at),_=xw(a,e).sort((E,k)=>new Date(k.updated_at||k.created_at).getTime()-new Date(E.updated_at||E.created_at).getTime()).slice(0,20);async function O(){N(!0),M(null);try{const k=await(await fetch(`/api/agents/${e.id}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:m.trim(),description:p.trim()||null,role:y})})).json();k.error?M(k.error):(f(!1),s())}catch{M("Failed to update agent")}finally{N(!1)}}const H={pending:"text-yellow-500",in_progress:"text-blue-500",completed:"text-green-500",cancelled:"text-red-500"};return c.jsx(ra,{open:l,onOpenChange:r,children:c.jsxs(In,{className:"max-w-lg max-h-[85vh] overflow-y-auto",children:[c.jsx(Ba,{children:c.jsxs(sa,{className:"flex items-center gap-2",children:[c.jsx(js,{className:"size-5 text-orange-500"}),u?"Edit Agent":"Agent Details"]})}),c.jsxs("div",{className:"space-y-4",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("span",{className:`size-2 rounded-full ${T.color}`}),c.jsx("span",{className:"text-sm text-muted-foreground",children:T.label}),c.jsxs("span",{className:"text-sm text-muted-foreground",children:["— last seen ",pw(e.last_seen_at)]})]}),u?c.jsxs("div",{className:"space-y-3",children:[c.jsxs("div",{className:"space-y-1.5",children:[c.jsx("label",{className:"text-sm font-medium",children:"Name"}),c.jsx(It,{value:m,onChange:E=>h(E.target.value),className:"h-9"})]}),c.jsxs("div",{className:"space-y-1.5",children:[c.jsx("label",{className:"text-sm font-medium",children:"Description"}),c.jsx(It,{value:p,onChange:E=>v(E.target.value),className:"h-9"})]}),c.jsxs("div",{className:"space-y-1.5",children:[c.jsx("label",{className:"text-sm font-medium",children:"Role"}),c.jsxs(gn,{value:y,onValueChange:w,children:[c.jsx(Zt,{className:"h-9",children:c.jsx(hn,{})}),c.jsxs(Jt,{children:[c.jsx(Te,{value:"agent",children:"Agent"}),c.jsx(Te,{value:"admin",children:"Admin"}),c.jsx(Te,{value:"observer",children:"Observer"})]})]})]}),C&&c.jsx("p",{className:"text-sm text-red-500",children:C}),c.jsxs("div",{className:"flex gap-2",children:[c.jsxs(se,{size:"sm",onClick:O,disabled:S||!m.trim(),className:"gap-1.5",children:[c.jsx(r0,{className:"size-3.5"}),S?"Saving...":"Save"]}),c.jsx(se,{size:"sm",variant:"outline",onClick:()=>{f(!1),M(null)},children:"Cancel"})]})]}):c.jsxs("div",{className:"space-y-3",children:[c.jsxs("div",{className:"grid grid-cols-2 gap-3 text-sm",children:[c.jsxs("div",{children:[c.jsx("span",{className:"text-muted-foreground",children:"Name"}),c.jsx("p",{className:"font-medium",children:e.name})]}),c.jsxs("div",{children:[c.jsx("span",{className:"text-muted-foreground",children:"ID"}),c.jsx("p",{className:"font-mono text-xs",children:e.id})]}),c.jsxs("div",{children:[c.jsx("span",{className:"text-muted-foreground",children:"Role"}),c.jsx("div",{className:"mt-0.5",children:c.jsx(wg,{role:e.role})})]}),c.jsxs("div",{children:[c.jsx("span",{className:"text-muted-foreground",children:"Description"}),c.jsx("p",{children:e.description||"—"})]})]}),c.jsxs(se,{size:"sm",variant:"outline",onClick:()=>f(!0),className:"gap-1.5",children:[c.jsx(oo,{className:"size-3.5"})," Edit"]})]}),c.jsxs("div",{className:"grid grid-cols-4 gap-2",children:[c.jsx(St,{className:"py-2",children:c.jsxs(wt,{className:"px-3 py-0 text-center",children:[c.jsx("p",{className:"text-lg font-bold",children:e.total}),c.jsx("p",{className:"text-xs text-muted-foreground",children:"Total"})]})}),c.jsx(St,{className:"py-2",children:c.jsxs(wt,{className:"px-3 py-0 text-center",children:[c.jsx("p",{className:"text-lg font-bold text-yellow-500",children:e.pending}),c.jsx("p",{className:"text-xs text-muted-foreground",children:"Pending"})]})}),c.jsx(St,{className:"py-2",children:c.jsxs(wt,{className:"px-3 py-0 text-center",children:[c.jsx("p",{className:"text-lg font-bold text-blue-500",children:e.inProgress}),c.jsx("p",{className:"text-xs text-muted-foreground",children:"Active"})]})}),c.jsx(St,{className:"py-2",children:c.jsxs(wt,{className:"px-3 py-0 text-center",children:[c.jsx("p",{className:"text-lg font-bold text-green-500",children:e.completed}),c.jsx("p",{className:"text-xs text-muted-foreground",children:"Done"})]})})]}),c.jsxs("div",{className:"flex items-center gap-4 text-sm",children:[c.jsxs("div",{children:[c.jsx("span",{className:"text-muted-foreground",children:"Completion rate: "}),c.jsx(Ht,{variant:e.completionRate>=80?"default":e.completionRate>=50?"secondary":"outline",children:e.total>0?`${e.completionRate}%`:"—"})]}),c.jsxs("div",{children:[c.jsx("span",{className:"text-muted-foreground",children:"Avg work time: "}),c.jsx("span",{className:"font-medium",children:e.avgWorkTime!==null?vw(e.avgWorkTime):"—"})]})]}),e.lastTask&&c.jsxs("div",{className:"text-sm",children:[c.jsx("span",{className:"text-muted-foreground",children:"Last active task: "}),c.jsx("span",{className:"font-medium",children:e.lastTask.title}),c.jsxs("span",{className:`ml-1.5 ${H[e.lastTask.status]||"text-muted-foreground"}`,children:["(",e.lastTask.status.replace("_"," "),")"]})]}),_.length>0&&c.jsxs("div",{children:[c.jsxs("p",{className:"text-sm font-medium mb-2",children:["Recent Tasks (",_.length,")"]}),c.jsx("div",{className:"max-h-[200px] overflow-y-auto rounded border divide-y",children:_.map(E=>c.jsxs("div",{className:"flex items-center justify-between px-3 py-2 text-sm",children:[c.jsx("span",{className:"truncate max-w-[300px]",children:E.title}),c.jsx(Ht,{variant:"outline",className:`text-xs shrink-0 ml-2 ${H[E.status]||""}`,children:E.status.replace("_"," ")})]},E.id))})]})]})]})})}function WT(e){const a=[],l=new Set;for(let r=0;r<e.length;r++){if(l.has(e[r].id))continue;const s=[e[r]];for(let u=r+1;u<e.length;u++){if(l.has(e[u].id))continue;const f=e[r].name.toLowerCase(),m=e[u].name.toLowerCase(),h=Math.max(f.length,m.length);if(h===0)continue;(1-Ay(f,m)/h>=.6||f.includes(m)||m.includes(f))&&(s.push(e[u]),l.add(e[u].id))}if(s.length>1){l.add(e[r].id);const u=s[0].name.toLowerCase(),f=s[1].name.toLowerCase(),m=Math.max(u.length,f.length),h=Ay(u,f);a.push({agents:s,similarity:Math.round((1-h/m)*100)})}}return a}function KT({open:e,onOpenChange:a,agents:l,onMerged:r}){const s=x.useMemo(()=>WT(l),[l]),[u,f]=x.useState(null);async function m(h,p){f(p);try{const v=h.agents.filter(y=>y.id!==p).map(y=>y.id);await Promise.all(v.map(y=>fetch(`/api/agents/${y}`,{method:"DELETE"}))),r()}finally{f(null)}}return c.jsx(ra,{open:e,onOpenChange:a,children:c.jsxs(In,{className:"max-w-md max-h-[70vh] overflow-y-auto",children:[c.jsx(Ba,{children:c.jsxs(sa,{className:"flex items-center gap-2",children:[c.jsx(l0,{className:"size-5"})," Merge Duplicate Agents"]})}),s.length===0?c.jsx("p",{className:"text-sm text-muted-foreground py-4 text-center",children:"No duplicate agents found."}):c.jsx("div",{className:"space-y-4",children:s.map((h,p)=>c.jsxs("div",{className:"rounded border p-3 space-y-2",children:[c.jsxs("p",{className:"text-sm font-medium",children:["Similar names (",h.similarity,"% match)"]}),c.jsx("div",{className:"space-y-1.5",children:h.agents.map(v=>c.jsxs("div",{className:"flex items-center justify-between text-sm",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx(js,{className:"size-3.5 text-orange-500"}),c.jsx("span",{children:v.name}),c.jsx("code",{className:"text-xs text-muted-foreground",children:v.id})]}),c.jsx(se,{size:"sm",variant:"outline",className:"h-7 text-xs",disabled:u!==null,onClick:()=>m(h,v.id),children:u===v.id?"Merging...":"Keep"})]},v.id))}),c.jsx("p",{className:"text-xs text-muted-foreground",children:'Click "Keep" to keep that agent and delete the others.'})]},p))})]})})}function XT({agents:e,onClear:a}){return e.length<2?null:c.jsxs(St,{className:"mt-4",children:[c.jsx(Vt,{className:"pb-2",children:c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs(Ut,{className:"text-sm flex items-center gap-2",children:[c.jsx(e0,{className:"size-4"})," Agent Comparison"]}),c.jsxs(se,{variant:"ghost",size:"sm",className:"h-7 text-xs",onClick:a,children:[c.jsx(Fm,{className:"size-3 mr-1"})," Close"]})]})}),c.jsx(wt,{children:c.jsx("div",{className:"overflow-x-auto",children:c.jsxs("table",{className:"w-full text-sm",children:[c.jsx("thead",{children:c.jsxs("tr",{className:"border-b",children:[c.jsx("th",{className:"text-left py-2 pr-4 text-muted-foreground font-medium",children:"Metric"}),e.map(l=>c.jsx("th",{className:"text-center py-2 px-3 font-medium",children:l.name},l.id))]})}),c.jsxs("tbody",{className:"divide-y",children:[c.jsxs("tr",{children:[c.jsx("td",{className:"py-1.5 pr-4 text-muted-foreground",children:"Status"}),e.map(l=>{const r=Sg(l.last_seen_at);return c.jsx("td",{className:"text-center py-1.5 px-3",children:c.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[c.jsx("span",{className:`size-2 rounded-full ${r.color}`}),r.label]})},l.id)})]}),c.jsxs("tr",{children:[c.jsx("td",{className:"py-1.5 pr-4 text-muted-foreground",children:"Role"}),e.map(l=>c.jsx("td",{className:"text-center py-1.5 px-3",children:c.jsx(wg,{role:l.role})},l.id))]}),c.jsxs("tr",{children:[c.jsx("td",{className:"py-1.5 pr-4 text-muted-foreground",children:"Total Tasks"}),e.map(l=>c.jsx("td",{className:"text-center py-1.5 px-3 font-medium",children:l.total},l.id))]}),c.jsxs("tr",{children:[c.jsx("td",{className:"py-1.5 pr-4 text-muted-foreground",children:"Pending"}),e.map(l=>c.jsx("td",{className:"text-center py-1.5 px-3 text-yellow-500",children:l.pending},l.id))]}),c.jsxs("tr",{children:[c.jsx("td",{className:"py-1.5 pr-4 text-muted-foreground",children:"In Progress"}),e.map(l=>c.jsx("td",{className:"text-center py-1.5 px-3 text-blue-500",children:l.inProgress},l.id))]}),c.jsxs("tr",{children:[c.jsx("td",{className:"py-1.5 pr-4 text-muted-foreground",children:"Completed"}),e.map(l=>c.jsx("td",{className:"text-center py-1.5 px-3 text-green-500",children:l.completed},l.id))]}),c.jsxs("tr",{children:[c.jsx("td",{className:"py-1.5 pr-4 text-muted-foreground",children:"Rate"}),e.map(l=>c.jsx("td",{className:"text-center py-1.5 px-3",children:c.jsx(Ht,{variant:l.completionRate>=80?"default":l.completionRate>=50?"secondary":"outline",children:l.total>0?`${l.completionRate}%`:"—"})},l.id))]}),c.jsxs("tr",{children:[c.jsx("td",{className:"py-1.5 pr-4 text-muted-foreground",children:"Avg Time"}),e.map(l=>c.jsx("td",{className:"text-center py-1.5 px-3",children:l.avgWorkTime!==null?vw(l.avgWorkTime):"—"},l.id))]}),c.jsxs("tr",{children:[c.jsx("td",{className:"py-1.5 pr-4 text-muted-foreground",children:"Last Task"}),e.map(l=>{var r;return c.jsx("td",{className:"text-center py-1.5 px-3 max-w-[150px] truncate",children:((r=l.lastTask)==null?void 0:r.title)||"—"},l.id)})]})]})]})})})]})}function QT(){return[{id:"select",header:({table:e})=>c.jsx("input",{type:"checkbox",className:"rounded",checked:e.getIsAllPageRowsSelected(),onChange:a=>e.toggleAllPageRowsSelected(a.target.checked)}),cell:({row:e})=>c.jsx("input",{type:"checkbox",className:"rounded",checked:e.getIsSelected(),onChange:a=>{a.stopPropagation(),e.toggleSelected(a.target.checked)},onClick:a=>a.stopPropagation()}),size:30,enableSorting:!1},{accessorKey:"name",header:({column:e})=>c.jsxs(se,{variant:"ghost",size:"sm",className:"-ml-3",onClick:()=>e.toggleSorting(),children:["Name ",c.jsx(dn,{className:"size-3"})]}),cell:({row:e})=>{const a=Sg(e.original.last_seen_at);return c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("span",{className:`size-2 rounded-full shrink-0 ${a.color}`,title:a.label}),c.jsx(js,{className:"size-4 text-orange-500 shrink-0"}),c.jsx("span",{className:"font-medium text-sm",children:e.original.name})]})}},{accessorKey:"role",header:"Role",cell:({row:e})=>c.jsx(wg,{role:e.original.role}),size:80},{accessorKey:"id",header:"ID",cell:({row:e})=>c.jsx("code",{className:"text-sm text-muted-foreground",children:e.original.id})},{accessorKey:"description",header:"Description",cell:({row:e})=>c.jsx("span",{className:"text-sm text-muted-foreground truncate max-w-[200px] block",children:e.original.description||"—"})},{accessorKey:"total",header:({column:e})=>c.jsxs(se,{variant:"ghost",size:"sm",className:"-ml-3",onClick:()=>e.toggleSorting(),children:["Tasks ",c.jsx(dn,{className:"size-3"})]}),cell:({row:e})=>{const{total:a,pending:l,inProgress:r,completed:s}=e.original;return a===0?c.jsx("span",{className:"text-sm text-muted-foreground",children:"0"}):c.jsxs("div",{className:"flex items-center gap-1.5 text-sm",children:[c.jsx("span",{className:"font-medium",children:a}),c.jsxs("span",{className:"text-muted-foreground",children:["(",c.jsx("span",{className:"text-yellow-500",children:l}),"/",c.jsx("span",{className:"text-blue-500",children:r}),"/",c.jsx("span",{className:"text-green-500",children:s}),")"]})]})}},{accessorKey:"completionRate",header:({column:e})=>c.jsxs(se,{variant:"ghost",size:"sm",className:"-ml-3",onClick:()=>e.toggleSorting(),children:["Rate ",c.jsx(dn,{className:"size-3"})]}),cell:({row:e})=>{const a=e.original.completionRate;return e.original.total===0?c.jsx("span",{className:"text-sm text-muted-foreground",children:"—"}):c.jsxs(Ht,{variant:a>=80?"default":a>=50?"secondary":"outline",className:"text-sm",children:[a,"%"]})}},{id:"lastTask",header:"Last Task",cell:({row:e})=>{const a=e.original.lastTask;return a?c.jsx("span",{className:"text-sm truncate max-w-[180px] block",title:a.title,children:a.title}):c.jsx("span",{className:"text-sm text-muted-foreground",children:"—"})}},{accessorKey:"last_seen_at",header:({column:e})=>c.jsxs(se,{variant:"ghost",size:"sm",className:"-ml-3",onClick:()=>e.toggleSorting(),children:["Last Seen ",c.jsx(dn,{className:"size-3"})]}),cell:({row:e})=>c.jsx("span",{className:"text-sm text-muted-foreground whitespace-nowrap",children:pw(e.original.last_seen_at)})},{id:"actions",header:"",cell:({row:e,table:a})=>{const l=a.options.meta;return c.jsx("div",{onClick:r=>r.stopPropagation(),children:c.jsxs(jl,{children:[c.jsx(Ml,{asChild:!0,children:c.jsx(se,{variant:"ghost",size:"icon",className:"size-7",children:c.jsx(_s,{className:"size-4"})})}),c.jsxs(Fa,{align:"end",children:[c.jsxs(dt,{onClick:()=>l==null?void 0:l.onOpenDetail(e.original),children:[c.jsx(oo,{className:"size-3.5 mr-2"})," View / Edit"]}),c.jsx(mo,{}),c.jsxs(dt,{className:"text-red-500 focus:text-red-500",onClick:()=>l==null?void 0:l.onDelete(e.original.id),children:[c.jsx(la,{className:"size-3.5 mr-2"})," Delete"]})]})]})})},size:50}]}function ZT(){const[e,a]=x.useState([]),[l,r]=x.useState([]),[s,u]=x.useState(!0),[f,m]=x.useState([{id:"total",desc:!0}]),[h,p]=x.useState(""),[v,y]=x.useState({}),[w,S]=x.useState(!1),[N,C]=x.useState(!1),[M,T]=x.useState(null),[D,_]=x.useState(!1),[O,H]=x.useState("all"),[E,k]=x.useState(!1),F=x.useRef(null),K=x.useMemo(()=>QT(),[]);function W(){Promise.all([fetch("/api/agents").then(A=>A.json()),fetch("/api/tasks").then(A=>A.json())]).then(([A,R])=>{a(A),r(R)}).finally(()=>u(!1))}x.useEffect(()=>{W()},[]),x.useEffect(()=>{function A(R){var V,te,ae;if(R.key==="/"&&!R.ctrlKey&&!R.metaKey){const oe=(V=R.target)==null?void 0:V.tagName;oe!=="INPUT"&&oe!=="TEXTAREA"&&(R.preventDefault(),(te=F.current)==null||te.focus())}R.key==="Escape"&&(p(""),(ae=F.current)==null||ae.blur())}return document.addEventListener("keydown",A),()=>document.removeEventListener("keydown",A)},[]);const Z=x.useMemo(()=>e.map(A=>{const R=xw(l,A),V=R.length,te=R.filter(xe=>xe.status==="pending").length,ae=R.filter(xe=>xe.status==="in_progress").length,oe=R.filter(xe=>xe.status==="completed").length,de=V>0?Math.round(oe/V*100):0,le=R.filter(xe=>xe.status==="completed"&&xe.completed_at);let we=null;if(le.length>0){const xe=le.map(Me=>{const De=new Date(Me.completed_at).getTime(),ot=new Date(Me.created_at).getTime();return De-ot}).filter(Me=>Me>0);xe.length>0&&(we=xe.reduce((Me,De)=>Me+De,0)/xe.length)}const fe=$T(R);return{...A,total:V,pending:te,inProgress:ae,completed:oe,completionRate:de,avgWorkTime:we,lastTask:fe}}),[e,l]),re=x.useMemo(()=>O==="all"?Z:O==="active"?Z.filter(A=>A.inProgress>0):Z.filter(A=>A.inProgress===0),[Z,O]);async function ne(A){await fetch(`/api/agents/${A}`,{method:"DELETE"}),a(R=>R.filter(V=>V.id!==A))}async function ue(A){await Promise.all(A.map(R=>fetch(`/api/agents/${R}`,{method:"DELETE"}))),a(R=>R.filter(V=>!A.includes(V.id))),y({})}function me(A){T(A),_(!0)}const z=fu({data:re,columns:K,state:{sorting:f,globalFilter:h,rowSelection:v},onSortingChange:m,onGlobalFilterChange:p,onRowSelectionChange:y,getCoreRowModel:iu(),getSortedRowModel:du(),getFilteredRowModel:cu(),getPaginationRowModel:uu(),enableRowSelection:!0,getRowId:A=>A.id,initialState:{pagination:{pageSize:15}},meta:{onDelete:ne,onOpenDetail:me}}),Y=Object.keys(v).filter(A=>v[A]),Q=Y.length>0,G=Z.filter(A=>Y.includes(A.id));return s?c.jsx("div",{className:"text-center text-muted-foreground py-12",children:"Loading agents..."}):e.length===0&&!w?c.jsxs("div",{className:"text-center py-12",children:[c.jsx(js,{className:"mx-auto size-10 text-muted-foreground/50 mb-3"}),c.jsx("p",{className:"text-muted-foreground",children:"No agents registered."}),c.jsxs("p",{className:"text-sm text-muted-foreground mt-1",children:["Agents register via ",c.jsx("code",{className:"bg-muted px-1.5 py-0.5 rounded text-sm",children:"register_agent"})," MCP tool or CLI."]}),c.jsxs(se,{variant:"outline",size:"sm",className:"mt-4 gap-1.5",onClick:()=>S(!0),children:[c.jsx(hl,{className:"size-3.5"})," New Agent"]}),c.jsx(ky,{open:w,onOpenChange:S,onCreated:W})]}):c.jsxs("div",{className:"space-y-4",children:[c.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[c.jsxs("div",{className:"relative flex-1 min-w-[180px] max-w-xs",children:[c.jsx(Ic,{className:"absolute left-2.5 top-2.5 size-3.5 text-muted-foreground"}),c.jsx(It,{ref:F,placeholder:"Search agents... (press /)",value:h,onChange:A=>p(A.target.value),className:"pl-8 h-9"})]}),c.jsxs(gn,{value:O,onValueChange:A=>H(A),children:[c.jsx(Zt,{className:"h-9 w-[130px]",children:c.jsx(hn,{placeholder:"Filter"})}),c.jsxs(Jt,{children:[c.jsx(Te,{value:"all",children:"All"}),c.jsx(Te,{value:"active",children:"Active"}),c.jsx(Te,{value:"idle",children:"Idle"})]})]}),c.jsxs("span",{className:"text-sm text-muted-foreground",children:[re.length," agent(s)"]}),c.jsx("div",{className:"flex-1"}),c.jsxs(se,{variant:"outline",size:"sm",className:"gap-1.5 h-9",onClick:()=>C(!0),children:[c.jsx(l0,{className:"size-3.5"})," Merge"]}),c.jsxs(se,{variant:"outline",size:"sm",className:"gap-1.5 h-9",onClick:()=>S(!0),children:[c.jsx(hl,{className:"size-3.5"})," New Agent"]})]}),c.jsx("div",{className:"rounded-md border",children:c.jsxs(Fs,{children:[c.jsx(Bs,{children:z.getHeaderGroups().map(A=>c.jsx(mn,{children:A.headers.map(R=>c.jsx(Us,{children:R.isPlaceholder?null:bl(R.column.columnDef.header,R.getContext())},R.id))},A.id))}),c.jsx(Vs,{children:z.getRowModel().rows.length?z.getRowModel().rows.map(A=>c.jsx(mn,{"data-state":A.getIsSelected()?"selected":void 0,className:"cursor-pointer",onClick:()=>me(A.original),children:A.getVisibleCells().map(R=>c.jsx(Pa,{children:bl(R.column.columnDef.cell,R.getContext())},R.id))},A.id)):c.jsx(mn,{children:c.jsx(Pa,{colSpan:K.length,className:"h-24 text-center text-muted-foreground",children:"No agents found."})})})]})}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("p",{className:"text-sm text-muted-foreground",children:[z.getFilteredRowModel().rows.length," agent(s)"]}),z.getPageCount()>1&&c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx(se,{variant:"outline",size:"sm",onClick:()=>z.previousPage(),disabled:!z.getCanPreviousPage(),children:c.jsx(Ms,{className:"size-3.5"})}),c.jsxs("span",{className:"text-sm text-muted-foreground",children:["Page ",z.getState().pagination.pageIndex+1," of ",z.getPageCount()]}),c.jsx(se,{variant:"outline",size:"sm",onClick:()=>z.nextPage(),disabled:!z.getCanNextPage(),children:c.jsx(ro,{className:"size-3.5"})})]})]}),E&&G.length>=2&&c.jsx(XT,{agents:G,onClear:()=>{k(!1),y({})}}),Q&&c.jsxs("div",{className:"fixed bottom-6 left-1/2 -translate-x-1/2 z-50 flex items-center gap-3 rounded-xl border bg-background px-5 py-3 shadow-xl",children:[c.jsxs("span",{className:"text-sm font-medium",children:[Y.length," selected"]}),c.jsx("div",{className:"h-4 w-px bg-border"}),Y.length>=2&&c.jsxs(c.Fragment,{children:[c.jsxs(se,{variant:"outline",size:"sm",className:"h-7 text-sm gap-1",onClick:()=>k(!0),children:[c.jsx(e0,{className:"size-3"})," Compare"]}),c.jsx("div",{className:"h-4 w-px bg-border"})]}),c.jsxs(se,{variant:"outline",size:"sm",className:"h-7 text-sm text-red-500",onClick:()=>ue(Y),children:[c.jsx(la,{className:"size-3"})," Delete"]}),c.jsx("div",{className:"h-4 w-px bg-border"}),c.jsx(se,{variant:"ghost",size:"sm",className:"h-7 text-sm",onClick:()=>{y({}),k(!1)},children:"Clear"})]}),c.jsx(ky,{open:w,onOpenChange:S,onCreated:W}),c.jsx(KT,{open:N,onOpenChange:C,agents:e,onMerged:W}),c.jsx(qT,{agent:M,tasks:l,open:D,onOpenChange:_,onUpdated:W})]})}function yw(e){const a=Math.floor((Date.now()-new Date(e).getTime())/1e3);if(a<60)return`${a}s ago`;const l=Math.floor(a/60);if(l<60)return`${l}m ago`;const r=Math.floor(l/60);return r<24?`${r}h ago`:`${Math.floor(r/24)}d ago`}function JT(e){return{pending:"text-yellow-500",in_progress:"text-blue-500",completed:"text-green-500",failed:"text-red-500",cancelled:"text-muted-foreground"}[e]||"text-foreground"}function bw(e){return e==="active"?"default":e==="completed"?"secondary":"outline"}function eO(e){let a=e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">");return a=a.replace(/```(\w*)\n([\s\S]*?)```/g,(l,r,s)=>`<pre class="my-2 rounded bg-muted p-3 text-xs font-mono overflow-x-auto"><code>${s.trim()}</code></pre>`),a=a.replace(/`([^`]+)`/g,'<code class="rounded bg-muted px-1 py-0.5 text-xs font-mono">$1</code>'),a=a.replace(/\*\*([^*]+)\*\*/g,"<strong>$1</strong>"),a=a.replace(new RegExp("(?<!\\*)\\*([^*]+)\\*(?!\\*)","g"),"<em>$1</em>"),a=a.replace(/^### (.+)$/gm,'<h3 class="text-sm font-semibold mt-3 mb-1">$1</h3>'),a=a.replace(/^## (.+)$/gm,'<h2 class="text-base font-semibold mt-4 mb-1">$1</h2>'),a=a.replace(/^- (.+)$/gm,'<li class="ml-4 list-disc">$1</li>'),a=a.replace(/((?:<li[^>]*>.*<\/li>\n?)+)/g,'<ul class="my-1 space-y-0.5 text-sm">$1</ul>'),a=a.replace(/^\d+\. (.+)$/gm,'<li class="ml-4 list-decimal">$1</li>'),a=a.replace(/\n\n/g,'</p><p class="my-1.5">'),a=a.replace(new RegExp("(?<!<\\/pre>|<\\/li>|<\\/ul>|<\\/h[23]>)\\n(?!<)","g"),"<br>"),`<p class="my-1.5">${a}</p>`}function rm({open:e,onOpenChange:a,onSaved:l,projects:r,agents:s,editPlan:u}){const[f,m]=x.useState(""),[h,p]=x.useState(""),[v,y]=x.useState("active"),[w,S]=x.useState("none"),[N,C]=x.useState("none"),[M,T]=x.useState(!1),[D,_]=x.useState(null),O=!!u;x.useEffect(()=>{u?(m(u.name),p(u.description||""),y(u.status),S(u.project_id||"none"),C(u.agent_id||"none")):(m(""),p(""),y("active"),S("none"),C("none")),_(null)},[u,e]);async function H(E){if(E.preventDefault(),!!f.trim()){T(!0),_(null);try{const k={name:f.trim(),status:v};h.trim()&&(k.description=h.trim()),w!=="none"&&(k.project_id=w),N!=="none"&&(k.agent_id=N);const F=O?`/api/plans/${u.id}`:"/api/plans",Z=await(await fetch(F,{method:O?"PATCH":"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(k)})).json();Z.error?_(Z.error):(a(!1),l())}catch{_(O?"Failed to update plan":"Failed to create plan")}finally{T(!1)}}}return c.jsx(ra,{open:e,onOpenChange:a,children:c.jsxs(In,{className:"max-w-lg",children:[c.jsx(Ba,{children:c.jsx(sa,{children:O?"Edit Plan":"New Plan"})}),c.jsxs("form",{onSubmit:H,className:"space-y-4",children:[c.jsxs("div",{className:"space-y-1.5",children:[c.jsx("label",{className:"text-sm font-medium",children:"Name"}),c.jsx(It,{value:f,onChange:E=>m(E.target.value),placeholder:"Plan name",className:"h-9",autoFocus:!0})]}),c.jsxs("div",{className:"space-y-1.5",children:[c.jsx("label",{className:"text-sm font-medium",children:"Description"}),c.jsx("textarea",{value:h,onChange:E=>p(E.target.value),placeholder:"Plan description (supports markdown)",rows:8,className:"flex w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 resize-y font-mono"}),c.jsx("p",{className:"text-xs text-muted-foreground",children:"Supports markdown: **bold**, *italic*, `code`, ```code blocks```, lists, headings"})]}),c.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[c.jsxs("div",{className:"space-y-1.5",children:[c.jsx("label",{className:"text-sm font-medium",children:"Status"}),c.jsxs(gn,{value:v,onValueChange:y,children:[c.jsx(Zt,{className:"h-9",children:c.jsx(hn,{})}),c.jsxs(Jt,{children:[c.jsx(Te,{value:"active",children:"Active"}),c.jsx(Te,{value:"completed",children:"Completed"}),c.jsx(Te,{value:"archived",children:"Archived"})]})]})]}),c.jsxs("div",{className:"space-y-1.5",children:[c.jsx("label",{className:"text-sm font-medium",children:"Project"}),c.jsxs(gn,{value:w,onValueChange:S,children:[c.jsx(Zt,{className:"h-9",children:c.jsx(hn,{placeholder:"No project"})}),c.jsxs(Jt,{children:[c.jsx(Te,{value:"none",children:"No project"}),r.map(E=>c.jsx(Te,{value:E.id,children:E.name},E.id))]})]})]})]}),c.jsxs("div",{className:"space-y-1.5",children:[c.jsx("label",{className:"text-sm font-medium",children:"Owner (Agent)"}),c.jsxs(gn,{value:N,onValueChange:C,children:[c.jsx(Zt,{className:"h-9",children:c.jsx(hn,{placeholder:"No owner"})}),c.jsxs(Jt,{children:[c.jsx(Te,{value:"none",children:"No owner"}),s.map(E=>c.jsx(Te,{value:E.id,children:E.name},E.id))]})]})]}),D&&c.jsx("p",{className:"text-sm text-red-500",children:D}),c.jsxs(Is,{children:[c.jsx(se,{type:"button",variant:"outline",onClick:()=>a(!1),children:"Cancel"}),c.jsx(se,{type:"submit",disabled:!f.trim()||M,children:M?O?"Saving...":"Creating...":O?"Save":"Create"})]})]})]})})}function tO({plan:e,open:a,onOpenChange:l,projects:r,agents:s}){var y,w;const[u,f]=x.useState(null),[m,h]=x.useState(!1);x.useEffect(()=>{if(!e||!a){f(null);return}h(!0),fetch(`/api/plans/${e.id}`).then(S=>S.json()).then(S=>{S&&S.id?f(S):f({...e,tasks:S.tasks||[]})}).catch(()=>f({...e,tasks:[]})).finally(()=>h(!1))},[e,a]);const p=x.useMemo(()=>{var S;return e!=null&&e.project_id?((S=r.find(N=>N.id===e.project_id))==null?void 0:S.name)||e.project_id.slice(0,8):null},[e,r]),v=x.useMemo(()=>{var S;return e!=null&&e.agent_id?((S=s.find(N=>N.id===e.agent_id))==null?void 0:S.name)||e.agent_id.slice(0,8):null},[e,s]);return e?c.jsx(ra,{open:a,onOpenChange:l,children:c.jsxs(In,{className:"max-w-2xl max-h-[85vh] overflow-y-auto",children:[c.jsx(Ba,{children:c.jsxs(sa,{className:"flex items-center gap-2",children:[c.jsx(Lm,{className:"size-5 text-blue-500"}),e.name]})}),c.jsxs("div",{className:"space-y-4",children:[c.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[c.jsx(Ht,{variant:bw(e.status),children:e.status}),p&&c.jsx(Ht,{variant:"outline",children:p}),v&&c.jsxs(Ht,{variant:"outline",className:"text-xs",children:["Owner: ",v]})]}),e.description&&c.jsxs(St,{className:"shadow-none",children:[c.jsx(Vt,{className:"pb-2",children:c.jsx(Ut,{className:"text-sm",children:"Description"})}),c.jsx(wt,{children:c.jsx("div",{className:"prose prose-sm dark:prose-invert max-w-none text-sm leading-relaxed",dangerouslySetInnerHTML:{__html:eO(e.description)}})})]}),c.jsxs("div",{className:"grid grid-cols-2 gap-4 text-sm",children:[c.jsxs("div",{children:[c.jsx("span",{className:"text-muted-foreground",children:"Task List"}),c.jsx("p",{className:"font-medium",children:e.task_list_id||"—"})]}),c.jsxs("div",{children:[c.jsx("span",{className:"text-muted-foreground",children:"Created"}),c.jsx("p",{className:"font-medium",children:new Date(e.created_at).toLocaleString()})]}),c.jsxs("div",{children:[c.jsx("span",{className:"text-muted-foreground",children:"Updated"}),c.jsx("p",{className:"font-medium",children:new Date(e.updated_at).toLocaleString()})]})]}),c.jsxs("div",{children:[c.jsxs("h3",{className:"text-sm font-medium mb-2",children:["Tasks (",((y=u==null?void 0:u.tasks)==null?void 0:y.length)??0,")"]}),m?c.jsx("p",{className:"text-sm text-muted-foreground",children:"Loading tasks..."}):(w=u==null?void 0:u.tasks)!=null&&w.length?c.jsx("div",{className:"space-y-1 max-h-[300px] overflow-y-auto",children:u.tasks.map(S=>c.jsxs("div",{className:"flex items-center gap-2 rounded-md px-2 py-1.5 text-sm hover:bg-muted/50",children:[c.jsx("span",{className:`size-2 rounded-full shrink-0 ${JT(S.status).replace("text-","bg-")}`}),c.jsx("code",{className:"text-sm text-muted-foreground shrink-0",children:S.short_id||S.id.slice(0,8)}),c.jsx("span",{className:"truncate flex-1",children:S.title}),c.jsx(Ht,{variant:"outline",className:"text-xs shrink-0",children:S.priority}),c.jsx("span",{className:"text-sm text-muted-foreground shrink-0",children:S.assigned_to||"—"}),c.jsx("span",{className:"text-sm text-muted-foreground shrink-0",children:yw(S.updated_at)})]},S.id))}):c.jsx("p",{className:"text-sm text-muted-foreground",children:"No tasks in this plan."})]})]})]})}):null}function nO(){return[{id:"select",header:({table:e})=>c.jsx("input",{type:"checkbox",className:"rounded",checked:e.getIsAllPageRowsSelected(),onChange:a=>e.toggleAllPageRowsSelected(a.target.checked)}),cell:({row:e})=>c.jsx("input",{type:"checkbox",className:"rounded",checked:e.getIsSelected(),onChange:a=>{a.stopPropagation(),e.toggleSelected(a.target.checked)},onClick:a=>a.stopPropagation()}),size:30,enableSorting:!1},{accessorKey:"name",header:({column:e})=>c.jsxs(se,{variant:"ghost",size:"sm",className:"-ml-3",onClick:()=>e.toggleSorting(),children:["Name ",c.jsx(dn,{className:"size-3"})]}),cell:({row:e})=>c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx(Lm,{className:"size-4 text-blue-500 shrink-0"}),c.jsx("span",{className:"font-medium text-sm",children:e.original.name})]})},{accessorKey:"status",header:"Status",cell:({row:e})=>c.jsx(Ht,{variant:bw(e.original.status),children:e.original.status}),filterFn:(e,a,l)=>!l||l==="all"?!0:e.original.status===l},{accessorKey:"agent_id",header:"Owner",cell:({row:e,table:a})=>{var u;const l=a.options.meta,r=e.original.agent_id;if(!r)return c.jsx("span",{className:"text-sm text-muted-foreground",children:"—"});const s=(u=l==null?void 0:l.agents)==null?void 0:u.find(f=>f.id===r);return c.jsx("span",{className:"text-sm",children:(s==null?void 0:s.name)||r.slice(0,8)})}},{accessorKey:"project_id",header:"Project",cell:({row:e,table:a})=>{var u;const l=a.options.meta,r=e.original.project_id;if(!r)return c.jsx("span",{className:"text-sm text-muted-foreground",children:"—"});const s=(u=l==null?void 0:l.projects)==null?void 0:u.find(f=>f.id===r);return c.jsx("span",{className:"text-sm",children:(s==null?void 0:s.name)||r.slice(0,8)})}},{accessorKey:"description",header:"Description",cell:({row:e})=>{const a=e.original.description;if(!a)return c.jsx("span",{className:"text-sm text-muted-foreground",children:"—"});const l=a.length>80?a.slice(0,80)+"...":a;return c.jsx("span",{className:"text-sm text-muted-foreground truncate max-w-[250px] block",children:l})}},{accessorKey:"created_at",header:({column:e})=>c.jsxs(se,{variant:"ghost",size:"sm",className:"-ml-3",onClick:()=>e.toggleSorting(),children:["Created ",c.jsx(dn,{className:"size-3"})]}),cell:({row:e})=>c.jsx("span",{className:"text-sm text-muted-foreground whitespace-nowrap",children:yw(e.original.created_at)})},{id:"actions",header:"",cell:({row:e,table:a})=>{const l=a.options.meta;return c.jsx("div",{onClick:r=>r.stopPropagation(),children:c.jsxs(jl,{children:[c.jsx(Ml,{asChild:!0,children:c.jsx(se,{variant:"ghost",size:"icon",className:"size-7",children:c.jsx(_s,{className:"size-4"})})}),c.jsxs(Fa,{align:"end",children:[c.jsxs(dt,{onClick:()=>l==null?void 0:l.onEdit(e.original),children:[c.jsx(oo,{className:"size-3.5 mr-2"})," Edit"]}),c.jsx(mo,{}),c.jsxs(dt,{className:"text-red-500 focus:text-red-500",onClick:()=>l==null?void 0:l.onDelete(e.original.id),children:[c.jsx(la,{className:"size-3.5 mr-2"})," Delete"]})]})]})})},size:50}]}function aO(){const[e,a]=x.useState([]),[l,r]=x.useState([]),[s,u]=x.useState([]),[f,m]=x.useState(!0),[h,p]=x.useState([]),[v,y]=x.useState(""),[w,S]=x.useState("all"),[N,C]=x.useState({}),[M,T]=x.useState(!1),[D,_]=x.useState(null),[O,H]=x.useState(null),E=x.useRef(null),k=x.useMemo(()=>nO(),[]);function F(){fetch("/api/plans").then(z=>z.json()).then(a).finally(()=>m(!1))}function K(){fetch("/api/projects").then(z=>z.json()).then(z=>r(z))}function W(){fetch("/api/agents").then(z=>z.json()).then(z=>u(z))}x.useEffect(()=>{F(),K(),W()},[]),x.useEffect(()=>{function z(Y){var Q,G,A;if(Y.key==="/"&&!Y.ctrlKey&&!Y.metaKey){const R=(Q=Y.target)==null?void 0:Q.tagName;R!=="INPUT"&&R!=="TEXTAREA"&&(Y.preventDefault(),(G=E.current)==null||G.focus())}Y.key==="Escape"&&(O?H(null):(y(""),(A=E.current)==null||A.blur()))}return document.addEventListener("keydown",z),()=>document.removeEventListener("keydown",z)},[O]);async function Z(z){await fetch(`/api/plans/${z}`,{method:"DELETE"}),a(Y=>Y.filter(Q=>Q.id!==z))}async function re(z){await Promise.all(z.map(Y=>fetch(`/api/plans/${Y}`,{method:"DELETE"}))),a(Y=>Y.filter(Q=>!z.includes(Q.id))),C({})}const ne=fu({data:e,columns:k,state:{sorting:h,globalFilter:v,rowSelection:N,columnFilters:w!=="all"?[{id:"status",value:w}]:[]},onSortingChange:p,onGlobalFilterChange:y,onRowSelectionChange:C,getCoreRowModel:iu(),getSortedRowModel:du(),getFilteredRowModel:cu(),getPaginationRowModel:uu(),enableRowSelection:!0,getRowId:z=>z.id,initialState:{pagination:{pageSize:15}},meta:{onDelete:Z,onEdit:z=>_(z),projects:l,agents:s}}),ue=Object.keys(N).filter(z=>N[z]),me=ue.length>0;return f?c.jsx("div",{className:"text-center text-muted-foreground py-12",children:"Loading plans..."}):e.length===0&&!M?c.jsxs("div",{className:"text-center py-12",children:[c.jsx(Lm,{className:"mx-auto size-10 text-muted-foreground/50 mb-3"}),c.jsx("p",{className:"text-muted-foreground",children:"No plans yet."}),c.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:"Plans help you organize groups of tasks into execution phases."}),c.jsxs(se,{variant:"outline",size:"sm",className:"mt-4 gap-1.5",onClick:()=>T(!0),children:[c.jsx(hl,{className:"size-3.5"})," New Plan"]}),c.jsx(rm,{open:M,onOpenChange:T,onSaved:F,projects:l,agents:s})]}):c.jsxs("div",{className:"space-y-4",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsxs("div",{className:"relative flex-1 min-w-[200px] max-w-sm",children:[c.jsx(Ic,{className:"absolute left-2.5 top-2.5 size-3.5 text-muted-foreground"}),c.jsx(It,{ref:E,placeholder:"Search plans... (press /)",value:v,onChange:z=>y(z.target.value),className:"pl-8 h-9"})]}),c.jsxs(gn,{value:w,onValueChange:S,children:[c.jsx(Zt,{className:"h-9 w-[140px]",children:c.jsx(hn,{})}),c.jsxs(Jt,{children:[c.jsx(Te,{value:"all",children:"All Statuses"}),c.jsx(Te,{value:"active",children:"Active"}),c.jsx(Te,{value:"completed",children:"Completed"}),c.jsx(Te,{value:"archived",children:"Archived"})]})]}),c.jsxs("span",{className:"text-sm text-muted-foreground",children:[ne.getFilteredRowModel().rows.length," plan(s)"]}),c.jsx("div",{className:"flex-1"}),c.jsxs(se,{variant:"outline",size:"sm",className:"gap-1.5 h-9",onClick:()=>T(!0),children:[c.jsx(hl,{className:"size-3.5"})," New Plan"]})]}),c.jsx("div",{className:"rounded-md border",children:c.jsxs(Fs,{children:[c.jsx(Bs,{children:ne.getHeaderGroups().map(z=>c.jsx(mn,{children:z.headers.map(Y=>c.jsx(Us,{children:Y.isPlaceholder?null:bl(Y.column.columnDef.header,Y.getContext())},Y.id))},z.id))}),c.jsx(Vs,{children:ne.getRowModel().rows.length?ne.getRowModel().rows.map(z=>c.jsx(mn,{className:"cursor-pointer","data-state":z.getIsSelected()?"selected":void 0,onClick:()=>H(z.original),children:z.getVisibleCells().map(Y=>c.jsx(Pa,{children:bl(Y.column.columnDef.cell,Y.getContext())},Y.id))},z.id)):c.jsx(mn,{children:c.jsx(Pa,{colSpan:k.length,className:"h-24 text-center text-muted-foreground",children:"No plans found."})})})]})}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("p",{className:"text-sm text-muted-foreground",children:[ne.getFilteredRowModel().rows.length," plan(s)"]}),ne.getPageCount()>1&&c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx(se,{variant:"outline",size:"sm",onClick:()=>ne.previousPage(),disabled:!ne.getCanPreviousPage(),children:c.jsx(Ms,{className:"size-3.5"})}),c.jsxs("span",{className:"text-sm text-muted-foreground",children:["Page ",ne.getState().pagination.pageIndex+1," of"," ",ne.getPageCount()]}),c.jsx(se,{variant:"outline",size:"sm",onClick:()=>ne.nextPage(),disabled:!ne.getCanNextPage(),children:c.jsx(ro,{className:"size-3.5"})})]})]}),me&&c.jsxs("div",{className:"fixed bottom-6 left-1/2 -translate-x-1/2 z-50 flex items-center gap-3 rounded-xl border bg-background px-5 py-3 shadow-xl",children:[c.jsxs("span",{className:"text-sm font-medium",children:[ue.length," selected"]}),c.jsx("div",{className:"h-4 w-px bg-border"}),c.jsxs(se,{variant:"outline",size:"sm",className:"h-7 text-sm text-red-500",onClick:()=>re(ue),children:[c.jsx(la,{className:"size-3"})," Delete"]}),c.jsx("div",{className:"h-4 w-px bg-border"}),c.jsx(se,{variant:"ghost",size:"sm",className:"h-7 text-sm",onClick:()=>C({}),children:"Clear"})]}),c.jsx(rm,{open:M,onOpenChange:T,onSaved:F,projects:l,agents:s}),c.jsx(rm,{open:!!D,onOpenChange:z=>{z||_(null)},onSaved:F,projects:l,agents:s,editPlan:D}),c.jsx(tO,{plan:O,open:!!O,onOpenChange:z=>{z||H(null)},projects:l,agents:s})]})}function lO(){return c.jsxs("div",{className:"space-y-6",children:[c.jsxs(St,{children:[c.jsx(Vt,{className:"pb-3",children:c.jsx(Ut,{className:"text-sm",children:"Agent-native & headless"})}),c.jsxs(wt,{className:"space-y-2 text-sm text-muted-foreground",children:[c.jsxs("p",{children:[c.jsx("strong",{className:"text-foreground",children:"CLI and MCP are the primary surfaces."})," This dashboard is an optional local admin view that talks only to ",c.jsx("code",{className:"font-mono",children:"/api/*"})," on your machine — there is no sign-in, no hosted auth, and no connection to hosted platform services."]}),c.jsxs("p",{children:["For agent workflows use ",c.jsx("code",{className:"font-mono",children:"todos claim"}),", ",c.jsx("code",{className:"font-mono",children:"todos-mcp"}),", or"," ",c.jsx("code",{className:"font-mono",children:"TODOS_PROFILE=minimal"}),". Cloud sync is explicit opt-in from CLI/MCP only."]})]})]}),c.jsxs(St,{children:[c.jsx(Vt,{className:"pb-3",children:c.jsx(Ut,{className:"text-sm",children:"How it works"})}),c.jsx(wt,{children:c.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-sm",children:[c.jsx(Cc,{n:"1",label:"Install",desc:"bun install -g @hasna/todos"}),c.jsx(Ff,{className:"size-4 text-muted-foreground shrink-0"}),c.jsx(Cc,{n:"2",label:"Add tasks",desc:"todos add 'Fix login bug'"}),c.jsx(Ff,{className:"size-4 text-muted-foreground shrink-0"}),c.jsx(Cc,{n:"3",label:"Connect AI",desc:"Add todos-mcp to your agent"}),c.jsx(Ff,{className:"size-4 text-muted-foreground shrink-0"}),c.jsx(Cc,{n:"4",label:"Track",desc:"todos serve or todos interactive"})]})})]}),c.jsxs(St,{children:[c.jsx(Vt,{className:"pb-3",children:c.jsxs(Ut,{className:"text-sm flex items-center gap-2",children:[c.jsx(LN,{className:"size-4"})," Keyboard Shortcuts"]})}),c.jsx(wt,{children:c.jsxs("div",{className:"grid grid-cols-2 gap-x-8 gap-y-2 text-sm sm:grid-cols-3",children:[c.jsx(Da,{keys:"/",label:"Focus search"}),c.jsx(Da,{keys:"n",label:"New task"}),c.jsx(Da,{keys:"r",label:"Reload data"}),c.jsx(Da,{keys:"0",label:"Dashboard"}),c.jsx(Da,{keys:"1",label:"Tasks"}),c.jsx(Da,{keys:"2",label:"Projects"}),c.jsx(Da,{keys:"3",label:"Agents"}),c.jsx(Da,{keys:"4",label:"Help"}),c.jsx(Da,{keys:"Esc",label:"Back / clear"})]})})]}),c.jsxs(St,{children:[c.jsx(Vt,{className:"pb-3",children:c.jsxs(Ut,{className:"text-sm flex items-center gap-2",children:[c.jsx(YN,{className:"size-4"})," CLI Commands"]})}),c.jsx(wt,{children:c.jsxs("div",{className:"space-y-2 text-sm",children:[c.jsx(Zn,{cmd:"todos add 'Task'",desc:"Create a new task"}),c.jsx(Zn,{cmd:"todos list",desc:"List all tasks"}),c.jsx(Zn,{cmd:"todos list --status pending",desc:"Filter by status"}),c.jsx(Zn,{cmd:"todos show <id>",desc:"Show task details"}),c.jsx(Zn,{cmd:"todos start <id>",desc:"Start a task"}),c.jsx(Zn,{cmd:"todos done <id>",desc:"Complete a task"}),c.jsx(Zn,{cmd:"todos search 'query'",desc:"Full-text search"}),c.jsx(Zn,{cmd:"todos serve",desc:"Start web dashboard"}),c.jsx(Zn,{cmd:"todos interactive",desc:"Interactive TUI"}),c.jsx(Zn,{cmd:"todos sync --task-list <id>",desc:"Sync with Claude Code"})]})})]}),c.jsxs(St,{children:[c.jsx(Vt,{className:"pb-3",children:c.jsxs(Ut,{className:"text-sm flex items-center gap-2",children:[c.jsx(GN,{className:"size-4"})," MCP Server"]})}),c.jsxs(wt,{children:[c.jsx("p",{className:"text-sm text-muted-foreground mb-3",children:"Add to your Claude Code or AI agent config:"}),c.jsx("pre",{className:"rounded-lg bg-muted p-3 text-sm font-mono overflow-x-auto",children:`{
|
|
339
|
+
*/function bl(e,a){return e?NT(e)?x.createElement(e,a):e:null}function NT(e){return jT(e)||typeof e=="function"||MT(e)}function jT(e){return typeof e=="function"&&(()=>{const a=Object.getPrototypeOf(e);return a.prototype&&a.prototype.isReactComponent})()}function MT(e){return typeof e=="object"&&typeof e.$$typeof=="symbol"&&["react.memo","react.forward_ref"].includes(e.$$typeof.description)}function fu(e){const a={state:{},onStateChange:()=>{},renderFallbackValue:null,...e},[l]=x.useState(()=>({current:yT(a)})),[r,s]=x.useState(()=>l.current.initialState);return l.current.setOptions(u=>({...u,...e,state:{...r,...e.state},onStateChange:f=>{s(f),e.onStateChange==null||e.onStateChange(f)}})),l.current}const _T=i0("inline-flex items-center rounded-full border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",{variants:{variant:{default:"border-transparent bg-primary text-primary-foreground",secondary:"border-transparent bg-secondary text-secondary-foreground",destructive:"border-transparent bg-destructive text-white",outline:"text-foreground"}},defaultVariants:{variant:"default"}});function Ht({className:e,variant:a,...l}){return c.jsx("div",{className:Ae(_T({variant:a}),e),...l})}const It=x.forwardRef(({className:e,type:a,...l},r)=>c.jsx("input",{type:a,className:Ae("flex h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-base shadow-sm transition-colors file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50 md:text-sm dark:bg-input/30",e),ref:r,...l}));It.displayName="Input";const Fs=x.forwardRef(({className:e,...a},l)=>c.jsx("div",{className:"relative w-full overflow-auto",children:c.jsx("table",{ref:l,className:Ae("w-full caption-bottom text-sm",e),...a})}));Fs.displayName="Table";const Bs=x.forwardRef(({className:e,...a},l)=>c.jsx("thead",{ref:l,className:Ae("[&_tr]:border-b",e),...a}));Bs.displayName="TableHeader";const Vs=x.forwardRef(({className:e,...a},l)=>c.jsx("tbody",{ref:l,className:Ae("[&_tr:last-child]:border-0",e),...a}));Vs.displayName="TableBody";const RT=x.forwardRef(({className:e,...a},l)=>c.jsx("tfoot",{ref:l,className:Ae("border-t bg-muted/50 font-medium [&>tr]:last:border-b-0",e),...a}));RT.displayName="TableFooter";const mn=x.forwardRef(({className:e,...a},l)=>c.jsx("tr",{ref:l,className:Ae("border-b transition-colors hover:bg-muted/50 data-[state=selected]:bg-muted",e),...a}));mn.displayName="TableRow";const Us=x.forwardRef(({className:e,...a},l)=>c.jsx("th",{ref:l,className:Ae("h-10 px-2 text-left align-middle font-medium text-muted-foreground [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",e),...a}));Us.displayName="TableHead";const Pa=x.forwardRef(({className:e,...a},l)=>c.jsx("td",{ref:l,className:Ae("p-2 align-middle [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",e),...a}));Pa.displayName="TableCell";const ET=x.forwardRef(({className:e,...a},l)=>c.jsx("caption",{ref:l,className:Ae("mt-4 text-sm text-muted-foreground",e),...a}));ET.displayName="TableCaption";const gn=v2,hn=y2,Zt=x.forwardRef(({className:e,children:a,...l},r)=>c.jsxs(x2,{ref:r,className:Ae("flex h-9 w-full items-center justify-between gap-2 rounded-md border border-input bg-transparent px-3 py-2 text-sm shadow-sm ring-offset-background placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-ring disabled:cursor-not-allowed disabled:opacity-50 [&>span]:line-clamp-1",e),...l,children:[a,c.jsx(b2,{asChild:!0,children:c.jsx(n0,{className:"size-4 opacity-50"})})]}));Zt.displayName="SelectTrigger";const Jt=x.forwardRef(({className:e,children:a,position:l="popper",...r},s)=>c.jsx(S2,{children:c.jsx(w2,{ref:s,className:Ae("relative z-50 max-h-96 min-w-[8rem] overflow-hidden rounded-md border bg-popover text-popover-foreground shadow-md animate-in",l==="popper"&&"translate-y-1",e),position:l,...r,children:c.jsx(C2,{className:Ae("p-1",l==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"),children:a})})}));Jt.displayName="SelectContent";const Te=x.forwardRef(({className:e,children:a,...l},r)=>c.jsxs(N2,{ref:r,className:Ae("relative flex w-full cursor-default select-none items-center rounded-sm py-1.5 pl-2 pr-8 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",e),...l,children:[c.jsx("span",{className:"absolute right-2 flex h-3.5 w-3.5 items-center justify-center",children:c.jsx(M2,{children:c.jsx(t0,{className:"h-4 w-4"})})}),c.jsx(j2,{children:a})]}));Te.displayName="SelectItem";const DT=x.forwardRef(({className:e,...a},l)=>c.jsx(_2,{ref:l,className:Ae("-mx-1 my-1 h-px bg-muted",e),...a}));DT.displayName="SelectSeparator";const ra=g_,TT=h_,dw=x.forwardRef(({className:e,...a},l)=>c.jsx(p_,{ref:l,className:Ae("fixed inset-0 z-50 bg-black/50 data-[state=open]:animate-in data-[state=closed]:animate-out",e),...a}));dw.displayName="DialogOverlay";const In=x.forwardRef(({className:e,children:a,...l},r)=>c.jsxs(TT,{children:[c.jsx(dw,{}),c.jsxs(v_,{ref:r,className:Ae("fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out sm:rounded-lg",e),...l,children:[a,c.jsxs(b_,{className:"absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none",children:[c.jsx(Fm,{className:"h-4 w-4"}),c.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));In.displayName="DialogContent";const Ba=({className:e,...a})=>c.jsx("div",{className:Ae("flex flex-col space-y-1.5 text-center sm:text-left",e),...a}),Is=({className:e,...a})=>c.jsx("div",{className:Ae("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",e),...a}),sa=x.forwardRef(({className:e,...a},l)=>c.jsx(x_,{ref:l,className:Ae("text-lg font-semibold leading-none tracking-tight",e),...a}));sa.displayName="DialogTitle";const OT=x.forwardRef(({className:e,...a},l)=>c.jsx(y_,{ref:l,className:Ae("text-sm text-muted-foreground",e),...a}));OT.displayName="DialogDescription";function Cy(e){const a=Math.floor((Date.now()-new Date(e).getTime())/1e3);if(a<60)return`${a}s`;const l=Math.floor(a/60);if(l<60)return`${l}m`;const r=Math.floor(l/60);return r<24?`${r}h`:`${Math.floor(r/24)}d`}const Ny={critical:{border:"border-l-red-500",dot:"bg-red-500",label:"Critical"},high:{border:"border-l-orange-500",dot:"bg-orange-500",label:"High"},medium:{border:"border-l-blue-500",dot:"bg-blue-500",label:"Medium"},low:{border:"border-l-gray-400",dot:"bg-gray-400",label:"Low"}},jy={pending:{text:"text-yellow-500",bg:"bg-yellow-500"},in_progress:{text:"text-blue-500",bg:"bg-blue-500"},completed:{text:"text-green-500",bg:"bg-green-500"},failed:{text:"text-red-500",bg:"bg-red-500"},cancelled:{text:"text-gray-400",bg:"bg-gray-400"}},My=["bg-blue-500","bg-green-500","bg-purple-500","bg-orange-500","bg-pink-500","bg-teal-500","bg-indigo-500","bg-red-500"];function AT(e){let a=0;for(const l of e)a=(a<<5)-a+l.charCodeAt(0)|0;return My[Math.abs(a)%My.length]}function _y({name:e}){return c.jsx("span",{className:`inline-flex size-5 items-center justify-center rounded-full text-[10px] font-bold text-white ${AT(e)}`,title:e,children:e[0].toUpperCase()})}function kT(e,a){const l={critical:0,high:1,medium:2,low:3};return[...e].sort((r,s)=>a==="priority"?(l[r.priority]??4)-(l[s.priority]??4):a==="updated"?new Date(s.updated_at).getTime()-new Date(r.updated_at).getTime():a==="created"?new Date(s.created_at).getTime()-new Date(r.created_at).getTime():0)}function zT({task:e,projectMap:a,compact:l,onStart:r,onComplete:s,onDelete:u,onEdit:f,onSelect:m,onDragStart:h}){const[p,v]=x.useState(!1),y=e.project_id?a.get(e.project_id):null,w=Ny[e.priority]||Ny.medium,S=e.assigned_to||e.agent_id;return l?c.jsxs("div",{draggable:!0,onDragStart:N=>h(N,e),onClick:()=>m(e),className:`flex items-center gap-2 rounded-md border border-l-4 ${w.border} px-2 py-1.5 cursor-pointer hover:bg-accent/50 transition-colors`,children:[c.jsx("span",{className:`size-2 rounded-full shrink-0 ${w.dot}`}),c.jsx("span",{className:"text-sm truncate flex-1",children:e.title}),S&&c.jsx(_y,{name:S}),c.jsx("span",{className:"text-sm text-muted-foreground shrink-0",children:Cy(e.updated_at)})]}):c.jsxs("div",{draggable:!0,onDragStart:N=>h(N,e),onClick:()=>m(e),onMouseEnter:()=>v(!0),onMouseLeave:()=>v(!1),className:`rounded-lg border border-l-4 ${w.border} bg-card p-3 cursor-pointer hover:bg-accent/50 transition-colors relative`,children:[c.jsxs("div",{className:"flex items-start justify-between gap-2",children:[c.jsxs("div",{className:"min-w-0 flex-1",children:[c.jsxs("div",{className:"flex items-center gap-1.5 mb-1",children:[c.jsx("span",{className:`size-2 rounded-full shrink-0 ${w.dot}`,title:w.label}),c.jsx("code",{className:"text-sm text-muted-foreground",children:e.short_id||e.id.slice(0,8)})]}),c.jsx("p",{className:"text-sm font-medium leading-tight line-clamp-2",children:e.title}),p&&e.description&&c.jsx("p",{className:"mt-1 text-sm text-muted-foreground line-clamp-2",children:e.description})]}),c.jsx("div",{onClick:N=>N.stopPropagation(),className:"shrink-0",children:c.jsxs(jl,{children:[c.jsx(Ml,{asChild:!0,children:c.jsx(se,{variant:"ghost",size:"icon",className:"size-6",children:c.jsx(_s,{className:"size-3.5"})})}),c.jsxs(Fa,{align:"end",children:[c.jsxs(dt,{onClick:()=>f(e),children:[c.jsx(oo,{className:"size-3.5 mr-2"})," Edit"]}),e.status==="pending"&&c.jsxs(dt,{onClick:()=>r(e.id),children:[c.jsx(eo,{className:"size-3.5 mr-2"})," Start"]}),e.status==="in_progress"&&c.jsxs(dt,{onClick:()=>s(e.id),children:[c.jsx(Jr,{className:"size-3.5 mr-2"})," Complete"]}),c.jsx(mo,{}),c.jsxs(dt,{className:"text-red-500 focus:text-red-500",onClick:()=>u(e.id),children:[c.jsx(la,{className:"size-3.5 mr-2"})," Delete"]})]})]})})]}),c.jsxs("div",{className:"mt-2 flex items-center gap-2 text-sm text-muted-foreground",children:[y&&c.jsx(Ht,{variant:"outline",className:"text-sm px-1.5 py-0",children:y}),c.jsx("div",{className:"flex-1"}),c.jsxs("div",{onClick:N=>N.stopPropagation(),className:"flex items-center gap-0.5",children:[e.status==="pending"&&c.jsx(se,{variant:"ghost",size:"icon",className:"size-5",title:"Start",onClick:()=>r(e.id),children:c.jsx(eo,{className:"size-3 text-blue-500"})}),e.status==="in_progress"&&c.jsx(se,{variant:"ghost",size:"icon",className:"size-5",title:"Complete",onClick:()=>s(e.id),children:c.jsx(Jr,{className:"size-3 text-green-500"})})]}),S&&c.jsx(_y,{name:S}),c.jsx("span",{children:Cy(e.updated_at)})]})]})}function Ry({status:e,label:a,tasks:l,collapsed:r,onToggleCollapse:s,sortField:u,onSortChange:f,showLimit:m,onShowMore:h,compact:p,projectMap:v,onStart:y,onComplete:w,onDelete:S,onEdit:N,onSelect:C,onDragStart:M,onDrop:T,onDragOver:D}){const _=jy[e]||jy.pending,O=kT(l,u),H=O.slice(0,m),E=O.length-H.length;return c.jsxs("div",{className:"flex flex-col",onDragOver:D,onDrop:()=>T(e),children:[c.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[c.jsx(se,{variant:"ghost",size:"icon",className:"size-5",onClick:s,children:r?c.jsx(ro,{className:"size-3.5"}):c.jsx(n0,{className:"size-3.5"})}),c.jsx("span",{className:`size-2.5 rounded-full ${_.bg}`}),c.jsx("h3",{className:`text-sm font-semibold ${_.text}`,children:a}),c.jsx(Ht,{variant:"secondary",className:"text-sm px-1.5 py-0 ml-auto",children:l.length}),!r&&c.jsx("div",{onClick:k=>k.stopPropagation(),children:c.jsxs(jl,{children:[c.jsx(Ml,{asChild:!0,children:c.jsx(se,{variant:"ghost",size:"icon",className:"size-5",children:c.jsx(dn,{className:"size-3"})})}),c.jsxs(Fa,{align:"end",children:[c.jsxs(dt,{onClick:()=>f("priority"),children:[u==="priority"&&"• ","Priority"]}),c.jsxs(dt,{onClick:()=>f("updated"),children:[u==="updated"&&"• ","Updated"]}),c.jsxs(dt,{onClick:()=>f("created"),children:[u==="created"&&"• ","Created"]})]})]})})]}),!r&&c.jsxs("div",{className:"space-y-2 min-h-[100px]",children:[H.length===0?c.jsx("div",{className:"rounded-lg border border-dashed p-4 text-center text-sm text-muted-foreground",children:"No tasks"}):H.map(k=>c.jsx(zT,{task:k,projectMap:v,compact:p,onStart:y,onComplete:w,onDelete:S,onEdit:N,onSelect:C,onDragStart:M},k.id)),E>0&&c.jsxs(se,{variant:"ghost",size:"sm",className:"w-full text-sm text-muted-foreground",onClick:h,children:["Show ",Math.min(E,20)," more (",E," remaining)"]})]}),r&&c.jsxs("div",{className:"text-sm text-muted-foreground text-center py-2 border border-dashed rounded-lg",children:[l.length," task(s)"]})]})}const Ey=[{key:"pending",label:"Pending"},{key:"in_progress",label:"In Progress"},{key:"completed",label:"Completed"},{key:"failed",label:"Failed"},{key:"cancelled",label:"Cancelled"}];function PT({data:e,projectMap:a,onStart:l,onComplete:r,onDelete:s,onEdit:u,onSelect:f,onStatusChange:m}){const[h,p]=x.useState({completed:!0,cancelled:!0}),[v,y]=x.useState({}),[w,S]=x.useState({}),[N,C]=x.useState(!1),[M,T]=x.useState(!1),[D,_]=x.useState("all"),[O,H]=x.useState(!1),[E,k]=x.useState(null),[F,K]=x.useState(null),W=15,Z=x.useMemo(()=>D==="all"?e:e.filter(G=>G.priority===D),[e,D]),re=M?Ey:Ey.filter(G=>G.key!=="cancelled");function ne(G,A){k(A),G.dataTransfer.effectAllowed="move",G.dataTransfer.setData("text/plain",A.id)}function ue(G){G.preventDefault(),G.dataTransfer.dropEffect="move"}function me(G){if(!E||E.status===G){k(null),K(null);return}m?m(E.id,G):G==="in_progress"&&E.status==="pending"?l(E.id):G==="completed"&&E.status==="in_progress"&&r(E.id),k(null),K(null)}function z(G){p(A=>({...A,[G]:!A[G]}))}function Y(G,A){y(R=>({...R,[G]:A}))}function Q(G){S(A=>({...A,[G]:(A[G]||W)+20}))}if(O){const A=[...new Set(Z.map(R=>R.project_id||"__none__"))].map(R=>({id:R,name:R==="__none__"?"No Project":a.get(R)||R.slice(0,8),tasks:Z.filter(V=>(V.project_id||"__none__")===R)}));return A.sort((R,V)=>V.tasks.length-R.tasks.length),c.jsxs("div",{className:"space-y-6",children:[c.jsx(Dy,{compact:N,onCompactChange:C,showCancelled:M,onShowCancelledChange:T,priorityFilter:D,onPriorityFilterChange:_,groupByProject:O,onGroupByProjectChange:H}),A.map(R=>c.jsxs("div",{children:[c.jsxs("h3",{className:"text-sm font-semibold mb-3 flex items-center gap-2",children:[c.jsx("span",{className:"size-3 rounded bg-muted"}),R.name,c.jsx(Ht,{variant:"secondary",className:"text-sm",children:R.tasks.length})]}),c.jsx("div",{className:`grid gap-4 ${re.length<=4?"grid-cols-4":"grid-cols-5"}`,children:re.map(V=>{const te=`${R.id}_${V.key}`;return c.jsx(Ry,{status:V.key,label:V.label,tasks:R.tasks.filter(ae=>ae.status===V.key),collapsed:!!h[te],onToggleCollapse:()=>p(ae=>({...ae,[te]:!ae[te]})),sortField:v[te]||"priority",onSortChange:ae=>Y(te,ae),showLimit:w[te]||W,onShowMore:()=>Q(te),compact:N,projectMap:a,onStart:l,onComplete:r,onDelete:s,onEdit:u,onSelect:f,onDragStart:ne,onDrop:me,onDragOver:ue},te)})})]},R.id))]})}return c.jsxs("div",{className:"space-y-4",children:[c.jsx(Dy,{compact:N,onCompactChange:C,showCancelled:M,onShowCancelledChange:T,priorityFilter:D,onPriorityFilterChange:_,groupByProject:O,onGroupByProjectChange:H}),c.jsx("div",{className:`grid gap-4 ${re.length<=4?"grid-cols-4":"grid-cols-5"}`,children:re.map(G=>c.jsx(Ry,{status:G.key,label:G.label,tasks:Z.filter(A=>A.status===G.key),collapsed:!!h[G.key],onToggleCollapse:()=>z(G.key),sortField:v[G.key]||"priority",onSortChange:A=>Y(G.key,A),showLimit:w[G.key]||W,onShowMore:()=>Q(G.key),compact:N,projectMap:a,onStart:l,onComplete:r,onDelete:s,onEdit:u,onSelect:f,onDragStart:ne,onDrop:me,onDragOver:ue},G.key))})]})}function Dy({compact:e,onCompactChange:a,showCancelled:l,onShowCancelledChange:r,priorityFilter:s,onPriorityFilterChange:u,groupByProject:f,onGroupByProjectChange:m}){return c.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[c.jsxs(gn,{value:s,onValueChange:u,children:[c.jsx(Zt,{className:"w-[130px] h-8",children:c.jsx(hn,{placeholder:"Priority"})}),c.jsxs(Jt,{children:[c.jsx(Te,{value:"all",children:"All Priorities"}),c.jsx(Te,{value:"critical",children:"Critical"}),c.jsx(Te,{value:"high",children:"High"}),c.jsx(Te,{value:"medium",children:"Medium"}),c.jsx(Te,{value:"low",children:"Low"})]})]}),c.jsx(se,{variant:f?"secondary":"outline",size:"sm",className:"h-8 text-sm",onClick:()=>m(!f),children:"Group by Project"}),c.jsx(se,{variant:l?"secondary":"outline",size:"sm",className:"h-8 text-sm",onClick:()=>r(!l),children:"Cancelled"}),c.jsx(se,{variant:e?"secondary":"outline",size:"sm",className:"h-8 text-sm ml-auto",onClick:()=>a(!e),children:e?"Detailed":"Compact"})]})}function HT(e){let a=e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">");return a=a.replace(/```(\w*)\n([\s\S]*?)```/g,(l,r,s)=>`<pre class="my-2 rounded bg-muted p-3 text-xs font-mono overflow-x-auto"><code>${s.trim()}</code></pre>`),a=a.replace(/`([^`]+)`/g,'<code class="rounded bg-muted px-1 py-0.5 text-xs font-mono">$1</code>'),a=a.replace(/\*\*([^*]+)\*\*/g,"<strong>$1</strong>"),a=a.replace(new RegExp("(?<!\\*)\\*([^*]+)\\*(?!\\*)","g"),"<em>$1</em>"),a=a.replace(/^### (.+)$/gm,'<h3 class="text-sm font-semibold mt-3 mb-1">$1</h3>'),a=a.replace(/^## (.+)$/gm,'<h2 class="text-base font-semibold mt-4 mb-1">$1</h2>'),a=a.replace(/^- (.+)$/gm,'<li class="ml-4 list-disc">$1</li>'),a=a.replace(/((?:<li[^>]*>.*<\/li>\n?)+)/g,'<ul class="my-1 space-y-0.5 text-sm">$1</ul>'),a=a.replace(/^\d+\. (.+)$/gm,'<li class="ml-4 list-decimal">$1</li>'),a=a.replace(/\n\n/g,'</p><p class="my-1.5">'),a=a.replace(new RegExp("(?<!<\\/pre>|<\\/li>|<\\/ul>|<\\/h[23]>)\\n(?!<)","g"),"<br>"),`<p class="my-1.5">${a}</p>`}function LT({content:e}){return c.jsx("div",{className:"prose prose-sm dark:prose-invert max-w-none text-sm text-foreground leading-relaxed",dangerouslySetInnerHTML:{__html:HT(e)}})}function fw({status:e}){const l={pending:{label:"Pending",variant:"outline"},in_progress:{label:"In Progress",variant:"default"},completed:{label:"Completed",variant:"secondary"},failed:{label:"Failed",variant:"destructive"},cancelled:{label:"Cancelled",variant:"outline"}}[e]||{label:e,variant:"outline"};return c.jsx(Ht,{variant:l.variant,children:l.label})}function mw({priority:e}){const a={critical:"bg-red-100 text-red-800 dark:bg-red-900 dark:text-red-200",high:"bg-orange-100 text-orange-800 dark:bg-orange-900 dark:text-orange-200",medium:"bg-blue-100 text-blue-800 dark:bg-blue-900 dark:text-blue-200",low:"bg-gray-100 text-gray-700 dark:bg-gray-800 dark:text-gray-300"};return c.jsx("span",{className:`inline-flex items-center rounded-full px-2 py-0.5 text-xs font-medium ${a[e]||""}`,children:e})}function Dc(e){const a=Math.floor((Date.now()-new Date(e).getTime())/1e3);if(a<60)return`${a}s ago`;const l=Math.floor(a/60);if(l<60)return`${l}m ago`;const r=Math.floor(l/60);return r<24?`${r}h ago`:`${Math.floor(r/24)}d ago`}function FT(e){return e<6e4?`${Math.round(e/1e3)}s`:e<36e5?`${Math.round(e/6e4)}m`:`${(e/36e5).toFixed(1)}h`}function gw(e){return e?new Date(e).getTime()<Date.now():!1}function BT({task:e,projectName:a,onBack:l,onStart:r,onComplete:s,onDelete:u,onEdit:f}){const m=new Date(e.created_at).getTime(),p=((e.completed_at?new Date(e.completed_at).getTime():null)||Date.now())-m;return c.jsx("div",{className:"space-y-4",children:c.jsxs(St,{children:[c.jsx(Vt,{className:"pb-3",children:c.jsxs("div",{className:"flex items-start justify-between gap-4",children:[c.jsxs("div",{className:"space-y-1.5 min-w-0 flex-1",children:[c.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[c.jsx("code",{className:"text-xs text-muted-foreground bg-muted px-1.5 py-0.5 rounded",children:e.short_id||e.id.slice(0,8)}),c.jsx(fw,{status:e.status}),c.jsx(mw,{priority:e.priority}),e.due_at&&c.jsxs("span",{className:`inline-flex items-center gap-1 text-xs ${gw(e.due_at)&&e.status!=="completed"?"text-red-500 font-medium":"text-muted-foreground"}`,children:[c.jsx(Jy,{className:"size-3"}),"Due ",new Date(e.due_at).toLocaleDateString()]})]}),c.jsx(Ut,{className:"text-lg leading-tight",children:e.title})]}),c.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[c.jsxs(se,{variant:"outline",size:"sm",onClick:()=>f(e),children:[c.jsx(oo,{className:"size-3.5"})," Edit"]}),e.status==="pending"&&c.jsxs(se,{variant:"outline",size:"sm",onClick:()=>r(e.id),children:[c.jsx(eo,{className:"size-3.5"})," Start"]}),e.status==="in_progress"&&c.jsxs(se,{variant:"outline",size:"sm",onClick:()=>s(e.id),children:[c.jsx(Jr,{className:"size-3.5"})," Complete"]}),c.jsxs(se,{variant:"outline",size:"sm",className:"text-red-500 hover:text-red-600",onClick:()=>{u(e.id),l()},children:[c.jsx(Fm,{className:"size-3.5"})," Delete"]})]})]})}),c.jsxs(wt,{className:"space-y-4",children:[e.description&&c.jsx("div",{className:"rounded-lg border bg-muted/30 p-4",children:c.jsx(LT,{content:e.description})}),c.jsx("div",{className:"flex flex-wrap gap-3",children:c.jsxs("div",{className:"flex items-center gap-1.5 rounded-lg border px-3 py-1.5 text-xs",children:[c.jsx(a0,{className:"size-3 text-muted-foreground"}),c.jsx("span",{className:"text-muted-foreground",children:"Total:"}),c.jsx("span",{className:"font-medium",children:FT(p)})]})}),c.jsxs("div",{className:"grid grid-cols-2 gap-x-8 gap-y-2 text-sm sm:grid-cols-3",children:[c.jsxs("div",{children:[c.jsx("span",{className:"text-muted-foreground",children:"Project:"})," ",c.jsx("span",{className:"font-medium",children:a||"None"})]}),e.task_list_id&&c.jsxs("div",{children:[c.jsx("span",{className:"text-muted-foreground",children:"Task List:"})," ",c.jsx("span",{className:"font-medium",children:e.task_list_id})]}),e.assigned_to&&c.jsxs("div",{children:[c.jsx("span",{className:"text-muted-foreground",children:"Assigned to:"})," ",c.jsx("span",{className:"font-medium",children:e.assigned_to})]}),e.agent_id&&c.jsxs("div",{children:[c.jsx("span",{className:"text-muted-foreground",children:"Agent:"})," ",c.jsx("span",{className:"font-medium",children:e.agent_id})]}),e.locked_by&&c.jsxs("div",{children:[c.jsx("span",{className:"text-muted-foreground",children:"Locked by:"})," ",c.jsx("span",{className:"font-medium",children:e.locked_by})]}),c.jsxs("div",{children:[c.jsx("span",{className:"text-muted-foreground",children:"Created:"})," ",c.jsx("span",{children:Dc(e.created_at)})]}),c.jsxs("div",{children:[c.jsx("span",{className:"text-muted-foreground",children:"Updated:"})," ",c.jsx("span",{children:Dc(e.updated_at)})]}),e.completed_at&&c.jsxs("div",{children:[c.jsx("span",{className:"text-muted-foreground",children:"Completed:"})," ",c.jsx("span",{children:Dc(e.completed_at)})]}),c.jsxs("div",{children:[c.jsx("span",{className:"text-muted-foreground",children:"Version:"})," ",c.jsx("span",{children:e.version})]})]}),e.tags.length>0&&c.jsx("div",{className:"flex flex-wrap gap-1.5",children:e.tags.map(v=>c.jsx(Ht,{variant:"outline",className:"text-xs",children:v},v))})]})]})})}const VT=[{id:"select",header:({table:e})=>c.jsx("input",{type:"checkbox",className:"rounded",checked:e.getIsAllPageRowsSelected(),onChange:a=>e.toggleAllPageRowsSelected(a.target.checked)}),cell:({row:e})=>c.jsx("input",{type:"checkbox",className:"rounded",checked:e.getIsSelected(),onChange:a=>{a.stopPropagation(),e.toggleSelected(a.target.checked)},onClick:a=>a.stopPropagation()}),size:30,enableSorting:!1},{accessorKey:"short_id",header:"ID",cell:({row:e})=>c.jsx("code",{className:"text-xs text-muted-foreground",children:e.original.short_id||e.original.id.slice(0,8)}),size:100},{accessorKey:"title",header:({column:e})=>c.jsxs(se,{variant:"ghost",size:"sm",className:"-ml-3",onClick:()=>e.toggleSorting(),children:["Title ",c.jsx(dn,{className:"size-3"})]}),cell:({row:e})=>c.jsxs("div",{className:"max-w-[400px]",children:[c.jsx("div",{className:"font-medium truncate",children:e.original.title}),e.original.due_at&&gw(e.original.due_at)&&e.original.status!=="completed"&&c.jsx("span",{className:"text-[10px] text-red-500 font-medium",children:"Overdue"})]})},{accessorKey:"status",header:"Status",cell:({row:e})=>c.jsx(fw,{status:e.original.status}),filterFn:(e,a,l)=>!l||l==="all"?!0:e.original.status===l},{accessorKey:"priority",header:({column:e})=>c.jsxs(se,{variant:"ghost",size:"sm",className:"-ml-3",onClick:()=>e.toggleSorting(),children:["Priority ",c.jsx(dn,{className:"size-3"})]}),cell:({row:e})=>c.jsx(mw,{priority:e.original.priority}),sortingFn:(e,a)=>{const l={critical:0,high:1,medium:2,low:3};return(l[e.original.priority]??4)-(l[a.original.priority]??4)}},{accessorKey:"assigned_to",header:"Assigned",cell:({row:e})=>c.jsx("span",{className:"text-xs text-muted-foreground",children:e.original.assigned_to||e.original.agent_id||"—"})},{accessorKey:"updated_at",header:({column:e})=>c.jsxs(se,{variant:"ghost",size:"sm",className:"-ml-3",onClick:()=>e.toggleSorting(),children:["Updated ",c.jsx(dn,{className:"size-3"})]}),cell:({row:e})=>c.jsx("span",{className:"text-xs text-muted-foreground whitespace-nowrap",children:Dc(e.original.updated_at)})},{id:"actions",header:"",cell:({row:e,table:a})=>{const l=a.options.meta,r=e.original;return c.jsx("div",{onClick:s=>s.stopPropagation(),children:c.jsxs(jl,{children:[c.jsx(Ml,{asChild:!0,children:c.jsx(se,{variant:"ghost",size:"icon",className:"size-7",children:c.jsx(_s,{className:"size-4"})})}),c.jsxs(Fa,{align:"end",children:[c.jsxs(dt,{onClick:()=>l==null?void 0:l.onEdit(r),children:[c.jsx(oo,{className:"size-3.5 mr-2"})," Edit"]}),r.status==="pending"&&c.jsxs(dt,{onClick:()=>l==null?void 0:l.onStart(r.id),children:[c.jsx(eo,{className:"size-3.5 mr-2"})," Start"]}),r.status==="in_progress"&&c.jsxs(dt,{onClick:()=>l==null?void 0:l.onComplete(r.id),children:[c.jsx(Jr,{className:"size-3.5 mr-2"})," Complete"]}),c.jsx(mo,{}),c.jsxs(dt,{className:"text-red-500 focus:text-red-500",onClick:()=>l==null?void 0:l.onConfirmDelete(r.id),children:[c.jsx(la,{className:"size-3.5 mr-2"})," Delete"]})]})]})})},size:50}];function UT({data:e,projectMap:a,projects:l,onStart:r,onComplete:s,onDelete:u,onEdit:f,onBulkAction:m,onNewTask:h}){var G;const[p,v]=x.useState([]),[y,w]=x.useState([]),[S,N]=x.useState(""),[C,M]=x.useState("table"),[T,D]=x.useState(null),[_,O]=x.useState(null),[H,E]=x.useState({}),[k,F]=x.useState("all"),K=x.useRef(null);x.useEffect(()=>{function A(R){var V,te,ae;if(R.key==="/"&&!R.ctrlKey&&!R.metaKey){const oe=(V=R.target)==null?void 0:V.tagName;oe!=="INPUT"&&oe!=="TEXTAREA"&&(R.preventDefault(),(te=K.current)==null||te.focus())}R.key==="Escape"&&(T?D(null):(N(""),(ae=K.current)==null||ae.blur()))}return document.addEventListener("keydown",A),()=>document.removeEventListener("keydown",A)},[T]),x.useEffect(()=>{if(T){const A=e.find(R=>R.id===T.id);D(A||null)}},[e,T==null?void 0:T.id]);const W=x.useMemo(()=>k==="all"?e:k==="none"?e.filter(A=>!A.project_id):e.filter(A=>A.project_id===k),[e,k]),Z=x.useMemo(()=>{const A={all:W.length};for(const R of W)A[R.status]=(A[R.status]||0)+1;return A},[W]),re=x.useMemo(()=>{const A=[...VT];return A.splice(4,0,{accessorKey:"project_id",header:"Project",cell:({row:R})=>{const V=R.original.project_id;return V?c.jsx("span",{className:"text-xs text-muted-foreground truncate max-w-[120px] block",children:a.get(V)||V.slice(0,8)}):c.jsx("span",{className:"text-xs text-muted-foreground",children:"—"})}}),A},[a]),ne=fu({data:W,columns:re,state:{sorting:p,columnFilters:y,globalFilter:S,rowSelection:H},onSortingChange:v,onColumnFiltersChange:w,onGlobalFilterChange:N,onRowSelectionChange:E,getCoreRowModel:iu(),getSortedRowModel:du(),getFilteredRowModel:cu(),getPaginationRowModel:uu(),enableRowSelection:!0,getRowId:A=>A.id,initialState:{pagination:{pageSize:15}},meta:{onStart:r,onComplete:s,onDelete:u,onConfirmDelete:Y,onEdit:f}}),ue=((G=ne.getColumn("status"))==null?void 0:G.getFilterValue())||"all",me=Object.keys(H).filter(A=>H[A]),z=me.length>0;function Y(A){O(A)}function Q(){_&&(u(_),O(null),(T==null?void 0:T.id)===_&&D(null))}return c.jsxs(c.Fragment,{children:[c.jsxs("div",{className:"space-y-4",children:[c.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[h&&c.jsxs(se,{size:"sm",className:"h-9",onClick:h,title:"Press n",children:[c.jsx(hl,{className:"size-4"})," New Task"]}),c.jsxs("div",{className:"relative flex-1 min-w-[180px] max-w-xs",children:[c.jsx(Ic,{className:"absolute left-2.5 top-2.5 size-4 text-muted-foreground"}),c.jsx(It,{ref:K,placeholder:"Search... (/)",value:S,onChange:A=>N(A.target.value),className:"pl-8 h-9"})]}),c.jsxs(gn,{value:k,onValueChange:F,children:[c.jsx(Zt,{className:"w-[140px] h-9",children:c.jsx(hn,{placeholder:"All Projects"})}),c.jsxs(Jt,{children:[c.jsx(Te,{value:"all",children:"All Projects"}),c.jsx(Te,{value:"none",children:"No Project"}),l.map(A=>c.jsx(Te,{value:A.id,children:A.name},A.id))]})]}),c.jsxs(gn,{value:ue,onValueChange:A=>{var R;return(R=ne.getColumn("status"))==null?void 0:R.setFilterValue(A==="all"?void 0:A)},children:[c.jsx(Zt,{className:"w-[140px] h-9",children:c.jsx(hn,{placeholder:"All Statuses"})}),c.jsx(Jt,{children:["all","pending","in_progress","completed","failed","cancelled"].map(A=>{const R=Z[A]||0,V=A==="all"?"All":A==="in_progress"?"In Progress":A.charAt(0).toUpperCase()+A.slice(1);return c.jsxs(Te,{value:A,children:[V," (",R,")"]},A)})})]}),c.jsxs(jl,{children:[c.jsx(Ml,{asChild:!0,children:c.jsx(se,{variant:"outline",size:"icon",className:"size-9 shrink-0",title:"Export",children:c.jsx(PN,{className:"size-4"})})}),c.jsxs(Fa,{align:"end",children:[c.jsx(dt,{onClick:()=>window.open("/api/tasks/export?format=csv","_blank"),children:"Export CSV"}),c.jsx(dt,{onClick:()=>window.open("/api/tasks/export?format=json","_blank"),children:"Export JSON"})]})]}),c.jsxs("div",{className:"flex items-center border rounded-md",children:[c.jsx(se,{variant:C==="table"?"secondary":"ghost",size:"icon",className:"size-8 rounded-r-none",onClick:()=>M("table"),title:"Table view",children:c.jsx(BN,{className:"size-4"})}),c.jsx(se,{variant:C==="kanban"?"secondary":"ghost",size:"icon",className:"size-8 rounded-l-none",onClick:()=>M("kanban"),title:"Kanban view",children:c.jsx(FN,{className:"size-4"})})]})]}),C==="kanban"&&c.jsx(PT,{data:ne.getFilteredRowModel().rows.map(A=>A.original),projectMap:a,onStart:r,onComplete:s,onDelete:Y,onEdit:f,onSelect:D,onStatusChange:async(A,R)=>{try{const V=e.find(te=>te.id===A);if(!V)return;R==="in_progress"&&V.status==="pending"?r(A):R==="completed"&&V.status==="in_progress"?s(A):(await fetch(`/api/tasks/${A}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({status:R})}),r("__reload__"))}catch{}}}),C==="table"&&c.jsx("div",{className:"rounded-md border",children:c.jsxs(Fs,{children:[c.jsx(Bs,{children:ne.getHeaderGroups().map(A=>c.jsx(mn,{children:A.headers.map(R=>c.jsx(Us,{children:R.isPlaceholder?null:bl(R.column.columnDef.header,R.getContext())},R.id))},A.id))}),c.jsx(Vs,{children:ne.getRowModel().rows.length?ne.getRowModel().rows.map(A=>c.jsx(mn,{className:"cursor-pointer","data-state":A.getIsSelected()?"selected":void 0,onClick:()=>D(A.original),children:A.getVisibleCells().map(R=>c.jsx(Pa,{children:bl(R.column.columnDef.cell,R.getContext())},R.id))},A.id)):c.jsx(mn,{children:c.jsx(Pa,{colSpan:re.length,className:"h-24 text-center text-muted-foreground",children:"No tasks found."})})})]})}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("p",{className:"text-sm text-muted-foreground",children:[ne.getFilteredRowModel().rows.length," task(s)"]}),c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx(se,{variant:"outline",size:"sm",onClick:()=>ne.previousPage(),disabled:!ne.getCanPreviousPage(),children:c.jsx(Ms,{className:"size-4"})}),c.jsxs("span",{className:"text-sm text-muted-foreground",children:["Page ",ne.getState().pagination.pageIndex+1," of ",ne.getPageCount()]}),c.jsx(se,{variant:"outline",size:"sm",onClick:()=>ne.nextPage(),disabled:!ne.getCanNextPage(),children:c.jsx(ro,{className:"size-4"})})]})]}),z&&c.jsxs("div",{className:"fixed bottom-6 left-1/2 -translate-x-1/2 z-50 flex items-center gap-3 rounded-xl border bg-background px-5 py-3 shadow-xl",children:[c.jsxs("span",{className:"text-sm font-medium",children:[me.length," selected"]}),c.jsx("div",{className:"h-4 w-px bg-border"}),c.jsxs(se,{variant:"outline",size:"sm",onClick:()=>{m(me,"start"),E({})},children:[c.jsx(eo,{className:"size-4"})," Start"]}),c.jsxs(se,{variant:"outline",size:"sm",onClick:()=>{m(me,"complete"),E({})},children:[c.jsx(Jr,{className:"size-4"})," Complete"]}),c.jsxs(se,{variant:"outline",size:"sm",className:"text-red-500",onClick:()=>{m(me,"delete"),E({})},children:[c.jsx(la,{className:"size-4"})," Delete"]}),c.jsx("div",{className:"h-4 w-px bg-border"}),c.jsx(se,{variant:"ghost",size:"sm",onClick:()=>E({}),children:"Clear"})]})]}),c.jsx(ra,{open:!!T,onOpenChange:A=>{A||D(null)},children:c.jsx(In,{className:"max-w-2xl max-h-[85vh] overflow-y-auto",children:T&&c.jsx(BT,{task:T,projectName:T.project_id&&a.get(T.project_id)||null,onBack:()=>D(null),onStart:r,onComplete:s,onDelete:A=>{D(null),Y(A)},onEdit:f})})}),c.jsx(ra,{open:!!_,onOpenChange:A=>{A||O(null)},children:c.jsxs(In,{className:"max-w-sm",children:[c.jsx(Ba,{children:c.jsx(sa,{children:"Delete Task"})}),c.jsx("p",{className:"text-sm text-muted-foreground",children:"Are you sure you want to delete this task? This action cannot be undone."}),c.jsxs("div",{className:"flex justify-end gap-2 pt-2",children:[c.jsx(se,{variant:"outline",onClick:()=>O(null),children:"Cancel"}),c.jsxs(se,{variant:"destructive",onClick:Q,children:[c.jsx(la,{className:"size-4"})," Delete"]})]})]})})]})}function hw(e){const a=Math.floor((Date.now()-new Date(e).getTime())/1e3);if(a<60)return`${a}s ago`;const l=Math.floor(a/60);if(l<60)return`${l}m ago`;const r=Math.floor(l/60);return r<24?`${r}h ago`:`${Math.floor(r/24)}d ago`}function Ty(e){return{pending:"text-yellow-500",in_progress:"text-blue-500",completed:"text-green-500",failed:"text-red-500",cancelled:"text-muted-foreground"}[e]||"text-foreground"}function Oy({open:e,onOpenChange:a,onCreated:l}){const[r,s]=x.useState(""),[u,f]=x.useState(""),[m,h]=x.useState(""),[p,v]=x.useState(!1),[y,w]=x.useState(null);async function S(N){if(N.preventDefault(),!(!r.trim()||!u.trim())){v(!0),w(null);try{const M=await(await fetch("/api/projects",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:r.trim(),path:u.trim(),description:m.trim()||void 0})})).json();M.error?w(M.error):(s(""),f(""),h(""),a(!1),l())}catch{w("Failed to create project")}finally{v(!1)}}}return c.jsx(ra,{open:e,onOpenChange:a,children:c.jsxs(In,{children:[c.jsx(Ba,{children:c.jsx(sa,{children:"New Project"})}),c.jsxs("form",{onSubmit:S,className:"space-y-4",children:[c.jsxs("div",{className:"space-y-1.5",children:[c.jsx("label",{className:"text-sm font-medium",children:"Name"}),c.jsx(It,{value:r,onChange:N=>s(N.target.value),placeholder:"Project name",className:"h-9",autoFocus:!0})]}),c.jsxs("div",{className:"space-y-1.5",children:[c.jsx("label",{className:"text-sm font-medium",children:"Path"}),c.jsx(It,{value:u,onChange:N=>f(N.target.value),placeholder:"/path/to/project",className:"h-9"})]}),c.jsxs("div",{className:"space-y-1.5",children:[c.jsx("label",{className:"text-sm font-medium",children:"Description"}),c.jsx(It,{value:m,onChange:N=>h(N.target.value),placeholder:"Optional description",className:"h-9"})]}),y&&c.jsx("p",{className:"text-sm text-red-500",children:y}),c.jsxs(Is,{children:[c.jsx(se,{type:"button",variant:"outline",onClick:()=>a(!1),children:"Cancel"}),c.jsx(se,{type:"submit",disabled:!r.trim()||!u.trim()||p,children:p?"Creating...":"Create"})]})]})]})})}function IT({project:e,onBack:a}){const[l,r]=x.useState([]),[s,u]=x.useState(!0);x.useEffect(()=>{fetch(`/api/tasks?project_id=${e.id}`).then(m=>m.json()).then(r).finally(()=>u(!1))},[e.id]);const f={};for(const m of l)f[m.status]=(f[m.status]||0)+1;return c.jsxs("div",{className:"space-y-4",children:[c.jsxs(se,{variant:"ghost",size:"sm",onClick:a,className:"gap-1.5 -ml-2",children:[c.jsx(TN,{className:"size-3.5"})," Back to projects"]}),c.jsxs(St,{className:"shadow-none",children:[c.jsxs(Vt,{children:[c.jsxs("div",{className:"flex items-start justify-between",children:[c.jsxs("div",{children:[c.jsxs(Ut,{className:"text-lg flex items-center gap-2",children:[c.jsx(Uc,{className:"size-5 text-purple-500"}),e.name]}),c.jsx("code",{className:"text-sm text-muted-foreground mt-1 block",children:e.path})]}),e.task_prefix&&c.jsx(Ht,{variant:"outline",children:e.task_prefix})]}),e.description&&c.jsx("p",{className:"text-sm text-muted-foreground mt-2",children:e.description})]}),c.jsxs(wt,{className:"space-y-4",children:[c.jsx("div",{className:"grid grid-cols-5 gap-2 text-center",children:["pending","in_progress","completed","failed","cancelled"].map(m=>c.jsxs("div",{className:"rounded-lg border p-2",children:[c.jsx("div",{className:`text-xl font-bold ${Ty(m)}`,children:f[m]||0}),c.jsx("div",{className:"text-sm text-muted-foreground capitalize",children:m==="in_progress"?"Active":m})]},m))}),c.jsxs("div",{children:[c.jsxs("h3",{className:"text-sm font-medium mb-2",children:["Tasks (",l.length,")"]}),s?c.jsx("p",{className:"text-sm text-muted-foreground",children:"Loading..."}):l.length===0?c.jsx("p",{className:"text-sm text-muted-foreground",children:"No tasks in this project."}):c.jsx("div",{className:"space-y-1 max-h-[400px] overflow-y-auto",children:l.map(m=>c.jsxs("div",{className:"flex items-center gap-2 rounded-md px-2 py-1.5 text-sm hover:bg-muted/50",children:[c.jsx("span",{className:`size-2 rounded-full shrink-0 ${Ty(m.status).replace("text-","bg-")}`}),c.jsx("code",{className:"text-sm text-muted-foreground shrink-0",children:m.short_id||m.id.slice(0,8)}),c.jsx("span",{className:"truncate flex-1",children:m.title}),c.jsx("span",{className:"text-sm text-muted-foreground shrink-0",children:m.assigned_to||"—"}),c.jsx("span",{className:"text-sm text-muted-foreground shrink-0",children:hw(m.updated_at)})]},m.id))})]})]})]})]})}function GT(){return[{id:"select",header:({table:e})=>c.jsx("input",{type:"checkbox",className:"rounded",checked:e.getIsAllPageRowsSelected(),onChange:a=>e.toggleAllPageRowsSelected(a.target.checked)}),cell:({row:e})=>c.jsx("input",{type:"checkbox",className:"rounded",checked:e.getIsSelected(),onChange:a=>{a.stopPropagation(),e.toggleSelected(a.target.checked)},onClick:a=>a.stopPropagation()}),size:30,enableSorting:!1},{accessorKey:"name",header:({column:e})=>c.jsxs(se,{variant:"ghost",size:"sm",className:"-ml-3",onClick:()=>e.toggleSorting(),children:["Name ",c.jsx(dn,{className:"size-3"})]}),cell:({row:e})=>c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx(Uc,{className:"size-4 text-purple-500 shrink-0"}),c.jsx("span",{className:"font-medium text-sm",children:e.original.name})]})},{accessorKey:"path",header:"Path",cell:({row:e})=>c.jsx("code",{className:"text-sm text-muted-foreground truncate max-w-[300px] block",children:e.original.path})},{accessorKey:"task_prefix",header:"Prefix",cell:({row:e})=>e.original.task_prefix?c.jsx(Ht,{variant:"outline",className:"text-sm",children:e.original.task_prefix}):c.jsx("span",{className:"text-sm text-muted-foreground",children:"—"})},{accessorKey:"task_counter",header:({column:e})=>c.jsxs(se,{variant:"ghost",size:"sm",className:"-ml-3",onClick:()=>e.toggleSorting(),children:["Tasks ",c.jsx(dn,{className:"size-3"})]}),cell:({row:e})=>c.jsx("span",{className:"text-sm",children:e.original.task_counter})},{accessorKey:"task_list_id",header:"Task List",cell:({row:e})=>c.jsx("span",{className:"text-sm text-muted-foreground truncate max-w-[150px] block",children:e.original.task_list_id||"—"})},{accessorKey:"created_at",header:({column:e})=>c.jsxs(se,{variant:"ghost",size:"sm",className:"-ml-3",onClick:()=>e.toggleSorting(),children:["Created ",c.jsx(dn,{className:"size-3"})]}),cell:({row:e})=>c.jsx("span",{className:"text-sm text-muted-foreground whitespace-nowrap",children:hw(e.original.created_at)})},{id:"actions",header:"",cell:({row:e,table:a})=>{const l=a.options.meta;return c.jsx("div",{onClick:r=>r.stopPropagation(),children:c.jsxs(jl,{children:[c.jsx(Ml,{asChild:!0,children:c.jsx(se,{variant:"ghost",size:"icon",className:"size-7",children:c.jsx(_s,{className:"size-4"})})}),c.jsxs(Fa,{align:"end",children:[c.jsx(mo,{className:"hidden"}),c.jsxs(dt,{className:"text-red-500 focus:text-red-500",onClick:()=>l==null?void 0:l.onDelete(e.original.id),children:[c.jsx(la,{className:"size-3.5 mr-2"})," Delete"]})]})]})})},size:50}]}function YT(){const[e,a]=x.useState([]),[l,r]=x.useState(!0),[s,u]=x.useState(null),[f,m]=x.useState([]),[h,p]=x.useState(""),[v,y]=x.useState({}),[w,S]=x.useState(!1),N=x.useRef(null),C=x.useMemo(()=>GT(),[]);function M(){fetch("/api/projects").then(E=>E.json()).then(a).finally(()=>r(!1))}x.useEffect(()=>{M()},[]),x.useEffect(()=>{function E(k){var F,K,W;if(k.key==="/"&&!k.ctrlKey&&!k.metaKey){const Z=(F=k.target)==null?void 0:F.tagName;Z!=="INPUT"&&Z!=="TEXTAREA"&&(k.preventDefault(),(K=N.current)==null||K.focus())}k.key==="Escape"&&(s?u(null):(p(""),(W=N.current)==null||W.blur()))}return document.addEventListener("keydown",E),()=>document.removeEventListener("keydown",E)},[s]);async function T(E){await fetch(`/api/projects/${E}`,{method:"DELETE"}),a(k=>k.filter(F=>F.id!==E))}async function D(E){await Promise.all(E.map(k=>fetch(`/api/projects/${k}`,{method:"DELETE"}))),a(k=>k.filter(F=>!E.includes(F.id))),y({})}const _=fu({data:e,columns:C,state:{sorting:f,globalFilter:h,rowSelection:v},onSortingChange:m,onGlobalFilterChange:p,onRowSelectionChange:y,getCoreRowModel:iu(),getSortedRowModel:du(),getFilteredRowModel:cu(),getPaginationRowModel:uu(),enableRowSelection:!0,getRowId:E=>E.id,initialState:{pagination:{pageSize:15}},meta:{onDelete:T}}),O=Object.keys(v).filter(E=>v[E]),H=O.length>0;return l?c.jsx("div",{className:"text-center text-muted-foreground py-12",children:"Loading projects..."}):s?c.jsx(IT,{project:s,onBack:()=>u(null)}):e.length===0&&!w?c.jsxs("div",{className:"text-center py-12",children:[c.jsx(Uc,{className:"mx-auto size-10 text-muted-foreground/50 mb-3"}),c.jsx("p",{className:"text-muted-foreground",children:"No projects registered."}),c.jsxs("p",{className:"text-sm text-muted-foreground mt-1",children:["Projects are auto-created when you run ",c.jsx("code",{className:"bg-muted px-1.5 py-0.5 rounded text-sm",children:"todos add"})," from a git repo."]}),c.jsxs(se,{variant:"outline",size:"sm",className:"mt-4 gap-1.5",onClick:()=>S(!0),children:[c.jsx(hl,{className:"size-3.5"})," New Project"]}),c.jsx(Oy,{open:w,onOpenChange:S,onCreated:M})]}):c.jsxs("div",{className:"space-y-4",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsxs("div",{className:"relative flex-1 min-w-[200px] max-w-sm",children:[c.jsx(Ic,{className:"absolute left-2.5 top-2.5 size-3.5 text-muted-foreground"}),c.jsx(It,{ref:N,placeholder:"Search projects... (press /)",value:h,onChange:E=>p(E.target.value),className:"pl-8 h-9"})]}),c.jsxs("span",{className:"text-sm text-muted-foreground",children:[e.length," project(s)"]}),c.jsx("div",{className:"flex-1"}),c.jsxs(se,{variant:"outline",size:"sm",className:"gap-1.5 h-9",onClick:()=>S(!0),children:[c.jsx(hl,{className:"size-3.5"})," New Project"]})]}),c.jsx("div",{className:"rounded-md border",children:c.jsxs(Fs,{children:[c.jsx(Bs,{children:_.getHeaderGroups().map(E=>c.jsx(mn,{children:E.headers.map(k=>c.jsx(Us,{children:k.isPlaceholder?null:bl(k.column.columnDef.header,k.getContext())},k.id))},E.id))}),c.jsx(Vs,{children:_.getRowModel().rows.length?_.getRowModel().rows.map(E=>c.jsx(mn,{className:"cursor-pointer","data-state":E.getIsSelected()?"selected":void 0,onClick:()=>u(E.original),children:E.getVisibleCells().map(k=>c.jsx(Pa,{children:bl(k.column.columnDef.cell,k.getContext())},k.id))},E.id)):c.jsx(mn,{children:c.jsx(Pa,{colSpan:C.length,className:"h-24 text-center text-muted-foreground",children:"No projects found."})})})]})}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("p",{className:"text-sm text-muted-foreground",children:[_.getFilteredRowModel().rows.length," project(s)"]}),_.getPageCount()>1&&c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx(se,{variant:"outline",size:"sm",onClick:()=>_.previousPage(),disabled:!_.getCanPreviousPage(),children:c.jsx(Ms,{className:"size-3.5"})}),c.jsxs("span",{className:"text-sm text-muted-foreground",children:["Page ",_.getState().pagination.pageIndex+1," of ",_.getPageCount()]}),c.jsx(se,{variant:"outline",size:"sm",onClick:()=>_.nextPage(),disabled:!_.getCanNextPage(),children:c.jsx(ro,{className:"size-3.5"})})]})]}),H&&c.jsxs("div",{className:"fixed bottom-6 left-1/2 -translate-x-1/2 z-50 flex items-center gap-3 rounded-xl border bg-background px-5 py-3 shadow-xl",children:[c.jsxs("span",{className:"text-sm font-medium",children:[O.length," selected"]}),c.jsx("div",{className:"h-4 w-px bg-border"}),c.jsxs(se,{variant:"outline",size:"sm",className:"h-7 text-sm text-red-500",onClick:()=>D(O),children:[c.jsx(la,{className:"size-3"})," Delete"]}),c.jsx("div",{className:"h-4 w-px bg-border"}),c.jsx(se,{variant:"ghost",size:"sm",className:"h-7 text-sm",onClick:()=>y({}),children:"Clear"})]}),c.jsx(Oy,{open:w,onOpenChange:S,onCreated:M})]})}function pw(e){const a=Math.floor((Date.now()-new Date(e).getTime())/1e3);if(a<60)return`${a}s ago`;const l=Math.floor(a/60);if(l<60)return`${l}m ago`;const r=Math.floor(l/60);return r<24?`${r}h ago`:`${Math.floor(r/24)}d ago`}function vw(e){return e<6e4?`${Math.round(e/1e3)}s`:e<36e5?`${Math.round(e/6e4)}m`:`${(e/36e5).toFixed(1)}h`}function Sg(e){const a=Date.now()-new Date(e).getTime();return a<300*1e3?{color:"bg-green-500",label:"Online"}:a<3600*1e3?{color:"bg-yellow-500",label:"Away"}:{color:"bg-gray-400",label:"Offline"}}function wg({role:e}){const a=e||"agent",l={admin:"bg-purple-100 text-purple-800 dark:bg-purple-900 dark:text-purple-200",agent:"bg-blue-100 text-blue-800 dark:bg-blue-900 dark:text-blue-200",observer:"bg-gray-100 text-gray-700 dark:bg-gray-800 dark:text-gray-300"};return c.jsx("span",{className:`inline-flex items-center rounded-full px-2 py-0.5 text-xs font-medium ${l[a]||l.agent}`,children:a})}function xw(e,a){return e.filter(l=>l.assigned_to===a.name||l.assigned_to===a.id||l.agent_id===a.id||l.agent_id===a.name)}function $T(e){return e.length===0?null:e.reduce((a,l)=>{const r=new Date(a.updated_at||a.created_at).getTime();return new Date(l.updated_at||l.created_at).getTime()>r?l:a})}function Ay(e,a){const l=e.length,r=a.length,s=Array.from({length:l+1},()=>Array(r+1).fill(0));for(let u=0;u<=l;u++)s[u][0]=u;for(let u=0;u<=r;u++)s[0][u]=u;for(let u=1;u<=l;u++)for(let f=1;f<=r;f++)s[u][f]=Math.min(s[u-1][f]+1,s[u][f-1]+1,s[u-1][f-1]+(e[u-1]===a[f-1]?0:1));return s[l][r]}function ky({open:e,onOpenChange:a,onCreated:l}){const[r,s]=x.useState(""),[u,f]=x.useState(""),[m,h]=x.useState("agent"),[p,v]=x.useState(!1),[y,w]=x.useState(null);async function S(N){if(N.preventDefault(),!!r.trim()){v(!0),w(null);try{const M=await(await fetch("/api/agents",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:r.trim(),description:u.trim()||void 0,role:m})})).json();M.error?w(M.error):(s(""),f(""),h("agent"),a(!1),l())}catch{w("Failed to register agent")}finally{v(!1)}}}return c.jsx(ra,{open:e,onOpenChange:a,children:c.jsxs(In,{children:[c.jsx(Ba,{children:c.jsx(sa,{children:"New Agent"})}),c.jsxs("form",{onSubmit:S,className:"space-y-4",children:[c.jsxs("div",{className:"space-y-1.5",children:[c.jsx("label",{className:"text-sm font-medium",children:"Name"}),c.jsx(It,{value:r,onChange:N=>s(N.target.value),placeholder:"Agent name",className:"h-9",autoFocus:!0})]}),c.jsxs("div",{className:"space-y-1.5",children:[c.jsx("label",{className:"text-sm font-medium",children:"Description"}),c.jsx(It,{value:u,onChange:N=>f(N.target.value),placeholder:"Optional description",className:"h-9"})]}),c.jsxs("div",{className:"space-y-1.5",children:[c.jsx("label",{className:"text-sm font-medium",children:"Role"}),c.jsxs(gn,{value:m,onValueChange:h,children:[c.jsx(Zt,{className:"h-9",children:c.jsx(hn,{})}),c.jsxs(Jt,{children:[c.jsx(Te,{value:"agent",children:"Agent"}),c.jsx(Te,{value:"admin",children:"Admin"}),c.jsx(Te,{value:"observer",children:"Observer"})]})]})]}),y&&c.jsx("p",{className:"text-sm text-red-500",children:y}),c.jsxs(Is,{children:[c.jsx(se,{type:"button",variant:"outline",onClick:()=>a(!1),children:"Cancel"}),c.jsx(se,{type:"submit",disabled:!r.trim()||p,children:p?"Creating...":"Create"})]})]})]})})}function qT({agent:e,tasks:a,open:l,onOpenChange:r,onUpdated:s}){const[u,f]=x.useState(!1),[m,h]=x.useState(""),[p,v]=x.useState(""),[y,w]=x.useState("agent"),[S,N]=x.useState(!1),[C,M]=x.useState(null);if(x.useEffect(()=>{e&&(h(e.name),v(e.description||""),w(e.role||"agent"),f(!1),M(null))},[e]),!e)return null;const T=Sg(e.last_seen_at),_=xw(a,e).sort((E,k)=>new Date(k.updated_at||k.created_at).getTime()-new Date(E.updated_at||E.created_at).getTime()).slice(0,20);async function O(){N(!0),M(null);try{const k=await(await fetch(`/api/agents/${e.id}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:m.trim(),description:p.trim()||null,role:y})})).json();k.error?M(k.error):(f(!1),s())}catch{M("Failed to update agent")}finally{N(!1)}}const H={pending:"text-yellow-500",in_progress:"text-blue-500",completed:"text-green-500",cancelled:"text-red-500"};return c.jsx(ra,{open:l,onOpenChange:r,children:c.jsxs(In,{className:"max-w-lg max-h-[85vh] overflow-y-auto",children:[c.jsx(Ba,{children:c.jsxs(sa,{className:"flex items-center gap-2",children:[c.jsx(js,{className:"size-5 text-orange-500"}),u?"Edit Agent":"Agent Details"]})}),c.jsxs("div",{className:"space-y-4",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("span",{className:`size-2 rounded-full ${T.color}`}),c.jsx("span",{className:"text-sm text-muted-foreground",children:T.label}),c.jsxs("span",{className:"text-sm text-muted-foreground",children:["— last seen ",pw(e.last_seen_at)]})]}),u?c.jsxs("div",{className:"space-y-3",children:[c.jsxs("div",{className:"space-y-1.5",children:[c.jsx("label",{className:"text-sm font-medium",children:"Name"}),c.jsx(It,{value:m,onChange:E=>h(E.target.value),className:"h-9"})]}),c.jsxs("div",{className:"space-y-1.5",children:[c.jsx("label",{className:"text-sm font-medium",children:"Description"}),c.jsx(It,{value:p,onChange:E=>v(E.target.value),className:"h-9"})]}),c.jsxs("div",{className:"space-y-1.5",children:[c.jsx("label",{className:"text-sm font-medium",children:"Role"}),c.jsxs(gn,{value:y,onValueChange:w,children:[c.jsx(Zt,{className:"h-9",children:c.jsx(hn,{})}),c.jsxs(Jt,{children:[c.jsx(Te,{value:"agent",children:"Agent"}),c.jsx(Te,{value:"admin",children:"Admin"}),c.jsx(Te,{value:"observer",children:"Observer"})]})]})]}),C&&c.jsx("p",{className:"text-sm text-red-500",children:C}),c.jsxs("div",{className:"flex gap-2",children:[c.jsxs(se,{size:"sm",onClick:O,disabled:S||!m.trim(),className:"gap-1.5",children:[c.jsx(r0,{className:"size-3.5"}),S?"Saving...":"Save"]}),c.jsx(se,{size:"sm",variant:"outline",onClick:()=>{f(!1),M(null)},children:"Cancel"})]})]}):c.jsxs("div",{className:"space-y-3",children:[c.jsxs("div",{className:"grid grid-cols-2 gap-3 text-sm",children:[c.jsxs("div",{children:[c.jsx("span",{className:"text-muted-foreground",children:"Name"}),c.jsx("p",{className:"font-medium",children:e.name})]}),c.jsxs("div",{children:[c.jsx("span",{className:"text-muted-foreground",children:"ID"}),c.jsx("p",{className:"font-mono text-xs",children:e.id})]}),c.jsxs("div",{children:[c.jsx("span",{className:"text-muted-foreground",children:"Role"}),c.jsx("div",{className:"mt-0.5",children:c.jsx(wg,{role:e.role})})]}),c.jsxs("div",{children:[c.jsx("span",{className:"text-muted-foreground",children:"Description"}),c.jsx("p",{children:e.description||"—"})]})]}),c.jsxs(se,{size:"sm",variant:"outline",onClick:()=>f(!0),className:"gap-1.5",children:[c.jsx(oo,{className:"size-3.5"})," Edit"]})]}),c.jsxs("div",{className:"grid grid-cols-4 gap-2",children:[c.jsx(St,{className:"py-2",children:c.jsxs(wt,{className:"px-3 py-0 text-center",children:[c.jsx("p",{className:"text-lg font-bold",children:e.total}),c.jsx("p",{className:"text-xs text-muted-foreground",children:"Total"})]})}),c.jsx(St,{className:"py-2",children:c.jsxs(wt,{className:"px-3 py-0 text-center",children:[c.jsx("p",{className:"text-lg font-bold text-yellow-500",children:e.pending}),c.jsx("p",{className:"text-xs text-muted-foreground",children:"Pending"})]})}),c.jsx(St,{className:"py-2",children:c.jsxs(wt,{className:"px-3 py-0 text-center",children:[c.jsx("p",{className:"text-lg font-bold text-blue-500",children:e.inProgress}),c.jsx("p",{className:"text-xs text-muted-foreground",children:"Active"})]})}),c.jsx(St,{className:"py-2",children:c.jsxs(wt,{className:"px-3 py-0 text-center",children:[c.jsx("p",{className:"text-lg font-bold text-green-500",children:e.completed}),c.jsx("p",{className:"text-xs text-muted-foreground",children:"Done"})]})})]}),c.jsxs("div",{className:"flex items-center gap-4 text-sm",children:[c.jsxs("div",{children:[c.jsx("span",{className:"text-muted-foreground",children:"Completion rate: "}),c.jsx(Ht,{variant:e.completionRate>=80?"default":e.completionRate>=50?"secondary":"outline",children:e.total>0?`${e.completionRate}%`:"—"})]}),c.jsxs("div",{children:[c.jsx("span",{className:"text-muted-foreground",children:"Avg work time: "}),c.jsx("span",{className:"font-medium",children:e.avgWorkTime!==null?vw(e.avgWorkTime):"—"})]})]}),e.lastTask&&c.jsxs("div",{className:"text-sm",children:[c.jsx("span",{className:"text-muted-foreground",children:"Last active task: "}),c.jsx("span",{className:"font-medium",children:e.lastTask.title}),c.jsxs("span",{className:`ml-1.5 ${H[e.lastTask.status]||"text-muted-foreground"}`,children:["(",e.lastTask.status.replace("_"," "),")"]})]}),_.length>0&&c.jsxs("div",{children:[c.jsxs("p",{className:"text-sm font-medium mb-2",children:["Recent Tasks (",_.length,")"]}),c.jsx("div",{className:"max-h-[200px] overflow-y-auto rounded border divide-y",children:_.map(E=>c.jsxs("div",{className:"flex items-center justify-between px-3 py-2 text-sm",children:[c.jsx("span",{className:"truncate max-w-[300px]",children:E.title}),c.jsx(Ht,{variant:"outline",className:`text-xs shrink-0 ml-2 ${H[E.status]||""}`,children:E.status.replace("_"," ")})]},E.id))})]})]})]})})}function WT(e){const a=[],l=new Set;for(let r=0;r<e.length;r++){if(l.has(e[r].id))continue;const s=[e[r]];for(let u=r+1;u<e.length;u++){if(l.has(e[u].id))continue;const f=e[r].name.toLowerCase(),m=e[u].name.toLowerCase(),h=Math.max(f.length,m.length);if(h===0)continue;(1-Ay(f,m)/h>=.6||f.includes(m)||m.includes(f))&&(s.push(e[u]),l.add(e[u].id))}if(s.length>1){l.add(e[r].id);const u=s[0].name.toLowerCase(),f=s[1].name.toLowerCase(),m=Math.max(u.length,f.length),h=Ay(u,f);a.push({agents:s,similarity:Math.round((1-h/m)*100)})}}return a}function KT({open:e,onOpenChange:a,agents:l,onMerged:r}){const s=x.useMemo(()=>WT(l),[l]),[u,f]=x.useState(null);async function m(h,p){f(p);try{const v=h.agents.filter(y=>y.id!==p).map(y=>y.id);await Promise.all(v.map(y=>fetch(`/api/agents/${y}`,{method:"DELETE"}))),r()}finally{f(null)}}return c.jsx(ra,{open:e,onOpenChange:a,children:c.jsxs(In,{className:"max-w-md max-h-[70vh] overflow-y-auto",children:[c.jsx(Ba,{children:c.jsxs(sa,{className:"flex items-center gap-2",children:[c.jsx(l0,{className:"size-5"})," Merge Duplicate Agents"]})}),s.length===0?c.jsx("p",{className:"text-sm text-muted-foreground py-4 text-center",children:"No duplicate agents found."}):c.jsx("div",{className:"space-y-4",children:s.map((h,p)=>c.jsxs("div",{className:"rounded border p-3 space-y-2",children:[c.jsxs("p",{className:"text-sm font-medium",children:["Similar names (",h.similarity,"% match)"]}),c.jsx("div",{className:"space-y-1.5",children:h.agents.map(v=>c.jsxs("div",{className:"flex items-center justify-between text-sm",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx(js,{className:"size-3.5 text-orange-500"}),c.jsx("span",{children:v.name}),c.jsx("code",{className:"text-xs text-muted-foreground",children:v.id})]}),c.jsx(se,{size:"sm",variant:"outline",className:"h-7 text-xs",disabled:u!==null,onClick:()=>m(h,v.id),children:u===v.id?"Merging...":"Keep"})]},v.id))}),c.jsx("p",{className:"text-xs text-muted-foreground",children:'Click "Keep" to keep that agent and delete the others.'})]},p))})]})})}function XT({agents:e,onClear:a}){return e.length<2?null:c.jsxs(St,{className:"mt-4",children:[c.jsx(Vt,{className:"pb-2",children:c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs(Ut,{className:"text-sm flex items-center gap-2",children:[c.jsx(e0,{className:"size-4"})," Agent Comparison"]}),c.jsxs(se,{variant:"ghost",size:"sm",className:"h-7 text-xs",onClick:a,children:[c.jsx(Fm,{className:"size-3 mr-1"})," Close"]})]})}),c.jsx(wt,{children:c.jsx("div",{className:"overflow-x-auto",children:c.jsxs("table",{className:"w-full text-sm",children:[c.jsx("thead",{children:c.jsxs("tr",{className:"border-b",children:[c.jsx("th",{className:"text-left py-2 pr-4 text-muted-foreground font-medium",children:"Metric"}),e.map(l=>c.jsx("th",{className:"text-center py-2 px-3 font-medium",children:l.name},l.id))]})}),c.jsxs("tbody",{className:"divide-y",children:[c.jsxs("tr",{children:[c.jsx("td",{className:"py-1.5 pr-4 text-muted-foreground",children:"Status"}),e.map(l=>{const r=Sg(l.last_seen_at);return c.jsx("td",{className:"text-center py-1.5 px-3",children:c.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[c.jsx("span",{className:`size-2 rounded-full ${r.color}`}),r.label]})},l.id)})]}),c.jsxs("tr",{children:[c.jsx("td",{className:"py-1.5 pr-4 text-muted-foreground",children:"Role"}),e.map(l=>c.jsx("td",{className:"text-center py-1.5 px-3",children:c.jsx(wg,{role:l.role})},l.id))]}),c.jsxs("tr",{children:[c.jsx("td",{className:"py-1.5 pr-4 text-muted-foreground",children:"Total Tasks"}),e.map(l=>c.jsx("td",{className:"text-center py-1.5 px-3 font-medium",children:l.total},l.id))]}),c.jsxs("tr",{children:[c.jsx("td",{className:"py-1.5 pr-4 text-muted-foreground",children:"Pending"}),e.map(l=>c.jsx("td",{className:"text-center py-1.5 px-3 text-yellow-500",children:l.pending},l.id))]}),c.jsxs("tr",{children:[c.jsx("td",{className:"py-1.5 pr-4 text-muted-foreground",children:"In Progress"}),e.map(l=>c.jsx("td",{className:"text-center py-1.5 px-3 text-blue-500",children:l.inProgress},l.id))]}),c.jsxs("tr",{children:[c.jsx("td",{className:"py-1.5 pr-4 text-muted-foreground",children:"Completed"}),e.map(l=>c.jsx("td",{className:"text-center py-1.5 px-3 text-green-500",children:l.completed},l.id))]}),c.jsxs("tr",{children:[c.jsx("td",{className:"py-1.5 pr-4 text-muted-foreground",children:"Rate"}),e.map(l=>c.jsx("td",{className:"text-center py-1.5 px-3",children:c.jsx(Ht,{variant:l.completionRate>=80?"default":l.completionRate>=50?"secondary":"outline",children:l.total>0?`${l.completionRate}%`:"—"})},l.id))]}),c.jsxs("tr",{children:[c.jsx("td",{className:"py-1.5 pr-4 text-muted-foreground",children:"Avg Time"}),e.map(l=>c.jsx("td",{className:"text-center py-1.5 px-3",children:l.avgWorkTime!==null?vw(l.avgWorkTime):"—"},l.id))]}),c.jsxs("tr",{children:[c.jsx("td",{className:"py-1.5 pr-4 text-muted-foreground",children:"Last Task"}),e.map(l=>{var r;return c.jsx("td",{className:"text-center py-1.5 px-3 max-w-[150px] truncate",children:((r=l.lastTask)==null?void 0:r.title)||"—"},l.id)})]})]})]})})})]})}function QT(){return[{id:"select",header:({table:e})=>c.jsx("input",{type:"checkbox",className:"rounded",checked:e.getIsAllPageRowsSelected(),onChange:a=>e.toggleAllPageRowsSelected(a.target.checked)}),cell:({row:e})=>c.jsx("input",{type:"checkbox",className:"rounded",checked:e.getIsSelected(),onChange:a=>{a.stopPropagation(),e.toggleSelected(a.target.checked)},onClick:a=>a.stopPropagation()}),size:30,enableSorting:!1},{accessorKey:"name",header:({column:e})=>c.jsxs(se,{variant:"ghost",size:"sm",className:"-ml-3",onClick:()=>e.toggleSorting(),children:["Name ",c.jsx(dn,{className:"size-3"})]}),cell:({row:e})=>{const a=Sg(e.original.last_seen_at);return c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("span",{className:`size-2 rounded-full shrink-0 ${a.color}`,title:a.label}),c.jsx(js,{className:"size-4 text-orange-500 shrink-0"}),c.jsx("span",{className:"font-medium text-sm",children:e.original.name})]})}},{accessorKey:"role",header:"Role",cell:({row:e})=>c.jsx(wg,{role:e.original.role}),size:80},{accessorKey:"id",header:"ID",cell:({row:e})=>c.jsx("code",{className:"text-sm text-muted-foreground",children:e.original.id})},{accessorKey:"description",header:"Description",cell:({row:e})=>c.jsx("span",{className:"text-sm text-muted-foreground truncate max-w-[200px] block",children:e.original.description||"—"})},{accessorKey:"total",header:({column:e})=>c.jsxs(se,{variant:"ghost",size:"sm",className:"-ml-3",onClick:()=>e.toggleSorting(),children:["Tasks ",c.jsx(dn,{className:"size-3"})]}),cell:({row:e})=>{const{total:a,pending:l,inProgress:r,completed:s}=e.original;return a===0?c.jsx("span",{className:"text-sm text-muted-foreground",children:"0"}):c.jsxs("div",{className:"flex items-center gap-1.5 text-sm",children:[c.jsx("span",{className:"font-medium",children:a}),c.jsxs("span",{className:"text-muted-foreground",children:["(",c.jsx("span",{className:"text-yellow-500",children:l}),"/",c.jsx("span",{className:"text-blue-500",children:r}),"/",c.jsx("span",{className:"text-green-500",children:s}),")"]})]})}},{accessorKey:"completionRate",header:({column:e})=>c.jsxs(se,{variant:"ghost",size:"sm",className:"-ml-3",onClick:()=>e.toggleSorting(),children:["Rate ",c.jsx(dn,{className:"size-3"})]}),cell:({row:e})=>{const a=e.original.completionRate;return e.original.total===0?c.jsx("span",{className:"text-sm text-muted-foreground",children:"—"}):c.jsxs(Ht,{variant:a>=80?"default":a>=50?"secondary":"outline",className:"text-sm",children:[a,"%"]})}},{id:"lastTask",header:"Last Task",cell:({row:e})=>{const a=e.original.lastTask;return a?c.jsx("span",{className:"text-sm truncate max-w-[180px] block",title:a.title,children:a.title}):c.jsx("span",{className:"text-sm text-muted-foreground",children:"—"})}},{accessorKey:"last_seen_at",header:({column:e})=>c.jsxs(se,{variant:"ghost",size:"sm",className:"-ml-3",onClick:()=>e.toggleSorting(),children:["Last Seen ",c.jsx(dn,{className:"size-3"})]}),cell:({row:e})=>c.jsx("span",{className:"text-sm text-muted-foreground whitespace-nowrap",children:pw(e.original.last_seen_at)})},{id:"actions",header:"",cell:({row:e,table:a})=>{const l=a.options.meta;return c.jsx("div",{onClick:r=>r.stopPropagation(),children:c.jsxs(jl,{children:[c.jsx(Ml,{asChild:!0,children:c.jsx(se,{variant:"ghost",size:"icon",className:"size-7",children:c.jsx(_s,{className:"size-4"})})}),c.jsxs(Fa,{align:"end",children:[c.jsxs(dt,{onClick:()=>l==null?void 0:l.onOpenDetail(e.original),children:[c.jsx(oo,{className:"size-3.5 mr-2"})," View / Edit"]}),c.jsx(mo,{}),c.jsxs(dt,{className:"text-red-500 focus:text-red-500",onClick:()=>l==null?void 0:l.onDelete(e.original.id),children:[c.jsx(la,{className:"size-3.5 mr-2"})," Delete"]})]})]})})},size:50}]}function ZT(){const[e,a]=x.useState([]),[l,r]=x.useState([]),[s,u]=x.useState(!0),[f,m]=x.useState([{id:"total",desc:!0}]),[h,p]=x.useState(""),[v,y]=x.useState({}),[w,S]=x.useState(!1),[N,C]=x.useState(!1),[M,T]=x.useState(null),[D,_]=x.useState(!1),[O,H]=x.useState("all"),[E,k]=x.useState(!1),F=x.useRef(null),K=x.useMemo(()=>QT(),[]);function W(){Promise.all([fetch("/api/agents").then(A=>A.json()),fetch("/api/tasks").then(A=>A.json())]).then(([A,R])=>{a(A),r(R)}).finally(()=>u(!1))}x.useEffect(()=>{W()},[]),x.useEffect(()=>{function A(R){var V,te,ae;if(R.key==="/"&&!R.ctrlKey&&!R.metaKey){const oe=(V=R.target)==null?void 0:V.tagName;oe!=="INPUT"&&oe!=="TEXTAREA"&&(R.preventDefault(),(te=F.current)==null||te.focus())}R.key==="Escape"&&(p(""),(ae=F.current)==null||ae.blur())}return document.addEventListener("keydown",A),()=>document.removeEventListener("keydown",A)},[]);const Z=x.useMemo(()=>e.map(A=>{const R=xw(l,A),V=R.length,te=R.filter(xe=>xe.status==="pending").length,ae=R.filter(xe=>xe.status==="in_progress").length,oe=R.filter(xe=>xe.status==="completed").length,de=V>0?Math.round(oe/V*100):0,le=R.filter(xe=>xe.status==="completed"&&xe.completed_at);let we=null;if(le.length>0){const xe=le.map(Me=>{const De=new Date(Me.completed_at).getTime(),ot=new Date(Me.created_at).getTime();return De-ot}).filter(Me=>Me>0);xe.length>0&&(we=xe.reduce((Me,De)=>Me+De,0)/xe.length)}const fe=$T(R);return{...A,total:V,pending:te,inProgress:ae,completed:oe,completionRate:de,avgWorkTime:we,lastTask:fe}}),[e,l]),re=x.useMemo(()=>O==="all"?Z:O==="active"?Z.filter(A=>A.inProgress>0):Z.filter(A=>A.inProgress===0),[Z,O]);async function ne(A){await fetch(`/api/agents/${A}`,{method:"DELETE"}),a(R=>R.filter(V=>V.id!==A))}async function ue(A){await Promise.all(A.map(R=>fetch(`/api/agents/${R}`,{method:"DELETE"}))),a(R=>R.filter(V=>!A.includes(V.id))),y({})}function me(A){T(A),_(!0)}const z=fu({data:re,columns:K,state:{sorting:f,globalFilter:h,rowSelection:v},onSortingChange:m,onGlobalFilterChange:p,onRowSelectionChange:y,getCoreRowModel:iu(),getSortedRowModel:du(),getFilteredRowModel:cu(),getPaginationRowModel:uu(),enableRowSelection:!0,getRowId:A=>A.id,initialState:{pagination:{pageSize:15}},meta:{onDelete:ne,onOpenDetail:me}}),Y=Object.keys(v).filter(A=>v[A]),Q=Y.length>0,G=Z.filter(A=>Y.includes(A.id));return s?c.jsx("div",{className:"text-center text-muted-foreground py-12",children:"Loading agents..."}):e.length===0&&!w?c.jsxs("div",{className:"text-center py-12",children:[c.jsx(js,{className:"mx-auto size-10 text-muted-foreground/50 mb-3"}),c.jsx("p",{className:"text-muted-foreground",children:"No agents registered."}),c.jsxs("p",{className:"text-sm text-muted-foreground mt-1",children:["Agents register via ",c.jsx("code",{className:"bg-muted px-1.5 py-0.5 rounded text-sm",children:"register_agent"})," MCP tool or CLI."]}),c.jsxs(se,{variant:"outline",size:"sm",className:"mt-4 gap-1.5",onClick:()=>S(!0),children:[c.jsx(hl,{className:"size-3.5"})," New Agent"]}),c.jsx(ky,{open:w,onOpenChange:S,onCreated:W})]}):c.jsxs("div",{className:"space-y-4",children:[c.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[c.jsxs("div",{className:"relative flex-1 min-w-[180px] max-w-xs",children:[c.jsx(Ic,{className:"absolute left-2.5 top-2.5 size-3.5 text-muted-foreground"}),c.jsx(It,{ref:F,placeholder:"Search agents... (press /)",value:h,onChange:A=>p(A.target.value),className:"pl-8 h-9"})]}),c.jsxs(gn,{value:O,onValueChange:A=>H(A),children:[c.jsx(Zt,{className:"h-9 w-[130px]",children:c.jsx(hn,{placeholder:"Filter"})}),c.jsxs(Jt,{children:[c.jsx(Te,{value:"all",children:"All"}),c.jsx(Te,{value:"active",children:"Active"}),c.jsx(Te,{value:"idle",children:"Idle"})]})]}),c.jsxs("span",{className:"text-sm text-muted-foreground",children:[re.length," agent(s)"]}),c.jsx("div",{className:"flex-1"}),c.jsxs(se,{variant:"outline",size:"sm",className:"gap-1.5 h-9",onClick:()=>C(!0),children:[c.jsx(l0,{className:"size-3.5"})," Merge"]}),c.jsxs(se,{variant:"outline",size:"sm",className:"gap-1.5 h-9",onClick:()=>S(!0),children:[c.jsx(hl,{className:"size-3.5"})," New Agent"]})]}),c.jsx("div",{className:"rounded-md border",children:c.jsxs(Fs,{children:[c.jsx(Bs,{children:z.getHeaderGroups().map(A=>c.jsx(mn,{children:A.headers.map(R=>c.jsx(Us,{children:R.isPlaceholder?null:bl(R.column.columnDef.header,R.getContext())},R.id))},A.id))}),c.jsx(Vs,{children:z.getRowModel().rows.length?z.getRowModel().rows.map(A=>c.jsx(mn,{"data-state":A.getIsSelected()?"selected":void 0,className:"cursor-pointer",onClick:()=>me(A.original),children:A.getVisibleCells().map(R=>c.jsx(Pa,{children:bl(R.column.columnDef.cell,R.getContext())},R.id))},A.id)):c.jsx(mn,{children:c.jsx(Pa,{colSpan:K.length,className:"h-24 text-center text-muted-foreground",children:"No agents found."})})})]})}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("p",{className:"text-sm text-muted-foreground",children:[z.getFilteredRowModel().rows.length," agent(s)"]}),z.getPageCount()>1&&c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx(se,{variant:"outline",size:"sm",onClick:()=>z.previousPage(),disabled:!z.getCanPreviousPage(),children:c.jsx(Ms,{className:"size-3.5"})}),c.jsxs("span",{className:"text-sm text-muted-foreground",children:["Page ",z.getState().pagination.pageIndex+1," of ",z.getPageCount()]}),c.jsx(se,{variant:"outline",size:"sm",onClick:()=>z.nextPage(),disabled:!z.getCanNextPage(),children:c.jsx(ro,{className:"size-3.5"})})]})]}),E&&G.length>=2&&c.jsx(XT,{agents:G,onClear:()=>{k(!1),y({})}}),Q&&c.jsxs("div",{className:"fixed bottom-6 left-1/2 -translate-x-1/2 z-50 flex items-center gap-3 rounded-xl border bg-background px-5 py-3 shadow-xl",children:[c.jsxs("span",{className:"text-sm font-medium",children:[Y.length," selected"]}),c.jsx("div",{className:"h-4 w-px bg-border"}),Y.length>=2&&c.jsxs(c.Fragment,{children:[c.jsxs(se,{variant:"outline",size:"sm",className:"h-7 text-sm gap-1",onClick:()=>k(!0),children:[c.jsx(e0,{className:"size-3"})," Compare"]}),c.jsx("div",{className:"h-4 w-px bg-border"})]}),c.jsxs(se,{variant:"outline",size:"sm",className:"h-7 text-sm text-red-500",onClick:()=>ue(Y),children:[c.jsx(la,{className:"size-3"})," Delete"]}),c.jsx("div",{className:"h-4 w-px bg-border"}),c.jsx(se,{variant:"ghost",size:"sm",className:"h-7 text-sm",onClick:()=>{y({}),k(!1)},children:"Clear"})]}),c.jsx(ky,{open:w,onOpenChange:S,onCreated:W}),c.jsx(KT,{open:N,onOpenChange:C,agents:e,onMerged:W}),c.jsx(qT,{agent:M,tasks:l,open:D,onOpenChange:_,onUpdated:W})]})}function yw(e){const a=Math.floor((Date.now()-new Date(e).getTime())/1e3);if(a<60)return`${a}s ago`;const l=Math.floor(a/60);if(l<60)return`${l}m ago`;const r=Math.floor(l/60);return r<24?`${r}h ago`:`${Math.floor(r/24)}d ago`}function JT(e){return{pending:"text-yellow-500",in_progress:"text-blue-500",completed:"text-green-500",failed:"text-red-500",cancelled:"text-muted-foreground"}[e]||"text-foreground"}function bw(e){return e==="active"?"default":e==="completed"?"secondary":"outline"}function eO(e){let a=e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">");return a=a.replace(/```(\w*)\n([\s\S]*?)```/g,(l,r,s)=>`<pre class="my-2 rounded bg-muted p-3 text-xs font-mono overflow-x-auto"><code>${s.trim()}</code></pre>`),a=a.replace(/`([^`]+)`/g,'<code class="rounded bg-muted px-1 py-0.5 text-xs font-mono">$1</code>'),a=a.replace(/\*\*([^*]+)\*\*/g,"<strong>$1</strong>"),a=a.replace(new RegExp("(?<!\\*)\\*([^*]+)\\*(?!\\*)","g"),"<em>$1</em>"),a=a.replace(/^### (.+)$/gm,'<h3 class="text-sm font-semibold mt-3 mb-1">$1</h3>'),a=a.replace(/^## (.+)$/gm,'<h2 class="text-base font-semibold mt-4 mb-1">$1</h2>'),a=a.replace(/^- (.+)$/gm,'<li class="ml-4 list-disc">$1</li>'),a=a.replace(/((?:<li[^>]*>.*<\/li>\n?)+)/g,'<ul class="my-1 space-y-0.5 text-sm">$1</ul>'),a=a.replace(/^\d+\. (.+)$/gm,'<li class="ml-4 list-decimal">$1</li>'),a=a.replace(/\n\n/g,'</p><p class="my-1.5">'),a=a.replace(new RegExp("(?<!<\\/pre>|<\\/li>|<\\/ul>|<\\/h[23]>)\\n(?!<)","g"),"<br>"),`<p class="my-1.5">${a}</p>`}function rm({open:e,onOpenChange:a,onSaved:l,projects:r,agents:s,editPlan:u}){const[f,m]=x.useState(""),[h,p]=x.useState(""),[v,y]=x.useState("active"),[w,S]=x.useState("none"),[N,C]=x.useState("none"),[M,T]=x.useState(!1),[D,_]=x.useState(null),O=!!u;x.useEffect(()=>{u?(m(u.name),p(u.description||""),y(u.status),S(u.project_id||"none"),C(u.agent_id||"none")):(m(""),p(""),y("active"),S("none"),C("none")),_(null)},[u,e]);async function H(E){if(E.preventDefault(),!!f.trim()){T(!0),_(null);try{const k={name:f.trim(),status:v};h.trim()&&(k.description=h.trim()),w!=="none"&&(k.project_id=w),N!=="none"&&(k.agent_id=N);const F=O?`/api/plans/${u.id}`:"/api/plans",Z=await(await fetch(F,{method:O?"PATCH":"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(k)})).json();Z.error?_(Z.error):(a(!1),l())}catch{_(O?"Failed to update plan":"Failed to create plan")}finally{T(!1)}}}return c.jsx(ra,{open:e,onOpenChange:a,children:c.jsxs(In,{className:"max-w-lg",children:[c.jsx(Ba,{children:c.jsx(sa,{children:O?"Edit Plan":"New Plan"})}),c.jsxs("form",{onSubmit:H,className:"space-y-4",children:[c.jsxs("div",{className:"space-y-1.5",children:[c.jsx("label",{className:"text-sm font-medium",children:"Name"}),c.jsx(It,{value:f,onChange:E=>m(E.target.value),placeholder:"Plan name",className:"h-9",autoFocus:!0})]}),c.jsxs("div",{className:"space-y-1.5",children:[c.jsx("label",{className:"text-sm font-medium",children:"Description"}),c.jsx("textarea",{value:h,onChange:E=>p(E.target.value),placeholder:"Plan description (supports markdown)",rows:8,className:"flex w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 resize-y font-mono"}),c.jsx("p",{className:"text-xs text-muted-foreground",children:"Supports markdown: **bold**, *italic*, `code`, ```code blocks```, lists, headings"})]}),c.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[c.jsxs("div",{className:"space-y-1.5",children:[c.jsx("label",{className:"text-sm font-medium",children:"Status"}),c.jsxs(gn,{value:v,onValueChange:y,children:[c.jsx(Zt,{className:"h-9",children:c.jsx(hn,{})}),c.jsxs(Jt,{children:[c.jsx(Te,{value:"active",children:"Active"}),c.jsx(Te,{value:"completed",children:"Completed"}),c.jsx(Te,{value:"archived",children:"Archived"})]})]})]}),c.jsxs("div",{className:"space-y-1.5",children:[c.jsx("label",{className:"text-sm font-medium",children:"Project"}),c.jsxs(gn,{value:w,onValueChange:S,children:[c.jsx(Zt,{className:"h-9",children:c.jsx(hn,{placeholder:"No project"})}),c.jsxs(Jt,{children:[c.jsx(Te,{value:"none",children:"No project"}),r.map(E=>c.jsx(Te,{value:E.id,children:E.name},E.id))]})]})]})]}),c.jsxs("div",{className:"space-y-1.5",children:[c.jsx("label",{className:"text-sm font-medium",children:"Owner (Agent)"}),c.jsxs(gn,{value:N,onValueChange:C,children:[c.jsx(Zt,{className:"h-9",children:c.jsx(hn,{placeholder:"No owner"})}),c.jsxs(Jt,{children:[c.jsx(Te,{value:"none",children:"No owner"}),s.map(E=>c.jsx(Te,{value:E.id,children:E.name},E.id))]})]})]}),D&&c.jsx("p",{className:"text-sm text-red-500",children:D}),c.jsxs(Is,{children:[c.jsx(se,{type:"button",variant:"outline",onClick:()=>a(!1),children:"Cancel"}),c.jsx(se,{type:"submit",disabled:!f.trim()||M,children:M?O?"Saving...":"Creating...":O?"Save":"Create"})]})]})]})})}function tO({plan:e,open:a,onOpenChange:l,projects:r,agents:s}){var y,w;const[u,f]=x.useState(null),[m,h]=x.useState(!1);x.useEffect(()=>{if(!e||!a){f(null);return}h(!0),fetch(`/api/plans/${e.id}`).then(S=>S.json()).then(S=>{S&&S.id?f(S):f({...e,tasks:S.tasks||[]})}).catch(()=>f({...e,tasks:[]})).finally(()=>h(!1))},[e,a]);const p=x.useMemo(()=>{var S;return e!=null&&e.project_id?((S=r.find(N=>N.id===e.project_id))==null?void 0:S.name)||e.project_id.slice(0,8):null},[e,r]),v=x.useMemo(()=>{var S;return e!=null&&e.agent_id?((S=s.find(N=>N.id===e.agent_id))==null?void 0:S.name)||e.agent_id.slice(0,8):null},[e,s]);return e?c.jsx(ra,{open:a,onOpenChange:l,children:c.jsxs(In,{className:"max-w-2xl max-h-[85vh] overflow-y-auto",children:[c.jsx(Ba,{children:c.jsxs(sa,{className:"flex items-center gap-2",children:[c.jsx(Lm,{className:"size-5 text-blue-500"}),e.name]})}),c.jsxs("div",{className:"space-y-4",children:[c.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[c.jsx(Ht,{variant:bw(e.status),children:e.status}),p&&c.jsx(Ht,{variant:"outline",children:p}),v&&c.jsxs(Ht,{variant:"outline",className:"text-xs",children:["Owner: ",v]})]}),e.description&&c.jsxs(St,{className:"shadow-none",children:[c.jsx(Vt,{className:"pb-2",children:c.jsx(Ut,{className:"text-sm",children:"Description"})}),c.jsx(wt,{children:c.jsx("div",{className:"prose prose-sm dark:prose-invert max-w-none text-sm leading-relaxed",dangerouslySetInnerHTML:{__html:eO(e.description)}})})]}),c.jsxs("div",{className:"grid grid-cols-2 gap-4 text-sm",children:[c.jsxs("div",{children:[c.jsx("span",{className:"text-muted-foreground",children:"Task List"}),c.jsx("p",{className:"font-medium",children:e.task_list_id||"—"})]}),c.jsxs("div",{children:[c.jsx("span",{className:"text-muted-foreground",children:"Created"}),c.jsx("p",{className:"font-medium",children:new Date(e.created_at).toLocaleString()})]}),c.jsxs("div",{children:[c.jsx("span",{className:"text-muted-foreground",children:"Updated"}),c.jsx("p",{className:"font-medium",children:new Date(e.updated_at).toLocaleString()})]})]}),c.jsxs("div",{children:[c.jsxs("h3",{className:"text-sm font-medium mb-2",children:["Tasks (",((y=u==null?void 0:u.tasks)==null?void 0:y.length)??0,")"]}),m?c.jsx("p",{className:"text-sm text-muted-foreground",children:"Loading tasks..."}):(w=u==null?void 0:u.tasks)!=null&&w.length?c.jsx("div",{className:"space-y-1 max-h-[300px] overflow-y-auto",children:u.tasks.map(S=>c.jsxs("div",{className:"flex items-center gap-2 rounded-md px-2 py-1.5 text-sm hover:bg-muted/50",children:[c.jsx("span",{className:`size-2 rounded-full shrink-0 ${JT(S.status).replace("text-","bg-")}`}),c.jsx("code",{className:"text-sm text-muted-foreground shrink-0",children:S.short_id||S.id.slice(0,8)}),c.jsx("span",{className:"truncate flex-1",children:S.title}),c.jsx(Ht,{variant:"outline",className:"text-xs shrink-0",children:S.priority}),c.jsx("span",{className:"text-sm text-muted-foreground shrink-0",children:S.assigned_to||"—"}),c.jsx("span",{className:"text-sm text-muted-foreground shrink-0",children:yw(S.updated_at)})]},S.id))}):c.jsx("p",{className:"text-sm text-muted-foreground",children:"No tasks in this plan."})]})]})]})}):null}function nO(){return[{id:"select",header:({table:e})=>c.jsx("input",{type:"checkbox",className:"rounded",checked:e.getIsAllPageRowsSelected(),onChange:a=>e.toggleAllPageRowsSelected(a.target.checked)}),cell:({row:e})=>c.jsx("input",{type:"checkbox",className:"rounded",checked:e.getIsSelected(),onChange:a=>{a.stopPropagation(),e.toggleSelected(a.target.checked)},onClick:a=>a.stopPropagation()}),size:30,enableSorting:!1},{accessorKey:"name",header:({column:e})=>c.jsxs(se,{variant:"ghost",size:"sm",className:"-ml-3",onClick:()=>e.toggleSorting(),children:["Name ",c.jsx(dn,{className:"size-3"})]}),cell:({row:e})=>c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx(Lm,{className:"size-4 text-blue-500 shrink-0"}),c.jsx("span",{className:"font-medium text-sm",children:e.original.name})]})},{accessorKey:"status",header:"Status",cell:({row:e})=>c.jsx(Ht,{variant:bw(e.original.status),children:e.original.status}),filterFn:(e,a,l)=>!l||l==="all"?!0:e.original.status===l},{accessorKey:"agent_id",header:"Owner",cell:({row:e,table:a})=>{var u;const l=a.options.meta,r=e.original.agent_id;if(!r)return c.jsx("span",{className:"text-sm text-muted-foreground",children:"—"});const s=(u=l==null?void 0:l.agents)==null?void 0:u.find(f=>f.id===r);return c.jsx("span",{className:"text-sm",children:(s==null?void 0:s.name)||r.slice(0,8)})}},{accessorKey:"project_id",header:"Project",cell:({row:e,table:a})=>{var u;const l=a.options.meta,r=e.original.project_id;if(!r)return c.jsx("span",{className:"text-sm text-muted-foreground",children:"—"});const s=(u=l==null?void 0:l.projects)==null?void 0:u.find(f=>f.id===r);return c.jsx("span",{className:"text-sm",children:(s==null?void 0:s.name)||r.slice(0,8)})}},{accessorKey:"description",header:"Description",cell:({row:e})=>{const a=e.original.description;if(!a)return c.jsx("span",{className:"text-sm text-muted-foreground",children:"—"});const l=a.length>80?a.slice(0,80)+"...":a;return c.jsx("span",{className:"text-sm text-muted-foreground truncate max-w-[250px] block",children:l})}},{accessorKey:"created_at",header:({column:e})=>c.jsxs(se,{variant:"ghost",size:"sm",className:"-ml-3",onClick:()=>e.toggleSorting(),children:["Created ",c.jsx(dn,{className:"size-3"})]}),cell:({row:e})=>c.jsx("span",{className:"text-sm text-muted-foreground whitespace-nowrap",children:yw(e.original.created_at)})},{id:"actions",header:"",cell:({row:e,table:a})=>{const l=a.options.meta;return c.jsx("div",{onClick:r=>r.stopPropagation(),children:c.jsxs(jl,{children:[c.jsx(Ml,{asChild:!0,children:c.jsx(se,{variant:"ghost",size:"icon",className:"size-7",children:c.jsx(_s,{className:"size-4"})})}),c.jsxs(Fa,{align:"end",children:[c.jsxs(dt,{onClick:()=>l==null?void 0:l.onEdit(e.original),children:[c.jsx(oo,{className:"size-3.5 mr-2"})," Edit"]}),c.jsx(mo,{}),c.jsxs(dt,{className:"text-red-500 focus:text-red-500",onClick:()=>l==null?void 0:l.onDelete(e.original.id),children:[c.jsx(la,{className:"size-3.5 mr-2"})," Delete"]})]})]})})},size:50}]}function aO(){const[e,a]=x.useState([]),[l,r]=x.useState([]),[s,u]=x.useState([]),[f,m]=x.useState(!0),[h,p]=x.useState([]),[v,y]=x.useState(""),[w,S]=x.useState("all"),[N,C]=x.useState({}),[M,T]=x.useState(!1),[D,_]=x.useState(null),[O,H]=x.useState(null),E=x.useRef(null),k=x.useMemo(()=>nO(),[]);function F(){fetch("/api/plans").then(z=>z.json()).then(a).finally(()=>m(!1))}function K(){fetch("/api/projects").then(z=>z.json()).then(z=>r(z))}function W(){fetch("/api/agents").then(z=>z.json()).then(z=>u(z))}x.useEffect(()=>{F(),K(),W()},[]),x.useEffect(()=>{function z(Y){var Q,G,A;if(Y.key==="/"&&!Y.ctrlKey&&!Y.metaKey){const R=(Q=Y.target)==null?void 0:Q.tagName;R!=="INPUT"&&R!=="TEXTAREA"&&(Y.preventDefault(),(G=E.current)==null||G.focus())}Y.key==="Escape"&&(O?H(null):(y(""),(A=E.current)==null||A.blur()))}return document.addEventListener("keydown",z),()=>document.removeEventListener("keydown",z)},[O]);async function Z(z){await fetch(`/api/plans/${z}`,{method:"DELETE"}),a(Y=>Y.filter(Q=>Q.id!==z))}async function re(z){await Promise.all(z.map(Y=>fetch(`/api/plans/${Y}`,{method:"DELETE"}))),a(Y=>Y.filter(Q=>!z.includes(Q.id))),C({})}const ne=fu({data:e,columns:k,state:{sorting:h,globalFilter:v,rowSelection:N,columnFilters:w!=="all"?[{id:"status",value:w}]:[]},onSortingChange:p,onGlobalFilterChange:y,onRowSelectionChange:C,getCoreRowModel:iu(),getSortedRowModel:du(),getFilteredRowModel:cu(),getPaginationRowModel:uu(),enableRowSelection:!0,getRowId:z=>z.id,initialState:{pagination:{pageSize:15}},meta:{onDelete:Z,onEdit:z=>_(z),projects:l,agents:s}}),ue=Object.keys(N).filter(z=>N[z]),me=ue.length>0;return f?c.jsx("div",{className:"text-center text-muted-foreground py-12",children:"Loading plans..."}):e.length===0&&!M?c.jsxs("div",{className:"text-center py-12",children:[c.jsx(Lm,{className:"mx-auto size-10 text-muted-foreground/50 mb-3"}),c.jsx("p",{className:"text-muted-foreground",children:"No plans yet."}),c.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:"Plans help you organize groups of tasks into execution phases."}),c.jsxs(se,{variant:"outline",size:"sm",className:"mt-4 gap-1.5",onClick:()=>T(!0),children:[c.jsx(hl,{className:"size-3.5"})," New Plan"]}),c.jsx(rm,{open:M,onOpenChange:T,onSaved:F,projects:l,agents:s})]}):c.jsxs("div",{className:"space-y-4",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsxs("div",{className:"relative flex-1 min-w-[200px] max-w-sm",children:[c.jsx(Ic,{className:"absolute left-2.5 top-2.5 size-3.5 text-muted-foreground"}),c.jsx(It,{ref:E,placeholder:"Search plans... (press /)",value:v,onChange:z=>y(z.target.value),className:"pl-8 h-9"})]}),c.jsxs(gn,{value:w,onValueChange:S,children:[c.jsx(Zt,{className:"h-9 w-[140px]",children:c.jsx(hn,{})}),c.jsxs(Jt,{children:[c.jsx(Te,{value:"all",children:"All Statuses"}),c.jsx(Te,{value:"active",children:"Active"}),c.jsx(Te,{value:"completed",children:"Completed"}),c.jsx(Te,{value:"archived",children:"Archived"})]})]}),c.jsxs("span",{className:"text-sm text-muted-foreground",children:[ne.getFilteredRowModel().rows.length," plan(s)"]}),c.jsx("div",{className:"flex-1"}),c.jsxs(se,{variant:"outline",size:"sm",className:"gap-1.5 h-9",onClick:()=>T(!0),children:[c.jsx(hl,{className:"size-3.5"})," New Plan"]})]}),c.jsx("div",{className:"rounded-md border",children:c.jsxs(Fs,{children:[c.jsx(Bs,{children:ne.getHeaderGroups().map(z=>c.jsx(mn,{children:z.headers.map(Y=>c.jsx(Us,{children:Y.isPlaceholder?null:bl(Y.column.columnDef.header,Y.getContext())},Y.id))},z.id))}),c.jsx(Vs,{children:ne.getRowModel().rows.length?ne.getRowModel().rows.map(z=>c.jsx(mn,{className:"cursor-pointer","data-state":z.getIsSelected()?"selected":void 0,onClick:()=>H(z.original),children:z.getVisibleCells().map(Y=>c.jsx(Pa,{children:bl(Y.column.columnDef.cell,Y.getContext())},Y.id))},z.id)):c.jsx(mn,{children:c.jsx(Pa,{colSpan:k.length,className:"h-24 text-center text-muted-foreground",children:"No plans found."})})})]})}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("p",{className:"text-sm text-muted-foreground",children:[ne.getFilteredRowModel().rows.length," plan(s)"]}),ne.getPageCount()>1&&c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx(se,{variant:"outline",size:"sm",onClick:()=>ne.previousPage(),disabled:!ne.getCanPreviousPage(),children:c.jsx(Ms,{className:"size-3.5"})}),c.jsxs("span",{className:"text-sm text-muted-foreground",children:["Page ",ne.getState().pagination.pageIndex+1," of"," ",ne.getPageCount()]}),c.jsx(se,{variant:"outline",size:"sm",onClick:()=>ne.nextPage(),disabled:!ne.getCanNextPage(),children:c.jsx(ro,{className:"size-3.5"})})]})]}),me&&c.jsxs("div",{className:"fixed bottom-6 left-1/2 -translate-x-1/2 z-50 flex items-center gap-3 rounded-xl border bg-background px-5 py-3 shadow-xl",children:[c.jsxs("span",{className:"text-sm font-medium",children:[ue.length," selected"]}),c.jsx("div",{className:"h-4 w-px bg-border"}),c.jsxs(se,{variant:"outline",size:"sm",className:"h-7 text-sm text-red-500",onClick:()=>re(ue),children:[c.jsx(la,{className:"size-3"})," Delete"]}),c.jsx("div",{className:"h-4 w-px bg-border"}),c.jsx(se,{variant:"ghost",size:"sm",className:"h-7 text-sm",onClick:()=>C({}),children:"Clear"})]}),c.jsx(rm,{open:M,onOpenChange:T,onSaved:F,projects:l,agents:s}),c.jsx(rm,{open:!!D,onOpenChange:z=>{z||_(null)},onSaved:F,projects:l,agents:s,editPlan:D}),c.jsx(tO,{plan:O,open:!!O,onOpenChange:z=>{z||H(null)},projects:l,agents:s})]})}function lO(){return c.jsxs("div",{className:"space-y-6",children:[c.jsxs(St,{children:[c.jsx(Vt,{className:"pb-3",children:c.jsx(Ut,{className:"text-sm",children:"Agent-native & headless"})}),c.jsxs(wt,{className:"space-y-2 text-sm text-muted-foreground",children:[c.jsxs("p",{children:[c.jsx("strong",{className:"text-foreground",children:"CLI and MCP are the primary surfaces."})," This dashboard is an optional local admin view that talks only to ",c.jsx("code",{className:"font-mono",children:"/api/*"})," on your machine — there is no sign-in, no hosted auth, and no connection to hosted platform services."]}),c.jsxs("p",{children:["For agent workflows use ",c.jsx("code",{className:"font-mono",children:"todos claim"}),", ",c.jsx("code",{className:"font-mono",children:"todos-mcp"}),", or"," ",c.jsx("code",{className:"font-mono",children:"TODOS_PROFILE=minimal"}),". Native remote storage is explicit opt-in through storage configuration."]})]})]}),c.jsxs(St,{children:[c.jsx(Vt,{className:"pb-3",children:c.jsx(Ut,{className:"text-sm",children:"How it works"})}),c.jsx(wt,{children:c.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-sm",children:[c.jsx(Cc,{n:"1",label:"Install",desc:"bun install -g @hasna/todos"}),c.jsx(Ff,{className:"size-4 text-muted-foreground shrink-0"}),c.jsx(Cc,{n:"2",label:"Add tasks",desc:"todos add 'Fix login bug'"}),c.jsx(Ff,{className:"size-4 text-muted-foreground shrink-0"}),c.jsx(Cc,{n:"3",label:"Connect AI",desc:"Add todos-mcp to your agent"}),c.jsx(Ff,{className:"size-4 text-muted-foreground shrink-0"}),c.jsx(Cc,{n:"4",label:"Track",desc:"todos serve or todos interactive"})]})})]}),c.jsxs(St,{children:[c.jsx(Vt,{className:"pb-3",children:c.jsxs(Ut,{className:"text-sm flex items-center gap-2",children:[c.jsx(LN,{className:"size-4"})," Keyboard Shortcuts"]})}),c.jsx(wt,{children:c.jsxs("div",{className:"grid grid-cols-2 gap-x-8 gap-y-2 text-sm sm:grid-cols-3",children:[c.jsx(Da,{keys:"/",label:"Focus search"}),c.jsx(Da,{keys:"n",label:"New task"}),c.jsx(Da,{keys:"r",label:"Reload data"}),c.jsx(Da,{keys:"0",label:"Dashboard"}),c.jsx(Da,{keys:"1",label:"Tasks"}),c.jsx(Da,{keys:"2",label:"Projects"}),c.jsx(Da,{keys:"3",label:"Agents"}),c.jsx(Da,{keys:"4",label:"Help"}),c.jsx(Da,{keys:"Esc",label:"Back / clear"})]})})]}),c.jsxs(St,{children:[c.jsx(Vt,{className:"pb-3",children:c.jsxs(Ut,{className:"text-sm flex items-center gap-2",children:[c.jsx(YN,{className:"size-4"})," CLI Commands"]})}),c.jsx(wt,{children:c.jsxs("div",{className:"space-y-2 text-sm",children:[c.jsx(Zn,{cmd:"todos add 'Task'",desc:"Create a new task"}),c.jsx(Zn,{cmd:"todos list",desc:"List all tasks"}),c.jsx(Zn,{cmd:"todos list --status pending",desc:"Filter by status"}),c.jsx(Zn,{cmd:"todos show <id>",desc:"Show task details"}),c.jsx(Zn,{cmd:"todos start <id>",desc:"Start a task"}),c.jsx(Zn,{cmd:"todos done <id>",desc:"Complete a task"}),c.jsx(Zn,{cmd:"todos search 'query'",desc:"Full-text search"}),c.jsx(Zn,{cmd:"todos serve",desc:"Start web dashboard"}),c.jsx(Zn,{cmd:"todos interactive",desc:"Interactive TUI"}),c.jsx(Zn,{cmd:"todos sync --task-list <id>",desc:"Sync with Claude Code"})]})})]}),c.jsxs(St,{children:[c.jsx(Vt,{className:"pb-3",children:c.jsxs(Ut,{className:"text-sm flex items-center gap-2",children:[c.jsx(GN,{className:"size-4"})," MCP Server"]})}),c.jsxs(wt,{children:[c.jsx("p",{className:"text-sm text-muted-foreground mb-3",children:"Add to your Claude Code or AI agent config:"}),c.jsx("pre",{className:"rounded-lg bg-muted p-3 text-sm font-mono overflow-x-auto",children:`{
|
|
340
340
|
"mcpServers": {
|
|
341
341
|
"todos": {
|
|
342
342
|
"command": "todos-mcp",
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
<meta charset="UTF-8" />
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
6
|
<title>Hasna Todos</title>
|
|
7
|
-
<script type="module" crossorigin src="/assets/index-
|
|
7
|
+
<script type="module" crossorigin src="/assets/index-DVotjwab.js"></script>
|
|
8
8
|
<link rel="stylesheet" crossorigin href="/assets/index-DJm6m6Yy.css">
|
|
9
9
|
</head>
|
|
10
10
|
<body>
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"project-commands.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/project-commands.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAkIzC,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,OAAO,
|
|
1
|
+
{"version":3,"file":"project-commands.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/project-commands.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAkIzC,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,OAAO,QAwzBvD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"query-commands.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/query-commands.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAkNzC,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,OAAO,
|
|
1
|
+
{"version":3,"file":"query-commands.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/query-commands.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAkNzC,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,OAAO,QAmqFrD"}
|
|
@@ -1,3 +1,8 @@
|
|
|
1
1
|
import type { Command } from "commander";
|
|
2
|
+
export declare function s3CredentialsFromEnv(env?: Record<string, string | undefined>): {
|
|
3
|
+
sessionToken?: string | undefined;
|
|
4
|
+
accessKeyId: string;
|
|
5
|
+
secretAccessKey: string;
|
|
6
|
+
};
|
|
2
7
|
export declare function registerStorageCommands(program: Command): void;
|
|
3
8
|
//# sourceMappingURL=storage-commands.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"storage-commands.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/storage-commands.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"storage-commands.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/storage-commands.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AA8EzC,wBAAgB,oBAAoB,CAAC,GAAG,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAe;;;;EAazF;AAYD,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,OAAO,QAyGvD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"task-commands.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/task-commands.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"task-commands.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/task-commands.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AA+HzC,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,OAAO,QAq6BpD"}
|