cogpit 3.5.2 → 3.5.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/dist/cli-runtime.js +1917 -1515
  2. package/dist/instance-worker.js +21 -5
  3. package/dist/web/assets/{AutomationsPanel-B3zT5G5K.js → AutomationsPanel-D7XmgTgZ.js} +1 -1
  4. package/dist/web/assets/{CogpitBlock-d05YgSdQ.js → CogpitBlock-CiS2M1Q_.js} +14 -14
  5. package/dist/web/assets/{CommandPaletteHost-D8fk5Qkq.js → CommandPaletteHost-Dj06VjlP.js} +1 -1
  6. package/dist/web/assets/{ConfigBrowser-BRsvua8m.js → ConfigBrowser-DqQo1F4o.js} +1 -1
  7. package/dist/web/assets/{CrewPanel-C1Yq8jMT.js → CrewPanel-DzLPmS6o.js} +1 -1
  8. package/dist/web/assets/{HighlightedEditor-clIIwmWB.js → HighlightedEditor-DPrSCx1c.js} +2 -2
  9. package/dist/web/assets/{KeyboardShortcutsDialog-0VokzXOy.js → KeyboardShortcutsDialog-BdXPWBJw.js} +1 -1
  10. package/dist/web/assets/{MissionHome-CNjhPZva.js → MissionHome-CTcx5vR7.js} +1 -1
  11. package/dist/web/assets/{MobileFileChanges-iLhOAdgx.js → MobileFileChanges-Ngv9AlhR.js} +1 -1
  12. package/dist/web/assets/PluginsDialog-CWRSNNll.js +1 -0
  13. package/dist/web/assets/{PreviewPanel-DF4kUYpX.js → PreviewPanel-CQcJIdef.js} +1 -1
  14. package/dist/web/assets/{ProjectFilesPanel-D9_OzQi2.js → ProjectFilesPanel-D5EKIBD7.js} +4 -4
  15. package/dist/web/assets/{ProjectSwitcherModal-DMEEWm7Q.js → ProjectSwitcherModal-BoSCOiv9.js} +1 -1
  16. package/dist/web/assets/{TerminalOutput-CrGF3VWW.js → TerminalOutput-DYZJD2WR.js} +1 -1
  17. package/dist/web/assets/{ThemeSelectorModal-BLBet6sQ.js → ThemeSelectorModal-8sO11Ob-.js} +1 -1
  18. package/dist/web/assets/{WorkflowsPanel-DkXoYVsK.js → WorkflowsPanel-qv6TkN7g.js} +1 -1
  19. package/dist/web/assets/WorktreePanel-Dr82TWOP.js +1 -0
  20. package/dist/web/assets/{edition-ui-CvFxsVfJ.js → edition-ui-DQHX5fm4.js} +1 -1
  21. package/dist/web/assets/{index-CAupRX51.js → index-BGSPI7dK.js} +1 -1
  22. package/dist/web/assets/index-BVmNox_3.js +504 -0
  23. package/dist/web/assets/{index-DxZSG7e3.js → index-CHtH7TlZ.js} +2 -2
  24. package/dist/web/assets/index-DKDki7Rz.css +1 -0
  25. package/dist/web/assets/index-DU4gWgPu.js +3 -0
  26. package/dist/web/assets/{index-DueGSx7L.js → index-zhwBlO_8.js} +2 -2
  27. package/dist/web/assets/{session-parser.worker-Dv5Kch9n.js → session-parser.worker-DCsmYUeX.js} +22 -22
  28. package/dist/web/assets/{switch-BHG6oFbM.js → switch-gTnbAJaZ.js} +1 -1
  29. package/dist/web/assets/{vendor-ui-keo4oB2X.js → vendor-ui-CKjyvB3_.js} +201 -196
  30. package/dist/web/index.html +3 -3
  31. package/package.json +1 -1
  32. package/dist/web/assets/PluginsDialog-xM9uR8bB.js +0 -1
  33. package/dist/web/assets/WorktreePanel-DvFGKfAn.js +0 -1
  34. package/dist/web/assets/index-BvNyEUVG.js +0 -506
  35. package/dist/web/assets/index-D6HYPdiw.css +0 -1
