@wrongstack/webui 0.298.2 → 0.299.0

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 (102) hide show
  1. package/dist/assets/{AgentRosterView-RvxaV08Y.js → AgentRosterView-BqojERFR.js} +4 -4
  2. package/dist/assets/{AnalyticsDashboard-irejsLMt.js → AnalyticsDashboard-D58kSekC.js} +1 -1
  3. package/dist/assets/{AudienceMemoryPanel-DDW_WPjf.js → AudienceMemoryPanel-Cc1UkbDl.js} +1 -1
  4. package/dist/assets/ChangesView-BKU80ANq.js +1 -0
  5. package/dist/assets/ChronicleDashboard-CvCS1Dj1.js +1 -0
  6. package/dist/assets/CodeEditor-BHZQhx_8.js +1 -0
  7. package/dist/assets/CodeMap-qllGEFLB.js +1 -0
  8. package/dist/assets/{CronJobsPanel-BXujnpGC.js → CronJobsPanel-DD5mhZ4Q.js} +1 -1
  9. package/dist/assets/{DeadCodeScanPanel-HTbGUTMl.js → DeadCodeScanPanel-PB-c8et_.js} +1 -1
  10. package/dist/assets/{DebugDashboard-B5kJBUv0.js → DebugDashboard-Q8QiVflQ.js} +1 -1
  11. package/dist/assets/{DesignGalleryView-BQ0CZpQm.js → DesignGalleryView-CGOtWO7s.js} +1 -1
  12. package/dist/assets/{GoalView-DvaSR6CO.js → GoalView-Dlk42vW7.js} +1 -1
  13. package/dist/assets/KanbanView-DIP6kKmU.js +3 -0
  14. package/dist/assets/{MailboxDetailView-Dh8ekyMw.js → MailboxDetailView-ZcKcOEAe.js} +1 -1
  15. package/dist/assets/MemoryManager-B7620q_K.js +1 -0
  16. package/dist/assets/{ModelPicker-BxYMTEEN.js → ModelPicker-DvNLZzkm.js} +1 -1
  17. package/dist/assets/OfficeMapPanel-DKJNTtOZ.js +4 -0
  18. package/dist/assets/{ProcessMonitor-DVUCtVHZ.js → ProcessMonitor-2nSk6sXA.js} +1 -1
  19. package/dist/assets/{QueuePanel-n9lScdWu.js → QueuePanel-4KBBWFxj.js} +1 -1
  20. package/dist/assets/{RefreshDebugView-eZQ3wdxU.js → RefreshDebugView-D3XnE53y.js} +1 -1
  21. package/dist/assets/RequirementIntakeView-BMxlf8bt.js +1 -0
  22. package/dist/assets/{SageTabs-B-eQ--Sb.js → SageTabs-g1hO2hJ0.js} +2 -2
  23. package/dist/assets/SddHub-Kv_TbTgT.js +2 -0
  24. package/dist/assets/SessionInspectView-PnKTvyvP.js +1 -0
  25. package/dist/assets/SessionList-BeinIC-h.js +1 -0
  26. package/dist/assets/SessionsDashboard-DEG_BylE.js +1 -0
  27. package/dist/assets/SetupScreen-DxJwZ1OZ.js +1 -0
  28. package/dist/assets/SkillDetailView-D7EQ2XtV.js +3 -0
  29. package/dist/assets/{SpecsView-BYiJr__T.js → SpecsView-Fm7pYYcj.js} +1 -1
  30. package/dist/assets/TechStackView-Bo_UenRF.js +1 -0
  31. package/dist/assets/{TerminalPanel-BgMsGfGa.js → TerminalPanel-BL9ZPGJt.js} +1 -1
  32. package/dist/assets/{Toaster-EXqX2jqp.js → Toaster-CJI70aa-.js} +1 -1
  33. package/dist/assets/{activity-DReNmuta.js → activity-BCgOEWgR.js} +2 -2
  34. package/dist/assets/{activity-Dyh19u3P.js → activity-BQ0zqkw2.js} +2 -2
  35. package/dist/assets/{activity-BJijwuIr.js → activity-CAovbq3e.js} +2 -2
  36. package/dist/assets/{activity-BBPMHCAJ.js → activity-CFQyCvgu.js} +2 -2
  37. package/dist/assets/{activity-GR8KiHvf.js → activity-CdQf7zRK.js} +2 -2
  38. package/dist/assets/{activity-iuGHFz2B.js → activity-DACvyn2-.js} +2 -2
  39. package/dist/assets/{activity-DeEOo2zu.js → activity-DOwYydU-.js} +2 -2
  40. package/dist/assets/{button-DwmC7ENW.js → button-Dcy288Mc.js} +1 -1
  41. package/dist/assets/{chat-store-LHzJqRCp.js → chat-store-CtOyUCdF.js} +2 -2
  42. package/dist/assets/{codemap-activity-store-B6n7KiS8.js → codemap-activity-store-DQfjo7-j.js} +1 -1
  43. package/dist/assets/codemap-index-store-COStDU-8.js +1 -0
  44. package/dist/assets/{dialog-DsCmc6eL.js → dialog-ftgTihmF.js} +1 -1
  45. package/dist/assets/{empty-state-02bIS4x7.js → empty-state-RRSqQaCk.js} +1 -1
  46. package/dist/assets/{i18n-DxnYsmc-.js → i18n-B0hsnanh.js} +2 -2
  47. package/dist/assets/index-DHdO0CRE.js +132 -0
  48. package/dist/assets/index-DKrFQ76m.css +1 -0
  49. package/dist/assets/{input-UhWgodVi.js → input-fo9-BPBC.js} +1 -1
  50. package/dist/assets/{mailbox-store-xh2Ux-Xs.js → mailbox-store-D8TvJsuk.js} +1 -1
  51. package/dist/assets/{progress-ring-C0O73ZjR.js → progress-ring-61A-xUEl.js} +1 -1
  52. package/dist/assets/{roster-ws-DlQQL7Eh.js → roster-ws-Dfg_187V.js} +1 -1
  53. package/dist/assets/{session-store-BE_S1f5v.js → session-store-b2KGFwkX.js} +1 -1
  54. package/dist/assets/{shared-bBntASiy.js → shared-KAzksK0C.js} +1 -1
  55. package/dist/assets/stores-BptlyD_v.js +7 -0
  56. package/dist/assets/ui-store-BsBnjO3w.js +1 -0
  57. package/dist/assets/useWebSocket-Bc4S0N4r.js +29 -0
  58. package/dist/assets/{utils-_s0GyctV.js → utils-B-9lSDIn.js} +1 -1
  59. package/dist/assets/{vendor-CxV3l5PQ.js → vendor-BuarzSSb.js} +30 -30
  60. package/dist/assets/{view-navigation-DLdE7qHU.js → view-navigation-DxfiZrXS.js} +1 -1
  61. package/dist/assets/ws-client-DqFoX4jJ.js +1 -0
  62. package/dist/components/CouncilLogTimeline.d.ts +2 -0
  63. package/dist/components/QuickModelSwitcher.filter.d.ts +9 -4
  64. package/dist/components/RequirementIntakeView.d.ts +2 -0
  65. package/dist/components/SessionInspectView.d.ts +2 -0
  66. package/dist/components/SettingsPanel/ModelCatalogPicker.d.ts +1 -2
  67. package/dist/components/SettingsPanel/brain-section-options.d.ts +16 -0
  68. package/dist/components/ViewRouter.d.ts +1 -1
  69. package/dist/hooks/useWebSocket.d.ts +1 -0
  70. package/dist/index.html +21 -21
  71. package/dist/index.js +10761 -9484
  72. package/dist/lib/view-navigation.d.ts +2 -2
  73. package/dist/lib/ws-client-actions.d.ts +1 -0
  74. package/dist/stores/council-log-store.d.ts +67 -0
  75. package/dist/stores/index.d.ts +3 -1
  76. package/dist/stores/session-inspect-store.d.ts +51 -0
  77. package/dist/stores/ui-store.d.ts +19 -7
  78. package/dist/stores/viz-store.d.ts +1 -1
  79. package/dist/types/brain.d.ts +15 -0
  80. package/dist/types/client-message.d.ts +5 -0
  81. package/dist/types/server-message.d.ts +2 -2
  82. package/dist/types/system.d.ts +35 -0
  83. package/package.json +8 -8
  84. package/dist/assets/ChangesView-Bnd167hf.js +0 -1
  85. package/dist/assets/ChronicleDashboard-DC62FDEt.js +0 -1
  86. package/dist/assets/CodeEditor-DCWcCQPO.js +0 -1
  87. package/dist/assets/CodeMap-DSqqgBuD.js +0 -1
  88. package/dist/assets/KanbanView-DpWs_i8T.js +0 -3
  89. package/dist/assets/MemoryManager-CUAbNwsz.js +0 -1
  90. package/dist/assets/OfficeMapPanel-HgERknuN.js +0 -4
  91. package/dist/assets/SddHub-D81poT6w.js +0 -2
  92. package/dist/assets/SessionsDashboard-CR3NZeHw.js +0 -1
  93. package/dist/assets/SetupScreen-t6wrhv6l.js +0 -1
  94. package/dist/assets/SkillDetailView-D6TOvMQU.js +0 -3
  95. package/dist/assets/TechStackView-HEMM3PkG.js +0 -1
  96. package/dist/assets/codemap-index-store-oapPwtvI.js +0 -1
  97. package/dist/assets/index-Bf75VrDE.js +0 -132
  98. package/dist/assets/index-NFp5CXyK.css +0 -1
  99. package/dist/assets/stores-BS-Bdi-5.js +0 -7
  100. package/dist/assets/ui-store-C4Ybfoon.js +0 -1
  101. package/dist/assets/useWebSocket-x8PMoTq8.js +0 -28
  102. package/dist/assets/ws-client-Cy3oRAmZ.js +0 -1
