@wrongstack/webui 0.296.3 → 0.297.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 (118) hide show
  1. package/dist/App.d.ts.map +1 -1
  2. package/dist/assets/{AgentRosterView-Bnfjs7SR.js → AgentRosterView-Cje2NBtU.js} +4 -4
  3. package/dist/assets/AnalyticsDashboard-CkceglT6.js +1 -0
  4. package/dist/assets/{AudienceMemoryPanel-BCXl0qMA.js → AudienceMemoryPanel-DB-8ISNP.js} +2 -2
  5. package/dist/assets/{ChangesView-CngAYbT4.js → ChangesView-DouwIaDk.js} +1 -1
  6. package/dist/assets/ChronicleDashboard-B4Khm6hu.js +1 -0
  7. package/dist/assets/CodeEditor-CrKbA5s8.js +1 -0
  8. package/dist/assets/CodeMap-Dz8yNlUe.js +1 -0
  9. package/dist/assets/{CronJobsPanel-CUjKpoEA.js → CronJobsPanel-CAImDL8t.js} +1 -1
  10. package/dist/assets/{DeadCodeScanPanel-DHsw8Nn4.js → DeadCodeScanPanel-C5ehBTQF.js} +1 -1
  11. package/dist/assets/DebugDashboard-DLNPZIEI.js +1 -0
  12. package/dist/assets/{DesignGalleryView-DDOG2RxE.js → DesignGalleryView-D0azMq2e.js} +1 -1
  13. package/dist/assets/GoalView-gtQRK78W.js +1 -0
  14. package/dist/assets/KanbanView-BXKe19EI.js +3 -0
  15. package/dist/assets/{LazyMarkdown-CaNUh8CL.js → LazyMarkdown-BGwFjYKr.js} +3 -3
  16. package/dist/assets/MailboxDetailView-D4fXipos.js +1 -0
  17. package/dist/assets/MemoryManager-D_rquas9.js +1 -0
  18. package/dist/assets/{ModelPicker-D5XBxW8U.js → ModelPicker-CN-UD3lc.js} +1 -1
  19. package/dist/assets/OfficeMapPanel-CJFrTNmg.js +4 -0
  20. package/dist/assets/{ProcessMonitor-DJaaQP3Q.js → ProcessMonitor-ButM8C0T.js} +1 -1
  21. package/dist/assets/{QueuePanel-DBQkV_Ka.js → QueuePanel-C5oihwYM.js} +1 -1
  22. package/dist/assets/{RefreshDebugView-BL9PikWZ.js → RefreshDebugView-DVvWsh9A.js} +1 -1
  23. package/dist/assets/{SageTabs-CPyvLW73.js → SageTabs-C9vAgvCD.js} +2 -2
  24. package/dist/assets/SddHub-D_nsWjuM.js +2 -0
  25. package/dist/assets/SessionsDashboard-DdwU3Ma5.js +1 -0
  26. package/dist/assets/SetupScreen-CQCfLdPI.js +1 -0
  27. package/dist/assets/SkillDetailView-mVxi-9jo.js +3 -0
  28. package/dist/assets/{SpecsView-T1qjfodF.js → SpecsView-BJs_okSx.js} +1 -1
  29. package/dist/assets/TechStackView-BZ4M7TYc.js +1 -0
  30. package/dist/assets/{TerminalPanel-yTWOVqll.js → TerminalPanel-W2V0X7b9.js} +1 -1
  31. package/dist/assets/{Toaster-D5WTIK_V.js → Toaster-CbcX_Cou.js} +1 -1
  32. package/dist/assets/{button-Bmh1yFe5.js → button-uGqXvobk.js} +1 -1
  33. package/dist/assets/chat-store-CM1dMeuY.js +17 -0
  34. package/dist/assets/{codemap-activity-store-CkJTt5go.js → codemap-activity-store-DP3mCZu1.js} +1 -1
  35. package/dist/assets/codemap-index-store-DyAe3ZYJ.js +1 -0
  36. package/dist/assets/{dialog-BLr7olIX.js → dialog-CT1PTjzK.js} +1 -1
  37. package/dist/assets/{empty-state-DoEewhfx.js → empty-state-CdyXy96A.js} +1 -1
  38. package/dist/assets/{i18n-D-JnOQZX.js → i18n-1BkaqMgr.js} +2 -2
  39. package/dist/assets/index-BPfIz78e.js +131 -0
  40. package/dist/assets/index-BlceaIyu.css +1 -0
  41. package/dist/assets/{input-BRS2rHSR.js → input-B-VCX2sG.js} +1 -1
  42. package/dist/assets/{mailbox-store-BN2cGkN_.js → mailbox-store-DVoNbOZr.js} +1 -1
  43. package/dist/assets/{progress-ring-DZ7API6e.js → progress-ring-CFOvGxw7.js} +1 -1
  44. package/dist/assets/{roster-ws-CVCrt_ih.js → roster-ws-DXm0krqH.js} +1 -1
  45. package/dist/assets/session-store-BsNYnfOc.js +1 -0
  46. package/dist/assets/settings-C5F2tQ7C.js +1 -0
  47. package/dist/assets/settings-Cdk8i_p6.js +1 -0
  48. package/dist/assets/settings-D6wFOw5n.js +1 -0
  49. package/dist/assets/settings-DCEOkxYE.js +1 -0
  50. package/dist/assets/settings-DEmKlLmn.js +1 -0
  51. package/dist/assets/settings-DsflqNn0.js +1 -0
  52. package/dist/assets/settings-skShEZ2B.js +1 -0
  53. package/dist/assets/{shared-DYL4K3aB.js → shared-jvJxtKc5.js} +1 -1
  54. package/dist/assets/{stores-hEu6z1qz.js → stores-mpa0202y.js} +1 -1
  55. package/dist/assets/{ui-store-BI3LH2q8.js → ui-store-CS-njcmT.js} +1 -1
  56. package/dist/assets/useWebSocket-Dh3aAFDE.js +28 -0
  57. package/dist/assets/{utils-DzRQUvln.js → utils-CN2sfDVP.js} +1 -1
  58. package/dist/assets/{vendor-9hC4n4Me.js → vendor-2VBBgNb5.js} +27 -27
  59. package/dist/assets/{view-navigation-BSA3_knE.js → view-navigation-Cgy5xh9q.js} +1 -1
  60. package/dist/assets/ws-client-WVGn8ORh.js +1 -0
  61. package/dist/components/AgentOfficeDetails.d.ts.map +1 -1
  62. package/dist/components/AgentOfficeView.d.ts.map +1 -1
  63. package/dist/components/AgentRosterView.d.ts.map +1 -1
  64. package/dist/components/AnalyticsDashboard.d.ts.map +1 -1
  65. package/dist/components/CodeMap.d.ts.map +1 -1
  66. package/dist/components/DeadCodeScanPanel/DeadCodeScanPanel.d.ts.map +1 -1
  67. package/dist/components/DebugDashboard.d.ts.map +1 -1
  68. package/dist/components/OfficeMapCanvas/CanvasPanels.d.ts.map +1 -1
  69. package/dist/components/OfficeMapCanvas.d.ts.map +1 -1
  70. package/dist/components/SetupScreen/ProviderKeyCard.d.ts.map +1 -1
  71. package/dist/components/SetupScreen.d.ts.map +1 -1
  72. package/dist/components/UpdateBanner.d.ts +8 -0
  73. package/dist/components/UpdateBanner.d.ts.map +1 -0
  74. package/dist/components/context-editor/ContextWindowEditor.d.ts.map +1 -1
  75. package/dist/hooks/ws-handlers/chat-handlers.d.ts.map +1 -1
  76. package/dist/hooks/ws-handlers/files-mailbox-handlers.d.ts +2 -1
  77. package/dist/hooks/ws-handlers/files-mailbox-handlers.d.ts.map +1 -1
  78. package/dist/hooks/ws-handlers/session-handlers.d.ts.map +1 -1
  79. package/dist/index.html +22 -22
  80. package/dist/index.js +9253 -8915
  81. package/dist/index.js.map +4 -4
  82. package/dist/lib/ws-client.d.ts.map +1 -1
  83. package/dist/stores/chat-store.d.ts +17 -1
  84. package/dist/stores/chat-store.d.ts.map +1 -1
  85. package/dist/stores/session-store.d.ts +11 -0
  86. package/dist/stores/session-store.d.ts.map +1 -1
  87. package/dist/types/server-message.d.ts +9 -0
  88. package/dist/types/server-message.d.ts.map +1 -1
  89. package/package.json +7 -7
  90. package/dist/assets/AnalyticsDashboard-Df_4y-Kx.js +0 -1
  91. package/dist/assets/ChronicleDashboard-BTnRluuW.js +0 -1
  92. package/dist/assets/CodeEditor-Bb8Oyrho.js +0 -1
  93. package/dist/assets/CodeMap-BOhBy8OQ.js +0 -1
  94. package/dist/assets/DebugDashboard-CF9tnDg7.js +0 -1
  95. package/dist/assets/GoalView-CAckYUC5.js +0 -1
  96. package/dist/assets/KanbanView-BMzDV1-z.js +0 -3
  97. package/dist/assets/MailboxDetailView-DQUJsig8.js +0 -1
  98. package/dist/assets/MemoryManager-JTZWsb0i.js +0 -1
  99. package/dist/assets/OfficeMapPanel-C6S89GWN.js +0 -4
  100. package/dist/assets/SddHub-CLFzMwKX.js +0 -2
  101. package/dist/assets/SessionsDashboard-B1lpqE1X.js +0 -1
  102. package/dist/assets/SetupScreen-M95bQ1A6.js +0 -1
  103. package/dist/assets/SkillDetailView-CeA6lnQh.js +0 -3
  104. package/dist/assets/TechStackView-ByuNsOIe.js +0 -1
  105. package/dist/assets/chat-store-DaSs2P3S.js +0 -13
  106. package/dist/assets/codemap-index-store-8v-MK2XF.js +0 -1
  107. package/dist/assets/index-B_lRId11.css +0 -1
  108. package/dist/assets/index-WvJRbCoi.js +0 -131
  109. package/dist/assets/session-store-w5G2euPs.js +0 -1
  110. package/dist/assets/settings-BHVrMeiB.js +0 -1
  111. package/dist/assets/settings-BNkUdI3D.js +0 -1
  112. package/dist/assets/settings-ByapDpso.js +0 -1
  113. package/dist/assets/settings-DDjoc06u.js +0 -1
  114. package/dist/assets/settings-DgZ3cEL3.js +0 -1
  115. package/dist/assets/settings-iiGjrvpU.js +0 -1
  116. package/dist/assets/settings-oGMBWYjV.js +0 -1
  117. package/dist/assets/useWebSocket-DAm5zYOB.js +0 -28
  118. package/dist/assets/ws-client-eyEv8wbm.js +0 -1