@@ -1 +1 @@
1
- import{c as G,j as t,r as o}from"./vendor-react-gGw_S5I_.js";import{by as ye,bN as Ce,c as F,aC as ke,ae as X,ac as q,aB as ve,aA as Z,au as ae,B as I,F as A,bO as Ne,bP as Se,bQ as we,bR as De,bS as Te,bT as Ee,bU as V,bV as Re,bW as ee,bX as Oe,k as te,aa as le,bY as Ie,a9 as ie,a5 as re,a3 as oe,a4 as ce,a7 as de,a6 as ue,a8 as me,x as ze,E as Ae,f as Le,U as Be,h as $e,i as Fe,b7 as Ge,az as Me,ax as ne,aw as Pe,ay as Ue,m as _e,bZ as Ve}from"./index-BvNyEUVG.js";import{c0 as Ke,a3 as He,a5 as Qe,bz as Ye,dm as Je,U as We,dn as xe,aB as fe,dp as Xe,dq as qe,aE as K,X as H,bi as Ze,cU as he,dr as et,b2 as tt,bR as nt,ak as st,cM as at}from"./vendor-ui-keo4oB2X.js";import{H as lt}from"./HighlightedEditor-clIIwmWB.js";import"./vendor-markdown-BEJ8yVzA.js";const it={agent:"bg-muted text-muted-foreground",skill:"bg-muted text-muted-foreground",command:"bg-muted text-muted-foreground",instructions:"bg-muted text-muted-foreground",settings:"bg-muted text-muted-foreground"},rt={agents:{subdir:"agents",fileType:"agent"},skills:{subdir:"skills",fileType:"skill"},commands:{subdir:"commands",fileType:"command"}},se=["instructions","agents","skills","commands","settings"],ot={instructions:{label:"Instructions",icon:Je,color:"text-muted-foreground"},agents:{label:"Agents",icon:Ye,color:"text-muted-foreground"},skills:{label:"Skills",icon:Qe,color:"text-muted-foreground"},commands:{label:"Commands",icon:He,color:"text-muted-foreground"},settings:{label:"Settings",icon:Ke,color:"text-muted-foreground"}};function Q(l,e,i){const n=[];for(const s of l)s.type==="directory"&&s.children?n.push(...Q(s.children,e,i)):s.type==="file"&&n.push({name:s.name,path:s.path,fileType:s.fileType||"unknown",description:s.description||"",scope:e,pluginName:i,readOnly:s.readOnly??e==="plugin",cli:s.cli,linkTarget:s.linkTarget});return n}function ct(l){const e={instructions:[],agents:[],skills:[],commands:[],settings:[]};for(const i of l){const n=Q(i.items,i.scope,i.pluginName);for(const s of n)switch(s.fileType){case"instructions":e.instructions.push(s);break;case"agent":e.agents.push(s);break;case"skill":e.skills.push(s);break;case"command":e.commands.push(s);break;case"settings":default:e.settings.push(s)}}return e}function ge(l){const e=G.c(5),{scope:i,pluginName:n}=l;if(i==="plugin"&&n){let r;e[0]===Symbol.for("react.memo_cache_sentinel")?(r=t.jsx(We,{"data-icon":"inline-start",className:"size-3"}),e[0]=r):r=e[0];let u;return e[1]!==n?(u=t.jsxs("span",{className:"flex shrink-0 items-center gap-1 text-xs text-muted-foreground",children:[r,n]}),e[1]=n,e[2]=u):u=e[2],u}if(i==="project"){let r;return e[3]===Symbol.for("react.memo_cache_sentinel")?(r=t.jsxs("span",{className:"flex shrink-0 items-center gap-1 text-xs text-muted-foreground",children:[t.jsx(xe,{"data-icon":"inline-start",className:"size-3"}),"project"]}),e[3]=r):r=e[3],r}let s;return e[4]===Symbol.for("react.memo_cache_sentinel")?(s=t.jsxs("span",{className:"flex shrink-0 items-center gap-1 text-xs text-muted-foreground",children:[t.jsx(fe,{"data-icon":"inline-start",className:"size-3"}),"global"]}),e[4]=s):s=e[4],s}const dt=Object.fromEntries(ye().map(l=>[l.kind,Ce(l.kind)]));function pe(l){const e=G.c(10),{cli:i,variant:n}=l,s=n===void 0?"compact":n;if(!i)return null;if(i.length===0){let m;e[0]===Symbol.for("react.memo_cache_sentinel")?(m=t.jsx(Xe,{"data-icon":"inline-start",className:"size-3"}),e[0]=m):m=e[0];const c=s==="full"&&"unlinked";let d;return e[1]!==c?(d=t.jsxs("span",{className:"flex shrink-0 items-center gap-1 text-xs text-warning",title:"Present in the shared source directory but not linked into any CLI",children:[m,c]}),e[1]=c,e[2]=d):d=e[2],d}let r;if(e[3]!==i||e[4]!==s){let m;e[6]!==s?(m=c=>{const d=dt[c];return t.jsx("span",{title:d.label,className:s==="full"?"flex h-5 items-center justify-center rounded border bg-muted px-1.5 text-xs font-medium text-muted-foreground":"flex size-5 items-center justify-center rounded border bg-muted text-xs font-medium text-muted-foreground",children:s==="full"?c:d.letter},c)},e[6]=s,e[7]=m):m=e[7],r=i.map(m),e[3]=i,e[4]=s,e[5]=r}else r=e[5];let u;return e[8]!==r?(u=t.jsx("span",{className:"flex items-center gap-0.5 shrink-0",children:r}),e[8]=r,e[9]=u):u=e[9],u}function je(l){const e=G.c(10),{linkTarget:i,variant:n,className:s}=l,r=n===void 0?"compact":n;if(!i)return null;let u;e[0]!==s?(u=F("flex min-w-0 shrink-0 items-center gap-1 text-info",s),e[0]=s,e[1]=u):u=e[1];const m=`Symlink → ${i}`;let c;e[2]===Symbol.for("react.memo_cache_sentinel")?(c=t.jsx(qe,{"data-icon":"inline-start",className:"size-3 shrink-0"}),e[2]=c):c=e[2];let d;e[3]!==i||e[4]!==r?(d=r==="full"&&t.jsxs("span",{className:"truncate font-mono text-xs",children:["→ ",i]}),e[3]=i,e[4]=r,e[5]=d):d=e[5];let p;return e[6]!==u||e[7]!==m||e[8]!==d?(p=t.jsxs("span",{className:u,title:m,children:[c,d]}),e[6]=u,e[7]=m,e[8]=d,e[9]=p):p=e[9],p}function ut({globalDir:l,projectDir:e,fileType:i,onCreated:n,onCancel:s}){const[r,u]=o.useState(""),[m,c]=o.useState(e?"project":"global"),[d,p]=o.useState(!1),w=o.useRef(null),y=o.useId();o.useEffect(()=>{var x;(x=w.current)==null||x.focus()},[]);const k=m==="project"&&e?e:l,b=!!l&&!!e;async function S(){if(!(!r.trim()||!k)){p(!0);try{const x=await A("/api/config-browser/create",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({dir:k,fileType:i,name:r.trim()})});if(x.ok){const g=await x.json();n(g.path,i,m)}}finally{p(!1)}}}return t.jsxs(ke,{className:"gap-3 px-3 py-2",children:[b&&t.jsxs(X,{children:[t.jsx(q,{children:"Scope"}),t.jsxs(ve,{"aria-label":"File scope",value:[m],onValueChange:x=>{const g=x[0];(g==="global"||g==="project")&&c(g)},variant:"outline",size:"sm",spacing:0,className:"w-full",children:[t.jsxs(Z,{value:"global",className:"flex-1",children:[t.jsx(fe,{"data-icon":"inline-start"}),"Global"]}),t.jsxs(Z,{value:"project",className:"flex-1",children:[t.jsx(xe,{"data-icon":"inline-start"}),"Project"]})]})]}),t.jsxs(X,{children:[t.jsxs(q,{htmlFor:y,children:[i.charAt(0).toUpperCase()+i.slice(1)," name"]}),t.jsxs("div",{className:"flex items-center gap-1",children:[t.jsx(ae,{id:y,ref:w,type:"text",value:r,onChange:x=>u(x.target.value),onKeyDown:x=>{x.key==="Enter"&&S(),x.key==="Escape"&&s()},placeholder:`${i} name...`,className:"h-7 min-w-0 flex-1 text-xs",disabled:d}),t.jsx(I,{variant:"ghost",size:"icon-xs","aria-label":`Create ${i}`,onClick:()=>void S(),disabled:d||!r.trim()||!k,children:t.jsx(K,{"data-icon":"inline-start"})}),t.jsx(I,{variant:"ghost",size:"icon-xs","aria-label":"Cancel create",onClick:s,children:t.jsx(H,{"data-icon":"inline-start"})})]})]})]})}function mt(l){const e=G.c(50),{category:i,items:n,selectedPath:s,onSelect:r,onNewFile:u,onDeleteItem:m,onRenameItem:c,renamingPath:d,renameValue:p,onRenameValueChange:w,onRenameSubmit:y,onRenameCancel:k,creatingInCategory:b,onCreated:S,onCancelCreate:x}=l,g=ot[i],C=g.icon;if(n.length===0&&!u)return null;let N;e[0]!==g.color?(N=F("size-3.5",g.color),e[0]=g.color,e[1]=N):N=e[1];let v;e[2]!==C||e[3]!==N?(v=t.jsx(C,{"data-icon":"inline-start",className:N}),e[2]=C,e[3]=N,e[4]=v):v=e[4];let T;e[5]!==g.label?(T=t.jsx("span",{className:"flex-1 text-xs font-medium text-muted-foreground",children:g.label}),e[5]=g.label,e[6]=T):T=e[6];let E;e[7]!==n.length?(E=t.jsx("span",{className:"text-xs tabular-nums text-muted-foreground",children:n.length}),e[7]=n.length,e[8]=E):E=e[8];let f;e[9]!==i||e[10]!==u?(f=u&&t.jsxs(Ne,{children:[t.jsx(Se,{render:t.jsx(I,{variant:"ghost",size:"icon-xs",className:"opacity-0 transition-opacity group-hover:opacity-100","aria-label":`New ${i.slice(0,-1)}`,onClick:u}),children:t.jsx(Ze,{"data-icon":"inline-start"})}),t.jsxs(we,{children:["New ",i.slice(0,-1)]})]}),e[9]=i,e[10]=u,e[11]=f):f=e[11];let D;e[12]!==v||e[13]!==T||e[14]!==E||e[15]!==f?(D=t.jsxs("div",{className:"group flex h-8 items-center gap-1.5 px-3",children:[v,T,E,f]}),e[12]=v,e[13]=T,e[14]=E,e[15]=f,e[16]=D):D=e[16];let z;if(e[17]!==n||e[18]!==m||e[19]!==k||e[20]!==c||e[21]!==y||e[22]!==w||e[23]!==r||e[24]!==p||e[25]!==d||e[26]!==s){let B;e[28]!==m||e[29]!==k||e[30]!==c||e[31]!==y||e[32]!==w||e[33]!==r||e[34]!==p||e[35]!==d||e[36]!==s?(B=j=>{const U=s===j.path;if(d===j.path)return t.jsxs("div",{className:"flex items-center gap-1 border-l-2 border-foreground/30 bg-accent px-3 py-1",children:[t.jsx(ae,{value:p,onChange:$=>w($.target.value),onKeyDown:$=>{$.key==="Enter"&&y(),$.key==="Escape"&&k()},autoFocus:!0,className:"h-7 min-w-0 flex-1 text-xs"}),t.jsx(I,{variant:"ghost",size:"icon-xs","aria-label":"Save name",onClick:y,disabled:!p.trim(),children:t.jsx(K,{"data-icon":"inline-start"})}),t.jsx(I,{variant:"ghost",size:"icon-xs","aria-label":"Cancel rename",onClick:k,children:t.jsx(H,{"data-icon":"inline-start"})})]},j.path);const M=t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"min-w-0 flex-1",children:[t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx("span",{className:"truncate text-sm",children:j.name}),t.jsx(je,{linkTarget:j.linkTarget}),j.readOnly&&t.jsx(he,{className:"size-2.5 shrink-0 text-muted-foreground/40"})]}),j.description&&t.jsx("p",{className:"mt-0.5 truncate text-xs text-muted-foreground",children:j.description})]}),t.jsx(pe,{cli:j.cli}),t.jsx(ge,{scope:j.scope,pluginName:j.pluginName})]}),P=F("flex w-full items-center gap-2 border-l-2 px-3 py-2 text-left text-sm transition-colors",U?"border-foreground/30 bg-accent text-accent-foreground":"border-transparent text-muted-foreground hover:bg-accent hover:text-foreground");return!m||!c?t.jsx("button",{type:"button",className:P,onClick:()=>r(j),children:M},j.path):t.jsxs(De,{children:[t.jsx(Te,{render:t.jsx("button",{type:"button",className:P,onClick:()=>r(j)}),children:M}),t.jsx(Ee,{className:"min-w-36",children:j.readOnly?t.jsx(V,{children:t.jsx(Re,{children:"Read-only file"})}):t.jsxs(t.Fragment,{children:[t.jsx(V,{children:t.jsx(ee,{onClick:()=>c(j),children:"Rename"})}),t.jsx(Oe,{}),t.jsx(V,{children:t.jsx(ee,{variant:"destructive",onClick:()=>m(j),children:"Delete"})})]})})]},j.path)},e[28]=m,e[29]=k,e[30]=c,e[31]=y,e[32]=w,e[33]=r,e[34]=p,e[35]=d,e[36]=s,e[37]=B):B=e[37],z=n.map(B),e[17]=n,e[18]=m,e[19]=k,e[20]=c,e[21]=y,e[22]=w,e[23]=r,e[24]=p,e[25]=d,e[26]=s,e[27]=z}else z=e[27];let R;e[38]!==b||e[39]!==n.length?(R=n.length===0&&!b&&t.jsx("p",{className:"px-3 py-1 text-xs text-muted-foreground",children:"None configured"}),e[38]=b,e[39]=n.length,e[40]=R):R=e[40];let O;e[41]!==b||e[42]!==x||e[43]!==S?(O=b&&t.jsx(ut,{globalDir:b.globalDir,projectDir:b.projectDir,fileType:b.fileType,onCreated:S,onCancel:x}),e[41]=b,e[42]=x,e[43]=S,e[44]=O):O=e[44];let L;return e[45]!==D||e[46]!==z||e[47]!==R||e[48]!==O?(L=t.jsxs("section",{children:[D,z,R,O]}),e[45]=D,e[46]=z,e[47]=R,e[48]=O,e[49]=L):L=e[49],L}function xt({file:l,onDeleted:e,readOnly:i=!1}){const[n,s]=o.useState(null),[r,u]=o.useState(null),[m,c]=o.useState(!0),[d,p]=o.useState(!1),[w,y]=o.useState(!1),[k,b]=o.useState(!1),[S,x]=o.useState(!1),g=n!==null&&n!==r,C=i||l.readOnly;o.useEffect(()=>{c(!0),s(null),u(null),y(!1),b(!1),A(`/api/config-browser/file?path=${encodeURIComponent(l.path)}`).then(f=>f.json()).then(f=>{s(f.content??""),u(f.content??"")}).catch(()=>{s(""),u("")}).finally(()=>c(!1))},[l.path]);const N=o.useCallback(async()=>{if(!(!g||C)){p(!0);try{(await A("/api/config-browser/file",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:l.path,content:n})})).ok&&(u(n),y(!0),setTimeout(()=>y(!1),2e3))}finally{p(!1)}}},[n,l.path,g,C]),v=o.useCallback(()=>{s(r)},[r]),T=o.useCallback(async()=>{if(!C){x(!0);try{(await A(`/api/config-browser/file?path=${encodeURIComponent(l.path)}`,{method:"DELETE"})).ok&&(b(!1),e())}catch{}finally{x(!1)}}},[l.path,C,e]);o.useEffect(()=>{function f(D){!C&&(D.metaKey||D.ctrlKey)&&D.key==="s"&&(D.preventDefault(),N())}return window.addEventListener("keydown",f),()=>window.removeEventListener("keydown",f)},[N,C]);function E(){return w?"Saved!":d?"Saving...":"Save"}return t.jsxs("div",{className:"flex flex-1 flex-col min-h-0 min-w-0",children:[t.jsxs("div",{className:"flex min-h-11 shrink-0 items-center gap-2 border-b bg-card px-4 py-2",children:[t.jsx(te,{variant:"outline",className:F("h-5 text-xs",it[l.fileType]||"bg-muted text-muted-foreground"),children:l.fileType}),t.jsx(ge,{scope:l.scope,pluginName:l.pluginName}),t.jsx(pe,{cli:l.cli,variant:"full"}),C&&t.jsxs(te,{variant:"outline",className:"h-5 bg-muted text-xs text-muted-foreground",children:[t.jsx(he,{"data-icon":"inline-start",className:"size-3"})," read-only"]}),g&&t.jsx("span",{className:"size-2 shrink-0 rounded-full bg-warning",title:"Unsaved changes"}),t.jsxs("div",{className:"flex items-center gap-2 ml-auto min-w-0",children:[t.jsx(je,{linkTarget:l.linkTarget,variant:"full"}),t.jsx("span",{className:"truncate font-mono text-xs text-muted-foreground",title:l.path,children:l.path})]})]}),m?t.jsx("div",{className:"flex-1 flex items-center justify-center text-muted-foreground text-sm",children:"Loading..."}):t.jsxs("div",{className:"flex-1 min-h-0 overflow-hidden flex flex-col",children:[t.jsx(lt,{value:n??"",onChange:s,readOnly:C,filePath:l.path}),!C&&t.jsxs("div",{className:"flex shrink-0 items-center gap-2 border-t bg-card px-4 py-2",children:[t.jsxs(I,{size:"xs",onClick:N,disabled:!g||d,children:[t.jsx(K,{"data-icon":"inline-start"}),E()]}),t.jsxs(I,{variant:"outline",size:"xs",onClick:v,disabled:!g,children:[t.jsx(et,{"data-icon":"inline-start"}),"Discard"]}),t.jsx("div",{className:"flex-1"}),t.jsxs(le,{open:k,onOpenChange:b,children:[t.jsxs(Ie,{render:t.jsx(I,{variant:"outline",size:"xs"}),children:[t.jsx(tt,{"data-icon":"inline-start"}),"Delete"]}),t.jsxs(ie,{size:"sm",children:[t.jsxs(re,{children:[t.jsx(oe,{children:"Delete configuration file?"}),t.jsxs(ce,{children:['Delete "',l.name,'" permanently? This action cannot be undone.']})]}),t.jsxs(de,{children:[t.jsx(ue,{size:"sm",disabled:S,children:"Cancel"}),t.jsxs(me,{variant:"destructive",size:"sm",disabled:S,onClick:()=>void T(),children:[S&&t.jsx(ze,{"data-icon":"inline-start"}),S?"Deleting...":"Delete file"]})]})]})]})]})]})]})}function ft(){const l=G.c(1);let e;return l[0]===Symbol.for("react.memo_cache_sentinel")?(e=t.jsx(Ae,{className:"border-0",children:t.jsxs(Le,{children:[t.jsx(Be,{variant:"icon",children:t.jsx(nt,{})}),t.jsx($e,{children:"Select a configuration file"}),t.jsx(Fe,{children:"Browse instructions, agents, skills, commands, and settings from the sidebar."})]})}),l[0]=e):e=l[0],e}function ht(l){return l.cli?l.cli.length>0?l.cli.join(" "):"unlinked":""}function gt(l,e){if(!e)return l;const i=e.toLowerCase();return l.filter(n=>[n.name,n.description,n.path,n.linkTarget??"",ht(n)].some(r=>r.toLowerCase().includes(i)))}const kt=o.memo(function({projectPath:e,initialFilePath:i}){var J,W;const n=Ge("configWrite"),[s,r]=o.useState([]),[u,m]=o.useState(!0),[c,d]=o.useState(null),[p,w]=o.useState(!1),[y,k]=o.useState(null),[b,S]=o.useState(""),[x,g]=o.useState(null),[C,N]=o.useState(""),[v,T]=o.useState(null),E=o.useRef(!1),f=o.useCallback(async()=>{if(!n){r([]),d(null),m(!1);return}m(!0);try{const a=e?`/api/config-browser/tree?cwd=${encodeURIComponent(e)}`:"/api/config-browser/tree",h=await A(a);if(h.ok){const _=await h.json();r(_.sections||[])}}finally{m(!1)}},[n,e]);o.useEffect(()=>{f()},[f]),o.useEffect(()=>{if(!i||u||E.current)return;const a=s.flatMap(h=>Q(h.items,h.scope,h.pluginName)).find(h=>h.path===i);a&&(d(a),E.current=!0)},[i,u,s]);const D=ct(s),z=Object.fromEntries(se.map(a=>[a,gt(D[a],b)])),R=(J=s.find(a=>a.scope==="global"))==null?void 0:J.baseDir,O=(W=s.find(a=>a.scope==="project"))==null?void 0:W.baseDir,L=o.useCallback(a=>{d(a),w(!1),k(null)},[]),B=o.useCallback((a,h,_)=>{k(null),f(),d({path:a,name:a.split("/").pop()||"",fileType:h,readOnly:!1,scope:_,description:""})},[f]),j=o.useCallback(()=>{d(null),f()},[f]),U=o.useCallback(a=>{if(!n||!R&&!O)return;const h=rt[a];h&&k({category:a,globalDir:R?`${R}/${h.subdir}`:null,projectDir:O?`${O}/${h.subdir}`:null,fileType:h.fileType})},[n,R,O]),Y=o.useCallback(a=>{!n||a.readOnly||T(a)},[n]),M=o.useCallback(async()=>{if(!n||!v||v.readOnly)return;const a=v;T(null);try{(await A(`/api/config-browser/file?path=${encodeURIComponent(a.path)}`,{method:"DELETE"})).ok&&((c==null?void 0:c.path)===a.path&&d(null),f())}catch{}},[n,f,v,c]),P=o.useCallback(a=>{if(!n||a.readOnly)return;const h=a.name==="SKILL.md"?a.path.split("/").slice(-2,-1)[0]||a.name:a.name.replace(/\.[^.]+$/,"");g(a),N(h)},[n]),$=o.useCallback(async()=>{if(!(!n||!x||!C.trim()))try{const a=await A("/api/config-browser/rename",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({oldPath:x.path,newName:C.trim()})});if(a.ok){const h=await a.json();g(null),N(""),await f(),h.newPath&&d({...x,path:h.newPath,name:h.newPath.split("/").pop()||x.name})}}catch{}},[n,x,C,f]),be=o.useCallback(()=>{g(null),N("")},[]);return n?t.jsxs("div",{className:"flex flex-1 min-h-0 min-w-0",children:[t.jsxs("div",{className:F("min-h-0 shrink-0 flex-col border-r bg-sidebar md:flex md:w-80",c&&!p?"hidden":"flex w-full"),children:[t.jsxs("div",{className:"flex h-11 items-center gap-2 border-b px-3",children:[t.jsx("span",{className:"text-sm font-medium text-foreground",children:"Configuration"}),e&&t.jsx("span",{className:"ml-auto truncate text-xs text-muted-foreground",title:e,children:e.split("/").pop()})]}),t.jsx("div",{className:"border-b p-2",children:t.jsxs(Me,{children:[t.jsx(ne,{children:t.jsx(st,{"data-icon":"inline-start"})}),t.jsx(Pe,{value:b,onChange:a=>S(a.target.value),placeholder:"Search configuration"}),b&&t.jsx(ne,{align:"inline-end",children:t.jsx(Ue,{size:"icon-xs","aria-label":"Clear search",onClick:()=>S(""),children:t.jsx(H,{"data-icon":"inline-start"})})})]})}),t.jsx(_e,{className:"flex-1",children:t.jsx("div",{className:"flex flex-col gap-1 py-2",children:u?t.jsx("div",{className:"flex flex-col gap-2 px-3 py-2","aria-label":"Loading configuration",children:Array.from({length:6},(a,h)=>t.jsx(Ve,{className:"h-8 w-full"},h))}):se.map(a=>{const h=a==="agents"||a==="skills"||a==="commands";return t.jsx(mt,{category:a,items:z[a],selectedPath:(c==null?void 0:c.path)??null,onSelect:L,onNewFile:n&&h?()=>U(a):void 0,onDeleteItem:n?Y:void 0,onRenameItem:n?P:void 0,renamingPath:(x==null?void 0:x.path)??null,renameValue:C,onRenameValueChange:N,onRenameSubmit:$,onRenameCancel:be,creatingInCategory:n&&(y==null?void 0:y.category)===a?y:null,onCreated:B,onCancelCreate:()=>k(null)},a)})})})]}),t.jsx("div",{className:F("min-h-0 min-w-0 flex-1 flex-col md:flex",c&&!p?"flex":"hidden"),children:c?t.jsxs(t.Fragment,{children:[t.jsxs(I,{variant:"ghost",className:"min-h-11 shrink-0 justify-start md:hidden",onClick:()=>w(!0),children:[t.jsx(at,{"data-icon":"inline-start"}),"All configuration files"]}),t.jsx(xt,{file:c,onDeleted:j,readOnly:!n})]}):t.jsx(ft,{})}),t.jsx(le,{open:v!==null,onOpenChange:a=>{a||T(null)},children:t.jsxs(ie,{size:"sm",children:[t.jsxs(re,{children:[t.jsx(oe,{children:"Delete configuration file?"}),t.jsxs(ce,{children:['Delete "',v==null?void 0:v.name,'" permanently? This action cannot be undone.']})]}),t.jsxs(de,{children:[t.jsx(ue,{size:"sm",children:"Cancel"}),t.jsx(me,{variant:"destructive",size:"sm",onClick:()=>void M(),children:"Delete file"})]})]})})]}):t.jsx("div",{className:"flex flex-1 items-center justify-center text-sm text-muted-foreground",children:"Server configuration is available to administrators only."})});export{kt as ConfigBrowser};
1
+ import{c as G,j as t,r as o}from"./vendor-react-gGw_S5I_.js";import{by as ye,bN as Ce,c as F,aC as ke,ae as X,ac as q,aB as ve,aA as Z,au as ae,B as I,F as A,bO as Ne,bP as Se,bQ as we,bR as De,bS as Te,bT as Ee,bU as V,bV as Re,bW as ee,bX as Oe,k as te,aa as le,bY as Ie,a9 as ie,a5 as re,a3 as oe,a4 as ce,a7 as de,a6 as ue,a8 as me,x as ze,E as Ae,f as Le,U as Be,h as $e,i as Fe,b7 as Ge,az as Me,ax as ne,aw as Pe,ay as Ue,m as _e,bZ as Ve}from"./index-BVmNox_3.js";import{b_ as Ke,a3 as He,a5 as Qe,bx as Ye,dm as Je,U as We,dn as xe,aB as fe,dp as Xe,dq as qe,dr as K,X as H,bg as Ze,cU as he,ds as et,b0 as tt,bP as nt,ak as st,cM as at}from"./vendor-ui-CKjyvB3_.js";import{H as lt}from"./HighlightedEditor-DPrSCx1c.js";import"./vendor-markdown-BEJ8yVzA.js";const it={agent:"bg-muted text-muted-foreground",skill:"bg-muted text-muted-foreground",command:"bg-muted text-muted-foreground",instructions:"bg-muted text-muted-foreground",settings:"bg-muted text-muted-foreground"},rt={agents:{subdir:"agents",fileType:"agent"},skills:{subdir:"skills",fileType:"skill"},commands:{subdir:"commands",fileType:"command"}},se=["instructions","agents","skills","commands","settings"],ot={instructions:{label:"Instructions",icon:Je,color:"text-muted-foreground"},agents:{label:"Agents",icon:Ye,color:"text-muted-foreground"},skills:{label:"Skills",icon:Qe,color:"text-muted-foreground"},commands:{label:"Commands",icon:He,color:"text-muted-foreground"},settings:{label:"Settings",icon:Ke,color:"text-muted-foreground"}};function Q(l,e,i){const n=[];for(const s of l)s.type==="directory"&&s.children?n.push(...Q(s.children,e,i)):s.type==="file"&&n.push({name:s.name,path:s.path,fileType:s.fileType||"unknown",description:s.description||"",scope:e,pluginName:i,readOnly:s.readOnly??e==="plugin",cli:s.cli,linkTarget:s.linkTarget});return n}function ct(l){const e={instructions:[],agents:[],skills:[],commands:[],settings:[]};for(const i of l){const n=Q(i.items,i.scope,i.pluginName);for(const s of n)switch(s.fileType){case"instructions":e.instructions.push(s);break;case"agent":e.agents.push(s);break;case"skill":e.skills.push(s);break;case"command":e.commands.push(s);break;case"settings":default:e.settings.push(s)}}return e}function ge(l){const e=G.c(5),{scope:i,pluginName:n}=l;if(i==="plugin"&&n){let r;e[0]===Symbol.for("react.memo_cache_sentinel")?(r=t.jsx(We,{"data-icon":"inline-start",className:"size-3"}),e[0]=r):r=e[0];let u;return e[1]!==n?(u=t.jsxs("span",{className:"flex shrink-0 items-center gap-1 text-xs text-muted-foreground",children:[r,n]}),e[1]=n,e[2]=u):u=e[2],u}if(i==="project"){let r;return e[3]===Symbol.for("react.memo_cache_sentinel")?(r=t.jsxs("span",{className:"flex shrink-0 items-center gap-1 text-xs text-muted-foreground",children:[t.jsx(xe,{"data-icon":"inline-start",className:"size-3"}),"project"]}),e[3]=r):r=e[3],r}let s;return e[4]===Symbol.for("react.memo_cache_sentinel")?(s=t.jsxs("span",{className:"flex shrink-0 items-center gap-1 text-xs text-muted-foreground",children:[t.jsx(fe,{"data-icon":"inline-start",className:"size-3"}),"global"]}),e[4]=s):s=e[4],s}const dt=Object.fromEntries(ye().map(l=>[l.kind,Ce(l.kind)]));function pe(l){const e=G.c(10),{cli:i,variant:n}=l,s=n===void 0?"compact":n;if(!i)return null;if(i.length===0){let m;e[0]===Symbol.for("react.memo_cache_sentinel")?(m=t.jsx(Xe,{"data-icon":"inline-start",className:"size-3"}),e[0]=m):m=e[0];const c=s==="full"&&"unlinked";let d;return e[1]!==c?(d=t.jsxs("span",{className:"flex shrink-0 items-center gap-1 text-xs text-warning",title:"Present in the shared source directory but not linked into any CLI",children:[m,c]}),e[1]=c,e[2]=d):d=e[2],d}let r;if(e[3]!==i||e[4]!==s){let m;e[6]!==s?(m=c=>{const d=dt[c];return t.jsx("span",{title:d.label,className:s==="full"?"flex h-5 items-center justify-center rounded border bg-muted px-1.5 text-xs font-medium text-muted-foreground":"flex size-5 items-center justify-center rounded border bg-muted text-xs font-medium text-muted-foreground",children:s==="full"?c:d.letter},c)},e[6]=s,e[7]=m):m=e[7],r=i.map(m),e[3]=i,e[4]=s,e[5]=r}else r=e[5];let u;return e[8]!==r?(u=t.jsx("span",{className:"flex items-center gap-0.5 shrink-0",children:r}),e[8]=r,e[9]=u):u=e[9],u}function je(l){const e=G.c(10),{linkTarget:i,variant:n,className:s}=l,r=n===void 0?"compact":n;if(!i)return null;let u;e[0]!==s?(u=F("flex min-w-0 shrink-0 items-center gap-1 text-info",s),e[0]=s,e[1]=u):u=e[1];const m=`Symlink → ${i}`;let c;e[2]===Symbol.for("react.memo_cache_sentinel")?(c=t.jsx(qe,{"data-icon":"inline-start",className:"size-3 shrink-0"}),e[2]=c):c=e[2];let d;e[3]!==i||e[4]!==r?(d=r==="full"&&t.jsxs("span",{className:"truncate font-mono text-xs",children:["→ ",i]}),e[3]=i,e[4]=r,e[5]=d):d=e[5];let p;return e[6]!==u||e[7]!==m||e[8]!==d?(p=t.jsxs("span",{className:u,title:m,children:[c,d]}),e[6]=u,e[7]=m,e[8]=d,e[9]=p):p=e[9],p}function ut({globalDir:l,projectDir:e,fileType:i,onCreated:n,onCancel:s}){const[r,u]=o.useState(""),[m,c]=o.useState(e?"project":"global"),[d,p]=o.useState(!1),w=o.useRef(null),y=o.useId();o.useEffect(()=>{var x;(x=w.current)==null||x.focus()},[]);const k=m==="project"&&e?e:l,b=!!l&&!!e;async function S(){if(!(!r.trim()||!k)){p(!0);try{const x=await A("/api/config-browser/create",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({dir:k,fileType:i,name:r.trim()})});if(x.ok){const g=await x.json();n(g.path,i,m)}}finally{p(!1)}}}return t.jsxs(ke,{className:"gap-3 px-3 py-2",children:[b&&t.jsxs(X,{children:[t.jsx(q,{children:"Scope"}),t.jsxs(ve,{"aria-label":"File scope",value:[m],onValueChange:x=>{const g=x[0];(g==="global"||g==="project")&&c(g)},variant:"outline",size:"sm",spacing:0,className:"w-full",children:[t.jsxs(Z,{value:"global",className:"flex-1",children:[t.jsx(fe,{"data-icon":"inline-start"}),"Global"]}),t.jsxs(Z,{value:"project",className:"flex-1",children:[t.jsx(xe,{"data-icon":"inline-start"}),"Project"]})]})]}),t.jsxs(X,{children:[t.jsxs(q,{htmlFor:y,children:[i.charAt(0).toUpperCase()+i.slice(1)," name"]}),t.jsxs("div",{className:"flex items-center gap-1",children:[t.jsx(ae,{id:y,ref:w,type:"text",value:r,onChange:x=>u(x.target.value),onKeyDown:x=>{x.key==="Enter"&&S(),x.key==="Escape"&&s()},placeholder:`${i} name...`,className:"h-7 min-w-0 flex-1 text-xs",disabled:d}),t.jsx(I,{variant:"ghost",size:"icon-xs","aria-label":`Create ${i}`,onClick:()=>void S(),disabled:d||!r.trim()||!k,children:t.jsx(K,{"data-icon":"inline-start"})}),t.jsx(I,{variant:"ghost",size:"icon-xs","aria-label":"Cancel create",onClick:s,children:t.jsx(H,{"data-icon":"inline-start"})})]})]})]})}function mt(l){const e=G.c(50),{category:i,items:n,selectedPath:s,onSelect:r,onNewFile:u,onDeleteItem:m,onRenameItem:c,renamingPath:d,renameValue:p,onRenameValueChange:w,onRenameSubmit:y,onRenameCancel:k,creatingInCategory:b,onCreated:S,onCancelCreate:x}=l,g=ot[i],C=g.icon;if(n.length===0&&!u)return null;let N;e[0]!==g.color?(N=F("size-3.5",g.color),e[0]=g.color,e[1]=N):N=e[1];let v;e[2]!==C||e[3]!==N?(v=t.jsx(C,{"data-icon":"inline-start",className:N}),e[2]=C,e[3]=N,e[4]=v):v=e[4];let T;e[5]!==g.label?(T=t.jsx("span",{className:"flex-1 text-xs font-medium text-muted-foreground",children:g.label}),e[5]=g.label,e[6]=T):T=e[6];let E;e[7]!==n.length?(E=t.jsx("span",{className:"text-xs tabular-nums text-muted-foreground",children:n.length}),e[7]=n.length,e[8]=E):E=e[8];let f;e[9]!==i||e[10]!==u?(f=u&&t.jsxs(Ne,{children:[t.jsx(Se,{render:t.jsx(I,{variant:"ghost",size:"icon-xs",className:"opacity-0 transition-opacity group-hover:opacity-100","aria-label":`New ${i.slice(0,-1)}`,onClick:u}),children:t.jsx(Ze,{"data-icon":"inline-start"})}),t.jsxs(we,{children:["New ",i.slice(0,-1)]})]}),e[9]=i,e[10]=u,e[11]=f):f=e[11];let D;e[12]!==v||e[13]!==T||e[14]!==E||e[15]!==f?(D=t.jsxs("div",{className:"group flex h-8 items-center gap-1.5 px-3",children:[v,T,E,f]}),e[12]=v,e[13]=T,e[14]=E,e[15]=f,e[16]=D):D=e[16];let z;if(e[17]!==n||e[18]!==m||e[19]!==k||e[20]!==c||e[21]!==y||e[22]!==w||e[23]!==r||e[24]!==p||e[25]!==d||e[26]!==s){let B;e[28]!==m||e[29]!==k||e[30]!==c||e[31]!==y||e[32]!==w||e[33]!==r||e[34]!==p||e[35]!==d||e[36]!==s?(B=j=>{const U=s===j.path;if(d===j.path)return t.jsxs("div",{className:"flex items-center gap-1 border-l-2 border-foreground/30 bg-accent px-3 py-1",children:[t.jsx(ae,{value:p,onChange:$=>w($.target.value),onKeyDown:$=>{$.key==="Enter"&&y(),$.key==="Escape"&&k()},autoFocus:!0,className:"h-7 min-w-0 flex-1 text-xs"}),t.jsx(I,{variant:"ghost",size:"icon-xs","aria-label":"Save name",onClick:y,disabled:!p.trim(),children:t.jsx(K,{"data-icon":"inline-start"})}),t.jsx(I,{variant:"ghost",size:"icon-xs","aria-label":"Cancel rename",onClick:k,children:t.jsx(H,{"data-icon":"inline-start"})})]},j.path);const M=t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"min-w-0 flex-1",children:[t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx("span",{className:"truncate text-sm",children:j.name}),t.jsx(je,{linkTarget:j.linkTarget}),j.readOnly&&t.jsx(he,{className:"size-2.5 shrink-0 text-muted-foreground/40"})]}),j.description&&t.jsx("p",{className:"mt-0.5 truncate text-xs text-muted-foreground",children:j.description})]}),t.jsx(pe,{cli:j.cli}),t.jsx(ge,{scope:j.scope,pluginName:j.pluginName})]}),P=F("flex w-full items-center gap-2 border-l-2 px-3 py-2 text-left text-sm transition-colors",U?"border-foreground/30 bg-accent text-accent-foreground":"border-transparent text-muted-foreground hover:bg-accent hover:text-foreground");return!m||!c?t.jsx("button",{type:"button",className:P,onClick:()=>r(j),children:M},j.path):t.jsxs(De,{children:[t.jsx(Te,{render:t.jsx("button",{type:"button",className:P,onClick:()=>r(j)}),children:M}),t.jsx(Ee,{className:"min-w-36",children:j.readOnly?t.jsx(V,{children:t.jsx(Re,{children:"Read-only file"})}):t.jsxs(t.Fragment,{children:[t.jsx(V,{children:t.jsx(ee,{onClick:()=>c(j),children:"Rename"})}),t.jsx(Oe,{}),t.jsx(V,{children:t.jsx(ee,{variant:"destructive",onClick:()=>m(j),children:"Delete"})})]})})]},j.path)},e[28]=m,e[29]=k,e[30]=c,e[31]=y,e[32]=w,e[33]=r,e[34]=p,e[35]=d,e[36]=s,e[37]=B):B=e[37],z=n.map(B),e[17]=n,e[18]=m,e[19]=k,e[20]=c,e[21]=y,e[22]=w,e[23]=r,e[24]=p,e[25]=d,e[26]=s,e[27]=z}else z=e[27];let R;e[38]!==b||e[39]!==n.length?(R=n.length===0&&!b&&t.jsx("p",{className:"px-3 py-1 text-xs text-muted-foreground",children:"None configured"}),e[38]=b,e[39]=n.length,e[40]=R):R=e[40];let O;e[41]!==b||e[42]!==x||e[43]!==S?(O=b&&t.jsx(ut,{globalDir:b.globalDir,projectDir:b.projectDir,fileType:b.fileType,onCreated:S,onCancel:x}),e[41]=b,e[42]=x,e[43]=S,e[44]=O):O=e[44];let L;return e[45]!==D||e[46]!==z||e[47]!==R||e[48]!==O?(L=t.jsxs("section",{children:[D,z,R,O]}),e[45]=D,e[46]=z,e[47]=R,e[48]=O,e[49]=L):L=e[49],L}function xt({file:l,onDeleted:e,readOnly:i=!1}){const[n,s]=o.useState(null),[r,u]=o.useState(null),[m,c]=o.useState(!0),[d,p]=o.useState(!1),[w,y]=o.useState(!1),[k,b]=o.useState(!1),[S,x]=o.useState(!1),g=n!==null&&n!==r,C=i||l.readOnly;o.useEffect(()=>{c(!0),s(null),u(null),y(!1),b(!1),A(`/api/config-browser/file?path=${encodeURIComponent(l.path)}`).then(f=>f.json()).then(f=>{s(f.content??""),u(f.content??"")}).catch(()=>{s(""),u("")}).finally(()=>c(!1))},[l.path]);const N=o.useCallback(async()=>{if(!(!g||C)){p(!0);try{(await A("/api/config-browser/file",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:l.path,content:n})})).ok&&(u(n),y(!0),setTimeout(()=>y(!1),2e3))}finally{p(!1)}}},[n,l.path,g,C]),v=o.useCallback(()=>{s(r)},[r]),T=o.useCallback(async()=>{if(!C){x(!0);try{(await A(`/api/config-browser/file?path=${encodeURIComponent(l.path)}`,{method:"DELETE"})).ok&&(b(!1),e())}catch{}finally{x(!1)}}},[l.path,C,e]);o.useEffect(()=>{function f(D){!C&&(D.metaKey||D.ctrlKey)&&D.key==="s"&&(D.preventDefault(),N())}return window.addEventListener("keydown",f),()=>window.removeEventListener("keydown",f)},[N,C]);function E(){return w?"Saved!":d?"Saving...":"Save"}return t.jsxs("div",{className:"flex flex-1 flex-col min-h-0 min-w-0",children:[t.jsxs("div",{className:"flex min-h-11 shrink-0 items-center gap-2 border-b bg-card px-4 py-2",children:[t.jsx(te,{variant:"outline",className:F("h-5 text-xs",it[l.fileType]||"bg-muted text-muted-foreground"),children:l.fileType}),t.jsx(ge,{scope:l.scope,pluginName:l.pluginName}),t.jsx(pe,{cli:l.cli,variant:"full"}),C&&t.jsxs(te,{variant:"outline",className:"h-5 bg-muted text-xs text-muted-foreground",children:[t.jsx(he,{"data-icon":"inline-start",className:"size-3"})," read-only"]}),g&&t.jsx("span",{className:"size-2 shrink-0 rounded-full bg-warning",title:"Unsaved changes"}),t.jsxs("div",{className:"flex items-center gap-2 ml-auto min-w-0",children:[t.jsx(je,{linkTarget:l.linkTarget,variant:"full"}),t.jsx("span",{className:"truncate font-mono text-xs text-muted-foreground",title:l.path,children:l.path})]})]}),m?t.jsx("div",{className:"flex-1 flex items-center justify-center text-muted-foreground text-sm",children:"Loading..."}):t.jsxs("div",{className:"flex-1 min-h-0 overflow-hidden flex flex-col",children:[t.jsx(lt,{value:n??"",onChange:s,readOnly:C,filePath:l.path}),!C&&t.jsxs("div",{className:"flex shrink-0 items-center gap-2 border-t bg-card px-4 py-2",children:[t.jsxs(I,{size:"xs",onClick:N,disabled:!g||d,children:[t.jsx(K,{"data-icon":"inline-start"}),E()]}),t.jsxs(I,{variant:"outline",size:"xs",onClick:v,disabled:!g,children:[t.jsx(et,{"data-icon":"inline-start"}),"Discard"]}),t.jsx("div",{className:"flex-1"}),t.jsxs(le,{open:k,onOpenChange:b,children:[t.jsxs(Ie,{render:t.jsx(I,{variant:"outline",size:"xs"}),children:[t.jsx(tt,{"data-icon":"inline-start"}),"Delete"]}),t.jsxs(ie,{size:"sm",children:[t.jsxs(re,{children:[t.jsx(oe,{children:"Delete configuration file?"}),t.jsxs(ce,{children:['Delete "',l.name,'" permanently? This action cannot be undone.']})]}),t.jsxs(de,{children:[t.jsx(ue,{size:"sm",disabled:S,children:"Cancel"}),t.jsxs(me,{variant:"destructive",size:"sm",disabled:S,onClick:()=>void T(),children:[S&&t.jsx(ze,{"data-icon":"inline-start"}),S?"Deleting...":"Delete file"]})]})]})]})]})]})]})}function ft(){const l=G.c(1);let e;return l[0]===Symbol.for("react.memo_cache_sentinel")?(e=t.jsx(Ae,{className:"border-0",children:t.jsxs(Le,{children:[t.jsx(Be,{variant:"icon",children:t.jsx(nt,{})}),t.jsx($e,{children:"Select a configuration file"}),t.jsx(Fe,{children:"Browse instructions, agents, skills, commands, and settings from the sidebar."})]})}),l[0]=e):e=l[0],e}function ht(l){return l.cli?l.cli.length>0?l.cli.join(" "):"unlinked":""}function gt(l,e){if(!e)return l;const i=e.toLowerCase();return l.filter(n=>[n.name,n.description,n.path,n.linkTarget??"",ht(n)].some(r=>r.toLowerCase().includes(i)))}const kt=o.memo(function({projectPath:e,initialFilePath:i}){var J,W;const n=Ge("configWrite"),[s,r]=o.useState([]),[u,m]=o.useState(!0),[c,d]=o.useState(null),[p,w]=o.useState(!1),[y,k]=o.useState(null),[b,S]=o.useState(""),[x,g]=o.useState(null),[C,N]=o.useState(""),[v,T]=o.useState(null),E=o.useRef(!1),f=o.useCallback(async()=>{if(!n){r([]),d(null),m(!1);return}m(!0);try{const a=e?`/api/config-browser/tree?cwd=${encodeURIComponent(e)}`:"/api/config-browser/tree",h=await A(a);if(h.ok){const _=await h.json();r(_.sections||[])}}finally{m(!1)}},[n,e]);o.useEffect(()=>{f()},[f]),o.useEffect(()=>{if(!i||u||E.current)return;const a=s.flatMap(h=>Q(h.items,h.scope,h.pluginName)).find(h=>h.path===i);a&&(d(a),E.current=!0)},[i,u,s]);const D=ct(s),z=Object.fromEntries(se.map(a=>[a,gt(D[a],b)])),R=(J=s.find(a=>a.scope==="global"))==null?void 0:J.baseDir,O=(W=s.find(a=>a.scope==="project"))==null?void 0:W.baseDir,L=o.useCallback(a=>{d(a),w(!1),k(null)},[]),B=o.useCallback((a,h,_)=>{k(null),f(),d({path:a,name:a.split("/").pop()||"",fileType:h,readOnly:!1,scope:_,description:""})},[f]),j=o.useCallback(()=>{d(null),f()},[f]),U=o.useCallback(a=>{if(!n||!R&&!O)return;const h=rt[a];h&&k({category:a,globalDir:R?`${R}/${h.subdir}`:null,projectDir:O?`${O}/${h.subdir}`:null,fileType:h.fileType})},[n,R,O]),Y=o.useCallback(a=>{!n||a.readOnly||T(a)},[n]),M=o.useCallback(async()=>{if(!n||!v||v.readOnly)return;const a=v;T(null);try{(await A(`/api/config-browser/file?path=${encodeURIComponent(a.path)}`,{method:"DELETE"})).ok&&((c==null?void 0:c.path)===a.path&&d(null),f())}catch{}},[n,f,v,c]),P=o.useCallback(a=>{if(!n||a.readOnly)return;const h=a.name==="SKILL.md"?a.path.split("/").slice(-2,-1)[0]||a.name:a.name.replace(/\.[^.]+$/,"");g(a),N(h)},[n]),$=o.useCallback(async()=>{if(!(!n||!x||!C.trim()))try{const a=await A("/api/config-browser/rename",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({oldPath:x.path,newName:C.trim()})});if(a.ok){const h=await a.json();g(null),N(""),await f(),h.newPath&&d({...x,path:h.newPath,name:h.newPath.split("/").pop()||x.name})}}catch{}},[n,x,C,f]),be=o.useCallback(()=>{g(null),N("")},[]);return n?t.jsxs("div",{className:"flex flex-1 min-h-0 min-w-0",children:[t.jsxs("div",{className:F("min-h-0 shrink-0 flex-col border-r bg-sidebar md:flex md:w-80",c&&!p?"hidden":"flex w-full"),children:[t.jsxs("div",{className:"flex h-11 items-center gap-2 border-b px-3",children:[t.jsx("span",{className:"text-sm font-medium text-foreground",children:"Configuration"}),e&&t.jsx("span",{className:"ml-auto truncate text-xs text-muted-foreground",title:e,children:e.split("/").pop()})]}),t.jsx("div",{className:"border-b p-2",children:t.jsxs(Me,{children:[t.jsx(ne,{children:t.jsx(st,{"data-icon":"inline-start"})}),t.jsx(Pe,{value:b,onChange:a=>S(a.target.value),placeholder:"Search configuration"}),b&&t.jsx(ne,{align:"inline-end",children:t.jsx(Ue,{size:"icon-xs","aria-label":"Clear search",onClick:()=>S(""),children:t.jsx(H,{"data-icon":"inline-start"})})})]})}),t.jsx(_e,{className:"flex-1",children:t.jsx("div",{className:"flex flex-col gap-1 py-2",children:u?t.jsx("div",{className:"flex flex-col gap-2 px-3 py-2","aria-label":"Loading configuration",children:Array.from({length:6},(a,h)=>t.jsx(Ve,{className:"h-8 w-full"},h))}):se.map(a=>{const h=a==="agents"||a==="skills"||a==="commands";return t.jsx(mt,{category:a,items:z[a],selectedPath:(c==null?void 0:c.path)??null,onSelect:L,onNewFile:n&&h?()=>U(a):void 0,onDeleteItem:n?Y:void 0,onRenameItem:n?P:void 0,renamingPath:(x==null?void 0:x.path)??null,renameValue:C,onRenameValueChange:N,onRenameSubmit:$,onRenameCancel:be,creatingInCategory:n&&(y==null?void 0:y.category)===a?y:null,onCreated:B,onCancelCreate:()=>k(null)},a)})})})]}),t.jsx("div",{className:F("min-h-0 min-w-0 flex-1 flex-col md:flex",c&&!p?"flex":"hidden"),children:c?t.jsxs(t.Fragment,{children:[t.jsxs(I,{variant:"ghost",className:"min-h-11 shrink-0 justify-start md:hidden",onClick:()=>w(!0),children:[t.jsx(at,{"data-icon":"inline-start"}),"All configuration files"]}),t.jsx(xt,{file:c,onDeleted:j,readOnly:!n})]}):t.jsx(ft,{})}),t.jsx(le,{open:v!==null,onOpenChange:a=>{a||T(null)},children:t.jsxs(ie,{size:"sm",children:[t.jsxs(re,{children:[t.jsx(oe,{children:"Delete configuration file?"}),t.jsxs(ce,{children:['Delete "',v==null?void 0:v.name,'" permanently? This action cannot be undone.']})]}),t.jsxs(de,{children:[t.jsx(ue,{size:"sm",children:"Cancel"}),t.jsx(me,{variant:"destructive",size:"sm",onClick:()=>void M(),children:"Delete file"})]})]})})]}):t.jsx("div",{className:"flex flex-1 items-center justify-center text-sm text-muted-foreground",children:"Server configuration is available to administrators only."})});export{kt as ConfigBrowser};
@@ -1 +1 @@
1
- import{r as C,c as ue,j as n}from"./vendor-react-gGw_S5I_.js";import{F as ze,cR as it,a0 as je,cS as jt,cT as yt,cU as Nt,B as te,E as rt,f as ct,U as It,h as dt,i as ut,ae as Qe,cV as Ct,ac as Je,aC as et,cW as kt,cX as St,m as ft,ad as Mt,cY as $t,av as Rt,cv as Tt,cZ as At,cE as Ot,aZ as Et,o as Lt,n as _t,D as zt,j as Dt,c as oe,c_ as Ft,bP as Pt,bQ as Yt,bO as qt,c$ as qe,V as We,d0 as Wt,ct as Ht,c9 as Ut,ca as Bt,cb as Ae,cc as Oe,al as Vt,k as Gt,d1 as Kt,d2 as Xt,d3 as Zt,b8 as Qt}from"./index-BvNyEUVG.js";import{S as Jt}from"./switch-BHG6oFbM.js";import{bU as es,dw as ts,aR as ss,bs as ns,N as ht,bq as mt,bi as os,bz as as,br as ls,A as De,dx as is,aQ as rs,X as cs}from"./vendor-ui-keo4oB2X.js";import"./vendor-markdown-BEJ8yVzA.js";async function ke(t){if(t.ok)return t;const e=await t.json().catch(()=>null);throw new Error((e==null?void 0:e.error)||"Couldn't update crew chat.")}function Ee(t,e){return[...new Map([...t,...e].map(s=>[s.sequence,s])).values()].sort((s,r)=>s.sequence-r.sequence)}function ds(t){const[e,s]=C.useState(null),[r,i]=C.useState([]),[a,c]=C.useState(null),[o,f]=C.useState(!1),[g,h]=C.useState(!1),[l,w]=C.useState(!1),[u,x]=C.useState(new Set),m=C.useRef(0),p=C.useRef(null),y=C.useRef(!1),k=C.useRef(!1),b=C.useRef(new Set),M=C.useRef(!1),N=C.useRef(null),$=C.useCallback(async j=>{const L=++m.current;try{const I=N.current,S=await(await ke(await ze(`/api/crew-chat/${encodeURIComponent(t)}${I===null?"":`?after=${I}&limit=100`}`))).json();if(!j()||L!==m.current)return;s(R=>R&&JSON.stringify(R.members)===JSON.stringify(S.members)?{...S,members:R.members}:S),i(R=>Ee(R,S.messages)),N.current=S.nextCursor,M.current||(M.current=!0,w(S.hasMore)),c(null)}catch(I){j()&&L===m.current&&c(I instanceof Error?I.message:"Couldn't load crew chat.")}},[t]);it($,2e3);const _=C.useCallback(async j=>{var L;if(y.current)return!1;y.current=!0,f(!0),((L=p.current)==null?void 0:L.text)!==j&&(p.current={text:j,id:crypto.randomUUID()});try{const A=await(await ke(await je(`/api/crew-chat/${encodeURIComponent(t)}`,{text:j,commandId:p.current.id}))).json();return m.current++,i(S=>Ee(S,[A.message])),p.current=null,c(A.pending.length?"Message saved. Some members are unavailable; delivery will retry.":null),!0}catch(I){return c(I instanceof Error?I.message:"Couldn't send the message."),!1}finally{y.current=!1,f(!1)}},[t]),O=C.useCallback(async(j,L)=>{if(!b.current.has(j)){b.current.add(j),x(I=>new Set(I).add(j));try{await ke(await je(`/api/crew-chat/${encodeURIComponent(t)}`,{sessionId:j,listening:L},{method:"PATCH"})),m.current++,s(I=>I&&{...I,members:I.members.map(A=>A.sessionId===j?{...A,listening:L}:A)}),c(null)}catch(I){c(I instanceof Error?I.message:"Couldn't change listening.")}finally{b.current.delete(j),x(I=>{const A=new Set(I);return A.delete(j),A})}}},[t]),E=C.useCallback(async()=>{if(!(!r.length||k.current)){k.current=!0,h(!0);try{const L=await(await ke(await ze(`/api/crew-chat/${encodeURIComponent(t)}?before=${r[0].sequence}`))).json();i(I=>Ee(I,L.messages)),w(L.hasMore)}catch(j){c(j instanceof Error?j.message:"Couldn't load older messages.")}finally{k.current=!1,h(!1)}}},[r,t]);return{page:e,messages:r,error:a,posting:o,busyMembers:u,hasOlder:l,loadingOlder:g,post:_,setListening:O,older:E}}const us=[],fs=new Map;function hs(t){var He,Ue,Be,Ve,Ge,Ke,Xe;const e=ue.c(111),{rootId:s,kinds:r,active:i}=t,a=r===void 0?fs:r,c=i===void 0?!0:i,o=ds(s),[f,g]=C.useState(""),h=C.useRef(null),l=C.useRef(!0);let w;e[0]!==o.messages?(w=(He=o.messages.at(-1))==null?void 0:He.sequence,e[0]=o.messages,e[1]=w):w=e[1];const u=w,x=((Ue=o.page)==null?void 0:Ue.members)??us;let m;e[2]!==x?(m=jt(x),e[2]=x,e[3]=m):m=e[3];const p=m;let y;e[4]!==x||e[5]!==s?(y=yt(x,s),e[4]=x,e[5]=s,e[6]=y):y=e[6];const k=y;let b;e[7]!==x?(b=new Map(x.map(ps)),e[7]=x,e[8]=b):b=e[8];const M=b;let N;e[9]!==o.messages||e[10]!==s?(N=Nt(o.messages,s),e[9]=o.messages,e[10]=s,e[11]=N):N=e[11];const $=N;let _;e[12]!==c?(_=()=>{var G,B;c&&l.current&&((B=(G=h.current)==null?void 0:G.scrollIntoView)==null||B.call(G,{block:"end"}))},e[12]=c,e[13]=_):_=e[13];let O;e[14]!==c||e[15]!==u?(O=[c,u],e[14]=c,e[15]=u,e[16]=O):O=e[16],C.useEffect(_,O);let E;e[17]!==o||e[18]!==f?(E=async()=>{const G=f.trim();!G||o.posting||await o.post(G)&&(g(B=>B.trim()===G?"":B),l.current=!0)},e[17]=o,e[18]=f,e[19]=E):E=e[19];const j=E;let L;e[20]!==o.page||e[21]!==x?(L=o.page?`${x.filter(ms).length} listening · Members & mentions`:"Loading chat…",e[20]=o.page,e[21]=x,e[22]=L):L=e[22];let I;e[23]!==L?(I=n.jsx("summary",{className:"cursor-pointer text-xs text-muted-foreground",children:L}),e[23]=L,e[24]=I):I=e[24];let A;if(e[25]!==o||e[26]!==a||e[27]!==x||e[28]!==s||e[29]!==k){let G;e[31]!==o||e[32]!==a||e[33]!==s||e[34]!==k?(G=B=>{var Ze;return n.jsxs(Qe,{orientation:"horizontal",className:"items-center gap-2",children:[n.jsx(Ct,{role:B.sessionId===s?"lead":"agent",sessionId:B.sessionId,kinds:a,tints:k,className:"size-5"}),n.jsxs(Je,{className:"min-w-0 flex-1 items-baseline gap-1.5",htmlFor:`listen-${B.sessionId}`,"aria-label":`Listen for ${B.name}`,children:[n.jsx("span",{className:"truncate",children:B.name}),n.jsxs("span",{className:"truncate text-xs font-normal text-muted-foreground",children:["@",B.handle]})]}),n.jsx(te,{variant:"ghost",size:"icon-xs",disabled:!((Ze=o.page)!=null&&Ze.canPost)||!B.canInteract,onClick:()=>g(ye=>`${ye}${ye&&!/\s$/.test(ye)?" ":""}@${B.handle} `),"aria-label":`Mention ${B.name}`,title:`Mention @${B.handle}`,className:"text-muted-foreground",children:n.jsx(ts,{"data-icon":"inline-start"})}),n.jsx(Jt,{id:`listen-${B.sessionId}`,size:"sm",checked:B.listening,disabled:!B.canInteract||o.busyMembers.has(B.sessionId),onCheckedChange:ye=>void o.setListening(B.sessionId,ye)})]},B.sessionId)},e[31]=o,e[32]=a,e[33]=s,e[34]=k,e[35]=G):G=e[35],A=x.map(G),e[25]=o,e[26]=a,e[27]=x,e[28]=s,e[29]=k,e[30]=A}else A=e[30];let S;e[36]!==A?(S=n.jsx(et,{className:"max-h-48 gap-2 overflow-y-auto py-2",children:A}),e[36]=A,e[37]=S):S=e[37];let R;e[38]===Symbol.for("react.memo_cache_sentinel")?(R=n.jsx("p",{className:"pb-1 text-xs text-muted-foreground",children:"Listening sends short notices while an agent works. @mentions send the full message, even when listening is off."}),e[38]=R):R=e[38];let F;e[39]!==I||e[40]!==S?(F=n.jsxs("details",{className:"shrink-0 border-b px-3 py-2",children:[I,S,R]}),e[39]=I,e[40]=S,e[41]=F):F=e[41];let P;e[42]===Symbol.for("react.memo_cache_sentinel")?(P=G=>{const B=G.target;l.current=B.scrollHeight-B.scrollTop-B.clientHeight<80},e[42]=P):P=e[42];let H;e[43]!==o?(H=o.hasOlder&&n.jsx("div",{className:"flex justify-center py-2",children:n.jsx(te,{variant:"ghost",size:"xs",disabled:o.loadingOlder,onClick:()=>void o.older(),children:o.loadingOlder?"Loading…":"Load earlier messages"})}),e[43]=o,e[44]=H):H=e[44];let D;e[45]!==o.messages.length||e[46]!==o.page?(D=o.page&&o.messages.length===0&&n.jsx(rt,{children:n.jsxs(ct,{children:[n.jsx(It,{variant:"icon",children:n.jsx(es,{})}),n.jsx(dt,{children:"Talk to the crew"}),n.jsx(ut,{children:"Share a discovery, ask a question, or tag someone for their input."})]})}),e[45]=o.messages.length,e[46]=o.page,e[47]=D):D=e[47];let Y;if(e[48]!==M||e[49]!==p||e[50]!==a||e[51]!==s||e[52]!==$||e[53]!==k){let G;e[55]!==M||e[56]!==p||e[57]!==a||e[58]!==s||e[59]!==k?(G=B=>n.jsxs(C.Fragment,{children:[B.day!==void 0&&n.jsx(kt,{day:B.day}),n.jsx(St,{run:B,members:M,handles:p,kinds:a,tints:k,rootId:s})]},B.messages[0].sequence),e[55]=M,e[56]=p,e[57]=a,e[58]=s,e[59]=k,e[60]=G):G=e[60],Y=$.map(G),e[48]=M,e[49]=p,e[50]=a,e[51]=s,e[52]=$,e[53]=k,e[54]=Y}else Y=e[54];let V;e[61]===Symbol.for("react.memo_cache_sentinel")?(V=n.jsx("div",{ref:h}),e[61]=V):V=e[61];let U;e[62]!==Y?(U=n.jsxs("div",{role:"log","aria-label":"Shared messages","aria-live":"polite","aria-relevant":"additions",className:"flex flex-col gap-4 px-3 py-3",children:[Y,V]}),e[62]=Y,e[63]=U):U=e[63];let z;e[64]!==H||e[65]!==D||e[66]!==U?(z=n.jsxs(ft,{className:"min-h-0 flex-1",onScrollCapture:P,children:[H,D,U]}),e[64]=H,e[65]=D,e[66]=U,e[67]=z):z=e[67];let q;e[68]!==j?(q=G=>{G.preventDefault(),j()},e[68]=j,e[69]=q):q=e[69];const W=!!o.error,K=`crew-chat-${s}`;let d;e[70]!==K?(d=n.jsx(Je,{htmlFor:K,className:"sr-only",children:"Message the crew"}),e[70]=K,e[71]=d):d=e[71];const v=`crew-chat-${s}`,T=!((Be=o.page)!=null&&Be.canPost),X=!!o.error;let ae;e[72]===Symbol.for("react.memo_cache_sentinel")?(ae=G=>g(G.target.value),e[72]=ae):ae=e[72];let Q;e[73]!==j?(Q=G=>{G.key==="Enter"&&(G.metaKey||G.ctrlKey)&&!G.nativeEvent.isComposing&&(G.preventDefault(),j())},e[73]=j,e[74]=Q):Q=e[74];let J;e[75]!==f||e[76]!==v||e[77]!==T||e[78]!==X||e[79]!==Q?(J=n.jsx(Mt,{id:v,value:f,rows:3,maxLength:$t,placeholder:"Message the crew… use @ to tag an agent",disabled:T,"aria-invalid":X,onChange:ae,onKeyDown:Q}),e[75]=f,e[76]=v,e[77]=T,e[78]=X,e[79]=Q,e[80]=J):J=e[80];let ee;e[81]!==o.error?(ee=o.error&&n.jsx("p",{role:"alert",className:"text-xs text-destructive",children:o.error}),e[81]=o.error,e[82]=ee):ee=e[82];let se;e[83]!==W||e[84]!==d||e[85]!==J||e[86]!==ee?(se=n.jsxs(Qe,{"data-invalid":W,children:[d,J,ee]}),e[83]=W,e[84]=d,e[85]=J,e[86]=ee,e[87]=se):se=e[87];const re=((Ve=o.page)==null?void 0:Ve.canPost)===!1?"You have read access to this crew.":"⌘ / Ctrl + Enter to send";let Z;e[88]!==re?(Z=n.jsx(Rt,{className:"flex-1",children:re}),e[88]=re,e[89]=Z):Z=e[89];let ce;e[90]!==((Ge=o.page)==null?void 0:Ge.canPost)||e[91]!==o.posting||e[92]!==f?(ce=!((Ke=o.page)!=null&&Ke.canPost)||!f.trim()||o.posting,e[90]=(Xe=o.page)==null?void 0:Xe.canPost,e[91]=o.posting,e[92]=f,e[93]=ce):ce=e[93];let me;e[94]===Symbol.for("react.memo_cache_sentinel")?(me=n.jsx(ss,{"data-icon":"inline-start"}),e[94]=me):me=e[94];const Te=o.posting?"Sending…":"Send";let ge;e[95]!==ce||e[96]!==Te?(ge=n.jsxs(te,{type:"submit",size:"sm",disabled:ce,children:[me,Te]}),e[95]=ce,e[96]=Te,e[97]=ge):ge=e[97];let xe;e[98]!==Z||e[99]!==ge?(xe=n.jsxs("div",{className:"flex items-center gap-2",children:[Z,ge]}),e[98]=Z,e[99]=ge,e[100]=xe):xe=e[100];let we;e[101]!==se||e[102]!==xe?(we=n.jsxs(et,{className:"gap-2",children:[se,xe]}),e[101]=se,e[102]=xe,e[103]=we):we=e[103];let be;e[104]!==q||e[105]!==we?(be=n.jsx("form",{className:"shrink-0 border-t p-3",onSubmit:q,children:we}),e[104]=q,e[105]=we,e[106]=be):be=e[106];let Ce;return e[107]!==F||e[108]!==z||e[109]!==be?(Ce=n.jsxs("section",{"aria-label":"Crew chat",className:"flex h-full min-h-0 flex-col",children:[F,z,be]}),e[107]=F,e[108]=z,e[109]=be,e[110]=Ce):Ce=e[110],Ce}function ms(t){return t.listening}function ps(t){return[t.sessionId,t]}const fe={working:"bg-success ring-2 ring-success/30","needs-you":"bg-warning",done:"bg-muted-foreground/50",failed:"bg-destructive",unreachable:"border border-muted-foreground/60"};function pt(t){const e=new Date(t),s=e.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"});return e.toDateString()===new Date().toDateString()?s:`${e.toLocaleDateString([],{month:"short",day:"numeric"})}, ${s}`}function he(t){if(t.status==="deferred")return"needs-you";switch(t.outcome){case"needs_input":return"needs-you";case"running":return"working";case"error":return"failed";case"unreachable":case"not_found":return"unreachable";default:return"done"}}function tt(t,e){var s,r;return{sessionId:t.sessionId,dirName:((s=t.address)==null?void 0:s.dirName)??"",fileName:((r=t.address)==null?void 0:r.fileName)??"",projectShortName:"",lastModified:t.lastActivityAt??"",lastActivityAt:t.lastActivityAt,size:0,cwd:t.cwd,customTitle:t.customTitle,aiTitle:t.aiTitle,firstUserMessage:t.firstUserMessage,...t.parentId&&{crew:{rootId:e,parentId:t.parentId,startedAt:t.startedAt??0,...t.name&&{name:t.name}}}}}function gs(t,e,s){var o;const r=((o=[...e.values()].find(f=>f.parentId===null))==null?void 0:o.sessionId)??t.sessionId,i=s[t.sessionId],a=tt(t,r);if(!t.parentId)return Tt(a,i);const c=e.get(t.parentId);return At(a,{customName:i,parent:c&&tt(c,r)})}function xs(t){const e=new Map;for(const a of t.members){if(!a.parentId)continue;const c=e.get(a.parentId);c?c.push(a):e.set(a.parentId,[a])}const s=[],r=new Set,i=(a,c)=>{var f;const o=[...e.get(a)??[]].sort((g,h)=>(g.startedAt??0)-(h.startedAt??0));for(const g of o)r.has(g.sessionId)||(r.add(g.sessionId),s.push({member:g,depth:c,children:((f=e.get(g.sessionId))==null?void 0:f.length)??0}),i(g.sessionId,c+1))};i(t.rootId,0);for(const a of t.members)a.parentId&&!r.has(a.sessionId)&&(r.add(a.sessionId),s.push({member:a,depth:0,children:0}));return s}function ws(t){const e=({member:s,pending:r})=>r.askedAt??(Date.parse(s.lastActivityAt??"")||0);return t.members.flatMap(s=>s.waiting.map(r=>({member:s,pending:r}))).sort((s,r)=>e(s)-e(r))}function bs(t){const e={size:0,working:0,needsYou:0,done:0,failed:0,unreachable:0,unreadResults:0};for(const s of t.members){if(!s.parentId)continue;e.size++;const r=he(s);r==="working"?e.working++:r==="needs-you"?e.needsYou++:r==="failed"?e.failed++:r==="unreachable"?e.unreachable++:e.done++,Re(s)&&e.unreadResults++}return e}function Re(t){return!!(t.result&&t.result.state!=="running"&&!t.result.acknowledged)}function Ie(t){const[e]=t.waiting;switch(he(t)){case"needs-you":return(e==null?void 0:e.kind)==="permission"?`Waiting on a permission · ${e.toolName}`:(e==null?void 0:e.kind)==="question"?"Asked a question":!e&&t.status==="deferred"?"Awaiting permission review":"Plan to review";case"working":return t.status==="tool_use"&&t.toolName?t.toolName:t.status==="thinking"?"Thinking":t.status==="compacting"?"Compacting":t.status==="awaiting_agents"?"Waiting on its agents":"Working";case"failed":return t.error?`Failed · ${t.error}`:"Failed";case"unreachable":return t.device?`${t.device.name} is not answering`:"Not found";default:return Re(t)?"Finished · result unread":"Finished"}}const le=196,ne=86,de=40,ve=12,vs=28,Me=6,st=8,pe=10,js=6,$e=28,Fe=36;function gt(t){const e=he(t);return e==="working"||e==="needs-you"}function ys(t){const e={all:t.members.length,active:0,working:0,needsYou:0};for(const s of t.members){const r=he(s);r==="working"?e.working++:r==="needs-you"&&e.needsYou++}return e.active=e.working+e.needsYou,e}const nt=(t,e)=>(t.startedAt??0)-(e.startedAt??0)||t.sessionId.localeCompare(e.sessionId);function xt(t){const e=new Map(t.members.map(i=>[i.sessionId,i])),s=new Map,r=[];for(const i of t.members){const a=i.parentId&&i.sessionId!==t.rootId?e.get(i.parentId):void 0;if(!a){r.push(i);continue}const c=s.get(a.sessionId);c?c.push(i):s.set(a.sessionId,[i])}for(const i of s.values())i.sort(nt);return r.sort((i,a)=>+(a.sessionId===t.rootId)-+(i.sessionId===t.rootId)||nt(i,a)),{roots:r,childrenOf:s}}function Ns(t,e){if(e==="all")return new Set(t.members.map(i=>i.sessionId));const s=new Map(t.members.map(i=>[i.sessionId,i])),r=new Set;for(const i of t.members){if(!gt(i))continue;let a=i;for(;a&&!r.has(a.sessionId);)r.add(a.sessionId),a=a.sessionId===t.rootId||!a.parentId?void 0:s.get(a.parentId)}return r}function Is(t){const{roots:e,childrenOf:s}=xt(t),r=new Set;let i=0;const a=e.map(c=>({member:c,depth:0}));for(;a.length>0;){const{member:c,depth:o}=a.pop();if(!r.has(c.sessionId)){r.add(c.sessionId),i=Math.max(i,o);for(const f of s.get(c.sessionId)??[])a.push({member:f,depth:o+1})}}return i}function Cs(t){return(t+1)*le+t*de}function ks(t,e,s,{group:r=!1,stacked:i}={}){const{roots:a,childrenOf:c}=xt(t),o=Ns(t,e),f=N=>(c.get(N)??[]).filter($=>o.has($.sessionId)),g=(i==null?void 0:i.cardWidth)??le,h=[],l=[],w=[],u=new Set;let x=0,m=0;const p=N=>{const $={count:0,working:0,needsYou:0},_=new Set(u),O=[...f(N)];for(;O.length>0;){const E=O.pop();if(_.has(E.sessionId))continue;_.add(E.sessionId),$.count++;const j=he(E);j==="working"?$.working++:j==="needs-you"&&$.needsYou++,O.push(...f(E.sessionId))}return $},y=N=>f(N).filter($=>!u.has($.sessionId)),k=N=>y(N.sessionId).length===0||s.has(N.sessionId),b=(N,$,_)=>{u.add(N.sessionId);const O=y(N.sessionId),E=O.length>0&&s.has(N.sessionId),j=E?[]:O,L=r&&!i&&j.length>=st?j.filter(k):[],I=L.length>=st?L:[],A=new Set(I),S=j.filter(P=>!A.has(P)),R={member:N,depth:$,x:(_==null?void 0:_.x)??$*(i?$e:le+de),y:(_==null?void 0:_.y)??x+(S.length===0&&I.length>0?pe:0),childCount:O.length,collapsed:E,hidden:E?p(N.sessionId):{count:0,working:0,needsYou:0},context:e==="active"&&!gt(N),grouped:!!_};if(h.push(R),m=Math.max(m,R.x+g+(i&&O.length>0?Fe:0)),i){x+=ne+ve;const P=j.map(H=>b(H,$+1));return P.length>0&&l.push({parentId:N.sessionId,path:Ms(R.x,R.y,P)}),R.y}if(E){const P=R.y+ne/2;l.push({parentId:N.sessionId,path:`M${R.x+le} ${P}H${R.x+le+de/2}`})}if(_)return R.y;if(j.length===0)return x+=ne+ve,R.y;const F=S.map(P=>b(P,$+1));return I.length>0&&F.push(M(N.sessionId,I,$+1)+pe),l.push({parentId:N.sessionId,path:Ss(R.x+le,R.y,F)}),R.y},M=(N,$,_)=>{const O=Math.min(js,Math.max(2,Math.ceil(Math.sqrt($.length/1.5)))),E=Math.ceil($.length/O),j={parentId:N,x:_*(le+de),y:x,width:O*le+(O-1)*de+2*pe,height:E*ne+(E-1)*ve+2*pe};return w.push(j),$.forEach((L,I)=>b(L,_,{x:j.x+pe+I%O*(le+de),y:j.y+pe+Math.floor(I/O)*(ne+ve)})),m=Math.max(m,j.x+j.width),x+=j.height+ve,j.y};for(const N of a)!o.has(N.sessionId)||u.has(N.sessionId)||(h.length>0&&(x+=vs),b(N,0));return{orientation:i?"stacked":"across",cardWidth:g,nodes:h,edges:l,groups:w,width:m,height:Math.max(0,x-ve)}}function Ss(t,e,s){const r=e+ne/2,i=[`M${t} ${r}H${t+de}`];for(const a of s)a!==e&&i.push(wt(t,r,a+ne/2));return i.join("")}function wt(t,e,s){const r=t+de/2;return`M${r} ${e}V${s-Me}Q${r} ${s} ${r+Me} ${s}H${t+de}`}function Ms(t,e,s){return s.map(r=>bt(t,e,r)).join("")}function bt(t,e,s){const r=t+$e/2,i=s+ne/2;return`M${r} ${e+ne}V${i-Me}Q${r} ${i} ${r+Me} ${i}H${t+$e}`}function $s(t,e){const s=new Map(t.nodes.map(c=>[c.member.sessionId,c])),r=new Map(t.groups.map(c=>[c.parentId,c]));let i=e?s.get(e):void 0;const a=[];for(;i!=null&&i.member.parentId;){const c=i.member.parentId,o=s.get(c);if(!o||o.depth!==i.depth-1)break;if(t.orientation==="stacked"){a.unshift(bt(o.x,o.y,i.y)),i=o;continue}const f=o.x+le,g=o.y+ne/2,h=i.grouped?r.get(c):void 0,l=(h?h.y+pe:i.y)+ne/2;a.unshift(l===g?`M${f} ${g}H${f+de}`:`M${f} ${g}H${f+de/2}${wt(f,g,l)}`),i=o}return a.length>0?a.join(""):null}const ie=14,Pe=.25,ot=1.5,Rs=.7,Se=1.2,Ts=56,As=900,Os=.85,Es=320,Le={all:new Set,active:new Set};function Ls(t){const[e,s]=Ot(Et("crew-map-filter"),"all"),r=e==="active"?"active":"all",[i,a]=C.useState({rootId:t,folds:Le}),c=C.useRef(new Map),o=i.rootId===t?i.folds:Le,f=C.useCallback(h=>a(l=>{const w=l.rootId===t?l.folds:Le,u=new Set(w[r]);return u.delete(h)||u.add(h),{rootId:t,folds:{...w,[r]:u}}}),[r,t]),g=C.useMemo(()=>({get current(){return c.current.get(t)??null},set current(h){c.current.set(t,h)}}),[t]);return{filter:r,setFilter:s,collapsed:o[r],toggle:f,viewport:g}}function _s(t){const e=ue.c(86),{crew:s,hereId:r,controls:i,kinds:a,nameOf:c,onOpen:o}=t,[f,g]=C.useState(!1),{filter:h,collapsed:l,toggle:w}=i;let u,x,m,p,y,k,b,M,N,$,_,O,E,j,L,I;if(e[0]!==l||e[1]!==i||e[2]!==s||e[3]!==f||e[4]!==h||e[5]!==r||e[6]!==a||e[7]!==c||e[8]!==o||e[9]!==w){let U;e[26]!==s.rootId?(U=v=>v.sessionId===s.rootId,e[26]=s.rootId,e[27]=U):U=e[27];const z=s.members.find(U);let q;e[28]!==l||e[29]!==i||e[30]!==s||e[31]!==h||e[32]!==r||e[33]!==a||e[34]!==c||e[35]!==w?(q=(v,T)=>n.jsx(Ps,{crew:s,collapsed:l,groups:!v,filter:h,hereId:r,kinds:a,nameOf:c,memory:v,onOpen:T,onToggle:w,onShowAll:()=>i.setFilter("all")}),e[28]=l,e[29]=i,e[30]=s,e[31]=h,e[32]=r,e[33]=a,e[34]=c,e[35]=w,e[36]=q):q=e[36],m=q,k="flex h-full min-h-0 flex-col";let W;e[37]!==i||e[38]!==s?(W=n.jsx(at,{crew:s,controls:i}),e[37]=i,e[38]=s,e[39]=W):W=e[39];let K;e[40]===Symbol.for("react.memo_cache_sentinel")?(K=n.jsx("span",{className:"flex-1"}),e[40]=K):K=e[40];let d;e[41]===Symbol.for("react.memo_cache_sentinel")?(d=n.jsx(te,{variant:"ghost",size:"icon-xs","aria-label":"Expand the map",title:"Expand the map",onClick:()=>g(!0),children:n.jsx(ns,{"data-icon":"inline-start"})}),e[41]=d):d=e[41],e[42]!==W?(b=n.jsxs("div",{className:"flex shrink-0 items-center gap-2 px-3 pb-2",children:[W,K,d]}),e[42]=W,e[43]=b):b=e[43],e[44]!==m||e[45]!==i.viewport||e[46]!==o?(M=m(i.viewport,o),e[44]=m,e[45]=i.viewport,e[46]=o,e[47]=M):M=e[47],x=Lt,I=f,y=g,u=_t,O=!0,E="flex h-[calc(100dvh-1rem)] w-[calc(100vw-1rem)] max-w-none flex-col gap-0 overflow-hidden p-0 sm:h-[calc(100dvh-4rem)] sm:w-[calc(100vw-4rem)] sm:max-w-none",e[48]===Symbol.for("react.memo_cache_sentinel")?(j=n.jsx(zt,{className:"sr-only",children:"Crew map"}),L=n.jsx(Dt,{className:"sr-only",children:"Every session in this crew, from the one that started it."}),e[48]=j,e[49]=L):(j=e[48],L=e[49]),$="flex h-12 shrink-0 items-center gap-3 pl-4 pr-14",e[50]===Symbol.for("react.memo_cache_sentinel")?(_=n.jsx(ht,{"aria-hidden":"true",className:"size-4 shrink-0 text-muted-foreground"}),e[50]=_):_=e[50],p="min-w-0 truncate text-sm font-medium",N=z?c(z):"Crew",e[0]=l,e[1]=i,e[2]=s,e[3]=f,e[4]=h,e[5]=r,e[6]=a,e[7]=c,e[8]=o,e[9]=w,e[10]=u,e[11]=x,e[12]=m,e[13]=p,e[14]=y,e[15]=k,e[16]=b,e[17]=M,e[18]=N,e[19]=$,e[20]=_,e[21]=O,e[22]=E,e[23]=j,e[24]=L,e[25]=I}else u=e[10],x=e[11],m=e[12],p=e[13],y=e[14],k=e[15],b=e[16],M=e[17],N=e[18],$=e[19],_=e[20],O=e[21],E=e[22],j=e[23],L=e[24],I=e[25];let A;e[51]!==p||e[52]!==N?(A=n.jsx("span",{className:p,children:N}),e[51]=p,e[52]=N,e[53]=A):A=e[53];let S;e[54]===Symbol.for("react.memo_cache_sentinel")?(S=n.jsx("span",{className:"flex-1"}),e[54]=S):S=e[54];let R;e[55]!==i||e[56]!==s?(R=n.jsx(at,{crew:s,controls:i}),e[55]=i,e[56]=s,e[57]=R):R=e[57];let F;e[58]!==A||e[59]!==R||e[60]!==$||e[61]!==_?(F=n.jsxs("header",{className:$,children:[_,A,S,R]}),e[58]=A,e[59]=R,e[60]=$,e[61]=_,e[62]=F):F=e[62];let P;e[63]!==o?(P=U=>{g(!1),o(U)},e[63]=o,e[64]=P):P=e[64];let H;e[65]!==m||e[66]!==P?(H=m(null,P),e[65]=m,e[66]=P,e[67]=H):H=e[67];let D;e[68]!==u||e[69]!==F||e[70]!==H||e[71]!==O||e[72]!==E||e[73]!==j||e[74]!==L?(D=n.jsxs(u,{showCloseButton:O,className:E,children:[j,L,F,H]}),e[68]=u,e[69]=F,e[70]=H,e[71]=O,e[72]=E,e[73]=j,e[74]=L,e[75]=D):D=e[75];let Y;e[76]!==x||e[77]!==y||e[78]!==D||e[79]!==I?(Y=n.jsx(x,{open:I,onOpenChange:y,children:D}),e[76]=x,e[77]=y,e[78]=D,e[79]=I,e[80]=Y):Y=e[80];let V;return e[81]!==k||e[82]!==b||e[83]!==M||e[84]!==Y?(V=n.jsxs("div",{className:k,children:[b,M,Y]}),e[81]=k,e[82]=b,e[83]=M,e[84]=Y,e[85]=V):V=e[85],V}function at(t){const e=ue.c(3),{crew:s,controls:r}=t;let i;if(e[0]!==r||e[1]!==s){const a=ys(s),c=[{id:"all",label:"All",count:a.all,hint:"Every session in the crew"},{id:"active",label:"Active",count:a.active,hint:"Sessions working or waiting on you, and the sessions that started them"}];i=n.jsx("div",{role:"radiogroup","aria-label":"Show on the map",className:"flex shrink-0 gap-0.5 rounded-full border bg-background p-0.5",children:c.map(o=>{const{id:f,label:g,count:h,hint:l}=o;return n.jsxs("button",{type:"button",role:"radio","aria-checked":r.filter===f,"aria-label":`${g}, ${vt(h)}`,title:l,onClick:()=>r.setFilter(f),className:oe("inline-flex items-center gap-1.5 rounded-full px-2.5 py-0.5 text-xs text-muted-foreground outline-none transition-colors hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring",r.filter===f&&"bg-accent text-foreground"),children:[g,n.jsx("span",{className:"tabular-nums text-muted-foreground",children:h})]},f)})}),e[0]=r,e[1]=s,e[2]=i}else i=e[2];return i}function vt(t){return`${t} ${t===1?"session":"sessions"}`}function _e(t,e,s){return t.orientation==="stacked"?{scale:e,left:ie,top:ie}:{scale:e,left:Math.max(ie,(s.width-t.width*e)/2),top:Math.max(ie,Math.min((s.height-t.height*e)/2,s.height*.12))}}function zs(t,e,s){return{width:Math.max(s.width,e.left+t.width*e.scale+ie),height:Math.max(s.height,e.top+t.height*e.scale+Ts)}}function lt(t,e,{widthOnly:s=!1}={}){if(t.width===0||e.width===0)return 1;const r=(e.width-2*ie)/t.width,i=s?r:Math.min(r,(e.height-2*ie)/t.height);return Ye(i,Pe,1)}const Ye=(t,e,s)=>Math.min(s,Math.max(e,t));function Ds(t,e,s,r,i){var w;const a=new Map(e.layout.nodes.map(u=>[u.member.sessionId,u])),c=new Map(s.nodes.map(u=>[u.member.sessionId,u]));if(e.frame===r&&a.size===c.size&&s.nodes.every(u=>{const x=a.get(u.member.sessionId);return x!==void 0&&x.x===u.x&&x.y===u.y}))return null;const f=u=>({x:e.frame.left+u.x*e.frame.scale-t.left,y:e.frame.top+u.y*e.frame.scale-t.top}),g=i&&a.has(i)&&c.has(i)?i:(w=e.layout.nodes.filter(u=>c.has(u.member.sessionId)).map(u=>({node:u,screen:f(u)})).filter(({screen:u})=>u.y+ne*e.frame.scale>0&&u.x+e.layout.cardWidth*e.frame.scale>0).sort((u,x)=>u.screen.y-x.screen.y||u.screen.x-x.screen.x)[0])==null?void 0:w.node.member.sessionId;if(!g)return null;const h=f(a.get(g)),l=c.get(g);return{left:r.left+l.x*r.scale-h.x,top:r.top+l.y*r.scale-h.y}}function Fs(t,e,s,r){const i=new Map(t.nodes.map(x=>[x.member.sessionId,x])),a=e?i.get(e):void 0;if(!a)return{left:0,top:0};const{scale:c}=s,o=s.left+a.x*c,f=s.top+a.y*c,g=o+t.cardWidth*c,h=f+ne*c;if(g<=r.clientWidth&&h<=r.clientHeight)return{left:0,top:0};const l=a.member.parentId&&i.get(a.member.parentId)||a;let w=s.left+Math.min(l.x,a.x)*c-ie,u=s.top+Math.min(l.y,a.y)*c-ie;return g-w>r.clientWidth&&(w=o-ie),h-u>r.clientHeight&&(u=f-r.clientHeight/3),{left:Math.max(0,w),top:Math.max(0,u)}}function Ps({crew:t,collapsed:e,groups:s,filter:r,hereId:i,kinds:a,nameOf:c,memory:o,onOpen:f,onToggle:g,onShowAll:h}){const l=C.useRef(null),[w,u]=C.useState({width:0,height:0}),x=s&&w.width>=As,m=C.useMemo(()=>Is(t),[t]),p=w.width-2*ie,y=!s&&w.width>0&&Cs(m)*Os>p,k=y?Ye(p-m*$e-Fe,le,Es):le,b=C.useMemo(()=>ks(t,r,e,{group:x,...y&&{stacked:{cardWidth:k}}}),[t,r,e,x,y,k]),[M,N]=C.useState(()=>{var d;return((d=o==null?void 0:o.current)==null?void 0:d.frame)??{scale:1,left:ie,top:ie}}),[$,_]=C.useState(!1),O=C.useRef(null),E=C.useRef(null),j=C.useRef({left:0,top:0}),L=C.useRef(null),I=C.useRef(null),A=zs(b,M,w),{scale:S}=M;C.useLayoutEffect(()=>{const d=l.current;if(!d)return;const v=()=>u(X=>X.width===d.clientWidth&&X.height===d.clientHeight?X:{width:d.clientWidth,height:d.clientHeight});v();const T=new ResizeObserver(v);return T.observe(d),()=>T.disconnect()},[]);const R=C.useCallback(d=>{const v=l.current;o&&v&&(o.current={frame:d,left:v.scrollLeft,top:v.scrollTop})},[o]),F=C.useCallback((d,v)=>{O.current={frame:d,scroll:v},N(d)},[]),P=C.useCallback(d=>{const v=_e(d,Math.max(lt(d,w,{widthOnly:!0}),Rs),w);F(v,()=>{const T=l.current;return T?Fs(d,i,v,T):{left:0,top:0}})},[F,i,w]);C.useLayoutEffect(()=>{const d=l.current;if(w.width===0||!d)return;const v=L.current;if(v){if(v.filter!==r||v.layout.orientation!==b.orientation)P(b);else if(v.layout!==b){const T=Ds(j.current,v,b,M,E.current);T&&(d.scrollLeft=T.left,d.scrollTop=T.top,j.current={left:d.scrollLeft,top:d.scrollTop})}}else{const T=o==null?void 0:o.current;T?F(T.frame,()=>({left:T.left,top:T.top})):P(b)}E.current=null,L.current={layout:b,filter:r,frame:M}}),C.useLayoutEffect(()=>{const d=O.current,v=l.current;if(!d||!v||d.frame!==M)return;O.current=null;const{left:T,top:X}=d.scroll();v.scrollLeft=T,v.scrollTop=X,j.current={left:v.scrollLeft,top:v.scrollTop},R(M)});const H=C.useRef(i);C.useEffect(()=>{var d,v;H.current!==i&&(H.current=i,i&&((v=(d=l.current)==null?void 0:d.querySelector(`[data-crew-map-card="${CSS.escape(i)}"]`))==null||v.scrollIntoView({block:"nearest",inline:"nearest",behavior:"smooth"})))},[i]);const D=C.useCallback((d,v)=>{var ce;const T=l.current,X=((ce=O.current)==null?void 0:ce.frame.scale)??S,ae=Ye(X*d,Pe,ot);if(!T||ae===X)return;const Q=T.getBoundingClientRect(),J=v?v.clientX-Q.left:T.clientWidth/2,ee=v?v.clientY-Q.top:T.clientHeight/2,se=(T.scrollLeft+J-M.left)/S,re=(T.scrollTop+ee-M.top)/S,Z=_e(b,ae,w);F(Z,()=>({left:Z.left+se*Z.scale-J,top:Z.top+re*Z.scale-ee}))},[F,M.left,M.top,b,S,w]),Y=C.useRef(D);C.useLayoutEffect(()=>{Y.current=D}),C.useEffect(()=>{const d=l.current;if(!d)return;const v=T=>{!T.ctrlKey&&!T.metaKey||(T.preventDefault(),Y.current(Math.exp(-T.deltaY*.01),T))};return d.addEventListener("wheel",v,{passive:!1}),()=>d.removeEventListener("wheel",v)},[]);const V=d=>{const v=l.current;!v||d.pointerType!=="mouse"||d.button!==0||d.target.closest("button")||(I.current={pointerId:d.pointerId,x:d.clientX,y:d.clientY,left:v.scrollLeft,top:v.scrollTop},v.setPointerCapture(d.pointerId),_(!0))},U=d=>{const v=I.current,T=l.current;!v||!T||v.pointerId!==d.pointerId||(T.scrollLeft=v.left-(d.clientX-v.x),T.scrollTop=v.top-(d.clientY-v.y))},z=d=>{var v,T;((v=I.current)==null?void 0:v.pointerId)===d.pointerId&&(I.current=null,(T=l.current)==null||T.releasePointerCapture(d.pointerId),_(!1))},q=C.useMemo(()=>$s(b,i),[b,i]),W=b.nodes.length===0,K=b.orientation==="stacked"?b.cardWidth+Fe/2:le+de/2;return n.jsxs("div",{className:"relative min-h-0 flex-1 border-t",children:[n.jsx("div",{ref:l,role:"region","aria-label":"Crew map","data-crew-map-layout":b.orientation,onScroll:d=>{j.current={left:d.currentTarget.scrollLeft,top:d.currentTarget.scrollTop},O.current||R(M)},onPointerDown:V,onPointerMove:U,onPointerUp:z,onPointerCancel:z,onKeyDown:d=>{d.target===d.currentTarget&&(d.key==="+"||d.key==="="?D(Se):d.key==="-"&&D(1/Se))},tabIndex:-1,className:oe("absolute inset-0 overflow-auto overscroll-contain outline-none [touch-action:pan-x_pan-y]","bg-muted/30 bg-local bg-[radial-gradient(circle,var(--border)_1px,transparent_1px)] bg-size-[18px_18px]",$?"cursor-grabbing select-none":"cursor-grab"),children:W?n.jsxs(rt,{className:"h-full",children:[n.jsxs(ct,{children:[n.jsx(dt,{children:"Nothing is active"}),n.jsx(ut,{className:"text-xs",children:"No session in this crew is working or waiting on you."})]}),n.jsx(te,{variant:"outline",size:"xs",onClick:h,children:"Show all sessions"})]}):n.jsx("div",{className:"relative",style:{width:A.width,height:A.height},children:n.jsxs("div",{className:"absolute origin-top-left",style:{left:M.left,top:M.top,width:b.width,height:b.height,transform:`scale(${S})`},children:[b.groups.map(d=>n.jsx("div",{"aria-hidden":"true",className:"absolute rounded-xl border border-dashed border-muted-foreground/25 bg-muted/25",style:{left:d.x,top:d.y,width:d.width,height:d.height}},d.parentId)),n.jsxs("svg",{"aria-hidden":"true",width:b.width,height:b.height,className:"pointer-events-none absolute inset-0 overflow-visible",fill:"none",children:[b.edges.map(d=>n.jsx("path",{d:d.path,className:"stroke-muted-foreground/35",strokeWidth:1.25},d.parentId)),q&&n.jsx("path",{d:q,className:"stroke-foreground/55",strokeWidth:1.5})]}),n.jsx("ul",{"aria-label":"Sessions",className:"absolute inset-0",children:b.nodes.map(d=>n.jsx(Hs,{node:d,width:b.cardWidth,toggleLeft:K,here:d.member.sessionId===i,kind:a.get(d.member.sessionId),name:c(d.member),onOpen:f,onToggle:v=>{E.current=v,g(v)}},d.member.sessionId))})]})})}),!W&&n.jsxs("div",{className:"absolute bottom-2.5 right-2.5 flex items-center gap-0.5 rounded-lg border bg-popover p-0.5 shadow-sm",children:[n.jsx(te,{variant:"ghost",size:"icon-xs","aria-label":"Zoom out",title:"Zoom out",disabled:S<=Pe,onClick:()=>D(1/Se),children:n.jsx(mt,{"data-icon":"inline-start"})}),n.jsxs(te,{variant:"ghost",size:"xs","aria-label":"Actual size",title:"Actual size",className:"min-w-11 px-1 tabular-nums text-muted-foreground",onClick:()=>D(1/S),children:[Math.round(S*100),"%"]}),n.jsx(te,{variant:"ghost",size:"icon-xs","aria-label":"Zoom in",title:"Zoom in",disabled:S>=ot,onClick:()=>D(Se),children:n.jsx(os,{"data-icon":"inline-start"})}),n.jsx("span",{className:"mx-0.5 h-4 w-px bg-border","aria-hidden":"true"}),n.jsx(te,{variant:"ghost",size:"xs",title:"Fit the whole crew on screen",className:"px-1.5 text-muted-foreground",onClick:()=>F(_e(b,lt(b,w),w),()=>({left:0,top:0})),children:"Fit"})]})]})}const Ys={"needs-you":"border-warning/60 bg-[color-mix(in_oklch,var(--warning)_7%,var(--card))]",failed:"border-destructive/45",unreachable:"border-dashed"},qs={"needs-you":"text-warning",failed:"text-destructive"};function Ws(t){var s,r;const e=(s=t.pullRequests)==null?void 0:s.at(-1);return[t.model&&qe(t.model),(r=t.device)==null?void 0:r.name,e&&`#${e.number}`,t.lastActivityAt&&We(t.lastActivityAt)].filter(Boolean).join(" · ")}function Hs(t){const e=ue.c(75),{node:s,width:r,toggleLeft:i,here:a,kind:c,name:o,onOpen:f,onToggle:g}=t,{member:h}=s;let l;e[0]!==h?(l=he(h),e[0]=h,e[1]=l):l=e[1];const w=l;let u;e[2]!==h?(u=Ie(h),e[2]=h,e[3]=u):u=e[3];const x=u;let m;e[4]!==c?(m=c?Ft(c):as,e[4]=c,e[5]=m):m=e[5];const p=m;let y;e[6]!==h?(y=Ws(h),e[6]=h,e[7]=y):y=e[7];const k=y,b=s.context&&"shown because a session it started is active";let M;e[8]!==x||e[9]!==o||e[10]!==b?(M=[o,x,b].filter(Boolean),e[8]=x,e[9]=o,e[10]=b,e[11]=M):M=e[11];const N=M.join(", ");let $;e[12]!==s.x||e[13]!==s.y||e[14]!==r?($={left:s.x,top:s.y,width:r,height:ne},e[12]=s.x,e[13]=s.y,e[14]=r,e[15]=$):$=e[15];const _=h.sessionId,O=a?"true":void 0;let E;e[16]!==h||e[17]!==f?(E=()=>f(h),e[16]=h,e[17]=f,e[18]=E):E=e[18];const j=Ys[w],L=a&&"outline-solid outline-[1.5px] outline-offset-2 outline-foreground/70",I=s.context&&"opacity-60 hover:opacity-100 focus-visible:opacity-100";let A;e[19]!==j||e[20]!==L||e[21]!==I?(A=oe("flex size-full cursor-pointer flex-col justify-center gap-1 rounded-lg border bg-card px-2.5 py-2 text-left shadow-xs outline-none","transition-[border-color,opacity,box-shadow] hover:border-foreground/25 hover:shadow-sm focus-visible:ring-2 focus-visible:ring-ring",j,L,I),e[19]=j,e[20]=L,e[21]=I,e[22]=A):A=e[22];let S;e[23]!==N||e[24]!==h.sessionId||e[25]!==w||e[26]!==E||e[27]!==A||e[28]!==O?(S=n.jsx("button",{type:"button","data-crew-map-card":_,"data-crew-map-state":w,"aria-current":O,"aria-label":N,onClick:E,className:A}),e[23]=N,e[24]=h.sessionId,e[25]=w,e[26]=E,e[27]=A,e[28]=O,e[29]=S):S=e[29];let R;e[30]!==p?(R=n.jsx(p,{"aria-hidden":"true",className:"mt-[3px] size-3.5 shrink-0 text-muted-foreground"}),e[30]=p,e[31]=R):R=e[31];let F;e[32]!==o?(F=n.jsx("span",{className:"line-clamp-2 min-w-0 flex-1 text-[13px]/[18px] font-medium",children:o}),e[32]=o,e[33]=F):F=e[33];let P;e[34]!==R||e[35]!==F?(P=n.jsxs("span",{className:"flex min-w-0 items-start gap-1.5",children:[R,F]}),e[34]=R,e[35]=F,e[36]=P):P=e[36];const H=fe[w];let D;e[37]!==H?(D=oe("size-1.5 shrink-0 rounded-full",H),e[37]=H,e[38]=D):D=e[38];let Y;e[39]!==D?(Y=n.jsx("span",{className:D,"aria-hidden":"true"}),e[39]=D,e[40]=Y):Y=e[40];let V;e[41]!==h||e[42]!==w?(V=Re(h)?"text-warning":qs[w],e[41]=h,e[42]=w,e[43]=V):V=e[43];let U;e[44]!==V?(U=oe("min-w-0 truncate text-muted-foreground",V),e[44]=V,e[45]=U):U=e[45];let z;e[46]!==x||e[47]!==U?(z=n.jsx("span",{className:U,children:x}),e[46]=x,e[47]=U,e[48]=z):z=e[48];let q;e[49]!==Y||e[50]!==z?(q=n.jsxs("span",{className:"flex min-w-0 items-center gap-1.5 text-xs",children:[Y,z]}),e[49]=Y,e[50]=z,e[51]=q):q=e[51];let W;e[52]!==a||e[53]!==k?(W=(k||a)&&n.jsxs("span",{className:"flex min-w-0 items-center gap-1.5 text-[11.5px] tabular-nums text-muted-foreground/75",children:[n.jsx("span",{className:"min-w-0 flex-1 truncate",children:k}),a&&n.jsx("span",{className:"shrink-0 font-medium text-foreground/70",children:"You are here"})]}),e[52]=a,e[53]=k,e[54]=W):W=e[54];let K;e[55]!==S||e[56]!==P||e[57]!==q||e[58]!==W?(K=n.jsxs(Pt,{delay:700,render:S,children:[P,q,W]}),e[55]=S,e[56]=P,e[57]=q,e[58]=W,e[59]=K):K=e[59];let d;e[60]!==h||e[61]!==o?(d=n.jsx(Yt,{side:"left",align:"start",className:"max-w-72",children:n.jsx(Bs,{member:h,name:o})}),e[60]=h,e[61]=o,e[62]=d):d=e[62];let v;e[63]!==K||e[64]!==d?(v=n.jsxs(qt,{children:[K,d]}),e[63]=K,e[64]=d,e[65]=v):v=e[65];let T;e[66]!==o||e[67]!==s||e[68]!==g||e[69]!==i?(T=s.childCount>0&&n.jsx(Us,{node:s,name:o,left:i,onToggle:g}),e[66]=o,e[67]=s,e[68]=g,e[69]=i,e[70]=T):T=e[70];let X;return e[71]!==v||e[72]!==T||e[73]!==$?(X=n.jsxs("li",{className:"group/node absolute",style:$,children:[v,T]}),e[71]=v,e[72]=T,e[73]=$,e[74]=X):X=e[74],X}function Us(t){const e=ue.c(25),{node:s,name:r,left:i,onToggle:a}=t,{collapsed:c,hidden:o}=s;let f=null;o.needsYou>0?f="needs-you":o.working>0&&(f="working");let g;e[0]!==c||e[1]!==o.count||e[2]!==o.needsYou||e[3]!==o.working||e[4]!==r?(g=c?[`Show the ${vt(o.count)} under ${r}`,o.needsYou>0&&`${o.needsYou} waiting on you`,o.working>0&&`${o.working} working`].filter(Boolean).join(", "):`Fold the sessions under ${r}`,e[0]=c,e[1]=o.count,e[2]=o.needsYou,e[3]=o.working,e[4]=r,e[5]=g):g=e[5];const h=g,l=!c,w=c?void 0:"Fold";let u;e[6]!==s.member.sessionId||e[7]!==a?(u=()=>a(s.member.sessionId),e[6]=s.member.sessionId,e[7]=a,e[8]=u):u=e[8];const x=!c&&"opacity-0 group-hover/node:opacity-100 focus-visible:opacity-100 [@media(hover:none)]:opacity-100";let m;e[9]!==x?(m=oe("absolute z-10 flex h-5 min-w-5 -translate-x-1/2 -translate-y-1/2 cursor-pointer items-center justify-center gap-1 rounded-full border bg-card px-1.5 text-[11px] font-medium tabular-nums text-muted-foreground shadow-xs outline-none","transition-opacity hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring",x),e[9]=x,e[10]=m):m=e[10];let p;e[11]!==i?(p={left:i,top:ne/2},e[11]=i,e[12]=p):p=e[12];let y;e[13]!==f||e[14]!==c||e[15]!==o.count?(y=c?n.jsxs(n.Fragment,{children:[f&&n.jsx("span",{className:oe("size-1.5 rounded-full",fe[f]),"aria-hidden":"true"}),"+",o.count]}):n.jsx(mt,{"aria-hidden":"true",className:"size-3"}),e[13]=f,e[14]=c,e[15]=o.count,e[16]=y):y=e[16];let k;return e[17]!==h||e[18]!==l||e[19]!==w||e[20]!==u||e[21]!==m||e[22]!==p||e[23]!==y?(k=n.jsx("button",{type:"button","aria-expanded":l,"aria-label":h,title:w,onClick:u,className:m,style:p,children:y}),e[17]=h,e[18]=l,e[19]=w,e[20]=u,e[21]=m,e[22]=p,e[23]=y,e[24]=k):k=e[24],k}function Bs(t){var u,x;const e=ue.c(35),{member:s,name:r}=t;let i;e[0]!==s.firstUserMessage?(i=(u=s.firstUserMessage)==null?void 0:u.replace(/\s+/g," ").trim(),e[0]=s.firstUserMessage,e[1]=i):i=e[1];const a=i;let c;e[2]!==s.cwd?(c=(x=s.cwd)==null?void 0:x.split(/[\\/]/).filter(Boolean).at(-1),e[2]=s.cwd,e[3]=c):c=e[3];const o=c;let f;if(e[4]!==o||e[5]!==s.device||e[6]!==s.model||e[7]!==s.startedAt||e[8]!==s.turnCount){if(f=[],s.model){let m;e[10]!==s.model?(m=qe(s.model),e[10]=s.model,e[11]=m):m=e[11];let p;e[12]!==m?(p=["Model",m],e[12]=m,e[13]=p):p=e[13],f.push(p)}if(s.device){let m;e[14]!==s.device.name?(m=["Device",s.device.name],e[14]=s.device.name,e[15]=m):m=e[15],f.push(m)}if(o){let m;e[16]!==o?(m=["Folder",o],e[16]=o,e[17]=m):m=e[17],f.push(m)}if(s.startedAt){let m;e[18]!==s.startedAt?(m=pt(s.startedAt),e[18]=s.startedAt,e[19]=m):m=e[19];let p;e[20]!==m?(p=["Started",m],e[20]=m,e[21]=p):p=e[21],f.push(p)}if(s.turnCount){const m=String(s.turnCount);let p;e[22]!==m?(p=["Turns",m],e[22]=m,e[23]=p):p=e[23],f.push(p)}e[4]=o,e[5]=s.device,e[6]=s.model,e[7]=s.startedAt,e[8]=s.turnCount,e[9]=f}else f=e[9];let g;e[24]!==r?(g=n.jsx("p",{className:"font-medium",children:r}),e[24]=r,e[25]=g):g=e[25];let h;e[26]!==r||e[27]!==a?(h=a&&a!==r&&n.jsx("p",{className:"line-clamp-3 text-muted-foreground",children:a}),e[26]=r,e[27]=a,e[28]=h):h=e[28];let l;e[29]!==f?(l=f.length>0&&n.jsx("dl",{className:"grid grid-cols-[auto_minmax(0,1fr)] gap-x-3 gap-y-0.5",children:f.map(Vs)}),e[29]=f,e[30]=l):l=e[30];let w;return e[31]!==g||e[32]!==h||e[33]!==l?(w=n.jsxs("div",{className:"flex flex-col gap-1.5 py-0.5",children:[g,h,l]}),e[31]=g,e[32]=h,e[33]=l,e[34]=w):w=e[34],w}function Vs(t){const[e,s]=t;return n.jsxs("div",{className:"contents",children:[n.jsx("dt",{className:"text-muted-foreground",children:e}),n.jsx("dd",{className:"truncate tabular-nums",children:s})]},e)}const Gs=4e3;function Ks(t){var m;const[e,s]=C.useState(null),[r,i]=C.useState(null),[a,c]=C.useState(new Set),o=(m=Wt())==null?void 0:m.refresh,f=C.useRef(t),g=C.useRef(new Set);C.useLayoutEffect(()=>(f.current=t,()=>{f.current=null}),[t]);const h=C.useCallback(async p=>{if(t)try{const y=await ze(`/api/session-crew/${encodeURIComponent(t)}`);if(!p())return;if(!y.ok){i(y.status===404?"This session is no longer available.":"Couldn't load the crew.");return}const k=await y.json();if(!p())return;s(b=>JSON.stringify(b)===JSON.stringify(k)?b:k),i(null)}catch{p()&&i("Couldn't load the crew.")}},[t]);it(t?h:null,Gs),C.useEffect(()=>{s(p=>p!=null&&p.members.some(y=>y.sessionId===t)?p:null),i(null),c(new Set)},[t]);const l=C.useCallback(async(p,y,k)=>{const b=`${t}:${p}`;if(g.current.has(b))return;const M=()=>f.current===t;g.current.add(b),c(N=>new Set(N).add(p));try{const N=await y();if(!M())return;if(!N.ok&&N.status!==404){i(k);return}o==null||o(),await h(M)}catch{M()&&i(k)}finally{g.current.delete(b),M()&&c(N=>{const $=new Set(N);return $.delete(p),$})}},[h,o,t]),w=C.useCallback((p,y,k)=>l(y,()=>je("/api/session-respond",{sessionId:p,requestId:y,...k}),"Couldn't send the answer."),[l]),u=C.useCallback((p,y)=>l(y,()=>je("/api/delegated-tasks",{sessionId:p,taskId:y,action:"ack"}),"Couldn't mark the result read."),[l]),x=C.useCallback(p=>l(p.sessionId,()=>{var y;return((y=p.result)==null?void 0:y.state)==="running"&&p.parentId?je("/api/delegated-tasks",{sessionId:p.parentId,taskId:p.result.taskId,action:"cancel"}):je("/api/stop-session",{sessionId:p.sessionId,cancelQueued:!0})},"Couldn't stop the session."),[l]);return{crew:e,error:r,busy:a,respond:w,markRead:u,stop:x}}const Xs=[{id:"all",label:"All"},{id:"working",label:"Working"},{id:"needs-you",label:"Need you"},{id:"done",label:"Done"}],Zs={working:"bg-success shadow-[0_0_0_2px_color-mix(in_oklch,var(--success)_25%,transparent)]","needs-you":"bg-warning",done:"bg-muted-foreground/40",failed:"bg-destructive",unreachable:"border border-muted-foreground/50"};function un(t){var U;const e=ue.c(40),{context:s,closePanel:r}=t,i=((U=s.session)==null?void 0:U.sessionId)??null,{crew:a,error:c,busy:o,respond:f,markRead:g,stop:h}=Ks(i),{names:l}=Ht(),[w,u]=C.useState("overview");let x;e[0]===Symbol.for("react.memo_cache_sentinel")?(x=new Set,e[0]=x):x=e[0];const[m,p]=C.useState(x),y=Ls((a==null?void 0:a.rootId)??"");let k;e[1]!==(a==null?void 0:a.members)?(k=new Map(((a==null?void 0:a.members)??[]).map(Js)),e[1]=a==null?void 0:a.members,e[2]=k):k=e[2];const b=k;let M;e[3]!==(a==null?void 0:a.members)?(M=new Map(((a==null?void 0:a.members)??[]).flatMap(Qs)),e[3]=a==null?void 0:a.members,e[4]=M):M=e[4];const N=M;let $;e[5]!==b||e[6]!==l?($=z=>gs(z,b,l),e[5]=b,e[6]=l,e[7]=$):$=e[7];const _=$;let O;e[8]!==s?(O=z=>{z.address&&z.device?Xt(Zt(z.address.dirName,z.address.fileName,z.device.id)):z.address&&s.openSession?s.openSession(z.address.dirName,z.address.fileName):Qt(z.sessionId)},e[8]=s,e[9]=O):O=e[9];const E=O;let j;e[10]===Symbol.for("react.memo_cache_sentinel")?(j=z=>p(q=>{const W=new Set(q);return W.delete(z)||W.add(z),W}),e[10]=j):j=e[10];const L=j;let I;e[11]!==b?(I=z=>{p(q=>{var v;const W=new Set(q),K=new Set;let d=z.parentId;for(;d&&!K.has(d);)K.add(d),W.delete(d),d=((v=b.get(d))==null?void 0:v.parentId)??null;return W}),requestAnimationFrame(()=>{var q;return(q=document.querySelector(`[data-crew-row="${z.sessionId}"]`))==null?void 0:q.scrollIntoView({block:"nearest",behavior:"smooth"})})},e[11]=b,e[12]=I):I=e[12];const A=I;let S,R,F;e[13]===Symbol.for("react.memo_cache_sentinel")?(R=n.jsx(ht,{"aria-hidden":"true",className:"size-4 text-muted-foreground"}),F=n.jsx("h2",{className:"text-sm font-medium",children:"Crew"}),S=n.jsx("div",{className:"flex-1"}),e[13]=S,e[14]=R,e[15]=F):(S=e[13],R=e[14],F=e[15]);let P;e[16]===Symbol.for("react.memo_cache_sentinel")?(P=n.jsx(cs,{"data-icon":"inline-start"}),e[16]=P):P=e[16];let H;e[17]!==r?(H=n.jsxs("div",{className:"flex h-10 shrink-0 items-center gap-2 px-3",children:[R,F,S,n.jsx(te,{variant:"ghost",size:"icon-sm",onClick:r,"aria-label":"Close crew",children:P})]}),e[17]=r,e[18]=H):H=e[18];let D;e[19]!==c?(D=c&&n.jsx("p",{role:"alert",className:"px-3 pb-2 text-xs text-destructive",children:c}),e[19]=c,e[20]=D):D=e[20];let Y;e[21]!==o||e[22]!==m||e[23]!==a||e[24]!==c||e[25]!==N||e[26]!==y||e[27]!==g||e[28]!==_||e[29]!==E||e[30]!==f||e[31]!==A||e[32]!==i||e[33]!==h||e[34]!==w?(Y=a?n.jsxs(Ut,{value:w,onValueChange:u,className:"min-h-0 flex-1 grid-rows-[auto_minmax(0,1fr)]",children:[n.jsxs(Bt,{variant:"line",className:"mx-3 mb-1",children:[n.jsx(Ae,{value:"overview",children:"Overview"}),n.jsx(Ae,{value:"map",children:"Map"}),n.jsx(Ae,{value:"chat",children:"Chat"})]}),n.jsx(Oe,{value:"overview",className:"min-h-0",children:n.jsxs(ft,{className:"h-full min-h-0",children:[n.jsx(en,{crew:a,hereId:i,nameOf:_,onOpen:E,onReveal:A}),n.jsx(sn,{crew:a,busy:o,nameOf:_,onOpen:E,onRespond:f}),n.jsx(nn,{crew:a,hereId:i,busy:o,nameOf:_,onOpen:E,onMarkRead:g,onStop:h,collapsed:m,onToggle:L})]})}),n.jsx(Oe,{value:"map",className:"min-h-0",children:n.jsx(_s,{crew:a,hereId:i,controls:y,kinds:N,nameOf:_,onOpen:E})}),n.jsx(Oe,{value:"chat",keepMounted:!0,className:"min-h-0",children:n.jsx(hs,{rootId:a.rootId,kinds:N,active:w==="chat"},a.rootId)})]}):!c&&n.jsx("p",{className:"px-3 py-6 text-center text-sm text-muted-foreground",children:"Loading the crew…"}),e[21]=o,e[22]=m,e[23]=a,e[24]=c,e[25]=N,e[26]=y,e[27]=g,e[28]=_,e[29]=E,e[30]=f,e[31]=A,e[32]=i,e[33]=h,e[34]=w,e[35]=Y):Y=e[35];let V;return e[36]!==H||e[37]!==D||e[38]!==Y?(V=n.jsxs("aside",{"aria-label":"Crew",className:"flex size-full min-h-0 flex-col bg-canvas",children:[H,D,Y]}),e[36]=H,e[37]=D,e[38]=Y,e[39]=V):V=e[39],V}function Qs(t){return t.address?[[t.sessionId,Vt(t.address.dirName)]]:[]}function Js(t){return[t.sessionId,t]}function en(t){var M;const e=ue.c(46),{crew:s,hereId:r,nameOf:i,onOpen:a,onReveal:c}=t;let o,f,g,h,l;if(e[0]!==s||e[1]!==r||e[2]!==i||e[3]!==a||e[4]!==c){let N;e[10]!==s.rootId?(N=S=>S.sessionId===s.rootId,e[10]=s.rootId,e[11]=N):N=e[11];const $=s.members.find(N),_=s.members.filter(tn);let O;e[12]!==s?(O=bs(s),e[12]=s,e[13]=O):O=e[13],l=O;const E=(M=_[0])==null?void 0:M.startedAt;o="Crew summary",f="border-b px-3 pb-3 pt-1";const j=$&&n.jsx("button",{type:"button",onClick:()=>a($),"aria-current":$.sessionId===r?"true":void 0,className:"min-w-0 flex-1 truncate rounded-sm text-left text-sm font-medium outline-none hover:underline focus-visible:ring-2 focus-visible:ring-ring",children:i($)}),L=l.size===1?"session":"sessions",I=E?` · since ${pt(E)}`:"";let A;e[14]!==L||e[15]!==I||e[16]!==l.size?(A=n.jsxs("span",{className:"shrink-0 text-xs tabular-nums text-muted-foreground",children:[l.size," ",L,I]}),e[14]=L,e[15]=I,e[16]=l.size,e[17]=A):A=e[17],e[18]!==A||e[19]!==j?(g=n.jsxs("div",{className:"flex items-baseline gap-2",children:[j,A]}),e[18]=A,e[19]=j,e[20]=g):g=e[20],h=_.length>0&&n.jsx("div",{"data-crew-strip":!0,className:"mt-2.5 grid grid-cols-[repeat(auto-fit,minmax(6px,1fr))] gap-[3px]",role:"list","aria-label":"One cell per session, in the order they were started",children:_.map(S=>{const R=he(S);return n.jsx("button",{type:"button",role:"listitem","data-crew-cell":R,title:`${i(S)}: ${Ie(S)}`,"aria-label":`${i(S)}: ${Ie(S)}`,onClick:()=>c(S),className:oe("h-2.5 rounded-[2px] outline-none focus-visible:ring-2 focus-visible:ring-ring",Zs[R],S.sessionId===r&&"outline outline-[1.5px] outline-offset-2 outline-foreground")},S.sessionId)})}),e[0]=s,e[1]=r,e[2]=i,e[3]=a,e[4]=c,e[5]=o,e[6]=f,e[7]=g,e[8]=h,e[9]=l}else o=e[5],f=e[6],g=e[7],h=e[8],l=e[9];let w;e[21]!==l.working?(w=l.working>0&&n.jsx(Ne,{dot:fe.working,value:l.working,label:"working"}),e[21]=l.working,e[22]=w):w=e[22];let u;e[23]!==l.needsYou?(u=l.needsYou>0&&n.jsx(Ne,{dot:fe["needs-you"],value:l.needsYou,label:l.needsYou===1?"needs you":"need you"}),e[23]=l.needsYou,e[24]=u):u=e[24];let x;e[25]!==l.done?(x=l.done>0&&n.jsx(Ne,{dot:fe.done,value:l.done,label:"done"}),e[25]=l.done,e[26]=x):x=e[26];let m;e[27]!==l.failed?(m=l.failed>0&&n.jsx(Ne,{dot:fe.failed,value:l.failed,label:"failed"}),e[27]=l.failed,e[28]=m):m=e[28];let p;e[29]!==l.unreachable?(p=l.unreachable>0&&n.jsx(Ne,{dot:fe.unreachable,value:l.unreachable,label:"away"}),e[29]=l.unreachable,e[30]=p):p=e[30];let y;e[31]!==l.unreadResults?(y=l.unreadResults>0&&n.jsxs("span",{className:"ml-auto text-warning",children:[n.jsx("span",{className:"font-medium tabular-nums",children:l.unreadResults})," ",l.unreadResults===1?"result":"results"," unread"]}),e[31]=l.unreadResults,e[32]=y):y=e[32];let k;e[33]!==y||e[34]!==w||e[35]!==u||e[36]!==x||e[37]!==m||e[38]!==p?(k=n.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-x-3.5 gap-y-1 text-xs text-muted-foreground",children:[w,u,x,m,p,y]}),e[33]=y,e[34]=w,e[35]=u,e[36]=x,e[37]=m,e[38]=p,e[39]=k):k=e[39];let b;return e[40]!==o||e[41]!==k||e[42]!==f||e[43]!==g||e[44]!==h?(b=n.jsxs("section",{"aria-label":o,className:f,children:[g,h,k]}),e[40]=o,e[41]=k,e[42]=f,e[43]=g,e[44]=h,e[45]=b):b=e[45],b}function tn(t){return t.parentId!==null}function Ne(t){const e=ue.c(10),{dot:s,value:r,label:i}=t;let a;e[0]!==s?(a=oe("size-1.5 rounded-full",s),e[0]=s,e[1]=a):a=e[1];let c;e[2]!==a?(c=n.jsx("span",{className:a,"aria-hidden":"true"}),e[2]=a,e[3]=c):c=e[3];let o;e[4]!==r?(o=n.jsx("span",{className:"font-medium tabular-nums text-foreground",children:r}),e[4]=r,e[5]=o):o=e[5];let f;return e[6]!==i||e[7]!==c||e[8]!==o?(f=n.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[c,o," ",i]}),e[6]=i,e[7]=c,e[8]=o,e[9]=f):f=e[9],f}function sn(t){const e=ue.c(6),{crew:s,busy:r,nameOf:i,onOpen:a,onRespond:c}=t,o=ws(s),[f,g]=C.useState(0);if(o.length===0)return null;const h=Math.min(f,o.length-1),{member:l,pending:w}=o[h],u=o[h+1];let x;e[0]===Symbol.for("react.memo_cache_sentinel")?(x=n.jsx("h3",{className:"text-sm font-medium text-foreground",children:"Needs you"}),e[0]=x):x=e[0];let m;e[1]===Symbol.for("react.memo_cache_sentinel")?(m=n.jsx("span",{className:"flex-1"}),e[1]=m):m=e[1];let p;e[2]===Symbol.for("react.memo_cache_sentinel")?(p=n.jsx("span",{className:oe("size-1.5 shrink-0 rounded-full",fe["needs-you"]),"aria-hidden":"true"}),e[2]=p):p=e[2];const y=w.askedAt?`waiting ${We(new Date(w.askedAt).toISOString())}`:"waiting";let k;e[3]!==y?(k=n.jsx("span",{className:"ml-auto shrink-0 tabular-nums text-warning",children:y}),e[3]=y,e[4]=k):k=e[4];let b;return e[5]===Symbol.for("react.memo_cache_sentinel")?(b=n.jsx(De,{"data-icon":"inline-end"}),e[5]=b):b=e[5],n.jsxs("section",{"aria-label":"Needs you",className:"border-b px-3 py-2.5",children:[n.jsxs("div",{className:"mb-2 flex items-center gap-2 text-xs text-muted-foreground",children:[x,n.jsx("span",{className:"tabular-nums",children:o.length}),m,o.length>1&&n.jsxs(n.Fragment,{children:[n.jsxs("span",{className:"tabular-nums",children:[h+1," of ",o.length]}),n.jsx(te,{variant:"ghost",size:"icon-xs","aria-label":"Previous request",disabled:h===0,onClick:()=>g(h-1),children:n.jsx(ls,{"data-icon":"inline-start"})}),n.jsx(te,{variant:"ghost",size:"icon-xs","aria-label":"Next request",disabled:h===o.length-1,onClick:()=>g(h+1),children:n.jsx(De,{"data-icon":"inline-start"})})]})]}),n.jsxs("div",{className:"flex flex-col gap-1.5",children:[n.jsxs("div",{className:"flex items-center gap-2 px-0.5 text-xs",children:[p,n.jsx("span",{className:"min-w-0 truncate font-medium text-foreground",children:i(l)}),l.device&&n.jsx(Gt,{variant:"outline",children:l.device.name}),k]}),n.jsx(Kt,{sessionId:l.sessionId,pending:w,queued:0,responding:r.has(w.requestId),onRespond:(M,N)=>void c(l.sessionId,M,N),onOpen:()=>a(l)},w.requestId),n.jsxs(te,{variant:"ghost",size:"xs",className:"self-end text-muted-foreground",onClick:()=>a(l),children:["Open session",b]})]}),u&&n.jsxs("p",{className:"mt-2 truncate text-xs text-muted-foreground",children:["Next: ",n.jsx("span",{className:"font-medium text-foreground",children:i(u.member)})," ",Ie(u.member).toLowerCase()]})]})}function nn({crew:t,hereId:e,busy:s,nameOf:r,onOpen:i,onMarkRead:a,onStop:c,collapsed:o,onToggle:f}){const[g,h]=C.useState("all");let l=null;const w=xs(t).filter(({member:u,depth:x})=>{if(g!=="all"){const m=he(u);return g==="done"?m!=="working"&&m!=="needs-you":m===g}return l!==null&&x>l?!1:(l=o.has(u.sessionId)?x:null,!0)});return n.jsxs("section",{"aria-label":"Sessions",className:"px-1.5 py-2.5",children:[n.jsxs("div",{className:"mb-1.5 flex items-center gap-2 px-1.5",children:[n.jsx("h3",{className:"text-sm font-medium",children:"Sessions"}),n.jsx("span",{className:"flex-1"}),n.jsx("div",{role:"radiogroup","aria-label":"Show sessions",className:"flex gap-0.5",children:Xs.map(({id:u,label:x})=>n.jsx("button",{type:"button",role:"radio","aria-checked":g===u,onClick:()=>h(u),className:oe("rounded-full px-2 py-0.5 text-[11px] text-muted-foreground outline-none hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring",g===u&&"bg-accent text-foreground"),children:x},u))})]}),w.length===0?n.jsx("p",{className:"px-1.5 py-4 text-center text-xs text-muted-foreground",children:"No sessions here."}):n.jsx("ul",{className:"flex flex-col",children:w.map(u=>n.jsx(on,{row:u,here:u.member.sessionId===e,busy:s,name:r(u.member),onOpen:i,onMarkRead:a,onStop:c,collapsed:g==="all"?o.has(u.member.sessionId):void 0,onToggle:()=>f(u.member.sessionId)},u.member.sessionId))})]})}function on(t){var ce,me;const e=ue.c(81),{row:s,here:r,busy:i,name:a,onOpen:c,onMarkRead:o,onStop:f,collapsed:g,onToggle:h}=t,{member:l,depth:w,children:u}=s;let x;e[0]!==l?(x=he(l),e[0]=l,e[1]=x):x=e[1];const m=x;let p;e[2]!==l?(p=Ie(l),e[2]=l,e[3]=p):p=e[3];const y=p;let k;e[4]!==l.pullRequests?(k=(ce=l.pullRequests)==null?void 0:ce.at(-1),e[4]=l.pullRequests,e[5]=k):k=e[5];const b=k;let M;e[6]!==l?(M=Re(l)&&l.result&&l.parentId,e[6]=l,e[7]=M):M=e[7];const N=M,$=(m==="working"||m==="needs-you")&&(!l.device||((me=l.result)==null?void 0:me.state)==="running"&&l.parentId!==null),_=l.sessionId,O=r?"bg-accent":"hover:bg-accent/60",E=w>0&&"border-l border-border/70";let j;e[8]!==O||e[9]!==E?(j=oe("group/crew relative flex items-start rounded-md",O,E),e[8]=O,e[9]=E,e[10]=j):j=e[10];const L=w>0?6+(w-1)*14:0;let I;e[11]!==L?(I={marginLeft:L},e[11]=L,e[12]=I):I=e[12];let A;e[13]!==u||e[14]!==g||e[15]!==a||e[16]!==h?(A=u>0&&g!==void 0&&n.jsx(te,{variant:"ghost",size:"icon-xs","aria-label":`${g?"Expand":"Collapse"} ${a}'s child sessions`,"aria-expanded":!g,onClick:h,children:n.jsx(De,{"data-icon":"inline-start",className:oe("transition-transform",!g&&"rotate-90")})}),e[13]=u,e[14]=g,e[15]=a,e[16]=h,e[17]=A):A=e[17];let S;e[18]!==A?(S=n.jsx("span",{className:"mt-1.5 flex w-6 shrink-0 justify-center",children:A}),e[18]=A,e[19]=S):S=e[19];let R;e[20]!==l||e[21]!==c?(R=()=>c(l),e[20]=l,e[21]=c,e[22]=R):R=e[22];const F=r?"true":void 0,P=`${a}, ${y}`,H=fe[m];let D;e[23]!==H?(D=oe("size-1.5 justify-self-center rounded-full",H),e[23]=H,e[24]=D):D=e[24];let Y;e[25]!==D?(Y=n.jsx("span",{className:D,"aria-hidden":"true"}),e[25]=D,e[26]=Y):Y=e[26];let V;e[27]!==a?(V=n.jsx("span",{className:"truncate",children:a}),e[27]=a,e[28]=V):V=e[28];let U;e[29]!==r?(U=r&&n.jsx("span",{className:"shrink-0 rounded-full border px-1.5 text-[10.5px] font-normal text-muted-foreground",children:"you are here"}),e[29]=r,e[30]=U):U=e[30];let z;e[31]!==V||e[32]!==U?(z=n.jsxs("span",{className:"flex min-w-0 items-center gap-1.5 text-[12.5px] font-medium",children:[V,U]}),e[31]=V,e[32]=U,e[33]=z):z=e[33];let q;e[34]!==l.lastActivityAt?(q=l.lastActivityAt?We(l.lastActivityAt):"",e[34]=l.lastActivityAt,e[35]=q):q=e[35];let W;e[36]!==q?(W=n.jsx("span",{className:"text-[11px] tabular-nums text-muted-foreground/80",children:q}),e[36]=q,e[37]=W):W=e[37];const K=(m==="needs-you"||N)&&"text-warning",d=m==="failed"&&"text-destructive";let v;e[38]!==K||e[39]!==d?(v=oe("min-w-0 flex-1 truncate",K,d),e[38]=K,e[39]=d,e[40]=v):v=e[40];let T;e[41]!==y||e[42]!==v?(T=n.jsx("span",{className:v,children:y}),e[41]=y,e[42]=v,e[43]=T):T=e[43];let X;e[44]!==b?(X=b&&n.jsxs("span",{className:"shrink-0 rounded-full border px-1.5 text-[11px]",children:["#",b.number]}),e[44]=b,e[45]=X):X=e[45];let ae;e[46]!==l.device?(ae=l.device&&n.jsx("span",{className:"shrink-0",children:l.device.name}),e[46]=l.device,e[47]=ae):ae=e[47];let Q;e[48]!==u?(Q=u>0&&n.jsxs("span",{className:"shrink-0",children:[u," ",u===1?"session":"sessions"]}),e[48]=u,e[49]=Q):Q=e[49];let J;e[50]!==l.model?(J=l.model&&n.jsx("span",{className:"shrink-0 text-muted-foreground/70",children:qe(l.model)}),e[50]=l.model,e[51]=J):J=e[51];let ee;e[52]!==T||e[53]!==X||e[54]!==ae||e[55]!==Q||e[56]!==J?(ee=n.jsxs("span",{className:"col-start-2 col-end-4 flex min-w-0 items-center gap-2 text-[11.5px] text-muted-foreground",children:[T,X,ae,Q,J]}),e[52]=T,e[53]=X,e[54]=ae,e[55]=Q,e[56]=J,e[57]=ee):ee=e[57];let se;e[58]!==R||e[59]!==F||e[60]!==P||e[61]!==Y||e[62]!==z||e[63]!==W||e[64]!==ee?(se=n.jsxs("button",{type:"button",onClick:R,"aria-current":F,"aria-label":P,className:"grid min-w-0 flex-1 grid-cols-[14px_minmax(0,1fr)_auto] items-center gap-x-2 gap-y-0.5 rounded-md px-2 py-1.5 text-left outline-none focus-visible:ring-2 focus-visible:ring-ring",children:[Y,z,W,ee]}),e[58]=R,e[59]=F,e[60]=P,e[61]=Y,e[62]=z,e[63]=W,e[64]=ee,e[65]=se):se=e[65];let re;e[66]!==i||e[67]!==$||e[68]!==l||e[69]!==a||e[70]!==o||e[71]!==f||e[72]!==N?(re=(N||$)&&n.jsxs("div",{className:"absolute right-1.5 top-1 hidden gap-1 group-focus-within/crew:flex group-hover/crew:flex",children:[N&&l.result&&l.parentId&&n.jsx(te,{variant:"outline",size:"icon-xs",className:"bg-popover","aria-label":`Mark ${a}'s result read`,title:"Mark the result read",disabled:i.has(l.result.taskId),onClick:()=>void o(l.parentId,l.result.taskId),children:n.jsx(is,{"data-icon":"inline-start"})}),$&&n.jsx(te,{variant:"outline",size:"icon-xs",className:"bg-popover text-destructive","aria-label":`Stop ${a}`,title:"Stop this session",disabled:i.has(l.sessionId),onClick:()=>void f(l),children:n.jsx(rs,{"data-icon":"inline-start"})})]}),e[66]=i,e[67]=$,e[68]=l,e[69]=a,e[70]=o,e[71]=f,e[72]=N,e[73]=re):re=e[73];let Z;return e[74]!==l.sessionId||e[75]!==I||e[76]!==S||e[77]!==se||e[78]!==re||e[79]!==j?(Z=n.jsxs("li",{"data-crew-row":_,className:j,style:I,children:[S,se,re]}),e[74]=l.sessionId,e[75]=I,e[76]=S,e[77]=se,e[78]=re,e[79]=j,e[80]=Z):Z=e[80],Z}export{un as CrewPanel};
1
+ import{r as C,c as ue,j as n}from"./vendor-react-gGw_S5I_.js";import{F as ze,d4 as it,a0 as je,d5 as jt,d6 as yt,d7 as Nt,B as te,E as rt,f as ct,U as It,h as dt,i as ut,ae as Je,d8 as Ct,ac as Qe,aC as et,d9 as kt,da as St,m as ft,ad as Mt,db as $t,av as Rt,cv as Tt,dc as At,cU as Ot,aZ as Et,o as Lt,n as _t,D as zt,j as Dt,c as oe,dd as Ft,bP as Pt,bQ as Yt,bO as qt,de as qe,V as We,df as Wt,ct as Ht,c9 as Ut,ca as Bt,cb as Ae,cc as Oe,al as Gt,k as Vt,dg as Kt,dh as Xt,di as Zt,b8 as Jt}from"./index-BVmNox_3.js";import{S as Qt}from"./switch-gTnbAJaZ.js";import{bS as es,dx as ts,aP as ss,bq as ns,N as ht,bo as pt,bg as os,bx as as,bp as ls,A as De,dy as is,aO as rs,X as cs}from"./vendor-ui-CKjyvB3_.js";import"./vendor-markdown-BEJ8yVzA.js";async function ke(t){if(t.ok)return t;const e=await t.json().catch(()=>null);throw new Error((e==null?void 0:e.error)||"Couldn't update crew chat.")}function Ee(t,e){return[...new Map([...t,...e].map(s=>[s.sequence,s])).values()].sort((s,r)=>s.sequence-r.sequence)}function ds(t){const[e,s]=C.useState(null),[r,i]=C.useState([]),[a,c]=C.useState(null),[o,f]=C.useState(!1),[g,h]=C.useState(!1),[l,w]=C.useState(!1),[u,x]=C.useState(new Set),p=C.useRef(0),m=C.useRef(null),y=C.useRef(!1),k=C.useRef(!1),b=C.useRef(new Set),M=C.useRef(!1),N=C.useRef(null),$=C.useCallback(async j=>{const L=++p.current;try{const I=N.current,S=await(await ke(await ze(`/api/crew-chat/${encodeURIComponent(t)}${I===null?"":`?after=${I}&limit=100`}`))).json();if(!j()||L!==p.current)return;s(R=>R&&JSON.stringify(R.members)===JSON.stringify(S.members)?{...S,members:R.members}:S),i(R=>Ee(R,S.messages)),N.current=S.nextCursor,M.current||(M.current=!0,w(S.hasMore)),c(null)}catch(I){j()&&L===p.current&&c(I instanceof Error?I.message:"Couldn't load crew chat.")}},[t]);it($,2e3);const _=C.useCallback(async j=>{var L;if(y.current)return!1;y.current=!0,f(!0),((L=m.current)==null?void 0:L.text)!==j&&(m.current={text:j,id:crypto.randomUUID()});try{const A=await(await ke(await je(`/api/crew-chat/${encodeURIComponent(t)}`,{text:j,commandId:m.current.id}))).json();return p.current++,i(S=>Ee(S,[A.message])),m.current=null,c(A.pending.length?"Message saved. Some members are unavailable; delivery will retry.":null),!0}catch(I){return c(I instanceof Error?I.message:"Couldn't send the message."),!1}finally{y.current=!1,f(!1)}},[t]),O=C.useCallback(async(j,L)=>{if(!b.current.has(j)){b.current.add(j),x(I=>new Set(I).add(j));try{await ke(await je(`/api/crew-chat/${encodeURIComponent(t)}`,{sessionId:j,listening:L},{method:"PATCH"})),p.current++,s(I=>I&&{...I,members:I.members.map(A=>A.sessionId===j?{...A,listening:L}:A)}),c(null)}catch(I){c(I instanceof Error?I.message:"Couldn't change listening.")}finally{b.current.delete(j),x(I=>{const A=new Set(I);return A.delete(j),A})}}},[t]),E=C.useCallback(async()=>{if(!(!r.length||k.current)){k.current=!0,h(!0);try{const L=await(await ke(await ze(`/api/crew-chat/${encodeURIComponent(t)}?before=${r[0].sequence}`))).json();i(I=>Ee(I,L.messages)),w(L.hasMore)}catch(j){c(j instanceof Error?j.message:"Couldn't load older messages.")}finally{k.current=!1,h(!1)}}},[r,t]);return{page:e,messages:r,error:a,posting:o,busyMembers:u,hasOlder:l,loadingOlder:g,post:_,setListening:O,older:E}}const us=[],fs=new Map;function hs(t){var He,Ue,Be,Ge,Ve,Ke,Xe;const e=ue.c(111),{rootId:s,kinds:r,active:i}=t,a=r===void 0?fs:r,c=i===void 0?!0:i,o=ds(s),[f,g]=C.useState(""),h=C.useRef(null),l=C.useRef(!0);let w;e[0]!==o.messages?(w=(He=o.messages.at(-1))==null?void 0:He.sequence,e[0]=o.messages,e[1]=w):w=e[1];const u=w,x=((Ue=o.page)==null?void 0:Ue.members)??us;let p;e[2]!==x?(p=jt(x),e[2]=x,e[3]=p):p=e[3];const m=p;let y;e[4]!==x||e[5]!==s?(y=yt(x,s),e[4]=x,e[5]=s,e[6]=y):y=e[6];const k=y;let b;e[7]!==x?(b=new Map(x.map(ms)),e[7]=x,e[8]=b):b=e[8];const M=b;let N;e[9]!==o.messages||e[10]!==s?(N=Nt(o.messages,s),e[9]=o.messages,e[10]=s,e[11]=N):N=e[11];const $=N;let _;e[12]!==c?(_=()=>{var V,B;c&&l.current&&((B=(V=h.current)==null?void 0:V.scrollIntoView)==null||B.call(V,{block:"end"}))},e[12]=c,e[13]=_):_=e[13];let O;e[14]!==c||e[15]!==u?(O=[c,u],e[14]=c,e[15]=u,e[16]=O):O=e[16],C.useEffect(_,O);let E;e[17]!==o||e[18]!==f?(E=async()=>{const V=f.trim();!V||o.posting||await o.post(V)&&(g(B=>B.trim()===V?"":B),l.current=!0)},e[17]=o,e[18]=f,e[19]=E):E=e[19];const j=E;let L;e[20]!==o.page||e[21]!==x?(L=o.page?`${x.filter(ps).length} listening · Members & mentions`:"Loading chat…",e[20]=o.page,e[21]=x,e[22]=L):L=e[22];let I;e[23]!==L?(I=n.jsx("summary",{className:"cursor-pointer text-xs text-muted-foreground",children:L}),e[23]=L,e[24]=I):I=e[24];let A;if(e[25]!==o||e[26]!==a||e[27]!==x||e[28]!==s||e[29]!==k){let V;e[31]!==o||e[32]!==a||e[33]!==s||e[34]!==k?(V=B=>{var Ze;return n.jsxs(Je,{orientation:"horizontal",className:"items-center gap-2",children:[n.jsx(Ct,{role:B.sessionId===s?"lead":"agent",sessionId:B.sessionId,kinds:a,tints:k,className:"size-5"}),n.jsxs(Qe,{className:"min-w-0 flex-1 items-baseline gap-1.5",htmlFor:`listen-${B.sessionId}`,"aria-label":`Listen for ${B.name}`,children:[n.jsx("span",{className:"truncate",children:B.name}),n.jsxs("span",{className:"truncate text-xs font-normal text-muted-foreground",children:["@",B.handle]})]}),n.jsx(te,{variant:"ghost",size:"icon-xs",disabled:!((Ze=o.page)!=null&&Ze.canPost)||!B.canInteract,onClick:()=>g(ye=>`${ye}${ye&&!/\s$/.test(ye)?" ":""}@${B.handle} `),"aria-label":`Mention ${B.name}`,title:`Mention @${B.handle}`,className:"text-muted-foreground",children:n.jsx(ts,{"data-icon":"inline-start"})}),n.jsx(Qt,{id:`listen-${B.sessionId}`,size:"sm",checked:B.listening,disabled:!B.canInteract||o.busyMembers.has(B.sessionId),onCheckedChange:ye=>void o.setListening(B.sessionId,ye)})]},B.sessionId)},e[31]=o,e[32]=a,e[33]=s,e[34]=k,e[35]=V):V=e[35],A=x.map(V),e[25]=o,e[26]=a,e[27]=x,e[28]=s,e[29]=k,e[30]=A}else A=e[30];let S;e[36]!==A?(S=n.jsx(et,{className:"max-h-48 gap-2 overflow-y-auto py-2",children:A}),e[36]=A,e[37]=S):S=e[37];let R;e[38]===Symbol.for("react.memo_cache_sentinel")?(R=n.jsx("p",{className:"pb-1 text-xs text-muted-foreground",children:"Listening sends short notices while an agent works. @mentions send the full message, even when listening is off."}),e[38]=R):R=e[38];let F;e[39]!==I||e[40]!==S?(F=n.jsxs("details",{className:"shrink-0 border-b px-3 py-2",children:[I,S,R]}),e[39]=I,e[40]=S,e[41]=F):F=e[41];let P;e[42]===Symbol.for("react.memo_cache_sentinel")?(P=V=>{const B=V.target;l.current=B.scrollHeight-B.scrollTop-B.clientHeight<80},e[42]=P):P=e[42];let H;e[43]!==o?(H=o.hasOlder&&n.jsx("div",{className:"flex justify-center py-2",children:n.jsx(te,{variant:"ghost",size:"xs",disabled:o.loadingOlder,onClick:()=>void o.older(),children:o.loadingOlder?"Loading…":"Load earlier messages"})}),e[43]=o,e[44]=H):H=e[44];let D;e[45]!==o.messages.length||e[46]!==o.page?(D=o.page&&o.messages.length===0&&n.jsx(rt,{children:n.jsxs(ct,{children:[n.jsx(It,{variant:"icon",children:n.jsx(es,{})}),n.jsx(dt,{children:"Talk to the crew"}),n.jsx(ut,{children:"Share a discovery, ask a question, or tag someone for their input."})]})}),e[45]=o.messages.length,e[46]=o.page,e[47]=D):D=e[47];let Y;if(e[48]!==M||e[49]!==m||e[50]!==a||e[51]!==s||e[52]!==$||e[53]!==k){let V;e[55]!==M||e[56]!==m||e[57]!==a||e[58]!==s||e[59]!==k?(V=B=>n.jsxs(C.Fragment,{children:[B.day!==void 0&&n.jsx(kt,{day:B.day}),n.jsx(St,{run:B,members:M,handles:m,kinds:a,tints:k,rootId:s})]},B.messages[0].sequence),e[55]=M,e[56]=m,e[57]=a,e[58]=s,e[59]=k,e[60]=V):V=e[60],Y=$.map(V),e[48]=M,e[49]=m,e[50]=a,e[51]=s,e[52]=$,e[53]=k,e[54]=Y}else Y=e[54];let G;e[61]===Symbol.for("react.memo_cache_sentinel")?(G=n.jsx("div",{ref:h}),e[61]=G):G=e[61];let U;e[62]!==Y?(U=n.jsxs("div",{role:"log","aria-label":"Shared messages","aria-live":"polite","aria-relevant":"additions",className:"flex flex-col gap-4 px-3 py-3",children:[Y,G]}),e[62]=Y,e[63]=U):U=e[63];let z;e[64]!==H||e[65]!==D||e[66]!==U?(z=n.jsxs(ft,{className:"min-h-0 flex-1",onScrollCapture:P,children:[H,D,U]}),e[64]=H,e[65]=D,e[66]=U,e[67]=z):z=e[67];let q;e[68]!==j?(q=V=>{V.preventDefault(),j()},e[68]=j,e[69]=q):q=e[69];const W=!!o.error,K=`crew-chat-${s}`;let d;e[70]!==K?(d=n.jsx(Qe,{htmlFor:K,className:"sr-only",children:"Message the crew"}),e[70]=K,e[71]=d):d=e[71];const v=`crew-chat-${s}`,T=!((Be=o.page)!=null&&Be.canPost),X=!!o.error;let ae;e[72]===Symbol.for("react.memo_cache_sentinel")?(ae=V=>g(V.target.value),e[72]=ae):ae=e[72];let J;e[73]!==j?(J=V=>{V.key==="Enter"&&(V.metaKey||V.ctrlKey)&&!V.nativeEvent.isComposing&&(V.preventDefault(),j())},e[73]=j,e[74]=J):J=e[74];let Q;e[75]!==f||e[76]!==v||e[77]!==T||e[78]!==X||e[79]!==J?(Q=n.jsx(Mt,{id:v,value:f,rows:3,maxLength:$t,placeholder:"Message the crew… use @ to tag an agent",disabled:T,"aria-invalid":X,onChange:ae,onKeyDown:J}),e[75]=f,e[76]=v,e[77]=T,e[78]=X,e[79]=J,e[80]=Q):Q=e[80];let ee;e[81]!==o.error?(ee=o.error&&n.jsx("p",{role:"alert",className:"text-xs text-destructive",children:o.error}),e[81]=o.error,e[82]=ee):ee=e[82];let se;e[83]!==W||e[84]!==d||e[85]!==Q||e[86]!==ee?(se=n.jsxs(Je,{"data-invalid":W,children:[d,Q,ee]}),e[83]=W,e[84]=d,e[85]=Q,e[86]=ee,e[87]=se):se=e[87];const re=((Ge=o.page)==null?void 0:Ge.canPost)===!1?"You have read access to this crew.":"⌘ / Ctrl + Enter to send";let Z;e[88]!==re?(Z=n.jsx(Rt,{className:"flex-1",children:re}),e[88]=re,e[89]=Z):Z=e[89];let ce;e[90]!==((Ve=o.page)==null?void 0:Ve.canPost)||e[91]!==o.posting||e[92]!==f?(ce=!((Ke=o.page)!=null&&Ke.canPost)||!f.trim()||o.posting,e[90]=(Xe=o.page)==null?void 0:Xe.canPost,e[91]=o.posting,e[92]=f,e[93]=ce):ce=e[93];let pe;e[94]===Symbol.for("react.memo_cache_sentinel")?(pe=n.jsx(ss,{"data-icon":"inline-start"}),e[94]=pe):pe=e[94];const Te=o.posting?"Sending…":"Send";let ge;e[95]!==ce||e[96]!==Te?(ge=n.jsxs(te,{type:"submit",size:"sm",disabled:ce,children:[pe,Te]}),e[95]=ce,e[96]=Te,e[97]=ge):ge=e[97];let xe;e[98]!==Z||e[99]!==ge?(xe=n.jsxs("div",{className:"flex items-center gap-2",children:[Z,ge]}),e[98]=Z,e[99]=ge,e[100]=xe):xe=e[100];let we;e[101]!==se||e[102]!==xe?(we=n.jsxs(et,{className:"gap-2",children:[se,xe]}),e[101]=se,e[102]=xe,e[103]=we):we=e[103];let be;e[104]!==q||e[105]!==we?(be=n.jsx("form",{className:"shrink-0 border-t p-3",onSubmit:q,children:we}),e[104]=q,e[105]=we,e[106]=be):be=e[106];let Ce;return e[107]!==F||e[108]!==z||e[109]!==be?(Ce=n.jsxs("section",{"aria-label":"Crew chat",className:"flex h-full min-h-0 flex-col",children:[F,z,be]}),e[107]=F,e[108]=z,e[109]=be,e[110]=Ce):Ce=e[110],Ce}function ps(t){return t.listening}function ms(t){return[t.sessionId,t]}const fe={working:"bg-success ring-2 ring-success/30","needs-you":"bg-warning",done:"bg-muted-foreground/50",failed:"bg-destructive",unreachable:"border border-muted-foreground/60"};function mt(t){const e=new Date(t),s=e.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"});return e.toDateString()===new Date().toDateString()?s:`${e.toLocaleDateString([],{month:"short",day:"numeric"})}, ${s}`}function he(t){if(t.status==="deferred")return"needs-you";switch(t.outcome){case"needs_input":return"needs-you";case"running":return"working";case"error":return"failed";case"unreachable":case"not_found":return"unreachable";default:return"done"}}function tt(t,e){var s,r;return{sessionId:t.sessionId,dirName:((s=t.address)==null?void 0:s.dirName)??"",fileName:((r=t.address)==null?void 0:r.fileName)??"",projectShortName:"",lastModified:t.lastActivityAt??"",lastActivityAt:t.lastActivityAt,size:0,cwd:t.cwd,customTitle:t.customTitle,aiTitle:t.aiTitle,firstUserMessage:t.firstUserMessage,...t.parentId&&{crew:{rootId:e,parentId:t.parentId,startedAt:t.startedAt??0,...t.name&&{name:t.name}}}}}function gs(t,e,s){var o;const r=((o=[...e.values()].find(f=>f.parentId===null))==null?void 0:o.sessionId)??t.sessionId,i=s[t.sessionId],a=tt(t,r);if(!t.parentId)return Tt(a,i);const c=e.get(t.parentId);return At(a,{customName:i,parent:c&&tt(c,r)})}function xs(t){const e=new Map;for(const a of t.members){if(!a.parentId)continue;const c=e.get(a.parentId);c?c.push(a):e.set(a.parentId,[a])}const s=[],r=new Set,i=(a,c)=>{var f;const o=[...e.get(a)??[]].sort((g,h)=>(g.startedAt??0)-(h.startedAt??0));for(const g of o)r.has(g.sessionId)||(r.add(g.sessionId),s.push({member:g,depth:c,children:((f=e.get(g.sessionId))==null?void 0:f.length)??0}),i(g.sessionId,c+1))};i(t.rootId,0);for(const a of t.members)a.parentId&&!r.has(a.sessionId)&&(r.add(a.sessionId),s.push({member:a,depth:0,children:0}));return s}function ws(t){const e=({member:s,pending:r})=>r.askedAt??(Date.parse(s.lastActivityAt??"")||0);return t.members.flatMap(s=>s.waiting.map(r=>({member:s,pending:r}))).sort((s,r)=>e(s)-e(r))}function bs(t){const e={size:0,working:0,needsYou:0,done:0,failed:0,unreachable:0,unreadResults:0};for(const s of t.members){if(!s.parentId)continue;e.size++;const r=he(s);r==="working"?e.working++:r==="needs-you"?e.needsYou++:r==="failed"?e.failed++:r==="unreachable"?e.unreachable++:e.done++,Re(s)&&e.unreadResults++}return e}function Re(t){return!!(t.result&&t.result.state!=="running"&&!t.result.acknowledged)}function Ie(t){const[e]=t.waiting;switch(he(t)){case"needs-you":return(e==null?void 0:e.kind)==="permission"?`Waiting on a permission · ${e.toolName}`:(e==null?void 0:e.kind)==="question"?"Asked a question":!e&&t.status==="deferred"?"Awaiting permission review":"Plan to review";case"working":return t.status==="tool_use"&&t.toolName?t.toolName:t.status==="thinking"?"Thinking":t.status==="compacting"?"Compacting":t.status==="awaiting_agents"?"Waiting on its agents":"Working";case"failed":return t.error?`Failed · ${t.error}`:"Failed";case"unreachable":return t.device?`${t.device.name} is not answering`:"Not found";default:return Re(t)?"Finished · result unread":"Finished"}}const le=196,ne=86,de=40,ve=12,vs=28,Me=6,st=8,me=10,js=6,$e=28,Fe=36;function gt(t){const e=he(t);return e==="working"||e==="needs-you"}function ys(t){const e={all:t.members.length,active:0,working:0,needsYou:0};for(const s of t.members){const r=he(s);r==="working"?e.working++:r==="needs-you"&&e.needsYou++}return e.active=e.working+e.needsYou,e}const nt=(t,e)=>(t.startedAt??0)-(e.startedAt??0)||t.sessionId.localeCompare(e.sessionId);function xt(t){const e=new Map(t.members.map(i=>[i.sessionId,i])),s=new Map,r=[];for(const i of t.members){const a=i.parentId&&i.sessionId!==t.rootId?e.get(i.parentId):void 0;if(!a){r.push(i);continue}const c=s.get(a.sessionId);c?c.push(i):s.set(a.sessionId,[i])}for(const i of s.values())i.sort(nt);return r.sort((i,a)=>+(a.sessionId===t.rootId)-+(i.sessionId===t.rootId)||nt(i,a)),{roots:r,childrenOf:s}}function Ns(t,e){if(e==="all")return new Set(t.members.map(i=>i.sessionId));const s=new Map(t.members.map(i=>[i.sessionId,i])),r=new Set;for(const i of t.members){if(!gt(i))continue;let a=i;for(;a&&!r.has(a.sessionId);)r.add(a.sessionId),a=a.sessionId===t.rootId||!a.parentId?void 0:s.get(a.parentId)}return r}function Is(t){const{roots:e,childrenOf:s}=xt(t),r=new Set;let i=0;const a=e.map(c=>({member:c,depth:0}));for(;a.length>0;){const{member:c,depth:o}=a.pop();if(!r.has(c.sessionId)){r.add(c.sessionId),i=Math.max(i,o);for(const f of s.get(c.sessionId)??[])a.push({member:f,depth:o+1})}}return i}function Cs(t){return(t+1)*le+t*de}function ks(t,e,s,{group:r=!1,stacked:i}={}){const{roots:a,childrenOf:c}=xt(t),o=Ns(t,e),f=N=>(c.get(N)??[]).filter($=>o.has($.sessionId)),g=(i==null?void 0:i.cardWidth)??le,h=[],l=[],w=[],u=new Set;let x=0,p=0;const m=N=>{const $={count:0,working:0,needsYou:0},_=new Set(u),O=[...f(N)];for(;O.length>0;){const E=O.pop();if(_.has(E.sessionId))continue;_.add(E.sessionId),$.count++;const j=he(E);j==="working"?$.working++:j==="needs-you"&&$.needsYou++,O.push(...f(E.sessionId))}return $},y=N=>f(N).filter($=>!u.has($.sessionId)),k=N=>y(N.sessionId).length===0||s.has(N.sessionId),b=(N,$,_)=>{u.add(N.sessionId);const O=y(N.sessionId),E=O.length>0&&s.has(N.sessionId),j=E?[]:O,L=r&&!i&&j.length>=st?j.filter(k):[],I=L.length>=st?L:[],A=new Set(I),S=j.filter(P=>!A.has(P)),R={member:N,depth:$,x:(_==null?void 0:_.x)??$*(i?$e:le+de),y:(_==null?void 0:_.y)??x+(S.length===0&&I.length>0?me:0),childCount:O.length,collapsed:E,hidden:E?m(N.sessionId):{count:0,working:0,needsYou:0},context:e==="active"&&!gt(N),grouped:!!_};if(h.push(R),p=Math.max(p,R.x+g+(i&&O.length>0?Fe:0)),i){x+=ne+ve;const P=j.map(H=>b(H,$+1));return P.length>0&&l.push({parentId:N.sessionId,path:Ms(R.x,R.y,P)}),R.y}if(E){const P=R.y+ne/2;l.push({parentId:N.sessionId,path:`M${R.x+le} ${P}H${R.x+le+de/2}`})}if(_)return R.y;if(j.length===0)return x+=ne+ve,R.y;const F=S.map(P=>b(P,$+1));return I.length>0&&F.push(M(N.sessionId,I,$+1)+me),l.push({parentId:N.sessionId,path:Ss(R.x+le,R.y,F)}),R.y},M=(N,$,_)=>{const O=Math.min(js,Math.max(2,Math.ceil(Math.sqrt($.length/1.5)))),E=Math.ceil($.length/O),j={parentId:N,x:_*(le+de),y:x,width:O*le+(O-1)*de+2*me,height:E*ne+(E-1)*ve+2*me};return w.push(j),$.forEach((L,I)=>b(L,_,{x:j.x+me+I%O*(le+de),y:j.y+me+Math.floor(I/O)*(ne+ve)})),p=Math.max(p,j.x+j.width),x+=j.height+ve,j.y};for(const N of a)!o.has(N.sessionId)||u.has(N.sessionId)||(h.length>0&&(x+=vs),b(N,0));return{orientation:i?"stacked":"across",cardWidth:g,nodes:h,edges:l,groups:w,width:p,height:Math.max(0,x-ve)}}function Ss(t,e,s){const r=e+ne/2,i=[`M${t} ${r}H${t+de}`];for(const a of s)a!==e&&i.push(wt(t,r,a+ne/2));return i.join("")}function wt(t,e,s){const r=t+de/2;return`M${r} ${e}V${s-Me}Q${r} ${s} ${r+Me} ${s}H${t+de}`}function Ms(t,e,s){return s.map(r=>bt(t,e,r)).join("")}function bt(t,e,s){const r=t+$e/2,i=s+ne/2;return`M${r} ${e+ne}V${i-Me}Q${r} ${i} ${r+Me} ${i}H${t+$e}`}function $s(t,e){const s=new Map(t.nodes.map(c=>[c.member.sessionId,c])),r=new Map(t.groups.map(c=>[c.parentId,c]));let i=e?s.get(e):void 0;const a=[];for(;i!=null&&i.member.parentId;){const c=i.member.parentId,o=s.get(c);if(!o||o.depth!==i.depth-1)break;if(t.orientation==="stacked"){a.unshift(bt(o.x,o.y,i.y)),i=o;continue}const f=o.x+le,g=o.y+ne/2,h=i.grouped?r.get(c):void 0,l=(h?h.y+me:i.y)+ne/2;a.unshift(l===g?`M${f} ${g}H${f+de}`:`M${f} ${g}H${f+de/2}${wt(f,g,l)}`),i=o}return a.length>0?a.join(""):null}const ie=14,Pe=.25,ot=1.5,Rs=.7,Se=1.2,Ts=56,As=900,Os=.85,Es=320,Le={all:new Set,active:new Set};function Ls(t){const[e,s]=Ot(Et("crew-map-filter"),"all"),r=e==="active"?"active":"all",[i,a]=C.useState({rootId:t,folds:Le}),c=C.useRef(new Map),o=i.rootId===t?i.folds:Le,f=C.useCallback(h=>a(l=>{const w=l.rootId===t?l.folds:Le,u=new Set(w[r]);return u.delete(h)||u.add(h),{rootId:t,folds:{...w,[r]:u}}}),[r,t]),g=C.useMemo(()=>({get current(){return c.current.get(t)??null},set current(h){c.current.set(t,h)}}),[t]);return{filter:r,setFilter:s,collapsed:o[r],toggle:f,viewport:g}}function _s(t){const e=ue.c(86),{crew:s,hereId:r,controls:i,kinds:a,nameOf:c,onOpen:o}=t,[f,g]=C.useState(!1),{filter:h,collapsed:l,toggle:w}=i;let u,x,p,m,y,k,b,M,N,$,_,O,E,j,L,I;if(e[0]!==l||e[1]!==i||e[2]!==s||e[3]!==f||e[4]!==h||e[5]!==r||e[6]!==a||e[7]!==c||e[8]!==o||e[9]!==w){let U;e[26]!==s.rootId?(U=v=>v.sessionId===s.rootId,e[26]=s.rootId,e[27]=U):U=e[27];const z=s.members.find(U);let q;e[28]!==l||e[29]!==i||e[30]!==s||e[31]!==h||e[32]!==r||e[33]!==a||e[34]!==c||e[35]!==w?(q=(v,T)=>n.jsx(Ps,{crew:s,collapsed:l,groups:!v,filter:h,hereId:r,kinds:a,nameOf:c,memory:v,onOpen:T,onToggle:w,onShowAll:()=>i.setFilter("all")}),e[28]=l,e[29]=i,e[30]=s,e[31]=h,e[32]=r,e[33]=a,e[34]=c,e[35]=w,e[36]=q):q=e[36],p=q,k="flex h-full min-h-0 flex-col";let W;e[37]!==i||e[38]!==s?(W=n.jsx(at,{crew:s,controls:i}),e[37]=i,e[38]=s,e[39]=W):W=e[39];let K;e[40]===Symbol.for("react.memo_cache_sentinel")?(K=n.jsx("span",{className:"flex-1"}),e[40]=K):K=e[40];let d;e[41]===Symbol.for("react.memo_cache_sentinel")?(d=n.jsx(te,{variant:"ghost",size:"icon-xs","aria-label":"Expand the map",title:"Expand the map",onClick:()=>g(!0),children:n.jsx(ns,{"data-icon":"inline-start"})}),e[41]=d):d=e[41],e[42]!==W?(b=n.jsxs("div",{className:"flex shrink-0 items-center gap-2 px-3 pb-2",children:[W,K,d]}),e[42]=W,e[43]=b):b=e[43],e[44]!==p||e[45]!==i.viewport||e[46]!==o?(M=p(i.viewport,o),e[44]=p,e[45]=i.viewport,e[46]=o,e[47]=M):M=e[47],x=Lt,I=f,y=g,u=_t,O=!0,E="flex h-[calc(100dvh-1rem)] w-[calc(100vw-1rem)] max-w-none flex-col gap-0 overflow-hidden p-0 sm:h-[calc(100dvh-4rem)] sm:w-[calc(100vw-4rem)] sm:max-w-none",e[48]===Symbol.for("react.memo_cache_sentinel")?(j=n.jsx(zt,{className:"sr-only",children:"Crew map"}),L=n.jsx(Dt,{className:"sr-only",children:"Every session in this crew, from the one that started it."}),e[48]=j,e[49]=L):(j=e[48],L=e[49]),$="flex h-12 shrink-0 items-center gap-3 pl-4 pr-14",e[50]===Symbol.for("react.memo_cache_sentinel")?(_=n.jsx(ht,{"aria-hidden":"true",className:"size-4 shrink-0 text-muted-foreground"}),e[50]=_):_=e[50],m="min-w-0 truncate text-sm font-medium",N=z?c(z):"Crew",e[0]=l,e[1]=i,e[2]=s,e[3]=f,e[4]=h,e[5]=r,e[6]=a,e[7]=c,e[8]=o,e[9]=w,e[10]=u,e[11]=x,e[12]=p,e[13]=m,e[14]=y,e[15]=k,e[16]=b,e[17]=M,e[18]=N,e[19]=$,e[20]=_,e[21]=O,e[22]=E,e[23]=j,e[24]=L,e[25]=I}else u=e[10],x=e[11],p=e[12],m=e[13],y=e[14],k=e[15],b=e[16],M=e[17],N=e[18],$=e[19],_=e[20],O=e[21],E=e[22],j=e[23],L=e[24],I=e[25];let A;e[51]!==m||e[52]!==N?(A=n.jsx("span",{className:m,children:N}),e[51]=m,e[52]=N,e[53]=A):A=e[53];let S;e[54]===Symbol.for("react.memo_cache_sentinel")?(S=n.jsx("span",{className:"flex-1"}),e[54]=S):S=e[54];let R;e[55]!==i||e[56]!==s?(R=n.jsx(at,{crew:s,controls:i}),e[55]=i,e[56]=s,e[57]=R):R=e[57];let F;e[58]!==A||e[59]!==R||e[60]!==$||e[61]!==_?(F=n.jsxs("header",{className:$,children:[_,A,S,R]}),e[58]=A,e[59]=R,e[60]=$,e[61]=_,e[62]=F):F=e[62];let P;e[63]!==o?(P=U=>{g(!1),o(U)},e[63]=o,e[64]=P):P=e[64];let H;e[65]!==p||e[66]!==P?(H=p(null,P),e[65]=p,e[66]=P,e[67]=H):H=e[67];let D;e[68]!==u||e[69]!==F||e[70]!==H||e[71]!==O||e[72]!==E||e[73]!==j||e[74]!==L?(D=n.jsxs(u,{showCloseButton:O,className:E,children:[j,L,F,H]}),e[68]=u,e[69]=F,e[70]=H,e[71]=O,e[72]=E,e[73]=j,e[74]=L,e[75]=D):D=e[75];let Y;e[76]!==x||e[77]!==y||e[78]!==D||e[79]!==I?(Y=n.jsx(x,{open:I,onOpenChange:y,children:D}),e[76]=x,e[77]=y,e[78]=D,e[79]=I,e[80]=Y):Y=e[80];let G;return e[81]!==k||e[82]!==b||e[83]!==M||e[84]!==Y?(G=n.jsxs("div",{className:k,children:[b,M,Y]}),e[81]=k,e[82]=b,e[83]=M,e[84]=Y,e[85]=G):G=e[85],G}function at(t){const e=ue.c(3),{crew:s,controls:r}=t;let i;if(e[0]!==r||e[1]!==s){const a=ys(s),c=[{id:"all",label:"All",count:a.all,hint:"Every session in the crew"},{id:"active",label:"Active",count:a.active,hint:"Sessions working or waiting on you, and the sessions that started them"}];i=n.jsx("div",{role:"radiogroup","aria-label":"Show on the map",className:"flex shrink-0 gap-0.5 rounded-full border bg-background p-0.5",children:c.map(o=>{const{id:f,label:g,count:h,hint:l}=o;return n.jsxs("button",{type:"button",role:"radio","aria-checked":r.filter===f,"aria-label":`${g}, ${vt(h)}`,title:l,onClick:()=>r.setFilter(f),className:oe("inline-flex items-center gap-1.5 rounded-full px-2.5 py-0.5 text-xs text-muted-foreground outline-none transition-colors hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring",r.filter===f&&"bg-accent text-foreground"),children:[g,n.jsx("span",{className:"tabular-nums text-muted-foreground",children:h})]},f)})}),e[0]=r,e[1]=s,e[2]=i}else i=e[2];return i}function vt(t){return`${t} ${t===1?"session":"sessions"}`}function _e(t,e,s){return t.orientation==="stacked"?{scale:e,left:ie,top:ie}:{scale:e,left:Math.max(ie,(s.width-t.width*e)/2),top:Math.max(ie,Math.min((s.height-t.height*e)/2,s.height*.12))}}function zs(t,e,s){return{width:Math.max(s.width,e.left+t.width*e.scale+ie),height:Math.max(s.height,e.top+t.height*e.scale+Ts)}}function lt(t,e,{widthOnly:s=!1}={}){if(t.width===0||e.width===0)return 1;const r=(e.width-2*ie)/t.width,i=s?r:Math.min(r,(e.height-2*ie)/t.height);return Ye(i,Pe,1)}const Ye=(t,e,s)=>Math.min(s,Math.max(e,t));function Ds(t,e,s,r,i){var w;const a=new Map(e.layout.nodes.map(u=>[u.member.sessionId,u])),c=new Map(s.nodes.map(u=>[u.member.sessionId,u]));if(e.frame===r&&a.size===c.size&&s.nodes.every(u=>{const x=a.get(u.member.sessionId);return x!==void 0&&x.x===u.x&&x.y===u.y}))return null;const f=u=>({x:e.frame.left+u.x*e.frame.scale-t.left,y:e.frame.top+u.y*e.frame.scale-t.top}),g=i&&a.has(i)&&c.has(i)?i:(w=e.layout.nodes.filter(u=>c.has(u.member.sessionId)).map(u=>({node:u,screen:f(u)})).filter(({screen:u})=>u.y+ne*e.frame.scale>0&&u.x+e.layout.cardWidth*e.frame.scale>0).sort((u,x)=>u.screen.y-x.screen.y||u.screen.x-x.screen.x)[0])==null?void 0:w.node.member.sessionId;if(!g)return null;const h=f(a.get(g)),l=c.get(g);return{left:r.left+l.x*r.scale-h.x,top:r.top+l.y*r.scale-h.y}}function Fs(t,e,s,r){const i=new Map(t.nodes.map(x=>[x.member.sessionId,x])),a=e?i.get(e):void 0;if(!a)return{left:0,top:0};const{scale:c}=s,o=s.left+a.x*c,f=s.top+a.y*c,g=o+t.cardWidth*c,h=f+ne*c;if(g<=r.clientWidth&&h<=r.clientHeight)return{left:0,top:0};const l=a.member.parentId&&i.get(a.member.parentId)||a;let w=s.left+Math.min(l.x,a.x)*c-ie,u=s.top+Math.min(l.y,a.y)*c-ie;return g-w>r.clientWidth&&(w=o-ie),h-u>r.clientHeight&&(u=f-r.clientHeight/3),{left:Math.max(0,w),top:Math.max(0,u)}}function Ps({crew:t,collapsed:e,groups:s,filter:r,hereId:i,kinds:a,nameOf:c,memory:o,onOpen:f,onToggle:g,onShowAll:h}){const l=C.useRef(null),[w,u]=C.useState({width:0,height:0}),x=s&&w.width>=As,p=C.useMemo(()=>Is(t),[t]),m=w.width-2*ie,y=!s&&w.width>0&&Cs(p)*Os>m,k=y?Ye(m-p*$e-Fe,le,Es):le,b=C.useMemo(()=>ks(t,r,e,{group:x,...y&&{stacked:{cardWidth:k}}}),[t,r,e,x,y,k]),[M,N]=C.useState(()=>{var d;return((d=o==null?void 0:o.current)==null?void 0:d.frame)??{scale:1,left:ie,top:ie}}),[$,_]=C.useState(!1),O=C.useRef(null),E=C.useRef(null),j=C.useRef({left:0,top:0}),L=C.useRef(null),I=C.useRef(null),A=zs(b,M,w),{scale:S}=M;C.useLayoutEffect(()=>{const d=l.current;if(!d)return;const v=()=>u(X=>X.width===d.clientWidth&&X.height===d.clientHeight?X:{width:d.clientWidth,height:d.clientHeight});v();const T=new ResizeObserver(v);return T.observe(d),()=>T.disconnect()},[]);const R=C.useCallback(d=>{const v=l.current;o&&v&&(o.current={frame:d,left:v.scrollLeft,top:v.scrollTop})},[o]),F=C.useCallback((d,v)=>{O.current={frame:d,scroll:v},N(d)},[]),P=C.useCallback(d=>{const v=_e(d,Math.max(lt(d,w,{widthOnly:!0}),Rs),w);F(v,()=>{const T=l.current;return T?Fs(d,i,v,T):{left:0,top:0}})},[F,i,w]);C.useLayoutEffect(()=>{const d=l.current;if(w.width===0||!d)return;const v=L.current;if(v){if(v.filter!==r||v.layout.orientation!==b.orientation)P(b);else if(v.layout!==b){const T=Ds(j.current,v,b,M,E.current);T&&(d.scrollLeft=T.left,d.scrollTop=T.top,j.current={left:d.scrollLeft,top:d.scrollTop})}}else{const T=o==null?void 0:o.current;T?F(T.frame,()=>({left:T.left,top:T.top})):P(b)}E.current=null,L.current={layout:b,filter:r,frame:M}}),C.useLayoutEffect(()=>{const d=O.current,v=l.current;if(!d||!v||d.frame!==M)return;O.current=null;const{left:T,top:X}=d.scroll();v.scrollLeft=T,v.scrollTop=X,j.current={left:v.scrollLeft,top:v.scrollTop},R(M)});const H=C.useRef(i);C.useEffect(()=>{var d,v;H.current!==i&&(H.current=i,i&&((v=(d=l.current)==null?void 0:d.querySelector(`[data-crew-map-card="${CSS.escape(i)}"]`))==null||v.scrollIntoView({block:"nearest",inline:"nearest",behavior:"smooth"})))},[i]);const D=C.useCallback((d,v)=>{var ce;const T=l.current,X=((ce=O.current)==null?void 0:ce.frame.scale)??S,ae=Ye(X*d,Pe,ot);if(!T||ae===X)return;const J=T.getBoundingClientRect(),Q=v?v.clientX-J.left:T.clientWidth/2,ee=v?v.clientY-J.top:T.clientHeight/2,se=(T.scrollLeft+Q-M.left)/S,re=(T.scrollTop+ee-M.top)/S,Z=_e(b,ae,w);F(Z,()=>({left:Z.left+se*Z.scale-Q,top:Z.top+re*Z.scale-ee}))},[F,M.left,M.top,b,S,w]),Y=C.useRef(D);C.useLayoutEffect(()=>{Y.current=D}),C.useEffect(()=>{const d=l.current;if(!d)return;const v=T=>{!T.ctrlKey&&!T.metaKey||(T.preventDefault(),Y.current(Math.exp(-T.deltaY*.01),T))};return d.addEventListener("wheel",v,{passive:!1}),()=>d.removeEventListener("wheel",v)},[]);const G=d=>{const v=l.current;!v||d.pointerType!=="mouse"||d.button!==0||d.target.closest("button")||(I.current={pointerId:d.pointerId,x:d.clientX,y:d.clientY,left:v.scrollLeft,top:v.scrollTop},v.setPointerCapture(d.pointerId),_(!0))},U=d=>{const v=I.current,T=l.current;!v||!T||v.pointerId!==d.pointerId||(T.scrollLeft=v.left-(d.clientX-v.x),T.scrollTop=v.top-(d.clientY-v.y))},z=d=>{var v,T;((v=I.current)==null?void 0:v.pointerId)===d.pointerId&&(I.current=null,(T=l.current)==null||T.releasePointerCapture(d.pointerId),_(!1))},q=C.useMemo(()=>$s(b,i),[b,i]),W=b.nodes.length===0,K=b.orientation==="stacked"?b.cardWidth+Fe/2:le+de/2;return n.jsxs("div",{className:"relative min-h-0 flex-1 border-t",children:[n.jsx("div",{ref:l,role:"region","aria-label":"Crew map","data-crew-map-layout":b.orientation,onScroll:d=>{j.current={left:d.currentTarget.scrollLeft,top:d.currentTarget.scrollTop},O.current||R(M)},onPointerDown:G,onPointerMove:U,onPointerUp:z,onPointerCancel:z,onKeyDown:d=>{d.target===d.currentTarget&&(d.key==="+"||d.key==="="?D(Se):d.key==="-"&&D(1/Se))},tabIndex:-1,className:oe("absolute inset-0 overflow-auto overscroll-contain outline-none [touch-action:pan-x_pan-y]","bg-muted/30 bg-local bg-[radial-gradient(circle,var(--border)_1px,transparent_1px)] bg-size-[18px_18px]",$?"cursor-grabbing select-none":"cursor-grab"),children:W?n.jsxs(rt,{className:"h-full",children:[n.jsxs(ct,{children:[n.jsx(dt,{children:"Nothing is active"}),n.jsx(ut,{className:"text-xs",children:"No session in this crew is working or waiting on you."})]}),n.jsx(te,{variant:"outline",size:"xs",onClick:h,children:"Show all sessions"})]}):n.jsx("div",{className:"relative",style:{width:A.width,height:A.height},children:n.jsxs("div",{className:"absolute origin-top-left",style:{left:M.left,top:M.top,width:b.width,height:b.height,transform:`scale(${S})`},children:[b.groups.map(d=>n.jsx("div",{"aria-hidden":"true",className:"absolute rounded-xl border border-dashed border-muted-foreground/25 bg-muted/25",style:{left:d.x,top:d.y,width:d.width,height:d.height}},d.parentId)),n.jsxs("svg",{"aria-hidden":"true",width:b.width,height:b.height,className:"pointer-events-none absolute inset-0 overflow-visible",fill:"none",children:[b.edges.map(d=>n.jsx("path",{d:d.path,className:"stroke-muted-foreground/35",strokeWidth:1.25},d.parentId)),q&&n.jsx("path",{d:q,className:"stroke-foreground/55",strokeWidth:1.5})]}),n.jsx("ul",{"aria-label":"Sessions",className:"absolute inset-0",children:b.nodes.map(d=>n.jsx(Hs,{node:d,width:b.cardWidth,toggleLeft:K,here:d.member.sessionId===i,kind:a.get(d.member.sessionId),name:c(d.member),onOpen:f,onToggle:v=>{E.current=v,g(v)}},d.member.sessionId))})]})})}),!W&&n.jsxs("div",{className:"absolute bottom-2.5 right-2.5 flex items-center gap-0.5 rounded-lg border bg-popover p-0.5 shadow-sm",children:[n.jsx(te,{variant:"ghost",size:"icon-xs","aria-label":"Zoom out",title:"Zoom out",disabled:S<=Pe,onClick:()=>D(1/Se),children:n.jsx(pt,{"data-icon":"inline-start"})}),n.jsxs(te,{variant:"ghost",size:"xs","aria-label":"Actual size",title:"Actual size",className:"min-w-11 px-1 tabular-nums text-muted-foreground",onClick:()=>D(1/S),children:[Math.round(S*100),"%"]}),n.jsx(te,{variant:"ghost",size:"icon-xs","aria-label":"Zoom in",title:"Zoom in",disabled:S>=ot,onClick:()=>D(Se),children:n.jsx(os,{"data-icon":"inline-start"})}),n.jsx("span",{className:"mx-0.5 h-4 w-px bg-border","aria-hidden":"true"}),n.jsx(te,{variant:"ghost",size:"xs",title:"Fit the whole crew on screen",className:"px-1.5 text-muted-foreground",onClick:()=>F(_e(b,lt(b,w),w),()=>({left:0,top:0})),children:"Fit"})]})]})}const Ys={"needs-you":"border-warning/60 bg-[color-mix(in_oklch,var(--warning)_7%,var(--card))]",failed:"border-destructive/45",unreachable:"border-dashed"},qs={"needs-you":"text-warning",failed:"text-destructive"};function Ws(t){var s,r;const e=(s=t.pullRequests)==null?void 0:s.at(-1);return[t.model&&qe(t.model),(r=t.device)==null?void 0:r.name,e&&`#${e.number}`,t.lastActivityAt&&We(t.lastActivityAt)].filter(Boolean).join(" · ")}function Hs(t){const e=ue.c(75),{node:s,width:r,toggleLeft:i,here:a,kind:c,name:o,onOpen:f,onToggle:g}=t,{member:h}=s;let l;e[0]!==h?(l=he(h),e[0]=h,e[1]=l):l=e[1];const w=l;let u;e[2]!==h?(u=Ie(h),e[2]=h,e[3]=u):u=e[3];const x=u;let p;e[4]!==c?(p=c?Ft(c):as,e[4]=c,e[5]=p):p=e[5];const m=p;let y;e[6]!==h?(y=Ws(h),e[6]=h,e[7]=y):y=e[7];const k=y,b=s.context&&"shown because a session it started is active";let M;e[8]!==x||e[9]!==o||e[10]!==b?(M=[o,x,b].filter(Boolean),e[8]=x,e[9]=o,e[10]=b,e[11]=M):M=e[11];const N=M.join(", ");let $;e[12]!==s.x||e[13]!==s.y||e[14]!==r?($={left:s.x,top:s.y,width:r,height:ne},e[12]=s.x,e[13]=s.y,e[14]=r,e[15]=$):$=e[15];const _=h.sessionId,O=a?"true":void 0;let E;e[16]!==h||e[17]!==f?(E=()=>f(h),e[16]=h,e[17]=f,e[18]=E):E=e[18];const j=Ys[w],L=a&&"outline-solid outline-[1.5px] outline-offset-2 outline-foreground/70",I=s.context&&"opacity-60 hover:opacity-100 focus-visible:opacity-100";let A;e[19]!==j||e[20]!==L||e[21]!==I?(A=oe("flex size-full cursor-pointer flex-col justify-center gap-1 rounded-lg border bg-card px-2.5 py-2 text-left shadow-xs outline-none","transition-[border-color,opacity,box-shadow] hover:border-foreground/25 hover:shadow-sm focus-visible:ring-2 focus-visible:ring-ring",j,L,I),e[19]=j,e[20]=L,e[21]=I,e[22]=A):A=e[22];let S;e[23]!==N||e[24]!==h.sessionId||e[25]!==w||e[26]!==E||e[27]!==A||e[28]!==O?(S=n.jsx("button",{type:"button","data-crew-map-card":_,"data-crew-map-state":w,"aria-current":O,"aria-label":N,onClick:E,className:A}),e[23]=N,e[24]=h.sessionId,e[25]=w,e[26]=E,e[27]=A,e[28]=O,e[29]=S):S=e[29];let R;e[30]!==m?(R=n.jsx(m,{"aria-hidden":"true",className:"mt-[3px] size-3.5 shrink-0 text-muted-foreground"}),e[30]=m,e[31]=R):R=e[31];let F;e[32]!==o?(F=n.jsx("span",{className:"line-clamp-2 min-w-0 flex-1 text-[13px]/[18px] font-medium",children:o}),e[32]=o,e[33]=F):F=e[33];let P;e[34]!==R||e[35]!==F?(P=n.jsxs("span",{className:"flex min-w-0 items-start gap-1.5",children:[R,F]}),e[34]=R,e[35]=F,e[36]=P):P=e[36];const H=fe[w];let D;e[37]!==H?(D=oe("size-1.5 shrink-0 rounded-full",H),e[37]=H,e[38]=D):D=e[38];let Y;e[39]!==D?(Y=n.jsx("span",{className:D,"aria-hidden":"true"}),e[39]=D,e[40]=Y):Y=e[40];let G;e[41]!==h||e[42]!==w?(G=Re(h)?"text-warning":qs[w],e[41]=h,e[42]=w,e[43]=G):G=e[43];let U;e[44]!==G?(U=oe("min-w-0 truncate text-muted-foreground",G),e[44]=G,e[45]=U):U=e[45];let z;e[46]!==x||e[47]!==U?(z=n.jsx("span",{className:U,children:x}),e[46]=x,e[47]=U,e[48]=z):z=e[48];let q;e[49]!==Y||e[50]!==z?(q=n.jsxs("span",{className:"flex min-w-0 items-center gap-1.5 text-xs",children:[Y,z]}),e[49]=Y,e[50]=z,e[51]=q):q=e[51];let W;e[52]!==a||e[53]!==k?(W=(k||a)&&n.jsxs("span",{className:"flex min-w-0 items-center gap-1.5 text-[11.5px] tabular-nums text-muted-foreground/75",children:[n.jsx("span",{className:"min-w-0 flex-1 truncate",children:k}),a&&n.jsx("span",{className:"shrink-0 font-medium text-foreground/70",children:"You are here"})]}),e[52]=a,e[53]=k,e[54]=W):W=e[54];let K;e[55]!==S||e[56]!==P||e[57]!==q||e[58]!==W?(K=n.jsxs(Pt,{delay:700,render:S,children:[P,q,W]}),e[55]=S,e[56]=P,e[57]=q,e[58]=W,e[59]=K):K=e[59];let d;e[60]!==h||e[61]!==o?(d=n.jsx(Yt,{side:"left",align:"start",className:"max-w-72",children:n.jsx(Bs,{member:h,name:o})}),e[60]=h,e[61]=o,e[62]=d):d=e[62];let v;e[63]!==K||e[64]!==d?(v=n.jsxs(qt,{children:[K,d]}),e[63]=K,e[64]=d,e[65]=v):v=e[65];let T;e[66]!==o||e[67]!==s||e[68]!==g||e[69]!==i?(T=s.childCount>0&&n.jsx(Us,{node:s,name:o,left:i,onToggle:g}),e[66]=o,e[67]=s,e[68]=g,e[69]=i,e[70]=T):T=e[70];let X;return e[71]!==v||e[72]!==T||e[73]!==$?(X=n.jsxs("li",{className:"group/node absolute",style:$,children:[v,T]}),e[71]=v,e[72]=T,e[73]=$,e[74]=X):X=e[74],X}function Us(t){const e=ue.c(25),{node:s,name:r,left:i,onToggle:a}=t,{collapsed:c,hidden:o}=s;let f=null;o.needsYou>0?f="needs-you":o.working>0&&(f="working");let g;e[0]!==c||e[1]!==o.count||e[2]!==o.needsYou||e[3]!==o.working||e[4]!==r?(g=c?[`Show the ${vt(o.count)} under ${r}`,o.needsYou>0&&`${o.needsYou} waiting on you`,o.working>0&&`${o.working} working`].filter(Boolean).join(", "):`Fold the sessions under ${r}`,e[0]=c,e[1]=o.count,e[2]=o.needsYou,e[3]=o.working,e[4]=r,e[5]=g):g=e[5];const h=g,l=!c,w=c?void 0:"Fold";let u;e[6]!==s.member.sessionId||e[7]!==a?(u=()=>a(s.member.sessionId),e[6]=s.member.sessionId,e[7]=a,e[8]=u):u=e[8];const x=!c&&"opacity-0 group-hover/node:opacity-100 focus-visible:opacity-100 [@media(hover:none)]:opacity-100";let p;e[9]!==x?(p=oe("absolute z-10 flex h-5 min-w-5 -translate-x-1/2 -translate-y-1/2 cursor-pointer items-center justify-center gap-1 rounded-full border bg-card px-1.5 text-[11px] font-medium tabular-nums text-muted-foreground shadow-xs outline-none","transition-opacity hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring",x),e[9]=x,e[10]=p):p=e[10];let m;e[11]!==i?(m={left:i,top:ne/2},e[11]=i,e[12]=m):m=e[12];let y;e[13]!==f||e[14]!==c||e[15]!==o.count?(y=c?n.jsxs(n.Fragment,{children:[f&&n.jsx("span",{className:oe("size-1.5 rounded-full",fe[f]),"aria-hidden":"true"}),"+",o.count]}):n.jsx(pt,{"aria-hidden":"true",className:"size-3"}),e[13]=f,e[14]=c,e[15]=o.count,e[16]=y):y=e[16];let k;return e[17]!==h||e[18]!==l||e[19]!==w||e[20]!==u||e[21]!==p||e[22]!==m||e[23]!==y?(k=n.jsx("button",{type:"button","aria-expanded":l,"aria-label":h,title:w,onClick:u,className:p,style:m,children:y}),e[17]=h,e[18]=l,e[19]=w,e[20]=u,e[21]=p,e[22]=m,e[23]=y,e[24]=k):k=e[24],k}function Bs(t){var u,x;const e=ue.c(35),{member:s,name:r}=t;let i;e[0]!==s.firstUserMessage?(i=(u=s.firstUserMessage)==null?void 0:u.replace(/\s+/g," ").trim(),e[0]=s.firstUserMessage,e[1]=i):i=e[1];const a=i;let c;e[2]!==s.cwd?(c=(x=s.cwd)==null?void 0:x.split(/[\\/]/).filter(Boolean).at(-1),e[2]=s.cwd,e[3]=c):c=e[3];const o=c;let f;if(e[4]!==o||e[5]!==s.device||e[6]!==s.model||e[7]!==s.startedAt||e[8]!==s.turnCount){if(f=[],s.model){let p;e[10]!==s.model?(p=qe(s.model),e[10]=s.model,e[11]=p):p=e[11];let m;e[12]!==p?(m=["Model",p],e[12]=p,e[13]=m):m=e[13],f.push(m)}if(s.device){let p;e[14]!==s.device.name?(p=["Device",s.device.name],e[14]=s.device.name,e[15]=p):p=e[15],f.push(p)}if(o){let p;e[16]!==o?(p=["Folder",o],e[16]=o,e[17]=p):p=e[17],f.push(p)}if(s.startedAt){let p;e[18]!==s.startedAt?(p=mt(s.startedAt),e[18]=s.startedAt,e[19]=p):p=e[19];let m;e[20]!==p?(m=["Started",p],e[20]=p,e[21]=m):m=e[21],f.push(m)}if(s.turnCount){const p=String(s.turnCount);let m;e[22]!==p?(m=["Turns",p],e[22]=p,e[23]=m):m=e[23],f.push(m)}e[4]=o,e[5]=s.device,e[6]=s.model,e[7]=s.startedAt,e[8]=s.turnCount,e[9]=f}else f=e[9];let g;e[24]!==r?(g=n.jsx("p",{className:"font-medium",children:r}),e[24]=r,e[25]=g):g=e[25];let h;e[26]!==r||e[27]!==a?(h=a&&a!==r&&n.jsx("p",{className:"line-clamp-3 text-muted-foreground",children:a}),e[26]=r,e[27]=a,e[28]=h):h=e[28];let l;e[29]!==f?(l=f.length>0&&n.jsx("dl",{className:"grid grid-cols-[auto_minmax(0,1fr)] gap-x-3 gap-y-0.5",children:f.map(Gs)}),e[29]=f,e[30]=l):l=e[30];let w;return e[31]!==g||e[32]!==h||e[33]!==l?(w=n.jsxs("div",{className:"flex flex-col gap-1.5 py-0.5",children:[g,h,l]}),e[31]=g,e[32]=h,e[33]=l,e[34]=w):w=e[34],w}function Gs(t){const[e,s]=t;return n.jsxs("div",{className:"contents",children:[n.jsx("dt",{className:"text-muted-foreground",children:e}),n.jsx("dd",{className:"truncate tabular-nums",children:s})]},e)}const Vs=4e3;function Ks(t){var p;const[e,s]=C.useState(null),[r,i]=C.useState(null),[a,c]=C.useState(new Set),o=(p=Wt())==null?void 0:p.refresh,f=C.useRef(t),g=C.useRef(new Set);C.useLayoutEffect(()=>(f.current=t,()=>{f.current=null}),[t]);const h=C.useCallback(async m=>{if(t)try{const y=await ze(`/api/session-crew/${encodeURIComponent(t)}`);if(!m())return;if(!y.ok){i(y.status===404?"This session is no longer available.":"Couldn't load the crew.");return}const k=await y.json();if(!m())return;s(b=>JSON.stringify(b)===JSON.stringify(k)?b:k),i(null)}catch{m()&&i("Couldn't load the crew.")}},[t]);it(t?h:null,Vs),C.useEffect(()=>{s(m=>m!=null&&m.members.some(y=>y.sessionId===t)?m:null),i(null),c(new Set)},[t]);const l=C.useCallback(async(m,y,k)=>{const b=`${t}:${m}`;if(g.current.has(b))return;const M=()=>f.current===t;g.current.add(b),c(N=>new Set(N).add(m));try{const N=await y();if(!M())return;if(!N.ok&&N.status!==404){i(k);return}o==null||o(),await h(M)}catch{M()&&i(k)}finally{g.current.delete(b),M()&&c(N=>{const $=new Set(N);return $.delete(m),$})}},[h,o,t]),w=C.useCallback((m,y,k)=>l(y,()=>je("/api/session-respond",{sessionId:m,requestId:y,...k}),"Couldn't send the answer."),[l]),u=C.useCallback((m,y)=>l(y,()=>je("/api/delegated-tasks",{sessionId:m,taskId:y,action:"ack"}),"Couldn't mark the result read."),[l]),x=C.useCallback(m=>l(m.sessionId,()=>{var y;return((y=m.result)==null?void 0:y.state)==="running"&&m.parentId?je("/api/delegated-tasks",{sessionId:m.parentId,taskId:m.result.taskId,action:"cancel"}):je("/api/stop-session",{sessionId:m.sessionId,cancelQueued:!0})},"Couldn't stop the session."),[l]);return{crew:e,error:r,busy:a,respond:w,markRead:u,stop:x}}const Xs=[{id:"all",label:"All"},{id:"working",label:"Working"},{id:"needs-you",label:"Need you"},{id:"done",label:"Done"}],Zs={working:"bg-success shadow-[0_0_0_2px_color-mix(in_oklch,var(--success)_25%,transparent)]","needs-you":"bg-warning",done:"bg-muted-foreground/40",failed:"bg-destructive",unreachable:"border border-muted-foreground/50"};function un(t){var U;const e=ue.c(40),{context:s,closePanel:r}=t,i=((U=s.session)==null?void 0:U.sessionId)??null,{crew:a,error:c,busy:o,respond:f,markRead:g,stop:h}=Ks(i),{names:l}=Ht(),[w,u]=C.useState("overview");let x;e[0]===Symbol.for("react.memo_cache_sentinel")?(x=new Set,e[0]=x):x=e[0];const[p,m]=C.useState(x),y=Ls((a==null?void 0:a.rootId)??"");let k;e[1]!==(a==null?void 0:a.members)?(k=new Map(((a==null?void 0:a.members)??[]).map(Qs)),e[1]=a==null?void 0:a.members,e[2]=k):k=e[2];const b=k;let M;e[3]!==(a==null?void 0:a.members)?(M=new Map(((a==null?void 0:a.members)??[]).flatMap(Js)),e[3]=a==null?void 0:a.members,e[4]=M):M=e[4];const N=M;let $;e[5]!==b||e[6]!==l?($=z=>gs(z,b,l),e[5]=b,e[6]=l,e[7]=$):$=e[7];const _=$;let O;e[8]!==s?(O=z=>{z.address&&z.device?Xt(Zt(z.address.dirName,z.address.fileName,z.device.id)):z.address&&s.openSession?s.openSession(z.address.dirName,z.address.fileName):Jt(z.sessionId)},e[8]=s,e[9]=O):O=e[9];const E=O;let j;e[10]===Symbol.for("react.memo_cache_sentinel")?(j=z=>m(q=>{const W=new Set(q);return W.delete(z)||W.add(z),W}),e[10]=j):j=e[10];const L=j;let I;e[11]!==b?(I=z=>{m(q=>{var v;const W=new Set(q),K=new Set;let d=z.parentId;for(;d&&!K.has(d);)K.add(d),W.delete(d),d=((v=b.get(d))==null?void 0:v.parentId)??null;return W}),requestAnimationFrame(()=>{var q;return(q=document.querySelector(`[data-crew-row="${z.sessionId}"]`))==null?void 0:q.scrollIntoView({block:"nearest",behavior:"smooth"})})},e[11]=b,e[12]=I):I=e[12];const A=I;let S,R,F;e[13]===Symbol.for("react.memo_cache_sentinel")?(R=n.jsx(ht,{"aria-hidden":"true",className:"size-4 text-muted-foreground"}),F=n.jsx("h2",{className:"text-sm font-medium",children:"Crew"}),S=n.jsx("div",{className:"flex-1"}),e[13]=S,e[14]=R,e[15]=F):(S=e[13],R=e[14],F=e[15]);let P;e[16]===Symbol.for("react.memo_cache_sentinel")?(P=n.jsx(cs,{"data-icon":"inline-start"}),e[16]=P):P=e[16];let H;e[17]!==r?(H=n.jsxs("div",{className:"flex h-10 shrink-0 items-center gap-2 px-3",children:[R,F,S,n.jsx(te,{variant:"ghost",size:"icon-sm",onClick:r,"aria-label":"Close crew",children:P})]}),e[17]=r,e[18]=H):H=e[18];let D;e[19]!==c?(D=c&&n.jsx("p",{role:"alert",className:"px-3 pb-2 text-xs text-destructive",children:c}),e[19]=c,e[20]=D):D=e[20];let Y;e[21]!==o||e[22]!==p||e[23]!==a||e[24]!==c||e[25]!==N||e[26]!==y||e[27]!==g||e[28]!==_||e[29]!==E||e[30]!==f||e[31]!==A||e[32]!==i||e[33]!==h||e[34]!==w?(Y=a?n.jsxs(Ut,{value:w,onValueChange:u,className:"min-h-0 flex-1 grid-rows-[auto_minmax(0,1fr)]",children:[n.jsxs(Bt,{variant:"line",className:"mx-3 mb-1",children:[n.jsx(Ae,{value:"overview",children:"Overview"}),n.jsx(Ae,{value:"map",children:"Map"}),n.jsx(Ae,{value:"chat",children:"Chat"})]}),n.jsx(Oe,{value:"overview",className:"min-h-0",children:n.jsxs(ft,{className:"h-full min-h-0",children:[n.jsx(en,{crew:a,hereId:i,nameOf:_,onOpen:E,onReveal:A}),n.jsx(sn,{crew:a,busy:o,nameOf:_,onOpen:E,onRespond:f}),n.jsx(nn,{crew:a,hereId:i,busy:o,nameOf:_,onOpen:E,onMarkRead:g,onStop:h,collapsed:p,onToggle:L})]})}),n.jsx(Oe,{value:"map",className:"min-h-0",children:n.jsx(_s,{crew:a,hereId:i,controls:y,kinds:N,nameOf:_,onOpen:E})}),n.jsx(Oe,{value:"chat",keepMounted:!0,className:"min-h-0",children:n.jsx(hs,{rootId:a.rootId,kinds:N,active:w==="chat"},a.rootId)})]}):!c&&n.jsx("p",{className:"px-3 py-6 text-center text-sm text-muted-foreground",children:"Loading the crew…"}),e[21]=o,e[22]=p,e[23]=a,e[24]=c,e[25]=N,e[26]=y,e[27]=g,e[28]=_,e[29]=E,e[30]=f,e[31]=A,e[32]=i,e[33]=h,e[34]=w,e[35]=Y):Y=e[35];let G;return e[36]!==H||e[37]!==D||e[38]!==Y?(G=n.jsxs("aside",{"aria-label":"Crew",className:"flex size-full min-h-0 flex-col bg-canvas",children:[H,D,Y]}),e[36]=H,e[37]=D,e[38]=Y,e[39]=G):G=e[39],G}function Js(t){return t.address?[[t.sessionId,Gt(t.address.dirName)]]:[]}function Qs(t){return[t.sessionId,t]}function en(t){var M;const e=ue.c(46),{crew:s,hereId:r,nameOf:i,onOpen:a,onReveal:c}=t;let o,f,g,h,l;if(e[0]!==s||e[1]!==r||e[2]!==i||e[3]!==a||e[4]!==c){let N;e[10]!==s.rootId?(N=S=>S.sessionId===s.rootId,e[10]=s.rootId,e[11]=N):N=e[11];const $=s.members.find(N),_=s.members.filter(tn);let O;e[12]!==s?(O=bs(s),e[12]=s,e[13]=O):O=e[13],l=O;const E=(M=_[0])==null?void 0:M.startedAt;o="Crew summary",f="border-b px-3 pb-3 pt-1";const j=$&&n.jsx("button",{type:"button",onClick:()=>a($),"aria-current":$.sessionId===r?"true":void 0,className:"min-w-0 flex-1 truncate rounded-sm text-left text-sm font-medium outline-none hover:underline focus-visible:ring-2 focus-visible:ring-ring",children:i($)}),L=l.size===1?"session":"sessions",I=E?` · since ${mt(E)}`:"";let A;e[14]!==L||e[15]!==I||e[16]!==l.size?(A=n.jsxs("span",{className:"shrink-0 text-xs tabular-nums text-muted-foreground",children:[l.size," ",L,I]}),e[14]=L,e[15]=I,e[16]=l.size,e[17]=A):A=e[17],e[18]!==A||e[19]!==j?(g=n.jsxs("div",{className:"flex items-baseline gap-2",children:[j,A]}),e[18]=A,e[19]=j,e[20]=g):g=e[20],h=_.length>0&&n.jsx("div",{"data-crew-strip":!0,className:"mt-2.5 grid grid-cols-[repeat(auto-fit,minmax(6px,1fr))] gap-[3px]",role:"list","aria-label":"One cell per session, in the order they were started",children:_.map(S=>{const R=he(S);return n.jsx("button",{type:"button",role:"listitem","data-crew-cell":R,title:`${i(S)}: ${Ie(S)}`,"aria-label":`${i(S)}: ${Ie(S)}`,onClick:()=>c(S),className:oe("h-2.5 rounded-[2px] outline-none focus-visible:ring-2 focus-visible:ring-ring",Zs[R],S.sessionId===r&&"outline outline-[1.5px] outline-offset-2 outline-foreground")},S.sessionId)})}),e[0]=s,e[1]=r,e[2]=i,e[3]=a,e[4]=c,e[5]=o,e[6]=f,e[7]=g,e[8]=h,e[9]=l}else o=e[5],f=e[6],g=e[7],h=e[8],l=e[9];let w;e[21]!==l.working?(w=l.working>0&&n.jsx(Ne,{dot:fe.working,value:l.working,label:"working"}),e[21]=l.working,e[22]=w):w=e[22];let u;e[23]!==l.needsYou?(u=l.needsYou>0&&n.jsx(Ne,{dot:fe["needs-you"],value:l.needsYou,label:l.needsYou===1?"needs you":"need you"}),e[23]=l.needsYou,e[24]=u):u=e[24];let x;e[25]!==l.done?(x=l.done>0&&n.jsx(Ne,{dot:fe.done,value:l.done,label:"done"}),e[25]=l.done,e[26]=x):x=e[26];let p;e[27]!==l.failed?(p=l.failed>0&&n.jsx(Ne,{dot:fe.failed,value:l.failed,label:"failed"}),e[27]=l.failed,e[28]=p):p=e[28];let m;e[29]!==l.unreachable?(m=l.unreachable>0&&n.jsx(Ne,{dot:fe.unreachable,value:l.unreachable,label:"away"}),e[29]=l.unreachable,e[30]=m):m=e[30];let y;e[31]!==l.unreadResults?(y=l.unreadResults>0&&n.jsxs("span",{className:"ml-auto text-warning",children:[n.jsx("span",{className:"font-medium tabular-nums",children:l.unreadResults})," ",l.unreadResults===1?"result":"results"," unread"]}),e[31]=l.unreadResults,e[32]=y):y=e[32];let k;e[33]!==y||e[34]!==w||e[35]!==u||e[36]!==x||e[37]!==p||e[38]!==m?(k=n.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-x-3.5 gap-y-1 text-xs text-muted-foreground",children:[w,u,x,p,m,y]}),e[33]=y,e[34]=w,e[35]=u,e[36]=x,e[37]=p,e[38]=m,e[39]=k):k=e[39];let b;return e[40]!==o||e[41]!==k||e[42]!==f||e[43]!==g||e[44]!==h?(b=n.jsxs("section",{"aria-label":o,className:f,children:[g,h,k]}),e[40]=o,e[41]=k,e[42]=f,e[43]=g,e[44]=h,e[45]=b):b=e[45],b}function tn(t){return t.parentId!==null}function Ne(t){const e=ue.c(10),{dot:s,value:r,label:i}=t;let a;e[0]!==s?(a=oe("size-1.5 rounded-full",s),e[0]=s,e[1]=a):a=e[1];let c;e[2]!==a?(c=n.jsx("span",{className:a,"aria-hidden":"true"}),e[2]=a,e[3]=c):c=e[3];let o;e[4]!==r?(o=n.jsx("span",{className:"font-medium tabular-nums text-foreground",children:r}),e[4]=r,e[5]=o):o=e[5];let f;return e[6]!==i||e[7]!==c||e[8]!==o?(f=n.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[c,o," ",i]}),e[6]=i,e[7]=c,e[8]=o,e[9]=f):f=e[9],f}function sn(t){const e=ue.c(6),{crew:s,busy:r,nameOf:i,onOpen:a,onRespond:c}=t,o=ws(s),[f,g]=C.useState(0);if(o.length===0)return null;const h=Math.min(f,o.length-1),{member:l,pending:w}=o[h],u=o[h+1];let x;e[0]===Symbol.for("react.memo_cache_sentinel")?(x=n.jsx("h3",{className:"text-sm font-medium text-foreground",children:"Needs you"}),e[0]=x):x=e[0];let p;e[1]===Symbol.for("react.memo_cache_sentinel")?(p=n.jsx("span",{className:"flex-1"}),e[1]=p):p=e[1];let m;e[2]===Symbol.for("react.memo_cache_sentinel")?(m=n.jsx("span",{className:oe("size-1.5 shrink-0 rounded-full",fe["needs-you"]),"aria-hidden":"true"}),e[2]=m):m=e[2];const y=w.askedAt?`waiting ${We(new Date(w.askedAt).toISOString())}`:"waiting";let k;e[3]!==y?(k=n.jsx("span",{className:"ml-auto shrink-0 tabular-nums text-warning",children:y}),e[3]=y,e[4]=k):k=e[4];let b;return e[5]===Symbol.for("react.memo_cache_sentinel")?(b=n.jsx(De,{"data-icon":"inline-end"}),e[5]=b):b=e[5],n.jsxs("section",{"aria-label":"Needs you",className:"border-b px-3 py-2.5",children:[n.jsxs("div",{className:"mb-2 flex items-center gap-2 text-xs text-muted-foreground",children:[x,n.jsx("span",{className:"tabular-nums",children:o.length}),p,o.length>1&&n.jsxs(n.Fragment,{children:[n.jsxs("span",{className:"tabular-nums",children:[h+1," of ",o.length]}),n.jsx(te,{variant:"ghost",size:"icon-xs","aria-label":"Previous request",disabled:h===0,onClick:()=>g(h-1),children:n.jsx(ls,{"data-icon":"inline-start"})}),n.jsx(te,{variant:"ghost",size:"icon-xs","aria-label":"Next request",disabled:h===o.length-1,onClick:()=>g(h+1),children:n.jsx(De,{"data-icon":"inline-start"})})]})]}),n.jsxs("div",{className:"flex flex-col gap-1.5",children:[n.jsxs("div",{className:"flex items-center gap-2 px-0.5 text-xs",children:[m,n.jsx("span",{className:"min-w-0 truncate font-medium text-foreground",children:i(l)}),l.device&&n.jsx(Vt,{variant:"outline",children:l.device.name}),k]}),n.jsx(Kt,{sessionId:l.sessionId,pending:w,queued:0,responding:r.has(w.requestId),onRespond:(M,N)=>void c(l.sessionId,M,N),onOpen:()=>a(l)},w.requestId),n.jsxs(te,{variant:"ghost",size:"xs",className:"self-end text-muted-foreground",onClick:()=>a(l),children:["Open session",b]})]}),u&&n.jsxs("p",{className:"mt-2 truncate text-xs text-muted-foreground",children:["Next: ",n.jsx("span",{className:"font-medium text-foreground",children:i(u.member)})," ",Ie(u.member).toLowerCase()]})]})}function nn({crew:t,hereId:e,busy:s,nameOf:r,onOpen:i,onMarkRead:a,onStop:c,collapsed:o,onToggle:f}){const[g,h]=C.useState("all");let l=null;const w=xs(t).filter(({member:u,depth:x})=>{if(g!=="all"){const p=he(u);return g==="done"?p!=="working"&&p!=="needs-you":p===g}return l!==null&&x>l?!1:(l=o.has(u.sessionId)?x:null,!0)});return n.jsxs("section",{"aria-label":"Sessions",className:"px-1.5 py-2.5",children:[n.jsxs("div",{className:"mb-1.5 flex items-center gap-2 px-1.5",children:[n.jsx("h3",{className:"text-sm font-medium",children:"Sessions"}),n.jsx("span",{className:"flex-1"}),n.jsx("div",{role:"radiogroup","aria-label":"Show sessions",className:"flex gap-0.5",children:Xs.map(({id:u,label:x})=>n.jsx("button",{type:"button",role:"radio","aria-checked":g===u,onClick:()=>h(u),className:oe("rounded-full px-2 py-0.5 text-[11px] text-muted-foreground outline-none hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring",g===u&&"bg-accent text-foreground"),children:x},u))})]}),w.length===0?n.jsx("p",{className:"px-1.5 py-4 text-center text-xs text-muted-foreground",children:"No sessions here."}):n.jsx("ul",{className:"flex flex-col",children:w.map(u=>n.jsx(on,{row:u,here:u.member.sessionId===e,busy:s,name:r(u.member),onOpen:i,onMarkRead:a,onStop:c,collapsed:g==="all"?o.has(u.member.sessionId):void 0,onToggle:()=>f(u.member.sessionId)},u.member.sessionId))})]})}function on(t){var ce,pe;const e=ue.c(81),{row:s,here:r,busy:i,name:a,onOpen:c,onMarkRead:o,onStop:f,collapsed:g,onToggle:h}=t,{member:l,depth:w,children:u}=s;let x;e[0]!==l?(x=he(l),e[0]=l,e[1]=x):x=e[1];const p=x;let m;e[2]!==l?(m=Ie(l),e[2]=l,e[3]=m):m=e[3];const y=m;let k;e[4]!==l.pullRequests?(k=(ce=l.pullRequests)==null?void 0:ce.at(-1),e[4]=l.pullRequests,e[5]=k):k=e[5];const b=k;let M;e[6]!==l?(M=Re(l)&&l.result&&l.parentId,e[6]=l,e[7]=M):M=e[7];const N=M,$=(p==="working"||p==="needs-you")&&(!l.device||((pe=l.result)==null?void 0:pe.state)==="running"&&l.parentId!==null),_=l.sessionId,O=r?"bg-accent":"hover:bg-accent/60",E=w>0&&"border-l border-border/70";let j;e[8]!==O||e[9]!==E?(j=oe("group/crew relative flex items-start rounded-md",O,E),e[8]=O,e[9]=E,e[10]=j):j=e[10];const L=w>0?6+(w-1)*14:0;let I;e[11]!==L?(I={marginLeft:L},e[11]=L,e[12]=I):I=e[12];let A;e[13]!==u||e[14]!==g||e[15]!==a||e[16]!==h?(A=u>0&&g!==void 0&&n.jsx(te,{variant:"ghost",size:"icon-xs","aria-label":`${g?"Expand":"Collapse"} ${a}'s child sessions`,"aria-expanded":!g,onClick:h,children:n.jsx(De,{"data-icon":"inline-start",className:oe("transition-transform",!g&&"rotate-90")})}),e[13]=u,e[14]=g,e[15]=a,e[16]=h,e[17]=A):A=e[17];let S;e[18]!==A?(S=n.jsx("span",{className:"mt-1.5 flex w-6 shrink-0 justify-center",children:A}),e[18]=A,e[19]=S):S=e[19];let R;e[20]!==l||e[21]!==c?(R=()=>c(l),e[20]=l,e[21]=c,e[22]=R):R=e[22];const F=r?"true":void 0,P=`${a}, ${y}`,H=fe[p];let D;e[23]!==H?(D=oe("size-1.5 justify-self-center rounded-full",H),e[23]=H,e[24]=D):D=e[24];let Y;e[25]!==D?(Y=n.jsx("span",{className:D,"aria-hidden":"true"}),e[25]=D,e[26]=Y):Y=e[26];let G;e[27]!==a?(G=n.jsx("span",{className:"truncate",children:a}),e[27]=a,e[28]=G):G=e[28];let U;e[29]!==r?(U=r&&n.jsx("span",{className:"shrink-0 rounded-full border px-1.5 text-[10.5px] font-normal text-muted-foreground",children:"you are here"}),e[29]=r,e[30]=U):U=e[30];let z;e[31]!==G||e[32]!==U?(z=n.jsxs("span",{className:"flex min-w-0 items-center gap-1.5 text-[12.5px] font-medium",children:[G,U]}),e[31]=G,e[32]=U,e[33]=z):z=e[33];let q;e[34]!==l.lastActivityAt?(q=l.lastActivityAt?We(l.lastActivityAt):"",e[34]=l.lastActivityAt,e[35]=q):q=e[35];let W;e[36]!==q?(W=n.jsx("span",{className:"text-[11px] tabular-nums text-muted-foreground/80",children:q}),e[36]=q,e[37]=W):W=e[37];const K=(p==="needs-you"||N)&&"text-warning",d=p==="failed"&&"text-destructive";let v;e[38]!==K||e[39]!==d?(v=oe("min-w-0 flex-1 truncate",K,d),e[38]=K,e[39]=d,e[40]=v):v=e[40];let T;e[41]!==y||e[42]!==v?(T=n.jsx("span",{className:v,children:y}),e[41]=y,e[42]=v,e[43]=T):T=e[43];let X;e[44]!==b?(X=b&&n.jsxs("span",{className:"shrink-0 rounded-full border px-1.5 text-[11px]",children:["#",b.number]}),e[44]=b,e[45]=X):X=e[45];let ae;e[46]!==l.device?(ae=l.device&&n.jsx("span",{className:"shrink-0",children:l.device.name}),e[46]=l.device,e[47]=ae):ae=e[47];let J;e[48]!==u?(J=u>0&&n.jsxs("span",{className:"shrink-0",children:[u," ",u===1?"session":"sessions"]}),e[48]=u,e[49]=J):J=e[49];let Q;e[50]!==l.model?(Q=l.model&&n.jsx("span",{className:"shrink-0 text-muted-foreground/70",children:qe(l.model)}),e[50]=l.model,e[51]=Q):Q=e[51];let ee;e[52]!==T||e[53]!==X||e[54]!==ae||e[55]!==J||e[56]!==Q?(ee=n.jsxs("span",{className:"col-start-2 col-end-4 flex min-w-0 items-center gap-2 text-[11.5px] text-muted-foreground",children:[T,X,ae,J,Q]}),e[52]=T,e[53]=X,e[54]=ae,e[55]=J,e[56]=Q,e[57]=ee):ee=e[57];let se;e[58]!==R||e[59]!==F||e[60]!==P||e[61]!==Y||e[62]!==z||e[63]!==W||e[64]!==ee?(se=n.jsxs("button",{type:"button",onClick:R,"aria-current":F,"aria-label":P,className:"grid min-w-0 flex-1 grid-cols-[14px_minmax(0,1fr)_auto] items-center gap-x-2 gap-y-0.5 rounded-md px-2 py-1.5 text-left outline-none focus-visible:ring-2 focus-visible:ring-ring",children:[Y,z,W,ee]}),e[58]=R,e[59]=F,e[60]=P,e[61]=Y,e[62]=z,e[63]=W,e[64]=ee,e[65]=se):se=e[65];let re;e[66]!==i||e[67]!==$||e[68]!==l||e[69]!==a||e[70]!==o||e[71]!==f||e[72]!==N?(re=(N||$)&&n.jsxs("div",{className:"absolute right-1.5 top-1 hidden gap-1 group-focus-within/crew:flex group-hover/crew:flex",children:[N&&l.result&&l.parentId&&n.jsx(te,{variant:"outline",size:"icon-xs",className:"bg-popover","aria-label":`Mark ${a}'s result read`,title:"Mark the result read",disabled:i.has(l.result.taskId),onClick:()=>void o(l.parentId,l.result.taskId),children:n.jsx(is,{"data-icon":"inline-start"})}),$&&n.jsx(te,{variant:"outline",size:"icon-xs",className:"bg-popover text-destructive","aria-label":`Stop ${a}`,title:"Stop this session",disabled:i.has(l.sessionId),onClick:()=>void f(l),children:n.jsx(rs,{"data-icon":"inline-start"})})]}),e[66]=i,e[67]=$,e[68]=l,e[69]=a,e[70]=o,e[71]=f,e[72]=N,e[73]=re):re=e[73];let Z;return e[74]!==l.sessionId||e[75]!==I||e[76]!==S||e[77]!==se||e[78]!==re||e[79]!==j?(Z=n.jsxs("li",{"data-crew-row":_,className:j,style:I,children:[S,se,re]}),e[74]=l.sessionId,e[75]=I,e[76]=S,e[77]=se,e[78]=re,e[79]=j,e[80]=Z):Z=e[80],Z}export{un as CrewPanel};
@@ -1,2 +1,2 @@
1
- import{c as T,r as L,j as c}from"./vendor-react-gGw_S5I_.js";import{cL as _,cM as C,cN as D,c as H}from"./index-BvNyEUVG.js";function K(r){const e=T.c(26),{value:t,onChange:j,readOnly:i,filePath:k,ariaLabel:R,textareaRef:f,onKeyDown:v,onSelect:w}=r,N=_(),u=L.useRef(null),p=L.useRef(null);let d;e[0]!==k?(d=C(k),e[0]=k,e[1]=d):d=e[1];const h=D(t,d,N,80);let m;e[2]===Symbol.for("react.memo_cache_sentinel")?(m=()=>{u.current&&p.current&&(p.current.scrollTop=u.current.scrollTop,p.current.scrollLeft=u.current.scrollLeft)},e[2]=m):m=e[2];const S=m;let x;e[3]!==f?(x=b=>{u.current=b,f&&(f.current=b)},e[3]=f,e[4]=x):x=e[4];const y=x;let l;e[5]!==h||e[6]!==t?(l=h?h.map(M):c.jsx("code",{className:"text-foreground",children:t}),e[5]=h,e[6]=t,e[7]=l):l=e[7];let n;e[8]!==l?(n=c.jsx("pre",{ref:p,"aria-hidden":!0,className:"absolute inset-0 overflow-hidden font-mono text-[13px] leading-relaxed p-4 m-0 pointer-events-none whitespace-pre-wrap break-words",children:l}),e[8]=l,e[9]=n):n=e[9];let s;e[10]!==j?(s=b=>j(b.target.value),e[10]=j,e[11]=s):s=e[11];const E=i&&"cursor-default";let a;e[12]!==E?(a=H("absolute inset-0 w-full h-full resize-none bg-transparent font-mono text-[13px] leading-relaxed p-4 outline-none","text-transparent caret-foreground selection:bg-selection","scrollbar-thin scrollbar-track-transparent scrollbar-thumb-border",E),e[12]=E,e[13]=a):a=e[13];let o;e[14]!==R||e[15]!==y||e[16]!==v||e[17]!==w||e[18]!==i||e[19]!==s||e[20]!==a||e[21]!==t?(o=c.jsx("textarea",{ref:y,"aria-label":R,value:t,onChange:s,onScroll:S,onKeyDown:v,onSelect:w,readOnly:i,spellCheck:!1,className:a,placeholder:"Empty file"}),e[14]=R,e[15]=y,e[16]=v,e[17]=w,e[18]=i,e[19]=s,e[20]=a,e[21]=t,e[22]=o):o=e[22];let g;return e[23]!==n||e[24]!==o?(g=c.jsxs("div",{className:"relative min-h-0 flex-1 bg-background",children:[n,o]}),e[23]=n,e[24]=o,e[25]=g):g=e[25],g}function M(r,e){return c.jsxs("span",{children:[r.map(P),`
2
- `]},e)}function P(r,e){return c.jsx("span",{style:{color:r.color},children:r.content},e)}export{K as H};
1
+ import{c as T,r as L,j as c}from"./vendor-react-gGw_S5I_.js";import{c$ as _,d0 as C,d1 as D,c as H}from"./index-BVmNox_3.js";function K(r){const e=T.c(26),{value:t,onChange:j,readOnly:i,filePath:k,ariaLabel:R,textareaRef:f,onKeyDown:v,onSelect:w}=r,N=_(),u=L.useRef(null),p=L.useRef(null);let d;e[0]!==k?(d=C(k),e[0]=k,e[1]=d):d=e[1];const h=D(t,d,N,80);let m;e[2]===Symbol.for("react.memo_cache_sentinel")?(m=()=>{u.current&&p.current&&(p.current.scrollTop=u.current.scrollTop,p.current.scrollLeft=u.current.scrollLeft)},e[2]=m):m=e[2];const S=m;let x;e[3]!==f?(x=b=>{u.current=b,f&&(f.current=b)},e[3]=f,e[4]=x):x=e[4];const y=x;let l;e[5]!==h||e[6]!==t?(l=h?h.map(P):c.jsx("code",{className:"text-foreground",children:t}),e[5]=h,e[6]=t,e[7]=l):l=e[7];let n;e[8]!==l?(n=c.jsx("pre",{ref:p,"aria-hidden":!0,className:"absolute inset-0 overflow-hidden font-mono text-[13px] leading-relaxed p-4 m-0 pointer-events-none whitespace-pre-wrap break-words",children:l}),e[8]=l,e[9]=n):n=e[9];let s;e[10]!==j?(s=b=>j(b.target.value),e[10]=j,e[11]=s):s=e[11];const E=i&&"cursor-default";let a;e[12]!==E?(a=H("absolute inset-0 w-full h-full resize-none bg-transparent font-mono text-[13px] leading-relaxed p-4 outline-none","text-transparent caret-foreground selection:bg-selection","scrollbar-thin scrollbar-track-transparent scrollbar-thumb-border",E),e[12]=E,e[13]=a):a=e[13];let o;e[14]!==R||e[15]!==y||e[16]!==v||e[17]!==w||e[18]!==i||e[19]!==s||e[20]!==a||e[21]!==t?(o=c.jsx("textarea",{ref:y,"aria-label":R,value:t,onChange:s,onScroll:S,onKeyDown:v,onSelect:w,readOnly:i,spellCheck:!1,className:a,placeholder:"Empty file"}),e[14]=R,e[15]=y,e[16]=v,e[17]=w,e[18]=i,e[19]=s,e[20]=a,e[21]=t,e[22]=o):o=e[22];let g;return e[23]!==n||e[24]!==o?(g=c.jsxs("div",{className:"relative min-h-0 flex-1 bg-background",children:[n,o]}),e[23]=n,e[24]=o,e[25]=g):g=e[25],g}function P(r,e){return c.jsxs("span",{children:[r.map($),`
2
+ `]},e)}function $(r,e){return c.jsx("span",{style:{color:r.color},children:r.content},e)}export{K as H};
@@ -1 +1 @@
1
- import{c as O,j as t,r as E}from"./vendor-react-gGw_S5I_.js";import{o as H,bB as $,bC as T,bD as Q,B as P,bE as Y,bF as _,n as q,l as J,D as M,j as U,S as V,ax as W,az as X,aw as Z,bG as ee,G as te,I as se,m as ae,bH as le,bI as ne,bJ as re}from"./index-BvNyEUVG.js";import{bK as F,df as oe,ak as ce}from"./vendor-ui-keo4oB2X.js";import"./vendor-markdown-BEJ8yVzA.js";const ie=new Set(["Alt","Control","Meta","Shift"]);function pe(e){const s=O.c(6),{open:f,onOpenChange:l}=e,x=f?"open":"closed";let a;s[0]!==x?(a=t.jsx(de,{},x),s[0]=x,s[1]=a):a=s[1];let r;return s[2]!==l||s[3]!==f||s[4]!==a?(r=t.jsx(H,{open:f,onOpenChange:l,children:a}),s[2]=l,s[3]=f,s[4]=a,s[5]=r):r=s[5],r}function de(){const e=O.c(45),[s,f]=E.useState(""),[l,x]=E.useState(null),[a,r]=E.useState(null),[A,B]=E.useState($);let I,k;e[0]!==l?(I=()=>{if(!l)return;const v=l,G=function(n){if(n.key==="Escape"){n.preventDefault(),n.stopPropagation(),x(null),r(null);return}if(ie.has(n.key))return;n.preventDefault(),n.stopPropagation();const c=le(n),p=ne(c,v);if(p){r(`Already assigned to “${p.label}”.`);return}re(v,c),B($()),x(null),r(null)};return window.addEventListener("keydown",G,!0),()=>window.removeEventListener("keydown",G,!0)},k=[l],e[0]=l,e[1]=I,e[2]=k):(I=e[1],k=e[2]),E.useEffect(I,k);let b,g,d,j,y,N,S,w,m,u,h;if(e[3]!==A||e[4]!==a||e[5]!==s||e[6]!==l){const v=s.trim().toLowerCase(),G=v?T.filter(i=>`${i.label} ${i.description} ${i.group}`.toLowerCase().includes(v)):T;g=q,S="max-w-2xl gap-0 overflow-hidden p-0",w=!1,e[18]===Symbol.for("react.memo_cache_sentinel")?(m=t.jsxs(J,{className:"p-4 pb-3",children:[t.jsxs(M,{className:"flex items-center gap-2",children:[t.jsx(oe,{"data-icon":"inline-start","aria-hidden":"true",className:"size-4"}),"Keyboard shortcuts"]}),t.jsx(U,{children:"Click a shortcut, then press a new key combination. Changes are saved on this device."})]}),u=t.jsx(V,{}),e[18]=m,e[19]=u):(m=e[18],u=e[19]);let K;e[20]===Symbol.for("react.memo_cache_sentinel")?(K=t.jsx(W,{children:t.jsx(ce,{"data-icon":"inline-start","aria-hidden":"true"})}),e[20]=K):K=e[20];let n;e[21]===Symbol.for("react.memo_cache_sentinel")?(n=i=>f(i.target.value),e[21]=n):n=e[21];let c;e[22]!==s?(c=t.jsxs(X,{className:"flex-1",children:[K,t.jsx(Z,{"aria-label":"Search keyboard shortcuts",value:s,onChange:n,placeholder:"Search shortcuts…"})]}),e[22]=s,e[23]=c):c=e[23];let p;e[24]===Symbol.for("react.memo_cache_sentinel")?(p=t.jsxs(P,{variant:"outline",size:"sm",onClick:()=>{ee(),B($()),r(null)},children:[t.jsx(F,{"data-icon":"inline-start"}),"Reset all"]}),e[24]=p):p=e[24],e[25]!==c?(h=t.jsxs("div",{className:"flex items-center gap-2 p-3",children:[c,p]}),e[25]=c,e[26]=h):h=e[26],e[27]!==a?(d=a&&t.jsx(te,{variant:"destructive",className:"mx-3 mb-2 w-auto",children:t.jsxs(se,{children:[a," Press another shortcut or Esc to cancel."]})}),e[27]=a,e[28]=d):d=e[28],b=ae,N="h-[min(28rem,60vh)]",j="flex flex-col gap-4 px-3 pb-4",y=Q.map(i=>{const L=G.filter(o=>o.group===i);return L.length===0?null:t.jsxs("section",{className:"flex flex-col gap-1",children:[t.jsx("h3",{className:"px-2 py-1 text-xs font-medium text-muted-foreground",children:i}),L.map(o=>{const z=l===o.command;return t.jsxs("div",{className:"flex min-h-12 items-center gap-3 rounded-md px-2 py-1.5 hover:bg-accent",children:[t.jsxs("div",{className:"min-w-0 flex-1",children:[t.jsx("p",{className:"truncate text-sm",children:o.label}),t.jsx("p",{className:"truncate text-xs text-muted-foreground",children:o.description})]}),t.jsx(P,{variant:z?"secondary":"outline",size:"sm",className:"min-w-28 font-mono text-xs",onClick:()=>{r(null),x(z?null:o.command)},"aria-label":`Change shortcut for ${o.label}`,children:z?"Press keys…":Y(A[o.command])}),t.jsx(P,{variant:"ghost",size:"icon-sm",onClick:()=>{_(o.command),B($()),r(null)},"aria-label":`Reset shortcut for ${o.label}`,children:t.jsx(F,{"data-icon":"inline-start"})})]},o.command)})]},i)}),e[3]=A,e[4]=a,e[5]=s,e[6]=l,e[7]=b,e[8]=g,e[9]=d,e[10]=j,e[11]=y,e[12]=N,e[13]=S,e[14]=w,e[15]=m,e[16]=u,e[17]=h}else b=e[7],g=e[8],d=e[9],j=e[10],y=e[11],N=e[12],S=e[13],w=e[14],m=e[15],u=e[16],h=e[17];let C;e[29]!==j||e[30]!==y?(C=t.jsx("div",{className:j,children:y}),e[29]=j,e[30]=y,e[31]=C):C=e[31];let D;e[32]!==b||e[33]!==C||e[34]!==N?(D=t.jsx(b,{className:N,children:C}),e[32]=b,e[33]=C,e[34]=N,e[35]=D):D=e[35];let R;return e[36]!==g||e[37]!==d||e[38]!==D||e[39]!==S||e[40]!==w||e[41]!==m||e[42]!==u||e[43]!==h?(R=t.jsxs(g,{className:S,showCloseButton:w,children:[m,u,h,d,D]}),e[36]=g,e[37]=d,e[38]=D,e[39]=S,e[40]=w,e[41]=m,e[42]=u,e[43]=h,e[44]=R):R=e[44],R}export{pe as KeyboardShortcutsDialog};
1
+ import{c as O,j as t,r as I}from"./vendor-react-gGw_S5I_.js";import{o as H,bB as $,bC as T,bD as Q,B as P,bE as Y,bF as _,n as q,l as J,D as M,j as U,S as V,ax as W,az as X,aw as Z,bG as ee,G as te,I as se,m as ae,bH as le,bI as ne,bJ as re}from"./index-BVmNox_3.js";import{bI as F,df as oe,ak as ce}from"./vendor-ui-CKjyvB3_.js";import"./vendor-markdown-BEJ8yVzA.js";const ie=new Set(["Alt","Control","Meta","Shift"]);function pe(e){const s=O.c(6),{open:f,onOpenChange:l}=e,x=f?"open":"closed";let a;s[0]!==x?(a=t.jsx(de,{},x),s[0]=x,s[1]=a):a=s[1];let r;return s[2]!==l||s[3]!==f||s[4]!==a?(r=t.jsx(H,{open:f,onOpenChange:l,children:a}),s[2]=l,s[3]=f,s[4]=a,s[5]=r):r=s[5],r}function de(){const e=O.c(45),[s,f]=I.useState(""),[l,x]=I.useState(null),[a,r]=I.useState(null),[A,B]=I.useState($);let E,k;e[0]!==l?(E=()=>{if(!l)return;const v=l,G=function(n){if(n.key==="Escape"){n.preventDefault(),n.stopPropagation(),x(null),r(null);return}if(ie.has(n.key))return;n.preventDefault(),n.stopPropagation();const c=le(n),p=ne(c,v);if(p){r(`Already assigned to “${p.label}”.`);return}re(v,c),B($()),x(null),r(null)};return window.addEventListener("keydown",G,!0),()=>window.removeEventListener("keydown",G,!0)},k=[l],e[0]=l,e[1]=E,e[2]=k):(E=e[1],k=e[2]),I.useEffect(E,k);let b,g,d,j,y,N,S,w,m,u,h;if(e[3]!==A||e[4]!==a||e[5]!==s||e[6]!==l){const v=s.trim().toLowerCase(),G=v?T.filter(i=>`${i.label} ${i.description} ${i.group}`.toLowerCase().includes(v)):T;g=q,S="max-w-2xl gap-0 overflow-hidden p-0",w=!1,e[18]===Symbol.for("react.memo_cache_sentinel")?(m=t.jsxs(J,{className:"p-4 pb-3",children:[t.jsxs(M,{className:"flex items-center gap-2",children:[t.jsx(oe,{"data-icon":"inline-start","aria-hidden":"true",className:"size-4"}),"Keyboard shortcuts"]}),t.jsx(U,{children:"Click a shortcut, then press a new key combination. Changes are saved on this device."})]}),u=t.jsx(V,{}),e[18]=m,e[19]=u):(m=e[18],u=e[19]);let K;e[20]===Symbol.for("react.memo_cache_sentinel")?(K=t.jsx(W,{children:t.jsx(ce,{"data-icon":"inline-start","aria-hidden":"true"})}),e[20]=K):K=e[20];let n;e[21]===Symbol.for("react.memo_cache_sentinel")?(n=i=>f(i.target.value),e[21]=n):n=e[21];let c;e[22]!==s?(c=t.jsxs(X,{className:"flex-1",children:[K,t.jsx(Z,{"aria-label":"Search keyboard shortcuts",value:s,onChange:n,placeholder:"Search shortcuts…"})]}),e[22]=s,e[23]=c):c=e[23];let p;e[24]===Symbol.for("react.memo_cache_sentinel")?(p=t.jsxs(P,{variant:"outline",size:"sm",onClick:()=>{ee(),B($()),r(null)},children:[t.jsx(F,{"data-icon":"inline-start"}),"Reset all"]}),e[24]=p):p=e[24],e[25]!==c?(h=t.jsxs("div",{className:"flex items-center gap-2 p-3",children:[c,p]}),e[25]=c,e[26]=h):h=e[26],e[27]!==a?(d=a&&t.jsx(te,{variant:"destructive",className:"mx-3 mb-2 w-auto",children:t.jsxs(se,{children:[a," Press another shortcut or Esc to cancel."]})}),e[27]=a,e[28]=d):d=e[28],b=ae,N="h-[min(28rem,60vh)]",j="flex flex-col gap-4 px-3 pb-4",y=Q.map(i=>{const L=G.filter(o=>o.group===i);return L.length===0?null:t.jsxs("section",{className:"flex flex-col gap-1",children:[t.jsx("h3",{className:"px-2 py-1 text-xs font-medium text-muted-foreground",children:i}),L.map(o=>{const z=l===o.command;return t.jsxs("div",{className:"flex min-h-12 items-center gap-3 rounded-md px-2 py-1.5 hover:bg-accent",children:[t.jsxs("div",{className:"min-w-0 flex-1",children:[t.jsx("p",{className:"truncate text-sm",children:o.label}),t.jsx("p",{className:"truncate text-xs text-muted-foreground",children:o.description})]}),t.jsx(P,{variant:z?"secondary":"outline",size:"sm",className:"min-w-28 font-mono text-xs",onClick:()=>{r(null),x(z?null:o.command)},"aria-label":`Change shortcut for ${o.label}`,children:z?"Press keys…":Y(A[o.command])}),t.jsx(P,{variant:"ghost",size:"icon-sm",onClick:()=>{_(o.command),B($()),r(null)},"aria-label":`Reset shortcut for ${o.label}`,children:t.jsx(F,{"data-icon":"inline-start"})})]},o.command)})]},i)}),e[3]=A,e[4]=a,e[5]=s,e[6]=l,e[7]=b,e[8]=g,e[9]=d,e[10]=j,e[11]=y,e[12]=N,e[13]=S,e[14]=w,e[15]=m,e[16]=u,e[17]=h}else b=e[7],g=e[8],d=e[9],j=e[10],y=e[11],N=e[12],S=e[13],w=e[14],m=e[15],u=e[16],h=e[17];let C;e[29]!==j||e[30]!==y?(C=t.jsx("div",{className:j,children:y}),e[29]=j,e[30]=y,e[31]=C):C=e[31];let D;e[32]!==b||e[33]!==C||e[34]!==N?(D=t.jsx(b,{className:N,children:C}),e[32]=b,e[33]=C,e[34]=N,e[35]=D):D=e[35];let R;return e[36]!==g||e[37]!==d||e[38]!==D||e[39]!==S||e[40]!==w||e[41]!==m||e[42]!==u||e[43]!==h?(R=t.jsxs(g,{className:S,showCloseButton:w,children:[m,u,h,d,D]}),e[36]=g,e[37]=d,e[38]=D,e[39]=S,e[40]=w,e[41]=m,e[42]=u,e[43]=h,e[44]=R):R=e[44],R}export{pe as KeyboardShortcutsDialog};