@@ -1 +0,0 @@
1
- import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{An as t,Bi as n,Ca as r,Cn as i,Ft as a,Ia as o,Ir as s,Ln as c,Ni as l,Ot as u,Tn as d,Vt as f,Wt as p,Xi as m,Yi as h,Zt as g,_,a as ee,an as v,cn as y,dt as b,f as x,gn as te,hi as S,i as C,jr as w,jt as T,ki as E,kn as ne,kr as D,la as O,li as re,lr as ie,lt as ae,n as oe,nr as se,oi as k,qi as ce,qr as A,r as le,ra as j,ri as M,s as N,si as ue,va as de,xn as fe}from"./vendor-CxV3l5PQ.js";import{n as pe}from"./ui-store-C4Ybfoon.js";import{t as me}from"./useWebSocket-x8PMoTq8.js";import{t as P}from"./ws-client-Cy3oRAmZ.js";import{t as F}from"./utils-_s0GyctV.js";import{M as he}from"./stores-BS-Bdi-5.js";import{a as ge,i as _e,n as ve,o as ye,r as I,t as L}from"./dialog-DsCmc6eL.js";import{t as R}from"./button-DwmC7ENW.js";import{t as z}from"./input-UhWgodVi.js";import{C as be,S as xe,c as Se}from"./index-Bf75VrDE.js";import{t as Ce}from"./roster-ws-DlQQL7Eh.js";import{_ as we,a as Te,b as Ee,c as De,d as Oe,f as ke,g as B,h as Ae,i as V,l as H,m as U,n as je,o as Me,p as Ne,r as Pe,s as Fe,t as Ie,u as Le,v as Re,y as W}from"./shared-bBntASiy.js";var G=e(o(),1),K=ae(),ze=212,Be=188;function Ve(e){return e.length>14?`${e.slice(0,11)}…`:e}function He(e,t=58){let n=e.replace(/\s+/g,` `).trim();return n.length>t?`${n.slice(0,t-1)}…`:n}function Ue(e){return e.type===`symbol`?[e.path,e.symbol?`#${e.symbol}`:``].filter(Boolean).join(``):e.path??e.command??e.symbol??e.role??e.type}function We(e){return e===`active`?`border-success/45 bg-success/10 text-success`:e===`stale`?`border-warning/45 bg-warning/10 text-warning`:e===`contradicted`?`border-destructive/45 bg-destructive/10 text-destructive`:e===`superseded`?`border-warning/35 bg-warning/5 text-warning`:`border-border bg-muted/55 text-muted-foreground`}function Ge({data:e}){let{entry:t,center:n}=e;return(0,K.jsxs)(`div`,{className:n?`border border-primary/70 bg-card px-3 py-2.5 text-card-foreground shadow-[0_0_0_1px_hsl(var(--primary)/0.2),0_0_24px_hsl(var(--primary)/0.12)]`:`border border-border/80 bg-card/95 px-3 py-2.5 text-card-foreground shadow-lg`,style:{width:ze},title:t.text,children:[(0,K.jsx)(N,{type:`target`,position:_.Top,className:`!border-background !bg-muted-foreground`}),(0,K.jsx)(N,{type:`source`,position:_.Bottom,className:`!border-background !bg-primary`}),(0,K.jsx)(N,{type:`source`,position:_.Right,className:`!border-background !bg-primary`}),(0,K.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,K.jsx)(`span`,{className:`border px-1.5 py-0.5 text-[9px] font-bold uppercase ${We(t.status)}`,children:t.status}),(0,K.jsx)(`span`,{className:`ml-auto truncate font-mono text-[9px] text-muted-foreground`,children:Ve(t.id)})]}),(0,K.jsx)(`p`,{className:`mt-2 line-clamp-2 text-[11px] leading-4 text-foreground/90`,children:He(t.text)}),(0,K.jsx)(`p`,{className:`mt-1 font-mono text-[9px] uppercase text-muted-foreground`,children:t.kind})]})}function Ke({data:e}){return(0,K.jsxs)(`div`,{className:`border border-info/40 bg-info/8 px-2.5 py-2 text-card-foreground shadow-lg`,style:{width:Be},title:e.label,children:[(0,K.jsx)(N,{type:`target`,position:_.Left,className:`!border-background !bg-info`}),(0,K.jsx)(`p`,{className:`font-mono text-[9px] font-bold uppercase text-info`,children:e.anchor.type}),(0,K.jsx)(`p`,{className:`mt-1 truncate font-mono text-[10px] text-foreground/85`,children:e.label})]})}var qe={memoryNode:Ge,anchorNode:Ke};function Je(e){return{id:e,revision:0,scope:`project`,kind:`fact`,status:`deleted`,text:`Memory is unavailable or has been removed.`,importance:0,confidence:0,freshness:0,tags:[],anchors:[],createdAt:``,updatedAt:``}}function Ye({nodes:e,edges:t,className:n}){return(0,K.jsx)(`div`,{className:F(`w-full`,n),children:(0,K.jsxs)(x,{nodes:e,edges:t,nodeTypes:qe,fitView:!0,fitViewOptions:{padding:.24,maxZoom:1.05},minZoom:.4,maxZoom:1.5,nodesConnectable:!1,elementsSelectable:!1,panOnScroll:!1,zoomOnScroll:!1,proOptions:{hideAttribution:!0},children:[(0,K.jsx)(le,{variant:C.Dots,gap:18,size:1,color:`hsl(var(--muted-foreground) / 0.18)`}),(0,K.jsx)(ee,{showInteractive:!1,className:`!border-border !bg-card !shadow-lg`})]})})}function q({centerMemory:e,allMemories:t,graphEdges:n,loading:r=!1,error:i=null}){let[a,o]=(0,G.useState)(!1),s=`mem:${e.id}`,c=(0,G.useMemo)(()=>n.filter(e=>e.from===s&&e.to.startsWith(`mem:`)||e.to===s&&e.from.startsWith(`mem:`)).slice(0,24),[s,n]),{nodes:l,edges:u}=(0,G.useMemo)(()=>{let n=[],r=[],i=new Map(t.map(e=>[e.id,e]));n.push({id:e.id,type:`memoryNode`,position:{x:320-ze/2,y:120},data:{entry:e,center:!0}});let a=[...e.supersededBy?[{id:e.supersededBy,relation:`superseded by`}]:[],...(e.supersedes??[]).map(e=>({id:e,relation:`supersedes`})),...(e.contradicts??[]).map(e=>({id:e,relation:`contradicts`}))];for(let e of c){let t=(e.from===s?e.to:e.from).slice(4);a.some(n=>n.id===t&&n.relation===e.relation)||a.push({id:t,relation:e.relation,weight:e.weight,evidence:e.evidence})}let o=320-(a.length-1)*220/2;return a.forEach((t,a)=>{let s=i.get(t.id)??Je(t.id),c=t.relation===`superseded by`,l=c?0:280+Math.floor(a/3)*130,u=c?320-ze/2:o+a*220-ze/2;n.push({id:`memory:${t.id}:${a}`,type:`memoryNode`,position:{x:u,y:l},data:{entry:s,center:!1}});let d=t.relation===`contradicts`,f=c?`memory:${t.id}:${a}`:e.id,p=c?e.id:`memory:${t.id}:${a}`;r.push({id:`relation:${t.relation}:${t.id}:${a}`,source:f,target:p,type:`smoothstep`,animated:!d,label:t.weight===void 0?t.relation:`${t.relation} ${t.weight.toFixed(2)}`,data:{evidence:t.evidence??[]},style:{stroke:d?`hsl(var(--destructive))`:`hsl(var(--primary))`,strokeWidth:1.7,...d?{strokeDasharray:`5 4`}:{}},labelStyle:{fill:d?`hsl(var(--destructive))`:`hsl(var(--muted-foreground))`,fontSize:9,fontWeight:700},labelBgStyle:{fill:`hsl(var(--card))`,fillOpacity:.9}})}),e.anchors.forEach((t,i)=>{let a=`anchor:${i}`;n.push({id:a,type:`anchorNode`,position:{x:540,y:120+(i-(e.anchors.length-1)/2)*66},data:{anchor:t,label:Ue(t)}}),r.push({id:`anchor-edge:${i}`,source:e.id,target:a,type:`smoothstep`,style:{stroke:`hsl(var(--info))`,strokeWidth:1.3}})}),{nodes:n,edges:r}},[t,e,s,c]);return l.length<=1&&!r&&!i?null:(0,K.jsxs)(`section`,{className:`overflow-hidden border border-border/75 bg-background/35`,"aria-label":`Memory relationship graph`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between border-b border-border/70 bg-card/55 px-3 py-2`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`p`,{className:`text-[10px] font-bold uppercase tracking-[0.16em] text-muted-foreground`,children:`Relationship map`}),l.length>1&&(0,K.jsxs)(R,{variant:`ghost`,size:`sm`,onClick:()=>o(!0),className:`h-6 gap-1 px-2 text-[9px] font-bold uppercase tracking-[0.12em]`,"aria-label":`Open full screen graph`,children:[(0,K.jsx)(re,{className:`size-3`}),`Open full screen`]})]}),(0,K.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:r?`loading real graph…`:`${l.length} nodes · ${u.length} edges`})]}),i&&(0,K.jsx)(`p`,{className:`border-b border-destructive/25 bg-destructive/5 px-3 py-2 text-[10px] text-destructive`,children:i}),l.length>1&&(0,K.jsx)(Ye,{nodes:l,edges:u,className:`h-[320px]`}),c.some(e=>e.evidence?.length)&&(0,K.jsx)(`div`,{className:`grid gap-1 border-t border-border/70 bg-card/35 px-3 py-2`,children:c.filter(e=>e.evidence?.length).slice(0,12).map(e=>{let t=(e.from===s?e.to:e.from).slice(4);return(0,K.jsxs)(`p`,{className:`truncate font-mono text-[9px] text-muted-foreground`,children:[(0,K.jsx)(`span`,{className:`text-info`,children:e.relation}),` `,Ve(t),` · why:`,` `,e.evidence?.join(`, `)]},e.id)})}),a&&(0,K.jsx)(L,{open:a,onOpenChange:o,children:(0,K.jsxs)(ve,{className:`flex max-h-[90dvh] max-w-[90vw] flex-col p-0`,showCloseButton:!1,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between border-b border-border/70 bg-card/55 px-4 py-3`,children:[(0,K.jsxs)(`p`,{className:`text-[10px] font-bold uppercase tracking-[0.16em] text-muted-foreground`,children:[`Relationship map — `,e.id]}),(0,K.jsx)(R,{variant:`ghost`,size:`sm`,onClick:()=>o(!1),className:`h-7 gap-1 px-2 text-[10px]`,children:`Close`})]}),(0,K.jsx)(`div`,{className:`min-h-0 flex-1 px-4 pb-4`,children:(0,K.jsx)(Ye,{nodes:l,edges:u,className:`h-[65vh]`})})]})})]})}function Xe({memory:e,allMemories:t,relatedMemories:n,graphEdges:r,graphLoading:i,graphError:a,onClose:o,onOpenMemory:s,onEdit:c,onDelete:l,onTagSelect:u,onNotice:f}){return(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 border-b border-border/70 bg-card/65 px-4 py-3 backdrop-blur-xl`,children:[(0,K.jsx)(R,{variant:`ghost`,size:`icon`,className:`md:hidden`,onClick:o,"aria-label":`Back to memory list`,children:(0,K.jsx)(de,{className:`size-4`})}),(0,K.jsx)(`span`,{className:F(`text-[10px] font-bold uppercase tracking-[0.14em]`,Ae(e.kind)),children:Pe[e.kind]??e.kind}),(0,K.jsx)(H,{status:e.status}),(0,K.jsx)(`span`,{className:`border border-border/70 px-2 py-0.5 font-mono text-[9px] uppercase text-muted-foreground`,children:e.scope}),e.audience&&(0,K.jsxs)(`span`,{className:`flex items-center gap-1 border border-primary/30 bg-primary/10 px-2 py-0.5 font-mono text-[9px] text-primary`,title:Ne(e.audience),children:[(0,K.jsx)(j,{className:`size-3`}),Ne(e.audience)]}),(0,K.jsxs)(`div`,{className:`ml-auto flex items-center gap-1.5`,children:[(0,K.jsx)(R,{variant:`ghost`,size:`icon`,"aria-label":`Copy memory ID`,title:`Copy memory ID`,onClick:()=>{navigator.clipboard?.writeText(e.id),f(`Memory ID copied.`)},children:(0,K.jsx)(E,{className:`size-4`})}),(0,K.jsxs)(R,{variant:`outline`,size:`sm`,onClick:c,disabled:e.status===`deleted`,children:[(0,K.jsx)(d,{className:`size-3.5`}),` Edit`]}),(0,K.jsxs)(R,{variant:`destructive`,size:`sm`,onClick:l,disabled:e.status===`deleted`,children:[(0,K.jsx)(T,{className:`size-3.5`}),` Delete`]})]})]}),(0,K.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto overscroll-contain p-4 md:p-5`,children:(0,K.jsxs)(`div`,{className:`mx-auto max-w-5xl space-y-5`,children:[(0,K.jsx)(Ze,{memory:e}),(0,K.jsx)(J,{memory:e}),e.tags.length>0&&(0,K.jsx)(Qe,{tags:e.tags,onTagSelect:u}),e.anchors.length>0&&(0,K.jsx)(Y,{anchors:e.anchors}),n.length>0&&(0,K.jsx)($e,{relatedMemories:n,allMemories:t,onOpenMemory:s}),(0,K.jsx)(q,{centerMemory:e,allMemories:t,graphEdges:r,loading:i,error:a}),(0,K.jsx)(X,{memory:e}),e.status===`deleted`&&(0,K.jsx)(et,{contextPolicy:e.contextPolicy})]})})]})}function Ze({memory:e}){return(0,K.jsxs)(`div`,{className:`relative overflow-hidden border border-border/75 bg-card/55 p-5 shadow-[inset_0_1px_0_hsl(var(--foreground)/0.04)]`,children:[(0,K.jsx)(`div`,{className:`pointer-events-none absolute -right-10 -top-10 size-36 bg-[radial-gradient(circle,hsl(var(--info)/0.13),transparent_68%)]`}),(0,K.jsx)(`p`,{className:`relative whitespace-pre-wrap text-sm leading-7 text-foreground md:text-[15px]`,children:e.text}),e.summary&&(0,K.jsx)(`p`,{className:`relative mt-4 border-l-2 border-info/50 pl-3 text-xs italic leading-5 text-muted-foreground`,children:e.summary}),(0,K.jsxs)(`div`,{className:`relative mt-5 flex flex-wrap items-center gap-2 border-t border-border/60 pt-3`,children:[(0,K.jsx)(`code`,{className:`min-w-0 break-all font-mono text-[10px] text-muted-foreground`,children:e.id}),(0,K.jsxs)(`span`,{className:`ml-auto font-mono text-[10px] text-muted-foreground`,children:[`revision `,e.revision]})]})]})}function J({memory:e}){return(0,K.jsx)(`div`,{className:`grid gap-px bg-border/60 sm:grid-cols-3`,children:[[`Importance`,e.importance,g],[`Confidence`,e.confidence,n],[`Freshness`,e.freshness,te]].map(([e,t,n])=>(0,K.jsxs)(`div`,{className:`bg-card/60 p-3`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(n,{className:`size-3.5 text-info`}),(0,K.jsx)(`span`,{className:`text-[10px] font-bold uppercase tracking-[0.13em] text-muted-foreground`,children:e}),(0,K.jsxs)(`span`,{className:`ml-auto font-mono text-xs font-bold tabular-nums`,children:[Math.round(t*100),`%`]})]}),(0,K.jsx)(`div`,{className:`mt-2 h-1 bg-muted`,children:(0,K.jsx)(`div`,{className:`h-full bg-info shadow-[0_0_8px_hsl(var(--info)/0.45)]`,style:{width:`${Math.round(t*100)}%`}})})]},e))})}function Qe({tags:e,onTagSelect:t}){return(0,K.jsxs)(`section`,{children:[(0,K.jsxs)(`h3`,{className:`mb-2 flex items-center gap-2 text-[10px] font-bold uppercase tracking-[0.14em] text-muted-foreground`,children:[(0,K.jsx)(a,{className:`size-3.5 text-info`}),` Tags`]}),(0,K.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:e.map(e=>(0,K.jsxs)(`button`,{type:`button`,onClick:()=>t(e),className:`border border-info/25 bg-info/5 px-2 py-1 font-mono text-[10px] text-info hover:border-info/55 hover:bg-info/10`,children:[`#`,e]},e))})]})}function Y({anchors:e}){return(0,K.jsxs)(`section`,{className:`border border-border/75 bg-card/40`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between border-b border-border/65 px-3 py-2.5`,children:[(0,K.jsxs)(`h3`,{className:`flex items-center gap-2 text-[10px] font-bold uppercase tracking-[0.14em] text-muted-foreground`,children:[(0,K.jsx)(M,{className:`size-3.5 text-info`}),` Anchors`]}),(0,K.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:e.length})]}),(0,K.jsx)(`ul`,{className:`divide-y divide-border/55`,children:e.map((e,t)=>(0,K.jsxs)(`li`,{className:`flex min-w-0 items-start gap-3 px-3 py-2.5`,children:[(0,K.jsx)(`span`,{className:`mt-0.5 flex size-7 shrink-0 items-center justify-center border border-info/25 bg-info/5 text-info`,children:e.type===`command`?(0,K.jsx)(f,{className:`size-3.5`}):(0,K.jsx)(M,{className:`size-3.5`})}),(0,K.jsxs)(`div`,{className:`min-w-0`,children:[(0,K.jsx)(`p`,{className:`text-[9px] font-bold uppercase text-muted-foreground`,children:e.type}),(0,K.jsxs)(`p`,{className:`mt-0.5 break-all font-mono text-[10px] leading-4 text-foreground/85`,children:[e.path??e.command??e.role??`—`,e.symbol?`#${e.symbol}`:``]})]}),(e.lineStart||e.lineEnd)&&(0,K.jsxs)(`span`,{className:`ml-auto shrink-0 font-mono text-[9px] text-muted-foreground`,children:[`L`,e.lineStart??`?`,`–`,e.lineEnd??`?`]})]},`${e.type}:${e.path??e.command??e.symbol??e.role}:${t}`))})]})}function $e({relatedMemories:e,allMemories:t,onOpenMemory:n}){return(0,K.jsxs)(`section`,{className:`border border-border/75 bg-card/40`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between border-b border-border/65 px-3 py-2.5`,children:[(0,K.jsxs)(`h3`,{className:`flex items-center gap-2 text-[10px] font-bold uppercase tracking-[0.14em] text-muted-foreground`,children:[(0,K.jsx)(w,{className:`size-3.5 text-info`}),` Memory relationships`]}),(0,K.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:e.length})]}),(0,K.jsx)(`ul`,{className:`divide-y divide-border/55`,children:e.map(e=>{let r=t.find(t=>t.id===e.id);return(0,K.jsx)(`li`,{children:(0,K.jsxs)(`button`,{type:`button`,disabled:!r,onClick:()=>r&&n(r.id),className:`group flex w-full min-w-0 items-center gap-3 px-3 py-2.5 text-left hover:bg-info/5 disabled:cursor-not-allowed disabled:opacity-55`,children:[(0,K.jsx)(`span`,{className:F(`w-24 shrink-0 text-[9px] font-bold uppercase`,e.relation===`Contradicts`?`text-destructive`:`text-info`),children:e.relation}),(0,K.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-xs`,children:r?B(r.text,95):`Referenced memory is unavailable`}),(0,K.jsx)(`code`,{className:`hidden max-w-32 truncate font-mono text-[9px] text-muted-foreground sm:block`,children:e.id}),r&&(0,K.jsx)(ce,{className:`size-3.5 shrink-0 text-muted-foreground group-hover:text-info`})]})},`${e.relation}:${e.id}`)})})]})}function X({memory:e}){return(0,K.jsx)(`section`,{className:`grid gap-px bg-border/60 sm:grid-cols-2 lg:grid-cols-4`,children:[[`Created`,U(e.createdAt),O],[`Updated`,U(e.updatedAt),te],[`Last accessed`,U(e.lastAccessedAt),c],[`Last verified`,U(e.lastVerifiedAt),g]].map(([e,t,n])=>(0,K.jsxs)(`div`,{className:`bg-card/50 p-3`,children:[(0,K.jsx)(n,{className:`size-3.5 text-muted-foreground`}),(0,K.jsx)(`p`,{className:`mt-2 text-[9px] font-bold uppercase tracking-[0.12em] text-muted-foreground`,children:e}),(0,K.jsx)(`p`,{className:`mt-1 text-[10px] leading-4 text-foreground/85`,children:t})]},e))})}function et({contextPolicy:e}){return(0,K.jsxs)(`div`,{className:`flex items-start gap-3 border border-border bg-muted/50 p-4 text-xs text-muted-foreground`,children:[(0,K.jsx)(r,{className:`mt-0.5 size-4 shrink-0`}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`font-bold text-foreground`,children:`Deleted memory`}),(0,K.jsx)(`p`,{className:`mt-1 leading-5`,children:e===`never`?`This record is audit-only and carries an absolute ban: it can never enter LLM context.`:`The record is inactive and cannot be edited, but remains eligible as historical evidence when retrieval finds it relevant.`})]})]})}var Z={filePath:``,primaryMatches:[],symbolMatches:[],relatedMatches:[],totalCount:0,activeCount:0,supersededCount:0,reviewPendingCount:0};function tt(e){let{filePath:t,lineStart:n,lineEnd:r,limit:i=50,showSuperseded:a=!0,showDeleted:o=!1,autoFetch:s=!0,sendOptions:c}=e,l=c?JSON.stringify(c):``,[u,d]=(0,G.useState)(null),[f,p]=(0,G.useState)(!1),[m,h]=(0,G.useState)(null),g=(0,G.useRef)(0),_=(0,G.useRef)(null),ee=(0,G.useRef)(c);ee.current=c;let v=(0,G.useCallback)(()=>{if(!t){d(null),h(null),p(!1);return}let e=++g.current;p(!0),h(null);let s=P();if(!s){h(`WebSocket client unavailable`),p(!1);return}_.current?.(),_.current=null;let c=t,l=s.on(`memory.sage.forFile`,t=>{if(e!==g.current)return;let n=t.payload.response;n&&n.filePath!==c||(t.payload.error?(h(t.payload.error),d(null)):(d(n??Z),h(null)),p(!1))});_.current=l;let u={filePath:t,limit:i,showSuperseded:a,showDeleted:o,...n===void 0?{}:{lineStart:n},...r===void 0?{}:{lineEnd:r}};try{s.findMemoriesForFile(u,ee.current??void 0)}catch(t){l(),_.current===l&&(_.current=null),e===g.current&&(h(t instanceof Error?t.message:String(t)),p(!1))}},[t,n,r,i,a,o]);(0,G.useEffect)(()=>{if(s)return v(),()=>{g.current++,_.current?.(),_.current=null}},[s,v,l]);let y=(0,G.useCallback)(()=>{v()},[v]);return(0,G.useEffect)(()=>()=>{_.current?.(),_.current=null},[]),{data:u,loading:f,error:m,refetch:y}}function nt(e){return e>=.9?`bg-success/15 border-success/40`:e>=.7?`bg-info/15 border-info/40`:e>=.4?`bg-warning/10 border-warning/30`:`bg-muted/30 border-border/40`}function Q(e){switch(e){case`scope_file`:return`scope: file`;case`scope_symbol`:return`scope: symbol`;case`anchor_file`:return`anchor: file`;case`anchor_symbol`:return`anchor: symbol`;case`anchor_directory`:return`anchor: directory`;case`mention`:return`text mention`}}function rt({match:e,cursorBoosted:t,onShowMemory:n,onAcceptDeletion:r,onKeep:a,onUpdate:o,onMarkPermanent:s,onRecover:c,pendingAction:l}){let d=e.memory.status===`deleted`,f=e.memory.status===`superseded`,h=e.pendingReview,g=l!==void 0,_=t===!0;return(0,K.jsxs)(`article`,{className:F(`group relative rounded-md border px-3 py-2 text-sm transition-colors`,nt(e.matchStrength),_&&`ring-1 ring-primary/40 ring-offset-0`,d&&`opacity-70`),"data-match-via":e.matchedVia,"data-memory-id":e.memory.id,children:[(0,K.jsx)(`header`,{className:`flex items-start justify-between gap-2`,children:(0,K.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[10px] uppercase tracking-wide`,children:[(0,K.jsx)(`span`,{className:F(`font-mono`,Ae(e.memory.kind)),children:Pe[e.memory.kind]??e.memory.kind}),(0,K.jsx)(`span`,{className:`text-muted-foreground`,children:`·`}),(0,K.jsx)(`span`,{className:`font-mono text-muted-foreground`,children:Q(e.matchedVia)}),_&&(0,K.jsxs)(`span`,{className:`flex items-center gap-0.5 rounded-sm bg-primary/15 px-1 py-0.5 font-mono text-primary`,title:`Cursor line range matches this memory's anchor`,children:[(0,K.jsx)(i,{className:`size-2.5`}),` cursor`]}),h&&(0,K.jsxs)(`span`,{className:`flex items-center gap-0.5 rounded-sm bg-warning/15 px-1 py-0.5 font-mono text-warning`,title:`Hygiene review: ${h.reason} (${h.ageDays}d old)`,children:[(0,K.jsx)(u,{className:`size-2.5`}),` review`]}),d&&(0,K.jsx)(`span`,{className:`font-mono text-destructive`,children:`deleted`}),f&&!d&&(0,K.jsx)(`span`,{className:`font-mono text-muted-foreground`,children:`superseded`})]}),(0,K.jsx)(`p`,{className:`mt-1 text-foreground/90`,children:B(e.memory.text,200)}),(0,K.jsxs)(`div`,{className:`mt-1 flex items-center gap-2 text-[10px] text-muted-foreground`,children:[(0,K.jsx)(H,{status:e.memory.status}),(0,K.jsxs)(`span`,{children:[`updated `,Re(e.memory.updatedAt)]})]})]})}),(0,K.jsxs)(`footer`,{className:`mt-2 flex flex-wrap items-center gap-1.5`,children:[d&&c&&(0,K.jsxs)(R,{type:`button`,size:`sm`,variant:`outline`,disabled:g,onClick:()=>c(e.memory.id),className:`h-7 gap-1 border-primary/40 px-2 text-[11px] text-primary hover:bg-primary/10`,title:`Restore this memory to active status (PR #1: memory_recover)`,children:[(0,K.jsx)(te,{className:`size-3`}),` Recover`]}),f&&e.supersededByActiveId&&n&&(0,K.jsxs)(R,{type:`button`,size:`sm`,variant:`outline`,disabled:g,onClick:()=>n(e.supersededByActiveId),className:`h-7 gap-1 px-2 text-[11px]`,title:`This version is superseded — jump to the active version`,children:[(0,K.jsx)(D,{className:`size-3`}),` Go to active`]}),h&&(0,K.jsxs)(K.Fragment,{children:[h.suggestedAction===`delete`&&(0,K.jsxs)(R,{type:`button`,size:`sm`,variant:`destructive`,disabled:g,onClick:()=>r?.(h.candidateId,e.memory.id),className:`h-7 gap-1 px-2 text-[11px]`,title:`Accept hygiene's deletion suggestion — memory will be forgotten`,children:[(0,K.jsx)(m,{className:`size-3`}),` Accept Deletion`]}),(0,K.jsxs)(R,{type:`button`,size:`sm`,variant:`outline`,disabled:g,onClick:()=>a?.(h.candidateId,e.memory.id),className:`h-7 gap-1 px-2 text-[11px]`,title:`Reject the suggestion — memory stays as-is and may be re-suggested later`,children:[(0,K.jsx)(b,{className:`size-3`}),` Keep`]}),(0,K.jsxs)(R,{type:`button`,size:`sm`,variant:`outline`,disabled:g,onClick:()=>o?.(e.memory.id),className:`h-7 gap-1 px-2 text-[11px]`,title:`Update the memory's content — versioning creates a new active record`,children:[(0,K.jsx)(p,{className:`size-3`}),` Update`]}),s&&(0,K.jsxs)(R,{type:`button`,size:`sm`,variant:`outline`,disabled:g,onClick:()=>s(e.memory.id),className:`h-7 gap-1 border-warning/40 px-2 text-[11px] text-warning hover:bg-warning/10`,title:"Promote to `permanent` — hygiene will never surface this again",children:[(0,K.jsx)(i,{className:`size-3`}),` Mark as Permanent`]})]}),n&&!d&&(0,K.jsxs)(R,{type:`button`,size:`sm`,variant:`ghost`,disabled:g,onClick:()=>n(e.memory.id),className:`h-7 gap-1 px-2 text-[11px] text-muted-foreground hover:text-foreground`,title:`Open the full record in MemoryManager`,children:[(0,K.jsx)(k,{className:`size-3`}),` Show full`]}),l&&(0,K.jsxs)(`span`,{className:`ml-auto flex items-center gap-1 text-[10px] text-muted-foreground`,children:[(0,K.jsx)(se,{className:`size-3 animate-spin`}),` `,l]})]})]})}function it({icon:e,title:t,count:n,matches:r,cursorBoosted:a=!1,...o}){let s=be(r,10);return r.length===0?null:(0,K.jsxs)(`section`,{className:`flex flex-col gap-1.5`,children:[(0,K.jsxs)(`h3`,{className:`flex items-center gap-1.5 px-1 text-[10px] font-semibold uppercase tracking-wide text-muted-foreground`,children:[(0,K.jsx)(e,{className:`size-3`}),(0,K.jsx)(`span`,{children:t}),(0,K.jsxs)(`span`,{className:`font-mono`,children:[`(`,n,`)`]}),a&&(0,K.jsxs)(`span`,{className:`ml-auto flex items-center gap-0.5 font-mono text-[9px] text-primary`,children:[(0,K.jsx)(i,{className:`size-2.5`}),` cursor boost`]})]}),(0,K.jsx)(`div`,{className:`flex flex-col gap-1.5`,children:s.pageItems.map(e=>(0,K.jsx)(rt,{match:e,cursorBoosted:a&&(e.matchedVia===`anchor_symbol`||e.matchedVia===`scope_symbol`),pendingAction:o.pendingActionById.get(e.memory.id),...o},e.memory.id))}),(0,K.jsx)(xe,{page:s.page,pageSize:s.pageSize,totalItems:s.totalItems,onPageChange:s.setPage,compact:!0,itemLabel:`memories`})]})}function at({filePath:e,lineStart:t,lineEnd:n,open:r,onClose:a,onShowMemory:o,onAcceptDeletion:s,onKeep:c,onUpdate:d,onMarkPermanent:f,onRecover:p}){let[m,h]=(0,G.useState)(!1),[g,_]=(0,G.useState)(new Map),{data:ee,loading:v,error:y,refetch:b}=tt({filePath:e,lineStart:t,lineEnd:n,showDeleted:m,autoFetch:r}),x=t!==void 0&&n!==void 0,S=(0,G.useCallback)(async(e,t,n)=>{if(n){_(n=>new Map(n).set(e,t));try{await n(e)}finally{_(t=>{let n=new Map(t);return n.delete(e),n})}}},[]);if((0,G.useEffect)(()=>{h(!1)},[e]),!r)return null;let C=ee,w=C?.totalCount??0;return(0,K.jsxs)(`aside`,{className:`flex h-full min-h-0 w-full flex-col border-l border-border/70 bg-card/15`,"aria-label":`File memory drawer`,"data-file-path":e??``,children:[(0,K.jsxs)(`header`,{className:`flex shrink-0 items-center justify-between gap-2 border-b border-border/60 px-3 py-2`,children:[(0,K.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[10px] uppercase tracking-wide text-muted-foreground`,children:[(0,K.jsx)(A,{className:`size-3`}),(0,K.jsx)(`span`,{className:`truncate font-mono`,title:e??``,children:e??`(no file)`})]}),(0,K.jsxs)(`div`,{className:`mt-0.5 flex items-center gap-2 text-[10px] text-muted-foreground`,children:[(0,K.jsxs)(`span`,{className:`font-mono`,children:[w,` memories`]}),C&&C.reviewPendingCount>0&&(0,K.jsxs)(`span`,{className:`flex items-center gap-0.5 font-mono text-warning`,children:[(0,K.jsx)(u,{className:`size-3`}),C.reviewPendingCount,` pending review`]}),C&&C.supersededCount>0&&(0,K.jsxs)(`span`,{className:`font-mono`,children:[C.supersededCount,` superseded`]})]})]}),(0,K.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1`,children:[(0,K.jsx)(R,{type:`button`,size:`sm`,variant:`ghost`,onClick:()=>b(),disabled:v||!e,className:`h-7 w-7 p-0`,"aria-label":`Refresh`,title:`Re-query for this file`,children:(0,K.jsx)(te,{className:F(`size-3.5`,v&&`animate-spin`)})}),(0,K.jsx)(R,{type:`button`,size:`sm`,variant:`ghost`,onClick:a,className:`h-7 w-7 p-0`,"aria-label":`Close drawer`,title:`Close memory drawer`,children:(0,K.jsx)(l,{className:`size-3.5`})})]})]}),(0,K.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2 border-b border-border/40 bg-background/40 px-3 py-1.5 text-[10px] text-muted-foreground`,children:[(0,K.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-1.5`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:m,onChange:e=>h(e.target.checked),className:`size-3 accent-primary`,disabled:!e,"data-testid":`memory-drawer-show-deleted`}),m?(0,K.jsx)(k,{className:`size-3`}):(0,K.jsx)(ue,{className:`size-3`}),(0,K.jsx)(`span`,{children:`Show recoverable (deleted)`})]}),x&&(0,K.jsxs)(`span`,{className:`ml-auto flex items-center gap-1 font-mono text-[10px] text-primary`,children:[(0,K.jsx)(i,{className:`size-3`}),` lines `,t,`–`,n]})]}),(0,K.jsx)(`div`,{className:`flex-1 min-h-0 overflow-y-auto px-3 py-3`,children:e?v&&!C?(0,K.jsx)(ot,{loading:!0,message:`Loading memories…`}):y?(0,K.jsx)(ot,{tone:`error`,message:`Error: ${y}`}):!C||w===0?(0,K.jsx)(ot,{message:`No memories attached to ${e} yet.`}):(0,K.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,K.jsx)(it,{icon:i,title:`Cursor boost`,count:C.symbolMatches.length,cursorBoosted:x,matches:C.symbolMatches,pendingActionById:g,onShowMemory:o,onAcceptDeletion:(e,t)=>S(t,`accepting…`,()=>s?.(e,t)),onKeep:(e,t)=>S(t,`keeping…`,()=>c?.(e,t)),onUpdate:e=>S(e,`updating…`,()=>d?.(e)),onMarkPermanent:e=>S(e,`marking…`,()=>f?.(e)),onRecover:e=>S(e,`recovering…`,()=>p?.(e))}),(0,K.jsx)(it,{icon:A,title:`File-scoped`,count:C.primaryMatches.length,matches:C.primaryMatches,pendingActionById:g,onShowMemory:o,onAcceptDeletion:(e,t)=>S(t,`accepting…`,()=>s?.(e,t)),onKeep:(e,t)=>S(t,`keeping…`,()=>c?.(e,t)),onUpdate:e=>S(e,`updating…`,()=>d?.(e)),onMarkPermanent:e=>S(e,`marking…`,()=>f?.(e)),onRecover:e=>S(e,`recovering…`,()=>p?.(e))}),(0,K.jsx)(it,{icon:k,title:`Mentioned in`,count:C.relatedMatches.length,matches:C.relatedMatches,pendingActionById:g,onShowMemory:o,onAcceptDeletion:(e,t)=>S(t,`accepting…`,()=>s?.(e,t)),onKeep:(e,t)=>S(t,`keeping…`,()=>c?.(e,t)),onUpdate:e=>S(e,`updating…`,()=>d?.(e)),onMarkPermanent:e=>S(e,`marking…`,()=>f?.(e)),onRecover:e=>S(e,`recovering…`,()=>p?.(e))})]}):(0,K.jsx)(ot,{message:`Open a file to see its memories.`})})]})}function ot({message:e,loading:t=!1,tone:n=`default`}){return(0,K.jsxs)(`div`,{className:F(`flex min-h-[120px] flex-col items-center justify-center gap-2 rounded-md border border-dashed border-border/60 px-4 py-6 text-center text-[11px]`,n===`error`?`text-destructive`:`text-muted-foreground`),children:[t&&(0,K.jsx)(se,{className:`size-4 animate-spin`}),(0,K.jsx)(`p`,{children:e})]})}function st({mode:e,draft:t,busy:n,error:r,onChange:i,onCancel:a,onSubmit:o}){let s=(0,G.useRef)(null),[c,l]=(0,G.useState)([]);(0,G.useEffect)(()=>{s.current?.focus();let e=new AbortController;return Ce(`agent-roster.list`,{},e.signal).then(e=>{let t=e.roles;Array.isArray(t)&&l(t.filter(e=>typeof e==`string`))}).catch(()=>void 0),()=>e.abort()},[]);let f=(e,n)=>{i({...t,[e]:n})},m=()=>{f(`anchors`,[...t.anchors,{type:`file`,path:``}])};return(0,K.jsxs)(`form`,{className:`flex min-h-0 flex-1 flex-col`,onSubmit:e=>{e.preventDefault(),o()},"aria-busy":n,children:[(0,K.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 border-b border-border/70 bg-card/70 px-4 py-3 backdrop-blur-xl`,children:[(0,K.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,K.jsx)(`span`,{className:`flex size-8 items-center justify-center border border-info/35 bg-info/10 text-info`,children:e===`create`?(0,K.jsx)(p,{className:`size-4`}):(0,K.jsx)(d,{className:`size-4`})}),(0,K.jsxs)(`div`,{className:`min-w-0`,children:[(0,K.jsx)(`p`,{className:`truncate text-sm font-bold`,children:e===`create`?`Capture a memory`:`Edit memory`}),(0,K.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,children:e===`create`?`Add durable knowledge with retrieval metadata.`:`Update content without losing provenance.`})]})]}),(0,K.jsxs)(`div`,{className:`ml-auto flex items-center gap-2`,children:[(0,K.jsxs)(R,{type:`button`,variant:`ghost`,size:`sm`,onClick:a,disabled:n,children:[(0,K.jsx)(b,{className:`size-3.5`}),` Cancel`]}),(0,K.jsxs)(R,{type:`submit`,size:`sm`,disabled:n||!t.text.trim(),children:[n?(0,K.jsx)(se,{className:`size-3.5 animate-spin`}):e===`create`?(0,K.jsx)(fe,{className:`size-3.5`}):(0,K.jsx)(y,{className:`size-3.5`}),n?`Saving…`:e===`create`?`Create memory`:`Save changes`]})]})]}),(0,K.jsx)(`div`,{className:`flex-1 min-h-0 overflow-y-auto overscroll-contain p-4 md:p-5`,children:(0,K.jsxs)(`div`,{className:`mx-auto max-w-4xl space-y-5`,children:[r&&(0,K.jsxs)(`div`,{role:`alert`,className:`flex items-start gap-2 border border-destructive/40 bg-destructive/10 px-3 py-2.5 text-sm text-destructive`,children:[(0,K.jsx)(u,{className:`mt-0.5 size-4 shrink-0`}),(0,K.jsx)(`span`,{children:r})]}),(0,K.jsxs)(`section`,{className:`border border-border/75 bg-card/45 p-4`,children:[(0,K.jsxs)(`div`,{className:`mb-3 flex items-center justify-between gap-3`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h3`,{className:`text-xs font-bold uppercase tracking-[0.14em]`,children:`Knowledge`}),(0,K.jsx)(`p`,{className:`mt-1 text-[10px] text-muted-foreground`,children:`Write the durable fact or decision in complete, searchable language.`})]}),(0,K.jsxs)(`span`,{className:`font-mono text-[10px] text-muted-foreground tabular-nums`,children:[t.text.length,` chars`]})]}),(0,K.jsx)(`label`,{htmlFor:`memory-text`,className:`sr-only`,children:`Memory content`}),(0,K.jsx)(`textarea`,{ref:s,id:`memory-text`,value:t.text,onChange:e=>f(`text`,e.target.value),rows:7,required:!0,placeholder:`Example: WebUI state is owned by Zustand stores; server messages update those stores through singleton WebSocket handlers.`,className:`min-h-36 w-full resize-y border border-input bg-background/75 px-3 py-3 text-sm leading-6 text-foreground shadow-inner placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring`})]}),(0,K.jsxs)(`section`,{className:`grid gap-3 sm:grid-cols-2 lg:grid-cols-3`,children:[(0,K.jsxs)(`div`,{className:`min-w-0`,children:[(0,K.jsx)(`label`,{htmlFor:`memory-kind`,className:`mb-1.5 block text-[10px] font-bold uppercase tracking-[0.14em] text-muted-foreground`,children:`Kind`}),(0,K.jsx)(`select`,{id:`memory-kind`,value:t.kind,onChange:e=>f(`kind`,e.target.value),className:`h-10 w-full border border-input bg-background px-3 text-sm`,children:V.map(e=>(0,K.jsx)(`option`,{value:e,children:Pe[e]},e))})]}),e===`create`?(0,K.jsxs)(`div`,{className:`min-w-0`,children:[(0,K.jsx)(`label`,{htmlFor:`memory-scope`,className:`mb-1.5 block text-[10px] font-bold uppercase tracking-[0.14em] text-muted-foreground`,children:`Scope`}),(0,K.jsx)(`select`,{id:`memory-scope`,value:t.scope,onChange:e=>f(`scope`,e.target.value),className:`h-10 w-full border border-input bg-background px-3 text-sm`,children:Te.map(e=>(0,K.jsx)(`option`,{value:e,children:e},e))})]}):(0,K.jsxs)(`div`,{className:`min-w-0`,children:[(0,K.jsx)(`label`,{htmlFor:`memory-status`,className:`mb-1.5 block text-[10px] font-bold uppercase tracking-[0.14em] text-muted-foreground`,children:`Lifecycle status`}),(0,K.jsx)(`select`,{id:`memory-status`,value:t.status,onChange:e=>f(`status`,e.target.value),className:`h-10 w-full border border-input bg-background px-3 text-sm`,children:je.map(e=>(0,K.jsx)(`option`,{value:e,children:e},e))})]}),(0,K.jsxs)(`div`,{className:F(`min-w-0`,e===`create`?`sm:col-span-2 lg:col-span-1`:``),children:[(0,K.jsx)(`label`,{htmlFor:`memory-tags`,className:`mb-1.5 block text-[10px] font-bold uppercase tracking-[0.14em] text-muted-foreground`,children:`Tags`}),(0,K.jsx)(z,{id:`memory-tags`,value:t.tags,onChange:e=>f(`tags`,e.target.value),placeholder:`architecture, webui, workflow`,className:`h-10 bg-background`})]})]}),(0,K.jsxs)(`section`,{className:`grid gap-3 sm:grid-cols-3`,children:[(0,K.jsx)(De,{id:`memory-importance`,label:`Importance`,value:t.importance,onChange:e=>f(`importance`,e)}),(0,K.jsx)(De,{id:`memory-confidence`,label:`Confidence`,value:t.confidence,onChange:e=>f(`confidence`,e)}),(0,K.jsx)(De,{id:`memory-freshness`,label:`Freshness`,value:t.freshness,onChange:e=>f(`freshness`,e)})]}),(0,K.jsxs)(`section`,{className:`border border-border/75 bg-card/45 p-4`,children:[(0,K.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h3`,{className:`text-xs font-bold uppercase tracking-[0.14em]`,children:`Anchors`}),(0,K.jsx)(`p`,{className:`mt-1 text-[10px] text-muted-foreground`,children:`Bind knowledge to files, symbols, packages, tests, Git paths, or commands.`})]}),(0,K.jsxs)(R,{type:`button`,variant:`outline`,size:`sm`,onClick:m,children:[(0,K.jsx)(fe,{className:`size-3.5`}),` Add anchor`]})]}),t.anchors.length===0?(0,K.jsxs)(`button`,{type:`button`,onClick:m,className:`mt-4 flex w-full items-center justify-center gap-2 border border-dashed border-border px-4 py-7 text-xs text-muted-foreground transition-colors hover:border-info/50 hover:bg-info/5 hover:text-info`,children:[(0,K.jsx)(ie,{className:`size-4`}),` No anchors yet — add one to improve retrieval precision`]}):(0,K.jsx)(`div`,{className:`mt-4 space-y-2`,children:t.anchors.map((e,n)=>(0,K.jsxs)(`div`,{className:`grid gap-2 border border-border/65 bg-background/40 p-2 sm:grid-cols-[9rem_minmax(0,1fr)_auto]`,children:[(0,K.jsxs)(`label`,{className:`sr-only`,htmlFor:`anchor-type-${n}`,children:[`Anchor `,n+1,` type`]}),(0,K.jsx)(`select`,{id:`anchor-type-${n}`,value:e.type,onChange:e=>{let r=e.target.value,i=r===`command`?{type:r,command:``}:r===`agent`?{type:r,role:``}:{type:r,path:``},a=t.anchors.map((e,t)=>t===n?i:e);f(`anchors`,a)},className:`h-10 border border-input bg-background px-2 text-xs`,children:Ie.map(e=>(0,K.jsx)(`option`,{value:e,children:e},e))}),(0,K.jsxs)(`div`,{className:F(`grid min-w-0 gap-2`,e.type===`symbol`&&`sm:grid-cols-[minmax(0,1fr)_11rem]`),children:[(0,K.jsxs)(`label`,{className:`sr-only`,htmlFor:`anchor-value-${n}`,children:[`Anchor `,n+1,` value`]}),(0,K.jsx)(z,{id:`anchor-value-${n}`,list:e.type===`agent`?`memory-agent-role-options`:void 0,value:Le(e),onChange:e=>{let r=t.anchors.map((t,r)=>r===n?Ee(t,e.target.value):t);f(`anchors`,r)},placeholder:e.type===`command`?`pnpm test --filter webui`:e.type===`agent`?`reviewer`:`packages/webui/src/App.tsx`,className:`h-10 min-w-0 bg-background font-mono text-xs`}),e.type===`symbol`&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`label`,{className:`sr-only`,htmlFor:`anchor-symbol-${n}`,children:[`Anchor `,n+1,` symbol`]}),(0,K.jsx)(z,{id:`anchor-symbol-${n}`,value:e.symbol??``,onChange:e=>{let r=t.anchors.map((t,r)=>r===n?{...t,symbol:e.target.value}:t);f(`anchors`,r)},placeholder:`Symbol name`,className:`h-10 bg-background font-mono text-xs`})]})]}),(0,K.jsx)(R,{type:`button`,variant:`ghost`,size:`icon`,"aria-label":`Remove anchor ${n+1}`,onClick:()=>f(`anchors`,t.anchors.filter((e,t)=>t!==n)),children:(0,K.jsx)(T,{className:`size-4 text-destructive`})})]},`${e.type}:${n}`))}),(0,K.jsx)(`datalist`,{id:`memory-agent-role-options`,children:c.map(e=>(0,K.jsx)(`option`,{value:e},e))})]}),(0,K.jsxs)(`section`,{className:`grid gap-3 border border-border/75 bg-card/45 p-4 sm:grid-cols-2`,children:[(0,K.jsxs)(`div`,{className:`sm:col-span-2`,children:[(0,K.jsx)(`h3`,{className:`text-xs font-bold uppercase tracking-[0.14em]`,children:`Relationships`}),(0,K.jsx)(`p`,{className:`mt-1 text-[10px] text-muted-foreground`,children:`Reference exact memory IDs. Relationships are validated and graph edges are rebuilt by SAGE.`})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{htmlFor:`memory-supersedes`,className:`mb-1.5 block text-[10px] font-bold uppercase tracking-[0.14em] text-muted-foreground`,children:`Supersedes`}),(0,K.jsx)(z,{id:`memory-supersedes`,value:t.supersedes,onChange:e=>f(`supersedes`,e.target.value),placeholder:`mem_id, mem_id`,className:`h-10 bg-background font-mono text-xs`})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{htmlFor:`memory-contradicts`,className:`mb-1.5 block text-[10px] font-bold uppercase tracking-[0.14em] text-muted-foreground`,children:`Contradicts`}),(0,K.jsx)(z,{id:`memory-contradicts`,value:t.contradicts,onChange:e=>f(`contradicts`,e.target.value),placeholder:`mem_id, mem_id`,className:`h-10 bg-background font-mono text-xs`})]})]}),(0,K.jsxs)(`section`,{className:`space-y-2`,children:[(0,K.jsx)(`h3`,{className:`text-[10px] font-bold uppercase tracking-[0.14em] text-muted-foreground`,children:`Audience (Optional)`}),(0,K.jsx)(`p`,{className:`text-[10px] text-muted-foreground/70`,children:`Target this memory to specific agent types. Leave empty for general project memory.`}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{htmlFor:`memory-audience-roles`,className:`mb-1.5 block text-[10px] font-bold uppercase tracking-[0.14em] text-muted-foreground`,children:`Roles`}),(0,K.jsx)(z,{id:`memory-audience-roles`,value:t.audienceRoles,onChange:e=>f(`audienceRoles`,e.target.value),placeholder:`reviewer, refactor-planner`,className:`h-9 bg-background font-mono text-xs`})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{htmlFor:`memory-audience-task-types`,className:`mb-1.5 block text-[10px] font-bold uppercase tracking-[0.14em] text-muted-foreground`,children:`Task types`}),(0,K.jsx)(z,{id:`memory-audience-task-types`,value:t.audienceTaskTypes,onChange:e=>f(`audienceTaskTypes`,e.target.value),placeholder:`review, refactor, bugfix`,className:`h-9 bg-background font-mono text-xs`})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{htmlFor:`memory-audience-modes`,className:`mb-1.5 block text-[10px] font-bold uppercase tracking-[0.14em] text-muted-foreground`,children:`Modes`}),(0,K.jsx)(z,{id:`memory-audience-modes`,value:t.audienceModes,onChange:e=>f(`audienceModes`,e.target.value),placeholder:`teach, code-review`,className:`h-9 bg-background font-mono text-xs`})]})]})]})})]})}function ct({searchQuery:e,statusFilter:t,kindFilter:n,audienceOnly:r,tagFilter:i,hasFilters:o,allTags:c,stats:l,onSearchChange:u,onStatusFilterChange:d,onKindFilterChange:f,onToggleAudienceOnly:p,onTagFilterChange:m,onClearFilters:g}){let[_,ee]=(0,G.useState)(!!i),y=_||!!i,x=c.length>0;return(0,K.jsxs)(`div`,{className:`shrink-0 space-y-2 overflow-hidden border-b border-border/70 bg-card/45 p-3`,children:[(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsxs)(`div`,{className:`relative min-w-0 flex-1`,children:[(0,K.jsx)(v,{className:`pointer-events-none absolute left-3 top-1/2 size-3.5 -translate-y-1/2 text-muted-foreground`}),(0,K.jsx)(z,{"aria-label":`Search memories`,value:e,onChange:e=>u(e.target.value),placeholder:`Search content, IDs, tags, anchors…`,className:`h-10 min-w-0 bg-background pl-9 pr-8 text-xs`}),e&&(0,K.jsx)(`button`,{type:`button`,"aria-label":`Clear search`,onClick:()=>u(``),className:`absolute right-2 top-1/2 -translate-y-1/2 p-1 text-muted-foreground hover:text-foreground`,children:(0,K.jsx)(b,{className:`size-3.5`})})]}),(0,K.jsx)(R,{variant:r?`default`:`ghost`,size:`icon`,onClick:p,"aria-label":`Filter audience-scoped only`,title:`Show only audience-scoped memories`,className:`shrink-0`,children:(0,K.jsx)(j,{className:`size-4`})}),o&&(0,K.jsx)(R,{variant:`ghost`,size:`icon`,onClick:g,"aria-label":`Clear all filters`,title:`Clear all filters`,children:(0,K.jsx)(s,{className:`size-4`})})]}),(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,K.jsx)(`label`,{className:`sr-only`,htmlFor:`memory-status-filter`,children:`Filter by status`}),(0,K.jsxs)(`select`,{id:`memory-status-filter`,value:t,onChange:e=>d(e.target.value),className:`h-9 min-w-0 border border-input bg-background px-2 text-xs`,children:[(0,K.jsx)(`option`,{value:`all`,children:`All statuses`}),Me.map(e=>(0,K.jsxs)(`option`,{value:e,children:[e,` · `,l?.byStatus[e]??0]},e))]}),(0,K.jsx)(`label`,{className:`sr-only`,htmlFor:`memory-kind-filter`,children:`Filter by kind`}),(0,K.jsxs)(`select`,{id:`memory-kind-filter`,value:n,onChange:e=>f(e.target.value),className:`h-9 min-w-0 border border-input bg-background px-2 text-xs`,children:[(0,K.jsx)(`option`,{value:`all`,children:`All kinds`}),V.map(e=>(0,K.jsxs)(`option`,{value:e,children:[Pe[e],` · `,l?.byKind[e]??0]},e))]})]}),x&&(0,K.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,K.jsxs)(`button`,{type:`button`,onClick:()=>{i||ee(e=>!e)},"aria-expanded":y,"aria-controls":`memory-tags-panel`,disabled:!!i,className:F(`flex items-center gap-1.5 px-1 py-0.5 text-[10px] uppercase tracking-wide transition-colors`,y?`text-foreground`:`text-muted-foreground hover:text-foreground`,!!i&&`cursor-default`),title:i?`Active filter: ${i} (click the chip to clear)`:y?`Hide tag filters`:`Show tag filters (${c.length})`,children:[(0,K.jsx)(h,{className:F(`size-3 transition-transform`,!y&&`-rotate-90`)}),(0,K.jsx)(a,{className:`size-3`}),(0,K.jsx)(`span`,{className:`font-semibold`,children:`Tags`}),(0,K.jsx)(`span`,{className:`font-mono text-[9px] text-muted-foreground`,children:c.length})]}),i&&(0,K.jsx)(`span`,{role:`status`,"aria-label":`Active tag filter: ${i}`,className:`border border-info/55 bg-info/10 px-1 font-mono text-[9px] uppercase text-info`,children:i})]}),x&&y&&(0,K.jsxs)(`fieldset`,{id:`memory-tags-panel`,className:`min-w-0 border-0 p-0`,children:[(0,K.jsx)(`legend`,{className:`sr-only`,children:`Popular tags`}),(0,K.jsx)(`div`,{className:`no-scrollbar flex gap-1.5 overflow-x-auto pb-0.5`,children:c.slice(0,18).map(([e,t])=>(0,K.jsxs)(`button`,{type:`button`,"aria-pressed":i===e,onClick:()=>m(i===e?null:e),className:F(`flex shrink-0 items-center gap-1 border px-2 py-1 text-[10px] transition-colors`,i===e?`border-info/55 bg-info/10 text-info`:`border-border/70 bg-background/45 text-muted-foreground hover:border-info/35 hover:text-foreground`),children:[(0,K.jsx)(a,{className:`size-2.5`}),` `,e,(0,K.jsx)(`span`,{className:`font-mono opacity-60`,children:t})]},e))})]})]})}var lt=100;function ut({memoryListRef:e,memories:t,filteredMemories:n,selectedId:r,onSelectMemory:i,onOpenCreate:a,onClearFilters:o}){let s=n.length>lt,c=oe({count:n.length,getScrollElement:()=>e.current,estimateSize:()=>100,overscan:8,enabled:s});return(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`div`,{className:`flex shrink-0 items-center justify-between border-b border-border/60 px-3 py-2 text-[10px] text-muted-foreground`,children:[(0,K.jsxs)(`span`,{children:[n.length,` of `,t.length,` memories`]}),(0,K.jsx)(`span`,{className:`font-mono uppercase`,children:`updated ↓`})]}),(0,K.jsx)(`section`,{ref:e,className:`min-h-0 flex-1 overflow-y-auto overscroll-contain`,"aria-label":`Memories`,children:n.length===0?(0,K.jsx)(dt,{hasMemories:t.length>0,onOpenCreate:a,onClearFilters:o}):s?(0,K.jsx)(`div`,{style:{height:`${c.getTotalSize()}px`,width:`100%`,position:`relative`},children:c.getVirtualItems().map(e=>{let t=n[e.index];return t?(0,K.jsx)(`div`,{"data-index":e.index,ref:c.measureElement,style:{position:`absolute`,top:0,left:0,width:`100%`,transform:`translateY(${e.start}px)`},children:(0,K.jsx)(ft,{memory:t,isSelected:r===t.id,onClick:()=>i(t.id)})},t.id):null})}):n.map(e=>(0,K.jsx)(ft,{memory:e,isSelected:r===e.id,onClick:()=>i(e.id)},e.id))})]})}function dt({hasMemories:e,onOpenCreate:t,onClearFilters:n}){return(0,K.jsxs)(`div`,{className:`flex min-h-64 flex-col items-center justify-center px-6 text-center`,children:[(0,K.jsx)(`span`,{className:`flex size-12 items-center justify-center border border-dashed border-border text-muted-foreground`,children:(0,K.jsx)(S,{className:`size-5`})}),(0,K.jsx)(`h2`,{className:`mt-4 text-sm font-bold`,children:e?`No matching memories`:`Build your memory graph`}),(0,K.jsx)(`p`,{className:`mt-1 max-w-xs text-xs leading-5 text-muted-foreground`,children:e?`Change the filters or clear the search query.`:`Capture durable facts, decisions, conventions, and file-bound notes for every agent.`}),(0,K.jsxs)(R,{className:`mt-4`,variant:`outline`,size:`sm`,onClick:e?n:t,children:[e?(0,K.jsx)(s,{className:`size-3.5`}):(0,K.jsx)(fe,{className:`size-3.5`}),e?`Clear filters`:`Create first memory`]})]})}function ft({memory:e,isSelected:t,onClick:n}){return(0,K.jsxs)(`button`,{type:`button`,"aria-current":t?`true`:void 0,onClick:n,className:F(`group relative block w-full border-b border-border/55 px-3 py-3 text-left transition-[background-color,border-color] hover:bg-info/5`,t&&`bg-info/8`),children:[t&&(0,K.jsx)(`span`,{className:`absolute inset-y-0 left-0 w-0.5 bg-info shadow-[0_0_10px_hsl(var(--info)/0.7)]`}),(0,K.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,K.jsx)(`span`,{className:F(`truncate text-[10px] font-bold uppercase tracking-[0.1em]`,Ae(e.kind)),children:Pe[e.kind]??e.kind}),(0,K.jsx)(H,{status:e.status}),(0,K.jsxs)(`span`,{className:`ml-auto shrink-0 font-mono text-[9px] text-muted-foreground`,children:[`r`,e.revision]})]}),(0,K.jsx)(`p`,{className:F(`mt-2 line-clamp-2 text-xs leading-5 text-foreground/90`,e.status===`deleted`&&`line-through opacity-60`),children:B(e.text)}),(0,K.jsxs)(`div`,{className:`mt-2 flex min-w-0 items-center gap-1.5`,children:[(0,K.jsx)(`span`,{className:`border border-border/60 bg-background/50 px-1.5 py-0.5 font-mono text-[9px] uppercase text-muted-foreground`,children:e.scope}),e.audience&&(0,K.jsxs)(`span`,{className:`flex items-center gap-0.5 border border-primary/30 bg-primary/10 px-1.5 py-0.5 font-mono text-[9px] text-primary`,children:[(0,K.jsx)(j,{className:`size-2.5`}),(e.audience.roles??e.audience.taskTypes??e.audience.modes??[]).slice(0,1)[0]??`scoped`]}),e.tags.slice(0,2).map(e=>(0,K.jsxs)(`span`,{className:`max-w-24 truncate border border-border/60 px-1.5 py-0.5 font-mono text-[9px] text-muted-foreground`,children:[`#`,e]},e)),e.tags.length>2&&(0,K.jsxs)(`span`,{className:`font-mono text-[9px] text-muted-foreground`,children:[`+`,e.tags.length-2]}),(0,K.jsx)(`span`,{className:`ml-auto shrink-0 text-[9px] text-muted-foreground`,children:Re(e.updatedAt)}),(0,K.jsx)(ce,{className:`size-3 shrink-0 text-muted-foreground transition-transform group-hover:translate-x-0.5 group-hover:text-info`})]})]})}function pt({busyAction:e,deletingId:t,memories:n,onCancel:r,onConfirm:i,onOpenChange:a}){return(0,K.jsx)(L,{open:!!t,onOpenChange:a,children:(0,K.jsxs)(ve,{className:`max-w-md`,children:[(0,K.jsxs)(ge,{children:[(0,K.jsx)(`span`,{className:`mb-2 flex size-10 items-center justify-center border border-destructive/35 bg-destructive/10 text-destructive`,children:(0,K.jsx)(T,{className:`size-4`})}),(0,K.jsx)(ye,{children:`Delete this memory?`}),(0,K.jsx)(I,{className:`leading-6`,children:`SAGE will mark the record deleted, remove graph edges, and clean references from related memories. The record remains in the audit trail but cannot be restored from this page.`})]}),(0,K.jsx)(`div`,{className:`border border-border/70 bg-background/45 p-3 text-xs text-muted-foreground`,children:B(n.find(e=>e.id===t)?.text??``,180)}),(0,K.jsxs)(_e,{children:[(0,K.jsx)(R,{variant:`outline`,onClick:r,disabled:e===`delete`,children:`Cancel`}),(0,K.jsxs)(R,{variant:`destructive`,onClick:i,disabled:e===`delete`,children:[e===`delete`?(0,K.jsx)(se,{className:`size-4 animate-spin`}):(0,K.jsx)(T,{className:`size-4`}),e===`delete`?`Deleting…`:`Delete memory`]})]})]})})}function mt({onCapture:e}){return(0,K.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col items-center justify-center p-8 text-center`,children:[(0,K.jsxs)(`div`,{className:`relative flex size-20 items-center justify-center border border-info/25 bg-info/5 text-info`,children:[(0,K.jsx)(j,{className:`size-8`}),(0,K.jsx)(`span`,{className:`absolute inset-2 border border-info/10`})]}),(0,K.jsx)(`h2`,{className:`mt-5 text-lg font-bold`,children:`Your project’s long-term context`}),(0,K.jsx)(`p`,{className:`mt-2 max-w-md text-sm leading-6 text-muted-foreground`,children:`Select a memory to inspect its metadata and relationship graph, or capture knowledge that future agents should retrieve automatically.`}),(0,K.jsxs)(`div`,{className:`mt-6 grid w-full max-w-lg gap-2 sm:grid-cols-3`,children:[(0,K.jsxs)(`div`,{className:`border border-border/70 bg-card/45 p-3`,children:[(0,K.jsx)(m,{className:`mx-auto size-4 text-success`}),(0,K.jsx)(`p`,{className:`mt-2 text-[10px] font-bold uppercase`,children:`Verified anchors`})]}),(0,K.jsxs)(`div`,{className:`border border-border/70 bg-card/45 p-3`,children:[(0,K.jsx)(j,{className:`mx-auto size-4 text-info`}),(0,K.jsx)(`p`,{className:`mt-2 text-[10px] font-bold uppercase`,children:`Typed relations`})]}),(0,K.jsxs)(`div`,{className:`border border-border/70 bg-card/45 p-3`,children:[(0,K.jsx)(fe,{className:`mx-auto size-4 text-warning`}),(0,K.jsx)(`p`,{className:`mt-2 text-[10px] font-bold uppercase`,children:`Agent recall`})]})]}),(0,K.jsxs)(R,{onClick:e,children:[(0,K.jsx)(fe,{className:`size-4`}),` Capture memory`]})]})}function ht(e,t){let n=t.searchQuery.trim().toLowerCase();return e.filter(e=>{if(t.statusFilter!==`all`&&e.status!==t.statusFilter||t.kindFilter!==`all`&&e.kind!==t.kindFilter||t.tagFilter&&!e.tags.includes(t.tagFilter)||t.audienceOnly&&!e.audience)return!1;if(!n)return!0;let r=e.anchors.map(e=>[e.path,e.symbol,e.command,e.role].filter(Boolean).join(` `)).join(` `),i=e.audience?[e.audience.roles?.join(` `)??``,e.audience.taskTypes?.join(` `)??``,e.audience.modes?.join(` `)??``].join(` `):``;return[e.id,e.text,e.summary??``,e.kind,e.scope,e.tags.join(` `),r,i].join(` `).toLowerCase().includes(n)})}function gt(e){let t=new Map;for(let n of e)for(let e of n.tags)t.set(e,(t.get(e)??0)+1);return[...t.entries()].sort((e,t)=>t[1]-e[1]||e[0].localeCompare(t[0]))}function _t(e){if(!e)return[];let t=[];e.supersededBy&&t.push({relation:`Superseded by`,id:e.supersededBy});for(let n of e.supersedes??[])t.push({relation:`Supersedes`,id:n});for(let n of e.contradicts??[])t.push({relation:`Contradicts`,id:n});return t}function vt(){let{client:e,listSageMemoriesPage:n,rememberSage:r,updateSage:i,deleteSage:a,getSageGraph:o,recoverSage:s,resolveMemoryCandidate:c}=me(),l=he(e=>e.wsConnected),d=pe(e=>e.setCurrentView),f=Se(`memory`),[p,h]=(0,G.useState)([]),[g,_]=(0,G.useState)(null),[ee,v]=(0,G.useState)(!0),[y,b]=(0,G.useState)(!1),[x,S]=(0,G.useState)(null),[C,w]=(0,G.useState)(null),[T,E]=(0,G.useState)(null),[D,O]=(0,G.useState)(null),[re,ie]=(0,G.useState)([]),[ae,oe]=(0,G.useState)([]),[se,k]=(0,G.useState)(null),[ce,A]=(0,G.useState)(!1),[le,M]=(0,G.useState)(!1),[N,ue]=(0,G.useState)(!1),[P,ge]=(0,G.useState)(ke),[_e,ve]=(0,G.useState)(ke),[ye,I]=(0,G.useState)(null),[L,z]=(0,G.useState)(null),[be,xe]=(0,G.useState)(``),[Ce,Te]=(0,G.useState)(`all`),[Ee,De]=(0,G.useState)(`all`),[B,Ae]=(0,G.useState)(!1),[V,H]=(0,G.useState)(null),[U,je]=(0,G.useState)(!1),[Me,Ne]=(0,G.useState)(null),[Pe,Ie]=(0,G.useState)(!1),[Le,Re]=(0,G.useState)(!1),[ze,Be]=(0,G.useState)({}),[Ve,He]=(0,G.useState)(!1),[Ue,We]=(0,G.useState)(null),[Ge,Ke]=(0,G.useState)(void 0),[qe,Je]=(0,G.useState)(void 0),Ye=(0,G.useRef)(!1),q=(0,G.useRef)(!0),Ze=(0,G.useRef)(0),J=(0,G.useRef)(0),Qe=(0,G.useRef)(null),Y=(0,G.useRef)(null),$e=(0,G.useMemo)(()=>JSON.stringify(P)!==JSON.stringify(_e),[_e,P]),X=(0,G.useMemo)(()=>p.find(e=>e.id===D)??null,[p,D]),et=(0,G.useCallback)(t=>{let r=t!==null,i=++Ze.current;Qe.current?.(),S(null),r?Re(!0):(b(!0),Ye.current||v(!0));let a=()=>{},o=null,s=!1,c=()=>{s||(s=!0,o!==null&&clearTimeout(o),a(),Qe.current===c&&(Qe.current=null))};a=e.on(`memory.sage.listPage`,e=>{if(i!==Ze.current||!q.current){c();return}if(c(),e.payload.error)S(e.payload.error);else{let t=e.payload.memories??[];h(e=>r?[...e,...t]:t),Ne(e.payload.nextCursor??null),Ie(!!e.payload.nextCursor);let n=e.payload.statusCounts??{};Be(n);let i=Object.values(n).reduce((e,t)=>e+t,0);e.payload.stats?_(e.payload.stats):_(e=>({total:i,byStatus:n,byKind:e?.byKind??{},edges:e?.edges??0})),Ye.current=!0,r||O(e=>e&&t.some(t=>t.id===e)?e:null)}v(!1),b(!1),Re(!1)}),o=setTimeout(()=>{i!==Ze.current||!q.current||(c(),S(`The memory store did not respond. Check the WebSocket connection and try again.`),v(!1),b(!1),Re(!1))},2e4),Qe.current=c,n({limit:100,...U?{statuses:[`deleted`]}:{},...t?{cursor:t}:{}},{echoToChat:!1})},[e,n,U]),Z=(0,G.useCallback)(()=>{Ne(null),Ie(!1),et(null)},[et]),tt=(0,G.useCallback)(()=>{Le||!Me||et(Me)},[et,Le,Me]);(0,G.useEffect)(()=>(q.current=!0,Z(),()=>{q.current=!1,Ze.current+=1,J.current+=1,Qe.current?.(),Y.current?.()}),[Z]),(0,G.useEffect)(()=>{if(ie([]),oe([]),k(null),!D){A(!1);return}let t=D;A(!0);let n=null,r=e.on(`memory.sage.graph`,e=>{e.payload.query===t&&(n!==null&&clearTimeout(n),ie(e.payload.edges??[]),oe(e.payload.memories??[]),k(e.payload.error??null),A(!1))});return n=setTimeout(()=>{k(`Relationship graph did not respond in time.`),A(!1)},15e3),o(t,{maxDepth:1,limit:120},{echoToChat:!1}),()=>{n!==null&&clearTimeout(n),r()}},[e,o,D]);let nt=(0,G.useRef)(l);(0,G.useEffect)(()=>{l&&!nt.current&&Ye.current&&Z(),nt.current=l},[Z,l]),(0,G.useEffect)(()=>{if(!T)return;let e=setTimeout(()=>E(null),4e3);return()=>clearTimeout(e)},[T]);let Q=(0,G.useCallback)(()=>!$e||!le&&!N||window.confirm(`Discard the unsaved memory changes?`),[N,$e,le]),rt=(0,G.useCallback)(()=>{if(!Q())return;let e=ke();ge(e),ve(e),ue(!0),M(!1),O(null),w(null)},[Q]),it=(0,G.useCallback)(e=>{Q()&&(O(e),ue(!1),M(!1),w(null))},[Q]),ot=(0,G.useCallback)(()=>{if(!X||X.status===`deleted`)return;let e=Oe(X);ge(e),ve(e),M(!0),ue(!1),w(null)},[X]),lt=(0,G.useCallback)(()=>{Q()&&(M(!1),ue(!1),w(null))},[Q]),dt=(0,G.useCallback)((t,n,r)=>{if(!P.text.trim()){w(`Memory content is required.`);return}let i=++J.current;Y.current?.(),I(r),w(null),E(null);let a=()=>{},o=null,s=!1,c=()=>{s||(s=!0,o!==null&&clearTimeout(o),a(),Y.current===c&&(Y.current=null))},l=e=>{if(i!==J.current||!q.current){c();return}if(c(),I(null),e.payload.error||!e.payload.memory){w(e.payload.error??`The server returned no memory record.`);return}let t=e.payload.memory;h(e=>{let n=e.filter(e=>e.id!==t.id);return[t,...n]}),O(t.id),ue(!1),M(!1),E(r===`create`?`Memory captured.`:`Memory updated.`),Z()};a=t===`memory.sage.remember`?e.on(`memory.sage.remember`,l):e.on(`memory.sage.update`,l),o=setTimeout(()=>{i!==J.current||!q.current||(c(),I(null),w(`${r===`create`?`Create`:`Save`} timed out. Your draft is still here.`))},2e4),Y.current=c,n()},[e,P.text,Z]),ft=(0,G.useCallback)(()=>{dt(`memory.sage.remember`,()=>r({text:P.text.trim(),kind:P.kind,scope:P.scope,tags:W(P.tags),importance:P.importance,confidence:P.confidence,freshness:P.freshness,anchors:we(P.anchors),...W(P.audienceRoles).length||W(P.audienceTaskTypes).length||W(P.audienceModes).length?{audience:{roles:W(P.audienceRoles),taskTypes:W(P.audienceTaskTypes),modes:W(P.audienceModes)}}:{},supersedes:W(P.supersedes),contradicts:W(P.contradicts)},{echoToChat:!1}),`create`)},[P,r,dt]),vt=(0,G.useCallback)(()=>{X&&dt(`memory.sage.update`,()=>i(X.id,{text:P.text.trim(),kind:P.kind,status:P.status,tags:W(P.tags),importance:P.importance,confidence:P.confidence,freshness:P.freshness,anchors:we(P.anchors),...W(P.audienceRoles).length||W(P.audienceTaskTypes).length||W(P.audienceModes).length?{audience:{roles:W(P.audienceRoles),taskTypes:W(P.audienceTaskTypes),modes:W(P.audienceModes)}}:{},supersedes:W(P.supersedes),contradicts:W(P.contradicts)},{echoToChat:!1}),`update`)},[P,dt,X,i]),yt=(0,G.useCallback)(()=>{if(!L)return;let t=++J.current;Y.current?.(),I(`delete`),w(null);let n=()=>{},r=null,i=!1,o=()=>{i||(i=!0,r!==null&&clearTimeout(r),n(),Y.current===o&&(Y.current=null))};n=e.on(`memory.sage.delete`,e=>{if(t!==J.current||!q.current){o();return}if(o(),I(null),!e.payload.success){w(e.payload.message||`Delete failed.`);return}z(null),O(null),M(!1),E(`Memory deleted and relationship edges cleaned up.`),Z()}),r=setTimeout(()=>{t!==J.current||!q.current||(o(),I(null),w(`Delete timed out. The memory may still exist; refresh to confirm.`))},2e4),Y.current=o,a(L,`Deleted from the WebUI Memory Manager.`)},[e,a,L,Z]),bt=(0,G.useMemo)(()=>ht(p,{searchQuery:be,statusFilter:Ce,kindFilter:Ee,tagFilter:V,audienceOnly:B}),[B,Ee,p,be,Ce,V]),xt=(0,G.useMemo)(()=>gt(p),[p]),St=(0,G.useMemo)(()=>_t(X),[X]),Ct=(0,G.useCallback)(()=>{xe(``),Te(`all`),De(`all`),Ae(!1),H(null)},[]),wt=!!(be||Ce!==`all`||Ee!==`all`||V||B),Tt=N||!!X,$=Ve&&!!Ue;return ee&&p.length===0?(0,K.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col bg-background`,"aria-busy":`true`,children:[(0,K.jsxs)(`div`,{className:`border-b border-border/70 bg-card/70 px-5 py-4`,children:[(0,K.jsx)(`div`,{className:`h-3 w-28 animate-pulse bg-muted`}),(0,K.jsx)(`div`,{className:`mt-3 h-7 w-56 animate-pulse bg-muted`})]}),(0,K.jsxs)(`div`,{className:`grid flex-1 gap-px bg-border/60 md:grid-cols-[minmax(300px,0.82fr)_minmax(0,1.35fr)]`,children:[(0,K.jsx)(`div`,{className:`space-y-px bg-background p-4`,children:Array.from({length:7},(e,t)=>(0,K.jsx)(`div`,{className:`h-24 animate-pulse border border-border/60 bg-card/45`},t))}),(0,K.jsx)(`div`,{className:`hidden bg-background p-6 md:block`,children:(0,K.jsx)(`div`,{className:`h-full animate-pulse border border-border/60 bg-card/35`})})]}),(0,K.jsx)(`span`,{className:`sr-only`,role:`status`,children:`Loading SAGE content`})]}):x&&p.length===0?(0,K.jsx)(`div`,{className:`flex h-full min-h-0 items-center justify-center bg-background p-6`,children:(0,K.jsxs)(`div`,{className:`max-w-md border border-destructive/35 bg-card p-6 shadow-2xl`,children:[(0,K.jsx)(`span`,{className:`flex size-11 items-center justify-center border border-destructive/35 bg-destructive/10 text-destructive`,children:(0,K.jsx)(u,{className:`size-5`})}),(0,K.jsx)(`h2`,{className:`mt-4 text-lg font-bold`,children:`Memory store unavailable`}),(0,K.jsx)(`p`,{className:`mt-2 text-sm leading-6 text-muted-foreground`,children:x}),(0,K.jsxs)(`div`,{className:`mt-5 flex gap-2`,children:[(0,K.jsxs)(R,{onClick:Z,children:[(0,K.jsx)(te,{className:`size-4`}),` Retry`]}),(0,K.jsxs)(R,{variant:`outline`,onClick:()=>d(`chat`),children:[(0,K.jsx)(de,{className:`size-4`}),` Back to chat`]})]})]})}):(0,K.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col overflow-hidden bg-background`,children:[(0,K.jsxs)(`header`,{className:`relative shrink-0 overflow-hidden border-b border-border/70 bg-card/72 px-4 py-3 backdrop-blur-xl sm:px-5`,children:[(0,K.jsx)(`div`,{className:`pointer-events-none absolute inset-y-0 right-0 w-1/2 bg-[radial-gradient(circle_at_right,hsl(var(--info)/0.11),transparent_68%)]`}),(0,K.jsxs)(`div`,{className:`relative flex flex-wrap items-center gap-3`,children:[(0,K.jsx)(R,{variant:`ghost`,size:`icon`,onClick:()=>d(`chat`),"aria-label":`Back to chat`,title:`Back to chat`,children:(0,K.jsx)(de,{className:`size-4`})}),(0,K.jsx)(`span`,{className:`flex size-10 items-center justify-center border border-info/40 bg-info/10 text-info shadow-[0_0_20px_hsl(var(--info)/0.12)]`,children:(0,K.jsx)(j,{className:`size-5`})}),(0,K.jsxs)(`div`,{className:`min-w-0`,children:[(0,K.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,K.jsx)(`h1`,{className:`text-base font-bold sm:text-lg`,children:`SAGE`}),(0,K.jsx)(`span`,{className:`border border-success/35 bg-success/10 px-2 py-0.5 font-mono text-[9px] font-bold uppercase text-success`,children:`project knowledge`})]}),(0,K.jsx)(`p`,{className:`mt-0.5 max-w-2xl text-[10px] text-muted-foreground sm:text-xs`,children:`Inspect, connect, curate, and retire durable context used across agent sessions.`})]}),(0,K.jsxs)(`div`,{className:`ml-auto flex items-center gap-2`,children:[(0,K.jsxs)(`span`,{className:F(`hidden items-center gap-1.5 border px-2 py-1 font-mono text-[9px] uppercase sm:flex`,l?`border-success/30 text-success`:`border-warning/30 text-warning`),children:[(0,K.jsx)(`span`,{className:`size-1.5 bg-current`}),` `,l?`live store`:`reconnecting`]}),(0,K.jsxs)(R,{variant:`outline`,size:`sm`,onClick:Z,disabled:y,"aria-label":`Refresh memories`,children:[(0,K.jsx)(te,{className:F(`size-3.5`,y&&`animate-spin`)}),(0,K.jsx)(`span`,{className:`hidden sm:inline`,children:`Refresh`})]}),(0,K.jsxs)(R,{size:`sm`,onClick:rt,children:[(0,K.jsx)(fe,{className:`size-3.5`}),` New memory`]})]})]})]}),(0,K.jsxs)(`div`,{className:`grid shrink-0 grid-cols-2 gap-px border-b border-border/70 bg-border/60 sm:grid-cols-4`,children:[(0,K.jsx)(Fe,{label:`Memories`,value:g?.total??p.length,hint:`${bt.length} visible`}),(0,K.jsx)(Fe,{label:`Active`,value:g?.byStatus.active??p.filter(e=>e.status===`active`).length,hint:`retrievable`,tone:`success`}),(0,K.jsx)(Fe,{label:`Needs review`,value:(g?.byStatus.stale??0)+(g?.byStatus.contradicted??0),hint:`stale + conflicts`,tone:`warning`}),(0,K.jsx)(`div`,{className:`hidden sm:block`,children:(0,K.jsx)(Fe,{label:`Graph edges`,value:g?.edges??0,hint:`${xt.length} tags`,tone:`info`})})]}),(()=>{let e=p.filter(e=>e.audience).length;if(e===0)return null;let t=new Set;for(let e of p)if(e.audience){for(let n of e.audience.roles??[])t.add(n);for(let n of e.audience.taskTypes??[])t.add(n);for(let n of e.audience.modes??[])t.add(n)}return(0,K.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2 border-b border-border/70 bg-primary/5 px-4 py-1.5`,children:[(0,K.jsx)(j,{className:`size-3.5 text-primary`}),(0,K.jsxs)(`span`,{className:`text-[11px] font-medium text-primary`,children:[e,` audience-scoped memory`,e===1?``:`ies`]}),t.size>0&&(0,K.jsxs)(`span`,{className:`text-[10px] text-muted-foreground`,children:[`(`,[...t].sort().join(`, `),`)`]})]})})(),(T||x||C)&&(0,K.jsxs)(`div`,{className:`shrink-0 border-b border-border/70 px-4 py-2`,"aria-live":`polite`,children:[T&&(0,K.jsxs)(`div`,{role:`status`,className:`flex items-center gap-2 text-xs text-success`,children:[(0,K.jsx)(m,{className:`size-3.5`}),` `,T]}),x&&(0,K.jsxs)(`div`,{role:`alert`,className:`flex items-center gap-2 text-xs text-warning`,children:[(0,K.jsx)(u,{className:`size-3.5`}),` `,x,` Existing content remains available.`]}),C&&!le&&!N&&(0,K.jsxs)(`div`,{role:`alert`,className:`flex items-center gap-2 text-xs text-destructive`,children:[(0,K.jsx)(u,{className:`size-3.5`}),` `,C]})]}),(0,K.jsxs)(`div`,{className:`grid min-h-0 flex-1 md:grid-cols-[minmax(320px,0.82fr)_minmax(0,1.35fr)]`,children:[(0,K.jsxs)(`section`,{className:F(`min-h-0 border-r border-border/70 bg-card/25`,Tt?`hidden md:flex md:flex-col`:`flex flex-col`),"aria-label":`Memory library`,children:[(0,K.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1 border-b border-border/60 px-3 pt-1`,role:`tablist`,"aria-label":`Memory view`,children:[(0,K.jsx)(R,{type:`button`,variant:`ghost`,size:`sm`,role:`tab`,"aria-selected":!U,onClick:()=>{U&&je(!1)},className:F(`h-7 rounded-b-none border-b-2 px-3 text-[11px]`,U?`border-transparent text-muted-foreground`:`border-primary text-foreground`),children:`Active`}),(0,K.jsxs)(R,{type:`button`,variant:`ghost`,size:`sm`,role:`tab`,"aria-selected":U,onClick:()=>{U||je(!0)},className:F(`h-7 rounded-b-none border-b-2 px-3 text-[11px]`,U?`border-primary text-foreground`:`border-transparent text-muted-foreground`),children:[`Deleted`,typeof ze.deleted==`number`?` (${ze.deleted})`:``]})]}),(0,K.jsx)(ct,{searchQuery:be,statusFilter:Ce,kindFilter:Ee,audienceOnly:B,tagFilter:V,hasFilters:wt,allTags:xt,stats:g,onSearchChange:xe,onStatusFilterChange:Te,onKindFilterChange:De,onToggleAudienceOnly:()=>Ae(e=>!e),onTagFilterChange:H,onClearFilters:Ct}),(0,K.jsx)(ut,{memoryListRef:f,memories:p,filteredMemories:bt,selectedId:D,onSelectMemory:it,onOpenCreate:rt,onClearFilters:Ct}),Pe?(0,K.jsx)(`div`,{className:`shrink-0 border-t border-border/60 p-2`,children:(0,K.jsx)(R,{type:`button`,variant:`outline`,size:`sm`,onClick:tt,disabled:Le,className:`h-7 w-full text-[11px]`,children:Le?`Loading…`:`Load more (${p.length} loaded)`})}):null]}),(0,K.jsxs)(`section`,{className:F(`min-h-0 bg-background`,Tt?`flex flex-col`:`hidden md:flex md:flex-col`),"aria-label":`Memory detail`,children:[p.some(e=>(e.anchors??[]).some(e=>e.type===`file`&&e.path))&&(0,K.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2 border-b border-border/60 bg-card/30 px-3 py-1.5`,children:[(0,K.jsx)(`span`,{className:`text-[10px] uppercase tracking-wide text-muted-foreground`,children:`File drawer`}),(0,K.jsxs)(`select`,{value:Ue??``,onChange:e=>{let t=e.target.value||null;We(t),t&&He(!0)},className:`min-w-0 max-w-[260px] flex-1 truncate rounded-sm border border-border/60 bg-background px-1.5 py-0.5 text-[10px] font-mono`,"aria-label":`File for memory drawer`,"data-testid":`memory-drawer-file-select`,children:[(0,K.jsx)(`option`,{value:``,children:`— select a file —`}),p.flatMap(e=>e.anchors??[]).filter(e=>e.type===`file`&&e.path).map((e,t)=>(0,K.jsx)(`option`,{value:e.path,title:e.path,children:e.path},`${e.path}-${t}`))]}),(0,K.jsxs)(R,{type:`button`,size:`sm`,variant:$?`default`:`outline`,onClick:()=>{Ue&&He(e=>!e)},disabled:!Ue,className:`h-7 shrink-0 gap-1 px-2 text-[11px]`,"aria-pressed":$,title:$?`Hide file memory drawer`:`Show file memory drawer`,children:[$?(0,K.jsx)(t,{className:`size-3`}):(0,K.jsx)(ne,{className:`size-3`}),$?`Hide`:`Show`,` drawer`]})]}),N?(0,K.jsx)(st,{mode:`create`,draft:P,busy:ye===`create`,error:C,onChange:ge,onCancel:lt,onSubmit:ft}):X?le?(0,K.jsx)(st,{mode:`edit`,draft:P,busy:ye===`update`,error:C,onChange:ge,onCancel:lt,onSubmit:vt}):$?(0,K.jsx)(at,{filePath:Ue,lineStart:Ge,lineEnd:qe,open:$,onClose:()=>He(!1),onShowMemory:e=>O(e),onAcceptDeletion:async(e,t)=>{c({candidateId:e,action:`accept`}),E(`Accepted hygiene review for ${t.slice(0,12)}… (candidate ${e.slice(0,12)}…).`),setTimeout(()=>{Z()},500)},onKeep:async(e,t)=>{c({candidateId:e,action:`reject`}),E(`Kept ${t.slice(0,12)}… (candidate ${e.slice(0,12)}… rejected).`)},onUpdate:e=>{O(e),ot()},onMarkPermanent:async e=>{I(`update`);try{await i(e,{persistence:`permanent`}),E(`Memory ${e.slice(0,12)}… promoted to permanent.`),await Z()}catch(e){w(e instanceof Error?e.message:String(e))}finally{I(null)}},onRecover:async e=>{s({id:e,reason:`recovered via file drawer`}),E(`Recovered ${e.slice(0,12)}…`),setTimeout(()=>{Z()},500)}}):(0,K.jsx)(Xe,{memory:X,allMemories:[...p,...ae],relatedMemories:St,graphEdges:re,graphLoading:ce,graphError:se,onClose:()=>O(null),onOpenMemory:it,onEdit:ot,onDelete:()=>z(X.id),onTagSelect:e=>{H(e),O(null)},onNotice:E}):(0,K.jsx)(mt,{onCapture:rt})]})]}),(0,K.jsx)(pt,{busyAction:ye,deletingId:L,memories:p,onCancel:()=>z(null),onConfirm:yt,onOpenChange:e=>{!e&&ye!==`delete`&&z(null)}})]})}export{vt as MemoryManager};
@@ -1,4 +0,0 @@
1
- import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{Br as t,Di as n,Er as r,Gr as i,Ia as a,Jn as o,Ln as s,Nt as c,Oa as l,Oi as u,On as d,Pa as f,Sa as p,Ta as m,Ti as h,Tr as g,Ui as _,Vi as v,Vn as y,Vr as b,Vt as x,Xi as S,Xn as C,Xr as w,Yn as T,_ as E,_i as D,a as ee,an as O,c as k,d as A,dt as j,er as te,f as ne,fi as re,h as ie,i as ae,in as oe,ir as M,ja as N,l as se,lt as ce,m as le,mi as ue,mt as de,o as fe,oa as P,on as pe,p as me,pr as he,pt as F,qn as I,r as ge,s as L,ta as _e,u as ve,ut as R,v as ye,wi as z,xt as be,yr as xe,yt as B}from"./vendor-CxV3l5PQ.js";import"./i18n-DxnYsmc-.js";import{s as Se}from"./ws-client-Cy3oRAmZ.js";import{t as V}from"./utils-_s0GyctV.js";import{t as Ce}from"./session-store-BE_S1f5v.js";import{_ as we,c as H,l as Te,x as Ee}from"./stores-BS-Bdi-5.js";import{r as De}from"./mailbox-store-xh2Ux-Xs.js";import{d as Oe}from"./markdown-sSmz-Ua_.js";import{_ as ke,d as Ae,f as je,g as Me,l as Ne,u as Pe,w as Fe}from"./index-Bf75VrDE.js";var U=e(a(),1);function Ie(e){return typeof e==`object`&&e&&!Array.isArray(e)?e:{}}function Le(e){return typeof e==`number`&&Number.isFinite(e)?e:void 0}function W(e){return typeof e==`string`&&e.trim()?e.trim():void 0}function G(e,t){for(let n of t){let t=W(e[n]);if(t)return t}}function K(e,t){for(let n of t){let t=Le(e[n]);if(t!==void 0)return t}}function Re(e){return e.split(/[\\/]/).filter(Boolean).pop()??e}function ze(e){return e?e.split(/\r?\n/).length:0}function Be(e){let t=0,n=0;for(let r of e.split(/\r?\n/))r.startsWith(`+++`)||r.startsWith(`---`)||(r.startsWith(`+`)&&(t+=1),r.startsWith(`-`)&&(n+=1));return t||n?{added:t,removed:n}:null}function Ve(e){let t=e.split(/\r?\n/,1)[0]?.trim()??e;return t.length>72?`${t.slice(0,69)}…`:t}function He(e){let t=e.toLowerCase().replace(/[.:/-]+/g,`_`);return/^(read|view|open_file|read_file)|file_read/.test(t)?`read`:/^(write|create|save)|file_write/.test(t)?`write`:/edit|update|patch|replace|apply_patch/.test(t)?`edit`:/bash|shell|terminal|exec|command|powershell|cmd/.test(t)?`terminal`:/fetch|browser|browse|http|url|web/.test(t)?`web`:/search|grep|find|glob|query/.test(t)?`search`:/memory|recall|remember/.test(t)?`memory`:`other`}function Ue(e,t){let n=(Array.isArray(e.fileTargets)?e.fileTargets:[]).flatMap(e=>{let t=Ie(e),n=G(t,[`filePath`,`file_path`,`path`]);return n?[{filePath:n,operation:W(t.operation),line:K(t,[`line`,`startLine`,`start_line`]),endLine:K(t,[`endLine`,`end_line`])}]:[]});if(n.length>0)return n;let r=G(t,[`file_path`,`filePath`,`path`,`filename`,`target_file`,`targetFile`]);return r?[{filePath:r,line:K(t,[`line`,`start_line`,`startLine`,`offset`]),endLine:K(t,[`end_line`,`endLine`])}]:[]}function We(e,t){let n=e?.line??K(t,[`line`,`start_line`,`startLine`,`offset`]),r=e?.endLine??K(t,[`end_line`,`endLine`]),i=K(t,[`limit`,`line_count`,`lineCount`]);return r===void 0&&n!==void 0&&i!==void 0&&i>0&&(r=n+i-1),n!==void 0&&r!==void 0?{start:n,end:r,label:`L${n}–${r}`}:n===void 0?{}:{start:n,label:`L${n}`}}function Ge(e,t,n,r,i,a){let o=We(a,n),s=a?.filePath??G(n,[`file_path`,`filePath`,`path`,`filename`]),c=s?Re(s):void 0;if(e===`read`)return{target:s,summary:i===void 0?o.label?`${o.label} queued to read`:`Reading file`:`${i.toLocaleString()} lines read`,lineLabel:o.label};if(e===`write`){let e=G(n,[`content`,`text`,`data`]),t=K(r,[`inputLines`])??(e?ze(e):void 0);return{target:s,summary:t===void 0?`Writing file`:`${t.toLocaleString()} lines written`,lineLabel:o.label}}if(e===`edit`){let e=G(n,[`patch`,`diff`]),t=e?Be(e):null,i=G(n,[`old_string`,`oldString`,`search`]),a=G(n,[`new_string`,`newString`,`replacement`]),c=K(r,[`addedLines`]),l=K(r,[`removedLines`]),u=K(r,[`oldLines`]),d=K(r,[`newLines`]);return{target:s,summary:t||c!==void 0||l!==void 0?`+${t?.added??c??0} / −${t?.removed??l??0} lines`:i!==void 0||a!==void 0||u!==void 0||d!==void 0?`${i?ze(i):u??0} → ${a?ze(a):d??0} lines`:o.label?`${o.label} updated`:`Updating file`,lineLabel:o.label}}if(e===`terminal`){let e=G(n,[`command`,`cmd`,`script`,`shell`])??t;return{summary:Ve(e),target:e}}if(e===`web`){let e=G(n,[`url`,`href`,`uri`]),t=G(n,[`query`,`q`,`search`]);return{target:e??t,summary:e?`Fetched ${e}`:t?`Looked up “${t}”`:`Went online`}}if(e===`search`){let e=G(n,[`query`,`pattern`,`q`,`search`])??c;return{target:s??e,summary:e?`Searched “${e}”`:`Searching project`}}if(e===`memory`){let e=G(n,[`query`,`text`,`key`]);return{target:e,summary:e?`Recalled “${e}”`:`Checking memory`}}return{target:s,summary:c?`${t} · ${c}`:t}}function Ke(e,t){let n=W(t.name)??W(t.toolName);if(n)return n;if(e.kind===`agent:tool`)return e.target??void 0;if(e.kind.startsWith(`tool:`))return e.source}function qe(e,t,n){return W(t.agentId)??W(t.subagentId)??(e.kind===`agent:tool`?e.source:void 0)??(e.source!==n&&e.source!==`filesystem`?e.source:void 0)??`leader`}function Je(e){return W(e.parentSessionId)??W(e.sessionId)}function Ye(e,t){return e.kind===`tool:started`||e.kind===`tool:progress`?`running`:t.ok===!1?`failed`:`succeeded`}function Xe(e){if(![`tool:started`,`tool:progress`,`tool:executed`,`agent:tool`].includes(e.kind))return null;let t=Ie(e.data),n=Ke(e,t);if(!n)return null;let r=qe(e,t,n),i=t.input,a=Ie(i),o=Ue(t,a),s=Le(t.outputLines),c=He(n),l=Ge(c,n,a,t,s,o[0]),u=W(t.id),d=Math.floor(e.timestamp/2e3),f=Ye(e,t),p=Le(t.durationMs);return{id:u?`${r}:${u}`:`${r}:${n}:${d}`,agentId:r,agentName:W(t.agentName),sessionId:Je(t),toolName:n,kind:c,status:f,startedAt:f===`running`?e.timestamp:Math.max(0,e.timestamp-(p??0)),...f===`running`?{}:{completedAt:e.timestamp},durationMs:p,target:l.target,summary:l.summary,lineLabel:l.lineLabel,outputLines:s,outputBytes:Le(t.outputBytes),outputTokens:Le(t.outputTokens),input:i,output:W(t.output),fileTargets:o,raw:e.raw??t}}function Ze(e,t,n){return e?.length?nt(e.map(e=>({id:`snapshot:${n??`session`}:${t}:${e.id}`,kind:`tool:executed`,timestamp:e.completedAt,source:t,target:e.name,label:e.name,data:{...e,agentId:t,sessionId:n},flowGroup:`agent:${t}`})),t,n):[]}function Qe(e){return e?.length?e.map(e=>({id:e.id,direction:e.direction,from:e.from,to:e.to,type:e.type,subject:e.subject,body:``,priority:`normal`,timestamp:new Date(e.at).toISOString(),timestampMs:e.at,unread:e.direction===`incoming`})).sort((e,t)=>t.timestampMs-e.timestampMs).slice(0,12):[]}function $e(e,t,n=3e4){let r=new Map;e.forEach((e,t)=>{for(let n of[e.agent.serverId,e.agent.mailboxId,e.agent.name]){let e=q(n);e&&!r.has(e)&&r.set(e,t)}});let i=new Set,a=[];for(let o of e){let e=o.mail[0];if(!e||i.has(e.id)||t-e.timestampMs>n)continue;let s=r.get(q(e.from)),c=r.get(q(e.to));s===void 0||c===void 0||s===c||(i.add(e.id),a.push({id:e.id,mail:e,fromIndex:s,toIndex:c}))}return a}function et(e,t){return e.toLowerCase()===t.toLowerCase()}function q(e){return e?.trim().toLowerCase()??``}function tt(e,t,n){let r=new Set([t.serverId,t.mailboxId,t.name].map(q).filter(e=>e.length>0)),i=n?`@session:${q(n)}`:``,a=q(t.role),o=q(t.serverId)===`leader`||q(t.serverId).startsWith(`leader@`)||a===`lead`||a===`leader`;return e.flatMap(e=>{let t=q(e.from),n=q(e.to),a=r.has(t),s=n===`*`||n===`all`||i.length>0&&n===i,c=(e.audience!==`leaders`||o)&&(r.has(n)||o&&s);if(!c&&!a)return[];let l=Date.parse(e.timestamp);return[{...e,direction:c?`incoming`:`outgoing`,timestampMs:Number.isFinite(l)?l:0,unread:c&&!Object.keys(e.readBy??{}).some(e=>r.has(q(e)))}]}).sort((e,t)=>t.timestampMs-e.timestampMs).slice(0,8)}function nt(e,t,n){let r=new Map;for(let i=e.length-1;i>=0;--i){let a=e[i];if(!a)continue;let o=Xe(a);if(!o||!et(o.agentId,t)||n&&o.sessionId&&o.sessionId!==n)continue;let s=r.get(o.id);r.set(o.id,s?{...s,...o,startedAt:Math.min(s.startedAt,o.startedAt),fileTargets:o.fileTargets.length>0?o.fileTargets:s.fileTargets,input:o.input??s.input,output:o.output??s.output,raw:o.raw??s.raw}:o)}let i=[...r.values()].sort((e,t)=>(t.completedAt??t.startedAt)-(e.completedAt??e.startedAt));return i.filter((e,t)=>e.input!==void 0||e.fileTargets.length>0||e.output!==void 0||!i.some((n,r)=>r!==t&&n.toolName===e.toolName&&(n.input!==void 0||n.fileTargets.length>0||n.output!==void 0)&&Math.abs((n.completedAt??n.startedAt)-(e.completedAt??e.startedAt))<2500))}function rt(e,t,n){let r=He(t),i={read:`Reading a file`,write:`Writing a file`,edit:`Updating code`,terminal:`Running a command`,web:`Working online`,search:`Searching project`,memory:`Checking memory`,other:t};return{id:`${e}:live:${t}`,agentId:e,sessionId:n,toolName:t,kind:r,status:`running`,startedAt:Date.now(),summary:i[r],fileTargets:[]}}var J=ce(),it={read:O,write:w,edit:w,terminal:x,web:re,search:t,memory:o,other:z};function at(e,t=46){if(!e||e.length<=t)return e;let n=e.split(/[\\/]/).slice(-2).join(`/`);return n.length<=t?`…/${n}`:`…${e.slice(-(t-1))}`}function ot(e){return e===void 0?`—`:e<1e3?`${Math.round(e)} ms`:`${(e/1e3).toFixed(+(e<1e4))} s`}function st(e){if(e===void 0)return``;if(typeof e==`string`)return e;try{return JSON.stringify(e,null,2)}catch{return String(e)}}function Y({label:e,value:t}){return(0,J.jsxs)(`div`,{className:`agent-office__detail-row`,children:[(0,J.jsx)(`span`,{children:e}),(0,J.jsx)(`strong`,{children:t})]})}function ct({selected:e,onClose:t}){let{t:n}=N(),{call:r,agentName:a}=e,o=it[r.kind],s=st(r.input),c=st(r.output);return(0,J.jsxs)(`aside`,{className:`agent-office__detail`,"aria-label":`${r.toolName} details`,children:[(0,J.jsxs)(`div`,{className:`agent-office__detail-header`,children:[(0,J.jsx)(`div`,{className:V(`agent-office__detail-icon`,`is-${r.kind}`),children:(0,J.jsx)(o,{"aria-hidden":`true`})}),(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`span`,{children:n(`activity:agentOffice.toolCall`)}),(0,J.jsx)(`h2`,{children:r.toolName})]}),(0,J.jsx)(`button`,{type:`button`,onClick:t,"aria-label":`Close details`,children:(0,J.jsx)(j,{})})]}),(0,J.jsxs)(`div`,{className:`agent-office__detail-status`,children:[(0,J.jsx)(`span`,{className:V(`agent-office__status-dot`,r.status===`running`&&`is-active`,r.status===`failed`&&`is-failed`)}),(0,J.jsx)(`strong`,{children:r.summary}),(0,J.jsx)(`span`,{children:r.status})]}),(0,J.jsxs)(`section`,{className:`agent-office__detail-section`,children:[(0,J.jsx)(`h3`,{children:n(`activity:agentOffice.execution`)}),(0,J.jsx)(Y,{label:n(`activity:agentOffice.agent`),value:a}),(0,J.jsx)(Y,{label:n(`activity:agentOffice.started`),value:new Date(r.startedAt).toLocaleTimeString()}),(0,J.jsx)(Y,{label:n(`activity:agentOffice.duration`),value:ot(r.durationMs)}),r.sessionId&&(0,J.jsx)(Y,{label:n(`activity:agentOffice.session`),value:at(r.sessionId,28)})]}),(r.target||r.fileTargets.length>0)&&(0,J.jsxs)(`section`,{className:`agent-office__detail-section`,children:[(0,J.jsx)(`h3`,{children:n(`activity:agentOffice.target`)}),r.target&&(0,J.jsx)(`code`,{className:`agent-office__target-code`,children:r.target}),r.fileTargets.map((e,t)=>(0,J.jsxs)(`div`,{className:`agent-office__file-target`,children:[(0,J.jsx)(i,{"aria-hidden":`true`}),(0,J.jsx)(`span`,{children:e.filePath}),(e.line||e.endLine)&&(0,J.jsxs)(`strong`,{children:[`L`,e.line??1,e.endLine?`–${e.endLine}`:``]})]},`${e.filePath}:${t}`))]}),(r.outputLines!==void 0||r.outputBytes!==void 0||r.outputTokens!==void 0)&&(0,J.jsxs)(`section`,{className:`agent-office__detail-section`,children:[(0,J.jsx)(`h3`,{children:n(`activity:agentOffice.resultSize`)}),(0,J.jsxs)(`div`,{className:`agent-office__metric-grid`,children:[r.outputLines!==void 0&&(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`strong`,{children:r.outputLines.toLocaleString()}),(0,J.jsx)(`span`,{children:n(`activity:agentOffice.lines`)})]}),r.outputBytes!==void 0&&(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`strong`,{children:r.outputBytes.toLocaleString()}),(0,J.jsx)(`span`,{children:n(`activity:agentOffice.bytes`)})]}),r.outputTokens!==void 0&&(0,J.jsxs)(`div`,{children:[(0,J.jsxs)(`strong`,{children:[`≈`,r.outputTokens.toLocaleString()]}),(0,J.jsx)(`span`,{children:n(`activity:agentOffice.tokens`)})]})]})]}),s&&(0,J.jsxs)(`section`,{className:`agent-office__detail-section`,children:[(0,J.jsx)(`h3`,{children:n(`activity:agentOffice.input`)}),(0,J.jsx)(`pre`,{children:(0,J.jsx)(`code`,{children:s})})]}),c&&(0,J.jsxs)(`section`,{className:`agent-office__detail-section`,children:[(0,J.jsx)(`h3`,{children:n(`activity:agentOffice.outputPreview`)}),(0,J.jsx)(`pre`,{children:(0,J.jsx)(`code`,{children:c})})]})]})}function lt({selected:e,onClose:t}){let{t:n}=N(),{mail:r,agentName:i}=e;return(0,J.jsxs)(`aside`,{className:`agent-office__detail`,"aria-label":`${r.subject} details`,children:[(0,J.jsxs)(`div`,{className:`agent-office__detail-header`,children:[(0,J.jsx)(`div`,{className:`agent-office__detail-icon is-mail`,children:(0,J.jsx)(C,{"aria-hidden":`true`})}),(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`span`,{children:r.direction===`incoming`?`INCOMING MAIL`:`OUTGOING MAIL`}),(0,J.jsx)(`h2`,{children:r.subject})]}),(0,J.jsx)(`button`,{type:`button`,onClick:t,"aria-label":`Close mail details`,children:(0,J.jsx)(j,{})})]}),(0,J.jsxs)(`div`,{className:`agent-office__detail-status`,children:[(0,J.jsx)(`span`,{className:V(`agent-office__status-dot`,r.unread&&`is-active`)}),(0,J.jsxs)(`strong`,{children:[r.from,` → `,r.to]}),(0,J.jsx)(`span`,{children:r.type}),r.audience===`leaders`&&(0,J.jsxs)(`span`,{children:[(0,J.jsx)(te,{className:`h-3 w-3`}),` `,n(`activity:mailbox.audienceLeaders`)]})]}),(0,J.jsxs)(`section`,{className:`agent-office__detail-section`,children:[(0,J.jsx)(`h3`,{children:n(`activity:mailbox.messages`)}),(0,J.jsx)(Y,{label:n(`activity:agentOffice.agent`),value:i}),(0,J.jsx)(Y,{label:n(`activity:agentOffice.started`),value:new Date(r.timestampMs).toLocaleTimeString()}),(0,J.jsx)(Y,{label:`Priority`,value:r.priority}),(0,J.jsx)(Y,{label:`Route`,value:`${r.from} → ${r.to}`})]}),(0,J.jsxs)(`section`,{className:`agent-office__detail-section`,children:[(0,J.jsx)(`h3`,{children:r.subject}),(0,J.jsx)(`div`,{className:`agent-office__mail-body`,children:r.body})]})]})}function ut({selected:e,onClose:t}){let{t:n}=N();return(0,J.jsxs)(`aside`,{className:`agent-office__detail`,"aria-label":`${e.agentName} task details`,children:[(0,J.jsxs)(`div`,{className:`agent-office__detail-header`,children:[(0,J.jsx)(`div`,{className:`agent-office__detail-icon is-task`,children:(0,J.jsx)(M,{"aria-hidden":`true`})}),(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`span`,{children:n(`activity:agentOffice.currentTask`)}),(0,J.jsx)(`h2`,{children:e.agentName})]}),(0,J.jsx)(`button`,{type:`button`,onClick:t,"aria-label":`Close task details`,children:(0,J.jsx)(j,{})})]}),(0,J.jsxs)(`section`,{className:`agent-office__detail-section`,children:[(0,J.jsx)(`h3`,{children:n(`activity:agentOffice.task`)}),e.taskId&&(0,J.jsx)(Y,{label:`ID`,value:e.taskId}),(0,J.jsx)(`div`,{className:`agent-office__task-body`,children:e.task})]})]})}function dt({selected:e,onClose:t}){let{t:n}=N(),r=e.todos.filter(e=>e.status!==`completed`).length;return(0,J.jsxs)(`aside`,{className:`agent-office__detail`,"aria-label":`${e.officeLabel} briefing`,children:[(0,J.jsxs)(`div`,{className:`agent-office__detail-header`,children:[(0,J.jsx)(`div`,{className:`agent-office__detail-icon is-briefing`,children:(0,J.jsx)(I,{"aria-hidden":`true`})}),(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`span`,{children:e.instructionActive?n(`activity:agentOffice.activeInstruction`):n(`activity:agentOffice.officeBriefing`)}),(0,J.jsx)(`h2`,{children:e.officeLabel})]}),(0,J.jsx)(`button`,{type:`button`,onClick:t,"aria-label":`Close office briefing`,children:(0,J.jsx)(j,{})})]}),(0,J.jsxs)(`div`,{className:`agent-office__detail-status`,children:[(0,J.jsx)(`span`,{className:V(`agent-office__status-dot`,(e.instructionActive||r>0)&&`is-active`)}),(0,J.jsx)(`strong`,{children:e.telemetryConnected?n(`activity:agentOffice.activeTodos`):n(`activity:agentOffice.telemetryWaiting`)}),(0,J.jsx)(`span`,{children:e.telemetryConnected?r:`—`})]}),(0,J.jsxs)(`section`,{className:`agent-office__detail-section`,children:[(0,J.jsx)(`h3`,{children:e.instructionActive?n(`activity:agentOffice.activeInstruction`):n(`activity:agentOffice.leaderPrompt`)}),e.promptAt!==void 0&&(0,J.jsx)(Y,{label:n(`activity:agentOffice.promptReceived`),value:new Date(e.promptAt).toLocaleString()}),(0,J.jsx)(`div`,{className:`agent-office__task-body`,children:e.prompt??(e.telemetryConnected?n(`activity:agentOffice.noPrompt`):n(`activity:agentOffice.telemetryWaiting`))})]}),(0,J.jsxs)(`section`,{className:`agent-office__detail-section`,children:[(0,J.jsx)(`h3`,{children:n(`activity:agentOffice.todos`)}),(0,J.jsx)(`div`,{className:`agent-office__todo-detail-list`,children:e.telemetryConnected?e.todos.length>0?e.todos.map(e=>(0,J.jsxs)(`div`,{className:V(`agent-office__todo-detail`,`is-${e.status}`),children:[(0,J.jsx)(`span`,{"aria-hidden":`true`}),(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`strong`,{children:e.content}),(0,J.jsx)(`small`,{children:n(`activity:agentOffice.todoStatus.${e.status}`)})]})]},e.id)):(0,J.jsx)(`span`,{className:`agent-office__history-empty`,children:n(`activity:agentOffice.noActiveTodos`)}):(0,J.jsx)(`span`,{className:`agent-office__history-empty`,children:n(`activity:agentOffice.todoTelemetryWaiting`)})})]})]})}function ft({selected:e,onClose:t}){return e.kind===`tool`?(0,J.jsx)(ct,{selected:e,onClose:t}):e.kind===`mail`?(0,J.jsx)(lt,{selected:e,onClose:t}):e.kind===`task`?(0,J.jsx)(ut,{selected:e,onClose:t}):(0,J.jsx)(dt,{selected:e,onClose:t})}function pt(e){return e==null||!Number.isFinite(e)?`0`:e<1e3?String(Math.round(e)):e<1e6?`${(e/1e3).toFixed(1)}k`:`${(e/1e6).toFixed(1)}M`}function mt(e,t){if(!e)return`never`;let n=Date.parse(e);if(!Number.isFinite(n))return`never`;let r=Math.max(0,Math.round((t-n)/1e3));return r<60?`${r}s ago`:r<3600?`${Math.round(r/60)}m ago`:r<86400?`${Math.round(r/3600)}h ago`:`${Math.round(r/86400)}d ago`}function ht(e,t){if(!e)return``;let n=Date.parse(e);if(!Number.isFinite(n))return``;let r=Math.max(0,Math.round((t-n)/1e3));return r<60?`${r}s`:r<3600?`${Math.round(r/60)}m`:`${Math.round(r/3600)}h`}function gt(e){if(!e)return;let t=e.split(`/`);return t[t.length-1]?.slice(0,18)}function _t(e,t=56){if(!e)return;let n=e.replace(/\s+/g,` `).trim();if(n)return n.length<=t?n:t<=1?`…`:`${n.slice(0,t-1).trimEnd()}…`}function vt(e,t){if(e.length===0)return{positions:new Map,columns:0,rows:0,columnWidth:380};let n=Math.max(1,...e.map(e=>e.agentCount)),r=Math.max(380,Math.min(3,n)*190+80),i=e=>270+Math.max(1,...e.map(e=>Math.ceil(Math.max(1,e.agentCount)/3)))*150,a=Math.max(320,t.width),o=Math.max(240,t.height),s=1,c=-1/0,l=1/0;for(let t=1;t<=e.length;t+=1){let n=[];for(let r=0;r<e.length;r+=t)n.push(i(e.slice(r,r+t)));let u=n.length,d=Math.max(660,Math.min(t,e.length)*r),f=320+n.reduce((e,t)=>e+t,0)+Math.max(0,u-1)*100,p=Math.min(a/d,o/f),m=Math.abs(Math.log(d/f/(a/o)));(p>c+1e-9||Math.abs(p-c)<=1e-9&&m<l)&&(s=t,c=p,l=m)}let u=new Map,d=370;for(let t=0;t<e.length;t+=s){let n=e.slice(t,t+s);n.forEach((e,t)=>{u.set(e.id,{x:600+(t-(n.length-1)/2)*r,y:d})}),d+=i(n)+100}return{positions:u,columns:s,rows:Math.ceil(e.length/s),columnWidth:r}}function yt(e,t,n,r=640){let i=Math.min(3,n),a=Math.floor(t/i),o=t%i;return{x:e-(Math.min(i,n-a*i)-1)*190/2+o*190,y:r+a*150}}function bt(e){return e===`tui`?`tui`:e===`repl`||e===`cli`?`repl`:`webui`}function xt(e){return e===`tui`?`TUI`:e===`repl`?`REPL`:`WebUI`}function St(e){switch(e){case`running`:case`active`:return`active`;case`idle`:return`idle`;case`completed`:return`completed`;case`failed`:case`error`:return`error`;case`stopped`:return`offline`;default:return`idle`}}function Ct(e){if(e)return e.split(`/`).filter(Boolean).pop()??e}function wt(e){let t=Ct(e)??e??``;return t.length>10?`…${t.slice(-8)}`:t}function Tt(e,t){let n=Ct(t);if(n)return e.find(e=>Ct(e.sessionId)===n)}function Et(e,t){let n=St(t.status);return{officeId:`${e}__agent-${t.id}`,serverId:t.id,name:t.name??t.id,status:n,iteration:t.iteration??0,toolCalls:t.toolCalls??0,costUsd:t.costUsd??0,tokensIn:t.tokensIn??0,tokensOut:t.tokensOut??0,ctxPct:t.ctxPct,model:t.model,currentTool:t.currentTool,currentTask:t.description,taskId:t.taskId,presenceSource:`fleet`}}function Dt(e,t){return e===`cli`?`CLI`:e===`repl`?`REPL`:xt(t)}function Ot(e,t,n=[],r=new Map,i=Date.now()){let a=new Set,o=[];for(let n of e){let e=bt(n.clientType),r=Dt(n.clientType,e),i=`client-${n.pid??n.sessionId}`,s=[],c=!1;for(let e of n.agents){a.add(e.id);let n=t.get(e.id),r=St(n?.status??e.status);(r===`active`||r===`streaming`)&&(c=!0),s.push({officeId:`${i}__agent-${e.id}`,serverId:e.id,name:n?.name??e.name??e.id,status:r,iteration:n?.iteration??e.iterations??0,toolCalls:n?.toolCalls??e.toolCalls??0,costUsd:n?.costUsd??e.costUsd??0,tokensIn:n?.tokensIn??e.tokensIn??0,tokensOut:n?.tokensOut??e.tokensOut??0,ctxPct:n?.ctxPct??e.ctxPct,model:n?.model??e.model,lastActivityAt:e.lastActivityAt,currentTool:n?.currentTool??e.currentTool,currentTask:e.currentTask??n?.description,taskId:e.taskId??n?.taskId,recentTools:e.recentTools,recentMail:e.recentMail,activity:e.activity,presenceSource:`registry`})}let l=n.status===`closing`||n.status===`stale`||n.status===`lost`?`offline`:c?`active`:`idle`,u=n.agents.find(e=>e.id===`leader`);o.push({id:i,type:e,label:`${r} · ${n.pid?`PID ${n.pid}`:wt(n.sessionId)}`,sublabel:[`session ${wt(n.sessionId)}`,n.gitBranch?`⎇ ${n.gitBranch}`:``,n.workingDir?n.workingDir.split(/[\\/]/).filter(Boolean).pop():``].filter(Boolean).join(` · `),status:l,sessionId:n.sessionId,pid:n.pid,branch:n.gitBranch,workingDir:n.workingDir,startedAt:n.startedAt,lastHeartbeatAt:n.lastHeartbeatAt,latestPrompt:u?.latestPrompt,latestPromptAt:u?.latestPromptAt,activeInstruction:u?.status===`running`||u?.status===`streaming`?u.latestPrompt??u.currentTask:void 0,todos:u?.todos,agents:s})}for(let e of n.filter(e=>e.online)){let t=Tt(o,e.sessionId);if(!t)continue;let n=e.name.trim().toLowerCase(),r=t.agents.find(t=>t.serverId===e.agentId||t.name.trim().toLowerCase()===n);r&&(a.add(e.agentId),r.mailboxId=e.agentId,r.role=e.role,r.currentTask=r.currentTask??e.currentTask,r.currentTool=r.currentTool??e.currentTool)}let s=[...t.values()].filter(e=>!a.has(e.id)),c,l=()=>{if(c)return c;let e=o.find(e=>e.type===`webui`);return e?(c=e,e):(c={id:`client-self`,type:`webui`,label:`This WebUI`,sublabel:`Web UI`,status:`idle`,agents:[]},o.push(c),c)};for(let e of s){let t=Tt(o,e.sessionId)??l(),n=Et(t.id,e);(n.status===`active`||n.status===`streaming`)&&t.status!==`offline`&&(t.status=`active`),t.agents.push(n),a.add(e.id)}for(let[e,t]of r){if(a.has(e)||i-t.finishedAt>9e5)continue;let n=Tt(o,t.agent.sessionId);n&&n.agents.push(Et(n.id,t.agent))}return o.length===0&&o.push({id:`client-self`,type:`webui`,label:`This WebUI`,sublabel:`Web UI · connecting…`,status:`idle`,agents:[]}),o}function kt(e){return e.startsWith(`tool`)?`hsl(var(--warning))`:e.startsWith(`mailbox`)?`hsl(var(--info))`:e.startsWith(`provider`)?`hsl(var(--primary))`:e.startsWith(`agent`)||e.startsWith(`subagent`)?`hsl(var(--success))`:e.includes(`error`)?`hsl(var(--destructive))`:`hsl(var(--primary))`}var At=new Set([`completed`,`failed`,`timeout`,`stopped`]);function jt(e){let t=(0,U.useRef)(new Map).current;return(0,U.useMemo)(()=>{let n=Date.now(),r=new Set;for(let i of e.values())if(r.add(i.id),At.has(i.status)){let e=t.get(i.id);e?e.agent=i:t.set(i.id,{agent:i,finishedAt:i.completedAt??n})}else t.delete(i.id);for(let[e,n]of[...t.entries()])!r.has(e)&&!At.has(n.agent.status)&&t.set(e,{agent:{...n.agent,status:`stopped`},finishedAt:n.finishedAt});for(let[e,r]of t)n-r.finishedAt>9e5&&t.delete(e);return{map:t,now:n}},[e,t])}var Mt=[`bot`,`cactus`,`duck`,`radio`],Nt={leader:`plum`,builder:`ocean`,researcher:`mint`,reviewer:`rose`,planner:`amber`,operator:`graphite`},Pt={leader:0,builder:1,researcher:2,reviewer:3,planner:4,operator:5},Ft={read:O,write:w,edit:w,terminal:x,web:re,search:t,memory:o,other:z},It={leader:_e,builder:z,researcher:O,reviewer:S,planner:M,operator:x};function Lt(e){if(e.serverId===`leader`||e.serverId.startsWith(`leader@`))return`leader`;let t=[e.role,e.name,e.currentTask].filter(Boolean).join(` `).toLowerCase();return/review|critic|audit|security|test|qa|verify|checker/.test(t)?`reviewer`:/research|analyst|explor|investig|search|hunter|recon/.test(t)?`researcher`:/plan|architect|design|coordinat|strateg|spec/.test(t)?`planner`:/build|implement|code|develop|engineer|refactor|fix|frontend|backend/.test(t)?`builder`:`operator`}function Rt(e,t){let n=2166136261;for(let t=0;t<e.length;t+=1)n^=e.charCodeAt(t),n=Math.imul(n,16777619);let r=n>>>0;return{palette:Nt[t],layout:r%4,clutter:Math.floor(r/4)%3,avatar:Pt[t],motion:Math.floor(r/31)%4,charm:Mt[Math.floor(r/47)%Mt.length]}}function zt(e,t=22){let n=e.split(`/`).filter(Boolean).pop()??e;return n.length>t?`${n.slice(0,t-1)}…`:n}function Bt(e,t=46){if(!e||e.length<=t)return e;let n=e.split(/[\\/]/).slice(-2).join(`/`);return n.length<=t?`…/${n}`:`…${e.slice(-(t-1))}`}function Vt(e,t){let n=Math.max(0,Math.floor((t-e)/1e3));if(n<5)return`now`;if(n<60)return`${n}s`;let r=Math.floor(n/60);return r<60?`${r}m`:`${Math.floor(r/60)}h`}function Ht(e,t){if(!e)return`—`;let n=Date.parse(e);if(!Number.isFinite(n))return`—`;let r=Math.max(0,Math.floor((t-n)/1e3));return r<60?`${r}s`:r<3600?`${Math.floor(r/60)}m`:r<86400?`${Math.floor(r/3600)}h`:`${Math.floor(r/86400)}d`}function Ut(e){let t=new Set,n=new Set,r=new Set,i=0,a=0,o={files:0,reads:0,writes:0,edits:0,linesAdded:0,linesRemoved:0,terminalCalls:0,incomingMail:0,outgoingMail:0};for(let s of e){let e=s.agent.activity;for(let n of e?.filesTouched??[])t.add(n);o.reads+=e?.reads??0,o.writes+=e?.writes??0,o.edits+=e?.edits??0,o.linesAdded+=e?.linesAdded??0,o.linesRemoved+=e?.linesRemoved??0,o.terminalCalls+=e?.terminalCalls??0,i+=e?.mailReceived??0,a+=e?.mailSent??0;for(let e of s.mail)(e.direction===`incoming`?n:r).add(e.id)}return o.files=t.size,o.incomingMail=Math.max(i,n.size),o.outgoingMail=Math.max(a,r.size),o}function Wt(e,t,n){return n.map((n,r)=>({...rt(e.serverId,n.name,t.sessionId),id:`${e.serverId}:log:${n.at}:${r}`,kind:He(n.name),status:n.ok?`succeeded`:`failed`,startedAt:Math.max(0,n.at-n.durationMs),completedAt:n.at,durationMs:n.durationMs,summary:n.ok?`${n.name} completed`:`${n.name} failed`}))}function Gt(...e){let t=[];for(let n of e.flat()){let e=n.completedAt??n.startedAt;t.some(t=>(t.id===n.id||t.toolName===n.toolName)&&Math.abs((t.completedAt??t.startedAt)-e)<2500)||t.push(n)}return t.sort((e,t)=>(t.completedAt??t.startedAt)-(e.completedAt??e.startedAt))}function Kt(...e){let t=new Map;for(let n of e.flat())t.set(n.id,n);return[...t.values()].sort((e,t)=>t.timestampMs-e.timestampMs).slice(0,12)}function qt({kind:e,active:t}){let n=Ft[e];return(0,J.jsxs)(`span`,{className:V(`agent-office__tool-glyph`,`is-${e}`,t&&`is-active`),children:[e===`read`&&(0,J.jsx)(i,{className:`agent-office__file-underlay`,"aria-hidden":`true`}),(0,J.jsx)(n,{"aria-hidden":`true`})]})}function Jt({active:e,failed:t,role:n,variant:r,motion:i}){let a=It[n];return(0,J.jsxs)(`div`,{className:V(`agent-office__avatar`,`is-${n}`,`is-avatar-${r}`,`is-motion-${i}`,e&&`is-active`,!e&&!t&&`is-idle`,t&&`is-failed`),"aria-hidden":`true`,children:[(0,J.jsx)(`span`,{className:`agent-office__avatar-chair`}),(0,J.jsx)(`span`,{className:`agent-office__avatar-body`}),(0,J.jsxs)(`span`,{className:`agent-office__avatar-head`,children:[(0,J.jsx)(`span`,{className:`agent-office__avatar-hair`}),(0,J.jsx)(`span`,{className:`agent-office__avatar-face`}),(0,J.jsx)(`span`,{className:`agent-office__avatar-mouth`}),(0,J.jsx)(`span`,{className:`agent-office__avatar-headset`})]}),(0,J.jsx)(`span`,{className:`agent-office__avatar-arm`}),(0,J.jsx)(`span`,{className:`agent-office__avatar-prop`}),(0,J.jsx)(`span`,{className:`agent-office__avatar-role-badge`,children:(0,J.jsx)(a,{})})]})}function Yt({call:e,compact:t=!1,onSelect:n}){let r=e.status===`running`;return(0,J.jsxs)(`button`,{type:`button`,className:V(`agent-office__parcel`,`is-${e.kind}`,t&&`is-compact`,r&&`is-running`,e.status===`failed`&&`is-failed`),onClick:n,"aria-label":`${e.toolName}: ${e.summary}`,children:[(0,J.jsx)(qt,{kind:e.kind,active:r}),(0,J.jsxs)(`span`,{className:`agent-office__parcel-copy`,children:[(0,J.jsxs)(`span`,{className:`agent-office__parcel-topline`,children:[(0,J.jsx)(`strong`,{children:e.toolName}),e.lineLabel&&(0,J.jsx)(`span`,{className:`agent-office__line-chip`,children:e.lineLabel})]}),!t&&e.target&&(0,J.jsx)(`span`,{className:`agent-office__parcel-target`,children:Bt(e.target)}),(0,J.jsx)(`span`,{className:`agent-office__parcel-summary`,children:e.summary})]}),(0,J.jsx)(`span`,{className:`agent-office__parcel-state`,"aria-hidden":`true`,children:r?(0,J.jsx)(`span`,{className:`agent-office__pulse-dot`}):e.status===`failed`?(0,J.jsx)(j,{}):(0,J.jsx)(S,{})})]})}function Xt({mail:e,compact:t=!1,onSelect:n}){let r=e.direction===`incoming`;return(0,J.jsxs)(`button`,{type:`button`,className:V(`agent-office__mail-parcel`,t&&`is-compact`,r?`is-incoming`:`is-outgoing`,e.unread&&`is-unread`),onClick:n,"aria-label":`${r?`Incoming`:`Outgoing`} mail: ${e.subject}`,children:[(0,J.jsx)(`span`,{className:`agent-office__mail-icon`,children:r?(0,J.jsx)(xe,{"aria-hidden":`true`}):(0,J.jsx)(oe,{"aria-hidden":`true`})}),(0,J.jsxs)(`span`,{className:`agent-office__parcel-copy`,children:[(0,J.jsx)(`strong`,{children:r?`${e.from} →`:`→ ${e.to}`}),(0,J.jsx)(`span`,{className:`agent-office__parcel-summary`,children:e.subject})]}),(0,J.jsx)(C,{"aria-hidden":`true`})]})}function Zt({office:e,now:t}){let{t:n}=N(),{client:r,agents:i,stats:a}=e,o=r.lastHeartbeatAt?Date.parse(r.lastHeartbeatAt):NaN,s=Number.isFinite(o)&&t-o<2e4,c=Number.isFinite(o)&&!s,l=i.some(({agent:e})=>e.presenceSource===`registry`),d=s?`VERIFIED`:c?`DELAYED`:l?`REGISTRY`:`LOCAL`,f=i.some(({agent:e})=>e.recentTools!==void 0||e.activity!==void 0),p=i.some(({agent:e})=>e.toolCalls>0&&e.recentTools===void 0&&e.activity===void 0);return(0,J.jsxs)(`header`,{className:`agent-office__client-header`,children:[(0,J.jsxs)(`div`,{className:`agent-office__client-title`,children:[(0,J.jsx)(`span`,{className:`agent-office__client-icon`,children:(0,J.jsx)(_e,{"aria-hidden":`true`})}),(0,J.jsxs)(`div`,{className:`agent-office__client-copy`,children:[(0,J.jsx)(`strong`,{children:r.label}),(0,J.jsx)(`span`,{children:r.sublabel||r.sessionId})]}),(0,J.jsxs)(`div`,{className:`agent-office__client-presence`,children:[(0,J.jsxs)(`span`,{className:`agent-office__client-agent-count`,children:[i.length,` `,n(`activity:agentOffice.agents`)]}),(0,J.jsxs)(`span`,{className:V(`agent-office__presence-chip`,!c&&`is-live`,c&&`is-legacy`),children:[(0,J.jsx)(F,{"aria-hidden":`true`}),` `,d]}),(0,J.jsxs)(`span`,{className:`agent-office__presence-chip`,children:[(0,J.jsx)(u,{"aria-hidden":`true`}),` `,Ht(r.startedAt,t),` UP`]}),(0,J.jsxs)(`span`,{className:V(`agent-office__presence-chip`,p?`is-legacy`:f&&`is-telemetry`),children:[(0,J.jsx)(m,{"aria-hidden":`true`}),p?`RECONNECT`:f?`TOOLS LIVE`:`READY`]})]})]}),(0,J.jsxs)(`fieldset`,{className:`agent-office__client-stats`,"aria-label":`Session activity totals`,children:[(0,J.jsxs)(`span`,{title:`Unique files touched`,children:[(0,J.jsx)(b,{}),` `,(0,J.jsx)(`strong`,{children:a.files}),` FILES`]}),(0,J.jsxs)(`span`,{title:`File reads`,children:[(0,J.jsx)(O,{}),` `,(0,J.jsx)(`strong`,{children:a.reads}),` READ`]}),(0,J.jsxs)(`span`,{title:`Files written`,children:[(0,J.jsx)(w,{}),` `,(0,J.jsx)(`strong`,{children:a.writes}),` WRITE`]}),(0,J.jsxs)(`span`,{title:`Files edited`,children:[(0,J.jsx)(w,{}),` `,(0,J.jsx)(`strong`,{children:a.edits}),` EDIT`]}),(0,J.jsxs)(`span`,{className:`agent-office__client-delta`,title:`Lines added and removed`,children:[(0,J.jsxs)(`strong`,{children:[`+`,a.linesAdded]}),` / `,(0,J.jsxs)(`b`,{children:[`−`,a.linesRemoved]})]}),(0,J.jsxs)(`span`,{title:`Terminal commands`,children:[(0,J.jsx)(x,{}),` `,(0,J.jsx)(`strong`,{children:a.terminalCalls}),` TERM`]}),(0,J.jsxs)(`span`,{title:`Incoming and outgoing mail`,children:[(0,J.jsx)(C,{}),` `,(0,J.jsx)(`strong`,{children:a.incomingMail}),`↓ `,(0,J.jsx)(`strong`,{children:a.outgoingMail}),`↑`]})]})]})}function Qt({office:e,now:t,onSelect:n}){let{t:r}=N(),{client:i}=e,a=i.todos!==void 0,o=i.todos??[],s=o.filter(e=>e.status!==`completed`),c=o.length-s.length,l=!!i.activeInstruction,u=i.activeInstruction??i.latestPrompt,d=i.latestPromptAt!==void 0&&t-i.latestPromptAt<3e4,f=()=>n({kind:`briefing`,officeLabel:i.label,prompt:u,promptAt:i.latestPromptAt,instructionActive:l,telemetryConnected:a,todos:o});return(0,J.jsxs)(`section`,{className:`agent-office__briefing`,"aria-label":r(`activity:agentOffice.officeBriefing`),children:[(0,J.jsxs)(`button`,{type:`button`,className:V(`agent-office__prompt-card`,l&&`is-active`,d&&`is-fresh`,!a&&`is-waiting`),onClick:f,children:[(0,J.jsx)(`span`,{className:`agent-office__briefing-icon is-prompt`,children:(0,J.jsx)(I,{"aria-hidden":`true`})}),(0,J.jsxs)(`span`,{className:`agent-office__briefing-copy`,children:[(0,J.jsx)(`span`,{children:r(l?`activity:agentOffice.activeInstruction`:`activity:agentOffice.leaderPrompt`)}),(0,J.jsx)(`strong`,{children:u??r(a?`activity:agentOffice.noPrompt`:`activity:agentOffice.telemetryWaiting`)})]}),l&&(0,J.jsxs)(`span`,{className:`agent-office__instruction-live`,children:[(0,J.jsx)(`i`,{"aria-hidden":`true`}),` LIVE`]}),i.latestPromptAt!==void 0&&(0,J.jsx)(`time`,{dateTime:new Date(i.latestPromptAt).toISOString(),children:Vt(i.latestPromptAt,t)})]}),(0,J.jsxs)(`button`,{type:`button`,className:V(`agent-office__todo-board`,s.length>0&&`has-active`,!a&&`is-waiting`),onClick:f,children:[(0,J.jsxs)(`span`,{className:`agent-office__todo-heading`,children:[(0,J.jsxs)(`span`,{children:[(0,J.jsx)(M,{"aria-hidden":`true`}),` `,r(`activity:agentOffice.activeTodos`)]}),(0,J.jsx)(`strong`,{children:a?r(`activity:agentOffice.todoProgress`,{done:c,total:o.length}):r(`activity:agentOffice.syncWaiting`)})]}),(0,J.jsxs)(`span`,{className:`agent-office__todo-preview`,children:[a?s.length>0?s.slice(0,3).map(e=>(0,J.jsxs)(`span`,{className:V(`agent-office__todo-line`,`is-${e.status}`),children:[(0,J.jsx)(`i`,{"aria-hidden":`true`}),(0,J.jsx)(`span`,{children:e.activeForm||e.content})]},e.id)):(0,J.jsxs)(`span`,{className:`agent-office__todo-empty`,children:[(0,J.jsx)(v,{"aria-hidden":`true`}),o.length>0?r(`activity:agentOffice.allTodosDone`):r(`activity:agentOffice.noActiveTodos`)]}):(0,J.jsxs)(`span`,{className:`agent-office__todo-empty is-waiting`,children:[(0,J.jsx)(m,{"aria-hidden":`true`}),r(`activity:agentOffice.todoTelemetryWaiting`)]}),s.length>3&&(0,J.jsx)(`span`,{className:`agent-office__todo-more`,children:r(`activity:agentOffice.moreTodos`,{count:s.length-3})})]})]})]})}function $t({active:e}){let{t}=N();return(0,J.jsxs)(`div`,{className:`agent-office__parcel agent-office__parcel--empty`,children:[(0,J.jsx)(`span`,{className:`agent-office__tool-glyph`,children:(0,J.jsx)(P,{"aria-hidden":`true`})}),(0,J.jsxs)(`span`,{className:`agent-office__parcel-copy`,children:[(0,J.jsx)(`strong`,{children:t(e?`activity:agentOffice.thinking`:`activity:agentOffice.waiting`)}),(0,J.jsx)(`span`,{children:t(e?`activity:agentOffice.preparing`:`activity:agentOffice.deskReady`)})]})]})}function en({model:e,now:t,onSelect:n,routedMailIds:r}){let{t:i}=N(),{agent:a,client:o,current:s,display:c,history:l,mail:u}=e,d=a.status===`active`||a.status===`streaming`,f=a.status===`error`,p=u[0],h=Lt(a),g=Rt(`${o.sessionId}:${a.serverId}:${a.name}`,h),_=p&&t-p.timestampMs<3e4&&!r?.has(p.id),v=l.slice(0,6),y=v[0]?.completedAt??v[0]?.startedAt??c?.completedAt??c?.startedAt,b=s?`is-tool-${s.kind}`:void 0;return(0,J.jsxs)(`article`,{className:V(`agent-office__lane`,`is-desk-${g.palette}`,`is-layout-${g.layout}`,`is-clutter-${g.clutter}`,d&&`is-active`,f&&`is-failed`),children:[(0,J.jsxs)(`div`,{className:`agent-office__identity`,children:[(0,J.jsxs)(`div`,{className:`agent-office__identity-line`,children:[(0,J.jsx)(`span`,{className:V(`agent-office__status-dot`,d&&`is-active`,f&&`is-failed`)}),(0,J.jsx)(`strong`,{title:a.name,children:a.name}),(0,J.jsxs)(`span`,{className:`agent-office__agent-verified`,title:a.presenceSource===`registry`?`Verified by live session registry`:`Verified by local fleet state`,children:[(0,J.jsx)(S,{"aria-hidden":`true`}),a.presenceSource===`registry`?`LIVE`:`LOCAL`]})]}),(0,J.jsx)(`span`,{className:`agent-office__role`,children:a.role??(a.serverId===`leader`||a.serverId.startsWith(`leader@`)?i(`activity:agentOffice.leadAgent`):i(`activity:agentOffice.agent`))}),(0,J.jsxs)(`div`,{className:`agent-office__agent-meta`,children:[(0,J.jsx)(`span`,{children:o.branch?`⎇ ${o.branch}`:o.type.toUpperCase()}),(0,J.jsx)(`span`,{children:i(`activity:agentOffice.callsCount`,{count:a.toolCalls})}),a.model&&(0,J.jsx)(`span`,{className:`agent-office__model-chip`,title:a.model,children:zt(a.model)})]}),a.currentTask&&(0,J.jsxs)(`button`,{type:`button`,className:`agent-office__agent-task`,onClick:()=>n({kind:`task`,task:a.currentTask??``,taskId:a.taskId,agentName:a.name}),children:[(0,J.jsx)(M,{"aria-hidden":`true`}),(0,J.jsxs)(`span`,{children:[(0,J.jsx)(`strong`,{children:i(`activity:agentOffice.currentTask`)}),(0,J.jsx)(`small`,{children:a.currentTask})]})]}),!a.currentTask&&d&&(0,J.jsxs)(`div`,{className:`agent-office__agent-task is-missing`,children:[(0,J.jsx)(m,{"aria-hidden":`true`}),(0,J.jsxs)(`span`,{children:[(0,J.jsx)(`strong`,{children:i(`activity:agentOffice.currentTask`)}),(0,J.jsx)(`small`,{children:o.todos===void 0?i(`activity:agentOffice.telemetryWaiting`):i(`activity:agentOffice.taskNotReported`)})]})]}),p&&(0,J.jsxs)(`button`,{type:`button`,className:V(`agent-office__identity-mail`,p.unread&&`is-unread`),onClick:()=>n({kind:`mail`,mail:p,agentName:a.name}),"aria-label":`${u.length} mail messages. Latest: ${p.subject}`,children:[(0,J.jsx)(C,{"aria-hidden":`true`}),(0,J.jsxs)(`span`,{children:[(0,J.jsxs)(`strong`,{children:[u.length,` MAIL`]}),(0,J.jsx)(`small`,{children:p.subject})]})]})]}),(0,J.jsxs)(`div`,{className:V(`agent-office__scene`,b),children:[(0,J.jsxs)(`div`,{className:`agent-office__window`,"aria-hidden":`true`,children:[(0,J.jsx)(`span`,{}),(0,J.jsx)(`span`,{}),(0,J.jsx)(`span`,{})]}),(0,J.jsxs)(`div`,{className:`agent-office__plant`,"aria-hidden":`true`,children:[(0,J.jsx)(`span`,{}),(0,J.jsx)(`i`,{}),(0,J.jsx)(`b`,{})]}),(0,J.jsxs)(`div`,{className:`agent-office__desk-zone`,"aria-hidden":`true`,children:[(0,J.jsx)(Jt,{active:d,failed:f,role:h,variant:g.avatar,motion:g.motion}),(0,J.jsx)(`span`,{className:`agent-office__monitor`,children:c?(0,J.jsx)(qt,{kind:c.kind,active:s!==void 0}):(0,J.jsx)(z,{})}),(0,J.jsxs)(`span`,{className:`agent-office__activity-fx`,children:[(0,J.jsx)(`span`,{}),(0,J.jsx)(`i`,{}),(0,J.jsx)(`b`,{})]}),(0,J.jsx)(`span`,{className:`agent-office__desk`}),(0,J.jsx)(`span`,{className:`agent-office__desk-lamp`}),(0,J.jsxs)(`span`,{className:`agent-office__desk-clutter`,children:[(0,J.jsx)(`i`,{}),(0,J.jsx)(`b`,{})]}),(0,J.jsxs)(`span`,{className:V(`agent-office__desk-charm`,`is-${g.charm}`),children:[(0,J.jsx)(`i`,{}),(0,J.jsx)(`b`,{})]}),(0,J.jsxs)(`span`,{className:V(`agent-office__mug`,`is-${h}`),children:[(0,J.jsx)(`i`,{"aria-hidden":`true`}),(0,J.jsx)(`b`,{"aria-hidden":`true`})]})]}),_&&(0,J.jsx)(`div`,{className:V(`agent-office__mail-flyby`,`is-${p.direction}`),children:(0,J.jsx)(Xt,{mail:p,compact:!0,onSelect:()=>n({kind:`mail`,mail:p,agentName:a.name})},p.id)}),(0,J.jsxs)(`div`,{className:V(`agent-office__conveyor`,s&&`is-moving`),children:[(0,J.jsxs)(`div`,{className:`agent-office__belt`,"aria-hidden":`true`,children:[(0,J.jsx)(`span`,{}),(0,J.jsx)(`span`,{}),(0,J.jsx)(`span`,{}),(0,J.jsx)(`span`,{}),(0,J.jsx)(`span`,{}),(0,J.jsx)(`span`,{})]}),(0,J.jsx)(`div`,{className:`agent-office__current-action`,children:c?(0,J.jsx)(Yt,{call:c,onSelect:()=>n({kind:`tool`,call:c,agentName:a.name})},c.id):(0,J.jsx)($t,{active:d})})]})]}),(0,J.jsxs)(`div`,{className:`agent-office__history`,children:[(0,J.jsxs)(`div`,{className:`agent-office__history-heading`,children:[(0,J.jsx)(`span`,{children:i(`activity:agentOffice.recent`)}),y!==void 0&&(0,J.jsx)(`span`,{children:Vt(y,t)})]}),(0,J.jsx)(`div`,{className:`agent-office__history-list`,children:v.length>0?v.map(e=>(0,J.jsx)(Yt,{call:e,compact:!0,onSelect:()=>n({kind:`tool`,call:e,agentName:a.name})},`tool:${e.id}`)):(0,J.jsx)(`span`,{className:`agent-office__history-empty`,children:a.toolCalls>0&&a.recentTools===void 0&&a.activity===void 0?i(`activity:agentOffice.telemetryReconnect`):i(`activity:agentOffice.noCalls`)})})]})]})}function tn(e){return e.agent.status===`active`||e.agent.status===`streaming`||e.agent.status===`error`}function nn({agents:e,now:t,onSelect:n}){let{t:r}=N();return(0,J.jsxs)(`section`,{className:`agent-office__lounge`,"aria-label":r(`activity:agentOffice.breakRoom`),children:[(0,J.jsxs)(`header`,{className:`agent-office__lounge-heading`,children:[(0,J.jsx)(h,{"aria-hidden":`true`}),(0,J.jsx)(`strong`,{children:r(`activity:agentOffice.breakRoom`)}),(0,J.jsx)(`span`,{children:r(`activity:agentOffice.onBreak`,{count:e.length})})]}),(0,J.jsx)(`div`,{className:`agent-office__lounge-seats`,children:e.map(e=>{let{agent:i,history:a,mail:o}=e,s=Lt(i),c=It[s],l=o.filter(e=>e.unread).length,u=a[0]?.completedAt??a[0]?.startedAt,d=o[0],f=()=>{i.currentTask?n({kind:`task`,task:i.currentTask,taskId:i.taskId,agentName:i.name}):d&&n({kind:`mail`,mail:d,agentName:i.name})},p=!!i.currentTask||!!d;return(0,J.jsxs)(`button`,{type:`button`,className:V(`agent-office__lounge-seat`,`is-${s}`),onClick:f,disabled:!p,children:[(0,J.jsx)(`span`,{className:`agent-office__lounge-avatar`,children:(0,J.jsx)(c,{"aria-hidden":`true`})}),(0,J.jsxs)(`span`,{className:`agent-office__lounge-copy`,children:[(0,J.jsx)(`strong`,{children:i.name}),(0,J.jsx)(`small`,{children:i.role??r(`activity:agentOffice.agent`)})]}),(0,J.jsxs)(`span`,{className:`agent-office__lounge-meta`,children:[u!==void 0&&(0,J.jsx)(`span`,{children:Vt(u,t)}),l>0&&(0,J.jsxs)(`span`,{className:`agent-office__lounge-mail`,children:[(0,J.jsx)(C,{"aria-hidden":`true`}),` `,l]})]})]},e.key)})})]})}function rn(){let{t:e}=N(),t=Te(e=>e.liveSessions),n=Te(e=>e.aggregate),i=Ee(e=>e.agents),a=De(e=>e.agents),o=De(e=>e.messages),s=Se(e=>e.toolEvents),c=Ce(e=>e.projectName),l=jt(i),[d,f]=(0,U.useState)(null),p=(0,U.useMemo)(()=>Ot(t,i,a,l.map,l.now),[t,i,a,l]),g=(0,U.useMemo)(()=>p.flatMap(e=>e.agents.map(t=>{let n=Gt(nt(s,t.serverId,e.sessionId),Ze(t.recentTools,t.serverId,e.sessionId),Wt(t,e,i.get(t.serverId)?.toolLog??[])),r=t.status===`active`||t.status===`streaming`,a=n.find(e=>e.status===`running`);!a&&r&&t.currentTool&&(a=rt(t.serverId,t.currentTool,e.sessionId));let c=a??n[0],l=n.filter(e=>e.status!==`running`).slice(0,6),u=Kt(Qe(t.recentMail),tt(o,t,e.sessionId));return{key:t.officeId,client:e,agent:t,calls:n,current:a,display:c,history:l,mail:u}})),[p,i,o,s]),_=(0,U.useMemo)(()=>p.map(e=>{let t=g.filter(t=>t.client.id===e.id);return{client:e,agents:t,stats:Ut(t)}}).filter(e=>e.agents.length>0),[p,g]),v=g.filter(({agent:e})=>e.status===`active`||e.status===`streaming`).length,y=c||t.find(e=>e.projectName)?.projectName||e(`activity:office.fleetHq`),b=Date.now();return(0,J.jsxs)(`div`,{className:`agent-office`,children:[(0,J.jsxs)(`header`,{className:`agent-office__header`,children:[(0,J.jsxs)(`div`,{className:`agent-office__title`,children:[(0,J.jsx)(`span`,{className:`agent-office__brand-mark`,children:(0,J.jsx)(_e,{"aria-hidden":`true`})}),(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`span`,{children:e(`activity:agentOffice.liveProjectOffice`)}),(0,J.jsx)(`h1`,{children:y})]})]}),(0,J.jsxs)(`div`,{className:`agent-office__live-pill`,children:[(0,J.jsx)(`span`,{}),` LIVE`]}),(0,J.jsxs)(`div`,{className:`agent-office__summary`,children:[(0,J.jsxs)(`div`,{children:[(0,J.jsx)(P,{}),(0,J.jsx)(`strong`,{children:g.length}),(0,J.jsx)(`span`,{children:e(`activity:agentOffice.agents`)})]}),(0,J.jsxs)(`div`,{children:[(0,J.jsx)(R,{}),(0,J.jsx)(`strong`,{children:v}),(0,J.jsx)(`span`,{children:e(`activity:agentOffice.working`)})]}),(0,J.jsxs)(`div`,{children:[(0,J.jsx)(m,{}),(0,J.jsx)(`strong`,{children:n.toolCalls.toLocaleString()}),(0,J.jsx)(`span`,{children:e(`activity:agentOffice.toolCalls`)})]})]})]}),(0,J.jsx)(`main`,{className:`agent-office__floor`,children:g.length>0?_.map(t=>{let n=t.agents.filter(tn),r=t.agents.filter(e=>!tn(e)),i=$e(n,b),a=new Set(i.map(e=>e.id));return(0,J.jsxs)(`section`,{className:`agent-office__client-office`,children:[(0,J.jsx)(Zt,{office:t,now:b}),(0,J.jsx)(Qt,{office:t,now:b,onSelect:f}),n.length>0&&(0,J.jsxs)(`div`,{className:`agent-office__column-headings`,"aria-hidden":`true`,children:[(0,J.jsx)(`span`,{children:e(`activity:agentOffice.team`)}),(0,J.jsx)(`span`,{children:e(`activity:agentOffice.liveDesk`)}),(0,J.jsx)(`span`,{children:e(`activity:agentOffice.lastActions`)})]}),(0,J.jsxs)(`div`,{className:`agent-office__client-desks`,children:[n.map(e=>(0,J.jsx)(en,{model:e,now:b,onSelect:f,routedMailIds:a},e.key)),i.length>0&&(0,J.jsx)(`div`,{className:`agent-office__mail-routes`,"aria-hidden":`true`,children:i.map(e=>(0,J.jsx)(`div`,{className:`agent-office__mail-route`,style:{"--from":`${(e.fromIndex+.5)/n.length*100}%`,"--to":`${(e.toIndex+.5)/n.length*100}%`},children:(0,J.jsx)(`span`,{className:`agent-office__mail-route-parcel`,children:(0,J.jsx)(C,{"aria-hidden":`true`})})},e.id))}),n.length===0&&(0,J.jsxs)(`div`,{className:`agent-office__desks-empty`,children:[(0,J.jsx)(h,{"aria-hidden":`true`}),e(`activity:agentOffice.desksEmpty`)]})]}),r.length>0&&(0,J.jsx)(nn,{agents:r,now:b,onSelect:f})]},t.client.id)}):(0,J.jsxs)(`div`,{className:`agent-office__empty-state`,children:[(0,J.jsx)(`span`,{children:(0,J.jsx)(F,{"aria-hidden":`true`})}),(0,J.jsx)(`h2`,{children:e(`activity:agentOffice.readyTitle`)}),(0,J.jsx)(`p`,{children:e(`activity:agentOffice.readyBody`)})]})}),(0,J.jsxs)(`footer`,{className:`agent-office__footer`,children:[(0,J.jsxs)(`span`,{children:[(0,J.jsx)(`span`,{className:`agent-office__status-dot is-active`}),` `,e(`activity:agentOffice.liveEvent`)]}),(0,J.jsxs)(`span`,{children:[(0,J.jsx)(r,{}),` `,e(`activity:agentOffice.connectedSessions`,{count:t.length})]}),(0,J.jsxs)(`span`,{children:[(0,J.jsx)(u,{}),` `,e(`activity:agentOffice.detailHint`)]})]}),d&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`button`,{type:`button`,className:`agent-office__detail-backdrop`,onClick:()=>f(null),"aria-label":`Close tool details`}),(0,J.jsx)(ft,{selected:d,onClose:()=>f(null)})]})]})}function an(){let{t:e}=N(),{clientCounts:t,currentSession:n,totalAgents:r,activeAgents:i,aggregate:a}=Te(l(e=>({clientCounts:e.clientCounts,currentSession:e.currentSession,totalAgents:e.totalAgents,activeAgents:e.activeAgents,aggregate:e.aggregate}))),o=t.tui+t.webui+t.repl,s=e=>e?.toLocaleString()??`0`;return(0,J.jsxs)(`div`,{className:`absolute left-4 top-20 z-10 rounded-xl border border-border/70 bg-card/90 p-3 text-foreground shadow-xl backdrop-blur`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-2 mb-2`,children:[(0,J.jsx)(m,{className:`h-3.5 w-3.5 text-success`}),(0,J.jsx)(`span`,{className:`text-[10px] font-bold uppercase text-muted-foreground`,children:e(`activity:office.sessionStats`)})]}),(0,J.jsxs)(`div`,{className:`space-y-1.5 text-[10px]`,children:[(0,J.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,J.jsx)(B,{className:`h-3 w-3 text-muted-foreground`}),(0,J.jsx)(`span`,{className:`text-muted-foreground`,children:e(`activity:office.clients`)})]}),(0,J.jsxs)(`span`,{className:`font-mono text-foreground`,children:[i,` `,(0,J.jsx)(`span`,{className:`text-muted-foreground`,children:`/`}),` `,(0,J.jsx)(`span`,{className:`text-success`,children:o})]})]}),(0,J.jsxs)(`div`,{className:`flex items-center gap-3 pl-4 text-[9px]`,children:[t.tui>0&&(0,J.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,J.jsx)(c,{className:`h-2.5 w-2.5 text-success`}),(0,J.jsx)(`span`,{className:`text-muted-foreground`,children:`TUI`}),(0,J.jsx)(`span`,{className:`font-mono text-success`,children:t.tui})]}),t.webui>0&&(0,J.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,J.jsx)(y,{className:`h-2.5 w-2.5 text-primary`}),(0,J.jsx)(`span`,{className:`text-muted-foreground`,children:`WebUI`}),(0,J.jsx)(`span`,{className:`font-mono text-primary`,children:t.webui})]}),t.repl>0&&(0,J.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,J.jsx)(c,{className:`h-2.5 w-2.5 text-warning`}),(0,J.jsx)(`span`,{className:`text-muted-foreground`,children:`REPL`}),(0,J.jsx)(`span`,{className:`font-mono text-warning`,children:t.repl})]})]}),(0,J.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,J.jsx)(P,{className:`h-3 w-3 text-muted-foreground`}),(0,J.jsx)(`span`,{className:`text-muted-foreground`,children:e(`activity:officeMap.agents`)})]}),(0,J.jsxs)(`span`,{className:`font-mono text-foreground`,children:[i,` `,(0,J.jsx)(`span`,{className:`text-muted-foreground`,children:`/`}),` `,(0,J.jsx)(`span`,{className:`text-primary`,children:r})]})]}),n.model&&(0,J.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,J.jsx)(D,{className:`h-3 w-3 text-muted-foreground`}),(0,J.jsx)(`span`,{className:`text-muted-foreground`,children:e(`activity:officeMap.model`)})]}),(0,J.jsx)(`span`,{className:`max-w-[120px] truncate font-mono text-primary`,title:n.model,children:n.model.split(`/`).pop()?.slice(0,16)})]}),n.mode&&(0,J.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,J.jsx)(R,{className:`h-3 w-3 text-muted-foreground`}),(0,J.jsx)(`span`,{className:`text-muted-foreground`,children:e(`activity:officeMap.mode`)})]}),(0,J.jsx)(`span`,{className:V(`font-mono uppercase text-[9px] px-1.5 py-0.5 rounded`,n.mode===`auto`&&`bg-primary/10 text-primary`,n.mode===`suggest`&&`bg-success/10 text-success`,n.mode===`off`&&`bg-muted text-muted-foreground`,![`auto`,`suggest`,`off`].includes(n.mode||``)&&`bg-muted text-muted-foreground`),children:n.mode})]}),(0,J.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,J.jsx)(g,{className:`h-3 w-3 text-muted-foreground`}),(0,J.jsx)(`span`,{className:`text-muted-foreground`,children:e(`activity:office.toolCallsLabel`)})]}),(0,J.jsx)(`span`,{className:`font-mono text-warning`,children:s(a.toolCalls)})]}),(0,J.jsxs)(`div`,{className:`mt-1.5 space-y-1 border-t border-border/70 pt-1.5`,children:[(0,J.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,J.jsx)(`span`,{className:`text-[8px] text-muted-foreground`,children:`IN`}),(0,J.jsx)(`span`,{className:`text-muted-foreground`,children:e(`activity:office.input`)})]}),(0,J.jsx)(`span`,{className:`font-mono text-[9px] text-foreground`,children:s(a.tokensIn)})]}),(0,J.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,J.jsx)(`span`,{className:`text-[8px] text-muted-foreground`,children:`OUT`}),(0,J.jsx)(`span`,{className:`text-muted-foreground`,children:e(`activity:office.output`)})]}),(0,J.jsx)(`span`,{className:`font-mono text-[9px] text-foreground`,children:s(a.tokensOut)})]})]}),(0,J.jsxs)(`div`,{className:`mt-1.5 flex items-center justify-between gap-4 border-t border-border/70 pt-1.5`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,J.jsx)(ue,{className:`h-3 w-3 text-muted-foreground`}),(0,J.jsx)(`span`,{className:`text-muted-foreground`,children:e(`activity:office.cost`)})]}),(0,J.jsx)(`span`,{className:`font-mono font-medium text-success`,children:(e=>e==null?`$0.0000`:`$${e.toFixed(4)}`)(a.costUsd)})]})]})]})}function on({events:e,now:t}){let{t:n}=N(),r=e.slice(0,14);return(0,J.jsx)(`div`,{className:`absolute bottom-0 left-0 right-0 z-10 pointer-events-none px-3 pb-3`,children:(0,J.jsxs)(`div`,{className:`pointer-events-auto mx-auto max-w-3xl rounded-lg border border-border/70 bg-card/90 px-3 py-2 shadow-xl backdrop-blur`,children:[(0,J.jsxs)(`div`,{className:`mb-1.5 flex items-center gap-1.5 text-[10px] uppercase text-primary`,children:[(0,J.jsx)(m,{className:`h-3 w-3`}),n(`activity:office.liveActivity`)]}),r.length===0?(0,J.jsx)(`div`,{className:`text-[11px] italic text-muted-foreground`,children:n(`activity:office.waitingActivity`)}):(0,J.jsx)(`div`,{className:`flex flex-col gap-0.5 max-h-32 overflow-hidden`,children:r.map(e=>{let r=Math.max(0,Math.round((t-e.timestamp)/1e3));return(0,J.jsxs)(`div`,{className:`flex items-center gap-2 text-[11px] leading-tight`,children:[(0,J.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full shrink-0`,style:{backgroundColor:kt(e.kind)}}),(0,J.jsx)(`span`,{className:`flex-1 truncate text-foreground`,children:e.label}),(0,J.jsx)(`span`,{className:`shrink-0 tabular-nums text-muted-foreground`,children:r<1?n(`activity:office.now`):`${r}s`})]},e.id)})})]})})}function sn(e){if(e<1e3)return`${e}ms`;let t=Math.round(e/100);return t<600?`${(t/10).toFixed(1)}s`:`${Math.floor(t/600)}m ${Math.round(t%600/10)}s`}var cn={user:{Icon:be,labelKey:`activity:message.roleYou`,avatarBg:`bg-primary`,avatarColor:`text-primary-foreground`,avatarRing:`ring-2 ring-offset-2 ring-offset-background ring-primary/20`,bubbleBg:`bg-transparent`,bubbleBorder:`border-primary/40`,textColor:`text-foreground`},assistant:{Icon:P,labelKey:`activity:message.roleAssistant`,avatarBg:`bg-accent`,avatarColor:`text-accent-foreground`,avatarRing:`ring-2 ring-offset-2 ring-offset-background ring-accent/20`,bubbleBg:`bg-card`,bubbleBorder:`border-border`,textColor:`text-foreground`},tool:{Icon:c,labelKey:`activity:message.roleTool`,avatarBg:`bg-secondary`,avatarColor:`text-secondary-foreground`,avatarRing:`ring-2 ring-offset-2 ring-offset-background ring-secondary/20`,bubbleBg:`bg-muted/80`,bubbleBorder:`border-border`,textColor:`text-foreground`},system:{Icon:P,labelKey:`activity:transcript.kindSystem`,avatarBg:`bg-muted`,avatarColor:`text-muted-foreground`,avatarRing:`ring-2 ring-offset-2 ring-offset-background ring-muted/20`,bubbleBg:`bg-muted/50`,bubbleBorder:`border-border`,textColor:`text-muted-foreground`},error:{Icon:_,labelKey:`activity:transcript.kindError`,avatarBg:`bg-destructive`,avatarColor:`text-destructive-foreground`,avatarRing:`ring-2 ring-offset-2 ring-offset-background ring-destructive/20`,bubbleBg:`bg-destructive/5`,bubbleBorder:`border-destructive/20`,textColor:`text-destructive`}};function ln({entry:e}){let{t}=N();return e.role===`error`?(0,J.jsx)(Ae,{text:e.text}):e.role===`tool`?(0,J.jsxs)(`div`,{className:`flex flex-col gap-1.5 tool-details`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-1.5 text-sm font-medium text-foreground`,children:[(0,J.jsx)(c,{className:`h-3 w-3`}),(0,J.jsx)(`span`,{className:`font-mono`,children:e.tool??t(`activity:watch.toolFallback`)}),e.durationMs!==void 0&&(0,J.jsxs)(`span`,{className:`ml-auto text-[10px] text-muted-foreground font-normal tabular-nums`,children:[(0,J.jsx)(n,{className:`h-3 w-3 inline mr-0.5 align-text-bottom`}),sn(e.durationMs)]})]}),e.input!==void 0&&e.input!==null&&(0,J.jsx)(`div`,{className:`p-3 bg-muted/50 rounded-lg overflow-x-auto`,children:(0,J.jsx)(Ne,{input:e.input})}),e.output!==void 0&&e.output!==null?(0,J.jsx)(`div`,{className:`text-sm leading-relaxed markdown-content`,children:typeof e.output==`string`?(0,J.jsx)(Pe,{remarkPlugins:[Oe],rehypePlugins:ke,components:Me,children:e.output}):(0,J.jsx)(`pre`,{className:`whitespace-pre-wrap font-mono text-xs bg-card rounded-lg p-2 border border-border overflow-x-auto`,children:JSON.stringify(e.output,null,2)})}):e.text?(0,J.jsx)(`div`,{className:`text-sm leading-relaxed markdown-content`,children:(0,J.jsx)(Pe,{remarkPlugins:[Oe],rehypePlugins:ke,components:Me,children:e.text})}):null,e.isError&&(0,J.jsxs)(`div`,{className:`rounded-lg border border-destructive/30 bg-destructive/5 px-3 py-2`,children:[(0,J.jsx)(`span`,{className:`text-xs font-medium text-destructive`,children:t(`activity:watch.toolFailed`)}),e.text&&(0,J.jsx)(`pre`,{className:`mt-1 text-xs whitespace-pre-wrap text-destructive/80`,children:e.text})]})]}):(0,J.jsx)(`div`,{className:`text-sm leading-relaxed markdown-content`,children:(0,J.jsx)(Pe,{remarkPlugins:[Oe],rehypePlugins:ke,components:Me,children:e.text})})}function un({entry:e,isContinuation:t=!1}){let{t:n}=N(),r=cn[e.role],i=r.Icon;return(0,J.jsxs)(`div`,{className:`group flex gap-3 animate-message msg-bubble rounded-lg transition-shadow`,children:[t?(0,J.jsx)(`div`,{className:`flex-shrink-0 w-8`}):(0,J.jsx)(`div`,{className:V(`flex-shrink-0 w-8 h-8 rounded-full flex items-center justify-center`,r.avatarBg,r.avatarColor,r.avatarRing),children:(0,J.jsx)(i,{className:`h-4 w-4`})}),(0,J.jsxs)(`div`,{className:`flex flex-col gap-1.5 min-w-0 flex-1`,children:[!t&&(0,J.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,J.jsx)(`span`,{className:V(`text-xs font-medium`,r.textColor),children:e.role===`tool`&&e.tool?e.tool:n(r.labelKey)}),(0,J.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:new Date(e.ts).toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`})}),e.role===`tool`&&e.durationMs!==void 0&&(0,J.jsxs)(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:[`· `,sn(e.durationMs)]})]}),(0,J.jsx)(`div`,{className:V(`rounded-2xl px-4 py-3 border`,e.role===`user`&&`rounded-br-md`,e.role===`assistant`&&`rounded-bl-md`,e.role===`tool`&&`rounded-bl-sm`,e.role===`system`&&`rounded-bl-sm opacity-70`,e.role===`error`&&`rounded-bl-sm`,r.bubbleBg,r.bubbleBorder),children:(0,J.jsx)(`div`,{className:V(`text-sm leading-relaxed markdown-content`,r.textColor),children:(0,J.jsx)(ln,{entry:e})})}),e.text&&e.role!==`error`&&(0,J.jsx)(`div`,{className:`opacity-0 group-hover:opacity-100 transition-opacity`,children:(0,J.jsx)(je,{text:e.text,label:n(`common:action.copy`)})})]})]})}var dn=[`steer`,`ask`,`assign`,`note`],fn=2500;function pn({sessionId:e,limit:t=200}){let[n,r]=(0,U.useState)(null),{t:i}=N(),[a,o]=(0,U.useState)(null),[s,c]=(0,U.useState)(``),[l,u]=(0,U.useState)(!1),[d,p]=(0,U.useState)(null),[m,h]=(0,U.useState)(`steer`),[g,_]=(0,U.useState)(`high`),[v,y]=(0,U.useState)([]),[b,x]=(0,U.useState)(!1),S=(0,U.useRef)(null),C=(0,U.useRef)(!0),w=(0,U.useRef)(!0),T=Te(e=>e.liveSessions),E=(0,U.useMemo)(()=>T.find(t=>t.sessionId===e),[T,e]),D=(0,U.useMemo)(()=>{let e=E;return e?`${e.status}|${e.agents.map(e=>`${e.id}:${e.status}:${e.toolCalls??0}:${e.iterations??0}`).join(`,`)}`:``},[E]),ee=E?.status===`active`||(E?.agents.some(e=>e.status===`running`||e.status===`streaming`)??!1),O=(0,U.useMemo)(()=>{if(!E)return null;let e=E.agents.find(e=>e.status===`running`||e.status===`streaming`);return e?.currentTool?`🔧 ${e.currentTool}`:e?i(`activity:sessionWatch.working`,{name:e.name??e.id}):null},[E,i]),k=(0,U.useMemo)(()=>{if(!E)return null;let e=E.agents.find(e=>e.partialText&&(e.status===`streaming`||e.status===`running`))??E.agents.find(e=>e.partialText);return e?.partialText?{label:e.id===`leader`?i(`activity:sessionWatch.claude`):e.name||e.id,text:e.partialText}:null},[E,i]),A=(0,U.useCallback)(async()=>{try{let n=await fetch(`/api/sessions/${encodeURIComponent(e)}/events?limit=${t}`);if(!n.ok)throw Error(`HTTP ${n.status}`);let i=await n.json();w.current&&(r(i),o(null))}catch(e){w.current&&o(e instanceof Error?e.message:String(e))}},[e,t]),j=(0,U.useCallback)(async()=>{try{let t=await fetch(`/api/sessions/${encodeURIComponent(e)}/mailbox`);if(!t.ok)return;let n=await t.json();w.current&&Array.isArray(n.thread)&&y(n.thread)}catch{}},[e]);(0,U.useEffect)(()=>{w.current=!0,r(null),o(null),y([]),A(),j();let e=setInterval(()=>{document.hidden||(A(),j())},fn);return()=>{w.current=!1,clearInterval(e)}},[A,j]),(0,U.useEffect)(()=>{D&&A()},[D,A]),(0,U.useEffect)(()=>{C.current&&S.current&&(S.current.scrollTop=S.current.scrollHeight)},[n,k]);let te=()=>{let e=S.current;e&&(C.current=e.scrollHeight-e.scrollTop-e.clientHeight<40)},ne=async()=>{let t=s.trim();if(!(!t||l)){u(!0),p(null);try{let n=await fetch(`/api/sessions/${encodeURIComponent(e)}/message`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({text:t,type:m,priority:g})});if(!n.ok)throw Error(`HTTP ${n.status}`);c(``),p(ee?f.t(`activity:sessionWatch.sentRunning`):f.t(`activity:sessionWatch.sentIdle`)),j()}catch(e){p(f.t(`activity:sessionWatch.sentFailed`,{error:e instanceof Error?e.message:String(e)}))}finally{u(!1)}}},re=async()=>{if(!b){x(!0),p(null);try{let t=await fetch(`/api/sessions/${encodeURIComponent(e)}/interrupt`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({reason:f.t(`activity:sessionWatch.interruptReason`)})});if(!t.ok)throw Error(`HTTP ${t.status}`);p(f.t(`activity:sessionWatch.interruptSent`)),j()}catch(e){p(f.t(`activity:sessionWatch.interruptFailed`,{error:e instanceof Error?e.message:String(e)}))}finally{x(!1)}}},ie=n?.entries??[];return(0,J.jsxs)(`div`,{className:`flex h-full min-h-0 min-w-0 flex-col`,children:[(0,J.jsxs)(`div`,{className:`flex items-center justify-between mb-1.5 shrink-0`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[10px] uppercase tracking-wide text-muted-foreground`,children:[(0,J.jsx)(`span`,{className:V(`h-1.5 w-1.5 rounded-full`,ee?`bg-success animate-pulse`:`bg-muted-foreground`)}),i(`activity:sessionWatch.liveStream`)]}),(0,J.jsxs)(`div`,{className:`flex items-center gap-2`,children:[n&&(0,J.jsxs)(`div`,{className:`text-[10px] text-muted-foreground`,children:[i(`activity:sessionWatch.events`,{count:n.total}),` · `,n.status]}),ee&&(0,J.jsx)(`button`,{type:`button`,onClick:()=>void re(),disabled:b,title:i(`activity:sessionWatch.interruptTitle`),className:`rounded border border-destructive/40 bg-destructive/15 px-1.5 py-0.5 text-[10px] text-destructive hover:bg-destructive/25 disabled:opacity-40 transition-colors`,children:i(b?`activity:sessionWatch.interrupting`:`activity:sessionWatch.interrupt`)})]})]}),O&&(0,J.jsxs)(`div`,{className:`mb-1.5 shrink-0 text-[10px] text-foreground truncate`,children:[`▶ `,O]}),a&&(0,J.jsxs)(`div`,{className:`text-[11px] text-destructive mb-1 shrink-0`,children:[`· `,a]}),(0,J.jsxs)(`div`,{ref:S,onScroll:te,className:`min-h-0 min-w-0 flex-1 overflow-y-auto overscroll-contain space-y-1.5 pr-1`,children:[ie.length===0&&!a&&(0,J.jsx)(`div`,{className:`text-[11px] text-muted-foreground italic`,children:i(`activity:sessionWatch.loading`)}),ie.map((e,t)=>(0,J.jsx)(un,{entry:e,isContinuation:t>0&&ie[t-1].role===e.role},`${e.ts}-${t}`)),k&&(0,J.jsxs)(`div`,{className:`flex gap-3 animate-message`,children:[(0,J.jsx)(`div`,{className:`flex-shrink-0 w-8 h-8 rounded-full flex items-center justify-center bg-accent text-accent-foreground ring-2 ring-offset-2 ring-offset-background ring-accent/20`,children:(0,J.jsx)(P,{className:`h-4 w-4 animate-pulse`})}),(0,J.jsxs)(`div`,{className:`flex flex-col gap-1.5 max-w-[85%] min-w-0`,children:[(0,J.jsx)(`span`,{className:`text-xs font-medium text-muted-foreground px-1`,children:k.label}),(0,J.jsx)(`div`,{className:`rounded-2xl rounded-bl-md px-4 py-3 bg-card border border-border`,children:(0,J.jsxs)(`span`,{className:`text-sm leading-relaxed text-foreground whitespace-pre-wrap break-words`,children:[k.text,(0,J.jsx)(`span`,{className:`animate-pulse text-primary`,children:`▋`})]})})]})]})]}),v.length>0&&(0,J.jsxs)(`div`,{className:`mt-2 pt-2 border-t border-border shrink-0 max-h-28 overflow-y-auto space-y-1`,children:[(0,J.jsx)(`div`,{className:`text-[9px] uppercase tracking-wide text-muted-foreground`,children:i(`activity:mailbox.messages`)}),v.slice(-6).map(e=>{let t=e.completed?i(`activity:sessionWatch.done`):e.readByLeader?i(`activity:sessionWatch.read`):i(`activity:sessionWatch.delivered`);return(0,J.jsxs)(`div`,{className:`text-[10px] leading-snug`,children:[(0,J.jsx)(`span`,{className:V(`font-semibold mr-1.5`,e.fromLeader?`text-accent`:`text-primary`),children:e.fromLeader?i(`activity:sessionWatch.agent`):i(`activity:sessionWatch.you`)}),(0,J.jsx)(`span`,{className:`text-foreground whitespace-pre-wrap break-words`,children:e.body}),!e.fromLeader&&(0,J.jsx)(`span`,{className:V(`ml-1.5 text-[9px]`,e.completed?`text-success`:e.readByLeader?`text-primary`:`text-muted-foreground`),children:t})]},e.id)})]}),(0,J.jsxs)(`div`,{className:`mt-2 pt-2 border-t border-border shrink-0`,children:[(0,J.jsxs)(`div`,{className:`mb-1 flex items-center gap-1.5`,children:[(0,J.jsx)(`select`,{value:m,onChange:e=>h(e.target.value),title:i(`activity:sessionWatch.msgType.${m}Hint`),className:`rounded bg-muted border border-border px-1.5 py-0.5 text-[10px] text-foreground focus:outline-none focus:ring-1 focus:ring-ring`,children:dn.map(e=>(0,J.jsx)(`option`,{value:e,children:i(`activity:sessionWatch.msgType.${e}Label`)},e))}),(0,J.jsxs)(`select`,{value:g,onChange:e=>_(e.target.value),title:i(`activity:sessionWatch.priority`),className:`rounded bg-muted border border-border px-1.5 py-0.5 text-[10px] text-foreground focus:outline-none focus:ring-1 focus:ring-ring`,children:[(0,J.jsx)(`option`,{value:`high`,children:`high`}),(0,J.jsx)(`option`,{value:`normal`,children:`normal`}),(0,J.jsx)(`option`,{value:`low`,children:`low`})]})]}),(0,J.jsxs)(`div`,{className:`flex items-end gap-1.5`,children:[(0,J.jsx)(`textarea`,{value:s,onChange:e=>c(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.metaKey||e.ctrlKey)&&(e.preventDefault(),ne())},rows:2,placeholder:i(`activity:sessionWatch.placeholder`,{label:i(`activity:sessionWatch.msgType.${m}Label`)}),className:`flex-1 resize-none rounded-md bg-muted border border-border px-2 py-1 text-sm text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-ring`}),(0,J.jsx)(`button`,{type:`button`,onClick:()=>void ne(),disabled:l||!s.trim(),className:`shrink-0 rounded-md bg-primary text-primary-foreground px-2.5 py-1.5 text-xs hover:bg-primary/90 disabled:opacity-40 disabled:cursor-not-allowed transition-colors`,children:l?`…`:i(`activity:sessionWatch.send`)})]}),d&&(0,J.jsx)(`div`,{className:`mt-1 text-[10px] text-muted-foreground`,children:d}),(0,J.jsx)(`div`,{className:`mt-0.5 text-[9px] text-muted-foreground`,children:i(`activity:sessionWatch.sendHint`)})]})]})}var X={primary:`hsl(var(--primary))`,info:`hsl(var(--info))`,success:`hsl(var(--success))`,warning:`hsl(var(--warning))`,destructive:`hsl(var(--destructive))`,muted:`hsl(var(--muted-foreground))`},mn=.12;function hn(e){return Math.min(100,Math.max(0,e??0))}function Z({status:e,small:t,activity:n=0}){let r=t?`w-2 h-2`:`w-3 h-3`,i=t?4+n*4:6+n*6,a={idle:`bg-muted-foreground`,active:`bg-success`,streaming:`bg-primary`,completed:`bg-primary`,error:`bg-destructive`,offline:`bg-muted-foreground/60`},o={idle:X.muted,active:X.success,streaming:X.primary,completed:X.primary,error:X.destructive,offline:X.muted};return(0,J.jsx)(`span`,{className:V(`rounded-full`,r,n>0&&`animate-pulse`,a[e]),style:{boxShadow:n>0?`0 0 ${i}px ${o[e]}`:void 0}})}function Q(){let e={opacity:0,width:1,height:1,minWidth:0,border:`none`,background:`transparent`};return(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(L,{type:`target`,position:E.Top,style:e,isConnectable:!1}),(0,J.jsx)(L,{type:`source`,position:E.Bottom,style:e,isConnectable:!1})]})}function gn({data:e}){let{t}=N();return(0,J.jsxs)(`div`,{className:`mt-2 flex items-center justify-between border-t border-border/60 pt-1.5 text-[10px] text-muted-foreground`,children:[(0,J.jsxs)(`span`,{children:[(0,J.jsx)(`span`,{className:`font-mono text-foreground`,children:e.agentCount??0}),` `,t(`activity:office.agentsSuffix`)]}),e.startedAt&&(0,J.jsx)(`span`,{children:t(`activity:office.upPrefix`,{time:ht(e.startedAt,Date.now())})})]})}function _n({data:e}){let{t}=N(),n=e.status===`active`||e.status===`streaming`,r=e.status===`error`,i=e.status===`offline`,a=e.color||X.info;return(0,J.jsxs)(`div`,{className:V(`rounded-xl border-2 p-4 min-w-[180px] transition-all backdrop-blur-sm`,n&&`shadow-lg shadow-primary/15`,r&&`border-destructive/50 bg-destructive/10`,i&&`border-border/70 bg-muted/35 opacity-60`,!n&&!r&&!i&&`border-primary/30 bg-primary/10`),children:[(0,J.jsx)(Q,{}),(0,J.jsxs)(`div`,{className:`flex items-center gap-3 mb-3`,children:[(0,J.jsx)(`div`,{className:V(`flex items-center justify-center w-10 h-10 rounded-lg`,n?`bg-primary/15`:`bg-primary/10`),children:(0,J.jsx)(y,{className:`h-5 w-5`,style:{color:a}})}),(0,J.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,J.jsx)(`div`,{className:`text-xs font-bold truncate`,style:{color:a},children:e.label}),(0,J.jsx)(`div`,{className:`text-[10px] text-muted-foreground`,children:t(`activity:office.webuiClient`)})]}),(0,J.jsx)(Z,{status:e.status,activity:e.vizActivity??0})]}),e.sublabel&&(0,J.jsx)(`div`,{className:`mb-2 truncate text-[10px] text-muted-foreground`,children:e.sublabel}),(0,J.jsx)(`div`,{className:`flex items-center gap-2 text-[10px] text-muted-foreground`,children:i?(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(de,{className:`h-3 w-3 text-muted-foreground`}),(0,J.jsx)(`span`,{children:t(`activity:office.disconnected`)})]}):(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(F,{className:`h-3 w-3 text-success`}),(0,J.jsx)(`span`,{children:t(`activity:office.connected`)})]})}),n&&(0,J.jsx)(`div`,{className:`mt-2 h-1 overflow-hidden rounded-full bg-primary/20`,children:(0,J.jsx)(`div`,{className:`h-full animate-pulse bg-primary`,style:{width:`60%`}})}),(0,J.jsx)(gn,{data:e})]})}function vn({data:e}){let{t}=N(),n=e.status===`active`||e.status===`streaming`,r=e.status===`error`,i=e.color||X.success;return(0,J.jsxs)(`div`,{className:V(`rounded-xl border-2 p-4 min-w-[180px] transition-all backdrop-blur-sm`,n&&`shadow-lg shadow-success/15`,r&&`border-destructive/50 bg-destructive/10`,!n&&!r&&`border-success/30 bg-success/10`),children:[(0,J.jsx)(Q,{}),(0,J.jsxs)(`div`,{className:`flex items-center gap-3 mb-3`,children:[(0,J.jsx)(`div`,{className:V(`flex items-center justify-center w-10 h-10 rounded-lg`,n?`bg-success/15`:`bg-success/10`),children:(0,J.jsx)(c,{className:`h-5 w-5`,style:{color:i}})}),(0,J.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,J.jsx)(`div`,{className:`text-xs font-bold truncate`,style:{color:i},children:e.label}),(0,J.jsx)(`div`,{className:`text-[10px] text-muted-foreground`,children:t(`activity:office.tuiClient`)})]}),(0,J.jsx)(Z,{status:e.status,activity:e.vizActivity??0})]}),e.sublabel&&(0,J.jsx)(`div`,{className:`mb-2 truncate text-[10px] text-muted-foreground`,children:e.sublabel}),(0,J.jsxs)(`div`,{className:`flex items-center gap-2 text-[10px] text-muted-foreground`,children:[(0,J.jsx)(c,{className:`h-3 w-3 text-success`}),(0,J.jsx)(`span`,{children:t(`activity:office.terminal`)})]}),(0,J.jsx)(gn,{data:e})]})}function yn({data:e}){let{t}=N(),n=e.status===`active`||e.status===`streaming`,r=e.color||X.warning;return(0,J.jsxs)(`div`,{className:V(`rounded-xl border-2 p-4 min-w-[160px] transition-all backdrop-blur-sm`,n&&`shadow-lg shadow-warning/15`,!n&&`border-warning/30 bg-warning/10`),children:[(0,J.jsx)(Q,{}),(0,J.jsxs)(`div`,{className:`flex items-center gap-3 mb-3`,children:[(0,J.jsx)(`div`,{className:V(`flex items-center justify-center w-10 h-10 rounded-lg`,n?`bg-warning/15`:`bg-warning/10`),children:(0,J.jsx)(c,{className:`h-5 w-5`,style:{color:r}})}),(0,J.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,J.jsx)(`div`,{className:`text-xs font-bold truncate`,style:{color:r},children:e.label}),(0,J.jsx)(`div`,{className:`text-[10px] text-muted-foreground`,children:t(`activity:office.repl`)})]}),(0,J.jsx)(Z,{status:e.status,activity:e.vizActivity??0})]}),e.sublabel&&(0,J.jsx)(`div`,{className:`mb-1 truncate text-[10px] text-muted-foreground`,children:e.sublabel}),(0,J.jsx)(gn,{data:e})]})}function bn({data:e}){let{t}=N(),n=e.status===`active`||e.status===`streaming`,r=e.color||X.primary;return(0,J.jsxs)(`div`,{className:`relative min-w-[200px] rounded-xl border-2 border-border/70 bg-card/90 p-4 shadow-lg backdrop-blur-sm transition-all`,children:[(0,J.jsx)(Q,{}),(0,J.jsx)(`div`,{className:`absolute -top-3 left-1/2 -translate-x-1/2 rounded-full bg-primary px-2 py-0.5 text-[11px] font-bold text-primary-foreground`,children:t(`activity:office.coordinator`)}),(0,J.jsxs)(`div`,{className:`flex items-center gap-3 mb-3 mt-2`,children:[(0,J.jsx)(`div`,{className:V(`flex items-center justify-center w-12 h-12 rounded-xl`,n?`bg-primary/15`:`bg-primary/10`),children:(0,J.jsx)(D,{className:`h-6 w-6`,style:{color:r}})}),(0,J.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,J.jsx)(`div`,{className:`text-sm font-bold truncate`,style:{color:r},children:e.label}),(0,J.jsx)(`div`,{className:`text-[10px] text-muted-foreground`,children:e.sublabel||t(`activity:office.fleetSummary`)})]}),(0,J.jsx)(Z,{status:e.status,activity:e.vizActivity??0})]}),(0,J.jsxs)(`div`,{className:`grid grid-cols-2 gap-2 text-[10px] mb-2`,children:[(0,J.jsxs)(`div`,{className:`rounded bg-muted/40 p-1.5 text-center`,children:[(0,J.jsxs)(`div`,{className:`font-mono`,children:[(0,J.jsx)(`span`,{className:`text-success`,children:e.agentsActive||0}),(0,J.jsx)(`span`,{className:`text-muted-foreground`,children:` / `}),(0,J.jsx)(`span`,{className:`text-primary`,children:e.agentsTotal||0})]}),(0,J.jsx)(`div`,{className:`text-muted-foreground`,children:t(`activity:officeMap.agents`)})]}),(0,J.jsxs)(`div`,{className:`rounded bg-muted/40 p-1.5 text-center`,children:[(0,J.jsx)(`div`,{className:`font-mono text-warning`,children:(e.toolCalls||0).toLocaleString()}),(0,J.jsx)(`div`,{className:`text-muted-foreground`,children:t(`activity:office.toolCallsLabel`)})]}),(0,J.jsxs)(`div`,{className:`rounded bg-muted/40 p-1.5 text-center`,children:[(0,J.jsx)(`div`,{className:`font-mono text-foreground`,children:pt(e.tokensIn)}),(0,J.jsx)(`div`,{className:`text-muted-foreground`,children:t(`activity:office.tokensLabel`)})]}),(0,J.jsxs)(`div`,{className:`rounded bg-muted/40 p-1.5 text-center`,children:[(0,J.jsxs)(`div`,{className:`font-mono text-success`,children:[`$`,(e.costUsd||0).toFixed(3)]}),(0,J.jsx)(`div`,{className:`text-muted-foreground`,children:t(`activity:office.cost`)})]})]}),n&&(0,J.jsxs)(`div`,{className:`flex items-center gap-2 text-[10px] text-primary`,children:[(0,J.jsx)(`span`,{className:`h-2 w-2 animate-pulse rounded-full bg-primary`}),t(`activity:office.coordinatingFleet`)]})]})}function xn({data:e}){let{t}=N(),n=e.status===`active`||e.status===`streaming`,r=e.status===`error`,i=e.status===`completed`,a=e.color||X.primary,o=hn(e.ctxPct);return(0,J.jsxs)(`div`,{className:V(`w-[170px] min-w-0 max-w-[170px] overflow-hidden rounded-lg border p-3 transition-all backdrop-blur-sm`,n&&`border-primary/50 bg-primary/10 shadow-lg shadow-primary/10`,r&&`border-destructive/50 bg-destructive/10`,i&&`border-border/70 bg-muted/35`,!n&&!r&&!i&&`border-primary/30 bg-primary/10`),children:[(0,J.jsx)(Q,{}),(0,J.jsxs)(`div`,{className:`flex items-center gap-2 mb-1.5`,children:[(0,J.jsx)(P,{className:`h-4 w-4 shrink-0`,style:{color:a}}),(0,J.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,J.jsx)(`div`,{className:`text-[11px] font-bold truncate`,style:{color:a},children:e.label}),e.model&&(0,J.jsx)(`div`,{className:`truncate text-[10px] text-muted-foreground`,children:gt(e.model)})]}),(0,J.jsx)(Z,{status:e.status,small:!0,activity:e.vizActivity??0})]}),e.currentTask&&(0,J.jsxs)(`div`,{className:`mb-1.5 flex min-w-0 items-center gap-1 overflow-hidden text-[11px] text-primary`,children:[(0,J.jsx)(`span`,{className:V(`h-1.5 w-1.5 shrink-0 rounded-full bg-primary`,n&&`animate-pulse`)}),(0,J.jsx)(`span`,{className:`min-w-0 truncate font-mono`,title:e.currentTask,children:_t(e.currentTask,72)})]}),(0,J.jsxs)(`div`,{className:`grid grid-cols-2 gap-x-2 gap-y-0.5 text-[11px] mb-1.5`,children:[(0,J.jsxs)(`div`,{className:`flex justify-between`,children:[(0,J.jsx)(`span`,{className:`text-muted-foreground`,children:`iter`}),(0,J.jsx)(`span`,{className:`font-mono text-foreground`,children:e.iteration||0})]}),(0,J.jsxs)(`div`,{className:`flex justify-between`,children:[(0,J.jsx)(`span`,{className:`text-muted-foreground`,children:`tools`}),(0,J.jsx)(`span`,{className:`font-mono text-warning`,children:e.toolCalls||0})]}),(0,J.jsxs)(`div`,{className:`flex justify-between`,children:[(0,J.jsx)(`span`,{className:`text-muted-foreground`,children:`tok`}),(0,J.jsx)(`span`,{className:`font-mono text-foreground`,children:pt((e.tokensIn||0)+(e.tokensOut||0))})]}),(0,J.jsxs)(`div`,{className:`flex justify-between`,children:[(0,J.jsx)(`span`,{className:`text-muted-foreground`,children:`cost`}),(0,J.jsxs)(`span`,{className:`font-mono text-success`,children:[`$`,(e.costUsd||0).toFixed(3)]})]})]}),o>0&&(0,J.jsxs)(`div`,{className:`mb-1`,children:[(0,J.jsxs)(`div`,{className:`mb-0.5 flex justify-between text-[10px] text-muted-foreground`,children:[(0,J.jsx)(`span`,{children:`ctx`}),(0,J.jsxs)(`span`,{className:V(`font-mono`,o>=90?`text-destructive`:o>=70?`text-warning`:`text-muted-foreground`),children:[o,`%`]})]}),(0,J.jsx)(`div`,{className:`h-1 overflow-hidden rounded-full bg-muted`,children:(0,J.jsx)(`div`,{className:V(`h-full`,o>=90?`bg-destructive`:o>=70?`bg-warning`:`bg-primary`),style:{width:`${o}%`}})})]}),e.lastActivityAt&&(0,J.jsxs)(`div`,{className:V(`flex items-center gap-1 text-[10px]`,n?`text-muted-foreground/70`:`text-muted-foreground`),children:[i&&(0,J.jsx)(`span`,{className:`text-success`,children:t(`activity:office.donePrefix`)}),r&&(0,J.jsx)(`span`,{className:`text-destructive`,children:t(`activity:office.failedPrefix`)}),(0,J.jsx)(`span`,{children:t(`activity:office.seenPrefix`,{time:mt(e.lastActivityAt,Date.now())})})]})]})}function Sn({data:e}){let{t}=N();return(0,J.jsxs)(`div`,{className:V(`rounded-lg border border-dashed p-3 min-w-[120px] transition-all opacity-40`,`border-border/70 bg-muted/30`),children:[(0,J.jsx)(Q,{}),(0,J.jsxs)(`div`,{className:`flex items-center gap-2 mb-2`,children:[(0,J.jsx)(p,{className:`h-4 w-4 text-muted-foreground`}),(0,J.jsx)(`div`,{className:`flex-1 min-w-0`,children:(0,J.jsx)(`div`,{className:`truncate text-[10px] text-muted-foreground`,children:e.label})}),(0,J.jsx)(Z,{status:e.status,small:!0,activity:e.vizActivity??0})]}),(0,J.jsx)(`div`,{className:`text-[11px] text-muted-foreground`,children:t(`activity:office.availableDesk`)})]})}function Cn({data:e}){let{t}=N(),n=e.color||X.warning,r=(e.unreadCount||0)>0;return(0,J.jsxs)(`div`,{className:V(`rounded-xl border-2 p-4 min-w-[160px] transition-all backdrop-blur-sm`,r&&`border-warning/50 bg-warning/10 shadow-lg shadow-warning/10`,!r&&`border-warning/30 bg-warning/6`),children:[(0,J.jsx)(Q,{}),(0,J.jsxs)(`div`,{className:`flex items-center gap-3 mb-3`,children:[(0,J.jsx)(`div`,{className:V(`flex items-center justify-center w-10 h-10 rounded-lg`,r?`bg-warning/18`:`bg-warning/10`),children:(0,J.jsx)(C,{className:`h-5 w-5`,style:{color:n}})}),(0,J.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,J.jsx)(`div`,{className:`text-xs font-bold`,style:{color:n},children:t(`activity:office.mailboxHub`)}),(0,J.jsx)(`div`,{className:`text-[10px] text-muted-foreground`,children:r?t(`activity:office.unreadSuffix`,{count:e.unreadCount||0}):t(`activity:office.allClear`)})]}),r&&(0,J.jsx)(`div`,{className:`flex h-5 w-5 items-center justify-center rounded-full bg-warning text-[10px] font-bold text-background`,children:e.unreadCount})]}),(0,J.jsxs)(`div`,{className:`grid grid-cols-2 gap-2 text-[10px]`,children:[(0,J.jsxs)(`div`,{className:`rounded bg-muted/40 p-1.5 text-center`,children:[(0,J.jsxs)(`div`,{className:`flex items-center justify-center gap-1 text-warning`,children:[(0,J.jsx)(oe,{className:`h-3 w-3`}),(0,J.jsx)(`span`,{children:e.messageCount||0})]}),(0,J.jsx)(`div`,{className:`text-muted-foreground`,children:t(`activity:office.total`)})]}),(0,J.jsxs)(`div`,{className:`rounded bg-muted/40 p-1.5 text-center`,children:[(0,J.jsxs)(`div`,{className:`flex items-center justify-center gap-1 text-success`,children:[(0,J.jsx)(xe,{className:`h-3 w-3`}),(0,J.jsx)(`span`,{children:e.unreadCount||0})]}),(0,J.jsx)(`div`,{className:`text-muted-foreground`,children:t(`activity:office.unreadLabel`)})]})]}),e.sublabel&&(0,J.jsxs)(`div`,{className:`mt-2 truncate border-t border-border/60 pt-1.5 text-[11px] text-muted-foreground`,children:[`✉ `,e.sublabel]})]})}var wn={webui:_n,tui:vn,repl:yn,coordinator:bn,agent:xn,mailbox:Cn,desk:Sn};function $({k:e,v:t,accent:n}){return(0,J.jsxs)(`div`,{className:`flex justify-between gap-3`,children:[(0,J.jsx)(`span`,{className:`text-muted-foreground shrink-0`,children:e}),(0,J.jsx)(`span`,{className:V(`font-mono truncate text-right`,n??`text-foreground/80`),children:t})]})}function Tn({selectedNode:e,selectedAgentTranscript:t,mailboxMessages:n,onClose:r,onOpenWatch:i}){let{t:a}=N(),o=e.data,s=Date.now(),l=o.kind===`agent`,u=o.kind===`webui`||o.kind===`tui`||o.kind===`repl`,d=(o.tokensIn||0)+(o.tokensOut||0),f=hn(o.ctxPct);return(0,J.jsxs)(`div`,{className:V(`absolute top-20 right-4 bg-background border border-border rounded-lg p-4 shadow-xl z-20`,o.kind===`agent`?`w-[28rem] max-w-[calc(100%-2rem)]`:o.sessionId?`w-80`:`w-64`),children:[(0,J.jsxs)(`div`,{className:`flex items-center justify-between mb-3`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-2`,children:[o.kind===`webui`&&(0,J.jsx)(y,{className:`h-4 w-4 text-info`}),o.kind===`tui`&&(0,J.jsx)(c,{className:`h-4 w-4 text-success`}),o.kind===`coordinator`&&(0,J.jsx)(D,{className:`h-4 w-4 text-primary`}),o.kind===`agent`&&(0,J.jsx)(P,{className:`h-4 w-4 text-primary`}),o.kind===`mailbox`&&(0,J.jsx)(C,{className:`h-4 w-4 text-warning`}),(0,J.jsx)(`span`,{className:`text-sm font-bold text-foreground`,children:o.label})]}),(0,J.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[o.sessionId&&(0,J.jsx)(`button`,{type:`button`,title:a(`activity:office.openFullView`),onClick:()=>i({sessionId:o.sessionId,label:o.label}),className:`text-muted-foreground hover:text-primary`,children:(0,J.jsx)(T,{className:`h-3.5 w-3.5`})}),(0,J.jsx)(`button`,{type:`button`,onClick:r,className:`text-muted-foreground hover:text-foreground text-lg leading-none`,children:`×`})]})]}),(0,J.jsxs)(`div`,{className:`space-y-1.5 text-xs`,children:[(0,J.jsx)($,{k:`Status`,v:String(o.status).toUpperCase(),accent:V(o.status===`active`&&`text-success`,o.status===`streaming`&&`text-primary`,o.status===`error`&&`text-destructive`,o.status===`idle`&&`text-muted-foreground`,o.status===`offline`&&`text-muted-foreground/70`)}),l&&(0,J.jsxs)(J.Fragment,{children:[o.model&&(0,J.jsx)($,{k:`Model`,v:gt(o.model),accent:`text-primary`}),o.currentTask&&(0,J.jsxs)(`div`,{className:`pt-1`,children:[(0,J.jsx)(`div`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground`,children:a(`activity:agentOffice.currentTask`)}),(0,J.jsx)(`div`,{className:`mt-1 max-h-32 overflow-y-auto whitespace-pre-wrap break-words font-mono text-[10px] text-primary`,children:o.currentTask})]}),(0,J.jsx)($,{k:`Iterations`,v:o.iteration||0,accent:`text-primary`}),(0,J.jsx)($,{k:`Tool calls`,v:o.toolCalls||0,accent:`text-warning`}),(0,J.jsx)($,{k:`Tokens in`,v:pt(o.tokensIn)}),(0,J.jsx)($,{k:`Tokens out`,v:pt(o.tokensOut)}),(0,J.jsx)($,{k:`Tokens total`,v:pt(d)}),f>0&&(0,J.jsx)($,{k:`Context`,v:`${f}%`,accent:f>=90?`text-destructive`:f>=70?`text-warning`:`text-foreground/70`}),(0,J.jsx)($,{k:`Cost`,v:`$${(o.costUsd||0).toFixed(4)}`,accent:`text-success`}),o.lastActivityAt&&(0,J.jsx)($,{k:`Last seen`,v:mt(o.lastActivityAt,s),accent:`text-muted-foreground`}),(0,J.jsx)(`div`,{className:`pt-2`,children:(0,J.jsx)(Fe,{entries:t,agentName:o.label,compact:!0,maxHeightClassName:`max-h-64`})})]}),u&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)($,{k:`Surface`,v:xt(o.kind),accent:`text-foreground/80`}),o.branch&&(0,J.jsx)($,{k:`Branch`,v:`⎇ ${o.branch}`,accent:`text-foreground/70`}),o.pid!=null&&(0,J.jsx)($,{k:`PID`,v:o.pid}),o.workingDir&&(0,J.jsx)($,{k:`Dir`,v:o.workingDir,accent:`text-muted-foreground`}),(0,J.jsx)($,{k:`Agents`,v:o.agentCount??0,accent:`text-primary`}),o.startedAt&&(0,J.jsx)($,{k:`Uptime`,v:ht(o.startedAt,s),accent:`text-foreground/70`})]}),o.kind===`mailbox`&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)($,{k:`Total messages`,v:o.messageCount||0,accent:`text-warning`}),(0,J.jsx)($,{k:`Unread`,v:o.unreadCount||0,accent:`text-warning`}),n.length>0&&(0,J.jsxs)(`div`,{className:`mt-1 space-y-1 border-t border-border pt-2`,children:[(0,J.jsx)(`div`,{className:`text-[10px] uppercase tracking-wide text-muted-foreground`,children:a(`activity:office.recent`)}),[...n].sort((e,t)=>Date.parse(t.timestamp)-Date.parse(e.timestamp)).slice(0,6).map(e=>(0,J.jsxs)(`div`,{className:`flex items-start gap-1.5 text-[10px]`,children:[(0,J.jsx)(`span`,{className:V(`mt-1 h-1.5 w-1.5 shrink-0 rounded-full`,!e.completed&&(e.readByCount??0)===0?`bg-warning`:e.completed?`bg-success`:`bg-muted`)}),(0,J.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,J.jsx)(`div`,{className:`truncate text-foreground/80`,children:e.subject||a(`activity:office.noSubject`)}),(0,J.jsxs)(`div`,{className:`truncate font-mono text-[9px] text-muted-foreground`,children:[e.from,` → `,e.to,` · `,mt(e.timestamp,s),e.audience===`leaders`?` · ${a(`activity:mailbox.audienceLeaders`)}`:``]})]})]},e.id))]})]}),o.kind===`coordinator`&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)($,{k:`Connections`,v:o.connections||0,accent:`text-primary`}),(0,J.jsx)($,{k:`Iterations`,v:o.iteration||0,accent:`text-primary`})]}),(l||u)&&o.sessionId&&(0,J.jsx)(`div`,{className:`mt-2 border-t border-border pt-2 h-72`,children:(0,J.jsx)(pn,{sessionId:o.sessionId})})]})]})}var En={wire:({sourceX:e,sourceY:t,targetX:n,targetY:r,sourcePosition:i,targetPosition:a,data:o,selected:s})=>{let c=o?.color||X.primary,l=H(e=>e.animateEdges),u=o?.animated&&l?Math.max(.15,o?.intensity??.6):0,[d,f,p]=ye({sourceX:e,sourceY:t,sourcePosition:i??E.Bottom,targetX:n,targetY:r,targetPosition:a??E.Top,curvature:.28}),m=5+u*7,h=5+u*4,g=m+h,_=`${Math.max(.5,1.6-u).toFixed(2)}s`;return(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`path`,{d,fill:`none`,stroke:c,strokeWidth:s?2.5:1.4,strokeOpacity:s?.9:.28,className:`react-flow__edge-path`}),u>.05&&(0,J.jsx)(`path`,{d,fill:`none`,stroke:c,strokeWidth:2.2,strokeOpacity:.45+u*.5,strokeDasharray:`${m} ${h}`,strokeLinecap:`round`,style:{filter:`drop-shadow(0 0 ${2+u*4}px ${c})`},children:(0,J.jsx)(`animate`,{attributeName:`stroke-dashoffset`,from:g,to:`0`,dur:_,repeatCount:`indefinite`})}),o?.label&&u>.1&&(0,J.jsx)(fe,{children:(0,J.jsx)(`div`,{style:{position:`absolute`,transform:`translate(-50%, -50%) translate(${f}px, ${p}px)`},className:`pointer-events-none max-w-[220px] truncate whitespace-nowrap rounded-full border border-border/70 bg-card/90 px-1.5 py-0.5 text-[8px] font-medium text-foreground backdrop-blur-sm`,children:o.label})})]})}};function Dn(){let{t:e}=N();return(0,J.jsxs)(J.Fragment,{children:[(0,J.jsxs)(`div`,{className:`absolute bottom-4 left-4 z-10 rounded-lg border border-border/70 bg-card/90 p-3 text-[10px] shadow-xl backdrop-blur`,children:[(0,J.jsx)(`div`,{className:`mb-2 font-bold text-foreground`,children:e(`activity:office.legendStatus`)}),(0,J.jsxs)(`div`,{className:`space-y-1`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,J.jsx)(`span`,{className:`h-2 w-2 animate-pulse rounded-full bg-success`}),(0,J.jsx)(`span`,{className:`text-muted-foreground`,children:e(`activity:office.legendActive`)})]}),(0,J.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,J.jsx)(`span`,{className:`h-2 w-2 rounded-full bg-muted-foreground`}),(0,J.jsx)(`span`,{className:`text-muted-foreground`,children:e(`activity:office.legendIdle`)})]}),(0,J.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,J.jsx)(`span`,{className:`h-2 w-2 animate-pulse rounded-full bg-destructive`}),(0,J.jsx)(`span`,{className:`text-muted-foreground`,children:e(`activity:office.legendError`)})]})]})]}),(0,J.jsxs)(`div`,{className:`absolute bottom-4 right-4 z-10 rounded-lg border border-border/70 bg-card/90 p-3 text-[10px] shadow-xl backdrop-blur`,children:[(0,J.jsx)(`div`,{className:`mb-2 font-bold text-foreground`,children:e(`activity:office.legendConnections`)}),(0,J.jsxs)(`div`,{className:`space-y-1`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,J.jsx)(`span`,{className:`text-warning`,children:`✉`}),(0,J.jsx)(`span`,{className:`text-muted-foreground`,children:e(`activity:office.legendMail`)})]}),(0,J.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,J.jsx)(`span`,{className:`text-primary`,children:`→`}),(0,J.jsx)(`span`,{className:`text-muted-foreground`,children:e(`activity:office.legendTask`)})]}),(0,J.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,J.jsx)(`span`,{className:`text-success`,children:`●`}),(0,J.jsx)(`span`,{className:`text-muted-foreground`,children:e(`activity:office.legendStatusConn`)})]})]})]})]})}function On({draft:e,isSending:t,result:n,onClose:r,onDraftChange:i,onSend:a}){let{t:o}=N();return(0,J.jsxs)(`div`,{className:`absolute right-4 top-16 z-30 w-80 rounded-xl border border-warning/35 bg-card/95 p-3 shadow-2xl backdrop-blur`,children:[(0,J.jsxs)(`div`,{className:`mb-1.5 flex items-center justify-between`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[11px] font-semibold text-warning`,children:[(0,J.jsx)(oe,{className:`h-3.5 w-3.5`}),` `,o(`activity:office.broadcastToAll`)]}),(0,J.jsx)(`button`,{type:`button`,onClick:r,className:`text-base leading-none text-muted-foreground hover:text-foreground`,children:`×`})]}),(0,J.jsx)(`textarea`,{value:e,onChange:e=>i(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.metaKey||e.ctrlKey)&&(e.preventDefault(),a())},rows:3,placeholder:o(`activity:office.broadcastPlaceholder`),className:`w-full resize-none rounded-md border border-border/70 bg-background/70 px-2 py-1 text-[11px] text-foreground placeholder:text-muted-foreground focus:border-warning/45 focus:outline-none`}),(0,J.jsxs)(`div`,{className:`mt-1.5 flex items-center justify-between`,children:[(0,J.jsx)(`span`,{className:`text-[9px] text-muted-foreground`,children:o(`activity:office.broadcastSendHint`)}),(0,J.jsx)(`button`,{type:`button`,onClick:a,disabled:t||!e.trim(),className:`rounded-md border border-warning/35 bg-warning/12 px-2.5 py-1 text-[11px] text-warning transition-colors hover:bg-warning/18 disabled:cursor-not-allowed disabled:opacity-40`,children:t?`…`:o(`activity:office.broadcast`)})]}),n&&(0,J.jsx)(`div`,{className:`mt-1 text-[10px] text-muted-foreground`,children:n})]})}function kn({broadcastOpen:e,labels:t,onArrange:n,onBroadcastToggle:r,onFeedToggle:i,showFeed:a}){return(0,J.jsxs)(se,{position:`top-right`,className:`flex items-center gap-2`,children:[(0,J.jsxs)(`button`,{type:`button`,onClick:n,title:t.arrangeTitle,className:`flex items-center gap-1.5 rounded-md border border-border/70 bg-card/90 px-2.5 py-1.5 text-xs text-foreground shadow-sm transition-colors hover:bg-accent`,children:[(0,J.jsx)(he,{className:`h-3.5 w-3.5`}),t.arrange]}),(0,J.jsxs)(`button`,{type:`button`,onClick:i,title:t.feedTitle,className:V(`flex items-center gap-1.5 px-2.5 py-1.5 rounded-md border text-xs transition-colors`,a?`border-primary/35 bg-primary/10 text-primary`:`border-border/70 bg-card/90 text-muted-foreground hover:bg-accent hover:text-foreground`),children:[(0,J.jsx)(pe,{className:`h-3.5 w-3.5`}),t.feed]}),(0,J.jsxs)(`button`,{type:`button`,onClick:r,title:t.broadcastTitle,className:V(`flex items-center gap-1.5 px-2.5 py-1.5 rounded-md border text-xs transition-colors`,e?`border-warning/35 bg-warning/10 text-warning`:`border-border/70 bg-card/90 text-muted-foreground hover:bg-accent hover:text-foreground`),children:[(0,J.jsx)(oe,{className:`h-3.5 w-3.5`}),t.broadcast]})]})}function An(){return(0,J.jsx)(k,{className:`rounded-lg border border-border/70 bg-card/90`,nodeColor:e=>{switch(e.data.kind){case`coordinator`:return X.primary;case`webui`:return X.info;case`tui`:return X.success;case`repl`:case`mailbox`:return X.warning;default:return X.primary}},maskColor:`hsl(var(--background) / 0.72)`})}function jn({closeTitle:e,label:t,onClose:n,sessionId:r,streamTitle:i}){return(0,J.jsxs)(`div`,{className:`absolute inset-y-0 right-0 z-30 flex w-[min(680px,92%)] flex-col border-l border-border bg-background shadow-2xl`,children:[(0,J.jsxs)(`div`,{className:`flex items-center justify-between border-b border-border px-4 py-2.5 shrink-0 bg-card`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,J.jsx)(P,{className:`h-4 w-4 text-primary shrink-0`}),(0,J.jsxs)(`div`,{className:`min-w-0`,children:[(0,J.jsx)(`div`,{className:`truncate text-sm font-bold text-foreground`,children:t}),(0,J.jsx)(`div`,{className:`text-[10px] uppercase tracking-wide text-muted-foreground`,children:i})]})]}),(0,J.jsx)(`button`,{type:`button`,onClick:n,title:e,className:`text-muted-foreground hover:text-foreground text-xl leading-none shrink-0`,children:`×`})]}),(0,J.jsx)(`div`,{className:`flex-1 min-h-0 p-4`,children:(0,J.jsx)(pn,{sessionId:r,limit:500})})]})}function Mn(){let{t:e}=N(),{fitView:t}=ie(),n=(0,U.useRef)(null),[r,i]=(0,U.useState)({width:1280,height:720});(0,U.useEffect)(()=>{let e=n.current;if(!e)return;let t=()=>{let{width:t,height:n}=e.getBoundingClientRect();t<1||n<1||i(e=>Math.abs(e.width-t)<2&&Math.abs(e.height-n)<2?e:{width:t,height:n})};t();let r=new ResizeObserver(t);return r.observe(e),()=>r.disconnect()},[]);let a=Se(e=>e.events),o=Ee(e=>e.agents),s=Ee(e=>e.agentTranscripts),c=Ee(e=>e.leaderId),l=Te(e=>e.liveSessions),u=De(e=>e.messages),d=De(e=>e.agents),f=Ce(e=>e.session),p=jt(o),m=(0,U.useMemo)(()=>Ot(l,o,d,p.map,p.now),[l,o,d,p]),h=H(e=>e.showHud),g=H(e=>e.showLegend),_=H(e=>e.showMinimap),v=H(e=>e.showControls),y=H(e=>e.showFeed),b=H(e=>e.setShowFeed),x=H(e=>e.background),[S,C,w]=le([]),[T,E,D]=me([]),[O,k]=(0,U.useState)(null),[j,te]=(0,U.useState)(null),[re,oe]=(0,U.useState)(!1),[M,se]=(0,U.useState)(``),[ce,ue]=(0,U.useState)(!1),[de,fe]=(0,U.useState)(null),P=(0,U.useMemo)(()=>{if(O?.data.kind!==`agent`)return we;let e=O.data.serverId??(O.id.includes(`__agent-`)?O.id.split(`__agent-`).pop():O.id.replace(/^agent-/,``));return e?s.get(e)??we:we},[s,O]),pe=(0,U.useCallback)(async()=>{let e=M.trim();if(!(!e||ce)){ue(!0),fe(null);try{let t=await fetch(`/api/fleet/broadcast`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({text:e})});if(!t.ok)throw Error(`HTTP ${t.status}`);let n=await t.json();se(``),fe(`Delivered to ${n.delivered??0}/${n.targets??0} session(s)`)}catch(e){fe(`Failed: ${e instanceof Error?e.message:String(e)}`)}finally{ue(!1)}}},[M,ce]),he=(0,U.useRef)(new Map),F=4e3,I=(0,U.useRef)(new Map),L=(0,U.useRef)(new Map),ve=(0,U.useRef)(new Map),R=(0,U.useRef)(new Map),ye=(0,U.useRef)(``);(0,U.useEffect)(()=>{let n=[],i=[],a=Date.now(),s=vt(m.map(e=>({id:e.id,agentCount:e.agents.length})),r),l=u.filter(e=>!e.completed&&(e.readByCount??0)===0).length,d=u.length?[...u].sort((e,t)=>Date.parse(t.timestamp)-Date.parse(e.timestamp))[0]:void 0;n.push({id:`mailbox`,type:`mailbox`,position:{x:830,y:50},data:{label:e(`activity:office.mailboxHub`),kind:`mailbox`,status:l>0?`active`:`idle`,unreadCount:l,messageCount:u.length,sublabel:d?`${d.from} → ${d.to}: ${d.subject}`:void 0,color:X.warning}});let f=0,p=0,h=0,g=0,_=0;for(let e of m)for(let t of e.agents)p+=1,(t.status===`active`||t.status===`streaming`)&&(f+=1),h+=t.toolCalls,g+=t.costUsd,_+=t.tokensIn+t.tokensOut;let v=c?o.get(c):null,y=f>0;n.push({id:`coordinator`,type:`coordinator`,position:{x:370,y:50},data:{label:e(`activity:office.fleetHqLabel`),sublabel:e(`activity:office.clientsSuffix`,{count:m.length}),kind:`coordinator`,status:v?.status===`failed`?`error`:y?`active`:`idle`,connections:m.length,agentsActive:f,agentsTotal:p,toolCalls:h,costUsd:g,tokensIn:_,color:X.primary}});let b={tui:X.success,webui:X.info,repl:X.warning};for(let t of m){let r=s.positions.get(t.id)??{x:600,y:370},o=r.x,c=r.y,u=b[t.type],d=t.status===`active`;if(n.push({id:t.id,type:t.type,position:{x:o,y:c},data:{label:t.label,sublabel:t.sublabel,kind:t.type,status:t.status,sessionId:t.sessionId,pid:t.pid,branch:t.branch,workingDir:t.workingDir,startedAt:t.startedAt,agentCount:t.agents.length,color:u}}),i.push({id:`${t.id}->coordinator`,source:t.id,target:`coordinator`,type:`wire`,animated:d,data:{color:u,animated:d,label:e(`activity:office.controlLabel`),flowType:`task`}}),i.push({id:`mailbox->${t.id}`,source:`mailbox`,target:t.id,type:`wire`,animated:l>0,data:{color:X.warning,animated:l>0,label:l>0?`${l}`:void 0,flowType:`mail`}}),t.agents.length===0){n.push({id:`desk-${t.id}`,type:`desk`,position:{x:o,y:c+270},data:{label:e(`activity:office.idleDesk`),kind:`agent`,status:`idle`,color:X.muted}});continue}t.agents.forEach((r,s)=>{let l=r.status===`active`||r.status===`streaming`,u=R.current.get(r.serverId);if(u&&(r.toolCalls>u.toolCalls||r.iteration>u.iteration)||l){he.current.set(r.officeId,a+F);let e=L.current.get(r.officeId)??0;L.current.set(r.officeId,Math.min(1,e+(1-e)*.5));for(let e of[`${t.id}->${r.officeId}`,`${t.id}->coordinator`]){let t=I.current.get(e)??0;I.current.set(e,Math.min(1,t+.5))}}R.current.set(r.serverId,{toolCalls:r.toolCalls,iteration:r.iteration}),n.push({id:r.officeId,type:`agent`,position:yt(o,s,t.agents.length,c+270),data:{label:r.name,kind:`agent`,status:r.status,serverId:r.serverId,sessionId:t.sessionId,currentTask:r.currentTask,iteration:r.iteration,toolCalls:r.toolCalls,costUsd:r.costUsd,tokensIn:r.tokensIn,tokensOut:r.tokensOut,ctxPct:r.ctxPct,model:r.model,lastActivityAt:r.lastActivityAt,color:X.primary}}),i.push({id:`${t.id}->${r.officeId}`,source:t.id,target:r.officeId,type:`wire`,animated:l,data:{color:X.primary,animated:l,label:l?_t(r.currentTask,48)??e(`activity:office.taskFallback`):void 0,flowType:`task`}})})}let x=new Set(m.flatMap(e=>e.agents.map(e=>e.serverId)));for(let e of[...R.current.keys()])x.has(e)||R.current.delete(e);let S=n.map(e=>{let t=he.current.get(e.id),n=L.current.get(e.id)??0;return t&&t>a&&e.data.status!==`error`&&e.data.status!==`offline`?{...e,data:{...e.data,status:`active`,vizActivity:n}}:{...e,data:{...e.data,vizActivity:n}}}),w=i.map(e=>{let t=I.current.get(e.id)??0;return t>.05?{...e,animated:!0,data:{...e.data,animated:!0,intensity:t}}:e}),T=new Map;for(let e of S)T.set(e.id,{...e.position});ve.current=T,C(S),E(w);let D=[`${Math.round(r.width)}x${Math.round(r.height)}`,`${s.columns}x${s.rows}`,m.map(e=>`${e.id}:${e.agents.length}`).join(`|`),S.map(e=>e.id).sort().join(`|`)].join(`:`);if(D!==ye.current){ye.current=D;let e=setTimeout(()=>t({padding:mn,duration:300}),50);return()=>clearTimeout(e)}},[m,c,o,u,f,r,F,C,E,t]);let z=m.flatMap(e=>e.agents.map(t=>({clientId:e.id,clientType:e.type,officeId:t.officeId,serverId:t.serverId}))),be=m.map(e=>e.id),xe=new Map;for(let e of z)(!xe.has(e.serverId)||e.clientType===`webui`)&&xe.set(e.serverId,e.officeId);function B(e){return xe.get(e)??`agent-${e}`}function V(e){let t=e.split(`__agent-`)[0];return t&&t!==e?`${t}->${e}`:`coordinator->${e}`}function Oe(e){switch(e.kind){case`mailbox:send`:case`mailbox:deliver`:return{nodes:[`mailbox`],edges:e.kind===`mailbox:send`?be.map(e=>`mailbox->${e}`):[],status:`active`};case`agent:spawned`:{let t=B(e.source);return{nodes:[`coordinator`,t],edges:[V(t)],status:`active`}}case`agent:tool`:case`tool:started`:case`tool:progress`:{let t=B(e.source);return{nodes:[`coordinator`,t],edges:[V(t)],status:e.kind===`tool:progress`||e.kind===`tool:started`?`streaming`:`active`}}case`tool:executed`:{let t=B(e.target??e.source);return{nodes:[t],edges:[V(t)],status:`active`}}case`provider:call`:case`provider:delta`:case`provider:response`:return{nodes:[`coordinator`],edges:[],status:e.kind===`provider:delta`?`streaming`:`active`};case`iteration:start`:case`iteration:end`:return{nodes:[`coordinator`],edges:z.map(e=>V(e.officeId)),status:e.kind===`iteration:start`?`streaming`:`active`};case`agent:text`:{let t=B(e.source);return{nodes:[t],edges:[V(t)],status:`streaming`}}case`agent:status`:{let t=B(e.source);return{nodes:[`coordinator`,t],edges:[V(t)],status:e.data&&typeof e.data==`object`&&`status`in e.data&&String(e.data.status)===`failed`?`error`:`completed`}}case`agent:ctx`:return{nodes:[B(e.source)],edges:[],status:`active`};case`budget:extended`:return{nodes:[`coordinator`,B(e.source)],edges:[],status:`active`};case`context:compacted`:case`context:repaired`:return{nodes:[`coordinator`],edges:[],status:`active`};case`error`:return{nodes:e.source?[B(e.source)]:[],edges:[],status:`error`};case`cost:update`:return{nodes:[`coordinator`],edges:[],status:`active`};case`fleet:snapshot`:{let t=e.data?.sessions??[],n=[`coordinator`];for(let e of t)if(e.agents)for(let t of e.agents){let e=B(t.id);n.includes(e)||n.push(e)}return{nodes:n,edges:[],status:`active`}}default:return{nodes:[],edges:[],status:`idle`}}}(0,U.useEffect)(()=>{if(a.length===0)return;let e=a[0];if(!e)return;let{nodes:t,edges:n,status:r}=Oe(e),i=Date.now();t.length>0&&(t.forEach(e=>{he.current.set(e,i+F);let t=L.current.get(e)??0;L.current.set(e,Math.min(1,t+(1-t)*.5))}),C(e=>e.map(e=>t.includes(e.id)?{...e,data:{...e.data,status:r,vizActivity:L.current.get(e.id)??0}}:e))),n.length>0&&(n.forEach(e=>{let t=I.current.get(e)??0;I.current.set(e,Math.min(1,t+.5))}),E(e=>e.map(e=>n.includes(e.id)?{...e,animated:!0,data:{...e.data,animated:!0,intensity:I.current.get(e.id)??1}}:e)))},[a,C,E,F,o]),(0,U.useEffect)(()=>{let e=setInterval(()=>{let e=new Map,t=!1;for(let[n,r]of I.current){let i=r*.85;i<.05?(I.current.delete(n),e.set(n,{intensity:0,animated:!1}),t=!0):(I.current.set(n,i),e.set(n,{intensity:i,animated:!0}),t=!0)}t&&E(t=>t.map(t=>{let n=e.get(t.id);return n?{...t,animated:n.animated,data:{...t.data,animated:n.animated,intensity:n.intensity}}:t}));let n=new Map,r=!1;for(let[e,t]of L.current){let i=t*.9;i<.03?(L.current.delete(e),n.set(e,0),r=!0):(L.current.set(e,i),n.set(e,i),r=!0)}r&&C(e=>e.map(e=>{let t=n.get(e.id);return t===void 0?e:{...e,data:{...e.data,vizActivity:t}}}))},1e3);return()=>clearInterval(e)},[E,C]);let ke=(0,U.useCallback)(e=>E(t=>A({...e,type:`wire`},t)),[E]),Ae=(0,U.useCallback)((e,t)=>{k(t)},[]),je=(0,U.useCallback)(()=>{k(null)},[]);(0,U.useEffect)(()=>{if(!j)return;let e=e=>{e.key===`Escape`&&te(null)};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[j]);let Me=(0,U.useCallback)(()=>{C(e=>e.map(e=>{let t=ve.current.get(e.id);return t?{...e,position:{...t}}:e})),setTimeout(()=>t({padding:mn,duration:300}),50)},[C,t]),[,Ne]=(0,U.useState)(0);return(0,U.useEffect)(()=>{let e=setInterval(()=>{document.hidden||Ne(e=>e+1)},2e3);return()=>clearInterval(e)},[]),(0,J.jsxs)(`div`,{ref:n,className:`relative h-full w-full overflow-hidden bg-[hsl(var(--surface-2)/0.55)]`,children:[(0,J.jsx)(`div`,{className:`absolute inset-0 opacity-[0.03]`,style:{backgroundImage:`
2
- linear-gradient(rgba(255,255,255,0.1) 1px, transparent 1px),
3
- linear-gradient(90deg, rgba(255,255,255,0.1) 1px, transparent 1px)
4
- `,backgroundSize:`40px 40px`}}),h&&(0,J.jsx)(an,{}),(0,J.jsx)(`div`,{className:`absolute top-3 left-1/2 -translate-x-1/2 z-10`,children:(0,J.jsx)(`div`,{className:`rounded-lg border border-border/70 bg-card/90 px-4 py-2 shadow-xl backdrop-blur`,children:(0,J.jsxs)(`div`,{className:`flex items-center gap-2 text-xs font-bold text-foreground`,children:[(0,J.jsx)(_e,{className:`h-4 w-4 text-primary`}),e(`activity:office.fleetHq`),(0,J.jsx)(`span`,{className:`ml-2 h-2 w-2 animate-pulse rounded-full bg-success`}),(0,J.jsx)(`span`,{className:`text-[10px] font-normal text-muted-foreground`,children:e(`activity:office.live`)})]})})}),g&&(0,J.jsx)(Dn,{}),(0,J.jsxs)(ne,{nodes:S,edges:T,onNodesChange:w,onEdgesChange:D,onConnect:ke,onNodeClick:Ae,onPaneClick:je,nodeTypes:wn,edgeTypes:En,fitView:!0,fitViewOptions:{padding:mn},minZoom:.15,maxZoom:1.5,defaultEdgeOptions:{type:`wire`},proOptions:{hideAttribution:!0},children:[(0,J.jsx)(kn,{broadcastOpen:re,labels:{arrange:e(`activity:office.arrange`),arrangeTitle:e(`activity:office.arrangeTitle`),broadcast:e(`activity:office.broadcast`),broadcastTitle:e(`activity:office.broadcastTitle`),feed:e(`activity:office.feed`),feedTitle:e(`activity:office.feedTitle`)},onArrange:Me,onBroadcastToggle:()=>oe(e=>!e),onFeedToggle:()=>b(!y),showFeed:y}),x!==`none`&&(0,J.jsx)(ge,{variant:x===`lines`?ae.Lines:x===`cross`?ae.Cross:ae.Dots,gap:20,size:1,color:`hsl(var(--border) / 0.35)`}),v&&(0,J.jsx)(ee,{className:`rounded-lg border border-border/70 bg-card/90 [&>button]:bg-card [&>button]:text-foreground`}),_&&(0,J.jsx)(An,{})]}),y&&(0,J.jsx)(on,{events:a,now:Date.now()}),re&&(0,J.jsx)(On,{draft:M,isSending:ce,result:de,onClose:()=>oe(!1),onDraftChange:se,onSend:()=>void pe()}),O&&(0,J.jsx)(Tn,{selectedNode:O,selectedAgentTranscript:P,mailboxMessages:u,onClose:je,onOpenWatch:te}),j&&(0,J.jsx)(jn,{closeTitle:e(`activity:office.closeEsc`),label:j.label,onClose:()=>te(null),sessionId:j.sessionId,streamTitle:e(`activity:office.fullOperationStream`)})]})}function Nn(){let{t:e}=N(),t=H(e=>e.viewMode),n=H(e=>e.setViewMode),r=[{id:`office`,label:e(`activity:agentOffice.office`),description:e(`activity:agentOffice.officeDescription`),icon:d},{id:`topology`,label:e(`activity:agentOffice.topology`),description:e(`activity:agentOffice.topologyDescription`),icon:s}],i=(e,t)=>{let i;if(e.key===`ArrowLeft`&&(i=(t-1+r.length)%r.length),e.key===`ArrowRight`&&(i=(t+1)%r.length),e.key===`Home`&&(i=0),e.key===`End`&&(i=r.length-1),i===void 0)return;e.preventDefault();let a=r[i];a&&(n(a.id),e.currentTarget.parentElement?.querySelectorAll(`[role="tab"]`)[i]?.focus())};return(0,J.jsxs)(`div`,{className:`flex h-full min-h-0 w-full flex-col bg-background`,children:[(0,J.jsx)(`nav`,{"aria-label":`${e(`activity:agentOffice.office`)} / ${e(`activity:agentOffice.topology`)}`,className:`relative z-[60] shrink-0 border-b border-border bg-card/95 px-3 pt-2 shadow-[0_8px_28px_hsl(var(--shadow-color)/0.1)] backdrop-blur-xl sm:px-5`,children:(0,J.jsx)(`div`,{role:`tablist`,"aria-orientation":`horizontal`,className:`mx-auto grid w-full max-w-3xl grid-cols-2 gap-1`,children:r.map((e,r)=>{let a=e.icon,o=t===e.id;return(0,J.jsxs)(`button`,{id:`office-map-tab-${e.id}`,type:`button`,role:`tab`,"aria-selected":o,"aria-controls":`office-map-view-panel`,tabIndex:o?0:-1,onClick:()=>n(e.id),onKeyDown:e=>i(e,r),className:V(`group relative flex min-w-0 items-center gap-2.5 border-b-2 px-3 py-2.5 text-left transition-all duration-200 sm:gap-3 sm:px-5`,o?`border-primary bg-primary/[0.07] text-foreground`:`border-transparent text-muted-foreground hover:border-border hover:bg-accent/60 hover:text-foreground`),children:[(0,J.jsx)(`span`,{className:V(`grid h-8 w-8 shrink-0 place-items-center rounded-lg border transition-colors`,o?`border-primary/35 bg-primary/15 text-primary`:`border-border bg-background/70 text-muted-foreground group-hover:text-foreground`),children:(0,J.jsx)(a,{className:`h-4 w-4`,"aria-hidden":`true`})}),(0,J.jsxs)(`span`,{className:`min-w-0`,children:[(0,J.jsx)(`strong`,{className:`block truncate font-display text-xs font-semibold sm:text-sm`,children:e.label}),(0,J.jsx)(`small`,{className:`hidden truncate font-mono text-[9px] font-normal text-muted-foreground sm:block`,children:e.description})]}),(0,J.jsx)(`span`,{"aria-hidden":`true`,className:V(`ml-auto h-1.5 w-1.5 shrink-0 rounded-full transition-all`,o?`bg-primary shadow-[0_0_0_4px_hsl(var(--primary)/0.12)]`:`bg-border`)})]},e.id)})})}),(0,J.jsx)(`div`,{id:`office-map-view-panel`,role:`tabpanel`,"aria-labelledby":`office-map-tab-${t}`,className:`relative min-h-0 flex-1`,children:t===`office`?(0,J.jsx)(rn,{}):(0,J.jsx)(ve,{children:(0,J.jsx)(Mn,{})})})]})}export{Nn as OfficeMapPanel};
@@ -1,2 +0,0 @@
1
- import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{Bt as t,Ct as n,Di as r,Dn as i,Et as a,Gt as o,Ia as s,Ln as c,Ni as l,Nt as u,Ot as d,Pa as f,Pt as p,Sn as m,Ta as h,Un as g,Ut as _,Vi as v,Wt as y,Xi as b,Yi as ee,Yn as te,_i as ne,dt as x,fn as S,in as C,ja as w,jr as T,jt as E,lt as D,nr as O,oa as k,pn as re,qi as ie,qr as A,ui as j,ut as M,va as ae,xt as N}from"./vendor-CxV3l5PQ.js";import"./i18n-DxnYsmc-.js";import{n as P}from"./ui-store-C4Ybfoon.js";import{t as oe}from"./useWebSocket-x8PMoTq8.js";import{t as F}from"./utils-_s0GyctV.js";import{a as I,o as L,u as R}from"./stores-BS-Bdi-5.js";import{o as z}from"./view-navigation-DLdE7qHU.js";import{a as B,i as V,n as H,o as U,r as W,t as G}from"./dialog-DsCmc6eL.js";import{t as K}from"./button-DwmC7ENW.js";import{n as se,t as ce}from"./ModelPicker-BxYMTEEN.js";import{c as le,s as ue}from"./index-Bf75VrDE.js";import{a as q,c as de,i as J,l as Y,n as fe,o as pe,r as me,s as X,t as he,u as ge}from"./progress-ring-C0O73ZjR.js";import{SpecsView as _e}from"./SpecsView-BYiJr__T.js";var Z=e(s(),1),Q=D();function ve({feed:e,now:t}){let{t:n}=w();return(0,Q.jsxs)(`div`,{className:`flex h-full min-h-0 min-w-0 flex-col`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-1.5 border-b border-border px-3 py-2 text-xs font-semibold text-foreground`,children:[(0,Q.jsx)(h,{className:`h-3.5 w-3.5 text-warning`}),n(`activity:sdd.activityHeading`)]}),(0,Q.jsx)(`div`,{className:`min-h-0 min-w-0 flex-1 space-y-1 overflow-auto overscroll-contain p-2`,children:e.length===0?(0,Q.jsx)(`p`,{className:`px-1 pt-4 text-center text-[11px] text-muted-foreground`,children:n(`activity:sdd.feedEmpty`)}):e.map((e,n)=>{let r=J[e.kind]??J.started,i=r.icon;return(0,Q.jsxs)(`div`,{className:F(`sdd-rise flex items-start gap-2 rounded-md px-2 py-1.5 text-[11px]`,n===0?`bg-muted`:`hover:bg-muted`),children:[(0,Q.jsx)(i,{className:F(`mt-0.5 h-3.5 w-3.5 shrink-0`,r.color)}),(0,Q.jsx)(`span`,{className:`flex-1 leading-snug text-foreground`,children:e.text}),(0,Q.jsx)(`span`,{className:`shrink-0 tabular-nums text-[10px] text-muted-foreground`,children:X(e.ts,t)})]},`${e.ts}-${n}`)})})]})}function ye({open:e,onOpenChange:t,snapshot:n,busy:r,onConfirm:i}){let{t:a}=w(),o=n?.mergedCommits?.length??0,s=n?.baseBranch,[c,l]=(0,Z.useState)(!1);(0,Z.useEffect)(()=>{e&&l(!1)},[e]);let u=n?.status===`running`||n?.status===`paused`,f=(0,Z.useMemo)(()=>{let e=new Set;for(let t of n?.tasks??[])t.worktreeBranch&&e.add(t.worktreeBranch);return e.size},[n?.tasks]),p=(0,Z.useMemo)(()=>{let e=new Set;for(let t of n?.tasks??[])t.displayStatus===`in_progress`&&t.agentName&&e.add(t.agentName);return e.size},[n?.tasks]);return(0,Q.jsx)(G,{open:e,onOpenChange:e=>!r&&t(e),children:(0,Q.jsxs)(H,{className:`sm:max-w-lg border-destructive/50`,children:[(0,Q.jsxs)(B,{children:[(0,Q.jsxs)(U,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(E,{className:`h-5 w-5 text-destructive`}),a(`activity:sdd.destroyTitle`)]}),(0,Q.jsx)(W,{children:a(`activity:sdd.destroyDesc`)})]}),(0,Q.jsxs)(`ul`,{className:`space-y-1.5 py-1 text-sm`,children:[u&&(0,Q.jsxs)(`li`,{className:`flex items-start gap-2`,children:[(0,Q.jsx)(`span`,{className:`mt-0.5 text-destructive`,children:`■`}),(0,Q.jsx)(`span`,{children:p>0?a(`activity:sdd.stopRunAgents`,{count:p}):a(`activity:sdd.stopRun`)})]}),(0,Q.jsxs)(`li`,{className:`flex items-start gap-2`,children:[(0,Q.jsx)(`span`,{className:`mt-0.5 text-destructive`,children:`■`}),(0,Q.jsx)(`span`,{children:f>0?a(`activity:sdd.removeWorktreesCount`,{count:f}):a(`activity:sdd.removeWorktreesAll`)})]}),(0,Q.jsxs)(`li`,{className:`flex items-start gap-2`,children:[(0,Q.jsx)(`span`,{className:`mt-0.5 text-destructive`,children:`■`}),(0,Q.jsx)(`span`,{children:a(`activity:sdd.deleteArtifacts`)})]})]}),o>0&&(0,Q.jsxs)(`label`,{className:`flex cursor-pointer items-start gap-2 rounded-md border border-warning/30 bg-warning/5 p-2.5 text-sm`,children:[(0,Q.jsx)(`input`,{type:`checkbox`,checked:c,onChange:e=>l(e.target.checked),className:`mt-0.5 h-4 w-4 accent-warning`}),(0,Q.jsxs)(`span`,{children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:a(`activity:sdd.revertMerged`,{count:o})}),` `,`on `,(0,Q.jsx)(`code`,{className:`text-xs`,children:s??a(`activity:sdd.baseBranchFallback`)}),(0,Q.jsx)(`span`,{className:`block text-xs text-muted-foreground`,children:a(`activity:sdd.revertHint`)})]})]}),(0,Q.jsxs)(`div`,{className:`flex items-start gap-2 rounded-md bg-muted/50 p-2 text-xs text-muted-foreground`,children:[(0,Q.jsx)(d,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-warning`}),a(o>0&&!c?`activity:sdd.noteLeaveMerged`:`activity:sdd.noteAbandon`)]}),(0,Q.jsxs)(V,{className:`gap-2 sm:gap-2`,children:[(0,Q.jsx)(K,{variant:`outline`,size:`sm`,disabled:r,onClick:()=>t(!1),children:a(`common:action.cancel`)}),(0,Q.jsx)(K,{size:`sm`,disabled:r,onClick:()=>i(c),className:`bg-destructive text-destructive-foreground hover:bg-destructive/90`,children:r?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(O,{className:`mr-1 h-3.5 w-3.5 animate-spin`}),` `,a(`activity:sdd.destroying`)]}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(E,{className:`mr-1 h-3.5 w-3.5`}),` `,a(`activity:sdd.destroyAll`)]})})]})]})})}var be=[{key:`pending`,labelKey:`kanbanBacklog`,accent:`border-border/70`,head:`text-muted-foreground`},{key:`queued`,labelKey:`kanbanReady`,accent:`border-primary/35`,head:`text-primary`},{key:`in_progress`,labelKey:`kanbanRunning`,accent:`border-warning/45`,head:`text-warning`},{key:`review`,labelKey:`kanbanReview`,accent:`border-primary/35`,head:`text-primary`},{key:`failed`,labelKey:`kanbanFailed`,accent:`border-destructive/35`,head:`text-destructive`},{key:`completed`,labelKey:`kanbanDone`,accent:`border-success/35`,head:`text-success`}];function xe({tasks:e,selectedId:t,onTaskClick:n}){let{t:r}=w(),i=(0,Z.useMemo)(()=>{let t=new Map;for(let e of be)t.set(e.key,[]);for(let n of e){let e=n.displayStatus===`blocked`?`pending`:n.displayStatus===`cancelled`?`failed`:n.displayStatus;(t.get(e)??t.get(`pending`))?.push(n)}return t},[e]);return(0,Q.jsx)(`div`,{className:`flex h-full min-h-0 min-w-0 gap-3 overflow-x-auto p-4`,children:be.map(e=>{let a=i.get(e.key)??[];return(0,Q.jsxs)(`div`,{className:`flex min-h-0 w-64 shrink-0 flex-col`,children:[(0,Q.jsxs)(`div`,{className:F(`mb-2 flex items-center gap-2 border-b-2 pb-1.5`,e.accent),children:[(0,Q.jsx)(`span`,{className:F(`text-xs font-bold uppercase tracking-wide`,e.head),children:r(`activity:sdd.${e.labelKey}`)}),(0,Q.jsx)(`span`,{className:`rounded-full bg-muted px-1.5 text-[10px] text-muted-foreground`,children:a.length})]}),(0,Q.jsxs)(`div`,{className:`min-h-0 flex-1 space-y-2 overflow-y-auto overscroll-contain pr-1`,children:[a.map(e=>(0,Q.jsx)(Se,{task:e,selected:e.id===t,onClick:()=>n(e.id)},e.id)),a.length===0&&(0,Q.jsx)(`div`,{className:`rounded-md border border-dashed border-border py-6 text-center text-[10px] text-muted-foreground`,children:r(`activity:sdd.kanbanEmpty`)})]})]},e.key)})})}function Se({task:e,selected:t,onClick:n}){let r=e.displayStatus===`in_progress`;return(0,Q.jsxs)(`button`,{type:`button`,onClick:n,className:F(`sdd-node-enter w-full rounded-lg border bg-card/85 p-2 text-left shadow-sm transition hover:border-primary/35 hover:bg-accent/35`,t?`border-primary/55 ring-1 ring-primary/35`:`border-border/70`,r&&`sdd-node-running`,e.displayStatus===`completed`&&`sdd-node-complete`,e.displayStatus===`failed`&&`sdd-node-failed`),children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[r&&(0,Q.jsx)(O,{className:`h-3 w-3 animate-spin text-warning`}),e.displayStatus===`completed`&&(0,Q.jsx)(b,{className:`h-3 w-3 text-success`}),e.displayStatus===`failed`&&(0,Q.jsx)(x,{className:`h-3 w-3 text-destructive`}),(0,Q.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:e.shortId}),(0,Q.jsx)(`span`,{className:F(`ml-auto rounded px-1.5 text-[9px] font-bold uppercase`,Y(e.priority).chip),children:e.priority})]}),(0,Q.jsx)(`p`,{className:`mt-1 line-clamp-2 text-[11px] leading-snug text-foreground`,children:e.title}),(e.agentName||e.worktreeBranch||e.retries)&&(0,Q.jsxs)(`div`,{className:`mt-1.5 flex items-center gap-1.5`,children:[e.agentName&&(0,Q.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,Q.jsx)(`span`,{className:F(`flex h-4 w-4 items-center justify-center rounded-full text-[8px] font-bold text-white`,r?`bg-warning sdd-agent-live`:`bg-muted-foreground`),children:pe(e.agentName)}),(0,Q.jsx)(`span`,{className:`max-w-[80px] truncate text-[10px] text-muted-foreground`,children:e.agentName})]}),e.retries?(0,Q.jsxs)(`span`,{className:`flex items-center gap-0.5 text-[9px] text-destructive`,children:[(0,Q.jsx)(S,{className:`h-2.5 w-2.5`}),e.retries]}):null,e.worktreeBranch&&(0,Q.jsx)(T,{className:`ml-auto h-2.5 w-2.5 text-muted-foreground`})]})]})}function Ce({task:e,allTasks:i,feed:a,now:o,expanded:s,modelCandidates:c,defaultModel:l,onClose:u,onToggleExpanded:d,onRetry:f,onReassign:p,onSetModel:m,onSetVerification:h,onCancel:v,onDelete:y,onSplit:ee,onSelectTask:ne}){let{t:C}=w(),D=ge(e.displayStatus),O=D.icon,k=e.displayStatus===`in_progress`,re=e.displayStatus===`pending`||e.displayStatus===`blocked`||e.displayStatus===`queued`,[ie,A]=(0,Z.useState)(!1),[j,M]=(0,Z.useState)(``),[N,P]=(0,Z.useState)(null),[oe,I]=(0,Z.useState)(!1),[L,R]=(0,Z.useState)(``),[z,B]=(0,Z.useState)(!1),[V,H]=(0,Z.useState)(e.verificationCommand??``),U=()=>{j.trim()&&(p(e.id,j.trim()),A(!1),M(``))},W=()=>{let t=L.split(`
2
- `).map(e=>e.trim()).filter(Boolean).map(e=>{let[t,...n]=e.split(`::`),r=(t??``).trim();return{title:r,description:n.join(`::`).trim()||r}}).filter(e=>e.title);t.length&&(ee(e.id,t),I(!1),R(``))},G=(0,Z.useMemo)(()=>new Map(i.map(e=>[e.shortId,e])),[i]),K=(0,Z.useMemo)(()=>i.filter(t=>t.deps.includes(e.shortId)),[i,e.shortId]),se=(0,Z.useMemo)(()=>a.filter(t=>t.taskId===e.id||t.taskShortId===e.shortId),[a,e.id,e.shortId]),le=e.startedAt&&!e.completedAt?de(o-e.startedAt):e.startedAt&&e.completedAt?de(e.completedAt-e.startedAt):null;return(0,Q.jsxs)(`div`,{className:`sdd-rise flex h-full min-h-0 min-w-0 flex-col`,children:[(0,Q.jsxs)(`div`,{className:F(`flex items-center gap-2 border-b border-border/70 bg-card/70 px-3 py-2`,s&&`px-5 py-3`),children:[(0,Q.jsx)(`button`,{type:`button`,onClick:u,className:`text-muted-foreground hover:text-foreground`,title:C(`activity:sddTask.backTitle`),children:(0,Q.jsx)(ae,{className:`h-4 w-4`})}),(0,Q.jsx)(`span`,{className:`font-mono text-xs text-muted-foreground`,children:e.shortId}),d&&(0,Q.jsx)(`button`,{type:`button`,onClick:d,className:`ml-1 inline-flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground transition hover:bg-muted hover:text-foreground`,title:C(s?`activity:sddTask.collapseTitle`:`activity:sddTask.expandTitle`),"aria-label":C(s?`activity:sddTask.collapseTitle`:`activity:sddTask.expandTitle`),"aria-pressed":s,children:s?(0,Q.jsx)(g,{className:`h-4 w-4`}):(0,Q.jsx)(te,{className:`h-4 w-4`})}),(0,Q.jsxs)(`span`,{className:F(`ml-auto flex items-center gap-1 rounded-full border px-2 py-0.5 text-[11px]`,D.ring,D.text),children:[(0,Q.jsx)(O,{className:F(`h-3 w-3`,k&&`animate-spin`)}),D.label]})]}),(0,Q.jsxs)(`div`,{className:F(`min-h-0 min-w-0 flex-1 overflow-auto overscroll-contain`,s?`grid grid-cols-2 content-start gap-4 p-5`:`space-y-3 p-3`),children:[(0,Q.jsx)(`h3`,{className:F(`text-sm font-semibold leading-snug text-foreground`,s&&`col-span-2 text-lg`),children:e.title}),e.agentName&&(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 rounded-lg border border-border/70 bg-muted/45 p-2`,children:[(0,Q.jsx)(`span`,{className:F(`flex h-7 w-7 items-center justify-center rounded-full text-[10px] font-bold text-white`,k?`bg-warning sdd-agent-live`:`bg-muted-foreground`),children:pe(e.agentName)}),(0,Q.jsxs)(`div`,{className:`leading-tight`,children:[(0,Q.jsx)(`div`,{className:`text-xs font-medium text-foreground`,children:e.agentName}),(0,Q.jsx)(`div`,{className:`text-[10px] text-muted-foreground`,children:C(k?`activity:sddTask.workingOn`:`activity:sddTask.assigned`)})]})]}),(0,Q.jsxs)(`div`,{className:`grid grid-cols-2 gap-1.5 text-[11px]`,children:[(0,Q.jsx)(Te,{label:C(`activity:sddTask.metaPriority`),children:(0,Q.jsx)(`span`,{className:F(`font-medium uppercase`,Y(e.priority).text),children:e.priority})}),(0,Q.jsx)(Te,{label:C(`activity:sddTask.metaType`),children:e.type}),le&&(0,Q.jsx)(Te,{label:e.completedAt?C(`activity:sddTask.metaDuration`):C(`activity:sddTask.metaElapsed`),children:(0,Q.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,Q.jsx)(r,{className:`h-3 w-3 text-muted-foreground`}),le]})}),e.retries?(0,Q.jsx)(Te,{label:C(`activity:sddTask.metaRetries`),children:(0,Q.jsxs)(`span`,{className:`flex items-center gap-1 text-destructive`,children:[(0,Q.jsx)(S,{className:`h-3 w-3`}),e.retries]})}):null,e.worktreeBranch&&(0,Q.jsx)(Te,{label:C(`activity:sddTask.metaWorktree`),full:!0,children:(0,Q.jsxs)(`span`,{className:`flex items-center gap-1 font-mono text-foreground`,title:e.worktreeBranch,children:[(0,Q.jsx)(T,{className:`h-3 w-3 text-muted-foreground`}),(0,Q.jsx)(`span`,{className:`truncate`,children:e.worktreeBranch})]})})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsxs)(`div`,{className:`mb-1 flex items-center gap-1.5 text-[10px] font-semibold uppercase tracking-wide text-muted-foreground`,children:[C(`activity:sddTask.workerModel`),!e.model&&l&&(0,Q.jsxs)(`span`,{className:`font-normal normal-case text-muted-foreground`,children:[`· `,C(`activity:sddTask.runDefault`,{model:l})]})]}),(0,Q.jsx)(ce,{value:e.model,provider:e.provider,candidates:c,placeholder:l?C(`activity:sddTask.runDefaultPlaceholderModel`,{model:l}):C(`activity:sddTask.runDefaultPlaceholder`),onPick:(t,n)=>m(e.id,t,n),onReset:e.model?()=>m(e.id,void 0,void 0):void 0}),e.fallbackModels&&e.fallbackModels.length>0&&(0,Q.jsx)(`div`,{className:`mt-1 flex flex-wrap gap-1`,children:e.fallbackModels.map(e=>(0,Q.jsxs)(`span`,{className:`rounded bg-muted px-1.5 py-0.5 font-mono text-[9px] text-muted-foreground`,children:[`↳ `,e]},e))})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsxs)(`div`,{className:`mb-1 flex items-center gap-1.5 text-[10px] font-semibold uppercase tracking-wide text-muted-foreground`,children:[C(`activity:sddTask.verificationCmd`),(0,Q.jsxs)(`span`,{className:`font-normal normal-case text-muted-foreground`,children:[`· `,C(`activity:sddTask.gatesCompletion`)]})]}),z?(0,Q.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,Q.jsx)(`input`,{value:V,onChange:e=>H(e.target.value),onKeyDown:t=>{t.key===`Enter`?(h(e.id,V.trim()||void 0),B(!1)):t.key===`Escape`&&(H(e.verificationCommand??``),B(!1))},placeholder:C(`activity:sddTask.verifyPlaceholder`),className:`w-full rounded border border-border bg-background px-2 py-1 font-mono text-[11px] text-foreground`}),(0,Q.jsxs)(`div`,{className:`flex gap-1`,children:[(0,Q.jsx)(`button`,{type:`button`,onClick:()=>{h(e.id,V.trim()||void 0),B(!1)},className:`rounded bg-primary px-2 py-0.5 text-[10px] text-primary-foreground hover:opacity-90`,children:C(`common:action.save`)}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>{H(e.verificationCommand??``),B(!1)},className:`rounded bg-muted px-2 py-0.5 text-[10px] text-muted-foreground hover:bg-muted/80`,children:C(`common:action.cancel`)})]})]}):e.verificationCommand?(0,Q.jsxs)(`div`,{className:`flex items-center gap-1`,children:[e.verificationState&&(0,Q.jsx)(`span`,{title:e.verificationDetail,className:e.verificationState===`passed`?`rounded bg-success/10 px-1.5 py-0.5 text-[10px] text-success`:`rounded bg-destructive/10 px-1.5 py-0.5 text-[10px] text-destructive`,children:e.verificationState===`passed`?`✓ verified`:`✗ failed`}),(0,Q.jsx)(`code`,{className:`flex-1 truncate rounded bg-muted px-1.5 py-0.5 font-mono text-[10px] text-foreground`,children:e.verificationCommand}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>B(!0),className:`rounded bg-muted px-1.5 py-0.5 text-[10px] text-muted-foreground hover:bg-muted/80`,children:C(`common:action.edit`)}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>h(e.id,void 0),className:`rounded bg-muted px-1.5 py-0.5 text-[10px] text-muted-foreground hover:bg-muted/80`,children:C(`common:action.clear`)})]}):(0,Q.jsx)(`button`,{type:`button`,onClick:()=>B(!0),className:`rounded border border-dashed border-border px-2 py-1 text-[10px] text-muted-foreground hover:bg-muted`,children:C(`activity:sddTask.addVerify`)})]}),e.description&&(0,Q.jsxs)(`div`,{className:F(s&&`col-span-2`),children:[(0,Q.jsx)(`div`,{className:`mb-1 text-[10px] font-semibold uppercase tracking-wide text-muted-foreground`,children:C(`activity:sddTask.description`)}),(0,Q.jsx)(`p`,{className:`whitespace-pre-wrap rounded-md bg-muted p-2 text-[11px] leading-relaxed text-foreground`,children:e.description})]}),(0,Q.jsx)(we,{events:se,expanded:s}),e.deps.length>0&&(0,Q.jsx)(Ee,{title:C(`activity:sddTask.dependsOn`),shortIds:e.deps,byShort:G,onSelectTask:ne}),K.length>0&&(0,Q.jsx)(Ee,{title:C(`activity:sddTask.blocks`),shortIds:K.map(e=>e.shortId),byShort:G,onSelectTask:ne})]}),(0,Q.jsxs)(`div`,{className:F(`border-t border-border p-2`,s&&`px-5 py-3`),children:[ie?(0,Q.jsxs)(`div`,{className:`sdd-rise flex items-center gap-1.5`,children:[(0,Q.jsx)(`input`,{value:j,onChange:e=>M(e.target.value),onKeyDown:e=>{e.key===`Enter`&&U(),e.key===`Escape`&&A(!1)},placeholder:C(`activity:sddTask.newWorkerPlaceholder`),className:`min-w-0 flex-1 rounded-md border border-border/70 bg-background px-2 py-1.5 text-xs outline-none focus:border-primary/60`}),(0,Q.jsx)(`button`,{type:`button`,onClick:U,disabled:!j.trim(),className:`rounded-md bg-primary/10 px-2 py-1.5 text-xs font-medium text-primary hover:bg-primary/15 disabled:opacity-40`,children:(0,Q.jsx)(b,{className:`h-3.5 w-3.5`})}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>A(!1),className:`rounded-md bg-muted px-2 py-1.5 text-xs text-muted-foreground hover:bg-muted`,children:(0,Q.jsx)(x,{className:`h-3.5 w-3.5`})})]}):N?(0,Q.jsxs)(`div`,{className:`sdd-rise flex items-center gap-2`,children:[(0,Q.jsx)(`span`,{className:`flex-1 text-xs text-foreground`,children:C(N===`stop`?`activity:sddTask.confirmStop`:`activity:sddTask.confirmDelete`)}),(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>{N===`stop`?v(e.id):y(e.id),P(null)},className:`inline-flex items-center gap-1 rounded-md bg-destructive/10 px-2.5 py-1.5 text-xs font-medium text-destructive hover:bg-destructive/15`,children:[(0,Q.jsx)(b,{className:`h-3.5 w-3.5`}),` `,C(N===`stop`?`common:action.stop`:`common:action.delete`)]}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>P(null),className:`rounded-md bg-muted px-2 py-1.5 text-xs text-muted-foreground hover:bg-muted`,children:(0,Q.jsx)(x,{className:`h-3.5 w-3.5`})})]}):(0,Q.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>f(e.id),title:C(`activity:sddTask.retryTitle`),className:`inline-flex flex-1 items-center justify-center gap-1 rounded-md bg-warning/12 py-1.5 text-xs font-medium text-warning hover:bg-warning/18`,children:[(0,Q.jsx)(S,{className:`h-3.5 w-3.5`}),` `,C(`common:action.retry`)]}),(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>A(!0),className:`inline-flex flex-1 items-center justify-center gap-1 rounded-md bg-primary/10 py-1.5 text-xs font-medium text-primary hover:bg-primary/15`,children:[(0,Q.jsx)(n,{className:`h-3.5 w-3.5`}),` `,C(`activity:sddTask.reassign`)]}),k&&(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>P(`stop`),title:C(`activity:sddTask.stopTitle`),className:`inline-flex flex-1 items-center justify-center gap-1 rounded-md bg-destructive/10 py-1.5 text-xs font-medium text-destructive hover:bg-destructive/15`,children:[(0,Q.jsx)(t,{className:`h-3.5 w-3.5`}),` `,C(`common:action.stop`)]}),!k&&(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>I(!0),title:C(`activity:sddTask.splitTitle`),className:`inline-flex flex-1 items-center justify-center gap-1 rounded-md bg-primary/10 py-1.5 text-xs font-medium text-primary hover:bg-primary/15`,children:[(0,Q.jsx)(_,{className:`h-3.5 w-3.5`}),` `,C(`activity:sddTask.split`)]}),re&&(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>P(`delete`),title:C(`activity:sddTask.deleteTitle`),className:`inline-flex flex-1 items-center justify-center gap-1 rounded-md bg-destructive/10 py-1.5 text-xs font-medium text-destructive hover:bg-destructive/15`,children:[(0,Q.jsx)(E,{className:`h-3.5 w-3.5`}),` `,C(`common:action.delete`)]})]}),oe&&(0,Q.jsxs)(`div`,{className:`mt-2 flex flex-col gap-2`,children:[(0,Q.jsx)(`label`,{className:`text-[11px] text-muted-foreground`,htmlFor:`sdd-split-input`,children:C(`activity:sddTask.splitHint`)}),(0,Q.jsx)(`textarea`,{id:`sdd-split-input`,rows:3,value:L,onChange:e=>R(e.target.value),placeholder:C(`activity:sddTask.splitPlaceholder`),className:`w-full resize-y rounded-md border border-border/70 bg-background px-2 py-1.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-ring`}),(0,Q.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Q.jsxs)(`button`,{type:`button`,onClick:W,className:`inline-flex flex-1 items-center justify-center gap-1 rounded-md bg-primary/10 py-1.5 text-xs font-medium text-primary hover:bg-primary/15`,children:[(0,Q.jsx)(_,{className:`h-3.5 w-3.5`}),` `,C(`activity:sddTask.splitInto`)]}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>{I(!1),R(``)},className:`rounded-md bg-muted px-2 py-1.5 text-xs text-muted-foreground hover:bg-muted`,children:(0,Q.jsx)(x,{className:`h-3.5 w-3.5`})})]})]})]})]})}function we({events:e,expanded:t}){let{t:n}=w();return(0,Q.jsxs)(`section`,{className:F(`rounded-lg border border-border/70 bg-background/45`,t&&`col-span-2`),children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 border-b border-border/60 px-3 py-2.5`,children:[(0,Q.jsx)(h,{className:`h-4 w-4 text-primary`}),(0,Q.jsx)(`h4`,{className:`text-xs font-semibold text-foreground`,children:n(`activity:sddTask.eventLog`)}),(0,Q.jsx)(`span`,{className:`rounded-full bg-muted px-2 py-0.5 text-[10px] text-muted-foreground`,children:e.length}),(0,Q.jsx)(`span`,{className:`ml-auto text-[10px] text-muted-foreground`,children:n(`activity:sddTask.newestFirst`)})]}),e.length===0?(0,Q.jsx)(`p`,{className:`px-3 py-5 text-center text-[11px] text-muted-foreground`,children:n(`activity:sddTask.noEvents`)}):(0,Q.jsx)(`div`,{className:F(`divide-y divide-border/45 overflow-auto`,t?`max-h-[32rem]`:`max-h-72`),children:e.map((e,t)=>{let n=e.kind===`file`,r=e.kind===`tool`,i=e.ok===!1||e.kind===`failed`||e.kind===`verification_failed`,a=n?A:r?u:h;return(0,Q.jsxs)(`div`,{className:F(`grid grid-cols-[4.75rem_1rem_minmax(0,1fr)] gap-2 px-3 py-2.5 text-[11px]`,i&&`bg-destructive/[0.035]`),children:[(0,Q.jsx)(`time`,{dateTime:new Date(e.ts).toISOString(),className:`font-mono text-[10px] text-muted-foreground`,title:new Date(e.ts).toLocaleString(),children:new Date(e.ts).toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`,second:`2-digit`})}),(0,Q.jsx)(a,{className:F(`mt-0.5 h-3.5 w-3.5`,i?`text-destructive`:n?`text-info`:r?`text-warning`:`text-primary`)}),(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[e.action&&(0,Q.jsx)(`span`,{className:`rounded bg-muted px-1.5 py-0.5 font-mono text-[10px] font-medium text-foreground`,children:e.action}),e.agentName&&(0,Q.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:e.agentName}),e.durationMs!==void 0&&(0,Q.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:e.durationMs<1e3?`${Math.round(e.durationMs)}ms`:`${(e.durationMs/1e3).toFixed(1)}s`})]}),e.filePath?(0,Q.jsx)(`code`,{className:`mt-1 block break-all font-mono text-[10px] leading-relaxed text-foreground`,children:e.filePath}):e.detail?(0,Q.jsx)(`code`,{className:`mt-1 block break-words font-mono text-[10px] leading-relaxed text-muted-foreground`,children:e.detail}):(0,Q.jsx)(`p`,{className:`mt-1 break-words leading-relaxed text-foreground`,children:e.text})]})]},`${e.ts}-${e.kind}-${t}`)})})]})}function Te({label:e,children:t,full:n}){return(0,Q.jsxs)(`div`,{className:F(`rounded-md border border-border bg-muted/50 px-2 py-1`,n&&`col-span-2`),children:[(0,Q.jsx)(`div`,{className:`text-[9px] uppercase tracking-wide text-muted-foreground`,children:e}),(0,Q.jsx)(`div`,{className:`text-foreground`,children:t})]})}function Ee({title:e,shortIds:t,byShort:n,onSelectTask:r}){return(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`div`,{className:`mb-1 text-[10px] font-semibold uppercase tracking-wide text-muted-foreground`,children:e}),(0,Q.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:t.map(e=>{let t=n.get(e);return(0,Q.jsxs)(`button`,{type:`button`,disabled:!t,onClick:()=>t&&r(t.id),className:`flex items-center gap-1 rounded-full border border-border bg-muted px-2 py-0.5 text-[10px] text-foreground hover:bg-muted disabled:opacity-50`,title:t?.title,children:[(0,Q.jsx)(`span`,{className:F(`h-1.5 w-1.5 rounded-full`,ge(t?.displayStatus??`pending`).dot)}),(0,Q.jsx)(`span`,{className:`font-mono`,children:e})]},e)})})]})}function De({onClose:e}){let{t:n}=w(),{client:r}=oe(),o=L(e=>e.snapshot),s=L(e=>e.lifecycleResult),c=L(e=>e.destroying),l=L(e=>e.setDestroying),u=L(e=>e.setLifecycleResult),[f,p]=(0,Z.useState)(()=>Date.now()),[g,_]=(0,Z.useState)(null),[v,y]=(0,Z.useState)(!1),[b,ee]=(0,Z.useState)(`graph`),[te,C]=(0,Z.useState)(!1);(0,Z.useEffect)(()=>{r?.send?.({type:`sdd.board.get`})},[r]);let T=o&&(o.status===`running`||o.status===`paused`);(0,Z.useEffect)(()=>{if(!T)return;let e=setInterval(()=>p(Date.now()),1e3);return p(Date.now()),()=>clearInterval(e)},[T]);let D=(0,Z.useCallback)(e=>r?.send?.(e),[r]),O=(0,Z.useRef)(null),k=(0,Z.useCallback)(e=>{O.current=null,D({type:`sdd.board.destroy`,payload:{revertMerged:e}})},[D]),re=(0,Z.useCallback)(e=>{C(!1),u(null),l(!0),T?(D({type:`sdd.board.stop`,payload:{}}),O.current={revertMerged:e,deadline:Date.now()+2e4}):k(e)},[T,D,k,l,u]);(0,Z.useEffect)(()=>{let e=O.current;e&&(!T||Date.now()>=e.deadline)&&k(e.revertMerged)},[T,o,k]);let ie=(0,Z.useCallback)(()=>{u(null),D({type:`sdd.board.cleanup_worktrees`,payload:{}})},[D,u]),A=(0,Z.useCallback)(()=>{u(null),D({type:`sdd.board.rollback`,payload:{}})},[D,u]),ae=(0,Z.useMemo)(()=>(o?.tasks??[]).map(e=>({id:e.id,shortId:e.shortId,title:e.title,displayStatus:e.displayStatus,priority:e.priority,deps:e.deps,agentName:e.agentName,worktreeBranch:e.worktreeBranch})),[o?.tasks]),N=(0,Z.useMemo)(()=>{let e=new Map;for(let t of o?.tasks??[])t.displayStatus===`in_progress`&&t.agentName&&e.set(t.agentName,{name:t.agentName,task:t.title});return[...e.values()]},[o?.tasks]),I=(0,Z.useCallback)(e=>_(e),[]),z=(0,Z.useCallback)(()=>{_(null),y(!1)},[]),B=(0,Z.useCallback)(e=>D({type:`sdd.board.retry`,payload:{taskId:e}}),[D]),V=(0,Z.useCallback)(()=>D({type:`sdd.board.retry_all_failed`,payload:{}}),[D]),H=(0,Z.useCallback)((e,t)=>{let n=t.trim();n&&D({type:`sdd.board.reassign`,payload:{taskId:e,agentName:n}})},[D]),U=(0,Z.useCallback)((e,t,n)=>D({type:`sdd.board.set_task_model`,payload:{taskId:e,model:t,provider:n}}),[D]),W=(0,Z.useCallback)((e,t)=>D({type:`sdd.board.set_task_verification`,payload:{taskId:e,verificationCommand:t}}),[D]),G=(0,Z.useCallback)(e=>D({type:`sdd.board.cancel_task`,payload:{taskId:e}}),[D]),ce=(0,Z.useCallback)(e=>{D({type:`sdd.board.delete_task`,payload:{taskId:e}}),_(null),y(!1)},[D]),le=(0,Z.useCallback)((e,t)=>{D({type:`sdd.board.split_task`,payload:{taskId:e,subtasks:t}}),_(null),y(!1)},[D]),ue=se(g!==null),J=(0,Z.useMemo)(()=>o?.tasks.find(e=>e.id===g)??null,[o?.tasks,g]),Y=o?.progress,X=o?.diagnostics?.deadlockChains??[];return(0,Q.jsxs)(`div`,{className:`flex h-full min-h-0 min-w-0 flex-col bg-background`,children:[(0,Q.jsxs)(`header`,{className:`sdd-sheen shrink-0 border-b border-border px-4 pb-3 pt-2.5`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(h,{className:`h-5 w-5 text-warning`}),(0,Q.jsx)(`h1`,{className:`text-lg font-semibold text-foreground`,children:o?.title??n(`activity:sddBoard.titleFallback`)}),o&&(0,Q.jsx)(`span`,{className:F(`rounded-full border px-2 py-0.5 text-[11px] font-medium capitalize`,q[o.status]??q.idle),children:o.status}),o?.defaultModel&&(0,Q.jsxs)(`span`,{className:`flex items-center gap-1 rounded-full border border-border bg-muted px-2 py-0.5 text-[10px] text-muted-foreground`,title:n(`activity:sddBoard.defaultModelTitle`),children:[(0,Q.jsx)(ne,{className:`h-3 w-3 text-primary`}),o.defaultModel]})]}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[o&&(0,Q.jsxs)(`button`,{type:`button`,title:`Open the mirrored kanban board(s) for this run (one per dependency wave)`,onClick:()=>{let e=`run:${o.runId}`,t=R.getState().boards.filter(t=>t.tags?.includes(e)),n=t.find(e=>e.tags?.includes(`phase:wave-0`))??t[0];n&&R.getState().setActiveBoardId(n.id),P.getState().setCurrentView(`kanban`)},className:`inline-flex items-center gap-1 rounded-md border border-border px-2.5 py-1 text-xs font-medium text-muted-foreground hover:bg-muted`,children:[(0,Q.jsx)(h,{className:`h-3.5 w-3.5`}),` Kanban`]}),o&&(0,Q.jsx)(`div`,{className:`flex items-center rounded-md border border-border bg-muted p-0.5 text-[11px]`,children:[`graph`,`kanban`].map(e=>(0,Q.jsx)(`button`,{type:`button`,onClick:()=>ee(e),className:F(`rounded px-2 py-0.5 capitalize transition`,b===e?`bg-primary/12 text-primary`:`text-muted-foreground hover:text-foreground`),children:n(e===`graph`?`activity:sddBoard.graphLabel`:`activity:sddBoard.kanbanLabel`)},e))}),T&&(Y?.failed??0)>0&&(0,Q.jsxs)(`button`,{type:`button`,onClick:V,title:n(`activity:sddBoard.retryAllTitle`),className:`inline-flex items-center gap-1 rounded-md bg-warning/15 px-2.5 py-1 text-xs font-medium text-warning hover:bg-warning/25`,children:[(0,Q.jsx)(S,{className:`h-3.5 w-3.5`}),` `,n(`activity:sddBoard.retryFailed`,{count:Y?.failed??0})]}),T&&(0,Q.jsxs)(Q.Fragment,{children:[o?.status===`paused`?(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>D({type:`sdd.board.resume`,payload:{}}),className:`inline-flex items-center gap-1 rounded-md bg-success/15 px-2.5 py-1 text-xs font-medium text-success hover:bg-success/25`,children:[(0,Q.jsx)(m,{className:`h-3.5 w-3.5`}),` `,n(`activity:sddBoard.resume`)]}):(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>D({type:`sdd.board.pause`,payload:{}}),className:`inline-flex items-center gap-1 rounded-md bg-warning/15 px-2.5 py-1 text-xs font-medium text-warning hover:bg-warning/25`,children:[(0,Q.jsx)(i,{className:`h-3.5 w-3.5`}),` `,n(`activity:sddBoard.pause`)]}),(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>D({type:`sdd.board.stop`,payload:{}}),className:`inline-flex items-center gap-1 rounded-md bg-destructive/15 px-2.5 py-1 text-xs font-medium text-destructive hover:bg-destructive/25`,children:[(0,Q.jsx)(t,{className:`h-3.5 w-3.5`}),` `,n(`activity:sddBoard.stop`)]})]}),o&&!T&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`button`,{type:`button`,onClick:ie,title:n(`activity:sddBoard.cleanTitle`),className:`inline-flex items-center gap-1 rounded-md bg-muted px-2.5 py-1 text-xs font-medium text-muted-foreground hover:bg-muted/80`,children:[(0,Q.jsx)(j,{className:`h-3.5 w-3.5`}),` `,n(`activity:sddBoard.cleanWorktrees`)]}),(o.mergedCommits?.length??0)>0&&(0,Q.jsxs)(`button`,{type:`button`,onClick:A,title:n(`activity:sddBoard.rollbackTitle`,{count:o.mergedCommits?.length??0,base:o.baseBranch??n(`activity:sdd.baseBranchFallback`)}),className:`inline-flex items-center gap-1 rounded-md bg-warning/15 px-2.5 py-1 text-xs font-medium text-warning hover:bg-warning/25`,children:[(0,Q.jsx)(a,{className:`h-3.5 w-3.5`}),` `,n(`activity:sddBoard.rollback`,{count:o.mergedCommits?.length??0})]})]}),o&&(c?(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded-md bg-destructive/15 px-2.5 py-1 text-xs font-medium text-destructive`,children:[(0,Q.jsx)(S,{className:`h-3.5 w-3.5 animate-spin`}),` `,n(T?`activity:sddBoard.stopping`:`activity:sddBoard.destroying`)]}):(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>C(!0),title:n(`activity:sddBoard.destroyTitle`),className:`inline-flex items-center gap-1 rounded-md bg-destructive px-2.5 py-1 text-xs font-medium text-destructive-foreground hover:bg-destructive/90`,children:[(0,Q.jsx)(E,{className:`h-3.5 w-3.5`}),` `,n(`activity:sddBoard.destroy`)]})),(0,Q.jsx)(K,{variant:`ghost`,size:`icon`,onClick:e,children:(0,Q.jsx)(x,{className:`h-4 w-4`})})]})]}),o&&Y&&(0,Q.jsxs)(`div`,{className:`mt-2.5 flex items-center gap-5`,children:[(0,Q.jsx)(he,{pct:Y.percentComplete}),(0,Q.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-3 text-xs`,children:[(0,Q.jsx)(Ae,{label:n(`activity:sddBoard.statDone`),value:`${Y.completed}/${Y.total}`,color:`text-success`}),Y.inProgress>0&&(0,Q.jsx)(Ae,{label:n(`activity:sddBoard.statRunning`),value:Y.inProgress,color:`text-warning`}),Y.failed>0&&(0,Q.jsx)(Ae,{label:n(`activity:sddBoard.statFailed`),value:Y.failed,color:`text-destructive`}),(0,Q.jsx)(Ae,{label:n(`activity:sddBoard.statWave`),value:o.wave+1,color:`text-primary`}),T&&o.startedAt>0&&(0,Q.jsx)(Ae,{label:n(`activity:sddBoard.statElapsed`),value:de(f-o.startedAt),color:`text-foreground`})]}),(0,Q.jsx)(`div`,{className:`flex min-h-[24px] items-center gap-1.5`,children:N.length===0?(0,Q.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:n(`activity:sddBoard.noActiveWorkers`)}):N.map((e,t)=>(0,Q.jsxs)(`span`,{title:`${e.name} → ${e.task}`,className:`flex items-center gap-1 rounded-full bg-muted py-0.5 pl-0.5 pr-2`,children:[(0,Q.jsx)(`span`,{className:F(`sdd-agent-live flex h-5 w-5 items-center justify-center rounded-full text-[9px] font-bold text-white`,me[t%me.length]),children:pe(e.name)}),(0,Q.jsx)(`span`,{className:`max-w-[90px] truncate text-[11px] text-foreground`,children:e.name})]},e.name))})]})]})]}),s&&(0,Q.jsx)(ke,{result:s,onDismiss:()=>u(null)}),X.length>0&&(0,Q.jsxs)(`div`,{className:`flex items-start gap-2 border-b border-destructive/30 bg-destructive/5 px-4 py-2 text-xs text-destructive`,children:[(0,Q.jsx)(d,{className:`mt-0.5 h-4 w-4 shrink-0`}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`div`,{className:`font-semibold`,children:n(`activity:sddBoard.deadlock`)}),X.map(e=>(0,Q.jsxs)(`div`,{className:`font-mono`,children:[e.blocked,` ← `,e.blockedBy.join(`, `)]},e.blocked))]})]}),(0,Q.jsxs)(`div`,{className:`flex min-h-0 min-w-0 flex-1`,children:[(0,Q.jsx)(`div`,{className:`relative min-h-0 min-w-0 flex-1 overflow-hidden`,children:o?b===`graph`?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(fe,{tasks:ae,columns:o.columns,onTaskClick:I}),(0,Q.jsx)(`div`,{className:`pointer-events-none absolute bottom-2 left-1/2 -translate-x-1/2 rounded-full bg-black/40 px-2 py-0.5 text-[10px] text-muted-foreground backdrop-blur`,children:n(`activity:sddBoard.clickTaskHint`)})]}):(0,Q.jsx)(xe,{tasks:o.tasks,selectedId:g,onTaskClick:I}):(0,Q.jsxs)(`div`,{className:`flex h-full flex-col items-center justify-center gap-3 text-sm text-muted-foreground`,children:[(0,Q.jsx)(M,{className:`h-10 w-10 text-primary/40`}),(0,Q.jsx)(`p`,{className:`text-foreground`,children:n(`activity:sddBoard.noRunTitle`)}),(0,Q.jsx)(`p`,{className:`max-w-sm text-center text-xs text-muted-foreground`,children:n(`activity:sddBoard.noRunBody`)})]})}),o&&(0,Q.jsx)(`aside`,{"data-testid":`sdd-task-panel`,"data-expanded":v&&J?`true`:`false`,className:F(`shrink-0 border-l border-border bg-card transition-[width] duration-200 ease-out`,v&&J?`w-[min(72rem,72vw)]`:`w-80`),children:J?(0,Q.jsx)(Ce,{task:J,allTasks:o.tasks,feed:o.taskEvents?.[J.id]??o.feed??[],now:f,expanded:v,modelCandidates:ue,defaultModel:o.defaultModel,onClose:z,onToggleExpanded:()=>y(e=>!e),onRetry:B,onReassign:H,onSetModel:U,onSetVerification:W,onCancel:G,onDelete:ce,onSplit:le,onSelectTask:_},J.id):(0,Q.jsx)(ve,{feed:o.feed??[],now:f})})]}),(0,Q.jsx)(ye,{open:te,onOpenChange:C,snapshot:o,busy:c,onConfirm:re})]})}function Oe(e){let t=e.op===`cleanup_worktrees`?`lcClean`:e.op===`rollback`?`lcRollback`:`lcDestroy`,n=f.t(`activity:sddBoard.${t}`);if(!e.ok)return f.t(`activity:sddBoard.lcFailed`,{op:n,reason:e.reason??f.t(`activity:sddBoard.lcUnknownError`)});let r=[];typeof e.removed==`number`&&r.push(f.t(`activity:sddBoard.lcWorktrees`,{count:e.removed})),typeof e.reverted==`number`&&e.reverted>0&&r.push(f.t(`activity:sddBoard.lcCommits`,{count:e.reverted})),e.deleted?.length&&r.push(f.t(`activity:sddBoard.lcDeleted`,{items:e.deleted.join(`, `)}));let i=r.length?r.join(` · `):f.t(`activity:sddBoard.lcNothing`);return e.reason?f.t(`activity:sddBoard.lcNote`,{op:n,body:i,reason:e.reason}):f.t(`activity:sddBoard.lcOk`,{op:n,body:i})}function ke({result:e,onDismiss:t}){let n=!e.ok||!!e.reason;return(0,Q.jsxs)(`div`,{className:F(`flex items-start gap-2 border-b px-4 py-2 text-xs`,n?`border-warning/30 bg-warning/5 text-warning`:`border-success/30 bg-success/5 text-success`),children:[n?(0,Q.jsx)(l,{className:`mt-0.5 h-4 w-4 shrink-0`}):(0,Q.jsx)(v,{className:`mt-0.5 h-4 w-4 shrink-0`}),(0,Q.jsx)(`span`,{className:`flex-1`,children:Oe(e)}),(0,Q.jsx)(`button`,{type:`button`,onClick:t,className:`shrink-0 opacity-60 hover:opacity-100`,children:(0,Q.jsx)(x,{className:`h-3.5 w-3.5`})})]})}function Ae({label:e,value:t,color:n}){return(0,Q.jsxs)(`span`,{className:`flex items-baseline gap-1`,children:[(0,Q.jsx)(`span`,{className:F(`font-semibold tabular-nums`,n),children:t}),(0,Q.jsx)(`span`,{className:`text-[10px] uppercase tracking-wide text-muted-foreground`,children:e})]})}var je={idle:`phaseStart`,questioning:`phaseInterview`,spec_review:`phaseSpecReview`,implementation:`phasePlanning`,task_review:`phaseTaskReview`,executing:`phaseRunning`,done:`phaseDone`},Me=[`questioning`,`spec_review`,`implementation`,`task_review`,`executing`];function Ne({onClose:e,onRunStarted:t}){let{t:n}=w(),{client:r}=oe(),i=I(e=>e.snapshot),a=I(e=>e.agentText),s=I(e=>e.error),l=I(e=>e.startedRunId),u=I(e=>e.setStartedRunId),[d,f]=(0,Z.useState)(``),[m,h]=(0,Z.useState)(``),[g,_]=(0,Z.useState)(!1),[v,te]=(0,Z.useState)(!0),[ne,S]=(0,Z.useState)(!0),[T,E]=(0,Z.useState)(!1),[D,k]=(0,Z.useState)(void 0),[A,j]=(0,Z.useState)(void 0),[M,ae]=(0,Z.useState)([]),[N,P]=(0,Z.useState)(4),[L,R]=(0,Z.useState)(!0),[z,B]=(0,Z.useState)(!1),V=se(T),H=(0,Z.useCallback)(e=>r?.send?.(e),[r]),U=(0,Z.useRef)(null);(0,Z.useEffect)(()=>{H({type:`sdd.spec.get`})},[H]),(0,Z.useEffect)(()=>{U.current?.scrollIntoView({behavior:`smooth`,block:`end`})},[i?.answers.length??0,a]),(0,Z.useEffect)(()=>{l&&(u(null),t?.())},[t,u,l]);let W=i?.busy??!1,G=i?.phase??`idle`,q=!!i?.sessionId,de=!!i?.resumed,J=i?.lastRunId;(0,Z.useEffect)(()=>{q&&_(!1)},[q]);let pe=i?.answers[i.answers.length-1]?.question??``,me=!!i&&(i.taskCount>0||!!i.graphId||G===`task_review`||G===`executing`),X=()=>{let e=d.trim();!e||W||g||(_(!0),H({type:`sdd.spec.start`,payload:{goal:e}}))},he=()=>{let e=m.trim();!e||W||(H({type:`sdd.spec.message`,payload:{text:e}}),h(``))},ge=()=>!W&&H({type:`sdd.spec.approve`,payload:{}}),_e=()=>{H({type:`sdd.run.start`,payload:{parallelSlots:N,worktrees:L,planDecompose:z,...D?{model:D,provider:A}:{},...M.length?{fallbackModels:M}:{}}}),E(!1)},ve=()=>{W||H({type:`sdd.spec.discard`,payload:{}})},ye=(0,Z.useMemo)(()=>(i?.board?.tasks??[]).map(e=>({id:e.id,shortId:e.shortId,title:e.title,displayStatus:e.displayStatus,priority:e.priority,deps:e.deps,agentName:e.agentName,worktreeBranch:e.worktreeBranch,retries:e.retries})),[i?.board]),be=ye.length>0;return(0,Q.jsxs)(`div`,{className:`flex h-full min-h-0 min-w-0 flex-col bg-background`,children:[(0,Q.jsxs)(`header`,{className:`sdd-sheen flex shrink-0 items-center justify-between border-b border-border px-4 py-2`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(y,{className:`h-5 w-5 text-primary`}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`h1`,{className:`text-lg font-semibold`,children:i?.title||n(`activity:sddWizard.titleFallback`)}),q&&(0,Q.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[n(`activity:sddWizard.${je[G]??`phaseStart`}`),G===`questioning`&&` · ${n(`activity:sddWizard.questionsSuffix`,{cur:i?.questionCount??0,max:i?.maxQuestions??0})}`,i&&i.taskCount>0?` · ${n(`activity:sddWizard.tasksSuffix`,{count:i.taskCount})}`:``]})]}),W&&(0,Q.jsx)(O,{className:`h-4 w-4 animate-spin text-muted-foreground`})]}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[J&&(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>t?.(),className:`inline-flex items-center gap-1 rounded-md border border-border px-2 py-1 text-xs font-medium text-muted-foreground hover:bg-muted`,children:[(0,Q.jsx)(re,{className:`h-3.5 w-3.5`}),` `,n(`activity:sddWizard.openLiveBoard`)]}),q&&(0,Q.jsx)(`button`,{type:`button`,onClick:ve,disabled:W,title:n(`activity:sddWizard.discardTitle`),className:`inline-flex items-center gap-1 rounded-md border border-border px-2 py-1 text-xs font-medium text-muted-foreground hover:bg-destructive/10 hover:text-destructive disabled:opacity-50`,children:n(`activity:sddWizard.discardInterview`)}),me&&(0,Q.jsxs)(`div`,{className:`relative flex items-center gap-1.5`,children:[(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>E(e=>!e),title:n(`activity:sddWizard.runCfgTitle`),className:F(`inline-flex items-center gap-1 rounded-md border px-2 py-1 text-xs font-medium`,D||M.length||z?`border-primary/40 bg-primary/10 text-primary`:`border-border bg-muted text-muted-foreground hover:text-foreground`),children:[(0,Q.jsx)(o,{className:`h-3.5 w-3.5`}),D||n(`activity:sddWizard.modelsLabel`)]}),(0,Q.jsxs)(`button`,{type:`button`,onClick:_e,className:`inline-flex items-center gap-1 rounded-md bg-success/15 px-2.5 py-1 text-xs font-medium text-success hover:bg-success/25`,children:[(0,Q.jsx)(re,{className:`h-3.5 w-3.5`}),` `,n(`activity:sddWizard.startRun`)]}),T&&(0,Q.jsxs)(`div`,{className:`sdd-rise absolute right-0 top-9 z-50 w-72 rounded-lg border border-border bg-popover p-3 shadow-xl`,children:[(0,Q.jsx)(`div`,{className:`mb-1 text-[10px] font-semibold uppercase tracking-wide text-muted-foreground`,children:n(`activity:sddWizard.defaultWorkerModel`)}),(0,Q.jsx)(ce,{value:D,provider:A,candidates:V,placeholder:n(`activity:sddWizard.leaderDefaultPlaceholder`),resetLabel:n(`activity:sddWizard.useSessionDefault`),onPick:(e,t)=>{k(e),j(t)},onReset:D?()=>{k(void 0),j(void 0)}:void 0}),(0,Q.jsx)(`div`,{className:`mb-1 mt-3 text-[10px] font-semibold uppercase tracking-wide text-muted-foreground`,children:n(`activity:sddWizard.fallbackChain`)}),(0,Q.jsx)(ue,{value:M,candidates:V,onChange:ae}),(0,Q.jsx)(`p`,{className:`mt-2 text-[10px] text-muted-foreground`,children:n(`activity:sddWizard.appliesToAll`)}),(0,Q.jsxs)(`div`,{className:`mt-3 flex items-center justify-between gap-2`,children:[(0,Q.jsx)(`label`,{htmlFor:`sdd-slots`,className:`text-[10px] font-semibold uppercase tracking-wide text-muted-foreground`,children:n(`activity:sddWizard.parallelAgents`)}),(0,Q.jsx)(`input`,{id:`sdd-slots`,type:`number`,min:1,max:16,value:N,onChange:e=>{let t=Number.parseInt(e.target.value,10);P(Number.isFinite(t)?Math.min(16,Math.max(1,t)):1)},className:`w-16 rounded-md border border-border bg-background px-2 py-1 text-right text-xs outline-none focus:border-primary`})]}),(0,Q.jsxs)(`label`,{className:`mt-2 flex cursor-pointer items-center justify-between gap-2`,children:[(0,Q.jsx)(`span`,{className:`text-[10px] font-semibold uppercase tracking-wide text-muted-foreground`,children:n(`activity:sddWizard.isolateWorktrees`)}),(0,Q.jsx)(`input`,{type:`checkbox`,checked:L,onChange:e=>R(e.target.checked),className:`h-3.5 w-3.5 accent-primary`})]}),(0,Q.jsx)(`p`,{className:`mt-1 text-[10px] text-muted-foreground`,children:n(L?`activity:sddWizard.worktreeOn`:`activity:sddWizard.worktreeOff`)}),(0,Q.jsxs)(`label`,{className:`mt-2 flex cursor-pointer items-center justify-between gap-2`,children:[(0,Q.jsx)(`span`,{className:`text-[10px] font-semibold uppercase tracking-wide text-muted-foreground`,children:n(`activity:sddWizard.planDecompose`)}),(0,Q.jsx)(`input`,{type:`checkbox`,checked:z,onChange:e=>B(e.target.checked),className:`h-3.5 w-3.5 accent-primary`})]}),(0,Q.jsx)(`p`,{className:`mt-1 text-[10px] text-muted-foreground`,children:n(z?`activity:sddWizard.planDecomposeOn`:`activity:sddWizard.planDecomposeOff`)})]})]}),(0,Q.jsx)(K,{variant:`ghost`,size:`icon`,onClick:e,children:(0,Q.jsx)(x,{className:`h-4 w-4`})})]})]}),q&&(0,Q.jsx)(`div`,{className:`flex shrink-0 items-center gap-1 border-b bg-card/50 px-4 py-1.5 text-[11px]`,children:Me.map((e,t)=>{let r=e===G,i=Me.indexOf(G)>t;return(0,Q.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,Q.jsxs)(`span`,{className:F(`rounded-full px-2 py-0.5`,r?`bg-primary/15 text-primary`:i?`text-success`:`text-muted-foreground`),children:[i&&(0,Q.jsx)(b,{className:`mr-0.5 inline h-3 w-3`}),n(`activity:sddWizard.${je[e]}`)]}),t<Me.length-1&&(0,Q.jsx)(`span`,{className:`text-muted-foreground/65`,children:`→`})]},e)})}),(0,Q.jsxs)(`div`,{ref:le(`sdd-wizard`),className:`min-h-0 flex-1 overflow-auto overscroll-contain p-4`,children:[s&&(0,Q.jsx)(`div`,{className:`mb-3 rounded-md border border-destructive/40 bg-destructive/5 p-2 text-xs text-destructive`,children:s}),de&&q&&(0,Q.jsx)(`div`,{className:`mb-3 rounded-md border border-primary/30 bg-primary/5 px-3 py-2 text-xs text-primary`,children:n(`activity:sddWizard.resumeBanner`)}),q?(0,Q.jsxs)(`div`,{className:`space-y-4`,children:[be&&(0,Q.jsxs)(`div`,{className:`sdd-rise overflow-hidden rounded-lg border border-primary/20 bg-[hsl(var(--surface-2)/0.85)]`,children:[(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>te(e=>!e),className:`flex w-full items-center gap-1.5 border-b border-border/60 px-3 py-1.5 text-[11px] font-medium text-primary hover:bg-muted/40`,children:[v?(0,Q.jsx)(ee,{className:`h-3.5 w-3.5`}):(0,Q.jsx)(ie,{className:`h-3.5 w-3.5`}),(0,Q.jsx)(c,{className:`h-3.5 w-3.5`}),n(`activity:sddWizard.taskGraphSummary`,{count:i?.taskCount??0}),(0,Q.jsx)(`span`,{className:`ml-auto text-muted-foreground`,children:n(v?`activity:sddWizard.dragToExplore`:`activity:sddWizard.show`)})]}),v&&(0,Q.jsx)(`div`,{className:`h-[32dvh] min-h-[200px]`,children:(0,Q.jsx)(fe,{tasks:ye,columns:i?.board?.columns??[]})})]}),(0,Q.jsxs)(`div`,{className:`mx-auto max-w-2xl space-y-3`,children:[i?.goal&&(0,Q.jsxs)(`div`,{className:`rounded-md border border-border bg-muted/30 px-3 py-2`,children:[(0,Q.jsxs)(`div`,{className:`mb-1 flex items-center gap-1.5 text-[10px] font-semibold uppercase tracking-wide text-muted-foreground`,children:[(0,Q.jsx)(p,{className:`h-3 w-3`}),` `,n(`activity:sddWizard.goalLabel`)]}),(0,Q.jsx)(`p`,{className:`whitespace-pre-wrap text-sm leading-relaxed text-foreground/90`,children:i.goal})]}),i?.answers.length||a&&G===`questioning`||W?(0,Q.jsxs)(`div`,{className:`space-y-2.5`,children:[i?.answers.map(e=>(0,Q.jsxs)(`div`,{className:`space-y-2.5`,children:[(0,Q.jsx)(Fe,{speaker:`assistant`,text:e.question}),(0,Q.jsx)(Fe,{speaker:`user`,text:e.answer})]},e.question.slice(0,64))),a&&G===`questioning`&&a!==pe&&(0,Q.jsx)(Fe,{speaker:`assistant`,text:a}),W&&(0,Q.jsx)(Fe,{speaker:`assistant`,text:``,thinking:!0})]}):null,i?.spec&&(0,Q.jsxs)(`div`,{className:`sdd-rise rounded-md border border-border bg-card p-3`,children:[(0,Q.jsxs)(`div`,{className:`mb-1 flex items-center gap-1.5 text-sm font-semibold`,children:[(0,Q.jsx)(y,{className:`h-3.5 w-3.5 text-primary`}),i.spec.title]}),(0,Q.jsx)(`p`,{className:`mb-2 text-xs text-muted-foreground`,children:i.spec.overview}),(0,Q.jsx)(`ul`,{className:`space-y-0.5 text-xs`,children:i.spec.requirements.map(e=>(0,Q.jsxs)(`li`,{className:`flex gap-1.5`,children:[(0,Q.jsx)(`span`,{className:F(`shrink-0 font-mono uppercase`,Y(e.priority).text),children:e.priority[0]}),(0,Q.jsx)(`span`,{children:e.description})]},`${e.priority}-${e.description.slice(0,32)}`))})]}),a&&(G===`implementation`||G===`task_review`)&&(0,Q.jsxs)(`div`,{className:`sdd-rise rounded-md border border-border bg-card`,children:[(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>S(e=>!e),className:`flex w-full items-center gap-1.5 border-b border-border/60 px-3 py-2 text-sm font-semibold hover:bg-muted/40`,children:[ne?(0,Q.jsx)(ee,{className:`h-3.5 w-3.5`}):(0,Q.jsx)(ie,{className:`h-3.5 w-3.5`}),(0,Q.jsx)(y,{className:`h-3.5 w-3.5 text-primary`}),` `,n(`activity:sddWizard.implementationPlan`)]}),ne&&(0,Q.jsx)(`div`,{className:`max-h-[40dvh] overflow-auto px-3 py-2`,children:(0,Q.jsx)(`p`,{className:`whitespace-pre-wrap text-sm leading-relaxed text-foreground/90`,children:Pe(a)})})]}),a&&G!==`questioning`&&G!==`implementation`&&G!==`task_review`&&!i?.spec&&(0,Q.jsx)(Fe,{speaker:`assistant`,text:a}),(G===`spec_review`||G===`implementation`||G===`task_review`)&&(0,Q.jsxs)(K,{variant:`secondary`,onClick:ge,disabled:W,children:[(0,Q.jsx)(b,{className:`mr-1.5 h-4 w-4`}),n(G===`spec_review`?`activity:sddWizard.approveSpec`:G===`task_review`?`activity:sddWizard.approveTasks`:`activity:sddWizard.approvePlan`)]}),(0,Q.jsx)(`div`,{ref:U})]})]}):(0,Q.jsxs)(`div`,{className:`mx-auto mt-8 max-w-xl`,children:[(0,Q.jsx)(`label`,{className:`mb-2 block text-sm font-medium`,htmlFor:`sdd-goal`,children:n(`activity:sddWizard.goalPrompt`)}),(0,Q.jsx)(`textarea`,{id:`sdd-goal`,value:d,onChange:e=>f(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.metaKey||e.ctrlKey)&&X()},rows:4,placeholder:n(`activity:sddWizard.goalPlaceholder`),className:`w-full resize-none rounded-md border border-border bg-card px-3 py-2 text-sm outline-none focus:border-primary`}),(0,Q.jsx)(K,{className:`mt-3`,onClick:X,disabled:!d.trim()||g,children:g?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(O,{className:`mr-1.5 h-4 w-4 animate-spin`}),` `,n(`activity:sddWizard.startingInterview`)]}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(y,{className:`mr-1.5 h-4 w-4`}),` `,n(`activity:sddWizard.startInterview`)]})}),(0,Q.jsx)(`p`,{className:`mt-3 text-xs text-muted-foreground`,children:n(`activity:sddWizard.introBody`)})]})]}),q&&G!==`executing`&&G!==`done`&&(0,Q.jsxs)(`div`,{className:`flex shrink-0 items-end gap-2 border-t bg-card px-4 py-2`,children:[(0,Q.jsx)(`textarea`,{value:m,onChange:e=>h(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),he())},rows:1,placeholder:n(G===`questioning`?`activity:sddWizard.answerPlaceholder`:`activity:sddWizard.changePlaceholder`),disabled:W,className:`max-h-32 flex-1 resize-none rounded-md border border-border bg-background px-3 py-2 text-sm outline-none focus:border-primary disabled:opacity-50`}),(0,Q.jsx)(K,{size:`icon`,onClick:he,disabled:W||!m.trim(),children:(0,Q.jsx)(C,{className:`h-4 w-4`})})]})]})}function Pe(e){let t=e.replace(/```json[\s\S]*?```/gi,``).trim();return t.length>0?t:e.trim()}function Fe({speaker:e,text:t,live:n,thinking:r}){let i=e===`user`;return(0,Q.jsxs)(`div`,{className:F(`sdd-rise flex items-start gap-2`,i&&`flex-row-reverse`),children:[(0,Q.jsx)(`span`,{className:F(`mt-0.5 flex h-6 w-6 shrink-0 items-center justify-center rounded-full`,i?`bg-info/15 text-info`:`bg-primary/15 text-primary`,(n||r)&&`sdd-agent-live`),children:i?(0,Q.jsx)(N,{className:`h-3.5 w-3.5`}):(0,Q.jsx)(k,{className:`h-3.5 w-3.5`})}),(0,Q.jsx)(`div`,{className:F(`max-w-[80%] whitespace-pre-wrap rounded-2xl px-3 py-2 text-sm leading-relaxed text-foreground`,i?`rounded-tr-sm bg-info/10`:`rounded-tl-sm bg-muted`),children:r?(0,Q.jsxs)(`span`,{className:`flex items-center gap-1 py-0.5`,children:[(0,Q.jsx)(`span`,{className:`h-1.5 w-1.5 animate-bounce rounded-full bg-muted-foreground [animation-delay:-200ms]`}),(0,Q.jsx)(`span`,{className:`h-1.5 w-1.5 animate-bounce rounded-full bg-muted-foreground [animation-delay:-100ms]`}),(0,Q.jsx)(`span`,{className:`h-1.5 w-1.5 animate-bounce rounded-full bg-muted-foreground`})]}):t})]})}var $=[{id:`project`,labelKey:`activity:sddhub.tabProject`},{id:`board`,labelKey:`activity:sddhub.tabBoard`},{id:`specs`,labelKey:`activity:sddhub.tabSpecs`}];function Ie(){let{t:e}=w(),[t,n]=(0,Z.useState)(`project`),r=I(e=>e.startedRunId),i=I(e=>e.setStartedRunId),a=()=>z(`chat`),o=(0,Z.useCallback)(()=>n(`board`),[]);(0,Z.useEffect)(()=>{r&&(n(`board`),i(null))},[r,i]);let s=(e,t)=>{let r;if(e.key===`ArrowLeft`&&(r=(t-1+$.length)%$.length),e.key===`ArrowRight`&&(r=(t+1)%$.length),e.key===`Home`&&(r=0),e.key===`End`&&(r=$.length-1),r===void 0)return;e.preventDefault();let i=$[r];i&&(n(i.id),e.currentTarget.parentElement?.querySelectorAll(`[role="tab"]`)[r]?.focus())};return(0,Q.jsxs)(`div`,{className:`flex h-full min-h-0 min-w-0 flex-col bg-background`,children:[(0,Q.jsx)(`div`,{role:`tablist`,"aria-orientation":`horizontal`,className:`flex shrink-0 items-end border-b border-border/70 bg-card px-4`,children:$.map((r,i)=>{let a=t===r.id;return(0,Q.jsxs)(`button`,{id:`sdd-hub-tab-${r.id}`,type:`button`,role:`tab`,"aria-selected":a,"aria-controls":`sdd-hub-panel-${r.id}`,tabIndex:a?0:-1,onClick:()=>n(r.id),onKeyDown:e=>s(e,i),className:F(`relative px-4 py-2.5 text-sm font-medium transition-colors`,a?`text-foreground`:`text-muted-foreground hover:text-foreground`),children:[e(r.labelKey),a&&(0,Q.jsx)(`span`,{"aria-hidden":`true`,className:`absolute bottom-0 left-0 right-0 h-0.5 bg-primary`})]},r.id)})}),(0,Q.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-hidden`,children:[(0,Q.jsx)(`div`,{id:`sdd-hub-panel-project`,role:`tabpanel`,"aria-labelledby":`sdd-hub-tab-project`,hidden:t!==`project`,className:`h-full overflow-y-auto overscroll-contain`,children:(0,Q.jsx)(Ne,{onClose:a,onRunStarted:o})}),(0,Q.jsx)(`div`,{id:`sdd-hub-panel-board`,role:`tabpanel`,"aria-labelledby":`sdd-hub-tab-board`,hidden:t!==`board`,className:`h-full overflow-y-auto overscroll-contain`,children:(0,Q.jsx)(De,{onClose:a})}),(0,Q.jsx)(`div`,{id:`sdd-hub-panel-specs`,role:`tabpanel`,"aria-labelledby":`sdd-hub-tab-specs`,hidden:t!==`specs`,className:`h-full overflow-y-auto overscroll-contain`,children:(0,Q.jsx)(_e,{onClose:a,onRunStarted:o})})]})]})}export{Ie as SddHub};