package/dist/App.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"App.d.ts","sourceRoot":"","sources":["../src/App.tsx"],"names":[],"mappings":"AA26BA,wBAAgB,GAAG,gCAQlB"}
1
+ {"version":3,"file":"App.d.ts","sourceRoot":"","sources":["../src/App.tsx"],"names":[],"mappings":"AA66BA,wBAAgB,GAAG,gCAQlB"}
@@ -1,11 +1,11 @@
1
- import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{t}from"./chat-store-DaSs2P3S.js";import{Ai as n,Ct as r,Ir as i,It as a,Ji as o,Kn as s,Li as c,Si as l,Ut as u,Xi as d,Yi as f,Zt as p,ai as m,at as h,bt as g,cn as _,et as v,gi as y,ii as b,it as x,ot as S,pa as C,qt as w,rr as T,tr as E,xa as D}from"./vendor-9hC4n4Me.js";import{n as O}from"./ui-store-BI3LH2q8.js";import{t as k}from"./ws-client-eyEv8wbm.js";import{t as A}from"./utils-DzRQUvln.js";import{x as j}from"./stores-hEu6z1qz.js";import{n as M}from"./Toaster-D5WTIK_V.js";import{n as N,t as P}from"./ModelPicker-D5XBxW8U.js";import{u as F}from"./index-WvJRbCoi.js";import{t as I}from"./roster-ws-CVCrt_ih.js";var L=e(D(),1),R=v(),z=[`Sun`,`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`],B=[[`timeoutMs`,`Total timeout (ms)`],[`idleTimeoutMs`,`Idle timeout (ms)`],[`maxIterations`,`Max iterations`],[`maxToolCalls`,`Max tool calls`],[`maxTokens`,`Max tokens`],[`maxCostUsd`,`Max cost (USD)`]];function V(e){return`${e.provider}/${e.model}`}function H(e){let t=e.indexOf(`/`);return t<0?{provider:``,model:e}:{provider:e.slice(0,t),model:e.slice(t+1)}}function U(e){return Array.isArray(e)?e.join(`, `):``}function W(e){return[...new Set(e.split(/[\n,]+/).map(e=>e.trim()).filter(Boolean))]}function G({initialConfig:e,systemProtected:t,saving:n,onSave:r,onCancel:i}){let[a,o]=(0,L.useState)(()=>structuredClone(e)),s=N(!0),c=a.modelPolicy,l=(0,L.useMemo)(()=>(c?.allowed??[]).map(V),[c?.allowed]),d=(0,L.useMemo)(()=>(c?.fallbacks??[]).map(V),[c?.fallbacks]),f=e=>o(t=>({...t,...e})),p=(e,t)=>{let n=W(t);o(t=>{let r={...t};return n.length?r[e]=n:delete r[e],r})},m=(e,t)=>{o(n=>{let r={...n.budget??{}};t===``?delete r[e]:r[e]=Number(t);let i={...n};return Object.keys(r).length?i.budget=r:delete i.budget,i})},h=e=>{let t=e.map(H),n=new Set(e);o(e=>({...e,modelPolicy:{allowed:t,fallbacks:(e.modelPolicy?.fallbacks??[]).filter(e=>n.has(V(e))),strict:e.modelPolicy?.strict??!0}}))};return(0,R.jsxs)(`div`,{className:`space-y-4 rounded-lg border border-border bg-card/40 p-4`,children:[t&&(0,R.jsxs)(`div`,{className:`flex gap-2 rounded-md border border-amber-500/30 bg-amber-500/5 p-2 text-[11px] text-muted-foreground`,children:[(0,R.jsx)(u,{className:`mt-0.5 h-4 w-4 shrink-0 text-amber-500`}),(0,R.jsx)(`span`,{children:`Protected system agent: required tools and capabilities are retained, minimum budgets are enforced, working hours remain advisory, and emergency model recovery stays enabled so core operations cannot be disabled.`})]}),(0,R.jsxs)(`section`,{className:`space-y-2`,children:[(0,R.jsx)(`h4`,{className:`text-xs font-semibold`,children:`Provider and model policy`}),(0,R.jsx)(P,{candidates:s,provider:a.provider,value:a.model,placeholder:`Use project default model`,resetLabel:`Use project default`,onReset:()=>{o(e=>{let t={...e};return delete t.provider,delete t.model,t})},onPick:(e,t)=>{let n=`${t}/${e}`;f({provider:t,model:e}),c&&!l.includes(n)&&h([...l,n])}}),(0,R.jsxs)(`label`,{className:`flex items-center gap-2 text-[11px]`,children:[(0,R.jsx)(`input`,{type:`checkbox`,checked:!!c,onChange:e=>{if(e.target.checked){let e=a.provider&&a.model?[{provider:a.provider,model:a.model}]:s[0]?[{provider:s[0].provider,model:s[0].model}]:[];e.length&&f({modelPolicy:{allowed:e,strict:!0}})}else o(e=>{let t={...e};return delete t.modelPolicy,t})}}),`Restrict this agent to an explicit model allowlist`]}),c&&(0,R.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,R.jsxs)(`div`,{className:`space-y-1`,children:[(0,R.jsx)(`span`,{className:`text-[10px] font-medium`,children:`Allowed models`}),(0,R.jsx)(F,{value:l,candidates:s,onChange:h,placeholder:`Add allowed model`,emptyHint:`At least one model is required`})]}),(0,R.jsxs)(`div`,{className:`space-y-1`,children:[(0,R.jsx)(`span`,{className:`text-[10px] font-medium`,children:`Ordered fallback chain`}),(0,R.jsx)(F,{value:d,candidates:s,onChange:e=>{let t=[...new Set([...l,...e])];o(n=>({...n,modelPolicy:{allowed:t.map(H),fallbacks:e.map(H),strict:n.modelPolicy?.strict??!0}}))},placeholder:`Add fallback model`,emptyHint:`No fallback; primary failure stops the task`})]})]})]}),(0,R.jsx)(`section`,{className:`grid gap-3 sm:grid-cols-3`,children:[[`tools`,`Tools`,`read_file, search, bash`],[`skillNames`,`Skills`,`security-check, browser`],[`allowedCapabilities`,`Capabilities`,`fs.read, fs.write`]].map(([e,t,n])=>(0,R.jsxs)(`label`,{className:`space-y-1 text-[10px]`,children:[(0,R.jsx)(`span`,{className:`font-medium`,children:t}),(0,R.jsx)(`textarea`,{value:U(a[e]),onChange:t=>p(e,t.target.value),placeholder:n,className:`h-20 w-full resize-y rounded border border-border bg-background p-2 font-mono`})]},e))}),(0,R.jsxs)(`section`,{className:`space-y-2`,children:[(0,R.jsx)(`h4`,{className:`text-xs font-semibold`,children:`Workspace and isolation`}),(0,R.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,R.jsxs)(`label`,{className:`space-y-1 text-[10px]`,children:[(0,R.jsx)(`span`,{children:`Project-relative working directory`}),(0,R.jsx)(`input`,{value:a.cwd??``,onChange:e=>f({cwd:e.target.value||void 0}),placeholder:`packages/webui`,className:`h-8 w-full rounded border border-border bg-background px-2 font-mono`})]}),(0,R.jsxs)(`label`,{className:`space-y-1 text-[10px]`,children:[(0,R.jsx)(`span`,{children:`Git worktree isolation`}),(0,R.jsxs)(`select`,{value:String(a.worktree??`auto`),onChange:e=>f({worktree:e.target.value}),className:`h-8 w-full rounded border border-border bg-background px-2`,children:[(0,R.jsx)(`option`,{value:`auto`,children:`Automatic`}),(0,R.jsx)(`option`,{value:`required`,children:`Required`}),(0,R.jsx)(`option`,{value:`off`,children:`Off`})]})]})]})]}),(0,R.jsxs)(`section`,{className:`space-y-2`,children:[(0,R.jsx)(`h4`,{className:`text-xs font-semibold`,children:`Limits`}),(0,R.jsx)(`div`,{className:`grid gap-2 sm:grid-cols-3`,children:B.map(([e,t])=>(0,R.jsxs)(`label`,{className:`space-y-1 text-[10px]`,children:[(0,R.jsx)(`span`,{children:t}),(0,R.jsx)(`input`,{type:`number`,min:`0`,step:e===`maxCostUsd`?`0.01`:`1`,value:a.budget?.[e]??``,onChange:t=>m(e,t.target.value),className:`h-8 w-full rounded border border-border bg-background px-2`})]},e))})]}),(0,R.jsxs)(`section`,{className:`space-y-2`,children:[(0,R.jsxs)(`label`,{className:`flex items-center gap-2 text-xs font-semibold`,children:[(0,R.jsx)(`input`,{type:`checkbox`,checked:!!a.availability,onChange:e=>{e.target.checked?f({availability:{timezone:Intl.DateTimeFormat().resolvedOptions().timeZone||`UTC`,days:[1,2,3,4,5],start:`09:00`,end:`18:00`,mode:t?`advisory`:`enforce`}}):o(e=>{let t={...e};return delete t.availability,t})}}),`Working hours`]}),a.availability&&(0,R.jsxs)(`div`,{className:`space-y-2 rounded border border-border p-2`,children:[(0,R.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:z.map((e,t)=>(0,R.jsxs)(`label`,{className:`flex items-center gap-1 text-[10px]`,children:[(0,R.jsx)(`input`,{type:`checkbox`,checked:a.availability?.days.includes(t)??!1,onChange:e=>{let n=a.availability;if(!n)return;let r=e.target.checked?[...new Set([...n.days,t])].sort():n.days.filter(e=>e!==t);f({availability:{...n,days:r}})}}),e]},e))}),(0,R.jsxs)(`div`,{className:`grid gap-2 sm:grid-cols-4`,children:[(0,R.jsx)(`input`,{value:a.availability.timezone,onChange:e=>f({availability:{...a.availability,timezone:e.target.value}}),placeholder:`Europe/Kiev`,className:`h-8 rounded border border-border bg-background px-2 text-[10px]`}),(0,R.jsx)(`input`,{type:`time`,value:a.availability.start,onChange:e=>f({availability:{...a.availability,start:e.target.value}}),className:`h-8 rounded border border-border bg-background px-2 text-[10px]`}),(0,R.jsx)(`input`,{type:`time`,value:a.availability.end,onChange:e=>f({availability:{...a.availability,end:e.target.value}}),className:`h-8 rounded border border-border bg-background px-2 text-[10px]`}),(0,R.jsxs)(`select`,{value:t?`advisory`:a.availability.mode??`enforce`,disabled:t,onChange:e=>f({availability:{...a.availability,mode:e.target.value}}),className:`h-8 rounded border border-border bg-background px-2 text-[10px]`,children:[(0,R.jsx)(`option`,{value:`enforce`,children:`Enforce`}),(0,R.jsx)(`option`,{value:`advisory`,children:`Advisory`})]})]})]})]}),(0,R.jsxs)(`div`,{className:`flex gap-2`,children:[(0,R.jsx)(`button`,{type:`button`,disabled:n||!!(c&&c.allowed.length===0),onClick:()=>r(a),className:`rounded bg-primary px-3 py-1.5 text-xs text-primary-foreground disabled:opacity-50`,children:n?`Saving…`:`Save runtime policy`}),(0,R.jsx)(`button`,{type:`button`,onClick:i,className:`rounded border border-border px-3 py-1.5 text-xs hover:bg-accent`,children:`Cancel`})]})]})}var K=[{id:`live`,icon:(0,R.jsx)(C,{className:`h-4 w-4`}),label:`Live Fleet`},{id:`catalog`,icon:(0,R.jsx)(f,{className:`h-4 w-4`}),label:`Roster Catalog`},{id:`learning`,icon:(0,R.jsx)(d,{className:`h-4 w-4`}),label:`Self-Learning`},{id:`customize`,icon:(0,R.jsx)(w,{className:`h-4 w-4`}),label:`Customization`}],q=[{role:`generic`,name:`Generic Project Agent`,summary:`Flexible template that can be cloned into independently learning project roles.`,tools:0,budget:{maxIterations:2500,maxToolCalls:7500}},{role:`audit-log`,name:`Audit Log`,summary:`Analyzes session logs, event streams, and system traces.`,tools:12,budget:{timeoutMs:108e5,maxIterations:2500,maxToolCalls:7500}},{role:`bug-hunter`,name:`Bug Hunter`,summary:`Scans code for bugs, code smells, and anti-patterns.`,tools:15,budget:{timeoutMs:18e6,maxIterations:4e3,maxToolCalls:1e4}},{role:`refactor-planner`,name:`Refactor Planner`,summary:`Analyzes code structure and produces phased refactoring plans.`,tools:14,budget:{timeoutMs:144e5,maxIterations:3e3,maxToolCalls:9e3}},{role:`security-scanner`,name:`Security Scanner`,summary:`Scans code, configs, and dependencies for security issues.`,tools:18,budget:{timeoutMs:18e6,maxIterations:4e3,maxToolCalls:1e4}},{role:`critic`,name:`Critic`,summary:`Evaluates decisions, plans, and implementations.`,tools:10,budget:{timeoutMs:108e5,maxIterations:2e3,maxToolCalls:5e3}},{role:`shadow-agent`,name:`Shadow Agent`,summary:`Background monitoring agent that watches fleet health.`,tools:8,budget:{timeoutMs:36e6,maxIterations:500,maxToolCalls:2e3}},{role:`executor`,name:`Executor`,summary:`General-purpose task executor for delegated work.`,tools:20,budget:{timeoutMs:72e5,maxIterations:1500,maxToolCalls:4e3}},{role:`chimera`,name:`Chimera`,summary:`Post-session code quality review of changed files.`,tools:10,budget:{timeoutMs:72e5,maxIterations:1e3,maxToolCalls:3e3}},{role:`researcher`,name:`Researcher`,summary:`Web research and data gathering specialist.`,tools:8,budget:{timeoutMs:72e5,maxIterations:1e3,maxToolCalls:3e3}},{role:`tech-stack`,name:`Tech Stack Validator`,summary:`Validates package/library/framework choices.`,tools:9,budget:{timeoutMs:72e5,maxIterations:1e3,maxToolCalls:3e3}},{role:`orchestrator`,name:`Orchestrator`,summary:`Coordinates multi-agent task execution.`,tools:12,budget:{timeoutMs:144e5,maxIterations:3e3,maxToolCalls:8e3}},{role:`supervisor`,name:`Supervisor`,summary:`Oversees subagent execution and handles escalations.`,tools:10,budget:{timeoutMs:144e5,maxIterations:2e3,maxToolCalls:6e3}},{role:`quality-gate`,name:`Quality Gate`,summary:`Enforces quality gates on implementations.`,tools:8,budget:{timeoutMs:72e5,maxIterations:1e3,maxToolCalls:3e3}},{role:`architect`,name:`Architect`,summary:`Makes design and architecture decisions.`,tools:14,budget:{timeoutMs:144e5,maxIterations:3e3,maxToolCalls:8e3}},{role:`prompt-engineer`,name:`Prompt Engineer`,summary:`Designs and optimizes system prompts.`,tools:8,budget:{timeoutMs:72e5,maxIterations:1e3,maxToolCalls:3e3}},{role:`mnemosyne`,name:`Mnemosyne`,summary:`Memory curator — reviews and maintains SAGE integrity.`,tools:6,budget:{timeoutMs:72e5,maxIterations:500,maxToolCalls:2e3}},{role:`autophase`,name:`AutoPhase`,summary:`Manages multi-phase autonomous task execution.`,tools:10,budget:{timeoutMs:144e5,maxIterations:2e3,maxToolCalls:6e3}}];function J({customStats:e,rosterLoading:t,onRefresh:n}){return(0,R.jsx)(`div`,{className:`shrink-0 border-b border-border/70 bg-card/80 px-4 py-2.5`,children:(0,R.jsxs)(`div`,{className:`flex items-center justify-between gap-2 flex-nowrap min-w-0`,children:[(0,R.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0 overflow-hidden`,children:[(0,R.jsx)(`div`,{className:`flex items-center justify-center w-8 h-8 shrink-0 rounded-lg bg-primary/10`,children:(0,R.jsx)(E,{className:`h-4 w-4 text-primary`})}),(0,R.jsxs)(`div`,{className:`min-w-0 overflow-hidden`,children:[(0,R.jsx)(`h1`,{className:`text-sm font-semibold truncate`,children:`Agent Roster`}),(0,R.jsxs)(`p`,{className:`text-[10px] text-muted-foreground truncate`,children:[e.filter(e=>e.exists||e.hasIdentity||e.hasConfig||e.hasKnowledge).length,` `,`customized · `,e.reduce((e,t)=>e+t.entryCount,0),` learned entries`]})]})]}),(0,R.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[t&&(0,R.jsx)(s,{className:`h-4 w-4 animate-spin text-muted-foreground shrink-0`}),(0,R.jsxs)(`button`,{type:`button`,onClick:n,className:`inline-flex items-center gap-1 rounded border border-border/50 px-2 py-1 text-[10px] hover:bg-accent transition-colors shrink-0 whitespace-nowrap`,title:`Refresh roster data`,children:[(0,R.jsx)(_,{className:`h-3 w-3`}),` Refresh`]})]})]})})}function Y({activeTab:e,onTabChange:t}){return(0,R.jsx)(`div`,{className:`shrink-0 border-b border-border/50 bg-muted/20 px-3 flex gap-0`,children:K.map(n=>(0,R.jsxs)(`button`,{type:`button`,onClick:()=>t(n.id),className:A(`flex items-center gap-1.5 px-3 py-2 text-[10px] font-medium border-b-2 transition-colors`,e===n.id?`border-primary text-primary`:`border-transparent text-muted-foreground hover:text-foreground hover:border-muted-foreground/30`),children:[n.icon,n.label]},n.id))})}function X({customStats:e,onRefresh:r}){let[i,o]=(0,L.useState)(null),[c,l]=(0,L.useState)(null),[u,p]=(0,L.useState)({}),[m,h]=(0,L.useState)(``),[_,v]=(0,L.useState)(null),[y,S]=(0,L.useState)(!1),[C,w]=(0,L.useState)(!1),[T,E]=(0,L.useState)(null),[D,j]=(0,L.useState)(!1),[N,P]=(0,L.useState)(!1),F=(0,L.useMemo)(()=>[...e].sort((e,t)=>e.role.localeCompare(t.role)),[e]),z=(0,L.useMemo)(()=>i?F.find(e=>e.role===i):null,[i,F]),B=(0,L.useCallback)(async e=>{w(!0),l(null);try{let t=await I(`agent-roster.read-learned`,{role:e});l(t.entries??[]),p({})}catch{}w(!1)},[]),V=(0,L.useCallback)(async()=>{if(!i||!c)return;S(!0);let e=c.filter((e,t)=>u[t]!==`drop`).join(`
1
+ import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{t}from"./chat-store-CM1dMeuY.js";import{Ai as n,Ct as r,Ir as i,It as a,Kn as o,Ri as s,Sa as c,Si as l,Ut as u,Xi as d,Yi as f,Zi as p,Zt as m,ai as h,at as g,bt as _,cn as v,et as y,gi as b,ii as x,it as S,ma as C,ot as w,qt as T,rr as E,tr as D}from"./vendor-2VBBgNb5.js";import{n as O}from"./ui-store-CS-njcmT.js";import{t as k}from"./ws-client-WVGn8ORh.js";import{t as A}from"./utils-CN2sfDVP.js";import{x as j}from"./stores-mpa0202y.js";import{n as M}from"./Toaster-CbcX_Cou.js";import{n as N,t as P}from"./ModelPicker-CN-UD3lc.js";import{u as F}from"./index-BPfIz78e.js";import{t as I}from"./roster-ws-DXm0krqH.js";var L=e(c(),1),R=y(),z=[`Sun`,`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`],B=[[`timeoutMs`,`Total timeout (ms)`],[`idleTimeoutMs`,`Idle timeout (ms)`],[`maxIterations`,`Max iterations`],[`maxToolCalls`,`Max tool calls`],[`maxTokens`,`Max tokens`],[`maxCostUsd`,`Max cost (USD)`]];function V(e){return`${e.provider}/${e.model}`}function H(e){let t=e.indexOf(`/`);return t<0?{provider:``,model:e}:{provider:e.slice(0,t),model:e.slice(t+1)}}function U(e){return Array.isArray(e)?e.join(`, `):``}function W(e){return[...new Set(e.split(/[\n,]+/).map(e=>e.trim()).filter(Boolean))]}function G({initialConfig:e,systemProtected:t,saving:n,onSave:r,onCancel:i}){let[a,o]=(0,L.useState)(()=>structuredClone(e)),s=N(!0),c=a.modelPolicy,l=(0,L.useMemo)(()=>(c?.allowed??[]).map(V),[c?.allowed]),d=(0,L.useMemo)(()=>(c?.fallbacks??[]).map(V),[c?.fallbacks]),f=e=>o(t=>({...t,...e})),p=(e,t)=>{let n=W(t);o(t=>{let r={...t};return n.length?r[e]=n:delete r[e],r})},m=(e,t)=>{o(n=>{let r={...n.budget??{}};t===``?delete r[e]:r[e]=Number(t);let i={...n};return Object.keys(r).length?i.budget=r:delete i.budget,i})},h=e=>{let t=e.map(H),n=new Set(e);o(e=>({...e,modelPolicy:{allowed:t,fallbacks:(e.modelPolicy?.fallbacks??[]).filter(e=>n.has(V(e))),strict:e.modelPolicy?.strict??!0}}))};return(0,R.jsxs)(`div`,{className:`space-y-4 rounded-lg border border-border bg-card/40 p-4`,children:[t&&(0,R.jsxs)(`div`,{className:`flex gap-2 rounded-md border border-amber-500/30 bg-amber-500/5 p-2 text-[11px] text-muted-foreground`,children:[(0,R.jsx)(u,{className:`mt-0.5 h-4 w-4 shrink-0 text-amber-500`}),(0,R.jsx)(`span`,{children:`Protected system agent: required tools and capabilities are retained, minimum budgets are enforced, working hours remain advisory, and emergency model recovery stays enabled so core operations cannot be disabled.`})]}),(0,R.jsxs)(`section`,{className:`space-y-2`,children:[(0,R.jsx)(`h4`,{className:`text-xs font-semibold`,children:`Provider and model policy`}),(0,R.jsx)(P,{candidates:s,provider:a.provider,value:a.model,placeholder:`Use project default model`,resetLabel:`Use project default`,onReset:()=>{o(e=>{let t={...e};return delete t.provider,delete t.model,t})},onPick:(e,t)=>{let n=`${t}/${e}`;f({provider:t,model:e}),c&&!l.includes(n)&&h([...l,n])}}),(0,R.jsxs)(`label`,{className:`flex items-center gap-2 text-[11px]`,children:[(0,R.jsx)(`input`,{type:`checkbox`,checked:!!c,onChange:e=>{if(e.target.checked){let e=a.provider&&a.model?[{provider:a.provider,model:a.model}]:s[0]?[{provider:s[0].provider,model:s[0].model}]:[];e.length&&f({modelPolicy:{allowed:e,strict:!0}})}else o(e=>{let t={...e};return delete t.modelPolicy,t})}}),`Restrict this agent to an explicit model allowlist`]}),c&&(0,R.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,R.jsxs)(`div`,{className:`space-y-1`,children:[(0,R.jsx)(`span`,{className:`text-[10px] font-medium`,children:`Allowed models`}),(0,R.jsx)(F,{value:l,candidates:s,onChange:h,placeholder:`Add allowed model`,emptyHint:`At least one model is required`})]}),(0,R.jsxs)(`div`,{className:`space-y-1`,children:[(0,R.jsx)(`span`,{className:`text-[10px] font-medium`,children:`Ordered fallback chain`}),(0,R.jsx)(F,{value:d,candidates:s,onChange:e=>{let t=[...new Set([...l,...e])];o(n=>({...n,modelPolicy:{allowed:t.map(H),fallbacks:e.map(H),strict:n.modelPolicy?.strict??!0}}))},placeholder:`Add fallback model`,emptyHint:`No fallback; primary failure stops the task`})]})]})]}),(0,R.jsx)(`section`,{className:`grid gap-3 sm:grid-cols-3`,children:[[`tools`,`Tools`,`read_file, search, bash`],[`skillNames`,`Skills`,`security-check, browser`],[`allowedCapabilities`,`Capabilities`,`fs.read, fs.write`]].map(([e,t,n])=>(0,R.jsxs)(`label`,{className:`space-y-1 text-[10px]`,children:[(0,R.jsx)(`span`,{className:`font-medium`,children:t}),(0,R.jsx)(`textarea`,{value:U(a[e]),onChange:t=>p(e,t.target.value),placeholder:n,className:`h-20 w-full resize-y rounded border border-border bg-background p-2 font-mono`})]},e))}),(0,R.jsxs)(`section`,{className:`space-y-2`,children:[(0,R.jsx)(`h4`,{className:`text-xs font-semibold`,children:`Workspace and isolation`}),(0,R.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,R.jsxs)(`label`,{className:`space-y-1 text-[10px]`,children:[(0,R.jsx)(`span`,{children:`Project-relative working directory`}),(0,R.jsx)(`input`,{value:a.cwd??``,onChange:e=>f({cwd:e.target.value||void 0}),placeholder:`packages/webui`,className:`h-8 w-full rounded border border-border bg-background px-2 font-mono`})]}),(0,R.jsxs)(`label`,{className:`space-y-1 text-[10px]`,children:[(0,R.jsx)(`span`,{children:`Git worktree isolation`}),(0,R.jsxs)(`select`,{value:String(a.worktree??`auto`),onChange:e=>f({worktree:e.target.value}),className:`h-8 w-full rounded border border-border bg-background px-2`,children:[(0,R.jsx)(`option`,{value:`auto`,children:`Automatic`}),(0,R.jsx)(`option`,{value:`required`,children:`Required`}),(0,R.jsx)(`option`,{value:`off`,children:`Off`})]})]})]})]}),(0,R.jsxs)(`section`,{className:`space-y-2`,children:[(0,R.jsx)(`h4`,{className:`text-xs font-semibold`,children:`Limits`}),(0,R.jsx)(`div`,{className:`grid gap-2 sm:grid-cols-3`,children:B.map(([e,t])=>(0,R.jsxs)(`label`,{className:`space-y-1 text-[10px]`,children:[(0,R.jsx)(`span`,{children:t}),(0,R.jsx)(`input`,{type:`number`,min:`0`,step:e===`maxCostUsd`?`0.01`:`1`,value:a.budget?.[e]??``,onChange:t=>m(e,t.target.value),className:`h-8 w-full rounded border border-border bg-background px-2`})]},e))})]}),(0,R.jsxs)(`section`,{className:`space-y-2`,children:[(0,R.jsxs)(`label`,{className:`flex items-center gap-2 text-xs font-semibold`,children:[(0,R.jsx)(`input`,{type:`checkbox`,checked:!!a.availability,onChange:e=>{e.target.checked?f({availability:{timezone:Intl.DateTimeFormat().resolvedOptions().timeZone||`UTC`,days:[1,2,3,4,5],start:`09:00`,end:`18:00`,mode:t?`advisory`:`enforce`}}):o(e=>{let t={...e};return delete t.availability,t})}}),`Working hours`]}),a.availability&&(0,R.jsxs)(`div`,{className:`space-y-2 rounded border border-border p-2`,children:[(0,R.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:z.map((e,t)=>(0,R.jsxs)(`label`,{className:`flex items-center gap-1 text-[10px]`,children:[(0,R.jsx)(`input`,{type:`checkbox`,checked:a.availability?.days.includes(t)??!1,onChange:e=>{let n=a.availability;if(!n)return;let r=e.target.checked?[...new Set([...n.days,t])].sort():n.days.filter(e=>e!==t);f({availability:{...n,days:r}})}}),e]},e))}),(0,R.jsxs)(`div`,{className:`grid gap-2 sm:grid-cols-4`,children:[(0,R.jsx)(`input`,{value:a.availability.timezone,onChange:e=>f({availability:{...a.availability,timezone:e.target.value}}),placeholder:`Europe/Kiev`,className:`h-8 rounded border border-border bg-background px-2 text-[10px]`}),(0,R.jsx)(`input`,{type:`time`,value:a.availability.start,onChange:e=>f({availability:{...a.availability,start:e.target.value}}),className:`h-8 rounded border border-border bg-background px-2 text-[10px]`}),(0,R.jsx)(`input`,{type:`time`,value:a.availability.end,onChange:e=>f({availability:{...a.availability,end:e.target.value}}),className:`h-8 rounded border border-border bg-background px-2 text-[10px]`}),(0,R.jsxs)(`select`,{value:t?`advisory`:a.availability.mode??`enforce`,disabled:t,onChange:e=>f({availability:{...a.availability,mode:e.target.value}}),className:`h-8 rounded border border-border bg-background px-2 text-[10px]`,children:[(0,R.jsx)(`option`,{value:`enforce`,children:`Enforce`}),(0,R.jsx)(`option`,{value:`advisory`,children:`Advisory`})]})]})]})]}),(0,R.jsxs)(`div`,{className:`flex gap-2`,children:[(0,R.jsx)(`button`,{type:`button`,disabled:n||!!(c&&c.allowed.length===0),onClick:()=>r(a),className:`rounded bg-primary px-3 py-1.5 text-xs text-primary-foreground disabled:opacity-50`,children:n?`Saving…`:`Save runtime policy`}),(0,R.jsx)(`button`,{type:`button`,onClick:i,className:`rounded border border-border px-3 py-1.5 text-xs hover:bg-accent`,children:`Cancel`})]})]})}var K=[{id:`live`,icon:(0,R.jsx)(C,{className:`h-4 w-4`}),label:`Live Fleet`},{id:`catalog`,icon:(0,R.jsx)(d,{className:`h-4 w-4`}),label:`Roster Catalog`},{id:`learning`,icon:(0,R.jsx)(p,{className:`h-4 w-4`}),label:`Self-Learning`},{id:`customize`,icon:(0,R.jsx)(T,{className:`h-4 w-4`}),label:`Customization`}],q=[{role:`generic`,name:`Generic Project Agent`,summary:`Flexible template that can be cloned into independently learning project roles.`,tools:0,budget:{maxIterations:2500,maxToolCalls:7500}},{role:`audit-log`,name:`Audit Log`,summary:`Analyzes session logs, event streams, and system traces.`,tools:12,budget:{timeoutMs:108e5,maxIterations:2500,maxToolCalls:7500}},{role:`bug-hunter`,name:`Bug Hunter`,summary:`Scans code for bugs, code smells, and anti-patterns.`,tools:15,budget:{timeoutMs:18e6,maxIterations:4e3,maxToolCalls:1e4}},{role:`refactor-planner`,name:`Refactor Planner`,summary:`Analyzes code structure and produces phased refactoring plans.`,tools:14,budget:{timeoutMs:144e5,maxIterations:3e3,maxToolCalls:9e3}},{role:`security-scanner`,name:`Security Scanner`,summary:`Scans code, configs, and dependencies for security issues.`,tools:18,budget:{timeoutMs:18e6,maxIterations:4e3,maxToolCalls:1e4}},{role:`critic`,name:`Critic`,summary:`Evaluates decisions, plans, and implementations.`,tools:10,budget:{timeoutMs:108e5,maxIterations:2e3,maxToolCalls:5e3}},{role:`shadow-agent`,name:`Shadow Agent`,summary:`Background monitoring agent that watches fleet health.`,tools:8,budget:{timeoutMs:36e6,maxIterations:500,maxToolCalls:2e3}},{role:`executor`,name:`Executor`,summary:`General-purpose task executor for delegated work.`,tools:20,budget:{timeoutMs:72e5,maxIterations:1500,maxToolCalls:4e3}},{role:`chimera`,name:`Chimera`,summary:`Post-session code quality review of changed files.`,tools:10,budget:{timeoutMs:72e5,maxIterations:1e3,maxToolCalls:3e3}},{role:`researcher`,name:`Researcher`,summary:`Web research and data gathering specialist.`,tools:8,budget:{timeoutMs:72e5,maxIterations:1e3,maxToolCalls:3e3}},{role:`tech-stack`,name:`Tech Stack Validator`,summary:`Validates package/library/framework choices.`,tools:9,budget:{timeoutMs:72e5,maxIterations:1e3,maxToolCalls:3e3}},{role:`orchestrator`,name:`Orchestrator`,summary:`Coordinates multi-agent task execution.`,tools:12,budget:{timeoutMs:144e5,maxIterations:3e3,maxToolCalls:8e3}},{role:`supervisor`,name:`Supervisor`,summary:`Oversees subagent execution and handles escalations.`,tools:10,budget:{timeoutMs:144e5,maxIterations:2e3,maxToolCalls:6e3}},{role:`quality-gate`,name:`Quality Gate`,summary:`Enforces quality gates on implementations.`,tools:8,budget:{timeoutMs:72e5,maxIterations:1e3,maxToolCalls:3e3}},{role:`architect`,name:`Architect`,summary:`Makes design and architecture decisions.`,tools:14,budget:{timeoutMs:144e5,maxIterations:3e3,maxToolCalls:8e3}},{role:`prompt-engineer`,name:`Prompt Engineer`,summary:`Designs and optimizes system prompts.`,tools:8,budget:{timeoutMs:72e5,maxIterations:1e3,maxToolCalls:3e3}},{role:`mnemosyne`,name:`Mnemosyne`,summary:`Memory curator — reviews and maintains SAGE integrity.`,tools:6,budget:{timeoutMs:72e5,maxIterations:500,maxToolCalls:2e3}},{role:`autophase`,name:`AutoPhase`,summary:`Manages multi-phase autonomous task execution.`,tools:10,budget:{timeoutMs:144e5,maxIterations:2e3,maxToolCalls:6e3}}];function J({customStats:e,rosterLoading:t,onRefresh:n}){return(0,R.jsx)(`div`,{className:`shrink-0 border-b border-border/70 bg-card/80 px-4 py-2.5`,children:(0,R.jsxs)(`div`,{className:`flex items-center justify-between gap-2 flex-nowrap min-w-0`,children:[(0,R.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0 overflow-hidden`,children:[(0,R.jsx)(`div`,{className:`flex items-center justify-center w-8 h-8 shrink-0 rounded-lg bg-primary/10`,children:(0,R.jsx)(D,{className:`h-4 w-4 text-primary`})}),(0,R.jsxs)(`div`,{className:`min-w-0 overflow-hidden`,children:[(0,R.jsx)(`h1`,{className:`text-sm font-semibold truncate`,children:`Agent Roster`}),(0,R.jsxs)(`p`,{className:`text-[10px] text-muted-foreground truncate`,children:[e.filter(e=>e.exists||e.hasIdentity||e.hasConfig||e.hasKnowledge).length,` `,`customized · `,e.reduce((e,t)=>e+t.entryCount,0),` learned entries`]})]})]}),(0,R.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[t&&(0,R.jsx)(o,{className:`h-4 w-4 animate-spin text-muted-foreground shrink-0`}),(0,R.jsxs)(`button`,{type:`button`,onClick:n,className:`inline-flex items-center gap-1 rounded border border-border/50 px-2 py-1 text-[10px] hover:bg-accent transition-colors shrink-0 whitespace-nowrap`,title:`Refresh roster data`,children:[(0,R.jsx)(v,{className:`h-3 w-3`}),` Refresh`]})]})]})})}function Y({activeTab:e,onTabChange:t}){return(0,R.jsx)(`div`,{className:`shrink-0 border-b border-border/50 bg-muted/20 px-3 flex gap-0`,children:K.map(n=>(0,R.jsxs)(`button`,{type:`button`,onClick:()=>t(n.id),className:A(`flex items-center gap-1.5 px-3 py-2 text-[10px] font-medium border-b-2 transition-colors`,e===n.id?`border-primary text-primary`:`border-transparent text-muted-foreground hover:text-foreground hover:border-muted-foreground/30`),children:[n.icon,n.label]},n.id))})}function X({customStats:e,onRefresh:r}){let[i,s]=(0,L.useState)(null),[c,l]=(0,L.useState)(null),[u,f]=(0,L.useState)({}),[m,h]=(0,L.useState)(``),[g,v]=(0,L.useState)(null),[y,b]=(0,L.useState)(!1),[C,w]=(0,L.useState)(!1),[T,E]=(0,L.useState)(null),[D,j]=(0,L.useState)(!1),[N,P]=(0,L.useState)(!1),F=(0,L.useMemo)(()=>[...e].sort((e,t)=>e.role.localeCompare(t.role)),[e]),z=(0,L.useMemo)(()=>i?F.find(e=>e.role===i):null,[i,F]),B=(0,L.useCallback)(async e=>{w(!0),l(null);try{let t=await I(`agent-roster.read-learned`,{role:e});l(t.entries??[]),f({})}catch{}w(!1)},[]),V=(0,L.useCallback)(async()=>{if(!i||!c)return;b(!0);let e=c.filter((e,t)=>u[t]!==`drop`).join(`
2
2
 
3
3
  ---
4
4
 
5
- `);try{await I(`agent-roster.update-learned`,{role:i,content:e}),l(null),p({})}catch{}S(!1)},[i,c,u]),H=(0,L.useCallback)(async()=>{if(!(!i||!m.trim())){v(null),S(!0);try{let e=`> Taught ${new Date().toISOString().slice(0,10)}\n\n${m.trim()}`;(await I(`agent-roster.append-learned`,{role:i,content:e})).success?(v({ok:!0,msg:`Saved to learned.md`}),h(``),r()):v({ok:!1,msg:`Save failed`})}catch(e){v({ok:!1,msg:e instanceof Error?e.message:`Failed`})}S(!1)}},[r,i,m]),U=(0,L.useCallback)(async(e,t)=>{S(!0),v(null);try{let n=await I(`agent-roster.update-learning`,{role:e,enabled:t});if(n.error)throw Error(n.error);v({ok:!0,msg:t?`Automatic learning resumed`:`Automatic learning paused`}),r()}catch(e){v({ok:!1,msg:e instanceof Error?e.message:`Policy update failed`})}finally{S(!1)}},[r]),W=(0,L.useCallback)(async e=>{try{let t=await I(`agent-roster.read-consolidated`,{role:e});E(t.isConsolidated?t.content:null)}catch{E(null)}},[]),G=(0,L.useCallback)(async e=>{j(!0),v(null);try{let n=await I(`agent-roster.consolidate`,{role:e});if(n.error)throw Error(n.error);if(n.rawEntryCount===0){v({ok:!1,msg:`No raw entries to optimize yet.`});return}if(n.consolidated){await r(),await W(e),v({ok:!0,msg:`Optimized. Consolidated knowledge updated.`}),M.success(n.model?`Learnings consolidated with ${n.model}.`:`Learnings consolidated.`);return}if(n.emptySynthesis){v({ok:!1,msg:`The model returned an empty result. Nothing was changed — try again.`}),M.error(`Optimization produced an empty result. Try again.`);return}let i=n.instruction;if(!i)throw Error(`No consolidation instruction generated`);let a=t.getState();a.addMessage({role:`user`,content:i}),a.setLoading(!0),k().sendMessage(i);let o=O.getState();o.setSidebarOpen(!1),o.setCurrentView(`chat`),v({ok:!0,msg:`No active model on server — optimization sent to chat agent instead.`}),M.info(`No active model on server. Optimization sent to the chat agent.`)}catch(e){v({ok:!1,msg:e instanceof Error?e.message:`Optimization failed`}),M.error(e instanceof Error?e.message:`Optimization failed`)}finally{j(!1)}},[r,W]),K=(0,L.useCallback)(async e=>{if(e.length!==0){P(!0),v(null);try{let n=[],r=0,a=0,o=``,s=[];for(let t of e)try{let e=await I(`agent-roster.consolidate`,{role:t});e.error?(a++,o=e.error):e.consolidated?n.push(t):e.rawEntryCount===0?r++:e.emptySynthesis?(a++,o=`Model returned an empty result`):e.instruction?s.push({role:t,instruction:e.instruction}):(a++,o=`No consolidation produced`)}catch(e){a++,o=e instanceof Error?e.message:String(e)}if(i&&n.includes(i)&&await W(i),s.length>0){let e=`Optimize the learned data for ${s.length} agent${s.length>1?`s`:``}. For each agent below, read its raw learned entries, synthesize them into a single narrowly-scoped document preserving every fact, and save the result to its consolidated.md file.\n\n`+s.map(e=>`## Agent: ${e.role}\n\n${e.instruction}`).join(`
5
+ `);try{await I(`agent-roster.update-learned`,{role:i,content:e}),l(null),f({})}catch{}b(!1)},[i,c,u]),H=(0,L.useCallback)(async()=>{if(!(!i||!m.trim())){v(null),b(!0);try{let e=`> Taught ${new Date().toISOString().slice(0,10)}\n\n${m.trim()}`;(await I(`agent-roster.append-learned`,{role:i,content:e})).success?(v({ok:!0,msg:`Saved to learned.md`}),h(``),r()):v({ok:!1,msg:`Save failed`})}catch(e){v({ok:!1,msg:e instanceof Error?e.message:`Failed`})}b(!1)}},[r,i,m]),U=(0,L.useCallback)(async(e,t)=>{b(!0),v(null);try{let n=await I(`agent-roster.update-learning`,{role:e,enabled:t});if(n.error)throw Error(n.error);v({ok:!0,msg:t?`Automatic learning resumed`:`Automatic learning paused`}),r()}catch(e){v({ok:!1,msg:e instanceof Error?e.message:`Policy update failed`})}finally{b(!1)}},[r]),W=(0,L.useCallback)(async e=>{try{let t=await I(`agent-roster.read-consolidated`,{role:e});E(t.isConsolidated?t.content:null)}catch{E(null)}},[]),G=(0,L.useCallback)(async e=>{j(!0),v(null);try{let n=await I(`agent-roster.consolidate`,{role:e});if(n.error)throw Error(n.error);if(n.rawEntryCount===0){v({ok:!1,msg:`No raw entries to optimize yet.`});return}if(n.consolidated){await r(),await W(e),v({ok:!0,msg:`Optimized. Consolidated knowledge updated.`}),M.success(n.model?`Learnings consolidated with ${n.model}.`:`Learnings consolidated.`);return}if(n.emptySynthesis){v({ok:!1,msg:`The model returned an empty result. Nothing was changed — try again.`}),M.error(`Optimization produced an empty result. Try again.`);return}let i=n.instruction;if(!i)throw Error(`No consolidation instruction generated`);let a=t.getState();a.addMessage({role:`user`,content:i}),a.setLoading(!0),k().sendMessage(i);let o=O.getState();o.setSidebarOpen(!1),o.setCurrentView(`chat`),v({ok:!0,msg:`No active model on server — optimization sent to chat agent instead.`}),M.info(`No active model on server. Optimization sent to the chat agent.`)}catch(e){v({ok:!1,msg:e instanceof Error?e.message:`Optimization failed`}),M.error(e instanceof Error?e.message:`Optimization failed`)}finally{j(!1)}},[r,W]),K=(0,L.useCallback)(async e=>{if(e.length!==0){P(!0),v(null);try{let n=[],r=0,a=0,o=``,s=[];for(let t of e)try{let e=await I(`agent-roster.consolidate`,{role:t});e.error?(a++,o=e.error):e.consolidated?n.push(t):e.rawEntryCount===0?r++:e.emptySynthesis?(a++,o=`Model returned an empty result`):e.instruction?s.push({role:t,instruction:e.instruction}):(a++,o=`No consolidation produced`)}catch(e){a++,o=e instanceof Error?e.message:String(e)}if(i&&n.includes(i)&&await W(i),s.length>0){let e=`Optimize the learned data for ${s.length} agent${s.length>1?`s`:``}. For each agent below, read its raw learned entries, synthesize them into a single narrowly-scoped document preserving every fact, and save the result to its consolidated.md file.\n\n`+s.map(e=>`## Agent: ${e.role}\n\n${e.instruction}`).join(`
6
6
 
7
7
  ---
8
8
 
9
- `),n=t.getState();n.addMessage({role:`user`,content:e}),n.setLoading(!0),k().sendMessage(e);let r=O.getState();r.setSidebarOpen(!1),r.setCurrentView(`chat`)}if(n.length===0&&s.length===0){if(a>0){let t=r>0?` ${r} skipped.`:``,n=`Bulk consolidate failed for ${a} of ${e.length} agent${e.length>1?`s`:``}.${o?` Last error: ${o}`:``}${t}`;v({ok:!1,msg:n});return}let t=r>0?`Bulk optimize: ${r} skipped (no entries to optimize).`:`No agents had optimizable entries.`;v({ok:!0,msg:t}),M.info(t,6e3);return}let c=[];n.length>0&&c.push(`${n.length} consolidated`),s.length>0&&c.push(`${s.length} sent to chat`),r>0&&c.push(`${r} skipped`),a>0&&c.push(`${a} failed`);let l=`Bulk optimize: ${c.join(`, `)}.`;v({ok:a===0,msg:l}),n.length>0&&s.length===0?M.success(l,6e3):M.info(l,6e3)}catch(e){v({ok:!1,msg:e instanceof Error?e.message:`Bulk optimization failed`}),M.error(e instanceof Error?e.message:`Bulk optimization failed`)}finally{P(!1)}}},[i,W]);return F.length===0?(0,R.jsx)(`div`,{className:`flex flex-1 items-center justify-center text-muted-foreground`,children:(0,R.jsxs)(`div`,{className:`text-center space-y-3`,children:[(0,R.jsx)(b,{className:`h-10 w-10 mx-auto opacity-30`}),(0,R.jsx)(`p`,{className:`text-sm`,children:`No self-learning data yet`}),(0,R.jsx)(`p`,{className:`text-xs text-muted-foreground/70`,children:`Learning entries appear when agents capture output`})]})}):(0,R.jsxs)(`div`,{className:`flex min-h-0 min-w-0 flex-1 overflow-hidden`,children:[(0,R.jsxs)(`div`,{className:A(`flex flex-col min-h-0 min-w-0 overflow-hidden border-r border-border/50`,i?`w-80 shrink-0`:`flex-1`),children:[(0,R.jsxs)(`div`,{className:`shrink-0 px-3 py-2 border-b border-border/50`,children:[(0,R.jsxs)(`h3`,{className:`text-xs font-semibold flex items-center gap-1.5`,children:[(0,R.jsx)(b,{className:`h-3.5 w-3.5 text-brand-2`}),`All Roster Agents`]}),(()=>{let e=F.filter(e=>e.needsSummarization);return e.length===0?null:(0,R.jsxs)(`div`,{className:`mt-2 flex flex-col gap-1.5 rounded border border-warning/40 bg-warning/10 px-2 py-1.5`,children:[(0,R.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,R.jsx)(x,{className:`h-3 w-3 text-warning shrink-0`}),(0,R.jsxs)(`span`,{className:`text-[10px] text-warning leading-tight`,children:[e.length,` agent`,e.length>1?`s`:``,` need`,e.length===1?`s`:``,` optimization`]}),(0,R.jsx)(`button`,{type:`button`,onClick:()=>{let t=e[0];t&&(o(t.role),l(null),E(null))},className:`ml-auto text-[9px] text-warning underline hover:text-warning/80 shrink-0`,children:`review →`})]}),(0,R.jsxs)(`button`,{type:`button`,onClick:()=>K(e.map(e=>e.role)),disabled:N,className:`flex items-center justify-center gap-1 rounded bg-warning/20 border border-warning/40 px-2 py-1 text-[10px] font-medium text-warning hover:bg-warning/30 transition-colors disabled:opacity-50`,children:[N?(0,R.jsx)(s,{className:`h-3 w-3 animate-spin`}):(0,R.jsx)(x,{className:`h-3 w-3`}),N?`Optimizing…`:`Optimize All (${e.length})`]})]})})()]}),(0,R.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto p-2 space-y-1`,children:F.map(e=>(0,R.jsxs)(`button`,{type:`button`,onClick:()=>{o(e.role),l(null),E(null)},className:A(`w-full text-left rounded-lg border px-3 py-2 transition-colors`,i===e.role?`border-primary/50 bg-primary/[0.06]`:`border-border/60 hover:border-primary/30`,e.needsSummarization&&i!==e.role&&`border-warning/40`),children:[(0,R.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,R.jsx)(`span`,{className:`text-xs font-semibold`,children:e.role}),(0,R.jsx)(`span`,{className:A(`text-[9px] tabular-nums`,e.learningEnabled?`text-success`:`text-muted-foreground`),children:e.learningEnabled?`learning`:`paused`})]}),(0,R.jsxs)(`div`,{className:`flex items-center gap-2 mt-1 text-[9px] text-muted-foreground`,children:[(0,R.jsxs)(`span`,{className:`tabular-nums`,children:[e.entryCount,` entries`]}),e.sessionCaptureCount>0&&(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(`span`,{className:`text-muted-foreground/50`,children:`·`}),(0,R.jsxs)(`span`,{className:`text-success tabular-nums`,children:[`+`,e.sessionCaptureCount]})]}),e.lastCapture&&(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(`span`,{className:`text-muted-foreground/50`,children:`·`}),(0,R.jsx)(`span`,{children:new Date(e.lastCapture).toLocaleDateString()})]}),e.needsSummarization&&(0,R.jsxs)(`span`,{className:`inline-flex items-center gap-0.5 text-warning font-medium`,children:[(0,R.jsx)(x,{className:`h-2.5 w-2.5`}),`optimize`]})]})]},e.role))})]}),(0,R.jsxs)(`div`,{className:`flex-1 min-w-0 overflow-y-auto p-4`,children:[!i&&(0,R.jsx)(`div`,{className:`flex items-center justify-center h-full text-muted-foreground`,children:`Select an agent to view learning details`}),i&&z&&(0,R.jsxs)(`div`,{className:`space-y-4`,children:[(0,R.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,R.jsx)(`h3`,{className:`text-base font-semibold`,children:i}),(0,R.jsx)(`div`,{className:`flex gap-1`,children:(0,R.jsxs)(`button`,{type:`button`,onClick:()=>U(i,!z.learningEnabled),disabled:y,className:A(`inline-flex items-center gap-1 rounded border px-2 py-1 text-[10px] transition-colors disabled:opacity-50`,z.learningEnabled?`border-success/40 text-success hover:bg-success/10`:`border-border/50 text-muted-foreground hover:bg-accent`),children:[(0,R.jsx)(b,{className:`h-3 w-3`}),` `,z.learningEnabled?`Learning on`:`Learning paused`]})})]}),(0,R.jsxs)(`div`,{className:`grid grid-cols-4 gap-2`,children:[(0,R.jsxs)(`div`,{className:`rounded-lg border bg-card p-2`,children:[(0,R.jsx)(`span`,{className:`text-[9px] text-muted-foreground uppercase tracking-wider`,children:`Entries`}),(0,R.jsx)(`div`,{className:`text-lg font-mono font-semibold mt-0.5`,children:z.entryCount})]}),(0,R.jsxs)(`div`,{className:`rounded-lg border bg-card p-2`,children:[(0,R.jsx)(`span`,{className:`text-[9px] text-muted-foreground uppercase tracking-wider`,children:`Size`}),(0,R.jsxs)(`div`,{className:`text-lg font-mono font-semibold mt-0.5`,children:[z.totalBytes,`B`]})]}),(0,R.jsxs)(`div`,{className:`rounded-lg border bg-card p-2`,children:[(0,R.jsx)(`span`,{className:`text-[9px] text-muted-foreground uppercase tracking-wider`,children:`Last Capture`}),(0,R.jsx)(`div`,{className:`text-lg font-mono font-semibold mt-0.5`,children:z.lastCapture?new Date(z.lastCapture).toLocaleDateString():`—`})]}),(0,R.jsxs)(`div`,{className:`rounded-lg border bg-card p-2`,children:[(0,R.jsx)(`span`,{className:`text-[9px] text-muted-foreground uppercase tracking-wider`,children:`Lifetime Captures`}),(0,R.jsx)(`div`,{className:`text-lg font-mono font-semibold mt-0.5`,children:z.lifetimeCaptureCount})]})]}),z.needsSummarization&&(0,R.jsxs)(`div`,{className:`flex items-center gap-3 text-xs text-warning bg-warning/10 rounded-lg px-3 py-2.5`,children:[(0,R.jsx)(g,{className:`h-4 w-4 shrink-0`}),(0,R.jsxs)(`span`,{className:`flex-1`,children:[`Learned data exceeds soft limit (`,z.totalBytes.toLocaleString(),`B / 8,192B). Optimize to synthesize raw entries into a consolidated document and reduce context volume.`]}),(0,R.jsxs)(`button`,{type:`button`,onClick:()=>G(i),disabled:D,className:`inline-flex items-center gap-1 rounded bg-warning/20 text-warning border border-warning/40 px-2.5 py-1 text-[10px] font-medium hover:bg-warning/30 transition-colors disabled:opacity-50 shrink-0`,children:[D?(0,R.jsx)(s,{className:`h-3 w-3 animate-spin`}):(0,R.jsx)(x,{className:`h-3 w-3`}),D?`Optimizing…`:`Optimize Now`]})]}),(0,R.jsxs)(`div`,{className:`space-y-2 border border-border rounded-lg p-3 bg-card`,children:[(0,R.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,R.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,R.jsx)(a,{className:`h-4 w-4 text-primary`}),(0,R.jsx)(`span`,{className:`text-xs font-semibold`,children:`Optimize Learnings`})]}),(0,R.jsxs)(`button`,{type:`button`,onClick:()=>G(i),disabled:D||z.entryCount===0,className:`inline-flex items-center gap-1 rounded bg-primary px-3 py-1.5 text-xs text-primary-foreground hover:bg-primary/90 transition-colors disabled:opacity-50`,title:z.entryCount===0?`No raw entries to optimize`:`Synthesize raw entries into a consolidated, narrowly-scoped document`,children:[D?(0,R.jsx)(s,{className:`h-3.5 w-3.5 animate-spin`}):(0,R.jsx)(x,{className:`h-3.5 w-3.5`}),D?`Optimizing…`:`Optimize`]})]}),(0,R.jsxs)(`p`,{className:`text-[10px] text-muted-foreground leading-relaxed`,children:[`Synthesizes all `,z.entryCount,` raw entries into a single reviewed document — narrowly scoped to this agent's skills, preserving every fact but reducing context volume. The result replaces raw entries in the agent's prompt.`]}),z.isConsolidated&&z.consolidation&&(0,R.jsxs)(`div`,{className:`flex items-center gap-2 text-[10px] text-muted-foreground pt-1 border-t border-border/50`,children:[(0,R.jsx)(n,{className:`h-3 w-3 text-success`}),(0,R.jsxs)(`span`,{children:[`Consolidated`,` `,new Date(z.consolidation.consolidatedAt).toLocaleDateString(),` ·`,` `,z.consolidation.sourceBytes,`B →`,` `,z.consolidation.consolidatedBytes,`B`,z.consolidation.sourceEntryCount<z.entryCount&&(0,R.jsxs)(`span`,{className:`text-warning ml-1`,children:[`· `,z.entryCount-z.consolidation.sourceEntryCount,` `,`new pending`]})]}),(0,R.jsx)(`button`,{type:`button`,onClick:()=>{T===null?W(i):E(null)},className:`ml-auto underline text-primary hover:text-primary/80`,children:T===null?`View`:`Hide`})]}),T!==null&&(0,R.jsxs)(`div`,{className:`mt-2 max-h-72 overflow-y-auto rounded border border-border/50 bg-background/50 p-2`,children:[(0,R.jsxs)(`div`,{className:`text-[10px] text-muted-foreground mb-1 font-medium`,children:[`Consolidated knowledge for `,i]}),(0,R.jsx)(`pre`,{className:`text-[10px] whitespace-pre-wrap font-sans leading-relaxed`,children:T||`(empty)`})]})]}),z.entryCount>0&&(0,R.jsxs)(`div`,{className:`space-y-2`,children:[(0,R.jsx)(`div`,{className:`flex items-center gap-2`,children:(0,R.jsxs)(`button`,{type:`button`,onClick:()=>B(i),disabled:C,className:`inline-flex items-center gap-1 rounded border border-border/50 px-3 py-1.5 text-xs hover:bg-accent transition-colors`,children:[C?(0,R.jsx)(s,{className:`h-3 w-3 animate-spin`}):(0,R.jsx)(f,{className:`h-3 w-3`}),`Review Learned Entries (`,z.entryCount,`)`]})}),c&&(0,R.jsxs)(`div`,{className:`space-y-2 border border-border rounded-lg p-3 bg-card`,children:[(0,R.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,R.jsxs)(`span`,{className:`text-xs font-medium`,children:[c.filter((e,t)=>u[t]!==`drop`).length,`/`,c.length,` kept`]}),(0,R.jsxs)(`div`,{className:`flex gap-2`,children:[(0,R.jsx)(`button`,{type:`button`,onClick:V,disabled:y,className:`inline-flex items-center gap-1 rounded bg-primary px-2 py-1 text-[10px] text-primary-foreground hover:bg-primary/90 transition-colors`,children:y?`Applying…`:`Apply Selection`}),(0,R.jsx)(`button`,{type:`button`,onClick:()=>{l(null),p({})},className:`inline-flex items-center gap-1 rounded border border-border/50 px-2 py-1 text-[10px] hover:bg-accent transition-colors`,children:`Cancel`})]})]}),(0,R.jsx)(`div`,{className:`max-h-72 overflow-y-auto space-y-2`,children:c.map((e,t)=>{let n=u[t]??`keep`,r=e.length>200?e.slice(0,200)+`…`:e;return(0,R.jsx)(`div`,{className:A(`rounded-lg border p-2 transition-colors`,n===`drop`?`border-destructive/40 bg-destructive/5 opacity-60`:`border-border`),children:(0,R.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,R.jsx)(`pre`,{className:`text-[10px] whitespace-pre-wrap flex-1 leading-relaxed font-sans`,children:r}),(0,R.jsxs)(`div`,{className:`flex gap-1 shrink-0`,children:[(0,R.jsx)(`button`,{type:`button`,onClick:()=>p(e=>({...e,[t]:`keep`})),className:A(`px-2 py-1 text-[9px] rounded`,n===`keep`?`bg-success/20 text-success`:`bg-muted text-muted-foreground`),children:`Keep`}),(0,R.jsx)(`button`,{type:`button`,onClick:()=>p(e=>({...e,[t]:`drop`})),className:A(`px-2 py-1 text-[9px] rounded`,n===`drop`?`bg-destructive/20 text-destructive`:`bg-muted text-muted-foreground`),children:`Drop`})]})]})},t)})})]})]}),(0,R.jsxs)(`div`,{className:`space-y-2 pt-4 border-t border-border`,children:[(0,R.jsxs)(`div`,{className:`flex items-center gap-1 text-sm font-medium`,children:[(0,R.jsx)(d,{className:`h-4 w-4 text-brand-2`}),` Teach this agent`]}),(0,R.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,children:`Describe a command, pattern, or behavior you want this agent to remember.`}),(0,R.jsx)(`textarea`,{className:`w-full h-20 text-xs p-2 bg-card border border-border rounded resize-y`,value:m,onChange:e=>h(e.target.value),placeholder:`e.g. Always use pnpm for this project`}),(0,R.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,R.jsxs)(`button`,{type:`button`,onClick:H,disabled:!m.trim()||y,className:`inline-flex items-center gap-1 rounded bg-primary px-3 py-1.5 text-xs text-primary-foreground hover:bg-primary/90 transition-colors disabled:opacity-50`,children:[(0,R.jsx)(d,{className:`h-3.5 w-3.5`}),` Teach`]}),_&&(0,R.jsx)(`span`,{className:A(`text-xs`,_.ok?`text-success`:`text-destructive`),children:_.msg})]})]})]})]})]})}function ee({customStats:e,catalog:t}){let[n,r]=(0,L.useState)(``),[a,s]=(0,L.useState)(null),l=(0,L.useMemo)(()=>new Set(e.filter(e=>e.exists||e.hasIdentity||e.hasConfig||e.hasKnowledge).map(e=>e.role)),[e]),u=(0,L.useMemo)(()=>{if(!n.trim())return t;let e=n.toLowerCase();return t.filter(t=>t.role.includes(e)||t.name.toLowerCase().includes(e)||t.summary.toLowerCase().includes(e))},[t,n]),d=(0,L.useCallback)(t=>e.find(e=>e.role===t),[e]),f=u;return(0,R.jsxs)(`div`,{className:`flex min-h-0 min-w-0 flex-1 flex-col overflow-hidden`,children:[(0,R.jsx)(`div`,{className:`shrink-0 px-3 py-2 border-b border-border/50`,children:(0,R.jsxs)(`div`,{className:`flex items-center gap-2 rounded-lg border border-border/60 bg-background px-3 py-1.5`,children:[(0,R.jsx)(p,{className:`h-3.5 w-3.5 text-muted-foreground`}),(0,R.jsx)(`input`,{type:`text`,value:n,onChange:e=>r(e.target.value),placeholder:`Search agents by name, role, or description…`,className:`flex-1 bg-transparent text-xs outline-none placeholder:text-muted-foreground/50`}),n&&(0,R.jsx)(`button`,{type:`button`,onClick:()=>r(``),className:`text-muted-foreground hover:text-foreground`,children:(0,R.jsx)(h,{className:`h-3 w-3`})})]})}),(0,R.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-y-auto p-3`,children:[(0,R.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-2`,children:f.map(e=>{let t=d(e.role),n=l.has(e.role),r=a===e.role;return(0,R.jsxs)(`div`,{className:A(`rounded-lg border bg-card transition-colors`,r?`border-primary/40 ring-1 ring-primary/20`:`border-border/60 hover:border-primary/30`),children:[(0,R.jsxs)(`button`,{type:`button`,onClick:()=>s(r?null:e.role),className:`w-full text-left p-3`,children:[(0,R.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,R.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,R.jsx)(o,{className:`h-4 w-4 shrink-0 text-primary`}),(0,R.jsx)(`span`,{className:`text-sm font-semibold truncate`,children:e.name}),(0,R.jsxs)(`code`,{className:`text-[9px] text-muted-foreground font-mono shrink-0`,children:[`@`,e.role]})]}),(0,R.jsx)(c,{className:A(`h-3.5 w-3.5 shrink-0 text-muted-foreground transition-transform`,r&&`rotate-180`)})]}),(0,R.jsx)(`p`,{className:`text-[10px] text-muted-foreground mt-1 leading-relaxed line-clamp-2`,children:e.summary}),(0,R.jsxs)(`div`,{className:`flex items-center gap-2 mt-1.5`,children:[(0,R.jsxs)(`span`,{className:`text-[9px] text-muted-foreground tabular-nums`,children:[e.tools,` tools`]}),e.budget.maxIterations&&(0,R.jsxs)(`span`,{className:`text-[9px] text-muted-foreground tabular-nums`,children:[e.budget.maxIterations.toLocaleString(),` max it`]}),n&&(0,R.jsxs)(`span`,{className:`inline-flex items-center gap-0.5 rounded bg-brand-2/10 px-1 py-0.5 text-[8px] text-brand-2 font-medium`,children:[(0,R.jsx)(i,{className:`h-2.5 w-2.5`}),` Customized`]}),t?.needsSummarization&&(0,R.jsx)(`span`,{className:`text-[9px] text-warning`,children:`⚠ Needs summary`})]})]}),r&&(0,R.jsxs)(`div`,{className:`border-t border-border/50 px-3 py-2 space-y-2`,children:[(0,R.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,R.jsxs)(`div`,{className:`rounded bg-muted/30 p-1.5`,children:[(0,R.jsx)(`span`,{className:`text-[8px] text-muted-foreground uppercase tracking-wider`,children:`Max Iterations`}),(0,R.jsx)(`div`,{className:`text-xs font-mono mt-0.5`,children:e.budget.maxIterations?.toLocaleString()??`—`})]}),(0,R.jsxs)(`div`,{className:`rounded bg-muted/30 p-1.5`,children:[(0,R.jsx)(`span`,{className:`text-[8px] text-muted-foreground uppercase tracking-wider`,children:`Timeout`}),(0,R.jsx)(`div`,{className:`text-xs font-mono mt-0.5`,children:e.budget.timeoutMs?`${Math.round(e.budget.timeoutMs/6e4)}m`:`—`})]}),(0,R.jsxs)(`div`,{className:`rounded bg-muted/30 p-1.5`,children:[(0,R.jsx)(`span`,{className:`text-[8px] text-muted-foreground uppercase tracking-wider`,children:`Max Tool Calls`}),(0,R.jsx)(`div`,{className:`text-xs font-mono mt-0.5`,children:e.budget.maxToolCalls?.toLocaleString()??`—`})]}),(0,R.jsxs)(`div`,{className:`rounded bg-muted/30 p-1.5`,children:[(0,R.jsx)(`span`,{className:`text-[8px] text-muted-foreground uppercase tracking-wider`,children:`Customized`}),(0,R.jsx)(`div`,{className:`text-xs font-mono mt-0.5`,children:n?`Yes`:`No`})]})]}),n&&t&&(0,R.jsxs)(`div`,{className:`rounded bg-accent/30 p-2 space-y-1`,children:[(0,R.jsx)(`span`,{className:`text-[9px] font-medium text-muted-foreground`,children:`Project Customizations`}),(0,R.jsxs)(`div`,{className:`flex flex-wrap gap-2 text-[9px]`,children:[t.hasIdentity&&(0,R.jsxs)(`span`,{className:`inline-flex items-center gap-0.5`,children:[(0,R.jsx)(i,{className:`h-2.5 w-2.5 text-primary`}),` identity.md`]}),t.entryCount>0&&(0,R.jsxs)(`span`,{className:`inline-flex items-center gap-0.5`,children:[(0,R.jsx)(b,{className:`h-2.5 w-2.5 text-brand-2`}),` `,t.entryCount,` `,`learned entries`]}),t.hasConfig&&(0,R.jsxs)(`span`,{className:`inline-flex items-center gap-0.5`,children:[(0,R.jsx)(w,{className:`h-2.5 w-2.5 text-muted-foreground`}),` config.json`]}),t.sessionCaptureCount>0&&(0,R.jsxs)(`span`,{className:`inline-flex items-center gap-0.5`,children:[(0,R.jsx)(C,{className:`h-2.5 w-2.5 text-success`}),` `,t.sessionCaptureCount,` session captures`]})]})]})]})]},e.role)})}),f.length===0&&(0,R.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-40 text-muted-foreground`,children:[(0,R.jsx)(p,{className:`h-8 w-8 mb-2 opacity-30`}),(0,R.jsxs)(`p`,{className:`text-sm`,children:[`No agents match "`,n,`"`]})]})]}),(0,R.jsxs)(`div`,{className:`shrink-0 border-t border-border/50 px-3 py-2 text-[10px] text-muted-foreground flex items-center gap-2`,children:[(0,R.jsxs)(`span`,{children:[(0,R.jsx)(`strong`,{children:t.length}),` roster roles`]}),(0,R.jsx)(`span`,{className:`text-muted-foreground/50`,children:`·`}),(0,R.jsxs)(`span`,{className:`text-brand-2`,children:[(0,R.jsx)(`strong`,{children:l.size}),` customized`]}),(0,R.jsx)(`span`,{className:`text-muted-foreground/50`,children:`·`}),(0,R.jsxs)(`span`,{children:[(0,R.jsx)(`strong`,{children:e.reduce((e,t)=>e+t.entryCount,0)}),` total learned entries`]})]})]})}var Z={running:{led:`bg-success`,badge:`bg-success/12 text-success`,icon:(0,R.jsx)(`span`,{className:`led text-success led-pulse`}),color:`text-success`},completed:{led:`bg-success`,badge:`bg-success/12 text-success`,icon:(0,R.jsx)(n,{className:`h-3.5 w-3.5`}),color:`text-success`},failed:{led:`bg-destructive`,badge:`bg-destructive/15 text-destructive`,icon:(0,R.jsx)(l,{className:`h-3.5 w-3.5`}),color:`text-destructive`},timeout:{led:`bg-warning`,badge:`bg-muted text-muted-foreground`,icon:(0,R.jsx)(y,{className:`h-3.5 w-3.5`}),color:`text-warning`},stopped:{led:`bg-muted-foreground`,badge:`bg-muted text-muted-foreground`,icon:(0,R.jsx)(`span`,{className:`led text-muted-foreground`}),color:`text-muted-foreground`},idle:{led:`bg-muted-foreground`,badge:`bg-muted text-muted-foreground`,icon:(0,R.jsx)(`span`,{className:`led text-muted-foreground`}),color:`text-muted-foreground`}};function Q(e){let t=Math.floor(e/1e3);if(t<60)return`${t}s`;let n=Math.floor(t/60);if(n<60)return`${n}m ${t%60}s`;let r=Math.floor(n/60);return r<24?`${r}h ${n%60}m`:`${Math.floor(r/24)}d`}function $(e){if(e==null||!Number.isFinite(e)||e<=0)return`$0`;if(e<.01){let t=e.toFixed(5);return t===`0.00000`?`$0`:`$`+t.replace(/(\d)0+$/,`$1`).replace(/\.$/,``)}return`$`+e.toFixed(3)}function te({nowTick:e}){let t=j(e=>e.agents),n=j(e=>e.leaderId),[i,a]=(0,L.useState)(null),[s,c]=(0,L.useState)(`all`),l=(0,L.useMemo)(()=>{let e=Array.from(t.values());return e.sort((e,t)=>{let n=e.status===`running`?0:1,r=t.status===`running`?0:1;return n===r?t.startedAt-e.startedAt:n-r}),s===`all`?e:s===`running`?e.filter(e=>e.status===`running`):s===`done`?e.filter(e=>e.status===`completed`):s===`failed`?e.filter(e=>e.status===`failed`||e.status===`timeout`):e},[t,s]),u=(0,L.useMemo)(()=>{let e=0,n=0,r=0;for(let i of t.values())i.status===`running`?e++:i.status===`completed`?n++:(i.status===`failed`||i.status===`timeout`)&&r++;return{running:e,completed:n,failed:r,total:t.size}},[t]),d=j(e=>e.clearFinishedAgents),f=i?l.find(e=>e.id===i):null,p=(0,L.useCallback)(e=>{let t=O.getState();e?(t.setInspectorFocusedAgentId(e),t.setInspectorTab(`agents`)):t.setInspectorTab(`fleet`),t.setInspectorOpen(!0)},[]);return l.length===0?(0,R.jsx)(`div`,{className:`flex flex-1 items-center justify-center text-muted-foreground`,children:(0,R.jsxs)(`div`,{className:`text-center space-y-3`,children:[(0,R.jsx)(o,{className:`h-10 w-10 mx-auto opacity-30`}),(0,R.jsx)(`p`,{className:`text-sm`,children:`No active fleet agents`}),(0,R.jsx)(`p`,{className:`text-xs text-muted-foreground/70`,children:`Agents appear here when subagents spawn`})]})}):(0,R.jsxs)(`div`,{className:`flex min-h-0 min-w-0 flex-1 overflow-hidden`,children:[(0,R.jsxs)(`div`,{className:A(`flex flex-col min-h-0 min-w-0 overflow-hidden`,f?`w-80 shrink-0 border-r border-border/50`:`flex-1`),children:[(0,R.jsxs)(`div`,{className:`flex items-center gap-1 shrink-0 px-3 py-2 border-b border-border/50`,children:[[`all`,`running`,`done`,`failed`].map(e=>(0,R.jsxs)(`button`,{type:`button`,onClick:()=>c(e),className:A(`rounded px-2 py-0.5 text-[10px] font-medium transition-colors`,s===e?`bg-primary/10 text-primary`:`text-muted-foreground hover:text-foreground hover:bg-muted/50`),children:[e===`all`&&`All (${u.total})`,e===`running`&&`Running (${u.running})`,e===`done`&&`Done (${u.completed})`,e===`failed`&&`Failed (${u.failed})`]},e)),(0,R.jsx)(`span`,{className:`flex-1`}),u.completed+u.failed>0&&(0,R.jsxs)(`button`,{type:`button`,onClick:d,className:`inline-flex items-center gap-0.5 rounded px-1.5 py-0.5 text-[10px] text-muted-foreground hover:text-destructive hover:bg-destructive/10 transition-colors`,children:[(0,R.jsx)(r,{className:`h-2.5 w-2.5`}),` Clear`]})]}),(0,R.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto p-2 space-y-1`,children:l.map(e=>(0,R.jsxs)(`button`,{type:`button`,onClick:()=>a(i===e.id?null:e.id),className:A(`w-full text-left rounded-lg border px-3 py-2 transition-colors flex items-center gap-2`,i===e.id?`border-primary/50 bg-primary/[0.06]`:`border-border/60 hover:border-primary/30 hover:bg-primary/[0.03]`),children:[(0,R.jsx)(`span`,{className:A(`led shrink-0`,Z[e.status]?.led??`bg-muted-foreground`,e.status===`running`&&`led-pulse`)}),(0,R.jsx)(`span`,{className:`text-xs font-semibold min-w-0 truncate max-w-[7rem]`,children:e.name}),e.id===n&&(0,R.jsx)(m,{className:`h-3 w-3 shrink-0 text-warning`}),e.model&&(0,R.jsx)(`span`,{className:`text-[9px] text-muted-foreground font-mono truncate max-w-[6rem] shrink-0`,children:e.model}),(0,R.jsxs)(`span`,{className:`text-[9px] text-muted-foreground tabular-nums shrink-0`,children:[e.iteration,`it · `,e.toolCalls,`t`]}),e.status===`running`&&(0,R.jsx)(`span`,{className:`text-[9px] text-primary tabular-nums shrink-0 ml-auto`,children:Q(Date.now()-e.startedAt)}),e.status!==`running`&&(0,R.jsx)(`span`,{className:A(`text-[9px] tabular-nums shrink-0 ml-auto`,Z[e.status]?.color??`text-muted-foreground`),children:e.status}),e.costUsd>0&&(0,R.jsx)(`span`,{className:`text-[9px] text-success tabular-nums font-medium shrink-0`,children:$(e.costUsd)}),e.status===`running`&&e.currentTool&&(0,R.jsxs)(`span`,{className:`text-[9px] text-primary font-mono truncate max-w-[6rem] shrink-0`,children:[`→ `,e.currentTool]})]},e.id))}),(0,R.jsxs)(`div`,{className:`shrink-0 border-t border-border/50 px-3 py-2 flex items-center gap-2 text-[10px] text-muted-foreground`,children:[(0,R.jsx)(`span`,{className:`font-medium tabular-nums`,children:u.total}),` agents total`,(0,R.jsx)(`span`,{className:`text-muted-foreground/50`,children:`·`}),(0,R.jsx)(`span`,{className:`text-success tabular-nums`,children:u.running}),` running`,(0,R.jsx)(`span`,{className:`text-muted-foreground/50`,children:`·`}),(0,R.jsx)(`span`,{className:`tabular-nums`,children:u.completed}),` done`,u.failed>0&&(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(`span`,{className:`text-muted-foreground/50`,children:`·`}),(0,R.jsx)(`span`,{className:`text-destructive tabular-nums`,children:u.failed}),` failed`]}),(0,R.jsx)(`span`,{className:`flex-1`}),(0,R.jsxs)(`button`,{type:`button`,onClick:()=>p(),className:`inline-flex items-center gap-1 rounded border border-border/50 px-2 py-1 hover:bg-accent transition-colors`,children:[(0,R.jsx)(T,{className:`h-3 w-3`}),`Fleet Inspector`]})]})]}),f&&(0,R.jsx)(`div`,{className:`flex-1 min-w-0 overflow-y-auto p-4`,children:(0,R.jsx)(ne,{agent:f,nowTick:e})})]})}function ne({agent:e,nowTick:t}){let n=e.status===`running`?Q(t-e.startedAt):e.completedAt?Q(e.completedAt-e.startedAt):`-`,r=Math.min(100,Math.max(0,e.ctxPct)),i=e.currentTool||e.lastTool,a=j(e=>e.leaderId);return(0,R.jsxs)(`div`,{className:`space-y-4`,children:[(0,R.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,R.jsx)(`div`,{className:`flex items-center justify-center w-10 h-10 rounded-lg bg-primary/10`,children:(0,R.jsx)(o,{className:`h-5 w-5 text-primary`})}),(0,R.jsxs)(`div`,{children:[(0,R.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,R.jsx)(`span`,{className:`text-base font-semibold`,children:e.name}),e.id===a&&(0,R.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded border border-warning/30 bg-warning/10 px-1.5 py-0.5 text-[9px] font-medium text-warning`,children:[(0,R.jsx)(m,{className:`h-2.5 w-2.5`}),` Leader`]})]}),(0,R.jsxs)(`div`,{className:`flex items-center gap-2 text-[10px] text-muted-foreground`,children:[(0,R.jsx)(`span`,{className:A(`led`,Z[e.status]?.led,e.status===`running`&&`led-pulse`)}),(0,R.jsx)(`span`,{children:e.status}),e.model&&(0,R.jsxs)(`span`,{children:[`· `,e.provider,`/`,e.model]}),(0,R.jsxs)(`span`,{children:[`· `,n]})]})]})]}),(0,R.jsxs)(`div`,{className:`grid grid-cols-4 gap-2`,children:[(0,R.jsxs)(`div`,{className:`rounded-lg border bg-card p-2`,children:[(0,R.jsx)(`span`,{className:`text-[9px] text-muted-foreground uppercase tracking-wider`,children:`Iterations`}),(0,R.jsx)(`div`,{className:`text-lg font-mono font-semibold mt-0.5`,children:e.iteration})]}),(0,R.jsxs)(`div`,{className:`rounded-lg border bg-card p-2`,children:[(0,R.jsx)(`span`,{className:`text-[9px] text-muted-foreground uppercase tracking-wider`,children:`Tool Calls`}),(0,R.jsx)(`div`,{className:`text-lg font-mono font-semibold mt-0.5`,children:e.toolCalls})]}),(0,R.jsxs)(`div`,{className:`rounded-lg border bg-card p-2`,children:[(0,R.jsx)(`span`,{className:`text-[9px] text-muted-foreground uppercase tracking-wider`,children:`Cost`}),(0,R.jsx)(`div`,{className:`text-lg font-mono font-semibold mt-0.5 text-success`,children:$(e.costUsd)})]}),(0,R.jsxs)(`div`,{className:`rounded-lg border bg-card p-2`,children:[(0,R.jsx)(`span`,{className:`text-[9px] text-muted-foreground uppercase tracking-wider`,children:`Context`}),(0,R.jsxs)(`div`,{className:`text-lg font-mono font-semibold mt-0.5`,children:[r,`%`]})]})]}),e.maxContext>0&&(0,R.jsxs)(`div`,{className:`space-y-1`,children:[(0,R.jsxs)(`div`,{className:`flex justify-between text-[10px]`,children:[(0,R.jsx)(`span`,{className:`text-muted-foreground`,children:`Context Window`}),(0,R.jsxs)(`span`,{className:A(`tabular font-medium`,r>=85?`text-destructive`:r>=70?`text-warning`:`text-success`),children:[e.ctxTokens.toLocaleString(),` / `,e.maxContext.toLocaleString(),` tokens`]})]}),(0,R.jsx)(`div`,{className:`h-2 w-full overflow-hidden rounded-full bg-muted`,children:(0,R.jsx)(`div`,{className:A(`h-full rounded-full transition-all`,r>=85?`bg-destructive`:r>=70?`bg-warning`:`bg-primary`),style:{width:`${Math.max(2,r)}%`}})})]}),i&&(0,R.jsxs)(`div`,{className:A(`flex items-center gap-2 rounded-lg border px-3 py-2`,e.status===`running`?`border-primary/30 bg-primary/[0.04]`:`border-border bg-muted/30`),children:[(0,R.jsx)(S,{className:A(`h-4 w-4`,e.status===`running`?`text-primary animate-pulse`:`text-muted-foreground`)}),(0,R.jsx)(`span`,{className:`text-sm font-mono`,children:e.currentTool??e.lastTool}),(0,R.jsx)(`span`,{className:`text-[10px] text-muted-foreground ml-auto`,children:e.currentTool?`Running`:`Last tool`})]}),e.error&&(0,R.jsxs)(`div`,{className:`rounded-lg border border-destructive/30 bg-destructive/5 p-3`,children:[(0,R.jsx)(`span`,{className:`text-[10px] font-semibold text-destructive uppercase tracking-wider`,children:`Error`}),(0,R.jsx)(`p`,{className:`text-xs text-destructive/90 mt-1`,children:e.error.message})]}),e.toolLog.length>0&&(0,R.jsxs)(`div`,{className:`space-y-1`,children:[(0,R.jsxs)(`span`,{className:`text-[10px] font-semibold text-muted-foreground uppercase tracking-wider`,children:[`Tool Log (`,e.toolLog.length,`)`]}),(0,R.jsx)(`div`,{className:`space-y-0.5`,children:e.toolLog.slice(0,10).map((e,t)=>(0,R.jsxs)(`div`,{className:A(`flex items-center gap-2 rounded px-2 py-1 text-[10px] font-mono`,e.ok?`bg-muted/30`:`bg-destructive/5 border border-destructive/20`),children:[(0,R.jsx)(`span`,{className:A(`led shrink-0`,e.ok?`text-success`:`text-destructive`)}),(0,R.jsx)(`span`,{className:`truncate flex-1`,children:e.name}),(0,R.jsxs)(`span`,{className:`tabular text-muted-foreground`,children:[e.durationMs,`ms`]}),!e.ok&&(0,R.jsx)(`span`,{className:`text-destructive`,children:`✗`})]},`${e.name}-${t}`))})]}),e.budgetWarning&&(0,R.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-2 rounded-lg bg-warning/10 border border-warning/25 text-xs`,children:[(0,R.jsx)(x,{className:`h-3.5 w-3.5 text-warning shrink-0`}),(0,R.jsxs)(`span`,{className:`text-warning`,children:[`Budget: `,e.budgetWarning.kind,` limit (`,e.budgetWarning.used,`/`,e.budgetWarning.limit,`)`]})]})]})}function re(){let[e,t]=(0,L.useState)([]),[n,r]=(0,L.useState)(q),[i,a]=(0,L.useState)(!1),[o,s]=(0,L.useState)(null),c=(0,L.useCallback)(async()=>{a(!0),s(null);try{let e=await I(`agent-roster.list`,{});e.stats&&t(e.stats),e.catalog?.length&&r(e.catalog)}catch(e){s(e instanceof Error?e.message:`Failed to load roster`)}a(!1)},[]);return(0,L.useEffect)(()=>{c()},[c]),(0,L.useEffect)(()=>{let e=null,t=k().on(`agent-roster.updated`,()=>{e&&clearTimeout(e),e=setTimeout(()=>{e=null,c()},300)});return()=>{e&&clearTimeout(e),t()}},[c]),{customStats:e,catalog:n,rosterLoading:i,rosterError:o,loadRoster:c}}function ie({customStats:e,catalog:n,onRefresh:o}){let[s,c]=(0,L.useState)(null),[l,d]=(0,L.useState)(null),[p,m]=(0,L.useState)(``),[h,g]=(0,L.useState)(null),[_,v]=(0,L.useState)(!1),[y,x]=(0,L.useState)(null),[S,C]=(0,L.useState)(!1),[T,E]=(0,L.useState)({name:``,role:``,baseRole:`generic`,purpose:``,taskTypes:``}),D=(0,L.useMemo)(()=>s?e.find(e=>e.role===s):null,[s,e]),j=(0,L.useMemo)(()=>{let e=n.find(e=>e.role===s);return e?.systemProtected??!e?.custom},[n,s]),M=(0,L.useCallback)(async(e,t)=>{v(!0),x(null),c(e);try{let n=await I(`agent-roster.read-customization`,{role:e});m(t===`config`?`${JSON.stringify(n.config??{},null,2)}\n`:n[t]??``),d(t),g(null)}catch(e){x(e instanceof Error?e.message:`Failed to load customization`)}finally{v(!1)}},[]),N=(0,L.useCallback)(async e=>{v(!0),x(null),c(e);try{let t=await I(`agent-roster.read-customization`,{role:e});g(t.config??{}),d(null)}catch(e){x(e instanceof Error?e.message:`Failed to load runtime policy`)}finally{v(!1)}},[]),P=(0,L.useCallback)(async e=>{if(s){v(!0),x(null);try{await I(`agent-roster.update-config`,{role:s,config:e}),g(null),o()}catch(e){x(e instanceof Error?e.message:`Runtime policy save failed`)}finally{v(!1)}}},[o,s]),F=(0,L.useCallback)(async()=>{if(!(!s||!l)){v(!0);try{let e={identity:`agent-roster.update-identity`,learned:`agent-roster.update-learned`,config:`agent-roster.update-config`},t={role:s};if(l===`config`)try{t.config=JSON.parse(p)}catch{x(`config.json must contain valid JSON`),v(!1);return}else t.content=p;await I(e[l],t),d(null),x(null),o()}catch(e){x(e instanceof Error?e.message:`Save failed`)}v(!1)}},[s,l,p,o]),z=(0,L.useCallback)(async()=>{if(s)try{let e=await I(`agent-roster.llm-improve`,{role:s,prompt:`Improve this agent for optimal project performance`});if(!e.instruction)throw Error(`No improvement instruction generated`);let n=t.getState();n.addMessage({role:`user`,content:e.instruction}),n.setLoading(!0),k().sendMessage(e.instruction);let r=O.getState();r.setSidebarOpen(!1),r.setCurrentView(`chat`)}catch(e){x(e instanceof Error?e.message:`LLM improvement failed`)}},[s]),B=(0,L.useCallback)(async e=>{if(window.confirm(`Reset all project-specific data for agent "${e}"?`))try{await I(`agent-roster.reset`,{role:e}),c(null),o()}catch{}},[o]),V=(0,L.useCallback)(async()=>{let e=T.taskTypes.split(/[\n,]+/).map(e=>e.trim()).filter(Boolean);v(!0),x(null);try{let t=await I(`agent-roster.create`,{name:T.name,role:T.role,baseRole:T.baseRole,purpose:T.purpose,taskTypes:e});C(!1),E({name:``,role:``,baseRole:`generic`,purpose:``,taskTypes:``}),c(t.role),o()}catch(e){x(e instanceof Error?e.message:`Agent creation failed`)}finally{v(!1)}},[T,o]),H=(0,L.useMemo)(()=>[...e].sort((e,t)=>{let n=+!!e.hasIdentity+ +(e.entryCount>0)+ +!!e.hasConfig;return+!!t.hasIdentity+ +(t.entryCount>0)+ +!!t.hasConfig-n}),[e]);return(0,R.jsxs)(`div`,{className:`flex min-h-0 min-w-0 flex-1 overflow-hidden`,children:[(0,R.jsxs)(`div`,{className:`w-80 shrink-0 border-r border-border/50 flex flex-col overflow-hidden`,children:[(0,R.jsx)(`div`,{className:`shrink-0 border-b border-border/50 px-3 py-2`,children:(0,R.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,R.jsxs)(`h3`,{className:`flex items-center gap-1.5 text-xs font-semibold`,children:[(0,R.jsx)(w,{className:`h-3.5 w-3.5`}),`Project Agents`]}),(0,R.jsx)(`button`,{type:`button`,onClick:()=>{C(!0),c(null),g(null),x(null)},className:`rounded border border-primary/40 px-1.5 py-1 text-[9px] text-primary hover:bg-primary/10`,children:`+ Clone`})]})}),(0,R.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-y-auto p-2 space-y-1`,children:[H.map(e=>(0,R.jsxs)(`button`,{type:`button`,onClick:()=>{c(e.role),g(null),d(null)},className:A(`w-full text-left rounded-lg border px-3 py-2 transition-colors`,s===e.role?`border-primary/50 bg-primary/[0.06]`:`border-border/60 hover:border-primary/30`),children:[(0,R.jsx)(`div`,{className:`text-xs font-semibold`,children:e.role}),(0,R.jsxs)(`div`,{className:`flex gap-2 mt-0.5 text-[9px] text-muted-foreground`,children:[e.hasIdentity&&(0,R.jsx)(`span`,{className:`text-primary`,children:`id`}),e.entryCount>0&&(0,R.jsxs)(`span`,{className:`text-brand-2`,children:[e.entryCount,`e`]}),e.hasConfig&&(0,R.jsx)(`span`,{children:`cfg`})]})]},e.role)),H.length===0&&(0,R.jsx)(`div`,{className:`text-[10px] text-muted-foreground text-center py-4`,children:`No customizations yet`})]})]}),(0,R.jsxs)(`div`,{className:`flex-1 min-w-0 overflow-y-auto p-4`,children:[S&&(0,R.jsxs)(`div`,{className:`max-w-2xl space-y-4`,children:[(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`h3`,{className:`text-base font-semibold`,children:`Create or Clone Project Agent`}),(0,R.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:`Inherit any roster agent as a template, then develop an independent identity, runtime policy and learned history.`})]}),(0,R.jsxs)(`label`,{className:`block space-y-1 text-xs`,children:[(0,R.jsx)(`span`,{className:`font-medium`,children:`Clone from roster role`}),(0,R.jsx)(`select`,{value:T.baseRole,onChange:e=>E(t=>({...t,baseRole:e.target.value})),className:`h-9 w-full rounded border border-border bg-card px-2`,children:[...n].sort((e,t)=>e.name.localeCompare(t.name)).map(e=>(0,R.jsxs)(`option`,{value:e.role,children:[e.name,` (`,e.role,`)`]},e.role))}),(0,R.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,children:`Prompt, tools, skills and defaults are inherited. Learning and later edits remain isolated to the new agent.`})]}),(0,R.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,R.jsxs)(`label`,{className:`space-y-1 text-xs`,children:[(0,R.jsx)(`span`,{className:`font-medium`,children:`Display name`}),(0,R.jsx)(`input`,{value:T.name,onChange:e=>E(t=>({...t,name:e.target.value})),placeholder:`ABC`,className:`h-9 w-full rounded border border-border bg-card px-2`})]}),(0,R.jsxs)(`label`,{className:`space-y-1 text-xs`,children:[(0,R.jsx)(`span`,{className:`font-medium`,children:`Role id (optional)`}),(0,R.jsx)(`input`,{value:T.role,onChange:e=>E(t=>({...t,role:e.target.value})),placeholder:`abc (generated from name)`,className:`h-9 w-full rounded border border-border bg-card px-2 font-mono`})]})]}),(0,R.jsxs)(`label`,{className:`block space-y-1 text-xs`,children:[(0,R.jsx)(`span`,{className:`font-medium`,children:`Purpose`}),(0,R.jsx)(`textarea`,{value:T.purpose,onChange:e=>E(t=>({...t,purpose:e.target.value})),placeholder:`Own X, Y and Z workflows for this project and verify their results.`,className:`h-24 w-full resize-y rounded border border-border bg-card p-2`})]}),(0,R.jsxs)(`label`,{className:`block space-y-1 text-xs`,children:[(0,R.jsx)(`span`,{className:`font-medium`,children:`Task types (comma or one per line)`}),(0,R.jsx)(`textarea`,{value:T.taskTypes,onChange:e=>E(t=>({...t,taskTypes:e.target.value})),placeholder:`X workflow
9
+ `),n=t.getState();n.addMessage({role:`user`,content:e}),n.setLoading(!0),k().sendMessage(e);let r=O.getState();r.setSidebarOpen(!1),r.setCurrentView(`chat`)}if(n.length===0&&s.length===0){if(a>0){let t=r>0?` ${r} skipped.`:``,n=`Bulk consolidate failed for ${a} of ${e.length} agent${e.length>1?`s`:``}.${o?` Last error: ${o}`:``}${t}`;v({ok:!1,msg:n});return}let t=r>0?`Bulk optimize: ${r} skipped (no entries to optimize).`:`No agents had optimizable entries.`;v({ok:!0,msg:t}),M.info(t,6e3);return}let c=[];n.length>0&&c.push(`${n.length} consolidated`),s.length>0&&c.push(`${s.length} sent to chat`),r>0&&c.push(`${r} skipped`),a>0&&c.push(`${a} failed`);let l=`Bulk optimize: ${c.join(`, `)}.`;v({ok:a===0,msg:l}),n.length>0&&s.length===0?M.success(l,6e3):M.info(l,6e3)}catch(e){v({ok:!1,msg:e instanceof Error?e.message:`Bulk optimization failed`}),M.error(e instanceof Error?e.message:`Bulk optimization failed`)}finally{P(!1)}}},[i,W]);return F.length===0?(0,R.jsx)(`div`,{className:`flex flex-1 items-center justify-center text-muted-foreground`,children:(0,R.jsxs)(`div`,{className:`text-center space-y-3`,children:[(0,R.jsx)(x,{className:`h-10 w-10 mx-auto opacity-30`}),(0,R.jsx)(`p`,{className:`text-sm`,children:`No self-learning data yet`}),(0,R.jsx)(`p`,{className:`text-xs text-muted-foreground/70`,children:`Learning entries appear when agents capture output`})]})}):(0,R.jsxs)(`div`,{className:`flex min-h-0 min-w-0 flex-1 overflow-hidden`,children:[(0,R.jsxs)(`div`,{className:A(`flex flex-col min-h-0 min-w-0 overflow-hidden border-r border-border/50`,i?`w-80 shrink-0`:`flex-1`),children:[(0,R.jsxs)(`div`,{className:`shrink-0 px-3 py-2 border-b border-border/50`,children:[(0,R.jsxs)(`h3`,{className:`text-xs font-semibold flex items-center gap-1.5`,children:[(0,R.jsx)(x,{className:`h-3.5 w-3.5 text-brand-2`}),`All Roster Agents`]}),(()=>{let e=F.filter(e=>e.needsSummarization);return e.length===0?null:(0,R.jsxs)(`div`,{className:`mt-2 flex flex-col gap-1.5 rounded border border-warning/40 bg-warning/10 px-2 py-1.5`,children:[(0,R.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,R.jsx)(S,{className:`h-3 w-3 text-warning shrink-0`}),(0,R.jsxs)(`span`,{className:`text-[10px] text-warning leading-tight`,children:[e.length,` agent`,e.length>1?`s`:``,` need`,e.length===1?`s`:``,` optimization`]}),(0,R.jsx)(`button`,{type:`button`,onClick:()=>{let t=e[0];t&&(s(t.role),l(null),E(null))},className:`ml-auto text-[9px] text-warning underline hover:text-warning/80 shrink-0`,children:`review →`})]}),(0,R.jsxs)(`button`,{type:`button`,onClick:()=>K(e.map(e=>e.role)),disabled:N,className:`flex items-center justify-center gap-1 rounded bg-warning/20 border border-warning/40 px-2 py-1 text-[10px] font-medium text-warning hover:bg-warning/30 transition-colors disabled:opacity-50`,children:[N?(0,R.jsx)(o,{className:`h-3 w-3 animate-spin`}):(0,R.jsx)(S,{className:`h-3 w-3`}),N?`Optimizing…`:`Optimize All (${e.length})`]})]})})()]}),(0,R.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto p-2 space-y-1`,children:F.map(e=>(0,R.jsxs)(`button`,{type:`button`,onClick:()=>{s(e.role),l(null),E(null)},className:A(`w-full text-left rounded-lg border px-3 py-2 transition-colors`,i===e.role?`border-primary/50 bg-primary/[0.06]`:`border-border/60 hover:border-primary/30`,e.needsSummarization&&i!==e.role&&`border-warning/40`),children:[(0,R.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,R.jsx)(`span`,{className:`text-xs font-semibold`,children:e.role}),(0,R.jsx)(`span`,{className:A(`text-[9px] tabular-nums`,e.learningEnabled?`text-success`:`text-muted-foreground`),children:e.learningEnabled?`learning`:`paused`})]}),(0,R.jsxs)(`div`,{className:`flex items-center gap-2 mt-1 text-[9px] text-muted-foreground`,children:[(0,R.jsxs)(`span`,{className:`tabular-nums`,children:[e.entryCount,` entries`]}),e.sessionCaptureCount>0&&(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(`span`,{className:`text-muted-foreground/50`,children:`·`}),(0,R.jsxs)(`span`,{className:`text-success tabular-nums`,children:[`+`,e.sessionCaptureCount]})]}),e.lastCapture&&(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(`span`,{className:`text-muted-foreground/50`,children:`·`}),(0,R.jsx)(`span`,{children:new Date(e.lastCapture).toLocaleDateString()})]}),e.needsSummarization&&(0,R.jsxs)(`span`,{className:`inline-flex items-center gap-0.5 text-warning font-medium`,children:[(0,R.jsx)(S,{className:`h-2.5 w-2.5`}),`optimize`]})]})]},e.role))})]}),(0,R.jsxs)(`div`,{className:`flex-1 min-w-0 overflow-y-auto p-4`,children:[!i&&(0,R.jsx)(`div`,{className:`flex items-center justify-center h-full text-muted-foreground`,children:`Select an agent to view learning details`}),i&&z&&(0,R.jsxs)(`div`,{className:`space-y-4`,children:[(0,R.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,R.jsx)(`h3`,{className:`text-base font-semibold`,children:i}),(0,R.jsx)(`div`,{className:`flex gap-1`,children:(0,R.jsxs)(`button`,{type:`button`,onClick:()=>U(i,!z.learningEnabled),disabled:y,className:A(`inline-flex items-center gap-1 rounded border px-2 py-1 text-[10px] transition-colors disabled:opacity-50`,z.learningEnabled?`border-success/40 text-success hover:bg-success/10`:`border-border/50 text-muted-foreground hover:bg-accent`),children:[(0,R.jsx)(x,{className:`h-3 w-3`}),` `,z.learningEnabled?`Learning on`:`Learning paused`]})})]}),(0,R.jsxs)(`div`,{className:`grid grid-cols-4 gap-2`,children:[(0,R.jsxs)(`div`,{className:`rounded-lg border bg-card p-2`,children:[(0,R.jsx)(`span`,{className:`text-[9px] text-muted-foreground uppercase tracking-wider`,children:`Entries`}),(0,R.jsx)(`div`,{className:`text-lg font-mono font-semibold mt-0.5`,children:z.entryCount})]}),(0,R.jsxs)(`div`,{className:`rounded-lg border bg-card p-2`,children:[(0,R.jsx)(`span`,{className:`text-[9px] text-muted-foreground uppercase tracking-wider`,children:`Size`}),(0,R.jsxs)(`div`,{className:`text-lg font-mono font-semibold mt-0.5`,children:[z.totalBytes,`B`]})]}),(0,R.jsxs)(`div`,{className:`rounded-lg border bg-card p-2`,children:[(0,R.jsx)(`span`,{className:`text-[9px] text-muted-foreground uppercase tracking-wider`,children:`Last Capture`}),(0,R.jsx)(`div`,{className:`text-lg font-mono font-semibold mt-0.5`,children:z.lastCapture?new Date(z.lastCapture).toLocaleDateString():`—`})]}),(0,R.jsxs)(`div`,{className:`rounded-lg border bg-card p-2`,children:[(0,R.jsx)(`span`,{className:`text-[9px] text-muted-foreground uppercase tracking-wider`,children:`Lifetime Captures`}),(0,R.jsx)(`div`,{className:`text-lg font-mono font-semibold mt-0.5`,children:z.lifetimeCaptureCount})]})]}),z.needsSummarization&&(0,R.jsxs)(`div`,{className:`flex items-center gap-3 text-xs text-warning bg-warning/10 rounded-lg px-3 py-2.5`,children:[(0,R.jsx)(_,{className:`h-4 w-4 shrink-0`}),(0,R.jsxs)(`span`,{className:`flex-1`,children:[`Learned data exceeds soft limit (`,z.totalBytes.toLocaleString(),`B / 8,192B). Optimize to synthesize raw entries into a consolidated document and reduce context volume.`]}),(0,R.jsxs)(`button`,{type:`button`,onClick:()=>G(i),disabled:D,className:`inline-flex items-center gap-1 rounded bg-warning/20 text-warning border border-warning/40 px-2.5 py-1 text-[10px] font-medium hover:bg-warning/30 transition-colors disabled:opacity-50 shrink-0`,children:[D?(0,R.jsx)(o,{className:`h-3 w-3 animate-spin`}):(0,R.jsx)(S,{className:`h-3 w-3`}),D?`Optimizing…`:`Optimize Now`]})]}),(0,R.jsxs)(`div`,{className:`space-y-2 border border-border rounded-lg p-3 bg-card`,children:[(0,R.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,R.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,R.jsx)(a,{className:`h-4 w-4 text-primary`}),(0,R.jsx)(`span`,{className:`text-xs font-semibold`,children:`Optimize Learnings`})]}),(0,R.jsxs)(`button`,{type:`button`,onClick:()=>G(i),disabled:D||z.entryCount===0,className:`inline-flex items-center gap-1 rounded bg-primary px-3 py-1.5 text-xs text-primary-foreground hover:bg-primary/90 transition-colors disabled:opacity-50`,title:z.entryCount===0?`No raw entries to optimize`:`Synthesize raw entries into a consolidated, narrowly-scoped document`,children:[D?(0,R.jsx)(o,{className:`h-3.5 w-3.5 animate-spin`}):(0,R.jsx)(S,{className:`h-3.5 w-3.5`}),D?`Optimizing…`:`Optimize`]})]}),(0,R.jsxs)(`p`,{className:`text-[10px] text-muted-foreground leading-relaxed`,children:[`Synthesizes all `,z.entryCount,` raw entries into a single reviewed document — narrowly scoped to this agent's skills, preserving every fact but reducing context volume. The result replaces raw entries in the agent's prompt.`]}),z.isConsolidated&&z.consolidation&&(0,R.jsxs)(`div`,{className:`flex items-center gap-2 text-[10px] text-muted-foreground pt-1 border-t border-border/50`,children:[(0,R.jsx)(n,{className:`h-3 w-3 text-success`}),(0,R.jsxs)(`span`,{children:[`Consolidated`,` `,new Date(z.consolidation.consolidatedAt).toLocaleDateString(),` ·`,` `,z.consolidation.sourceBytes,`B →`,` `,z.consolidation.consolidatedBytes,`B`,z.consolidation.sourceEntryCount<z.entryCount&&(0,R.jsxs)(`span`,{className:`text-warning ml-1`,children:[`· `,z.entryCount-z.consolidation.sourceEntryCount,` `,`new pending`]})]}),(0,R.jsx)(`button`,{type:`button`,onClick:()=>{T===null?W(i):E(null)},className:`ml-auto underline text-primary hover:text-primary/80`,children:T===null?`View`:`Hide`})]}),T!==null&&(0,R.jsxs)(`div`,{className:`mt-2 max-h-72 overflow-y-auto rounded border border-border/50 bg-background/50 p-2`,children:[(0,R.jsxs)(`div`,{className:`text-[10px] text-muted-foreground mb-1 font-medium`,children:[`Consolidated knowledge for `,i]}),(0,R.jsx)(`pre`,{className:`text-[10px] whitespace-pre-wrap font-sans leading-relaxed`,children:T||`(empty)`})]})]}),z.entryCount>0&&(0,R.jsxs)(`div`,{className:`space-y-2`,children:[(0,R.jsx)(`div`,{className:`flex items-center gap-2`,children:(0,R.jsxs)(`button`,{type:`button`,onClick:()=>B(i),disabled:C,className:`inline-flex items-center gap-1 rounded border border-border/50 px-3 py-1.5 text-xs hover:bg-accent transition-colors`,children:[C?(0,R.jsx)(o,{className:`h-3 w-3 animate-spin`}):(0,R.jsx)(d,{className:`h-3 w-3`}),`Review Learned Entries (`,z.entryCount,`)`]})}),c&&(0,R.jsxs)(`div`,{className:`space-y-2 border border-border rounded-lg p-3 bg-card`,children:[(0,R.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,R.jsxs)(`span`,{className:`text-xs font-medium`,children:[c.filter((e,t)=>u[t]!==`drop`).length,`/`,c.length,` kept`]}),(0,R.jsxs)(`div`,{className:`flex gap-2`,children:[(0,R.jsx)(`button`,{type:`button`,onClick:V,disabled:y,className:`inline-flex items-center gap-1 rounded bg-primary px-2 py-1 text-[10px] text-primary-foreground hover:bg-primary/90 transition-colors`,children:y?`Applying…`:`Apply Selection`}),(0,R.jsx)(`button`,{type:`button`,onClick:()=>{l(null),f({})},className:`inline-flex items-center gap-1 rounded border border-border/50 px-2 py-1 text-[10px] hover:bg-accent transition-colors`,children:`Cancel`})]})]}),(0,R.jsx)(`div`,{className:`max-h-72 overflow-y-auto space-y-2`,children:c.map((e,t)=>{let n=u[t]??`keep`,r=e.length>200?e.slice(0,200)+`…`:e;return(0,R.jsx)(`div`,{className:A(`rounded-lg border p-2 transition-colors`,n===`drop`?`border-destructive/40 bg-destructive/5 opacity-60`:`border-border`),children:(0,R.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,R.jsx)(`pre`,{className:`text-[10px] whitespace-pre-wrap flex-1 leading-relaxed font-sans`,children:r}),(0,R.jsxs)(`div`,{className:`flex gap-1 shrink-0`,children:[(0,R.jsx)(`button`,{type:`button`,onClick:()=>f(e=>({...e,[t]:`keep`})),className:A(`px-2 py-1 text-[9px] rounded`,n===`keep`?`bg-success/20 text-success`:`bg-muted text-muted-foreground`),children:`Keep`}),(0,R.jsx)(`button`,{type:`button`,onClick:()=>f(e=>({...e,[t]:`drop`})),className:A(`px-2 py-1 text-[9px] rounded`,n===`drop`?`bg-destructive/20 text-destructive`:`bg-muted text-muted-foreground`),children:`Drop`})]})]})},t)})})]})]}),(0,R.jsxs)(`div`,{className:`space-y-2 pt-4 border-t border-border`,children:[(0,R.jsxs)(`div`,{className:`flex items-center gap-1 text-sm font-medium`,children:[(0,R.jsx)(p,{className:`h-4 w-4 text-brand-2`}),` Teach this agent`]}),(0,R.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,children:`Describe a command, pattern, or behavior you want this agent to remember.`}),(0,R.jsx)(`textarea`,{className:`w-full h-20 text-xs p-2 bg-card border border-border rounded resize-y`,value:m,onChange:e=>h(e.target.value),placeholder:`e.g. Always use pnpm for this project`}),(0,R.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,R.jsxs)(`button`,{type:`button`,onClick:H,disabled:!m.trim()||y,className:`inline-flex items-center gap-1 rounded bg-primary px-3 py-1.5 text-xs text-primary-foreground hover:bg-primary/90 transition-colors disabled:opacity-50`,children:[(0,R.jsx)(p,{className:`h-3.5 w-3.5`}),` Teach`]}),g&&(0,R.jsx)(`span`,{className:A(`text-xs`,g.ok?`text-success`:`text-destructive`),children:g.msg})]})]})]})]})]})}function ee({customStats:e,catalog:t}){let[n,r]=(0,L.useState)(``),[a,o]=(0,L.useState)(null),c=(0,L.useMemo)(()=>new Set(e.filter(e=>e.exists||e.hasIdentity||e.hasConfig||e.hasKnowledge).map(e=>e.role)),[e]),l=(0,L.useMemo)(()=>{if(!n.trim())return t;let e=n.toLowerCase();return t.filter(t=>t.role.includes(e)||t.name.toLowerCase().includes(e)||t.summary.toLowerCase().includes(e))},[t,n]),u=(0,L.useCallback)(t=>e.find(e=>e.role===t),[e]),d=l;return(0,R.jsxs)(`div`,{className:`flex min-h-0 min-w-0 flex-1 flex-col overflow-hidden`,children:[(0,R.jsx)(`div`,{className:`shrink-0 px-3 py-2 border-b border-border/50`,children:(0,R.jsxs)(`div`,{className:`flex items-center gap-2 rounded-lg border border-border/60 bg-background px-3 py-1.5`,children:[(0,R.jsx)(m,{className:`h-3.5 w-3.5 text-muted-foreground`}),(0,R.jsx)(`input`,{type:`text`,value:n,onChange:e=>r(e.target.value),placeholder:`Search agents by name, role, or description…`,className:`flex-1 bg-transparent text-xs outline-none placeholder:text-muted-foreground/50`}),n&&(0,R.jsx)(`button`,{type:`button`,onClick:()=>r(``),className:`text-muted-foreground hover:text-foreground`,children:(0,R.jsx)(g,{className:`h-3 w-3`})})]})}),(0,R.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-y-auto p-3`,children:[(0,R.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-2`,children:d.map(e=>{let t=u(e.role),n=c.has(e.role),r=a===e.role;return(0,R.jsxs)(`div`,{className:A(`rounded-lg border bg-card transition-colors`,r?`border-primary/40 ring-1 ring-primary/20`:`border-border/60 hover:border-primary/30`),children:[(0,R.jsxs)(`button`,{type:`button`,onClick:()=>o(r?null:e.role),className:`w-full text-left p-3`,children:[(0,R.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,R.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,R.jsx)(f,{className:`h-4 w-4 shrink-0 text-primary`}),(0,R.jsx)(`span`,{className:`text-sm font-semibold truncate`,children:e.name}),(0,R.jsxs)(`code`,{className:`text-[9px] text-muted-foreground font-mono shrink-0`,children:[`@`,e.role]})]}),(0,R.jsx)(s,{className:A(`h-3.5 w-3.5 shrink-0 text-muted-foreground transition-transform`,r&&`rotate-180`)})]}),(0,R.jsx)(`p`,{className:`text-[10px] text-muted-foreground mt-1 leading-relaxed line-clamp-2`,children:e.summary}),(0,R.jsxs)(`div`,{className:`flex items-center gap-2 mt-1.5`,children:[(0,R.jsxs)(`span`,{className:`text-[9px] text-muted-foreground tabular-nums`,children:[e.tools,` tools`]}),e.budget.maxIterations&&(0,R.jsxs)(`span`,{className:`text-[9px] text-muted-foreground tabular-nums`,children:[e.budget.maxIterations.toLocaleString(),` max it`]}),n&&(0,R.jsxs)(`span`,{className:`inline-flex items-center gap-0.5 rounded bg-brand-2/10 px-1 py-0.5 text-[8px] text-brand-2 font-medium`,children:[(0,R.jsx)(i,{className:`h-2.5 w-2.5`}),` Customized`]}),t?.needsSummarization&&(0,R.jsx)(`span`,{className:`text-[9px] text-warning`,children:`⚠ Needs summary`})]})]}),r&&(0,R.jsxs)(`div`,{className:`border-t border-border/50 px-3 py-2 space-y-2`,children:[(0,R.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,R.jsxs)(`div`,{className:`rounded bg-muted/30 p-1.5`,children:[(0,R.jsx)(`span`,{className:`text-[8px] text-muted-foreground uppercase tracking-wider`,children:`Max Iterations`}),(0,R.jsx)(`div`,{className:`text-xs font-mono mt-0.5`,children:e.budget.maxIterations?.toLocaleString()??`—`})]}),(0,R.jsxs)(`div`,{className:`rounded bg-muted/30 p-1.5`,children:[(0,R.jsx)(`span`,{className:`text-[8px] text-muted-foreground uppercase tracking-wider`,children:`Timeout`}),(0,R.jsx)(`div`,{className:`text-xs font-mono mt-0.5`,children:e.budget.timeoutMs?`${Math.round(e.budget.timeoutMs/6e4)}m`:`—`})]}),(0,R.jsxs)(`div`,{className:`rounded bg-muted/30 p-1.5`,children:[(0,R.jsx)(`span`,{className:`text-[8px] text-muted-foreground uppercase tracking-wider`,children:`Max Tool Calls`}),(0,R.jsx)(`div`,{className:`text-xs font-mono mt-0.5`,children:e.budget.maxToolCalls?.toLocaleString()??`—`})]}),(0,R.jsxs)(`div`,{className:`rounded bg-muted/30 p-1.5`,children:[(0,R.jsx)(`span`,{className:`text-[8px] text-muted-foreground uppercase tracking-wider`,children:`Customized`}),(0,R.jsx)(`div`,{className:`text-xs font-mono mt-0.5`,children:n?`Yes`:`No`})]})]}),n&&t&&(0,R.jsxs)(`div`,{className:`rounded bg-accent/30 p-2 space-y-1`,children:[(0,R.jsx)(`span`,{className:`text-[9px] font-medium text-muted-foreground`,children:`Project Customizations`}),(0,R.jsxs)(`div`,{className:`flex flex-wrap gap-2 text-[9px]`,children:[t.hasIdentity&&(0,R.jsxs)(`span`,{className:`inline-flex items-center gap-0.5`,children:[(0,R.jsx)(i,{className:`h-2.5 w-2.5 text-primary`}),` identity.md`]}),t.entryCount>0&&(0,R.jsxs)(`span`,{className:`inline-flex items-center gap-0.5`,children:[(0,R.jsx)(x,{className:`h-2.5 w-2.5 text-brand-2`}),` `,t.entryCount,` `,`learned entries`]}),t.hasConfig&&(0,R.jsxs)(`span`,{className:`inline-flex items-center gap-0.5`,children:[(0,R.jsx)(T,{className:`h-2.5 w-2.5 text-muted-foreground`}),` config.json`]}),t.sessionCaptureCount>0&&(0,R.jsxs)(`span`,{className:`inline-flex items-center gap-0.5`,children:[(0,R.jsx)(C,{className:`h-2.5 w-2.5 text-success`}),` `,t.sessionCaptureCount,` session captures`]})]})]})]})]},e.role)})}),d.length===0&&(0,R.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-40 text-muted-foreground`,children:[(0,R.jsx)(m,{className:`h-8 w-8 mb-2 opacity-30`}),(0,R.jsxs)(`p`,{className:`text-sm`,children:[`No agents match "`,n,`"`]})]})]}),(0,R.jsxs)(`div`,{className:`shrink-0 border-t border-border/50 px-3 py-2 text-[10px] text-muted-foreground flex items-center gap-2`,children:[(0,R.jsxs)(`span`,{children:[(0,R.jsx)(`strong`,{children:t.length}),` roster roles`]}),(0,R.jsx)(`span`,{className:`text-muted-foreground/50`,children:`·`}),(0,R.jsxs)(`span`,{className:`text-brand-2`,children:[(0,R.jsx)(`strong`,{children:c.size}),` customized`]}),(0,R.jsx)(`span`,{className:`text-muted-foreground/50`,children:`·`}),(0,R.jsxs)(`span`,{children:[(0,R.jsx)(`strong`,{children:e.reduce((e,t)=>e+t.entryCount,0)}),` total learned entries`]})]})]})}var Z={running:{led:`bg-success`,badge:`bg-success/12 text-success`,icon:(0,R.jsx)(`span`,{className:`led text-success led-pulse`}),color:`text-success`},completed:{led:`bg-success`,badge:`bg-success/12 text-success`,icon:(0,R.jsx)(n,{className:`h-3.5 w-3.5`}),color:`text-success`},failed:{led:`bg-destructive`,badge:`bg-destructive/15 text-destructive`,icon:(0,R.jsx)(l,{className:`h-3.5 w-3.5`}),color:`text-destructive`},timeout:{led:`bg-warning`,badge:`bg-muted text-muted-foreground`,icon:(0,R.jsx)(b,{className:`h-3.5 w-3.5`}),color:`text-warning`},stopped:{led:`bg-muted-foreground`,badge:`bg-muted text-muted-foreground`,icon:(0,R.jsx)(`span`,{className:`led text-muted-foreground`}),color:`text-muted-foreground`},idle:{led:`bg-muted-foreground`,badge:`bg-muted text-muted-foreground`,icon:(0,R.jsx)(`span`,{className:`led text-muted-foreground`}),color:`text-muted-foreground`}};function Q(e){let t=Math.floor(e/1e3);if(t<60)return`${t}s`;let n=Math.floor(t/60);if(n<60)return`${n}m ${t%60}s`;let r=Math.floor(n/60);return r<24?`${r}h ${n%60}m`:`${Math.floor(r/24)}d`}function $(e){if(e==null||!Number.isFinite(e)||e<=0)return`$0`;if(e<.01){let t=e.toFixed(5);return t===`0.00000`?`$0`:`$`+t.replace(/(\d)0+$/,`$1`).replace(/\.$/,``)}return`$`+e.toFixed(3)}function te({nowTick:e}){let t=j(e=>e.agents),n=j(e=>e.leaderId),[i,a]=(0,L.useState)(null),[o,s]=(0,L.useState)(`all`),c=(0,L.useMemo)(()=>{let e=Array.from(t.values());return e.sort((e,t)=>{let n=e.status===`running`?0:1,r=t.status===`running`?0:1;return n===r?t.startedAt-e.startedAt:n-r}),o===`all`?e:o===`running`?e.filter(e=>e.status===`running`):o===`done`?e.filter(e=>e.status===`completed`):o===`failed`?e.filter(e=>e.status===`failed`||e.status===`timeout`):e},[t,o]),l=(0,L.useMemo)(()=>{let e=0,n=0,r=0;for(let i of t.values())i.status===`running`?e++:i.status===`completed`?n++:(i.status===`failed`||i.status===`timeout`)&&r++;return{running:e,completed:n,failed:r,total:t.size}},[t]),u=j(e=>e.clearFinishedAgents),d=i?c.find(e=>e.id===i):null,p=(0,L.useCallback)(e=>{let t=O.getState();e?(t.setInspectorFocusedAgentId(e),t.setInspectorTab(`agents`)):t.setInspectorTab(`fleet`),t.setInspectorOpen(!0)},[]);return c.length===0?(0,R.jsx)(`div`,{className:`flex flex-1 items-center justify-center text-muted-foreground`,children:(0,R.jsxs)(`div`,{className:`text-center space-y-3`,children:[(0,R.jsx)(f,{className:`h-10 w-10 mx-auto opacity-30`}),(0,R.jsx)(`p`,{className:`text-sm`,children:`No active fleet agents`}),(0,R.jsx)(`p`,{className:`text-xs text-muted-foreground/70`,children:`Agents appear here when subagents spawn`})]})}):(0,R.jsxs)(`div`,{className:`flex min-h-0 min-w-0 flex-1 overflow-hidden`,children:[(0,R.jsxs)(`div`,{className:A(`flex flex-col min-h-0 min-w-0 overflow-hidden`,d?`w-80 shrink-0 border-r border-border/50`:`flex-1`),children:[(0,R.jsxs)(`div`,{className:`flex items-center gap-1 shrink-0 px-3 py-2 border-b border-border/50`,children:[[`all`,`running`,`done`,`failed`].map(e=>(0,R.jsxs)(`button`,{type:`button`,onClick:()=>s(e),className:A(`rounded px-2 py-0.5 text-[10px] font-medium transition-colors`,o===e?`bg-primary/10 text-primary`:`text-muted-foreground hover:text-foreground hover:bg-muted/50`),children:[e===`all`&&`All (${l.total})`,e===`running`&&`Running (${l.running})`,e===`done`&&`Done (${l.completed})`,e===`failed`&&`Failed (${l.failed})`]},e)),(0,R.jsx)(`span`,{className:`flex-1`}),l.completed+l.failed>0&&(0,R.jsxs)(`button`,{type:`button`,onClick:u,className:`inline-flex items-center gap-0.5 rounded px-1.5 py-0.5 text-[10px] text-muted-foreground hover:text-destructive hover:bg-destructive/10 transition-colors`,children:[(0,R.jsx)(r,{className:`h-2.5 w-2.5`}),` Clear`]})]}),(0,R.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto p-2 space-y-1`,children:c.map(e=>(0,R.jsxs)(`button`,{type:`button`,onClick:()=>a(i===e.id?null:e.id),className:A(`w-full text-left rounded-lg border px-3 py-2 transition-colors flex items-center gap-2`,i===e.id?`border-primary/50 bg-primary/[0.06]`:`border-border/60 hover:border-primary/30 hover:bg-primary/[0.03]`),children:[(0,R.jsx)(`span`,{className:A(`led shrink-0`,Z[e.status]?.led??`bg-muted-foreground`,e.status===`running`&&`led-pulse`)}),(0,R.jsx)(`span`,{className:`text-xs font-semibold min-w-0 truncate max-w-[7rem]`,children:e.name}),e.id===n&&(0,R.jsx)(h,{className:`h-3 w-3 shrink-0 text-warning`}),e.model&&(0,R.jsx)(`span`,{className:`text-[9px] text-muted-foreground font-mono truncate max-w-[6rem] shrink-0`,children:e.model}),(0,R.jsxs)(`span`,{className:`text-[9px] text-muted-foreground tabular-nums shrink-0`,children:[e.iteration,`it · `,e.toolCalls,`t`]}),e.status===`running`&&(0,R.jsx)(`span`,{className:`text-[9px] text-primary tabular-nums shrink-0 ml-auto`,children:Q(Date.now()-e.startedAt)}),e.status!==`running`&&(0,R.jsx)(`span`,{className:A(`text-[9px] tabular-nums shrink-0 ml-auto`,Z[e.status]?.color??`text-muted-foreground`),children:e.status}),e.costUsd>0&&(0,R.jsx)(`span`,{className:`text-[9px] text-success tabular-nums font-medium shrink-0`,children:$(e.costUsd)}),e.status===`running`&&e.currentTool&&(0,R.jsxs)(`span`,{className:`text-[9px] text-primary font-mono truncate max-w-[6rem] shrink-0`,children:[`→ `,e.currentTool]})]},e.id))}),(0,R.jsxs)(`div`,{className:`shrink-0 border-t border-border/50 px-3 py-2 flex items-center gap-2 text-[10px] text-muted-foreground`,children:[(0,R.jsx)(`span`,{className:`font-medium tabular-nums`,children:l.total}),` agents total`,(0,R.jsx)(`span`,{className:`text-muted-foreground/50`,children:`·`}),(0,R.jsx)(`span`,{className:`text-success tabular-nums`,children:l.running}),` running`,(0,R.jsx)(`span`,{className:`text-muted-foreground/50`,children:`·`}),(0,R.jsx)(`span`,{className:`tabular-nums`,children:l.completed}),` done`,l.failed>0&&(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(`span`,{className:`text-muted-foreground/50`,children:`·`}),(0,R.jsx)(`span`,{className:`text-destructive tabular-nums`,children:l.failed}),` failed`]}),(0,R.jsx)(`span`,{className:`flex-1`}),(0,R.jsxs)(`button`,{type:`button`,onClick:()=>p(),className:`inline-flex items-center gap-1 rounded border border-border/50 px-2 py-1 hover:bg-accent transition-colors`,children:[(0,R.jsx)(E,{className:`h-3 w-3`}),`Fleet Inspector`]})]})]}),d&&(0,R.jsx)(`div`,{className:`flex-1 min-w-0 overflow-y-auto p-4`,children:(0,R.jsx)(ne,{agent:d,nowTick:e})})]})}function ne({agent:e,nowTick:t}){let n=e.status===`running`?Q(t-e.startedAt):e.completedAt?Q(e.completedAt-e.startedAt):`-`,r=Math.min(100,Math.max(0,e.ctxPct)),i=e.currentTool||e.lastTool,a=j(e=>e.leaderId);return(0,R.jsxs)(`div`,{className:`space-y-4`,children:[(0,R.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,R.jsx)(`div`,{className:`flex items-center justify-center w-10 h-10 rounded-lg bg-primary/10`,children:(0,R.jsx)(f,{className:`h-5 w-5 text-primary`})}),(0,R.jsxs)(`div`,{children:[(0,R.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,R.jsx)(`span`,{className:`text-base font-semibold`,children:e.name}),e.id===a&&(0,R.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded border border-warning/30 bg-warning/10 px-1.5 py-0.5 text-[9px] font-medium text-warning`,children:[(0,R.jsx)(h,{className:`h-2.5 w-2.5`}),` Leader`]})]}),(0,R.jsxs)(`div`,{className:`flex items-center gap-2 text-[10px] text-muted-foreground`,children:[(0,R.jsx)(`span`,{className:A(`led`,Z[e.status]?.led,e.status===`running`&&`led-pulse`)}),(0,R.jsx)(`span`,{children:e.status}),e.model&&(0,R.jsxs)(`span`,{children:[`· `,e.provider,`/`,e.model]}),(0,R.jsxs)(`span`,{children:[`· `,n]})]})]})]}),(0,R.jsxs)(`div`,{className:`grid grid-cols-4 gap-2`,children:[(0,R.jsxs)(`div`,{className:`rounded-lg border bg-card p-2`,children:[(0,R.jsx)(`span`,{className:`text-[9px] text-muted-foreground uppercase tracking-wider`,children:`Iterations`}),(0,R.jsx)(`div`,{className:`text-lg font-mono font-semibold mt-0.5`,children:e.iteration})]}),(0,R.jsxs)(`div`,{className:`rounded-lg border bg-card p-2`,children:[(0,R.jsx)(`span`,{className:`text-[9px] text-muted-foreground uppercase tracking-wider`,children:`Tool Calls`}),(0,R.jsx)(`div`,{className:`text-lg font-mono font-semibold mt-0.5`,children:e.toolCalls})]}),(0,R.jsxs)(`div`,{className:`rounded-lg border bg-card p-2`,children:[(0,R.jsx)(`span`,{className:`text-[9px] text-muted-foreground uppercase tracking-wider`,children:`Cost`}),(0,R.jsx)(`div`,{className:`text-lg font-mono font-semibold mt-0.5 text-success`,children:$(e.costUsd)})]}),(0,R.jsxs)(`div`,{className:`rounded-lg border bg-card p-2`,children:[(0,R.jsx)(`span`,{className:`text-[9px] text-muted-foreground uppercase tracking-wider`,children:`Context`}),(0,R.jsxs)(`div`,{className:`text-lg font-mono font-semibold mt-0.5`,children:[r,`%`]})]})]}),e.maxContext>0&&(0,R.jsxs)(`div`,{className:`space-y-1`,children:[(0,R.jsxs)(`div`,{className:`flex justify-between text-[10px]`,children:[(0,R.jsx)(`span`,{className:`text-muted-foreground`,children:`Context Window`}),(0,R.jsxs)(`span`,{className:A(`tabular font-medium`,r>=85?`text-destructive`:r>=70?`text-warning`:`text-success`),children:[e.ctxTokens.toLocaleString(),` / `,e.maxContext.toLocaleString(),` tokens`]})]}),(0,R.jsx)(`div`,{className:`h-2 w-full overflow-hidden rounded-full bg-muted`,children:(0,R.jsx)(`div`,{className:A(`h-full rounded-full transition-all`,r>=85?`bg-destructive`:r>=70?`bg-warning`:`bg-primary`),style:{width:`${Math.max(2,r)}%`}})})]}),i&&(0,R.jsxs)(`div`,{className:A(`flex items-center gap-2 rounded-lg border px-3 py-2`,e.status===`running`?`border-primary/30 bg-primary/[0.04]`:`border-border bg-muted/30`),children:[(0,R.jsx)(w,{className:A(`h-4 w-4`,e.status===`running`?`text-primary animate-pulse`:`text-muted-foreground`)}),(0,R.jsx)(`span`,{className:`text-sm font-mono`,children:e.currentTool??e.lastTool}),(0,R.jsx)(`span`,{className:`text-[10px] text-muted-foreground ml-auto`,children:e.currentTool?`Running`:`Last tool`})]}),e.error&&(0,R.jsxs)(`div`,{className:`rounded-lg border border-destructive/30 bg-destructive/5 p-3`,children:[(0,R.jsx)(`span`,{className:`text-[10px] font-semibold text-destructive uppercase tracking-wider`,children:`Error`}),(0,R.jsx)(`p`,{className:`text-xs text-destructive/90 mt-1`,children:e.error.message})]}),e.toolLog.length>0&&(0,R.jsxs)(`div`,{className:`space-y-1`,children:[(0,R.jsxs)(`span`,{className:`text-[10px] font-semibold text-muted-foreground uppercase tracking-wider`,children:[`Tool Log (`,e.toolLog.length,`)`]}),(0,R.jsx)(`div`,{className:`space-y-0.5`,children:e.toolLog.slice(0,10).map((e,t)=>(0,R.jsxs)(`div`,{className:A(`flex items-center gap-2 rounded px-2 py-1 text-[10px] font-mono`,e.ok?`bg-muted/30`:`bg-destructive/5 border border-destructive/20`),children:[(0,R.jsx)(`span`,{className:A(`led shrink-0`,e.ok?`text-success`:`text-destructive`)}),(0,R.jsx)(`span`,{className:`truncate flex-1`,children:e.name}),(0,R.jsxs)(`span`,{className:`tabular text-muted-foreground`,children:[e.durationMs,`ms`]}),!e.ok&&(0,R.jsx)(`span`,{className:`text-destructive`,children:`✗`})]},`${e.name}-${t}`))})]}),e.budgetWarning&&(0,R.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-2 rounded-lg bg-warning/10 border border-warning/25 text-xs`,children:[(0,R.jsx)(S,{className:`h-3.5 w-3.5 text-warning shrink-0`}),(0,R.jsxs)(`span`,{className:`text-warning`,children:[`Budget: `,e.budgetWarning.kind,` limit (`,e.budgetWarning.used,`/`,e.budgetWarning.limit,`)`]})]})]})}function re(){let[e,t]=(0,L.useState)([]),[n,r]=(0,L.useState)(q),[i,a]=(0,L.useState)(!1),[o,s]=(0,L.useState)(null),c=(0,L.useCallback)(async()=>{a(!0),s(null);try{let e=await I(`agent-roster.list`,{});e.stats&&t(e.stats),e.catalog?.length&&r(e.catalog)}catch(e){s(e instanceof Error?e.message:`Failed to load roster`)}a(!1)},[]);return(0,L.useEffect)(()=>{c()},[c]),(0,L.useEffect)(()=>{let e=null,t=k().on(`agent-roster.updated`,()=>{e&&clearTimeout(e),e=setTimeout(()=>{e=null,c()},300)});return()=>{e&&clearTimeout(e),t()}},[c]),{customStats:e,catalog:n,rosterLoading:i,rosterError:o,loadRoster:c}}function ie({customStats:e,catalog:n,onRefresh:o}){let[s,c]=(0,L.useState)(null),[l,f]=(0,L.useState)(null),[p,m]=(0,L.useState)(``),[h,g]=(0,L.useState)(null),[_,v]=(0,L.useState)(!1),[y,b]=(0,L.useState)(null),[S,C]=(0,L.useState)(!1),[w,E]=(0,L.useState)({name:``,role:``,baseRole:`generic`,purpose:``,taskTypes:``}),D=(0,L.useMemo)(()=>s?e.find(e=>e.role===s):null,[s,e]),j=(0,L.useMemo)(()=>{let e=n.find(e=>e.role===s);return e?.systemProtected??!e?.custom},[n,s]),M=(0,L.useCallback)(async(e,t)=>{v(!0),b(null),c(e);try{let n=await I(`agent-roster.read-customization`,{role:e});m(t===`config`?`${JSON.stringify(n.config??{},null,2)}\n`:n[t]??``),f(t),g(null)}catch(e){b(e instanceof Error?e.message:`Failed to load customization`)}finally{v(!1)}},[]),N=(0,L.useCallback)(async e=>{v(!0),b(null),c(e);try{let t=await I(`agent-roster.read-customization`,{role:e});g(t.config??{}),f(null)}catch(e){b(e instanceof Error?e.message:`Failed to load runtime policy`)}finally{v(!1)}},[]),P=(0,L.useCallback)(async e=>{if(s){v(!0),b(null);try{await I(`agent-roster.update-config`,{role:s,config:e}),g(null),o()}catch(e){b(e instanceof Error?e.message:`Runtime policy save failed`)}finally{v(!1)}}},[o,s]),F=(0,L.useCallback)(async()=>{if(!(!s||!l)){v(!0);try{let e={identity:`agent-roster.update-identity`,learned:`agent-roster.update-learned`,config:`agent-roster.update-config`},t={role:s};if(l===`config`)try{t.config=JSON.parse(p)}catch{b(`config.json must contain valid JSON`),v(!1);return}else t.content=p;await I(e[l],t),f(null),b(null),o()}catch(e){b(e instanceof Error?e.message:`Save failed`)}v(!1)}},[s,l,p,o]),z=(0,L.useCallback)(async()=>{if(s)try{let e=await I(`agent-roster.llm-improve`,{role:s,prompt:`Improve this agent for optimal project performance`});if(!e.instruction)throw Error(`No improvement instruction generated`);let n=t.getState();n.addMessage({role:`user`,content:e.instruction}),n.setLoading(!0),k().sendMessage(e.instruction);let r=O.getState();r.setSidebarOpen(!1),r.setCurrentView(`chat`)}catch(e){b(e instanceof Error?e.message:`LLM improvement failed`)}},[s]),B=(0,L.useCallback)(async e=>{if(window.confirm(`Reset all project-specific data for agent "${e}"?`))try{await I(`agent-roster.reset`,{role:e}),c(null),o()}catch{}},[o]),V=(0,L.useCallback)(async()=>{let e=w.taskTypes.split(/[\n,]+/).map(e=>e.trim()).filter(Boolean);v(!0),b(null);try{let t=await I(`agent-roster.create`,{name:w.name,role:w.role,baseRole:w.baseRole,purpose:w.purpose,taskTypes:e});C(!1),E({name:``,role:``,baseRole:`generic`,purpose:``,taskTypes:``}),c(t.role),o()}catch(e){b(e instanceof Error?e.message:`Agent creation failed`)}finally{v(!1)}},[w,o]),H=(0,L.useMemo)(()=>[...e].sort((e,t)=>{let n=+!!e.hasIdentity+ +(e.entryCount>0)+ +!!e.hasConfig;return+!!t.hasIdentity+ +(t.entryCount>0)+ +!!t.hasConfig-n}),[e]);return(0,R.jsxs)(`div`,{className:`flex min-h-0 min-w-0 flex-1 overflow-hidden`,children:[(0,R.jsxs)(`div`,{className:`w-80 shrink-0 border-r border-border/50 flex flex-col overflow-hidden`,children:[(0,R.jsx)(`div`,{className:`shrink-0 border-b border-border/50 px-3 py-2`,children:(0,R.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,R.jsxs)(`h3`,{className:`flex items-center gap-1.5 text-xs font-semibold`,children:[(0,R.jsx)(T,{className:`h-3.5 w-3.5`}),`Project Agents`]}),(0,R.jsx)(`button`,{type:`button`,onClick:()=>{C(!0),c(null),g(null),b(null)},className:`rounded border border-primary/40 px-1.5 py-1 text-[9px] text-primary hover:bg-primary/10`,children:`+ Clone`})]})}),(0,R.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-y-auto p-2 space-y-1`,children:[H.map(e=>(0,R.jsxs)(`button`,{type:`button`,onClick:()=>{c(e.role),g(null),f(null)},className:A(`w-full text-left rounded-lg border px-3 py-2 transition-colors`,s===e.role?`border-primary/50 bg-primary/[0.06]`:`border-border/60 hover:border-primary/30`),children:[(0,R.jsx)(`div`,{className:`text-xs font-semibold`,children:e.role}),(0,R.jsxs)(`div`,{className:`flex gap-2 mt-0.5 text-[9px] text-muted-foreground`,children:[e.hasIdentity&&(0,R.jsx)(`span`,{className:`text-primary`,children:`id`}),e.entryCount>0&&(0,R.jsxs)(`span`,{className:`text-brand-2`,children:[e.entryCount,`e`]}),e.hasConfig&&(0,R.jsx)(`span`,{children:`cfg`})]})]},e.role)),H.length===0&&(0,R.jsx)(`div`,{className:`text-[10px] text-muted-foreground text-center py-4`,children:`No customizations yet`})]})]}),(0,R.jsxs)(`div`,{className:`flex-1 min-w-0 overflow-y-auto p-4`,children:[S&&(0,R.jsxs)(`div`,{className:`max-w-2xl space-y-4`,children:[(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`h3`,{className:`text-base font-semibold`,children:`Create or Clone Project Agent`}),(0,R.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:`Inherit any roster agent as a template, then develop an independent identity, runtime policy and learned history.`})]}),(0,R.jsxs)(`label`,{className:`block space-y-1 text-xs`,children:[(0,R.jsx)(`span`,{className:`font-medium`,children:`Clone from roster role`}),(0,R.jsx)(`select`,{value:w.baseRole,onChange:e=>E(t=>({...t,baseRole:e.target.value})),className:`h-9 w-full rounded border border-border bg-card px-2`,children:[...n].sort((e,t)=>e.name.localeCompare(t.name)).map(e=>(0,R.jsxs)(`option`,{value:e.role,children:[e.name,` (`,e.role,`)`]},e.role))}),(0,R.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,children:`Prompt, tools, skills and defaults are inherited. Learning and later edits remain isolated to the new agent.`})]}),(0,R.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,R.jsxs)(`label`,{className:`space-y-1 text-xs`,children:[(0,R.jsx)(`span`,{className:`font-medium`,children:`Display name`}),(0,R.jsx)(`input`,{value:w.name,onChange:e=>E(t=>({...t,name:e.target.value})),placeholder:`ABC`,className:`h-9 w-full rounded border border-border bg-card px-2`})]}),(0,R.jsxs)(`label`,{className:`space-y-1 text-xs`,children:[(0,R.jsx)(`span`,{className:`font-medium`,children:`Role id (optional)`}),(0,R.jsx)(`input`,{value:w.role,onChange:e=>E(t=>({...t,role:e.target.value})),placeholder:`abc (generated from name)`,className:`h-9 w-full rounded border border-border bg-card px-2 font-mono`})]})]}),(0,R.jsxs)(`label`,{className:`block space-y-1 text-xs`,children:[(0,R.jsx)(`span`,{className:`font-medium`,children:`Purpose`}),(0,R.jsx)(`textarea`,{value:w.purpose,onChange:e=>E(t=>({...t,purpose:e.target.value})),placeholder:`Own X, Y and Z workflows for this project and verify their results.`,className:`h-24 w-full resize-y rounded border border-border bg-card p-2`})]}),(0,R.jsxs)(`label`,{className:`block space-y-1 text-xs`,children:[(0,R.jsx)(`span`,{className:`font-medium`,children:`Task types (comma or one per line)`}),(0,R.jsx)(`textarea`,{value:w.taskTypes,onChange:e=>E(t=>({...t,taskTypes:e.target.value})),placeholder:`X workflow
10
10
  Y analysis
11
- Z verification`,className:`h-24 w-full resize-y rounded border border-border bg-card p-2`})]}),y&&(0,R.jsx)(`p`,{className:`text-xs text-destructive`,children:y}),(0,R.jsxs)(`div`,{className:`flex gap-2`,children:[(0,R.jsx)(`button`,{type:`button`,onClick:V,disabled:_||!T.name.trim()||T.purpose.trim().length<10||!T.taskTypes.trim(),className:`rounded bg-primary px-3 py-1.5 text-xs text-primary-foreground disabled:opacity-50`,children:_?`Creating…`:`Clone Agent`}),(0,R.jsx)(`button`,{type:`button`,onClick:()=>C(!1),className:`rounded border border-border px-3 py-1.5 text-xs hover:bg-accent`,children:`Cancel`})]})]}),!S&&!s&&(0,R.jsx)(`div`,{className:`flex items-center justify-center h-full text-muted-foreground`,children:`Select an agent to edit customizations`}),!S&&s&&D&&(0,R.jsxs)(`div`,{className:`space-y-4 max-w-2xl`,children:[(0,R.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,R.jsx)(`h3`,{className:`text-base font-semibold`,children:s}),(0,R.jsxs)(`div`,{className:`flex gap-1`,children:[(0,R.jsxs)(`button`,{type:`button`,onClick:z,className:`inline-flex items-center gap-1 rounded border border-border/50 px-2 py-1 text-[10px] hover:bg-accent transition-colors`,children:[(0,R.jsx)(a,{className:`h-3 w-3 text-brand-2`}),` LLM Improve`]}),(0,R.jsxs)(`button`,{type:`button`,onClick:()=>B(s),className:`inline-flex items-center gap-1 rounded border border-destructive/30 px-2 py-1 text-[10px] text-destructive hover:bg-destructive/10 transition-colors`,children:[(0,R.jsx)(r,{className:`h-3 w-3`}),` Reset`]})]})]}),(0,R.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[D.hasIdentity&&(0,R.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded bg-primary/10 px-2 py-1 text-[10px] text-primary`,children:[(0,R.jsx)(i,{className:`h-3 w-3`}),` identity.md`]}),D.hasConfig&&(0,R.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded bg-muted px-2 py-1 text-[10px] text-muted-foreground`,children:[(0,R.jsx)(w,{className:`h-3 w-3`}),` config.json`]}),D.hasKnowledge&&(0,R.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded bg-muted px-2 py-1 text-[10px] text-muted-foreground`,children:[(0,R.jsx)(b,{className:`h-3 w-3`}),` knowledge.json`]}),D.entryCount>0&&(0,R.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded bg-brand-2/10 px-2 py-1 text-[10px] text-brand-2`,children:[(0,R.jsx)(f,{className:`h-3 w-3`}),` `,D.entryCount,` learned entries`]})]}),(0,R.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,R.jsxs)(`button`,{type:`button`,onClick:()=>M(s,`identity`),className:`inline-flex items-center gap-1 rounded border border-border/50 px-3 py-1.5 text-xs hover:bg-accent transition-colors`,children:[(0,R.jsx)(i,{className:`h-3.5 w-3.5`}),` Edit identity.md`]}),(0,R.jsxs)(`button`,{type:`button`,onClick:()=>M(s,`learned`),className:`inline-flex items-center gap-1 rounded border border-border/50 px-3 py-1.5 text-xs hover:bg-accent transition-colors`,children:[(0,R.jsx)(f,{className:`h-3.5 w-3.5`}),` Edit learned.md`]}),(0,R.jsxs)(`button`,{type:`button`,onClick:()=>N(s),className:`inline-flex items-center gap-1 rounded border border-primary/40 bg-primary/5 px-3 py-1.5 text-xs text-primary hover:bg-primary/10 transition-colors`,children:[(0,R.jsx)(u,{className:`h-3.5 w-3.5`}),` Runtime policy`]}),(0,R.jsxs)(`button`,{type:`button`,onClick:()=>M(s,`config`),className:`inline-flex items-center gap-1 rounded border border-border/50 px-3 py-1.5 text-xs hover:bg-accent transition-colors`,children:[(0,R.jsx)(w,{className:`h-3.5 w-3.5`}),` Edit config.json`]})]}),y&&(0,R.jsx)(`p`,{className:`text-xs text-destructive`,children:y}),h&&(0,R.jsx)(G,{initialConfig:h,systemProtected:j,saving:_,onSave:P,onCancel:()=>g(null)},s),l&&(0,R.jsxs)(`div`,{className:`space-y-2`,children:[(0,R.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,R.jsxs)(`span`,{className:`text-xs font-medium`,children:[l,`.md / `,l,`.json`]}),(0,R.jsxs)(`div`,{className:`flex gap-1`,children:[(0,R.jsx)(`button`,{type:`button`,onClick:F,disabled:_,className:`inline-flex items-center gap-1 rounded bg-primary px-3 py-1.5 text-xs text-primary-foreground hover:bg-primary/90 transition-colors disabled:opacity-50`,children:_?`Saving…`:`Save`}),(0,R.jsx)(`button`,{type:`button`,onClick:()=>d(null),className:`inline-flex items-center gap-1 rounded border border-border/50 px-3 py-1.5 text-xs hover:bg-accent transition-colors`,children:`Cancel`})]})]}),(0,R.jsx)(`textarea`,{className:`w-full h-48 font-mono text-xs p-2 bg-card border border-border rounded resize-y`,value:p,onChange:e=>m(e.target.value),placeholder:l===`config`?`{ "tools": [...], "budget": {...} }`:`# Project identity for ${s}\n\nDescribe this agent's role…`})]})]})]})]})}function ae({className:e}){let[t,n]=(0,L.useState)(`live`),[r,i]=(0,L.useState)(Date.now()),{customStats:a,catalog:o,rosterLoading:s,rosterError:c,loadRoster:l}=re();return(0,L.useEffect)(()=>{let e=setInterval(()=>{document.hidden||i(Date.now())},2e3);return()=>clearInterval(e)},[]),(0,R.jsxs)(`div`,{className:A(`flex h-full min-h-0 min-w-0 w-full flex-col overflow-hidden`,e),children:[(0,R.jsx)(J,{customStats:a,rosterLoading:s,onRefresh:l}),(0,R.jsx)(Y,{activeTab:t,onTabChange:n}),(0,R.jsxs)(`div`,{className:`flex min-h-0 min-w-0 w-full flex-1 overflow-hidden bg-background/50`,children:[c&&(0,R.jsxs)(`div`,{className:`flex items-center justify-center w-full text-destructive text-xs gap-2`,children:[(0,R.jsx)(g,{className:`h-4 w-4`}),c,(0,R.jsx)(`button`,{type:`button`,onClick:l,className:`underline`,children:`Retry`})]}),t===`live`&&(0,R.jsx)(te,{nowTick:r}),t===`catalog`&&(0,R.jsx)(ee,{customStats:a,catalog:o}),t===`learning`&&(0,R.jsx)(X,{customStats:a,onRefresh:l}),t===`customize`&&(0,R.jsx)(ie,{customStats:a,catalog:o,onRefresh:l})]})]})}export{ae as AgentRosterView};
11
+ Z verification`,className:`h-24 w-full resize-y rounded border border-border bg-card p-2`})]}),y&&(0,R.jsx)(`p`,{className:`text-xs text-destructive`,children:y}),(0,R.jsxs)(`div`,{className:`flex gap-2`,children:[(0,R.jsx)(`button`,{type:`button`,onClick:V,disabled:_||!w.name.trim()||w.purpose.trim().length<10||!w.taskTypes.trim(),className:`rounded bg-primary px-3 py-1.5 text-xs text-primary-foreground disabled:opacity-50`,children:_?`Creating…`:`Clone Agent`}),(0,R.jsx)(`button`,{type:`button`,onClick:()=>C(!1),className:`rounded border border-border px-3 py-1.5 text-xs hover:bg-accent`,children:`Cancel`})]})]}),!S&&!s&&(0,R.jsx)(`div`,{className:`flex items-center justify-center h-full text-muted-foreground`,children:`Select an agent to edit customizations`}),!S&&s&&D&&(0,R.jsxs)(`div`,{className:`space-y-4 max-w-2xl`,children:[(0,R.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,R.jsx)(`h3`,{className:`text-base font-semibold`,children:s}),(0,R.jsxs)(`div`,{className:`flex gap-1`,children:[(0,R.jsxs)(`button`,{type:`button`,onClick:z,className:`inline-flex items-center gap-1 rounded border border-border/50 px-2 py-1 text-[10px] hover:bg-accent transition-colors`,children:[(0,R.jsx)(a,{className:`h-3 w-3 text-brand-2`}),` LLM Improve`]}),(0,R.jsxs)(`button`,{type:`button`,onClick:()=>B(s),className:`inline-flex items-center gap-1 rounded border border-destructive/30 px-2 py-1 text-[10px] text-destructive hover:bg-destructive/10 transition-colors`,children:[(0,R.jsx)(r,{className:`h-3 w-3`}),` Reset`]})]})]}),(0,R.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[D.hasIdentity&&(0,R.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded bg-primary/10 px-2 py-1 text-[10px] text-primary`,children:[(0,R.jsx)(i,{className:`h-3 w-3`}),` identity.md`]}),D.hasConfig&&(0,R.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded bg-muted px-2 py-1 text-[10px] text-muted-foreground`,children:[(0,R.jsx)(T,{className:`h-3 w-3`}),` config.json`]}),D.hasKnowledge&&(0,R.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded bg-muted px-2 py-1 text-[10px] text-muted-foreground`,children:[(0,R.jsx)(x,{className:`h-3 w-3`}),` knowledge.json`]}),D.entryCount>0&&(0,R.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded bg-brand-2/10 px-2 py-1 text-[10px] text-brand-2`,children:[(0,R.jsx)(d,{className:`h-3 w-3`}),` `,D.entryCount,` learned entries`]})]}),(0,R.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,R.jsxs)(`button`,{type:`button`,onClick:()=>M(s,`identity`),className:`inline-flex items-center gap-1 rounded border border-border/50 px-3 py-1.5 text-xs hover:bg-accent transition-colors`,children:[(0,R.jsx)(i,{className:`h-3.5 w-3.5`}),` Edit identity.md`]}),(0,R.jsxs)(`button`,{type:`button`,onClick:()=>M(s,`learned`),className:`inline-flex items-center gap-1 rounded border border-border/50 px-3 py-1.5 text-xs hover:bg-accent transition-colors`,children:[(0,R.jsx)(d,{className:`h-3.5 w-3.5`}),` Edit learned.md`]}),(0,R.jsxs)(`button`,{type:`button`,onClick:()=>N(s),className:`inline-flex items-center gap-1 rounded border border-primary/40 bg-primary/5 px-3 py-1.5 text-xs text-primary hover:bg-primary/10 transition-colors`,children:[(0,R.jsx)(u,{className:`h-3.5 w-3.5`}),` Runtime policy`]}),(0,R.jsxs)(`button`,{type:`button`,onClick:()=>M(s,`config`),className:`inline-flex items-center gap-1 rounded border border-border/50 px-3 py-1.5 text-xs hover:bg-accent transition-colors`,children:[(0,R.jsx)(T,{className:`h-3.5 w-3.5`}),` Edit config.json`]})]}),y&&(0,R.jsx)(`p`,{className:`text-xs text-destructive`,children:y}),h&&(0,R.jsx)(G,{initialConfig:h,systemProtected:j,saving:_,onSave:P,onCancel:()=>g(null)},s),l&&(0,R.jsxs)(`div`,{className:`space-y-2`,children:[(0,R.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,R.jsxs)(`span`,{className:`text-xs font-medium`,children:[l,`.md / `,l,`.json`]}),(0,R.jsxs)(`div`,{className:`flex gap-1`,children:[(0,R.jsx)(`button`,{type:`button`,onClick:F,disabled:_,className:`inline-flex items-center gap-1 rounded bg-primary px-3 py-1.5 text-xs text-primary-foreground hover:bg-primary/90 transition-colors disabled:opacity-50`,children:_?`Saving…`:`Save`}),(0,R.jsx)(`button`,{type:`button`,onClick:()=>f(null),className:`inline-flex items-center gap-1 rounded border border-border/50 px-3 py-1.5 text-xs hover:bg-accent transition-colors`,children:`Cancel`})]})]}),(0,R.jsx)(`textarea`,{className:`w-full h-48 font-mono text-xs p-2 bg-card border border-border rounded resize-y`,value:p,onChange:e=>m(e.target.value),placeholder:l===`config`?`{ "tools": [...], "budget": {...} }`:`# Project identity for ${s}\n\nDescribe this agent's role…`})]})]})]})]})}function ae({className:e}){let[t,n]=(0,L.useState)(`live`),[r,i]=(0,L.useState)(Date.now()),{customStats:a,catalog:o,rosterLoading:s,rosterError:c,loadRoster:l}=re();return(0,L.useEffect)(()=>{let e=setInterval(()=>{document.hidden||i(Date.now())},2e3);return()=>clearInterval(e)},[]),(0,R.jsxs)(`div`,{className:A(`flex h-full min-h-0 min-w-0 w-full flex-col overflow-hidden`,e),children:[(0,R.jsx)(J,{customStats:a,rosterLoading:s,onRefresh:l}),(0,R.jsx)(Y,{activeTab:t,onTabChange:n}),(0,R.jsxs)(`div`,{className:`flex min-h-0 min-w-0 w-full flex-1 overflow-hidden bg-background/50`,children:[c&&(0,R.jsxs)(`div`,{className:`flex items-center justify-center w-full text-destructive text-xs gap-2`,children:[(0,R.jsx)(_,{className:`h-4 w-4`}),c,(0,R.jsx)(`button`,{type:`button`,onClick:l,className:`underline`,children:`Retry`})]}),t===`live`&&(0,R.jsx)(te,{nowTick:r}),t===`catalog`&&(0,R.jsx)(ee,{customStats:a,catalog:o}),t===`learning`&&(0,R.jsx)(X,{customStats:a,onRefresh:l}),t===`customize`&&(0,R.jsx)(ie,{customStats:a,catalog:o,onRefresh:l})]})]})}export{ae as AgentRosterView};
@@ -0,0 +1 @@
1
+ import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{Fn as t,Kn as n,Sa as r,Tt as i,Vi as a,_a as o,bt as s,et as c,ft as l,ma as u,oi as d,ri as f,xt as p}from"./vendor-2VBBgNb5.js";import"./i18n-1BkaqMgr.js";import{t as m}from"./ws-client-WVGn8ORh.js";import{M as h}from"./stores-mpa0202y.js";import{b as g,f as _,p as v}from"./index-BPfIz78e.js";var y=e(r(),1),b=c();function x(e){let t=Math.floor(e/1e3);if(t<60)return`${t}s`;let n=Math.floor(t/60);if(n<60)return`${n}m ${t%60}s`;let r=Math.floor(n/60);return r<24?`${r}h ${n%60}m`:`${Math.floor(r/24)}d`}function S(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}K`:String(e)}function C(e){return e<.01?`$${e.toFixed(4)}`:`$${e.toFixed(2)}`}function w(e){return new Date(e).toLocaleTimeString(void 0,{hour:`2-digit`,minute:`2-digit`,second:`2-digit`})}function T(e){return e.includes(`error`)||e.includes(`fail`)?`text-destructive`:e.includes(`warn`)?`text-warning`:e.includes(`success`)||e.includes(`complete`)?`text-success`:`text-muted-foreground`}function E({icon:e,label:t,value:n,sub:r,color:i=`text-muted-foreground`}){return(0,b.jsxs)(`div`,{className:`flex items-start gap-3 rounded-xl border border-border/70 bg-card/75 p-4 shadow-sm`,children:[(0,b.jsx)(`div`,{className:`mt-0.5 ${i}`,children:e}),(0,b.jsxs)(`div`,{className:`min-w-0`,children:[(0,b.jsx)(`div`,{className:`text-2xl font-semibold tabular-nums text-foreground`,children:n}),(0,b.jsx)(`div`,{className:`mt-0.5 text-xs text-muted-foreground`,children:t}),r?(0,b.jsx)(`div`,{className:`mt-1 text-xs text-muted-foreground/70`,children:r}):null]})]})}function D(){let{t:e}=o(),[r,c]=(0,y.useState)(null),[D,O]=(0,y.useState)([]),[k,A]=(0,y.useState)([]),[j,M]=(0,y.useState)(null),[N,P]=(0,y.useState)(!0),[F,I]=(0,y.useState)(!1),L=(0,y.useRef)(null),R=(0,y.useCallback)(async()=>{try{let e=await fetch(`/api/analytics/summary`);if(e.ok){let t=await e.json();c(t)}}catch{}},[]),z=(0,y.useCallback)(async()=>{try{let e=await fetch(`/api/analytics?limit=50`);if(e.ok){let t=await e.json();O(t.events)}}catch{}},[]),B=(0,y.useCallback)(async()=>{try{let e=await fetch(`/api/sessions`);if(e.ok){let t=await e.json();A(t)}}catch{}},[]),V=(0,y.useCallback)(async()=>{if(F)return;I(!0);let e=null,t=null;try{let n=m(h.getState().wsUrl);L.current=n,t=n.on(`stats.get`,n=>{let r=n.payload;M(r),I(!1),t?.(),e!==null&&clearTimeout(e)}),n.getStats({echoToChat:!1}),e=setTimeout(()=>{t?.(),I(!1)},8e3)}catch{t?.(),e!==null&&clearTimeout(e),I(!1)}},[F]);(0,y.useEffect)(()=>{let e=()=>{Promise.all([R(),z(),B(),V()]).finally(()=>P(!1))};e();let t=setInterval(e,1e4);return()=>clearInterval(t)},[R,z,B,V]);let{totalAgents:H,activeAgents:U,totalToolCalls:W,totalIterations:G}=(0,y.useMemo)(()=>{let e=0,t=0,n=0,r=0;for(let i of k)for(let a of i.agents)e++,a.status===`running`&&t++,n+=a.toolCalls,r+=a.iterations;return{totalAgents:e,activeAgents:t,totalToolCalls:n,totalIterations:r}},[k]),K=(0,y.useMemo)(()=>r?Object.entries(r.categoryBreakdown).sort((e,t)=>t[1]-e[1]).slice(0,8):[],[r]),q=(0,y.useMemo)(()=>r?Object.entries(r.eventBreakdown).sort((e,t)=>t[1]-e[1]).slice(0,10):[],[r]),J=(0,y.useMemo)(()=>{if(!r)return 0;let e=0;for(let[t,n]of Object.entries(r.eventBreakdown))t.toLowerCase().includes(`error`)&&(e+=n);return e},[r]),Y=(0,y.useMemo)(()=>{if(!r)return 0;let e=0;for(let[t,n]of Object.entries(r.eventBreakdown))t.toLowerCase().includes(`warn`)&&(e+=n);return e},[r]),X=v((0,y.useMemo)(()=>[...D].reverse(),[D]),20);return N?(0,b.jsx)(`div`,{className:`flex h-full min-h-0 items-center justify-center bg-[hsl(var(--surface-2)/0.45)] p-4`,children:(0,b.jsxs)(`div`,{className:`ws-surface flex items-center gap-2 rounded-xl px-4 py-3 text-sm text-muted-foreground`,children:[(0,b.jsx)(n,{className:`h-4 w-4 animate-spin text-primary`}),e(`activity:analytics.loading`)]})}):(0,b.jsx)(`div`,{ref:g(`analytics`),className:`h-full min-h-0 min-w-0 overflow-y-auto overscroll-contain bg-[hsl(var(--surface-2)/0.45)] p-4 sm:p-6`,children:(0,b.jsxs)(`div`,{className:`mx-auto flex w-full max-w-7xl flex-col gap-5`,children:[(0,b.jsx)(`div`,{className:`rounded-xl border border-border/70 bg-card/75 p-4 shadow-sm`,children:(0,b.jsxs)(`div`,{className:`flex flex-col gap-2 sm:flex-row sm:items-center sm:justify-between`,children:[(0,b.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,b.jsx)(a,{className:`h-4 w-4 text-primary`}),(0,b.jsx)(`h1`,{className:`truncate text-base font-semibold`,children:e(`activity:analytics.heading`)})]}),(0,b.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:e(`activity:analytics.autoRefresh`)})]})}),(0,b.jsxs)(`div`,{className:`min-w-0 space-y-5`,children:[(0,b.jsxs)(`div`,{className:`grid grid-cols-2 md:grid-cols-3 lg:grid-cols-6 gap-3`,children:[(0,b.jsx)(E,{icon:(0,b.jsx)(u,{className:`h-4 w-4`}),label:e(`activity:analytics.liveSessions`),value:k.length,color:`text-primary`}),(0,b.jsx)(E,{icon:(0,b.jsx)(l,{className:`h-4 w-4`}),label:e(`activity:analytics.agents`),value:`${U}/${H}`,sub:U>0?e(`activity:analytics.agentsActive`,{count:U}):void 0,color:`text-success`}),(0,b.jsx)(E,{icon:(0,b.jsx)(t,{className:`h-4 w-4`}),label:e(`activity:analytics.totalEvents`),value:r?.totalEvents??0,sub:e(`activity:analytics.categoriesSub`,{count:r?.uniqueCategories??0}),color:`text-warning`}),(0,b.jsx)(E,{icon:(0,b.jsx)(i,{className:`h-4 w-4`}),label:e(`activity:analytics.toolCalls`),value:W,sub:e(`activity:analytics.iterationsSub`,{count:G}),color:`text-success`}),(0,b.jsx)(E,{icon:(0,b.jsx)(f,{className:`h-4 w-4`}),label:e(`activity:analytics.sessionCost`),value:j?C(j.cost):`—`,sub:j?e(`activity:analytics.tokensSub`,{input:S(j.usage.input),output:S(j.usage.output)}):void 0,color:`text-primary`}),(0,b.jsx)(E,{icon:(0,b.jsx)(d,{className:`h-4 w-4`}),label:e(`activity:analytics.sessionDuration`),value:j?x(j.elapsedMs):`—`,sub:j?e(`activity:analytics.messagesSub`,{count:j.messages}):void 0,color:`text-muted-foreground`})]}),(0,b.jsxs)(`div`,{className:`grid grid-cols-1 lg:grid-cols-2 gap-4`,children:[(0,b.jsxs)(`div`,{className:`rounded-xl border border-border/70 bg-card/75 p-4 shadow-sm`,children:[(0,b.jsxs)(`h3`,{className:`mb-3 flex items-center gap-2 text-xs font-semibold uppercase text-muted-foreground`,children:[(0,b.jsx)(p,{className:`h-3.5 w-3.5 text-primary`}),e(`activity:analytics.eventsByCategory`)]}),K.length===0?(0,b.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e(`activity:analytics.noEvents`)}):(0,b.jsx)(`div`,{className:`space-y-1.5`,children:K.map(([e,t])=>{let n=K[0]?.[1]??1,r=Math.round(t/n*100);return(0,b.jsxs)(`div`,{className:`grid grid-cols-[minmax(0,7rem)_minmax(0,1fr)_2.5rem] items-center gap-2 text-xs`,children:[(0,b.jsx)(`span`,{className:`min-w-0 truncate text-foreground`,children:e}),(0,b.jsx)(`div`,{className:`h-4 overflow-hidden rounded-full bg-muted`,children:(0,b.jsx)(`div`,{className:`h-full rounded-full bg-primary/70 transition-all`,style:{width:`${Math.max(r,4)}%`}})}),(0,b.jsx)(`span`,{className:`text-right tabular-nums text-muted-foreground`,children:t})]},e)})})]}),(0,b.jsxs)(`div`,{className:`rounded-xl border border-border/70 bg-card/75 p-4 shadow-sm`,children:[(0,b.jsxs)(`h3`,{className:`mb-3 flex items-center gap-2 text-xs font-semibold uppercase text-muted-foreground`,children:[(0,b.jsx)(a,{className:`h-3.5 w-3.5 text-warning`}),e(`activity:analytics.topEvents`)]}),q.length===0?(0,b.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e(`activity:analytics.noEvents`)}):(0,b.jsx)(`div`,{className:`space-y-1.5`,children:q.map(([e,t])=>{let n=q[0]?.[1]??1,r=Math.round(t/n*100);return(0,b.jsxs)(`div`,{className:`grid grid-cols-[minmax(0,9rem)_minmax(0,1fr)_2.5rem] items-center gap-2 text-xs`,children:[(0,b.jsx)(`span`,{className:`min-w-0 truncate ${T(e)}`,children:e}),(0,b.jsx)(`div`,{className:`h-4 overflow-hidden rounded-full bg-muted`,children:(0,b.jsx)(`div`,{className:`h-full rounded-full bg-warning/70 transition-all`,style:{width:`${Math.max(r,4)}%`}})}),(0,b.jsx)(`span`,{className:`text-right tabular-nums text-muted-foreground`,children:t})]},e)})})]})]}),(0,b.jsxs)(`div`,{className:`grid grid-cols-1 lg:grid-cols-2 gap-4`,children:[(0,b.jsxs)(`div`,{className:`rounded-xl border border-border/70 bg-card/75 p-4 shadow-sm`,children:[(0,b.jsxs)(`h3`,{className:`mb-3 flex items-center gap-2 text-xs font-semibold uppercase text-muted-foreground`,children:[(0,b.jsx)(f,{className:`h-3.5 w-3.5 text-primary`}),e(`activity:analytics.activeSessionUsage`)]}),j?(0,b.jsxs)(`div`,{className:`grid grid-cols-2 gap-3 text-xs`,children:[(0,b.jsxs)(`div`,{className:`min-w-0 rounded-lg border border-border/70 bg-background/50 px-3 py-2`,children:[(0,b.jsx)(`span`,{className:`text-muted-foreground`,children:e(`activity:analytics.provider`)}),(0,b.jsx)(`p`,{className:`mt-0.5 truncate font-mono text-foreground`,children:j.provider})]}),(0,b.jsxs)(`div`,{className:`min-w-0 rounded-lg border border-border/70 bg-background/50 px-3 py-2`,children:[(0,b.jsx)(`span`,{className:`text-muted-foreground`,children:e(`activity:analytics.model`)}),(0,b.jsx)(`p`,{className:`mt-0.5 truncate font-mono text-foreground`,children:j.model})]}),(0,b.jsxs)(`div`,{className:`rounded-lg border border-border/70 bg-background/50 px-3 py-2`,children:[(0,b.jsx)(`span`,{className:`text-muted-foreground`,children:e(`activity:analytics.inputTokens`)}),(0,b.jsx)(`p`,{className:`mt-0.5 tabular-nums text-foreground`,children:S(j.usage.input)})]}),(0,b.jsxs)(`div`,{className:`rounded-lg border border-border/70 bg-background/50 px-3 py-2`,children:[(0,b.jsx)(`span`,{className:`text-muted-foreground`,children:e(`activity:analytics.outputTokens`)}),(0,b.jsx)(`p`,{className:`mt-0.5 tabular-nums text-foreground`,children:S(j.usage.output)})]}),(0,b.jsxs)(`div`,{className:`rounded-lg border border-border/70 bg-background/50 px-3 py-2`,children:[(0,b.jsx)(`span`,{className:`text-muted-foreground`,children:e(`activity:analytics.cacheRatio`)}),(0,b.jsxs)(`p`,{className:`mt-0.5 tabular-nums text-foreground`,children:[(j.cache.ratio*100).toFixed(1),`%`]})]}),(0,b.jsxs)(`div`,{className:`rounded-lg border border-border/70 bg-background/50 px-3 py-2`,children:[(0,b.jsx)(`span`,{className:`text-muted-foreground`,children:e(`activity:analytics.filesRead`)}),(0,b.jsx)(`p`,{className:`mt-0.5 tabular-nums text-foreground`,children:j.readFiles})]})]}):(0,b.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e(`activity:analytics.noSession`)})]}),(0,b.jsxs)(`div`,{className:`rounded-xl border border-border/70 bg-card/75 p-4 shadow-sm`,children:[(0,b.jsxs)(`h3`,{className:`mb-3 flex items-center gap-2 text-xs font-semibold uppercase text-muted-foreground`,children:[(0,b.jsx)(s,{className:`h-3.5 w-3.5 text-warning`}),e(`activity:analytics.healthErrors`)]}),(0,b.jsx)(`div`,{className:`space-y-2 text-xs`,children:r?(0,b.jsxs)(b.Fragment,{children:[(0,b.jsxs)(`div`,{className:`flex justify-between`,children:[(0,b.jsx)(`span`,{className:`text-muted-foreground`,children:e(`activity:analytics.errorEvents`)}),(0,b.jsx)(`span`,{className:`tabular-nums text-destructive`,children:J})]}),(0,b.jsxs)(`div`,{className:`flex justify-between`,children:[(0,b.jsx)(`span`,{className:`text-muted-foreground`,children:e(`activity:analytics.warningEvents`)}),(0,b.jsx)(`span`,{className:`tabular-nums text-warning`,children:Y})]}),(0,b.jsxs)(`div`,{className:`flex justify-between`,children:[(0,b.jsx)(`span`,{className:`text-muted-foreground`,children:e(`activity:analytics.cacheHitRate`)}),(0,b.jsx)(`span`,{className:`tabular-nums text-success`,children:j?`${(j.cache.ratio*100).toFixed(1)}%`:`—`})]}),(0,b.jsxs)(`div`,{className:`flex justify-between`,children:[(0,b.jsx)(`span`,{className:`text-muted-foreground`,children:e(`activity:analytics.totalCategories`)}),(0,b.jsx)(`span`,{className:`tabular-nums text-foreground`,children:r.uniqueCategories})]})]}):(0,b.jsx)(`p`,{className:`text-muted-foreground`,children:e(`activity:analytics.waitingData`)})})]})]}),(0,b.jsxs)(`div`,{className:`rounded-xl border border-border/70 bg-card/75 p-4 shadow-sm`,children:[(0,b.jsxs)(`h3`,{className:`mb-3 flex items-center gap-2 text-xs font-semibold uppercase text-muted-foreground`,children:[(0,b.jsx)(u,{className:`h-3.5 w-3.5 text-primary`}),e(`activity:analytics.recentEvents`)]}),D.length===0?(0,b.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e(`activity:analytics.noRecentEvents`)}):(0,b.jsx)(`div`,{className:`max-h-64 space-y-1 overflow-y-auto`,children:X.pageItems.map((e,t)=>(0,b.jsxs)(`div`,{className:`grid grid-cols-[4rem_minmax(0,7rem)_minmax(0,6rem)_minmax(0,1fr)] items-start gap-2 rounded px-2 py-1 text-xs hover:bg-muted/60`,children:[(0,b.jsx)(`span`,{className:`tabular-nums text-muted-foreground/70`,children:w(e.timestamp)}),(0,b.jsx)(`span`,{className:`min-w-0 truncate ${T(e.event)}`,children:e.event}),(0,b.jsx)(`span`,{className:`min-w-0 truncate text-muted-foreground`,children:e.category}),(0,b.jsx)(`span`,{className:`min-w-0 truncate text-foreground/80`,children:e.label??e.sessionId??``})]},`${e.timestamp}-${t}`))}),(0,b.jsx)(_,{page:X.page,pageSize:X.pageSize,totalItems:X.totalItems,onPageChange:X.setPage,compact:!0,itemLabel:`events`,className:`mt-3 rounded-lg border`})]})]})]})})}export{D as AnalyticsDashboard};
@@ -1,3 +1,3 @@
1
- import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{Ct as t,Dt as n,Ht as r,Zt as i,at as a,cn as o,et as s,ni as c,pn as l,vt as u,wr as d,xa as f}from"./vendor-9hC4n4Me.js";import{t as p}from"./useWebSocket-DAm5zYOB.js";import{t as m}from"./utils-DzRQUvln.js";import{a as h,i as g,n as _,o as v,r as y,t as b}from"./dialog-BLr7olIX.js";import{t as x}from"./button-Bmh1yFe5.js";import{t as S}from"./input-BRS2rHSR.js";import{f as C,p as w}from"./index-WvJRbCoi.js";import{g as T,i as E,r as D,y as O}from"./shared-DYL4K3aB.js";var k=e(f(),1),A=s();function j(e){if(!Array.isArray(e))return;let t=[...new Set(e.filter(e=>typeof e==`string`).map(e=>e.trim()).filter(Boolean))];return t.length>0?t:void 0}function M(e){if(!e||typeof e!=`object`||Array.isArray(e))return;let t=e,n={roles:j(t.roles),taskTypes:j(t.taskTypes),modes:j(t.modes)};return n.roles||n.taskTypes||n.modes?n:void 0}function N(e){let t=e.trim().replace(/^```(?:json)?\s*/i,``).replace(/\s*```$/,``),n=JSON.parse(t);if(!Array.isArray(n))throw Error(`Input must be a JSON array.`);let r=[],i=0;for(let e of n){if(!e||typeof e!=`object`||Array.isArray(e)){i++;continue}let t=e,n=typeof t.text==`string`?t.text.trim():``,a=M(t.audience);if(!n||!a){i++;continue}let o=typeof t.kind==`string`&&E.some(e=>e===t.kind)?t.kind:void 0,s=j(t.tags);r.push({text:n,audience:a,kind:o,tags:s,importance:typeof t.importance==`number`?t.importance:void 0,confidence:typeof t.confidence==`number`?t.confidence:void 0})}return{entries:r,skipped:i}}function P(e,t){if(!t)return!0;let n=e.audience;return[e.text,e.kind,e.status,...n?.roles??[],...n?.taskTypes??[],...n?.modes??[]].join(` `).toLocaleLowerCase().includes(t.toLocaleLowerCase())}function F(e,t){return[...new Set(e.flatMap(e=>e.audience?.[t]??[]).filter(e=>e.length>0))].sort((e,t)=>e.localeCompare(t))}function I(){let e=p(),[r,s]=(0,k.useState)([]),[f,E]=(0,k.useState)(!0),[D,O]=(0,k.useState)(null),[j,M]=(0,k.useState)(``),[I,z]=(0,k.useState)(!1),[B,V]=(0,k.useState)(!1),[H,U]=(0,k.useState)(null),[W,G]=(0,k.useState)(!1),[K,q]=(0,k.useState)(!1),J=(0,k.useRef)(null),Y=(0,k.useCallback)(()=>{E(!0),O(null),e.listSageMemories({echoToChat:!1})},[e.listSageMemories]);(0,k.useEffect)(()=>{let t=e.client,n=t.on(`memory.sage.list`,e=>{let t=e.payload;t.error?O({tone:`error`,text:t.error}):s(t.memories??[]),E(!1)}),r=t.on(`memory.sage.remember`,e=>{let t=e.payload;if(G(!1),t.error){O({tone:`error`,text:t.error});return}t.memory&&(s(e=>[t.memory,...e.filter(e=>e.id!==t.memory.id)]),z(!1))}),i=t.on(`memory.sage.update`,e=>{let t=e.payload;t.error?O({tone:`error`,text:t.error}):t.memory&&(s(e=>e.map(e=>e.id===t.memory.id?t.memory:e)),t.memory.audience||O({tone:`success`,text:`Audience scope removed. The memory is now general.`}))}),a=t.on(`memory.sage.delete`,e=>{let t=e.payload,n=J.current;t.success&&n?(s(e=>e.filter(e=>e.id!==n)),O({tone:`success`,text:`Audience memory deleted.`}),U(null),q(!1),J.current=null):t.success?Y():(O({tone:`error`,text:t.message??`Could not delete the memory.`}),q(!1),J.current=null)});return Y(),()=>{n(),r(),i(),a()}},[Y,e.client]);let X=(0,k.useMemo)(()=>r.filter(e=>{let t=e.audience;return!!(t&&(t.roles?.length||t.taskTypes?.length||t.modes?.length))}),[r]),Z=j.trim(),Q=(0,k.useMemo)(()=>X.filter(e=>P(e,Z)),[Z,X]),$=w(Q,16,Z),ie=(0,k.useMemo)(()=>F(X,`roles`),[X]),ae=(0,k.useMemo)(()=>F(X,`taskTypes`),[X]),oe=(0,k.useMemo)(()=>F(X,`modes`),[X]),se=t=>{O(null),e.updateSage(t,{audience:void 0},{echoToChat:!1})},ce=()=>{H&&(J.current=H,q(!0),O(null),e.deleteSage(H,`Removed from the audience memory panel.`))},le=async()=>{let e=X.map(e=>({id:e.id,text:e.text,kind:e.kind,status:e.status,audience:e.audience,tags:e.tags,importance:e.importance,confidence:e.confidence}));try{if(!navigator.clipboard)throw Error(`Clipboard access is unavailable.`);await navigator.clipboard.writeText(JSON.stringify(e,null,2)),O({tone:`success`,text:`${e.length} audience memor${e.length===1?`y`:`ies`} copied as JSON.`})}catch(e){O({tone:`error`,text:e instanceof Error?e.message:`Failed to copy JSON to the clipboard.`})}};return(0,A.jsxs)(A.Fragment,{children:[(0,A.jsxs)(`section`,{className:`flex h-full min-h-0 flex-col bg-card/20`,"aria-labelledby":`audience-memory-title`,children:[(0,A.jsxs)(`div`,{className:`shrink-0 border-b border-border/60 p-3`,children:[(0,A.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,A.jsx)(`div`,{className:`min-w-0`,children:(0,A.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,A.jsx)(`span`,{className:`flex size-7 shrink-0 items-center justify-center rounded-md border border-primary/20 bg-primary/10 text-primary`,children:(0,A.jsx)(n,{className:`size-3.5`})}),(0,A.jsxs)(`div`,{className:`min-w-0`,children:[(0,A.jsx)(`h2`,{id:`audience-memory-title`,className:`truncate text-sm font-semibold`,children:`Audience Memory`}),(0,A.jsx)(`p`,{className:`truncate text-[10px] text-muted-foreground`,children:`Guidance routed to matching agents`})]})]})}),(0,A.jsxs)(x,{variant:`default`,size:`sm`,className:`h-7 shrink-0 gap-1 px-2 text-xs`,onClick:()=>z(!0),children:[(0,A.jsx)(l,{className:`size-3`}),`Add`]})]}),(0,A.jsxs)(`div`,{className:`mt-3 grid grid-cols-4 gap-px overflow-hidden rounded-md border border-border/60 bg-border/60`,children:[(0,A.jsx)(L,{value:X.length,label:`Memories`}),(0,A.jsx)(L,{value:ie.length,label:`Roles`}),(0,A.jsx)(L,{value:ae.length,label:`Tasks`}),(0,A.jsx)(L,{value:oe.length,label:`Modes`})]}),(0,A.jsxs)(`div`,{className:`mt-3 flex items-center gap-1.5`,children:[(0,A.jsxs)(`div`,{className:`relative min-w-0 flex-1`,children:[(0,A.jsx)(i,{className:`pointer-events-none absolute left-2.5 top-1/2 size-3.5 -translate-y-1/2 text-muted-foreground`}),(0,A.jsx)(S,{value:j,onChange:e=>M(e.target.value),placeholder:`Search text, role, task or mode…`,"aria-label":`Search audience memories`,className:`h-8 pl-8 pr-8 text-xs`}),j&&(0,A.jsx)(`button`,{type:`button`,className:`absolute right-2 top-1/2 -translate-y-1/2 rounded-sm p-0.5 text-muted-foreground hover:text-foreground`,onClick:()=>M(``),"aria-label":`Clear audience memory search`,children:(0,A.jsx)(a,{className:`size-3`})})]}),(0,A.jsx)(x,{variant:`ghost`,size:`icon`,className:`size-8 shrink-0`,onClick:Y,"aria-label":`Refresh audience memories`,title:`Refresh`,children:(0,A.jsx)(o,{className:m(`size-3.5`,f&&`animate-spin`)})}),(0,A.jsx)(x,{variant:`ghost`,size:`icon`,className:`size-8 shrink-0`,onClick:()=>V(!0),"aria-label":`Import audience memories`,title:`Import JSON`,children:(0,A.jsx)(u,{className:`size-3.5`})}),(0,A.jsx)(x,{variant:`ghost`,size:`icon`,className:`size-8 shrink-0`,onClick:()=>void le(),"aria-label":`Copy audience memories as JSON`,title:`Copy JSON`,disabled:X.length===0,children:(0,A.jsx)(c,{className:`size-3.5`})})]})]}),D&&(0,A.jsxs)(`div`,{role:D.tone===`error`?`alert`:`status`,className:m(`mx-3 mt-3 flex shrink-0 items-start justify-between gap-2 rounded-md border px-2.5 py-2 text-[11px]`,D.tone===`error`?`border-destructive/30 bg-destructive/5 text-destructive`:`border-success/30 bg-success/5 text-success`),children:[(0,A.jsx)(`span`,{children:D.text}),(0,A.jsx)(`button`,{type:`button`,onClick:()=>O(null),className:`shrink-0 rounded-sm opacity-70 hover:opacity-100`,"aria-label":`Dismiss message`,children:(0,A.jsx)(a,{className:`size-3`})})]}),(0,A.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col`,children:[!f&&X.length>0&&(0,A.jsxs)(`div`,{className:`flex shrink-0 items-center justify-between px-3 pb-1.5 pt-3 text-[10px] text-muted-foreground`,children:[(0,A.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,A.jsx)(d,{className:`size-3`}),Z?`${Q.length} of ${X.length}`:`${X.length} scoped`]}),Z&&(0,A.jsx)(`button`,{type:`button`,className:`hover:text-foreground`,onClick:()=>M(``),children:`Clear filter`})]}),(0,A.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-y-auto px-3`,children:[f?(0,A.jsx)(ee,{}):X.length===0?(0,A.jsx)(te,{onAdd:()=>z(!0)}):Q.length===0?(0,A.jsxs)(`div`,{className:`flex h-full min-h-32 flex-col items-center justify-center px-4 text-center`,children:[(0,A.jsx)(i,{className:`mb-2 size-5 text-muted-foreground/60`}),(0,A.jsx)(`p`,{className:`text-xs font-medium`,children:`No matching memories`}),(0,A.jsx)(`p`,{className:`mt-1 text-[10px] text-muted-foreground`,children:`Try another role, task, mode, or phrase.`}),(0,A.jsx)(x,{variant:`ghost`,size:`sm`,className:`mt-2 h-7 text-xs`,onClick:()=>M(``),children:`Clear search`})]}):(0,A.jsx)(`ul`,{className:`space-y-2`,children:$.pageItems.map(e=>(0,A.jsx)(R,{memory:e,onFilter:M,onClearScope:()=>se(e.id),onDelete:()=>U(e.id)},e.id))}),(0,A.jsx)(C,{page:$.page,pageSize:$.pageSize,totalItems:$.totalItems,onPageChange:$.setPage,compact:!0,itemLabel:`memories`})]})]})]}),(0,A.jsx)(ne,{open:I,busy:W,onOpenChange:e=>{W||z(e)},onCreate:t=>{O(null),G(!0),e.rememberSage({text:t.text,kind:t.kind,audience:{roles:t.roles.length>0?t.roles:void 0,taskTypes:t.taskTypes.length>0?t.taskTypes:void 0,modes:t.modes.length>0?t.modes:void 0}},{echoToChat:!1})}}),(0,A.jsx)(re,{open:B,onOpenChange:V,onImport:t=>{try{let{entries:n,skipped:r}=N(t);if(n.length===0)return O({tone:`error`,text:`No valid audience-scoped memories were found in the JSON.`}),!1;for(let t of n)e.rememberSage(t,{echoToChat:!1});return O({tone:`success`,text:`${n.length} memor${n.length===1?`y`:`ies`} queued for import${r?`; ${r} invalid ${r===1?`entry was`:`entries were`} skipped`:``}.`}),V(!1),!0}catch(e){return O({tone:`error`,text:e instanceof Error?e.message:`Invalid JSON.`}),!1}}}),(0,A.jsx)(b,{open:!!H,onOpenChange:e=>{!e&&!K&&U(null)},children:(0,A.jsxs)(_,{className:`max-w-md`,children:[(0,A.jsxs)(h,{children:[(0,A.jsx)(v,{children:`Delete this audience memory?`}),(0,A.jsx)(y,{children:`This removes the memory from active use. To keep it as general project guidance, cancel and use the un-scope action instead.`})]}),(0,A.jsx)(`div`,{className:`rounded-md border border-border/70 bg-background/45 p-3 text-xs text-muted-foreground`,children:T(r.find(e=>e.id===H)?.text??``,180)}),(0,A.jsxs)(g,{children:[(0,A.jsx)(x,{variant:`outline`,onClick:()=>U(null),disabled:K,children:`Cancel`}),(0,A.jsxs)(x,{variant:`destructive`,onClick:ce,disabled:K,children:[(0,A.jsx)(t,{className:`size-4`}),K?`Deleting…`:`Delete memory`]})]})]})})]})}function L({value:e,label:t}){return(0,A.jsxs)(`div`,{className:`bg-card/95 px-1.5 py-2 text-center`,children:[(0,A.jsx)(`p`,{className:`text-sm font-semibold tabular-nums`,children:e}),(0,A.jsx)(`p`,{className:`truncate text-[9px] uppercase tracking-wide text-muted-foreground`,children:t})]})}function R({memory:e,onFilter:n,onClearScope:i,onDelete:a}){return(0,A.jsxs)(`li`,{className:`group rounded-md border border-border/65 bg-card/55 p-2.5 transition-colors hover:border-border hover:bg-card/85`,children:[(0,A.jsx)(`p`,{className:`break-words text-xs leading-5`,children:e.text}),e.audience&&(0,A.jsx)(z,{audience:e.audience,onFilter:n}),(0,A.jsxs)(`div`,{className:`mt-2 flex items-center justify-between gap-2 border-t border-border/45 pt-2`,children:[(0,A.jsxs)(`div`,{className:`flex min-w-0 items-center gap-1.5 text-[9px] uppercase tracking-wide text-muted-foreground`,children:[(0,A.jsx)(`span`,{className:`truncate`,children:D[e.kind]??e.kind}),(0,A.jsx)(`span`,{"aria-hidden":`true`,children:`·`}),(0,A.jsx)(`span`,{children:e.status})]}),(0,A.jsxs)(`div`,{className:`flex shrink-0 items-center gap-0.5`,children:[(0,A.jsx)(x,{variant:`ghost`,size:`icon`,className:`size-6`,onClick:i,"aria-label":`Remove audience scope from ${T(e.text,42)}`,title:`Make general memory`,children:(0,A.jsx)(r,{className:`size-3`})}),(0,A.jsx)(x,{variant:`ghost`,size:`icon`,className:`size-6 text-destructive hover:text-destructive`,onClick:a,"aria-label":`Delete ${T(e.text,42)}`,title:`Delete`,children:(0,A.jsx)(t,{className:`size-3`})})]})]})]})}function z({audience:e,onFilter:t}){return(0,A.jsx)(`div`,{className:`mt-2 flex flex-wrap gap-1`,children:[...(e.roles??[]).map(e=>({label:`role`,value:e})),...(e.taskTypes??[]).map(e=>({label:`task`,value:e})),...(e.modes??[]).map(e=>({label:`mode`,value:e}))].map(({label:e,value:n})=>(0,A.jsxs)(`button`,{type:`button`,className:`max-w-full truncate rounded border border-primary/15 bg-primary/7 px-1.5 py-0.5 font-mono text-[9px] text-primary/90 transition-colors hover:border-primary/35 hover:bg-primary/12`,onClick:()=>t(n),title:`Filter by ${e}: ${n}`,children:[e,`:`,n]},`${e}:${n}`))})}function ee(){return(0,A.jsx)(`div`,{className:`space-y-2 pt-3`,role:`status`,"aria-label":`Loading audience memories`,children:[0,1,2].map(e=>(0,A.jsxs)(`div`,{className:`animate-pulse rounded-md border border-border/50 p-3`,children:[(0,A.jsx)(`div`,{className:`h-2.5 w-full rounded bg-muted`}),(0,A.jsx)(`div`,{className:`mt-2 h-2.5 w-2/3 rounded bg-muted`}),(0,A.jsx)(`div`,{className:`mt-3 h-4 w-24 rounded bg-muted`})]},e))})}function te({onAdd:e}){return(0,A.jsxs)(`div`,{className:`flex h-full min-h-44 flex-col items-center justify-center px-5 text-center`,children:[(0,A.jsx)(`span`,{className:`mb-3 flex size-10 items-center justify-center rounded-full border border-dashed border-primary/35 bg-primary/5 text-primary`,children:(0,A.jsx)(n,{className:`size-4`})}),(0,A.jsx)(`p`,{className:`text-xs font-medium`,children:`Route guidance to the right agents`}),(0,A.jsx)(`p`,{className:`mt-1 max-w-52 text-[10px] leading-4 text-muted-foreground`,children:`Scope a memory by role, task type, or operating mode. Matching agents receive it automatically.`}),(0,A.jsxs)(x,{variant:`outline`,size:`sm`,className:`mt-3 h-7 gap-1 text-xs`,onClick:e,children:[(0,A.jsx)(l,{className:`size-3`}),`Add scoped memory`]})]})}function ne({open:e,busy:t,onOpenChange:n,onCreate:r}){let[i,a]=(0,k.useState)(``),[o,s]=(0,k.useState)(`workflow`),[c,l]=(0,k.useState)(``),[u,d]=(0,k.useState)(``),[f,p]=(0,k.useState)(``);(0,k.useEffect)(()=>{e||(a(``),s(`workflow`),l(``),d(``),p(``))},[e]);let m=O(c),S=O(u),C=O(f),w=i.trim().length>0&&(m.length>0||S.length>0||C.length>0);return(0,A.jsx)(b,{open:e,onOpenChange:n,children:(0,A.jsxs)(_,{className:`max-w-xl`,children:[(0,A.jsxs)(h,{children:[(0,A.jsx)(v,{children:`Add audience-scoped memory`}),(0,A.jsx)(y,{children:`This guidance is injected only when an agent matches at least one supplied selector.`})]}),(0,A.jsxs)(`div`,{className:`space-y-4`,children:[(0,A.jsxs)(`div`,{children:[(0,A.jsx)(`label`,{htmlFor:`audience-memory-text`,className:`mb-1.5 block text-xs font-medium`,children:`Memory`}),(0,A.jsx)(`textarea`,{id:`audience-memory-text`,value:i,onChange:e=>a(e.target.value),placeholder:`What should matching agents remember?`,rows:4,autoFocus:!0,className:`w-full resize-y rounded-md border border-input bg-background px-3 py-2 text-sm outline-none placeholder:text-muted-foreground focus-visible:ring-2 focus-visible:ring-ring`})]}),(0,A.jsxs)(`div`,{children:[(0,A.jsx)(`label`,{htmlFor:`audience-memory-kind`,className:`mb-1.5 block text-xs font-medium`,children:`Kind`}),(0,A.jsx)(`select`,{id:`audience-memory-kind`,value:o,onChange:e=>s(e.target.value),className:`h-9 w-full rounded-md border border-input bg-background px-3 text-xs outline-none focus-visible:ring-2 focus-visible:ring-ring`,children:E.map(e=>(0,A.jsx)(`option`,{value:e,children:D[e]??e},e))})]}),(0,A.jsxs)(`fieldset`,{className:`space-y-3 rounded-md border border-border/70 bg-background/35 p-3`,children:[(0,A.jsx)(`legend`,{className:`px-1 text-xs font-medium`,children:`Audience selectors`}),(0,A.jsx)(B,{id:`audience-memory-roles`,label:`Roles`,value:c,onChange:l,placeholder:`reviewer, refactor-planner`}),(0,A.jsx)(B,{id:`audience-memory-task-types`,label:`Task types`,value:u,onChange:d,placeholder:`review, refactor, bugfix`}),(0,A.jsx)(B,{id:`audience-memory-modes`,label:`Modes`,value:f,onChange:p,placeholder:`teach, code-review`}),(0,A.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,children:`Comma-separate multiple values. At least one selector is required.`})]})]}),(0,A.jsxs)(g,{children:[(0,A.jsx)(x,{variant:`outline`,onClick:()=>n(!1),disabled:t,children:`Cancel`}),(0,A.jsx)(x,{onClick:()=>r({text:i.trim(),kind:o,roles:m,taskTypes:S,modes:C}),disabled:!w||t,children:t?`Remembering…`:`Remember`})]})]})})}function B({id:e,label:t,value:n,placeholder:r,onChange:i}){return(0,A.jsxs)(`div`,{className:`grid gap-1.5 sm:grid-cols-[6rem_1fr] sm:items-center`,children:[(0,A.jsx)(`label`,{htmlFor:e,className:`text-[11px] font-medium text-muted-foreground`,children:t}),(0,A.jsx)(S,{id:e,value:n,onChange:e=>i(e.target.value),placeholder:r,className:`h-8 font-mono text-xs`})]})}function re({open:e,onOpenChange:t,onImport:n}){let[r,i]=(0,k.useState)(``);return(0,k.useEffect)(()=>{e||i(``)},[e]),(0,A.jsx)(b,{open:e,onOpenChange:t,children:(0,A.jsxs)(_,{className:`max-w-xl`,children:[(0,A.jsxs)(h,{children:[(0,A.jsx)(v,{children:`Import audience memories`}),(0,A.jsxs)(y,{children:[`Paste the JSON produced here or by `,(0,A.jsx)(`code`,{children:`/memory audience export`}),`. Entries without a valid audience selector are skipped.`]})]}),(0,A.jsxs)(`div`,{children:[(0,A.jsx)(`label`,{htmlFor:`audience-memory-import`,className:`mb-1.5 block text-xs font-medium`,children:`JSON array`}),(0,A.jsx)(`textarea`,{id:`audience-memory-import`,value:r,onChange:e=>i(e.target.value),placeholder:`[
1
+ import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{Ct as t,Dt as n,Ht as r,Sa as i,Zt as a,at as o,cn as s,et as c,ni as l,pn as u,vt as d,wr as f}from"./vendor-2VBBgNb5.js";import{t as p}from"./useWebSocket-Dh3aAFDE.js";import{t as m}from"./utils-CN2sfDVP.js";import{a as h,i as g,n as _,o as v,r as y,t as b}from"./dialog-CT1PTjzK.js";import{t as x}from"./button-uGqXvobk.js";import{t as S}from"./input-B-VCX2sG.js";import{f as C,p as w}from"./index-BPfIz78e.js";import{g as T,i as E,r as D,y as O}from"./shared-jvJxtKc5.js";var k=e(i(),1),A=c();function j(e){if(!Array.isArray(e))return;let t=[...new Set(e.filter(e=>typeof e==`string`).map(e=>e.trim()).filter(Boolean))];return t.length>0?t:void 0}function M(e){if(!e||typeof e!=`object`||Array.isArray(e))return;let t=e,n={roles:j(t.roles),taskTypes:j(t.taskTypes),modes:j(t.modes)};return n.roles||n.taskTypes||n.modes?n:void 0}function N(e){let t=e.trim().replace(/^```(?:json)?\s*/i,``).replace(/\s*```$/,``),n=JSON.parse(t);if(!Array.isArray(n))throw Error(`Input must be a JSON array.`);let r=[],i=0;for(let e of n){if(!e||typeof e!=`object`||Array.isArray(e)){i++;continue}let t=e,n=typeof t.text==`string`?t.text.trim():``,a=M(t.audience);if(!n||!a){i++;continue}let o=typeof t.kind==`string`&&E.some(e=>e===t.kind)?t.kind:void 0,s=j(t.tags);r.push({text:n,audience:a,kind:o,tags:s,importance:typeof t.importance==`number`?t.importance:void 0,confidence:typeof t.confidence==`number`?t.confidence:void 0})}return{entries:r,skipped:i}}function P(e,t){if(!t)return!0;let n=e.audience;return[e.text,e.kind,e.status,...n?.roles??[],...n?.taskTypes??[],...n?.modes??[]].join(` `).toLocaleLowerCase().includes(t.toLocaleLowerCase())}function F(e,t){return[...new Set(e.flatMap(e=>e.audience?.[t]??[]).filter(e=>e.length>0))].sort((e,t)=>e.localeCompare(t))}function I(){let e=p(),[r,i]=(0,k.useState)([]),[c,E]=(0,k.useState)(!0),[D,O]=(0,k.useState)(null),[j,M]=(0,k.useState)(``),[I,z]=(0,k.useState)(!1),[B,V]=(0,k.useState)(!1),[H,U]=(0,k.useState)(null),[W,G]=(0,k.useState)(!1),[K,q]=(0,k.useState)(!1),J=(0,k.useRef)(null),Y=(0,k.useCallback)(()=>{E(!0),O(null),e.listSageMemories({echoToChat:!1})},[e.listSageMemories]);(0,k.useEffect)(()=>{let t=e.client,n=t.on(`memory.sage.list`,e=>{let t=e.payload;t.error?O({tone:`error`,text:t.error}):i(t.memories??[]),E(!1)}),r=t.on(`memory.sage.remember`,e=>{let t=e.payload;if(G(!1),t.error){O({tone:`error`,text:t.error});return}t.memory&&(i(e=>[t.memory,...e.filter(e=>e.id!==t.memory.id)]),z(!1))}),a=t.on(`memory.sage.update`,e=>{let t=e.payload;t.error?O({tone:`error`,text:t.error}):t.memory&&(i(e=>e.map(e=>e.id===t.memory.id?t.memory:e)),t.memory.audience||O({tone:`success`,text:`Audience scope removed. The memory is now general.`}))}),o=t.on(`memory.sage.delete`,e=>{let t=e.payload,n=J.current;t.success&&n?(i(e=>e.filter(e=>e.id!==n)),O({tone:`success`,text:`Audience memory deleted.`}),U(null),q(!1),J.current=null):t.success?Y():(O({tone:`error`,text:t.message??`Could not delete the memory.`}),q(!1),J.current=null)});return Y(),()=>{n(),r(),a(),o()}},[Y,e.client]);let X=(0,k.useMemo)(()=>r.filter(e=>{let t=e.audience;return!!(t&&(t.roles?.length||t.taskTypes?.length||t.modes?.length))}),[r]),Z=j.trim(),Q=(0,k.useMemo)(()=>X.filter(e=>P(e,Z)),[Z,X]),$=w(Q,16,Z),ie=(0,k.useMemo)(()=>F(X,`roles`),[X]),ae=(0,k.useMemo)(()=>F(X,`taskTypes`),[X]),oe=(0,k.useMemo)(()=>F(X,`modes`),[X]),se=t=>{O(null),e.updateSage(t,{audience:void 0},{echoToChat:!1})},ce=()=>{H&&(J.current=H,q(!0),O(null),e.deleteSage(H,`Removed from the audience memory panel.`))},le=async()=>{let e=X.map(e=>({id:e.id,text:e.text,kind:e.kind,status:e.status,audience:e.audience,tags:e.tags,importance:e.importance,confidence:e.confidence}));try{if(!navigator.clipboard)throw Error(`Clipboard access is unavailable.`);await navigator.clipboard.writeText(JSON.stringify(e,null,2)),O({tone:`success`,text:`${e.length} audience memor${e.length===1?`y`:`ies`} copied as JSON.`})}catch(e){O({tone:`error`,text:e instanceof Error?e.message:`Failed to copy JSON to the clipboard.`})}};return(0,A.jsxs)(A.Fragment,{children:[(0,A.jsxs)(`section`,{className:`flex h-full min-h-0 flex-col bg-card/20`,"aria-labelledby":`audience-memory-title`,children:[(0,A.jsxs)(`div`,{className:`shrink-0 border-b border-border/60 p-3`,children:[(0,A.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,A.jsx)(`div`,{className:`min-w-0`,children:(0,A.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,A.jsx)(`span`,{className:`flex size-7 shrink-0 items-center justify-center rounded-md border border-primary/20 bg-primary/10 text-primary`,children:(0,A.jsx)(n,{className:`size-3.5`})}),(0,A.jsxs)(`div`,{className:`min-w-0`,children:[(0,A.jsx)(`h2`,{id:`audience-memory-title`,className:`truncate text-sm font-semibold`,children:`Audience Memory`}),(0,A.jsx)(`p`,{className:`truncate text-[10px] text-muted-foreground`,children:`Guidance routed to matching agents`})]})]})}),(0,A.jsxs)(x,{variant:`default`,size:`sm`,className:`h-7 shrink-0 gap-1 px-2 text-xs`,onClick:()=>z(!0),children:[(0,A.jsx)(u,{className:`size-3`}),`Add`]})]}),(0,A.jsxs)(`div`,{className:`mt-3 grid grid-cols-4 gap-px overflow-hidden rounded-md border border-border/60 bg-border/60`,children:[(0,A.jsx)(L,{value:X.length,label:`Memories`}),(0,A.jsx)(L,{value:ie.length,label:`Roles`}),(0,A.jsx)(L,{value:ae.length,label:`Tasks`}),(0,A.jsx)(L,{value:oe.length,label:`Modes`})]}),(0,A.jsxs)(`div`,{className:`mt-3 flex items-center gap-1.5`,children:[(0,A.jsxs)(`div`,{className:`relative min-w-0 flex-1`,children:[(0,A.jsx)(a,{className:`pointer-events-none absolute left-2.5 top-1/2 size-3.5 -translate-y-1/2 text-muted-foreground`}),(0,A.jsx)(S,{value:j,onChange:e=>M(e.target.value),placeholder:`Search text, role, task or mode…`,"aria-label":`Search audience memories`,className:`h-8 pl-8 pr-8 text-xs`}),j&&(0,A.jsx)(`button`,{type:`button`,className:`absolute right-2 top-1/2 -translate-y-1/2 rounded-sm p-0.5 text-muted-foreground hover:text-foreground`,onClick:()=>M(``),"aria-label":`Clear audience memory search`,children:(0,A.jsx)(o,{className:`size-3`})})]}),(0,A.jsx)(x,{variant:`ghost`,size:`icon`,className:`size-8 shrink-0`,onClick:Y,"aria-label":`Refresh audience memories`,title:`Refresh`,children:(0,A.jsx)(s,{className:m(`size-3.5`,c&&`animate-spin`)})}),(0,A.jsx)(x,{variant:`ghost`,size:`icon`,className:`size-8 shrink-0`,onClick:()=>V(!0),"aria-label":`Import audience memories`,title:`Import JSON`,children:(0,A.jsx)(d,{className:`size-3.5`})}),(0,A.jsx)(x,{variant:`ghost`,size:`icon`,className:`size-8 shrink-0`,onClick:()=>void le(),"aria-label":`Copy audience memories as JSON`,title:`Copy JSON`,disabled:X.length===0,children:(0,A.jsx)(l,{className:`size-3.5`})})]})]}),D&&(0,A.jsxs)(`div`,{role:D.tone===`error`?`alert`:`status`,className:m(`mx-3 mt-3 flex shrink-0 items-start justify-between gap-2 rounded-md border px-2.5 py-2 text-[11px]`,D.tone===`error`?`border-destructive/30 bg-destructive/5 text-destructive`:`border-success/30 bg-success/5 text-success`),children:[(0,A.jsx)(`span`,{children:D.text}),(0,A.jsx)(`button`,{type:`button`,onClick:()=>O(null),className:`shrink-0 rounded-sm opacity-70 hover:opacity-100`,"aria-label":`Dismiss message`,children:(0,A.jsx)(o,{className:`size-3`})})]}),(0,A.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col`,children:[!c&&X.length>0&&(0,A.jsxs)(`div`,{className:`flex shrink-0 items-center justify-between px-3 pb-1.5 pt-3 text-[10px] text-muted-foreground`,children:[(0,A.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,A.jsx)(f,{className:`size-3`}),Z?`${Q.length} of ${X.length}`:`${X.length} scoped`]}),Z&&(0,A.jsx)(`button`,{type:`button`,className:`hover:text-foreground`,onClick:()=>M(``),children:`Clear filter`})]}),(0,A.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-y-auto px-3`,children:[c?(0,A.jsx)(ee,{}):X.length===0?(0,A.jsx)(te,{onAdd:()=>z(!0)}):Q.length===0?(0,A.jsxs)(`div`,{className:`flex h-full min-h-32 flex-col items-center justify-center px-4 text-center`,children:[(0,A.jsx)(a,{className:`mb-2 size-5 text-muted-foreground/60`}),(0,A.jsx)(`p`,{className:`text-xs font-medium`,children:`No matching memories`}),(0,A.jsx)(`p`,{className:`mt-1 text-[10px] text-muted-foreground`,children:`Try another role, task, mode, or phrase.`}),(0,A.jsx)(x,{variant:`ghost`,size:`sm`,className:`mt-2 h-7 text-xs`,onClick:()=>M(``),children:`Clear search`})]}):(0,A.jsx)(`ul`,{className:`space-y-2`,children:$.pageItems.map(e=>(0,A.jsx)(R,{memory:e,onFilter:M,onClearScope:()=>se(e.id),onDelete:()=>U(e.id)},e.id))}),(0,A.jsx)(C,{page:$.page,pageSize:$.pageSize,totalItems:$.totalItems,onPageChange:$.setPage,compact:!0,itemLabel:`memories`})]})]})]}),(0,A.jsx)(ne,{open:I,busy:W,onOpenChange:e=>{W||z(e)},onCreate:t=>{O(null),G(!0),e.rememberSage({text:t.text,kind:t.kind,audience:{roles:t.roles.length>0?t.roles:void 0,taskTypes:t.taskTypes.length>0?t.taskTypes:void 0,modes:t.modes.length>0?t.modes:void 0}},{echoToChat:!1})}}),(0,A.jsx)(re,{open:B,onOpenChange:V,onImport:t=>{try{let{entries:n,skipped:r}=N(t);if(n.length===0)return O({tone:`error`,text:`No valid audience-scoped memories were found in the JSON.`}),!1;for(let t of n)e.rememberSage(t,{echoToChat:!1});return O({tone:`success`,text:`${n.length} memor${n.length===1?`y`:`ies`} queued for import${r?`; ${r} invalid ${r===1?`entry was`:`entries were`} skipped`:``}.`}),V(!1),!0}catch(e){return O({tone:`error`,text:e instanceof Error?e.message:`Invalid JSON.`}),!1}}}),(0,A.jsx)(b,{open:!!H,onOpenChange:e=>{!e&&!K&&U(null)},children:(0,A.jsxs)(_,{className:`max-w-md`,children:[(0,A.jsxs)(h,{children:[(0,A.jsx)(v,{children:`Delete this audience memory?`}),(0,A.jsx)(y,{children:`This removes the memory from active use. To keep it as general project guidance, cancel and use the un-scope action instead.`})]}),(0,A.jsx)(`div`,{className:`rounded-md border border-border/70 bg-background/45 p-3 text-xs text-muted-foreground`,children:T(r.find(e=>e.id===H)?.text??``,180)}),(0,A.jsxs)(g,{children:[(0,A.jsx)(x,{variant:`outline`,onClick:()=>U(null),disabled:K,children:`Cancel`}),(0,A.jsxs)(x,{variant:`destructive`,onClick:ce,disabled:K,children:[(0,A.jsx)(t,{className:`size-4`}),K?`Deleting…`:`Delete memory`]})]})]})})]})}function L({value:e,label:t}){return(0,A.jsxs)(`div`,{className:`bg-card/95 px-1.5 py-2 text-center`,children:[(0,A.jsx)(`p`,{className:`text-sm font-semibold tabular-nums`,children:e}),(0,A.jsx)(`p`,{className:`truncate text-[9px] uppercase tracking-wide text-muted-foreground`,children:t})]})}function R({memory:e,onFilter:n,onClearScope:i,onDelete:a}){return(0,A.jsxs)(`li`,{className:`group rounded-md border border-border/65 bg-card/55 p-2.5 transition-colors hover:border-border hover:bg-card/85`,children:[(0,A.jsx)(`p`,{className:`break-words text-xs leading-5`,children:e.text}),e.audience&&(0,A.jsx)(z,{audience:e.audience,onFilter:n}),(0,A.jsxs)(`div`,{className:`mt-2 flex items-center justify-between gap-2 border-t border-border/45 pt-2`,children:[(0,A.jsxs)(`div`,{className:`flex min-w-0 items-center gap-1.5 text-[9px] uppercase tracking-wide text-muted-foreground`,children:[(0,A.jsx)(`span`,{className:`truncate`,children:D[e.kind]??e.kind}),(0,A.jsx)(`span`,{"aria-hidden":`true`,children:`·`}),(0,A.jsx)(`span`,{children:e.status})]}),(0,A.jsxs)(`div`,{className:`flex shrink-0 items-center gap-0.5`,children:[(0,A.jsx)(x,{variant:`ghost`,size:`icon`,className:`size-6`,onClick:i,"aria-label":`Remove audience scope from ${T(e.text,42)}`,title:`Make general memory`,children:(0,A.jsx)(r,{className:`size-3`})}),(0,A.jsx)(x,{variant:`ghost`,size:`icon`,className:`size-6 text-destructive hover:text-destructive`,onClick:a,"aria-label":`Delete ${T(e.text,42)}`,title:`Delete`,children:(0,A.jsx)(t,{className:`size-3`})})]})]})]})}function z({audience:e,onFilter:t}){return(0,A.jsx)(`div`,{className:`mt-2 flex flex-wrap gap-1`,children:[...(e.roles??[]).map(e=>({label:`role`,value:e})),...(e.taskTypes??[]).map(e=>({label:`task`,value:e})),...(e.modes??[]).map(e=>({label:`mode`,value:e}))].map(({label:e,value:n})=>(0,A.jsxs)(`button`,{type:`button`,className:`max-w-full truncate rounded border border-primary/15 bg-primary/7 px-1.5 py-0.5 font-mono text-[9px] text-primary/90 transition-colors hover:border-primary/35 hover:bg-primary/12`,onClick:()=>t(n),title:`Filter by ${e}: ${n}`,children:[e,`:`,n]},`${e}:${n}`))})}function ee(){return(0,A.jsx)(`div`,{className:`space-y-2 pt-3`,role:`status`,"aria-label":`Loading audience memories`,children:[0,1,2].map(e=>(0,A.jsxs)(`div`,{className:`animate-pulse rounded-md border border-border/50 p-3`,children:[(0,A.jsx)(`div`,{className:`h-2.5 w-full rounded bg-muted`}),(0,A.jsx)(`div`,{className:`mt-2 h-2.5 w-2/3 rounded bg-muted`}),(0,A.jsx)(`div`,{className:`mt-3 h-4 w-24 rounded bg-muted`})]},e))})}function te({onAdd:e}){return(0,A.jsxs)(`div`,{className:`flex h-full min-h-44 flex-col items-center justify-center px-5 text-center`,children:[(0,A.jsx)(`span`,{className:`mb-3 flex size-10 items-center justify-center rounded-full border border-dashed border-primary/35 bg-primary/5 text-primary`,children:(0,A.jsx)(n,{className:`size-4`})}),(0,A.jsx)(`p`,{className:`text-xs font-medium`,children:`Route guidance to the right agents`}),(0,A.jsx)(`p`,{className:`mt-1 max-w-52 text-[10px] leading-4 text-muted-foreground`,children:`Scope a memory by role, task type, or operating mode. Matching agents receive it automatically.`}),(0,A.jsxs)(x,{variant:`outline`,size:`sm`,className:`mt-3 h-7 gap-1 text-xs`,onClick:e,children:[(0,A.jsx)(u,{className:`size-3`}),`Add scoped memory`]})]})}function ne({open:e,busy:t,onOpenChange:n,onCreate:r}){let[i,a]=(0,k.useState)(``),[o,s]=(0,k.useState)(`workflow`),[c,l]=(0,k.useState)(``),[u,d]=(0,k.useState)(``),[f,p]=(0,k.useState)(``);(0,k.useEffect)(()=>{e||(a(``),s(`workflow`),l(``),d(``),p(``))},[e]);let m=O(c),S=O(u),C=O(f),w=i.trim().length>0&&(m.length>0||S.length>0||C.length>0);return(0,A.jsx)(b,{open:e,onOpenChange:n,children:(0,A.jsxs)(_,{className:`max-w-xl`,children:[(0,A.jsxs)(h,{children:[(0,A.jsx)(v,{children:`Add audience-scoped memory`}),(0,A.jsx)(y,{children:`This guidance is injected only when an agent matches at least one supplied selector.`})]}),(0,A.jsxs)(`div`,{className:`space-y-4`,children:[(0,A.jsxs)(`div`,{children:[(0,A.jsx)(`label`,{htmlFor:`audience-memory-text`,className:`mb-1.5 block text-xs font-medium`,children:`Memory`}),(0,A.jsx)(`textarea`,{id:`audience-memory-text`,value:i,onChange:e=>a(e.target.value),placeholder:`What should matching agents remember?`,rows:4,autoFocus:!0,className:`w-full resize-y rounded-md border border-input bg-background px-3 py-2 text-sm outline-none placeholder:text-muted-foreground focus-visible:ring-2 focus-visible:ring-ring`})]}),(0,A.jsxs)(`div`,{children:[(0,A.jsx)(`label`,{htmlFor:`audience-memory-kind`,className:`mb-1.5 block text-xs font-medium`,children:`Kind`}),(0,A.jsx)(`select`,{id:`audience-memory-kind`,value:o,onChange:e=>s(e.target.value),className:`h-9 w-full rounded-md border border-input bg-background px-3 text-xs outline-none focus-visible:ring-2 focus-visible:ring-ring`,children:E.map(e=>(0,A.jsx)(`option`,{value:e,children:D[e]??e},e))})]}),(0,A.jsxs)(`fieldset`,{className:`space-y-3 rounded-md border border-border/70 bg-background/35 p-3`,children:[(0,A.jsx)(`legend`,{className:`px-1 text-xs font-medium`,children:`Audience selectors`}),(0,A.jsx)(B,{id:`audience-memory-roles`,label:`Roles`,value:c,onChange:l,placeholder:`reviewer, refactor-planner`}),(0,A.jsx)(B,{id:`audience-memory-task-types`,label:`Task types`,value:u,onChange:d,placeholder:`review, refactor, bugfix`}),(0,A.jsx)(B,{id:`audience-memory-modes`,label:`Modes`,value:f,onChange:p,placeholder:`teach, code-review`}),(0,A.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,children:`Comma-separate multiple values. At least one selector is required.`})]})]}),(0,A.jsxs)(g,{children:[(0,A.jsx)(x,{variant:`outline`,onClick:()=>n(!1),disabled:t,children:`Cancel`}),(0,A.jsx)(x,{onClick:()=>r({text:i.trim(),kind:o,roles:m,taskTypes:S,modes:C}),disabled:!w||t,children:t?`Remembering…`:`Remember`})]})]})})}function B({id:e,label:t,value:n,placeholder:r,onChange:i}){return(0,A.jsxs)(`div`,{className:`grid gap-1.5 sm:grid-cols-[6rem_1fr] sm:items-center`,children:[(0,A.jsx)(`label`,{htmlFor:e,className:`text-[11px] font-medium text-muted-foreground`,children:t}),(0,A.jsx)(S,{id:e,value:n,onChange:e=>i(e.target.value),placeholder:r,className:`h-8 font-mono text-xs`})]})}function re({open:e,onOpenChange:t,onImport:n}){let[r,i]=(0,k.useState)(``);return(0,k.useEffect)(()=>{e||i(``)},[e]),(0,A.jsx)(b,{open:e,onOpenChange:t,children:(0,A.jsxs)(_,{className:`max-w-xl`,children:[(0,A.jsxs)(h,{children:[(0,A.jsx)(v,{children:`Import audience memories`}),(0,A.jsxs)(y,{children:[`Paste the JSON produced here or by `,(0,A.jsx)(`code`,{children:`/memory audience export`}),`. Entries without a valid audience selector are skipped.`]})]}),(0,A.jsxs)(`div`,{children:[(0,A.jsx)(`label`,{htmlFor:`audience-memory-import`,className:`mb-1.5 block text-xs font-medium`,children:`JSON array`}),(0,A.jsx)(`textarea`,{id:`audience-memory-import`,value:r,onChange:e=>i(e.target.value),placeholder:`[
2
2
  { "text": "…", "audience": { "roles": ["reviewer"] } }
3
- ]`,rows:10,autoFocus:!0,spellCheck:!1,className:`w-full resize-y rounded-md border border-input bg-background p-3 font-mono text-xs outline-none placeholder:text-muted-foreground focus-visible:ring-2 focus-visible:ring-ring`})]}),(0,A.jsxs)(g,{children:[(0,A.jsx)(x,{variant:`outline`,onClick:()=>t(!1),children:`Cancel`}),(0,A.jsxs)(x,{onClick:()=>n(r),disabled:!r.trim(),children:[(0,A.jsx)(u,{className:`size-4`}),`Import memories`]})]})]})})}export{I as AudienceMemoryPanel};
3
+ ]`,rows:10,autoFocus:!0,spellCheck:!1,className:`w-full resize-y rounded-md border border-input bg-background p-3 font-mono text-xs outline-none placeholder:text-muted-foreground focus-visible:ring-2 focus-visible:ring-ring`})]}),(0,A.jsxs)(g,{children:[(0,A.jsx)(x,{variant:`outline`,onClick:()=>t(!1),children:`Cancel`}),(0,A.jsxs)(x,{onClick:()=>n(r),disabled:!r.trim(),children:[(0,A.jsx)(d,{className:`size-4`}),`Import memories`]})]})]})})}export{I as AudienceMemoryPanel};
@@ -1 +1 @@
1
- import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{Kn as t,Ri as n,Ur as r,b as i,cn as a,en as o,et as s,fi as c,ga as l,tn as u,xa as d}from"./vendor-9hC4n4Me.js";import"./i18n-D-JnOQZX.js";import{a as f,n as p,t as m}from"./monaco-BLUV5g0U.js";import{t as h}from"./ws-client-eyEv8wbm.js";import{t as g}from"./utils-DzRQUvln.js";import{M as _,g as v}from"./stores-hEu6z1qz.js";import{w as y}from"./index-WvJRbCoi.js";import{t as b}from"./empty-state-DoEewhfx.js";import{t as x}from"./monaco-theme-DSeCDzQy.js";var S=e(d(),1),C=s();p.config({monaco:m});var w={ts:`typescript`,tsx:`typescript`,js:`javascript`,jsx:`javascript`,mjs:`javascript`,json:`json`,css:`css`,scss:`scss`,html:`html`,md:`markdown`,py:`python`,go:`go`,rs:`rust`,java:`java`,c:`c`,cpp:`cpp`,cs:`csharp`,rb:`ruby`,php:`php`,sh:`shell`,bash:`shell`,yml:`yaml`,yaml:`yaml`,toml:`toml`,sql:`sql`};function T(e){return w[e.split(`.`).pop()?.toLowerCase()??``]??`plaintext`}function E({path:e,oldText:r,newText:a}){let{t:s}=l(),c=(0,S.useRef)(null),[u,d]=(0,S.useState)(!1),[p,m]=(0,S.useState)(!1),[g,v]=(0,S.useState)(null);(0,S.useEffect)(()=>{d(!1),m(!1),v(null)},[]);let y=(0,S.useCallback)(e=>{c.current=e,f.setTheme(x()),e.getModifiedEditor().onDidChangeModelContent(()=>d(!0))},[]),b=(0,S.useCallback)(()=>{let t=c.current?.getModifiedEditor().getValue();if(t==null)return;m(!0);let n=h(_.getState().wsUrl),r=n.on(`files.written`,t=>{t.type===`files.written`&&t.payload.filePath===e&&(r(),clearTimeout(i),m(!1),t.payload.success&&(d(!1),v(Date.now())))}),i=setTimeout(()=>{r(),m(!1)},5e3);n.send({type:`files.write`,payload:{filePath:e,content:t}})},[e]),w=T(e);return(0,C.jsxs)(`div`,{className:`flex h-full min-h-0 min-w-0 flex-1 flex-col overflow-hidden`,children:[(0,C.jsxs)(`div`,{className:`flex min-w-0 items-center justify-between gap-2 px-2 py-1.5 border-b border-border/40`,children:[(0,C.jsx)(`span`,{className:`text-xs font-mono text-muted-foreground truncate`,children:e}),(0,C.jsxs)(`button`,{type:`button`,onClick:b,disabled:!u||p,className:`inline-flex items-center gap-1.5 h-7 px-2.5 rounded-md border border-border text-xs font-medium disabled:opacity-40 enabled:hover:bg-muted transition-colors`,title:s(`activity:monacoDiff.applyTitle`),children:[p?(0,C.jsx)(t,{className:`h-3.5 w-3.5 animate-spin`}):g&&!u?(0,C.jsx)(n,{className:`h-3.5 w-3.5 text-success`}):(0,C.jsx)(o,{className:`h-3.5 w-3.5`}),s(p?`activity:monacoDiff.applying`:g&&!u?`activity:monacoDiff.applied`:`activity:monacoDiff.apply`)]})]}),(0,C.jsx)(`div`,{className:`min-h-0 min-w-0 flex-1 overflow-hidden`,children:(0,C.jsx)(i,{original:r,modified:a,language:w,theme:x(),onMount:y,options:{renderSideBySide:!0,readOnly:!1,originalEditable:!1,minimap:{enabled:!1},fontSize:13,scrollBeyondLastLine:!1,automaticLayout:!0}})})]})}var D=1e4;function O({className:e}){let{t:n}=l(),i=v(e=>e.selectedPath),o=v(e=>e.diff),s=v(e=>e.loadingDiff),[d,f]=(0,S.useState)(`unified`),[p,m]=(0,S.useState)(!1),x=!!i&&(s||!o);(0,S.useEffect)(()=>{if(m(!1),!x)return;let e=setTimeout(()=>m(!0),D);return()=>clearTimeout(e)},[x,i]);let w=()=>{i&&(m(!1),v.getState().setDiffLoading(!0),h(_.getState().wsUrl).getGitDiff?.(i))};if(!i)return(0,C.jsx)(b,{icon:(0,C.jsx)(r,{className:`h-6 w-6`}),title:`Source changes`,description:n(`activity:changes.selectPrompt`),className:e});let T=o&&!o.error&&!o.binary&&!o.tooLarge;return(0,C.jsx)(`div`,{className:g(`flex min-h-0 min-w-0 flex-1 flex-col overflow-hidden bg-[hsl(var(--surface-2)/0.45)] p-3`,e),children:(0,C.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col overflow-hidden rounded-xl border border-border/70 bg-card/75 shadow-sm`,children:[(0,C.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center justify-between gap-2 border-b border-border/70 px-3 py-2`,children:[(0,C.jsxs)(`div`,{className:`min-w-0`,children:[(0,C.jsx)(`div`,{className:`text-[10px] font-semibold uppercase text-muted-foreground`,children:`Source control`}),(0,C.jsx)(`div`,{className:`truncate font-mono text-xs text-foreground`,title:i,children:i})]}),T&&(0,C.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,C.jsxs)(`button`,{type:`button`,onClick:()=>f(`unified`),title:n(`activity:changes.unifiedTitle`),className:g(`inline-flex h-8 items-center gap-1 rounded-md border px-2 text-xs transition-colors`,d===`unified`?`border-primary/40 bg-primary/10 text-primary`:`border-border text-muted-foreground hover:bg-muted`),children:[(0,C.jsx)(u,{className:`h-3.5 w-3.5`}),` `,n(`activity:changes.unified`)]}),(0,C.jsxs)(`button`,{type:`button`,onClick:()=>f(`edit`),title:n(`activity:changes.editTitle`),className:g(`inline-flex h-8 items-center gap-1 rounded-md border px-2 text-xs transition-colors`,d===`edit`?`border-primary/40 bg-primary/10 text-primary`:`border-border text-muted-foreground hover:bg-muted`),children:[(0,C.jsx)(c,{className:`h-3.5 w-3.5`}),` `,n(`activity:changes.edit`)]})]})]}),(0,C.jsx)(`div`,{className:`flex min-h-0 flex-1 flex-col overflow-hidden`,children:s||!o?p?(0,C.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col items-center justify-center gap-3 p-4 text-center`,children:[(0,C.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:n(`activity:changes.diffTimeout`)}),(0,C.jsxs)(`button`,{type:`button`,onClick:w,className:`inline-flex h-8 items-center gap-1.5 rounded-md border border-border px-3 text-xs text-muted-foreground transition-colors hover:bg-muted hover:text-foreground`,children:[(0,C.jsx)(a,{className:`h-3.5 w-3.5`}),` `,n(`common:action.retry`)]})]}):(0,C.jsxs)(`div`,{className:`flex min-h-0 flex-1 items-center justify-center gap-2 text-sm text-muted-foreground`,children:[(0,C.jsx)(t,{className:`h-4 w-4 animate-spin`}),` `,n(`activity:changes.loadingDiff`)]}):o.error?(0,C.jsx)(`div`,{className:`flex min-h-0 flex-1 items-center justify-center text-sm text-destructive`,children:o.error}):o.binary?(0,C.jsx)(`div`,{className:`flex min-h-0 flex-1 items-center justify-center text-sm text-muted-foreground`,children:n(`activity:changes.binary`)}):o.tooLarge?(0,C.jsx)(`div`,{className:`flex min-h-0 flex-1 items-center justify-center text-sm text-muted-foreground`,children:n(`activity:changes.tooLarge`)}):d===`edit`?(0,C.jsx)(E,{path:o.path,oldText:o.oldText??``,newText:o.newText??``},o.path):(0,C.jsx)(y,{oldText:o.oldText,newText:o.newText,caption:o.path,fill:!0})})]})})}export{O as ChangesView};
1
+ import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{Kn as t,Sa as n,Ur as r,_a as i,b as a,cn as o,en as s,et as c,fi as l,tn as u,zi as d}from"./vendor-2VBBgNb5.js";import"./i18n-1BkaqMgr.js";import{a as f,n as p,t as m}from"./monaco-BLUV5g0U.js";import{t as h}from"./ws-client-WVGn8ORh.js";import{t as g}from"./utils-CN2sfDVP.js";import{M as _,g as v}from"./stores-mpa0202y.js";import{w as y}from"./index-BPfIz78e.js";import{t as b}from"./empty-state-CdyXy96A.js";import{t as x}from"./monaco-theme-DSeCDzQy.js";var S=e(n(),1),C=c();p.config({monaco:m});var w={ts:`typescript`,tsx:`typescript`,js:`javascript`,jsx:`javascript`,mjs:`javascript`,json:`json`,css:`css`,scss:`scss`,html:`html`,md:`markdown`,py:`python`,go:`go`,rs:`rust`,java:`java`,c:`c`,cpp:`cpp`,cs:`csharp`,rb:`ruby`,php:`php`,sh:`shell`,bash:`shell`,yml:`yaml`,yaml:`yaml`,toml:`toml`,sql:`sql`};function T(e){return w[e.split(`.`).pop()?.toLowerCase()??``]??`plaintext`}function E({path:e,oldText:n,newText:r}){let{t:o}=i(),c=(0,S.useRef)(null),[l,u]=(0,S.useState)(!1),[p,m]=(0,S.useState)(!1),[g,v]=(0,S.useState)(null);(0,S.useEffect)(()=>{u(!1),m(!1),v(null)},[]);let y=(0,S.useCallback)(e=>{c.current=e,f.setTheme(x()),e.getModifiedEditor().onDidChangeModelContent(()=>u(!0))},[]),b=(0,S.useCallback)(()=>{let t=c.current?.getModifiedEditor().getValue();if(t==null)return;m(!0);let n=h(_.getState().wsUrl),r=n.on(`files.written`,t=>{t.type===`files.written`&&t.payload.filePath===e&&(r(),clearTimeout(i),m(!1),t.payload.success&&(u(!1),v(Date.now())))}),i=setTimeout(()=>{r(),m(!1)},5e3);n.send({type:`files.write`,payload:{filePath:e,content:t}})},[e]),w=T(e);return(0,C.jsxs)(`div`,{className:`flex h-full min-h-0 min-w-0 flex-1 flex-col overflow-hidden`,children:[(0,C.jsxs)(`div`,{className:`flex min-w-0 items-center justify-between gap-2 px-2 py-1.5 border-b border-border/40`,children:[(0,C.jsx)(`span`,{className:`text-xs font-mono text-muted-foreground truncate`,children:e}),(0,C.jsxs)(`button`,{type:`button`,onClick:b,disabled:!l||p,className:`inline-flex items-center gap-1.5 h-7 px-2.5 rounded-md border border-border text-xs font-medium disabled:opacity-40 enabled:hover:bg-muted transition-colors`,title:o(`activity:monacoDiff.applyTitle`),children:[p?(0,C.jsx)(t,{className:`h-3.5 w-3.5 animate-spin`}):g&&!l?(0,C.jsx)(d,{className:`h-3.5 w-3.5 text-success`}):(0,C.jsx)(s,{className:`h-3.5 w-3.5`}),o(p?`activity:monacoDiff.applying`:g&&!l?`activity:monacoDiff.applied`:`activity:monacoDiff.apply`)]})]}),(0,C.jsx)(`div`,{className:`min-h-0 min-w-0 flex-1 overflow-hidden`,children:(0,C.jsx)(a,{original:n,modified:r,language:w,theme:x(),onMount:y,options:{renderSideBySide:!0,readOnly:!1,originalEditable:!1,minimap:{enabled:!1},fontSize:13,scrollBeyondLastLine:!1,automaticLayout:!0}})})]})}var D=1e4;function O({className:e}){let{t:n}=i(),a=v(e=>e.selectedPath),s=v(e=>e.diff),c=v(e=>e.loadingDiff),[d,f]=(0,S.useState)(`unified`),[p,m]=(0,S.useState)(!1),x=!!a&&(c||!s);(0,S.useEffect)(()=>{if(m(!1),!x)return;let e=setTimeout(()=>m(!0),D);return()=>clearTimeout(e)},[x,a]);let w=()=>{a&&(m(!1),v.getState().setDiffLoading(!0),h(_.getState().wsUrl).getGitDiff?.(a))};if(!a)return(0,C.jsx)(b,{icon:(0,C.jsx)(r,{className:`h-6 w-6`}),title:`Source changes`,description:n(`activity:changes.selectPrompt`),className:e});let T=s&&!s.error&&!s.binary&&!s.tooLarge;return(0,C.jsx)(`div`,{className:g(`flex min-h-0 min-w-0 flex-1 flex-col overflow-hidden bg-[hsl(var(--surface-2)/0.45)] p-3`,e),children:(0,C.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col overflow-hidden rounded-xl border border-border/70 bg-card/75 shadow-sm`,children:[(0,C.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center justify-between gap-2 border-b border-border/70 px-3 py-2`,children:[(0,C.jsxs)(`div`,{className:`min-w-0`,children:[(0,C.jsx)(`div`,{className:`text-[10px] font-semibold uppercase text-muted-foreground`,children:`Source control`}),(0,C.jsx)(`div`,{className:`truncate font-mono text-xs text-foreground`,title:a,children:a})]}),T&&(0,C.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,C.jsxs)(`button`,{type:`button`,onClick:()=>f(`unified`),title:n(`activity:changes.unifiedTitle`),className:g(`inline-flex h-8 items-center gap-1 rounded-md border px-2 text-xs transition-colors`,d===`unified`?`border-primary/40 bg-primary/10 text-primary`:`border-border text-muted-foreground hover:bg-muted`),children:[(0,C.jsx)(u,{className:`h-3.5 w-3.5`}),` `,n(`activity:changes.unified`)]}),(0,C.jsxs)(`button`,{type:`button`,onClick:()=>f(`edit`),title:n(`activity:changes.editTitle`),className:g(`inline-flex h-8 items-center gap-1 rounded-md border px-2 text-xs transition-colors`,d===`edit`?`border-primary/40 bg-primary/10 text-primary`:`border-border text-muted-foreground hover:bg-muted`),children:[(0,C.jsx)(l,{className:`h-3.5 w-3.5`}),` `,n(`activity:changes.edit`)]})]})]}),(0,C.jsx)(`div`,{className:`flex min-h-0 flex-1 flex-col overflow-hidden`,children:c||!s?p?(0,C.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col items-center justify-center gap-3 p-4 text-center`,children:[(0,C.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:n(`activity:changes.diffTimeout`)}),(0,C.jsxs)(`button`,{type:`button`,onClick:w,className:`inline-flex h-8 items-center gap-1.5 rounded-md border border-border px-3 text-xs text-muted-foreground transition-colors hover:bg-muted hover:text-foreground`,children:[(0,C.jsx)(o,{className:`h-3.5 w-3.5`}),` `,n(`common:action.retry`)]})]}):(0,C.jsxs)(`div`,{className:`flex min-h-0 flex-1 items-center justify-center gap-2 text-sm text-muted-foreground`,children:[(0,C.jsx)(t,{className:`h-4 w-4 animate-spin`}),` `,n(`activity:changes.loadingDiff`)]}):s.error?(0,C.jsx)(`div`,{className:`flex min-h-0 flex-1 items-center justify-center text-sm text-destructive`,children:s.error}):s.binary?(0,C.jsx)(`div`,{className:`flex min-h-0 flex-1 items-center justify-center text-sm text-muted-foreground`,children:n(`activity:changes.binary`)}):s.tooLarge?(0,C.jsx)(`div`,{className:`flex min-h-0 flex-1 items-center justify-center text-sm text-muted-foreground`,children:n(`activity:changes.tooLarge`)}):d===`edit`?(0,C.jsx)(E,{path:s.path,oldText:s.oldText??``,newText:s.newText??``},s.path):(0,C.jsx)(y,{oldText:s.oldText,newText:s.newText,caption:s.path,fill:!0})})]})})}export{O as ChangesView};
@@ -0,0 +1 @@
1
+ import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{Ii as t,Ki as n,Kr as r,Nt as i,Qn as a,Sa as o,Ut as s,Yi as c,Zt as l,_i as ee,at as u,br as d,bt as f,cn as p,et as m,ii as h,in as te,ma as g,wr as ne}from"./vendor-2VBBgNb5.js";import{t as re}from"./ws-client-WVGn8ORh.js";import{t as _}from"./utils-CN2sfDVP.js";import{f as v,p as y}from"./index-BPfIz78e.js";var b=e(o(),1),x=m();function S({status:e}){return(0,x.jsxs)(`section`,{className:`flex flex-wrap gap-x-5 gap-y-1 border-b border-border/60 bg-primary/[0.025] px-4 py-1.5 font-mono text-[9px] text-muted-foreground`,title:e.chronicleDirectory,children:[(0,x.jsx)(`span`,{className:`font-sans font-semibold uppercase tracking-wider text-primary`,children:`Chronicle ownership`}),(0,x.jsxs)(`span`,{children:[`collect `,(0,x.jsx)(`b`,{className:`text-foreground`,children:e.pipeline.collection})]}),(0,x.jsxs)(`span`,{children:[`process `,(0,x.jsx)(`b`,{className:`text-foreground`,children:e.pipeline.processing})]}),(0,x.jsxs)(`span`,{children:[`serve `,(0,x.jsx)(`b`,{className:`text-foreground`,children:e.pipeline.serving})]}),(0,x.jsxs)(`span`,{children:[`PID `,(0,x.jsx)(`b`,{className:`text-foreground`,children:e.pid}),` · `,e.clients,` clients`]}),(0,x.jsxs)(`span`,{children:[`watcher`,` `,(0,x.jsx)(`b`,{className:_(e.watcher.active?`text-success`:`text-warning`),children:e.watcher.active?`active`:`inactive`}),` `,`· `,e.watcher.watchedFiles,` files`]}),(0,x.jsxs)(`span`,{children:[`store `,(0,x.jsx)(`b`,{className:`text-foreground`,children:C(e.pipeline.storage)})]}),e.mode===`inline`&&(0,x.jsx)(`span`,{className:`font-sans font-semibold text-warning`,children:`INLINE FALLBACK`})]})}function C(e){return e.replaceAll(`\\`,`/`).split(`/`).filter(Boolean).slice(-3).join(`/`)}var w=[`eventType`,`providerId`,`modelId`,`outcome`,`resourceKind`],T=1440*60*1e3;function E(){return{limit:300,order:`desc`,from:new Date(Date.now()-T).toISOString()}}var ie=[{id:`all`,label:`All signals`,icon:(0,x.jsx)(g,{})},{id:`llm`,label:`LLM`,icon:(0,x.jsx)(n,{})},{id:`agents`,label:`Agents`,icon:(0,x.jsx)(c,{})},{id:`tools`,label:`Tools`,icon:(0,x.jsx)(i,{})},{id:`files`,label:`Files`,icon:(0,x.jsx)(r,{})},{id:`failures`,label:`Failures`,icon:(0,x.jsx)(f,{})}];function D(){let e=re(),[t,o]=(0,b.useState)([]),[s,d]=(0,b.useState)(null),[f,m]=(0,b.useState)({}),[h,g]=(0,b.useState)(E()),[C,T]=(0,b.useState)({text:``,path:``,providerId:``,modelId:``,sessionId:``}),[D,O]=(0,b.useState)(`all`),[A,P]=(0,b.useState)({total:0,scannedEvents:0,sourceFiles:0,invalidLines:0}),[I,de]=(0,b.useState)(k),[L,R]=(0,b.useState)(!0),[z,B]=(0,b.useState)(null),[V,H]=(0,b.useState)(null),[U,fe]=(0,b.useState)([]),[W,pe]=(0,b.useState)([]),[G,me]=(0,b.useState)(null),K=(0,b.useCallback)(t=>{if(!e.supportsCapability(`chronicle.query`)){R(!1),B(`Restart the backend once to activate Chronicle protocol support.`);return}if(R(!0),B(null),g(t),m({}),e.send({type:`chronicle.query`,payload:{query:t}}),e.supportsCapability(`chronicle.facets`))e.send({type:`chronicle.facets`,payload:{fields:[...w],query:t,limit:12}});else for(let n of w)e.send({type:`chronicle.facet`,payload:{field:n,query:t,limit:12}})},[e]),q=(0,b.useCallback)(()=>{e.supportsCapability(`chronicle.metrics`)&&(e.send({type:`chronicle.metrics`,payload:{view:`providers`}}),e.send({type:`chronicle.metrics`,payload:{view:`tasks`,limit:200}}))},[e]),J=(0,b.useCallback)(()=>{e.supportsCapability(`chronicle.status`)&&e.send({type:`chronicle.status`})},[e]);(0,b.useEffect)(()=>{let t=e.on(`chronicle.query_result`,e=>{e.type===`chronicle.query_result`&&(o(e.payload.events),P(e.payload),de(e.payload.summary??k),R(!1))}),n=e.on(`chronicle.facet_result`,e=>{e.type===`chronicle.facet_result`&&m(t=>({...t,[e.payload.field]:e.payload.values}))}),r=e.on(`chronicle.facets_result`,e=>{e.type===`chronicle.facets_result`&&m(e.payload.values)}),i=e.on(`chronicle.error`,e=>{e.type===`chronicle.error`&&(B(e.payload.message),R(!1))}),a=e.on(`chronicle.graph_result`,e=>{e.type===`chronicle.graph_result`&&H(e.payload)}),s=e.on(`chronicle.metrics_result`,e=>{e.type===`chronicle.metrics_result`&&(e.payload.view===`providers`?fe(e.payload.data):e.payload.view===`tasks`&&pe(e.payload.data))}),c=e.on(`chronicle.status_result`,e=>{e.type===`chronicle.status_result`&&me(e.payload)});return K(E()),q(),J(),()=>{t(),n(),r(),i(),a(),s(),c()}},[e,K,q,J]);let Y=(0,b.useMemo)(()=>t.filter(e=>se(e,D)),[t,D]),X=y(Y,25,D),Z=(0,b.useMemo)(()=>{let e=t.find(e=>e.eventType===`metrics.rollup`&&e.attributes?.signal===`runtime.health`)?.attributes?.stats;if(!e)return;let n=t=>e[t]?.last;return{eventLoop:{utilization:n(`eventLoop.utilization`),delayP95Ms:n(`eventLoop.delayP95Ms`)},memory:{heapUsedBytes:n(`memory.heapUsedBytes`)},chronicle:{pendingEvents:n(`chronicle.pendingEvents`),rejectedEvents:n(`chronicle.rejectedEvents`)}}},[t]),Q=(0,b.useMemo)(()=>{let e={};for(let t of W)e[t.status]=(e[t.status]??0)+1;let t=(e.completed??0)+(e.merged??0)+(e.failed??0)+(e.conflict??0),n=(e.completed??0)+(e.merged??0),r=[...W].sort((e,t)=>(t.endedAt??t.startedAt??``).localeCompare(e.endedAt??e.startedAt??``)).slice(0,8);return{counts:e,total:W.length,terminal:t,successRate:t>0?n/t*100:100,recent:r}},[W]),$=()=>K({...E(),...C.text?{text:C.text}:{},...C.path?{path:C.path}:{},...C.providerId?{providerId:C.providerId}:{},...C.modelId?{modelId:C.modelId}:{},...C.sessionId?{sessionId:C.sessionId}:{}}),he=()=>{T({text:``,path:``,providerId:``,modelId:``,sessionId:``}),O(`all`),K(E())},ge=t=>{d(t),H(null),e.supportsCapability(`chronicle.graph`)&&e.send({type:`chronicle.graph`,payload:{seed:{eventId:t.eventId},hops:2,maxNodes:250}})};return(0,x.jsxs)(`div`,{className:`flex h-full min-h-0 bg-background`,"data-testid":`chronicle-dashboard`,children:[(0,x.jsxs)(`main`,{className:`flex min-w-0 flex-1 flex-col`,children:[(0,x.jsx)(`header`,{className:`border-b border-border/70 bg-gradient-to-r from-primary/[0.045] via-background to-background px-5 py-4`,children:(0,x.jsxs)(`div`,{className:`flex items-start justify-between gap-4`,children:[(0,x.jsxs)(`div`,{children:[(0,x.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,x.jsx)(n,{className:`h-5 w-5 text-primary`}),(0,x.jsx)(`h1`,{className:`text-lg font-semibold tracking-tight`,children:`Coding Intelligence`}),(0,x.jsx)(`span`,{className:`rounded-full border border-primary/20 bg-primary/10 px-2 py-0.5 text-[9px] font-semibold tracking-wider text-primary`,children:`CHRONICLE`})]}),(0,x.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:`LLM, agent, tool and file evidence — connected from decision to code change.`})]}),(0,x.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,x.jsx)(`span`,{className:_(`h-2 w-2 rounded-full`,z?`bg-destructive`:L?`animate-pulse bg-warning`:`bg-success`)}),(0,x.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:L?`Reading journal`:z?`Unavailable`:`Live evidence`}),(0,x.jsx)(`button`,{type:`button`,onClick:()=>{K(h),q(),J()},className:`ml-2 rounded-md border border-border bg-card p-2 hover:bg-muted`,title:`Refresh evidence`,children:(0,x.jsx)(p,{className:_(`h-4 w-4`,L&&`animate-spin`)})})]})]})}),(0,x.jsxs)(`section`,{className:`grid grid-cols-2 border-b border-border/70 xl:grid-cols-6`,children:[(0,x.jsx)(N,{icon:(0,x.jsx)(n,{}),label:`LLM requests`,value:I.logicalRequests,detail:`${I.modelAttempts} attempts · ${I.providers} providers · ${I.models} models`}),(0,x.jsx)(N,{icon:(0,x.jsx)(c,{}),label:`Agent work`,value:I.agentEvents,detail:`${I.uniqueAgents} correlated agents · ${I.decisions} decisions`}),(0,x.jsx)(N,{icon:(0,x.jsx)(i,{}),label:`Tool calls`,value:I.toolCalls,detail:`${I.failedTools} failed · ${I.processes} processes`}),(0,x.jsx)(N,{icon:(0,x.jsx)(r,{}),label:`File evidence`,value:I.fileEvents,detail:`${I.uniqueFiles} unique paths`}),(0,x.jsx)(N,{icon:(0,x.jsx)(te,{}),label:`Retries`,value:I.scheduledRetries,detail:`${I.failures} failures · ${I.fallbacks} fallbacks`,tone:I.failures?`danger`:`normal`}),(0,x.jsx)(N,{icon:(0,x.jsx)(ee,{}),label:`Provider p95`,value:j(I.providerP95DurationMs),detail:`${j(I.providerAvgDurationMs)} average · all matches`})]}),(0,x.jsxs)(`section`,{className:`flex flex-wrap gap-x-6 gap-y-1 border-b border-border/60 bg-primary/[0.018] px-4 py-1.5 font-mono text-[9px] text-muted-foreground`,children:[(0,x.jsx)(`span`,{className:`font-sans font-semibold uppercase tracking-wider text-primary`,children:`Token economics`}),(0,x.jsxs)(`span`,{children:[`fresh input `,(0,x.jsx)(`b`,{className:`text-foreground`,children:I.inputTokens.toLocaleString()})]}),(0,x.jsxs)(`span`,{children:[`output `,(0,x.jsx)(`b`,{className:`text-foreground`,children:I.outputTokens.toLocaleString()})]}),(0,x.jsxs)(`span`,{children:[`cache read `,(0,x.jsx)(`b`,{className:`text-foreground`,children:I.cacheReadTokens.toLocaleString()})]}),(0,x.jsxs)(`span`,{children:[`cache write`,` `,(0,x.jsx)(`b`,{className:`text-foreground`,children:I.cacheWriteTokens.toLocaleString()})]}),(0,x.jsxs)(`span`,{children:[`cache hit `,(0,x.jsxs)(`b`,{className:`text-foreground`,children:[oe(I).toFixed(1),`%`]})]}),(0,x.jsxs)(`span`,{children:[`estimated cost `,(0,x.jsxs)(`b`,{className:`text-foreground`,children:[`$`,I.estimatedCostUsd.toFixed(4)]})]})]}),U.length>0&&(0,x.jsxs)(`section`,{className:`flex items-center gap-3 overflow-x-auto border-b border-border/60 bg-muted/[0.14] px-4 py-1.5`,children:[(0,x.jsx)(`span`,{className:`shrink-0 text-[9px] font-semibold uppercase tracking-wider text-muted-foreground`,children:`Model reliability`}),U.slice(0,6).map(e=>{let t=e.completed+e.failed,n=t>0?e.completed/t*100:100;return(0,x.jsxs)(`span`,{className:`flex shrink-0 items-center gap-2 rounded-full border border-border bg-card px-2.5 py-0.5 font-mono text-[9px]`,title:`${e.day} · ${e.attempts} attempts · avg ${j(e.avgDurationMs)} · ${e.inputTokens.toLocaleString()} in / ${e.outputTokens.toLocaleString()} out`,children:[(0,x.jsx)(`span`,{className:_(`h-1.5 w-1.5 rounded-full`,n>=99?`bg-success`:n>=90?`bg-warning`:`bg-destructive`)}),(0,x.jsxs)(`span`,{className:`max-w-[180px] truncate`,children:[e.providerId,`/`,e.modelId]}),(0,x.jsxs)(`b`,{className:`text-foreground`,children:[n.toFixed(0),`%`]}),(0,x.jsx)(`span`,{className:`text-muted-foreground`,children:e.day.slice(5)})]},`${e.day}-${e.providerId}-${e.modelId}`)})]}),Q.total>0&&(0,x.jsxs)(`section`,{className:`flex items-center gap-3 overflow-x-auto border-b border-border/60 bg-muted/[0.10] px-4 py-1.5`,children:[(0,x.jsxs)(`span`,{className:`flex shrink-0 items-center gap-1 text-[9px] font-semibold uppercase tracking-wider text-muted-foreground`,children:[(0,x.jsx)(a,{className:`h-3 w-3`}),`Task outcomes`]}),(0,x.jsxs)(`span`,{className:`flex shrink-0 items-center gap-2 rounded-full border border-border bg-card px-2.5 py-0.5 font-mono text-[9px]`,title:`${Q.total} tasks tracked · ${Q.terminal} finished`,children:[(0,x.jsx)(`span`,{className:_(`h-1.5 w-1.5 rounded-full`,Q.successRate>=90?`bg-success`:Q.successRate>=60?`bg-warning`:`bg-destructive`)}),(0,x.jsxs)(`b`,{className:`text-foreground`,children:[Q.successRate.toFixed(0),`%`]}),(0,x.jsxs)(`span`,{className:`text-muted-foreground`,children:[`success · `,Q.total,` tasks`]})]}),[`completed`,`merged`,`failed`,`conflict`,`started`].filter(e=>Q.counts[e]).map(e=>(0,x.jsxs)(`span`,{className:`shrink-0 font-mono text-[9px] text-muted-foreground`,children:[e,` `,(0,x.jsx)(`b`,{className:_(e===`failed`||e===`conflict`?`text-destructive`:`text-foreground`),children:Q.counts[e]})]},e)),(0,x.jsx)(`span`,{className:`mx-1 h-3 w-px shrink-0 bg-border`}),Q.recent.map(e=>(0,x.jsxs)(`button`,{type:`button`,onClick:()=>K({limit:300,order:`desc`,taskId:e.taskId}),className:`flex shrink-0 items-center gap-1.5 rounded-full border border-border bg-card px-2 py-0.5 font-mono text-[9px] hover:border-primary/50`,title:`${e.taskId}${e.boardId?` · board ${e.boardId}`:``}${e.sessionId?` · ${e.sessionId}`:``} · ${e.filesTouched} files${e.retries?` · ${e.retries} retries`:``}${e.verificationFailures?` · ${e.verificationFailures} verify-fails`:``}`,children:[(0,x.jsx)(`span`,{className:_(`h-1.5 w-1.5 rounded-full`,e.status===`completed`||e.status===`merged`?`bg-success`:e.status===`failed`||e.status===`conflict`?`bg-destructive`:`bg-primary`)}),(0,x.jsx)(`span`,{className:`max-w-[84px] truncate`,children:e.taskId}),e.durationMs!==null&&(0,x.jsx)(`span`,{className:`text-muted-foreground`,children:j(e.durationMs)}),e.filesTouched>0&&(0,x.jsxs)(`span`,{className:`flex items-center gap-0.5 text-muted-foreground`,children:[(0,x.jsx)(r,{className:`h-2.5 w-2.5`}),e.filesTouched]})]},e.taskId))]}),(0,x.jsx)(`section`,{className:`border-b border-border/70 px-4 py-3`,children:(0,x.jsxs)(`div`,{className:`grid grid-cols-2 gap-2 xl:grid-cols-[1.35fr_1fr_1fr_1fr_1fr_auto]`,children:[(0,x.jsx)(M,{icon:(0,x.jsx)(l,{}),placeholder:`Search event evidence`,value:C.text,onChange:e=>T(t=>({...t,text:e})),onEnter:$}),(0,x.jsx)(M,{placeholder:`File or directory`,value:C.path,onChange:e=>T(t=>({...t,path:e})),onEnter:$}),(0,x.jsx)(M,{placeholder:`Provider`,value:C.providerId,onChange:e=>T(t=>({...t,providerId:e})),onEnter:$}),(0,x.jsx)(M,{placeholder:`Model`,value:C.modelId,onChange:e=>T(t=>({...t,modelId:e})),onEnter:$}),(0,x.jsx)(M,{placeholder:`Session`,value:C.sessionId,onChange:e=>T(t=>({...t,sessionId:e})),onEnter:$}),(0,x.jsxs)(`div`,{className:`flex gap-1.5`,children:[(0,x.jsxs)(`button`,{type:`button`,onClick:$,className:`rounded-md bg-primary px-3 text-xs font-medium text-primary-foreground`,children:[(0,x.jsx)(ne,{className:`mr-1 inline h-3 w-3`}),`Apply`]}),(0,x.jsx)(`button`,{type:`button`,onClick:he,className:`rounded-md border border-border px-2.5 text-xs hover:bg-muted`,children:`Clear`})]})]})}),(0,x.jsxs)(`section`,{className:`flex items-center gap-1 overflow-x-auto border-b border-border/70 px-4 py-2`,children:[ie.map(e=>(0,x.jsxs)(`button`,{type:`button`,onClick:()=>O(e.id),className:_(`flex shrink-0 items-center gap-1.5 rounded-md px-2.5 py-1.5 text-[11px] transition-colors [&>svg]:h-3.5 [&>svg]:w-3.5`,D===e.id?`bg-primary/10 font-medium text-primary`:`text-muted-foreground hover:bg-muted hover:text-foreground`),children:[e.icon,e.label,(0,x.jsx)(`span`,{className:`ml-1 rounded bg-background/70 px-1 font-mono text-[9px]`,children:ae(I,e.id,A.total)})]},e.id)),(0,x.jsxs)(`div`,{className:`ml-auto hidden items-center gap-3 pl-4 text-[9px] text-muted-foreground lg:flex`,children:[(0,x.jsxs)(`span`,{children:[A.total.toLocaleString(),` matched`]}),(0,x.jsxs)(`span`,{children:[A.sourceFiles,` journal files`]}),A.invalidLines>0&&(0,x.jsxs)(`span`,{className:`text-warning`,children:[A.invalidLines,` invalid lines`]})]})]}),G&&(0,x.jsx)(S,{status:G}),Z&&(0,x.jsx)(ce,{health:Z}),(0,x.jsx)(`section`,{className:`flex gap-4 overflow-x-auto border-b border-border/60 bg-muted/[0.18] px-4 py-2`,children:[`providerId`,`modelId`,`outcome`].map(e=>(0,x.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1`,children:[(0,x.jsx)(`span`,{className:`mr-1 text-[9px] font-semibold uppercase tracking-wider text-muted-foreground`,children:e.replace(`Id`,``)}),(f[e]??[]).slice(0,4).map(t=>(0,x.jsxs)(`button`,{type:`button`,onClick:()=>K({...h,[e]:t.value}),className:`rounded-full border border-border bg-card px-2 py-0.5 text-[9px] hover:border-primary/50`,children:[t.value,` `,(0,x.jsx)(`b`,{children:t.count})]},t.value))]},e))}),(0,x.jsxs)(`div`,{className:`grid grid-cols-[92px_minmax(190px,1.25fr)_110px_minmax(180px,1fr)_minmax(140px,.8fr)_24px] gap-3 border-b border-border/60 bg-muted/20 px-4 py-1.5 text-[9px] font-semibold uppercase tracking-wider text-muted-foreground`,children:[(0,x.jsx)(`span`,{children:`Time`}),(0,x.jsx)(`span`,{children:`Signal`}),(0,x.jsx)(`span`,{children:`Outcome`}),(0,x.jsx)(`span`,{children:`Model / agent`}),(0,x.jsx)(`span`,{children:`Resource`}),(0,x.jsx)(`span`,{})]}),(0,x.jsx)(`div`,{className:`min-h-0 flex-1 overflow-auto`,children:z?(0,x.jsx)(F,{text:z}):!L&&Y.length===0?(0,x.jsx)(F,{text:`No coding evidence matches these filters.`}):(0,x.jsx)(`div`,{className:`divide-y divide-border/40`,children:X.pageItems.map(e=>(0,x.jsx)(le,{event:e,active:s?.eventId===e.eventId,onClick:()=>ge(e)},e.eventId))})}),(0,x.jsx)(v,{page:X.page,pageSize:X.pageSize,totalItems:X.totalItems,onPageChange:X.setPage,itemLabel:`events`})]}),s&&(0,x.jsxs)(`aside`,{className:`w-[440px] max-w-[48vw] shrink-0 overflow-auto border-l border-border bg-card/60 shadow-[-12px_0_32px_hsl(var(--background)/.35)]`,children:[(0,x.jsxs)(`div`,{className:`sticky top-0 z-10 flex items-center justify-between border-b border-border bg-card/95 px-4 py-3 backdrop-blur`,children:[(0,x.jsxs)(`div`,{children:[(0,x.jsx)(`div`,{className:`text-xs font-semibold`,children:`Evidence & lineage`}),(0,x.jsxs)(`div`,{className:`mt-0.5 font-mono text-[9px] text-muted-foreground`,children:[`#`,s.sequence,` · `,s.eventId]})]}),(0,x.jsx)(`button`,{type:`button`,onClick:()=>d(null),className:`rounded p-1 hover:bg-muted`,children:(0,x.jsx)(u,{className:`h-4 w-4`})})]}),(0,x.jsx)(ue,{event:s,graph:V})]})]})}var O={llm:0,agent:0,tool:0,file:0,memory:0,task:0,decision:0,runtime:0},k={logicalRequests:0,modelAttempts:0,completedAttempts:0,failedAttempts:0,scheduledRetries:0,fallbacks:0,providers:0,models:0,inputTokens:0,outputTokens:0,cacheReadTokens:0,cacheWriteTokens:0,estimatedCostUsd:0,providerAvgDurationMs:0,providerP95DurationMs:0,toolCalls:0,completedTools:0,failedTools:0,toolAvgDurationMs:0,processes:0,failedProcesses:0,fileEvents:0,uniqueFiles:0,agentEvents:0,uniqueAgents:0,decisions:0,escalations:0,failures:0,cancellations:0,families:{...O},failuresByFamily:{...O}};function ae(e,t,n){return t===`all`?n:t===`llm`?e.families.llm:t===`agents`?e.families.agent:t===`tools`?e.families.tool:t===`files`?e.families.file:e.failures}function oe(e){let t=e.inputTokens+e.cacheReadTokens;return t?e.cacheReadTokens/t*100:0}function se(e,t){return t===`all`?!0:t===`llm`?/^(provider|token|context|compaction)\./.test(e.eventType):t===`agents`?/^(agent|subagent|delegate|fleet|sdd)\./.test(e.eventType):t===`tools`?/^(tool|process|mcp|network)\./.test(e.eventType):t===`files`?e.resource?.kind===`file`||/^(file|worktree|storage)\./.test(e.eventType):e.outcome===`failure`||/(?:failed|error|retry|fallback|blocked|conflict)/i.test(e.eventType)}function A(e){if(!e)return`—`;let t=e/1e6;return t<1?`${(e/1e3).toFixed(0)}µs`:t<1e3?`${t.toFixed(1)}ms`:`${(t/1e3).toFixed(1)}s`}function j(e){return e?e<1?`${(e*1e3).toFixed(0)}µs`:e<1e3?`${e.toFixed(1)}ms`:`${(e/1e3).toFixed(1)}s`:`—`}function M({placeholder:e,value:t,onChange:n,onEnter:r,icon:i}){return(0,x.jsxs)(`label`,{className:`flex items-center gap-2 rounded-md border border-border bg-card px-2.5 py-2 focus-within:border-primary/60`,children:[i&&(0,x.jsx)(`span`,{className:`text-muted-foreground [&>svg]:h-3.5 [&>svg]:w-3.5`,children:i}),(0,x.jsx)(`input`,{className:`w-full bg-transparent text-xs outline-none placeholder:text-muted-foreground/70`,placeholder:e,value:t,onChange:e=>n(e.target.value),onKeyDown:e=>{e.key===`Enter`&&r()}})]})}function N({icon:e,label:t,value:n,detail:r,tone:i=`normal`}){return(0,x.jsxs)(`div`,{className:`min-w-0 border-r border-border/60 px-4 py-3`,children:[(0,x.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[10px] font-medium uppercase tracking-wide text-muted-foreground`,children:[(0,x.jsx)(`span`,{className:`text-primary [&>svg]:h-3.5 [&>svg]:w-3.5`,children:e}),t]}),(0,x.jsx)(`div`,{className:_(`mt-1 text-xl font-semibold tabular-nums`,i===`danger`&&`text-destructive`),children:typeof n==`number`?n.toLocaleString():n}),(0,x.jsx)(`div`,{className:`mt-0.5 truncate text-[9px] text-muted-foreground`,children:r})]})}function ce({health:e}){return(0,x.jsxs)(`section`,{className:`flex flex-wrap gap-x-5 gap-y-1 border-b border-border/60 bg-success/[0.025] px-4 py-1.5 font-mono text-[9px] text-muted-foreground`,children:[(0,x.jsx)(`span`,{className:`font-sans font-semibold uppercase tracking-wider text-success`,children:`Collector healthy`}),(0,x.jsxs)(`span`,{children:[`ELU`,` `,(0,x.jsxs)(`b`,{className:`text-foreground`,children:[((e.eventLoop?.utilization??0)*100).toFixed(1),`%`]})]}),(0,x.jsxs)(`span`,{children:[`p95 `,(0,x.jsxs)(`b`,{className:`text-foreground`,children:[(e.eventLoop?.delayP95Ms??0).toFixed(1),`ms`]})]}),(0,x.jsxs)(`span`,{children:[`heap`,` `,(0,x.jsxs)(`b`,{className:`text-foreground`,children:[((e.memory?.heapUsedBytes??0)/1048576).toFixed(0),`MB`]})]}),(0,x.jsxs)(`span`,{children:[`queue `,(0,x.jsx)(`b`,{className:`text-foreground`,children:e.chronicle?.pendingEvents??0})]}),(0,x.jsxs)(`span`,{children:[`dropped`,` `,(0,x.jsx)(`b`,{className:_((e.chronicle?.rejectedEvents??0)>0&&`text-destructive`),children:e.chronicle?.rejectedEvents??0})]})]})}function le({event:e,active:n,onClick:r}){let i=e.occurredAt??e.observedAt,a=e.runtime?.modelId??e.scope.agentId??e.runtime?.providerId??`—`,o=e.resource?.path??e.resource?.id??e.correlation.toolCallId??`—`;return(0,x.jsxs)(`button`,{type:`button`,onClick:r,className:_(`grid w-full grid-cols-[92px_minmax(190px,1.25fr)_110px_minmax(180px,1fr)_minmax(140px,.8fr)_24px] items-center gap-3 px-4 py-2.5 text-left hover:bg-muted/45`,n&&`bg-primary/[0.07]`),children:[(0,x.jsx)(`span`,{className:`font-mono text-[9px] text-muted-foreground`,children:new Date(i).toLocaleTimeString()}),(0,x.jsxs)(`span`,{className:`flex min-w-0 items-center gap-2`,children:[(0,x.jsx)(`span`,{className:_(`h-1.5 w-1.5 shrink-0 rounded-full`,e.outcome===`failure`?`bg-destructive`:e.outcome===`success`?`bg-success`:`bg-primary`)}),(0,x.jsx)(`span`,{className:`truncate font-mono text-[11px] font-medium`,children:e.eventType})]}),(0,x.jsx)(`span`,{className:_(`w-fit rounded px-1.5 py-0.5 text-[9px]`,I(e.outcome)),children:e.outcome??`unknown`}),(0,x.jsx)(`span`,{className:`truncate font-mono text-[9px] text-muted-foreground`,children:a}),(0,x.jsx)(`span`,{className:`truncate font-mono text-[9px] text-muted-foreground`,children:o}),(0,x.jsx)(t,{className:`h-3.5 w-3.5 text-muted-foreground`})]})}function ue({event:e,graph:t}){let n=(0,b.useMemo)(()=>[[`Scope`,e.scope],[`Correlation`,e.correlation],[`Runtime`,e.runtime],[`Resource`,e.resource],[`Attributes`,e.attributes],[`Tags`,e.tags]],[e]);return(0,x.jsxs)(`div`,{className:`p-4`,children:[(0,x.jsxs)(`div`,{className:`mb-4 rounded-lg border border-border bg-background/60 p-3`,children:[(0,x.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,x.jsx)(`span`,{className:_(`h-2 w-2 rounded-full`,e.outcome===`failure`?`bg-destructive`:e.outcome===`success`?`bg-success`:`bg-primary`)}),(0,x.jsx)(`span`,{className:`font-mono text-xs font-semibold`,children:e.eventType})]}),(0,x.jsxs)(`div`,{className:`mt-2 flex gap-4 text-[9px] text-muted-foreground`,children:[(0,x.jsx)(`span`,{children:new Date(e.occurredAt??e.observedAt).toLocaleString()}),(0,x.jsx)(`span`,{children:A(Number(e.durationNs??0))})]})]}),(0,x.jsxs)(`div`,{className:`mb-4 grid grid-cols-2 gap-2`,children:[(0,x.jsx)(P,{icon:(0,x.jsx)(s,{}),label:`Evidence hash`,value:e.hash.slice(0,16)}),(0,x.jsx)(P,{icon:(0,x.jsx)(h,{}),label:`Sequence`,value:String(e.sequence)})]}),t&&(0,x.jsxs)(`section`,{className:`mb-4`,children:[(0,x.jsxs)(`h3`,{className:`mb-1.5 flex items-center gap-1 text-[9px] font-semibold uppercase tracking-wider text-muted-foreground`,children:[(0,x.jsx)(d,{className:`h-3 w-3`}),`Lineage · `,t.nodes.length,` nodes · `,t.edges.length,` edges`]}),(0,x.jsx)(`div`,{className:`space-y-1 rounded-md border border-border bg-background/70 p-2`,children:t.edges.slice(0,40).map((e,n)=>(0,x.jsxs)(`div`,{className:`flex items-center gap-2 font-mono text-[9px]`,children:[(0,x.jsx)(`span`,{className:_(`rounded px-1`,e.confidence===`explicit`?`bg-success/10 text-success`:e.confidence===`inferred`?`bg-warning/10 text-warning`:`bg-primary/10 text-primary`),children:e.confidence}),(0,x.jsx)(`span`,{className:`text-muted-foreground`,children:e.kind}),(0,x.jsxs)(`span`,{className:`truncate`,children:[t.nodes.find(t=>t.eventId===e.from)?.eventType,` →`,` `,t.nodes.find(t=>t.eventId===e.to)?.eventType]})]},`${e.from}-${e.to}-${e.kind}-${n}`))}),t.truncated&&(0,x.jsx)(`p`,{className:`mt-1 text-[9px] text-warning`,children:`Lineage truncated at safety limit.`})]}),n.map(([e,t])=>t&&(0,x.jsxs)(`section`,{className:`mb-4`,children:[(0,x.jsx)(`h3`,{className:`mb-1.5 text-[9px] font-semibold uppercase tracking-wider text-muted-foreground`,children:e}),(0,x.jsx)(`pre`,{className:`overflow-auto rounded-md border border-border bg-background/70 p-3 font-mono text-[9px] leading-relaxed`,children:JSON.stringify(t,null,2)})]},e))]})}function P({icon:e,label:t,value:n}){return(0,x.jsxs)(`div`,{className:`rounded-md border border-border p-2`,children:[(0,x.jsxs)(`div`,{className:`flex items-center gap-1 text-[8px] uppercase text-muted-foreground`,children:[(0,x.jsx)(`span`,{className:`[&>svg]:h-3 [&>svg]:w-3`,children:e}),t]}),(0,x.jsx)(`div`,{className:`mt-1 truncate font-mono text-[9px]`,children:n})]})}function F({text:e}){return(0,x.jsx)(`div`,{className:`flex h-48 items-center justify-center text-sm text-muted-foreground`,children:e})}function I(e){return e===`failure`?`bg-destructive/10 text-destructive`:e===`success`?`bg-success/10 text-success`:e===`started`?`bg-primary/10 text-primary`:`bg-muted text-muted-foreground`}export{D as ChronicleDashboard};